Skip to contentSkip to conversation

qdev: isa bus.

PATCH In review Gerd Hoffmann 2 participants 6 messages Jul 9, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

cover qdev: isa bus.

Hi,

This is a proof-of-concept / RfC patch series to add isa bus support to qdev. It adds isa-bus.c and converts one user (pc keyboard+mouse).

I've tried to also handle isa-via-mmio used by certain architectures and hide that in isa-bus.c, so the individual drivers don't have to care once everything is converted over to qdev.

Reviews especially from people knowing non-pc archs better than I do are very welcome.

thanks,
Gerd

#1 lore raw

PATCH 1/4 qdev/isa: add isa bus support to qdev.

The implementation tries to cover both the pc-ish ioport case and the mmio-based isa port access found in other architectures. The common code in isa-bus.c handles mmio internally, so the separate init path for mmio present in many drivers can go away once all users are switched over to qdev.

---
 Makefile.target |    8 +-
 hw/isa-bus.c    |  216 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/isa.h        |   31 ++++++++
 3 files changed, 251 insertions(+), 4 deletions(-)
 create mode 100644 hw/isa-bus.c
Makefile.target +4 -4
index a593503..1a865fa 100644
@@ -562,7 +562,7 @@ obj-y += wdt_ib700.o wdt_i6300esb.o
 
 ifeq ($(TARGET_BASE_ARCH), i386)
 # Hardware support
-obj-y += ide.o pckbd.o vga.o $(sound-obj-y) dma.o
+obj-y += ide.o pckbd.o vga.o $(sound-obj-y) dma.o isa-bus.o
 obj-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 obj-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
@@ -572,7 +572,7 @@ endif
 ifeq ($(TARGET_BASE_ARCH), ppc)
 CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
 # shared objects
-obj-y += ppc.o ide.o vga.o $(sound-obj-y) dma.o openpic.o
+obj-y += ppc.o ide.o vga.o $(sound-obj-y) dma.o isa-bus.o openpic.o
 # PREP target
 obj-y += pckbd.o serial.o i8259.o i8254.o fdc.o mc146818rtc.o
 obj-y += prep_pci.o ppc_prep.o
@@ -598,7 +598,7 @@ obj-y += mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
 obj-y += mips_timer.o mips_int.o dma.o vga.o serial.o i8254.o i8259.o rc4030.o
 obj-y += g364fb.o jazz_led.o dp8393x.o
 obj-y += ide.o gt64xxx.o pckbd.o fdc.o mc146818rtc.o usb-uhci.o acpi.o ds1225y.o
-obj-y += piix_pci.o parallel.o cirrus_vga.o pcspk.o $(sound-obj-y)
+obj-y += piix_pci.o parallel.o cirrus_vga.o isa-bus.o pcspk.o $(sound-obj-y)
 obj-y += mipsnet.o
 obj-y += pflash_cfi01.o
 obj-y += vmware_vga.o
@@ -634,7 +634,7 @@ obj-y += pflash_cfi02.o
 endif
 ifeq ($(TARGET_BASE_ARCH), sparc)
 ifeq ($(TARGET_ARCH), sparc64)
-obj-y += sun4u.o ide.o pckbd.o vga.o apb_pci.o
+obj-y += sun4u.o ide.o isa-bus.o pckbd.o vga.o apb_pci.o
 obj-y += fdc.o mc146818rtc.o serial.o
 obj-y += cirrus_vga.o parallel.o
 else
hw/isa-bus.c new file +216 -0

216 lines not on this page · raw message

hw/isa.h +31 -0
index a8c1a56..941bfe3 100644
@@ -1,7 +1,38 @@
 #ifndef HW_ISA_H
 #define HW_ISA_H
+
 /* ISA bus */
 
+#include "qdev.h"
+
+typedef struct ISABus ISABus;
+typedef struct ISADevice ISADevice;
+typedef struct ISADeviceInfo ISADeviceInfo;
+
+struct ISADevice {
+    DeviceState qdev;
+    uint32_t iobase[2];
+    qemu_irq *irqs[2];
+    int nirqs;
+};
+
+typedef void (*isa_qdev_initfn)(ISADevice *dev);
+struct ISADeviceInfo {
+    DeviceInfo qdev;
+    isa_qdev_initfn init;
+    struct {
+        IOPortReadFunc  *read;
+        IOPortWriteFunc *write;
+        uint32_t        length;
+    } io[2];
+};
+
+ISABus *isa_bus_new(DeviceState *dev, int mmio, int it_shift);
+void isa_connect_irq(ISADevice *dev, int n, qemu_irq irq);
+void isa_init_irq(ISADevice *dev, qemu_irq *p);
+void isa_qdev_register(ISADeviceInfo *info);
+ISADevice *isa_create_simple(const char *name, uint32_t iobase, uint32_t iobase2);
+
 extern target_phys_addr_t isa_mem_base;
 
 int register_ioport_read(int start, int length, int size,
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/4 qdev/isa: add qdev support to i8042 (aka ps/2 kbd+mouse).

In reply to Gerd Hoffmann
---
 hw/pckbd.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)
hw/pckbd.c +38 -0
index d50cd6e..3f2023c 100644
@@ -113,6 +113,7 @@
 #define KBD_PENDING_AUX         2
 
 typedef struct KBDState {
+    ISADevice dev;
     uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
     uint8_t status;
     uint8_t mode;
@@ -440,3 +441,40 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
 #endif
     qemu_register_reset(kbd_reset, s);
 }
+
+static void i8042_initfn(ISADevice *dev)
+{
+    KBDState *s = DO_UPCAST(KBDState, dev, dev);
+
+    isa_init_irq(dev, &s->irq_kbd);
+    isa_init_irq(dev, &s->irq_mouse);
+
+    kbd_reset(s);
+    register_savevm("pckbd", 0, 3, kbd_save, kbd_load, s);
+
+    s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
+    s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
+#ifdef TARGET_I386
+    vmmouse_init(s->mouse);
+#endif
+    qemu_register_reset(kbd_reset, s);
+}
+
+static ISADeviceInfo i8042_info = {
+    .qdev.name     = "i8042",
+    .qdev.size     = sizeof(KBDState),
+    .qdev.no_user  = 1,
+    .init          = i8042_initfn,
+    .io[0].read    = kbd_read_data,
+    .io[0].write   = kbd_write_data,
+    .io[0].length  = 1,
+    .io[1].read    = kbd_read_status,
+    .io[1].write   = kbd_write_command,
+    .io[1].length  = 1,
+};
+
+static void i8042_register(void)
+{
+    isa_qdev_register(&i8042_info);
+}
+device_init(i8042_register)
Signature · 1 line
1.6.2.5
#3 lore raw

PATCH 3/4 qdev/isa: make the piix isa bridge register an isa bus.

In reply to Gerd Hoffmann
---
 hw/piix_pci.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/piix_pci.c +2 -0
index a5d42d1..bc65086 100644
@@ -25,6 +25,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "isa.h"
 #include "sysbus.h"
 
 typedef uint32_t pci_addr_t;
@@ -342,6 +343,7 @@ static void piix3_initfn(PCIDevice *d)
 {
     uint8_t *pci_conf;
 
+    isa_bus_new(&d->qdev, 0, 0);
     register_savevm("PIIX3", 0, 2, piix_save, piix_load, d);
 
     pci_conf = d->config;
Signature · 1 line
1.6.2.5
#4 lore raw

PATCH 4/4 qdev/isa: make pc use qdev for i8042 setup.

In reply to Gerd Hoffmann
---
 hw/pc.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
hw/pc.c +4 -1
index ecb618d..51e2768 100644
@@ -1095,6 +1095,7 @@ static void pc_init1(ram_addr_t ram_size,
     int bios_size, isa_bios_size, oprom_area_size;
     PCIBus *pci_bus;
     DeviceState *qdev;
+    ISADevice *isa_dev;
     int piix3_devfn = -1;
     CPUState *env;
     qemu_irq *cpu_irq;
@@ -1344,7 +1345,9 @@ static void pc_init1(ram_addr_t ram_size,
         }
     }
 
-    i8042_init(i8259[1], i8259[12], 0x60);
+    isa_dev = isa_create_simple("i8042", 0x60, 0x64);
+    isa_connect_irq(isa_dev, 0, i8259[1]);
+    isa_connect_irq(isa_dev, 1, i8259[12]);
     DMA_init(0);
 #ifdef HAS_AUDIO
     audio_init(pci_enabled ? pci_bus : NULL, i8259);
Signature · 1 line
1.6.2.5
#5 lore raw
In reply to Gerd Hoffmann
Quoted 3 lines

I've tried to also handle isa-via-mmio used by certain architectures and hide that in isa-bus.c, so the individual drivers don't have to care once everything is converted over to qdev.

ISA-via-mmio is actually something different. This is a feature of the host bridge, and implemented in isa_mmio.c.

The devices you're talking about are devices that have both ISA and "SysBus" incarnations with very similar programming interfaces, in the same way that some devices have both ISA and PCI variants.

Paul