mm-armv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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 & SUPERSECTION_MASK,
  236. prot | PMD_SECT_SUPER);
  237. virt += (PGDIR_SIZE / 2);
  238. phys += (PGDIR_SIZE / 2);
  239. }
  240. }
  241. /*
  242. * Add a PAGE mapping between VIRT and PHYS in domain
  243. * DOMAIN with protection PROT. Note that due to the
  244. * way we map the PTEs, we must allocate two PTE_SIZE'd
  245. * blocks - one for the Linux pte table, and one for
  246. * the hardware pte table.
  247. */
  248. static inline void
  249. alloc_init_page(unsigned long virt, unsigned long phys, unsigned int prot_l1, pgprot_t prot)
  250. {
  251. pmd_t *pmdp = pmd_off_k(virt);
  252. pte_t *ptep;
  253. if (pmd_none(*pmdp)) {
  254. unsigned long pmdval;
  255. ptep = alloc_bootmem_low_pages(2 * PTRS_PER_PTE *
  256. sizeof(pte_t));
  257. pmdval = __pa(ptep) | prot_l1;
  258. pmdp[0] = __pmd(pmdval);
  259. pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
  260. flush_pmd_entry(pmdp);
  261. }
  262. ptep = pte_offset_kernel(pmdp, virt);
  263. set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot));
  264. }
  265. /*
  266. * Clear any PGD mapping. On a two-level page table system,
  267. * the clearance is done by the middle-level functions (pmd)
  268. * rather than the top-level (pgd) functions.
  269. */
  270. static inline void clear_mapping(unsigned long virt)
  271. {
  272. pmd_clear(pmd_off_k(virt));
  273. }
  274. struct mem_types {
  275. unsigned int prot_pte;
  276. unsigned int prot_l1;
  277. unsigned int prot_sect;
  278. unsigned int domain;
  279. };
  280. static struct mem_types mem_types[] __initdata = {
  281. [MT_DEVICE] = {
  282. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  283. L_PTE_WRITE,
  284. .prot_l1 = PMD_TYPE_TABLE,
  285. .prot_sect = PMD_TYPE_SECT | PMD_SECT_UNCACHED |
  286. PMD_SECT_AP_WRITE,
  287. .domain = DOMAIN_IO,
  288. },
  289. [MT_CACHECLEAN] = {
  290. .prot_sect = PMD_TYPE_SECT,
  291. .domain = DOMAIN_KERNEL,
  292. },
  293. [MT_MINICLEAN] = {
  294. .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE,
  295. .domain = DOMAIN_KERNEL,
  296. },
  297. [MT_LOW_VECTORS] = {
  298. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  299. L_PTE_EXEC,
  300. .prot_l1 = PMD_TYPE_TABLE,
  301. .domain = DOMAIN_USER,
  302. },
  303. [MT_HIGH_VECTORS] = {
  304. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  305. L_PTE_USER | L_PTE_EXEC,
  306. .prot_l1 = PMD_TYPE_TABLE,
  307. .domain = DOMAIN_USER,
  308. },
  309. [MT_MEMORY] = {
  310. .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
  311. .domain = DOMAIN_KERNEL,
  312. },
  313. [MT_ROM] = {
  314. .prot_sect = PMD_TYPE_SECT,
  315. .domain = DOMAIN_KERNEL,
  316. },
  317. [MT_IXP2000_DEVICE] = { /* IXP2400 requires XCB=101 for on-chip I/O */
  318. .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
  319. L_PTE_WRITE,
  320. .prot_l1 = PMD_TYPE_TABLE,
  321. .prot_sect = PMD_TYPE_SECT | PMD_SECT_UNCACHED |
  322. PMD_SECT_AP_WRITE | PMD_SECT_BUFFERABLE |
  323. PMD_SECT_TEX(1),
  324. .domain = DOMAIN_IO,
  325. }
  326. };
  327. /*
  328. * Adjust the PMD section entries according to the CPU in use.
  329. */
  330. static void __init build_mem_type_table(void)
  331. {
  332. struct cachepolicy *cp;
  333. unsigned int cr = get_cr();
  334. int cpu_arch = cpu_architecture();
  335. int i;
  336. #if defined(CONFIG_CPU_DCACHE_DISABLE)
  337. if (cachepolicy > CPOLICY_BUFFERED)
  338. cachepolicy = CPOLICY_BUFFERED;
  339. #elif defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
  340. if (cachepolicy > CPOLICY_WRITETHROUGH)
  341. cachepolicy = CPOLICY_WRITETHROUGH;
  342. #endif
  343. if (cpu_arch < CPU_ARCH_ARMv5) {
  344. if (cachepolicy >= CPOLICY_WRITEALLOC)
  345. cachepolicy = CPOLICY_WRITEBACK;
  346. ecc_mask = 0;
  347. }
  348. if (cpu_arch <= CPU_ARCH_ARMv5) {
  349. for (i = 0; i < ARRAY_SIZE(mem_types); i++) {
  350. if (mem_types[i].prot_l1)
  351. mem_types[i].prot_l1 |= PMD_BIT4;
  352. if (mem_types[i].prot_sect)
  353. mem_types[i].prot_sect |= PMD_BIT4;
  354. }
  355. }
  356. /*
  357. * ARMv6 and above have extended page tables.
  358. */
  359. if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
  360. /*
  361. * bit 4 becomes XN which we must clear for the
  362. * kernel memory mapping.
  363. */
  364. mem_types[MT_MEMORY].prot_sect &= ~PMD_BIT4;
  365. mem_types[MT_ROM].prot_sect &= ~PMD_BIT4;
  366. /*
  367. * Mark cache clean areas and XIP ROM read only
  368. * from SVC mode and no access from userspace.
  369. */
  370. mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  371. mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  372. mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
  373. }
  374. cp = &cache_policies[cachepolicy];
  375. if (cpu_arch >= CPU_ARCH_ARMv5) {
  376. mem_types[MT_LOW_VECTORS].prot_pte |= cp->pte & PTE_CACHEABLE;
  377. mem_types[MT_HIGH_VECTORS].prot_pte |= cp->pte & PTE_CACHEABLE;
  378. } else {
  379. mem_types[MT_LOW_VECTORS].prot_pte |= cp->pte;
  380. mem_types[MT_HIGH_VECTORS].prot_pte |= cp->pte;
  381. mem_types[MT_MINICLEAN].prot_sect &= ~PMD_SECT_TEX(1);
  382. }
  383. mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
  384. mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
  385. mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
  386. mem_types[MT_ROM].prot_sect |= cp->pmd;
  387. for (i = 0; i < 16; i++) {
  388. unsigned long v = pgprot_val(protection_map[i]);
  389. v &= (~(PTE_BUFFERABLE|PTE_CACHEABLE)) | cp->pte;
  390. protection_map[i] = __pgprot(v);
  391. }
  392. pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
  393. L_PTE_DIRTY | L_PTE_WRITE |
  394. L_PTE_EXEC | cp->pte);
  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. static 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. long off;
  421. if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) {
  422. printk(KERN_WARNING "BUG: not creating mapping for "
  423. "0x%08lx at 0x%08lx in user region\n",
  424. md->physical, 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%08lx at 0x%08lx "
  430. "overlaps vmalloc space\n",
  431. md->physical, 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. virt = md->virtual;
  438. off = md->physical - virt;
  439. length = md->length;
  440. if (mem_types[md->type].prot_l1 == 0 &&
  441. (virt & 0xfffff || (virt + off) & 0xfffff || (virt + length) & 0xfffff)) {
  442. printk(KERN_WARNING "BUG: map for 0x%08lx at 0x%08lx can not "
  443. "be mapped using pages, ignoring.\n",
  444. md->physical, md->virtual);
  445. return;
  446. }
  447. while ((virt & 0xfffff || (virt + off) & 0xfffff) && length >= PAGE_SIZE) {
  448. alloc_init_page(virt, virt + off, prot_l1, prot_pte);
  449. virt += PAGE_SIZE;
  450. length -= PAGE_SIZE;
  451. }
  452. /* N.B. ARMv6 supersections are only defined to work with domain 0.
  453. * Since domain assignments can in fact be arbitrary, the
  454. * 'domain == 0' check below is required to insure that ARMv6
  455. * supersections are only allocated for domain 0 regardless
  456. * of the actual domain assignments in use.
  457. */
  458. if (cpu_architecture() >= CPU_ARCH_ARMv6 && domain == 0) {
  459. /* Align to supersection boundary */
  460. while ((virt & ~SUPERSECTION_MASK || (virt + off) &
  461. ~SUPERSECTION_MASK) && length >= (PGDIR_SIZE / 2)) {
  462. alloc_init_section(virt, virt + off, prot_sect);
  463. virt += (PGDIR_SIZE / 2);
  464. length -= (PGDIR_SIZE / 2);
  465. }
  466. while (length >= SUPERSECTION_SIZE) {
  467. alloc_init_supersection(virt, virt + off, prot_sect);
  468. virt += SUPERSECTION_SIZE;
  469. length -= SUPERSECTION_SIZE;
  470. }
  471. }
  472. /*
  473. * A section mapping covers half a "pgdir" entry.
  474. */
  475. while (length >= (PGDIR_SIZE / 2)) {
  476. alloc_init_section(virt, virt + off, prot_sect);
  477. virt += (PGDIR_SIZE / 2);
  478. length -= (PGDIR_SIZE / 2);
  479. }
  480. while (length >= PAGE_SIZE) {
  481. alloc_init_page(virt, virt + off, prot_l1, prot_pte);
  482. virt += PAGE_SIZE;
  483. length -= PAGE_SIZE;
  484. }
  485. }
  486. /*
  487. * In order to soft-boot, we need to insert a 1:1 mapping in place of
  488. * the user-mode pages. This will then ensure that we have predictable
  489. * results when turning the mmu off
  490. */
  491. void setup_mm_for_reboot(char mode)
  492. {
  493. unsigned long pmdval;
  494. pgd_t *pgd;
  495. pmd_t *pmd;
  496. int i;
  497. int cpu_arch = cpu_architecture();
  498. if (current->mm && current->mm->pgd)
  499. pgd = current->mm->pgd;
  500. else
  501. pgd = init_mm.pgd;
  502. for (i = 0; i < FIRST_USER_PGD_NR + USER_PTRS_PER_PGD; i++) {
  503. pmdval = (i << PGDIR_SHIFT) |
  504. PMD_SECT_AP_WRITE | PMD_SECT_AP_READ |
  505. PMD_TYPE_SECT;
  506. if (cpu_arch <= CPU_ARCH_ARMv5)
  507. pmdval |= PMD_BIT4;
  508. pmd = pmd_off(pgd, i << PGDIR_SHIFT);
  509. pmd[0] = __pmd(pmdval);
  510. pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
  511. flush_pmd_entry(pmd);
  512. }
  513. }
  514. extern void _stext, _etext;
  515. /*
  516. * Setup initial mappings. We use the page we allocated for zero page to hold
  517. * the mappings, which will get overwritten by the vectors in traps_init().
  518. * The mappings must be in virtual address order.
  519. */
  520. void __init memtable_init(struct meminfo *mi)
  521. {
  522. struct map_desc *init_maps, *p, *q;
  523. unsigned long address = 0;
  524. int i;
  525. build_mem_type_table();
  526. init_maps = p = alloc_bootmem_low_pages(PAGE_SIZE);
  527. #ifdef CONFIG_XIP_KERNEL
  528. p->physical = CONFIG_XIP_PHYS_ADDR & PMD_MASK;
  529. p->virtual = (unsigned long)&_stext & PMD_MASK;
  530. p->length = ((unsigned long)&_etext - p->virtual + ~PMD_MASK) & PMD_MASK;
  531. p->type = MT_ROM;
  532. p ++;
  533. #endif
  534. for (i = 0; i < mi->nr_banks; i++) {
  535. if (mi->bank[i].size == 0)
  536. continue;
  537. p->physical = mi->bank[i].start;
  538. p->virtual = __phys_to_virt(p->physical);
  539. p->length = mi->bank[i].size;
  540. p->type = MT_MEMORY;
  541. p ++;
  542. }
  543. #ifdef FLUSH_BASE
  544. p->physical = FLUSH_BASE_PHYS;
  545. p->virtual = FLUSH_BASE;
  546. p->length = PGDIR_SIZE;
  547. p->type = MT_CACHECLEAN;
  548. p ++;
  549. #endif
  550. #ifdef FLUSH_BASE_MINICACHE
  551. p->physical = FLUSH_BASE_PHYS + PGDIR_SIZE;
  552. p->virtual = FLUSH_BASE_MINICACHE;
  553. p->length = PGDIR_SIZE;
  554. p->type = MT_MINICLEAN;
  555. p ++;
  556. #endif
  557. /*
  558. * Go through the initial mappings, but clear out any
  559. * pgdir entries that are not in the description.
  560. */
  561. q = init_maps;
  562. do {
  563. if (address < q->virtual || q == p) {
  564. clear_mapping(address);
  565. address += PGDIR_SIZE;
  566. } else {
  567. create_mapping(q);
  568. address = q->virtual + q->length;
  569. address = (address + PGDIR_SIZE - 1) & PGDIR_MASK;
  570. q ++;
  571. }
  572. } while (address != 0);
  573. /*
  574. * Create a mapping for the machine vectors at the high-vectors
  575. * location (0xffff0000). If we aren't using high-vectors, also
  576. * create a mapping at the low-vectors virtual address.
  577. */
  578. init_maps->physical = virt_to_phys(init_maps);
  579. init_maps->virtual = 0xffff0000;
  580. init_maps->length = PAGE_SIZE;
  581. init_maps->type = MT_HIGH_VECTORS;
  582. create_mapping(init_maps);
  583. if (!vectors_high()) {
  584. init_maps->virtual = 0;
  585. init_maps->type = MT_LOW_VECTORS;
  586. create_mapping(init_maps);
  587. }
  588. flush_cache_all();
  589. local_flush_tlb_all();
  590. top_pmd = pmd_off_k(0xffff0000);
  591. }
  592. /*
  593. * Create the architecture specific mappings
  594. */
  595. void __init iotable_init(struct map_desc *io_desc, int nr)
  596. {
  597. int i;
  598. for (i = 0; i < nr; i++)
  599. create_mapping(io_desc + i);
  600. }