2 * Copyright (C) 2006 Jakub Jermar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @addtogroup sparc64mm
35 #include <arch/mm/tsb.h>
36 #include <arch/mm/tlb.h>
37 #include <arch/barrier.h>
39 #include <arch/types.h>
44 #define TSB_INDEX_MASK ((1<<(21+1+TSB_SIZE-PAGE_WIDTH))-1)
46 /** Invalidate portion of TSB.
48 * We assume that the address space is already locked.
49 * Note that respective portions of both TSBs
50 * are invalidated at a time.
52 * @param as Address space.
53 * @param page First page to invalidate in TSB.
54 * @param pages Number of pages to invalidate. Value of (count_t) -1 means the whole TSB.
56 void tsb_invalidate(as_t
*as
, uintptr_t page
, count_t pages
)
61 ASSERT(as
->arch
.itsb
&& as
->arch
.dtsb
);
63 i0
= (page
>> PAGE_WIDTH
) & TSB_INDEX_MASK
;
64 cnt
= min(pages
, ITSB_ENTRY_COUNT
);
66 for (i
= 0; i
< cnt
; i
++) {
67 as
->arch
.itsb
[(i0
+ i
) & (ITSB_ENTRY_COUNT
-1)].tag
.invalid
= 0;
68 as
->arch
.dtsb
[(i0
+ i
) & (DTSB_ENTRY_COUNT
-1)].tag
.invalid
= 0;
72 /** Copy software PTE to ITSB.
74 * @param t Software PTE.
76 void itsb_pte_copy(pte_t
*t
)
82 tsb
= &as
->arch
.itsb
[(t
->page
>> PAGE_WIDTH
) & TSB_INDEX_MASK
];
85 * We use write barriers to make sure that the TSB load
86 * won't use inconsistent data or that the fault will
90 tsb
->tag
.invalid
= 1; /* invalidate the entry (tag target has this set to 0) */
94 tsb
->tag
.context
= as
->asid
;
95 tsb
->tag
.va_tag
= t
->page
>> VA_TAG_PAGE_SHIFT
;
97 tsb
->data
.size
= PAGESIZE_8K
;
98 tsb
->data
.pfn
= t
->frame
>> PAGE_WIDTH
;
101 tsb
->data
.p
= t
->k
; /* p as privileged */
106 tsb
->tag
.invalid
= 0; /* mark the entry as valid */
109 /** Copy software PTE to DTSB.
111 * @param t Software PTE.
112 * @param ro If true, the mapping is copied read-only.
114 void dtsb_pte_copy(pte_t
*t
, bool ro
)
120 tsb
= &as
->arch
.dtsb
[(t
->page
>> PAGE_WIDTH
) & TSB_INDEX_MASK
];
123 * We use write barriers to make sure that the TSB load
124 * won't use inconsistent data or that the fault will
128 tsb
->tag
.invalid
= 1; /* invalidate the entry (tag target has this set to 0) */
132 tsb
->tag
.context
= as
->asid
;
133 tsb
->tag
.va_tag
= t
->page
>> VA_TAG_PAGE_SHIFT
;
135 tsb
->data
.size
= PAGESIZE_8K
;
136 tsb
->data
.pfn
= t
->frame
>> PAGE_WIDTH
;
139 tsb
->data
.p
= t
->k
; /* p as privileged */
140 tsb
->data
.w
= ro
? false : t
->w
;
145 tsb
->tag
.invalid
= 0; /* mark the entry as valid */