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