mmu.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  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/mach/arch.h>
  31. #include <asm/mach/map.h>
  32. #include <asm/mach/pci.h>
  33. #include "mm.h"
  34. /*
  35. * empty_zero_page is a special page that is used for
  36. * zero-initialized data and COW.
  37. */
  38. struct page *empty_zero_page;
  39. EXPORT_SYMBOL(empty_zero_page);
  40. /*
  41. * The pmd table for the upper-most set of pages.
  42. */
  43. pmd_t *top_pmd;
  44. #define CPOLICY_UNCACHED 0
  45. #define CPOLICY_BUFFERED 1
  46. #define CPOLICY_WRITETHROUGH 2
  47. #define CPOLICY_WRITEBACK 3
  48. #define CPOLICY_WRITEALLOC 4
  49. static unsigned int cachepolicy __initdata = CPOLICY_WRITEBACK;
  50. static unsigned int ecc_mask __initdata = 0;
  51. pgprot_t pgprot_user;
  52. pgprot_t pgprot_kernel;
  53. EXPORT_SYMBOL(pgprot_user);
  54. EXPORT_SYMBOL(pgprot_kernel);
  55. struct cachepolicy {
  56. const char policy[16];
  57. unsigned int cr_mask;
  58. pmdval_t pmd;
  59. pteval_t pte;
  60. };
  61. static struct cachepolicy cache_policies[] __initdata = {
  62. {
  63. .policy = "uncached",
  64. .cr_mask = CR_W|CR_C,
  65. .pmd = PMD_SECT_UNCACHED,
  66. .pte = L_PTE_MT_UNCACHED,
  67. }, {
  68. .policy = "buffered",
  69. .cr_mask = CR_C,
  70. .pmd = PMD_SECT_BUFFERED,
  71. .pte = L_PTE_MT_BUFFERABLE,
  72. }, {
  73. .policy = "writethrough",
  74. .cr_mask = 0,
  75. .pmd = PMD_SECT_WT,
  76. .pte = L_PTE_MT_WRITETHROUGH,
  77. }, {
  78. .policy = "writeback",
  79. .cr_mask = 0,
  80. .pmd = PMD_SECT_WB,
  81. .pte = L_PTE_MT_WRITEBACK,
  82. }, {
  83. .policy = "writealloc",
  84. .cr_mask = 0,
  85. .pmd = PMD_SECT_WBWA,
  86. .pte = L_PTE_MT_WRITEALLOC,
  87. }
  88. };
  89. /*
  90. * These are useful for identifying cache coherency
  91. * problems by allowing the cache or the cache and
  92. * writebuffer to be turned off. (Note: the write
  93. * buffer should not be on and the cache off).
  94. */
  95. static int __init early_cachepolicy(char *p)
  96. {
  97. int i;
  98. for (i = 0; i < ARRAY_SIZE(cache_policies); i++) {
  99. int len = strlen(cache_policies[i].policy);
  100. if (memcmp(p, cache_policies[i].policy, len) == 0) {
  101. cachepolicy = i;
  102. cr_alignment &= ~cache_policies[i].cr_mask;
  103. cr_no_alignment &= ~cache_policies[i].cr_mask;
  104. break;
  105. }
  106. }
  107. if (i == ARRAY_SIZE(cache_policies))
  108. printk(KERN_ERR "ERROR: unknown or unsupported cache policy\n");
  109. /*
  110. * This restriction is partly to do with the way we boot; it is
  111. * unpredictable to have memory mapped using two different sets of
  112. * memory attributes (shared, type, and cache attribs). We can not
  113. * change these attributes once the initial assembly has setup the
  114. * page tables.
  115. */
  116. if (cpu_architecture() >= CPU_ARCH_ARMv6) {
  117. printk(KERN_WARNING "Only cachepolicy=writeback supported on ARMv6 and later\n");
  118. cachepolicy = CPOLICY_WRITEBACK;
  119. }
  120. flush_cache_all();
  121. set_cr(cr_alignment);
  122. return 0;
  123. }
  124. early_param("cachepolicy", early_cachepolicy);
  125. static int __init early_nocache(char *__unused)
  126. {
  127. char *p = "buffered";
  128. printk(KERN_WARNING "nocache is deprecated; use cachepolicy=%s\n", p);
  129. early_cachepolicy(p);
  130. return 0;
  131. }
  132. early_param("nocache", early_nocache);
  133. static int __init early_nowrite(char *__unused)
  134. {
  135. char *p = "uncached";
  136. printk(KERN_WARNING "nowb is deprecated; use cachepolicy=%s\n", p);
  137. early_cachepolicy(p);
  138. return 0;
  139. }
  140. early_param("nowb", early_nowrite);
  141. #ifndef CONFIG_ARM_LPAE
  142. static int __init early_ecc(char *p)
  143. {
  144. if (memcmp(p, "on", 2) == 0)
  145. ecc_mask = PMD_PROTECTION;
  146. else if (memcmp(p, "off", 3) == 0)
  147. ecc_mask = 0;
  148. return 0;
  149. }
  150. early_param("ecc", early_ecc);
  151. #endif
  152. static int __init noalign_setup(char *__unused)
  153. {
  154. cr_alignment &= ~CR_A;
  155. cr_no_alignment &= ~CR_A;
  156. set_cr(cr_alignment);
  157. return 1;
  158. }
  159. __setup("noalign", noalign_setup);
  160. #ifndef CONFIG_SMP
  161. void adjust_cr(unsigned long mask, unsigned long set)
  162. {
  163. unsigned long flags;
  164. mask &= ~CR_A;
  165. set &= mask;
  166. local_irq_save(flags);
  167. cr_no_alignment = (cr_no_alignment & ~mask) | set;
  168. cr_alignment = (cr_alignment & ~mask) | set;
  169. set_cr((get_cr() & ~mask) | set);
  170. local_irq_restore(flags);
  171. }
  172. #endif
  173. #define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
  174. #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
  175. static struct mem_type mem_types[] = {
  176. [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
  177. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
  178. L_PTE_SHARED,
  179. .prot_l1 = PMD_TYPE_TABLE,
  180. .prot_sect = PROT_SECT_DEVICE | PMD_SECT_S,
  181. .domain = DOMAIN_IO,
  182. },
  183. [MT_DEVICE_NONSHARED] = { /* ARMv6 non-shared device */
  184. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_NONSHARED,
  185. .prot_l1 = PMD_TYPE_TABLE,
  186. .prot_sect = PROT_SECT_DEVICE,
  187. .domain = DOMAIN_IO,
  188. },
  189. [MT_DEVICE_CACHED] = { /* ioremap_cached */
  190. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_CACHED,
  191. .prot_l1 = PMD_TYPE_TABLE,
  192. .prot_sect = PROT_SECT_DEVICE | PMD_SECT_WB,
  193. .domain = DOMAIN_IO,
  194. },
  195. [MT_DEVICE_WC] = { /* ioremap_wc */
  196. .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_WC,
  197. .prot_l1 = PMD_TYPE_TABLE,
  198. .prot_sect = PROT_SECT_DEVICE,
  199. .domain = DOMAIN_IO,
  200. },
  201. [MT_UNCACHED] = {
  202. .prot_pte = PROT_PTE_DEVICE,
  203. .prot_l1 = PMD_TYPE_TABLE,
  204. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  205. .domain = DOMAIN_IO,
  206. },
  207. [MT_CACHECLEAN] = {
  208. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  209. .domain = DOMAIN_KERNEL,
  210. },
  211. #ifndef CONFIG_ARM_LPAE
  212. [MT_MINICLEAN] = {
  213. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
  214. .domain = DOMAIN_KERNEL,
  215. },
  216. #endif
  217. [MT_LOW_VECTORS] = {
  218. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  219. L_PTE_RDONLY,
  220. .prot_l1 = PMD_TYPE_TABLE,
  221. .domain = DOMAIN_USER,
  222. },
  223. [MT_HIGH_VECTORS] = {
  224. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  225. L_PTE_USER | L_PTE_RDONLY,
  226. .prot_l1 = PMD_TYPE_TABLE,
  227. .domain = DOMAIN_USER,
  228. },
  229. [MT_MEMORY] = {
  230. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
  231. .prot_l1 = PMD_TYPE_TABLE,
  232. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  233. .domain = DOMAIN_KERNEL,
  234. },
  235. [MT_ROM] = {
  236. .prot_sect = PMD_TYPE_SECT,
  237. .domain = DOMAIN_KERNEL,
  238. },
  239. [MT_MEMORY_NONCACHED] = {
  240. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  241. L_PTE_MT_BUFFERABLE,
  242. .prot_l1 = PMD_TYPE_TABLE,
  243. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  244. .domain = DOMAIN_KERNEL,
  245. },
  246. [MT_MEMORY_DTCM] = {
  247. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  248. L_PTE_XN,
  249. .prot_l1 = PMD_TYPE_TABLE,
  250. .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
  251. .domain = DOMAIN_KERNEL,
  252. },
  253. [MT_MEMORY_ITCM] = {
  254. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
  255. .prot_l1 = PMD_TYPE_TABLE,
  256. .domain = DOMAIN_KERNEL,
  257. },
  258. [MT_MEMORY_SO] = {
  259. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  260. L_PTE_MT_UNCACHED,
  261. .prot_l1 = PMD_TYPE_TABLE,
  262. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
  263. PMD_SECT_UNCACHED | PMD_SECT_XN,
  264. .domain = DOMAIN_KERNEL,
  265. },
  266. [MT_MEMORY_DMA_READY] = {
  267. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
  268. .prot_l1 = PMD_TYPE_TABLE,
  269. .domain = DOMAIN_KERNEL,
  270. },
  271. };
  272. const struct mem_type *get_mem_type(unsigned int type)
  273. {
  274. return type < ARRAY_SIZE(mem_types) ? &mem_types[type] : NULL;
  275. }
  276. EXPORT_SYMBOL(get_mem_type);
  277. /*
  278. * Adjust the PMD section entries according to the CPU in use.
  279. */
  280. static void __init build_mem_type_table(void)
  281. {
  282. struct cachepolicy *cp;
  283. unsigned int cr = get_cr();
  284. pteval_t user_pgprot, kern_pgprot, vecs_pgprot;
  285. int cpu_arch = cpu_architecture();
  286. int i;
  287. if (cpu_arch < CPU_ARCH_ARMv6) {
  288. #if defined(CONFIG_CPU_DCACHE_DISABLE)
  289. if (cachepolicy > CPOLICY_BUFFERED)
  290. cachepolicy = CPOLICY_BUFFERED;
  291. #elif defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
  292. if (cachepolicy > CPOLICY_WRITETHROUGH)
  293. cachepolicy = CPOLICY_WRITETHROUGH;
  294. #endif
  295. }
  296. if (cpu_arch < CPU_ARCH_ARMv5) {
  297. if (cachepolicy >= CPOLICY_WRITEALLOC)
  298. cachepolicy = CPOLICY_WRITEBACK;
  299. ecc_mask = 0;
  300. }
  301. if (is_smp())
  302. cachepolicy = CPOLICY_WRITEALLOC;
  303. /*
  304. * Strip out features not present on earlier architectures.
  305. * Pre-ARMv5 CPUs don't have TEX bits. Pre-ARMv6 CPUs or those
  306. * without extended page tables don't have the 'Shared' bit.
  307. */
  308. if (cpu_arch < CPU_ARCH_ARMv5)
  309. for (i = 0; i < ARRAY_SIZE(mem_types); i++)
  310. mem_types[i].prot_sect &= ~PMD_SECT_TEX(7);
  311. if ((cpu_arch < CPU_ARCH_ARMv6 || !(cr & CR_XP)) && !cpu_is_xsc3())
  312. for (i = 0; i < ARRAY_SIZE(mem_types); i++)
  313. mem_types[i].prot_sect &= ~PMD_SECT_S;
  314. /*
  315. * ARMv5 and lower, bit 4 must be set for page tables (was: cache
  316. * "update-able on write" bit on ARM610). However, Xscale and
  317. * Xscale3 require this bit to be cleared.
  318. */
  319. if (cpu_is_xscale() || cpu_is_xsc3()) {
  320. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  321. mem_types[i].prot_sect &= ~PMD_BIT4;
  322. mem_types[i].prot_l1 &= ~PMD_BIT4;
  323. }
  324. } else if (cpu_arch < CPU_ARCH_ARMv6) {
  325. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  326. if (mem_types[i].prot_l1)
  327. mem_types[i].prot_l1 |= PMD_BIT4;
  328. if (mem_types[i].prot_sect)
  329. mem_types[i].prot_sect |= PMD_BIT4;
  330. }
  331. }
  332. /*
  333. * Mark the device areas according to the CPU/architecture.
  334. */
  335. if (cpu_is_xsc3() || (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP))) {
  336. if (!cpu_is_xsc3()) {
  337. /*
  338. * Mark device regions on ARMv6+ as execute-never
  339. * to prevent speculative instruction fetches.
  340. */
  341. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
  342. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
  343. mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
  344. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
  345. }
  346. if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
  347. /*
  348. * For ARMv7 with TEX remapping,
  349. * - shared device is SXCB=1100
  350. * - nonshared device is SXCB=0100
  351. * - write combine device mem is SXCB=0001
  352. * (Uncached Normal memory)
  353. */
  354. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_TEX(1);
  355. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_TEX(1);
  356. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_BUFFERABLE;
  357. } else if (cpu_is_xsc3()) {
  358. /*
  359. * For Xscale3,
  360. * - shared device is TEXCB=00101
  361. * - nonshared device is TEXCB=01000
  362. * - write combine device mem is TEXCB=00100
  363. * (Inner/Outer Uncacheable in xsc3 parlance)
  364. */
  365. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_TEX(1) | PMD_SECT_BUFFERED;
  366. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_TEX(2);
  367. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_TEX(1);
  368. } else {
  369. /*
  370. * For ARMv6 and ARMv7 without TEX remapping,
  371. * - shared device is TEXCB=00001
  372. * - nonshared device is TEXCB=01000
  373. * - write combine device mem is TEXCB=00100
  374. * (Uncached Normal in ARMv6 parlance).
  375. */
  376. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_BUFFERED;
  377. mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_TEX(2);
  378. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_TEX(1);
  379. }
  380. } else {
  381. /*
  382. * On others, write combining is "Uncached/Buffered"
  383. */
  384. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_BUFFERABLE;
  385. }
  386. /*
  387. * Now deal with the memory-type mappings
  388. */
  389. cp = &cache_policies[cachepolicy];
  390. vecs_pgprot = kern_pgprot = user_pgprot = cp->pte;
  391. /*
  392. * Only use write-through for non-SMP systems
  393. */
  394. if (!is_smp() && cpu_arch >= CPU_ARCH_ARMv5 && cachepolicy > CPOLICY_WRITETHROUGH)
  395. vecs_pgprot = cache_policies[CPOLICY_WRITETHROUGH].pte;
  396. /*
  397. * Enable CPU-specific coherency if supported.
  398. * (Only available on XSC3 at the moment.)
  399. */
  400. if (arch_is_coherent() && cpu_is_xsc3()) {
  401. mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
  402. mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
  403. mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
  404. mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
  405. mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
  406. }
  407. /*
  408. * ARMv6 and above have extended page tables.
  409. */
  410. if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
  411. #ifndef CONFIG_ARM_LPAE
  412. /*
  413. * Mark cache clean areas and XIP ROM read only
  414. * from SVC mode and no access from userspace.
  415. */
  416. mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  417. mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  418. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  419. #endif
  420. if (is_smp()) {
  421. /*
  422. * Mark memory with the "shared" attribute
  423. * for SMP systems
  424. */
  425. user_pgprot |= L_PTE_SHARED;
  426. kern_pgprot |= L_PTE_SHARED;
  427. vecs_pgprot |= L_PTE_SHARED;
  428. mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_S;
  429. mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
  430. mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
  431. mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
  432. mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
  433. mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
  434. mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
  435. mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
  436. mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
  437. }
  438. }
  439. /*
  440. * Non-cacheable Normal - intended for memory areas that must
  441. * not cause dirty cache line writebacks when used
  442. */
  443. if (cpu_arch >= CPU_ARCH_ARMv6) {
  444. if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
  445. /* Non-cacheable Normal is XCB = 001 */
  446. mem_types[MT_MEMORY_NONCACHED].prot_sect |=
  447. PMD_SECT_BUFFERED;
  448. } else {
  449. /* For both ARMv6 and non-TEX-remapping ARMv7 */
  450. mem_types[MT_MEMORY_NONCACHED].prot_sect |=
  451. PMD_SECT_TEX(1);
  452. }
  453. } else {
  454. mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
  455. }
  456. #ifdef CONFIG_ARM_LPAE
  457. /*
  458. * Do not generate access flag faults for the kernel mappings.
  459. */
  460. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  461. mem_types[i].prot_pte |= PTE_EXT_AF;
  462. if (mem_types[i].prot_sect)
  463. mem_types[i].prot_sect |= PMD_SECT_AF;
  464. }
  465. kern_pgprot |= PTE_EXT_AF;
  466. vecs_pgprot |= PTE_EXT_AF;
  467. #endif
  468. for (i = 0; i < 16; i++) {
  469. unsigned long v = pgprot_val(protection_map[i]);
  470. protection_map[i] = __pgprot(v | user_pgprot);
  471. }
  472. mem_types[MT_LOW_VECTORS].prot_pte |= vecs_pgprot;
  473. mem_types[MT_HIGH_VECTORS].prot_pte |= vecs_pgprot;
  474. pgprot_user = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | user_pgprot);
  475. pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
  476. L_PTE_DIRTY | kern_pgprot);
  477. mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
  478. mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
  479. mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
  480. mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
  481. mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
  482. mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
  483. mem_types[MT_ROM].prot_sect |= cp->pmd;
  484. switch (cp->pmd) {
  485. case PMD_SECT_WT:
  486. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
  487. break;
  488. case PMD_SECT_WB:
  489. case PMD_SECT_WBWA:
  490. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
  491. break;
  492. }
  493. printk("Memory policy: ECC %sabled, Data cache %s\n",
  494. ecc_mask ? "en" : "dis", cp->policy);
  495. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  496. struct mem_type *t = &mem_types[i];
  497. if (t->prot_l1)
  498. t->prot_l1 |= PMD_DOMAIN(t->domain);
  499. if (t->prot_sect)
  500. t->prot_sect |= PMD_DOMAIN(t->domain);
  501. }
  502. }
  503. #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
  504. pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  505. unsigned long size, pgprot_t vma_prot)
  506. {
  507. if (!pfn_valid(pfn))
  508. return pgprot_noncached(vma_prot);
  509. else if (file->f_flags & O_SYNC)
  510. return pgprot_writecombine(vma_prot);
  511. return vma_prot;
  512. }
  513. EXPORT_SYMBOL(phys_mem_access_prot);
  514. #endif
  515. #define vectors_base() (vectors_high() ? 0xffff0000 : 0)
  516. static void __init *early_alloc_aligned(unsigned long sz, unsigned long align)
  517. {
  518. void *ptr = __va(memblock_alloc(sz, align));
  519. memset(ptr, 0, sz);
  520. return ptr;
  521. }
  522. static void __init *early_alloc(unsigned long sz)
  523. {
  524. return early_alloc_aligned(sz, sz);
  525. }
  526. static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, unsigned long prot)
  527. {
  528. if (pmd_none(*pmd)) {
  529. pte_t *pte = early_alloc(PTE_HWTABLE_OFF + PTE_HWTABLE_SIZE);
  530. __pmd_populate(pmd, __pa(pte), prot);
  531. }
  532. BUG_ON(pmd_bad(*pmd));
  533. return pte_offset_kernel(pmd, addr);
  534. }
  535. static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
  536. unsigned long end, unsigned long pfn,
  537. const struct mem_type *type)
  538. {
  539. pte_t *pte = early_pte_alloc(pmd, addr, type->prot_l1);
  540. do {
  541. set_pte_ext(pte, pfn_pte(pfn, __pgprot(type->prot_pte)), 0);
  542. pfn++;
  543. } while (pte++, addr += PAGE_SIZE, addr != end);
  544. }
  545. static void __init alloc_init_section(pud_t *pud, unsigned long addr,
  546. unsigned long end, phys_addr_t phys,
  547. const struct mem_type *type)
  548. {
  549. pmd_t *pmd = pmd_offset(pud, addr);
  550. /*
  551. * Try a section mapping - end, addr and phys must all be aligned
  552. * to a section boundary. Note that PMDs refer to the individual
  553. * L1 entries, whereas PGDs refer to a group of L1 entries making
  554. * up one logical pointer to an L2 table.
  555. */
  556. if (type->prot_sect && ((addr | end | phys) & ~SECTION_MASK) == 0) {
  557. pmd_t *p = pmd;
  558. #ifndef CONFIG_ARM_LPAE
  559. if (addr & SECTION_SIZE)
  560. pmd++;
  561. #endif
  562. do {
  563. *pmd = __pmd(phys | type->prot_sect);
  564. phys += SECTION_SIZE;
  565. } while (pmd++, addr += SECTION_SIZE, addr != end);
  566. flush_pmd_entry(p);
  567. } else {
  568. /*
  569. * No need to loop; pte's aren't interested in the
  570. * individual L1 entries.
  571. */
  572. alloc_init_pte(pmd, addr, end, __phys_to_pfn(phys), type);
  573. }
  574. }
  575. static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr,
  576. unsigned long end, unsigned long phys, const struct mem_type *type)
  577. {
  578. pud_t *pud = pud_offset(pgd, addr);
  579. unsigned long next;
  580. do {
  581. next = pud_addr_end(addr, end);
  582. alloc_init_section(pud, addr, next, phys, type);
  583. phys += next - addr;
  584. } while (pud++, addr = next, addr != end);
  585. }
  586. #ifndef CONFIG_ARM_LPAE
  587. static void __init create_36bit_mapping(struct map_desc *md,
  588. const struct mem_type *type)
  589. {
  590. unsigned long addr, length, end;
  591. phys_addr_t phys;
  592. pgd_t *pgd;
  593. addr = md->virtual;
  594. phys = __pfn_to_phys(md->pfn);
  595. length = PAGE_ALIGN(md->length);
  596. if (!(cpu_architecture() >= CPU_ARCH_ARMv6 || cpu_is_xsc3())) {
  597. printk(KERN_ERR "MM: CPU does not support supersection "
  598. "mapping for 0x%08llx at 0x%08lx\n",
  599. (long long)__pfn_to_phys((u64)md->pfn), addr);
  600. return;
  601. }
  602. /* N.B. ARMv6 supersections are only defined to work with domain 0.
  603. * Since domain assignments can in fact be arbitrary, the
  604. * 'domain == 0' check below is required to insure that ARMv6
  605. * supersections are only allocated for domain 0 regardless
  606. * of the actual domain assignments in use.
  607. */
  608. if (type->domain) {
  609. printk(KERN_ERR "MM: invalid domain in supersection "
  610. "mapping for 0x%08llx at 0x%08lx\n",
  611. (long long)__pfn_to_phys((u64)md->pfn), addr);
  612. return;
  613. }
  614. if ((addr | length | __pfn_to_phys(md->pfn)) & ~SUPERSECTION_MASK) {
  615. printk(KERN_ERR "MM: cannot create mapping for 0x%08llx"
  616. " at 0x%08lx invalid alignment\n",
  617. (long long)__pfn_to_phys((u64)md->pfn), addr);
  618. return;
  619. }
  620. /*
  621. * Shift bits [35:32] of address into bits [23:20] of PMD
  622. * (See ARMv6 spec).
  623. */
  624. phys |= (((md->pfn >> (32 - PAGE_SHIFT)) & 0xF) << 20);
  625. pgd = pgd_offset_k(addr);
  626. end = addr + length;
  627. do {
  628. pud_t *pud = pud_offset(pgd, addr);
  629. pmd_t *pmd = pmd_offset(pud, addr);
  630. int i;
  631. for (i = 0; i < 16; i++)
  632. *pmd++ = __pmd(phys | type->prot_sect | PMD_SECT_SUPER);
  633. addr += SUPERSECTION_SIZE;
  634. phys += SUPERSECTION_SIZE;
  635. pgd += SUPERSECTION_SIZE >> PGDIR_SHIFT;
  636. } while (addr != end);
  637. }
  638. #endif /* !CONFIG_ARM_LPAE */
  639. /*
  640. * Create the page directory entries and any necessary
  641. * page tables for the mapping specified by `md'. We
  642. * are able to cope here with varying sizes and address
  643. * offsets, and we take full advantage of sections and
  644. * supersections.
  645. */
  646. static void __init create_mapping(struct map_desc *md)
  647. {
  648. unsigned long addr, length, end;
  649. phys_addr_t phys;
  650. const struct mem_type *type;
  651. pgd_t *pgd;
  652. if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) {
  653. printk(KERN_WARNING "BUG: not creating mapping for 0x%08llx"
  654. " at 0x%08lx in user region\n",
  655. (long long)__pfn_to_phys((u64)md->pfn), md->virtual);
  656. return;
  657. }
  658. if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
  659. md->virtual >= PAGE_OFFSET &&
  660. (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
  661. printk(KERN_WARNING "BUG: mapping for 0x%08llx"
  662. " at 0x%08lx out of vmalloc space\n",
  663. (long long)__pfn_to_phys((u64)md->pfn), md->virtual);
  664. }
  665. type = &mem_types[md->type];
  666. #ifndef CONFIG_ARM_LPAE
  667. /*
  668. * Catch 36-bit addresses
  669. */
  670. if (md->pfn >= 0x100000) {
  671. create_36bit_mapping(md, type);
  672. return;
  673. }
  674. #endif
  675. addr = md->virtual & PAGE_MASK;
  676. phys = __pfn_to_phys(md->pfn);
  677. length = PAGE_ALIGN(md->length + (md->virtual & ~PAGE_MASK));
  678. if (type->prot_l1 == 0 && ((addr | phys | length) & ~SECTION_MASK)) {
  679. printk(KERN_WARNING "BUG: map for 0x%08llx at 0x%08lx can not "
  680. "be mapped using pages, ignoring.\n",
  681. (long long)__pfn_to_phys(md->pfn), addr);
  682. return;
  683. }
  684. pgd = pgd_offset_k(addr);
  685. end = addr + length;
  686. do {
  687. unsigned long next = pgd_addr_end(addr, end);
  688. alloc_init_pud(pgd, addr, next, phys, type);
  689. phys += next - addr;
  690. addr = next;
  691. } while (pgd++, addr != end);
  692. }
  693. /*
  694. * Create the architecture specific mappings
  695. */
  696. void __init iotable_init(struct map_desc *io_desc, int nr)
  697. {
  698. struct map_desc *md;
  699. struct vm_struct *vm;
  700. if (!nr)
  701. return;
  702. vm = early_alloc_aligned(sizeof(*vm) * nr, __alignof__(*vm));
  703. for (md = io_desc; nr; md++, nr--) {
  704. create_mapping(md);
  705. vm->addr = (void *)(md->virtual & PAGE_MASK);
  706. vm->size = PAGE_ALIGN(md->length + (md->virtual & ~PAGE_MASK));
  707. vm->phys_addr = __pfn_to_phys(md->pfn);
  708. vm->flags = VM_IOREMAP | VM_ARM_STATIC_MAPPING;
  709. vm->flags |= VM_ARM_MTYPE(md->type);
  710. vm->caller = iotable_init;
  711. vm_area_add_early(vm++);
  712. }
  713. }
  714. void __init vm_reserve_area_early(unsigned long addr, unsigned long size,
  715. void *caller)
  716. {
  717. struct vm_struct *vm;
  718. vm = early_alloc_aligned(sizeof(*vm), __alignof__(*vm));
  719. vm->addr = (void *)addr;
  720. vm->size = size;
  721. vm->flags = VM_IOREMAP | VM_ARM_STATIC_MAPPING;
  722. vm->caller = caller;
  723. vm_area_add_early(vm);
  724. }
  725. #ifndef CONFIG_ARM_LPAE
  726. /*
  727. * The Linux PMD is made of two consecutive section entries covering 2MB
  728. * (see definition in include/asm/pgtable-2level.h). However a call to
  729. * create_mapping() may optimize static mappings by using individual
  730. * 1MB section mappings. This leaves the actual PMD potentially half
  731. * initialized if the top or bottom section entry isn't used, leaving it
  732. * open to problems if a subsequent ioremap() or vmalloc() tries to use
  733. * the virtual space left free by that unused section entry.
  734. *
  735. * Let's avoid the issue by inserting dummy vm entries covering the unused
  736. * PMD halves once the static mappings are in place.
  737. */
  738. static void __init pmd_empty_section_gap(unsigned long addr)
  739. {
  740. vm_reserve_area_early(addr, SECTION_SIZE, pmd_empty_section_gap);
  741. }
  742. static void __init fill_pmd_gaps(void)
  743. {
  744. struct vm_struct *vm;
  745. unsigned long addr, next = 0;
  746. pmd_t *pmd;
  747. /* we're still single threaded hence no lock needed here */
  748. for (vm = vmlist; vm; vm = vm->next) {
  749. if (!(vm->flags & VM_ARM_STATIC_MAPPING))
  750. continue;
  751. addr = (unsigned long)vm->addr;
  752. if (addr < next)
  753. continue;
  754. /*
  755. * Check if this vm starts on an odd section boundary.
  756. * If so and the first section entry for this PMD is free
  757. * then we block the corresponding virtual address.
  758. */
  759. if ((addr & ~PMD_MASK) == SECTION_SIZE) {
  760. pmd = pmd_off_k(addr);
  761. if (pmd_none(*pmd))
  762. pmd_empty_section_gap(addr & PMD_MASK);
  763. }
  764. /*
  765. * Then check if this vm ends on an odd section boundary.
  766. * If so and the second section entry for this PMD is empty
  767. * then we block the corresponding virtual address.
  768. */
  769. addr += vm->size;
  770. if ((addr & ~PMD_MASK) == SECTION_SIZE) {
  771. pmd = pmd_off_k(addr) + 1;
  772. if (pmd_none(*pmd))
  773. pmd_empty_section_gap(addr);
  774. }
  775. /* no need to look at any vm entry until we hit the next PMD */
  776. next = (addr + PMD_SIZE - 1) & PMD_MASK;
  777. }
  778. }
  779. #else
  780. #define fill_pmd_gaps() do { } while (0)
  781. #endif
  782. #if defined(CONFIG_PCI) && !defined(CONFIG_NEED_MACH_IO_H)
  783. static void __init pci_reserve_io(void)
  784. {
  785. struct vm_struct *vm;
  786. unsigned long addr;
  787. /* we're still single threaded hence no lock needed here */
  788. for (vm = vmlist; vm; vm = vm->next) {
  789. if (!(vm->flags & VM_ARM_STATIC_MAPPING))
  790. continue;
  791. addr = (unsigned long)vm->addr;
  792. addr &= ~(SZ_2M - 1);
  793. if (addr == PCI_IO_VIRT_BASE)
  794. return;
  795. }
  796. vm_reserve_area_early(PCI_IO_VIRT_BASE, SZ_2M, pci_reserve_io);
  797. }
  798. #else
  799. #define pci_reserve_io() do { } while (0)
  800. #endif
  801. static void * __initdata vmalloc_min =
  802. (void *)(VMALLOC_END - (240 << 20) - VMALLOC_OFFSET);
  803. /*
  804. * vmalloc=size forces the vmalloc area to be exactly 'size'
  805. * bytes. This can be used to increase (or decrease) the vmalloc
  806. * area - the default is 240m.
  807. */
  808. static int __init early_vmalloc(char *arg)
  809. {
  810. unsigned long vmalloc_reserve = memparse(arg, NULL);
  811. if (vmalloc_reserve < SZ_16M) {
  812. vmalloc_reserve = SZ_16M;
  813. printk(KERN_WARNING
  814. "vmalloc area too small, limiting to %luMB\n",
  815. vmalloc_reserve >> 20);
  816. }
  817. if (vmalloc_reserve > VMALLOC_END - (PAGE_OFFSET + SZ_32M)) {
  818. vmalloc_reserve = VMALLOC_END - (PAGE_OFFSET + SZ_32M);
  819. printk(KERN_WARNING
  820. "vmalloc area is too big, limiting to %luMB\n",
  821. vmalloc_reserve >> 20);
  822. }
  823. vmalloc_min = (void *)(VMALLOC_END - vmalloc_reserve);
  824. return 0;
  825. }
  826. early_param("vmalloc", early_vmalloc);
  827. phys_addr_t arm_lowmem_limit __initdata = 0;
  828. void __init sanity_check_meminfo(void)
  829. {
  830. int i, j, highmem = 0;
  831. for (i = 0, j = 0; i < meminfo.nr_banks; i++) {
  832. struct membank *bank = &meminfo.bank[j];
  833. *bank = meminfo.bank[i];
  834. if (bank->start > ULONG_MAX)
  835. highmem = 1;
  836. #ifdef CONFIG_HIGHMEM
  837. if (__va(bank->start) >= vmalloc_min ||
  838. __va(bank->start) < (void *)PAGE_OFFSET)
  839. highmem = 1;
  840. bank->highmem = highmem;
  841. /*
  842. * Split those memory banks which are partially overlapping
  843. * the vmalloc area greatly simplifying things later.
  844. */
  845. if (!highmem && __va(bank->start) < vmalloc_min &&
  846. bank->size > vmalloc_min - __va(bank->start)) {
  847. if (meminfo.nr_banks >= NR_BANKS) {
  848. printk(KERN_CRIT "NR_BANKS too low, "
  849. "ignoring high memory\n");
  850. } else {
  851. memmove(bank + 1, bank,
  852. (meminfo.nr_banks - i) * sizeof(*bank));
  853. meminfo.nr_banks++;
  854. i++;
  855. bank[1].size -= vmalloc_min - __va(bank->start);
  856. bank[1].start = __pa(vmalloc_min - 1) + 1;
  857. bank[1].highmem = highmem = 1;
  858. j++;
  859. }
  860. bank->size = vmalloc_min - __va(bank->start);
  861. }
  862. #else
  863. bank->highmem = highmem;
  864. /*
  865. * Highmem banks not allowed with !CONFIG_HIGHMEM.
  866. */
  867. if (highmem) {
  868. printk(KERN_NOTICE "Ignoring RAM at %.8llx-%.8llx "
  869. "(!CONFIG_HIGHMEM).\n",
  870. (unsigned long long)bank->start,
  871. (unsigned long long)bank->start + bank->size - 1);
  872. continue;
  873. }
  874. /*
  875. * Check whether this memory bank would entirely overlap
  876. * the vmalloc area.
  877. */
  878. if (__va(bank->start) >= vmalloc_min ||
  879. __va(bank->start) < (void *)PAGE_OFFSET) {
  880. printk(KERN_NOTICE "Ignoring RAM at %.8llx-%.8llx "
  881. "(vmalloc region overlap).\n",
  882. (unsigned long long)bank->start,
  883. (unsigned long long)bank->start + bank->size - 1);
  884. continue;
  885. }
  886. /*
  887. * Check whether this memory bank would partially overlap
  888. * the vmalloc area.
  889. */
  890. if (__va(bank->start + bank->size) > vmalloc_min ||
  891. __va(bank->start + bank->size) < __va(bank->start)) {
  892. unsigned long newsize = vmalloc_min - __va(bank->start);
  893. printk(KERN_NOTICE "Truncating RAM at %.8llx-%.8llx "
  894. "to -%.8llx (vmalloc region overlap).\n",
  895. (unsigned long long)bank->start,
  896. (unsigned long long)bank->start + bank->size - 1,
  897. (unsigned long long)bank->start + newsize - 1);
  898. bank->size = newsize;
  899. }
  900. #endif
  901. if (!bank->highmem && bank->start + bank->size > arm_lowmem_limit)
  902. arm_lowmem_limit = bank->start + bank->size;
  903. j++;
  904. }
  905. #ifdef CONFIG_HIGHMEM
  906. if (highmem) {
  907. const char *reason = NULL;
  908. if (cache_is_vipt_aliasing()) {
  909. /*
  910. * Interactions between kmap and other mappings
  911. * make highmem support with aliasing VIPT caches
  912. * rather difficult.
  913. */
  914. reason = "with VIPT aliasing cache";
  915. }
  916. if (reason) {
  917. printk(KERN_CRIT "HIGHMEM is not supported %s, ignoring high memory\n",
  918. reason);
  919. while (j > 0 && meminfo.bank[j - 1].highmem)
  920. j--;
  921. }
  922. }
  923. #endif
  924. meminfo.nr_banks = j;
  925. high_memory = __va(arm_lowmem_limit - 1) + 1;
  926. memblock_set_current_limit(arm_lowmem_limit);
  927. }
  928. static inline void prepare_page_table(void)
  929. {
  930. unsigned long addr;
  931. phys_addr_t end;
  932. /*
  933. * Clear out all the mappings below the kernel image.
  934. */
  935. for (addr = 0; addr < MODULES_VADDR; addr += PMD_SIZE)
  936. pmd_clear(pmd_off_k(addr));
  937. #ifdef CONFIG_XIP_KERNEL
  938. /* The XIP kernel is mapped in the module area -- skip over it */
  939. addr = ((unsigned long)_etext + PMD_SIZE - 1) & PMD_MASK;
  940. #endif
  941. for ( ; addr < PAGE_OFFSET; addr += PMD_SIZE)
  942. pmd_clear(pmd_off_k(addr));
  943. /*
  944. * Find the end of the first block of lowmem.
  945. */
  946. end = memblock.memory.regions[0].base + memblock.memory.regions[0].size;
  947. if (end >= arm_lowmem_limit)
  948. end = arm_lowmem_limit;
  949. /*
  950. * Clear out all the kernel space mappings, except for the first
  951. * memory bank, up to the vmalloc region.
  952. */
  953. for (addr = __phys_to_virt(end);
  954. addr < VMALLOC_START; addr += PMD_SIZE)
  955. pmd_clear(pmd_off_k(addr));
  956. }
  957. #ifdef CONFIG_ARM_LPAE
  958. /* the first page is reserved for pgd */
  959. #define SWAPPER_PG_DIR_SIZE (PAGE_SIZE + \
  960. PTRS_PER_PGD * PTRS_PER_PMD * sizeof(pmd_t))
  961. #else
  962. #define SWAPPER_PG_DIR_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
  963. #endif
  964. /*
  965. * Reserve the special regions of memory
  966. */
  967. void __init arm_mm_memblock_reserve(void)
  968. {
  969. /*
  970. * Reserve the page tables. These are already in use,
  971. * and can only be in node 0.
  972. */
  973. memblock_reserve(__pa(swapper_pg_dir), SWAPPER_PG_DIR_SIZE);
  974. #ifdef CONFIG_SA1111
  975. /*
  976. * Because of the SA1111 DMA bug, we want to preserve our
  977. * precious DMA-able memory...
  978. */
  979. memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
  980. #endif
  981. }
  982. /*
  983. * Set up the device mappings. Since we clear out the page tables for all
  984. * mappings above VMALLOC_START, we will remove any debug device mappings.
  985. * This means you have to be careful how you debug this function, or any
  986. * called function. This means you can't use any function or debugging
  987. * method which may touch any device, otherwise the kernel _will_ crash.
  988. */
  989. static void __init devicemaps_init(struct machine_desc *mdesc)
  990. {
  991. struct map_desc map;
  992. unsigned long addr;
  993. void *vectors;
  994. /*
  995. * Allocate the vector page early.
  996. */
  997. vectors = early_alloc(PAGE_SIZE);
  998. early_trap_init(vectors);
  999. for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
  1000. pmd_clear(pmd_off_k(addr));
  1001. /*
  1002. * Map the kernel if it is XIP.
  1003. * It is always first in the modulearea.
  1004. */
  1005. #ifdef CONFIG_XIP_KERNEL
  1006. map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
  1007. map.virtual = MODULES_VADDR;
  1008. map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
  1009. map.type = MT_ROM;
  1010. create_mapping(&map);
  1011. #endif
  1012. /*
  1013. * Map the cache flushing regions.
  1014. */
  1015. #ifdef FLUSH_BASE
  1016. map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
  1017. map.virtual = FLUSH_BASE;
  1018. map.length = SZ_1M;
  1019. map.type = MT_CACHECLEAN;
  1020. create_mapping(&map);
  1021. #endif
  1022. #ifdef FLUSH_BASE_MINICACHE
  1023. map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
  1024. map.virtual = FLUSH_BASE_MINICACHE;
  1025. map.length = SZ_1M;
  1026. map.type = MT_MINICLEAN;
  1027. create_mapping(&map);
  1028. #endif
  1029. /*
  1030. * Create a mapping for the machine vectors at the high-vectors
  1031. * location (0xffff0000). If we aren't using high-vectors, also
  1032. * create a mapping at the low-vectors virtual address.
  1033. */
  1034. map.pfn = __phys_to_pfn(virt_to_phys(vectors));
  1035. map.virtual = 0xffff0000;
  1036. map.length = PAGE_SIZE;
  1037. map.type = MT_HIGH_VECTORS;
  1038. create_mapping(&map);
  1039. if (!vectors_high()) {
  1040. map.virtual = 0;
  1041. map.type = MT_LOW_VECTORS;
  1042. create_mapping(&map);
  1043. }
  1044. /*
  1045. * Ask the machine support to map in the statically mapped devices.
  1046. */
  1047. if (mdesc->map_io)
  1048. mdesc->map_io();
  1049. fill_pmd_gaps();
  1050. /* Reserve fixed i/o space in VMALLOC region */
  1051. pci_reserve_io();
  1052. /*
  1053. * Finally flush the caches and tlb to ensure that we're in a
  1054. * consistent state wrt the writebuffer. This also ensures that
  1055. * any write-allocated cache lines in the vector page are written
  1056. * back. After this point, we can start to touch devices again.
  1057. */
  1058. local_flush_tlb_all();
  1059. flush_cache_all();
  1060. }
  1061. static void __init kmap_init(void)
  1062. {
  1063. #ifdef CONFIG_HIGHMEM
  1064. pkmap_page_table = early_pte_alloc(pmd_off_k(PKMAP_BASE),
  1065. PKMAP_BASE, _PAGE_KERNEL_TABLE);
  1066. #endif
  1067. }
  1068. static void __init map_lowmem(void)
  1069. {
  1070. struct memblock_region *reg;
  1071. /* Map all the lowmem memory banks. */
  1072. for_each_memblock(memory, reg) {
  1073. phys_addr_t start = reg->base;
  1074. phys_addr_t end = start + reg->size;
  1075. struct map_desc map;
  1076. if (end > arm_lowmem_limit)
  1077. end = arm_lowmem_limit;
  1078. if (start >= end)
  1079. break;
  1080. map.pfn = __phys_to_pfn(start);
  1081. map.virtual = __phys_to_virt(start);
  1082. map.length = end - start;
  1083. map.type = MT_MEMORY;
  1084. create_mapping(&map);
  1085. }
  1086. }
  1087. /*
  1088. * paging_init() sets up the page tables, initialises the zone memory
  1089. * maps, and sets up the zero page, bad page and bad page tables.
  1090. */
  1091. void __init paging_init(struct machine_desc *mdesc)
  1092. {
  1093. void *zero_page;
  1094. memblock_set_current_limit(arm_lowmem_limit);
  1095. build_mem_type_table();
  1096. prepare_page_table();
  1097. map_lowmem();
  1098. dma_contiguous_remap();
  1099. devicemaps_init(mdesc);
  1100. kmap_init();
  1101. top_pmd = pmd_off_k(0xffff0000);
  1102. /* allocate the zero page. */
  1103. zero_page = early_alloc(PAGE_SIZE);
  1104. bootmem_init();
  1105. empty_zero_page = virt_to_page(zero_page);
  1106. __flush_dcache_page(NULL, empty_zero_page);
  1107. }