[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>
|
---|
[c0699467] | 43 | #include <abi/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>
|
---|
[c0699467] | 48 | #include <abi/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. */
|
---|
[4872160] | 67 | void arch_pre_main(bootinfo_t *bootinfo)
|
---|
[12c7f27] | 68 | {
|
---|
[4872160] | 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;
|
---|
[f4b1535] | 75 | str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
|
---|
[4872160] | 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;
|
---|
[59477e3] | 85 | }
|
---|
[e731b0d] | 86 |
|
---|
| 87 | /* Copy boot allocations info. */
|
---|
[4872160] | 88 | ballocs.base = bootinfo->ballocs.base;
|
---|
| 89 | ballocs.size = bootinfo->ballocs.size;
|
---|
[e731b0d] | 90 |
|
---|
[4872160] | 91 | /* Copy OFW tree. */
|
---|
| 92 | ofw_tree_init(bootinfo->ofw_root);
|
---|
[12c7f27] | 93 | }
|
---|
| 94 |
|
---|
[393f631] | 95 | void arch_pre_mm_init(void)
|
---|
| 96 | {
|
---|
[91d5ad6] | 97 | /* Initialize dispatch table */
|
---|
[8965838e] | 98 | interrupt_init();
|
---|
[e731b0d] | 99 |
|
---|
[8965838e] | 100 | /* Start decrementer */
|
---|
| 101 | start_decrementer();
|
---|
[393f631] | 102 | }
|
---|
| 103 |
|
---|
[e731b0d] | 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 | };
|
---|
[a71c158] | 159 |
|
---|
| 160 | outdev_t *fbdev = fb_init(&fb_prop);
|
---|
| 161 | if (fbdev)
|
---|
| 162 | stdout_wire(fbdev);
|
---|
[e731b0d] | 163 | }
|
---|
| 164 |
|
---|
[a71c158] | 165 | return true;
|
---|
[e731b0d] | 166 | }
|
---|
| 167 |
|
---|
[393f631] | 168 | void arch_post_mm_init(void)
|
---|
| 169 | {
|
---|
[f6a0f06] | 170 | if (config.cpu_active == 1) {
|
---|
[d0688a3] | 171 | #ifdef CONFIG_FB
|
---|
[e731b0d] | 172 | ofw_tree_walk_by_device_type("display", display_register, NULL);
|
---|
[d0688a3] | 173 | #endif
|
---|
[f5e39a32] | 174 |
|
---|
| 175 | /* Initialize IRQ routing */
|
---|
| 176 | irq_init(IRQ_COUNT, IRQ_COUNT);
|
---|
[afc12d0] | 177 |
|
---|
[f6a0f06] | 178 | /* Merge all zones to 1 big zone */
|
---|
| 179 | zone_merge_all();
|
---|
| 180 | }
|
---|
[393f631] | 181 | }
|
---|
| 182 |
|
---|
[26678e5] | 183 | void arch_post_cpu_init(void)
|
---|
| 184 | {
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[7453929] | 187 | void arch_pre_smp_init(void)
|
---|
| 188 | {
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[e731b0d] | 191 | static bool macio_register(ofw_tree_node_t *node, void *arg)
|
---|
[393f631] | 192 | {
|
---|
[e731b0d] | 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) {
|
---|
[2a77841d] | 200 | /* Initialize PIC */
|
---|
[3a2f8aa] | 201 | pic_init(assigned_address[0].addr, PAGE_SIZE, &pic_cir,
|
---|
| 202 | &pic_cir_arg);
|
---|
[666f492] | 203 |
|
---|
[2a77841d] | 204 | #ifdef CONFIG_MAC_KBD
|
---|
[e731b0d] | 205 | uintptr_t pa = assigned_address[0].addr + 0x16000;
|
---|
[2a77841d] | 206 | uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
|
---|
| 207 | size_t offset = pa - aligned_addr;
|
---|
| 208 | size_t size = 2 * PAGE_SIZE;
|
---|
[e731b0d] | 209 |
|
---|
[2a77841d] | 210 | cuda_t *cuda = (cuda_t *)
|
---|
| 211 | (hw_map(aligned_addr, offset + size) + offset);
|
---|
[e731b0d] | 212 |
|
---|
[2a77841d] | 213 | /* Initialize I/O controller */
|
---|
| 214 | cuda_instance_t *cuda_instance =
|
---|
[3a2f8aa] | 215 | cuda_init(cuda, IRQ_CUDA, pic_cir, pic_cir_arg);
|
---|
[2a77841d] | 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 | }
|
---|
[666f492] | 225 |
|
---|
[3a2f8aa] | 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);
|
---|
[2a77841d] | 235 | #endif
|
---|
| 236 | }
|
---|
[e731b0d] | 237 |
|
---|
| 238 | /* Consider only a single device for now */
|
---|
| 239 | return false;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[3a2f8aa] | 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 |
|
---|
[e731b0d] | 249 | void arch_post_smp_init(void)
|
---|
| 250 | {
|
---|
[eff1f033] | 251 | /* Currently the only supported platform for ppc32 is 'mac'. */
|
---|
| 252 | static const char *platform = "mac";
|
---|
| 253 |
|
---|
| 254 | sysinfo_set_item_data("platform", NULL, (void *) platform,
|
---|
| 255 | str_size(platform));
|
---|
| 256 |
|
---|
[e731b0d] | 257 | ofw_tree_walk_by_device_type("mac-io", macio_register, NULL);
|
---|
[393f631] | 258 | }
|
---|
| 259 |
|
---|
| 260 | void calibrate_delay_loop(void)
|
---|
| 261 | {
|
---|
| 262 | }
|
---|
[8965838e] | 263 |
|
---|
[e692a27] | 264 | void userspace(uspace_arg_t *kernel_uarg)
|
---|
| 265 | {
|
---|
[965dc18] | 266 | userspace_asm((uintptr_t) kernel_uarg->uspace_uarg,
|
---|
[26aafe8] | 267 | (uintptr_t) kernel_uarg->uspace_stack + STACK_SIZE - SP_DELTA,
|
---|
[965dc18] | 268 | (uintptr_t) kernel_uarg->uspace_entry);
|
---|
[e692a27] | 269 |
|
---|
| 270 | /* Unreachable */
|
---|
[516ff92] | 271 | while (true);
|
---|
[e692a27] | 272 | }
|
---|
[41d33ac] | 273 |
|
---|
[6da1013f] | 274 | /** Construct function pointer
|
---|
| 275 | *
|
---|
| 276 | * @param fptr function pointer structure
|
---|
| 277 | * @param addr function address
|
---|
| 278 | * @param caller calling function address
|
---|
| 279 | *
|
---|
| 280 | * @return address of the function pointer
|
---|
| 281 | *
|
---|
| 282 | */
|
---|
| 283 | void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
|
---|
| 284 | {
|
---|
| 285 | return addr;
|
---|
| 286 | }
|
---|
| 287 |
|
---|
[c2417bc] | 288 | void arch_reboot(void)
|
---|
| 289 | {
|
---|
| 290 | // TODO
|
---|
[666f492] | 291 | while (true);
|
---|
[c2417bc] | 292 | }
|
---|
| 293 |
|
---|
[281994b] | 294 | /** @}
|
---|
[b45c443] | 295 | */
|
---|