io.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Common io.c file
  3. * This file is created by Russell King <rmk+kernel@arm.linux.org.uk>
  4. *
  5. * Copyright (C) 2009 Texas Instruments
  6. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/io.h>
  14. #include <linux/mm.h>
  15. #include <linux/dma-mapping.h>
  16. #include <plat/omap7xx.h>
  17. #include <plat/omap1510.h>
  18. #include <plat/omap16xx.h>
  19. #include <plat/omap24xx.h>
  20. #include <plat/omap34xx.h>
  21. #include <plat/omap44xx.h>
  22. #define BETWEEN(p,st,sz) ((p) >= (st) && (p) < ((st) + (sz)))
  23. #define XLATE(p,pst,vst) ((void __iomem *)((p) - (pst) + (vst)))
  24. static int initialized;
  25. /*
  26. * Intercept ioremap() requests for addresses in our fixed mapping regions.
  27. */
  28. void __iomem *omap_ioremap(unsigned long p, size_t size, unsigned int type)
  29. {
  30. WARN(!initialized, "Do not use ioremap before init_early\n");
  31. #ifdef CONFIG_ARCH_OMAP1
  32. if (cpu_class_is_omap1()) {
  33. if (BETWEEN(p, OMAP1_IO_PHYS, OMAP1_IO_SIZE))
  34. return XLATE(p, OMAP1_IO_PHYS, OMAP1_IO_VIRT);
  35. }
  36. if (cpu_is_omap7xx()) {
  37. if (BETWEEN(p, OMAP7XX_DSP_BASE, OMAP7XX_DSP_SIZE))
  38. return XLATE(p, OMAP7XX_DSP_BASE, OMAP7XX_DSP_START);
  39. if (BETWEEN(p, OMAP7XX_DSPREG_BASE, OMAP7XX_DSPREG_SIZE))
  40. return XLATE(p, OMAP7XX_DSPREG_BASE,
  41. OMAP7XX_DSPREG_START);
  42. }
  43. if (cpu_is_omap15xx()) {
  44. if (BETWEEN(p, OMAP1510_DSP_BASE, OMAP1510_DSP_SIZE))
  45. return XLATE(p, OMAP1510_DSP_BASE, OMAP1510_DSP_START);
  46. if (BETWEEN(p, OMAP1510_DSPREG_BASE, OMAP1510_DSPREG_SIZE))
  47. return XLATE(p, OMAP1510_DSPREG_BASE,
  48. OMAP1510_DSPREG_START);
  49. }
  50. if (cpu_is_omap16xx()) {
  51. if (BETWEEN(p, OMAP16XX_DSP_BASE, OMAP16XX_DSP_SIZE))
  52. return XLATE(p, OMAP16XX_DSP_BASE, OMAP16XX_DSP_START);
  53. if (BETWEEN(p, OMAP16XX_DSPREG_BASE, OMAP16XX_DSPREG_SIZE))
  54. return XLATE(p, OMAP16XX_DSPREG_BASE,
  55. OMAP16XX_DSPREG_START);
  56. }
  57. #endif
  58. #ifdef CONFIG_ARCH_OMAP2
  59. if (cpu_is_omap24xx()) {
  60. if (BETWEEN(p, L3_24XX_PHYS, L3_24XX_SIZE))
  61. return XLATE(p, L3_24XX_PHYS, L3_24XX_VIRT);
  62. if (BETWEEN(p, L4_24XX_PHYS, L4_24XX_SIZE))
  63. return XLATE(p, L4_24XX_PHYS, L4_24XX_VIRT);
  64. }
  65. if (cpu_is_omap2420()) {
  66. if (BETWEEN(p, DSP_MEM_2420_PHYS, DSP_MEM_2420_SIZE))
  67. return XLATE(p, DSP_MEM_2420_PHYS, DSP_MEM_2420_VIRT);
  68. if (BETWEEN(p, DSP_IPI_2420_PHYS, DSP_IPI_2420_SIZE))
  69. return XLATE(p, DSP_IPI_2420_PHYS, DSP_IPI_2420_SIZE);
  70. if (BETWEEN(p, DSP_MMU_2420_PHYS, DSP_MMU_2420_SIZE))
  71. return XLATE(p, DSP_MMU_2420_PHYS, DSP_MMU_2420_VIRT);
  72. }
  73. if (cpu_is_omap2430()) {
  74. if (BETWEEN(p, L4_WK_243X_PHYS, L4_WK_243X_SIZE))
  75. return XLATE(p, L4_WK_243X_PHYS, L4_WK_243X_VIRT);
  76. if (BETWEEN(p, OMAP243X_GPMC_PHYS, OMAP243X_GPMC_SIZE))
  77. return XLATE(p, OMAP243X_GPMC_PHYS, OMAP243X_GPMC_VIRT);
  78. if (BETWEEN(p, OMAP243X_SDRC_PHYS, OMAP243X_SDRC_SIZE))
  79. return XLATE(p, OMAP243X_SDRC_PHYS, OMAP243X_SDRC_VIRT);
  80. if (BETWEEN(p, OMAP243X_SMS_PHYS, OMAP243X_SMS_SIZE))
  81. return XLATE(p, OMAP243X_SMS_PHYS, OMAP243X_SMS_VIRT);
  82. }
  83. #endif
  84. #ifdef CONFIG_ARCH_OMAP3
  85. if (cpu_is_ti816x()) {
  86. if (BETWEEN(p, L4_34XX_PHYS, L4_34XX_SIZE))
  87. return XLATE(p, L4_34XX_PHYS, L4_34XX_VIRT);
  88. } else if (cpu_is_omap34xx()) {
  89. if (BETWEEN(p, L3_34XX_PHYS, L3_34XX_SIZE))
  90. return XLATE(p, L3_34XX_PHYS, L3_34XX_VIRT);
  91. if (BETWEEN(p, L4_34XX_PHYS, L4_34XX_SIZE))
  92. return XLATE(p, L4_34XX_PHYS, L4_34XX_VIRT);
  93. if (BETWEEN(p, OMAP34XX_GPMC_PHYS, OMAP34XX_GPMC_SIZE))
  94. return XLATE(p, OMAP34XX_GPMC_PHYS, OMAP34XX_GPMC_VIRT);
  95. if (BETWEEN(p, OMAP343X_SMS_PHYS, OMAP343X_SMS_SIZE))
  96. return XLATE(p, OMAP343X_SMS_PHYS, OMAP343X_SMS_VIRT);
  97. if (BETWEEN(p, OMAP343X_SDRC_PHYS, OMAP343X_SDRC_SIZE))
  98. return XLATE(p, OMAP343X_SDRC_PHYS, OMAP343X_SDRC_VIRT);
  99. if (BETWEEN(p, L4_PER_34XX_PHYS, L4_PER_34XX_SIZE))
  100. return XLATE(p, L4_PER_34XX_PHYS, L4_PER_34XX_VIRT);
  101. if (BETWEEN(p, L4_EMU_34XX_PHYS, L4_EMU_34XX_SIZE))
  102. return XLATE(p, L4_EMU_34XX_PHYS, L4_EMU_34XX_VIRT);
  103. }
  104. #endif
  105. #ifdef CONFIG_ARCH_OMAP4
  106. if (cpu_is_omap44xx()) {
  107. if (BETWEEN(p, L3_44XX_PHYS, L3_44XX_SIZE))
  108. return XLATE(p, L3_44XX_PHYS, L3_44XX_VIRT);
  109. if (BETWEEN(p, L4_44XX_PHYS, L4_44XX_SIZE))
  110. return XLATE(p, L4_44XX_PHYS, L4_44XX_VIRT);
  111. if (BETWEEN(p, OMAP44XX_GPMC_PHYS, OMAP44XX_GPMC_SIZE))
  112. return XLATE(p, OMAP44XX_GPMC_PHYS, OMAP44XX_GPMC_VIRT);
  113. if (BETWEEN(p, OMAP44XX_EMIF1_PHYS, OMAP44XX_EMIF1_SIZE))
  114. return XLATE(p, OMAP44XX_EMIF1_PHYS, \
  115. OMAP44XX_EMIF1_VIRT);
  116. if (BETWEEN(p, OMAP44XX_EMIF2_PHYS, OMAP44XX_EMIF2_SIZE))
  117. return XLATE(p, OMAP44XX_EMIF2_PHYS, \
  118. OMAP44XX_EMIF2_VIRT);
  119. if (BETWEEN(p, OMAP44XX_DMM_PHYS, OMAP44XX_DMM_SIZE))
  120. return XLATE(p, OMAP44XX_DMM_PHYS, OMAP44XX_DMM_VIRT);
  121. if (BETWEEN(p, L4_PER_44XX_PHYS, L4_PER_44XX_SIZE))
  122. return XLATE(p, L4_PER_44XX_PHYS, L4_PER_44XX_VIRT);
  123. if (BETWEEN(p, L4_EMU_44XX_PHYS, L4_EMU_44XX_SIZE))
  124. return XLATE(p, L4_EMU_44XX_PHYS, L4_EMU_44XX_VIRT);
  125. }
  126. #endif
  127. return __arm_ioremap_caller(p, size, type, __builtin_return_address(0));
  128. }
  129. EXPORT_SYMBOL(omap_ioremap);
  130. void omap_iounmap(volatile void __iomem *addr)
  131. {
  132. unsigned long virt = (unsigned long)addr;
  133. if (virt >= VMALLOC_START && virt < VMALLOC_END)
  134. __iounmap(addr);
  135. }
  136. EXPORT_SYMBOL(omap_iounmap);
  137. void __init omap_init_consistent_dma_size(void)
  138. {
  139. #ifdef CONFIG_FB_OMAP_CONSISTENT_DMA_SIZE
  140. init_consistent_dma_size(CONFIG_FB_OMAP_CONSISTENT_DMA_SIZE << 20);
  141. #endif
  142. }
  143. void __init omap_ioremap_init(void)
  144. {
  145. initialized++;
  146. }