ioremap.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #include <linux/io.h>
  3. #include <linux/slab.h>
  4. #include <linux/mmzone.h>
  5. #include <linux/vmalloc.h>
  6. unsigned long ioremap_bot;
  7. EXPORT_SYMBOL(ioremap_bot);
  8. void __iomem *ioremap(phys_addr_t addr, unsigned long size)
  9. {
  10. pgprot_t prot = pgprot_noncached(PAGE_KERNEL);
  11. void *caller = __builtin_return_address(0);
  12. return __ioremap_caller(addr, size, prot, caller);
  13. }
  14. EXPORT_SYMBOL(ioremap);
  15. void __iomem *ioremap_wc(phys_addr_t addr, unsigned long size)
  16. {
  17. pgprot_t prot = pgprot_noncached_wc(PAGE_KERNEL);
  18. void *caller = __builtin_return_address(0);
  19. return __ioremap_caller(addr, size, prot, caller);
  20. }
  21. EXPORT_SYMBOL(ioremap_wc);
  22. void __iomem *ioremap_coherent(phys_addr_t addr, unsigned long size)
  23. {
  24. pgprot_t prot = pgprot_cached(PAGE_KERNEL);
  25. void *caller = __builtin_return_address(0);
  26. return __ioremap_caller(addr, size, prot, caller);
  27. }
  28. void __iomem *ioremap_prot(phys_addr_t addr, size_t size, pgprot_t prot)
  29. {
  30. pte_t pte = __pte(pgprot_val(prot));
  31. void *caller = __builtin_return_address(0);
  32. /* writeable implies dirty for kernel addresses */
  33. if (pte_write(pte))
  34. pte = pte_mkdirty(pte);
  35. return __ioremap_caller(addr, size, pte_pgprot(pte), caller);
  36. }
  37. EXPORT_SYMBOL(ioremap_prot);
  38. int early_ioremap_range(unsigned long ea, phys_addr_t pa,
  39. unsigned long size, pgprot_t prot)
  40. {
  41. unsigned long i;
  42. for (i = 0; i < size; i += PAGE_SIZE) {
  43. int err = map_kernel_page(ea + i, pa + i, pgprot_nx(prot));
  44. if (WARN_ON_ONCE(err)) /* Should clean up */
  45. return err;
  46. }
  47. return 0;
  48. }