blob: 60be9e24bd576ac410f52a894e09d9df4ad5ebea [file] [log] [blame]
Palmer Dabbelt527701e2020-07-09 11:43:21 -07001// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * A generic version of devmem_is_allowed.
4 *
5 * Based on arch/arm64/mm/mmap.c
6 *
7 * Copyright (C) 2020 Google, Inc.
8 * Copyright (C) 2012 ARM Ltd.
9 */
10
11#include <linux/mm.h>
12#include <linux/ioport.h>
13
14/*
15 * devmem_is_allowed() checks to see if /dev/mem access to a certain address
16 * is valid. The argument is a physical page number. We mimic x86 here by
17 * disallowing access to system RAM as well as device-exclusive MMIO regions.
18 * This effectively disable read()/write() on /dev/mem.
19 */
20int devmem_is_allowed(unsigned long pfn)
21{
Liang Wang854f3262021-08-13 16:54:45 -070022 if (iomem_is_exclusive(PFN_PHYS(pfn)))
Palmer Dabbelt527701e2020-07-09 11:43:21 -070023 return 0;
24 if (!page_is_ram(pfn))
25 return 1;
26 return 0;
27}