]> git.proxmox.com Git - mirror_qemu.git/blame - hw/hppa/machine.c
hppa: Add emulation of Artist graphics
[mirror_qemu.git] / hw / hppa / machine.c
CommitLineData
813dff13
HD
1/*
2 * QEMU HPPA hardware system emulator.
3 * Copyright 2018 Helge Deller <deller@gmx.de>
4 */
5
6#include "qemu/osdep.h"
7#include "qemu-common.h"
8#include "cpu.h"
813dff13
HD
9#include "elf.h"
10#include "hw/loader.h"
11#include "hw/boards.h"
12#include "qemu/error-report.h"
71e8a915 13#include "sysemu/reset.h"
813dff13 14#include "sysemu/sysemu.h"
bcdb9064 15#include "hw/rtc/mc146818rtc.h"
813dff13
HD
16#include "hw/ide.h"
17#include "hw/timer/i8254.h"
18#include "hw/char/serial.h"
376b8519 19#include "hw/net/lasi_82596.h"
070e9a1e 20#include "hppa_sys.h"
c108cc59 21#include "qemu/units.h"
813dff13 22#include "qapi/error.h"
852c27e2 23#include "net/net.h"
691cbbad 24#include "qemu/log.h"
813dff13 25
a72bd606
HD
26#define MAX_IDE_BUS 2
27
28static ISABus *hppa_isa_bus(void)
29{
30 ISABus *isa_bus;
31 qemu_irq *isa_irqs;
32 MemoryRegion *isa_region;
33
34 isa_region = g_new(MemoryRegion, 1);
35 memory_region_init_io(isa_region, NULL, &hppa_pci_ignore_ops,
36 NULL, "isa-io", 0x800);
37 memory_region_add_subregion(get_system_memory(), IDE_HPA,
38 isa_region);
39
40 isa_bus = isa_bus_new(NULL, get_system_memory(), isa_region,
41 &error_abort);
42 isa_irqs = i8259_init(isa_bus,
43 /* qemu_allocate_irq(dino_set_isa_irq, s, 0)); */
44 NULL);
45 isa_bus_irqs(isa_bus, isa_irqs);
46
47 return isa_bus;
48}
49
50static uint64_t cpu_hppa_to_phys(void *opaque, uint64_t addr)
51{
52 addr &= (0x10000000 - 1);
53 return addr;
54}
55
56static HPPACPU *cpu[HPPA_MAX_CPUS];
57static uint64_t firmware_entry;
813dff13
HD
58
59static void machine_hppa_init(MachineState *machine)
60{
a72bd606
HD
61 const char *kernel_filename = machine->kernel_filename;
62 const char *kernel_cmdline = machine->kernel_cmdline;
63 const char *initrd_filename = machine->initrd_filename;
877eb21d 64 DeviceState *dev;
a72bd606
HD
65 PCIBus *pci_bus;
66 ISABus *isa_bus;
67 qemu_irq rtc_irq, serial_irq;
68 char *firmware_filename;
69 uint64_t firmware_low, firmware_high;
70 long size;
71 uint64_t kernel_entry = 0, kernel_low, kernel_high;
72 MemoryRegion *addr_space = get_system_memory();
73 MemoryRegion *rom_region;
74 MemoryRegion *ram_region;
75 MemoryRegion *cpu_region;
76 long i;
33decbd2 77 unsigned int smp_cpus = machine->smp.cpus;
4765384c 78 SysBusDevice *s;
a72bd606
HD
79
80 ram_size = machine->ram_size;
81
82 /* Create CPUs. */
83 for (i = 0; i < smp_cpus; i++) {
266a880e 84 char *name = g_strdup_printf("cpu%ld-io-eir", i);
a72bd606
HD
85 cpu[i] = HPPA_CPU(cpu_create(machine->cpu_type));
86
87 cpu_region = g_new(MemoryRegion, 1);
88 memory_region_init_io(cpu_region, OBJECT(cpu[i]), &hppa_io_eir_ops,
266a880e 89 cpu[i], name, 4);
a72bd606
HD
90 memory_region_add_subregion(addr_space, CPU_HPA + i * 0x1000,
91 cpu_region);
266a880e 92 g_free(name);
a72bd606
HD
93 }
94
95 /* Limit main memory. */
96 if (ram_size > FIRMWARE_START) {
97 machine->ram_size = ram_size = FIRMWARE_START;
98 }
99
100 /* Main memory region. */
101 ram_region = g_new(MemoryRegion, 1);
102 memory_region_allocate_system_memory(ram_region, OBJECT(machine),
103 "ram", ram_size);
104 memory_region_add_subregion(addr_space, 0, ram_region);
105
376b8519
HD
106 /* Init Lasi chip */
107 lasi_init(addr_space);
108
a72bd606
HD
109 /* Init Dino (PCI host bus chip). */
110 pci_bus = dino_init(addr_space, &rtc_irq, &serial_irq);
111 assert(pci_bus);
112
113 /* Create ISA bus. */
114 isa_bus = hppa_isa_bus();
115 assert(isa_bus);
116
117 /* Realtime clock, used by firmware for PDC_TOD call. */
118 mc146818_rtc_init(isa_bus, 2000, rtc_irq);
119
120 /* Serial code setup. */
9bca0edb 121 if (serial_hd(0)) {
a72bd606
HD
122 uint32_t addr = DINO_UART_HPA + 0x800;
123 serial_mm_init(addr_space, addr, 0, serial_irq,
9bca0edb 124 115200, serial_hd(0), DEVICE_BIG_ENDIAN);
a72bd606
HD
125 }
126
127 /* SCSI disk setup. */
877eb21d
MCA
128 dev = DEVICE(pci_create_simple(pci_bus, -1, "lsi53c895a"));
129 lsi53c8xx_handle_legacy_cmdline(dev);
a72bd606 130
4765384c
SS
131 /* Graphics setup. */
132 if (machine->enable_graphics && vga_interface_type != VGA_NONE) {
133 dev = qdev_create(NULL, "artist");
134 qdev_init_nofail(dev);
135 s = SYS_BUS_DEVICE(dev);
136 sysbus_mmio_map(s, 0, LASI_GFX_HPA);
137 sysbus_mmio_map(s, 1, ARTIST_FB_ADDR);
138 }
139
0e6de551 140 /* Network setup. */
a72bd606 141 for (i = 0; i < nb_nics; i++) {
376b8519 142 if (!enable_lasi_lan()) {
0e6de551 143 pci_nic_init_nofail(&nd_table[i], pci_bus, "tulip", NULL);
376b8519 144 }
a72bd606
HD
145 }
146
147 /* Load firmware. Given that this is not "real" firmware,
148 but one explicitly written for the emulation, we might as
149 well load it directly from an ELF image. */
150 firmware_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
151 bios_name ? bios_name :
152 "hppa-firmware.img");
153 if (firmware_filename == NULL) {
154 error_report("no firmware provided");
155 exit(1);
156 }
157
4366e1db
LM
158 size = load_elf(firmware_filename, NULL, NULL, NULL,
159 &firmware_entry, &firmware_low, &firmware_high,
a72bd606
HD
160 true, EM_PARISC, 0, 0);
161
162 /* Unfortunately, load_elf sign-extends reading elf32. */
163 firmware_entry = (target_ureg)firmware_entry;
164 firmware_low = (target_ureg)firmware_low;
165 firmware_high = (target_ureg)firmware_high;
166
167 if (size < 0) {
168 error_report("could not load firmware '%s'", firmware_filename);
169 exit(1);
170 }
691cbbad
RH
171 qemu_log_mask(CPU_LOG_PAGE, "Firmware loaded at 0x%08" PRIx64
172 "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ".\n",
173 firmware_low, firmware_high, firmware_entry);
a72bd606
HD
174 if (firmware_low < ram_size || firmware_high >= FIRMWARE_END) {
175 error_report("Firmware overlaps with memory or IO space");
176 exit(1);
177 }
178 g_free(firmware_filename);
179
180 rom_region = g_new(MemoryRegion, 1);
6a3a2e82
IM
181 memory_region_init_ram(rom_region, NULL, "firmware",
182 (FIRMWARE_END - FIRMWARE_START), &error_fatal);
a72bd606
HD
183 memory_region_add_subregion(addr_space, FIRMWARE_START, rom_region);
184
185 /* Load kernel */
186 if (kernel_filename) {
4366e1db 187 size = load_elf(kernel_filename, NULL, &cpu_hppa_to_phys,
a72bd606
HD
188 NULL, &kernel_entry, &kernel_low, &kernel_high,
189 true, EM_PARISC, 0, 0);
190
191 /* Unfortunately, load_elf sign-extends reading elf32. */
192 kernel_entry = (target_ureg) cpu_hppa_to_phys(NULL, kernel_entry);
193 kernel_low = (target_ureg)kernel_low;
194 kernel_high = (target_ureg)kernel_high;
195
196 if (size < 0) {
197 error_report("could not load kernel '%s'", kernel_filename);
198 exit(1);
199 }
691cbbad
RH
200 qemu_log_mask(CPU_LOG_PAGE, "Kernel loaded at 0x%08" PRIx64
201 "-0x%08" PRIx64 ", entry at 0x%08" PRIx64
c108cc59
PMD
202 ", size %" PRIu64 " kB\n",
203 kernel_low, kernel_high, kernel_entry, size / KiB);
a72bd606
HD
204
205 if (kernel_cmdline) {
206 cpu[0]->env.gr[24] = 0x4000;
207 pstrcpy_targphys("cmdline", cpu[0]->env.gr[24],
208 TARGET_PAGE_SIZE, kernel_cmdline);
209 }
210
211 if (initrd_filename) {
212 ram_addr_t initrd_base;
f3839fda 213 int64_t initrd_size;
a72bd606
HD
214
215 initrd_size = get_image_size(initrd_filename);
216 if (initrd_size < 0) {
217 error_report("could not load initial ram disk '%s'",
218 initrd_filename);
219 exit(1);
220 }
221
222 /* Load the initrd image high in memory.
223 Mirror the algorithm used by palo:
224 (1) Due to sign-extension problems and PDC,
225 put the initrd no higher than 1G.
226 (2) Reserve 64k for stack. */
c108cc59
PMD
227 initrd_base = MIN(ram_size, 1 * GiB);
228 initrd_base = initrd_base - 64 * KiB;
a72bd606
HD
229 initrd_base = (initrd_base - initrd_size) & TARGET_PAGE_MASK;
230
231 if (initrd_base < kernel_high) {
232 error_report("kernel and initial ram disk too large!");
233 exit(1);
234 }
235
236 load_image_targphys(initrd_filename, initrd_base, initrd_size);
237 cpu[0]->env.gr[23] = initrd_base;
238 cpu[0]->env.gr[22] = initrd_base + initrd_size;
239 }
240 }
241
242 if (!kernel_entry) {
243 /* When booting via firmware, tell firmware if we want interactive
244 * mode (kernel_entry=1), and to boot from CD (gr[24]='d')
245 * or hard disc * (gr[24]='c').
246 */
247 kernel_entry = boot_menu ? 1 : 0;
248 cpu[0]->env.gr[24] = machine->boot_order[0];
249 }
250
251 /* We jump to the firmware entry routine and pass the
252 * various parameters in registers. After firmware initialization,
253 * firmware will start the Linux kernel with ramdisk and cmdline.
254 */
255 cpu[0]->env.gr[26] = ram_size;
256 cpu[0]->env.gr[25] = kernel_entry;
257
258 /* tell firmware how many SMP CPUs to present in inventory table */
259 cpu[0]->env.gr[21] = smp_cpus;
813dff13
HD
260}
261
a0628599 262static void hppa_machine_reset(MachineState *ms)
a72bd606 263{
33decbd2 264 unsigned int smp_cpus = ms->smp.cpus;
a72bd606
HD
265 int i;
266
267 qemu_devices_reset();
268
269 /* Start all CPUs at the firmware entry point.
270 * Monarch CPU will initialize firmware, secondary CPUs
271 * will enter a small idle look and wait for rendevouz. */
272 for (i = 0; i < smp_cpus; i++) {
273 cpu_set_pc(CPU(cpu[i]), firmware_entry);
274 cpu[i]->env.gr[5] = CPU_HPA + i * 0x1000;
275 }
276
277 /* already initialized by machine_hppa_init()? */
278 if (cpu[0]->env.gr[26] == ram_size) {
279 return;
280 }
281
282 cpu[0]->env.gr[26] = ram_size;
283 cpu[0]->env.gr[25] = 0; /* no firmware boot menu */
284 cpu[0]->env.gr[24] = 'c';
285 /* gr22/gr23 unused, no initrd while reboot. */
286 cpu[0]->env.gr[21] = smp_cpus;
287}
288
289
813dff13
HD
290static void machine_hppa_machine_init(MachineClass *mc)
291{
292 mc->desc = "HPPA generic machine";
a72bd606 293 mc->default_cpu_type = TYPE_HPPA_CPU;
813dff13 294 mc->init = machine_hppa_init;
a72bd606 295 mc->reset = hppa_machine_reset;
813dff13 296 mc->block_default_type = IF_SCSI;
a72bd606
HD
297 mc->max_cpus = HPPA_MAX_CPUS;
298 mc->default_cpus = 1;
813dff13 299 mc->is_default = 1;
d23b6caa 300 mc->default_ram_size = 512 * MiB;
813dff13
HD
301 mc->default_boot_order = "cd";
302}
303
304DEFINE_MACHINE("hppa", machine_hppa_machine_init)