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