nommu.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * linux/arch/arm/mm/nommu.c
  3. *
  4. * ARM uCLinux supporting functions.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/mm.h>
  8. #include <linux/pagemap.h>
  9. #include <linux/io.h>
  10. #include <linux/memblock.h>
  11. #include <linux/kernel.h>
  12. #include <asm/cacheflush.h>
  13. #include <asm/cp15.h>
  14. #include <asm/sections.h>
  15. #include <asm/page.h>
  16. #include <asm/setup.h>
  17. #include <asm/traps.h>
  18. #include <asm/mach/arch.h>
  19. #include <asm/cputype.h>
  20. #include <asm/mpu.h>
  21. #include <asm/procinfo.h>
  22. #include "mm.h"
  23. unsigned long vectors_base;
  24. #ifdef CONFIG_ARM_MPU
  25. struct mpu_rgn_info mpu_rgn_info;
  26. #endif
  27. #ifdef CONFIG_CPU_CP15
  28. #ifdef CONFIG_CPU_HIGH_VECTOR
  29. unsigned long setup_vectors_base(void)
  30. {
  31. unsigned long reg = get_cr();
  32. set_cr(reg | CR_V);
  33. return 0xffff0000;
  34. }
  35. #else /* CONFIG_CPU_HIGH_VECTOR */
  36. /* Write exception base address to VBAR */
  37. static inline void set_vbar(unsigned long val)
  38. {
  39. asm("mcr p15, 0, %0, c12, c0, 0" : : "r" (val) : "cc");
  40. }
  41. /*
  42. * Security extensions, bits[7:4], permitted values,
  43. * 0b0000 - not implemented, 0b0001/0b0010 - implemented
  44. */
  45. static inline bool security_extensions_enabled(void)
  46. {
  47. /* Check CPUID Identification Scheme before ID_PFR1 read */
  48. if ((read_cpuid_id() & 0x000f0000) == 0x000f0000)
  49. return !!cpuid_feature_extract(CPUID_EXT_PFR1, 4);
  50. return 0;
  51. }
  52. unsigned long setup_vectors_base(void)
  53. {
  54. unsigned long base = 0, reg = get_cr();
  55. set_cr(reg & ~CR_V);
  56. if (security_extensions_enabled()) {
  57. if (IS_ENABLED(CONFIG_REMAP_VECTORS_TO_RAM))
  58. base = CONFIG_DRAM_BASE;
  59. set_vbar(base);
  60. } else if (IS_ENABLED(CONFIG_REMAP_VECTORS_TO_RAM)) {
  61. if (CONFIG_DRAM_BASE != 0)
  62. pr_err("Security extensions not enabled, vectors cannot be remapped to RAM, vectors base will be 0x00000000\n");
  63. }
  64. return base;
  65. }
  66. #endif /* CONFIG_CPU_HIGH_VECTOR */
  67. #endif /* CONFIG_CPU_CP15 */
  68. void __init arm_mm_memblock_reserve(void)
  69. {
  70. #ifndef CONFIG_CPU_V7M
  71. vectors_base = IS_ENABLED(CONFIG_CPU_CP15) ? setup_vectors_base() : 0;
  72. /*
  73. * Register the exception vector page.
  74. * some architectures which the DRAM is the exception vector to trap,
  75. * alloc_page breaks with error, although it is not NULL, but "0."
  76. */
  77. memblock_reserve(vectors_base, 2 * PAGE_SIZE);
  78. #else /* ifndef CONFIG_CPU_V7M */
  79. /*
  80. * There is no dedicated vector page on V7-M. So nothing needs to be
  81. * reserved here.
  82. */
  83. #endif
  84. /*
  85. * In any case, always ensure address 0 is never used as many things
  86. * get very confused if 0 is returned as a legitimate address.
  87. */
  88. memblock_reserve(0, 1);
  89. }
  90. void __init adjust_lowmem_bounds(void)
  91. {
  92. phys_addr_t end;
  93. adjust_lowmem_bounds_mpu();
  94. end = memblock_end_of_DRAM();
  95. high_memory = __va(end - 1) + 1;
  96. memblock_set_current_limit(end);
  97. }
  98. /*
  99. * paging_init() sets up the page tables, initialises the zone memory
  100. * maps, and sets up the zero page, bad page and bad page tables.
  101. */
  102. void __init paging_init(const struct machine_desc *mdesc)
  103. {
  104. early_trap_init((void *)vectors_base);
  105. mpu_setup();
  106. bootmem_init();
  107. }
  108. /*
  109. * We don't need to do anything here for nommu machines.
  110. */
  111. void setup_mm_for_reboot(void)
  112. {
  113. }
  114. void flush_dcache_page(struct page *page)
  115. {
  116. __cpuc_flush_dcache_area(page_address(page), PAGE_SIZE);
  117. }
  118. EXPORT_SYMBOL(flush_dcache_page);
  119. void flush_kernel_dcache_page(struct page *page)
  120. {
  121. __cpuc_flush_dcache_area(page_address(page), PAGE_SIZE);
  122. }
  123. EXPORT_SYMBOL(flush_kernel_dcache_page);
  124. void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
  125. unsigned long uaddr, void *dst, const void *src,
  126. unsigned long len)
  127. {
  128. memcpy(dst, src, len);
  129. if (vma->vm_flags & VM_EXEC)
  130. __cpuc_coherent_user_range(uaddr, uaddr + len);
  131. }
  132. void __iomem *__arm_ioremap_pfn(unsigned long pfn, unsigned long offset,
  133. size_t size, unsigned int mtype)
  134. {
  135. if (pfn >= (0x100000000ULL >> PAGE_SHIFT))
  136. return NULL;
  137. return (void __iomem *) (offset + (pfn << PAGE_SHIFT));
  138. }
  139. EXPORT_SYMBOL(__arm_ioremap_pfn);
  140. void __iomem *__arm_ioremap_caller(phys_addr_t phys_addr, size_t size,
  141. unsigned int mtype, void *caller)
  142. {
  143. return (void __iomem *)phys_addr;
  144. }
  145. void __iomem * (*arch_ioremap_caller)(phys_addr_t, size_t, unsigned int, void *);
  146. void __iomem *ioremap(resource_size_t res_cookie, size_t size)
  147. {
  148. return __arm_ioremap_caller(res_cookie, size, MT_DEVICE,
  149. __builtin_return_address(0));
  150. }
  151. EXPORT_SYMBOL(ioremap);
  152. void __iomem *ioremap_cache(resource_size_t res_cookie, size_t size)
  153. __alias(ioremap_cached);
  154. void __iomem *ioremap_cached(resource_size_t res_cookie, size_t size)
  155. {
  156. return __arm_ioremap_caller(res_cookie, size, MT_DEVICE_CACHED,
  157. __builtin_return_address(0));
  158. }
  159. EXPORT_SYMBOL(ioremap_cache);
  160. EXPORT_SYMBOL(ioremap_cached);
  161. void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size)
  162. {
  163. return __arm_ioremap_caller(res_cookie, size, MT_DEVICE_WC,
  164. __builtin_return_address(0));
  165. }
  166. EXPORT_SYMBOL(ioremap_wc);
  167. #ifdef CONFIG_PCI
  168. #include <asm/mach/map.h>
  169. void __iomem *pci_remap_cfgspace(resource_size_t res_cookie, size_t size)
  170. {
  171. return arch_ioremap_caller(res_cookie, size, MT_UNCACHED,
  172. __builtin_return_address(0));
  173. }
  174. EXPORT_SYMBOL_GPL(pci_remap_cfgspace);
  175. #endif
  176. void *arch_memremap_wb(phys_addr_t phys_addr, size_t size)
  177. {
  178. return (void *)phys_addr;
  179. }
  180. void __iounmap(volatile void __iomem *addr)
  181. {
  182. }
  183. EXPORT_SYMBOL(__iounmap);
  184. void (*arch_iounmap)(volatile void __iomem *);
  185. void iounmap(volatile void __iomem *addr)
  186. {
  187. }
  188. EXPORT_SYMBOL(iounmap);