source: mainline/kernel/arch/sparc64/src/sun4v/sparc64.c@ c5429fe

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c5429fe was c5429fe, checked in by Jakub Jermar <jakub@…>, 7 years ago

Disambiguate architecture specific doxygroups

  • Property mode set to 100644
File size: 5.3 KB
Line 
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/** @addtogroup kernel_sparc64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch.h>
36#include <arch/arch.h>
37#include <debug.h>
38#include <config.h>
39#include <macros.h>
40#include <arch/trap/trap.h>
41#include <arch/console.h>
42#include <arch/sun4v/md.h>
43#include <console/console.h>
44#include <arch/boot/boot.h>
45#include <arch/arch.h>
46#include <arch/asm.h>
47#include <arch/mm/page.h>
48#include <arch/stack.h>
49#include <interrupt.h>
50#include <genarch/ofw/ofw_tree.h>
51#include <userspace.h>
52#include <ddi/irq.h>
53#include <stdbool.h>
54#include <str.h>
55#include <arch/drivers/niagara.h>
56#include <sysinfo/sysinfo.h>
57
58static void sun4v_pre_mm_init(void);
59static void sun4v_post_mm_init(void);
60static void sun4v_post_smp_init(void);
61
62arch_ops_t sun4v_ops = {
63 .pre_mm_init = sun4v_pre_mm_init,
64 .post_mm_init = sun4v_post_mm_init,
65 .post_smp_init = sun4v_post_smp_init,
66};
67
68arch_ops_t *sparc64_ops = &sun4v_ops;
69
70memmap_t memmap;
71
72/** Perform sparc64-specific initialization before main_bsp() is called. */
73void sparc64_pre_main(bootinfo_t *bootinfo)
74{
75 /* Copy init task info. */
76 init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
77
78 size_t i;
79 for (i = 0; i < init.cnt; i++) {
80 init.tasks[i].paddr = KA2PA(bootinfo->taskmap.tasks[i].addr);
81 init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
82 str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
83 bootinfo->taskmap.tasks[i].name);
84 }
85
86 /* Copy physical memory map. */
87 memmap.total = bootinfo->memmap.total;
88 memmap.cnt = min(bootinfo->memmap.cnt, MEMMAP_MAX_RECORDS);
89 for (i = 0; i < memmap.cnt; i++) {
90 memmap.zones[i].start = bootinfo->memmap.zones[i].start;
91 memmap.zones[i].size = bootinfo->memmap.zones[i].size;
92 }
93
94 md_init();
95}
96
97/** Perform sparc64 specific initialization before mm is initialized. */
98void sun4v_pre_mm_init(void)
99{
100 if (config.cpu_active == 1) {
101 trap_init();
102 exc_arch_init();
103 }
104}
105
106/** Perform sparc64 specific initialization afterr mm is initialized. */
107void sun4v_post_mm_init(void)
108{
109 if (config.cpu_active == 1) {
110 /* Map OFW information into sysinfo */
111 ofw_sysinfo_map();
112
113 /*
114 * We have 2^11 different interrupt vectors.
115 * But we only create 128 buckets.
116 */
117 irq_init(1 << 11, 128);
118 }
119}
120
121void sun4v_post_smp_init(void)
122{
123 /* Currently the only supported platform for sparc64/sun4v is 'sun4v'. */
124 static const char *platform = "sun4v";
125
126 sysinfo_set_item_data("platform", NULL, (void *) platform,
127 str_size(platform));
128
129 niagarain_init();
130}
131
132/** Calibrate delay loop.
133 *
134 * On sparc64, we implement delay() by waiting for the TICK register to
135 * reach a pre-computed value, as opposed to performing some pre-computed
136 * amount of instructions of known duration. We set the delay_loop_const
137 * to 1 in order to neutralize the multiplication done by delay().
138 */
139void calibrate_delay_loop(void)
140{
141 CPU->delay_loop_const = 1;
142}
143
144/** Wait several microseconds.
145 *
146 * We assume that interrupts are already disabled.
147 *
148 * @param t Microseconds to wait.
149 */
150void asm_delay_loop(const uint32_t usec)
151{
152 uint64_t stop = tick_read() + (uint64_t) usec * (uint64_t)
153 CPU->arch.clock_frequency / 1000000;
154
155 while (tick_read() < stop)
156 ;
157}
158
159/** Switch to userspace. */
160void userspace(uspace_arg_t *kernel_uarg)
161{
162 (void) interrupts_disable();
163 switch_to_userspace((uintptr_t) kernel_uarg->uspace_entry,
164 ((uintptr_t) kernel_uarg->uspace_stack) +
165 kernel_uarg->uspace_stack_size -
166 (ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT) + STACK_BIAS),
167 (uintptr_t) kernel_uarg->uspace_uarg);
168
169 /* Not reached */
170 while (true)
171 ;
172}
173
174void arch_reboot(void)
175{
176 // TODO
177 while (true)
178 ;
179}
180
181/** Construct function pointer
182 *
183 * @param fptr function pointer structure
184 * @param addr function address
185 * @param caller calling function address
186 *
187 * @return address of the function pointer
188 *
189 */
190void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
191{
192 return addr;
193}
194
195void irq_initialize_arch(irq_t *irq)
196{
197 (void) irq;
198}
199
200/** @}
201 */
Note: See TracBrowser for help on using the repository browser.