physaddr.c 1.4 KB

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