brintos

brintos / linux-shallow public Read only

0
0
Text · 993 B · 01b3627 Raw
30 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2 3#include <linux/mm.h>4#include <linux/io-mapping.h>5 6/**7 * io_mapping_map_user - remap an I/O mapping to userspace8 * @iomap: the source io_mapping9 * @vma: user vma to map to10 * @addr: target user address to start at11 * @pfn: physical address of kernel memory12 * @size: size of map area13 *14 *  Note: this is only safe if the mm semaphore is held when called.15 */16int io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma,17		unsigned long addr, unsigned long pfn, unsigned long size)18{19	vm_flags_t expected_flags = VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;20 21	if (WARN_ON_ONCE((vma->vm_flags & expected_flags) != expected_flags))22		return -EINVAL;23 24	/* We rely on prevalidation of the io-mapping to skip track_pfn(). */25	return remap_pfn_range_notrack(vma, addr, pfn, size,26		__pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |27			 (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK)));28}29EXPORT_SYMBOL_GPL(io_mapping_map_user);30