ioremap_32.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #include <linux/io.h>
  3. #include <linux/slab.h>
  4. #include <linux/vmalloc.h>
  5. #include <mm/mmu_decl.h>
  6. void __iomem *ioremap_wt(phys_addr_t addr, unsigned long size)
  7. {
  8. pgprot_t prot = pgprot_cached_wthru(PAGE_KERNEL);
  9. return __ioremap_caller(addr, size, prot, __builtin_return_address(0));
  10. }
  11. EXPORT_SYMBOL(ioremap_wt);
  12. void __iomem *
  13. __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *caller)
  14. {
  15. unsigned long v;
  16. phys_addr_t p, offset;
  17. int err;
  18. /*
  19. * If the address lies within the first 16 MB, assume it's in ISA
  20. * memory space
  21. */
  22. if (addr < SZ_16M)
  23. addr += _ISA_MEM_BASE;
  24. /*
  25. * Choose an address to map it to.
  26. * Once the vmalloc system is running, we use it.
  27. * Before then, we use space going down from IOREMAP_TOP
  28. * (ioremap_bot records where we're up to).
  29. */
  30. p = addr & PAGE_MASK;
  31. offset = addr & ~PAGE_MASK;
  32. size = PAGE_ALIGN(addr + size) - p;
  33. #ifndef CONFIG_CRASH_DUMP
  34. /*
  35. * Don't allow anybody to remap normal RAM that we're using.
  36. * mem_init() sets high_memory so only do the check after that.
  37. */
  38. if (slab_is_available() && p <= virt_to_phys(high_memory - 1) &&
  39. page_is_ram(__phys_to_pfn(p))) {
  40. pr_warn("%s(): phys addr 0x%llx is RAM lr %ps\n", __func__,
  41. (unsigned long long)p, __builtin_return_address(0));
  42. return NULL;
  43. }
  44. #endif
  45. if (size == 0)
  46. return NULL;
  47. /*
  48. * Is it already mapped? Perhaps overlapped by a previous
  49. * mapping.
  50. */
  51. v = p_block_mapped(p);
  52. if (v)
  53. return (void __iomem *)v + offset;
  54. if (slab_is_available())
  55. return generic_ioremap_prot(addr, size, prot);
  56. /*
  57. * Should check if it is a candidate for a BAT mapping
  58. */
  59. pr_warn("ioremap() called early from %pS. Use early_ioremap() instead\n", caller);
  60. err = early_ioremap_range(ioremap_bot - size - PAGE_SIZE, p, size, prot);
  61. if (err)
  62. return NULL;
  63. ioremap_bot -= size + PAGE_SIZE;
  64. return (void __iomem *)ioremap_bot + offset;
  65. }
  66. void iounmap(volatile void __iomem *addr)
  67. {
  68. /*
  69. * If mapped by BATs then there is nothing to do.
  70. * Calling vfree() generates a benign warning.
  71. */
  72. if (v_block_mapped((unsigned long)addr))
  73. return;
  74. generic_iounmap(addr);
  75. }
  76. EXPORT_SYMBOL(iounmap);