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 |
|
---|
58 | static void sun4v_pre_mm_init(void);
|
---|
59 | static void sun4v_post_mm_init(void);
|
---|
60 | static void sun4v_post_smp_init(void);
|
---|
61 |
|
---|
62 | arch_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 |
|
---|
68 | arch_ops_t *sparc64_ops = &sun4v_ops;
|
---|
69 |
|
---|
70 | memmap_t memmap;
|
---|
71 |
|
---|
72 | /** Perform sparc64-specific initialization before main_bsp() is called. */
|
---|
73 | void 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. */
|
---|
98 | void 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. */
|
---|
107 | void 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 |
|
---|
121 | void 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 | */
|
---|
139 | void 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 | */
|
---|
150 | void 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 | uintptr_t arch_get_initial_sp(uintptr_t stack_base, uintptr_t stack_size)
|
---|
160 | {
|
---|
161 | return ALIGN_DOWN(stack_base + stack_size - STACK_WINDOW_SAVE_AREA_SIZE - STACK_ARG_SAVE_AREA_SIZE, 16) - STACK_BIAS;
|
---|
162 | }
|
---|
163 |
|
---|
164 | /** Switch to userspace. */
|
---|
165 | void userspace(uintptr_t pc, uintptr_t sp)
|
---|
166 | {
|
---|
167 | (void) interrupts_disable();
|
---|
168 | switch_to_userspace(pc, sp, 0);
|
---|
169 |
|
---|
170 | /* Not reached */
|
---|
171 | while (true)
|
---|
172 | ;
|
---|
173 | }
|
---|
174 |
|
---|
175 | void arch_reboot(void)
|
---|
176 | {
|
---|
177 | // TODO
|
---|
178 | while (true)
|
---|
179 | ;
|
---|
180 | }
|
---|
181 |
|
---|
182 | /** Construct function pointer
|
---|
183 | *
|
---|
184 | * @param fptr function pointer structure
|
---|
185 | * @param addr function address
|
---|
186 | * @param caller calling function address
|
---|
187 | *
|
---|
188 | * @return address of the function pointer
|
---|
189 | *
|
---|
190 | */
|
---|
191 | void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
|
---|
192 | {
|
---|
193 | return addr;
|
---|
194 | }
|
---|
195 |
|
---|
196 | void irq_initialize_arch(irq_t *irq)
|
---|
197 | {
|
---|
198 | (void) irq;
|
---|
199 | }
|
---|
200 |
|
---|
201 | /** @}
|
---|
202 | */
|
---|