Subversion Repositories HelenOS

Rev

Rev 2071 | Rev 2231 | 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) 2005 Jakub Jermar
2
 * Copyright (c) 2005 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
#ifndef KERN_sparc64_TLB_H_
35
#ifndef KERN_sparc64_TLB_H_
36
#define KERN_sparc64_TLB_H_
36
#define KERN_sparc64_TLB_H_
37
 
37
 
38
#define ITLB_ENTRY_COUNT        64
38
#define ITLB_ENTRY_COUNT        64
39
#define DTLB_ENTRY_COUNT        64
39
#define DTLB_ENTRY_COUNT        64
40
 
40
 
41
#define MEM_CONTEXT_KERNEL      0
41
#define MEM_CONTEXT_KERNEL      0
42
#define MEM_CONTEXT_TEMP        1
42
#define MEM_CONTEXT_TEMP        1
43
 
43
 
44
/** Page sizes. */
44
/** Page sizes. */
45
#define PAGESIZE_8K 0
45
#define PAGESIZE_8K 0
46
#define PAGESIZE_64K    1
46
#define PAGESIZE_64K    1
47
#define PAGESIZE_512K   2
47
#define PAGESIZE_512K   2
48
#define PAGESIZE_4M 3
48
#define PAGESIZE_4M 3
49
 
49
 
50
/** Bit width of the TLB-locked portion of kernel address space. */
50
/** Bit width of the TLB-locked portion of kernel address space. */
51
#define KERNEL_PAGE_WIDTH       22  /* 4M */
51
#define KERNEL_PAGE_WIDTH       22  /* 4M */
52
 
52
 
53
/* TLB Demap Operation types. */
53
/* TLB Demap Operation types. */
54
#define TLB_DEMAP_PAGE      0
54
#define TLB_DEMAP_PAGE      0
55
#define TLB_DEMAP_CONTEXT   1
55
#define TLB_DEMAP_CONTEXT   1
56
 
56
 
57
#define TLB_DEMAP_TYPE_SHIFT    6
57
#define TLB_DEMAP_TYPE_SHIFT    6
58
 
58
 
59
/* TLB Demap Operation Context register encodings. */
59
/* TLB Demap Operation Context register encodings. */
60
#define TLB_DEMAP_PRIMARY   0
60
#define TLB_DEMAP_PRIMARY   0
61
#define TLB_DEMAP_SECONDARY 1
61
#define TLB_DEMAP_SECONDARY 1
62
#define TLB_DEMAP_NUCLEUS   2
62
#define TLB_DEMAP_NUCLEUS   2
63
 
63
 
64
#define TLB_DEMAP_CONTEXT_SHIFT 4
64
#define TLB_DEMAP_CONTEXT_SHIFT 4
65
 
65
 
66
/* TLB Tag Access shifts */
66
/* TLB Tag Access shifts */
67
#define TLB_TAG_ACCESS_CONTEXT_SHIFT    0
67
#define TLB_TAG_ACCESS_CONTEXT_SHIFT    0
68
#define TLB_TAG_ACCESS_CONTEXT_MASK ((1 << 13) - 1)
68
#define TLB_TAG_ACCESS_CONTEXT_MASK ((1 << 13) - 1)
69
#define TLB_TAG_ACCESS_VPN_SHIFT    13
69
#define TLB_TAG_ACCESS_VPN_SHIFT    13
70
 
70
 
71
#ifndef __ASM__
71
#ifndef __ASM__
72
 
72
 
73
#include <arch/mm/tte.h>
73
#include <arch/mm/tte.h>
74
#include <arch/mm/mmu.h>
74
#include <arch/mm/mmu.h>
75
#include <arch/mm/page.h>
75
#include <arch/mm/page.h>
76
#include <arch/asm.h>
76
#include <arch/asm.h>
77
#include <arch/barrier.h>
77
#include <arch/barrier.h>
78
#include <arch/types.h>
78
#include <arch/types.h>
79
#include <typedefs.h>
-
 
80
 
79
 
81
union tlb_context_reg {
80
union tlb_context_reg {
82
    uint64_t v;
81
    uint64_t v;
83
    struct {
82
    struct {
84
        unsigned long : 51;
83
        unsigned long : 51;
85
        unsigned context : 13;      /**< Context/ASID. */
84
        unsigned context : 13;      /**< Context/ASID. */
86
    } __attribute__ ((packed));
85
    } __attribute__ ((packed));
87
};
86
};
88
typedef union tlb_context_reg tlb_context_reg_t;
87
typedef union tlb_context_reg tlb_context_reg_t;
89
 
88
 
90
/** I-/D-TLB Data In/Access Register type. */
89
/** I-/D-TLB Data In/Access Register type. */
91
typedef tte_data_t tlb_data_t;
90
typedef tte_data_t tlb_data_t;
92
 
91
 
93
/** I-/D-TLB Data Access Address in Alternate Space. */
92
/** I-/D-TLB Data Access Address in Alternate Space. */
94
union tlb_data_access_addr {
93
union tlb_data_access_addr {
95
    uint64_t value;
94
    uint64_t value;
96
    struct {
95
    struct {
97
        uint64_t : 55;
96
        uint64_t : 55;
98
        unsigned tlb_entry : 6;
97
        unsigned tlb_entry : 6;
99
        unsigned : 3;
98
        unsigned : 3;
100
    } __attribute__ ((packed));
99
    } __attribute__ ((packed));
101
};
100
};
102
typedef union tlb_data_access_addr tlb_data_access_addr_t;
101
typedef union tlb_data_access_addr tlb_data_access_addr_t;
103
typedef union tlb_data_access_addr tlb_tag_read_addr_t;
102
typedef union tlb_data_access_addr tlb_tag_read_addr_t;
104
 
103
 
105
/** I-/D-TLB Tag Read Register. */
104
/** I-/D-TLB Tag Read Register. */
106
union tlb_tag_read_reg {
105
union tlb_tag_read_reg {
107
    uint64_t value;
106
    uint64_t value;
108
    struct {
107
    struct {
109
        uint64_t vpn : 51;  /**< Virtual Address bits 63:13. */
108
        uint64_t vpn : 51;  /**< Virtual Address bits 63:13. */
110
        unsigned context : 13;  /**< Context identifier. */
109
        unsigned context : 13;  /**< Context identifier. */
111
    } __attribute__ ((packed));
110
    } __attribute__ ((packed));
112
};
111
};
113
typedef union tlb_tag_read_reg tlb_tag_read_reg_t;
112
typedef union tlb_tag_read_reg tlb_tag_read_reg_t;
114
typedef union tlb_tag_read_reg tlb_tag_access_reg_t;
113
typedef union tlb_tag_read_reg tlb_tag_access_reg_t;
115
 
114
 
116
 
115
 
117
/** TLB Demap Operation Address. */
116
/** TLB Demap Operation Address. */
118
union tlb_demap_addr {
117
union tlb_demap_addr {
119
    uint64_t value;
118
    uint64_t value;
120
    struct {
119
    struct {
121
        uint64_t vpn: 51;   /**< Virtual Address bits 63:13. */
120
        uint64_t vpn: 51;   /**< Virtual Address bits 63:13. */
122
        unsigned : 6;       /**< Ignored. */
121
        unsigned : 6;       /**< Ignored. */
123
        unsigned type : 1;  /**< The type of demap operation. */
122
        unsigned type : 1;  /**< The type of demap operation. */
124
        unsigned context : 2;   /**< Context register selection. */
123
        unsigned context : 2;   /**< Context register selection. */
125
        unsigned : 4;       /**< Zero. */
124
        unsigned : 4;       /**< Zero. */
126
    } __attribute__ ((packed));
125
    } __attribute__ ((packed));
127
};
126
};
128
typedef union tlb_demap_addr tlb_demap_addr_t;
127
typedef union tlb_demap_addr tlb_demap_addr_t;
129
 
128
 
130
/** TLB Synchronous Fault Status Register. */
129
/** TLB Synchronous Fault Status Register. */
131
union tlb_sfsr_reg {
130
union tlb_sfsr_reg {
132
    uint64_t value;
131
    uint64_t value;
133
    struct {
132
    struct {
134
        unsigned long : 40; /**< Implementation dependent. */
133
        unsigned long : 40; /**< Implementation dependent. */
135
        unsigned asi : 8;   /**< ASI. */
134
        unsigned asi : 8;   /**< ASI. */
136
        unsigned : 2;
135
        unsigned : 2;
137
        unsigned ft : 7;    /**< Fault type. */
136
        unsigned ft : 7;    /**< Fault type. */
138
        unsigned e : 1;     /**< Side-effect bit. */
137
        unsigned e : 1;     /**< Side-effect bit. */
139
        unsigned ct : 2;    /**< Context Register selection. */
138
        unsigned ct : 2;    /**< Context Register selection. */
140
        unsigned pr : 1;    /**< Privilege bit. */
139
        unsigned pr : 1;    /**< Privilege bit. */
141
        unsigned w : 1;     /**< Write bit. */
140
        unsigned w : 1;     /**< Write bit. */
142
        unsigned ow : 1;    /**< Overwrite bit. */
141
        unsigned ow : 1;    /**< Overwrite bit. */
143
        unsigned fv : 1;    /**< Fault Valid bit. */
142
        unsigned fv : 1;    /**< Fault Valid bit. */
144
    } __attribute__ ((packed));
143
    } __attribute__ ((packed));
145
};
144
};
146
typedef union tlb_sfsr_reg tlb_sfsr_reg_t;
145
typedef union tlb_sfsr_reg tlb_sfsr_reg_t;
147
 
146
 
148
/** Read MMU Primary Context Register.
147
/** Read MMU Primary Context Register.
149
 *
148
 *
150
 * @return Current value of Primary Context Register.
149
 * @return Current value of Primary Context Register.
151
 */
150
 */
152
static inline uint64_t mmu_primary_context_read(void)
151
static inline uint64_t mmu_primary_context_read(void)
153
{
152
{
154
    return asi_u64_read(ASI_DMMU, VA_PRIMARY_CONTEXT_REG);
153
    return asi_u64_read(ASI_DMMU, VA_PRIMARY_CONTEXT_REG);
155
}
154
}
156
 
155
 
157
/** Write MMU Primary Context Register.
156
/** Write MMU Primary Context Register.
158
 *
157
 *
159
 * @param v New value of Primary Context Register.
158
 * @param v New value of Primary Context Register.
160
 */
159
 */
161
static inline void mmu_primary_context_write(uint64_t v)
160
static inline void mmu_primary_context_write(uint64_t v)
162
{
161
{
163
    asi_u64_write(ASI_DMMU, VA_PRIMARY_CONTEXT_REG, v);
162
    asi_u64_write(ASI_DMMU, VA_PRIMARY_CONTEXT_REG, v);
164
    flush();
163
    flush();
165
}
164
}
166
 
165
 
167
/** Read MMU Secondary Context Register.
166
/** Read MMU Secondary Context Register.
168
 *
167
 *
169
 * @return Current value of Secondary Context Register.
168
 * @return Current value of Secondary Context Register.
170
 */
169
 */
171
static inline uint64_t mmu_secondary_context_read(void)
170
static inline uint64_t mmu_secondary_context_read(void)
172
{
171
{
173
    return asi_u64_read(ASI_DMMU, VA_SECONDARY_CONTEXT_REG);
172
    return asi_u64_read(ASI_DMMU, VA_SECONDARY_CONTEXT_REG);
174
}
173
}
175
 
174
 
176
/** Write MMU Primary Context Register.
175
/** Write MMU Primary Context Register.
177
 *
176
 *
178
 * @param v New value of Primary Context Register.
177
 * @param v New value of Primary Context Register.
179
 */
178
 */
180
static inline void mmu_secondary_context_write(uint64_t v)
179
static inline void mmu_secondary_context_write(uint64_t v)
181
{
180
{
182
    asi_u64_write(ASI_DMMU, VA_SECONDARY_CONTEXT_REG, v);
181
    asi_u64_write(ASI_DMMU, VA_SECONDARY_CONTEXT_REG, v);
183
    flush();
182
    flush();
184
}
183
}
185
 
184
 
186
/** Read IMMU TLB Data Access Register.
185
/** Read IMMU TLB Data Access Register.
187
 *
186
 *
188
 * @param entry TLB Entry index.
187
 * @param entry TLB Entry index.
189
 *
188
 *
190
 * @return Current value of specified IMMU TLB Data Access Register.
189
 * @return Current value of specified IMMU TLB Data Access Register.
191
 */
190
 */
192
static inline uint64_t itlb_data_access_read(index_t entry)
191
static inline uint64_t itlb_data_access_read(index_t entry)
193
{
192
{
194
    tlb_data_access_addr_t reg;
193
    tlb_data_access_addr_t reg;
195
   
194
   
196
    reg.value = 0;
195
    reg.value = 0;
197
    reg.tlb_entry = entry;
196
    reg.tlb_entry = entry;
198
    return asi_u64_read(ASI_ITLB_DATA_ACCESS_REG, reg.value);
197
    return asi_u64_read(ASI_ITLB_DATA_ACCESS_REG, reg.value);
199
}
198
}
200
 
199
 
201
/** Write IMMU TLB Data Access Register.
200
/** Write IMMU TLB Data Access Register.
202
 *
201
 *
203
 * @param entry TLB Entry index.
202
 * @param entry TLB Entry index.
204
 * @param value Value to be written.
203
 * @param value Value to be written.
205
 */
204
 */
206
static inline void itlb_data_access_write(index_t entry, uint64_t value)
205
static inline void itlb_data_access_write(index_t entry, uint64_t value)
207
{
206
{
208
    tlb_data_access_addr_t reg;
207
    tlb_data_access_addr_t reg;
209
   
208
   
210
    reg.value = 0;
209
    reg.value = 0;
211
    reg.tlb_entry = entry;
210
    reg.tlb_entry = entry;
212
    asi_u64_write(ASI_ITLB_DATA_ACCESS_REG, reg.value, value);
211
    asi_u64_write(ASI_ITLB_DATA_ACCESS_REG, reg.value, value);
213
    flush();
212
    flush();
214
}
213
}
215
 
214
 
216
/** Read DMMU TLB Data Access Register.
215
/** Read DMMU TLB Data Access Register.
217
 *
216
 *
218
 * @param entry TLB Entry index.
217
 * @param entry TLB Entry index.
219
 *
218
 *
220
 * @return Current value of specified DMMU TLB Data Access Register.
219
 * @return Current value of specified DMMU TLB Data Access Register.
221
 */
220
 */
222
static inline uint64_t dtlb_data_access_read(index_t entry)
221
static inline uint64_t dtlb_data_access_read(index_t entry)
223
{
222
{
224
    tlb_data_access_addr_t reg;
223
    tlb_data_access_addr_t reg;
225
   
224
   
226
    reg.value = 0;
225
    reg.value = 0;
227
    reg.tlb_entry = entry;
226
    reg.tlb_entry = entry;
228
    return asi_u64_read(ASI_DTLB_DATA_ACCESS_REG, reg.value);
227
    return asi_u64_read(ASI_DTLB_DATA_ACCESS_REG, reg.value);
229
}
228
}
230
 
229
 
231
/** Write DMMU TLB Data Access Register.
230
/** Write DMMU TLB Data Access Register.
232
 *
231
 *
233
 * @param entry TLB Entry index.
232
 * @param entry TLB Entry index.
234
 * @param value Value to be written.
233
 * @param value Value to be written.
235
 */
234
 */
236
static inline void dtlb_data_access_write(index_t entry, uint64_t value)
235
static inline void dtlb_data_access_write(index_t entry, uint64_t value)
237
{
236
{
238
    tlb_data_access_addr_t reg;
237
    tlb_data_access_addr_t reg;
239
   
238
   
240
    reg.value = 0;
239
    reg.value = 0;
241
    reg.tlb_entry = entry;
240
    reg.tlb_entry = entry;
242
    asi_u64_write(ASI_DTLB_DATA_ACCESS_REG, reg.value, value);
241
    asi_u64_write(ASI_DTLB_DATA_ACCESS_REG, reg.value, value);
243
    membar();
242
    membar();
244
}
243
}
245
 
244
 
246
/** Read IMMU TLB Tag Read Register.
245
/** Read IMMU TLB Tag Read Register.
247
 *
246
 *
248
 * @param entry TLB Entry index.
247
 * @param entry TLB Entry index.
249
 *
248
 *
250
 * @return Current value of specified IMMU TLB Tag Read Register.
249
 * @return Current value of specified IMMU TLB Tag Read Register.
251
 */
250
 */
252
static inline uint64_t itlb_tag_read_read(index_t entry)
251
static inline uint64_t itlb_tag_read_read(index_t entry)
253
{
252
{
254
    tlb_tag_read_addr_t tag;
253
    tlb_tag_read_addr_t tag;
255
 
254
 
256
    tag.value = 0;
255
    tag.value = 0;
257
    tag.tlb_entry = entry;
256
    tag.tlb_entry = entry;
258
    return asi_u64_read(ASI_ITLB_TAG_READ_REG, tag.value);
257
    return asi_u64_read(ASI_ITLB_TAG_READ_REG, tag.value);
259
}
258
}
260
 
259
 
261
/** Read DMMU TLB Tag Read Register.
260
/** Read DMMU TLB Tag Read Register.
262
 *
261
 *
263
 * @param entry TLB Entry index.
262
 * @param entry TLB Entry index.
264
 *
263
 *
265
 * @return Current value of specified DMMU TLB Tag Read Register.
264
 * @return Current value of specified DMMU TLB Tag Read Register.
266
 */
265
 */
267
static inline uint64_t dtlb_tag_read_read(index_t entry)
266
static inline uint64_t dtlb_tag_read_read(index_t entry)
268
{
267
{
269
    tlb_tag_read_addr_t tag;
268
    tlb_tag_read_addr_t tag;
270
 
269
 
271
    tag.value = 0;
270
    tag.value = 0;
272
    tag.tlb_entry = entry;
271
    tag.tlb_entry = entry;
273
    return asi_u64_read(ASI_DTLB_TAG_READ_REG, tag.value);
272
    return asi_u64_read(ASI_DTLB_TAG_READ_REG, tag.value);
274
}
273
}
275
 
274
 
276
/** Write IMMU TLB Tag Access Register.
275
/** Write IMMU TLB Tag Access Register.
277
 *
276
 *
278
 * @param v Value to be written.
277
 * @param v Value to be written.
279
 */
278
 */
280
static inline void itlb_tag_access_write(uint64_t v)
279
static inline void itlb_tag_access_write(uint64_t v)
281
{
280
{
282
    asi_u64_write(ASI_IMMU, VA_IMMU_TAG_ACCESS, v);
281
    asi_u64_write(ASI_IMMU, VA_IMMU_TAG_ACCESS, v);
283
    flush();
282
    flush();
284
}
283
}
285
 
284
 
286
/** Read IMMU TLB Tag Access Register.
285
/** Read IMMU TLB Tag Access Register.
287
 *
286
 *
288
 * @return Current value of IMMU TLB Tag Access Register.
287
 * @return Current value of IMMU TLB Tag Access Register.
289
 */
288
 */
290
static inline uint64_t itlb_tag_access_read(void)
289
static inline uint64_t itlb_tag_access_read(void)
291
{
290
{
292
    return asi_u64_read(ASI_IMMU, VA_IMMU_TAG_ACCESS);
291
    return asi_u64_read(ASI_IMMU, VA_IMMU_TAG_ACCESS);
293
}
292
}
294
 
293
 
295
/** Write DMMU TLB Tag Access Register.
294
/** Write DMMU TLB Tag Access Register.
296
 *
295
 *
297
 * @param v Value to be written.
296
 * @param v Value to be written.
298
 */
297
 */
299
static inline void dtlb_tag_access_write(uint64_t v)
298
static inline void dtlb_tag_access_write(uint64_t v)
300
{
299
{
301
    asi_u64_write(ASI_DMMU, VA_DMMU_TAG_ACCESS, v);
300
    asi_u64_write(ASI_DMMU, VA_DMMU_TAG_ACCESS, v);
302
    membar();
301
    membar();
303
}
302
}
304
 
303
 
305
/** Read DMMU TLB Tag Access Register.
304
/** Read DMMU TLB Tag Access Register.
306
 *
305
 *
307
 * @return Current value of DMMU TLB Tag Access Register.
306
 * @return Current value of DMMU TLB Tag Access Register.
308
 */
307
 */
309
static inline uint64_t dtlb_tag_access_read(void)
308
static inline uint64_t dtlb_tag_access_read(void)
310
{
309
{
311
    return asi_u64_read(ASI_DMMU, VA_DMMU_TAG_ACCESS);
310
    return asi_u64_read(ASI_DMMU, VA_DMMU_TAG_ACCESS);
312
}
311
}
313
 
312
 
314
 
313
 
315
/** Write IMMU TLB Data in Register.
314
/** Write IMMU TLB Data in Register.
316
 *
315
 *
317
 * @param v Value to be written.
316
 * @param v Value to be written.
318
 */
317
 */
319
static inline void itlb_data_in_write(uint64_t v)
318
static inline void itlb_data_in_write(uint64_t v)
320
{
319
{
321
    asi_u64_write(ASI_ITLB_DATA_IN_REG, 0, v);
320
    asi_u64_write(ASI_ITLB_DATA_IN_REG, 0, v);
322
    flush();
321
    flush();
323
}
322
}
324
 
323
 
325
/** Write DMMU TLB Data in Register.
324
/** Write DMMU TLB Data in Register.
326
 *
325
 *
327
 * @param v Value to be written.
326
 * @param v Value to be written.
328
 */
327
 */
329
static inline void dtlb_data_in_write(uint64_t v)
328
static inline void dtlb_data_in_write(uint64_t v)
330
{
329
{
331
    asi_u64_write(ASI_DTLB_DATA_IN_REG, 0, v);
330
    asi_u64_write(ASI_DTLB_DATA_IN_REG, 0, v);
332
    membar();
331
    membar();
333
}
332
}
334
 
333
 
335
/** Read ITLB Synchronous Fault Status Register.
334
/** Read ITLB Synchronous Fault Status Register.
336
 *
335
 *
337
 * @return Current content of I-SFSR register.
336
 * @return Current content of I-SFSR register.
338
 */
337
 */
339
static inline uint64_t itlb_sfsr_read(void)
338
static inline uint64_t itlb_sfsr_read(void)
340
{
339
{
341
    return asi_u64_read(ASI_IMMU, VA_IMMU_SFSR);
340
    return asi_u64_read(ASI_IMMU, VA_IMMU_SFSR);
342
}
341
}
343
 
342
 
344
/** Write ITLB Synchronous Fault Status Register.
343
/** Write ITLB Synchronous Fault Status Register.
345
 *
344
 *
346
 * @param v New value of I-SFSR register.
345
 * @param v New value of I-SFSR register.
347
 */
346
 */
348
static inline void itlb_sfsr_write(uint64_t v)
347
static inline void itlb_sfsr_write(uint64_t v)
349
{
348
{
350
    asi_u64_write(ASI_IMMU, VA_IMMU_SFSR, v);
349
    asi_u64_write(ASI_IMMU, VA_IMMU_SFSR, v);
351
    flush();
350
    flush();
352
}
351
}
353
 
352
 
354
/** Read DTLB Synchronous Fault Status Register.
353
/** Read DTLB Synchronous Fault Status Register.
355
 *
354
 *
356
 * @return Current content of D-SFSR register.
355
 * @return Current content of D-SFSR register.
357
 */
356
 */
358
static inline uint64_t dtlb_sfsr_read(void)
357
static inline uint64_t dtlb_sfsr_read(void)
359
{
358
{
360
    return asi_u64_read(ASI_DMMU, VA_DMMU_SFSR);
359
    return asi_u64_read(ASI_DMMU, VA_DMMU_SFSR);
361
}
360
}
362
 
361
 
363
/** Write DTLB Synchronous Fault Status Register.
362
/** Write DTLB Synchronous Fault Status Register.
364
 *
363
 *
365
 * @param v New value of D-SFSR register.
364
 * @param v New value of D-SFSR register.
366
 */
365
 */
367
static inline void dtlb_sfsr_write(uint64_t v)
366
static inline void dtlb_sfsr_write(uint64_t v)
368
{
367
{
369
    asi_u64_write(ASI_DMMU, VA_DMMU_SFSR, v);
368
    asi_u64_write(ASI_DMMU, VA_DMMU_SFSR, v);
370
    membar();
369
    membar();
371
}
370
}
372
 
371
 
373
/** Read DTLB Synchronous Fault Address Register.
372
/** Read DTLB Synchronous Fault Address Register.
374
 *
373
 *
375
 * @return Current content of D-SFAR register.
374
 * @return Current content of D-SFAR register.
376
 */
375
 */
377
static inline uint64_t dtlb_sfar_read(void)
376
static inline uint64_t dtlb_sfar_read(void)
378
{
377
{
379
    return asi_u64_read(ASI_DMMU, VA_DMMU_SFAR);
378
    return asi_u64_read(ASI_DMMU, VA_DMMU_SFAR);
380
}
379
}
381
 
380
 
382
/** Perform IMMU TLB Demap Operation.
381
/** Perform IMMU TLB Demap Operation.
383
 *
382
 *
384
 * @param type Selects between context and page demap.
383
 * @param type Selects between context and page demap.
385
 * @param context_encoding Specifies which Context register has Context ID for
384
 * @param context_encoding Specifies which Context register has Context ID for
386
 *  demap.
385
 *  demap.
387
 * @param page Address which is on the page to be demapped.
386
 * @param page Address which is on the page to be demapped.
388
 */
387
 */
389
static inline void itlb_demap(int type, int context_encoding, uintptr_t page)
388
static inline void itlb_demap(int type, int context_encoding, uintptr_t page)
390
{
389
{
391
    tlb_demap_addr_t da;
390
    tlb_demap_addr_t da;
392
    page_address_t pg;
391
    page_address_t pg;
393
   
392
   
394
    da.value = 0;
393
    da.value = 0;
395
    pg.address = page;
394
    pg.address = page;
396
   
395
   
397
    da.type = type;
396
    da.type = type;
398
    da.context = context_encoding;
397
    da.context = context_encoding;
399
    da.vpn = pg.vpn;
398
    da.vpn = pg.vpn;
400
   
399
   
401
    asi_u64_write(ASI_IMMU_DEMAP, da.value, 0); /* da.value is the
400
    asi_u64_write(ASI_IMMU_DEMAP, da.value, 0); /* da.value is the
402
                             * address within the
401
                             * address within the
403
                             * ASI */
402
                             * ASI */
404
    flush();
403
    flush();
405
}
404
}
406
 
405
 
407
/** Perform DMMU TLB Demap Operation.
406
/** Perform DMMU TLB Demap Operation.
408
 *
407
 *
409
 * @param type Selects between context and page demap.
408
 * @param type Selects between context and page demap.
410
 * @param context_encoding Specifies which Context register has Context ID for
409
 * @param context_encoding Specifies which Context register has Context ID for
411
 *   demap.
410
 *   demap.
412
 * @param page Address which is on the page to be demapped.
411
 * @param page Address which is on the page to be demapped.
413
 */
412
 */
414
static inline void dtlb_demap(int type, int context_encoding, uintptr_t page)
413
static inline void dtlb_demap(int type, int context_encoding, uintptr_t page)
415
{
414
{
416
    tlb_demap_addr_t da;
415
    tlb_demap_addr_t da;
417
    page_address_t pg;
416
    page_address_t pg;
418
   
417
   
419
    da.value = 0;
418
    da.value = 0;
420
    pg.address = page;
419
    pg.address = page;
421
   
420
   
422
    da.type = type;
421
    da.type = type;
423
    da.context = context_encoding;
422
    da.context = context_encoding;
424
    da.vpn = pg.vpn;
423
    da.vpn = pg.vpn;
425
   
424
   
426
    asi_u64_write(ASI_DMMU_DEMAP, da.value, 0); /* da.value is the
425
    asi_u64_write(ASI_DMMU_DEMAP, da.value, 0); /* da.value is the
427
                             * address within the
426
                             * address within the
428
                             * ASI */
427
                             * ASI */
429
    membar();
428
    membar();
430
}
429
}
431
 
430
 
432
extern void fast_instruction_access_mmu_miss(int n, istate_t *istate);
431
extern void fast_instruction_access_mmu_miss(int n, istate_t *istate);
433
extern void fast_data_access_mmu_miss(int n, istate_t *istate);
432
extern void fast_data_access_mmu_miss(int n, istate_t *istate);
434
extern void fast_data_access_protection(int n, istate_t *istate);
433
extern void fast_data_access_protection(int n, istate_t *istate);
435
 
434
 
436
extern void dtlb_insert_mapping(uintptr_t page, uintptr_t frame, int pagesize, bool locked, bool cacheable);
435
extern void dtlb_insert_mapping(uintptr_t page, uintptr_t frame, int pagesize, bool locked, bool cacheable);
437
 
436
 
438
extern void dump_sfsr_and_sfar(void);
437
extern void dump_sfsr_and_sfar(void);
439
 
438
 
440
#endif /* !def __ASM__ */
439
#endif /* !def __ASM__ */
441
 
440
 
442
#endif
441
#endif
443
 
442
 
444
/** @}
443
/** @}
445
 */
444
 */
446
 
445