mm-armv.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * linux/arch/arm/mm/mm-armv.c
  3. *
  4. * Copyright (C) 1998-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. * Page table sludge for ARM v3 and v4 processor architectures.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/module.h>
  14. #include <linux/mm.h>
  15. #include <linux/init.h>
  16. #include <linux/bootmem.h>
  17. #include <linux/highmem.h>
  18. #include <linux/nodemask.h>
  19. #include <asm/pgalloc.h>
  20. #include <asm/page.h>
  21. #include <asm/setup.h>
  22. #include <asm/tlbflush.h>
  23. #include <asm/mach/map.h>
  24. #define CPOLICY_UNCACHED 0
  25. #define CPOLICY_BUFFERED 1
  26. #define CPOLICY_WRITETHROUGH 2
  27. #define CPOLICY_WRITEBACK 3
  28. #define CPOLICY_WRITEALLOC 4
  29. static unsigned int cachepolicy __initdata = CPOLICY_WRITEBACK;
  30. static unsigned int ecc_mask __initdata = 0;
  31. pgprot_t pgprot_kernel;
  32. EXPORT_SYMBOL(pgprot_kernel);
  33. pmd_t *top_pmd;
  34. struct cachepolicy {
  35. const char policy[16];
  36. unsigned int cr_mask;
  37. unsigned int pmd;
  38. unsigned int pte;
  39. };
  40. static struct cachepolicy cache_policies[] __initdata = {
  41. {
  42. .policy = "uncached",
  43. .cr_mask = CR_W|CR_C,
  44. .pmd = PMD_SECT_UNCACHED,
  45. .pte = 0,
  46. }, {
  47. .policy = "buffered",
  48. .cr_mask = CR_C,
  49. .pmd = PMD_SECT_BUFFERED,
  50. .pte = PTE_BUFFERABLE,
  51. }, {
  52. .policy = "writethrough",
  53. .cr_mask = 0,
  54. .pmd = PMD_SECT_WT,
  55. .pte = PTE_CACHEABLE,
  56. }, {
  57. .policy = "writeback",
  58. .cr_mask = 0,
  59. .pmd = PMD_SECT_WB,
  60. .pte = PTE_BUFFERABLE|PTE_CACHEABLE,
  61. }, {
  62. .policy = "writealloc",
  63. .cr_mask = 0,
  64. .pmd = PMD_SECT_WBWA,
  65. .pte = PTE_BUFFERABLE|PTE_CACHEABLE,
  66. }
  67. };
  68. /*
  69. * These are useful for identifing cache coherency
  70. * problems by allowing the cache or the cache and
  71. * writebuffer to be turned off. (Note: the write
  72. * buffer should not be on and the cache off).
  73. */
  74. static void __init early_cachepolicy(char **p)
  75. {
  76. int i;
  77. for (i = 0; i < ARRAY_SIZE(cache_policies); i++) {
  78. int len = strlen(cache_policies[i].policy);
  79. if (memcmp(*p, cache_policies[i].policy, len) == 0) {
  80. cachepolicy = i;
  81. cr_alignment &= ~cache_policies[i].cr_mask;
  82. cr_no_alignment &= ~cache_policies[i].cr_mask;
  83. *p += len;
  84. break;
  85. }
  86. }
  87. if (i == ARRAY_SIZE(cache_policies))
  88. printk(KERN_ERR "ERROR: unknown or unsupported cache policy\n");
  89. flush_cache_all();
  90. set_cr(cr_alignment);
  91. }
  92. static void __init early_nocache(char **__unused)
  93. {
  94. char *p = "buffered";
  95. printk(KERN_WARNING "nocache is deprecated; use cachepolicy=%s\n", p);
  96. early_cachepolicy(&p);
  97. }
  98. static void __init early_nowrite(char **__unused)
  99. {
  100. char *p = "uncached";
  101. printk(KERN_WARNING "nowb is deprecated; use cachepolicy=%s\n", p);
  102. early_cachepolicy(&p);
  103. }
  104. static void __init early_ecc(char **p)
  105. {
  106. if (memcmp(*p, "on", 2) == 0) {
  107. ecc_mask = PMD_PROTECTION;
  108. *p += 2;
  109. } else if (memcmp(*p, "off", 3) == 0) {
  110. ecc_mask = 0;
  111. *p += 3;
  112. }
  113. }
  114. __early_param("nocache", early_nocache);
  115. __early_param("nowb", early_nowrite);
  116. __early_param("cachepolicy=", early_cachepolicy);
  117. __early_param("ecc=", early_ecc);
  118. static int __init noalign_setup(char *__unused)
  119. {
  120. cr_alignment &= ~CR_A;
  121. cr_no_alignment &= ~CR_A;
  122. set_cr(cr_alignment);
  123. return 1;
  124. }
  125. __setup("noalign", noalign_setup);
  126. #define FIRST_KERNEL_PGD_NR (FIRST_USER_PGD_NR + USER_PTRS_PER_PGD)
  127. static inline pmd_t *pmd_off(pgd_t *pgd, unsigned long virt)
  128. {
  129. return pmd_offset(pgd, virt);
  130. }
  131. static inline pmd_t *pmd_off_k(unsigned long virt)
  132. {
  133. return pmd_off(pgd_offset_k(virt), virt);
  134. }
  135. /*
  136. * need to get a 16k page for level 1
  137. */
  138. pgd_t *get_pgd_slow(struct mm_struct *mm)
  139. {
  140. pgd_t *new_pgd, *init_pgd;
  141. pmd_t *new_pmd, *init_pmd;
  142. pte_t *new_pte, *init_pte;
  143. new_pgd = (pgd_t *)__get_free_pages(GFP_KERNEL, 2);
  144. if (!new_pgd)
  145. goto no_pgd;
  146. memzero(new_pgd, FIRST_KERNEL_PGD_NR * sizeof(pgd_t));
  147. /*
  148. * Copy over the kernel and IO PGD entries
  149. */
  150. init_pgd = pgd_offset_k(0);
  151. memcpy(new_pgd + FIRST_KERNEL_PGD_NR, init_pgd + FIRST_KERNEL_PGD_NR,
  152. (PTRS_PER_PGD - FIRST_KERNEL_PGD_NR) * sizeof(pgd_t));
  153. clean_dcache_area(new_pgd, PTRS_PER_PGD * sizeof(pgd_t));
  154. if (!vectors_high()) {
  155. /*
  156. * On ARM, first page must always be allocated since it
  157. * contains the machine vectors.
  158. */
  159. new_pmd = pmd_alloc(mm, new_pgd, 0);
  160. if (!new_pmd)
  161. goto no_pmd;
  162. new_pte = pte_alloc_map(mm, new_pmd, 0);
  163. if (!new_pte)
  164. goto no_pte;
  165. init_pmd = pmd_offset(init_pgd, 0);
  166. init_pte = pte_offset_map_nested(init_pmd, 0);
  167. set_pte(new_pte, *init_pte);
  168. pte_unmap_nested(init_pte);
  169. pte_unmap(new_pte);
  170. }
  171. return new_pgd;
  172. no_pte:
  173. pmd_free(new_pmd);
  174. no_pmd:
  175. free_pages((unsigned long)new_pgd, 2);
  176. no_pgd:
  177. return NULL;
  178. }
  179. void free_pgd_slow(pgd_t *pgd)
  180. {
  181. pmd_t *pmd;
  182. struct page *pte;
  183. if (!pgd)
  184. return;
  185. /* pgd is always present and good */
  186. pmd = pmd_off(pgd, 0);
  187. if (pmd_none(*pmd))
  188. goto free;
  189. if (pmd_bad(*pmd)) {
  190. pmd_ERROR(*pmd);
  191. pmd_clear(pmd);
  192. goto free;
  193. }
  194. pte = pmd_page(*pmd);
  195. pmd_clear(pmd);
  196. dec_page_state(nr_page_table_pages);
  197. pte_lock_deinit(pte);
  198. pte_free(pte);
  199. pmd_free(pmd);
  200. free:
  201. free_pages((unsigned long) pgd, 2);
  202. }
  203. /*
  204. * Create a SECTION PGD between VIRT and PHYS in domain
  205. * DOMAIN with protection PROT. This operates on half-
  206. * pgdir entry increments.
  207. */
  208. static inline void
  209. alloc_init_section(unsigned long virt, unsigned long phys, int prot)
  210. {
  211. pmd_t *pmdp = pmd_off_k(virt);
  212. if (virt & (1 << 20))
  213. pmdp++;
  214. *pmdp = __pmd(phys | prot);
  215. flush_pmd_entry(pmdp);
  216. }
  217. /*
  218. * Create a SUPER SECTION PGD between VIRT and PHYS with protection PROT
  219. */
  220. static inline void
  221. alloc_init_supersection(unsigned long virt, unsigned long phys, int prot)
  222. {
  223. int i;
  224. for (i = 0; i < 16; i += 1) {
  225. alloc_init_section(virt, phys, prot | PMD_SECT_SUPER);
  226. virt += (PGDIR_SIZE / 2);
  227. }
  228. }
  229. /*
  230. * Add a PAGE mapping between VIRT and PHYS in domain
  231. * DOMAIN with protection PROT. Note that due to the
  232. * way we map the PTEs, we must allocate two PTE_SIZE'd
  233. * blocks - one for the Linux pte table, and one for
  234. * the hardware pte table.
  235. */
  236. static inline void
  237. alloc_init_page(unsigned long virt, unsigned long phys, unsigned int prot_l1, pgprot_t prot)
  238. {
  239. pmd_t *pmdp = pmd_off_k(virt);
  240. pte_t *ptep;
  241. if (pmd_none(*pmdp)) {
  242. ptep = alloc_bootmem_low_pages(2 * PTRS_PER_PTE *
  243. sizeof(pte_t));
  244. __pmd_populate(pmdp, __pa(ptep) | prot_l1);
  245. }
  246. ptep = pte_offset_kernel(pmdp, virt);
  247. set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot));
  248. }
  249. struct mem_types {
  250. unsigned int prot_pte;
  251. unsigned int prot_l1;
  252. unsigned int prot_sect;
  253. unsigned int domain;
  254. };
  255. static struct mem_types mem_types[] __initdata = {
  256. [MT_DEVICE] = {
  257. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  258. L_PTE_WRITE,
  259. .prot_l1 = PMD_TYPE_TABLE,
  260. .prot_sect = PMD_TYPE_SECT | PMD_BIT4 | PMD_SECT_UNCACHED |
  261. PMD_SECT_AP_WRITE,
  262. .domain = DOMAIN_IO,
  263. },
  264. [MT_CACHECLEAN] = {
  265. .prot_sect = PMD_TYPE_SECT | PMD_BIT4,
  266. .domain = DOMAIN_KERNEL,
  267. },
  268. [MT_MINICLEAN] = {
  269. .prot_sect = PMD_TYPE_SECT | PMD_BIT4 | PMD_SECT_MINICACHE,
  270. .domain = DOMAIN_KERNEL,
  271. },
  272. [MT_LOW_VECTORS] = {
  273. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  274. L_PTE_EXEC,
  275. .prot_l1 = PMD_TYPE_TABLE,
  276. .domain = DOMAIN_USER,
  277. },
  278. [MT_HIGH_VECTORS] = {
  279. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  280. L_PTE_USER | L_PTE_EXEC,
  281. .prot_l1 = PMD_TYPE_TABLE,
  282. .domain = DOMAIN_USER,
  283. },
  284. [MT_MEMORY] = {
  285. .prot_sect = PMD_TYPE_SECT | PMD_BIT4 | PMD_SECT_AP_WRITE,
  286. .domain = DOMAIN_KERNEL,
  287. },
  288. [MT_ROM] = {
  289. .prot_sect = PMD_TYPE_SECT | PMD_BIT4,
  290. .domain = DOMAIN_KERNEL,
  291. },
  292. [MT_IXP2000_DEVICE] = { /* IXP2400 requires XCB=101 for on-chip I/O */
  293. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  294. L_PTE_WRITE,
  295. .prot_l1 = PMD_TYPE_TABLE,
  296. .prot_sect = PMD_TYPE_SECT | PMD_BIT4 | PMD_SECT_UNCACHED |
  297. PMD_SECT_AP_WRITE | PMD_SECT_BUFFERABLE |
  298. PMD_SECT_TEX(1),
  299. .domain = DOMAIN_IO,
  300. },
  301. [MT_NONSHARED_DEVICE] = {
  302. .prot_l1 = PMD_TYPE_TABLE,
  303. .prot_sect = PMD_TYPE_SECT | PMD_BIT4 | PMD_SECT_NONSHARED_DEV |
  304. PMD_SECT_AP_WRITE,
  305. .domain = DOMAIN_IO,
  306. }
  307. };
  308. /*
  309. * Adjust the PMD section entries according to the CPU in use.
  310. */
  311. void __init build_mem_type_table(void)
  312. {
  313. struct cachepolicy *cp;
  314. unsigned int cr = get_cr();
  315. unsigned int user_pgprot, kern_pgprot;
  316. int cpu_arch = cpu_architecture();
  317. int i;
  318. #if defined(CONFIG_CPU_DCACHE_DISABLE)
  319. if (cachepolicy > CPOLICY_BUFFERED)
  320. cachepolicy = CPOLICY_BUFFERED;
  321. #elif defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
  322. if (cachepolicy > CPOLICY_WRITETHROUGH)
  323. cachepolicy = CPOLICY_WRITETHROUGH;
  324. #endif
  325. if (cpu_arch < CPU_ARCH_ARMv5) {
  326. if (cachepolicy >= CPOLICY_WRITEALLOC)
  327. cachepolicy = CPOLICY_WRITEBACK;
  328. ecc_mask = 0;
  329. }
  330. /*
  331. * Xscale must not have PMD bit 4 set for section mappings.
  332. */
  333. if (cpu_is_xscale())
  334. for (i = 0; i < ARRAY_SIZE(mem_types); i++)
  335. mem_types[i].prot_sect &= ~PMD_BIT4;
  336. /*
  337. * ARMv5 and lower, excluding Xscale, bit 4 must be set for
  338. * page tables.
  339. */
  340. if (cpu_arch < CPU_ARCH_ARMv6 && !cpu_is_xscale())
  341. for (i = 0; i < ARRAY_SIZE(mem_types); i++)
  342. if (mem_types[i].prot_l1)
  343. mem_types[i].prot_l1 |= PMD_BIT4;
  344. cp = &cache_policies[cachepolicy];
  345. kern_pgprot = user_pgprot = cp->pte;
  346. /*
  347. * Enable CPU-specific coherency if supported.
  348. * (Only available on XSC3 at the moment.)
  349. */
  350. if (arch_is_coherent()) {
  351. if (cpu_is_xsc3()) {
  352. mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
  353. mem_types[MT_MEMORY].prot_pte |= L_PTE_COHERENT;
  354. }
  355. }
  356. /*
  357. * ARMv6 and above have extended page tables.
  358. */
  359. if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
  360. /*
  361. * bit 4 becomes XN which we must clear for the
  362. * kernel memory mapping.
  363. */
  364. mem_types[MT_MEMORY].prot_sect &= ~PMD_SECT_XN;
  365. mem_types[MT_ROM].prot_sect &= ~PMD_SECT_XN;
  366. /*
  367. * Mark cache clean areas and XIP ROM read only
  368. * from SVC mode and no access from userspace.
  369. */
  370. mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  371. mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  372. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  373. /*
  374. * Mark the device area as "shared device"
  375. */
  376. mem_types[MT_DEVICE].prot_pte |= L_PTE_BUFFERABLE;
  377. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_BUFFERED;
  378. /*
  379. * User pages need to be mapped with the ASID
  380. * (iow, non-global)
  381. */
  382. user_pgprot |= L_PTE_ASID;
  383. #ifdef CONFIG_SMP
  384. /*
  385. * Mark memory with the "shared" attribute for SMP systems
  386. */
  387. user_pgprot |= L_PTE_SHARED;
  388. kern_pgprot |= L_PTE_SHARED;
  389. mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
  390. #endif
  391. }
  392. for (i = 0; i < 16; i++) {
  393. unsigned long v = pgprot_val(protection_map[i]);
  394. v = (v & ~(L_PTE_BUFFERABLE|L_PTE_CACHEABLE)) | user_pgprot;
  395. protection_map[i] = __pgprot(v);
  396. }
  397. mem_types[MT_LOW_VECTORS].prot_pte |= kern_pgprot;
  398. mem_types[MT_HIGH_VECTORS].prot_pte |= kern_pgprot;
  399. if (cpu_arch >= CPU_ARCH_ARMv5) {
  400. #ifndef CONFIG_SMP
  401. /*
  402. * Only use write-through for non-SMP systems
  403. */
  404. mem_types[MT_LOW_VECTORS].prot_pte &= ~L_PTE_BUFFERABLE;
  405. mem_types[MT_HIGH_VECTORS].prot_pte &= ~L_PTE_BUFFERABLE;
  406. #endif
  407. } else {
  408. mem_types[MT_MINICLEAN].prot_sect &= ~PMD_SECT_TEX(1);
  409. }
  410. pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
  411. L_PTE_DIRTY | L_PTE_WRITE |
  412. L_PTE_EXEC | kern_pgprot);
  413. mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
  414. mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
  415. mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
  416. mem_types[MT_ROM].prot_sect |= cp->pmd;
  417. switch (cp->pmd) {
  418. case PMD_SECT_WT:
  419. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
  420. break;
  421. case PMD_SECT_WB:
  422. case PMD_SECT_WBWA:
  423. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
  424. break;
  425. }
  426. printk("Memory policy: ECC %sabled, Data cache %s\n",
  427. ecc_mask ? "en" : "dis", cp->policy);
  428. }
  429. #define vectors_base() (vectors_high() ? 0xffff0000 : 0)
  430. /*
  431. * Create the page directory entries and any necessary
  432. * page tables for the mapping specified by `md'. We
  433. * are able to cope here with varying sizes and address
  434. * offsets, and we take full advantage of sections and
  435. * supersections.
  436. */
  437. void __init create_mapping(struct map_desc *md)
  438. {
  439. unsigned long virt, length;
  440. int prot_sect, prot_l1, domain;
  441. pgprot_t prot_pte;
  442. unsigned long off = (u32)__pfn_to_phys(md->pfn);
  443. if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) {
  444. printk(KERN_WARNING "BUG: not creating mapping for "
  445. "0x%08llx at 0x%08lx in user region\n",
  446. __pfn_to_phys((u64)md->pfn), md->virtual);
  447. return;
  448. }
  449. if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
  450. md->virtual >= PAGE_OFFSET && md->virtual < VMALLOC_END) {
  451. printk(KERN_WARNING "BUG: mapping for 0x%08llx at 0x%08lx "
  452. "overlaps vmalloc space\n",
  453. __pfn_to_phys((u64)md->pfn), md->virtual);
  454. }
  455. domain = mem_types[md->type].domain;
  456. prot_pte = __pgprot(mem_types[md->type].prot_pte);
  457. prot_l1 = mem_types[md->type].prot_l1 | PMD_DOMAIN(domain);
  458. prot_sect = mem_types[md->type].prot_sect | PMD_DOMAIN(domain);
  459. /*
  460. * Catch 36-bit addresses
  461. */
  462. if(md->pfn >= 0x100000) {
  463. if(domain) {
  464. printk(KERN_ERR "MM: invalid domain in supersection "
  465. "mapping for 0x%08llx at 0x%08lx\n",
  466. __pfn_to_phys((u64)md->pfn), md->virtual);
  467. return;
  468. }
  469. if((md->virtual | md->length | __pfn_to_phys(md->pfn))
  470. & ~SUPERSECTION_MASK) {
  471. printk(KERN_ERR "MM: cannot create mapping for "
  472. "0x%08llx at 0x%08lx invalid alignment\n",
  473. __pfn_to_phys((u64)md->pfn), md->virtual);
  474. return;
  475. }
  476. /*
  477. * Shift bits [35:32] of address into bits [23:20] of PMD
  478. * (See ARMv6 spec).
  479. */
  480. off |= (((md->pfn >> (32 - PAGE_SHIFT)) & 0xF) << 20);
  481. }
  482. virt = md->virtual;
  483. off -= virt;
  484. length = md->length;
  485. if (mem_types[md->type].prot_l1 == 0 &&
  486. (virt & 0xfffff || (virt + off) & 0xfffff || (virt + length) & 0xfffff)) {
  487. printk(KERN_WARNING "BUG: map for 0x%08lx at 0x%08lx can not "
  488. "be mapped using pages, ignoring.\n",
  489. __pfn_to_phys(md->pfn), md->virtual);
  490. return;
  491. }
  492. while ((virt & 0xfffff || (virt + off) & 0xfffff) && length >= PAGE_SIZE) {
  493. alloc_init_page(virt, virt + off, prot_l1, prot_pte);
  494. virt += PAGE_SIZE;
  495. length -= PAGE_SIZE;
  496. }
  497. /* N.B. ARMv6 supersections are only defined to work with domain 0.
  498. * Since domain assignments can in fact be arbitrary, the
  499. * 'domain == 0' check below is required to insure that ARMv6
  500. * supersections are only allocated for domain 0 regardless
  501. * of the actual domain assignments in use.
  502. */
  503. if ((cpu_architecture() >= CPU_ARCH_ARMv6 || cpu_is_xsc3())
  504. && domain == 0) {
  505. /*
  506. * Align to supersection boundary if !high pages.
  507. * High pages have already been checked for proper
  508. * alignment above and they will fail the SUPSERSECTION_MASK
  509. * check because of the way the address is encoded into
  510. * offset.
  511. */
  512. if (md->pfn <= 0x100000) {
  513. while ((virt & ~SUPERSECTION_MASK ||
  514. (virt + off) & ~SUPERSECTION_MASK) &&
  515. length >= (PGDIR_SIZE / 2)) {
  516. alloc_init_section(virt, virt + off, prot_sect);
  517. virt += (PGDIR_SIZE / 2);
  518. length -= (PGDIR_SIZE / 2);
  519. }
  520. }
  521. while (length >= SUPERSECTION_SIZE) {
  522. alloc_init_supersection(virt, virt + off, prot_sect);
  523. virt += SUPERSECTION_SIZE;
  524. length -= SUPERSECTION_SIZE;
  525. }
  526. }
  527. /*
  528. * A section mapping covers half a "pgdir" entry.
  529. */
  530. while (length >= (PGDIR_SIZE / 2)) {
  531. alloc_init_section(virt, virt + off, prot_sect);
  532. virt += (PGDIR_SIZE / 2);
  533. length -= (PGDIR_SIZE / 2);
  534. }
  535. while (length >= PAGE_SIZE) {
  536. alloc_init_page(virt, virt + off, prot_l1, prot_pte);
  537. virt += PAGE_SIZE;
  538. length -= PAGE_SIZE;
  539. }
  540. }
  541. /*
  542. * In order to soft-boot, we need to insert a 1:1 mapping in place of
  543. * the user-mode pages. This will then ensure that we have predictable
  544. * results when turning the mmu off
  545. */
  546. void setup_mm_for_reboot(char mode)
  547. {
  548. unsigned long base_pmdval;
  549. pgd_t *pgd;
  550. int i;
  551. if (current->mm && current->mm->pgd)
  552. pgd = current->mm->pgd;
  553. else
  554. pgd = init_mm.pgd;
  555. base_pmdval = PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT;
  556. if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ && !cpu_is_xscale())
  557. base_pmdval |= PMD_BIT4;
  558. for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
  559. unsigned long pmdval = (i << PGDIR_SHIFT) | base_pmdval;
  560. pmd_t *pmd;
  561. pmd = pmd_off(pgd, i << PGDIR_SHIFT);
  562. pmd[0] = __pmd(pmdval);
  563. pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
  564. flush_pmd_entry(pmd);
  565. }
  566. }
  567. /*
  568. * Create the architecture specific mappings
  569. */
  570. void __init iotable_init(struct map_desc *io_desc, int nr)
  571. {
  572. int i;
  573. for (i = 0; i < nr; i++)
  574. create_mapping(io_desc + i);
  575. }