mmu.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  1. /*
  2. * linux/arch/arm/mm/mmu.c
  3. *
  4. * Copyright (C) 1995-2005 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/init.h>
  14. #include <linux/mman.h>
  15. #include <linux/nodemask.h>
  16. #include <linux/memblock.h>
  17. #include <linux/fs.h>
  18. #include <linux/vmalloc.h>
  19. #include <asm/cp15.h>
  20. #include <asm/cputype.h>
  21. #include <asm/sections.h>
  22. #include <asm/cachetype.h>
  23. #include <asm/setup.h>
  24. #include <asm/sizes.h>
  25. #include <asm/smp_plat.h>
  26. #include <asm/tlb.h>
  27. #include <asm/highmem.h>
  28. #include <asm/system_info.h>
  29. #include <asm/traps.h>
  30. #include <asm/mmu_writeable.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/map.h>
  33. #include <asm/user_accessible_timer.h>
  34. #include "mm.h"
  35. /*
  36. * empty_zero_page is a special page that is used for
  37. * zero-initialized data and COW.
  38. */
  39. struct page *empty_zero_page;
  40. EXPORT_SYMBOL(empty_zero_page);
  41. /*
  42. * The pmd table for the upper-most set of pages.
  43. */
  44. pmd_t *top_pmd;
  45. pmdval_t user_pmd_table = _PAGE_USER_TABLE;
  46. #define CPOLICY_UNCACHED 0
  47. #define CPOLICY_BUFFERED 1
  48. #define CPOLICY_WRITETHROUGH 2
  49. #define CPOLICY_WRITEBACK 3
  50. #define CPOLICY_WRITEALLOC 4
  51. #define RX_AREA_START _text
  52. #define RX_AREA_END __start_rodata
  53. static unsigned int cachepolicy __initdata = CPOLICY_WRITEBACK;
  54. static unsigned int ecc_mask __initdata = 0;
  55. pgprot_t pgprot_user;
  56. pgprot_t pgprot_kernel;
  57. EXPORT_SYMBOL(pgprot_user);
  58. EXPORT_SYMBOL(pgprot_kernel);
  59. struct cachepolicy {
  60. const char policy[16];
  61. unsigned int cr_mask;
  62. pmdval_t pmd;
  63. pteval_t pte;
  64. };
  65. static struct cachepolicy cache_policies[] __initdata = {
  66. {
  67. .policy = "uncached",
  68. .cr_mask = CR_W|CR_C,
  69. .pmd = PMD_SECT_UNCACHED,
  70. .pte = L_PTE_MT_UNCACHED,
  71. }, {
  72. .policy = "buffered",
  73. .cr_mask = CR_C,
  74. .pmd = PMD_SECT_BUFFERED,
  75. .pte = L_PTE_MT_BUFFERABLE,
  76. }, {
  77. .policy = "writethrough",
  78. .cr_mask = 0,
  79. .pmd = PMD_SECT_WT,
  80. .pte = L_PTE_MT_WRITETHROUGH,
  81. }, {
  82. .policy = "writeback",
  83. .cr_mask = 0,
  84. .pmd = PMD_SECT_WB,
  85. .pte = L_PTE_MT_WRITEBACK,
  86. }, {
  87. .policy = "writealloc",
  88. .cr_mask = 0,
  89. .pmd = PMD_SECT_WBWA,
  90. .pte = L_PTE_MT_WRITEALLOC,
  91. }
  92. };
  93. /*
  94. * These are useful for identifying cache coherency
  95. * problems by allowing the cache or the cache and
  96. * writebuffer to be turned off. (Note: the write
  97. * buffer should not be on and the cache off).
  98. */
  99. static int __init early_cachepolicy(char *p)
  100. {
  101. int i;
  102. for (i = 0; i < ARRAY_SIZE(cache_policies); i++) {
  103. int len = strlen(cache_policies[i].policy);
  104. if (memcmp(p, cache_policies[i].policy, len) == 0) {
  105. cachepolicy = i;
  106. cr_alignment &= ~cache_policies[i].cr_mask;
  107. cr_no_alignment &= ~cache_policies[i].cr_mask;
  108. break;
  109. }
  110. }
  111. if (i == ARRAY_SIZE(cache_policies))
  112. printk(KERN_ERR "ERROR: unknown or unsupported cache policy\n");
  113. /*
  114. * This restriction is partly to do with the way we boot; it is
  115. * unpredictable to have memory mapped using two different sets of
  116. * memory attributes (shared, type, and cache attribs). We can not
  117. * change these attributes once the initial assembly has setup the
  118. * page tables.
  119. */
  120. if (cpu_architecture() >= CPU_ARCH_ARMv6) {
  121. printk(KERN_WARNING "Only cachepolicy=writeback supported on ARMv6 and later\n");
  122. cachepolicy = CPOLICY_WRITEBACK;
  123. }
  124. flush_cache_all();
  125. set_cr(cr_alignment);
  126. return 0;
  127. }
  128. early_param("cachepolicy", early_cachepolicy);
  129. static int __init early_nocache(char *__unused)
  130. {
  131. char *p = "buffered";
  132. printk(KERN_WARNING "nocache is deprecated; use cachepolicy=%s\n", p);
  133. early_cachepolicy(p);
  134. return 0;
  135. }
  136. early_param("nocache", early_nocache);
  137. static int __init early_nowrite(char *__unused)
  138. {
  139. char *p = "uncached";
  140. printk(KERN_WARNING "nowb is deprecated; use cachepolicy=%s\n", p);
  141. early_cachepolicy(p);
  142. return 0;
  143. }
  144. early_param("nowb", early_nowrite);
  145. #ifndef CONFIG_ARM_LPAE
  146. static int __init early_ecc(char *p)
  147. {
  148. if (memcmp(p, "on", 2) == 0)
  149. ecc_mask = PMD_PROTECTION;
  150. else if (memcmp(p, "off", 3) == 0)
  151. ecc_mask = 0;
  152. return 0;
  153. }
  154. early_param("ecc", early_ecc);
  155. #endif
  156. static int __init noalign_setup(char *__unused)
  157. {
  158. cr_alignment &= ~CR_A;
  159. cr_no_alignment &= ~CR_A;
  160. set_cr(cr_alignment);
  161. return 1;
  162. }
  163. __setup("noalign", noalign_setup);
  164. #ifndef CONFIG_SMP
  165. void adjust_cr(unsigned long mask, unsigned long set)
  166. {
  167. unsigned long flags;
  168. mask &= ~CR_A;
  169. set &= mask;
  170. local_irq_save(flags);
  171. cr_no_alignment = (cr_no_alignment & ~mask) | set;
  172. cr_alignment = (cr_alignment & ~mask) | set;
  173. set_cr((get_cr() & ~mask) | set);
  174. local_irq_restore(flags);
  175. }
  176. #endif
  177. #define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
  178. #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
  179. static struct mem_type mem_types[] = {
  180. [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
  181. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
  182. L_PTE_SHARED,
  183. .prot_l1 = PMD_TYPE_TABLE,
  184. .prot_sect = PROT_SECT_DEVICE | PMD_SECT_S,
  185. .domain = DOMAIN_IO,
  186. },
  187. [MT_DEVICE_NONSHARED] = { /* ARMv6 non-shared device */
  188. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_NONSHARED,
  189. .prot_l1 = PMD_TYPE_TABLE,
  190. .prot_sect = PROT_SECT_DEVICE,
  191. .domain = DOMAIN_IO,
  192. },
  193. [MT_DEVICE_CACHED] = { /* ioremap_cached */
  194. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_CACHED,
  195. .prot_l1 = PMD_TYPE_TABLE,
  196. .prot_sect = PROT_SECT_DEVICE | PMD_SECT_WB,
  197. .domain = DOMAIN_IO,
  198. },
  199. [MT_DEVICE_WC] = { /* ioremap_wc */
  200. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_WC,
  201. .prot_l1 = PMD_TYPE_TABLE,
  202. .prot_sect = PROT_SECT_DEVICE,
  203. .domain = DOMAIN_IO,
  204. },
  205. [MT_UNCACHED] = {
  206. .prot_pte = PROT_PTE_DEVICE,
  207. .prot_l1 = PMD_TYPE_TABLE,
  208. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  209. .domain = DOMAIN_IO,
  210. },
  211. [MT_CACHECLEAN] = {
  212. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  213. .domain = DOMAIN_KERNEL,
  214. },
  215. #ifndef CONFIG_ARM_LPAE
  216. [MT_MINICLEAN] = {
  217. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
  218. .domain = DOMAIN_KERNEL,
  219. },
  220. #endif
  221. [MT_LOW_VECTORS] = {
  222. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  223. L_PTE_RDONLY,
  224. .prot_l1 = PMD_TYPE_TABLE,
  225. .domain = DOMAIN_USER,
  226. },
  227. [MT_HIGH_VECTORS] = {
  228. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  229. L_PTE_USER | L_PTE_RDONLY,
  230. .prot_l1 = PMD_TYPE_TABLE,
  231. .domain = DOMAIN_USER,
  232. },
  233. [MT_MEMORY] = {
  234. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
  235. .prot_l1 = PMD_TYPE_TABLE,
  236. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  237. .domain = DOMAIN_KERNEL,
  238. },
  239. [MT_MEMORY_R] = {
  240. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  241. .domain = DOMAIN_KERNEL,
  242. },
  243. [MT_MEMORY_RW] = {
  244. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
  245. .domain = DOMAIN_KERNEL,
  246. },
  247. [MT_MEMORY_RX] = {
  248. .prot_sect = PMD_TYPE_SECT,
  249. .domain = DOMAIN_KERNEL,
  250. },
  251. [MT_ROM] = {
  252. .prot_sect = PMD_TYPE_SECT,
  253. .domain = DOMAIN_KERNEL,
  254. },
  255. [MT_MEMORY_NONCACHED] = {
  256. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  257. L_PTE_MT_BUFFERABLE,
  258. .prot_l1 = PMD_TYPE_TABLE,
  259. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  260. .domain = DOMAIN_KERNEL,
  261. },
  262. [MT_MEMORY_DTCM] = {
  263. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  264. L_PTE_XN,
  265. .prot_l1 = PMD_TYPE_TABLE,
  266. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  267. .domain = DOMAIN_KERNEL,
  268. },
  269. [MT_MEMORY_ITCM] = {
  270. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
  271. .prot_l1 = PMD_TYPE_TABLE,
  272. .domain = DOMAIN_KERNEL,
  273. },
  274. [MT_MEMORY_SO] = {
  275. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  276. L_PTE_MT_UNCACHED,
  277. .prot_l1 = PMD_TYPE_TABLE,
  278. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
  279. PMD_SECT_UNCACHED | PMD_SECT_XN,
  280. .domain = DOMAIN_KERNEL,
  281. },
  282. [MT_MEMORY_DMA_READY] = {
  283. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  284. L_PTE_XN,
  285. .prot_l1 = PMD_TYPE_TABLE,
  286. .domain = DOMAIN_KERNEL,
  287. },
  288. [MT_DEVICE_USER_ACCESSIBLE] = {
  289. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
  290. L_PTE_SHARED | L_PTE_USER | L_PTE_RDONLY,
  291. .prot_l1 = PMD_TYPE_TABLE,
  292. .prot_sect = PROT_SECT_DEVICE | PMD_SECT_S,
  293. .domain = DOMAIN_IO,
  294. },
  295. };
  296. const struct mem_type *get_mem_type(unsigned int type)
  297. {
  298. return type < ARRAY_SIZE(mem_types) ? &mem_types[type] : NULL;
  299. }
  300. EXPORT_SYMBOL(get_mem_type);
  301. #define PTE_SET_FN(_name, pteop) \
  302. static int pte_set_##_name(pte_t *ptep, pgtable_t token, unsigned long addr, \
  303. void *data) \
  304. { \
  305. pte_t pte = pteop(*ptep); \
  306. \
  307. set_pte_ext(ptep, pte, 0); \
  308. return 0; \
  309. } \
  310. #define SET_MEMORY_FN(_name, callback) \
  311. int set_memory_##_name(unsigned long addr, int numpages) \
  312. { \
  313. unsigned long start = addr; \
  314. unsigned long size = PAGE_SIZE*numpages; \
  315. unsigned end = start + size; \
  316. \
  317. if (!IS_ENABLED(CONFIG_FORCE_PAGES)) { \
  318. if (start < MODULES_VADDR || start >= MODULES_END) \
  319. return -EINVAL;\
  320. \
  321. if (end < MODULES_VADDR || end >= MODULES_END) \
  322. return -EINVAL; \
  323. } \
  324. \
  325. apply_to_page_range(&init_mm, start, size, callback, NULL); \
  326. flush_tlb_kernel_range(start, end); \
  327. return 0;\
  328. }
  329. PTE_SET_FN(ro, pte_wrprotect)
  330. PTE_SET_FN(rw, pte_mkwrite)
  331. PTE_SET_FN(x, pte_mkexec)
  332. PTE_SET_FN(nx, pte_mknexec)
  333. SET_MEMORY_FN(ro, pte_set_ro)
  334. EXPORT_SYMBOL(set_memory_ro);
  335. SET_MEMORY_FN(rw, pte_set_rw)
  336. EXPORT_SYMBOL(set_memory_rw);
  337. SET_MEMORY_FN(x, pte_set_x)
  338. EXPORT_SYMBOL(set_memory_x);
  339. SET_MEMORY_FN(nx, pte_set_nx)
  340. EXPORT_SYMBOL(set_memory_nx);
  341. /*
  342. * Adjust the PMD section entries according to the CPU in use.
  343. */
  344. static void __init build_mem_type_table(void)
  345. {
  346. struct cachepolicy *cp;
  347. unsigned int cr = get_cr();
  348. pteval_t user_pgprot, kern_pgprot, vecs_pgprot;
  349. int cpu_arch = cpu_architecture();
  350. int i;
  351. if (cpu_arch < CPU_ARCH_ARMv6) {
  352. #if defined(CONFIG_CPU_DCACHE_DISABLE)
  353. if (cachepolicy > CPOLICY_BUFFERED)
  354. cachepolicy = CPOLICY_BUFFERED;
  355. #elif defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
  356. if (cachepolicy > CPOLICY_WRITETHROUGH)
  357. cachepolicy = CPOLICY_WRITETHROUGH;
  358. #endif
  359. }
  360. if (cpu_arch < CPU_ARCH_ARMv5) {
  361. if (cachepolicy >= CPOLICY_WRITEALLOC)
  362. cachepolicy = CPOLICY_WRITEBACK;
  363. ecc_mask = 0;
  364. }
  365. if (is_smp())
  366. cachepolicy = CPOLICY_WRITEALLOC;
  367. /*
  368. * Strip out features not present on earlier architectures.
  369. * Pre-ARMv5 CPUs don't have TEX bits. Pre-ARMv6 CPUs or those
  370. * without extended page tables don't have the 'Shared' bit.
  371. */
  372. if (cpu_arch < CPU_ARCH_ARMv5)
  373. for (i = 0; i < ARRAY_SIZE(mem_types); i++)
  374. mem_types[i].prot_sect &= ~PMD_SECT_TEX(7);
  375. if ((cpu_arch < CPU_ARCH_ARMv6 || !(cr & CR_XP)) && !cpu_is_xsc3())
  376. for (i = 0; i < ARRAY_SIZE(mem_types); i++)
  377. mem_types[i].prot_sect &= ~PMD_SECT_S;
  378. /*
  379. * ARMv5 and lower, bit 4 must be set for page tables (was: cache
  380. * "update-able on write" bit on ARM610). However, Xscale and
  381. * Xscale3 require this bit to be cleared.
  382. */
  383. if (cpu_is_xscale() || cpu_is_xsc3()) {
  384. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  385. mem_types[i].prot_sect &= ~PMD_BIT4;
  386. mem_types[i].prot_l1 &= ~PMD_BIT4;
  387. }
  388. } else if (cpu_arch < CPU_ARCH_ARMv6) {
  389. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  390. if (mem_types[i].prot_l1)
  391. mem_types[i].prot_l1 |= PMD_BIT4;
  392. if (mem_types[i].prot_sect)
  393. mem_types[i].prot_sect |= PMD_BIT4;
  394. }
  395. }
  396. /*
  397. * Mark the device areas according to the CPU/architecture.
  398. */
  399. if (cpu_is_xsc3() || (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP))) {
  400. if (!cpu_is_xsc3()) {
  401. /*
  402. * Mark device regions on ARMv6+ as execute-never
  403. * to prevent speculative instruction fetches.
  404. */
  405. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
  406. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
  407. mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
  408. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
  409. }
  410. if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
  411. /*
  412. * For ARMv7 with TEX remapping,
  413. * - shared device is SXCB=1100
  414. * - nonshared device is SXCB=0100
  415. * - write combine device mem is SXCB=0001
  416. * (Uncached Normal memory)
  417. */
  418. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_TEX(1);
  419. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_TEX(1);
  420. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_BUFFERABLE;
  421. } else if (cpu_is_xsc3()) {
  422. /*
  423. * For Xscale3,
  424. * - shared device is TEXCB=00101
  425. * - nonshared device is TEXCB=01000
  426. * - write combine device mem is TEXCB=00100
  427. * (Inner/Outer Uncacheable in xsc3 parlance)
  428. */
  429. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_TEX(1) | PMD_SECT_BUFFERED;
  430. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_TEX(2);
  431. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_TEX(1);
  432. } else {
  433. /*
  434. * For ARMv6 and ARMv7 without TEX remapping,
  435. * - shared device is TEXCB=00001
  436. * - nonshared device is TEXCB=01000
  437. * - write combine device mem is TEXCB=00100
  438. * (Uncached Normal in ARMv6 parlance).
  439. */
  440. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_BUFFERED;
  441. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_TEX(2);
  442. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_TEX(1);
  443. }
  444. } else {
  445. /*
  446. * On others, write combining is "Uncached/Buffered"
  447. */
  448. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_BUFFERABLE;
  449. }
  450. /*
  451. * Now deal with the memory-type mappings
  452. */
  453. cp = &cache_policies[cachepolicy];
  454. vecs_pgprot = kern_pgprot = user_pgprot = cp->pte;
  455. /*
  456. * Only use write-through for non-SMP systems
  457. */
  458. if (!is_smp() && cpu_arch >= CPU_ARCH_ARMv5 && cachepolicy > CPOLICY_WRITETHROUGH)
  459. vecs_pgprot = cache_policies[CPOLICY_WRITETHROUGH].pte;
  460. /*
  461. * Enable CPU-specific coherency if supported.
  462. * (Only available on XSC3 at the moment.)
  463. */
  464. if (arch_is_coherent() && cpu_is_xsc3()) {
  465. mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
  466. mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
  467. mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
  468. mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
  469. mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
  470. }
  471. /*
  472. * ARMv6 and above have extended page tables.
  473. */
  474. if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
  475. #ifndef CONFIG_ARM_LPAE
  476. /*
  477. * Mark cache clean areas and XIP ROM read only
  478. * from SVC mode and no access from userspace.
  479. */
  480. mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  481. mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  482. mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  483. mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  484. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  485. #endif
  486. if (is_smp()) {
  487. /*
  488. * Mark memory with the "shared" attribute
  489. * for SMP systems
  490. */
  491. user_pgprot |= L_PTE_SHARED;
  492. kern_pgprot |= L_PTE_SHARED;
  493. vecs_pgprot |= L_PTE_SHARED;
  494. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_S;
  495. mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
  496. mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
  497. mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
  498. mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
  499. mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
  500. mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
  501. mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
  502. mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
  503. mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
  504. mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
  505. mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
  506. }
  507. }
  508. #ifndef CONFIG_ARM_LPAE
  509. /*
  510. * We don't use domains on ARMv6 (since this causes problems with
  511. * v6/v7 kernels), so we must use a separate memory type for user
  512. * r/o, kernel r/w to map the vectors page.
  513. */
  514. if (cpu_arch == CPU_ARCH_ARMv6)
  515. vecs_pgprot |= L_PTE_MT_VECTORS;
  516. /*
  517. * Check is it with support for the PXN bit
  518. * in the Short-descriptor translation table format descriptors.
  519. */
  520. if (cpu_arch == CPU_ARCH_ARMv7 &&
  521. (read_cpuid_ext(CPUID_EXT_MMFR0) & 0xF) >= 4) {
  522. user_pmd_table |= PMD_PXNTABLE;
  523. }
  524. #endif
  525. /*
  526. * Non-cacheable Normal - intended for memory areas that must
  527. * not cause dirty cache line writebacks when used
  528. */
  529. if (cpu_arch >= CPU_ARCH_ARMv6) {
  530. if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
  531. /* Non-cacheable Normal is XCB = 001 */
  532. mem_types[MT_MEMORY_NONCACHED].prot_sect |=
  533. PMD_SECT_BUFFERED;
  534. } else {
  535. /* For both ARMv6 and non-TEX-remapping ARMv7 */
  536. mem_types[MT_MEMORY_NONCACHED].prot_sect |=
  537. PMD_SECT_TEX(1);
  538. }
  539. } else {
  540. mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
  541. }
  542. #ifdef CONFIG_ARM_LPAE
  543. /*
  544. * Do not generate access flag faults for the kernel mappings.
  545. */
  546. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  547. mem_types[i].prot_pte |= PTE_EXT_AF;
  548. if (mem_types[i].prot_sect)
  549. mem_types[i].prot_sect |= PMD_SECT_AF;
  550. }
  551. kern_pgprot |= PTE_EXT_AF;
  552. vecs_pgprot |= PTE_EXT_AF;
  553. /*
  554. * Set PXN for user mappings
  555. */
  556. user_pgprot |= PTE_EXT_PXN;
  557. #endif
  558. for (i = 0; i < 16; i++) {
  559. pteval_t v = pgprot_val(protection_map[i]);
  560. protection_map[i] = __pgprot(v | user_pgprot);
  561. }
  562. mem_types[MT_LOW_VECTORS].prot_pte |= vecs_pgprot;
  563. mem_types[MT_HIGH_VECTORS].prot_pte |= vecs_pgprot;
  564. pgprot_user = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | user_pgprot);
  565. pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
  566. L_PTE_DIRTY | kern_pgprot);
  567. mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
  568. mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
  569. mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
  570. mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
  571. mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
  572. mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
  573. mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
  574. mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
  575. mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
  576. mem_types[MT_ROM].prot_sect |= cp->pmd;
  577. switch (cp->pmd) {
  578. case PMD_SECT_WT:
  579. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
  580. break;
  581. case PMD_SECT_WB:
  582. case PMD_SECT_WBWA:
  583. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
  584. break;
  585. }
  586. printk("Memory policy: ECC %sabled, Data cache %s\n",
  587. ecc_mask ? "en" : "dis", cp->policy);
  588. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  589. struct mem_type *t = &mem_types[i];
  590. if (t->prot_l1)
  591. t->prot_l1 |= PMD_DOMAIN(t->domain);
  592. if (t->prot_sect)
  593. t->prot_sect |= PMD_DOMAIN(t->domain);
  594. }
  595. }
  596. #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
  597. pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  598. unsigned long size, pgprot_t vma_prot)
  599. {
  600. if (!pfn_valid(pfn))
  601. return pgprot_noncached(vma_prot);
  602. else if (file->f_flags & O_SYNC)
  603. return pgprot_writecombine(vma_prot);
  604. return vma_prot;
  605. }
  606. EXPORT_SYMBOL(phys_mem_access_prot);
  607. #endif
  608. #define vectors_base() (vectors_high() ? 0xffff0000 : 0)
  609. static void __init *early_alloc_aligned(unsigned long sz, unsigned long align)
  610. {
  611. void *ptr = __va(memblock_alloc(sz, align));
  612. memset(ptr, 0, sz);
  613. return ptr;
  614. }
  615. static void __init *early_alloc(unsigned long sz)
  616. {
  617. return early_alloc_aligned(sz, sz);
  618. }
  619. static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, unsigned long prot)
  620. {
  621. if (pmd_none(*pmd)) {
  622. pte_t *pte = early_alloc(PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE);
  623. __pmd_populate(pmd, __pa(pte), prot);
  624. }
  625. BUG_ON(pmd_bad(*pmd));
  626. return pte_offset_kernel(pmd, addr);
  627. }
  628. static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
  629. unsigned long end, unsigned long pfn,
  630. const struct mem_type *type)
  631. {
  632. pte_t *pte = early_pte_alloc(pmd, addr, type->prot_l1);
  633. do {
  634. set_pte_ext(pte, pfn_pte(pfn, __pgprot(type->prot_pte)), 0);
  635. pfn++;
  636. } while (pte++, addr += PAGE_SIZE, addr != end);
  637. }
  638. static void __init map_init_section(pmd_t *pmd, unsigned long addr,
  639. unsigned long end, phys_addr_t phys,
  640. const struct mem_type *type)
  641. {
  642. #ifndef CONFIG_ARM_LPAE
  643. /*
  644. * In classic MMU format, puds and pmds are folded in to
  645. * the pgds. pmd_offset gives the PGD entry. PGDs refer to a
  646. * group of L1 entries making up one logical pointer to
  647. * an L2 table (2MB), where as PMDs refer to the individual
  648. * L1 entries (1MB). Hence increment to get the correct
  649. * offset for odd 1MB sections.
  650. * (See arch/arm/include/asm/pgtable-2level.h)
  651. */
  652. if (addr & SECTION_SIZE)
  653. pmd++;
  654. #endif
  655. do {
  656. *pmd = __pmd(phys | type->prot_sect);
  657. phys += SECTION_SIZE;
  658. } while (pmd++, addr += SECTION_SIZE, addr != end);
  659. flush_pmd_entry(pmd);
  660. }
  661. static void __init alloc_init_pmd(pud_t *pud, unsigned long addr,
  662. unsigned long end, phys_addr_t phys,
  663. const struct mem_type *type)
  664. {
  665. pmd_t *pmd = pmd_offset(pud, addr);
  666. unsigned long next;
  667. do {
  668. /*
  669. * With LPAE, we must loop over to map
  670. * all the pmds for the given range.
  671. */
  672. next = pmd_addr_end(addr, end);
  673. /*
  674. * Try a section mapping - addr, next and phys must all be
  675. * aligned to a section boundary.
  676. */
  677. if (type->prot_sect &&
  678. ((addr | next | phys) & ~SECTION_MASK) == 0) {
  679. map_init_section(pmd, addr, next, phys, type);
  680. } else {
  681. alloc_init_pte(pmd, addr, next,
  682. __phys_to_pfn(phys), type);
  683. }
  684. phys += next - addr;
  685. } while (pmd++, addr = next, addr != end);
  686. }
  687. static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr,
  688. unsigned long end, unsigned long phys, const struct mem_type *type)
  689. {
  690. pud_t *pud = pud_offset(pgd, addr);
  691. unsigned long next;
  692. do {
  693. next = pud_addr_end(addr, end);
  694. alloc_init_pmd(pud, addr, next, phys, type);
  695. phys += next - addr;
  696. } while (pud++, addr = next, addr != end);
  697. }
  698. #ifndef CONFIG_ARM_LPAE
  699. static void __init create_36bit_mapping(struct map_desc *md,
  700. const struct mem_type *type)
  701. {
  702. unsigned long addr, length, end;
  703. phys_addr_t phys;
  704. pgd_t *pgd;
  705. addr = md->virtual;
  706. phys = __pfn_to_phys(md->pfn);
  707. length = PAGE_ALIGN(md->length);
  708. if (!(cpu_architecture() >= CPU_ARCH_ARMv6 || cpu_is_xsc3())) {
  709. printk(KERN_ERR "MM: CPU does not support supersection "
  710. "mapping for 0x%08llx at 0x%08lx\n",
  711. (long long)__pfn_to_phys((u64)md->pfn), addr);
  712. return;
  713. }
  714. /* N.B. ARMv6 supersections are only defined to work with domain 0.
  715. * Since domain assignments can in fact be arbitrary, the
  716. * 'domain == 0' check below is required to insure that ARMv6
  717. * supersections are only allocated for domain 0 regardless
  718. * of the actual domain assignments in use.
  719. */
  720. if (type->domain) {
  721. printk(KERN_ERR "MM: invalid domain in supersection "
  722. "mapping for 0x%08llx at 0x%08lx\n",
  723. (long long)__pfn_to_phys((u64)md->pfn), addr);
  724. return;
  725. }
  726. if ((addr | length | __pfn_to_phys(md->pfn)) & ~SUPERSECTION_MASK) {
  727. printk(KERN_ERR "MM: cannot create mapping for 0x%08llx"
  728. " at 0x%08lx invalid alignment\n",
  729. (long long)__pfn_to_phys((u64)md->pfn), addr);
  730. return;
  731. }
  732. /*
  733. * Shift bits [35:32] of address into bits [23:20] of PMD
  734. * (See ARMv6 spec).
  735. */
  736. phys |= (((md->pfn >> (32 - PAGE_SHIFT)) & 0xF) << 20);
  737. pgd = pgd_offset_k(addr);
  738. end = addr + length;
  739. do {
  740. pud_t *pud = pud_offset(pgd, addr);
  741. pmd_t *pmd = pmd_offset(pud, addr);
  742. int i;
  743. for (i = 0; i < 16; i++)
  744. *pmd++ = __pmd(phys | type->prot_sect | PMD_SECT_SUPER);
  745. addr += SUPERSECTION_SIZE;
  746. phys += SUPERSECTION_SIZE;
  747. pgd += SUPERSECTION_SIZE >> PGDIR_SHIFT;
  748. } while (addr != end);
  749. }
  750. #endif /* !CONFIG_ARM_LPAE */
  751. /*
  752. * Create the page directory entries and any necessary
  753. * page tables for the mapping specified by `md'. We
  754. * are able to cope here with varying sizes and address
  755. * offsets, and we take full advantage of sections and
  756. * supersections.
  757. */
  758. static void __init create_mapping(struct map_desc *md)
  759. {
  760. unsigned long addr, length, end;
  761. phys_addr_t phys;
  762. const struct mem_type *type;
  763. pgd_t *pgd;
  764. if ((md->virtual != vectors_base() &&
  765. md->virtual != get_user_accessible_timers_base()) &&
  766. md->virtual < TASK_SIZE) {
  767. printk(KERN_WARNING "BUG: not creating mapping for 0x%08llx"
  768. " at 0x%08lx in user region\n",
  769. (long long)__pfn_to_phys((u64)md->pfn), md->virtual);
  770. return;
  771. }
  772. if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
  773. md->virtual >= PAGE_OFFSET &&
  774. (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
  775. printk(KERN_WARNING "BUG: mapping for 0x%08llx"
  776. " at 0x%08lx out of vmalloc space\n",
  777. (long long)__pfn_to_phys((u64)md->pfn), md->virtual);
  778. }
  779. type = &mem_types[md->type];
  780. #ifndef CONFIG_ARM_LPAE
  781. /*
  782. * Catch 36-bit addresses
  783. */
  784. if (md->pfn >= 0x100000) {
  785. create_36bit_mapping(md, type);
  786. return;
  787. }
  788. #endif
  789. addr = md->virtual & PAGE_MASK;
  790. phys = __pfn_to_phys(md->pfn);
  791. length = PAGE_ALIGN(md->length + (md->virtual & ~PAGE_MASK));
  792. if (type->prot_l1 == 0 && ((addr | phys | length) & ~SECTION_MASK)) {
  793. printk(KERN_WARNING "BUG: map for 0x%08llx at 0x%08lx can not "
  794. "be mapped using pages, ignoring.\n",
  795. (long long)__pfn_to_phys(md->pfn), addr);
  796. return;
  797. }
  798. pgd = pgd_offset_k(addr);
  799. end = addr + length;
  800. do {
  801. unsigned long next = pgd_addr_end(addr, end);
  802. alloc_init_pud(pgd, addr, next, phys, type);
  803. phys += next - addr;
  804. addr = next;
  805. } while (pgd++, addr != end);
  806. }
  807. /*
  808. * Create the architecture specific mappings
  809. */
  810. void __init iotable_init(struct map_desc *io_desc, int nr)
  811. {
  812. struct map_desc *md;
  813. struct vm_struct *vm;
  814. int rc = 0;
  815. if (!nr)
  816. return;
  817. vm = early_alloc_aligned(sizeof(*vm) * nr, __alignof__(*vm));
  818. for (md = io_desc; nr; md++, nr--) {
  819. create_mapping(md);
  820. vm->addr = (void *)(md->virtual & PAGE_MASK);
  821. vm->size = PAGE_ALIGN(md->length + (md->virtual & ~PAGE_MASK));
  822. vm->phys_addr = __pfn_to_phys(md->pfn);
  823. vm->flags = VM_IOREMAP | VM_ARM_STATIC_MAPPING;
  824. vm->flags |= VM_ARM_MTYPE(md->type);
  825. vm->caller = iotable_init;
  826. rc = vm_area_check_early(vm);
  827. if (!rc)
  828. vm_area_add_early(vm++);
  829. }
  830. }
  831. #ifndef CONFIG_ARM_LPAE
  832. /*
  833. * The Linux PMD is made of two consecutive section entries covering 2MB
  834. * (see definition in include/asm/pgtable-2level.h). However a call to
  835. * create_mapping() may optimize static mappings by using individual
  836. * 1MB section mappings. This leaves the actual PMD potentially half
  837. * initialized if the top or bottom section entry isn't used, leaving it
  838. * open to problems if a subsequent ioremap() or vmalloc() tries to use
  839. * the virtual space left free by that unused section entry.
  840. *
  841. * Let's avoid the issue by inserting dummy vm entries covering the unused
  842. * PMD halves once the static mappings are in place.
  843. */
  844. static void __init pmd_empty_section_gap(unsigned long addr)
  845. {
  846. struct vm_struct *vm;
  847. vm = early_alloc_aligned(sizeof(*vm), __alignof__(*vm));
  848. vm->addr = (void *)addr;
  849. vm->size = SECTION_SIZE;
  850. vm->flags = VM_IOREMAP | VM_ARM_EMPTY_MAPPING;
  851. vm->caller = pmd_empty_section_gap;
  852. vm_area_add_early(vm);
  853. }
  854. static void __init fill_pmd_gaps(void)
  855. {
  856. struct vm_struct *vm;
  857. unsigned long addr, next = 0;
  858. pmd_t *pmd;
  859. /* we're still single threaded hence no lock needed here */
  860. for (vm = vmlist; vm; vm = vm->next) {
  861. if (!(vm->flags & (VM_ARM_STATIC_MAPPING | VM_ARM_EMPTY_MAPPING)))
  862. continue;
  863. addr = (unsigned long)vm->addr;
  864. if (addr < next)
  865. continue;
  866. /*
  867. * Check if this vm starts on an odd section boundary.
  868. * If so and the first section entry for this PMD is free
  869. * then we block the corresponding virtual address.
  870. */
  871. if ((addr & ~PMD_MASK) == SECTION_SIZE) {
  872. pmd = pmd_off_k(addr);
  873. if (pmd_none(*pmd))
  874. pmd_empty_section_gap(addr & PMD_MASK);
  875. }
  876. /*
  877. * Then check if this vm ends on an odd section boundary.
  878. * If so and the second section entry for this PMD is empty
  879. * then we block the corresponding virtual address.
  880. */
  881. addr += vm->size;
  882. if ((addr & ~PMD_MASK) == SECTION_SIZE) {
  883. pmd = pmd_off_k(addr) + 1;
  884. if (pmd_none(*pmd))
  885. pmd_empty_section_gap(addr);
  886. }
  887. /* no need to look at any vm entry until we hit the next PMD */
  888. next = (addr + PMD_SIZE - 1) & PMD_MASK;
  889. }
  890. }
  891. #else
  892. #define fill_pmd_gaps() do { } while (0)
  893. #endif
  894. static void * __initdata vmalloc_min =
  895. (void *)(VMALLOC_END - (240 << 20) - VMALLOC_OFFSET);
  896. /*
  897. * vmalloc=size forces the vmalloc area to be exactly 'size'
  898. * bytes. This can be used to increase (or decrease) the vmalloc
  899. * area - the default is 240m.
  900. */
  901. static int __init early_vmalloc(char *arg)
  902. {
  903. unsigned long vmalloc_reserve = memparse(arg, NULL);
  904. if (vmalloc_reserve < SZ_16M) {
  905. vmalloc_reserve = SZ_16M;
  906. printk(KERN_WARNING
  907. "vmalloc area too small, limiting to %luMB\n",
  908. vmalloc_reserve >> 20);
  909. }
  910. if (vmalloc_reserve > VMALLOC_END - (PAGE_OFFSET + SZ_32M)) {
  911. vmalloc_reserve = VMALLOC_END - (PAGE_OFFSET + SZ_32M);
  912. printk(KERN_WARNING
  913. "vmalloc area is too big, limiting to %luMB\n",
  914. vmalloc_reserve >> 20);
  915. }
  916. vmalloc_min = (void *)(VMALLOC_END - vmalloc_reserve);
  917. return 0;
  918. }
  919. early_param("vmalloc", early_vmalloc);
  920. phys_addr_t arm_lowmem_limit __initdata = 0;
  921. void __init sanity_check_meminfo(void)
  922. {
  923. int i, j, highmem = 0;
  924. #ifdef CONFIG_ENABLE_VMALLOC_SAVING
  925. unsigned long hole_start;
  926. for (i = 0; i < (meminfo.nr_banks - 1); i++) {
  927. hole_start = meminfo.bank[i].start + meminfo.bank[i].size;
  928. if (hole_start != meminfo.bank[i+1].start) {
  929. if (hole_start <= MAX_HOLE_ADDRESS) {
  930. vmalloc_min = (void *) (vmalloc_min +
  931. (meminfo.bank[i+1].start - hole_start));
  932. }
  933. }
  934. }
  935. #endif
  936. #ifdef CONFIG_DONT_MAP_HOLE_AFTER_MEMBANK0
  937. find_memory_hole();
  938. #endif
  939. for (i = 0, j = 0; i < meminfo.nr_banks; i++) {
  940. struct membank *bank = &meminfo.bank[j];
  941. *bank = meminfo.bank[i];
  942. if (bank->start > ULONG_MAX)
  943. highmem = 1;
  944. #ifdef CONFIG_HIGHMEM
  945. if (__va(bank->start) >= vmalloc_min ||
  946. __va(bank->start) < (void *)PAGE_OFFSET)
  947. highmem = 1;
  948. bank->highmem = highmem;
  949. /*
  950. * Split those memory banks which are partially overlapping
  951. * the vmalloc area greatly simplifying things later.
  952. */
  953. if (!highmem && __va(bank->start) < vmalloc_min &&
  954. bank->size > vmalloc_min - __va(bank->start)) {
  955. if (meminfo.nr_banks >= NR_BANKS) {
  956. printk(KERN_CRIT "NR_BANKS too low, "
  957. "ignoring high memory\n");
  958. } else {
  959. memmove(bank + 1, bank,
  960. (meminfo.nr_banks - i) * sizeof(*bank));
  961. meminfo.nr_banks++;
  962. i++;
  963. bank[1].size -= vmalloc_min - __va(bank->start);
  964. bank[1].start = __pa(vmalloc_min - 1) + 1;
  965. bank[1].highmem = highmem = 1;
  966. j++;
  967. }
  968. bank->size = vmalloc_min - __va(bank->start);
  969. }
  970. #else
  971. bank->highmem = highmem;
  972. /*
  973. * Highmem banks not allowed with !CONFIG_HIGHMEM.
  974. */
  975. if (highmem) {
  976. printk(KERN_NOTICE "Ignoring RAM at %.8llx-%.8llx "
  977. "(!CONFIG_HIGHMEM).\n",
  978. (unsigned long long)bank->start,
  979. (unsigned long long)bank->start + bank->size - 1);
  980. continue;
  981. }
  982. /*
  983. * Check whether this memory bank would entirely overlap
  984. * the vmalloc area.
  985. */
  986. if (__va(bank->start) >= vmalloc_min ||
  987. __va(bank->start) < (void *)PAGE_OFFSET) {
  988. printk(KERN_NOTICE "Ignoring RAM at %.8llx-%.8llx "
  989. "(vmalloc region overlap).\n",
  990. (unsigned long long)bank->start,
  991. (unsigned long long)bank->start + bank->size - 1);
  992. continue;
  993. }
  994. /*
  995. * Check whether this memory bank would partially overlap
  996. * the vmalloc area.
  997. */
  998. if (__va(bank->start + bank->size) > vmalloc_min ||
  999. __va(bank->start + bank->size) < __va(bank->start)) {
  1000. unsigned long newsize = vmalloc_min - __va(bank->start);
  1001. printk(KERN_NOTICE "Truncating RAM at %.8llx-%.8llx "
  1002. "to -%.8llx (vmalloc region overlap).\n",
  1003. (unsigned long long)bank->start,
  1004. (unsigned long long)bank->start + bank->size - 1,
  1005. (unsigned long long)bank->start + newsize - 1);
  1006. bank->size = newsize;
  1007. }
  1008. #endif
  1009. if (!bank->highmem && bank->start + bank->size > arm_lowmem_limit)
  1010. arm_lowmem_limit = bank->start + bank->size;
  1011. j++;
  1012. }
  1013. #ifdef CONFIG_HIGHMEM
  1014. if (highmem) {
  1015. const char *reason = NULL;
  1016. if (cache_is_vipt_aliasing()) {
  1017. /*
  1018. * Interactions between kmap and other mappings
  1019. * make highmem support with aliasing VIPT caches
  1020. * rather difficult.
  1021. */
  1022. reason = "with VIPT aliasing cache";
  1023. }
  1024. if (reason) {
  1025. printk(KERN_CRIT "HIGHMEM is not supported %s, ignoring high memory\n",
  1026. reason);
  1027. while (j > 0 && meminfo.bank[j - 1].highmem)
  1028. j--;
  1029. }
  1030. }
  1031. #endif
  1032. meminfo.nr_banks = j;
  1033. high_memory = __va(arm_lowmem_limit - 1) + 1;
  1034. memblock_set_current_limit(arm_lowmem_limit);
  1035. }
  1036. static inline void prepare_page_table(void)
  1037. {
  1038. unsigned long addr;
  1039. phys_addr_t end;
  1040. /*
  1041. * Clear out all the mappings below the kernel image.
  1042. */
  1043. for (addr = 0; addr < MODULES_VADDR; addr += PMD_SIZE)
  1044. pmd_clear(pmd_off_k(addr));
  1045. #ifdef CONFIG_XIP_KERNEL
  1046. /* The XIP kernel is mapped in the module area -- skip over it */
  1047. addr = ((unsigned long)_etext + PMD_SIZE - 1) & PMD_MASK;
  1048. #endif
  1049. for ( ; addr < PAGE_OFFSET; addr += PMD_SIZE)
  1050. pmd_clear(pmd_off_k(addr));
  1051. /*
  1052. * Find the end of the first block of lowmem.
  1053. */
  1054. end = memblock.memory.regions[0].base + memblock.memory.regions[0].size;
  1055. if (end >= arm_lowmem_limit)
  1056. end = arm_lowmem_limit;
  1057. /*
  1058. * Clear out all the kernel space mappings, except for the first
  1059. * memory bank, up to the vmalloc region.
  1060. */
  1061. for (addr = __phys_to_virt(end);
  1062. addr < VMALLOC_START; addr += PMD_SIZE)
  1063. pmd_clear(pmd_off_k(addr));
  1064. }
  1065. #ifdef CONFIG_ARM_LPAE
  1066. /* the first page is reserved for pgd */
  1067. #define SWAPPER_PG_DIR_SIZE (PAGE_SIZE + \
  1068. PTRS_PER_PGD * PTRS_PER_PMD * sizeof(pmd_t))
  1069. #else
  1070. #define SWAPPER_PG_DIR_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
  1071. #endif
  1072. /*
  1073. * Reserve the special regions of memory
  1074. */
  1075. void __init arm_mm_memblock_reserve(void)
  1076. {
  1077. /*
  1078. * Reserve the page tables. These are already in use,
  1079. * and can only be in node 0.
  1080. */
  1081. memblock_reserve(__pa(swapper_pg_dir), SWAPPER_PG_DIR_SIZE);
  1082. #ifdef CONFIG_SA1111
  1083. /*
  1084. * Because of the SA1111 DMA bug, we want to preserve our
  1085. * precious DMA-able memory...
  1086. */
  1087. memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
  1088. #endif
  1089. }
  1090. /*
  1091. * Set up the device mappings. Since we clear out the page tables for all
  1092. * mappings above VMALLOC_START, we will remove any debug device mappings.
  1093. * This means you have to be careful how you debug this function, or any
  1094. * called function. This means you can't use any function or debugging
  1095. * method which may touch any device, otherwise the kernel _will_ crash.
  1096. */
  1097. static void __init devicemaps_init(struct machine_desc *mdesc)
  1098. {
  1099. struct map_desc map;
  1100. unsigned long addr;
  1101. void *vectors;
  1102. /*
  1103. * Allocate the vector page early.
  1104. */
  1105. vectors = early_alloc(PAGE_SIZE * 2);
  1106. early_trap_init(vectors);
  1107. for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
  1108. pmd_clear(pmd_off_k(addr));
  1109. /*
  1110. * Map the kernel if it is XIP.
  1111. * It is always first in the modulearea.
  1112. */
  1113. #ifdef CONFIG_XIP_KERNEL
  1114. map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
  1115. map.virtual = MODULES_VADDR;
  1116. map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
  1117. map.type = MT_ROM;
  1118. create_mapping(&map);
  1119. #endif
  1120. /*
  1121. * Map the cache flushing regions.
  1122. */
  1123. #ifdef FLUSH_BASE
  1124. map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
  1125. map.virtual = FLUSH_BASE;
  1126. map.length = SZ_1M;
  1127. map.type = MT_CACHECLEAN;
  1128. create_mapping(&map);
  1129. #endif
  1130. #ifdef FLUSH_BASE_MINICACHE
  1131. map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
  1132. map.virtual = FLUSH_BASE_MINICACHE;
  1133. map.length = SZ_1M;
  1134. map.type = MT_MINICLEAN;
  1135. create_mapping(&map);
  1136. #endif
  1137. /*
  1138. * Create a mapping for the machine vectors at the high-vectors
  1139. * location (0xffff0000). If we aren't using high-vectors, also
  1140. * create a mapping at the low-vectors virtual address.
  1141. */
  1142. map.pfn = __phys_to_pfn(virt_to_phys(vectors));
  1143. map.virtual = 0xffff0000;
  1144. map.length = PAGE_SIZE;
  1145. #ifdef CONFIG_KUSER_HELPERS
  1146. map.type = MT_HIGH_VECTORS;
  1147. #else
  1148. map.type = MT_LOW_VECTORS;
  1149. #endif
  1150. create_mapping(&map);
  1151. if (!vectors_high()) {
  1152. map.virtual = 0;
  1153. map.length = PAGE_SIZE * 2;
  1154. map.type = MT_LOW_VECTORS;
  1155. create_mapping(&map);
  1156. }
  1157. /* Now create a kernel read-only mapping */
  1158. map.pfn += 1;
  1159. map.virtual = 0xffff0000 + PAGE_SIZE;
  1160. map.length = PAGE_SIZE;
  1161. map.type = MT_LOW_VECTORS;
  1162. create_mapping(&map);
  1163. /*
  1164. * Ask the machine support to map in the statically mapped devices.
  1165. */
  1166. if (mdesc->map_io)
  1167. mdesc->map_io();
  1168. fill_pmd_gaps();
  1169. if (use_user_accessible_timers()) {
  1170. /*
  1171. * Generate a mapping for the timer page.
  1172. */
  1173. int page_addr = get_timer_page_address();
  1174. if (page_addr != ARM_USER_ACCESSIBLE_TIMERS_INVALID_PAGE) {
  1175. map.pfn = __phys_to_pfn(page_addr);
  1176. map.virtual = CONFIG_ARM_USER_ACCESSIBLE_TIMER_BASE;
  1177. map.length = PAGE_SIZE;
  1178. map.type = MT_DEVICE_USER_ACCESSIBLE;
  1179. create_mapping(&map);
  1180. }
  1181. }
  1182. /*
  1183. * Finally flush the caches and tlb to ensure that we're in a
  1184. * consistent state wrt the writebuffer. This also ensures that
  1185. * any write-allocated cache lines in the vector page are written
  1186. * back. After this point, we can start to touch devices again.
  1187. */
  1188. local_flush_tlb_all();
  1189. flush_cache_all();
  1190. }
  1191. static void __init kmap_init(void)
  1192. {
  1193. #ifdef CONFIG_HIGHMEM
  1194. pkmap_page_table = early_pte_alloc(pmd_off_k(PKMAP_BASE),
  1195. PKMAP_BASE, _PAGE_KERNEL_TABLE);
  1196. #endif
  1197. }
  1198. #ifdef CONFIG_STRICT_MEMORY_RWX
  1199. static struct {
  1200. pmd_t *pmd_to_flush;
  1201. pmd_t *pmd;
  1202. unsigned long addr;
  1203. pmd_t saved_pmd;
  1204. bool made_writeable;
  1205. } mem_unprotect;
  1206. static DEFINE_SPINLOCK(mem_text_writeable_lock);
  1207. void mem_text_writeable_spinlock(unsigned long *flags)
  1208. {
  1209. spin_lock_irqsave(&mem_text_writeable_lock, *flags);
  1210. }
  1211. void mem_text_writeable_spinunlock(unsigned long *flags)
  1212. {
  1213. spin_unlock_irqrestore(&mem_text_writeable_lock, *flags);
  1214. }
  1215. /*
  1216. * mem_text_address_writeable() and mem_text_address_restore()
  1217. * should be called as a pair. They are used to make the
  1218. * specified address in the kernel text section temporarily writeable
  1219. * when it has been marked read-only by STRICT_MEMORY_RWX.
  1220. * Used by kprobes and other debugging tools to set breakpoints etc.
  1221. * mem_text_address_writeable() is invoked before writing.
  1222. * After the write, mem_text_address_restore() must be called
  1223. * to restore the original state.
  1224. * This is only effective when used on the kernel text section
  1225. * marked as MEMORY_RX by map_lowmem()
  1226. *
  1227. * They must each be called with mem_text_writeable_lock locked
  1228. * by the caller, with no unlocking between the calls.
  1229. * The caller should release mem_text_writeable_lock immediately
  1230. * after the call to mem_text_address_restore().
  1231. * Only the write and associated cache operations should be performed
  1232. * between the calls.
  1233. */
  1234. /* this function must be called with mem_text_writeable_lock held */
  1235. void mem_text_address_writeable(unsigned long addr)
  1236. {
  1237. struct task_struct *tsk = current;
  1238. struct mm_struct *mm = tsk->active_mm;
  1239. pgd_t *pgd = pgd_offset(mm, addr);
  1240. pud_t *pud = pud_offset(pgd, addr);
  1241. mem_unprotect.made_writeable = 0;
  1242. if ((addr < (unsigned long)RX_AREA_START) ||
  1243. (addr >= (unsigned long)RX_AREA_END))
  1244. return;
  1245. mem_unprotect.pmd = pmd_offset(pud, addr);
  1246. mem_unprotect.pmd_to_flush = mem_unprotect.pmd;
  1247. mem_unprotect.addr = addr & PAGE_MASK;
  1248. if (addr & SECTION_SIZE)
  1249. mem_unprotect.pmd++;
  1250. mem_unprotect.saved_pmd = *mem_unprotect.pmd;
  1251. if ((mem_unprotect.saved_pmd & PMD_TYPE_MASK) != PMD_TYPE_SECT)
  1252. return;
  1253. *mem_unprotect.pmd &= ~PMD_SECT_APX;
  1254. flush_pmd_entry(mem_unprotect.pmd_to_flush);
  1255. flush_tlb_kernel_page(mem_unprotect.addr);
  1256. mem_unprotect.made_writeable = 1;
  1257. }
  1258. /* this function must be called with mem_text_writeable_lock held */
  1259. void mem_text_address_restore(void)
  1260. {
  1261. if (mem_unprotect.made_writeable) {
  1262. *mem_unprotect.pmd = mem_unprotect.saved_pmd;
  1263. flush_pmd_entry(mem_unprotect.pmd_to_flush);
  1264. flush_tlb_kernel_page(mem_unprotect.addr);
  1265. }
  1266. }
  1267. #endif
  1268. void mem_text_write_kernel_word(unsigned long *addr, unsigned long word)
  1269. {
  1270. unsigned long flags;
  1271. mem_text_writeable_spinlock(&flags);
  1272. mem_text_address_writeable((unsigned long)addr);
  1273. *addr = word;
  1274. flush_icache_range((unsigned long)addr,
  1275. ((unsigned long)addr + sizeof(long)));
  1276. mem_text_address_restore();
  1277. mem_text_writeable_spinunlock(&flags);
  1278. }
  1279. EXPORT_SYMBOL(mem_text_write_kernel_word);
  1280. static void __init map_lowmem(void)
  1281. {
  1282. struct memblock_region *reg;
  1283. struct vm_struct *vm;
  1284. phys_addr_t start;
  1285. phys_addr_t end;
  1286. unsigned long vaddr;
  1287. unsigned long pfn;
  1288. unsigned long length;
  1289. unsigned int type;
  1290. int nr = 0;
  1291. /* Map all the lowmem memory banks. */
  1292. for_each_memblock(memory, reg) {
  1293. struct map_desc map;
  1294. nr++;
  1295. start = reg->base;
  1296. end = start + reg->size;
  1297. if (end > arm_lowmem_limit)
  1298. end = arm_lowmem_limit;
  1299. if (start >= end)
  1300. break;
  1301. map.pfn = __phys_to_pfn(start);
  1302. map.virtual = __phys_to_virt(start);
  1303. #ifdef CONFIG_STRICT_MEMORY_RWX
  1304. if (start <= __pa(_text) && __pa(_text) < end) {
  1305. map.length = SECTION_SIZE;
  1306. map.type = MT_MEMORY_RW;
  1307. create_mapping(&map);
  1308. map.pfn = __phys_to_pfn(start + SECTION_SIZE);
  1309. map.virtual = __phys_to_virt(start + SECTION_SIZE);
  1310. map.length = (unsigned long)RX_AREA_END - map.virtual;
  1311. map.type = MT_MEMORY_RX;
  1312. create_mapping(&map);
  1313. map.pfn = __phys_to_pfn(__pa(__start_rodata));
  1314. map.virtual = (unsigned long)__start_rodata;
  1315. map.length = __init_begin - __start_rodata;
  1316. map.type = MT_MEMORY_R;
  1317. create_mapping(&map);
  1318. map.pfn = __phys_to_pfn(__pa(__init_begin));
  1319. map.virtual = (unsigned long)__init_begin;
  1320. map.length = (char *)__arch_info_begin - __init_begin;
  1321. map.type = MT_MEMORY_RX;
  1322. create_mapping(&map);
  1323. map.pfn = __phys_to_pfn(__pa(__arch_info_begin));
  1324. map.virtual = (unsigned long)__arch_info_begin;
  1325. map.length = __phys_to_virt(end) -
  1326. (unsigned long)__arch_info_begin;
  1327. map.type = MT_MEMORY_RW;
  1328. } else {
  1329. map.length = end - start;
  1330. map.type = MT_MEMORY_RW;
  1331. }
  1332. #else
  1333. map.length = end - start;
  1334. map.type = MT_MEMORY;
  1335. #endif
  1336. create_mapping(&map);
  1337. }
  1338. vm = early_alloc_aligned(sizeof(*vm) * nr, __alignof__(*vm));
  1339. for_each_memblock(memory, reg) {
  1340. start = reg->base;
  1341. end = start + reg->size;
  1342. if (end > arm_lowmem_limit)
  1343. end = arm_lowmem_limit;
  1344. if (start >= end)
  1345. break;
  1346. pfn = __phys_to_pfn(start);
  1347. vaddr = __phys_to_virt(start);
  1348. length = end - start;
  1349. type = MT_MEMORY;
  1350. vm->addr = (void *)(vaddr & PAGE_MASK);
  1351. vm->size = PAGE_ALIGN(length + (vaddr & ~PAGE_MASK));
  1352. vm->phys_addr = __pfn_to_phys(pfn);
  1353. vm->flags = VM_LOWMEM | VM_ARM_STATIC_MAPPING;
  1354. vm->flags |= VM_ARM_MTYPE(type);
  1355. vm->caller = map_lowmem;
  1356. vm_area_add_early(vm);
  1357. mark_vmalloc_reserved_area(vm->addr, vm->size);
  1358. vm++;
  1359. }
  1360. }
  1361. #ifdef CONFIG_FORCE_PAGES
  1362. /*
  1363. * remap a PMD into pages
  1364. * We split a single pmd here none of this two pmd nonsense
  1365. */
  1366. static noinline void split_pmd(pmd_t *pmd, unsigned long addr,
  1367. unsigned long end, unsigned long pfn,
  1368. const struct mem_type *type)
  1369. {
  1370. pte_t *pte, *start_pte;
  1371. pmd_t *base_pmd;
  1372. base_pmd = pmd_offset(
  1373. pud_offset(pgd_offset(&init_mm, addr), addr), addr);
  1374. if (pmd_none(*base_pmd) || pmd_bad(*base_pmd)) {
  1375. start_pte = early_alloc(PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE);
  1376. #ifndef CONFIG_ARM_LPAE
  1377. /*
  1378. * Following is needed when new pte is allocated for pmd[1]
  1379. * cases, which may happen when base (start) address falls
  1380. * under pmd[1].
  1381. */
  1382. if (addr & SECTION_SIZE)
  1383. start_pte += pte_index(addr);
  1384. #endif
  1385. } else {
  1386. start_pte = pte_offset_kernel(base_pmd, addr);
  1387. }
  1388. pte = start_pte;
  1389. do {
  1390. set_pte_ext(pte, pfn_pte(pfn, type->prot_pte), 0);
  1391. pfn++;
  1392. } while (pte++, addr += PAGE_SIZE, addr != end);
  1393. *pmd = __pmd((__pa(start_pte) + PTE_HWTABLE_OFF) | type->prot_l1);
  1394. mb();
  1395. flush_pmd_entry(pmd);
  1396. flush_tlb_all();
  1397. }
  1398. /*
  1399. * It's significantly easier to remap as pages later after all memory is
  1400. * mapped. Everything is sections so all we have to do is split
  1401. */
  1402. static void __init remap_pages(void)
  1403. {
  1404. struct memblock_region *reg;
  1405. for_each_memblock(memory, reg) {
  1406. phys_addr_t phys_start = reg->base;
  1407. phys_addr_t phys_end = reg->base + reg->size;
  1408. unsigned long addr = (unsigned long)__va(phys_start);
  1409. unsigned long end = (unsigned long)__va(phys_end);
  1410. pmd_t *pmd = NULL;
  1411. unsigned long next;
  1412. unsigned long pfn = __phys_to_pfn(phys_start);
  1413. bool fixup = false, end_fixup = false;
  1414. unsigned long saved_start = addr;
  1415. if (phys_start > arm_lowmem_limit)
  1416. break;
  1417. if (phys_end > arm_lowmem_limit)
  1418. end = (unsigned long)__va(arm_lowmem_limit);
  1419. if (phys_start >= phys_end)
  1420. break;
  1421. pmd = pmd_offset(
  1422. pud_offset(pgd_offset(&init_mm, addr), addr), addr);
  1423. #ifndef CONFIG_ARM_LPAE
  1424. if (addr & SECTION_SIZE) {
  1425. fixup = true;
  1426. pmd_empty_section_gap((addr - SECTION_SIZE) & PMD_MASK);
  1427. pmd++;
  1428. }
  1429. if (end & SECTION_SIZE) {
  1430. end_fixup = true;
  1431. pmd_empty_section_gap(end);
  1432. }
  1433. #endif
  1434. do {
  1435. next = addr + SECTION_SIZE;
  1436. if (pmd_none(*pmd) || pmd_bad(*pmd))
  1437. split_pmd(pmd, addr, next, pfn,
  1438. &mem_types[MT_MEMORY]);
  1439. pmd++;
  1440. pfn += SECTION_SIZE >> PAGE_SHIFT;
  1441. } while (addr = next, addr < end);
  1442. if (fixup) {
  1443. /*
  1444. * Put a faulting page table here to avoid detecting no
  1445. * pmd when accessing an odd section boundary. This
  1446. * needs to be faulting to help catch errors and avoid
  1447. * speculation
  1448. */
  1449. pmd = pmd_off_k(saved_start);
  1450. pmd[0] = pmd[1] & ~1;
  1451. }
  1452. if (end_fixup) {
  1453. pmd = pmd_off_k(end);
  1454. pmd[1] = pmd[0] & ~1;
  1455. }
  1456. }
  1457. }
  1458. #else
  1459. static void __init remap_pages(void)
  1460. {
  1461. }
  1462. #endif
  1463. /*
  1464. * paging_init() sets up the page tables, initialises the zone memory
  1465. * maps, and sets up the zero page, bad page and bad page tables.
  1466. */
  1467. void __init paging_init(struct machine_desc *mdesc)
  1468. {
  1469. void *zero_page;
  1470. memblock_set_current_limit(arm_lowmem_limit);
  1471. build_mem_type_table();
  1472. prepare_page_table();
  1473. map_lowmem();
  1474. dma_contiguous_remap();
  1475. remap_pages();
  1476. devicemaps_init(mdesc);
  1477. kmap_init();
  1478. top_pmd = pmd_off_k(0xffff0000);
  1479. /* allocate the zero page. */
  1480. zero_page = early_alloc(PAGE_SIZE);
  1481. bootmem_init();
  1482. empty_zero_page = virt_to_page(zero_page);
  1483. __flush_dcache_page(NULL, empty_zero_page);
  1484. }