[39cb79a] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2005 Jakub Jermar
|
---|
[39cb79a] | 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 |
|
---|
[c5429fe] | 29 | /** @addtogroup kernel_sparc64
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[39cb79a] | 35 | #include <arch.h>
|
---|
[36df4109] | 36 | #include <arch/arch.h>
|
---|
[65fb232] | 37 | #include <debug.h>
|
---|
[ed166f7] | 38 | #include <config.h>
|
---|
[4872160] | 39 | #include <macros.h>
|
---|
[49b6d32] | 40 | #include <arch/trap/trap.h>
|
---|
[adb2ebf8] | 41 | #include <arch/console.h>
|
---|
[b4655da] | 42 | #include <arch/sun4v/md.h>
|
---|
[41d33ac] | 43 | #include <console/console.h>
|
---|
[94d614e] | 44 | #include <arch/boot/boot.h>
|
---|
[10b890b] | 45 | #include <arch/arch.h>
|
---|
[9a5b556] | 46 | #include <arch/asm.h>
|
---|
[ed166f7] | 47 | #include <arch/mm/page.h>
|
---|
| 48 | #include <arch/stack.h>
|
---|
[3a2f8aa] | 49 | #include <interrupt.h>
|
---|
[16529d5] | 50 | #include <genarch/ofw/ofw_tree.h>
|
---|
[ed166f7] | 51 | #include <userspace.h>
|
---|
[7dcf22a] | 52 | #include <ddi/irq.h>
|
---|
[76d0981d] | 53 | #include <stdbool.h>
|
---|
[19f857a] | 54 | #include <str.h>
|
---|
[66e08d02] | 55 | #include <arch/drivers/niagara.h>
|
---|
[eff1f033] | 56 | #include <sysinfo/sysinfo.h>
|
---|
[66e08d02] | 57 |
|
---|
[7510326] | 58 | static void sun4v_pre_mm_init(void);
|
---|
| 59 | static void sun4v_post_mm_init(void);
|
---|
| 60 | static void sun4v_post_smp_init(void);
|
---|
[36df4109] | 61 |
|
---|
[7510326] | 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,
|
---|
[36df4109] | 66 | };
|
---|
| 67 |
|
---|
[7510326] | 68 | arch_ops_t *sparc64_ops = &sun4v_ops;
|
---|
[36df4109] | 69 |
|
---|
[4872160] | 70 | memmap_t memmap;
|
---|
[39cb79a] | 71 |
|
---|
[06f96234] | 72 | /** Perform sparc64-specific initialization before main_bsp() is called. */
|
---|
[36df4109] | 73 | void sparc64_pre_main(bootinfo_t *bootinfo)
|
---|
[cfa70add] | 74 | {
|
---|
[61e90dd] | 75 | /* Copy init task info. */
|
---|
[4872160] | 76 | init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
|
---|
[a35b458] | 77 |
|
---|
[4872160] | 78 | size_t i;
|
---|
| 79 | for (i = 0; i < init.cnt; i++) {
|
---|
[32817cc] | 80 | init.tasks[i].paddr = KA2PA(bootinfo->taskmap.tasks[i].addr);
|
---|
[4872160] | 81 | init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
|
---|
[f4b1535] | 82 | str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
|
---|
[4872160] | 83 | bootinfo->taskmap.tasks[i].name);
|
---|
[cfa70add] | 84 | }
|
---|
[a35b458] | 85 |
|
---|
[4872160] | 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 | }
|
---|
[a35b458] | 93 |
|
---|
[b4655da] | 94 | md_init();
|
---|
[cfa70add] | 95 | }
|
---|
| 96 |
|
---|
[771cd22] | 97 | /** Perform sparc64 specific initialization before mm is initialized. */
|
---|
[7510326] | 98 | void sun4v_pre_mm_init(void)
|
---|
[39cb79a] | 99 | {
|
---|
[cade9c1] | 100 | if (config.cpu_active == 1) {
|
---|
[a9ac978] | 101 | trap_init();
|
---|
[cade9c1] | 102 | exc_arch_init();
|
---|
| 103 | }
|
---|
[39cb79a] | 104 | }
|
---|
| 105 |
|
---|
[771cd22] | 106 | /** Perform sparc64 specific initialization afterr mm is initialized. */
|
---|
[7510326] | 107 | void sun4v_post_mm_init(void)
|
---|
[39cb79a] | 108 | {
|
---|
[0d107f31] | 109 | if (config.cpu_active == 1) {
|
---|
[de3db94a] | 110 | /* Map OFW information into sysinfo */
|
---|
| 111 | ofw_sysinfo_map();
|
---|
[a35b458] | 112 |
|
---|
[771cd22] | 113 | /*
|
---|
| 114 | * We have 2^11 different interrupt vectors.
|
---|
| 115 | * But we only create 128 buckets.
|
---|
| 116 | */
|
---|
| 117 | irq_init(1 << 11, 128);
|
---|
[0d107f31] | 118 | }
|
---|
[39cb79a] | 119 | }
|
---|
| 120 |
|
---|
[7510326] | 121 | void sun4v_post_smp_init(void)
|
---|
[39cb79a] | 122 | {
|
---|
[eff1f033] | 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 |
|
---|
[69b68d1f] | 129 | niagarain_init();
|
---|
[39cb79a] | 130 | }
|
---|
| 131 |
|
---|
[9a5b556] | 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 | */
|
---|
[39cb79a] | 139 | void calibrate_delay_loop(void)
|
---|
| 140 | {
|
---|
[9a5b556] | 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 | {
|
---|
[aeaebcc] | 152 | uint64_t stop = tick_read() + (uint64_t) usec * (uint64_t)
|
---|
[f619ec11] | 153 | CPU->arch.clock_frequency / 1000000;
|
---|
[9a5b556] | 154 |
|
---|
| 155 | while (tick_read() < stop)
|
---|
| 156 | ;
|
---|
[39cb79a] | 157 | }
|
---|
[41d33ac] | 158 |
|
---|
[3fcea34] | 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 |
|
---|
[ed166f7] | 164 | /** Switch to userspace. */
|
---|
[3fcea34] | 165 | void userspace(uintptr_t pc, uintptr_t sp)
|
---|
[ed166f7] | 166 | {
|
---|
[8688a6e] | 167 | (void) interrupts_disable();
|
---|
[3fcea34] | 168 | switch_to_userspace(pc, sp, 0);
|
---|
[a35b458] | 169 |
|
---|
[2902e1bb] | 170 | /* Not reached */
|
---|
[76d0981d] | 171 | while (true)
|
---|
[1433ecda] | 172 | ;
|
---|
[ed166f7] | 173 | }
|
---|
| 174 |
|
---|
[f74bbaf] | 175 | void arch_reboot(void)
|
---|
| 176 | {
|
---|
| 177 | // TODO
|
---|
[76d0981d] | 178 | while (true)
|
---|
[1433ecda] | 179 | ;
|
---|
[f74bbaf] | 180 | }
|
---|
| 181 |
|
---|
[6da1013f] | 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 |
|
---|
[3a2f8aa] | 196 | void irq_initialize_arch(irq_t *irq)
|
---|
| 197 | {
|
---|
| 198 | (void) irq;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[2f40fe4] | 201 | /** @}
|
---|
[b45c443] | 202 | */
|
---|