1 /* 2 * QEMU PowerPC e500-based platforms 3 * 4 * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved. 5 * 6 * Author: Yu Liu, <yu.liu@freescale.com> 7 * 8 * This file is derived from hw/ppc440_bamboo.c, 9 * the copyright for that material belongs to the original owners. 10 * 11 * This is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 */ 16 17 #include "config.h" 18 #include "qemu-common.h" 19 #include "e500.h" 20 #include "e500-ccsr.h" 21 #include "net/net.h" 22 #include "qemu/config-file.h" 23 #include "hw/hw.h" 24 #include "hw/serial.h" 25 #include "hw/pci/pci.h" 26 #include "hw/boards.h" 27 #include "sysemu/sysemu.h" 28 #include "sysemu/kvm.h" 29 #include "kvm_ppc.h" 30 #include "sysemu/device_tree.h" 31 #include "hw/openpic.h" 32 #include "hw/ppc.h" 33 #include "hw/loader.h" 34 #include "elf.h" 35 #include "hw/sysbus.h" 36 #include "exec/address-spaces.h" 37 #include "qemu/host-utils.h" 38 #include "hw/ppce500_pci.h" 39 40 #define BINARY_DEVICE_TREE_FILE "mpc8544ds.dtb" 41 #define UIMAGE_LOAD_BASE 0 42 #define DTC_LOAD_PAD 0x1800000 43 #define DTC_PAD_MASK 0xFFFFF 44 #define DTB_MAX_SIZE (8 * 1024 * 1024) 45 #define INITRD_LOAD_PAD 0x2000000 46 #define INITRD_PAD_MASK 0xFFFFFF 47 48 #define RAM_SIZES_ALIGN (64UL << 20) 49 50 /* TODO: parameterize */ 51 #define MPC8544_CCSRBAR_BASE 0xE0000000ULL 52 #define MPC8544_CCSRBAR_SIZE 0x00100000ULL 53 #define MPC8544_MPIC_REGS_OFFSET 0x40000ULL 54 #define MPC8544_MSI_REGS_OFFSET 0x41600ULL 55 #define MPC8544_SERIAL0_REGS_OFFSET 0x4500ULL 56 #define MPC8544_SERIAL1_REGS_OFFSET 0x4600ULL 57 #define MPC8544_PCI_REGS_OFFSET 0x8000ULL 58 #define MPC8544_PCI_REGS_BASE (MPC8544_CCSRBAR_BASE + \ 59 MPC8544_PCI_REGS_OFFSET) 60 #define MPC8544_PCI_REGS_SIZE 0x1000ULL 61 #define MPC8544_PCI_IO 0xE1000000ULL 62 #define MPC8544_UTIL_OFFSET 0xe0000ULL 63 #define MPC8544_SPIN_BASE 0xEF000000ULL 64 65 struct boot_info 66 { 67 uint32_t dt_base; 68 uint32_t dt_size; 69 uint32_t entry; 70 }; 71 72 static uint32_t *pci_map_create(void *fdt, uint32_t mpic, int first_slot, 73 int nr_slots, int *len) 74 { 75 int i = 0; 76 int slot; 77 int pci_irq; 78 int host_irq; 79 int last_slot = first_slot + nr_slots; 80 uint32_t *pci_map; 81 82 *len = nr_slots * 4 * 7 * sizeof(uint32_t); 83 pci_map = g_malloc(*len); 84 85 for (slot = first_slot; slot < last_slot; slot++) { 86 for (pci_irq = 0; pci_irq < 4; pci_irq++) { 87 pci_map[i++] = cpu_to_be32(slot << 11); 88 pci_map[i++] = cpu_to_be32(0x0); 89 pci_map[i++] = cpu_to_be32(0x0); 90 pci_map[i++] = cpu_to_be32(pci_irq + 1); 91 pci_map[i++] = cpu_to_be32(mpic); 92 host_irq = ppce500_pci_map_irq_slot(slot, pci_irq); 93 pci_map[i++] = cpu_to_be32(host_irq + 1); 94 pci_map[i++] = cpu_to_be32(0x1); 95 } 96 } 97 98 assert((i * sizeof(uint32_t)) == *len); 99 100 return pci_map; 101 } 102 103 static void dt_serial_create(void *fdt, unsigned long long offset, 104 const char *soc, const char *mpic, 105 const char *alias, int idx, bool defcon) 106 { 107 char ser[128]; 108 109 snprintf(ser, sizeof(ser), "%s/serial@%llx", soc, offset); 110 qemu_devtree_add_subnode(fdt, ser); 111 qemu_devtree_setprop_string(fdt, ser, "device_type", "serial"); 112 qemu_devtree_setprop_string(fdt, ser, "compatible", "ns16550"); 113 qemu_devtree_setprop_cells(fdt, ser, "reg", offset, 0x100); 114 qemu_devtree_setprop_cell(fdt, ser, "cell-index", idx); 115 qemu_devtree_setprop_cell(fdt, ser, "clock-frequency", 0); 116 qemu_devtree_setprop_cells(fdt, ser, "interrupts", 42, 2); 117 qemu_devtree_setprop_phandle(fdt, ser, "interrupt-parent", mpic); 118 qemu_devtree_setprop_string(fdt, "/aliases", alias, ser); 119 120 if (defcon) { 121 qemu_devtree_setprop_string(fdt, "/chosen", "linux,stdout-path", ser); 122 } 123 } 124 125 static int ppce500_load_device_tree(CPUPPCState *env, 126 PPCE500Params *params, 127 hwaddr addr, 128 hwaddr initrd_base, 129 hwaddr initrd_size) 130 { 131 int ret = -1; 132 uint64_t mem_reg_property[] = { 0, cpu_to_be64(params->ram_size) }; 133 int fdt_size; 134 void *fdt; 135 uint8_t hypercall[16]; 136 uint32_t clock_freq = 400000000; 137 uint32_t tb_freq = 400000000; 138 int i; 139 const char *toplevel_compat = NULL; /* user override */ 140 char compatible_sb[] = "fsl,mpc8544-immr\0simple-bus"; 141 char soc[128]; 142 char mpic[128]; 143 uint32_t mpic_ph; 144 uint32_t msi_ph; 145 char gutil[128]; 146 char pci[128]; 147 char msi[128]; 148 uint32_t *pci_map = NULL; 149 int len; 150 uint32_t pci_ranges[14] = 151 { 152 0x2000000, 0x0, 0xc0000000, 153 0x0, 0xc0000000, 154 0x0, 0x20000000, 155 156 0x1000000, 0x0, 0x0, 157 0x0, 0xe1000000, 158 0x0, 0x10000, 159 }; 160 QemuOpts *machine_opts; 161 const char *dtb_file = NULL; 162 163 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0); 164 if (machine_opts) { 165 dtb_file = qemu_opt_get(machine_opts, "dtb"); 166 toplevel_compat = qemu_opt_get(machine_opts, "dt_compatible"); 167 } 168 169 if (dtb_file) { 170 char *filename; 171 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, dtb_file); 172 if (!filename) { 173 goto out; 174 } 175 176 fdt = load_device_tree(filename, &fdt_size); 177 if (!fdt) { 178 goto out; 179 } 180 goto done; 181 } 182 183 fdt = create_device_tree(&fdt_size); 184 if (fdt == NULL) { 185 goto out; 186 } 187 188 /* Manipulate device tree in memory. */ 189 qemu_devtree_setprop_cell(fdt, "/", "#address-cells", 2); 190 qemu_devtree_setprop_cell(fdt, "/", "#size-cells", 2); 191 192 qemu_devtree_add_subnode(fdt, "/memory"); 193 qemu_devtree_setprop_string(fdt, "/memory", "device_type", "memory"); 194 qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property, 195 sizeof(mem_reg_property)); 196 197 qemu_devtree_add_subnode(fdt, "/chosen"); 198 if (initrd_size) { 199 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start", 200 initrd_base); 201 if (ret < 0) { 202 fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n"); 203 } 204 205 ret = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end", 206 (initrd_base + initrd_size)); 207 if (ret < 0) { 208 fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n"); 209 } 210 } 211 212 ret = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", 213 params->kernel_cmdline); 214 if (ret < 0) 215 fprintf(stderr, "couldn't set /chosen/bootargs\n"); 216 217 if (kvm_enabled()) { 218 /* Read out host's frequencies */ 219 clock_freq = kvmppc_get_clockfreq(); 220 tb_freq = kvmppc_get_tbfreq(); 221 222 /* indicate KVM hypercall interface */ 223 qemu_devtree_add_subnode(fdt, "/hypervisor"); 224 qemu_devtree_setprop_string(fdt, "/hypervisor", "compatible", 225 "linux,kvm"); 226 kvmppc_get_hypercall(env, hypercall, sizeof(hypercall)); 227 qemu_devtree_setprop(fdt, "/hypervisor", "hcall-instructions", 228 hypercall, sizeof(hypercall)); 229 /* if KVM supports the idle hcall, set property indicating this */ 230 if (kvmppc_get_hasidle(env)) { 231 qemu_devtree_setprop(fdt, "/hypervisor", "has-idle", NULL, 0); 232 } 233 } 234 235 /* Create CPU nodes */ 236 qemu_devtree_add_subnode(fdt, "/cpus"); 237 qemu_devtree_setprop_cell(fdt, "/cpus", "#address-cells", 1); 238 qemu_devtree_setprop_cell(fdt, "/cpus", "#size-cells", 0); 239 240 /* We need to generate the cpu nodes in reverse order, so Linux can pick 241 the first node as boot node and be happy */ 242 for (i = smp_cpus - 1; i >= 0; i--) { 243 CPUState *cpu; 244 char cpu_name[128]; 245 uint64_t cpu_release_addr = MPC8544_SPIN_BASE + (i * 0x20); 246 247 cpu = qemu_get_cpu(i); 248 if (cpu == NULL) { 249 continue; 250 } 251 env = cpu->env_ptr; 252 253 snprintf(cpu_name, sizeof(cpu_name), "/cpus/PowerPC,8544@%x", 254 cpu->cpu_index); 255 qemu_devtree_add_subnode(fdt, cpu_name); 256 qemu_devtree_setprop_cell(fdt, cpu_name, "clock-frequency", clock_freq); 257 qemu_devtree_setprop_cell(fdt, cpu_name, "timebase-frequency", tb_freq); 258 qemu_devtree_setprop_string(fdt, cpu_name, "device_type", "cpu"); 259 qemu_devtree_setprop_cell(fdt, cpu_name, "reg", cpu->cpu_index); 260 qemu_devtree_setprop_cell(fdt, cpu_name, "d-cache-line-size", 261 env->dcache_line_size); 262 qemu_devtree_setprop_cell(fdt, cpu_name, "i-cache-line-size", 263 env->icache_line_size); 264 qemu_devtree_setprop_cell(fdt, cpu_name, "d-cache-size", 0x8000); 265 qemu_devtree_setprop_cell(fdt, cpu_name, "i-cache-size", 0x8000); 266 qemu_devtree_setprop_cell(fdt, cpu_name, "bus-frequency", 0); 267 if (cpu->cpu_index) { 268 qemu_devtree_setprop_string(fdt, cpu_name, "status", "disabled"); 269 qemu_devtree_setprop_string(fdt, cpu_name, "enable-method", "spin-table"); 270 qemu_devtree_setprop_u64(fdt, cpu_name, "cpu-release-addr", 271 cpu_release_addr); 272 } else { 273 qemu_devtree_setprop_string(fdt, cpu_name, "status", "okay"); 274 } 275 } 276 277 qemu_devtree_add_subnode(fdt, "/aliases"); 278 /* XXX These should go into their respective devices' code */ 279 snprintf(soc, sizeof(soc), "/soc@%llx", MPC8544_CCSRBAR_BASE); 280 qemu_devtree_add_subnode(fdt, soc); 281 qemu_devtree_setprop_string(fdt, soc, "device_type", "soc"); 282 qemu_devtree_setprop(fdt, soc, "compatible", compatible_sb, 283 sizeof(compatible_sb)); 284 qemu_devtree_setprop_cell(fdt, soc, "#address-cells", 1); 285 qemu_devtree_setprop_cell(fdt, soc, "#size-cells", 1); 286 qemu_devtree_setprop_cells(fdt, soc, "ranges", 0x0, 287 MPC8544_CCSRBAR_BASE >> 32, MPC8544_CCSRBAR_BASE, 288 MPC8544_CCSRBAR_SIZE); 289 /* XXX should contain a reasonable value */ 290 qemu_devtree_setprop_cell(fdt, soc, "bus-frequency", 0); 291 292 snprintf(mpic, sizeof(mpic), "%s/pic@%llx", soc, MPC8544_MPIC_REGS_OFFSET); 293 qemu_devtree_add_subnode(fdt, mpic); 294 qemu_devtree_setprop_string(fdt, mpic, "device_type", "open-pic"); 295 qemu_devtree_setprop_string(fdt, mpic, "compatible", "fsl,mpic"); 296 qemu_devtree_setprop_cells(fdt, mpic, "reg", MPC8544_MPIC_REGS_OFFSET, 297 0x40000); 298 qemu_devtree_setprop_cell(fdt, mpic, "#address-cells", 0); 299 qemu_devtree_setprop_cell(fdt, mpic, "#interrupt-cells", 2); 300 mpic_ph = qemu_devtree_alloc_phandle(fdt); 301 qemu_devtree_setprop_cell(fdt, mpic, "phandle", mpic_ph); 302 qemu_devtree_setprop_cell(fdt, mpic, "linux,phandle", mpic_ph); 303 qemu_devtree_setprop(fdt, mpic, "interrupt-controller", NULL, 0); 304 305 /* 306 * We have to generate ser1 first, because Linux takes the first 307 * device it finds in the dt as serial output device. And we generate 308 * devices in reverse order to the dt. 309 */ 310 dt_serial_create(fdt, MPC8544_SERIAL1_REGS_OFFSET, 311 soc, mpic, "serial1", 1, false); 312 dt_serial_create(fdt, MPC8544_SERIAL0_REGS_OFFSET, 313 soc, mpic, "serial0", 0, true); 314 315 snprintf(gutil, sizeof(gutil), "%s/global-utilities@%llx", soc, 316 MPC8544_UTIL_OFFSET); 317 qemu_devtree_add_subnode(fdt, gutil); 318 qemu_devtree_setprop_string(fdt, gutil, "compatible", "fsl,mpc8544-guts"); 319 qemu_devtree_setprop_cells(fdt, gutil, "reg", MPC8544_UTIL_OFFSET, 0x1000); 320 qemu_devtree_setprop(fdt, gutil, "fsl,has-rstcr", NULL, 0); 321 322 snprintf(msi, sizeof(msi), "/%s/msi@%llx", soc, MPC8544_MSI_REGS_OFFSET); 323 qemu_devtree_add_subnode(fdt, msi); 324 qemu_devtree_setprop_string(fdt, msi, "compatible", "fsl,mpic-msi"); 325 qemu_devtree_setprop_cells(fdt, msi, "reg", MPC8544_MSI_REGS_OFFSET, 0x200); 326 msi_ph = qemu_devtree_alloc_phandle(fdt); 327 qemu_devtree_setprop_cells(fdt, msi, "msi-available-ranges", 0x0, 0x100); 328 qemu_devtree_setprop_phandle(fdt, msi, "interrupt-parent", mpic); 329 qemu_devtree_setprop_cells(fdt, msi, "interrupts", 330 0xe0, 0x0, 331 0xe1, 0x0, 332 0xe2, 0x0, 333 0xe3, 0x0, 334 0xe4, 0x0, 335 0xe5, 0x0, 336 0xe6, 0x0, 337 0xe7, 0x0); 338 qemu_devtree_setprop_cell(fdt, msi, "phandle", msi_ph); 339 qemu_devtree_setprop_cell(fdt, msi, "linux,phandle", msi_ph); 340 341 snprintf(pci, sizeof(pci), "/pci@%llx", MPC8544_PCI_REGS_BASE); 342 qemu_devtree_add_subnode(fdt, pci); 343 qemu_devtree_setprop_cell(fdt, pci, "cell-index", 0); 344 qemu_devtree_setprop_string(fdt, pci, "compatible", "fsl,mpc8540-pci"); 345 qemu_devtree_setprop_string(fdt, pci, "device_type", "pci"); 346 qemu_devtree_setprop_cells(fdt, pci, "interrupt-map-mask", 0xf800, 0x0, 347 0x0, 0x7); 348 pci_map = pci_map_create(fdt, qemu_devtree_get_phandle(fdt, mpic), 349 params->pci_first_slot, params->pci_nr_slots, 350 &len); 351 qemu_devtree_setprop(fdt, pci, "interrupt-map", pci_map, len); 352 qemu_devtree_setprop_phandle(fdt, pci, "interrupt-parent", mpic); 353 qemu_devtree_setprop_cells(fdt, pci, "interrupts", 24, 2); 354 qemu_devtree_setprop_cells(fdt, pci, "bus-range", 0, 255); 355 for (i = 0; i < 14; i++) { 356 pci_ranges[i] = cpu_to_be32(pci_ranges[i]); 357 } 358 qemu_devtree_setprop_cell(fdt, pci, "fsl,msi", msi_ph); 359 qemu_devtree_setprop(fdt, pci, "ranges", pci_ranges, sizeof(pci_ranges)); 360 qemu_devtree_setprop_cells(fdt, pci, "reg", MPC8544_PCI_REGS_BASE >> 32, 361 MPC8544_PCI_REGS_BASE, 0, 0x1000); 362 qemu_devtree_setprop_cell(fdt, pci, "clock-frequency", 66666666); 363 qemu_devtree_setprop_cell(fdt, pci, "#interrupt-cells", 1); 364 qemu_devtree_setprop_cell(fdt, pci, "#size-cells", 2); 365 qemu_devtree_setprop_cell(fdt, pci, "#address-cells", 3); 366 qemu_devtree_setprop_string(fdt, "/aliases", "pci0", pci); 367 368 params->fixup_devtree(params, fdt); 369 370 if (toplevel_compat) { 371 qemu_devtree_setprop(fdt, "/", "compatible", toplevel_compat, 372 strlen(toplevel_compat) + 1); 373 } 374 375 done: 376 qemu_devtree_dumpdtb(fdt, fdt_size); 377 ret = rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr); 378 if (ret < 0) { 379 goto out; 380 } 381 g_free(fdt); 382 ret = fdt_size; 383 384 out: 385 g_free(pci_map); 386 387 return ret; 388 } 389 390 /* Create -kernel TLB entries for BookE. */ 391 static inline hwaddr booke206_page_size_to_tlb(uint64_t size) 392 { 393 return 63 - clz64(size >> 10); 394 } 395 396 static void mmubooke_create_initial_mapping(CPUPPCState *env) 397 { 398 struct boot_info *bi = env->load_info; 399 ppcmas_tlb_t *tlb = booke206_get_tlbm(env, 1, 0, 0); 400 hwaddr size, dt_end; 401 int ps; 402 403 /* Our initial TLB entry needs to cover everything from 0 to 404 the device tree top */ 405 dt_end = bi->dt_base + bi->dt_size; 406 ps = booke206_page_size_to_tlb(dt_end) + 1; 407 if (ps & 1) { 408 /* e500v2 can only do even TLB size bits */ 409 ps++; 410 } 411 size = (ps << MAS1_TSIZE_SHIFT); 412 tlb->mas1 = MAS1_VALID | size; 413 tlb->mas2 = 0; 414 tlb->mas7_3 = 0; 415 tlb->mas7_3 |= MAS3_UR | MAS3_UW | MAS3_UX | MAS3_SR | MAS3_SW | MAS3_SX; 416 417 env->tlb_dirty = true; 418 } 419 420 static void ppce500_cpu_reset_sec(void *opaque) 421 { 422 PowerPCCPU *cpu = opaque; 423 CPUPPCState *env = &cpu->env; 424 425 cpu_reset(CPU(cpu)); 426 427 /* Secondary CPU starts in halted state for now. Needs to change when 428 implementing non-kernel boot. */ 429 env->halted = 1; 430 env->exception_index = EXCP_HLT; 431 } 432 433 static void ppce500_cpu_reset(void *opaque) 434 { 435 PowerPCCPU *cpu = opaque; 436 CPUPPCState *env = &cpu->env; 437 struct boot_info *bi = env->load_info; 438 439 cpu_reset(CPU(cpu)); 440 441 /* Set initial guest state. */ 442 env->halted = 0; 443 env->gpr[1] = (16<<20) - 8; 444 env->gpr[3] = bi->dt_base; 445 env->nip = bi->entry; 446 mmubooke_create_initial_mapping(env); 447 } 448 449 void ppce500_init(PPCE500Params *params) 450 { 451 MemoryRegion *address_space_mem = get_system_memory(); 452 MemoryRegion *ram = g_new(MemoryRegion, 1); 453 PCIBus *pci_bus; 454 CPUPPCState *env = NULL; 455 uint64_t elf_entry; 456 uint64_t elf_lowaddr; 457 hwaddr entry=0; 458 hwaddr loadaddr=UIMAGE_LOAD_BASE; 459 target_long kernel_size=0; 460 target_ulong dt_base = 0; 461 target_ulong initrd_base = 0; 462 target_long initrd_size = 0; 463 target_ulong cur_base = 0; 464 int i = 0, j, k; 465 unsigned int pci_irq_nrs[4] = {1, 2, 3, 4}; 466 qemu_irq **irqs, *mpic; 467 DeviceState *dev; 468 CPUPPCState *firstenv = NULL; 469 MemoryRegion *ccsr_addr_space; 470 SysBusDevice *s; 471 PPCE500CCSRState *ccsr; 472 473 /* Setup CPUs */ 474 if (params->cpu_model == NULL) { 475 params->cpu_model = "e500v2_v30"; 476 } 477 478 irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *)); 479 irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB); 480 for (i = 0; i < smp_cpus; i++) { 481 PowerPCCPU *cpu; 482 CPUState *cs; 483 qemu_irq *input; 484 485 cpu = cpu_ppc_init(params->cpu_model); 486 if (cpu == NULL) { 487 fprintf(stderr, "Unable to initialize CPU!\n"); 488 exit(1); 489 } 490 env = &cpu->env; 491 cs = CPU(cpu); 492 493 if (!firstenv) { 494 firstenv = env; 495 } 496 497 irqs[i] = irqs[0] + (i * OPENPIC_OUTPUT_NB); 498 input = (qemu_irq *)env->irq_inputs; 499 irqs[i][OPENPIC_OUTPUT_INT] = input[PPCE500_INPUT_INT]; 500 irqs[i][OPENPIC_OUTPUT_CINT] = input[PPCE500_INPUT_CINT]; 501 env->spr[SPR_BOOKE_PIR] = cs->cpu_index = i; 502 env->mpic_iack = MPC8544_CCSRBAR_BASE + 503 MPC8544_MPIC_REGS_OFFSET + 0xa0; 504 505 ppc_booke_timers_init(cpu, 400000000, PPC_TIMER_E500); 506 507 /* Register reset handler */ 508 if (!i) { 509 /* Primary CPU */ 510 struct boot_info *boot_info; 511 boot_info = g_malloc0(sizeof(struct boot_info)); 512 qemu_register_reset(ppce500_cpu_reset, cpu); 513 env->load_info = boot_info; 514 } else { 515 /* Secondary CPUs */ 516 qemu_register_reset(ppce500_cpu_reset_sec, cpu); 517 } 518 } 519 520 env = firstenv; 521 522 /* Fixup Memory size on a alignment boundary */ 523 ram_size &= ~(RAM_SIZES_ALIGN - 1); 524 525 /* Register Memory */ 526 memory_region_init_ram(ram, "mpc8544ds.ram", ram_size); 527 vmstate_register_ram_global(ram); 528 memory_region_add_subregion(address_space_mem, 0, ram); 529 530 dev = qdev_create(NULL, "e500-ccsr"); 531 object_property_add_child(qdev_get_machine(), "e500-ccsr", 532 OBJECT(dev), NULL); 533 qdev_init_nofail(dev); 534 ccsr = CCSR(dev); 535 ccsr_addr_space = &ccsr->ccsr_space; 536 memory_region_add_subregion(address_space_mem, MPC8544_CCSRBAR_BASE, 537 ccsr_addr_space); 538 539 /* MPIC */ 540 mpic = g_new(qemu_irq, 256); 541 dev = qdev_create(NULL, "openpic"); 542 qdev_prop_set_uint32(dev, "nb_cpus", smp_cpus); 543 qdev_prop_set_uint32(dev, "model", params->mpic_version); 544 qdev_init_nofail(dev); 545 s = SYS_BUS_DEVICE(dev); 546 547 k = 0; 548 for (i = 0; i < smp_cpus; i++) { 549 for (j = 0; j < OPENPIC_OUTPUT_NB; j++) { 550 sysbus_connect_irq(s, k++, irqs[i][j]); 551 } 552 } 553 554 for (i = 0; i < 256; i++) { 555 mpic[i] = qdev_get_gpio_in(dev, i); 556 } 557 558 memory_region_add_subregion(ccsr_addr_space, MPC8544_MPIC_REGS_OFFSET, 559 s->mmio[0].memory); 560 561 /* Serial */ 562 if (serial_hds[0]) { 563 serial_mm_init(ccsr_addr_space, MPC8544_SERIAL0_REGS_OFFSET, 564 0, mpic[42], 399193, 565 serial_hds[0], DEVICE_BIG_ENDIAN); 566 } 567 568 if (serial_hds[1]) { 569 serial_mm_init(ccsr_addr_space, MPC8544_SERIAL1_REGS_OFFSET, 570 0, mpic[42], 399193, 571 serial_hds[1], DEVICE_BIG_ENDIAN); 572 } 573 574 /* General Utility device */ 575 dev = qdev_create(NULL, "mpc8544-guts"); 576 qdev_init_nofail(dev); 577 s = SYS_BUS_DEVICE(dev); 578 memory_region_add_subregion(ccsr_addr_space, MPC8544_UTIL_OFFSET, 579 sysbus_mmio_get_region(s, 0)); 580 581 /* PCI */ 582 dev = qdev_create(NULL, "e500-pcihost"); 583 qdev_prop_set_uint32(dev, "first_slot", params->pci_first_slot); 584 qdev_init_nofail(dev); 585 s = SYS_BUS_DEVICE(dev); 586 sysbus_connect_irq(s, 0, mpic[pci_irq_nrs[0]]); 587 sysbus_connect_irq(s, 1, mpic[pci_irq_nrs[1]]); 588 sysbus_connect_irq(s, 2, mpic[pci_irq_nrs[2]]); 589 sysbus_connect_irq(s, 3, mpic[pci_irq_nrs[3]]); 590 memory_region_add_subregion(ccsr_addr_space, MPC8544_PCI_REGS_OFFSET, 591 sysbus_mmio_get_region(s, 0)); 592 593 pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0"); 594 if (!pci_bus) 595 printf("couldn't create PCI controller!\n"); 596 597 sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, MPC8544_PCI_IO); 598 599 if (pci_bus) { 600 /* Register network interfaces. */ 601 for (i = 0; i < nb_nics; i++) { 602 pci_nic_init_nofail(&nd_table[i], "virtio", NULL); 603 } 604 } 605 606 /* Register spinning region */ 607 sysbus_create_simple("e500-spin", MPC8544_SPIN_BASE, NULL); 608 609 /* Load kernel. */ 610 if (params->kernel_filename) { 611 kernel_size = load_uimage(params->kernel_filename, &entry, 612 &loadaddr, NULL); 613 if (kernel_size < 0) { 614 kernel_size = load_elf(params->kernel_filename, NULL, NULL, 615 &elf_entry, &elf_lowaddr, NULL, 1, 616 ELF_MACHINE, 0); 617 entry = elf_entry; 618 loadaddr = elf_lowaddr; 619 } 620 /* XXX try again as binary */ 621 if (kernel_size < 0) { 622 fprintf(stderr, "qemu: could not load kernel '%s'\n", 623 params->kernel_filename); 624 exit(1); 625 } 626 627 cur_base = loadaddr + kernel_size; 628 629 /* Reserve space for dtb */ 630 dt_base = (cur_base + DTC_LOAD_PAD) & ~DTC_PAD_MASK; 631 cur_base += DTB_MAX_SIZE; 632 } 633 634 /* Load initrd. */ 635 if (params->initrd_filename) { 636 initrd_base = (cur_base + INITRD_LOAD_PAD) & ~INITRD_PAD_MASK; 637 initrd_size = load_image_targphys(params->initrd_filename, initrd_base, 638 ram_size - initrd_base); 639 640 if (initrd_size < 0) { 641 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", 642 params->initrd_filename); 643 exit(1); 644 } 645 646 cur_base = initrd_base + initrd_size; 647 } 648 649 /* If we're loading a kernel directly, we must load the device tree too. */ 650 if (params->kernel_filename) { 651 struct boot_info *boot_info; 652 int dt_size; 653 654 dt_size = ppce500_load_device_tree(env, params, dt_base, initrd_base, 655 initrd_size); 656 if (dt_size < 0) { 657 fprintf(stderr, "couldn't load device tree\n"); 658 exit(1); 659 } 660 assert(dt_size < DTB_MAX_SIZE); 661 662 boot_info = env->load_info; 663 boot_info->entry = entry; 664 boot_info->dt_base = dt_base; 665 boot_info->dt_size = dt_size; 666 } 667 668 if (kvm_enabled()) { 669 kvmppc_init(); 670 } 671 } 672 673 static int e500_ccsr_initfn(SysBusDevice *dev) 674 { 675 PPCE500CCSRState *ccsr; 676 677 ccsr = CCSR(dev); 678 memory_region_init(&ccsr->ccsr_space, "e500-ccsr", 679 MPC8544_CCSRBAR_SIZE); 680 return 0; 681 } 682 683 static void e500_ccsr_class_init(ObjectClass *klass, void *data) 684 { 685 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); 686 k->init = e500_ccsr_initfn; 687 } 688 689 static const TypeInfo e500_ccsr_info = { 690 .name = TYPE_CCSR, 691 .parent = TYPE_SYS_BUS_DEVICE, 692 .instance_size = sizeof(PPCE500CCSRState), 693 .class_init = e500_ccsr_class_init, 694 }; 695 696 static void e500_register_types(void) 697 { 698 type_register_static(&e500_ccsr_info); 699 } 700 701 type_init(e500_register_types) 702