mm-armv.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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_SECT_UNCACHED |
  261. PMD_SECT_AP_WRITE,
  262. .domain = DOMAIN_IO,
  263. },
  264. [MT_CACHECLEAN] = {
  265. .prot_sect = PMD_TYPE_SECT,
  266. .domain = DOMAIN_KERNEL,
  267. },
  268. [MT_MINICLEAN] = {
  269. .prot_sect = PMD_TYPE_SECT | 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_SECT_AP_WRITE,
  286. .domain = DOMAIN_KERNEL,
  287. },
  288. [MT_ROM] = {
  289. .prot_sect = PMD_TYPE_SECT,
  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_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_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. if (cpu_arch <= CPU_ARCH_ARMv5TEJ) {
  331. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  332. if (mem_types[i].prot_l1)
  333. mem_types[i].prot_l1 |= PMD_BIT4;
  334. if (mem_types[i].prot_sect)
  335. mem_types[i].prot_sect |= PMD_BIT4;
  336. }
  337. }
  338. cp = &cache_policies[cachepolicy];
  339. kern_pgprot = user_pgprot = cp->pte;
  340. /*
  341. * Enable CPU-specific coherency if supported.
  342. * (Only available on XSC3 at the moment.)
  343. */
  344. if (arch_is_coherent()) {
  345. if (cpu_is_xsc3()) {
  346. mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
  347. mem_types[MT_MEMORY].prot_pte |= L_PTE_COHERENT;
  348. }
  349. }
  350. /*
  351. * ARMv6 and above have extended page tables.
  352. */
  353. if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
  354. /*
  355. * bit 4 becomes XN which we must clear for the
  356. * kernel memory mapping.
  357. */
  358. mem_types[MT_MEMORY].prot_sect &= ~PMD_BIT4;
  359. mem_types[MT_ROM].prot_sect &= ~PMD_BIT4;
  360. /*
  361. * Mark cache clean areas and XIP ROM read only
  362. * from SVC mode and no access from userspace.
  363. */
  364. mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  365. mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  366. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  367. /*
  368. * Mark the device area as "shared device"
  369. */
  370. mem_types[MT_DEVICE].prot_pte |= L_PTE_BUFFERABLE;
  371. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_BUFFERED;
  372. /*
  373. * User pages need to be mapped with the ASID
  374. * (iow, non-global)
  375. */
  376. user_pgprot |= L_PTE_ASID;
  377. #ifdef CONFIG_SMP
  378. /*
  379. * Mark memory with the "shared" attribute for SMP systems
  380. */
  381. user_pgprot |= L_PTE_SHARED;
  382. kern_pgprot |= L_PTE_SHARED;
  383. mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
  384. #endif
  385. }
  386. for (i = 0; i < 16; i++) {
  387. unsigned long v = pgprot_val(protection_map[i]);
  388. v = (v & ~(L_PTE_BUFFERABLE|L_PTE_CACHEABLE)) | user_pgprot;
  389. protection_map[i] = __pgprot(v);
  390. }
  391. mem_types[MT_LOW_VECTORS].prot_pte |= kern_pgprot;
  392. mem_types[MT_HIGH_VECTORS].prot_pte |= kern_pgprot;
  393. if (cpu_arch >= CPU_ARCH_ARMv5) {
  394. #ifndef CONFIG_SMP
  395. /*
  396. * Only use write-through for non-SMP systems
  397. */
  398. mem_types[MT_LOW_VECTORS].prot_pte &= ~L_PTE_BUFFERABLE;
  399. mem_types[MT_HIGH_VECTORS].prot_pte &= ~L_PTE_BUFFERABLE;
  400. #endif
  401. } else {
  402. mem_types[MT_MINICLEAN].prot_sect &= ~PMD_SECT_TEX(1);
  403. }
  404. pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
  405. L_PTE_DIRTY | L_PTE_WRITE |
  406. L_PTE_EXEC | kern_pgprot);
  407. mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
  408. mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
  409. mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
  410. mem_types[MT_ROM].prot_sect |= cp->pmd;
  411. switch (cp->pmd) {
  412. case PMD_SECT_WT:
  413. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
  414. break;
  415. case PMD_SECT_WB:
  416. case PMD_SECT_WBWA:
  417. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
  418. break;
  419. }
  420. printk("Memory policy: ECC %sabled, Data cache %s\n",
  421. ecc_mask ? "en" : "dis", cp->policy);
  422. }
  423. #define vectors_base() (vectors_high() ? 0xffff0000 : 0)
  424. /*
  425. * Create the page directory entries and any necessary
  426. * page tables for the mapping specified by `md'. We
  427. * are able to cope here with varying sizes and address
  428. * offsets, and we take full advantage of sections and
  429. * supersections.
  430. */
  431. void __init create_mapping(struct map_desc *md)
  432. {
  433. unsigned long virt, length;
  434. int prot_sect, prot_l1, domain;
  435. pgprot_t prot_pte;
  436. unsigned long off = (u32)__pfn_to_phys(md->pfn);
  437. if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) {
  438. printk(KERN_WARNING "BUG: not creating mapping for "
  439. "0x%08llx at 0x%08lx in user region\n",
  440. __pfn_to_phys((u64)md->pfn), md->virtual);
  441. return;
  442. }
  443. if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
  444. md->virtual >= PAGE_OFFSET && md->virtual < VMALLOC_END) {
  445. printk(KERN_WARNING "BUG: mapping for 0x%08llx at 0x%08lx "
  446. "overlaps vmalloc space\n",
  447. __pfn_to_phys((u64)md->pfn), md->virtual);
  448. }
  449. domain = mem_types[md->type].domain;
  450. prot_pte = __pgprot(mem_types[md->type].prot_pte);
  451. prot_l1 = mem_types[md->type].prot_l1 | PMD_DOMAIN(domain);
  452. prot_sect = mem_types[md->type].prot_sect | PMD_DOMAIN(domain);
  453. /*
  454. * Catch 36-bit addresses
  455. */
  456. if(md->pfn >= 0x100000) {
  457. if(domain) {
  458. printk(KERN_ERR "MM: invalid domain in supersection "
  459. "mapping for 0x%08llx at 0x%08lx\n",
  460. __pfn_to_phys((u64)md->pfn), md->virtual);
  461. return;
  462. }
  463. if((md->virtual | md->length | __pfn_to_phys(md->pfn))
  464. & ~SUPERSECTION_MASK) {
  465. printk(KERN_ERR "MM: cannot create mapping for "
  466. "0x%08llx at 0x%08lx invalid alignment\n",
  467. __pfn_to_phys((u64)md->pfn), md->virtual);
  468. return;
  469. }
  470. /*
  471. * Shift bits [35:32] of address into bits [23:20] of PMD
  472. * (See ARMv6 spec).
  473. */
  474. off |= (((md->pfn >> (32 - PAGE_SHIFT)) & 0xF) << 20);
  475. }
  476. virt = md->virtual;
  477. off -= virt;
  478. length = md->length;
  479. if (mem_types[md->type].prot_l1 == 0 &&
  480. (virt & 0xfffff || (virt + off) & 0xfffff || (virt + length) & 0xfffff)) {
  481. printk(KERN_WARNING "BUG: map for 0x%08lx at 0x%08lx can not "
  482. "be mapped using pages, ignoring.\n",
  483. __pfn_to_phys(md->pfn), md->virtual);
  484. return;
  485. }
  486. while ((virt & 0xfffff || (virt + off) & 0xfffff) && length >= PAGE_SIZE) {
  487. alloc_init_page(virt, virt + off, prot_l1, prot_pte);
  488. virt += PAGE_SIZE;
  489. length -= PAGE_SIZE;
  490. }
  491. /* N.B. ARMv6 supersections are only defined to work with domain 0.
  492. * Since domain assignments can in fact be arbitrary, the
  493. * 'domain == 0' check below is required to insure that ARMv6
  494. * supersections are only allocated for domain 0 regardless
  495. * of the actual domain assignments in use.
  496. */
  497. if ((cpu_architecture() >= CPU_ARCH_ARMv6 || cpu_is_xsc3())
  498. && domain == 0) {
  499. /*
  500. * Align to supersection boundary if !high pages.
  501. * High pages have already been checked for proper
  502. * alignment above and they will fail the SUPSERSECTION_MASK
  503. * check because of the way the address is encoded into
  504. * offset.
  505. */
  506. if (md->pfn <= 0x100000) {
  507. while ((virt & ~SUPERSECTION_MASK ||
  508. (virt + off) & ~SUPERSECTION_MASK) &&
  509. length >= (PGDIR_SIZE / 2)) {
  510. alloc_init_section(virt, virt + off, prot_sect);
  511. virt += (PGDIR_SIZE / 2);
  512. length -= (PGDIR_SIZE / 2);
  513. }
  514. }
  515. while (length >= SUPERSECTION_SIZE) {
  516. alloc_init_supersection(virt, virt + off, prot_sect);
  517. virt += SUPERSECTION_SIZE;
  518. length -= SUPERSECTION_SIZE;
  519. }
  520. }
  521. /*
  522. * A section mapping covers half a "pgdir" entry.
  523. */
  524. while (length >= (PGDIR_SIZE / 2)) {
  525. alloc_init_section(virt, virt + off, prot_sect);
  526. virt += (PGDIR_SIZE / 2);
  527. length -= (PGDIR_SIZE / 2);
  528. }
  529. while (length >= PAGE_SIZE) {
  530. alloc_init_page(virt, virt + off, prot_l1, prot_pte);
  531. virt += PAGE_SIZE;
  532. length -= PAGE_SIZE;
  533. }
  534. }
  535. /*
  536. * In order to soft-boot, we need to insert a 1:1 mapping in place of
  537. * the user-mode pages. This will then ensure that we have predictable
  538. * results when turning the mmu off
  539. */
  540. void setup_mm_for_reboot(char mode)
  541. {
  542. unsigned long base_pmdval;
  543. pgd_t *pgd;
  544. int i;
  545. if (current->mm && current->mm->pgd)
  546. pgd = current->mm->pgd;
  547. else
  548. pgd = init_mm.pgd;
  549. base_pmdval = PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT;
  550. if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ)
  551. base_pmdval |= PMD_BIT4;
  552. for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
  553. unsigned long pmdval = (i << PGDIR_SHIFT) | base_pmdval;
  554. pmd_t *pmd;
  555. pmd = pmd_off(pgd, i << PGDIR_SHIFT);
  556. pmd[0] = __pmd(pmdval);
  557. pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
  558. flush_pmd_entry(pmd);
  559. }
  560. }
  561. /*
  562. * Create the architecture specific mappings
  563. */
  564. void __init iotable_init(struct map_desc *io_desc, int nr)
  565. {
  566. int i;
  567. for (i = 0; i < nr; i++)
  568. create_mapping(io_desc + i);
  569. }