mm-armv.c 16 KB

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