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