Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
35 jermar 1
/*
747 jermar 2
 * Copyright (C) 2005 - 2006 Jakub Jermar
3
 * Copyright (C) 2006 Jakub Vana
35 jermar 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
#ifndef __ia64_PAGE_H__
31
#define __ia64_PAGE_H__
32
 
869 vana 33
#ifndef __ASM__
34
 
35
 
747 jermar 36
#include <arch/mm/frame.h>
869 vana 37
#include <arch/barrier.h>
747 jermar 38
#include <genarch/mm/page_ht.h>
749 jermar 39
#include <arch/mm/asid.h>
121 jermar 40
#include <arch/types.h>
747 jermar 41
#include <typedefs.h>
42
#include <debug.h>
35 jermar 43
 
869 vana 44
#endif
45
 
35 jermar 46
#define PAGE_SIZE   FRAME_SIZE
715 vana 47
#define PAGE_WIDTH  FRAME_WIDTH
869 vana 48
#define KERNEL_PAGE_WIDTH   26
35 jermar 49
 
50
 
869 vana 51
 
756 jermar 52
#define SET_PTL0_ADDRESS_ARCH(x)    /**< To be removed as situation permits. */
120 jermar 53
 
749 jermar 54
#define PPN_SHIFT           12
55
 
748 jermar 56
#define VRN_SHIFT           61
57
#define VRN_MASK            (7LL << VRN_SHIFT)
869 vana 58
 
59
#ifdef __ASM__
60
#define VRN_KERNEL          7
61
#else
62
#define VRN_KERNEL          7LL
63
#endif
64
 
747 jermar 65
#define REGION_REGISTERS        8
715 vana 66
 
869 vana 67
#define KA2PA(x)    ((__address) (x-(VRN_KERNEL<<VRN_SHIFT)))
68
#define PA2KA(x)    ((__address) (x+(VRN_KERNEL<<VRN_SHIFT)))
69
 
70
 
747 jermar 71
#define VHPT_WIDTH          20          /* 1M */
792 jermar 72
#define VHPT_SIZE           (1 << VHPT_WIDTH)
73
#define VHPT_BASE           0       /* Must be aligned to VHPT_SIZE */
715 vana 74
 
751 jermar 75
#define PTA_BASE_SHIFT          15
76
 
749 jermar 77
/** Memory Attributes. */
78
#define MA_WRITEBACK    0x0
79
#define MA_UNCACHEABLE  0x4
80
 
81
/** Privilege Levels. Only the most and the least privileged ones are ever used. */
82
#define PL_KERNEL   0x0
83
#define PL_USER     0x3
84
 
85
/* Access Rigths. Only certain combinations are used by the kernel. */
86
#define AR_READ     0x0
87
#define AR_EXECUTE  0x1
88
#define AR_WRITE    0x2
89
 
818 vana 90
 
91
#define VA_REGION_INDEX 61
92
 
93
#define VA_REGION(va) (va>>VA_REGION_INDEX)
94
 
869 vana 95
#ifndef __ASM__
818 vana 96
 
747 jermar 97
struct vhpt_tag_info {
98
    unsigned long long tag : 63;
99
    unsigned ti : 1;
100
} __attribute__ ((packed));
710 vana 101
 
747 jermar 102
union vhpt_tag {
103
    struct vhpt_tag_info tag_info;
104
    unsigned tag_word;
710 vana 105
};
106
 
747 jermar 107
struct vhpt_entry_present {
710 vana 108
    /* Word 0 */
747 jermar 109
    unsigned p : 1;
110
    unsigned : 1;
111
    unsigned ma : 3;
112
    unsigned a : 1;
113
    unsigned d : 1;
114
    unsigned pl : 2;
115
    unsigned ar : 3;
116
    unsigned long long ppn : 38;
117
    unsigned : 2;
118
    unsigned ed : 1;
119
    unsigned ig1 : 11;
710 vana 120
 
121
    /* Word 1 */
747 jermar 122
    unsigned : 2;
123
    unsigned ps : 6;
124
    unsigned key : 24;
125
    unsigned : 32;
710 vana 126
 
127
    /* Word 2 */
747 jermar 128
    union vhpt_tag tag;
129
 
710 vana 130
    /* Word 3 */                                                   
792 jermar 131
    __u64 ig3 : 64;
747 jermar 132
} __attribute__ ((packed));
710 vana 133
 
747 jermar 134
struct vhpt_entry_not_present {
710 vana 135
    /* Word 0 */
747 jermar 136
    unsigned p : 1;
137
    unsigned long long ig0 : 52;
138
    unsigned ig1 : 11;
710 vana 139
 
140
    /* Word 1 */
747 jermar 141
    unsigned : 2;
142
    unsigned ps : 6;
143
    unsigned long long ig2 : 56;
710 vana 144
 
747 jermar 145
    /* Word 2 */
146
    union vhpt_tag tag;
710 vana 147
 
148
    /* Word 3 */                                                   
792 jermar 149
    __u64 ig3 : 64;
747 jermar 150
} __attribute__ ((packed));
710 vana 151
 
747 jermar 152
typedef union vhpt_entry {
153
    struct vhpt_entry_present present;
154
    struct vhpt_entry_not_present not_present;
749 jermar 155
    __u64 word[4];
792 jermar 156
} vhpt_entry_t;
710 vana 157
 
819 vana 158
typedef vhpt_entry_t tlb_entry_t;
159
 
747 jermar 160
struct region_register_map {
161
    unsigned ve : 1;
162
    unsigned : 1;
163
    unsigned ps : 6;
164
    unsigned rid : 24;
165
    unsigned : 32;
166
} __attribute__ ((packed));
684 jermar 167
 
747 jermar 168
typedef union region_register {
169
    struct region_register_map map;
170
    unsigned long long word;
171
} region_register;
715 vana 172
 
747 jermar 173
struct pta_register_map {
174
    unsigned ve : 1;
175
    unsigned : 1;
176
    unsigned size : 6;
177
    unsigned vf : 1;
178
    unsigned : 6;
179
    unsigned long long base : 49;
180
} __attribute__ ((packed));
181
 
182
typedef union pta_register {
183
    struct pta_register_map map;
184
    __u64 word;
185
} pta_register;
186
 
187
/** Return Translation Hashed Entry Address.
188
 *
189
 * VRN bits are used to read RID (ASID) from one
190
 * of the eight region registers registers.
191
 *
192
 * @param va Virtual address including VRN bits.
193
 *
194
 * @return Address of the head of VHPT collision chain.
195
 */
196
static inline __u64 thash(__u64 va)
715 vana 197
{
747 jermar 198
    __u64 ret;
715 vana 199
 
747 jermar 200
    __asm__ volatile ("thash %0 = %1\n" : "=r" (ret) : "r" (va));
715 vana 201
 
747 jermar 202
    return ret;
203
}
204
 
205
/** Return Translation Hashed Entry Tag.
206
 *
207
 * VRN bits are used to read RID (ASID) from one
208
 * of the eight region registers.
209
 *
210
 * @param va Virtual address including VRN bits.
211
 *
212
 * @return The unique tag for VPN and RID in the collision chain returned by thash().
213
 */
214
static inline __u64 ttag(__u64 va)
715 vana 215
{
747 jermar 216
    __u64 ret;
715 vana 217
 
747 jermar 218
    __asm__ volatile ("ttag %0 = %1\n" : "=r" (ret) : "r" (va));
219
 
220
    return ret;
221
}
222
 
223
/** Read Region Register.
224
 *
225
 * @param i Region register index.
226
 *
227
 * @return Current contents of rr[i].
228
 */
229
static inline __u64 rr_read(index_t i)
715 vana 230
{
747 jermar 231
    __u64 ret;
232
 
748 jermar 233
    ASSERT(i < REGION_REGISTERS);
747 jermar 234
    __asm__ volatile ("mov %0 = rr[%1]\n" : "=r" (ret) : "r" (i));
235
 
236
    return ret;
237
}
715 vana 238
 
239
 
747 jermar 240
/** Write Region Register.
241
 *
242
 * @param i Region register index.
243
 * @param v Value to be written to rr[i].
244
 */
245
static inline void rr_write(index_t i, __u64 v)
715 vana 246
{
748 jermar 247
    ASSERT(i < REGION_REGISTERS);
818 vana 248
    __asm__ volatile (
249
    "mov rr[%0] = %1;;\n"
250
    :
251
    : "r" (i), "r" (v));
747 jermar 252
}
253
 
254
/** Read Page Table Register.
255
 *
256
 * @return Current value stored in PTA.
257
 */
258
static inline __u64 pta_read(void)
259
{
260
    __u64 ret;
261
 
262
    __asm__ volatile ("mov %0 = cr.pta\n" : "=r" (ret));
263
 
264
    return ret;
265
}
715 vana 266
 
747 jermar 267
/** Write Page Table Register.
268
 *
269
 * @param v New value to be stored in PTA.
270
 */
271
static inline void pta_write(__u64 v)
272
{
273
    __asm__ volatile ("mov cr.pta = %0\n" : : "r" (v));
274
}
715 vana 275
 
747 jermar 276
extern void page_arch_init(void);
277
 
792 jermar 278
extern vhpt_entry_t *vhpt_hash(__address page, asid_t asid);
279
extern bool vhpt_compare(__address page, asid_t asid, vhpt_entry_t *v);
280
extern void vhpt_set_record(vhpt_entry_t *v, __address page, asid_t asid, __address frame, int flags);
281
 
869 vana 282
 
283
static inline void pokus(void)
284
{
285
    region_register rr;
286
    rr.word=rr_read(0);
287
    srlz_d();
288
    rr_write(0,rr.word);
289
    srlz_d();
290
 
291
}
292
 
35 jermar 293
#endif
869 vana 294
 
295
#endif
296
 
297