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