Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * xtensa mmu stuff |
| 3 | * |
| 4 | * Extracted from init.c |
| 5 | */ |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 6 | #include <linux/bootmem.h> |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 7 | #include <linux/percpu.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/string.h> |
| 10 | #include <linux/slab.h> |
| 11 | #include <linux/cache.h> |
| 12 | |
| 13 | #include <asm/tlb.h> |
| 14 | #include <asm/tlbflush.h> |
| 15 | #include <asm/mmu_context.h> |
| 16 | #include <asm/page.h> |
Baruch Siach | 6cb9711 | 2013-12-29 11:03:30 +0200 | [diff] [blame] | 17 | #include <asm/initialize_mmu.h> |
| 18 | #include <asm/io.h> |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 19 | |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 20 | #if defined(CONFIG_HIGHMEM) |
Max Filippov | dec7305 | 2014-07-15 02:49:15 +0400 | [diff] [blame] | 21 | static void * __init init_pmd(unsigned long vaddr, unsigned long n_pages) |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 22 | { |
| 23 | pgd_t *pgd = pgd_offset_k(vaddr); |
| 24 | pmd_t *pmd = pmd_offset(pgd, vaddr); |
Max Filippov | dec7305 | 2014-07-15 02:49:15 +0400 | [diff] [blame] | 25 | pte_t *pte; |
| 26 | unsigned long i; |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 27 | |
Max Filippov | dec7305 | 2014-07-15 02:49:15 +0400 | [diff] [blame] | 28 | n_pages = ALIGN(n_pages, PTRS_PER_PTE); |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 29 | |
Max Filippov | dec7305 | 2014-07-15 02:49:15 +0400 | [diff] [blame] | 30 | pr_debug("%s: vaddr: 0x%08lx, n_pages: %ld\n", |
| 31 | __func__, vaddr, n_pages); |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 32 | |
Max Filippov | dec7305 | 2014-07-15 02:49:15 +0400 | [diff] [blame] | 33 | pte = alloc_bootmem_low_pages(n_pages * sizeof(pte_t)); |
| 34 | |
| 35 | for (i = 0; i < n_pages; ++i) |
| 36 | pte_clear(NULL, 0, pte + i); |
| 37 | |
| 38 | for (i = 0; i < n_pages; i += PTRS_PER_PTE, ++pmd) { |
| 39 | pte_t *cur_pte = pte + i; |
| 40 | |
| 41 | BUG_ON(!pmd_none(*pmd)); |
| 42 | set_pmd(pmd, __pmd(((unsigned long)cur_pte) & PAGE_MASK)); |
| 43 | BUG_ON(cur_pte != pte_offset_kernel(pmd, 0)); |
| 44 | pr_debug("%s: pmd: 0x%p, pte: 0x%p\n", |
| 45 | __func__, pmd, cur_pte); |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 46 | } |
Max Filippov | dec7305 | 2014-07-15 02:49:15 +0400 | [diff] [blame] | 47 | return pte; |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void __init fixedrange_init(void) |
| 51 | { |
Max Filippov | dec7305 | 2014-07-15 02:49:15 +0400 | [diff] [blame] | 52 | init_pmd(__fix_to_virt(0), __end_of_fixed_addresses); |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 53 | } |
| 54 | #endif |
| 55 | |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 56 | void __init paging_init(void) |
| 57 | { |
| 58 | memset(swapper_pg_dir, 0, PAGE_SIZE); |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 59 | #ifdef CONFIG_HIGHMEM |
| 60 | fixedrange_init(); |
Max Filippov | dec7305 | 2014-07-15 02:49:15 +0400 | [diff] [blame] | 61 | pkmap_page_table = init_pmd(PKMAP_BASE, LAST_PKMAP); |
Max Filippov | 6555910 | 2014-02-04 02:17:09 +0400 | [diff] [blame] | 62 | kmap_init(); |
| 63 | #endif |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Flush the mmu and reset associated register to default values. |
| 68 | */ |
Max Filippov | f615136 | 2013-10-17 02:42:26 +0400 | [diff] [blame] | 69 | void init_mmu(void) |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 70 | { |
Max Filippov | e85e335 | 2012-12-03 15:01:43 +0400 | [diff] [blame] | 71 | #if !(XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY) |
| 72 | /* |
| 73 | * Writing zeros to the instruction and data TLBCFG special |
| 74 | * registers ensure that valid values exist in the register. |
| 75 | * |
| 76 | * For existing PGSZID<w> fields, zero selects the first element |
| 77 | * of the page-size array. For nonexistent PGSZID<w> fields, |
| 78 | * zero is the best value to write. Also, when changing PGSZID<w> |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 79 | * fields, the corresponding TLB must be flushed. |
| 80 | */ |
| 81 | set_itlbcfg_register(0); |
| 82 | set_dtlbcfg_register(0); |
Max Filippov | e85e335 | 2012-12-03 15:01:43 +0400 | [diff] [blame] | 83 | #endif |
Max Filippov | 9848e49 | 2014-01-16 03:38:58 +0400 | [diff] [blame] | 84 | #if XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY && defined(CONFIG_OF) |
Baruch Siach | 6cb9711 | 2013-12-29 11:03:30 +0200 | [diff] [blame] | 85 | /* |
| 86 | * Update the IO area mapping in case xtensa_kio_paddr has changed |
| 87 | */ |
| 88 | write_dtlb_entry(__pte(xtensa_kio_paddr + CA_WRITEBACK), |
| 89 | XCHAL_KIO_CACHED_VADDR + 6); |
| 90 | write_itlb_entry(__pte(xtensa_kio_paddr + CA_WRITEBACK), |
| 91 | XCHAL_KIO_CACHED_VADDR + 6); |
| 92 | write_dtlb_entry(__pte(xtensa_kio_paddr + CA_BYPASS), |
| 93 | XCHAL_KIO_BYPASS_VADDR + 6); |
| 94 | write_itlb_entry(__pte(xtensa_kio_paddr + CA_BYPASS), |
| 95 | XCHAL_KIO_BYPASS_VADDR + 6); |
| 96 | #endif |
| 97 | |
Max Filippov | f615136 | 2013-10-17 02:42:26 +0400 | [diff] [blame] | 98 | local_flush_tlb_all(); |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 99 | |
| 100 | /* Set rasid register to a known value. */ |
| 101 | |
Max Filippov | ec747b2 | 2012-12-11 01:26:24 +0400 | [diff] [blame] | 102 | set_rasid_register(ASID_INSERT(ASID_USER_FIRST)); |
Johannes Weiner | e5083a6 | 2009-03-04 16:21:31 +0100 | [diff] [blame] | 103 | |
| 104 | /* Set PTEVADDR special register to the start of the page |
| 105 | * table, which is in kernel mappable space (ie. not |
| 106 | * statically mapped). This register's value is undefined on |
| 107 | * reset. |
| 108 | */ |
| 109 | set_ptevaddr_register(PGTABLE_START); |
| 110 | } |