source: mainline/kernel/arch/sparc64/src/mm/sun4v/tsb.c@ b781cb29

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b781cb29 was d99c1d2, checked in by Martin Decky <martin@…>, 15 years ago

use [u]int{8|16|32|64}_t type definitions as detected by the autotool
replace direct usage of arch/types.h with typedefs.h

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[74cbac7d]1/*
2 * Copyright (c) 2006 Jakub Jermar
[8c2214e]3 * Copyright (c) 2009 Pavel Rimsky
[74cbac7d]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/tsb.h>
[8c2214e]37#include <arch/mm/pagesize.h>
[74cbac7d]38#include <arch/mm/tlb.h>
39#include <arch/mm/page.h>
40#include <arch/barrier.h>
41#include <mm/as.h>
[d99c1d2]42#include <typedefs.h>
[74cbac7d]43#include <macros.h>
44#include <debug.h>
45
46#define TSB_INDEX_MASK ((1 << (21 + 1 + TSB_SIZE - MMU_PAGE_WIDTH)) - 1)
47
48/** Invalidate portion of TSB.
49 *
50 * We assume that the address space is already locked. Note that respective
51 * portions of both TSBs are invalidated at a time.
52 *
[8c2214e]53 * @param as Address space.
54 * @param page First page to invalidate in TSB.
55 * @param pages Number of pages to invalidate. Value of (count_t) -1 means the
56 * whole TSB.
[74cbac7d]57 */
58void tsb_invalidate(as_t *as, uintptr_t page, size_t pages)
59{
[8c2214e]60 size_t i0, i;
[74cbac7d]61 size_t cnt;
62
[8c2214e]63 ASSERT(as->arch.tsb_description.tsb_base);
[74cbac7d]64
65 i0 = (page >> MMU_PAGE_WIDTH) & TSB_INDEX_MASK;
[8c2214e]66 ASSERT(i0 < TSB_ENTRY_COUNT);
[74cbac7d]67
[8c2214e]68 if (pages == (size_t) - 1 || (pages) > TSB_ENTRY_COUNT)
69 cnt = TSB_ENTRY_COUNT;
[74cbac7d]70 else
[8c2214e]71 cnt = pages;
[74cbac7d]72
73 for (i = 0; i < cnt; i++) {
[8c2214e]74 ((tsb_entry_t *) PA2KA(as->arch.tsb_description.tsb_base))[
75 (i0 + i) & (TSB_ENTRY_COUNT - 1)].data.v = false;
[74cbac7d]76 }
77}
78
79/** Copy software PTE to ITSB.
80 *
81 * @param t Software PTE.
82 */
[8c2214e]83void itsb_pte_copy(pte_t *t)
[74cbac7d]84{
85 as_t *as;
86 tsb_entry_t *tsb;
87 size_t entry;
88
89 as = t->as;
[8c2214e]90 entry = (t->page >> MMU_PAGE_WIDTH) & TSB_INDEX_MASK;
91 ASSERT(entry < TSB_ENTRY_COUNT);
92 tsb = &((tsb_entry_t *) PA2KA(as->arch.tsb_description.tsb_base))[entry];
[74cbac7d]93
94 /*
95 * We use write barriers to make sure that the TSB load
96 * won't use inconsistent data or that the fault will
97 * be repeated.
98 */
99
[8c2214e]100 tsb->data.v = false;
[74cbac7d]101
102 write_barrier();
103
104 tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
[8c2214e]105
[74cbac7d]106 tsb->data.value = 0;
[8c2214e]107 tsb->data.nfo = false;
108 tsb->data.ra = t->frame >> MMU_FRAME_WIDTH;
109 tsb->data.ie = false;
110 tsb->data.e = false;
[74cbac7d]111 tsb->data.cp = t->c; /* cp as cache in phys.-idxed, c as cacheable */
[8c2214e]112 tsb->data.cv = false;
[74cbac7d]113 tsb->data.p = t->k; /* p as privileged, k as kernel */
[8c2214e]114 tsb->data.x = true;
115 tsb->data.w = false;
116 tsb->data.size = PAGESIZE_8K;
[74cbac7d]117
118 write_barrier();
119
[8c2214e]120 tsb->data.v = t->p; /* v as valid, p as present */
[74cbac7d]121}
122
123/** Copy software PTE to DTSB.
124 *
125 * @param t Software PTE.
126 * @param ro If true, the mapping is copied read-only.
127 */
[8c2214e]128void dtsb_pte_copy(pte_t *t, bool ro)
[74cbac7d]129{
130 as_t *as;
131 tsb_entry_t *tsb;
132 size_t entry;
133
134 as = t->as;
[8c2214e]135 entry = (t->page >> MMU_PAGE_WIDTH) & TSB_INDEX_MASK;
136 ASSERT(entry < TSB_ENTRY_COUNT);
137 tsb = &((tsb_entry_t *) PA2KA(as->arch.tsb_description.tsb_base))[entry];
[74cbac7d]138
139 /*
140 * We use write barriers to make sure that the TSB load
141 * won't use inconsistent data or that the fault will
142 * be repeated.
143 */
144
[8c2214e]145 tsb->data.v = false;
[74cbac7d]146
147 write_barrier();
148
149 tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
[8c2214e]150
[74cbac7d]151 tsb->data.value = 0;
[8c2214e]152 tsb->data.nfo = false;
153 tsb->data.ra = t->frame >> MMU_FRAME_WIDTH;
154 tsb->data.ie = false;
155 tsb->data.e = false;
156 tsb->data.cp = t->c; /* cp as cache in phys.-idxed, c as cacheable */
[74cbac7d]157#ifdef CONFIG_VIRT_IDX_DCACHE
158 tsb->data.cv = t->c;
159#endif /* CONFIG_VIRT_IDX_DCACHE */
[8c2214e]160 tsb->data.p = t->k; /* p as privileged, k as kernel */
161 tsb->data.x = true;
[74cbac7d]162 tsb->data.w = ro ? false : t->w;
[8c2214e]163 tsb->data.size = PAGESIZE_8K;
[74cbac7d]164
165 write_barrier();
166
[8c2214e]167 tsb->data.v = t->p; /* v as valid, p as present */
[74cbac7d]168}
169
170/** @}
171 */
Note: See TracBrowser for help on using the repository browser.