Subversion Repositories HelenOS

Rev

Rev 1823 | Rev 1860 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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