From patchwork Tue Oct 13 11:38:39 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 35844 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9D164B7B86 for ; Tue, 13 Oct 2009 22:39:22 +1100 (EST) Received: from localhost ([127.0.0.1]:59563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mxfio-0007yv-Rf for incoming@patchwork.ozlabs.org; Tue, 13 Oct 2009 07:39:18 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MxfiN-0007yO-0m for qemu-devel@nongnu.org; Tue, 13 Oct 2009 07:38:51 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxfiI-0007xs-Sa for qemu-devel@nongnu.org; Tue, 13 Oct 2009 07:38:50 -0400 Received: from [199.232.76.173] (port=40945 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxfiI-0007xp-MD for qemu-devel@nongnu.org; Tue, 13 Oct 2009 07:38:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16214) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MxfiI-0007mW-6I for qemu-devel@nongnu.org; Tue, 13 Oct 2009 07:38:46 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9DBciTc023568 for ; Tue, 13 Oct 2009 07:38:45 -0400 Received: from zweiblum.home.kraxel.org (vpn1-5-43.ams2.redhat.com [10.36.5.43]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9DBcgpE030968; Tue, 13 Oct 2009 07:38:43 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id DBB48700FA; Tue, 13 Oct 2009 13:38:40 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 13 Oct 2009 13:38:39 +0200 Message-Id: <1255433919-25736-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH] isa: configure serial+parallel by index. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- hw/parallel.c | 23 +++++++++++++++++------ hw/serial.c | 26 +++++++++++++++++++------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/hw/parallel.c b/hw/parallel.c index 92eecb1..79fa8f6 100644 --- a/hw/parallel.c +++ b/hw/parallel.c @@ -80,6 +80,7 @@ struct ParallelState { typedef struct ISAParallelState { ISADevice dev; + uint32_t index; uint32_t iobase; uint32_t isairq; ParallelState state; @@ -445,11 +446,14 @@ static void parallel_reset(void *opaque) s->last_read_offset = ~0U; } +static const int isa_parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc }; + static int parallel_isa_initfn(ISADevice *dev) { + static int index; ISAParallelState *isa = DO_UPCAST(ISAParallelState, dev, dev); ParallelState *s = &isa->state; - int base = isa->iobase; + int base; uint8_t dummy; if (!s->chr) { @@ -457,6 +461,15 @@ static int parallel_isa_initfn(ISADevice *dev) exit(1); } + if (isa->index == -1) + isa->index = index; + if (isa->index >= MAX_PARALLEL_PORTS) + return -1; + if (isa->iobase == -1) + isa->iobase = isa_parallel_io[isa->index]; + index++; + + base = isa->iobase; isa_init_irq(dev, &s->irq, isa->isairq); parallel_reset(s); qemu_register_reset(parallel_reset, s); @@ -483,15 +496,12 @@ static int parallel_isa_initfn(ISADevice *dev) return 0; } -static const int isa_parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc }; - ParallelState *parallel_init(int index, CharDriverState *chr) { ISADevice *dev; dev = isa_create("isa-parallel"); - qdev_prop_set_uint32(&dev->qdev, "iobase", isa_parallel_io[index]); - qdev_prop_set_uint32(&dev->qdev, "irq", 7); + qdev_prop_set_uint32(&dev->qdev, "index", index); qdev_prop_set_chr(&dev->qdev, "chardev", chr); if (qdev_init(&dev->qdev) < 0) return NULL; @@ -579,7 +589,8 @@ static ISADeviceInfo parallel_isa_info = { .qdev.size = sizeof(ISAParallelState), .init = parallel_isa_initfn, .qdev.props = (Property[]) { - DEFINE_PROP_HEX32("iobase", ISAParallelState, iobase, 0x378), + DEFINE_PROP_HEX32("index", ISAParallelState, index, -1), + DEFINE_PROP_HEX32("iobase", ISAParallelState, iobase, -1), DEFINE_PROP_UINT32("irq", ISAParallelState, isairq, 7), DEFINE_PROP_CHR("chardev", ISAParallelState, state.chr), DEFINE_PROP_END_OF_LIST(), diff --git a/hw/serial.c b/hw/serial.c index eb14f11..869063c 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(), },