Use `errno_t` in all uspace and kernel code.
[helenos.git] / kernel / arch / sparc64 / src / mm / sun4v / as.c
blob7c52b899983903185a4459eabc73307c1e4bfe69
1 /*
2 * Copyright (c) 2006 Jakub Jermar
3 * Copyright (c) 2009 Pavel Rimsky
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
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.
30 /** @addtogroup sparc64mm
31 * @{
33 /** @file
36 #include <arch/mm/as.h>
37 #include <arch/mm/pagesize.h>
38 #include <arch/mm/tlb.h>
39 #include <assert.h>
40 #include <genarch/mm/page_ht.h>
41 #include <genarch/mm/asid_fifo.h>
42 #include <config.h>
43 #include <arch/sun4v/hypercall.h>
45 #ifdef CONFIG_TSB
47 #include <arch/mm/tsb.h>
48 #include <arch/asm.h>
49 #include <mm/frame.h>
50 #include <bitops.h>
51 #include <macros.h>
52 #include <mem.h>
54 #endif /* CONFIG_TSB */
56 /** Architecture dependent address space init. */
57 void as_arch_init(void)
59 if (config.cpu_active == 1) {
60 as_operations = &as_ht_operations;
61 asid_fifo_init();
65 errno_t as_constructor_arch(as_t *as, unsigned int flags)
67 #ifdef CONFIG_TSB
68 uintptr_t tsb_base = frame_alloc(TSB_FRAMES, flags, TSB_SIZE - 1);
69 if (!tsb_base)
70 return ENOMEM;
72 tsb_entry_t *tsb = (tsb_entry_t *) PA2KA(tsb_base);
74 as->arch.tsb_description.page_size = PAGESIZE_8K;
75 as->arch.tsb_description.associativity = 1;
76 as->arch.tsb_description.num_ttes = TSB_ENTRY_COUNT;
77 as->arch.tsb_description.pgsize_mask = 1 << PAGESIZE_8K;
78 as->arch.tsb_description.tsb_base = tsb_base;
79 as->arch.tsb_description.reserved = 0;
80 as->arch.tsb_description.context = 0;
82 memsetb(tsb, TSB_SIZE, 0);
83 #endif
85 return EOK;
88 int as_destructor_arch(as_t *as)
90 #ifdef CONFIG_TSB
91 frame_free(as->arch.tsb_description.tsb_base, TSB_FRAMES);
93 return TSB_FRAMES;
94 #else
95 return 0;
96 #endif
99 errno_t as_create_arch(as_t *as, unsigned int flags)
101 #ifdef CONFIG_TSB
102 tsb_invalidate(as, 0, (size_t) -1);
103 #endif
105 return EOK;
108 /** Perform sparc64-specific tasks when an address space becomes active on the
109 * processor.
111 * Install ASID and map TSBs.
113 * @param as Address space.
116 void as_install_arch(as_t *as)
118 mmu_secondary_context_write(as->asid);
120 #ifdef CONFIG_TSB
121 uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
123 assert(as->arch.tsb_description.tsb_base);
124 uintptr_t tsb = PA2KA(as->arch.tsb_description.tsb_base);
126 if (!overlaps(tsb, TSB_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
128 * TSBs were allocated from memory not covered
129 * by the locked 4M kernel DTLB entry. We need
130 * to map both TSBs explicitly.
133 mmu_demap_page(tsb, 0, MMU_FLAG_DTLB);
134 dtlb_insert_mapping(tsb, KA2PA(tsb), PAGESIZE_64K, true, true);
137 __hypercall_fast2(MMU_TSB_CTXNON0, 1, KA2PA(&as->arch.tsb_description));
138 #endif
141 /** Perform sparc64-specific tasks when an address space is removed from the
142 * processor.
144 * Demap TSBs.
146 * @param as Address space.
149 void as_deinstall_arch(as_t *as)
152 * Note that we don't and may not lock the address space. That's ok
153 * since we only read members that are currently read-only.
155 * Moreover, the as->asid is protected by asidlock, which is being held.
159 #ifdef CONFIG_TSB
160 uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
162 assert(as->arch.tsb_description.tsb_base);
164 uintptr_t tsb = PA2KA(as->arch.tsb_description.tsb_base);
166 if (!overlaps(tsb, TSB_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
168 * TSBs were allocated from memory not covered
169 * by the locked 4M kernel DTLB entry. We need
170 * to demap the entry installed by as_install_arch().
173 __hypercall_fast3(MMU_UNMAP_PERM_ADDR, tsb, 0, MMU_FLAG_DTLB);
175 #endif
178 /** @}