mmu.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  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 <linux/sizes.h>
  20. #include <asm/cp15.h>
  21. #include <asm/cputype.h>
  22. #include <asm/sections.h>
  23. #include <asm/cachetype.h>
  24. #include <asm/fixmap.h>
  25. #include <asm/sections.h>
  26. #include <asm/setup.h>
  27. #include <asm/smp_plat.h>
  28. #include <asm/tlb.h>
  29. #include <asm/highmem.h>
  30. #include <asm/system_info.h>
  31. #include <asm/traps.h>
  32. #include <asm/procinfo.h>
  33. #include <asm/memory.h>
  34. #include <asm/mach/arch.h>
  35. #include <asm/mach/map.h>
  36. #include <asm/mach/pci.h>
  37. #include <asm/fixmap.h>
  38. #include "fault.h"
  39. #include "mm.h"
  40. #include "tcm.h"
  41. /*
  42. * empty_zero_page is a special page that is used for
  43. * zero-initialized data and COW.
  44. */
  45. struct page *empty_zero_page;
  46. EXPORT_SYMBOL(empty_zero_page);
  47. /*
  48. * The pmd table for the upper-most set of pages.
  49. */
  50. pmd_t *top_pmd;
  51. pmdval_t user_pmd_table = _PAGE_USER_TABLE;
  52. #define CPOLICY_UNCACHED 0
  53. #define CPOLICY_BUFFERED 1
  54. #define CPOLICY_WRITETHROUGH 2
  55. #define CPOLICY_WRITEBACK 3
  56. #define CPOLICY_WRITEALLOC 4
  57. static unsigned int cachepolicy __initdata = CPOLICY_WRITEBACK;
  58. static unsigned int ecc_mask __initdata = 0;
  59. pgprot_t pgprot_user;
  60. pgprot_t pgprot_kernel;
  61. pgprot_t pgprot_hyp_device;
  62. pgprot_t pgprot_s2;
  63. pgprot_t pgprot_s2_device;
  64. EXPORT_SYMBOL(pgprot_user);
  65. EXPORT_SYMBOL(pgprot_kernel);
  66. struct cachepolicy {
  67. const char policy[16];
  68. unsigned int cr_mask;
  69. pmdval_t pmd;
  70. pteval_t pte;
  71. pteval_t pte_s2;
  72. };
  73. #ifdef CONFIG_ARM_LPAE
  74. #define s2_policy(policy) policy
  75. #else
  76. #define s2_policy(policy) 0
  77. #endif
  78. unsigned long kimage_voffset __ro_after_init;
  79. static struct cachepolicy cache_policies[] __initdata = {
  80. {
  81. .policy = "uncached",
  82. .cr_mask = CR_W|CR_C,
  83. .pmd = PMD_SECT_UNCACHED,
  84. .pte = L_PTE_MT_UNCACHED,
  85. .pte_s2 = s2_policy(L_PTE_S2_MT_UNCACHED),
  86. }, {
  87. .policy = "buffered",
  88. .cr_mask = CR_C,
  89. .pmd = PMD_SECT_BUFFERED,
  90. .pte = L_PTE_MT_BUFFERABLE,
  91. .pte_s2 = s2_policy(L_PTE_S2_MT_UNCACHED),
  92. }, {
  93. .policy = "writethrough",
  94. .cr_mask = 0,
  95. .pmd = PMD_SECT_WT,
  96. .pte = L_PTE_MT_WRITETHROUGH,
  97. .pte_s2 = s2_policy(L_PTE_S2_MT_WRITETHROUGH),
  98. }, {
  99. .policy = "writeback",
  100. .cr_mask = 0,
  101. .pmd = PMD_SECT_WB,
  102. .pte = L_PTE_MT_WRITEBACK,
  103. .pte_s2 = s2_policy(L_PTE_S2_MT_WRITEBACK),
  104. }, {
  105. .policy = "writealloc",
  106. .cr_mask = 0,
  107. .pmd = PMD_SECT_WBWA,
  108. .pte = L_PTE_MT_WRITEALLOC,
  109. .pte_s2 = s2_policy(L_PTE_S2_MT_WRITEBACK),
  110. }
  111. };
  112. #ifdef CONFIG_CPU_CP15
  113. static unsigned long initial_pmd_value __initdata = 0;
  114. /*
  115. * Initialise the cache_policy variable with the initial state specified
  116. * via the "pmd" value. This is used to ensure that on ARMv6 and later,
  117. * the C code sets the page tables up with the same policy as the head
  118. * assembly code, which avoids an illegal state where the TLBs can get
  119. * confused. See comments in early_cachepolicy() for more information.
  120. */
  121. void __init init_default_cache_policy(unsigned long pmd)
  122. {
  123. int i;
  124. initial_pmd_value = pmd;
  125. pmd &= PMD_SECT_CACHE_MASK;
  126. for (i = 0; i < ARRAY_SIZE(cache_policies); i++)
  127. if (cache_policies[i].pmd == pmd) {
  128. cachepolicy = i;
  129. break;
  130. }
  131. if (i == ARRAY_SIZE(cache_policies))
  132. pr_err("ERROR: could not find cache policy\n");
  133. }
  134. /*
  135. * These are useful for identifying cache coherency problems by allowing
  136. * the cache or the cache and writebuffer to be turned off. (Note: the
  137. * write buffer should not be on and the cache off).
  138. */
  139. static int __init early_cachepolicy(char *p)
  140. {
  141. int i, selected = -1;
  142. for (i = 0; i < ARRAY_SIZE(cache_policies); i++) {
  143. int len = strlen(cache_policies[i].policy);
  144. if (memcmp(p, cache_policies[i].policy, len) == 0) {
  145. selected = i;
  146. break;
  147. }
  148. }
  149. if (selected == -1)
  150. pr_err("ERROR: unknown or unsupported cache policy\n");
  151. /*
  152. * This restriction is partly to do with the way we boot; it is
  153. * unpredictable to have memory mapped using two different sets of
  154. * memory attributes (shared, type, and cache attribs). We can not
  155. * change these attributes once the initial assembly has setup the
  156. * page tables.
  157. */
  158. if (cpu_architecture() >= CPU_ARCH_ARMv6 && selected != cachepolicy) {
  159. pr_warn("Only cachepolicy=%s supported on ARMv6 and later\n",
  160. cache_policies[cachepolicy].policy);
  161. return 0;
  162. }
  163. if (selected != cachepolicy) {
  164. unsigned long cr = __clear_cr(cache_policies[selected].cr_mask);
  165. cachepolicy = selected;
  166. flush_cache_all();
  167. set_cr(cr);
  168. }
  169. return 0;
  170. }
  171. early_param("cachepolicy", early_cachepolicy);
  172. static int __init early_nocache(char *__unused)
  173. {
  174. char *p = "buffered";
  175. pr_warn("nocache is deprecated; use cachepolicy=%s\n", p);
  176. early_cachepolicy(p);
  177. return 0;
  178. }
  179. early_param("nocache", early_nocache);
  180. static int __init early_nowrite(char *__unused)
  181. {
  182. char *p = "uncached";
  183. pr_warn("nowb is deprecated; use cachepolicy=%s\n", p);
  184. early_cachepolicy(p);
  185. return 0;
  186. }
  187. early_param("nowb", early_nowrite);
  188. #ifndef CONFIG_ARM_LPAE
  189. static int __init early_ecc(char *p)
  190. {
  191. if (memcmp(p, "on", 2) == 0)
  192. ecc_mask = PMD_PROTECTION;
  193. else if (memcmp(p, "off", 3) == 0)
  194. ecc_mask = 0;
  195. return 0;
  196. }
  197. early_param("ecc", early_ecc);
  198. #endif
  199. #else /* ifdef CONFIG_CPU_CP15 */
  200. static int __init early_cachepolicy(char *p)
  201. {
  202. pr_warn("cachepolicy kernel parameter not supported without cp15\n");
  203. }
  204. early_param("cachepolicy", early_cachepolicy);
  205. static int __init noalign_setup(char *__unused)
  206. {
  207. pr_warn("noalign kernel parameter not supported without cp15\n");
  208. }
  209. __setup("noalign", noalign_setup);
  210. #endif /* ifdef CONFIG_CPU_CP15 / else */
  211. #define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
  212. #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
  213. #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
  214. static struct mem_type mem_types[] __ro_after_init = {
  215. [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
  216. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
  217. L_PTE_SHARED,
  218. .prot_pte_s2 = s2_policy(PROT_PTE_S2_DEVICE) |
  219. s2_policy(L_PTE_S2_MT_DEV_SHARED) |
  220. L_PTE_SHARED,
  221. .prot_l1 = PMD_TYPE_TABLE,
  222. .prot_sect = PROT_SECT_DEVICE | PMD_SECT_S,
  223. .domain = DOMAIN_IO,
  224. },
  225. [MT_DEVICE_NONSHARED] = { /* ARMv6 non-shared device */
  226. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_NONSHARED,
  227. .prot_l1 = PMD_TYPE_TABLE,
  228. .prot_sect = PROT_SECT_DEVICE,
  229. .domain = DOMAIN_IO,
  230. },
  231. [MT_DEVICE_CACHED] = { /* ioremap_cached */
  232. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_CACHED,
  233. .prot_l1 = PMD_TYPE_TABLE,
  234. .prot_sect = PROT_SECT_DEVICE | PMD_SECT_WB,
  235. .domain = DOMAIN_IO,
  236. },
  237. [MT_DEVICE_WC] = { /* ioremap_wc */
  238. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_WC,
  239. .prot_l1 = PMD_TYPE_TABLE,
  240. .prot_sect = PROT_SECT_DEVICE,
  241. .domain = DOMAIN_IO,
  242. },
  243. [MT_UNCACHED] = {
  244. .prot_pte = PROT_PTE_DEVICE,
  245. .prot_l1 = PMD_TYPE_TABLE,
  246. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  247. .domain = DOMAIN_IO,
  248. },
  249. [MT_CACHECLEAN] = {
  250. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  251. .domain = DOMAIN_KERNEL,
  252. },
  253. #ifndef CONFIG_ARM_LPAE
  254. [MT_MINICLEAN] = {
  255. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
  256. .domain = DOMAIN_KERNEL,
  257. },
  258. #endif
  259. [MT_LOW_VECTORS] = {
  260. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  261. L_PTE_RDONLY,
  262. .prot_l1 = PMD_TYPE_TABLE,
  263. .domain = DOMAIN_VECTORS,
  264. },
  265. [MT_HIGH_VECTORS] = {
  266. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  267. L_PTE_USER | L_PTE_RDONLY,
  268. .prot_l1 = PMD_TYPE_TABLE,
  269. .domain = DOMAIN_VECTORS,
  270. },
  271. [MT_MEMORY_RWX] = {
  272. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
  273. .prot_l1 = PMD_TYPE_TABLE,
  274. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  275. .domain = DOMAIN_KERNEL,
  276. },
  277. [MT_MEMORY_RW] = {
  278. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  279. L_PTE_XN,
  280. .prot_l1 = PMD_TYPE_TABLE,
  281. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  282. .domain = DOMAIN_KERNEL,
  283. },
  284. [MT_ROM] = {
  285. .prot_sect = PMD_TYPE_SECT,
  286. .domain = DOMAIN_KERNEL,
  287. },
  288. [MT_MEMORY_RWX_NONCACHED] = {
  289. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  290. L_PTE_MT_BUFFERABLE,
  291. .prot_l1 = PMD_TYPE_TABLE,
  292. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  293. .domain = DOMAIN_KERNEL,
  294. },
  295. [MT_MEMORY_RW_DTCM] = {
  296. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  297. L_PTE_XN,
  298. .prot_l1 = PMD_TYPE_TABLE,
  299. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  300. .domain = DOMAIN_KERNEL,
  301. },
  302. [MT_MEMORY_RWX_ITCM] = {
  303. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
  304. .prot_l1 = PMD_TYPE_TABLE,
  305. .domain = DOMAIN_KERNEL,
  306. },
  307. [MT_MEMORY_RW_SO] = {
  308. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  309. L_PTE_MT_UNCACHED | L_PTE_XN,
  310. .prot_l1 = PMD_TYPE_TABLE,
  311. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
  312. PMD_SECT_UNCACHED | PMD_SECT_XN,
  313. .domain = DOMAIN_KERNEL,
  314. },
  315. [MT_MEMORY_DMA_READY] = {
  316. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  317. L_PTE_XN,
  318. .prot_l1 = PMD_TYPE_TABLE,
  319. .domain = DOMAIN_KERNEL,
  320. },
  321. };
  322. const struct mem_type *get_mem_type(unsigned int type)
  323. {
  324. return type < ARRAY_SIZE(mem_types) ? &mem_types[type] : NULL;
  325. }
  326. EXPORT_SYMBOL(get_mem_type);
  327. static pte_t *(*pte_offset_fixmap)(pmd_t *dir, unsigned long addr);
  328. static pte_t bm_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS]
  329. __aligned(PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE) __initdata;
  330. static pte_t * __init pte_offset_early_fixmap(pmd_t *dir, unsigned long addr)
  331. {
  332. return &bm_pte[pte_index(addr)];
  333. }
  334. static pte_t *pte_offset_late_fixmap(pmd_t *dir, unsigned long addr)
  335. {
  336. return pte_offset_kernel(dir, addr);
  337. }
  338. static inline pmd_t * __init fixmap_pmd(unsigned long addr)
  339. {
  340. pgd_t *pgd = pgd_offset_k(addr);
  341. pud_t *pud = pud_offset(pgd, addr);
  342. pmd_t *pmd = pmd_offset(pud, addr);
  343. return pmd;
  344. }
  345. void __init early_fixmap_init(void)
  346. {
  347. pmd_t *pmd;
  348. /*
  349. * The early fixmap range spans multiple pmds, for which
  350. * we are not prepared:
  351. */
  352. BUILD_BUG_ON((__fix_to_virt(__end_of_early_ioremap_region) >> PMD_SHIFT)
  353. != FIXADDR_TOP >> PMD_SHIFT);
  354. pmd = fixmap_pmd(FIXADDR_TOP);
  355. pmd_populate_kernel(&init_mm, pmd, bm_pte);
  356. pte_offset_fixmap = pte_offset_early_fixmap;
  357. }
  358. /*
  359. * To avoid TLB flush broadcasts, this uses local_flush_tlb_kernel_range().
  360. * As a result, this can only be called with preemption disabled, as under
  361. * stop_machine().
  362. */
  363. void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
  364. {
  365. unsigned long vaddr = __fix_to_virt(idx);
  366. pte_t *pte = pte_offset_fixmap(pmd_off_k(vaddr), vaddr);
  367. /* Make sure fixmap region does not exceed available allocation. */
  368. BUILD_BUG_ON(FIXADDR_START + (__end_of_fixed_addresses * PAGE_SIZE) >
  369. FIXADDR_END);
  370. BUG_ON(idx >= __end_of_fixed_addresses);
  371. /* we only support device mappings until pgprot_kernel has been set */
  372. if (WARN_ON(pgprot_val(prot) != pgprot_val(FIXMAP_PAGE_IO) &&
  373. pgprot_val(pgprot_kernel) == 0))
  374. return;
  375. if (pgprot_val(prot))
  376. set_pte_at(NULL, vaddr, pte,
  377. pfn_pte(phys >> PAGE_SHIFT, prot));
  378. else
  379. pte_clear(NULL, vaddr, pte);
  380. local_flush_tlb_kernel_range(vaddr, vaddr + PAGE_SIZE);
  381. }
  382. /*
  383. * Adjust the PMD section entries according to the CPU in use.
  384. */
  385. static void __init build_mem_type_table(void)
  386. {
  387. struct cachepolicy *cp;
  388. unsigned int cr = get_cr();
  389. pteval_t user_pgprot, kern_pgprot, vecs_pgprot;
  390. pteval_t hyp_device_pgprot, s2_pgprot, s2_device_pgprot;
  391. int cpu_arch = cpu_architecture();
  392. int i;
  393. if (cpu_arch < CPU_ARCH_ARMv6) {
  394. #if defined(CONFIG_CPU_DCACHE_DISABLE)
  395. if (cachepolicy > CPOLICY_BUFFERED)
  396. cachepolicy = CPOLICY_BUFFERED;
  397. #elif defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
  398. if (cachepolicy > CPOLICY_WRITETHROUGH)
  399. cachepolicy = CPOLICY_WRITETHROUGH;
  400. #endif
  401. }
  402. if (cpu_arch < CPU_ARCH_ARMv5) {
  403. if (cachepolicy >= CPOLICY_WRITEALLOC)
  404. cachepolicy = CPOLICY_WRITEBACK;
  405. ecc_mask = 0;
  406. }
  407. if (is_smp()) {
  408. if (cachepolicy != CPOLICY_WRITEALLOC) {
  409. pr_warn("Forcing write-allocate cache policy for SMP\n");
  410. cachepolicy = CPOLICY_WRITEALLOC;
  411. }
  412. if (!(initial_pmd_value & PMD_SECT_S)) {
  413. pr_warn("Forcing shared mappings for SMP\n");
  414. initial_pmd_value |= PMD_SECT_S;
  415. }
  416. }
  417. /*
  418. * Strip out features not present on earlier architectures.
  419. * Pre-ARMv5 CPUs don't have TEX bits. Pre-ARMv6 CPUs or those
  420. * without extended page tables don't have the 'Shared' bit.
  421. */
  422. if (cpu_arch < CPU_ARCH_ARMv5)
  423. for (i = 0; i < ARRAY_SIZE(mem_types); i++)
  424. mem_types[i].prot_sect &= ~PMD_SECT_TEX(7);
  425. if ((cpu_arch < CPU_ARCH_ARMv6 || !(cr & CR_XP)) && !cpu_is_xsc3())
  426. for (i = 0; i < ARRAY_SIZE(mem_types); i++)
  427. mem_types[i].prot_sect &= ~PMD_SECT_S;
  428. /*
  429. * ARMv5 and lower, bit 4 must be set for page tables (was: cache
  430. * "update-able on write" bit on ARM610). However, Xscale and
  431. * Xscale3 require this bit to be cleared.
  432. */
  433. if (cpu_is_xscale_family()) {
  434. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  435. mem_types[i].prot_sect &= ~PMD_BIT4;
  436. mem_types[i].prot_l1 &= ~PMD_BIT4;
  437. }
  438. } else if (cpu_arch < CPU_ARCH_ARMv6) {
  439. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  440. if (mem_types[i].prot_l1)
  441. mem_types[i].prot_l1 |= PMD_BIT4;
  442. if (mem_types[i].prot_sect)
  443. mem_types[i].prot_sect |= PMD_BIT4;
  444. }
  445. }
  446. /*
  447. * Mark the device areas according to the CPU/architecture.
  448. */
  449. if (cpu_is_xsc3() || (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP))) {
  450. if (!cpu_is_xsc3()) {
  451. /*
  452. * Mark device regions on ARMv6+ as execute-never
  453. * to prevent speculative instruction fetches.
  454. */
  455. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
  456. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
  457. mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
  458. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
  459. /* Also setup NX memory mapping */
  460. mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
  461. }
  462. if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
  463. /*
  464. * For ARMv7 with TEX remapping,
  465. * - shared device is SXCB=1100
  466. * - nonshared device is SXCB=0100
  467. * - write combine device mem is SXCB=0001
  468. * (Uncached Normal memory)
  469. */
  470. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_TEX(1);
  471. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_TEX(1);
  472. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_BUFFERABLE;
  473. } else if (cpu_is_xsc3()) {
  474. /*
  475. * For Xscale3,
  476. * - shared device is TEXCB=00101
  477. * - nonshared device is TEXCB=01000
  478. * - write combine device mem is TEXCB=00100
  479. * (Inner/Outer Uncacheable in xsc3 parlance)
  480. */
  481. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_TEX(1) | PMD_SECT_BUFFERED;
  482. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_TEX(2);
  483. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_TEX(1);
  484. } else {
  485. /*
  486. * For ARMv6 and ARMv7 without TEX remapping,
  487. * - shared device is TEXCB=00001
  488. * - nonshared device is TEXCB=01000
  489. * - write combine device mem is TEXCB=00100
  490. * (Uncached Normal in ARMv6 parlance).
  491. */
  492. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_BUFFERED;
  493. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_TEX(2);
  494. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_TEX(1);
  495. }
  496. } else {
  497. /*
  498. * On others, write combining is "Uncached/Buffered"
  499. */
  500. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_BUFFERABLE;
  501. }
  502. /*
  503. * Now deal with the memory-type mappings
  504. */
  505. cp = &cache_policies[cachepolicy];
  506. vecs_pgprot = kern_pgprot = user_pgprot = cp->pte;
  507. s2_pgprot = cp->pte_s2;
  508. hyp_device_pgprot = mem_types[MT_DEVICE].prot_pte;
  509. s2_device_pgprot = mem_types[MT_DEVICE].prot_pte_s2;
  510. #ifndef CONFIG_ARM_LPAE
  511. /*
  512. * We don't use domains on ARMv6 (since this causes problems with
  513. * v6/v7 kernels), so we must use a separate memory type for user
  514. * r/o, kernel r/w to map the vectors page.
  515. */
  516. if (cpu_arch == CPU_ARCH_ARMv6)
  517. vecs_pgprot |= L_PTE_MT_VECTORS;
  518. /*
  519. * Check is it with support for the PXN bit
  520. * in the Short-descriptor translation table format descriptors.
  521. */
  522. if (cpu_arch == CPU_ARCH_ARMv7 &&
  523. (read_cpuid_ext(CPUID_EXT_MMFR0) & 0xF) >= 4) {
  524. user_pmd_table |= PMD_PXNTABLE;
  525. }
  526. #endif
  527. /*
  528. * ARMv6 and above have extended page tables.
  529. */
  530. if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
  531. #ifndef CONFIG_ARM_LPAE
  532. /*
  533. * Mark cache clean areas and XIP ROM read only
  534. * from SVC mode and no access from userspace.
  535. */
  536. mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  537. mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  538. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  539. #endif
  540. /*
  541. * If the initial page tables were created with the S bit
  542. * set, then we need to do the same here for the same
  543. * reasons given in early_cachepolicy().
  544. */
  545. if (initial_pmd_value & PMD_SECT_S) {
  546. user_pgprot |= L_PTE_SHARED;
  547. kern_pgprot |= L_PTE_SHARED;
  548. vecs_pgprot |= L_PTE_SHARED;
  549. s2_pgprot |= L_PTE_SHARED;
  550. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_S;
  551. mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
  552. mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
  553. mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
  554. mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
  555. mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
  556. mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
  557. mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
  558. mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
  559. mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
  560. mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
  561. }
  562. }
  563. /*
  564. * Non-cacheable Normal - intended for memory areas that must
  565. * not cause dirty cache line writebacks when used
  566. */
  567. if (cpu_arch >= CPU_ARCH_ARMv6) {
  568. if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
  569. /* Non-cacheable Normal is XCB = 001 */
  570. mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
  571. PMD_SECT_BUFFERED;
  572. } else {
  573. /* For both ARMv6 and non-TEX-remapping ARMv7 */
  574. mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
  575. PMD_SECT_TEX(1);
  576. }
  577. } else {
  578. mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
  579. }
  580. #ifdef CONFIG_ARM_LPAE
  581. /*
  582. * Do not generate access flag faults for the kernel mappings.
  583. */
  584. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  585. mem_types[i].prot_pte |= PTE_EXT_AF;
  586. if (mem_types[i].prot_sect)
  587. mem_types[i].prot_sect |= PMD_SECT_AF;
  588. }
  589. kern_pgprot |= PTE_EXT_AF;
  590. vecs_pgprot |= PTE_EXT_AF;
  591. /*
  592. * Set PXN for user mappings
  593. */
  594. user_pgprot |= PTE_EXT_PXN;
  595. #endif
  596. for (i = 0; i < 16; i++) {
  597. pteval_t v = pgprot_val(protection_map[i]);
  598. protection_map[i] = __pgprot(v | user_pgprot);
  599. }
  600. mem_types[MT_LOW_VECTORS].prot_pte |= vecs_pgprot;
  601. mem_types[MT_HIGH_VECTORS].prot_pte |= vecs_pgprot;
  602. pgprot_user = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | user_pgprot);
  603. pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
  604. L_PTE_DIRTY | kern_pgprot);
  605. pgprot_s2 = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | s2_pgprot);
  606. pgprot_s2_device = __pgprot(s2_device_pgprot);
  607. pgprot_hyp_device = __pgprot(hyp_device_pgprot);
  608. mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
  609. mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
  610. mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
  611. mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
  612. mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
  613. mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
  614. mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
  615. mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
  616. mem_types[MT_ROM].prot_sect |= cp->pmd;
  617. switch (cp->pmd) {
  618. case PMD_SECT_WT:
  619. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
  620. break;
  621. case PMD_SECT_WB:
  622. case PMD_SECT_WBWA:
  623. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
  624. break;
  625. }
  626. pr_info("Memory policy: %sData cache %s\n",
  627. ecc_mask ? "ECC enabled, " : "", cp->policy);
  628. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  629. struct mem_type *t = &mem_types[i];
  630. if (t->prot_l1)
  631. t->prot_l1 |= PMD_DOMAIN(t->domain);
  632. if (t->prot_sect)
  633. t->prot_sect |= PMD_DOMAIN(t->domain);
  634. }
  635. }
  636. #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
  637. pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  638. unsigned long size, pgprot_t vma_prot)
  639. {
  640. if (!pfn_valid(pfn))
  641. return pgprot_noncached(vma_prot);
  642. else if (file->f_flags & O_SYNC)
  643. return pgprot_writecombine(vma_prot);
  644. return vma_prot;
  645. }
  646. EXPORT_SYMBOL(phys_mem_access_prot);
  647. #endif
  648. #define vectors_base() (vectors_high() ? 0xffff0000 : 0)
  649. static void __init *early_alloc_aligned(unsigned long sz, unsigned long align)
  650. {
  651. void *ptr = __va(memblock_alloc(sz, align));
  652. memset(ptr, 0, sz);
  653. return ptr;
  654. }
  655. static void __init *early_alloc(unsigned long sz)
  656. {
  657. return early_alloc_aligned(sz, sz);
  658. }
  659. static void *__init late_alloc(unsigned long sz)
  660. {
  661. void *ptr = (void *)__get_free_pages(PGALLOC_GFP, get_order(sz));
  662. if (!ptr || !pgtable_page_ctor(virt_to_page(ptr)))
  663. BUG();
  664. return ptr;
  665. }
  666. static pte_t * __init arm_pte_alloc(pmd_t *pmd, unsigned long addr,
  667. unsigned long prot,
  668. void *(*alloc)(unsigned long sz))
  669. {
  670. if (pmd_none(*pmd)) {
  671. pte_t *pte = alloc(PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE);
  672. __pmd_populate(pmd, __pa(pte), prot);
  673. }
  674. BUG_ON(pmd_bad(*pmd));
  675. return pte_offset_kernel(pmd, addr);
  676. }
  677. static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr,
  678. unsigned long prot)
  679. {
  680. return arm_pte_alloc(pmd, addr, prot, early_alloc);
  681. }
  682. static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
  683. unsigned long end, unsigned long pfn,
  684. const struct mem_type *type,
  685. void *(*alloc)(unsigned long sz),
  686. bool ng)
  687. {
  688. pte_t *pte = arm_pte_alloc(pmd, addr, type->prot_l1, alloc);
  689. do {
  690. set_pte_ext(pte, pfn_pte(pfn, __pgprot(type->prot_pte)),
  691. ng ? PTE_EXT_NG : 0);
  692. pfn++;
  693. } while (pte++, addr += PAGE_SIZE, addr != end);
  694. }
  695. static void __init __map_init_section(pmd_t *pmd, unsigned long addr,
  696. unsigned long end, phys_addr_t phys,
  697. const struct mem_type *type, bool ng)
  698. {
  699. pmd_t *p = pmd;
  700. #ifndef CONFIG_ARM_LPAE
  701. /*
  702. * In classic MMU format, puds and pmds are folded in to
  703. * the pgds. pmd_offset gives the PGD entry. PGDs refer to a
  704. * group of L1 entries making up one logical pointer to
  705. * an L2 table (2MB), where as PMDs refer to the individual
  706. * L1 entries (1MB). Hence increment to get the correct
  707. * offset for odd 1MB sections.
  708. * (See arch/arm/include/asm/pgtable-2level.h)
  709. */
  710. if (addr & SECTION_SIZE)
  711. pmd++;
  712. #endif
  713. do {
  714. *pmd = __pmd(phys | type->prot_sect | (ng ? PMD_SECT_nG : 0));
  715. phys += SECTION_SIZE;
  716. } while (pmd++, addr += SECTION_SIZE, addr != end);
  717. flush_pmd_entry(p);
  718. }
  719. static void __init alloc_init_pmd(pud_t *pud, unsigned long addr,
  720. unsigned long end, phys_addr_t phys,
  721. const struct mem_type *type,
  722. void *(*alloc)(unsigned long sz), bool ng)
  723. {
  724. pmd_t *pmd = pmd_offset(pud, addr);
  725. unsigned long next;
  726. do {
  727. /*
  728. * With LPAE, we must loop over to map
  729. * all the pmds for the given range.
  730. */
  731. next = pmd_addr_end(addr, end);
  732. /*
  733. * Try a section mapping - addr, next and phys must all be
  734. * aligned to a section boundary.
  735. */
  736. if (type->prot_sect &&
  737. ((addr | next | phys) & ~SECTION_MASK) == 0) {
  738. __map_init_section(pmd, addr, next, phys, type, ng);
  739. } else {
  740. alloc_init_pte(pmd, addr, next,
  741. __phys_to_pfn(phys), type, alloc, ng);
  742. }
  743. phys += next - addr;
  744. } while (pmd++, addr = next, addr != end);
  745. }
  746. static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr,
  747. unsigned long end, phys_addr_t phys,
  748. const struct mem_type *type,
  749. void *(*alloc)(unsigned long sz), bool ng)
  750. {
  751. pud_t *pud = pud_offset(pgd, addr);
  752. unsigned long next;
  753. do {
  754. next = pud_addr_end(addr, end);
  755. alloc_init_pmd(pud, addr, next, phys, type, alloc, ng);
  756. phys += next - addr;
  757. } while (pud++, addr = next, addr != end);
  758. }
  759. #ifndef CONFIG_ARM_LPAE
  760. static void __init create_36bit_mapping(struct mm_struct *mm,
  761. struct map_desc *md,
  762. const struct mem_type *type,
  763. bool ng)
  764. {
  765. unsigned long addr, length, end;
  766. phys_addr_t phys;
  767. pgd_t *pgd;
  768. addr = md->virtual;
  769. phys = __pfn_to_phys(md->pfn);
  770. length = PAGE_ALIGN(md->length);
  771. if (!(cpu_architecture() >= CPU_ARCH_ARMv6 || cpu_is_xsc3())) {
  772. pr_err("MM: CPU does not support supersection mapping for 0x%08llx at 0x%08lx\n",
  773. (long long)__pfn_to_phys((u64)md->pfn), addr);
  774. return;
  775. }
  776. /* N.B. ARMv6 supersections are only defined to work with domain 0.
  777. * Since domain assignments can in fact be arbitrary, the
  778. * 'domain == 0' check below is required to insure that ARMv6
  779. * supersections are only allocated for domain 0 regardless
  780. * of the actual domain assignments in use.
  781. */
  782. if (type->domain) {
  783. pr_err("MM: invalid domain in supersection mapping for 0x%08llx at 0x%08lx\n",
  784. (long long)__pfn_to_phys((u64)md->pfn), addr);
  785. return;
  786. }
  787. if ((addr | length | __pfn_to_phys(md->pfn)) & ~SUPERSECTION_MASK) {
  788. pr_err("MM: cannot create mapping for 0x%08llx at 0x%08lx invalid alignment\n",
  789. (long long)__pfn_to_phys((u64)md->pfn), addr);
  790. return;
  791. }
  792. /*
  793. * Shift bits [35:32] of address into bits [23:20] of PMD
  794. * (See ARMv6 spec).
  795. */
  796. phys |= (((md->pfn >> (32 - PAGE_SHIFT)) & 0xF) << 20);
  797. pgd = pgd_offset(mm, addr);
  798. end = addr + length;
  799. do {
  800. pud_t *pud = pud_offset(pgd, addr);
  801. pmd_t *pmd = pmd_offset(pud, addr);
  802. int i;
  803. for (i = 0; i < 16; i++)
  804. *pmd++ = __pmd(phys | type->prot_sect | PMD_SECT_SUPER |
  805. (ng ? PMD_SECT_nG : 0));
  806. addr += SUPERSECTION_SIZE;
  807. phys += SUPERSECTION_SIZE;
  808. pgd += SUPERSECTION_SIZE >> PGDIR_SHIFT;
  809. } while (addr != end);
  810. }
  811. #endif /* !CONFIG_ARM_LPAE */
  812. static void __init __create_mapping(struct mm_struct *mm, struct map_desc *md,
  813. void *(*alloc)(unsigned long sz),
  814. bool ng)
  815. {
  816. unsigned long addr, length, end;
  817. phys_addr_t phys;
  818. const struct mem_type *type;
  819. pgd_t *pgd;
  820. type = &mem_types[md->type];
  821. #ifndef CONFIG_ARM_LPAE
  822. /*
  823. * Catch 36-bit addresses
  824. */
  825. if (md->pfn >= 0x100000) {
  826. create_36bit_mapping(mm, md, type, ng);
  827. return;
  828. }
  829. #endif
  830. addr = md->virtual & PAGE_MASK;
  831. phys = __pfn_to_phys(md->pfn);
  832. length = PAGE_ALIGN(md->length + (md->virtual & ~PAGE_MASK));
  833. if (type->prot_l1 == 0 && ((addr | phys | length) & ~SECTION_MASK)) {
  834. pr_warn("BUG: map for 0x%08llx at 0x%08lx can not be mapped using pages, ignoring.\n",
  835. (long long)__pfn_to_phys(md->pfn), addr);
  836. return;
  837. }
  838. pgd = pgd_offset(mm, addr);
  839. end = addr + length;
  840. do {
  841. unsigned long next = pgd_addr_end(addr, end);
  842. alloc_init_pud(pgd, addr, next, phys, type, alloc, ng);
  843. phys += next - addr;
  844. addr = next;
  845. } while (pgd++, addr != end);
  846. }
  847. /*
  848. * Create the page directory entries and any necessary
  849. * page tables for the mapping specified by `md'. We
  850. * are able to cope here with varying sizes and address
  851. * offsets, and we take full advantage of sections and
  852. * supersections.
  853. */
  854. static void __init create_mapping(struct map_desc *md)
  855. {
  856. if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) {
  857. pr_warn("BUG: not creating mapping for 0x%08llx at 0x%08lx in user region\n",
  858. (long long)__pfn_to_phys((u64)md->pfn), md->virtual);
  859. return;
  860. }
  861. if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
  862. md->virtual >= PAGE_OFFSET && md->virtual < FIXADDR_START &&
  863. (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
  864. pr_warn("BUG: mapping for 0x%08llx at 0x%08lx out of vmalloc space\n",
  865. (long long)__pfn_to_phys((u64)md->pfn), md->virtual);
  866. }
  867. __create_mapping(&init_mm, md, early_alloc, false);
  868. }
  869. void __init create_mapping_late(struct mm_struct *mm, struct map_desc *md,
  870. bool ng)
  871. {
  872. #ifdef CONFIG_ARM_LPAE
  873. pud_t *pud = pud_alloc(mm, pgd_offset(mm, md->virtual), md->virtual);
  874. if (WARN_ON(!pud))
  875. return;
  876. pmd_alloc(mm, pud, 0);
  877. #endif
  878. __create_mapping(mm, md, late_alloc, ng);
  879. }
  880. /*
  881. * Create the architecture specific mappings
  882. */
  883. void __init iotable_init(struct map_desc *io_desc, int nr)
  884. {
  885. struct map_desc *md;
  886. struct vm_struct *vm;
  887. struct static_vm *svm;
  888. if (!nr)
  889. return;
  890. svm = early_alloc_aligned(sizeof(*svm) * nr, __alignof__(*svm));
  891. for (md = io_desc; nr; md++, nr--) {
  892. create_mapping(md);
  893. vm = &svm->vm;
  894. vm->addr = (void *)(md->virtual & PAGE_MASK);
  895. vm->size = PAGE_ALIGN(md->length + (md->virtual & ~PAGE_MASK));
  896. vm->phys_addr = __pfn_to_phys(md->pfn);
  897. vm->flags = VM_IOREMAP | VM_ARM_STATIC_MAPPING;
  898. vm->flags |= VM_ARM_MTYPE(md->type);
  899. vm->caller = iotable_init;
  900. add_static_vm_early(svm++);
  901. }
  902. }
  903. void __init vm_reserve_area_early(unsigned long addr, unsigned long size,
  904. void *caller)
  905. {
  906. struct vm_struct *vm;
  907. struct static_vm *svm;
  908. svm = early_alloc_aligned(sizeof(*svm), __alignof__(*svm));
  909. vm = &svm->vm;
  910. vm->addr = (void *)addr;
  911. vm->size = size;
  912. vm->flags = VM_IOREMAP | VM_ARM_EMPTY_MAPPING;
  913. vm->caller = caller;
  914. add_static_vm_early(svm);
  915. }
  916. #ifndef CONFIG_ARM_LPAE
  917. /*
  918. * The Linux PMD is made of two consecutive section entries covering 2MB
  919. * (see definition in include/asm/pgtable-2level.h). However a call to
  920. * create_mapping() may optimize static mappings by using individual
  921. * 1MB section mappings. This leaves the actual PMD potentially half
  922. * initialized if the top or bottom section entry isn't used, leaving it
  923. * open to problems if a subsequent ioremap() or vmalloc() tries to use
  924. * the virtual space left free by that unused section entry.
  925. *
  926. * Let's avoid the issue by inserting dummy vm entries covering the unused
  927. * PMD halves once the static mappings are in place.
  928. */
  929. static void __init pmd_empty_section_gap(unsigned long addr)
  930. {
  931. vm_reserve_area_early(addr, SECTION_SIZE, pmd_empty_section_gap);
  932. }
  933. static void __init fill_pmd_gaps(void)
  934. {
  935. struct static_vm *svm;
  936. struct vm_struct *vm;
  937. unsigned long addr, next = 0;
  938. pmd_t *pmd;
  939. list_for_each_entry(svm, &static_vmlist, list) {
  940. vm = &svm->vm;
  941. addr = (unsigned long)vm->addr;
  942. if (addr < next)
  943. continue;
  944. /*
  945. * Check if this vm starts on an odd section boundary.
  946. * If so and the first section entry for this PMD is free
  947. * then we block the corresponding virtual address.
  948. */
  949. if ((addr & ~PMD_MASK) == SECTION_SIZE) {
  950. pmd = pmd_off_k(addr);
  951. if (pmd_none(*pmd))
  952. pmd_empty_section_gap(addr & PMD_MASK);
  953. }
  954. /*
  955. * Then check if this vm ends on an odd section boundary.
  956. * If so and the second section entry for this PMD is empty
  957. * then we block the corresponding virtual address.
  958. */
  959. addr += vm->size;
  960. if ((addr & ~PMD_MASK) == SECTION_SIZE) {
  961. pmd = pmd_off_k(addr) + 1;
  962. if (pmd_none(*pmd))
  963. pmd_empty_section_gap(addr);
  964. }
  965. /* no need to look at any vm entry until we hit the next PMD */
  966. next = (addr + PMD_SIZE - 1) & PMD_MASK;
  967. }
  968. }
  969. #else
  970. #define fill_pmd_gaps() do { } while (0)
  971. #endif
  972. #if defined(CONFIG_PCI) && !defined(CONFIG_NEED_MACH_IO_H)
  973. static void __init pci_reserve_io(void)
  974. {
  975. struct static_vm *svm;
  976. svm = find_static_vm_vaddr((void *)PCI_IO_VIRT_BASE);
  977. if (svm)
  978. return;
  979. vm_reserve_area_early(PCI_IO_VIRT_BASE, SZ_2M, pci_reserve_io);
  980. }
  981. #else
  982. #define pci_reserve_io() do { } while (0)
  983. #endif
  984. #ifdef CONFIG_DEBUG_LL
  985. void __init debug_ll_io_init(void)
  986. {
  987. struct map_desc map;
  988. debug_ll_addr(&map.pfn, &map.virtual);
  989. if (!map.pfn || !map.virtual)
  990. return;
  991. map.pfn = __phys_to_pfn(map.pfn);
  992. map.virtual &= PAGE_MASK;
  993. map.length = PAGE_SIZE;
  994. map.type = MT_DEVICE;
  995. iotable_init(&map, 1);
  996. }
  997. #endif
  998. static void * __initdata vmalloc_min =
  999. (void *)(VMALLOC_END - (240 << 20) - VMALLOC_OFFSET);
  1000. /*
  1001. * vmalloc=size forces the vmalloc area to be exactly 'size'
  1002. * bytes. This can be used to increase (or decrease) the vmalloc
  1003. * area - the default is 240m.
  1004. */
  1005. static int __init early_vmalloc(char *arg)
  1006. {
  1007. unsigned long vmalloc_reserve = memparse(arg, NULL);
  1008. if (vmalloc_reserve < SZ_16M) {
  1009. vmalloc_reserve = SZ_16M;
  1010. pr_warn("vmalloc area too small, limiting to %luMB\n",
  1011. vmalloc_reserve >> 20);
  1012. }
  1013. if (vmalloc_reserve > VMALLOC_END - (PAGE_OFFSET + SZ_32M)) {
  1014. vmalloc_reserve = VMALLOC_END - (PAGE_OFFSET + SZ_32M);
  1015. pr_warn("vmalloc area is too big, limiting to %luMB\n",
  1016. vmalloc_reserve >> 20);
  1017. }
  1018. vmalloc_min = (void *)(VMALLOC_END - vmalloc_reserve);
  1019. return 0;
  1020. }
  1021. early_param("vmalloc", early_vmalloc);
  1022. phys_addr_t arm_lowmem_limit __initdata = 0;
  1023. void __init adjust_lowmem_bounds(void)
  1024. {
  1025. phys_addr_t memblock_limit = 0;
  1026. u64 vmalloc_limit;
  1027. struct memblock_region *reg;
  1028. phys_addr_t lowmem_limit = 0;
  1029. /*
  1030. * Let's use our own (unoptimized) equivalent of __pa() that is
  1031. * not affected by wrap-arounds when sizeof(phys_addr_t) == 4.
  1032. * The result is used as the upper bound on physical memory address
  1033. * and may itself be outside the valid range for which phys_addr_t
  1034. * and therefore __pa() is defined.
  1035. */
  1036. vmalloc_limit = (u64)(uintptr_t)vmalloc_min - PAGE_OFFSET + PHYS_OFFSET;
  1037. /*
  1038. * The first usable region must be PMD aligned. Mark its start
  1039. * as MEMBLOCK_NOMAP if it isn't
  1040. */
  1041. for_each_memblock(memory, reg) {
  1042. if (!memblock_is_nomap(reg)) {
  1043. if (!IS_ALIGNED(reg->base, PMD_SIZE)) {
  1044. phys_addr_t len;
  1045. len = round_up(reg->base, PMD_SIZE) - reg->base;
  1046. memblock_mark_nomap(reg->base, len);
  1047. }
  1048. break;
  1049. }
  1050. }
  1051. for_each_memblock(memory, reg) {
  1052. phys_addr_t block_start = reg->base;
  1053. phys_addr_t block_end = reg->base + reg->size;
  1054. if (memblock_is_nomap(reg))
  1055. continue;
  1056. if (reg->base < vmalloc_limit) {
  1057. if (block_end > lowmem_limit)
  1058. /*
  1059. * Compare as u64 to ensure vmalloc_limit does
  1060. * not get truncated. block_end should always
  1061. * fit in phys_addr_t so there should be no
  1062. * issue with assignment.
  1063. */
  1064. lowmem_limit = min_t(u64,
  1065. vmalloc_limit,
  1066. block_end);
  1067. /*
  1068. * Find the first non-pmd-aligned page, and point
  1069. * memblock_limit at it. This relies on rounding the
  1070. * limit down to be pmd-aligned, which happens at the
  1071. * end of this function.
  1072. *
  1073. * With this algorithm, the start or end of almost any
  1074. * bank can be non-pmd-aligned. The only exception is
  1075. * that the start of the bank 0 must be section-
  1076. * aligned, since otherwise memory would need to be
  1077. * allocated when mapping the start of bank 0, which
  1078. * occurs before any free memory is mapped.
  1079. */
  1080. if (!memblock_limit) {
  1081. if (!IS_ALIGNED(block_start, PMD_SIZE))
  1082. memblock_limit = block_start;
  1083. else if (!IS_ALIGNED(block_end, PMD_SIZE))
  1084. memblock_limit = lowmem_limit;
  1085. }
  1086. }
  1087. }
  1088. arm_lowmem_limit = lowmem_limit;
  1089. high_memory = __va(arm_lowmem_limit - 1) + 1;
  1090. if (!memblock_limit)
  1091. memblock_limit = arm_lowmem_limit;
  1092. /*
  1093. * Round the memblock limit down to a pmd size. This
  1094. * helps to ensure that we will allocate memory from the
  1095. * last full pmd, which should be mapped.
  1096. */
  1097. memblock_limit = round_down(memblock_limit, PMD_SIZE);
  1098. if (!IS_ENABLED(CONFIG_HIGHMEM) || cache_is_vipt_aliasing()) {
  1099. if (memblock_end_of_DRAM() > arm_lowmem_limit) {
  1100. phys_addr_t end = memblock_end_of_DRAM();
  1101. pr_notice("Ignoring RAM at %pa-%pa\n",
  1102. &memblock_limit, &end);
  1103. pr_notice("Consider using a HIGHMEM enabled kernel.\n");
  1104. memblock_remove(memblock_limit, end - memblock_limit);
  1105. }
  1106. }
  1107. memblock_set_current_limit(memblock_limit);
  1108. }
  1109. static inline void prepare_page_table(void)
  1110. {
  1111. unsigned long addr;
  1112. phys_addr_t end;
  1113. /*
  1114. * Clear out all the mappings below the kernel image.
  1115. */
  1116. for (addr = 0; addr < MODULES_VADDR; addr += PMD_SIZE)
  1117. pmd_clear(pmd_off_k(addr));
  1118. #ifdef CONFIG_XIP_KERNEL
  1119. /* The XIP kernel is mapped in the module area -- skip over it */
  1120. addr = ((unsigned long)_exiprom + PMD_SIZE - 1) & PMD_MASK;
  1121. #endif
  1122. for ( ; addr < PAGE_OFFSET; addr += PMD_SIZE)
  1123. pmd_clear(pmd_off_k(addr));
  1124. /*
  1125. * Find the end of the first block of lowmem.
  1126. */
  1127. end = memblock.memory.regions[0].base + memblock.memory.regions[0].size;
  1128. if (end >= arm_lowmem_limit)
  1129. end = arm_lowmem_limit;
  1130. /*
  1131. * Clear out all the kernel space mappings, except for the first
  1132. * memory bank, up to the vmalloc region.
  1133. */
  1134. for (addr = __phys_to_virt(end);
  1135. addr < VMALLOC_START; addr += PMD_SIZE)
  1136. pmd_clear(pmd_off_k(addr));
  1137. }
  1138. #ifdef CONFIG_ARM_LPAE
  1139. /* the first page is reserved for pgd */
  1140. #define SWAPPER_PG_DIR_SIZE (PAGE_SIZE + \
  1141. PTRS_PER_PGD * PTRS_PER_PMD * sizeof(pmd_t))
  1142. #else
  1143. #define SWAPPER_PG_DIR_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
  1144. #endif
  1145. /*
  1146. * Reserve the special regions of memory
  1147. */
  1148. void __init arm_mm_memblock_reserve(void)
  1149. {
  1150. /*
  1151. * Reserve the page tables. These are already in use,
  1152. * and can only be in node 0.
  1153. */
  1154. memblock_reserve(__pa(swapper_pg_dir), SWAPPER_PG_DIR_SIZE);
  1155. #ifdef CONFIG_SA1111
  1156. /*
  1157. * Because of the SA1111 DMA bug, we want to preserve our
  1158. * precious DMA-able memory...
  1159. */
  1160. memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
  1161. #endif
  1162. }
  1163. /*
  1164. * Set up the device mappings. Since we clear out the page tables for all
  1165. * mappings above VMALLOC_START, except early fixmap, we might remove debug
  1166. * device mappings. This means earlycon can be used to debug this function
  1167. * Any other function or debugging method which may touch any device _will_
  1168. * crash the kernel.
  1169. */
  1170. static void __init devicemaps_init(const struct machine_desc *mdesc)
  1171. {
  1172. struct map_desc map;
  1173. unsigned long addr;
  1174. void *vectors;
  1175. /*
  1176. * Allocate the vector page early.
  1177. */
  1178. vectors = early_alloc(PAGE_SIZE * 2);
  1179. early_trap_init(vectors);
  1180. /*
  1181. * Clear page table except top pmd used by early fixmaps
  1182. */
  1183. for (addr = VMALLOC_START; addr < (FIXADDR_TOP & PMD_MASK); addr += PMD_SIZE)
  1184. pmd_clear(pmd_off_k(addr));
  1185. /*
  1186. * Map the kernel if it is XIP.
  1187. * It is always first in the modulearea.
  1188. */
  1189. #ifdef CONFIG_XIP_KERNEL
  1190. map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
  1191. map.virtual = MODULES_VADDR;
  1192. map.length = ((unsigned long)_exiprom - map.virtual + ~SECTION_MASK) & SECTION_MASK;
  1193. map.type = MT_ROM;
  1194. create_mapping(&map);
  1195. #endif
  1196. /*
  1197. * Map the cache flushing regions.
  1198. */
  1199. #ifdef FLUSH_BASE
  1200. map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
  1201. map.virtual = FLUSH_BASE;
  1202. map.length = SZ_1M;
  1203. map.type = MT_CACHECLEAN;
  1204. create_mapping(&map);
  1205. #endif
  1206. #ifdef FLUSH_BASE_MINICACHE
  1207. map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
  1208. map.virtual = FLUSH_BASE_MINICACHE;
  1209. map.length = SZ_1M;
  1210. map.type = MT_MINICLEAN;
  1211. create_mapping(&map);
  1212. #endif
  1213. /*
  1214. * Create a mapping for the machine vectors at the high-vectors
  1215. * location (0xffff0000). If we aren't using high-vectors, also
  1216. * create a mapping at the low-vectors virtual address.
  1217. */
  1218. map.pfn = __phys_to_pfn(virt_to_phys(vectors));
  1219. map.virtual = 0xffff0000;
  1220. map.length = PAGE_SIZE;
  1221. #ifdef CONFIG_KUSER_HELPERS
  1222. map.type = MT_HIGH_VECTORS;
  1223. #else
  1224. map.type = MT_LOW_VECTORS;
  1225. #endif
  1226. create_mapping(&map);
  1227. if (!vectors_high()) {
  1228. map.virtual = 0;
  1229. map.length = PAGE_SIZE * 2;
  1230. map.type = MT_LOW_VECTORS;
  1231. create_mapping(&map);
  1232. }
  1233. /* Now create a kernel read-only mapping */
  1234. map.pfn += 1;
  1235. map.virtual = 0xffff0000 + PAGE_SIZE;
  1236. map.length = PAGE_SIZE;
  1237. map.type = MT_LOW_VECTORS;
  1238. create_mapping(&map);
  1239. /*
  1240. * Ask the machine support to map in the statically mapped devices.
  1241. */
  1242. if (mdesc->map_io)
  1243. mdesc->map_io();
  1244. else
  1245. debug_ll_io_init();
  1246. fill_pmd_gaps();
  1247. /* Reserve fixed i/o space in VMALLOC region */
  1248. pci_reserve_io();
  1249. /*
  1250. * Finally flush the caches and tlb to ensure that we're in a
  1251. * consistent state wrt the writebuffer. This also ensures that
  1252. * any write-allocated cache lines in the vector page are written
  1253. * back. After this point, we can start to touch devices again.
  1254. */
  1255. local_flush_tlb_all();
  1256. flush_cache_all();
  1257. /* Enable asynchronous aborts */
  1258. early_abt_enable();
  1259. }
  1260. static void __init kmap_init(void)
  1261. {
  1262. #ifdef CONFIG_HIGHMEM
  1263. pkmap_page_table = early_pte_alloc(pmd_off_k(PKMAP_BASE),
  1264. PKMAP_BASE, _PAGE_KERNEL_TABLE);
  1265. #endif
  1266. early_pte_alloc(pmd_off_k(FIXADDR_START), FIXADDR_START,
  1267. _PAGE_KERNEL_TABLE);
  1268. }
  1269. static void __init map_lowmem(void)
  1270. {
  1271. struct memblock_region *reg;
  1272. phys_addr_t kernel_x_start = round_down(__pa(KERNEL_START), SECTION_SIZE);
  1273. phys_addr_t kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
  1274. /* Map all the lowmem memory banks. */
  1275. for_each_memblock(memory, reg) {
  1276. phys_addr_t start = reg->base;
  1277. phys_addr_t end = start + reg->size;
  1278. struct map_desc map;
  1279. if (memblock_is_nomap(reg))
  1280. continue;
  1281. if (end > arm_lowmem_limit)
  1282. end = arm_lowmem_limit;
  1283. if (start >= end)
  1284. break;
  1285. if (end < kernel_x_start) {
  1286. map.pfn = __phys_to_pfn(start);
  1287. map.virtual = __phys_to_virt(start);
  1288. map.length = end - start;
  1289. map.type = MT_MEMORY_RWX;
  1290. create_mapping(&map);
  1291. } else if (start >= kernel_x_end) {
  1292. map.pfn = __phys_to_pfn(start);
  1293. map.virtual = __phys_to_virt(start);
  1294. map.length = end - start;
  1295. map.type = MT_MEMORY_RW;
  1296. create_mapping(&map);
  1297. } else {
  1298. /* This better cover the entire kernel */
  1299. if (start < kernel_x_start) {
  1300. map.pfn = __phys_to_pfn(start);
  1301. map.virtual = __phys_to_virt(start);
  1302. map.length = kernel_x_start - start;
  1303. map.type = MT_MEMORY_RW;
  1304. create_mapping(&map);
  1305. }
  1306. map.pfn = __phys_to_pfn(kernel_x_start);
  1307. map.virtual = __phys_to_virt(kernel_x_start);
  1308. map.length = kernel_x_end - kernel_x_start;
  1309. map.type = MT_MEMORY_RWX;
  1310. create_mapping(&map);
  1311. if (kernel_x_end < end) {
  1312. map.pfn = __phys_to_pfn(kernel_x_end);
  1313. map.virtual = __phys_to_virt(kernel_x_end);
  1314. map.length = end - kernel_x_end;
  1315. map.type = MT_MEMORY_RW;
  1316. create_mapping(&map);
  1317. }
  1318. }
  1319. }
  1320. }
  1321. #ifdef CONFIG_ARM_PV_FIXUP
  1322. extern unsigned long __atags_pointer;
  1323. typedef void pgtables_remap(long long offset, unsigned long pgd, void *bdata);
  1324. pgtables_remap lpae_pgtables_remap_asm;
  1325. /*
  1326. * early_paging_init() recreates boot time page table setup, allowing machines
  1327. * to switch over to a high (>4G) address space on LPAE systems
  1328. */
  1329. static void __init early_paging_init(const struct machine_desc *mdesc)
  1330. {
  1331. pgtables_remap *lpae_pgtables_remap;
  1332. unsigned long pa_pgd;
  1333. unsigned int cr, ttbcr;
  1334. long long offset;
  1335. void *boot_data;
  1336. if (!mdesc->pv_fixup)
  1337. return;
  1338. offset = mdesc->pv_fixup();
  1339. if (offset == 0)
  1340. return;
  1341. /*
  1342. * Get the address of the remap function in the 1:1 identity
  1343. * mapping setup by the early page table assembly code. We
  1344. * must get this prior to the pv update. The following barrier
  1345. * ensures that this is complete before we fixup any P:V offsets.
  1346. */
  1347. lpae_pgtables_remap = (pgtables_remap *)(unsigned long)__pa(lpae_pgtables_remap_asm);
  1348. pa_pgd = __pa(swapper_pg_dir);
  1349. boot_data = __va(__atags_pointer);
  1350. barrier();
  1351. pr_info("Switching physical address space to 0x%08llx\n",
  1352. (u64)PHYS_OFFSET + offset);
  1353. /* Re-set the phys pfn offset, and the pv offset */
  1354. __pv_offset += offset;
  1355. __pv_phys_pfn_offset += PFN_DOWN(offset);
  1356. /* Run the patch stub to update the constants */
  1357. fixup_pv_table(&__pv_table_begin,
  1358. (&__pv_table_end - &__pv_table_begin) << 2);
  1359. /*
  1360. * We changing not only the virtual to physical mapping, but also
  1361. * the physical addresses used to access memory. We need to flush
  1362. * all levels of cache in the system with caching disabled to
  1363. * ensure that all data is written back, and nothing is prefetched
  1364. * into the caches. We also need to prevent the TLB walkers
  1365. * allocating into the caches too. Note that this is ARMv7 LPAE
  1366. * specific.
  1367. */
  1368. cr = get_cr();
  1369. set_cr(cr & ~(CR_I | CR_C));
  1370. asm("mrc p15, 0, %0, c2, c0, 2" : "=r" (ttbcr));
  1371. asm volatile("mcr p15, 0, %0, c2, c0, 2"
  1372. : : "r" (ttbcr & ~(3 << 8 | 3 << 10)));
  1373. flush_cache_all();
  1374. /*
  1375. * Fixup the page tables - this must be in the idmap region as
  1376. * we need to disable the MMU to do this safely, and hence it
  1377. * needs to be assembly. It's fairly simple, as we're using the
  1378. * temporary tables setup by the initial assembly code.
  1379. */
  1380. lpae_pgtables_remap(offset, pa_pgd, boot_data);
  1381. /* Re-enable the caches and cacheable TLB walks */
  1382. asm volatile("mcr p15, 0, %0, c2, c0, 2" : : "r" (ttbcr));
  1383. set_cr(cr);
  1384. }
  1385. #else
  1386. static void __init early_paging_init(const struct machine_desc *mdesc)
  1387. {
  1388. long long offset;
  1389. if (!mdesc->pv_fixup)
  1390. return;
  1391. offset = mdesc->pv_fixup();
  1392. if (offset == 0)
  1393. return;
  1394. pr_crit("Physical address space modification is only to support Keystone2.\n");
  1395. pr_crit("Please enable ARM_LPAE and ARM_PATCH_PHYS_VIRT support to use this\n");
  1396. pr_crit("feature. Your kernel may crash now, have a good day.\n");
  1397. add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
  1398. }
  1399. #endif
  1400. static void __init early_fixmap_shutdown(void)
  1401. {
  1402. int i;
  1403. unsigned long va = fix_to_virt(__end_of_permanent_fixed_addresses - 1);
  1404. pte_offset_fixmap = pte_offset_late_fixmap;
  1405. pmd_clear(fixmap_pmd(va));
  1406. local_flush_tlb_kernel_page(va);
  1407. for (i = 0; i < __end_of_permanent_fixed_addresses; i++) {
  1408. pte_t *pte;
  1409. struct map_desc map;
  1410. map.virtual = fix_to_virt(i);
  1411. pte = pte_offset_early_fixmap(pmd_off_k(map.virtual), map.virtual);
  1412. /* Only i/o device mappings are supported ATM */
  1413. if (pte_none(*pte) ||
  1414. (pte_val(*pte) & L_PTE_MT_MASK) != L_PTE_MT_DEV_SHARED)
  1415. continue;
  1416. map.pfn = pte_pfn(*pte);
  1417. map.type = MT_DEVICE;
  1418. map.length = PAGE_SIZE;
  1419. create_mapping(&map);
  1420. }
  1421. }
  1422. /*
  1423. * paging_init() sets up the page tables, initialises the zone memory
  1424. * maps, and sets up the zero page, bad page and bad page tables.
  1425. */
  1426. void __init paging_init(const struct machine_desc *mdesc)
  1427. {
  1428. void *zero_page;
  1429. prepare_page_table();
  1430. map_lowmem();
  1431. memblock_set_current_limit(arm_lowmem_limit);
  1432. dma_contiguous_remap();
  1433. early_fixmap_shutdown();
  1434. devicemaps_init(mdesc);
  1435. kmap_init();
  1436. tcm_init();
  1437. top_pmd = pmd_off_k(0xffff0000);
  1438. /* allocate the zero page. */
  1439. zero_page = early_alloc(PAGE_SIZE);
  1440. bootmem_init();
  1441. empty_zero_page = virt_to_page(zero_page);
  1442. __flush_dcache_page(NULL, empty_zero_page);
  1443. /* Compute the virt/idmap offset, mostly for the sake of KVM */
  1444. kimage_voffset = (unsigned long)&kimage_voffset - virt_to_idmap(&kimage_voffset);
  1445. }
  1446. void __init early_mm_init(const struct machine_desc *mdesc)
  1447. {
  1448. build_mem_type_table();
  1449. early_paging_init(mdesc);
  1450. }