Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
684 jermar 1
/*
2071 jermar 2
 * Copyright (c) 2006 Jakub Jermar
3
 * Copyright (c) 2006 Jakub Vana
684 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
 
3940 decky 30
/** @addtogroup ia64mm
1702 cejka 31
 * @{
32
 */
33
/** @file
34
 */
35
 
684 jermar 36
#include <arch/mm/page.h>
747 jermar 37
#include <genarch/mm/page_ht.h>
38
#include <mm/asid.h>
749 jermar 39
#include <arch/mm/asid.h>
1210 vana 40
#include <arch/mm/vhpt.h>
716 vana 41
#include <arch/types.h>
728 vana 42
#include <print.h>
684 jermar 43
#include <mm/page.h>
747 jermar 44
#include <mm/frame.h>
684 jermar 45
#include <config.h>
46
#include <panic.h>
746 jermar 47
#include <arch/asm.h>
747 jermar 48
#include <arch/barrier.h>
748 jermar 49
#include <memstr.h>
3578 vana 50
#include <align.h>
3940 decky 51
#include <ddi/ddi.h>
684 jermar 52
 
3940 decky 53
/** Physical memory area for devices. */
54
static parea_t dev_area;
55
 
792 jermar 56
static void set_environment(void);
749 jermar 57
 
58
/** Initialize ia64 virtual address translation subsystem. */
59
void page_arch_init(void)
60
{
793 jermar 61
    page_mapping_operations = &ht_mapping_operations;
749 jermar 62
    pk_disable();
792 jermar 63
    set_environment();
749 jermar 64
}
65
 
747 jermar 66
/** Initialize VHPT and region registers. */
792 jermar 67
void set_environment(void)
716 vana 68
{
747 jermar 69
    region_register rr;
70
    pta_register pta;  
71
    int i;
1210 vana 72
#ifdef CONFIG_VHPT  
1780 jermar 73
    uintptr_t vhpt_base;
1210 vana 74
#endif
869 vana 75
 
747 jermar 76
    /*
77
     * First set up kernel region register.
901 jermar 78
     * This is redundant (see start.S) but we keep it here just for sure.
747 jermar 79
     */
80
    rr.word = rr_read(VRN_KERNEL);
81
    rr.map.ve = 0;                  /* disable VHPT walker */
82
    rr.map.ps = PAGE_WIDTH;
901 jermar 83
    rr.map.rid = ASID2RID(ASID_KERNEL, VRN_KERNEL);
747 jermar 84
    rr_write(VRN_KERNEL, rr.word);
85
    srlz_i();
86
    srlz_d();
901 jermar 87
 
747 jermar 88
    /*
902 jermar 89
     * And setup the rest of region register.
747 jermar 90
     */
91
    for(i = 0; i < REGION_REGISTERS; i++) {
92
        /* skip kernel rr */
93
        if (i == VRN_KERNEL)
94
            continue;
728 vana 95
 
904 jermar 96
        rr.word = rr_read(i);
748 jermar 97
        rr.map.ve = 0;      /* disable VHPT walker */
902 jermar 98
        rr.map.rid = RID_KERNEL;
99
        rr.map.ps = PAGE_WIDTH;
747 jermar 100
        rr_write(i, rr.word);
101
        srlz_i();
102
        srlz_d();
103
    }
726 jermar 104
 
1210 vana 105
#ifdef CONFIG_VHPT  
106
    vhpt_base = vhpt_set_up();
107
#endif
715 vana 108
    /*
747 jermar 109
     * Set up PTA register.
110
     */
111
    pta.word = pta_read();
1210 vana 112
#ifndef CONFIG_VHPT
747 jermar 113
    pta.map.ve = 0;                   /* disable VHPT walker */
1210 vana 114
    pta.map.base = 0 >> PTA_BASE_SHIFT;
115
#else
116
    pta.map.ve = 1;                   /* enable VHPT walker */
117
    pta.map.base = vhpt_base >> PTA_BASE_SHIFT;
118
#endif
747 jermar 119
    pta.map.vf = 1;                   /* large entry format */
120
    pta.map.size = VHPT_WIDTH;
121
    pta_write(pta.word);
122
    srlz_i();
123
    srlz_d();
124
}
728 vana 125
 
748 jermar 126
/** Calculate address of collision chain from VPN and ASID.
127
 *
749 jermar 128
 * Interrupts must be disabled.
748 jermar 129
 *
3766 jermar 130
 * @param page      Address of virtual page including VRN bits.
131
 * @param asid      Address space identifier.
748 jermar 132
 *
3766 jermar 133
 * @return      VHPT entry address.
748 jermar 134
 */
1780 jermar 135
vhpt_entry_t *vhpt_hash(uintptr_t page, asid_t asid)
748 jermar 136
{
137
    region_register rr_save, rr;
749 jermar 138
    index_t vrn;
139
    rid_t rid;
792 jermar 140
    vhpt_entry_t *v;
748 jermar 141
 
749 jermar 142
    vrn = page >> VRN_SHIFT;
143
    rid = ASID2RID(asid, vrn);
144
 
145
    rr_save.word = rr_read(vrn);
146
    if (rr_save.map.rid == rid) {
147
        /*
148
         * The RID is already in place, compute thash and return.
149
         */
792 jermar 150
        v = (vhpt_entry_t *) thash(page);
151
        return v;
749 jermar 152
    }
153
 
154
    /*
155
     * The RID must be written to some region register.
156
     * To speed things up, register indexed by vrn is used.
157
     */
748 jermar 158
    rr.word = rr_save.word;
749 jermar 159
    rr.map.rid = rid;
160
    rr_write(vrn, rr.word);
748 jermar 161
    srlz_i();
792 jermar 162
    v = (vhpt_entry_t *) thash(page);
749 jermar 163
    rr_write(vrn, rr_save.word);
748 jermar 164
    srlz_i();
165
    srlz_d();
166
 
792 jermar 167
    return v;
748 jermar 168
}
749 jermar 169
 
170
/** Compare ASID and VPN against PTE.
171
 *
172
 * Interrupts must be disabled.
173
 *
3766 jermar 174
 * @param page      Address of virtual page including VRN bits.
175
 * @param asid      Address space identifier.
749 jermar 176
 *
3766 jermar 177
 * @return      True if page and asid match the page and asid of t,
178
 *          false otherwise.
749 jermar 179
 */
1780 jermar 180
bool vhpt_compare(uintptr_t page, asid_t asid, vhpt_entry_t *v)
749 jermar 181
{
182
    region_register rr_save, rr;   
183
    index_t vrn;
184
    rid_t rid;
185
    bool match;
186
 
792 jermar 187
    ASSERT(v);
749 jermar 188
 
189
    vrn = page >> VRN_SHIFT;
190
    rid = ASID2RID(asid, vrn);
191
 
192
    rr_save.word = rr_read(vrn);
193
    if (rr_save.map.rid == rid) {
194
        /*
195
         * The RID is already in place, compare ttag with t and return.
196
         */
792 jermar 197
        return ttag(page) == v->present.tag.tag_word;
749 jermar 198
    }
199
 
200
    /*
201
     * The RID must be written to some region register.
202
     * To speed things up, register indexed by vrn is used.
203
     */
204
    rr.word = rr_save.word;
205
    rr.map.rid = rid;
206
    rr_write(vrn, rr.word);
207
    srlz_i();
792 jermar 208
    match = (ttag(page) == v->present.tag.tag_word);
749 jermar 209
    rr_write(vrn, rr_save.word);
210
    srlz_i();
211
    srlz_d();
212
 
213
    return match;      
214
}
215
 
216
/** Set up one VHPT entry.
217
 *
1708 jermar 218
 * @param v VHPT entry to be set up.
3766 jermar 219
 * @param page      Virtual address of the page mapped by the entry.
220
 * @param asid      Address space identifier of the address space to which
221
 *          page belongs.
222
 * @param frame     Physical address of the frame to wich page is mapped.
223
 * @param flags     Different flags for the mapping.
749 jermar 224
 */
3766 jermar 225
void
226
vhpt_set_record(vhpt_entry_t *v, uintptr_t page, asid_t asid, uintptr_t frame,
227
    int flags)
749 jermar 228
{
229
    region_register rr_save, rr;   
230
    index_t vrn;
231
    rid_t rid;
1780 jermar 232
    uint64_t tag;
749 jermar 233
 
792 jermar 234
    ASSERT(v);
749 jermar 235
 
236
    vrn = page >> VRN_SHIFT;
237
    rid = ASID2RID(asid, vrn);
238
 
239
    /*
240
     * Compute ttag.
241
     */
242
    rr_save.word = rr_read(vrn);
243
    rr.word = rr_save.word;
244
    rr.map.rid = rid;
245
    rr_write(vrn, rr.word);
246
    srlz_i();
247
    tag = ttag(page);
248
    rr_write(vrn, rr_save.word);
249
    srlz_i();
250
    srlz_d();
251
 
252
    /*
253
     * Clear the entry.
254
     */
792 jermar 255
    v->word[0] = 0;
256
    v->word[1] = 0;
257
    v->word[2] = 0;
258
    v->word[3] = 0;
749 jermar 259
 
792 jermar 260
    v->present.p = true;
3766 jermar 261
    v->present.ma = (flags & PAGE_CACHEABLE) ?
262
        MA_WRITEBACK : MA_UNCACHEABLE;
792 jermar 263
    v->present.a = false;   /* not accessed */
264
    v->present.d = false;   /* not dirty */
265
    v->present.pl = (flags & PAGE_USER) ? PL_USER : PL_KERNEL;
266
    v->present.ar = (flags & PAGE_WRITE) ? AR_WRITE : AR_READ;
267
    v->present.ar |= (flags & PAGE_EXEC) ? AR_EXECUTE : 0;
268
    v->present.ppn = frame >> PPN_SHIFT;
269
    v->present.ed = false;  /* exception not deffered */
270
    v->present.ps = PAGE_WIDTH;
271
    v->present.key = 0;
272
    v->present.tag.tag_word = tag;
749 jermar 273
}
1702 cejka 274
 
3777 jermar 275
uintptr_t hw_map(uintptr_t physaddr, size_t size __attribute__ ((unused)))
3578 vana 276
{
3777 jermar 277
    /* This is a dirty hack. */
278
    return PA2KA(physaddr);
3578 vana 279
}
280
 
3940 decky 281
void hw_area(void)
3908 decky 282
{
3940 decky 283
    dev_area.pbase = end_frame;
284
    dev_area.frames = SIZE2FRAMES(0x7fffffffffffffffUL - end_frame);
285
    ddi_parea_register(&dev_area);
3908 decky 286
}
287
 
1888 jermar 288
/** @}
1702 cejka 289
 */