Rev 4129 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3817 | rimsky | 1 | /* |
2 | * Copyright (c) 2006 Jakub Jermar |
||
3 | * Copyright (c) 2009 Pavel Rimsky |
||
4 | * All rights reserved. |
||
5 | * |
||
6 | * Redistribution and use in source and binary forms, with or without |
||
7 | * modification, are permitted provided that the following conditions |
||
8 | * are met: |
||
9 | * |
||
10 | * - Redistributions of source code must retain the above copyright |
||
11 | * notice, this list of conditions and the following disclaimer. |
||
12 | * - Redistributions in binary form must reproduce the above copyright |
||
13 | * notice, this list of conditions and the following disclaimer in the |
||
14 | * documentation and/or other materials provided with the distribution. |
||
15 | * - The name of the author may not be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
30 | /** @addtogroup sparc64mm |
||
31 | * @{ |
||
32 | */ |
||
33 | /** @file |
||
34 | */ |
||
35 | |||
36 | #include <arch/mm/as.h> |
||
37 | #include <arch/mm/pagesize.h> |
||
3862 | rimsky | 38 | #include <arch/mm/tlb.h> |
3817 | rimsky | 39 | #include <genarch/mm/page_ht.h> |
40 | #include <genarch/mm/asid_fifo.h> |
||
41 | #include <debug.h> |
||
42 | #include <config.h> |
||
3862 | rimsky | 43 | #include <arch/sun4v/hypercall.h> |
3817 | rimsky | 44 | |
45 | #ifdef CONFIG_TSB |
||
46 | #include <arch/mm/tsb.h> |
||
47 | #include <arch/memstr.h> |
||
48 | #include <arch/asm.h> |
||
49 | #include <mm/frame.h> |
||
50 | #include <bitops.h> |
||
51 | #include <macros.h> |
||
52 | #endif /* CONFIG_TSB */ |
||
53 | |||
54 | /** Architecture dependent address space init. */ |
||
55 | void as_arch_init(void) |
||
56 | { |
||
57 | if (config.cpu_active == 1) { |
||
58 | as_operations = &as_ht_operations; |
||
59 | asid_fifo_init(); |
||
60 | } |
||
61 | } |
||
62 | |||
63 | int as_constructor_arch(as_t *as, int flags) |
||
64 | { |
||
65 | #ifdef CONFIG_TSB |
||
3862 | rimsky | 66 | int order = fnzb32( |
67 | (TSB_ENTRY_COUNT * sizeof(tsb_entry_t)) >> FRAME_WIDTH); |
||
3817 | rimsky | 68 | |
69 | uintptr_t tsb = (uintptr_t) frame_alloc(order, flags | FRAME_KA); |
||
70 | |||
71 | if (!tsb) |
||
72 | return -1; |
||
73 | |||
3862 | rimsky | 74 | as->arch.tsb_description.page_size = PAGESIZE_8K; |
75 | as->arch.tsb_description.associativity = 1; |
||
76 | as->arch.tsb_description.num_ttes = TSB_ENTRY_COUNT; |
||
77 | as->arch.tsb_description.pgsize_mask = 1 << PAGESIZE_8K; |
||
78 | as->arch.tsb_description.tsb_base = tsb; |
||
79 | as->arch.tsb_description.reserved = 0; |
||
3817 | rimsky | 80 | |
3862 | rimsky | 81 | memsetb((void *) as->arch.tsb_description.tsb_base, |
82 | TSB_ENTRY_COUNT * sizeof(tsb_entry_t), 0); |
||
3817 | rimsky | 83 | #endif |
84 | return 0; |
||
85 | } |
||
86 | |||
87 | int as_destructor_arch(as_t *as) |
||
88 | { |
||
89 | #ifdef CONFIG_TSB |
||
3862 | rimsky | 90 | count_t cnt = (TSB_ENTRY_COUNT * sizeof(tsb_entry_t)) >> FRAME_WIDTH; |
91 | frame_free(KA2PA((uintptr_t) as->arch.tsb_description.tsb_base)); |
||
3817 | rimsky | 92 | return cnt; |
93 | #else |
||
94 | return 0; |
||
95 | #endif |
||
96 | } |
||
97 | |||
98 | int as_create_arch(as_t *as, int flags) |
||
99 | { |
||
100 | #ifdef CONFIG_TSB |
||
101 | tsb_invalidate(as, 0, (count_t) -1); |
||
3862 | rimsky | 102 | as->arch.tsb_description.context = as->asid; |
3817 | rimsky | 103 | #endif |
104 | return 0; |
||
105 | } |
||
106 | |||
107 | /** Perform sparc64-specific tasks when an address space becomes active on the |
||
108 | * processor. |
||
109 | * |
||
110 | * Install ASID and map TSBs. |
||
111 | * |
||
112 | * @param as Address space. |
||
113 | */ |
||
114 | void as_install_arch(as_t *as) |
||
115 | { |
||
3862 | rimsky | 116 | mmu_secondary_context_write(as->asid); |
3817 | rimsky | 117 | |
118 | #ifdef CONFIG_TSB |
||
119 | uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH); |
||
120 | |||
3862 | rimsky | 121 | ASSERT(as->arch.tsb_description.tsb_base); |
122 | uintptr_t tsb = as->arch.tsb_description.tsb_base; |
||
3817 | rimsky | 123 | |
124 | if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) { |
||
125 | /* |
||
126 | * TSBs were allocated from memory not covered |
||
127 | * by the locked 4M kernel DTLB entry. We need |
||
128 | * to map both TSBs explicitly. |
||
129 | */ |
||
3862 | rimsky | 130 | mmu_demap_page(tsb, 0, MMU_FLAG_DTLB); |
4130 | rimsky | 131 | dtlb_insert_mapping(tsb, KA2PA(tsb), PAGESIZE_64K, true, true); |
3817 | rimsky | 132 | } |
133 | |||
3862 | rimsky | 134 | __hypercall_fast2(MMU_TSB_CTX0, 1, as->arch.tsb_description.tsb_base); |
3817 | rimsky | 135 | |
136 | #endif |
||
137 | } |
||
138 | |||
139 | /** Perform sparc64-specific tasks when an address space is removed from the |
||
140 | * processor. |
||
141 | * |
||
142 | * Demap TSBs. |
||
143 | * |
||
144 | * @param as Address space. |
||
145 | */ |
||
146 | void as_deinstall_arch(as_t *as) |
||
147 | { |
||
148 | /* |
||
149 | * Note that we don't and may not lock the address space. That's ok |
||
150 | * since we only read members that are currently read-only. |
||
151 | * |
||
152 | * Moreover, the as->asid is protected by asidlock, which is being held. |
||
153 | */ |
||
154 | #ifdef CONFIG_TSB |
||
155 | uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH); |
||
156 | |||
3862 | rimsky | 157 | ASSERT(as->arch.tsb_description.tsb_base); |
3817 | rimsky | 158 | |
3862 | rimsky | 159 | uintptr_t tsb = as->arch.tsb_description.tsb_base; |
3817 | rimsky | 160 | |
161 | if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) { |
||
162 | /* |
||
163 | * TSBs were allocated from memory not covered |
||
164 | * by the locked 4M kernel DTLB entry. We need |
||
165 | * to demap the entry installed by as_install_arch(). |
||
166 | */ |
||
4130 | rimsky | 167 | __hypercall_fast3(MMU_UNMAP_PERM_ADDR, tsb, 0, MMU_FLAG_DTLB); |
3817 | rimsky | 168 | } |
169 | #endif |
||
170 | } |
||
171 | |||
172 | /** @} |
||
173 | */ |