[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 14/25] hw/isa/superio: Factor out the IDE code from
From: |
Philippe Mathieu-Daudé |
Subject: |
[Qemu-devel] [PATCH 14/25] hw/isa/superio: Factor out the IDE code from pc87312.c |
Date: |
Thu, 8 Mar 2018 23:39:35 +0100 |
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
include/hw/isa/superio.h | 2 ++
hw/isa/isa-superio.c | 22 ++++++++++++++++++++++
hw/isa/pc87312.c | 36 ++++++++++++++++++++----------------
hw/isa/trace-events | 2 +-
4 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/include/hw/isa/superio.h b/include/hw/isa/superio.h
index 2fc33bf3d3..3dd5448f8c 100644
--- a/include/hw/isa/superio.h
+++ b/include/hw/isa/superio.h
@@ -31,6 +31,7 @@ typedef struct ISASuperIODevice {
ISADevice *serial[MAX_SERIAL_PORTS];
ISADevice *floppy;
ISADevice *kbc;
+ ISADevice *ide;
} ISASuperIODevice;
typedef struct ISASuperIOFuncs {
@@ -50,6 +51,7 @@ typedef struct ISASuperIOClass {
ISASuperIOFuncs parallel;
ISASuperIOFuncs serial;
ISASuperIOFuncs floppy;
+ ISASuperIOFuncs ide;
} ISASuperIOClass;
#endif /* HW_ISA_SUPERIO_H */
diff --git a/hw/isa/isa-superio.c b/hw/isa/isa-superio.c
index 041b47bdbf..f98711beff 100644
--- a/hw/isa/isa-superio.c
+++ b/hw/isa/isa-superio.c
@@ -146,6 +146,28 @@ static void isa_superio_realize(DeviceState *dev, Error
**errp)
/* Keyboard, mouse */
sio->kbc = isa_create_simple(bus, TYPE_I8042);
+
+ /* IDE */
+ if (k->ide.count && (!k->ide.is_enabled || k->ide.is_enabled(sio, 0))) {
+ isa = isa_create(bus, "isa-ide");
+ d = DEVICE(isa);
+ if (k->ide.get_iobase) {
+ qdev_prop_set_uint32(d, "iobase", k->ide.get_iobase(sio, 0));
+ }
+ if (k->ide.get_iobase) {
+ qdev_prop_set_uint32(d, "iobase2", k->ide.get_iobase(sio, 1));
+ }
+ if (k->ide.get_irq) {
+ qdev_prop_set_uint32(d, "irq", k->ide.get_irq(sio, 0));
+ }
+ qdev_init_nofail(d);
+ sio->ide = isa;
+ trace_superio_create_ide(0,
+ k->ide.get_iobase ?
+ k->ide.get_iobase(sio, 0) : -1,
+ k->ide.get_irq ?
+ k->ide.get_irq(sio, 0) : -1);
+ }
}
static void isa_superio_class_init(ObjectClass *oc, void *data)
diff --git a/hw/isa/pc87312.c b/hw/isa/pc87312.c
index a1845a91c3..5cf64505fe 100644
--- a/hw/isa/pc87312.c
+++ b/hw/isa/pc87312.c
@@ -150,16 +150,28 @@ static unsigned int get_fdc_irq(ISASuperIODevice *sio,
uint8_t index)
/* IDE controller */
-static inline bool is_ide_enabled(PC87312State *s)
+static bool is_ide_enabled(ISASuperIODevice *sio, uint8_t index)
{
+ PC87312State *s = PC87312(sio);
+
return s->regs[REG_FER] & FER_IDE_EN;
}
-static inline uint16_t get_ide_iobase(PC87312State *s)
+static uint16_t get_ide_iobase(ISASuperIODevice *sio, uint8_t index)
{
+ PC87312State *s = PC87312(sio);
+
+ if (index == 1) {
+ return get_ide_iobase(sio, 0) + 0x206;
+ }
return (s->regs[REG_FER] & FER_IDE_ADDR) ? 0x170 : 0x1f0;
}
+static unsigned int get_ide_irq(ISASuperIODevice *sio, uint8_t index)
+{
+ assert(index == 0);
+ return 14;
+}
static void reconfigure_devices(PC87312State *s)
{
@@ -277,14 +289,11 @@ static void pc87312_reset(DeviceState *d)
static void pc87312_realize(DeviceState *dev, Error **errp)
{
PC87312State *s;
- DeviceState *d;
ISADevice *isa;
- ISABus *bus;
Error *local_err = NULL;
s = PC87312(dev);
isa = ISA_DEVICE(dev);
- bus = isa_bus_from_device(isa);
isa_register_ioport(isa, &s->io, s->iobase);
pc87312_hard_reset(s);
@@ -293,17 +302,6 @@ static void pc87312_realize(DeviceState *dev, Error **errp)
error_propagate(errp, local_err);
return;
}
-
- if (is_ide_enabled(s)) {
- isa = isa_create(bus, "isa-ide");
- d = DEVICE(isa);
- qdev_prop_set_uint32(d, "iobase", get_ide_iobase(s));
- qdev_prop_set_uint32(d, "iobase2", get_ide_iobase(s) + 0x206);
- qdev_prop_set_uint32(d, "irq", 14);
- qdev_init_nofail(d);
- s->ide.dev = isa;
- trace_pc87312_info_ide(get_ide_iobase(s));
- }
}
static void pc87312_initfn(Object *obj)
@@ -361,6 +359,12 @@ static void pc87312_class_init(ObjectClass *klass, void
*data)
.get_iobase = get_fdc_iobase,
.get_irq = get_fdc_irq,
};
+ sc->ide = (ISASuperIOFuncs){
+ .count = 1,
+ .is_enabled = is_ide_enabled,
+ .get_iobase = get_ide_iobase,
+ .get_irq = get_ide_irq,
+ };
}
static const TypeInfo pc87312_type_info = {
diff --git a/hw/isa/trace-events b/hw/isa/trace-events
index 8d9900882f..80ac6175d6 100644
--- a/hw/isa/trace-events
+++ b/hw/isa/trace-events
@@ -4,8 +4,8 @@
superio_create_parallel(int id, uint16_t base, unsigned int irq) "id=%d, base
0x%03x, irq %u"
superio_create_serial(int id, uint16_t base, unsigned int irq) "id=%d, base
0x%03x, irq %u"
superio_create_floppy(int id, uint16_t base, unsigned int irq) "id=%d, base
0x%03x, irq %u"
+superio_create_ide(int id, uint16_t base, unsigned int irq) "id=%d, base
0x%03x, irq %u"
# hw/isa/pc87312.c
pc87312_io_read(uint32_t addr, uint32_t val) "read addr=0x%x val=0x%x"
pc87312_io_write(uint32_t addr, uint32_t val) "write addr=0x%x val=0x%x"
-pc87312_info_ide(uint32_t base) "base 0x%x"
--
2.16.2
- [Qemu-devel] [PATCH 04/25] MAINTAINERS: Fix the PC87312 include path, (continued)
- [Qemu-devel] [PATCH 04/25] MAINTAINERS: Fix the PC87312 include path, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 05/25] hw/isa/pc87312: Rename the device type as TYPE_PC87312_SUPERIO, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 06/25] hw/isa/pc87312: Use uint16_t for the ISA I/O base address, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 07/25] hw/isa/pc87312: Use 'unsigned int' for the irq value, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 08/25] hw/isa/superio: Add a Super I/O template based on the PC87312 device, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 09/25] hw/isa/pc87312: Inherit from the abstract TYPE_ISA_SUPERIO, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 11/25] hw/isa/superio: Factor out the serial code from pc87312.c, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 13/25] hw/isa/superio: Add a keyboard/mouse controller (8042), Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 10/25] hw/isa/superio: Factor out the parallel code from pc87312.c, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 12/25] hw/isa/superio: Factor out the floppy disc controller code from pc87312.c, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 14/25] hw/isa/superio: Factor out the IDE code from pc87312.c,
Philippe Mathieu-Daudé <=
- [Qemu-devel] [PATCH 16/25] hw/isa/superio: Factor out the FDC37M817 Super I/O from mips_malta.c, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 18/25] hw/isa/vt82c686: Rename vt82c686b_init() -> vt82c686b_isa_init(), Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 15/25] hw/mips/malta: Code movement, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 19/25] hw/isa/vt82c686: Add the TYPE_VT82C686B_SUPERIO, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 17/25] hw/mips/mips_fulong2e: Factor out vt82c686b_southbridge_init(), Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 20/25] MAINTAINERS: Add entries for the VT82C686B Super I/O, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 21/25] MAINTAINERS: Split the Alpha TCG/machine section, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 24/25] hw/alpha/dp264: Use the TYPE_SMC37C669_SUPERIO, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 23/25] hw/alpha/dp264: Add the ISA DMA controller, Philippe Mathieu-Daudé, 2018/03/08
- [Qemu-devel] [PATCH 22/25] hw/isa/superio: Add the SMC FDC37C669 Super I/O, Philippe Mathieu-Daudé, 2018/03/08