From patchwork Thu Oct 6 10:23:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 118062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A5DD5B7090 for ; Thu, 6 Oct 2011 22:36:26 +1100 (EST) Received: from localhost ([::1]:38828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBl7x-0005cR-DS for incoming@patchwork.ozlabs.org; Thu, 06 Oct 2011 06:24:33 -0400 Received: from eggs.gnu.org ([140.186.70.92]:52131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBl7M-0003mi-J0 for qemu-devel@nongnu.org; Thu, 06 Oct 2011 06:24:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RBl7I-0002OK-Mn for qemu-devel@nongnu.org; Thu, 06 Oct 2011 06:23:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16494) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RBl7I-0002Nl-DE for qemu-devel@nongnu.org; Thu, 06 Oct 2011 06:23:52 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p96ANpZ3010171 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 6 Oct 2011 06:23:51 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p96ANnvk018713 for ; Thu, 6 Oct 2011 06:23:51 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id EA30B250B6C; Thu, 6 Oct 2011 12:23:43 +0200 (IST) From: Avi Kivity To: qemu-devel@nongnu.org Date: Thu, 6 Oct 2011 12:23:20 +0200 Message-Id: <1317896615-25202-11-git-send-email-avi@redhat.com> In-Reply-To: <1317896615-25202-1-git-send-email-avi@redhat.com> References: <1317896615-25202-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/25] isa: Tidy support code for isabus_get_fw_dev_path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Richard Henderson The only user of ISADevice.ioports is isabus_get_fw_dev_path, and it only looks at the first entry of the array. Which suggests that this entire array+sort operation can be replaced by a simple minimum. Signed-off-by: Richard Henderson Signed-off-by: Avi Kivity --- hw/isa-bus.c | 25 +++++-------------------- hw/isa.h | 5 +---- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/hw/isa-bus.c b/hw/isa-bus.c index 6c15a31..e9c1712 100644 --- a/hw/isa-bus.c +++ b/hw/isa-bus.c @@ -83,24 +83,11 @@ void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq) dev->nirqs++; } -static void isa_init_ioport_one(ISADevice *dev, uint16_t ioport) -{ - assert(dev->nioports < ARRAY_SIZE(dev->ioports)); - dev->ioports[dev->nioports++] = ioport; -} - -static int isa_cmp_ports(const void *p1, const void *p2) -{ - return *(uint16_t*)p1 - *(uint16_t*)p2; -} - void isa_init_ioport_range(ISADevice *dev, uint16_t start, uint16_t length) { - int i; - for (i = start; i < start + length; i++) { - isa_init_ioport_one(dev, i); + if (dev->ioport_id == 0 || start < dev->ioport_id) { + dev->ioport_id = start; } - qsort(dev->ioports, dev->nioports, sizeof(dev->ioports[0]), isa_cmp_ports); } void isa_init_ioport(ISADevice *dev, uint16_t ioport) @@ -112,9 +99,7 @@ void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start) { memory_region_add_subregion(isabus->address_space_io, start, io); if (dev != NULL) { - assert(dev->nio < ARRAY_SIZE(dev->io)); - dev->io[dev->nio++] = io; - isa_init_ioport_range(dev, start, memory_region_size(io)); + isa_init_ioport(dev, start); } } @@ -208,8 +193,8 @@ static void isabus_register_devices(void) int off; off = snprintf(path, sizeof(path), "%s", qdev_fw_name(dev)); - if (d->nioports) { - snprintf(path + off, sizeof(path) - off, "@%04x", d->ioports[0]); + if (d->ioport_id) { + snprintf(path + off, sizeof(path) - off, "@%04x", d->ioport_id); } return strdup(path); diff --git a/hw/isa.h b/hw/isa.h index 432d17a..c5c2618 100644 --- a/hw/isa.h +++ b/hw/isa.h @@ -13,12 +13,9 @@ typedef struct ISADeviceInfo ISADeviceInfo; struct ISADevice { DeviceState qdev; - MemoryRegion *io[32]; uint32_t isairq[2]; - uint16_t ioports[32]; int nirqs; - int nioports; - int nio; + int ioport_id; }; typedef int (*isa_qdev_initfn)(ISADevice *dev);