Subversion Repositories HelenOS

Rev

Rev 2071 | Rev 2141 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2071 Rev 2089
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/barrier.h>
37
#include <arch/barrier.h>
38
#include <mm/as.h>
38
#include <mm/as.h>
39
#include <arch/types.h>
39
#include <arch/types.h>
40
#include <typedefs.h>
-
 
41
#include <macros.h>
40
#include <macros.h>
42
#include <debug.h>
41
#include <debug.h>
43
 
42
 
44
#define TSB_INDEX_MASK      ((1 << (21 + 1 + TSB_SIZE - PAGE_WIDTH)) - 1)
43
#define TSB_INDEX_MASK      ((1 << (21 + 1 + TSB_SIZE - PAGE_WIDTH)) - 1)
45
 
44
 
46
/** Invalidate portion of TSB.
45
/** Invalidate portion of TSB.
47
 *
46
 *
48
 * We assume that the address space is already locked. Note that respective
47
 * We assume that the address space is already locked. Note that respective
49
 * portions of both TSBs are invalidated at a time.
48
 * portions of both TSBs are invalidated at a time.
50
 *
49
 *
51
 * @param as Address space.
50
 * @param as Address space.
52
 * @param page First page to invalidate in TSB.
51
 * @param page First page to invalidate in TSB.
53
 * @param pages Number of pages to invalidate. Value of (count_t) -1 means the
52
 * @param pages Number of pages to invalidate. Value of (count_t) -1 means the
54
 *  whole TSB.
53
 *  whole TSB.
55
 */
54
 */
56
void tsb_invalidate(as_t *as, uintptr_t page, count_t pages)
55
void tsb_invalidate(as_t *as, uintptr_t page, count_t pages)
57
{
56
{
58
    index_t i0, i;
57
    index_t i0, i;
59
    count_t cnt;
58
    count_t cnt;
60
   
59
   
61
    ASSERT(as->arch.itsb && as->arch.dtsb);
60
    ASSERT(as->arch.itsb && as->arch.dtsb);
62
   
61
   
63
    i0 = (page >> PAGE_WIDTH) & TSB_INDEX_MASK;
62
    i0 = (page >> PAGE_WIDTH) & TSB_INDEX_MASK;
64
    cnt = min(pages, ITSB_ENTRY_COUNT);
63
    cnt = min(pages, ITSB_ENTRY_COUNT);
65
   
64
   
66
    for (i = 0; i < cnt; i++) {
65
    for (i = 0; i < cnt; i++) {
67
        as->arch.itsb[(i0 + i) & (ITSB_ENTRY_COUNT - 1)].tag.invalid =
66
        as->arch.itsb[(i0 + i) & (ITSB_ENTRY_COUNT - 1)].tag.invalid =
68
            true;
67
            true;
69
        as->arch.dtsb[(i0 + i) & (DTSB_ENTRY_COUNT - 1)].tag.invalid =
68
        as->arch.dtsb[(i0 + i) & (DTSB_ENTRY_COUNT - 1)].tag.invalid =
70
            true;
69
            true;
71
    }
70
    }
72
}
71
}
73
 
72
 
74
/** Copy software PTE to ITSB.
73
/** Copy software PTE to ITSB.
75
 *
74
 *
76
 * @param t Software PTE.
75
 * @param t Software PTE.
77
 */
76
 */
78
void itsb_pte_copy(pte_t *t)
77
void itsb_pte_copy(pte_t *t)
79
{
78
{
80
    as_t *as;
79
    as_t *as;
81
    tsb_entry_t *tsb;
80
    tsb_entry_t *tsb;
82
   
81
   
83
    as = t->as;
82
    as = t->as;
84
    tsb = &as->arch.itsb[(t->page >> PAGE_WIDTH) & TSB_INDEX_MASK];
83
    tsb = &as->arch.itsb[(t->page >> PAGE_WIDTH) & TSB_INDEX_MASK];
85
 
84
 
86
    /*
85
    /*
87
     * We use write barriers to make sure that the TSB load
86
     * We use write barriers to make sure that the TSB load
88
     * won't use inconsistent data or that the fault will
87
     * won't use inconsistent data or that the fault will
89
     * be repeated.
88
     * be repeated.
90
     */
89
     */
91
 
90
 
92
    tsb->tag.invalid = true;    /* invalidate the entry
91
    tsb->tag.invalid = true;    /* invalidate the entry
93
                     * (tag target has this
92
                     * (tag target has this
94
                     * set to 0) */
93
                     * set to 0) */
95
 
94
 
96
    write_barrier();
95
    write_barrier();
97
 
96
 
98
    tsb->tag.context = as->asid;
97
    tsb->tag.context = as->asid;
99
    tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
98
    tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
100
    tsb->data.value = 0;
99
    tsb->data.value = 0;
101
    tsb->data.size = PAGESIZE_8K;
100
    tsb->data.size = PAGESIZE_8K;
102
    tsb->data.pfn = t->frame >> FRAME_WIDTH;
101
    tsb->data.pfn = t->frame >> FRAME_WIDTH;
103
    tsb->data.cp = t->c;
102
    tsb->data.cp = t->c;
104
    tsb->data.p = t->k;     /* p as privileged */
103
    tsb->data.p = t->k;     /* p as privileged */
105
    tsb->data.v = t->p;
104
    tsb->data.v = t->p;
106
   
105
   
107
    write_barrier();
106
    write_barrier();
108
   
107
   
109
    tsb->tag.invalid = false;   /* mark the entry as valid */
108
    tsb->tag.invalid = false;   /* mark the entry as valid */
110
}
109
}
111
 
110
 
112
/** Copy software PTE to DTSB.
111
/** Copy software PTE to DTSB.
113
 *
112
 *
114
 * @param t Software PTE.
113
 * @param t Software PTE.
115
 * @param ro If true, the mapping is copied read-only.
114
 * @param ro If true, the mapping is copied read-only.
116
 */
115
 */
117
void dtsb_pte_copy(pte_t *t, bool ro)
116
void dtsb_pte_copy(pte_t *t, bool ro)
118
{
117
{
119
    as_t *as;
118
    as_t *as;
120
    tsb_entry_t *tsb;
119
    tsb_entry_t *tsb;
121
   
120
   
122
    as = t->as;
121
    as = t->as;
123
    tsb = &as->arch.dtsb[(t->page >> PAGE_WIDTH) & TSB_INDEX_MASK];
122
    tsb = &as->arch.dtsb[(t->page >> PAGE_WIDTH) & TSB_INDEX_MASK];
124
 
123
 
125
    /*
124
    /*
126
     * We use write barriers to make sure that the TSB load
125
     * We use write barriers to make sure that the TSB load
127
     * won't use inconsistent data or that the fault will
126
     * won't use inconsistent data or that the fault will
128
     * be repeated.
127
     * be repeated.
129
     */
128
     */
130
 
129
 
131
    tsb->tag.invalid = true;    /* invalidate the entry
130
    tsb->tag.invalid = true;    /* invalidate the entry
132
                     * (tag target has this
131
                     * (tag target has this
133
                     * set to 0) */
132
                     * set to 0) */
134
 
133
 
135
    write_barrier();
134
    write_barrier();
136
 
135
 
137
    tsb->tag.context = as->asid;
136
    tsb->tag.context = as->asid;
138
    tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
137
    tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
139
    tsb->data.value = 0;
138
    tsb->data.value = 0;
140
    tsb->data.size = PAGESIZE_8K;
139
    tsb->data.size = PAGESIZE_8K;
141
    tsb->data.pfn = t->frame >> FRAME_WIDTH;
140
    tsb->data.pfn = t->frame >> FRAME_WIDTH;
142
    tsb->data.cp = t->c;
141
    tsb->data.cp = t->c;
143
#ifdef CONFIG_VIRT_IDX_DCACHE
142
#ifdef CONFIG_VIRT_IDX_DCACHE
144
    tsb->data.cv = t->c;
143
    tsb->data.cv = t->c;
145
#endif /* CONFIG_VIRT_IDX_DCACHE */
144
#endif /* CONFIG_VIRT_IDX_DCACHE */
146
    tsb->data.p = t->k;     /* p as privileged */
145
    tsb->data.p = t->k;     /* p as privileged */
147
    tsb->data.w = ro ? false : t->w;
146
    tsb->data.w = ro ? false : t->w;
148
    tsb->data.v = t->p;
147
    tsb->data.v = t->p;
149
   
148
   
150
    write_barrier();
149
    write_barrier();
151
   
150
   
152
    tsb->tag.invalid = true;    /* mark the entry as valid */
151
    tsb->tag.invalid = true;    /* mark the entry as valid */
153
}
152
}
154
 
153
 
155
/** @}
154
/** @}
156
 */
155
 */
157
 
156