NS 87560 SuperIO chip
cover NS 87560 SuperIO chip
From: Helge Deller <[email protected]>
This series adds the emulation of a "NS 87560 SuperIO chip".
The SuperIO chip includes a floppy controller, two serial ports, one parallel port, an IDE controller and one OHCI USB port.
This National Semiconductor SuperIO chip was commonly used in many HP PA-RISC B- and C-class workstations, as in the HP C3700 machine which is being emulated by QEMU already. The last patch wires up this SuperIO driver to the existing C3700 machine emulation.
This driver was developed during the last few months by Abizer Lokhandwala <[email protected]> and mentored and reviewed by me. Originally Abizer applied for the SCSI TAPE emulation program which I offered for the Google-Summer-of-Code 2026 program, but since the TAPE project was dropped by Google, he instead stepped up to develop this driver - even without receiving sponsoring by Google.
So, I'm very grateful that he nevertheless invested his spare time to develop this driver!
I've already reviewed the patches off-list, but it would be great if other people could review the code as well.
Helge
Abizer Lokhandwala (6):
hw/isa/pc87560: Add main isa code for NS 87560 SuperIO chip hw/ide/pc87560-ide: Add IDE emulation of NS 87560 SuperIO chip hw/usb/hcd-ohci: Add big endian and consistency check support hw/usb/pc87560-ohci: Add USB OHCI emulation of NS 87560 SuperIO chip hw/pc87560: Wire up emulation of NS 87560 SuperIO chip hw/hppa: Add NS 87560 SuperIO chip to HP C3700 machine
Helge Deller (1):
hw/pci/pci_ids: Add PCI vendor ID and IDs for NS chips
MAINTAINERS | 4 + hw/hppa/machine.c | 41 +++- hw/ide/meson.build | 1 + hw/ide/pc87560-ide.c | 358 +++++++++++++++++++++++++++ hw/ide/trace-events | 4 + hw/isa/Kconfig | 11 + hw/isa/meson.build | 1 + hw/isa/pc87560.c | 510 +++++++++++++++++++++++++++++++++++++++ hw/usb/hcd-ohci.c | 35 +++ hw/usb/hcd-ohci.h | 5 + hw/usb/meson.build | 1 + hw/usb/pc87560-ohci.c | 355 +++++++++++++++++++++++++++ include/hw/isa/pc87560.h | 96 ++++++++ include/hw/pci/pci_ids.h | 5 + 14 files changed, 1420 insertions(+), 7 deletions(-) create mode 100644 hw/ide/pc87560-ide.c create mode 100644 hw/isa/pc87560.c create mode 100644 hw/usb/pc87560-ohci.c create mode 100644 include/hw/isa/pc87560.h
Signature · 1 line
2.54.0
PATCH 1/7 hw/pci/pci_ids: Add PCI vendor ID and IDs for NS chips
From: Helge Deller <[email protected]>
Some HP B- and C-class workstations used a PCI SuperIO chip from National Semiconductor for USB, serial, parallel and FDC. Add the relevant PCI IDs, so that the QEMU driver can reuse the constants.
--- include/hw/pci/pci_ids.h | 5 +++++ 1 file changed, 5 insertions(+)
include/hw/pci/pci_ids.h +5 -0
@@ -168,6 +168,11 @@#define PCI_DEVICE_ID_LSI_SAS1078 0x0060#define PCI_DEVICE_ID_LSI_SAS0079 0x0079 +#define PCI_VENDOR_ID_NS 0x100b +#define PCI_DEVICE_ID_NS_87415 0x0002 +#define PCI_DEVICE_ID_NS_87560_LIO 0x000e +#define PCI_DEVICE_ID_NS_87560_USB 0x0012 +#define PCI_VENDOR_ID_DEC 0x1011#define PCI_DEVICE_ID_DEC_21143 0x0019
Signature · 1 line
2.54.0
PATCH 5/7 hw/usb/pc87560-ohci: Add USB OHCI emulation of NS 87560 SuperIO chip
In reply to Helge DellerFrom: Abizer Lokhandwala <[email protected]>
Add emulation of the USB OHCI portion of the NS SuperIO chip.
--- MAINTAINERS | 1 + hw/usb/pc87560-ohci.c | 355 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 356 insertions(+) create mode 100644 hw/usb/pc87560-ohci.c
MAINTAINERS +1 -0
@@ -1357,6 +1357,7 @@ F: roms/seabios-hppa/ F: tests/functional/hppa/ F: hw/isa/pc87560.c F: hw/ide/pc87560-ide.c +F: hw/usb/pc87560-ohci.c F: include/hw/isa/pc87560.h Hexagon Machines
hw/usb/pc87560-ohci.c new file +355 -0
355 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH 4/7 hw/usb/hcd-ohci: Add big endian and consistency check support
In reply to Helge DellerFrom: Abizer Lokhandwala <[email protected]>
The OHCI controller allows running in big endian mode. If this mode is enabled, swap the buffer contents before accessing them since we by default run OHCI in little endian mode.
Additionally add the architected consistency check which halts OHCI on errors.
--- hw/usb/hcd-ohci.c | 35 +++++++++++++++++++++++++++++++++++ hw/usb/hcd-ohci.h | 5 +++++ 2 files changed, 40 insertions(+)
hw/usb/hcd-ohci.c +35 -0
@@ -74,6 +74,7 @@ struct ohci_hcca {/* Flags in the head field of an Endpoint Descriptor. */ #define OHCI_ED_H 1#define OHCI_ED_C 2 +#define OHCI_ED_HEAD_RSVD (1 << 2 | 1 << 3)/* Bitfields for the first word of a Transfer Descriptor. */ #define OHCI_TD_R (1 << 18)
@@ -371,6 +372,8 @@ void ohci_hard_reset(OHCIState *ohci)ohci_soft_reset (ohci); ohci->ctl =0 ;ohci_roothub_reset (ohci); + ohci->big_endian = false; + ohci->consistency_check = false; }/* Get an array of dwords from main memory */
@@ -867,6 +870,18 @@ static void ohci_td_pkt(const char *msg, const uint8_t *buf, size_t len) } } +static void ohci_bswap_buf (uint8_t *buf,size_t len) +{ +uint32_t w; +while (len >=sizeof (w)) { +memcpy (&w, buf,sizeof (w)); + w =bswap32 (w); +memcpy (buf, &w,sizeof (w)); + buf +=sizeof (w); + len -=sizeof (w); + } +} +/* * Service a transport descriptor. * Returns nonzero to terminate processing of this endpoint.
@@ -975,6 +990,9 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) DMA_DIRECTION_TO_DEVICE)) {ohci_die (ohci); } +if (ohci->big_endian) { +ohci_bswap_buf (ohci->usb_buf, pktlen); + } } } }
@@ -1024,6 +1042,9 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed)if (ret >=0 ) {if (dir ==OHCI_TD_DIR_IN ) { +if (ohci->big_endian) { +ohci_bswap_buf (ohci->usb_buf, ret); + }if (ohci_copy_td (ohci, &td, ohci->usb_buf, ret,DMA_DIRECTION_FROM_DEVICE )) {ohci_die (ohci);
@@ -1108,6 +1129,13 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) ohci->done_count = i; } exit_no_retire: +if (ohci->media_error) { +int cc =OHCI_BM (td.flags,TD_CC ); +/* only these 2 errors will ever actually be possible in qemu */ +if (cc ==OHCI_CC_DEVICENOTRESPONDING || cc ==OHCI_CC_UNDEXPETEDPID ) { + ohci->media_error (ohci); + } + }if (ohci_put_td (ohci, addr, &td)) {ohci_die (ohci);return 1 ;
@@ -1136,6 +1164,13 @@ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head)ohci_die (ohci);return 0 ; } +if (ohci->consistency_check && (ed.head &OHCI_ED_HEAD_RSVD )) { +if (ohci->descriptor_error) { + ohci->descriptor_error (ohci); + } +ohci_die (ohci); +return 0 ; + } next_ed = ed.next &OHCI_DPTR_MASK ;
hw/usb/hcd-ohci.h +5 -0
@@ -93,6 +93,11 @@ struct OHCIState {bool async_complete;void (*ohci_die)(OHCIState *ohci); +void (*media_error)(OHCIState *ohci); +void (*descriptor_error)(OHCIState *ohci); + +bool big_endian; +bool consistency_check; };#define TYPE_SYSBUS_OHCI "sysbus-ohci"
Signature · 1 line
2.54.0
PATCH 3/7 hw/ide/pc87560-ide: Add IDE emulation of NS 87560 SuperIO chip
In reply to Helge DellerFrom: Abizer Lokhandwala <[email protected]>
Add emulation of the IDE ports of the NS SuperIO chip.
--- MAINTAINERS | 1 + hw/ide/pc87560-ide.c | 358 +++++++++++++++++++++++++++++++++++++++++++ hw/ide/trace-events | 4 + 3 files changed, 363 insertions(+) create mode 100644 hw/ide/pc87560-ide.c
MAINTAINERS +1 -0
@@ -1356,6 +1356,7 @@ F: pc-bios/hppa-firmware.img F: roms/seabios-hppa/ F: tests/functional/hppa/ F: hw/isa/pc87560.c +F: hw/ide/pc87560-ide.c F: include/hw/isa/pc87560.h Hexagon Machines
hw/ide/pc87560-ide.c new file +358 -0
358 lines not on this page · raw message
hw/ide/trace-events +4 -0
@@ -27,6 +27,10 @@ ide_dma_cb(void *s, int64_t sector_num, int n, const char *dma) "IDEState %p; se bmdma_read_cmd646(uint64_t addr, uint32_t val) "bmdma: readb 0x%"PRIx64" : 0x%02x" bmdma_write_cmd646(uint64_t addr, uint64_t val) "bmdma: writeb 0x%"PRIx64" : 0x%02"PRIx64 +# hw/ide/pc87560.c +bmdma_read_pc87560(uint64_t addr, uint32_t val) "bmdma: readb 0x%"PRIx64" : 0x%02x" +bmdma_write_pc87560(uint64_t addr, uint64_t val) "bmdma: writeb 0x%"PRIx64" : 0x%02"PRIx64 + # pci.c bmdma_reset(void) "" bmdma_cmd_writeb(uint32_t val) "val: 0x%08x"
Signature · 1 line
2.54.0
PATCH 6/7 hw/pc87560: Wire up emulation of NS 87560 SuperIO chip
In reply to Helge DellerFrom: Abizer Lokhandwala <[email protected]>
Put everything together and add the meson code to enable build of the IDE-, USB- and core portions of the NS SuperIO chip.
--- hw/ide/meson.build | 1 + hw/isa/meson.build | 1 + hw/usb/meson.build | 1 + 3 files changed, 3 insertions(+)
hw/ide/meson.build +1 -0
@@ -14,3 +14,4 @@ system_ss.add(when: 'CONFIG_IDE_PCI', if_true: files('pci.c')) system_ss.add(when: 'CONFIG_IDE_PIIX', if_true: files('piix.c', 'ioport.c')) system_ss.add(when: 'CONFIG_IDE_SII3112', if_true: files('sii3112.c')) system_ss.add(when: 'CONFIG_IDE_VIA', if_true: files('via.c')) +system_ss.add(when: 'CONFIG_PC87560', if_true: files('pc87560-ide.c'))
hw/isa/meson.build +1 -0
@@ -8,4 +8,5 @@ system_ss.add(when: 'CONFIG_PIIX', if_true: files('piix.c')) system_ss.add(when: 'CONFIG_SMC37C669', if_true: files('smc37c669-superio.c')) system_ss.add(when: 'CONFIG_VT82C686', if_true: files('vt82c686.c')) +specific_ss.add(when: 'CONFIG_PC87560', if_true: files('pc87560.c')) specific_ss.add(when: 'CONFIG_LPC_ICH9', if_true: files('lpc_ich9.c'))
hw/usb/meson.build +1 -0
@@ -45,6 +45,7 @@ system_ss.add(when: 'CONFIG_USB_STORAGE_UAS', if_true: files('dev-uas.c')) system_ss.add(when: 'CONFIG_USB_AUDIO', if_true: files('dev-audio.c')) system_ss.add(when: 'CONFIG_USB_SERIAL', if_true: files('dev-serial.c')) system_ss.add(when: 'CONFIG_USB_NETWORK', if_true: files('dev-network.c')) +system_ss.add(when: 'CONFIG_PC87560', if_true: files('pc87560-ohci.c')) if host_os != 'windows' system_ss.add(when: 'CONFIG_USB_STORAGE_MTP', if_true: files('dev-mtp.c')) endif
Signature · 1 line
2.54.0
PATCH 2/7 hw/isa/pc87560: Add main isa code for NS 87560 SuperIO chip
In reply to Helge DellerFrom: Abizer Lokhandwala <[email protected]>
Add emulation of the core components (PCI function 1 aka I/O Peripherals) of the National Semiconductor SuperIO chip which was commonly used in HP PA-RISC B- and C-class workstations. This includes the PIC interrupt controller, the floppy controller, serial and parallel ports.
--- MAINTAINERS | 2 + hw/isa/Kconfig | 11 + hw/isa/pc87560.c | 510 +++++++++++++++++++++++++++++++++++++++ include/hw/isa/pc87560.h | 96 ++++++++ 4 files changed, 619 insertions(+) create mode 100644 hw/isa/pc87560.c create mode 100644 include/hw/isa/pc87560.h
MAINTAINERS +2 -0
@@ -1355,6 +1355,8 @@ F: include/hw/pci-host/dino.h F: pc-bios/hppa-firmware.img F: roms/seabios-hppa/ F: tests/functional/hppa/ +F: hw/isa/pc87560.c +F: include/hw/isa/pc87560.h Hexagon Machines ----------------
hw/isa/Kconfig +11 -0
@@ -67,6 +67,17 @@ config SMC37C669 bool select ISA_SUPERIO +config PC87560 + bool + default y if PCI_DEVICES + depends on PCI + depends on HPPA + select ISA_BUS + select FDC_ISA + select SERIAL_ISA + select IDE_PCI + select USB_OHCI + config LPC_ICH9 bool # For historical reasons, SuperIO devices are created in the board
hw/isa/pc87560.c new file +510 -0
510 lines not on this page · raw message
include/hw/isa/pc87560.h new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH 7/7 hw/hppa: Add NS 87560 SuperIO chip to HP C3700 machine
In reply to Helge DellerFrom: Abizer Lokhandwala <[email protected]>
Due to the lack of the emulated NS 87560 SuperIO chip, we used until now the emulated serial ports of a Diva GSP management board as a temporary replacement. Since the NS SuperIO chip emulation was just added in the previous commits, switch over to use it which allows us to emulate the physical hardware more closely.
--- hw/hppa/machine.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-)
hw/hppa/machine.c +34 -7
@@ -394,7 +394,7 @@ static TranslateFn *machine_HP_common_init_cpus(MachineState *machine)* Last creation step: Add NICs, graphics & load firmware */ static void machine_HP_common_init_tail (MachineState *machine,PCIBus *pci_bus, -TranslateFn *translate) +TranslateFn *translate,bool create_diva) {const char *kernel_filename = machine->kernel_filename;MachineClass *mc =MACHINE_GET_CLASS (machine);
@@ -426,7 +426,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,pci_init_nic_devices (pci_bus, mc->default_nic); } -if (pci_bus &&hppa_is_pa20 (&cpu[0 ]->env)) { +if (pci_bus &&hppa_is_pa20 (&cpu[0 ]->env) && create_diva) {/* BMC board: HP Diva GSP PCI card */ pci_dev =pci_new_multifunction (PCI_DEVFN (2 ,0 ),"diva-gsp" );if (!lasi_dev) {
@@ -442,8 +442,9 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,/* create USB OHCI controller for USB keyboard & mouse on Astro machines */ if (!lasi_dev && machine->enable_graphics &&defaults_enabled ()) {USBBus *usb_bus; - -pci_create_simple (pci_bus,-1 ,"pci-ohci" ); +if (create_diva) { +pci_create_simple (pci_bus,-1 ,"pci-ohci" ); + } usb_bus =USB_BUS (object_resolve_type_unambiguous (TYPE_USB_BUS , &error_abort));usb_create_simple (usb_bus,"usb-kbd" );
@@ -647,7 +648,7 @@ static void machine_HP_715_init(MachineState *machine) }/* Add NICs, graphics & load firmware */ -machine_HP_common_init_tail (machine,NULL , translate); +machine_HP_common_init_tail (machine,NULL , translate, false); }/*
@@ -726,7 +727,7 @@ static void machine_HP_B160L_init(MachineState *machine) }/* Add NICs, graphics & load firmware */ -machine_HP_common_init_tail (machine, pci_bus, translate); +machine_HP_common_init_tail (machine, pci_bus, translate, false); }static AstroState *astro_init (void )
@@ -771,6 +772,32 @@ static void machine_HP_C3700_init(MachineState *machine) pci_bus =PCI_BUS (qdev_get_child_bus (DEVICE (astro->elroy[0 ]),"pci" ));assert (pci_bus); +/* The C3700 has a SuperIO chip, while the A400 hasn't. */ +MachineClass *mc =MACHINE_GET_CLASS (machine); +bool is_C3700 =strcmp (mc->name,"C3700" ) ==0 ; +if (is_C3700) { +PCIDevice *ide_pdev =pci_create_simple (pci_bus,PCI_DEVFN (2 ,0 ), +"pc87560-ide" ); +PCIDevice *usb_pdev =pci_create_simple (pci_bus,PCI_DEVFN (2 ,2 ), +"pc87560-ohci" ); +PCIDevice *sio_pdev =pci_new (PCI_DEVFN (2 ,1 ),"pc87560-superio" ); +if (serial_hd (0 )) { +qdev_prop_set_chr (DEVICE (sio_pdev),"serial0" ,serial_hd (0 )); + } +if (serial_hd (1 )) { +qdev_prop_set_chr (DEVICE (sio_pdev),"serial1" ,serial_hd (1 )); + } +pci_realize_and_unref (sio_pdev, pci_bus, &error_fatal); + +qdev_connect_gpio_out (DEVICE (ide_pdev),0 , +qdev_get_gpio_in_named (DEVICE (sio_pdev),"pic-irq" ,7 )); +qdev_connect_gpio_out (DEVICE (usb_pdev),0 , +qdev_get_gpio_in_named (DEVICE (sio_pdev),"pic-irq" ,1 )); + +qdev_connect_gpio_out_named (DEVICE (sio_pdev),"pic-out" ,0 , +pci_allocate_irq (usb_pdev)); + } +/* SCSI disk setup. */ if (drive_get_max_bus (IF_SCSI ) >=0 ) {DeviceState *dev =DEVICE (pci_create_simple (pci_bus,-1 ,"lsi53c895a" ));
@@ -778,7 +805,7 @@ static void machine_HP_C3700_init(MachineState *machine) }/* Add NICs, graphics & load firmware */ -machine_HP_common_init_tail (machine, pci_bus, translate); +machine_HP_common_init_tail (machine, pci_bus, translate, !is_C3700); }/*
Signature · 1 line
2.54.0