mm-armv.c 16 KB

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