mm-armv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*
  2. * linux/arch/arm/mm/mm-armv.c
  3. *
  4. * Copyright (C) 1998-2002 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. * This lock is here just to satisfy pmd_alloc and pte_lock
  158. */
  159. spin_lock(&mm->page_table_lock);
  160. /*
  161. * On ARM, first page must always be allocated since it
  162. * contains the machine vectors.
  163. */
  164. new_pmd = pmd_alloc(mm, new_pgd, 0);
  165. if (!new_pmd)
  166. goto no_pmd;
  167. new_pte = pte_alloc_map(mm, new_pmd, 0);
  168. if (!new_pte)
  169. goto no_pte;
  170. init_pmd = pmd_offset(init_pgd, 0);
  171. init_pte = pte_offset_map_nested(init_pmd, 0);
  172. set_pte(new_pte, *init_pte);
  173. pte_unmap_nested(init_pte);
  174. pte_unmap(new_pte);
  175. spin_unlock(&mm->page_table_lock);
  176. }
  177. return new_pgd;
  178. no_pte:
  179. spin_unlock(&mm->page_table_lock);
  180. pmd_free(new_pmd);
  181. free_pages((unsigned long)new_pgd, 2);
  182. return NULL;
  183. no_pmd:
  184. spin_unlock(&mm->page_table_lock);
  185. free_pages((unsigned long)new_pgd, 2);
  186. return NULL;
  187. no_pgd:
  188. return NULL;
  189. }
  190. void free_pgd_slow(pgd_t *pgd)
  191. {
  192. pmd_t *pmd;
  193. struct page *pte;
  194. if (!pgd)
  195. return;
  196. /* pgd is always present and good */
  197. pmd = pmd_off(pgd, 0);
  198. if (pmd_none(*pmd))
  199. goto free;
  200. if (pmd_bad(*pmd)) {
  201. pmd_ERROR(*pmd);
  202. pmd_clear(pmd);
  203. goto free;
  204. }
  205. pte = pmd_page(*pmd);
  206. pmd_clear(pmd);
  207. dec_page_state(nr_page_table_pages);
  208. pte_free(pte);
  209. pmd_free(pmd);
  210. free:
  211. free_pages((unsigned long) pgd, 2);
  212. }
  213. /*
  214. * Create a SECTION PGD between VIRT and PHYS in domain
  215. * DOMAIN with protection PROT. This operates on half-
  216. * pgdir entry increments.
  217. */
  218. static inline void
  219. alloc_init_section(unsigned long virt, unsigned long phys, int prot)
  220. {
  221. pmd_t *pmdp = pmd_off_k(virt);
  222. if (virt & (1 << 20))
  223. pmdp++;
  224. *pmdp = __pmd(phys | prot);
  225. flush_pmd_entry(pmdp);
  226. }
  227. /*
  228. * Create a SUPER SECTION PGD between VIRT and PHYS with protection PROT
  229. */
  230. static inline void
  231. alloc_init_supersection(unsigned long virt, unsigned long phys, int prot)
  232. {
  233. int i;
  234. for (i = 0; i < 16; i += 1) {
  235. alloc_init_section(virt, phys, prot | PMD_SECT_SUPER);
  236. virt += (PGDIR_SIZE / 2);
  237. }
  238. }
  239. /*
  240. * Add a PAGE mapping between VIRT and PHYS in domain
  241. * DOMAIN with protection PROT. Note that due to the
  242. * way we map the PTEs, we must allocate two PTE_SIZE'd
  243. * blocks - one for the Linux pte table, and one for
  244. * the hardware pte table.
  245. */
  246. static inline void
  247. alloc_init_page(unsigned long virt, unsigned long phys, unsigned int prot_l1, pgprot_t prot)
  248. {
  249. pmd_t *pmdp = pmd_off_k(virt);
  250. pte_t *ptep;
  251. if (pmd_none(*pmdp)) {
  252. ptep = alloc_bootmem_low_pages(2 * PTRS_PER_PTE *
  253. sizeof(pte_t));
  254. __pmd_populate(pmdp, __pa(ptep) | prot_l1);
  255. }
  256. ptep = pte_offset_kernel(pmdp, virt);
  257. set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot));
  258. }
  259. /*
  260. * Clear any PGD mapping. On a two-level page table system,
  261. * the clearance is done by the middle-level functions (pmd)
  262. * rather than the top-level (pgd) functions.
  263. */
  264. static inline void clear_mapping(unsigned long virt)
  265. {
  266. pmd_clear(pmd_off_k(virt));
  267. }
  268. struct mem_types {
  269. unsigned int prot_pte;
  270. unsigned int prot_l1;
  271. unsigned int prot_sect;
  272. unsigned int domain;
  273. };
  274. static struct mem_types mem_types[] __initdata = {
  275. [MT_DEVICE] = {
  276. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  277. L_PTE_WRITE,
  278. .prot_l1 = PMD_TYPE_TABLE,
  279. .prot_sect = PMD_TYPE_SECT | PMD_SECT_UNCACHED |
  280. PMD_SECT_AP_WRITE,
  281. .domain = DOMAIN_IO,
  282. },
  283. [MT_CACHECLEAN] = {
  284. .prot_sect = PMD_TYPE_SECT,
  285. .domain = DOMAIN_KERNEL,
  286. },
  287. [MT_MINICLEAN] = {
  288. .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE,
  289. .domain = DOMAIN_KERNEL,
  290. },
  291. [MT_LOW_VECTORS] = {
  292. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  293. L_PTE_EXEC,
  294. .prot_l1 = PMD_TYPE_TABLE,
  295. .domain = DOMAIN_USER,
  296. },
  297. [MT_HIGH_VECTORS] = {
  298. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  299. L_PTE_USER | L_PTE_EXEC,
  300. .prot_l1 = PMD_TYPE_TABLE,
  301. .domain = DOMAIN_USER,
  302. },
  303. [MT_MEMORY] = {
  304. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  305. .domain = DOMAIN_KERNEL,
  306. },
  307. [MT_ROM] = {
  308. .prot_sect = PMD_TYPE_SECT,
  309. .domain = DOMAIN_KERNEL,
  310. },
  311. [MT_IXP2000_DEVICE] = { /* IXP2400 requires XCB=101 for on-chip I/O */
  312. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  313. L_PTE_WRITE,
  314. .prot_l1 = PMD_TYPE_TABLE,
  315. .prot_sect = PMD_TYPE_SECT | PMD_SECT_UNCACHED |
  316. PMD_SECT_AP_WRITE | PMD_SECT_BUFFERABLE |
  317. PMD_SECT_TEX(1),
  318. .domain = DOMAIN_IO,
  319. }
  320. };
  321. /*
  322. * Adjust the PMD section entries according to the CPU in use.
  323. */
  324. static void __init build_mem_type_table(void)
  325. {
  326. struct cachepolicy *cp;
  327. unsigned int cr = get_cr();
  328. unsigned int user_pgprot;
  329. int cpu_arch = cpu_architecture();
  330. int i;
  331. #if defined(CONFIG_CPU_DCACHE_DISABLE)
  332. if (cachepolicy > CPOLICY_BUFFERED)
  333. cachepolicy = CPOLICY_BUFFERED;
  334. #elif defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
  335. if (cachepolicy > CPOLICY_WRITETHROUGH)
  336. cachepolicy = CPOLICY_WRITETHROUGH;
  337. #endif
  338. if (cpu_arch < CPU_ARCH_ARMv5) {
  339. if (cachepolicy >= CPOLICY_WRITEALLOC)
  340. cachepolicy = CPOLICY_WRITEBACK;
  341. ecc_mask = 0;
  342. }
  343. if (cpu_arch <= CPU_ARCH_ARMv5TEJ) {
  344. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  345. if (mem_types[i].prot_l1)
  346. mem_types[i].prot_l1 |= PMD_BIT4;
  347. if (mem_types[i].prot_sect)
  348. mem_types[i].prot_sect |= PMD_BIT4;
  349. }
  350. }
  351. cp = &cache_policies[cachepolicy];
  352. user_pgprot = cp->pte;
  353. /*
  354. * ARMv6 and above have extended page tables.
  355. */
  356. if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
  357. /*
  358. * bit 4 becomes XN which we must clear for the
  359. * kernel memory mapping.
  360. */
  361. mem_types[MT_MEMORY].prot_sect &= ~PMD_BIT4;
  362. mem_types[MT_ROM].prot_sect &= ~PMD_BIT4;
  363. /*
  364. * Mark cache clean areas and XIP ROM read only
  365. * from SVC mode and no access from userspace.
  366. */
  367. mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  368. mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  369. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  370. /*
  371. * Mark the device area as "shared device"
  372. */
  373. mem_types[MT_DEVICE].prot_pte |= L_PTE_BUFFERABLE;
  374. mem_types[MT_DEVICE].prot_sect |= PMD_SECT_BUFFERED;
  375. /*
  376. * User pages need to be mapped with the ASID
  377. * (iow, non-global)
  378. */
  379. user_pgprot |= L_PTE_ASID;
  380. }
  381. if (cpu_arch >= CPU_ARCH_ARMv5) {
  382. mem_types[MT_LOW_VECTORS].prot_pte |= cp->pte & PTE_CACHEABLE;
  383. mem_types[MT_HIGH_VECTORS].prot_pte |= cp->pte & PTE_CACHEABLE;
  384. } else {
  385. mem_types[MT_LOW_VECTORS].prot_pte |= cp->pte;
  386. mem_types[MT_HIGH_VECTORS].prot_pte |= cp->pte;
  387. mem_types[MT_MINICLEAN].prot_sect &= ~PMD_SECT_TEX(1);
  388. }
  389. mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
  390. mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
  391. mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
  392. mem_types[MT_ROM].prot_sect |= cp->pmd;
  393. for (i = 0; i < 16; i++) {
  394. unsigned long v = pgprot_val(protection_map[i]);
  395. v = (v & ~(PTE_BUFFERABLE|PTE_CACHEABLE)) | user_pgprot;
  396. protection_map[i] = __pgprot(v);
  397. }
  398. pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
  399. L_PTE_DIRTY | L_PTE_WRITE |
  400. L_PTE_EXEC | cp->pte);
  401. switch (cp->pmd) {
  402. case PMD_SECT_WT:
  403. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
  404. break;
  405. case PMD_SECT_WB:
  406. case PMD_SECT_WBWA:
  407. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
  408. break;
  409. }
  410. printk("Memory policy: ECC %sabled, Data cache %s\n",
  411. ecc_mask ? "en" : "dis", cp->policy);
  412. }
  413. #define vectors_base() (vectors_high() ? 0xffff0000 : 0)
  414. /*
  415. * Create the page directory entries and any necessary
  416. * page tables for the mapping specified by `md'. We
  417. * are able to cope here with varying sizes and address
  418. * offsets, and we take full advantage of sections and
  419. * supersections.
  420. */
  421. static void __init create_mapping(struct map_desc *md)
  422. {
  423. unsigned long virt, length;
  424. int prot_sect, prot_l1, domain;
  425. pgprot_t prot_pte;
  426. long off;
  427. if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) {
  428. printk(KERN_WARNING "BUG: not creating mapping for "
  429. "0x%08lx at 0x%08lx in user region\n",
  430. md->physical, md->virtual);
  431. return;
  432. }
  433. if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
  434. md->virtual >= PAGE_OFFSET && md->virtual < VMALLOC_END) {
  435. printk(KERN_WARNING "BUG: mapping for 0x%08lx at 0x%08lx "
  436. "overlaps vmalloc space\n",
  437. md->physical, md->virtual);
  438. }
  439. domain = mem_types[md->type].domain;
  440. prot_pte = __pgprot(mem_types[md->type].prot_pte);
  441. prot_l1 = mem_types[md->type].prot_l1 | PMD_DOMAIN(domain);
  442. prot_sect = mem_types[md->type].prot_sect | PMD_DOMAIN(domain);
  443. virt = md->virtual;
  444. off = md->physical - virt;
  445. length = md->length;
  446. if (mem_types[md->type].prot_l1 == 0 &&
  447. (virt & 0xfffff || (virt + off) & 0xfffff || (virt + length) & 0xfffff)) {
  448. printk(KERN_WARNING "BUG: map for 0x%08lx at 0x%08lx can not "
  449. "be mapped using pages, ignoring.\n",
  450. md->physical, md->virtual);
  451. return;
  452. }
  453. while ((virt & 0xfffff || (virt + off) & 0xfffff) && length >= PAGE_SIZE) {
  454. alloc_init_page(virt, virt + off, prot_l1, prot_pte);
  455. virt += PAGE_SIZE;
  456. length -= PAGE_SIZE;
  457. }
  458. /* N.B. ARMv6 supersections are only defined to work with domain 0.
  459. * Since domain assignments can in fact be arbitrary, the
  460. * 'domain == 0' check below is required to insure that ARMv6
  461. * supersections are only allocated for domain 0 regardless
  462. * of the actual domain assignments in use.
  463. */
  464. if (cpu_architecture() >= CPU_ARCH_ARMv6 && domain == 0) {
  465. /* Align to supersection boundary */
  466. while ((virt & ~SUPERSECTION_MASK || (virt + off) &
  467. ~SUPERSECTION_MASK) && length >= (PGDIR_SIZE / 2)) {
  468. alloc_init_section(virt, virt + off, prot_sect);
  469. virt += (PGDIR_SIZE / 2);
  470. length -= (PGDIR_SIZE / 2);
  471. }
  472. while (length >= SUPERSECTION_SIZE) {
  473. alloc_init_supersection(virt, virt + off, prot_sect);
  474. virt += SUPERSECTION_SIZE;
  475. length -= SUPERSECTION_SIZE;
  476. }
  477. }
  478. /*
  479. * A section mapping covers half a "pgdir" entry.
  480. */
  481. while (length >= (PGDIR_SIZE / 2)) {
  482. alloc_init_section(virt, virt + off, prot_sect);
  483. virt += (PGDIR_SIZE / 2);
  484. length -= (PGDIR_SIZE / 2);
  485. }
  486. while (length >= PAGE_SIZE) {
  487. alloc_init_page(virt, virt + off, prot_l1, prot_pte);
  488. virt += PAGE_SIZE;
  489. length -= PAGE_SIZE;
  490. }
  491. }
  492. /*
  493. * In order to soft-boot, we need to insert a 1:1 mapping in place of
  494. * the user-mode pages. This will then ensure that we have predictable
  495. * results when turning the mmu off
  496. */
  497. void setup_mm_for_reboot(char mode)
  498. {
  499. unsigned long base_pmdval;
  500. pgd_t *pgd;
  501. int i;
  502. if (current->mm && current->mm->pgd)
  503. pgd = current->mm->pgd;
  504. else
  505. pgd = init_mm.pgd;
  506. base_pmdval = PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT;
  507. if (cpu_architecture() <= CPU_ARCH_ARMv5TEJ)
  508. base_pmdval |= PMD_BIT4;
  509. for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++, pgd++) {
  510. unsigned long pmdval = (i << PGDIR_SHIFT) | base_pmdval;
  511. pmd_t *pmd;
  512. pmd = pmd_off(pgd, i << PGDIR_SHIFT);
  513. pmd[0] = __pmd(pmdval);
  514. pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
  515. flush_pmd_entry(pmd);
  516. }
  517. }
  518. extern void _stext, _etext;
  519. /*
  520. * Setup initial mappings. We use the page we allocated for zero page to hold
  521. * the mappings, which will get overwritten by the vectors in traps_init().
  522. * The mappings must be in virtual address order.
  523. */
  524. void __init memtable_init(struct meminfo *mi)
  525. {
  526. struct map_desc *init_maps, *p, *q;
  527. unsigned long address = 0;
  528. int i;
  529. build_mem_type_table();
  530. init_maps = p = alloc_bootmem_low_pages(PAGE_SIZE);
  531. #ifdef CONFIG_XIP_KERNEL
  532. p->physical = CONFIG_XIP_PHYS_ADDR & PMD_MASK;
  533. p->virtual = (unsigned long)&_stext & PMD_MASK;
  534. p->length = ((unsigned long)&_etext - p->virtual + ~PMD_MASK) & PMD_MASK;
  535. p->type = MT_ROM;
  536. p ++;
  537. #endif
  538. for (i = 0; i < mi->nr_banks; i++) {
  539. if (mi->bank[i].size == 0)
  540. continue;
  541. p->physical = mi->bank[i].start;
  542. p->virtual = __phys_to_virt(p->physical);
  543. p->length = mi->bank[i].size;
  544. p->type = MT_MEMORY;
  545. p ++;
  546. }
  547. #ifdef FLUSH_BASE
  548. p->physical = FLUSH_BASE_PHYS;
  549. p->virtual = FLUSH_BASE;
  550. p->length = PGDIR_SIZE;
  551. p->type = MT_CACHECLEAN;
  552. p ++;
  553. #endif
  554. #ifdef FLUSH_BASE_MINICACHE
  555. p->physical = FLUSH_BASE_PHYS + PGDIR_SIZE;
  556. p->virtual = FLUSH_BASE_MINICACHE;
  557. p->length = PGDIR_SIZE;
  558. p->type = MT_MINICLEAN;
  559. p ++;
  560. #endif
  561. /*
  562. * Go through the initial mappings, but clear out any
  563. * pgdir entries that are not in the description.
  564. */
  565. q = init_maps;
  566. do {
  567. if (address < q->virtual || q == p) {
  568. clear_mapping(address);
  569. address += PGDIR_SIZE;
  570. } else {
  571. create_mapping(q);
  572. address = q->virtual + q->length;
  573. address = (address + PGDIR_SIZE - 1) & PGDIR_MASK;
  574. q ++;
  575. }
  576. } while (address != 0);
  577. /*
  578. * Create a mapping for the machine vectors at the high-vectors
  579. * location (0xffff0000). If we aren't using high-vectors, also
  580. * create a mapping at the low-vectors virtual address.
  581. */
  582. init_maps->physical = virt_to_phys(init_maps);
  583. init_maps->virtual = 0xffff0000;
  584. init_maps->length = PAGE_SIZE;
  585. init_maps->type = MT_HIGH_VECTORS;
  586. create_mapping(init_maps);
  587. if (!vectors_high()) {
  588. init_maps->virtual = 0;
  589. init_maps->type = MT_LOW_VECTORS;
  590. create_mapping(init_maps);
  591. }
  592. flush_cache_all();
  593. local_flush_tlb_all();
  594. top_pmd = pmd_off_k(0xffff0000);
  595. }
  596. /*
  597. * Create the architecture specific mappings
  598. */
  599. void __init iotable_init(struct map_desc *io_desc, int nr)
  600. {
  601. int i;
  602. for (i = 0; i < nr; i++)
  603. create_mapping(io_desc + i);
  604. }