aboutsummaryrefslogtreecommitdiff
path: root/hw/serial.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-10-13 13:38:39 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-27 12:28:42 -0500
commite8ee28fb3e6cc2c4f5ec10d0aec9ff8ae9469e93 (patch)
tree16eace0c597cf768456f8475799c43b6fdfe8e81 /hw/serial.c
parent844e78ef9c6102cc3e33e4aa00efc8abdf0d8dde (diff)
isa: configure serial+parallel by index.
This patch adds a 'index' property to the isa-parallel and isa-serial devices. This can be used to create devices with the default isa irqs and ioports by simply specifying the index, i.e. -device isa-serial,index=1 instead of -device isa-serial,iobase=0x2f8,irq=3 for ttyS1 aka com2. Likewise for parallel ports. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/serial.c')
-rw-r--r--hw/serial.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/hw/serial.c b/hw/serial.c
index eb14f11ba1..869063cb3e 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -148,6 +148,7 @@ struct SerialState {
typedef struct ISASerialState {
ISADevice dev;
+ uint32_t index;
uint32_t iobase;
uint32_t isairq;
SerialState state;
@@ -733,11 +734,25 @@ static void serial_init_core(SerialState *s)
serial_event, s);
}
+static const int isa_serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
+static const int isa_serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
+
static int serial_isa_initfn(ISADevice *dev)
{
+ static int index;
ISASerialState *isa = DO_UPCAST(ISASerialState, dev, dev);
SerialState *s = &isa->state;
+ if (isa->index == -1)
+ isa->index = index;
+ if (isa->index >= MAX_SERIAL_PORTS)
+ return -1;
+ if (isa->iobase == -1)
+ isa->iobase = isa_serial_io[isa->index];
+ if (isa->isairq == -1)
+ isa->isairq = isa_serial_irq[isa->index];
+ index++;
+
s->baudbase = 115200;
isa_init_irq(dev, &s->irq, isa->isairq);
serial_init_core(s);
@@ -748,16 +763,12 @@ static int serial_isa_initfn(ISADevice *dev)
return 0;
}
-static const int isa_serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
-static const int isa_serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
-
SerialState *serial_isa_init(int index, CharDriverState *chr)
{
ISADevice *dev;
dev = isa_create("isa-serial");
- qdev_prop_set_uint32(&dev->qdev, "iobase", isa_serial_io[index]);
- qdev_prop_set_uint32(&dev->qdev, "irq", isa_serial_irq[index]);
+ qdev_prop_set_uint32(&dev->qdev, "index", index);
qdev_prop_set_chr(&dev->qdev, "chardev", chr);
if (qdev_init(&dev->qdev) < 0)
return NULL;
@@ -886,8 +897,9 @@ static ISADeviceInfo serial_isa_info = {
.qdev.size = sizeof(ISASerialState),
.init = serial_isa_initfn,
.qdev.props = (Property[]) {
- DEFINE_PROP_HEX32("iobase", ISASerialState, iobase, 0x3f8),
- DEFINE_PROP_UINT32("irq", ISASerialState, isairq, 4),
+ DEFINE_PROP_HEX32("index", ISASerialState, index, -1),
+ DEFINE_PROP_HEX32("iobase", ISASerialState, iobase, -1),
+ DEFINE_PROP_UINT32("irq", ISASerialState, isairq, -1),
DEFINE_PROP_CHR("chardev", ISASerialState, state.chr),
DEFINE_PROP_END_OF_LIST(),
},