Subversion Repositories HelenOS

Rev

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

Rev 3862 Rev 4129
1
/*
1
/*
2
 * Copyright (c) 2006 Jakub Jermar
2
 * Copyright (c) 2006 Jakub Jermar
3
 * Copyright (c) 2009 Pavel Rimsky
3
 * Copyright (c) 2009 Pavel Rimsky
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
/** @addtogroup sparc64mm
30
/** @addtogroup sparc64mm
31
 * @{
31
 * @{
32
 */
32
 */
33
/** @file
33
/** @file
34
 */
34
 */
35
 
35
 
36
/* SUN4V-OK */
-
 
37
 
-
 
38
#include <arch/mm/as.h>
36
#include <arch/mm/as.h>
39
#include <arch/mm/pagesize.h>
37
#include <arch/mm/pagesize.h>
40
#include <arch/mm/tlb.h>
38
#include <arch/mm/tlb.h>
41
#include <genarch/mm/page_ht.h>
39
#include <genarch/mm/page_ht.h>
42
#include <genarch/mm/asid_fifo.h>
40
#include <genarch/mm/asid_fifo.h>
43
#include <debug.h>
41
#include <debug.h>
44
#include <config.h>
42
#include <config.h>
45
#include <arch/sun4v/hypercall.h>
43
#include <arch/sun4v/hypercall.h>
46
 
44
 
47
#ifdef CONFIG_TSB
45
#ifdef CONFIG_TSB
48
#include <arch/mm/tsb.h>
46
#include <arch/mm/tsb.h>
49
#include <arch/memstr.h>
47
#include <arch/memstr.h>
50
#include <arch/asm.h>
48
#include <arch/asm.h>
51
#include <mm/frame.h>
49
#include <mm/frame.h>
52
#include <bitops.h>
50
#include <bitops.h>
53
#include <macros.h>
51
#include <macros.h>
54
#endif /* CONFIG_TSB */
52
#endif /* CONFIG_TSB */
55
 
53
 
56
/** Architecture dependent address space init. */
54
/** Architecture dependent address space init. */
57
void as_arch_init(void)
55
void as_arch_init(void)
58
{
56
{
59
    if (config.cpu_active == 1) {
57
    if (config.cpu_active == 1) {
60
        as_operations = &as_ht_operations;
58
        as_operations = &as_ht_operations;
61
        asid_fifo_init();
59
        asid_fifo_init();
62
    }
60
    }
63
}
61
}
64
 
62
 
65
int as_constructor_arch(as_t *as, int flags)
63
int as_constructor_arch(as_t *as, int flags)
66
{
64
{
67
#ifdef CONFIG_TSB
65
#ifdef CONFIG_TSB
68
    int order = fnzb32(
66
    int order = fnzb32(
69
        (TSB_ENTRY_COUNT * sizeof(tsb_entry_t)) >> FRAME_WIDTH);
67
        (TSB_ENTRY_COUNT * sizeof(tsb_entry_t)) >> FRAME_WIDTH);
70
 
68
 
71
    uintptr_t tsb = (uintptr_t) frame_alloc(order, flags | FRAME_KA);
69
    uintptr_t tsb = (uintptr_t) frame_alloc(order, flags | FRAME_KA);
72
 
70
 
73
    if (!tsb)
71
    if (!tsb)
74
        return -1;
72
        return -1;
75
 
73
 
76
    as->arch.tsb_description.page_size = PAGESIZE_8K;
74
    as->arch.tsb_description.page_size = PAGESIZE_8K;
77
    as->arch.tsb_description.associativity = 1;
75
    as->arch.tsb_description.associativity = 1;
78
    as->arch.tsb_description.num_ttes = TSB_ENTRY_COUNT;
76
    as->arch.tsb_description.num_ttes = TSB_ENTRY_COUNT;
79
    as->arch.tsb_description.pgsize_mask = 1 << PAGESIZE_8K;
77
    as->arch.tsb_description.pgsize_mask = 1 << PAGESIZE_8K;
80
    as->arch.tsb_description.tsb_base = tsb;
78
    as->arch.tsb_description.tsb_base = tsb;
81
    as->arch.tsb_description.reserved = 0;
79
    as->arch.tsb_description.reserved = 0;
82
 
80
 
83
    memsetb((void *) as->arch.tsb_description.tsb_base,
81
    memsetb((void *) as->arch.tsb_description.tsb_base,
84
        TSB_ENTRY_COUNT * sizeof(tsb_entry_t), 0);
82
        TSB_ENTRY_COUNT * sizeof(tsb_entry_t), 0);
85
#endif
83
#endif
86
    return 0;
84
    return 0;
87
}
85
}
88
 
86
 
89
int as_destructor_arch(as_t *as)
87
int as_destructor_arch(as_t *as)
90
{
88
{
91
#ifdef CONFIG_TSB
89
#ifdef CONFIG_TSB
92
    count_t cnt = (TSB_ENTRY_COUNT * sizeof(tsb_entry_t)) >> FRAME_WIDTH;
90
    count_t cnt = (TSB_ENTRY_COUNT * sizeof(tsb_entry_t)) >> FRAME_WIDTH;
93
    frame_free(KA2PA((uintptr_t) as->arch.tsb_description.tsb_base));
91
    frame_free(KA2PA((uintptr_t) as->arch.tsb_description.tsb_base));
94
    return cnt;
92
    return cnt;
95
#else
93
#else
96
    return 0;
94
    return 0;
97
#endif
95
#endif
98
}
96
}
99
 
97
 
100
int as_create_arch(as_t *as, int flags)
98
int as_create_arch(as_t *as, int flags)
101
{
99
{
102
#ifdef CONFIG_TSB
100
#ifdef CONFIG_TSB
103
    tsb_invalidate(as, 0, (count_t) -1);
101
    tsb_invalidate(as, 0, (count_t) -1);
104
    as->arch.tsb_description.context = as->asid;
102
    as->arch.tsb_description.context = as->asid;
105
#endif
103
#endif
106
    return 0;
104
    return 0;
107
}
105
}
108
 
106
 
109
/** Perform sparc64-specific tasks when an address space becomes active on the
107
/** Perform sparc64-specific tasks when an address space becomes active on the
110
 * processor.
108
 * processor.
111
 *
109
 *
112
 * Install ASID and map TSBs.
110
 * Install ASID and map TSBs.
113
 *
111
 *
114
 * @param as Address space.
112
 * @param as Address space.
115
 */
113
 */
116
void as_install_arch(as_t *as)
114
void as_install_arch(as_t *as)
117
{
115
{
118
    mmu_secondary_context_write(as->asid);
116
    mmu_secondary_context_write(as->asid);
119
 
117
 
120
#ifdef CONFIG_TSB   
118
#ifdef CONFIG_TSB   
121
    uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
119
    uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
122
 
120
 
123
    ASSERT(as->arch.tsb_description.tsb_base);
121
    ASSERT(as->arch.tsb_description.tsb_base);
124
    uintptr_t tsb = as->arch.tsb_description.tsb_base;
122
    uintptr_t tsb = as->arch.tsb_description.tsb_base;
125
       
123
       
126
    if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
124
    if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
127
        /*
125
        /*
128
         * TSBs were allocated from memory not covered
126
         * TSBs were allocated from memory not covered
129
         * by the locked 4M kernel DTLB entry. We need
127
         * by the locked 4M kernel DTLB entry. We need
130
         * to map both TSBs explicitly.
128
         * to map both TSBs explicitly.
131
         */
129
         */
132
        mmu_demap_page(tsb, 0, MMU_FLAG_DTLB);
130
        mmu_demap_page(tsb, 0, MMU_FLAG_DTLB);
133
        mmu_map_perm_addr(
131
        mmu_map_perm_addr(
134
            tsb, KA2PA(tsb), true, true, false, true,
132
            tsb, KA2PA(tsb), true, true, false, true,
135
            PAGESIZE_64K, MMU_FLAG_DTLB);
133
            PAGESIZE_64K, MMU_FLAG_DTLB);
136
    }
134
    }
137
 
135
 
138
    __hypercall_fast2(MMU_TSB_CTX0, 1, as->arch.tsb_description.tsb_base);
136
    __hypercall_fast2(MMU_TSB_CTX0, 1, as->arch.tsb_description.tsb_base);
139
   
137
   
140
#endif
138
#endif
141
}
139
}
142
 
140
 
143
/** Perform sparc64-specific tasks when an address space is removed from the
141
/** Perform sparc64-specific tasks when an address space is removed from the
144
 * processor.
142
 * processor.
145
 *
143
 *
146
 * Demap TSBs.
144
 * Demap TSBs.
147
 *
145
 *
148
 * @param as Address space.
146
 * @param as Address space.
149
 */
147
 */
150
void as_deinstall_arch(as_t *as)
148
void as_deinstall_arch(as_t *as)
151
{
149
{
152
    /*
150
    /*
153
     * Note that we don't and may not lock the address space. That's ok
151
     * Note that we don't and may not lock the address space. That's ok
154
     * since we only read members that are currently read-only.
152
     * since we only read members that are currently read-only.
155
     *
153
     *
156
     * Moreover, the as->asid is protected by asidlock, which is being held.
154
     * Moreover, the as->asid is protected by asidlock, which is being held.
157
     */
155
     */
158
#ifdef CONFIG_TSB
156
#ifdef CONFIG_TSB
159
    uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
157
    uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
160
 
158
 
161
    ASSERT(as->arch.tsb_description.tsb_base);
159
    ASSERT(as->arch.tsb_description.tsb_base);
162
 
160
 
163
    uintptr_t tsb = as->arch.tsb_description.tsb_base;
161
    uintptr_t tsb = as->arch.tsb_description.tsb_base;
164
       
162
       
165
    if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
163
    if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
166
        /*
164
        /*
167
         * TSBs were allocated from memory not covered
165
         * TSBs were allocated from memory not covered
168
         * by the locked 4M kernel DTLB entry. We need
166
         * by the locked 4M kernel DTLB entry. We need
169
         * to demap the entry installed by as_install_arch().
167
         * to demap the entry installed by as_install_arch().
170
         */
168
         */
171
        mmu_demap_page(tsb, 0, MMU_FLAG_DTLB);
169
        mmu_demap_page(tsb, 0, MMU_FLAG_DTLB);
172
    }
170
    }
173
#endif
171
#endif
174
}
172
}
175
 
173
 
176
/** @}
174
/** @}
177
 */
175
 */
178
 
176