Subversion Repositories HelenOS

Rev

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

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