source: mainline/kernel/arch/sparc64/src/mm/sun4u/tsb.c

Last change on this file was c5429fe, checked in by Jakub Jermar <jakub@…>, 7 years ago

Disambiguate architecture specific doxygroups

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[74cbac7d]1/*
2 * Copyright (c) 2006 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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.
16 *
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.
27 */
28
[c5429fe]29/** @addtogroup kernel_sparc64_mm
[74cbac7d]30 * @{
31 */
32/** @file
33 */
34
35#include <arch/mm/tsb.h>
36#include <arch/mm/tlb.h>
37#include <arch/mm/page.h>
[05882233]38#include <barrier.h>
[63e27ef]39#include <assert.h>
[74cbac7d]40#include <mm/as.h>
[d99c1d2]41#include <typedefs.h>
[74cbac7d]42#include <macros.h>
43
44/** Invalidate portion of TSB.
45 *
46 * We assume that the address space is already locked. Note that respective
47 * portions of both TSBs are invalidated at a time.
48 *
49 * @param as Address space.
50 * @param page First page to invalidate in TSB.
51 * @param pages Number of pages to invalidate. Value of (size_t) -1 means the
52 * whole TSB.
53 */
54void tsb_invalidate(as_t *as, uintptr_t page, size_t pages)
55{
56 size_t i0;
57 size_t i;
58 size_t cnt;
[a35b458]59
[63e27ef]60 assert(as->arch.itsb);
61 assert(as->arch.dtsb);
[a35b458]62
[e08162b]63 i0 = (page >> MMU_PAGE_WIDTH) & ITSB_ENTRY_MASK;
[74cbac7d]64
65 if (pages == (size_t) -1 || (pages * 2) > ITSB_ENTRY_COUNT)
66 cnt = ITSB_ENTRY_COUNT;
67 else
68 cnt = pages * 2;
[a35b458]69
[74cbac7d]70 for (i = 0; i < cnt; i++) {
[e08162b]71 as->arch.itsb[(i0 + i) & ITSB_ENTRY_MASK].tag.invalid = true;
72 as->arch.dtsb[(i0 + i) & DTSB_ENTRY_MASK].tag.invalid = true;
[74cbac7d]73 }
74}
75
76/** Copy software PTE to ITSB.
77 *
78 * @param t Software PTE.
79 * @param index Zero if lower 8K-subpage, one if higher 8K subpage.
80 */
81void itsb_pte_copy(pte_t *t, size_t index)
82{
83 as_t *as;
[e08162b]84 tsb_entry_t *tte;
[74cbac7d]85 size_t entry;
86
[63e27ef]87 assert(index <= 1);
[a35b458]88
[74cbac7d]89 as = t->as;
[e08162b]90 entry = ((t->page >> MMU_PAGE_WIDTH) + index) & ITSB_ENTRY_MASK;
91 tte = &as->arch.itsb[entry];
[74cbac7d]92
93 /*
94 * We use write barriers to make sure that the TSB load
95 * won't use inconsistent data or that the fault will
96 * be repeated.
97 */
98
[904b1bc]99 /* Invalidate the entry (tag target has this set to 0) */
100 tte->tag.invalid = true;
[74cbac7d]101
102 write_barrier();
103
[e08162b]104 tte->tag.context = as->asid;
[74cbac7d]105 /* the shift is bigger than PAGE_WIDTH, do not bother with index */
[e08162b]106 tte->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
107 tte->data.value = 0;
108 tte->data.size = PAGESIZE_8K;
109 tte->data.pfn = (t->frame >> MMU_FRAME_WIDTH) + index;
110 tte->data.cp = t->c; /* cp as cache in phys.-idxed, c as cacheable */
111 tte->data.p = t->k; /* p as privileged, k as kernel */
112 tte->data.v = t->p; /* v as valid, p as present */
[a35b458]113
[74cbac7d]114 write_barrier();
[a35b458]115
[e08162b]116 tte->tag.invalid = false; /* mark the entry as valid */
[74cbac7d]117}
118
119/** Copy software PTE to DTSB.
120 *
121 * @param t Software PTE.
122 * @param index Zero if lower 8K-subpage, one if higher 8K-subpage.
123 * @param ro If true, the mapping is copied read-only.
124 */
125void dtsb_pte_copy(pte_t *t, size_t index, bool ro)
126{
127 as_t *as;
[e08162b]128 tsb_entry_t *tte;
[74cbac7d]129 size_t entry;
[a35b458]130
[63e27ef]131 assert(index <= 1);
[74cbac7d]132
133 as = t->as;
[e08162b]134 entry = ((t->page >> MMU_PAGE_WIDTH) + index) & DTSB_ENTRY_MASK;
135 tte = &as->arch.dtsb[entry];
[74cbac7d]136
137 /*
138 * We use write barriers to make sure that the TSB load
139 * won't use inconsistent data or that the fault will
140 * be repeated.
141 */
142
[904b1bc]143 /* Invalidate the entry (tag target has this set to 0) */
144 tte->tag.invalid = true;
[74cbac7d]145
146 write_barrier();
147
[e08162b]148 tte->tag.context = as->asid;
[74cbac7d]149 /* the shift is bigger than PAGE_WIDTH, do not bother with index */
[e08162b]150 tte->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
151 tte->data.value = 0;
152 tte->data.size = PAGESIZE_8K;
153 tte->data.pfn = (t->frame >> MMU_FRAME_WIDTH) + index;
154 tte->data.cp = t->c;
[74cbac7d]155#ifdef CONFIG_VIRT_IDX_DCACHE
[e08162b]156 tte->data.cv = t->c;
[74cbac7d]157#endif /* CONFIG_VIRT_IDX_DCACHE */
[e08162b]158 tte->data.p = t->k; /* p as privileged */
159 tte->data.w = ro ? false : t->w;
160 tte->data.v = t->p;
[a35b458]161
[74cbac7d]162 write_barrier();
[a35b458]163
[e08162b]164 tte->tag.invalid = false; /* mark the entry as valid */
[74cbac7d]165}
166
167/** @}
168 */
Note: See TracBrowser for help on using the repository browser.