2 * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
4 * Copyright (c) 2018-2020 BALATON Zoltan
6 * This work is licensed under the GNU GPL license version 2 or later.
10 #include "qemu/osdep.h"
11 #include "qemu-common.h"
12 #include "qemu/units.h"
13 #include "qapi/error.h"
15 #include "hw/ppc/ppc.h"
16 #include "hw/sysbus.h"
17 #include "hw/pci/pci_host.h"
19 #include "hw/pci-host/mv64361.h"
20 #include "hw/isa/vt82c686.h"
21 #include "hw/ide/pci.h"
22 #include "hw/i2c/smbus_eeprom.h"
23 #include "hw/qdev-properties.h"
24 #include "sysemu/reset.h"
25 #include "hw/boards.h"
26 #include "hw/loader.h"
27 #include "hw/fw-path-provider.h"
30 #include "qemu/error-report.h"
31 #include "sysemu/kvm.h"
33 #include "exec/address-spaces.h"
35 #include "qemu/datadir.h"
36 #include "sysemu/device_tree.h"
38 #define PROM_FILENAME "pegasos2.rom"
39 #define PROM_ADDR 0xfff00000
40 #define PROM_SIZE 0x80000
42 #define BUS_FREQ_HZ 133333333
44 static void pegasos2_cpu_reset(void *opaque
)
46 PowerPCCPU
*cpu
= opaque
;
49 cpu
->env
.spr
[SPR_HID1
] = 7ULL << 28;
52 static void pegasos2_init(MachineState
*machine
)
54 PowerPCCPU
*cpu
= NULL
;
55 MemoryRegion
*rom
= g_new(MemoryRegion
, 1);
60 const char *fwname
= machine
->firmware
?: PROM_FILENAME
;
66 cpu
= POWERPC_CPU(cpu_create(machine
->cpu_type
));
67 if (PPC_INPUT(&cpu
->env
) != PPC_FLAGS_INPUT_6xx
) {
68 error_report("Incompatible CPU, only 6xx bus supported");
72 /* Set time-base frequency */
73 cpu_ppc_tb_init(&cpu
->env
, BUS_FREQ_HZ
/ 4);
74 qemu_register_reset(pegasos2_cpu_reset
, cpu
);
77 memory_region_add_subregion(get_system_memory(), 0, machine
->ram
);
79 /* allocate and load firmware */
80 filename
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, fwname
);
82 error_report("Could not find firmware '%s'", fwname
);
85 memory_region_init_rom(rom
, NULL
, "pegasos2.rom", PROM_SIZE
, &error_fatal
);
86 memory_region_add_subregion(get_system_memory(), PROM_ADDR
, rom
);
87 sz
= load_elf(filename
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, 1,
88 PPC_ELF_MACHINE
, 0, 0);
90 sz
= load_image_targphys(filename
, PROM_ADDR
, PROM_SIZE
);
92 if (sz
<= 0 || sz
> PROM_SIZE
) {
93 error_report("Could not load firmware '%s'", filename
);
98 /* Marvell Discovery II system controller */
99 mv
= DEVICE(sysbus_create_simple(TYPE_MV64361
, -1,
100 ((qemu_irq
*)cpu
->env
.irq_inputs
)[PPC6xx_INPUT_INT
]));
101 pci_bus
= mv64361_get_pci_bus(mv
, 1);
103 /* VIA VT8231 South Bridge (multifunction PCI device) */
104 /* VT8231 function 0: PCI-to-ISA Bridge */
105 dev
= pci_create_simple_multifunction(pci_bus
, PCI_DEVFN(12, 0), true,
107 qdev_connect_gpio_out(DEVICE(dev
), 0,
108 qdev_get_gpio_in_named(mv
, "gpp", 31));
110 /* VT8231 function 1: IDE Controller */
111 dev
= pci_create_simple(pci_bus
, PCI_DEVFN(12, 1), "via-ide");
112 pci_ide_create_devs(dev
);
114 /* VT8231 function 2-3: USB Ports */
115 pci_create_simple(pci_bus
, PCI_DEVFN(12, 2), "vt82c686b-usb-uhci");
116 pci_create_simple(pci_bus
, PCI_DEVFN(12, 3), "vt82c686b-usb-uhci");
118 /* VT8231 function 4: Power Management Controller */
119 dev
= pci_create_simple(pci_bus
, PCI_DEVFN(12, 4), TYPE_VT8231_PM
);
120 i2c_bus
= I2C_BUS(qdev_get_child_bus(DEVICE(dev
), "i2c"));
121 spd_data
= spd_data_generate(DDR
, machine
->ram_size
);
122 smbus_eeprom_init_one(i2c_bus
, 0x57, spd_data
);
124 /* VT8231 function 5-6: AC97 Audio & Modem */
125 pci_create_simple(pci_bus
, PCI_DEVFN(12, 5), TYPE_VIA_AC97
);
126 pci_create_simple(pci_bus
, PCI_DEVFN(12, 6), TYPE_VIA_MC97
);
128 /* other PC hardware */
129 pci_vga_init(pci_bus
);
132 static void pegasos2_machine(MachineClass
*mc
)
134 mc
->desc
= "Genesi/bPlan Pegasos II";
135 mc
->init
= pegasos2_init
;
136 mc
->block_default_type
= IF_IDE
;
137 mc
->default_boot_order
= "cd";
138 mc
->default_display
= "std";
139 mc
->default_cpu_type
= POWERPC_CPU_TYPE_NAME("7400_v2.9");
140 mc
->default_ram_id
= "pegasos2.ram";
141 mc
->default_ram_size
= 512 * MiB
;
144 DEFINE_MACHINE("pegasos2", pegasos2_machine
)