1813dff13SHelge Deller /* 2813dff13SHelge Deller * QEMU HPPA hardware system emulator. 3813dff13SHelge Deller * Copyright 2018 Helge Deller <deller@gmx.de> 4813dff13SHelge Deller */ 5813dff13SHelge Deller 6813dff13SHelge Deller #include "qemu/osdep.h" 72c65db5eSPaolo Bonzini #include "qemu/datadir.h" 8813dff13SHelge Deller #include "cpu.h" 9813dff13SHelge Deller #include "elf.h" 10813dff13SHelge Deller #include "hw/loader.h" 11813dff13SHelge Deller #include "qemu/error-report.h" 1271e8a915SMarkus Armbruster #include "sysemu/reset.h" 13813dff13SHelge Deller #include "sysemu/sysemu.h" 14b28c4a64SHelge Deller #include "sysemu/runstate.h" 15bcdb9064SPhilippe Mathieu-Daudé #include "hw/rtc/mc146818rtc.h" 16813dff13SHelge Deller #include "hw/timer/i8254.h" 17813dff13SHelge Deller #include "hw/char/serial.h" 189701e569SMark Cave-Ayland #include "hw/char/parallel.h" 19134ba73fSMark Cave-Ayland #include "hw/intc/i8259.h" 20d26c575cSMark Cave-Ayland #include "hw/input/lasips2.h" 21376b8519SHelge Deller #include "hw/net/lasi_82596.h" 224a4554c6SHelge Deller #include "hw/nmi.h" 23134ba73fSMark Cave-Ayland #include "hw/pci/pci.h" 240db9350eSMark Cave-Ayland #include "hw/pci-host/dino.h" 2545f569a1SMark Cave-Ayland #include "hw/misc/lasi.h" 26148da670SMark Cave-Ayland #include "hppa_hardware.h" 27c108cc59SPhilippe Mathieu-Daudé #include "qemu/units.h" 28813dff13SHelge Deller #include "qapi/error.h" 29852c27e2SPaolo Bonzini #include "net/net.h" 30691cbbadSRichard Henderson #include "qemu/log.h" 31e07c4f44SPhilippe Mathieu-Daudé #include "net/net.h" 32813dff13SHelge Deller 33a72bd606SHelge Deller #define MAX_IDE_BUS 2 34a72bd606SHelge Deller 3528b71a2eSHelge Deller #define MIN_SEABIOS_HPPA_VERSION 1 /* require at least this fw version */ 3628b71a2eSHelge Deller 37b28c4a64SHelge Deller #define HPA_POWER_BUTTON (FIRMWARE_END - 0x10) 38b28c4a64SHelge Deller 39932befaaSMark Cave-Ayland #define enable_lasi_lan() 0 40932befaaSMark Cave-Ayland 41932befaaSMark Cave-Ayland 42b28c4a64SHelge Deller static void hppa_powerdown_req(Notifier *n, void *opaque) 43b28c4a64SHelge Deller { 44b28c4a64SHelge Deller hwaddr soft_power_reg = HPA_POWER_BUTTON; 45b28c4a64SHelge Deller uint32_t val; 46b28c4a64SHelge Deller 47b28c4a64SHelge Deller val = ldl_be_phys(&address_space_memory, soft_power_reg); 48b28c4a64SHelge Deller if ((val >> 8) == 0) { 49b28c4a64SHelge Deller /* immediately shut down when under hardware control */ 50b28c4a64SHelge Deller qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); 51b28c4a64SHelge Deller return; 52b28c4a64SHelge Deller } 53b28c4a64SHelge Deller 54b28c4a64SHelge Deller /* clear bit 31 to indicate that the power switch was pressed. */ 55b28c4a64SHelge Deller val &= ~1; 56b28c4a64SHelge Deller stl_be_phys(&address_space_memory, soft_power_reg, val); 57b28c4a64SHelge Deller } 58b28c4a64SHelge Deller 59b28c4a64SHelge Deller static Notifier hppa_system_powerdown_notifier = { 60b28c4a64SHelge Deller .notify = hppa_powerdown_req 61b28c4a64SHelge Deller }; 62b28c4a64SHelge Deller 6328f5332aSMark Cave-Ayland /* Fallback for unassigned PCI I/O operations. Avoids MCHK. */ 6428f5332aSMark Cave-Ayland static uint64_t ignore_read(void *opaque, hwaddr addr, unsigned size) 6528f5332aSMark Cave-Ayland { 6628f5332aSMark Cave-Ayland return 0; 6728f5332aSMark Cave-Ayland } 6828f5332aSMark Cave-Ayland 6928f5332aSMark Cave-Ayland static void ignore_write(void *opaque, hwaddr addr, uint64_t v, unsigned size) 7028f5332aSMark Cave-Ayland { 7128f5332aSMark Cave-Ayland } 7228f5332aSMark Cave-Ayland 7328f5332aSMark Cave-Ayland static const MemoryRegionOps hppa_pci_ignore_ops = { 7428f5332aSMark Cave-Ayland .read = ignore_read, 7528f5332aSMark Cave-Ayland .write = ignore_write, 7628f5332aSMark Cave-Ayland .endianness = DEVICE_BIG_ENDIAN, 7728f5332aSMark Cave-Ayland .valid = { 7828f5332aSMark Cave-Ayland .min_access_size = 1, 7928f5332aSMark Cave-Ayland .max_access_size = 8, 8028f5332aSMark Cave-Ayland }, 8128f5332aSMark Cave-Ayland .impl = { 8228f5332aSMark Cave-Ayland .min_access_size = 1, 8328f5332aSMark Cave-Ayland .max_access_size = 8, 8428f5332aSMark Cave-Ayland }, 8528f5332aSMark Cave-Ayland }; 86b28c4a64SHelge Deller 87a72bd606SHelge Deller static ISABus *hppa_isa_bus(void) 88a72bd606SHelge Deller { 89a72bd606SHelge Deller ISABus *isa_bus; 90a72bd606SHelge Deller qemu_irq *isa_irqs; 91a72bd606SHelge Deller MemoryRegion *isa_region; 92a72bd606SHelge Deller 93a72bd606SHelge Deller isa_region = g_new(MemoryRegion, 1); 94a72bd606SHelge Deller memory_region_init_io(isa_region, NULL, &hppa_pci_ignore_ops, 95a72bd606SHelge Deller NULL, "isa-io", 0x800); 96a72bd606SHelge Deller memory_region_add_subregion(get_system_memory(), IDE_HPA, 97a72bd606SHelge Deller isa_region); 98a72bd606SHelge Deller 99a72bd606SHelge Deller isa_bus = isa_bus_new(NULL, get_system_memory(), isa_region, 100a72bd606SHelge Deller &error_abort); 101a72bd606SHelge Deller isa_irqs = i8259_init(isa_bus, 102a72bd606SHelge Deller /* qemu_allocate_irq(dino_set_isa_irq, s, 0)); */ 103a72bd606SHelge Deller NULL); 104a72bd606SHelge Deller isa_bus_irqs(isa_bus, isa_irqs); 105a72bd606SHelge Deller 106a72bd606SHelge Deller return isa_bus; 107a72bd606SHelge Deller } 108a72bd606SHelge Deller 109a72bd606SHelge Deller static uint64_t cpu_hppa_to_phys(void *opaque, uint64_t addr) 110a72bd606SHelge Deller { 111a72bd606SHelge Deller addr &= (0x10000000 - 1); 112a72bd606SHelge Deller return addr; 113a72bd606SHelge Deller } 114a72bd606SHelge Deller 115a72bd606SHelge Deller static HPPACPU *cpu[HPPA_MAX_CPUS]; 116a72bd606SHelge Deller static uint64_t firmware_entry; 117813dff13SHelge Deller 11832ff8bf2SHelge Deller static void fw_cfg_boot_set(void *opaque, const char *boot_device, 11932ff8bf2SHelge Deller Error **errp) 12032ff8bf2SHelge Deller { 12132ff8bf2SHelge Deller fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); 12232ff8bf2SHelge Deller } 12332ff8bf2SHelge Deller 12428b71a2eSHelge Deller static FWCfgState *create_fw_cfg(MachineState *ms) 12528b71a2eSHelge Deller { 12628b71a2eSHelge Deller FWCfgState *fw_cfg; 12728b71a2eSHelge Deller uint64_t val; 12828b71a2eSHelge Deller 12924576007SHelge Deller fw_cfg = fw_cfg_init_mem(FW_CFG_IO_BASE, FW_CFG_IO_BASE + 4); 13028b71a2eSHelge Deller fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, ms->smp.cpus); 13128b71a2eSHelge Deller fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, HPPA_MAX_CPUS); 132bfdf22bcSPaolo Bonzini fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, ms->ram_size); 13328b71a2eSHelge Deller 13428b71a2eSHelge Deller val = cpu_to_le64(MIN_SEABIOS_HPPA_VERSION); 13528b71a2eSHelge Deller fw_cfg_add_file(fw_cfg, "/etc/firmware-min-version", 13628b71a2eSHelge Deller g_memdup(&val, sizeof(val)), sizeof(val)); 13728b71a2eSHelge Deller 138df5c6a50SHelge Deller val = cpu_to_le64(HPPA_TLB_ENTRIES); 139df5c6a50SHelge Deller fw_cfg_add_file(fw_cfg, "/etc/cpu/tlb_entries", 140df5c6a50SHelge Deller g_memdup(&val, sizeof(val)), sizeof(val)); 141df5c6a50SHelge Deller 142df5c6a50SHelge Deller val = cpu_to_le64(HPPA_BTLB_ENTRIES); 143df5c6a50SHelge Deller fw_cfg_add_file(fw_cfg, "/etc/cpu/btlb_entries", 144df5c6a50SHelge Deller g_memdup(&val, sizeof(val)), sizeof(val)); 145df5c6a50SHelge Deller 146b28c4a64SHelge Deller val = cpu_to_le64(HPA_POWER_BUTTON); 147b28c4a64SHelge Deller fw_cfg_add_file(fw_cfg, "/etc/power-button-addr", 148b28c4a64SHelge Deller g_memdup(&val, sizeof(val)), sizeof(val)); 149b28c4a64SHelge Deller 15032ff8bf2SHelge Deller fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, ms->boot_order[0]); 15132ff8bf2SHelge Deller qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); 15232ff8bf2SHelge Deller 15328b71a2eSHelge Deller return fw_cfg; 15428b71a2eSHelge Deller } 15528b71a2eSHelge Deller 156e881e3c8SMark Cave-Ayland static LasiState *lasi_init(void) 157e881e3c8SMark Cave-Ayland { 158e881e3c8SMark Cave-Ayland DeviceState *dev; 159e881e3c8SMark Cave-Ayland 160e881e3c8SMark Cave-Ayland dev = qdev_new(TYPE_LASI_CHIP); 161e881e3c8SMark Cave-Ayland sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); 162e881e3c8SMark Cave-Ayland 163e881e3c8SMark Cave-Ayland return LASI_CHIP(dev); 164e881e3c8SMark Cave-Ayland } 165e881e3c8SMark Cave-Ayland 1660d068996SMark Cave-Ayland static DinoState *dino_init(MemoryRegion *addr_space) 1670d068996SMark Cave-Ayland { 1680d068996SMark Cave-Ayland DeviceState *dev; 1690d068996SMark Cave-Ayland 1700d068996SMark Cave-Ayland dev = qdev_new(TYPE_DINO_PCI_HOST_BRIDGE); 1710d068996SMark Cave-Ayland object_property_set_link(OBJECT(dev), "memory-as", OBJECT(addr_space), 1720d068996SMark Cave-Ayland &error_fatal); 1730d068996SMark Cave-Ayland sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); 1740d068996SMark Cave-Ayland 1750d068996SMark Cave-Ayland return DINO_PCI_HOST_BRIDGE(dev); 1760d068996SMark Cave-Ayland } 1770d068996SMark Cave-Ayland 178813dff13SHelge Deller static void machine_hppa_init(MachineState *machine) 179813dff13SHelge Deller { 180a72bd606SHelge Deller const char *kernel_filename = machine->kernel_filename; 181a72bd606SHelge Deller const char *kernel_cmdline = machine->kernel_cmdline; 182a72bd606SHelge Deller const char *initrd_filename = machine->initrd_filename; 1832683758cSMark Cave-Ayland DeviceState *dev, *dino_dev, *lasi_dev; 184a72bd606SHelge Deller PCIBus *pci_bus; 185a72bd606SHelge Deller ISABus *isa_bus; 186a72bd606SHelge Deller char *firmware_filename; 187a72bd606SHelge Deller uint64_t firmware_low, firmware_high; 188a72bd606SHelge Deller long size; 189a72bd606SHelge Deller uint64_t kernel_entry = 0, kernel_low, kernel_high; 190a72bd606SHelge Deller MemoryRegion *addr_space = get_system_memory(); 191a72bd606SHelge Deller MemoryRegion *rom_region; 192a72bd606SHelge Deller MemoryRegion *cpu_region; 193a72bd606SHelge Deller long i; 19433decbd2SLike Xu unsigned int smp_cpus = machine->smp.cpus; 1954765384cSSven Schnelle SysBusDevice *s; 196a72bd606SHelge Deller 197a72bd606SHelge Deller /* Create CPUs. */ 198a72bd606SHelge Deller for (i = 0; i < smp_cpus; i++) { 199266a880eSPaolo Bonzini char *name = g_strdup_printf("cpu%ld-io-eir", i); 200a72bd606SHelge Deller cpu[i] = HPPA_CPU(cpu_create(machine->cpu_type)); 201a72bd606SHelge Deller 202a72bd606SHelge Deller cpu_region = g_new(MemoryRegion, 1); 203a72bd606SHelge Deller memory_region_init_io(cpu_region, OBJECT(cpu[i]), &hppa_io_eir_ops, 204266a880eSPaolo Bonzini cpu[i], name, 4); 205a72bd606SHelge Deller memory_region_add_subregion(addr_space, CPU_HPA + i * 0x1000, 206a72bd606SHelge Deller cpu_region); 207266a880eSPaolo Bonzini g_free(name); 208813dff13SHelge Deller } 209813dff13SHelge Deller 210a72bd606SHelge Deller /* Main memory region. */ 211b7746b11SPhilippe Mathieu-Daudé if (machine->ram_size > 3 * GiB) { 212b7746b11SPhilippe Mathieu-Daudé error_report("RAM size is currently restricted to 3GB"); 213b7746b11SPhilippe Mathieu-Daudé exit(EXIT_FAILURE); 214b7746b11SPhilippe Mathieu-Daudé } 2157c59c1e0SIgor Mammedov memory_region_add_subregion_overlap(addr_space, 0, machine->ram, -1); 2167c59c1e0SIgor Mammedov 217a72bd606SHelge Deller 218376b8519SHelge Deller /* Init Lasi chip */ 219e881e3c8SMark Cave-Ayland lasi_dev = DEVICE(lasi_init()); 2202683758cSMark Cave-Ayland memory_region_add_subregion(addr_space, LASI_HPA, 2212683758cSMark Cave-Ayland sysbus_mmio_get_region( 2222683758cSMark Cave-Ayland SYS_BUS_DEVICE(lasi_dev), 0)); 223376b8519SHelge Deller 224a72bd606SHelge Deller /* Init Dino (PCI host bus chip). */ 22536f9bbdbSMark Cave-Ayland dino_dev = DEVICE(dino_init(addr_space)); 226efdb3ce2SMark Cave-Ayland memory_region_add_subregion(addr_space, DINO_HPA, 227efdb3ce2SMark Cave-Ayland sysbus_mmio_get_region( 228efdb3ce2SMark Cave-Ayland SYS_BUS_DEVICE(dino_dev), 0)); 22905245dafSMark Cave-Ayland pci_bus = PCI_BUS(qdev_get_child_bus(dino_dev, "pci")); 230a72bd606SHelge Deller assert(pci_bus); 231a72bd606SHelge Deller 232a72bd606SHelge Deller /* Create ISA bus. */ 233a72bd606SHelge Deller isa_bus = hppa_isa_bus(); 234a72bd606SHelge Deller assert(isa_bus); 235a72bd606SHelge Deller 236a72bd606SHelge Deller /* Realtime clock, used by firmware for PDC_TOD call. */ 23736f9bbdbSMark Cave-Ayland mc146818_rtc_init(isa_bus, 2000, NULL); 238a72bd606SHelge Deller 239a72bd606SHelge Deller /* Serial code setup. */ 2409bca0edbSPeter Maydell if (serial_hd(0)) { 241a72bd606SHelge Deller uint32_t addr = DINO_UART_HPA + 0x800; 242a4b74c19SMark Cave-Ayland serial_mm_init(addr_space, addr, 0, 243a4b74c19SMark Cave-Ayland qdev_get_gpio_in(dino_dev, DINO_IRQ_RS232INT), 2449bca0edbSPeter Maydell 115200, serial_hd(0), DEVICE_BIG_ENDIAN); 245a72bd606SHelge Deller } 246a72bd606SHelge Deller 2472da547b8SMark Cave-Ayland if (serial_hd(1)) { 2482da547b8SMark Cave-Ayland /* Serial port */ 2492da547b8SMark Cave-Ayland serial_mm_init(addr_space, LASI_UART_HPA + 0x800, 0, 2502da547b8SMark Cave-Ayland qdev_get_gpio_in(lasi_dev, LASI_IRQ_UART_HPA), 8000000 / 16, 2512da547b8SMark Cave-Ayland serial_hd(1), DEVICE_BIG_ENDIAN); 2522da547b8SMark Cave-Ayland } 2532da547b8SMark Cave-Ayland 2549701e569SMark Cave-Ayland /* Parallel port */ 2559701e569SMark Cave-Ayland parallel_mm_init(addr_space, LASI_LPT_HPA + 0x800, 0, 2569701e569SMark Cave-Ayland qdev_get_gpio_in(lasi_dev, LASI_IRQ_LAN_HPA), 2579701e569SMark Cave-Ayland parallel_hds[0]); 2589701e569SMark Cave-Ayland 25928b71a2eSHelge Deller /* fw_cfg configuration interface */ 26028b71a2eSHelge Deller create_fw_cfg(machine); 26128b71a2eSHelge Deller 262a72bd606SHelge Deller /* SCSI disk setup. */ 263877eb21dSMark Cave-Ayland dev = DEVICE(pci_create_simple(pci_bus, -1, "lsi53c895a")); 264877eb21dSMark Cave-Ayland lsi53c8xx_handle_legacy_cmdline(dev); 265a72bd606SHelge Deller 2664765384cSSven Schnelle /* Graphics setup. */ 2674765384cSSven Schnelle if (machine->enable_graphics && vga_interface_type != VGA_NONE) { 2683e80f690SMarkus Armbruster dev = qdev_new("artist"); 2694765384cSSven Schnelle s = SYS_BUS_DEVICE(dev); 2703c6ef471SMarkus Armbruster sysbus_realize_and_unref(s, &error_fatal); 2714765384cSSven Schnelle sysbus_mmio_map(s, 0, LASI_GFX_HPA); 2724765384cSSven Schnelle sysbus_mmio_map(s, 1, ARTIST_FB_ADDR); 2734765384cSSven Schnelle } 2744765384cSSven Schnelle 2750e6de551SHelge Deller /* Network setup. */ 276c3c3fe47SMark Cave-Ayland if (enable_lasi_lan()) { 277c3c3fe47SMark Cave-Ayland lasi_82596_init(addr_space, LASI_LAN_HPA, 278c3c3fe47SMark Cave-Ayland qdev_get_gpio_in(lasi_dev, LASI_IRQ_LAN_HPA)); 279c3c3fe47SMark Cave-Ayland } 280c3c3fe47SMark Cave-Ayland 281a72bd606SHelge Deller for (i = 0; i < nb_nics; i++) { 282376b8519SHelge Deller if (!enable_lasi_lan()) { 2830e6de551SHelge Deller pci_nic_init_nofail(&nd_table[i], pci_bus, "tulip", NULL); 284a72bd606SHelge Deller } 285376b8519SHelge Deller } 286a72bd606SHelge Deller 287d26c575cSMark Cave-Ayland /* PS/2 Keyboard/Mouse */ 288d26c575cSMark Cave-Ayland lasips2_init(addr_space, LASI_PS2KBD_HPA, 289d26c575cSMark Cave-Ayland qdev_get_gpio_in(lasi_dev, LASI_IRQ_PS2KBD_HPA)); 290d26c575cSMark Cave-Ayland 291b28c4a64SHelge Deller /* register power switch emulation */ 292b28c4a64SHelge Deller qemu_register_powerdown_notifier(&hppa_system_powerdown_notifier); 293b28c4a64SHelge Deller 294a72bd606SHelge Deller /* Load firmware. Given that this is not "real" firmware, 295a72bd606SHelge Deller but one explicitly written for the emulation, we might as 296a72bd606SHelge Deller well load it directly from an ELF image. */ 297a72bd606SHelge Deller firmware_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, 298b57e3e97SPaolo Bonzini machine->firmware ?: "hppa-firmware.img"); 299a72bd606SHelge Deller if (firmware_filename == NULL) { 300a72bd606SHelge Deller error_report("no firmware provided"); 301a72bd606SHelge Deller exit(1); 302a72bd606SHelge Deller } 303a72bd606SHelge Deller 3044366e1dbSLiam Merwick size = load_elf(firmware_filename, NULL, NULL, NULL, 3056cdda0ffSAleksandar Markovic &firmware_entry, &firmware_low, &firmware_high, NULL, 306a72bd606SHelge Deller true, EM_PARISC, 0, 0); 307a72bd606SHelge Deller 308a72bd606SHelge Deller /* Unfortunately, load_elf sign-extends reading elf32. */ 309a72bd606SHelge Deller firmware_entry = (target_ureg)firmware_entry; 310a72bd606SHelge Deller firmware_low = (target_ureg)firmware_low; 311a72bd606SHelge Deller firmware_high = (target_ureg)firmware_high; 312a72bd606SHelge Deller 313a72bd606SHelge Deller if (size < 0) { 314a72bd606SHelge Deller error_report("could not load firmware '%s'", firmware_filename); 315a72bd606SHelge Deller exit(1); 316a72bd606SHelge Deller } 317691cbbadSRichard Henderson qemu_log_mask(CPU_LOG_PAGE, "Firmware loaded at 0x%08" PRIx64 318691cbbadSRichard Henderson "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ".\n", 319a72bd606SHelge Deller firmware_low, firmware_high, firmware_entry); 3208262863dSPhilippe Mathieu-Daudé if (firmware_low < FIRMWARE_START || firmware_high >= FIRMWARE_END) { 321a72bd606SHelge Deller error_report("Firmware overlaps with memory or IO space"); 322a72bd606SHelge Deller exit(1); 323a72bd606SHelge Deller } 324a72bd606SHelge Deller g_free(firmware_filename); 325a72bd606SHelge Deller 326a72bd606SHelge Deller rom_region = g_new(MemoryRegion, 1); 3276a3a2e82SIgor Mammedov memory_region_init_ram(rom_region, NULL, "firmware", 3286a3a2e82SIgor Mammedov (FIRMWARE_END - FIRMWARE_START), &error_fatal); 329a72bd606SHelge Deller memory_region_add_subregion(addr_space, FIRMWARE_START, rom_region); 330a72bd606SHelge Deller 331a72bd606SHelge Deller /* Load kernel */ 332a72bd606SHelge Deller if (kernel_filename) { 3334366e1dbSLiam Merwick size = load_elf(kernel_filename, NULL, &cpu_hppa_to_phys, 3346cdda0ffSAleksandar Markovic NULL, &kernel_entry, &kernel_low, &kernel_high, NULL, 335a72bd606SHelge Deller true, EM_PARISC, 0, 0); 336a72bd606SHelge Deller 337a72bd606SHelge Deller /* Unfortunately, load_elf sign-extends reading elf32. */ 338a72bd606SHelge Deller kernel_entry = (target_ureg) cpu_hppa_to_phys(NULL, kernel_entry); 339a72bd606SHelge Deller kernel_low = (target_ureg)kernel_low; 340a72bd606SHelge Deller kernel_high = (target_ureg)kernel_high; 341a72bd606SHelge Deller 342a72bd606SHelge Deller if (size < 0) { 343a72bd606SHelge Deller error_report("could not load kernel '%s'", kernel_filename); 344a72bd606SHelge Deller exit(1); 345a72bd606SHelge Deller } 346691cbbadSRichard Henderson qemu_log_mask(CPU_LOG_PAGE, "Kernel loaded at 0x%08" PRIx64 347691cbbadSRichard Henderson "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 348c108cc59SPhilippe Mathieu-Daudé ", size %" PRIu64 " kB\n", 349c108cc59SPhilippe Mathieu-Daudé kernel_low, kernel_high, kernel_entry, size / KiB); 350a72bd606SHelge Deller 351a72bd606SHelge Deller if (kernel_cmdline) { 352a72bd606SHelge Deller cpu[0]->env.gr[24] = 0x4000; 353a72bd606SHelge Deller pstrcpy_targphys("cmdline", cpu[0]->env.gr[24], 354a72bd606SHelge Deller TARGET_PAGE_SIZE, kernel_cmdline); 355a72bd606SHelge Deller } 356a72bd606SHelge Deller 357a72bd606SHelge Deller if (initrd_filename) { 358a72bd606SHelge Deller ram_addr_t initrd_base; 359f3839fdaSLi Zhijian int64_t initrd_size; 360a72bd606SHelge Deller 361a72bd606SHelge Deller initrd_size = get_image_size(initrd_filename); 362a72bd606SHelge Deller if (initrd_size < 0) { 363a72bd606SHelge Deller error_report("could not load initial ram disk '%s'", 364a72bd606SHelge Deller initrd_filename); 365a72bd606SHelge Deller exit(1); 366a72bd606SHelge Deller } 367a72bd606SHelge Deller 368a72bd606SHelge Deller /* Load the initrd image high in memory. 369a72bd606SHelge Deller Mirror the algorithm used by palo: 370a72bd606SHelge Deller (1) Due to sign-extension problems and PDC, 371a72bd606SHelge Deller put the initrd no higher than 1G. 372a72bd606SHelge Deller (2) Reserve 64k for stack. */ 373bfdf22bcSPaolo Bonzini initrd_base = MIN(machine->ram_size, 1 * GiB); 374c108cc59SPhilippe Mathieu-Daudé initrd_base = initrd_base - 64 * KiB; 375a72bd606SHelge Deller initrd_base = (initrd_base - initrd_size) & TARGET_PAGE_MASK; 376a72bd606SHelge Deller 377a72bd606SHelge Deller if (initrd_base < kernel_high) { 378a72bd606SHelge Deller error_report("kernel and initial ram disk too large!"); 379a72bd606SHelge Deller exit(1); 380a72bd606SHelge Deller } 381a72bd606SHelge Deller 382a72bd606SHelge Deller load_image_targphys(initrd_filename, initrd_base, initrd_size); 383a72bd606SHelge Deller cpu[0]->env.gr[23] = initrd_base; 384a72bd606SHelge Deller cpu[0]->env.gr[22] = initrd_base + initrd_size; 385a72bd606SHelge Deller } 386a72bd606SHelge Deller } 387a72bd606SHelge Deller 388a72bd606SHelge Deller if (!kernel_entry) { 389a72bd606SHelge Deller /* When booting via firmware, tell firmware if we want interactive 390a72bd606SHelge Deller * mode (kernel_entry=1), and to boot from CD (gr[24]='d') 391a72bd606SHelge Deller * or hard disc * (gr[24]='c'). 392a72bd606SHelge Deller */ 393a72bd606SHelge Deller kernel_entry = boot_menu ? 1 : 0; 394a72bd606SHelge Deller cpu[0]->env.gr[24] = machine->boot_order[0]; 395a72bd606SHelge Deller } 396a72bd606SHelge Deller 397a72bd606SHelge Deller /* We jump to the firmware entry routine and pass the 398a72bd606SHelge Deller * various parameters in registers. After firmware initialization, 399a72bd606SHelge Deller * firmware will start the Linux kernel with ramdisk and cmdline. 400a72bd606SHelge Deller */ 401bfdf22bcSPaolo Bonzini cpu[0]->env.gr[26] = machine->ram_size; 402a72bd606SHelge Deller cpu[0]->env.gr[25] = kernel_entry; 403a72bd606SHelge Deller 404a72bd606SHelge Deller /* tell firmware how many SMP CPUs to present in inventory table */ 405a72bd606SHelge Deller cpu[0]->env.gr[21] = smp_cpus; 40624576007SHelge Deller 40724576007SHelge Deller /* tell firmware fw_cfg port */ 40824576007SHelge Deller cpu[0]->env.gr[19] = FW_CFG_IO_BASE; 409a72bd606SHelge Deller } 410a72bd606SHelge Deller 411a0628599SLike Xu static void hppa_machine_reset(MachineState *ms) 412a72bd606SHelge Deller { 41333decbd2SLike Xu unsigned int smp_cpus = ms->smp.cpus; 414a72bd606SHelge Deller int i; 415a72bd606SHelge Deller 416a72bd606SHelge Deller qemu_devices_reset(); 417a72bd606SHelge Deller 418a72bd606SHelge Deller /* Start all CPUs at the firmware entry point. 419a72bd606SHelge Deller * Monarch CPU will initialize firmware, secondary CPUs 420a72bd606SHelge Deller * will enter a small idle look and wait for rendevouz. */ 421a72bd606SHelge Deller for (i = 0; i < smp_cpus; i++) { 422a72bd606SHelge Deller cpu_set_pc(CPU(cpu[i]), firmware_entry); 423a72bd606SHelge Deller cpu[i]->env.gr[5] = CPU_HPA + i * 0x1000; 424a72bd606SHelge Deller } 425a72bd606SHelge Deller 426a72bd606SHelge Deller /* already initialized by machine_hppa_init()? */ 427bfdf22bcSPaolo Bonzini if (cpu[0]->env.gr[26] == ms->ram_size) { 428a72bd606SHelge Deller return; 429a72bd606SHelge Deller } 430a72bd606SHelge Deller 431bfdf22bcSPaolo Bonzini cpu[0]->env.gr[26] = ms->ram_size; 432a72bd606SHelge Deller cpu[0]->env.gr[25] = 0; /* no firmware boot menu */ 433a72bd606SHelge Deller cpu[0]->env.gr[24] = 'c'; 434a72bd606SHelge Deller /* gr22/gr23 unused, no initrd while reboot. */ 435a72bd606SHelge Deller cpu[0]->env.gr[21] = smp_cpus; 43624576007SHelge Deller /* tell firmware fw_cfg port */ 43724576007SHelge Deller cpu[0]->env.gr[19] = FW_CFG_IO_BASE; 438a72bd606SHelge Deller } 439a72bd606SHelge Deller 4404a4554c6SHelge Deller static void hppa_nmi(NMIState *n, int cpu_index, Error **errp) 4414a4554c6SHelge Deller { 4424a4554c6SHelge Deller CPUState *cs; 4434a4554c6SHelge Deller 4444a4554c6SHelge Deller CPU_FOREACH(cs) { 4454a4554c6SHelge Deller cpu_interrupt(cs, CPU_INTERRUPT_NMI); 4464a4554c6SHelge Deller } 4474a4554c6SHelge Deller } 448a72bd606SHelge Deller 449*297d4103SMark Cave-Ayland static void hppa_machine_init_class_init(ObjectClass *oc, void *data) 450813dff13SHelge Deller { 45142cc2bf6SMark Cave-Ayland MachineClass *mc = MACHINE_CLASS(oc); 45242cc2bf6SMark Cave-Ayland NMIClass *nc = NMI_CLASS(oc); 45342cc2bf6SMark Cave-Ayland 4540d98fbb5SMark Cave-Ayland mc->desc = "HPPA B160L machine"; 455a72bd606SHelge Deller mc->default_cpu_type = TYPE_HPPA_CPU; 456813dff13SHelge Deller mc->init = machine_hppa_init; 457a72bd606SHelge Deller mc->reset = hppa_machine_reset; 458813dff13SHelge Deller mc->block_default_type = IF_SCSI; 459a72bd606SHelge Deller mc->max_cpus = HPPA_MAX_CPUS; 460a72bd606SHelge Deller mc->default_cpus = 1; 461ea0ac7f6SPhilippe Mathieu-Daudé mc->is_default = true; 462d23b6caaSPhilippe Mathieu-Daudé mc->default_ram_size = 512 * MiB; 463813dff13SHelge Deller mc->default_boot_order = "cd"; 4647c59c1e0SIgor Mammedov mc->default_ram_id = "ram"; 465813dff13SHelge Deller 4664a4554c6SHelge Deller nc->nmi_monitor_handler = hppa_nmi; 4674a4554c6SHelge Deller } 4684a4554c6SHelge Deller 469*297d4103SMark Cave-Ayland static const TypeInfo hppa_machine_init_typeinfo = { 470c165905cSMark Cave-Ayland .name = MACHINE_TYPE_NAME("hppa"), 471c165905cSMark Cave-Ayland .parent = TYPE_MACHINE, 472*297d4103SMark Cave-Ayland .class_init = hppa_machine_init_class_init, 4734a4554c6SHelge Deller .interfaces = (InterfaceInfo[]) { 4744a4554c6SHelge Deller { TYPE_NMI }, 4754a4554c6SHelge Deller { } 4764a4554c6SHelge Deller }, 4774a4554c6SHelge Deller }; 4784a4554c6SHelge Deller 479*297d4103SMark Cave-Ayland static void hppa_machine_init_register_types(void) 4804a4554c6SHelge Deller { 481*297d4103SMark Cave-Ayland type_register_static(&hppa_machine_init_typeinfo); 4824a4554c6SHelge Deller } 4834a4554c6SHelge Deller 484*297d4103SMark Cave-Ayland type_init(hppa_machine_init_register_types) 485