Rev 3386 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4153 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Jakub Jermar |
2 | * Copyright (c) 2006 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup sparc64mm |
29 | /** @addtogroup sparc64mm |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch/mm/tsb.h> |
35 | #include <arch/mm/tsb.h> |
36 | #include <arch/mm/tlb.h> |
36 | #include <arch/mm/tlb.h> |
37 | #include <arch/mm/page.h> |
37 | #include <arch/mm/page.h> |
38 | #include <arch/barrier.h> |
38 | #include <arch/barrier.h> |
39 | #include <mm/as.h> |
39 | #include <mm/as.h> |
40 | #include <arch/types.h> |
40 | #include <arch/types.h> |
41 | #include <macros.h> |
41 | #include <macros.h> |
42 | #include <debug.h> |
42 | #include <debug.h> |
43 | 43 | ||
44 | #define TSB_INDEX_MASK ((1 << (21 + 1 + TSB_SIZE - MMU_PAGE_WIDTH)) - 1) |
44 | #define TSB_INDEX_MASK ((1 << (21 + 1 + TSB_SIZE - MMU_PAGE_WIDTH)) - 1) |
45 | 45 | ||
46 | /** Invalidate portion of TSB. |
46 | /** Invalidate portion of TSB. |
47 | * |
47 | * |
48 | * We assume that the address space is already locked. Note that respective |
48 | * We assume that the address space is already locked. Note that respective |
49 | * portions of both TSBs are invalidated at a time. |
49 | * portions of both TSBs are invalidated at a time. |
50 | * |
50 | * |
51 | * @param as Address space. |
51 | * @param as Address space. |
52 | * @param page First page to invalidate in TSB. |
52 | * @param page First page to invalidate in TSB. |
53 | * @param pages Number of pages to invalidate. Value of (count_t) -1 means the |
53 | * @param pages Number of pages to invalidate. Value of (count_t) -1 means the |
54 | * whole TSB. |
54 | * whole TSB. |
55 | */ |
55 | */ |
56 | void tsb_invalidate(as_t *as, uintptr_t page, count_t pages) |
56 | void tsb_invalidate(as_t *as, uintptr_t page, count_t pages) |
57 | { |
57 | { |
58 | index_t i0, i; |
58 | index_t i0, i; |
59 | count_t cnt; |
59 | count_t cnt; |
60 | 60 | ||
61 | ASSERT(as->arch.itsb && as->arch.dtsb); |
61 | ASSERT(as->arch.itsb && as->arch.dtsb); |
62 | 62 | ||
63 | i0 = (page >> MMU_PAGE_WIDTH) & TSB_INDEX_MASK; |
63 | i0 = (page >> MMU_PAGE_WIDTH) & TSB_INDEX_MASK; |
64 | ASSERT(i0 < ITSB_ENTRY_COUNT && i0 < DTSB_ENTRY_COUNT); |
64 | ASSERT(i0 < ITSB_ENTRY_COUNT && i0 < DTSB_ENTRY_COUNT); |
65 | 65 | ||
66 | if (pages == (count_t) -1 || (pages * 2) > ITSB_ENTRY_COUNT) |
66 | if (pages == (count_t) -1 || (pages * 2) > ITSB_ENTRY_COUNT) |
67 | cnt = ITSB_ENTRY_COUNT; |
67 | cnt = ITSB_ENTRY_COUNT; |
68 | else |
68 | else |
69 | cnt = pages * 2; |
69 | cnt = pages * 2; |
70 | 70 | ||
71 | for (i = 0; i < cnt; i++) { |
71 | for (i = 0; i < cnt; i++) { |
72 | as->arch.itsb[(i0 + i) & (ITSB_ENTRY_COUNT - 1)].tag.invalid = |
72 | as->arch.itsb[(i0 + i) & (ITSB_ENTRY_COUNT - 1)].tag.invalid = |
73 | true; |
73 | true; |
74 | as->arch.dtsb[(i0 + i) & (DTSB_ENTRY_COUNT - 1)].tag.invalid = |
74 | as->arch.dtsb[(i0 + i) & (DTSB_ENTRY_COUNT - 1)].tag.invalid = |
75 | true; |
75 | true; |
76 | } |
76 | } |
77 | } |
77 | } |
78 | 78 | ||
79 | /** Copy software PTE to ITSB. |
79 | /** Copy software PTE to ITSB. |
80 | * |
80 | * |
81 | * @param t Software PTE. |
81 | * @param t Software PTE. |
82 | * @param index Zero if lower 8K-subpage, one if higher 8K subpage. |
82 | * @param index Zero if lower 8K-subpage, one if higher 8K subpage. |
83 | */ |
83 | */ |
84 | void itsb_pte_copy(pte_t *t, index_t index) |
84 | void itsb_pte_copy(pte_t *t, index_t index) |
85 | { |
85 | { |
86 | as_t *as; |
86 | as_t *as; |
87 | tsb_entry_t *tsb; |
87 | tsb_entry_t *tsb; |
88 | index_t entry; |
88 | index_t entry; |
89 | 89 | ||
90 | ASSERT(index <= 1); |
90 | ASSERT(index <= 1); |
91 | 91 | ||
92 | as = t->as; |
92 | as = t->as; |
93 | entry = ((t->page >> MMU_PAGE_WIDTH) + index) & TSB_INDEX_MASK; |
93 | entry = ((t->page >> MMU_PAGE_WIDTH) + index) & TSB_INDEX_MASK; |
94 | ASSERT(entry < ITSB_ENTRY_COUNT); |
94 | ASSERT(entry < ITSB_ENTRY_COUNT); |
95 | tsb = &as->arch.itsb[entry]; |
95 | tsb = &as->arch.itsb[entry]; |
96 | 96 | ||
97 | /* |
97 | /* |
98 | * We use write barriers to make sure that the TSB load |
98 | * We use write barriers to make sure that the TSB load |
99 | * won't use inconsistent data or that the fault will |
99 | * won't use inconsistent data or that the fault will |
100 | * be repeated. |
100 | * be repeated. |
101 | */ |
101 | */ |
102 | 102 | ||
103 | tsb->tag.invalid = true; /* invalidate the entry |
103 | tsb->tag.invalid = true; /* invalidate the entry |
104 | * (tag target has this |
104 | * (tag target has this |
105 | * set to 0) */ |
105 | * set to 0) */ |
106 | 106 | ||
107 | write_barrier(); |
107 | write_barrier(); |
108 | 108 | ||
109 | tsb->tag.context = as->asid; |
109 | tsb->tag.context = as->asid; |
110 | /* the shift is bigger than PAGE_WIDTH, do not bother with index */ |
110 | /* the shift is bigger than PAGE_WIDTH, do not bother with index */ |
111 | tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT; |
111 | tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT; |
112 | tsb->data.value = 0; |
112 | tsb->data.value = 0; |
113 | tsb->data.size = PAGESIZE_8K; |
113 | tsb->data.size = PAGESIZE_8K; |
114 | tsb->data.pfn = (t->frame >> MMU_FRAME_WIDTH) + index; |
114 | tsb->data.pfn = (t->frame >> MMU_FRAME_WIDTH) + index; |
115 | tsb->data.cp = t->c; |
115 | tsb->data.cp = t->c; /* cp as cache in phys.-idxed, c as cacheable */ |
116 | tsb->data.p = t->k; /* p as privileged */ |
116 | tsb->data.p = t->k; /* p as privileged, k as kernel */ |
117 | tsb->data.v = t->p; |
117 | tsb->data.v = t->p; /* v as valid, p as present */ |
118 | 118 | ||
119 | write_barrier(); |
119 | write_barrier(); |
120 | 120 | ||
121 | tsb->tag.invalid = false; /* mark the entry as valid */ |
121 | tsb->tag.invalid = false; /* mark the entry as valid */ |
122 | } |
122 | } |
123 | 123 | ||
124 | /** Copy software PTE to DTSB. |
124 | /** Copy software PTE to DTSB. |
125 | * |
125 | * |
126 | * @param t Software PTE. |
126 | * @param t Software PTE. |
127 | * @param index Zero if lower 8K-subpage, one if higher 8K-subpage. |
127 | * @param index Zero if lower 8K-subpage, one if higher 8K-subpage. |
128 | * @param ro If true, the mapping is copied read-only. |
128 | * @param ro If true, the mapping is copied read-only. |
129 | */ |
129 | */ |
130 | void dtsb_pte_copy(pte_t *t, index_t index, bool ro) |
130 | void dtsb_pte_copy(pte_t *t, index_t index, bool ro) |
131 | { |
131 | { |
132 | as_t *as; |
132 | as_t *as; |
133 | tsb_entry_t *tsb; |
133 | tsb_entry_t *tsb; |
134 | index_t entry; |
134 | index_t entry; |
135 | 135 | ||
136 | ASSERT(index <= 1); |
136 | ASSERT(index <= 1); |
137 | 137 | ||
138 | as = t->as; |
138 | as = t->as; |
139 | entry = ((t->page >> MMU_PAGE_WIDTH) + index) & TSB_INDEX_MASK; |
139 | entry = ((t->page >> MMU_PAGE_WIDTH) + index) & TSB_INDEX_MASK; |
140 | ASSERT(entry < DTSB_ENTRY_COUNT); |
140 | ASSERT(entry < DTSB_ENTRY_COUNT); |
141 | tsb = &as->arch.dtsb[entry]; |
141 | tsb = &as->arch.dtsb[entry]; |
142 | 142 | ||
143 | /* |
143 | /* |
144 | * We use write barriers to make sure that the TSB load |
144 | * We use write barriers to make sure that the TSB load |
145 | * won't use inconsistent data or that the fault will |
145 | * won't use inconsistent data or that the fault will |
146 | * be repeated. |
146 | * be repeated. |
147 | */ |
147 | */ |
148 | 148 | ||
149 | tsb->tag.invalid = true; /* invalidate the entry |
149 | tsb->tag.invalid = true; /* invalidate the entry |
150 | * (tag target has this |
150 | * (tag target has this |
151 | * set to 0) */ |
151 | * set to 0) */ |
152 | 152 | ||
153 | write_barrier(); |
153 | write_barrier(); |
154 | 154 | ||
155 | tsb->tag.context = as->asid; |
155 | tsb->tag.context = as->asid; |
156 | /* the shift is bigger than PAGE_WIDTH, do not bother with index */ |
156 | /* the shift is bigger than PAGE_WIDTH, do not bother with index */ |
157 | tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT; |
157 | tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT; |
158 | tsb->data.value = 0; |
158 | tsb->data.value = 0; |
159 | tsb->data.size = PAGESIZE_8K; |
159 | tsb->data.size = PAGESIZE_8K; |
160 | tsb->data.pfn = (t->frame >> MMU_FRAME_WIDTH) + index; |
160 | tsb->data.pfn = (t->frame >> MMU_FRAME_WIDTH) + index; |
161 | tsb->data.cp = t->c; |
161 | tsb->data.cp = t->c; |
162 | #ifdef CONFIG_VIRT_IDX_DCACHE |
162 | #ifdef CONFIG_VIRT_IDX_DCACHE |
163 | tsb->data.cv = t->c; |
163 | tsb->data.cv = t->c; |
164 | #endif /* CONFIG_VIRT_IDX_DCACHE */ |
164 | #endif /* CONFIG_VIRT_IDX_DCACHE */ |
165 | tsb->data.p = t->k; /* p as privileged */ |
165 | tsb->data.p = t->k; /* p as privileged */ |
166 | tsb->data.w = ro ? false : t->w; |
166 | tsb->data.w = ro ? false : t->w; |
167 | tsb->data.v = t->p; |
167 | tsb->data.v = t->p; |
168 | 168 | ||
169 | write_barrier(); |
169 | write_barrier(); |
170 | 170 | ||
171 | tsb->tag.invalid = false; /* mark the entry as valid */ |
171 | tsb->tag.invalid = false; /* mark the entry as valid */ |
172 | } |
172 | } |
173 | 173 | ||
174 | /** @} |
174 | /** @} |
175 | */ |
175 | */ |
- | 176 | ||
176 | 177 |