From patchwork Tue Aug 16 16:45:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 110193 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 813BBB6F72 for ; Wed, 17 Aug 2011 02:48:15 +1000 (EST) Received: from localhost ([::1]:39666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QtMoG-00041j-Iq for incoming@patchwork.ozlabs.org; Tue, 16 Aug 2011 12:48:12 -0400 Received: from eggs.gnu.org ([140.186.70.92]:49867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QtMo6-0003xo-BE for qemu-devel@nongnu.org; Tue, 16 Aug 2011 12:48:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QtMo4-00025B-MJ for qemu-devel@nongnu.org; Tue, 16 Aug 2011 12:48:02 -0400 Received: from mail-vw0-f45.google.com ([209.85.212.45]:57789) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QtMo4-00024p-C6 for qemu-devel@nongnu.org; Tue, 16 Aug 2011 12:48:00 -0400 Received: by vws17 with SMTP id 17so96031vws.4 for ; Tue, 16 Aug 2011 09:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=rl1HmRO1ySlsc3dANNj7Lb/mKCPnRl6DqyPYWdGGUgQ=; b=L+enRz44r/UbpzbRre8D7XNm4s4n8NfQheV6b076zVDjSHbaU/EDZnM0GudnY5a+Kd YzLuKW+B3A9FOLN2iKjgW0IwmZVwKQESvGOZxGkDUbxGCHE9z9o3rAaLVGRsCiAe+LqD wj5oixZACv92bQnEaPnUe08dpYAGmiEFOW+SE= Received: by 10.52.25.110 with SMTP id b14mr4499256vdg.122.1313513279871; Tue, 16 Aug 2011 09:47:59 -0700 (PDT) Received: from localhost.localdomain (c-71-227-161-214.hsd1.wa.comcast.net [71.227.161.214]) by mx.google.com with ESMTPS id gw3sm246636vdb.44.2011.08.16.09.47.58 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 16 Aug 2011 09:47:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 16 Aug 2011 09:45:32 -0700 Message-Id: <1313513145-5348-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1313513145-5348-1-git-send-email-rth@twiddle.net> References: <1313513145-5348-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.212.45 Cc: avi@redhat.com Subject: [Qemu-devel] [PATCH 01/14] 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 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 --- 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 char *isabus_get_fw_dev_path(DeviceState *dev) 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);