| 1 | /*
|
|---|
| 2 | * Copyright (c) 2005 Martin Decky
|
|---|
| 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 ppc32
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #include <config.h>
|
|---|
| 36 | #include <arch.h>
|
|---|
| 37 | #include <arch/boot/boot.h>
|
|---|
| 38 | #include <genarch/drivers/via-cuda/cuda.h>
|
|---|
| 39 | #include <genarch/kbrd/kbrd.h>
|
|---|
| 40 | #include <arch/interrupt.h>
|
|---|
| 41 | #include <genarch/fb/fb.h>
|
|---|
| 42 | #include <genarch/fb/visuals.h>
|
|---|
| 43 | #include <genarch/ofw/ofw_tree.h>
|
|---|
| 44 | #include <genarch/ofw/pci.h>
|
|---|
| 45 | #include <userspace.h>
|
|---|
| 46 | #include <mm/page.h>
|
|---|
| 47 | #include <proc/uarg.h>
|
|---|
| 48 | #include <console/console.h>
|
|---|
| 49 | #include <ddi/irq.h>
|
|---|
| 50 | #include <arch/drivers/pic.h>
|
|---|
| 51 | #include <align.h>
|
|---|
| 52 | #include <macros.h>
|
|---|
| 53 | #include <string.h>
|
|---|
| 54 | #include <print.h>
|
|---|
| 55 |
|
|---|
| 56 | #define IRQ_COUNT 64
|
|---|
| 57 | #define IRQ_CUDA 10
|
|---|
| 58 |
|
|---|
| 59 | bootinfo_t bootinfo;
|
|---|
| 60 |
|
|---|
| 61 | /** Performs ppc32-specific initialization before main_bsp() is called. */
|
|---|
| 62 | void arch_pre_main(void)
|
|---|
| 63 | {
|
|---|
| 64 | init.cnt = bootinfo.taskmap.count;
|
|---|
| 65 |
|
|---|
| 66 | uint32_t i;
|
|---|
| 67 |
|
|---|
| 68 | for (i = 0; i < min3(bootinfo.taskmap.count, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); i++) {
|
|---|
| 69 | init.tasks[i].addr = bootinfo.taskmap.tasks[i].addr;
|
|---|
| 70 | init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
|
|---|
| 71 | str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
|
|---|
| 72 | bootinfo.taskmap.tasks[i].name);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | /* Copy boot allocations info. */
|
|---|
| 76 | ballocs.base = bootinfo.ballocs.base;
|
|---|
| 77 | ballocs.size = bootinfo.ballocs.size;
|
|---|
| 78 |
|
|---|
| 79 | ofw_tree_init(bootinfo.ofw_root);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | void arch_pre_mm_init(void)
|
|---|
| 83 | {
|
|---|
| 84 | /* Initialize dispatch table */
|
|---|
| 85 | interrupt_init();
|
|---|
| 86 |
|
|---|
| 87 | /* Start decrementer */
|
|---|
| 88 | start_decrementer();
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | static bool display_register(ofw_tree_node_t *node, void *arg)
|
|---|
| 92 | {
|
|---|
| 93 | uintptr_t fb_addr = 0;
|
|---|
| 94 | uint32_t fb_width = 0;
|
|---|
| 95 | uint32_t fb_height = 0;
|
|---|
| 96 | uint32_t fb_scanline = 0;
|
|---|
| 97 | unsigned int visual = VISUAL_UNKNOWN;
|
|---|
| 98 |
|
|---|
| 99 | ofw_tree_property_t *prop = ofw_tree_getprop(node, "address");
|
|---|
| 100 | if ((prop) && (prop->value))
|
|---|
| 101 | fb_addr = *((uintptr_t *) prop->value);
|
|---|
| 102 |
|
|---|
| 103 | prop = ofw_tree_getprop(node, "width");
|
|---|
| 104 | if ((prop) && (prop->value))
|
|---|
| 105 | fb_width = *((uint32_t *) prop->value);
|
|---|
| 106 |
|
|---|
| 107 | prop = ofw_tree_getprop(node, "height");
|
|---|
| 108 | if ((prop) && (prop->value))
|
|---|
| 109 | fb_height = *((uint32_t *) prop->value);
|
|---|
| 110 |
|
|---|
| 111 | prop = ofw_tree_getprop(node, "depth");
|
|---|
| 112 | if ((prop) && (prop->value)) {
|
|---|
| 113 | uint32_t fb_bpp = *((uint32_t *) prop->value);
|
|---|
| 114 | switch (fb_bpp) {
|
|---|
| 115 | case 8:
|
|---|
| 116 | visual = VISUAL_INDIRECT_8;
|
|---|
| 117 | break;
|
|---|
| 118 | case 16:
|
|---|
| 119 | visual = VISUAL_RGB_5_5_5_BE;
|
|---|
| 120 | break;
|
|---|
| 121 | case 24:
|
|---|
| 122 | visual = VISUAL_BGR_8_8_8;
|
|---|
| 123 | break;
|
|---|
| 124 | case 32:
|
|---|
| 125 | visual = VISUAL_RGB_0_8_8_8;
|
|---|
| 126 | break;
|
|---|
| 127 | default:
|
|---|
| 128 | visual = VISUAL_UNKNOWN;
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | prop = ofw_tree_getprop(node, "linebytes");
|
|---|
| 133 | if ((prop) && (prop->value))
|
|---|
| 134 | fb_scanline = *((uint32_t *) prop->value);
|
|---|
| 135 |
|
|---|
| 136 | if ((fb_addr) && (fb_width > 0) && (fb_height > 0)
|
|---|
| 137 | && (fb_scanline > 0) && (visual != VISUAL_UNKNOWN)) {
|
|---|
| 138 | fb_properties_t fb_prop = {
|
|---|
| 139 | .addr = fb_addr,
|
|---|
| 140 | .offset = 0,
|
|---|
| 141 | .x = fb_width,
|
|---|
| 142 | .y = fb_height,
|
|---|
| 143 | .scan = fb_scanline,
|
|---|
| 144 | .visual = visual,
|
|---|
| 145 | };
|
|---|
| 146 |
|
|---|
| 147 | outdev_t *fbdev = fb_init(&fb_prop);
|
|---|
| 148 | if (fbdev)
|
|---|
| 149 | stdout_wire(fbdev);
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | return true;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | void arch_post_mm_init(void)
|
|---|
| 156 | {
|
|---|
| 157 | if (config.cpu_active == 1) {
|
|---|
| 158 | #ifdef CONFIG_FB
|
|---|
| 159 | ofw_tree_walk_by_device_type("display", display_register, NULL);
|
|---|
| 160 | #endif
|
|---|
| 161 |
|
|---|
| 162 | /* Initialize IRQ routing */
|
|---|
| 163 | irq_init(IRQ_COUNT, IRQ_COUNT);
|
|---|
| 164 |
|
|---|
| 165 | /* Merge all zones to 1 big zone */
|
|---|
| 166 | zone_merge_all();
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | void arch_post_cpu_init(void)
|
|---|
| 171 | {
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | void arch_pre_smp_init(void)
|
|---|
| 175 | {
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | static bool macio_register(ofw_tree_node_t *node, void *arg)
|
|---|
| 179 | {
|
|---|
| 180 | ofw_pci_reg_t *assigned_address = NULL;
|
|---|
| 181 |
|
|---|
| 182 | ofw_tree_property_t *prop = ofw_tree_getprop(node, "assigned-addresses");
|
|---|
| 183 | if ((prop) && (prop->value))
|
|---|
| 184 | assigned_address = ((ofw_pci_reg_t *) prop->value);
|
|---|
| 185 |
|
|---|
| 186 | if (assigned_address) {
|
|---|
| 187 | /* Initialize PIC */
|
|---|
| 188 | cir_t cir;
|
|---|
| 189 | void *cir_arg;
|
|---|
| 190 | pic_init(assigned_address[0].addr, PAGE_SIZE, &cir, &cir_arg);
|
|---|
| 191 |
|
|---|
| 192 | #ifdef CONFIG_MAC_KBD
|
|---|
| 193 | uintptr_t pa = assigned_address[0].addr + 0x16000;
|
|---|
| 194 | uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
|
|---|
| 195 | size_t offset = pa - aligned_addr;
|
|---|
| 196 | size_t size = 2 * PAGE_SIZE;
|
|---|
| 197 |
|
|---|
| 198 | cuda_t *cuda = (cuda_t *)
|
|---|
| 199 | (hw_map(aligned_addr, offset + size) + offset);
|
|---|
| 200 |
|
|---|
| 201 | /* Initialize I/O controller */
|
|---|
| 202 | cuda_instance_t *cuda_instance =
|
|---|
| 203 | cuda_init(cuda, IRQ_CUDA, cir, cir_arg);
|
|---|
| 204 | if (cuda_instance) {
|
|---|
| 205 | kbrd_instance_t *kbrd_instance = kbrd_init();
|
|---|
| 206 | if (kbrd_instance) {
|
|---|
| 207 | indev_t *sink = stdin_wire();
|
|---|
| 208 | indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
|
|---|
| 209 | cuda_wire(cuda_instance, kbrd);
|
|---|
| 210 | pic_enable_interrupt(IRQ_CUDA);
|
|---|
| 211 | }
|
|---|
| 212 | }
|
|---|
| 213 | #endif
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | /* Consider only a single device for now */
|
|---|
| 217 | return false;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | void arch_post_smp_init(void)
|
|---|
| 221 | {
|
|---|
| 222 | ofw_tree_walk_by_device_type("mac-io", macio_register, NULL);
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | void calibrate_delay_loop(void)
|
|---|
| 226 | {
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | void userspace(uspace_arg_t *kernel_uarg)
|
|---|
| 230 | {
|
|---|
| 231 | userspace_asm((uintptr_t) kernel_uarg->uspace_uarg,
|
|---|
| 232 | (uintptr_t) kernel_uarg->uspace_stack +
|
|---|
| 233 | THREAD_STACK_SIZE - SP_DELTA,
|
|---|
| 234 | (uintptr_t) kernel_uarg->uspace_entry);
|
|---|
| 235 |
|
|---|
| 236 | /* Unreachable */
|
|---|
| 237 | while (true);
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | /** Construct function pointer
|
|---|
| 241 | *
|
|---|
| 242 | * @param fptr function pointer structure
|
|---|
| 243 | * @param addr function address
|
|---|
| 244 | * @param caller calling function address
|
|---|
| 245 | *
|
|---|
| 246 | * @return address of the function pointer
|
|---|
| 247 | *
|
|---|
| 248 | */
|
|---|
| 249 | void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
|
|---|
| 250 | {
|
|---|
| 251 | return addr;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | void arch_reboot(void)
|
|---|
| 255 | {
|
|---|
| 256 | // TODO
|
|---|
| 257 | while (1);
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | /** @}
|
|---|
| 261 | */
|
|---|