physaddr.c 902 B

1234567891011121314151617181920212223242526272829303132333435
  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. /*
  10. * Boundary checking aginst the kernel linear mapping space.
  11. */
  12. WARN(!is_linear_mapping(x) && !is_kernel_mapping(x),
  13. "virt_to_phys used for non-linear address: %pK (%pS)\n",
  14. (void *)x, (void *)x);
  15. return __va_to_pa_nodebug(x);
  16. }
  17. EXPORT_SYMBOL(__virt_to_phys);
  18. phys_addr_t __phys_addr_symbol(unsigned long x)
  19. {
  20. unsigned long kernel_start = kernel_map.virt_addr;
  21. unsigned long kernel_end = kernel_start + kernel_map.size;
  22. /*
  23. * Boundary checking aginst the kernel image mapping.
  24. * __pa_symbol should only be used on kernel symbol addresses.
  25. */
  26. VIRTUAL_BUG_ON(x < kernel_start || x > kernel_end);
  27. return __va_to_pa_nodebug(x);
  28. }
  29. EXPORT_SYMBOL(__phys_addr_symbol);