Subversion Repositories HelenOS

Rev

Rev 748 | Rev 751 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 748 Rev 749
1
/*
1
/*
2
 * Copyright (C) 2006 Jakub Jermar
2
 * Copyright (C) 2006 Jakub Jermar
3
 * Copyright (C) 2006 Jakub Vana
3
 * Copyright (C) 2006 Jakub Vana
4
 * All rights reserved.
4
 * All rights reserved.
5
 *
5
 *
6
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
8
 * are met:
8
 * are met:
9
 *
9
 *
10
 * - Redistributions of source code must retain the above copyright
10
 * - Redistributions of source code must retain the above copyright
11
 *   notice, this list of conditions and the following disclaimer.
11
 *   notice, this list of conditions and the following disclaimer.
12
 * - Redistributions in binary form must reproduce the above copyright
12
 * - Redistributions in binary form must reproduce the above copyright
13
 *   notice, this list of conditions and the following disclaimer in the
13
 *   notice, this list of conditions and the following disclaimer in the
14
 *   documentation and/or other materials provided with the distribution.
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
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.
16
 *   derived from this software without specific prior written permission.
17
 *
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
24
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
27
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 */
28
 */
29
 
29
 
30
#include <arch/mm/page.h>
30
#include <arch/mm/page.h>
31
#include <genarch/mm/page_ht.h>
31
#include <genarch/mm/page_ht.h>
32
#include <mm/asid.h>
32
#include <mm/asid.h>
-
 
33
#include <arch/mm/asid.h>
33
#include <arch/types.h>
34
#include <arch/types.h>
-
 
35
#include <typedefs.h>
34
#include <print.h>
36
#include <print.h>
35
#include <mm/page.h>
37
#include <mm/page.h>
36
#include <mm/frame.h>
38
#include <mm/frame.h>
37
#include <config.h>
39
#include <config.h>
38
#include <panic.h>
40
#include <panic.h>
39
#include <arch/asm.h>
41
#include <arch/asm.h>
40
#include <arch/barrier.h>
42
#include <arch/barrier.h>
41
#include <memstr.h>
43
#include <memstr.h>
42
 
44
 
-
 
45
static void set_vhpt_environment(void);
-
 
46
 
-
 
47
/** Initialize ia64 virtual address translation subsystem. */
-
 
48
void page_arch_init(void)
-
 
49
{
-
 
50
    page_operations = &page_ht_operations;
-
 
51
    pk_disable();
-
 
52
    set_vhpt_environment();
-
 
53
}
-
 
54
 
43
/** Initialize VHPT and region registers. */
55
/** Initialize VHPT and region registers. */
44
static void set_vhpt_environment(void)
56
void set_vhpt_environment(void)
45
{
57
{
46
    region_register rr;
58
    region_register rr;
47
    pta_register pta;  
59
    pta_register pta;  
48
    int i;
60
    int i;
49
   
61
   
50
    /*
62
    /*
51
     * First set up kernel region register.
63
     * First set up kernel region register.
52
     */
64
     */
53
    rr.word = rr_read(VRN_KERNEL);
65
    rr.word = rr_read(VRN_KERNEL);
54
    rr.map.ve = 0;                  /* disable VHPT walker */
66
    rr.map.ve = 0;                  /* disable VHPT walker */
55
    rr.map.ps = PAGE_WIDTH;
67
    rr.map.ps = PAGE_WIDTH;
56
    rr.map.rid = ASID_KERNEL;
68
    rr.map.rid = ASID_KERNEL;
57
    rr_write(VRN_KERNEL, rr.word);
69
    rr_write(VRN_KERNEL, rr.word);
58
    srlz_i();
70
    srlz_i();
59
    srlz_d();
71
    srlz_d();
60
   
72
   
61
    /*
73
    /*
62
     * And invalidate the rest of region register.
74
     * And invalidate the rest of region register.
63
     */
75
     */
64
    for(i = 0; i < REGION_REGISTERS; i++) {
76
    for(i = 0; i < REGION_REGISTERS; i++) {
65
        /* skip kernel rr */
77
        /* skip kernel rr */
66
        if (i == VRN_KERNEL)
78
        if (i == VRN_KERNEL)
67
            continue;
79
            continue;
68
   
80
   
69
        rr.word == rr_read(i);
81
        rr.word == rr_read(i);
70
        rr.map.ve = 0;      /* disable VHPT walker */
82
        rr.map.ve = 0;      /* disable VHPT walker */
71
        rr.map.rid = ASID_INVALID;
83
        rr.map.rid = ASID_INVALID;
72
        rr_write(i, rr.word);
84
        rr_write(i, rr.word);
73
        srlz_i();
85
        srlz_i();
74
        srlz_d();
86
        srlz_d();
75
    }
87
    }
76
 
88
 
77
    /*
89
    /*
78
     * Allocate VHPT and invalidate all its entries.
90
     * Allocate VHPT and invalidate all its entries.
79
     */
91
     */
80
    page_ht = (pte_t *) frame_alloc(FRAME_KA, VHPT_WIDTH - FRAME_WIDTH, NULL);
92
    page_ht = (pte_t *) frame_alloc(FRAME_KA, VHPT_WIDTH - FRAME_WIDTH, NULL);
81
    memsetb((__address) page_ht, VHPT_SIZE, 0);
93
    memsetb((__address) page_ht, VHPT_SIZE, 0);
82
    ht_invalidate_all();   
94
    ht_invalidate_all();   
83
   
95
   
84
    /*
96
    /*
85
     * Set up PTA register.
97
     * Set up PTA register.
86
     */
98
     */
87
    pta.word = pta_read();
99
    pta.word = pta_read();
88
    pta.map.ve = 0;                   /* disable VHPT walker */
100
    pta.map.ve = 0;                   /* disable VHPT walker */
89
    pta.map.vf = 1;                   /* large entry format */
101
    pta.map.vf = 1;                   /* large entry format */
90
    pta.map.size = VHPT_WIDTH;
102
    pta.map.size = VHPT_WIDTH;
91
    pta.map.base = (__address) page_ht;
103
    pta.map.base = (__address) page_ht;
92
    pta_write(pta.word);
104
    pta_write(pta.word);
93
    srlz_i();
105
    srlz_i();
94
    srlz_d();
106
    srlz_d();
95
}
107
}
96
 
108
 
97
/** Initialize ia64 virtual address translation subsystem. */
-
 
98
void page_arch_init(void)
-
 
99
{
-
 
100
    page_operations = &page_ht_operations;
-
 
101
    pk_disable();
-
 
102
    set_vhpt_environment();
-
 
103
}
-
 
104
 
-
 
105
/** Calculate address of collision chain from VPN and ASID.
109
/** Calculate address of collision chain from VPN and ASID.
106
 *
110
 *
107
 * This is rather non-trivial function.
-
 
108
 * First, it has to translate ASID to RID.
-
 
109
 * This is achieved by taking VRN bits of
-
 
110
 * page into account.
-
 
111
 * Second, it must preserve the region register
-
 
112
 * it writes the RID to.
111
 * Interrupts must be disabled.
113
 *
112
 *
114
 * @param page Address of virtual page including VRN bits.
113
 * @param page Address of virtual page including VRN bits.
115
 * @param asid Address space identifier.
114
 * @param asid Address space identifier.
116
 *
115
 *
117
 * @return Head of VHPT collision chain for page and asid.
116
 * @return Head of VHPT collision chain for page and asid.
118
 */
117
 */
119
pte_t *vhpt_hash(__address page, asid_t asid)
118
pte_t *vhpt_hash(__address page, asid_t asid)
120
{
119
{
121
    region_register rr_save, rr;
120
    region_register rr_save, rr;
-
 
121
    index_t vrn;
-
 
122
    rid_t rid;
122
    pte_t *t;
123
    pte_t *t;
123
 
124
 
-
 
125
    vrn = page >> VRN_SHIFT;
-
 
126
    rid = ASID2RID(asid, vrn);
-
 
127
   
124
    rr_save.word = rr_read(VRN_WORK);
128
    rr_save.word = rr_read(vrn);
-
 
129
    if (rr_save.map.rid == rid) {
-
 
130
        /*
-
 
131
         * The RID is already in place, compute thash and return.
-
 
132
         */
-
 
133
        t = (pte_t *) thash(page);
-
 
134
        return t;
-
 
135
    }
-
 
136
   
-
 
137
    /*
-
 
138
     * The RID must be written to some region register.
-
 
139
     * To speed things up, register indexed by vrn is used.
-
 
140
     */
125
    rr.word = rr_save.word;
141
    rr.word = rr_save.word;
126
    if ((page >> VRN_SHIFT) != VRN_KERNEL)
-
 
127
        rr.map.rid = (asid * RIDS_PER_ASID) + (page >> VRN_SHIFT);
-
 
128
    else
-
 
129
        rr.map.rid = ASID_KERNEL;
142
    rr.map.rid = rid;
130
    rr_write(VRN_WORK, rr.word);
143
    rr_write(vrn, rr.word);
131
    srlz_i();
144
    srlz_i();
132
    t = (pte_t *) thash((VRN_WORK << VRN_SHIFT) | (~(VRN_MASK) & page));
145
    t = (pte_t *) thash(page);
133
    rr_write(VRN_WORK, rr_save.word);
146
    rr_write(vrn, rr_save.word);
134
    srlz_i();
147
    srlz_i();
135
    srlz_d();
148
    srlz_d();
136
 
149
 
137
    return t;
150
    return t;
138
}
151
}
-
 
152
 
-
 
153
/** Compare ASID and VPN against PTE.
-
 
154
 *
-
 
155
 * Interrupts must be disabled.
-
 
156
 *
-
 
157
 * @param page Address of virtual page including VRN bits.
-
 
158
 * @param asid Address space identifier.
-
 
159
 *
-
 
160
 * @return True if page and asid match the page and asid of t, false otherwise.
-
 
161
 */
-
 
162
bool vhpt_compare(__address page, asid_t asid, pte_t *t)
-
 
163
{
-
 
164
    region_register rr_save, rr;   
-
 
165
    index_t vrn;
-
 
166
    rid_t rid;
-
 
167
    bool match;
-
 
168
 
-
 
169
    ASSERT(t);
-
 
170
 
-
 
171
    vrn = page >> VRN_SHIFT;
-
 
172
    rid = ASID2RID(asid, vrn);
-
 
173
   
-
 
174
    rr_save.word = rr_read(vrn);
-
 
175
    if (rr_save.map.rid == rid) {
-
 
176
        /*
-
 
177
         * The RID is already in place, compare ttag with t and return.
-
 
178
         */
-
 
179
        return ttag(page) == t->present.tag.tag_word;
-
 
180
    }
-
 
181
   
-
 
182
    /*
-
 
183
     * The RID must be written to some region register.
-
 
184
     * To speed things up, register indexed by vrn is used.
-
 
185
     */
-
 
186
    rr.word = rr_save.word;
-
 
187
    rr.map.rid = rid;
-
 
188
    rr_write(vrn, rr.word);
-
 
189
    srlz_i();
-
 
190
    match = (ttag(page) == t->present.tag.tag_word);
-
 
191
    rr_write(vrn, rr_save.word);
-
 
192
    srlz_i();
-
 
193
    srlz_d();
-
 
194
 
-
 
195
    return match;      
-
 
196
}
-
 
197
 
-
 
198
/** Set up one VHPT entry.
-
 
199
 *
-
 
200
 * @param t VHPT entry to be set up.
-
 
201
 * @param page Virtual address of the page mapped by the entry.
-
 
202
 * @param asid Address space identifier of the address space to which page belongs.
-
 
203
 * @param frame Physical address of the frame to wich page is mapped.
-
 
204
 * @param flags Different flags for the mapping.
-
 
205
 */
-
 
206
void vhpt_set_record(pte_t *t, __address page, asid_t asid, __address frame, int flags)
-
 
207
{
-
 
208
    region_register rr_save, rr;   
-
 
209
    index_t vrn;
-
 
210
    rid_t rid;
-
 
211
    __u64 tag;
-
 
212
 
-
 
213
    ASSERT(t);
-
 
214
 
-
 
215
    vrn = page >> VRN_SHIFT;
-
 
216
    rid = ASID2RID(asid, vrn);
-
 
217
   
-
 
218
    /*
-
 
219
     * Compute ttag.
-
 
220
     */
-
 
221
    rr_save.word = rr_read(vrn);
-
 
222
    rr.word = rr_save.word;
-
 
223
    rr.map.rid = rid;
-
 
224
    rr_write(vrn, rr.word);
-
 
225
    srlz_i();
-
 
226
    tag = ttag(page);
-
 
227
    rr_write(vrn, rr_save.word);
-
 
228
    srlz_i();
-
 
229
    srlz_d();
-
 
230
   
-
 
231
    /*
-
 
232
     * Clear the entry.
-
 
233
     */
-
 
234
    t->word[0] = 0;
-
 
235
    t->word[1] = 0;
-
 
236
    t->word[2] = 0;
-
 
237
    t->word[3] = 0;
-
 
238
   
-
 
239
    t->present.p = true;
-
 
240
    t->present.ma = (flags & PAGE_CACHEABLE) ? MA_WRITEBACK : MA_UNCACHEABLE;
-
 
241
    t->present.a = false;   /* not accessed */
-
 
242
    t->present.d = false;   /* not dirty */
-
 
243
    t->present.pl = (flags & PAGE_USER) ? PL_USER : PL_KERNEL;
-
 
244
    t->present.ar = (flags & PAGE_WRITE) ? AR_WRITE : AR_READ;
-
 
245
    t->present.ar |= (flags & PAGE_EXEC) ? AR_EXECUTE : 0;
-
 
246
    t->present.ppn = frame >> PPN_SHIFT;
-
 
247
    t->present.ed = false;  /* exception not deffered */
-
 
248
    t->present.ps = PAGE_WIDTH;
-
 
249
    t->present.key = 0;
-
 
250
    t->present.tag.tag_word = tag;
-
 
251
    t->present.next = NULL;
-
 
252
}
139
 
253