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