physaddr.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/addrspace.h>
  8. #include <asm/sections.h>
  9. #include <asm/io.h>
  10. #include <asm/page.h>
  11. #include <asm/dma.h>
  12. static inline bool __debug_virt_addr_valid(unsigned long x)
  13. {
  14. /*
  15. * MAX_DMA_ADDRESS is a virtual address that may not correspond to an
  16. * actual physical address. Enough code relies on
  17. * virt_to_phys(MAX_DMA_ADDRESS) that we just need to work around it
  18. * and always return true.
  19. */
  20. if (x == MAX_DMA_ADDRESS)
  21. return true;
  22. return x >= PAGE_OFFSET && (KSEGX(x) < KSEG2 ||
  23. IS_ENABLED(CONFIG_EVA) ||
  24. !IS_ENABLED(CONFIG_HIGHMEM));
  25. }
  26. phys_addr_t __virt_to_phys(volatile const void *x)
  27. {
  28. WARN(!__debug_virt_addr_valid((unsigned long)x),
  29. "virt_to_phys used for non-linear address: %pK (%pS)\n",
  30. x, x);
  31. return __virt_to_phys_nodebug(x);
  32. }
  33. EXPORT_SYMBOL(__virt_to_phys);
  34. phys_addr_t __phys_addr_symbol(unsigned long x)
  35. {
  36. /* This is bounds checking against the kernel image only.
  37. * __pa_symbol should only be used on kernel symbol addresses.
  38. */
  39. VIRTUAL_BUG_ON(x < (unsigned long)_text ||
  40. x > (unsigned long)_end);
  41. return __pa_symbol_nodebug(x);
  42. }
  43. EXPORT_SYMBOL(__phys_addr_symbol);