physaddr.c 905 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/types.h>
  3. #include <linux/mmdebug.h>
  4. #include <linux/mm.h>
  5. #include <asm/page.h>
  6. #include <asm/sections.h>
  7. phys_addr_t __virt_to_phys(unsigned long x)
  8. {
  9. phys_addr_t y = x - PAGE_OFFSET;
  10. /*
  11. * Boundary checking aginst the kernel linear mapping space.
  12. */
  13. WARN(y >= KERN_VIRT_SIZE,
  14. "virt_to_phys used for non-linear address: %pK (%pS)\n",
  15. (void *)x, (void *)x);
  16. return __va_to_pa_nodebug(x);
  17. }
  18. EXPORT_SYMBOL(__virt_to_phys);
  19. phys_addr_t __phys_addr_symbol(unsigned long x)
  20. {
  21. unsigned long kernel_start = (unsigned long)PAGE_OFFSET;
  22. unsigned long kernel_end = (unsigned long)_end;
  23. /*
  24. * Boundary checking aginst the kernel image mapping.
  25. * __pa_symbol should only be used on kernel symbol addresses.
  26. */
  27. VIRTUAL_BUG_ON(x < kernel_start || x > kernel_end);
  28. return __va_to_pa_nodebug(x);
  29. }
  30. EXPORT_SYMBOL(__phys_addr_symbol);