1 // SPDX-License-Identifier: GPL-2.0-only 1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 2 /* 3 * A generic version of devmem_is_allowed. 3 * A generic version of devmem_is_allowed. 4 * 4 * 5 * Based on arch/arm64/mm/mmap.c 5 * Based on arch/arm64/mm/mmap.c 6 * 6 * 7 * Copyright (C) 2020 Google, Inc. 7 * Copyright (C) 2020 Google, Inc. 8 * Copyright (C) 2012 ARM Ltd. 8 * Copyright (C) 2012 ARM Ltd. 9 */ 9 */ 10 10 11 #include <linux/mm.h> 11 #include <linux/mm.h> 12 #include <linux/ioport.h> 12 #include <linux/ioport.h> 13 #include <linux/io.h> << 14 13 15 /* 14 /* 16 * devmem_is_allowed() checks to see if /dev/m 15 * devmem_is_allowed() checks to see if /dev/mem access to a certain address 17 * is valid. The argument is a physical page n 16 * is valid. The argument is a physical page number. We mimic x86 here by 18 * disallowing access to system RAM as well as 17 * disallowing access to system RAM as well as device-exclusive MMIO regions. 19 * This effectively disable read()/write() on 18 * This effectively disable read()/write() on /dev/mem. 20 */ 19 */ 21 int devmem_is_allowed(unsigned long pfn) 20 int devmem_is_allowed(unsigned long pfn) 22 { 21 { 23 if (iomem_is_exclusive(PFN_PHYS(pfn))) !! 22 if (iomem_is_exclusive(pfn << PAGE_SHIFT)) 24 return 0; 23 return 0; 25 if (!page_is_ram(pfn)) 24 if (!page_is_ram(pfn)) 26 return 1; 25 return 1; 27 return 0; 26 return 0; 28 } 27 } 29 28
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.