source: mainline/kernel/arch/sparc64/src/sun4u/sparc64.c@ 08e103d4

Last change on this file since 08e103d4 was 08e103d4, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Use clearer naming for string length functions

This and the following commit change the names of functions, as well as
their documentation, to use unambiguous terms "bytes" and "code points"
instead of ambiguous terms "size", "length", and "characters".

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