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