mm-armv.c 17 KB

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