Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
570 jermar 1
/*
2
 * Copyright (C) 2005 Jakub Jermar
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
#include <arch/mm/tlb.h>
30
#include <mm/tlb.h>
619 jermar 31
#include <arch/mm/frame.h>
32
#include <arch/mm/page.h>
33
#include <arch/mm/mmu.h>
570 jermar 34
#include <print.h>
617 jermar 35
#include <arch/types.h>
36
#include <typedefs.h>
619 jermar 37
#include <config.h>
570 jermar 38
 
619 jermar 39
/** Initialize ITLB and DTLB.
40
 *
41
 * The goal of this function is to disable MMU
42
 * so that both TLBs can be purged and new
43
 * kernel 4M locked entry can be installed.
44
 * After TLB is initialized, MMU is enabled
45
 * again.
46
 */
570 jermar 47
void tlb_arch_init(void)
48
{
619 jermar 49
    tlb_tag_access_reg_t tag;
50
    tlb_data_t data;
51
    frame_address_t fr;
52
    page_address_t pg;
53
 
54
    fr.address = config.base;
55
    pg.address = config.base;
56
 
57
    immu_disable();
58
    dmmu_disable();
59
 
60
    /*
61
     * For simplicity, we do identity mapping of first 4M of memory.
62
     * The very next change should be leaving the first 4M unmapped.
63
     */
64
    tag.value = 0;
65
    tag.vpn = pg.vpn;
66
 
67
    itlb_tag_access_write(tag.value);
68
    dtlb_tag_access_write(tag.value);
69
 
70
    data.value = 0;
71
    data.v = true;
72
    data.size = PAGESIZE_4M;
73
    data.pfn = fr.pfn;
74
    data.l = true;
75
    data.cp = 1;
76
    data.cv = 1;
77
    data.p = true;
78
    data.w = true;
79
    data.g = true;
80
 
81
    itlb_data_in_write(data.value);
82
    dtlb_data_in_write(data.value);
83
 
84
    tlb_invalidate_all();
85
 
86
    dmmu_enable();
87
    immu_enable();
570 jermar 88
}
89
 
90
/** Print contents of both TLBs. */
91
void tlb_print(void)
92
{
93
    int i;
94
    tlb_data_t d;
95
    tlb_tag_read_reg_t t;
96
 
97
    printf("I-TLB contents:\n");
98
    for (i = 0; i < ITLB_ENTRY_COUNT; i++) {
99
        d.value = itlb_data_access_read(i);
613 jermar 100
        t.value = itlb_tag_read_read(i);
570 jermar 101
 
617 jermar 102
        printf("%d: vpn=%Q, context=%d, v=%d, size=%d, nfo=%d, ie=%d, soft2=%X, diag=%X, pfn=%X, soft=%X, l=%d, cp=%d, cv=%d, e=%d, p=%d, w=%d, g=%d\n",
103
            i, t.vpn, t.context, d.v, d.size, d.nfo, d.ie, d.soft2, d.diag, d.pfn, d.soft, d.l, d.cp, d.cv, d.e, d.p, d.w, d.g);
570 jermar 104
    }
105
 
106
    printf("D-TLB contents:\n");
107
    for (i = 0; i < DTLB_ENTRY_COUNT; i++) {
108
        d.value = dtlb_data_access_read(i);
613 jermar 109
        t.value = dtlb_tag_read_read(i);
570 jermar 110
 
617 jermar 111
        printf("%d: vpn=%Q, context=%d, v=%d, size=%d, nfo=%d, ie=%d, soft2=%X, diag=%X, pfn=%X, soft=%X, l=%d, cp=%d, cv=%d, e=%d, p=%d, w=%d, g=%d\n",
112
            i, t.vpn, t.context, d.v, d.size, d.nfo, d.ie, d.soft2, d.diag, d.pfn, d.soft, d.l, d.cp, d.cv, d.e, d.p, d.w, d.g);
570 jermar 113
    }
114
 
115
}
617 jermar 116
 
117
/** Invalidate all unlocked ITLB and DTLB entries. */
118
void tlb_invalidate_all(void)
119
{
120
    int i;
121
    tlb_data_t d;
122
    tlb_tag_read_reg_t t;
123
 
124
    for (i = 0; i < ITLB_ENTRY_COUNT; i++) {
125
        d.value = itlb_data_access_read(i);
126
        if (!d.l) {
127
            t.value = itlb_tag_read_read(i);
128
            d.v = false;
129
            itlb_tag_access_write(t.value);
130
            itlb_data_access_write(i, d.value);
131
        }
132
    }
133
 
134
    for (i = 0; i < DTLB_ENTRY_COUNT; i++) {
135
        d.value = dtlb_data_access_read(i);
136
        if (!d.l) {
137
            t.value = dtlb_tag_read_read(i);
138
            d.v = false;
139
            dtlb_tag_access_write(t.value);
140
            dtlb_data_access_write(i, d.value);
141
        }
142
    }
143
 
144
}
145
 
146
/** Invalidate all ITLB and DTLB entries that belong to specified ASID (Context).
147
 *
148
 * @param asid Address Space ID.
149
 */
150
void tlb_invalidate_asid(asid_t asid)
151
{
152
    /* TODO: write asid to some Context register and encode the register in second parameter below. */
153
    itlb_demap(TLB_DEMAP_CONTEXT, TLB_DEMAP_NUCLEUS, 0);
154
    dtlb_demap(TLB_DEMAP_CONTEXT, TLB_DEMAP_NUCLEUS, 0);
155
}
156
 
157
/** Invalidate all ITLB and DLTB entries for specified page in specified address space.
158
 *
159
 * @param asid Address Space ID.
160
 * @param page Page which to sweep out from ITLB and DTLB.
161
 */
162
void tlb_invalidate_page(asid_t asid, __address page)
163
{
164
    /* TODO: write asid to some Context register and encode the register in second parameter below. */
165
    itlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, page);
166
    dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, page);
167
}