source: mainline/kernel/arch/sparc64/src/mm/sun4v/as.c

Last change on this file was b169619, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 20 months ago

Deduplicate mem functions

There are a number of functions which are copied between
kernel, libc, and potentially boot too. mem*() functions
are first such offenders. All this duplicate code will
be moved to directory 'common'.

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[ef67bab]1/*
[df4ed85]2 * Copyright (c) 2006 Jakub Jermar
[8c2214e]3 * Copyright (c) 2009 Pavel Rimsky
[ef67bab]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
[c5429fe]30/** @addtogroup kernel_sparc64_mm
[b45c443]31 * @{
32 */
33/** @file
34 */
35
[ef67bab]36#include <arch/mm/as.h>
[8c2214e]37#include <arch/mm/pagesize.h>
[ed166f7]38#include <arch/mm/tlb.h>
[63e27ef]39#include <assert.h>
[b3f8fb7]40#include <genarch/mm/page_ht.h>
[d0a0f12]41#include <genarch/mm/asid_fifo.h>
[a9ac978]42#include <config.h>
[8c2214e]43#include <arch/sun4v/hypercall.h>
[57da95c]44
45#ifdef CONFIG_TSB
[da1bafb]46
[57da95c]47#include <arch/mm/tsb.h>
[29b2bbf]48#include <arch/asm.h>
49#include <mm/frame.h>
50#include <bitops.h>
51#include <macros.h>
[b169619]52#include <memw.h>
[da1bafb]53
[92778f2]54#endif /* CONFIG_TSB */
55
[ef67bab]56/** Architecture dependent address space init. */
57void as_arch_init(void)
58{
[a9ac978]59 if (config.cpu_active == 1) {
60 as_operations = &as_ht_operations;
61 asid_fifo_init();
62 }
[ef67bab]63}
[b45c443]64
[b7fd2a0]65errno_t as_constructor_arch(as_t *as, unsigned int flags)
[29b2bbf]66{
67#ifdef CONFIG_TSB
[482f968]68 uintptr_t tsb_base = frame_alloc(TSB_FRAMES, FRAME_LOWMEM | flags,
69 TSB_SIZE - 1);
[e08162b]70 if (!tsb_base)
[ee6f434]71 return ENOMEM;
[e08162b]72
73 tsb_entry_t *tsb = (tsb_entry_t *) PA2KA(tsb_base);
74
[ba50a34]75 as->arch.tsb_description.page_size = PAGESIZE_8K;
76 as->arch.tsb_description.associativity = 1;
77 as->arch.tsb_description.num_ttes = TSB_ENTRY_COUNT;
78 as->arch.tsb_description.pgsize_mask = 1 << PAGESIZE_8K;
[e08162b]79 as->arch.tsb_description.tsb_base = tsb_base;
[ba50a34]80 as->arch.tsb_description.reserved = 0;
81 as->arch.tsb_description.context = 0;
[a35b458]82
[e08162b]83 memsetb(tsb, TSB_SIZE, 0);
[29b2bbf]84#endif
[a35b458]85
[ee6f434]86 return EOK;
[29b2bbf]87}
88
89int as_destructor_arch(as_t *as)
90{
91#ifdef CONFIG_TSB
[e08162b]92 frame_free(as->arch.tsb_description.tsb_base, TSB_FRAMES);
[a35b458]93
[e08162b]94 return TSB_FRAMES;
[29b2bbf]95#else
96 return 0;
97#endif
98}
99
[b7fd2a0]100errno_t as_create_arch(as_t *as, unsigned int flags)
[29b2bbf]101{
102#ifdef CONFIG_TSB
[98000fb]103 tsb_invalidate(as, 0, (size_t) -1);
[29b2bbf]104#endif
[a35b458]105
[ee6f434]106 return EOK;
[29b2bbf]107}
108
[771cd22]109/** Perform sparc64-specific tasks when an address space becomes active on the
110 * processor.
[57da95c]111 *
112 * Install ASID and map TSBs.
113 *
114 * @param as Address space.
[da1bafb]115 *
[57da95c]116 */
[ed166f7]117void as_install_arch(as_t *as)
118{
[ba50a34]119 mmu_secondary_context_write(as->asid);
[a35b458]120
[da1bafb]121#ifdef CONFIG_TSB
[8c2214e]122 uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
[a35b458]123
[63e27ef]124 assert(as->arch.tsb_description.tsb_base);
[8c2214e]125 uintptr_t tsb = PA2KA(as->arch.tsb_description.tsb_base);
[a35b458]126
[e08162b]127 if (!overlaps(tsb, TSB_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
[8c2214e]128 /*
129 * TSBs were allocated from memory not covered
130 * by the locked 4M kernel DTLB entry. We need
131 * to map both TSBs explicitly.
[da1bafb]132 *
[8c2214e]133 */
134 mmu_demap_page(tsb, 0, MMU_FLAG_DTLB);
135 dtlb_insert_mapping(tsb, KA2PA(tsb), PAGESIZE_64K, true, true);
136 }
[a35b458]137
[e08162b]138 __hypercall_fast2(MMU_TSB_CTXNON0, 1, KA2PA(&as->arch.tsb_description));
[8c2214e]139#endif
[57da95c]140}
141
[771cd22]142/** Perform sparc64-specific tasks when an address space is removed from the
143 * processor.
[57da95c]144 *
145 * Demap TSBs.
146 *
147 * @param as Address space.
[da1bafb]148 *
[57da95c]149 */
150void as_deinstall_arch(as_t *as)
151{
152 /*
[879585a3]153 * 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.
155 *
156 * Moreover, the as->asid is protected by asidlock, which is being held.
[da1bafb]157 *
[57da95c]158 */
[a35b458]159
[57da95c]160#ifdef CONFIG_TSB
[29b2bbf]161 uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
[a35b458]162
[63e27ef]163 assert(as->arch.tsb_description.tsb_base);
[a35b458]164
[8c2214e]165 uintptr_t tsb = PA2KA(as->arch.tsb_description.tsb_base);
[a35b458]166
[e08162b]167 if (!overlaps(tsb, TSB_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
[29b2bbf]168 /*
169 * TSBs were allocated from memory not covered
170 * by the locked 4M kernel DTLB entry. We need
171 * to demap the entry installed by as_install_arch().
[da1bafb]172 *
[29b2bbf]173 */
[8c2214e]174 __hypercall_fast3(MMU_UNMAP_PERM_ADDR, tsb, 0, MMU_FLAG_DTLB);
[57da95c]175 }
176#endif
[ed166f7]177}
178
179/** @}
[b45c443]180 */
Note: See TracBrowser for help on using the repository browser.