mm-armv.c 16 KB

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