nommu.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. static void __init adjust_lowmem_bounds_mpu(void)
  91. {
  92. unsigned long pmsa = read_cpuid_ext(CPUID_EXT_MMFR0) & MMFR0_PMSA;
  93. switch (pmsa) {
  94. case MMFR0_PMSAv7:
  95. pmsav7_adjust_lowmem_bounds();
  96. break;
  97. case MMFR0_PMSAv8:
  98. pmsav8_adjust_lowmem_bounds();
  99. break;
  100. default:
  101. break;
  102. }
  103. }
  104. static void __init mpu_setup(void)
  105. {
  106. unsigned long pmsa = read_cpuid_ext(CPUID_EXT_MMFR0) & MMFR0_PMSA;
  107. switch (pmsa) {
  108. case MMFR0_PMSAv7:
  109. pmsav7_setup();
  110. break;
  111. case MMFR0_PMSAv8:
  112. pmsav8_setup();
  113. break;
  114. default:
  115. break;
  116. }
  117. }
  118. void __init adjust_lowmem_bounds(void)
  119. {
  120. phys_addr_t end;
  121. adjust_lowmem_bounds_mpu();
  122. end = memblock_end_of_DRAM();
  123. high_memory = __va(end - 1) + 1;
  124. memblock_set_current_limit(end);
  125. }
  126. /*
  127. * paging_init() sets up the page tables, initialises the zone memory
  128. * maps, and sets up the zero page, bad page and bad page tables.
  129. */
  130. void __init paging_init(const struct machine_desc *mdesc)
  131. {
  132. early_trap_init((void *)vectors_base);
  133. mpu_setup();
  134. bootmem_init();
  135. }
  136. /*
  137. * We don't need to do anything here for nommu machines.
  138. */
  139. void setup_mm_for_reboot(void)
  140. {
  141. }
  142. void flush_dcache_page(struct page *page)
  143. {
  144. __cpuc_flush_dcache_area(page_address(page), PAGE_SIZE);
  145. }
  146. EXPORT_SYMBOL(flush_dcache_page);
  147. void flush_kernel_dcache_page(struct page *page)
  148. {
  149. __cpuc_flush_dcache_area(page_address(page), PAGE_SIZE);
  150. }
  151. EXPORT_SYMBOL(flush_kernel_dcache_page);
  152. void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
  153. unsigned long uaddr, void *dst, const void *src,
  154. unsigned long len)
  155. {
  156. memcpy(dst, src, len);
  157. if (vma->vm_flags & VM_EXEC)
  158. __cpuc_coherent_user_range(uaddr, uaddr + len);
  159. }
  160. void __iomem *__arm_ioremap_pfn(unsigned long pfn, unsigned long offset,
  161. size_t size, unsigned int mtype)
  162. {
  163. if (pfn >= (0x100000000ULL >> PAGE_SHIFT))
  164. return NULL;
  165. return (void __iomem *) (offset + (pfn << PAGE_SHIFT));
  166. }
  167. EXPORT_SYMBOL(__arm_ioremap_pfn);
  168. void __iomem *__arm_ioremap_caller(phys_addr_t phys_addr, size_t size,
  169. unsigned int mtype, void *caller)
  170. {
  171. return (void __iomem *)phys_addr;
  172. }
  173. void __iomem * (*arch_ioremap_caller)(phys_addr_t, size_t, unsigned int, void *);
  174. void __iomem *ioremap(resource_size_t res_cookie, size_t size)
  175. {
  176. return __arm_ioremap_caller(res_cookie, size, MT_DEVICE,
  177. __builtin_return_address(0));
  178. }
  179. EXPORT_SYMBOL(ioremap);
  180. void __iomem *ioremap_cache(resource_size_t res_cookie, size_t size)
  181. __alias(ioremap_cached);
  182. void __iomem *ioremap_cached(resource_size_t res_cookie, size_t size)
  183. {
  184. return __arm_ioremap_caller(res_cookie, size, MT_DEVICE_CACHED,
  185. __builtin_return_address(0));
  186. }
  187. EXPORT_SYMBOL(ioremap_cache);
  188. EXPORT_SYMBOL(ioremap_cached);
  189. void __iomem *ioremap_wc(resource_size_t res_cookie, size_t size)
  190. {
  191. return __arm_ioremap_caller(res_cookie, size, MT_DEVICE_WC,
  192. __builtin_return_address(0));
  193. }
  194. EXPORT_SYMBOL(ioremap_wc);
  195. #ifdef CONFIG_PCI
  196. #include <asm/mach/map.h>
  197. void __iomem *pci_remap_cfgspace(resource_size_t res_cookie, size_t size)
  198. {
  199. return arch_ioremap_caller(res_cookie, size, MT_UNCACHED,
  200. __builtin_return_address(0));
  201. }
  202. EXPORT_SYMBOL_GPL(pci_remap_cfgspace);
  203. #endif
  204. void *arch_memremap_wb(phys_addr_t phys_addr, size_t size)
  205. {
  206. return (void *)phys_addr;
  207. }
  208. void __iounmap(volatile void __iomem *addr)
  209. {
  210. }
  211. EXPORT_SYMBOL(__iounmap);
  212. void (*arch_iounmap)(volatile void __iomem *);
  213. void iounmap(volatile void __iomem *addr)
  214. {
  215. }
  216. EXPORT_SYMBOL(iounmap);