1ba7e5ac1SBALATON Zoltan /* 2ba7e5ac1SBALATON Zoltan * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator 3ba7e5ac1SBALATON Zoltan * 4a8eda5edSBALATON Zoltan * Copyright (c) 2018-2021 BALATON Zoltan 5ba7e5ac1SBALATON Zoltan * 6ba7e5ac1SBALATON Zoltan * This work is licensed under the GNU GPL license version 2 or later. 7ba7e5ac1SBALATON Zoltan * 8ba7e5ac1SBALATON Zoltan */ 9ba7e5ac1SBALATON Zoltan 10ba7e5ac1SBALATON Zoltan #include "qemu/osdep.h" 11ba7e5ac1SBALATON Zoltan #include "qemu/units.h" 12ba7e5ac1SBALATON Zoltan #include "qapi/error.h" 13ba7e5ac1SBALATON Zoltan #include "hw/ppc/ppc.h" 14ba7e5ac1SBALATON Zoltan #include "hw/sysbus.h" 15ba7e5ac1SBALATON Zoltan #include "hw/pci/pci_host.h" 16ba7e5ac1SBALATON Zoltan #include "hw/irq.h" 17ba7e5ac1SBALATON Zoltan #include "hw/pci-host/mv64361.h" 18ba7e5ac1SBALATON Zoltan #include "hw/isa/vt82c686.h" 19ba7e5ac1SBALATON Zoltan #include "hw/ide/pci.h" 20ba7e5ac1SBALATON Zoltan #include "hw/i2c/smbus_eeprom.h" 21ba7e5ac1SBALATON Zoltan #include "hw/qdev-properties.h" 22ba7e5ac1SBALATON Zoltan #include "sysemu/reset.h" 23284c0486SBALATON Zoltan #include "sysemu/runstate.h" 2488adcbf2SBALATON Zoltan #include "sysemu/qtest.h" 25ba7e5ac1SBALATON Zoltan #include "hw/boards.h" 26ba7e5ac1SBALATON Zoltan #include "hw/loader.h" 27ba7e5ac1SBALATON Zoltan #include "hw/fw-path-provider.h" 28ba7e5ac1SBALATON Zoltan #include "elf.h" 29ba7e5ac1SBALATON Zoltan #include "qemu/log.h" 30ba7e5ac1SBALATON Zoltan #include "qemu/error-report.h" 31ba7e5ac1SBALATON Zoltan #include "sysemu/kvm.h" 32ba7e5ac1SBALATON Zoltan #include "kvm_ppc.h" 33ba7e5ac1SBALATON Zoltan #include "exec/address-spaces.h" 3494cd1ffbSBALATON Zoltan #include "qom/qom-qobject.h" 3594cd1ffbSBALATON Zoltan #include "qapi/qmp/qdict.h" 36ba7e5ac1SBALATON Zoltan #include "trace.h" 37ba7e5ac1SBALATON Zoltan #include "qemu/datadir.h" 38ba7e5ac1SBALATON Zoltan #include "sysemu/device_tree.h" 39a6c9808aSBALATON Zoltan #include "hw/ppc/vof.h" 40ba7e5ac1SBALATON Zoltan 41a6c9808aSBALATON Zoltan #include <libfdt.h> 42a6c9808aSBALATON Zoltan 43a6c9808aSBALATON Zoltan #define PROM_FILENAME "vof.bin" 44ba7e5ac1SBALATON Zoltan #define PROM_ADDR 0xfff00000 45ba7e5ac1SBALATON Zoltan #define PROM_SIZE 0x80000 46ba7e5ac1SBALATON Zoltan 47ebe0e9bbSBALATON Zoltan #define INITRD_MIN_ADDR 0x600000 48ebe0e9bbSBALATON Zoltan 49a6c9808aSBALATON Zoltan #define KVMPPC_HCALL_BASE 0xf000 505f2eb049SBALATON Zoltan #define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0) 51a6c9808aSBALATON Zoltan #define KVMPPC_H_VOF_CLIENT (KVMPPC_HCALL_BASE + 0x5) 52a6c9808aSBALATON Zoltan 53a6c9808aSBALATON Zoltan #define H_SUCCESS 0 54a6c9808aSBALATON Zoltan #define H_PRIVILEGE -3 /* Caller not privileged */ 55a6c9808aSBALATON Zoltan #define H_PARAMETER -4 /* Parameter invalid, out-of-range or conflicting */ 56a6c9808aSBALATON Zoltan 57ba7e5ac1SBALATON Zoltan #define BUS_FREQ_HZ 133333333 58ba7e5ac1SBALATON Zoltan 59d200ea14SBALATON Zoltan #define PCI0_CFG_ADDR 0xcf8 60a6c9808aSBALATON Zoltan #define PCI0_MEM_BASE 0xc0000000 61a6c9808aSBALATON Zoltan #define PCI0_MEM_SIZE 0x20000000 62a6c9808aSBALATON Zoltan #define PCI0_IO_BASE 0xf8000000 63a6c9808aSBALATON Zoltan #define PCI0_IO_SIZE 0x10000 64a6c9808aSBALATON Zoltan 65d200ea14SBALATON Zoltan #define PCI1_CFG_ADDR 0xc78 66a6c9808aSBALATON Zoltan #define PCI1_MEM_BASE 0x80000000 67a6c9808aSBALATON Zoltan #define PCI1_MEM_SIZE 0x40000000 68a6c9808aSBALATON Zoltan #define PCI1_IO_BASE 0xfe000000 69a6c9808aSBALATON Zoltan #define PCI1_IO_SIZE 0x10000 70a6c9808aSBALATON Zoltan 71a8eda5edSBALATON Zoltan #define TYPE_PEGASOS2_MACHINE MACHINE_TYPE_NAME("pegasos2") 72a8eda5edSBALATON Zoltan OBJECT_DECLARE_TYPE(Pegasos2MachineState, MachineClass, PEGASOS2_MACHINE) 73a8eda5edSBALATON Zoltan 74a8eda5edSBALATON Zoltan struct Pegasos2MachineState { 75a8eda5edSBALATON Zoltan MachineState parent_obj; 76a8eda5edSBALATON Zoltan PowerPCCPU *cpu; 77a8eda5edSBALATON Zoltan DeviceState *mv; 78fb27a3e9SBALATON Zoltan qemu_irq mv_pirq[PCI_NUM_PINS]; 79fb27a3e9SBALATON Zoltan qemu_irq via_pirq[PCI_NUM_PINS]; 80a6c9808aSBALATON Zoltan Vof *vof; 81a6c9808aSBALATON Zoltan void *fdt_blob; 82a6c9808aSBALATON Zoltan uint64_t kernel_addr; 83a6c9808aSBALATON Zoltan uint64_t kernel_entry; 84a6c9808aSBALATON Zoltan uint64_t kernel_size; 85ebe0e9bbSBALATON Zoltan uint64_t initrd_addr; 86ebe0e9bbSBALATON Zoltan uint64_t initrd_size; 87a8eda5edSBALATON Zoltan }; 88a8eda5edSBALATON Zoltan 89a6c9808aSBALATON Zoltan static void *build_fdt(MachineState *machine, int *fdt_size); 90a6c9808aSBALATON Zoltan 91ba7e5ac1SBALATON Zoltan static void pegasos2_cpu_reset(void *opaque) 92ba7e5ac1SBALATON Zoltan { 93ba7e5ac1SBALATON Zoltan PowerPCCPU *cpu = opaque; 94a6c9808aSBALATON Zoltan Pegasos2MachineState *pm = PEGASOS2_MACHINE(current_machine); 95ba7e5ac1SBALATON Zoltan 96ba7e5ac1SBALATON Zoltan cpu_reset(CPU(cpu)); 97ba7e5ac1SBALATON Zoltan cpu->env.spr[SPR_HID1] = 7ULL << 28; 98a6c9808aSBALATON Zoltan if (pm->vof) { 99a6c9808aSBALATON Zoltan cpu->env.gpr[1] = 2 * VOF_STACK_SIZE - 0x20; 100a6c9808aSBALATON Zoltan cpu->env.nip = 0x100; 101a6c9808aSBALATON Zoltan } 102ba7e5ac1SBALATON Zoltan } 103ba7e5ac1SBALATON Zoltan 104fb27a3e9SBALATON Zoltan static void pegasos2_pci_irq(void *opaque, int n, int level) 105fb27a3e9SBALATON Zoltan { 106fb27a3e9SBALATON Zoltan Pegasos2MachineState *pm = opaque; 107fb27a3e9SBALATON Zoltan 108fb27a3e9SBALATON Zoltan /* PCI interrupt lines are connected to both MV64361 and VT8231 */ 109fb27a3e9SBALATON Zoltan qemu_set_irq(pm->mv_pirq[n], level); 110fb27a3e9SBALATON Zoltan qemu_set_irq(pm->via_pirq[n], level); 111fb27a3e9SBALATON Zoltan } 112fb27a3e9SBALATON Zoltan 113ba7e5ac1SBALATON Zoltan static void pegasos2_init(MachineState *machine) 114ba7e5ac1SBALATON Zoltan { 115a8eda5edSBALATON Zoltan Pegasos2MachineState *pm = PEGASOS2_MACHINE(machine); 116a8eda5edSBALATON Zoltan CPUPPCState *env; 117ba7e5ac1SBALATON Zoltan MemoryRegion *rom = g_new(MemoryRegion, 1); 118ba7e5ac1SBALATON Zoltan PCIBus *pci_bus; 11965133e33SBALATON Zoltan Object *via; 12065133e33SBALATON Zoltan PCIDevice *dev; 121ba7e5ac1SBALATON Zoltan I2CBus *i2c_bus; 122ba7e5ac1SBALATON Zoltan const char *fwname = machine->firmware ?: PROM_FILENAME; 123ba7e5ac1SBALATON Zoltan char *filename; 124ebe0e9bbSBALATON Zoltan int i; 125ebe0e9bbSBALATON Zoltan ssize_t sz; 126ba7e5ac1SBALATON Zoltan uint8_t *spd_data; 127ba7e5ac1SBALATON Zoltan 128ba7e5ac1SBALATON Zoltan /* init CPU */ 129a8eda5edSBALATON Zoltan pm->cpu = POWERPC_CPU(cpu_create(machine->cpu_type)); 130a8eda5edSBALATON Zoltan env = &pm->cpu->env; 131a8eda5edSBALATON Zoltan if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { 132ba7e5ac1SBALATON Zoltan error_report("Incompatible CPU, only 6xx bus supported"); 133ba7e5ac1SBALATON Zoltan exit(1); 134ba7e5ac1SBALATON Zoltan } 135ba7e5ac1SBALATON Zoltan 136ba7e5ac1SBALATON Zoltan /* Set time-base frequency */ 137a8eda5edSBALATON Zoltan cpu_ppc_tb_init(env, BUS_FREQ_HZ / 4); 138a8eda5edSBALATON Zoltan qemu_register_reset(pegasos2_cpu_reset, pm->cpu); 139ba7e5ac1SBALATON Zoltan 140ba7e5ac1SBALATON Zoltan /* RAM */ 141239fec24SBALATON Zoltan if (machine->ram_size > 2 * GiB) { 142239fec24SBALATON Zoltan error_report("RAM size more than 2 GiB is not supported"); 143239fec24SBALATON Zoltan exit(1); 144239fec24SBALATON Zoltan } 145ba7e5ac1SBALATON Zoltan memory_region_add_subregion(get_system_memory(), 0, machine->ram); 146ba7e5ac1SBALATON Zoltan 147ba7e5ac1SBALATON Zoltan /* allocate and load firmware */ 148ba7e5ac1SBALATON Zoltan filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname); 149ba7e5ac1SBALATON Zoltan if (!filename) { 150ba7e5ac1SBALATON Zoltan error_report("Could not find firmware '%s'", fwname); 151ba7e5ac1SBALATON Zoltan exit(1); 152ba7e5ac1SBALATON Zoltan } 153a6c9808aSBALATON Zoltan if (!machine->firmware && !pm->vof) { 154a6c9808aSBALATON Zoltan pm->vof = g_malloc0(sizeof(*pm->vof)); 155a6c9808aSBALATON Zoltan } 156ba7e5ac1SBALATON Zoltan memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE, &error_fatal); 157ba7e5ac1SBALATON Zoltan memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom); 158ba7e5ac1SBALATON Zoltan sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, 159ba7e5ac1SBALATON Zoltan PPC_ELF_MACHINE, 0, 0); 160ba7e5ac1SBALATON Zoltan if (sz <= 0) { 161a6c9808aSBALATON Zoltan sz = load_image_targphys(filename, pm->vof ? 0 : PROM_ADDR, PROM_SIZE); 162ba7e5ac1SBALATON Zoltan } 163ba7e5ac1SBALATON Zoltan if (sz <= 0 || sz > PROM_SIZE) { 164ba7e5ac1SBALATON Zoltan error_report("Could not load firmware '%s'", filename); 165ba7e5ac1SBALATON Zoltan exit(1); 166ba7e5ac1SBALATON Zoltan } 167ba7e5ac1SBALATON Zoltan g_free(filename); 168a6c9808aSBALATON Zoltan if (pm->vof) { 169a6c9808aSBALATON Zoltan pm->vof->fw_size = sz; 170a6c9808aSBALATON Zoltan } 171ba7e5ac1SBALATON Zoltan 172ba7e5ac1SBALATON Zoltan /* Marvell Discovery II system controller */ 173a8eda5edSBALATON Zoltan pm->mv = DEVICE(sysbus_create_simple(TYPE_MV64361, -1, 1740f3e0c6fSCédric Le Goater qdev_get_gpio_in(DEVICE(pm->cpu), PPC6xx_INPUT_INT))); 175fb27a3e9SBALATON Zoltan for (i = 0; i < PCI_NUM_PINS; i++) { 176fb27a3e9SBALATON Zoltan pm->mv_pirq[i] = qdev_get_gpio_in_named(pm->mv, "gpp", 12 + i); 177fb27a3e9SBALATON Zoltan } 178a8eda5edSBALATON Zoltan pci_bus = mv64361_get_pci_bus(pm->mv, 1); 179fb27a3e9SBALATON Zoltan pci_bus_irqs(pci_bus, pegasos2_pci_irq, pm, PCI_NUM_PINS); 180ba7e5ac1SBALATON Zoltan 181ba7e5ac1SBALATON Zoltan /* VIA VT8231 South Bridge (multifunction PCI device) */ 18265133e33SBALATON Zoltan via = OBJECT(pci_create_simple_multifunction(pci_bus, PCI_DEVFN(12, 0), 183e052944aSBernhard Beschow TYPE_VT8231_ISA)); 184fb27a3e9SBALATON Zoltan for (i = 0; i < PCI_NUM_PINS; i++) { 185fb27a3e9SBALATON Zoltan pm->via_pirq[i] = qdev_get_gpio_in_named(DEVICE(via), "pirq", i); 186fb27a3e9SBALATON Zoltan } 187ff9105daSBernhard Beschow object_property_add_alias(OBJECT(machine), "rtc-time", 18865133e33SBALATON Zoltan object_resolve_path_component(via, "rtc"), 189ff9105daSBernhard Beschow "date"); 1909eb6abbfSBernhard Beschow qdev_connect_gpio_out(DEVICE(via), 0, 191a8eda5edSBALATON Zoltan qdev_get_gpio_in_named(pm->mv, "gpp", 31)); 192ba7e5ac1SBALATON Zoltan 19365133e33SBALATON Zoltan dev = PCI_DEVICE(object_resolve_path_component(via, "ide")); 194ba7e5ac1SBALATON Zoltan pci_ide_create_devs(dev); 195ba7e5ac1SBALATON Zoltan 19665133e33SBALATON Zoltan dev = PCI_DEVICE(object_resolve_path_component(via, "pm")); 197ba7e5ac1SBALATON Zoltan i2c_bus = I2C_BUS(qdev_get_child_bus(DEVICE(dev), "i2c")); 198ba7e5ac1SBALATON Zoltan spd_data = spd_data_generate(DDR, machine->ram_size); 199ba7e5ac1SBALATON Zoltan smbus_eeprom_init_one(i2c_bus, 0x57, spd_data); 200ba7e5ac1SBALATON Zoltan 201ba7e5ac1SBALATON Zoltan /* other PC hardware */ 202ba7e5ac1SBALATON Zoltan pci_vga_init(pci_bus); 203a6c9808aSBALATON Zoltan 204a6c9808aSBALATON Zoltan if (machine->kernel_filename) { 205a6c9808aSBALATON Zoltan sz = load_elf(machine->kernel_filename, NULL, NULL, NULL, 206a6c9808aSBALATON Zoltan &pm->kernel_entry, &pm->kernel_addr, NULL, NULL, 1, 207a6c9808aSBALATON Zoltan PPC_ELF_MACHINE, 0, 0); 208a6c9808aSBALATON Zoltan if (sz <= 0) { 209a6c9808aSBALATON Zoltan error_report("Could not load kernel '%s'", 210a6c9808aSBALATON Zoltan machine->kernel_filename); 211a6c9808aSBALATON Zoltan exit(1); 212a6c9808aSBALATON Zoltan } 213a6c9808aSBALATON Zoltan pm->kernel_size = sz; 214a6c9808aSBALATON Zoltan if (!pm->vof) { 215a6c9808aSBALATON Zoltan warn_report("Option -kernel may be ineffective with -bios."); 216a6c9808aSBALATON Zoltan } 21788adcbf2SBALATON Zoltan } else if (pm->vof && !qtest_enabled()) { 21899173b67SBALATON Zoltan warn_report("Using Virtual OpenFirmware but no -kernel option."); 219a6c9808aSBALATON Zoltan } 22099173b67SBALATON Zoltan 221ebe0e9bbSBALATON Zoltan if (machine->initrd_filename) { 222ebe0e9bbSBALATON Zoltan pm->initrd_addr = pm->kernel_addr + pm->kernel_size + 64 * KiB; 223ebe0e9bbSBALATON Zoltan pm->initrd_addr = ROUND_UP(pm->initrd_addr, 4); 224ebe0e9bbSBALATON Zoltan pm->initrd_addr = MAX(pm->initrd_addr, INITRD_MIN_ADDR); 225ebe0e9bbSBALATON Zoltan sz = load_image_targphys(machine->initrd_filename, pm->initrd_addr, 226ebe0e9bbSBALATON Zoltan machine->ram_size - pm->initrd_addr); 227ebe0e9bbSBALATON Zoltan if (sz <= 0) { 228ebe0e9bbSBALATON Zoltan error_report("Could not load initrd '%s'", 229ebe0e9bbSBALATON Zoltan machine->initrd_filename); 230ebe0e9bbSBALATON Zoltan exit(1); 231ebe0e9bbSBALATON Zoltan } 232ebe0e9bbSBALATON Zoltan pm->initrd_size = sz; 233ebe0e9bbSBALATON Zoltan } 234ebe0e9bbSBALATON Zoltan 2356ebc0048SBALATON Zoltan if (!pm->vof && machine->kernel_cmdline && machine->kernel_cmdline[0]) { 236a6c9808aSBALATON Zoltan warn_report("Option -append may be ineffective with -bios."); 237a6c9808aSBALATON Zoltan } 238a6c9808aSBALATON Zoltan } 239a6c9808aSBALATON Zoltan 240bd20cde5SBALATON Zoltan static uint32_t pegasos2_mv_reg_read(Pegasos2MachineState *pm, 2415f2eb049SBALATON Zoltan uint32_t addr, uint32_t len) 2425f2eb049SBALATON Zoltan { 243bd20cde5SBALATON Zoltan MemoryRegion *r = sysbus_mmio_get_region(SYS_BUS_DEVICE(pm->mv), 0); 244bd20cde5SBALATON Zoltan uint64_t val = 0xffffffffULL; 245bd20cde5SBALATON Zoltan memory_region_dispatch_read(r, addr, &val, size_memop(len) | MO_LE, 246bd20cde5SBALATON Zoltan MEMTXATTRS_UNSPECIFIED); 247bd20cde5SBALATON Zoltan return val; 248bd20cde5SBALATON Zoltan } 2495f2eb049SBALATON Zoltan 250bd20cde5SBALATON Zoltan static void pegasos2_mv_reg_write(Pegasos2MachineState *pm, uint32_t addr, 251bd20cde5SBALATON Zoltan uint32_t len, uint32_t val) 252bd20cde5SBALATON Zoltan { 253bd20cde5SBALATON Zoltan MemoryRegion *r = sysbus_mmio_get_region(SYS_BUS_DEVICE(pm->mv), 0); 254bd20cde5SBALATON Zoltan memory_region_dispatch_write(r, addr, val, size_memop(len) | MO_LE, 255bd20cde5SBALATON Zoltan MEMTXATTRS_UNSPECIFIED); 256bd20cde5SBALATON Zoltan } 257bd20cde5SBALATON Zoltan 258bd20cde5SBALATON Zoltan static uint32_t pegasos2_pci_config_read(Pegasos2MachineState *pm, int bus, 259bd20cde5SBALATON Zoltan uint32_t addr, uint32_t len) 260bd20cde5SBALATON Zoltan { 261d200ea14SBALATON Zoltan hwaddr pcicfg = bus ? PCI1_CFG_ADDR : PCI0_CFG_ADDR; 262bd20cde5SBALATON Zoltan uint64_t val = 0xffffffffULL; 263bd20cde5SBALATON Zoltan 264bd20cde5SBALATON Zoltan if (len <= 4) { 265bd20cde5SBALATON Zoltan pegasos2_mv_reg_write(pm, pcicfg, 4, addr | BIT(31)); 266bd20cde5SBALATON Zoltan val = pegasos2_mv_reg_read(pm, pcicfg + 4, len); 2675f2eb049SBALATON Zoltan } 2685f2eb049SBALATON Zoltan return val; 2695f2eb049SBALATON Zoltan } 2705f2eb049SBALATON Zoltan 271bd20cde5SBALATON Zoltan static void pegasos2_pci_config_write(Pegasos2MachineState *pm, int bus, 272bd20cde5SBALATON Zoltan uint32_t addr, uint32_t len, uint32_t val) 273a6c9808aSBALATON Zoltan { 274d200ea14SBALATON Zoltan hwaddr pcicfg = bus ? PCI1_CFG_ADDR : PCI0_CFG_ADDR; 275a6c9808aSBALATON Zoltan 276bd20cde5SBALATON Zoltan pegasos2_mv_reg_write(pm, pcicfg, 4, addr | BIT(31)); 277bd20cde5SBALATON Zoltan pegasos2_mv_reg_write(pm, pcicfg + 4, len, val); 278a6c9808aSBALATON Zoltan } 279a6c9808aSBALATON Zoltan 2807966d70fSJason A. Donenfeld static void pegasos2_machine_reset(MachineState *machine, ShutdownCause reason) 281a6c9808aSBALATON Zoltan { 282a6c9808aSBALATON Zoltan Pegasos2MachineState *pm = PEGASOS2_MACHINE(machine); 283a6c9808aSBALATON Zoltan void *fdt; 284a6c9808aSBALATON Zoltan uint64_t d[2]; 285a6c9808aSBALATON Zoltan int sz; 286a6c9808aSBALATON Zoltan 2877966d70fSJason A. Donenfeld qemu_devices_reset(reason); 288a6c9808aSBALATON Zoltan if (!pm->vof) { 289a6c9808aSBALATON Zoltan return; /* Firmware should set up machine so nothing to do */ 290a6c9808aSBALATON Zoltan } 291a6c9808aSBALATON Zoltan 292a6c9808aSBALATON Zoltan /* Otherwise, set up devices that board firmware would normally do */ 293bd20cde5SBALATON Zoltan pegasos2_mv_reg_write(pm, 0, 4, 0x28020ff); 294bd20cde5SBALATON Zoltan pegasos2_mv_reg_write(pm, 0x278, 4, 0xa31fc); 295bd20cde5SBALATON Zoltan pegasos2_mv_reg_write(pm, 0xf300, 4, 0x11ff0400); 296bd20cde5SBALATON Zoltan pegasos2_mv_reg_write(pm, 0xf10c, 4, 0x80000000); 297bd20cde5SBALATON Zoltan pegasos2_mv_reg_write(pm, 0x1c, 4, 0x8000000); 298bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 0, PCI_COMMAND, 2, PCI_COMMAND_IO | 299a6c9808aSBALATON Zoltan PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); 300bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, PCI_COMMAND, 2, PCI_COMMAND_IO | 301a6c9808aSBALATON Zoltan PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); 302a6c9808aSBALATON Zoltan 303bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) | 304a6c9808aSBALATON Zoltan PCI_INTERRUPT_LINE, 2, 0x9); 305bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) | 306a6c9808aSBALATON Zoltan 0x50, 1, 0x2); 307fb27a3e9SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) | 308fb27a3e9SBALATON Zoltan 0x55, 1, 0x90); 309fb27a3e9SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) | 310fb27a3e9SBALATON Zoltan 0x56, 1, 0x99); 311fb27a3e9SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) | 312fb27a3e9SBALATON Zoltan 0x57, 1, 0x90); 313a6c9808aSBALATON Zoltan 314bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) | 315a6c9808aSBALATON Zoltan PCI_INTERRUPT_LINE, 2, 0x109); 316bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) | 317a6c9808aSBALATON Zoltan PCI_CLASS_PROG, 1, 0xf); 318bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) | 319a6c9808aSBALATON Zoltan 0x40, 1, 0xb); 320bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) | 321a6c9808aSBALATON Zoltan 0x50, 4, 0x17171717); 322bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) | 323a6c9808aSBALATON Zoltan PCI_COMMAND, 2, 0x87); 324a6c9808aSBALATON Zoltan 325bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 2) << 8) | 326a6c9808aSBALATON Zoltan PCI_INTERRUPT_LINE, 2, 0x409); 327*19ac7b29SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 2) << 8) | 328*19ac7b29SBALATON Zoltan PCI_COMMAND, 2, 0x7); 329a6c9808aSBALATON Zoltan 330bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 3) << 8) | 331a6c9808aSBALATON Zoltan PCI_INTERRUPT_LINE, 2, 0x409); 332*19ac7b29SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 3) << 8) | 333*19ac7b29SBALATON Zoltan PCI_COMMAND, 2, 0x7); 334a6c9808aSBALATON Zoltan 335bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 4) << 8) | 336a6c9808aSBALATON Zoltan PCI_INTERRUPT_LINE, 2, 0x9); 337bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 4) << 8) | 338a6c9808aSBALATON Zoltan 0x48, 4, 0xf00); 339bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 4) << 8) | 340a6c9808aSBALATON Zoltan 0x40, 4, 0x558020); 341bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 4) << 8) | 342a6c9808aSBALATON Zoltan 0x90, 4, 0xd00); 343a6c9808aSBALATON Zoltan 344bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 5) << 8) | 345a6c9808aSBALATON Zoltan PCI_INTERRUPT_LINE, 2, 0x309); 346a6c9808aSBALATON Zoltan 347bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 6) << 8) | 348a6c9808aSBALATON Zoltan PCI_INTERRUPT_LINE, 2, 0x309); 349a6c9808aSBALATON Zoltan 350a6c9808aSBALATON Zoltan /* Device tree and VOF set up */ 351a6c9808aSBALATON Zoltan vof_init(pm->vof, machine->ram_size, &error_fatal); 352a6c9808aSBALATON Zoltan if (vof_claim(pm->vof, 0, VOF_STACK_SIZE, VOF_STACK_SIZE) == -1) { 353a6c9808aSBALATON Zoltan error_report("Memory allocation for stack failed"); 354a6c9808aSBALATON Zoltan exit(1); 355a6c9808aSBALATON Zoltan } 356a6c9808aSBALATON Zoltan if (pm->kernel_size && 357a6c9808aSBALATON Zoltan vof_claim(pm->vof, pm->kernel_addr, pm->kernel_size, 0) == -1) { 358a6c9808aSBALATON Zoltan error_report("Memory for kernel is in use"); 359a6c9808aSBALATON Zoltan exit(1); 360a6c9808aSBALATON Zoltan } 361ebe0e9bbSBALATON Zoltan if (pm->initrd_size && 362ebe0e9bbSBALATON Zoltan vof_claim(pm->vof, pm->initrd_addr, pm->initrd_size, 0) == -1) { 363ebe0e9bbSBALATON Zoltan error_report("Memory for initrd is in use"); 364ebe0e9bbSBALATON Zoltan exit(1); 365ebe0e9bbSBALATON Zoltan } 366a6c9808aSBALATON Zoltan fdt = build_fdt(machine, &sz); 367a6c9808aSBALATON Zoltan /* FIXME: VOF assumes entry is same as load address */ 368a6c9808aSBALATON Zoltan d[0] = cpu_to_be64(pm->kernel_entry); 369a6c9808aSBALATON Zoltan d[1] = cpu_to_be64(pm->kernel_size - (pm->kernel_entry - pm->kernel_addr)); 370a6c9808aSBALATON Zoltan qemu_fdt_setprop(fdt, "/chosen", "qemu,boot-kernel", d, sizeof(d)); 371a6c9808aSBALATON Zoltan 372a6c9808aSBALATON Zoltan qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt)); 373a6c9808aSBALATON Zoltan g_free(pm->fdt_blob); 374a6c9808aSBALATON Zoltan pm->fdt_blob = fdt; 375a6c9808aSBALATON Zoltan 376a6c9808aSBALATON Zoltan vof_build_dt(fdt, pm->vof); 377a6c9808aSBALATON Zoltan vof_client_open_store(fdt, pm->vof, "/chosen", "stdout", "/failsafe"); 3788d55f876SDaniel Henrique Barboza 3798d55f876SDaniel Henrique Barboza /* Set machine->fdt for 'dumpdtb' QMP/HMP command */ 3808d55f876SDaniel Henrique Barboza machine->fdt = fdt; 3818d55f876SDaniel Henrique Barboza 382a6c9808aSBALATON Zoltan pm->cpu->vhyp = PPC_VIRTUAL_HYPERVISOR(machine); 383a6c9808aSBALATON Zoltan } 384a6c9808aSBALATON Zoltan 3855f2eb049SBALATON Zoltan enum pegasos2_rtas_tokens { 3865f2eb049SBALATON Zoltan RTAS_RESTART_RTAS = 0, 3875f2eb049SBALATON Zoltan RTAS_NVRAM_FETCH = 1, 3885f2eb049SBALATON Zoltan RTAS_NVRAM_STORE = 2, 3895f2eb049SBALATON Zoltan RTAS_GET_TIME_OF_DAY = 3, 3905f2eb049SBALATON Zoltan RTAS_SET_TIME_OF_DAY = 4, 3915f2eb049SBALATON Zoltan RTAS_EVENT_SCAN = 6, 3925f2eb049SBALATON Zoltan RTAS_CHECK_EXCEPTION = 7, 3935f2eb049SBALATON Zoltan RTAS_READ_PCI_CONFIG = 8, 3945f2eb049SBALATON Zoltan RTAS_WRITE_PCI_CONFIG = 9, 3955f2eb049SBALATON Zoltan RTAS_DISPLAY_CHARACTER = 10, 3965f2eb049SBALATON Zoltan RTAS_SET_INDICATOR = 11, 3975f2eb049SBALATON Zoltan RTAS_POWER_OFF = 17, 3985f2eb049SBALATON Zoltan RTAS_SUSPEND = 18, 3995f2eb049SBALATON Zoltan RTAS_HIBERNATE = 19, 4005f2eb049SBALATON Zoltan RTAS_SYSTEM_REBOOT = 20, 4015f2eb049SBALATON Zoltan }; 4025f2eb049SBALATON Zoltan 4035f2eb049SBALATON Zoltan static target_ulong pegasos2_rtas(PowerPCCPU *cpu, Pegasos2MachineState *pm, 4045f2eb049SBALATON Zoltan target_ulong args_real) 4055f2eb049SBALATON Zoltan { 4065f2eb049SBALATON Zoltan AddressSpace *as = CPU(cpu)->as; 4075f2eb049SBALATON Zoltan uint32_t token = ldl_be_phys(as, args_real); 4085f2eb049SBALATON Zoltan uint32_t nargs = ldl_be_phys(as, args_real + 4); 4095f2eb049SBALATON Zoltan uint32_t nrets = ldl_be_phys(as, args_real + 8); 4105f2eb049SBALATON Zoltan uint32_t args = args_real + 12; 4115f2eb049SBALATON Zoltan uint32_t rets = args_real + 12 + nargs * 4; 4125f2eb049SBALATON Zoltan 4135f2eb049SBALATON Zoltan if (nrets < 1) { 4145f2eb049SBALATON Zoltan qemu_log_mask(LOG_GUEST_ERROR, "Too few return values in RTAS call\n"); 4155f2eb049SBALATON Zoltan return H_PARAMETER; 4165f2eb049SBALATON Zoltan } 4175f2eb049SBALATON Zoltan switch (token) { 41894cd1ffbSBALATON Zoltan case RTAS_GET_TIME_OF_DAY: 41994cd1ffbSBALATON Zoltan { 42094cd1ffbSBALATON Zoltan QObject *qo = object_property_get_qobject(qdev_get_machine(), 42194cd1ffbSBALATON Zoltan "rtc-time", &error_fatal); 42294cd1ffbSBALATON Zoltan QDict *qd = qobject_to(QDict, qo); 42394cd1ffbSBALATON Zoltan 42494cd1ffbSBALATON Zoltan if (nargs != 0 || nrets != 8 || !qd) { 42594cd1ffbSBALATON Zoltan stl_be_phys(as, rets, -1); 42694cd1ffbSBALATON Zoltan qobject_unref(qo); 42794cd1ffbSBALATON Zoltan return H_PARAMETER; 42894cd1ffbSBALATON Zoltan } 42994cd1ffbSBALATON Zoltan 43094cd1ffbSBALATON Zoltan stl_be_phys(as, rets, 0); 43194cd1ffbSBALATON Zoltan stl_be_phys(as, rets + 4, qdict_get_int(qd, "tm_year") + 1900); 43294cd1ffbSBALATON Zoltan stl_be_phys(as, rets + 8, qdict_get_int(qd, "tm_mon") + 1); 43394cd1ffbSBALATON Zoltan stl_be_phys(as, rets + 12, qdict_get_int(qd, "tm_mday")); 43494cd1ffbSBALATON Zoltan stl_be_phys(as, rets + 16, qdict_get_int(qd, "tm_hour")); 43594cd1ffbSBALATON Zoltan stl_be_phys(as, rets + 20, qdict_get_int(qd, "tm_min")); 43694cd1ffbSBALATON Zoltan stl_be_phys(as, rets + 24, qdict_get_int(qd, "tm_sec")); 43794cd1ffbSBALATON Zoltan stl_be_phys(as, rets + 28, 0); 43894cd1ffbSBALATON Zoltan qobject_unref(qo); 43994cd1ffbSBALATON Zoltan return H_SUCCESS; 44094cd1ffbSBALATON Zoltan } 4415f2eb049SBALATON Zoltan case RTAS_READ_PCI_CONFIG: 4425f2eb049SBALATON Zoltan { 4435f2eb049SBALATON Zoltan uint32_t addr, len, val; 4445f2eb049SBALATON Zoltan 4455f2eb049SBALATON Zoltan if (nargs != 2 || nrets != 2) { 4465f2eb049SBALATON Zoltan stl_be_phys(as, rets, -1); 4475f2eb049SBALATON Zoltan return H_PARAMETER; 4485f2eb049SBALATON Zoltan } 4495f2eb049SBALATON Zoltan addr = ldl_be_phys(as, args); 4505f2eb049SBALATON Zoltan len = ldl_be_phys(as, args + 4); 451bd20cde5SBALATON Zoltan val = pegasos2_pci_config_read(pm, !(addr >> 24), 4525f2eb049SBALATON Zoltan addr & 0x0fffffff, len); 4535f2eb049SBALATON Zoltan stl_be_phys(as, rets, 0); 4545f2eb049SBALATON Zoltan stl_be_phys(as, rets + 4, val); 4555f2eb049SBALATON Zoltan return H_SUCCESS; 4565f2eb049SBALATON Zoltan } 4575f2eb049SBALATON Zoltan case RTAS_WRITE_PCI_CONFIG: 4585f2eb049SBALATON Zoltan { 4595f2eb049SBALATON Zoltan uint32_t addr, len, val; 4605f2eb049SBALATON Zoltan 4615f2eb049SBALATON Zoltan if (nargs != 3 || nrets != 1) { 4625f2eb049SBALATON Zoltan stl_be_phys(as, rets, -1); 4635f2eb049SBALATON Zoltan return H_PARAMETER; 4645f2eb049SBALATON Zoltan } 4655f2eb049SBALATON Zoltan addr = ldl_be_phys(as, args); 4665f2eb049SBALATON Zoltan len = ldl_be_phys(as, args + 4); 4675f2eb049SBALATON Zoltan val = ldl_be_phys(as, args + 8); 468bd20cde5SBALATON Zoltan pegasos2_pci_config_write(pm, !(addr >> 24), 4695f2eb049SBALATON Zoltan addr & 0x0fffffff, len, val); 4705f2eb049SBALATON Zoltan stl_be_phys(as, rets, 0); 4715f2eb049SBALATON Zoltan return H_SUCCESS; 4725f2eb049SBALATON Zoltan } 4735f2eb049SBALATON Zoltan case RTAS_DISPLAY_CHARACTER: 4745f2eb049SBALATON Zoltan if (nargs != 1 || nrets != 1) { 4755f2eb049SBALATON Zoltan stl_be_phys(as, rets, -1); 4765f2eb049SBALATON Zoltan return H_PARAMETER; 4775f2eb049SBALATON Zoltan } 4785f2eb049SBALATON Zoltan qemu_log_mask(LOG_UNIMP, "%c", ldl_be_phys(as, args)); 4795f2eb049SBALATON Zoltan stl_be_phys(as, rets, 0); 4805f2eb049SBALATON Zoltan return H_SUCCESS; 481284c0486SBALATON Zoltan case RTAS_POWER_OFF: 482284c0486SBALATON Zoltan { 483284c0486SBALATON Zoltan if (nargs != 2 || nrets != 1) { 484284c0486SBALATON Zoltan stl_be_phys(as, rets, -1); 485284c0486SBALATON Zoltan return H_PARAMETER; 486284c0486SBALATON Zoltan } 487284c0486SBALATON Zoltan qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); 488284c0486SBALATON Zoltan stl_be_phys(as, rets, 0); 489284c0486SBALATON Zoltan return H_SUCCESS; 490284c0486SBALATON Zoltan } 4915f2eb049SBALATON Zoltan default: 4925f2eb049SBALATON Zoltan qemu_log_mask(LOG_UNIMP, "Unknown RTAS token %u (args=%u, rets=%u)\n", 4935f2eb049SBALATON Zoltan token, nargs, nrets); 4945f2eb049SBALATON Zoltan stl_be_phys(as, rets, 0); 4955f2eb049SBALATON Zoltan return H_SUCCESS; 4965f2eb049SBALATON Zoltan } 4975f2eb049SBALATON Zoltan } 4985f2eb049SBALATON Zoltan 4997cebc5dbSNicholas Piggin static bool pegasos2_cpu_in_nested(PowerPCCPU *cpu) 5007cebc5dbSNicholas Piggin { 5017cebc5dbSNicholas Piggin return false; 5027cebc5dbSNicholas Piggin } 5037cebc5dbSNicholas Piggin 504a6c9808aSBALATON Zoltan static void pegasos2_hypercall(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) 505a6c9808aSBALATON Zoltan { 506a6c9808aSBALATON Zoltan Pegasos2MachineState *pm = PEGASOS2_MACHINE(vhyp); 507a6c9808aSBALATON Zoltan CPUPPCState *env = &cpu->env; 508a6c9808aSBALATON Zoltan 509a6c9808aSBALATON Zoltan /* The TCG path should also be holding the BQL at this point */ 510a6c9808aSBALATON Zoltan g_assert(qemu_mutex_iothread_locked()); 511a6c9808aSBALATON Zoltan 512d41ccf6eSVíctor Colombo if (FIELD_EX64(env->msr, MSR, PR)) { 513a6c9808aSBALATON Zoltan qemu_log_mask(LOG_GUEST_ERROR, "Hypercall made with MSR[PR]=1\n"); 514a6c9808aSBALATON Zoltan env->gpr[3] = H_PRIVILEGE; 5155f2eb049SBALATON Zoltan } else if (env->gpr[3] == KVMPPC_H_RTAS) { 5165f2eb049SBALATON Zoltan env->gpr[3] = pegasos2_rtas(cpu, pm, env->gpr[4]); 517a6c9808aSBALATON Zoltan } else if (env->gpr[3] == KVMPPC_H_VOF_CLIENT) { 518a6c9808aSBALATON Zoltan int ret = vof_client_call(MACHINE(pm), pm->vof, pm->fdt_blob, 519a6c9808aSBALATON Zoltan env->gpr[4]); 520a6c9808aSBALATON Zoltan env->gpr[3] = (ret ? H_PARAMETER : H_SUCCESS); 521a6c9808aSBALATON Zoltan } else { 522a6c9808aSBALATON Zoltan qemu_log_mask(LOG_GUEST_ERROR, "Unsupported hypercall " TARGET_FMT_lx 523a6c9808aSBALATON Zoltan "\n", env->gpr[3]); 524a6c9808aSBALATON Zoltan env->gpr[3] = -1; 525a6c9808aSBALATON Zoltan } 526a6c9808aSBALATON Zoltan } 527a6c9808aSBALATON Zoltan 528a6c9808aSBALATON Zoltan static void vhyp_nop(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) 529a6c9808aSBALATON Zoltan { 530a6c9808aSBALATON Zoltan } 531a6c9808aSBALATON Zoltan 532a6c9808aSBALATON Zoltan static target_ulong vhyp_encode_hpt_for_kvm_pr(PPCVirtualHypervisor *vhyp) 533a6c9808aSBALATON Zoltan { 534a6c9808aSBALATON Zoltan return POWERPC_CPU(current_cpu)->env.spr[SPR_SDR1]; 535ba7e5ac1SBALATON Zoltan } 536ba7e5ac1SBALATON Zoltan 537a312aaebSBALATON Zoltan static bool pegasos2_setprop(MachineState *ms, const char *path, 538a312aaebSBALATON Zoltan const char *propname, void *val, int vallen) 539a312aaebSBALATON Zoltan { 540a312aaebSBALATON Zoltan return true; 541a312aaebSBALATON Zoltan } 542a312aaebSBALATON Zoltan 543a8eda5edSBALATON Zoltan static void pegasos2_machine_class_init(ObjectClass *oc, void *data) 544ba7e5ac1SBALATON Zoltan { 545a8eda5edSBALATON Zoltan MachineClass *mc = MACHINE_CLASS(oc); 546a6c9808aSBALATON Zoltan PPCVirtualHypervisorClass *vhc = PPC_VIRTUAL_HYPERVISOR_CLASS(oc); 547a312aaebSBALATON Zoltan VofMachineIfClass *vmc = VOF_MACHINE_CLASS(oc); 548a8eda5edSBALATON Zoltan 549ba7e5ac1SBALATON Zoltan mc->desc = "Genesi/bPlan Pegasos II"; 550ba7e5ac1SBALATON Zoltan mc->init = pegasos2_init; 551a6c9808aSBALATON Zoltan mc->reset = pegasos2_machine_reset; 552ba7e5ac1SBALATON Zoltan mc->block_default_type = IF_IDE; 553ba7e5ac1SBALATON Zoltan mc->default_boot_order = "cd"; 554ba7e5ac1SBALATON Zoltan mc->default_display = "std"; 55556b8bfe9SBALATON Zoltan mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("7457_v1.2"); 556ba7e5ac1SBALATON Zoltan mc->default_ram_id = "pegasos2.ram"; 557ba7e5ac1SBALATON Zoltan mc->default_ram_size = 512 * MiB; 558a6c9808aSBALATON Zoltan 5597cebc5dbSNicholas Piggin vhc->cpu_in_nested = pegasos2_cpu_in_nested; 560a6c9808aSBALATON Zoltan vhc->hypercall = pegasos2_hypercall; 561a6c9808aSBALATON Zoltan vhc->cpu_exec_enter = vhyp_nop; 562a6c9808aSBALATON Zoltan vhc->cpu_exec_exit = vhyp_nop; 563a6c9808aSBALATON Zoltan vhc->encode_hpt_for_kvm_pr = vhyp_encode_hpt_for_kvm_pr; 564a312aaebSBALATON Zoltan 565a312aaebSBALATON Zoltan vmc->setprop = pegasos2_setprop; 566ba7e5ac1SBALATON Zoltan } 567ba7e5ac1SBALATON Zoltan 568a8eda5edSBALATON Zoltan static const TypeInfo pegasos2_machine_info = { 569a8eda5edSBALATON Zoltan .name = TYPE_PEGASOS2_MACHINE, 570a8eda5edSBALATON Zoltan .parent = TYPE_MACHINE, 571a8eda5edSBALATON Zoltan .class_init = pegasos2_machine_class_init, 572a8eda5edSBALATON Zoltan .instance_size = sizeof(Pegasos2MachineState), 573a6c9808aSBALATON Zoltan .interfaces = (InterfaceInfo[]) { 574a6c9808aSBALATON Zoltan { TYPE_PPC_VIRTUAL_HYPERVISOR }, 575a312aaebSBALATON Zoltan { TYPE_VOF_MACHINE_IF }, 576a6c9808aSBALATON Zoltan { } 577a6c9808aSBALATON Zoltan }, 578a8eda5edSBALATON Zoltan }; 579a8eda5edSBALATON Zoltan 580a8eda5edSBALATON Zoltan static void pegasos2_machine_register_types(void) 581a8eda5edSBALATON Zoltan { 582a8eda5edSBALATON Zoltan type_register_static(&pegasos2_machine_info); 583a8eda5edSBALATON Zoltan } 584a8eda5edSBALATON Zoltan 585a8eda5edSBALATON Zoltan type_init(pegasos2_machine_register_types) 586a6c9808aSBALATON Zoltan 587a6c9808aSBALATON Zoltan /* FDT creation for passing to firmware */ 588a6c9808aSBALATON Zoltan 589a6c9808aSBALATON Zoltan typedef struct { 590a6c9808aSBALATON Zoltan void *fdt; 591a6c9808aSBALATON Zoltan const char *path; 592a6c9808aSBALATON Zoltan } FDTInfo; 593a6c9808aSBALATON Zoltan 594a6c9808aSBALATON Zoltan /* We do everything in reverse order so it comes out right in the tree */ 595a6c9808aSBALATON Zoltan 596a6c9808aSBALATON Zoltan static void dt_ide(PCIBus *bus, PCIDevice *d, FDTInfo *fi) 597a6c9808aSBALATON Zoltan { 598a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, fi->path, "device_type", "spi"); 599a6c9808aSBALATON Zoltan } 600a6c9808aSBALATON Zoltan 601a6c9808aSBALATON Zoltan static void dt_usb(PCIBus *bus, PCIDevice *d, FDTInfo *fi) 602a6c9808aSBALATON Zoltan { 603a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, fi->path, "#size-cells", 0); 604a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, fi->path, "#address-cells", 1); 605a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, fi->path, "device_type", "usb"); 606a6c9808aSBALATON Zoltan } 607a6c9808aSBALATON Zoltan 608a6c9808aSBALATON Zoltan static void dt_isa(PCIBus *bus, PCIDevice *d, FDTInfo *fi) 609a6c9808aSBALATON Zoltan { 610a6c9808aSBALATON Zoltan GString *name = g_string_sized_new(64); 611a6c9808aSBALATON Zoltan uint32_t cells[3]; 612a6c9808aSBALATON Zoltan 613a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, fi->path, "#size-cells", 1); 614a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, fi->path, "#address-cells", 2); 615a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, fi->path, "device_type", "isa"); 616a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, fi->path, "name", "isa"); 617a6c9808aSBALATON Zoltan 618c0091740SBALATON Zoltan /* additional devices */ 619a6c9808aSBALATON Zoltan g_string_printf(name, "%s/lpt@i3bc", fi->path); 620a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fi->fdt, name->str); 621a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0); 622a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(7); 623a6c9808aSBALATON Zoltan cells[1] = 0; 624a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "interrupts", 625a6c9808aSBALATON Zoltan cells, 2 * sizeof(cells[0])); 626a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(1); 627a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(0x3bc); 628a6c9808aSBALATON Zoltan cells[2] = cpu_to_be32(8); 629a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0])); 630a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "lpt"); 631a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "name", "lpt"); 632a6c9808aSBALATON Zoltan 633a6c9808aSBALATON Zoltan g_string_printf(name, "%s/fdc@i3f0", fi->path); 634a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fi->fdt, name->str); 635a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0); 636a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(6); 637a6c9808aSBALATON Zoltan cells[1] = 0; 638a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "interrupts", 639a6c9808aSBALATON Zoltan cells, 2 * sizeof(cells[0])); 640a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(1); 641a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(0x3f0); 642a6c9808aSBALATON Zoltan cells[2] = cpu_to_be32(8); 643a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0])); 644a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "fdc"); 645a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "name", "fdc"); 646a6c9808aSBALATON Zoltan 647a6c9808aSBALATON Zoltan g_string_printf(name, "%s/timer@i40", fi->path); 648a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fi->fdt, name->str); 649a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0); 650a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(1); 651a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(0x40); 652a6c9808aSBALATON Zoltan cells[2] = cpu_to_be32(8); 653a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0])); 654a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "timer"); 655a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "name", "timer"); 656a6c9808aSBALATON Zoltan 657a6c9808aSBALATON Zoltan g_string_printf(name, "%s/rtc@i70", fi->path); 658a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fi->fdt, name->str); 659a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "compatible", "ds1385-rtc"); 660a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0); 661a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(8); 662a6c9808aSBALATON Zoltan cells[1] = 0; 663a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "interrupts", 664a6c9808aSBALATON Zoltan cells, 2 * sizeof(cells[0])); 665a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(1); 666a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(0x70); 667a6c9808aSBALATON Zoltan cells[2] = cpu_to_be32(2); 668a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0])); 669a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "rtc"); 670a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "name", "rtc"); 671a6c9808aSBALATON Zoltan 672a6c9808aSBALATON Zoltan g_string_printf(name, "%s/keyboard@i60", fi->path); 673a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fi->fdt, name->str); 674a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(1); 675a6c9808aSBALATON Zoltan cells[1] = 0; 676a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "interrupts", 677a6c9808aSBALATON Zoltan cells, 2 * sizeof(cells[0])); 678a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(1); 679a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(0x60); 680a6c9808aSBALATON Zoltan cells[2] = cpu_to_be32(5); 681a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0])); 682a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "keyboard"); 683a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "name", "keyboard"); 684a6c9808aSBALATON Zoltan 685a6c9808aSBALATON Zoltan g_string_printf(name, "%s/8042@i60", fi->path); 686a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fi->fdt, name->str); 687a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, name->str, "#interrupt-cells", 2); 688a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, name->str, "#size-cells", 0); 689a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, name->str, "#address-cells", 1); 690a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "interrupt-controller", ""); 691a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0); 692a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(1); 693a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(0x60); 694a6c9808aSBALATON Zoltan cells[2] = cpu_to_be32(5); 695a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0])); 696a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", ""); 697a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "name", "8042"); 698a6c9808aSBALATON Zoltan 699a6c9808aSBALATON Zoltan g_string_printf(name, "%s/serial@i2f8", fi->path); 700a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fi->fdt, name->str); 701a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0); 702a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(3); 703a6c9808aSBALATON Zoltan cells[1] = 0; 704a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "interrupts", 705a6c9808aSBALATON Zoltan cells, 2 * sizeof(cells[0])); 706a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(1); 707a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(0x2f8); 708a6c9808aSBALATON Zoltan cells[2] = cpu_to_be32(8); 709a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0])); 710a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "serial"); 711a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, name->str, "name", "serial"); 712a6c9808aSBALATON Zoltan 713a6c9808aSBALATON Zoltan g_string_free(name, TRUE); 714a6c9808aSBALATON Zoltan } 715a6c9808aSBALATON Zoltan 716a6c9808aSBALATON Zoltan static struct { 717a6c9808aSBALATON Zoltan const char *id; 718a6c9808aSBALATON Zoltan const char *name; 719a6c9808aSBALATON Zoltan void (*dtf)(PCIBus *bus, PCIDevice *d, FDTInfo *fi); 720a6c9808aSBALATON Zoltan } device_map[] = { 721a6c9808aSBALATON Zoltan { "pci11ab,6460", "host", NULL }, 722a6c9808aSBALATON Zoltan { "pci1106,8231", "isa", dt_isa }, 723a6c9808aSBALATON Zoltan { "pci1106,571", "ide", dt_ide }, 724a6c9808aSBALATON Zoltan { "pci1106,3044", "firewire", NULL }, 725a6c9808aSBALATON Zoltan { "pci1106,3038", "usb", dt_usb }, 726a6c9808aSBALATON Zoltan { "pci1106,8235", "other", NULL }, 727a6c9808aSBALATON Zoltan { "pci1106,3058", "sound", NULL }, 728a6c9808aSBALATON Zoltan { NULL, NULL } 729a6c9808aSBALATON Zoltan }; 730a6c9808aSBALATON Zoltan 731a6c9808aSBALATON Zoltan static void add_pci_device(PCIBus *bus, PCIDevice *d, void *opaque) 732a6c9808aSBALATON Zoltan { 733a6c9808aSBALATON Zoltan FDTInfo *fi = opaque; 734a6c9808aSBALATON Zoltan GString *node = g_string_new(NULL); 735a6c9808aSBALATON Zoltan uint32_t cells[(PCI_NUM_REGIONS + 1) * 5]; 736a6c9808aSBALATON Zoltan int i, j; 737a6c9808aSBALATON Zoltan const char *name = NULL; 738a6c9808aSBALATON Zoltan g_autofree const gchar *pn = g_strdup_printf("pci%x,%x", 739a6c9808aSBALATON Zoltan pci_get_word(&d->config[PCI_VENDOR_ID]), 740a6c9808aSBALATON Zoltan pci_get_word(&d->config[PCI_DEVICE_ID])); 741a6c9808aSBALATON Zoltan 742a6c9808aSBALATON Zoltan for (i = 0; device_map[i].id; i++) { 743a6c9808aSBALATON Zoltan if (!strcmp(pn, device_map[i].id)) { 744a6c9808aSBALATON Zoltan name = device_map[i].name; 745a6c9808aSBALATON Zoltan break; 746a6c9808aSBALATON Zoltan } 747a6c9808aSBALATON Zoltan } 748a6c9808aSBALATON Zoltan g_string_printf(node, "%s/%s@%x", fi->path, (name ?: pn), 749a6c9808aSBALATON Zoltan PCI_SLOT(d->devfn)); 750a6c9808aSBALATON Zoltan if (PCI_FUNC(d->devfn)) { 751a6c9808aSBALATON Zoltan g_string_append_printf(node, ",%x", PCI_FUNC(d->devfn)); 752a6c9808aSBALATON Zoltan } 753a6c9808aSBALATON Zoltan 754a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fi->fdt, node->str); 755a6c9808aSBALATON Zoltan if (device_map[i].dtf) { 756a6c9808aSBALATON Zoltan FDTInfo cfi = { fi->fdt, node->str }; 757a6c9808aSBALATON Zoltan device_map[i].dtf(bus, d, &cfi); 758a6c9808aSBALATON Zoltan } 759a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(d->devfn << 8); 760a6c9808aSBALATON Zoltan cells[1] = 0; 761a6c9808aSBALATON Zoltan cells[2] = 0; 762a6c9808aSBALATON Zoltan cells[3] = 0; 763a6c9808aSBALATON Zoltan cells[4] = 0; 764a6c9808aSBALATON Zoltan j = 5; 765a6c9808aSBALATON Zoltan for (i = 0; i < PCI_NUM_REGIONS; i++) { 766a6c9808aSBALATON Zoltan if (!d->io_regions[i].size) { 767a6c9808aSBALATON Zoltan continue; 768a6c9808aSBALATON Zoltan } 769a6c9808aSBALATON Zoltan cells[j] = cpu_to_be32(d->devfn << 8 | (PCI_BASE_ADDRESS_0 + i * 4)); 770a6c9808aSBALATON Zoltan if (d->io_regions[i].type & PCI_BASE_ADDRESS_SPACE_IO) { 771a6c9808aSBALATON Zoltan cells[j] |= cpu_to_be32(1 << 24); 772a6c9808aSBALATON Zoltan } else { 773a6c9808aSBALATON Zoltan cells[j] |= cpu_to_be32(2 << 24); 774a6c9808aSBALATON Zoltan if (d->io_regions[i].type & PCI_BASE_ADDRESS_MEM_PREFETCH) { 775a6c9808aSBALATON Zoltan cells[j] |= cpu_to_be32(4 << 28); 776a6c9808aSBALATON Zoltan } 777a6c9808aSBALATON Zoltan } 778a6c9808aSBALATON Zoltan cells[j + 1] = 0; 779a6c9808aSBALATON Zoltan cells[j + 2] = 0; 780a6c9808aSBALATON Zoltan cells[j + 3] = cpu_to_be32(d->io_regions[i].size >> 32); 781a6c9808aSBALATON Zoltan cells[j + 4] = cpu_to_be32(d->io_regions[i].size); 782a6c9808aSBALATON Zoltan j += 5; 783a6c9808aSBALATON Zoltan } 784a6c9808aSBALATON Zoltan qemu_fdt_setprop(fi->fdt, node->str, "reg", cells, j * sizeof(cells[0])); 785a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fi->fdt, node->str, "name", name ?: pn); 786a6c9808aSBALATON Zoltan if (pci_get_byte(&d->config[PCI_INTERRUPT_PIN])) { 787a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, node->str, "interrupts", 788a6c9808aSBALATON Zoltan pci_get_byte(&d->config[PCI_INTERRUPT_PIN])); 789a6c9808aSBALATON Zoltan } 790a6c9808aSBALATON Zoltan /* Pegasos2 firmware has subsystem-id amd subsystem-vendor-id swapped */ 791a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, node->str, "subsystem-vendor-id", 792a6c9808aSBALATON Zoltan pci_get_word(&d->config[PCI_SUBSYSTEM_ID])); 793a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, node->str, "subsystem-id", 794a6c9808aSBALATON Zoltan pci_get_word(&d->config[PCI_SUBSYSTEM_VENDOR_ID])); 795a6c9808aSBALATON Zoltan cells[0] = pci_get_long(&d->config[PCI_CLASS_REVISION]); 796a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, node->str, "class-code", cells[0] >> 8); 797e7dfb29eSDavid Gibson qemu_fdt_setprop_cell(fi->fdt, node->str, "revision-id", cells[0] & 0xff); 798a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, node->str, "device-id", 799a6c9808aSBALATON Zoltan pci_get_word(&d->config[PCI_DEVICE_ID])); 800a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fi->fdt, node->str, "vendor-id", 801a6c9808aSBALATON Zoltan pci_get_word(&d->config[PCI_VENDOR_ID])); 802a6c9808aSBALATON Zoltan 803a6c9808aSBALATON Zoltan g_string_free(node, TRUE); 804a6c9808aSBALATON Zoltan } 805a6c9808aSBALATON Zoltan 806a6c9808aSBALATON Zoltan static void *build_fdt(MachineState *machine, int *fdt_size) 807a6c9808aSBALATON Zoltan { 808a6c9808aSBALATON Zoltan Pegasos2MachineState *pm = PEGASOS2_MACHINE(machine); 809a6c9808aSBALATON Zoltan PowerPCCPU *cpu = pm->cpu; 810a6c9808aSBALATON Zoltan PCIBus *pci_bus; 811a6c9808aSBALATON Zoltan FDTInfo fi; 812a6c9808aSBALATON Zoltan uint32_t cells[16]; 813a6c9808aSBALATON Zoltan void *fdt = create_device_tree(fdt_size); 814a6c9808aSBALATON Zoltan 815a6c9808aSBALATON Zoltan fi.fdt = fdt; 816a6c9808aSBALATON Zoltan 817a6c9808aSBALATON Zoltan /* root node */ 818a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/", "CODEGEN,description", 819a6c9808aSBALATON Zoltan "Pegasos CHRP PowerPC System"); 820a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/", "CODEGEN,board", "Pegasos2"); 821a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/", "CODEGEN,vendor", "bplan GmbH"); 822a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/", "revision", "2B"); 823a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/", "model", "Pegasos2"); 824a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/", "device_type", "chrp"); 825a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 1); 826a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/", "name", "bplan,Pegasos2"); 827a6c9808aSBALATON Zoltan 828a6c9808aSBALATON Zoltan /* pci@c0000000 */ 829a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fdt, "/pci@c0000000"); 830a6c9808aSBALATON Zoltan cells[0] = 0; 831a6c9808aSBALATON Zoltan cells[1] = 0; 832a6c9808aSBALATON Zoltan qemu_fdt_setprop(fdt, "/pci@c0000000", "bus-range", 833a6c9808aSBALATON Zoltan cells, 2 * sizeof(cells[0])); 834a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/pci@c0000000", "pci-bridge-number", 1); 835a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(PCI0_MEM_BASE); 836a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(PCI0_MEM_SIZE); 837a6c9808aSBALATON Zoltan qemu_fdt_setprop(fdt, "/pci@c0000000", "reg", cells, 2 * sizeof(cells[0])); 838a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(0x01000000); 839a6c9808aSBALATON Zoltan cells[1] = 0; 840a6c9808aSBALATON Zoltan cells[2] = 0; 841a6c9808aSBALATON Zoltan cells[3] = cpu_to_be32(PCI0_IO_BASE); 842a6c9808aSBALATON Zoltan cells[4] = 0; 843a6c9808aSBALATON Zoltan cells[5] = cpu_to_be32(PCI0_IO_SIZE); 844a6c9808aSBALATON Zoltan cells[6] = cpu_to_be32(0x02000000); 845a6c9808aSBALATON Zoltan cells[7] = 0; 846a6c9808aSBALATON Zoltan cells[8] = cpu_to_be32(PCI0_MEM_BASE); 847a6c9808aSBALATON Zoltan cells[9] = cpu_to_be32(PCI0_MEM_BASE); 848a6c9808aSBALATON Zoltan cells[10] = 0; 849a6c9808aSBALATON Zoltan cells[11] = cpu_to_be32(PCI0_MEM_SIZE); 850a6c9808aSBALATON Zoltan qemu_fdt_setprop(fdt, "/pci@c0000000", "ranges", 851a6c9808aSBALATON Zoltan cells, 12 * sizeof(cells[0])); 852a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/pci@c0000000", "#size-cells", 2); 853a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/pci@c0000000", "#address-cells", 3); 854a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/pci@c0000000", "device_type", "pci"); 855a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/pci@c0000000", "name", "pci"); 856a6c9808aSBALATON Zoltan 857a6c9808aSBALATON Zoltan fi.path = "/pci@c0000000"; 858a6c9808aSBALATON Zoltan pci_bus = mv64361_get_pci_bus(pm->mv, 0); 859a6c9808aSBALATON Zoltan pci_for_each_device_reverse(pci_bus, 0, add_pci_device, &fi); 860a6c9808aSBALATON Zoltan 861a6c9808aSBALATON Zoltan /* pci@80000000 */ 862a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fdt, "/pci@80000000"); 863a6c9808aSBALATON Zoltan cells[0] = 0; 864a6c9808aSBALATON Zoltan cells[1] = 0; 865a6c9808aSBALATON Zoltan qemu_fdt_setprop(fdt, "/pci@80000000", "bus-range", 866a6c9808aSBALATON Zoltan cells, 2 * sizeof(cells[0])); 867a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/pci@80000000", "pci-bridge-number", 0); 868a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(PCI1_MEM_BASE); 869a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(PCI1_MEM_SIZE); 870a6c9808aSBALATON Zoltan qemu_fdt_setprop(fdt, "/pci@80000000", "reg", cells, 2 * sizeof(cells[0])); 871a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/pci@80000000", "8259-interrupt-acknowledge", 872a6c9808aSBALATON Zoltan 0xf1000cb4); 873a6c9808aSBALATON Zoltan cells[0] = cpu_to_be32(0x01000000); 874a6c9808aSBALATON Zoltan cells[1] = 0; 875a6c9808aSBALATON Zoltan cells[2] = 0; 876a6c9808aSBALATON Zoltan cells[3] = cpu_to_be32(PCI1_IO_BASE); 877a6c9808aSBALATON Zoltan cells[4] = 0; 878a6c9808aSBALATON Zoltan cells[5] = cpu_to_be32(PCI1_IO_SIZE); 879a6c9808aSBALATON Zoltan cells[6] = cpu_to_be32(0x02000000); 880a6c9808aSBALATON Zoltan cells[7] = 0; 881a6c9808aSBALATON Zoltan cells[8] = cpu_to_be32(PCI1_MEM_BASE); 882a6c9808aSBALATON Zoltan cells[9] = cpu_to_be32(PCI1_MEM_BASE); 883a6c9808aSBALATON Zoltan cells[10] = 0; 884a6c9808aSBALATON Zoltan cells[11] = cpu_to_be32(PCI1_MEM_SIZE); 885a6c9808aSBALATON Zoltan qemu_fdt_setprop(fdt, "/pci@80000000", "ranges", 886a6c9808aSBALATON Zoltan cells, 12 * sizeof(cells[0])); 887a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/pci@80000000", "#size-cells", 2); 888a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/pci@80000000", "#address-cells", 3); 889a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/pci@80000000", "device_type", "pci"); 890a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/pci@80000000", "name", "pci"); 891a6c9808aSBALATON Zoltan 892a6c9808aSBALATON Zoltan fi.path = "/pci@80000000"; 893a6c9808aSBALATON Zoltan pci_bus = mv64361_get_pci_bus(pm->mv, 1); 894a6c9808aSBALATON Zoltan pci_for_each_device_reverse(pci_bus, 0, add_pci_device, &fi); 895a6c9808aSBALATON Zoltan 896a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fdt, "/failsafe"); 897a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/failsafe", "device_type", "serial"); 898a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/failsafe", "name", "failsafe"); 899a6c9808aSBALATON Zoltan 9005f2eb049SBALATON Zoltan qemu_fdt_add_subnode(fdt, "/rtas"); 9015f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "system-reboot", RTAS_SYSTEM_REBOOT); 9025f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "hibernate", RTAS_HIBERNATE); 9035f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "suspend", RTAS_SUSPEND); 9045f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "power-off", RTAS_POWER_OFF); 9055f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "set-indicator", RTAS_SET_INDICATOR); 9065f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "display-character", 9075f2eb049SBALATON Zoltan RTAS_DISPLAY_CHARACTER); 9085f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "write-pci-config", 9095f2eb049SBALATON Zoltan RTAS_WRITE_PCI_CONFIG); 9105f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "read-pci-config", 9115f2eb049SBALATON Zoltan RTAS_READ_PCI_CONFIG); 9125f2eb049SBALATON Zoltan /* Pegasos2 firmware misspells check-exception and guests use that */ 9135f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "check-execption", 9145f2eb049SBALATON Zoltan RTAS_CHECK_EXCEPTION); 9155f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "event-scan", RTAS_EVENT_SCAN); 9165f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "set-time-of-day", 9175f2eb049SBALATON Zoltan RTAS_SET_TIME_OF_DAY); 9185f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "get-time-of-day", 9195f2eb049SBALATON Zoltan RTAS_GET_TIME_OF_DAY); 9205f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "nvram-store", RTAS_NVRAM_STORE); 9215f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "nvram-fetch", RTAS_NVRAM_FETCH); 9225f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "restart-rtas", RTAS_RESTART_RTAS); 9235f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-error-log-max", 0); 9245f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-event-scan-rate", 0); 9255f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-display-device", 0); 9265f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-size", 20); 9275f2eb049SBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-version", 1); 9285f2eb049SBALATON Zoltan 929a6c9808aSBALATON Zoltan /* cpus */ 930a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fdt, "/cpus"); 931a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/cpus", "#cpus", 1); 932a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 1); 933a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0); 934a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/cpus", "name", "cpus"); 935a6c9808aSBALATON Zoltan 936a6c9808aSBALATON Zoltan /* FIXME Get CPU name from CPU object */ 937a6c9808aSBALATON Zoltan const char *cp = "/cpus/PowerPC,G4"; 938a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fdt, cp); 939a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "l2cr", 0); 940a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "d-cache-size", 0x8000); 941a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "d-cache-block-size", 942a6c9808aSBALATON Zoltan cpu->env.dcache_line_size); 943a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "d-cache-line-size", 944a6c9808aSBALATON Zoltan cpu->env.dcache_line_size); 945a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "i-cache-size", 0x8000); 946a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "i-cache-block-size", 947a6c9808aSBALATON Zoltan cpu->env.icache_line_size); 948a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "i-cache-line-size", 949a6c9808aSBALATON Zoltan cpu->env.icache_line_size); 950a6c9808aSBALATON Zoltan if (cpu->env.id_tlbs) { 951a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "i-tlb-sets", cpu->env.nb_ways); 952a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "i-tlb-size", cpu->env.tlb_per_way); 953a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "d-tlb-sets", cpu->env.nb_ways); 954a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "d-tlb-size", cpu->env.tlb_per_way); 955a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "tlb-split", ""); 956a6c9808aSBALATON Zoltan } 957a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "tlb-sets", cpu->env.nb_ways); 958a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "tlb-size", cpu->env.nb_tlb); 959a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "state", "running"); 960a6c9808aSBALATON Zoltan if (cpu->env.insns_flags & PPC_ALTIVEC) { 961a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "altivec", ""); 962a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "data-streams", ""); 963a6c9808aSBALATON Zoltan } 964a6c9808aSBALATON Zoltan /* 965a6c9808aSBALATON Zoltan * FIXME What flags do data-streams, external-control and 966a6c9808aSBALATON Zoltan * performance-monitor depend on? 967a6c9808aSBALATON Zoltan */ 968a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "external-control", ""); 969a6c9808aSBALATON Zoltan if (cpu->env.insns_flags & PPC_FLOAT_FSQRT) { 970a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "general-purpose", ""); 971a6c9808aSBALATON Zoltan } 972a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "performance-monitor", ""); 973a6c9808aSBALATON Zoltan if (cpu->env.insns_flags & PPC_FLOAT_FRES) { 974a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "graphics", ""); 975a6c9808aSBALATON Zoltan } 976a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "reservation-granule-size", 4); 977a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "timebase-frequency", 978a6c9808aSBALATON Zoltan cpu->env.tb_env->tb_freq); 979a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "bus-frequency", BUS_FREQ_HZ); 980a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "clock-frequency", BUS_FREQ_HZ * 7.5); 981a6c9808aSBALATON Zoltan qemu_fdt_setprop_cell(fdt, cp, "cpu-version", cpu->env.spr[SPR_PVR]); 982a6c9808aSBALATON Zoltan cells[0] = 0; 983a6c9808aSBALATON Zoltan cells[1] = 0; 984a6c9808aSBALATON Zoltan qemu_fdt_setprop(fdt, cp, "reg", cells, 2 * sizeof(cells[0])); 985a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "device_type", "cpu"); 986a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, cp, "name", strrchr(cp, '/') + 1); 987a6c9808aSBALATON Zoltan 988a6c9808aSBALATON Zoltan /* memory */ 989a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fdt, "/memory@0"); 990a6c9808aSBALATON Zoltan cells[0] = 0; 991a6c9808aSBALATON Zoltan cells[1] = cpu_to_be32(machine->ram_size); 992a6c9808aSBALATON Zoltan qemu_fdt_setprop(fdt, "/memory@0", "reg", cells, 2 * sizeof(cells[0])); 993a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/memory@0", "device_type", "memory"); 994a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/memory@0", "name", "memory"); 995a6c9808aSBALATON Zoltan 996a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fdt, "/chosen"); 997ebe0e9bbSBALATON Zoltan if (pm->initrd_addr && pm->initrd_size) { 998ebe0e9bbSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", 999ebe0e9bbSBALATON Zoltan pm->initrd_addr + pm->initrd_size); 1000ebe0e9bbSBALATON Zoltan qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", 1001ebe0e9bbSBALATON Zoltan pm->initrd_addr); 1002ebe0e9bbSBALATON Zoltan } 1003a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", 1004a6c9808aSBALATON Zoltan machine->kernel_cmdline ?: ""); 1005a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/chosen", "name", "chosen"); 1006a6c9808aSBALATON Zoltan 1007a6c9808aSBALATON Zoltan qemu_fdt_add_subnode(fdt, "/openprom"); 1008a6c9808aSBALATON Zoltan qemu_fdt_setprop_string(fdt, "/openprom", "model", "Pegasos2,1.1"); 1009a6c9808aSBALATON Zoltan 1010a6c9808aSBALATON Zoltan return fdt; 1011a6c9808aSBALATON Zoltan } 1012