Skip to content

Commit

Permalink
hw/isa/superio: Factor out the IDE code from pc87312.c
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180308223946.26784-15-f4bug@amsat.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
philmd authored and bonzini committed Mar 12, 2018
1 parent 72d3d8f commit c16a4e1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
22 changes: 22 additions & 0 deletions hw/isa/isa-superio.c
Expand Up @@ -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)
Expand Down
36 changes: 20 additions & 16 deletions hw/isa/pc87312.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion hw/isa/trace-events
Expand Up @@ -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 changes: 2 additions & 0 deletions include/hw/isa/superio.h
Expand Up @@ -31,6 +31,7 @@ typedef struct ISASuperIODevice {
ISADevice *serial[MAX_SERIAL_PORTS];
ISADevice *floppy;
ISADevice *kbc;
ISADevice *ide;
} ISASuperIODevice;

typedef struct ISASuperIOFuncs {
Expand All @@ -50,6 +51,7 @@ typedef struct ISASuperIOClass {
ISASuperIOFuncs parallel;
ISASuperIOFuncs serial;
ISASuperIOFuncs floppy;
ISASuperIOFuncs ide;
} ISASuperIOClass;

#endif /* HW_ISA_SUPERIO_H */

0 comments on commit c16a4e1

Please sign in to comment.