Subversion Repositories HelenOS-historic

Rev

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