nommu.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. cpuid_feature_extract(CPUID_EXT_PFR1, 20);
  51. return 0;
  52. }
  53. unsigned long setup_vectors_base(void)
  54. {
  55. unsigned long base = 0, reg = get_cr();
  56. set_cr(reg & ~CR_V);
  57. if (security_extensions_enabled()) {
  58. if (IS_ENABLED(CONFIG_REMAP_VECTORS_TO_RAM))
  59. base = CONFIG_DRAM_BASE;
  60. set_vbar(base);
  61. } else if (IS_ENABLED(CONFIG_REMAP_VECTORS_TO_RAM)) {
  62. if (CONFIG_DRAM_BASE != 0)
  63. pr_err("Security extensions not enabled, vectors cannot be remapped to RAM, vectors base will be 0x00000000\n");
  64. }
  65. return base;
  66. }
  67. #endif /* CONFIG_CPU_HIGH_VECTOR */
  68. #endif /* CONFIG_CPU_CP15 */
  69. void __init arm_mm_memblock_reserve(void)
  70. {
  71. #ifndef CONFIG_CPU_V7M
  72. vectors_base = IS_ENABLED(CONFIG_CPU_CP15) ? setup_vectors_base() : 0;
  73. /*
  74. * Register the exception vector page.
  75. * some architectures which the DRAM is the exception vector to trap,
  76. * alloc_page breaks with error, although it is not NULL, but "0."
  77. */
  78. memblock_reserve(vectors_base, 2 * PAGE_SIZE);
  79. #else /* ifndef CONFIG_CPU_V7M */
  80. /*
  81. * There is no dedicated vector page on V7-M. So nothing needs to be
  82. * reserved here.
  83. */
  84. #endif
  85. /*
  86. * In any case, always ensure address 0 is never used as many things
  87. * get very confused if 0 is returned as a legitimate address.
  88. */
  89. memblock_reserve(0, 1);
  90. }
  91. static void __init adjust_lowmem_bounds_mpu(void)
  92. {
  93. unsigned long pmsa = read_cpuid_ext(CPUID_EXT_MMFR0) & MMFR0_PMSA;
  94. switch (pmsa) {
  95. case MMFR0_PMSAv7:
  96. pmsav7_adjust_lowmem_bounds();
  97. break;
  98. case MMFR0_PMSAv8:
  99. pmsav8_adjust_lowmem_bounds();
  100. break;
  101. default:
  102. break;
  103. }
  104. }
  105. static void __init mpu_setup(void)
  106. {
  107. unsigned long pmsa = read_cpuid_ext(CPUID_EXT_MMFR0) & MMFR0_PMSA;
  108. switch (pmsa) {
  109. case MMFR0_PMSAv7:
  110. pmsav7_setup();
  111. break;
  112. case MMFR0_PMSAv8:
  113. pmsav8_setup();
  114. break;
  115. default:
  116. break;
  117. }
  118. }
  119. void __init adjust_lowmem_bounds(void)
  120. {
  121. phys_addr_t end;
  122. adjust_lowmem_bounds_mpu();
  123. end = memblock_end_of_DRAM();
  124. high_memory = __va(end - 1) + 1;
  125. memblock_set_current_limit(end);
  126. }
  127. /*
  128. * paging_init() sets up the page tables, initialises the zone memory
  129. * maps, and sets up the zero page, bad page and bad page tables.
  130. */
  131. void __init paging_init(const struct machine_desc *mdesc)
  132. {
  133. early_trap_init((void *)vectors_base);
  134. mpu_setup();
  135. bootmem_init();
  136. }
  137. /*
  138. * We don't need to do anything here for nommu machines.
  139. */
  140. void setup_mm_for_reboot(void)
  141. {
  142. }
  143. void flush_dcache_page(struct page *page)
  144. {
  145. __cpuc_flush_dcache_area(page_address(page), PAGE_SIZE);
  146. }
  147. EXPORT_SYMBOL(flush_dcache_page);
  148. void flush_kernel_dcache_page(struct page *page)
  149. {
  150. __cpuc_flush_dcache_area(page_address(page), PAGE_SIZE);
  151. }
  152. EXPORT_SYMBOL(flush_kernel_dcache_page);
  153. void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
  154. unsigned long uaddr, void *dst, const void *src,
  155. unsigned long len)
  156. {
  157. memcpy(dst, src, len);
  158. if (vma->vm_flags & VM_EXEC)
  159. __cpuc_coherent_user_range(uaddr, uaddr + len);
  160. }
  161. void __iomem *__arm_ioremap_pfn(unsigned long pfn, unsigned long offset,
  162. size_t size, unsigned int mtype)
  163. {
  164. if (pfn >= (0x100000000ULL >> PAGE_SHIFT))
  165. return NULL;
  166. return (void __iomem *) (offset + (pfn << PAGE_SHIFT));
  167. }
  168. EXPORT_SYMBOL(__arm_ioremap_pfn);
  169. void __iomem *__arm_ioremap_caller(phys_addr_t phys_addr, size_t size,
  170. unsigned int mtype, void *caller)
  171. {
  172. return (void __iomem *)phys_addr;
  173. }
  174. void __iomem * (*arch_ioremap_caller)(phys_addr_t, size_t, unsigned int, void *);
  175. void __iomem *ioremap(resource_size_t res_cookie, size_t size)
  176. {
  177. return __arm_ioremap_caller(res_cookie, size, MT_DEVICE,
  178. __builtin_return_address(0));
  179. }
  180. EXPORT_SYMBOL(ioremap);
  181. void __iomem *ioremap_cache(resource_size_t res_cookie, size_t size)
  182. __alias(ioremap_cached);
  183. void __iomem *ioremap_cached(resource_size_t res_cookie, size_t size)
  184. {
  185. return __arm_ioremap_caller(res_cookie, size, MT_DEVICE_CACHED,
  186. __builtin_return_address(0));
  187. }
  188. EXPORT_SYMBOL(ioremap_cache);
  189. EXPORT_SYMBOL(ioremap_cached);
  190. void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size)
  191. {
  192. return __arm_ioremap_caller(res_cookie, size, MT_DEVICE_WC,
  193. __builtin_return_address(0));
  194. }
  195. EXPORT_SYMBOL(ioremap_wc);
  196. #ifdef CONFIG_PCI
  197. #include <asm/mach/map.h>
  198. void __iomem *pci_remap_cfgspace(resource_size_t res_cookie, size_t size)
  199. {
  200. return arch_ioremap_caller(res_cookie, size, MT_UNCACHED,
  201. __builtin_return_address(0));
  202. }
  203. EXPORT_SYMBOL_GPL(pci_remap_cfgspace);
  204. #endif
  205. void *arch_memremap_wb(phys_addr_t phys_addr, size_t size)
  206. {
  207. return (void *)phys_addr;
  208. }
  209. void __iounmap(volatile void __iomem *addr)
  210. {
  211. }
  212. EXPORT_SYMBOL(__iounmap);
  213. void (*arch_iounmap)(volatile void __iomem *);
  214. void iounmap(volatile void __iomem *addr)
  215. {
  216. }
  217. EXPORT_SYMBOL(iounmap);