Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * A generic version of devmem_is_allowed.
0004  *
0005  * Based on arch/arm64/mm/mmap.c
0006  *
0007  * Copyright (C) 2020 Google, Inc.
0008  * Copyright (C) 2012 ARM Ltd.
0009  */
0010 
0011 #include <linux/mm.h>
0012 #include <linux/ioport.h>
0013 
0014 /*
0015  * devmem_is_allowed() checks to see if /dev/mem access to a certain address
0016  * is valid. The argument is a physical page number.  We mimic x86 here by
0017  * disallowing access to system RAM as well as device-exclusive MMIO regions.
0018  * This effectively disable read()/write() on /dev/mem.
0019  */
0020 int devmem_is_allowed(unsigned long pfn)
0021 {
0022     if (iomem_is_exclusive(PFN_PHYS(pfn)))
0023         return 0;
0024     if (!page_is_ram(pfn))
0025         return 1;
0026     return 0;
0027 }