]> git.proxmox.com Git - mirror_qemu.git/blame - hw/hppa/machine.c
hw/core/machine: Constify MachineClass::valid_cpu_types[]
[mirror_qemu.git] / hw / hppa / machine.c
CommitLineData
813dff13
HD
1/*
2 * QEMU HPPA hardware system emulator.
a536f564
HD
3 * (C) Copyright 2018-2023 Helge Deller <deller@gmx.de>
4 *
5 * This work is licensed under the GNU GPL license version 2 or later.
813dff13
HD
6 */
7
8#include "qemu/osdep.h"
2c65db5e 9#include "qemu/datadir.h"
813dff13 10#include "cpu.h"
813dff13
HD
11#include "elf.h"
12#include "hw/loader.h"
813dff13 13#include "qemu/error-report.h"
71e8a915 14#include "sysemu/reset.h"
813dff13 15#include "sysemu/sysemu.h"
b28c4a64 16#include "sysemu/runstate.h"
bcdb9064 17#include "hw/rtc/mc146818rtc.h"
813dff13
HD
18#include "hw/timer/i8254.h"
19#include "hw/char/serial.h"
9701e569 20#include "hw/char/parallel.h"
134ba73f 21#include "hw/intc/i8259.h"
d26c575c 22#include "hw/input/lasips2.h"
376b8519 23#include "hw/net/lasi_82596.h"
4a4554c6 24#include "hw/nmi.h"
2ed4faa0 25#include "hw/usb.h"
134ba73f 26#include "hw/pci/pci.h"
7df6f751 27#include "hw/pci/pci_device.h"
2ed4faa0 28#include "hw/pci-host/astro.h"
0db9350e 29#include "hw/pci-host/dino.h"
45f569a1 30#include "hw/misc/lasi.h"
148da670 31#include "hppa_hardware.h"
c108cc59 32#include "qemu/units.h"
813dff13 33#include "qapi/error.h"
852c27e2 34#include "net/net.h"
691cbbad 35#include "qemu/log.h"
813dff13 36
f88131d9 37#define MIN_SEABIOS_HPPA_VERSION 12 /* require at least this fw version */
28b71a2e 38
e274d2a7
HD
39/* Power button address at &PAGE0->pad[4] */
40#define HPA_POWER_BUTTON (0x40 + 4 * sizeof(uint32_t))
b28c4a64 41
932befaa
MCA
42#define enable_lasi_lan() 0
43
7df6f751 44static DeviceState *lasi_dev;
932befaa 45
b28c4a64
HD
46static void hppa_powerdown_req(Notifier *n, void *opaque)
47{
48 hwaddr soft_power_reg = HPA_POWER_BUTTON;
49 uint32_t val;
50
51 val = ldl_be_phys(&address_space_memory, soft_power_reg);
52 if ((val >> 8) == 0) {
53 /* immediately shut down when under hardware control */
54 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
55 return;
56 }
57
58 /* clear bit 31 to indicate that the power switch was pressed. */
59 val &= ~1;
60 stl_be_phys(&address_space_memory, soft_power_reg, val);
61}
62
63static Notifier hppa_system_powerdown_notifier = {
64 .notify = hppa_powerdown_req
65};
66
28f5332a
MCA
67/* Fallback for unassigned PCI I/O operations. Avoids MCHK. */
68static uint64_t ignore_read(void *opaque, hwaddr addr, unsigned size)
69{
70 return 0;
71}
72
73static void ignore_write(void *opaque, hwaddr addr, uint64_t v, unsigned size)
74{
75}
76
77static const MemoryRegionOps hppa_pci_ignore_ops = {
78 .read = ignore_read,
79 .write = ignore_write,
80 .endianness = DEVICE_BIG_ENDIAN,
81 .valid = {
82 .min_access_size = 1,
83 .max_access_size = 8,
84 },
85 .impl = {
86 .min_access_size = 1,
87 .max_access_size = 8,
88 },
89};
b28c4a64 90
f386a16e 91static ISABus *hppa_isa_bus(hwaddr addr)
a72bd606
HD
92{
93 ISABus *isa_bus;
94 qemu_irq *isa_irqs;
95 MemoryRegion *isa_region;
96
97 isa_region = g_new(MemoryRegion, 1);
98 memory_region_init_io(isa_region, NULL, &hppa_pci_ignore_ops,
99 NULL, "isa-io", 0x800);
f386a16e 100 memory_region_add_subregion(get_system_memory(), addr, isa_region);
a72bd606
HD
101
102 isa_bus = isa_bus_new(NULL, get_system_memory(), isa_region,
103 &error_abort);
a536f564 104 isa_irqs = i8259_init(isa_bus, NULL);
7067887e 105 isa_bus_register_input_irqs(isa_bus, isa_irqs);
a72bd606
HD
106
107 return isa_bus;
108}
109
e2c41ee5
HD
110/*
111 * Helper functions to emulate RTC clock and DebugOutputPort
112 */
113static time_t rtc_ref;
114
115static uint64_t io_cpu_read(void *opaque, hwaddr addr, unsigned size)
116{
117 uint64_t val = 0;
118
119 switch (addr) {
120 case 0: /* RTC clock */
121 val = time(NULL);
122 val += rtc_ref;
123 break;
124 case 8: /* DebugOutputPort */
125 return 0xe9; /* readback */
126 }
127 return val;
128}
129
130static void io_cpu_write(void *opaque, hwaddr addr,
131 uint64_t val, unsigned size)
132{
133 unsigned char ch;
134 Chardev *debugout;
135
136 switch (addr) {
137 case 0: /* RTC clock */
138 rtc_ref = val - time(NULL);
139 break;
140 case 8: /* DebugOutputPort */
141 ch = val;
142 debugout = serial_hd(0);
143 if (debugout) {
144 qemu_chr_fe_write_all(debugout->be, &ch, 1);
145 } else {
146 fprintf(stderr, "%c", ch);
147 }
148 break;
149 }
150}
151
152static const MemoryRegionOps hppa_io_helper_ops = {
153 .read = io_cpu_read,
154 .write = io_cpu_write,
155 .endianness = DEVICE_BIG_ENDIAN,
156 .valid = {
157 .min_access_size = 1,
158 .max_access_size = 8,
159 },
160 .impl = {
161 .min_access_size = 1,
162 .max_access_size = 8,
163 },
164};
165
f386a16e 166typedef uint64_t TranslateFn(void *opaque, uint64_t addr);
e2c41ee5 167
f386a16e 168static uint64_t linux_kernel_virt_to_phys(void *opaque, uint64_t addr)
a72bd606
HD
169{
170 addr &= (0x10000000 - 1);
171 return addr;
172}
173
f386a16e
RH
174static uint64_t translate_pa10(void *dummy, uint64_t addr)
175{
176 return (uint32_t)addr;
177}
178
179static uint64_t translate_pa20(void *dummy, uint64_t addr)
180{
181 return hppa_abs_to_phys_pa2_w0(addr);
182}
183
a72bd606
HD
184static HPPACPU *cpu[HPPA_MAX_CPUS];
185static uint64_t firmware_entry;
813dff13 186
32ff8bf2
HD
187static void fw_cfg_boot_set(void *opaque, const char *boot_device,
188 Error **errp)
189{
190 fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
191}
192
f386a16e
RH
193static FWCfgState *create_fw_cfg(MachineState *ms, PCIBus *pci_bus,
194 hwaddr addr)
28b71a2e
HD
195{
196 FWCfgState *fw_cfg;
197 uint64_t val;
069d2966 198 const char qemu_version[] = QEMU_VERSION;
bcd4dd4c 199 MachineClass *mc = MACHINE_GET_CLASS(ms);
9cf2112b 200 int btlb_entries = HPPA_BTLB_ENTRIES(&cpu[0]->env);
bcd4dd4c 201 int len;
28b71a2e 202
f386a16e 203 fw_cfg = fw_cfg_init_mem(addr, addr + 4);
28b71a2e
HD
204 fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, ms->smp.cpus);
205 fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, HPPA_MAX_CPUS);
bfdf22bc 206 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, ms->ram_size);
28b71a2e
HD
207
208 val = cpu_to_le64(MIN_SEABIOS_HPPA_VERSION);
209 fw_cfg_add_file(fw_cfg, "/etc/firmware-min-version",
210 g_memdup(&val, sizeof(val)), sizeof(val));
211
9cf2112b 212 val = cpu_to_le64(HPPA_TLB_ENTRIES - btlb_entries);
df5c6a50
HD
213 fw_cfg_add_file(fw_cfg, "/etc/cpu/tlb_entries",
214 g_memdup(&val, sizeof(val)), sizeof(val));
215
9cf2112b 216 val = cpu_to_le64(btlb_entries);
bcd4dd4c
HD
217 fw_cfg_add_file(fw_cfg, "/etc/cpu/btlb_entries",
218 g_memdup(&val, sizeof(val)), sizeof(val));
219
220 len = strlen(mc->name) + 1;
221 fw_cfg_add_file(fw_cfg, "/etc/hppa/machine",
222 g_memdup(mc->name, len), len);
223
b28c4a64 224 val = cpu_to_le64(HPA_POWER_BUTTON);
bcd4dd4c
HD
225 fw_cfg_add_file(fw_cfg, "/etc/hppa/power-button-addr",
226 g_memdup(&val, sizeof(val)), sizeof(val));
227
e2c41ee5
HD
228 val = cpu_to_le64(CPU_HPA + 16);
229 fw_cfg_add_file(fw_cfg, "/etc/hppa/rtc-addr",
230 g_memdup(&val, sizeof(val)), sizeof(val));
231
bcd4dd4c
HD
232 val = cpu_to_le64(CPU_HPA + 24);
233 fw_cfg_add_file(fw_cfg, "/etc/hppa/DebugOutputPort",
b28c4a64
HD
234 g_memdup(&val, sizeof(val)), sizeof(val));
235
97ec4d21 236 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ms->boot_config.order[0]);
32ff8bf2
HD
237 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
238
069d2966
HD
239 fw_cfg_add_file(fw_cfg, "/etc/qemu-version",
240 g_memdup(qemu_version, sizeof(qemu_version)),
241 sizeof(qemu_version));
242
bcd4dd4c
HD
243 fw_cfg_add_extra_pci_roots(pci_bus, fw_cfg);
244
28b71a2e
HD
245 return fw_cfg;
246}
247
e881e3c8
MCA
248static LasiState *lasi_init(void)
249{
250 DeviceState *dev;
251
252 dev = qdev_new(TYPE_LASI_CHIP);
253 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
254
255 return LASI_CHIP(dev);
256}
257
0d068996
MCA
258static DinoState *dino_init(MemoryRegion *addr_space)
259{
260 DeviceState *dev;
261
262 dev = qdev_new(TYPE_DINO_PCI_HOST_BRIDGE);
263 object_property_set_link(OBJECT(dev), "memory-as", OBJECT(addr_space),
264 &error_fatal);
265 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
266
267 return DINO_PCI_HOST_BRIDGE(dev);
268}
269
7df6f751
HD
270/*
271 * Step 1: Create CPUs and Memory
272 */
f386a16e 273static TranslateFn *machine_HP_common_init_cpus(MachineState *machine)
813dff13 274{
a72bd606 275 MemoryRegion *addr_space = get_system_memory();
33decbd2 276 unsigned int smp_cpus = machine->smp.cpus;
f386a16e
RH
277 TranslateFn *translate;
278 MemoryRegion *cpu_region;
a72bd606 279
a72bd606 280 /* Create CPUs. */
f386a16e 281 for (unsigned int i = 0; i < smp_cpus; i++) {
a72bd606 282 cpu[i] = HPPA_CPU(cpu_create(machine->cpu_type));
f386a16e
RH
283 }
284
285 /*
286 * For now, treat address layout as if PSW_W is clear.
287 * TODO: create a proper hppa64 board model and load elf64 firmware.
288 */
289 if (hppa_is_pa20(&cpu[0]->env)) {
290 translate = translate_pa20;
291 } else {
292 translate = translate_pa10;
293 }
294
295 for (unsigned int i = 0; i < smp_cpus; i++) {
296 g_autofree char *name = g_strdup_printf("cpu%u-io-eir", i);
a72bd606
HD
297
298 cpu_region = g_new(MemoryRegion, 1);
299 memory_region_init_io(cpu_region, OBJECT(cpu[i]), &hppa_io_eir_ops,
266a880e 300 cpu[i], name, 4);
f386a16e
RH
301 memory_region_add_subregion(addr_space,
302 translate(NULL, CPU_HPA + i * 0x1000),
a72bd606
HD
303 cpu_region);
304 }
305
e2c41ee5
HD
306 /* RTC and DebugOutputPort on CPU #0 */
307 cpu_region = g_new(MemoryRegion, 1);
308 memory_region_init_io(cpu_region, OBJECT(cpu[0]), &hppa_io_helper_ops,
309 cpu[0], "cpu0-io-rtc", 2 * sizeof(uint64_t));
f386a16e
RH
310 memory_region_add_subregion(addr_space, translate(NULL, CPU_HPA + 16),
311 cpu_region);
e2c41ee5 312
a72bd606 313 /* Main memory region. */
b7746b11
PMD
314 if (machine->ram_size > 3 * GiB) {
315 error_report("RAM size is currently restricted to 3GB");
316 exit(EXIT_FAILURE);
317 }
7c59c1e0 318 memory_region_add_subregion_overlap(addr_space, 0, machine->ram, -1);
f386a16e
RH
319
320 return translate;
7df6f751 321}
7c59c1e0 322
7df6f751
HD
323/*
324 * Last creation step: Add SCSI discs, NICs, graphics & load firmware
325 */
f386a16e
RH
326static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
327 TranslateFn *translate)
7df6f751
HD
328{
329 const char *kernel_filename = machine->kernel_filename;
330 const char *kernel_cmdline = machine->kernel_cmdline;
331 const char *initrd_filename = machine->initrd_filename;
332 MachineClass *mc = MACHINE_GET_CLASS(machine);
333 DeviceState *dev;
2ed4faa0 334 PCIDevice *pci_dev;
7df6f751
HD
335 char *firmware_filename;
336 uint64_t firmware_low, firmware_high;
337 long size;
338 uint64_t kernel_entry = 0, kernel_low, kernel_high;
339 MemoryRegion *addr_space = get_system_memory();
340 MemoryRegion *rom_region;
341 long i;
342 unsigned int smp_cpus = machine->smp.cpus;
343 SysBusDevice *s;
28b71a2e 344
a72bd606 345 /* SCSI disk setup. */
877eb21d
MCA
346 dev = DEVICE(pci_create_simple(pci_bus, -1, "lsi53c895a"));
347 lsi53c8xx_handle_legacy_cmdline(dev);
a72bd606 348
4765384c
SS
349 /* Graphics setup. */
350 if (machine->enable_graphics && vga_interface_type != VGA_NONE) {
f9bcb2d6 351 vga_interface_created = true;
3e80f690 352 dev = qdev_new("artist");
4765384c 353 s = SYS_BUS_DEVICE(dev);
3c6ef471 354 sysbus_realize_and_unref(s, &error_fatal);
f386a16e
RH
355 sysbus_mmio_map(s, 0, translate(NULL, LASI_GFX_HPA));
356 sysbus_mmio_map(s, 1, translate(NULL, ARTIST_FB_ADDR));
4765384c
SS
357 }
358
0e6de551 359 /* Network setup. */
c3c3fe47 360 if (enable_lasi_lan()) {
f386a16e 361 lasi_82596_init(addr_space, translate(NULL, LASI_LAN_HPA),
c3c3fe47
MCA
362 qdev_get_gpio_in(lasi_dev, LASI_IRQ_LAN_HPA));
363 }
364
a72bd606 365 for (i = 0; i < nb_nics; i++) {
376b8519 366 if (!enable_lasi_lan()) {
9f8981a9 367 pci_nic_init_nofail(&nd_table[i], pci_bus, mc->default_nic, NULL);
376b8519 368 }
a72bd606
HD
369 }
370
2ed4faa0
HD
371 /* BMC board: HP Powerbar SP2 Diva (with console only) */
372 pci_dev = pci_new(-1, "pci-serial");
373 if (!lasi_dev) {
374 /* bind default keyboard/serial to Diva card */
375 qdev_prop_set_chr(DEVICE(pci_dev), "chardev", serial_hd(0));
376 }
377 qdev_prop_set_uint8(DEVICE(pci_dev), "prog_if", 0);
378 pci_realize_and_unref(pci_dev, pci_bus, &error_fatal);
379 pci_config_set_vendor_id(pci_dev->config, PCI_VENDOR_ID_HP);
380 pci_config_set_device_id(pci_dev->config, 0x1048);
381 pci_set_word(&pci_dev->config[PCI_SUBSYSTEM_VENDOR_ID], PCI_VENDOR_ID_HP);
382 pci_set_word(&pci_dev->config[PCI_SUBSYSTEM_ID], 0x1227); /* Powerbar */
383
384 /* create a second serial PCI card when running Astro */
385 if (!lasi_dev) {
386 pci_dev = pci_new(-1, "pci-serial-4x");
387 qdev_prop_set_chr(DEVICE(pci_dev), "chardev1", serial_hd(1));
388 qdev_prop_set_chr(DEVICE(pci_dev), "chardev2", serial_hd(2));
389 qdev_prop_set_chr(DEVICE(pci_dev), "chardev3", serial_hd(3));
390 qdev_prop_set_chr(DEVICE(pci_dev), "chardev4", serial_hd(4));
391 pci_realize_and_unref(pci_dev, pci_bus, &error_fatal);
392 }
393
394 /* create USB OHCI controller for USB keyboard & mouse on Astro machines */
395 if (!lasi_dev && machine->enable_graphics) {
396 pci_create_simple(pci_bus, -1, "pci-ohci");
397 usb_create_simple(usb_bus_find(-1), "usb-kbd");
398 usb_create_simple(usb_bus_find(-1), "usb-mouse");
399 }
400
b28c4a64
HD
401 /* register power switch emulation */
402 qemu_register_powerdown_notifier(&hppa_system_powerdown_notifier);
403
7df6f751 404 /* fw_cfg configuration interface */
f386a16e 405 create_fw_cfg(machine, pci_bus, translate(NULL, FW_CFG_IO_BASE));
7df6f751 406
a72bd606
HD
407 /* Load firmware. Given that this is not "real" firmware,
408 but one explicitly written for the emulation, we might as
409 well load it directly from an ELF image. */
410 firmware_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
b57e3e97 411 machine->firmware ?: "hppa-firmware.img");
a72bd606
HD
412 if (firmware_filename == NULL) {
413 error_report("no firmware provided");
414 exit(1);
415 }
416
f386a16e 417 size = load_elf(firmware_filename, NULL, translate, NULL,
6cdda0ff 418 &firmware_entry, &firmware_low, &firmware_high, NULL,
a72bd606
HD
419 true, EM_PARISC, 0, 0);
420
a72bd606
HD
421 if (size < 0) {
422 error_report("could not load firmware '%s'", firmware_filename);
423 exit(1);
424 }
691cbbad
RH
425 qemu_log_mask(CPU_LOG_PAGE, "Firmware loaded at 0x%08" PRIx64
426 "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ".\n",
427 firmware_low, firmware_high, firmware_entry);
f386a16e
RH
428 if (firmware_low < translate(NULL, FIRMWARE_START) ||
429 firmware_high >= translate(NULL, FIRMWARE_END)) {
a72bd606
HD
430 error_report("Firmware overlaps with memory or IO space");
431 exit(1);
432 }
433 g_free(firmware_filename);
434
435 rom_region = g_new(MemoryRegion, 1);
6a3a2e82
IM
436 memory_region_init_ram(rom_region, NULL, "firmware",
437 (FIRMWARE_END - FIRMWARE_START), &error_fatal);
f386a16e
RH
438 memory_region_add_subregion(addr_space,
439 translate(NULL, FIRMWARE_START), rom_region);
a72bd606
HD
440
441 /* Load kernel */
442 if (kernel_filename) {
f386a16e 443 size = load_elf(kernel_filename, NULL, linux_kernel_virt_to_phys,
6cdda0ff 444 NULL, &kernel_entry, &kernel_low, &kernel_high, NULL,
a72bd606
HD
445 true, EM_PARISC, 0, 0);
446
f386a16e 447 kernel_entry = linux_kernel_virt_to_phys(NULL, kernel_entry);
a72bd606
HD
448
449 if (size < 0) {
450 error_report("could not load kernel '%s'", kernel_filename);
451 exit(1);
452 }
691cbbad
RH
453 qemu_log_mask(CPU_LOG_PAGE, "Kernel loaded at 0x%08" PRIx64
454 "-0x%08" PRIx64 ", entry at 0x%08" PRIx64
c108cc59
PMD
455 ", size %" PRIu64 " kB\n",
456 kernel_low, kernel_high, kernel_entry, size / KiB);
a72bd606
HD
457
458 if (kernel_cmdline) {
459 cpu[0]->env.gr[24] = 0x4000;
460 pstrcpy_targphys("cmdline", cpu[0]->env.gr[24],
461 TARGET_PAGE_SIZE, kernel_cmdline);
462 }
463
464 if (initrd_filename) {
465 ram_addr_t initrd_base;
f3839fda 466 int64_t initrd_size;
a72bd606
HD
467
468 initrd_size = get_image_size(initrd_filename);
469 if (initrd_size < 0) {
470 error_report("could not load initial ram disk '%s'",
471 initrd_filename);
472 exit(1);
473 }
474
475 /* Load the initrd image high in memory.
476 Mirror the algorithm used by palo:
477 (1) Due to sign-extension problems and PDC,
478 put the initrd no higher than 1G.
479 (2) Reserve 64k for stack. */
bfdf22bc 480 initrd_base = MIN(machine->ram_size, 1 * GiB);
c108cc59 481 initrd_base = initrd_base - 64 * KiB;
a72bd606
HD
482 initrd_base = (initrd_base - initrd_size) & TARGET_PAGE_MASK;
483
484 if (initrd_base < kernel_high) {
485 error_report("kernel and initial ram disk too large!");
486 exit(1);
487 }
488
489 load_image_targphys(initrd_filename, initrd_base, initrd_size);
490 cpu[0]->env.gr[23] = initrd_base;
491 cpu[0]->env.gr[22] = initrd_base + initrd_size;
492 }
493 }
494
495 if (!kernel_entry) {
496 /* When booting via firmware, tell firmware if we want interactive
497 * mode (kernel_entry=1), and to boot from CD (gr[24]='d')
498 * or hard disc * (gr[24]='c').
499 */
97ec4d21
PB
500 kernel_entry = machine->boot_config.has_menu ? machine->boot_config.menu : 0;
501 cpu[0]->env.gr[24] = machine->boot_config.order[0];
a72bd606
HD
502 }
503
504 /* We jump to the firmware entry routine and pass the
505 * various parameters in registers. After firmware initialization,
506 * firmware will start the Linux kernel with ramdisk and cmdline.
507 */
bfdf22bc 508 cpu[0]->env.gr[26] = machine->ram_size;
a72bd606
HD
509 cpu[0]->env.gr[25] = kernel_entry;
510
511 /* tell firmware how many SMP CPUs to present in inventory table */
512 cpu[0]->env.gr[21] = smp_cpus;
24576007
HD
513
514 /* tell firmware fw_cfg port */
515 cpu[0]->env.gr[19] = FW_CFG_IO_BASE;
813dff13
HD
516}
517
7df6f751
HD
518/*
519 * Create HP B160L workstation
520 */
521static void machine_HP_B160L_init(MachineState *machine)
522{
523 DeviceState *dev, *dino_dev;
524 MemoryRegion *addr_space = get_system_memory();
f386a16e 525 TranslateFn *translate;
7df6f751
HD
526 ISABus *isa_bus;
527 PCIBus *pci_bus;
528
529 /* Create CPUs and RAM. */
f386a16e 530 translate = machine_HP_common_init_cpus(machine);
7df6f751 531
3d1611bf
HD
532 if (hppa_is_pa20(&cpu[0]->env)) {
533 error_report("The HP B160L workstation requires a 32-bit "
534 "CPU. Use '-machine C3700' instead.");
535 exit(1);
536 }
537
7df6f751
HD
538 /* Init Lasi chip */
539 lasi_dev = DEVICE(lasi_init());
f386a16e 540 memory_region_add_subregion(addr_space, translate(NULL, LASI_HPA),
7df6f751
HD
541 sysbus_mmio_get_region(
542 SYS_BUS_DEVICE(lasi_dev), 0));
543
544 /* Init Dino (PCI host bus chip). */
545 dino_dev = DEVICE(dino_init(addr_space));
f386a16e 546 memory_region_add_subregion(addr_space, translate(NULL, DINO_HPA),
7df6f751
HD
547 sysbus_mmio_get_region(
548 SYS_BUS_DEVICE(dino_dev), 0));
549 pci_bus = PCI_BUS(qdev_get_child_bus(dino_dev, "pci"));
550 assert(pci_bus);
551
552 /* Create ISA bus, needed for PS/2 kbd/mouse port emulation */
f386a16e 553 isa_bus = hppa_isa_bus(translate(NULL, IDE_HPA));
7df6f751
HD
554 assert(isa_bus);
555
556 /* Serial ports: Lasi and Dino use a 7.272727 MHz clock. */
f386a16e 557 serial_mm_init(addr_space, translate(NULL, LASI_UART_HPA + 0x800), 0,
7df6f751
HD
558 qdev_get_gpio_in(lasi_dev, LASI_IRQ_UART_HPA), 7272727 / 16,
559 serial_hd(0), DEVICE_BIG_ENDIAN);
560
f386a16e 561 serial_mm_init(addr_space, translate(NULL, DINO_UART_HPA + 0x800), 0,
7df6f751
HD
562 qdev_get_gpio_in(dino_dev, DINO_IRQ_RS232INT), 7272727 / 16,
563 serial_hd(1), DEVICE_BIG_ENDIAN);
564
565 /* Parallel port */
f386a16e 566 parallel_mm_init(addr_space, translate(NULL, LASI_LPT_HPA + 0x800), 0,
7df6f751
HD
567 qdev_get_gpio_in(lasi_dev, LASI_IRQ_LAN_HPA),
568 parallel_hds[0]);
569
570 /* PS/2 Keyboard/Mouse */
571 dev = qdev_new(TYPE_LASIPS2);
572 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
573 sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
574 qdev_get_gpio_in(lasi_dev, LASI_IRQ_PS2KBD_HPA));
f386a16e
RH
575 memory_region_add_subregion(addr_space,
576 translate(NULL, LASI_PS2KBD_HPA),
7df6f751
HD
577 sysbus_mmio_get_region(SYS_BUS_DEVICE(dev),
578 0));
f386a16e
RH
579 memory_region_add_subregion(addr_space,
580 translate(NULL, LASI_PS2KBD_HPA + 0x100),
7df6f751
HD
581 sysbus_mmio_get_region(SYS_BUS_DEVICE(dev),
582 1));
583
584 /* Add SCSI discs, NICs, graphics & load firmware */
f386a16e 585 machine_HP_common_init_tail(machine, pci_bus, translate);
7df6f751
HD
586}
587
2ed4faa0
HD
588static AstroState *astro_init(void)
589{
590 DeviceState *dev;
591
592 dev = qdev_new(TYPE_ASTRO_CHIP);
593 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
594
595 return ASTRO_CHIP(dev);
596}
597
598/*
599 * Create HP C3700 workstation
600 */
601static void machine_HP_C3700_init(MachineState *machine)
602{
603 PCIBus *pci_bus;
604 AstroState *astro;
605 DeviceState *astro_dev;
606 MemoryRegion *addr_space = get_system_memory();
f386a16e 607 TranslateFn *translate;
2ed4faa0
HD
608
609 /* Create CPUs and RAM. */
f386a16e 610 translate = machine_HP_common_init_cpus(machine);
2ed4faa0 611
3d1611bf
HD
612 if (!hppa_is_pa20(&cpu[0]->env)) {
613 error_report("The HP C3000 workstation requires a 64-bit CPU. "
614 "Use '-machine B160L' instead.");
615 exit(1);
616 }
617
2ed4faa0
HD
618 /* Init Astro and the Elroys (PCI host bus chips). */
619 astro = astro_init();
620 astro_dev = DEVICE(astro);
f386a16e 621 memory_region_add_subregion(addr_space, translate(NULL, ASTRO_HPA),
2ed4faa0
HD
622 sysbus_mmio_get_region(
623 SYS_BUS_DEVICE(astro_dev), 0));
624 pci_bus = PCI_BUS(qdev_get_child_bus(DEVICE(astro->elroy[0]), "pci"));
625 assert(pci_bus);
626
627 /* Add SCSI discs, NICs, graphics & load firmware */
f386a16e 628 machine_HP_common_init_tail(machine, pci_bus, translate);
2ed4faa0
HD
629}
630
7966d70f 631static void hppa_machine_reset(MachineState *ms, ShutdownCause reason)
a72bd606 632{
33decbd2 633 unsigned int smp_cpus = ms->smp.cpus;
a72bd606
HD
634 int i;
635
7966d70f 636 qemu_devices_reset(reason);
a72bd606
HD
637
638 /* Start all CPUs at the firmware entry point.
639 * Monarch CPU will initialize firmware, secondary CPUs
50ba97e9 640 * will enter a small idle loop and wait for rendevouz. */
a72bd606 641 for (i = 0; i < smp_cpus; i++) {
50ba97e9
HD
642 CPUState *cs = CPU(cpu[i]);
643
644 cpu_set_pc(cs, firmware_entry);
645 cpu[i]->env.psw = PSW_Q;
a72bd606 646 cpu[i]->env.gr[5] = CPU_HPA + i * 0x1000;
50ba97e9
HD
647
648 cs->exception_index = -1;
649 cs->halted = 0;
a72bd606
HD
650 }
651
652 /* already initialized by machine_hppa_init()? */
bfdf22bc 653 if (cpu[0]->env.gr[26] == ms->ram_size) {
a72bd606
HD
654 return;
655 }
656
bfdf22bc 657 cpu[0]->env.gr[26] = ms->ram_size;
a72bd606
HD
658 cpu[0]->env.gr[25] = 0; /* no firmware boot menu */
659 cpu[0]->env.gr[24] = 'c';
660 /* gr22/gr23 unused, no initrd while reboot. */
661 cpu[0]->env.gr[21] = smp_cpus;
24576007
HD
662 /* tell firmware fw_cfg port */
663 cpu[0]->env.gr[19] = FW_CFG_IO_BASE;
a72bd606
HD
664}
665
4a4554c6
HD
666static void hppa_nmi(NMIState *n, int cpu_index, Error **errp)
667{
668 CPUState *cs;
669
670 CPU_FOREACH(cs) {
671 cpu_interrupt(cs, CPU_INTERRUPT_NMI);
672 }
673}
a72bd606 674
7df6f751 675static void HP_B160L_machine_init_class_init(ObjectClass *oc, void *data)
813dff13 676{
790a4428
GS
677 static const char * const valid_cpu_types[] = {
678 TYPE_HPPA_CPU,
679 NULL
680 };
42cc2bf6
MCA
681 MachineClass *mc = MACHINE_CLASS(oc);
682 NMIClass *nc = NMI_CLASS(oc);
683
7df6f751 684 mc->desc = "HP B160L workstation";
a72bd606 685 mc->default_cpu_type = TYPE_HPPA_CPU;
790a4428 686 mc->valid_cpu_types = valid_cpu_types;
7df6f751 687 mc->init = machine_HP_B160L_init;
a72bd606 688 mc->reset = hppa_machine_reset;
813dff13 689 mc->block_default_type = IF_SCSI;
a72bd606
HD
690 mc->max_cpus = HPPA_MAX_CPUS;
691 mc->default_cpus = 1;
ea0ac7f6 692 mc->is_default = true;
d23b6caa 693 mc->default_ram_size = 512 * MiB;
813dff13 694 mc->default_boot_order = "cd";
7c59c1e0 695 mc->default_ram_id = "ram";
9f8981a9 696 mc->default_nic = "tulip";
813dff13 697
4a4554c6
HD
698 nc->nmi_monitor_handler = hppa_nmi;
699}
700
7df6f751
HD
701static const TypeInfo HP_B160L_machine_init_typeinfo = {
702 .name = MACHINE_TYPE_NAME("B160L"),
c165905c 703 .parent = TYPE_MACHINE,
7df6f751 704 .class_init = HP_B160L_machine_init_class_init,
4a4554c6
HD
705 .interfaces = (InterfaceInfo[]) {
706 { TYPE_NMI },
707 { }
708 },
709};
710
2ed4faa0
HD
711static void HP_C3700_machine_init_class_init(ObjectClass *oc, void *data)
712{
790a4428
GS
713 static const char * const valid_cpu_types[] = {
714 TYPE_HPPA64_CPU,
715 NULL
716 };
2ed4faa0
HD
717 MachineClass *mc = MACHINE_CLASS(oc);
718 NMIClass *nc = NMI_CLASS(oc);
719
720 mc->desc = "HP C3700 workstation";
fd9b04bf 721 mc->default_cpu_type = TYPE_HPPA64_CPU;
790a4428 722 mc->valid_cpu_types = valid_cpu_types;
2ed4faa0
HD
723 mc->init = machine_HP_C3700_init;
724 mc->reset = hppa_machine_reset;
725 mc->block_default_type = IF_SCSI;
726 mc->max_cpus = HPPA_MAX_CPUS;
727 mc->default_cpus = 1;
728 mc->is_default = false;
729 mc->default_ram_size = 1024 * MiB;
730 mc->default_boot_order = "cd";
731 mc->default_ram_id = "ram";
732 mc->default_nic = "tulip";
733
734 nc->nmi_monitor_handler = hppa_nmi;
735}
736
737static const TypeInfo HP_C3700_machine_init_typeinfo = {
738 .name = MACHINE_TYPE_NAME("C3700"),
739 .parent = TYPE_MACHINE,
740 .class_init = HP_C3700_machine_init_class_init,
741 .interfaces = (InterfaceInfo[]) {
742 { TYPE_NMI },
743 { }
744 },
745};
746
297d4103 747static void hppa_machine_init_register_types(void)
4a4554c6 748{
7df6f751 749 type_register_static(&HP_B160L_machine_init_typeinfo);
2ed4faa0 750 type_register_static(&HP_C3700_machine_init_typeinfo);
4a4554c6
HD
751}
752
297d4103 753type_init(hppa_machine_init_register_types)