linux/arch/arm/mm/physaddr.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2#include <linux/bug.h>
   3#include <linux/export.h>
   4#include <linux/types.h>
   5#include <linux/mmdebug.h>
   6#include <linux/mm.h>
   7
   8#include <asm/sections.h>
   9#include <asm/memory.h>
  10#include <asm/fixmap.h>
  11#include <asm/dma.h>
  12
  13#include "mm.h"
  14
  15static inline bool __virt_addr_valid(unsigned long x)
  16{
  17        /*
  18         * high_memory does not get immediately defined, and there
  19         * are early callers of __pa() against PAGE_OFFSET
  20         */
  21        if (!high_memory && x >= PAGE_OFFSET)
  22                return true;
  23
  24        if (high_memory && x >= PAGE_OFFSET && x < (unsigned long)high_memory)
  25                return true;
  26
  27        /*
  28         * MAX_DMA_ADDRESS is a virtual address that may not correspond to an
  29         * actual physical address. Enough code relies on __pa(MAX_DMA_ADDRESS)
  30         * that we just need to work around it and always return true.
  31         */
  32        if (x == MAX_DMA_ADDRESS)
  33                return true;
  34
  35        return false;
  36}
  37
  38phys_addr_t __virt_to_phys(unsigned long x)
  39{
  40        WARN(!__virt_addr_valid(x),
  41             "virt_to_phys used for non-linear address: %pK (%pS)\n",
  42             (void *)x, (void *)x);
  43
  44        return __virt_to_phys_nodebug(x);
  45}
  46EXPORT_SYMBOL(__virt_to_phys);
  47
  48phys_addr_t __phys_addr_symbol(unsigned long x)
  49{
  50        /* This is bounds checking against the kernel image only.
  51         * __pa_symbol should only be used on kernel symbol addresses.
  52         */
  53        VIRTUAL_BUG_ON(x < (unsigned long)KERNEL_START ||
  54                       x > (unsigned long)KERNEL_END);
  55
  56        return __pa_symbol_nodebug(x);
  57}
  58EXPORT_SYMBOL(__phys_addr_symbol);
  59