From patchwork Mon Aug 24 11:03:28 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 31907 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 bilbo.ozlabs.org (Postfix) with ESMTPS id A6426B7B64 for ; Mon, 24 Aug 2009 21:16:52 +1000 (EST) Received: from localhost ([127.0.0.1]:41540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfXXd-00017m-5G for incoming@patchwork.ozlabs.org; Mon, 24 Aug 2009 07:16:49 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MfXNT-000662-Ni for qemu-devel@nongnu.org; Mon, 24 Aug 2009 07:06:19 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MfXNQ-00062P-0m for qemu-devel@nongnu.org; Mon, 24 Aug 2009 07:06:19 -0400 Received: from [199.232.76.173] (port=49188 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MfXNP-000623-71 for qemu-devel@nongnu.org; Mon, 24 Aug 2009 07:06:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20021) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MfXNO-0006v1-JW for qemu-devel@nongnu.org; Mon, 24 Aug 2009 07:06:14 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7OB6Eua002875 for ; Mon, 24 Aug 2009 07:06:14 -0400 Received: from localhost.localdomain (vpn2-8-191.ams2.redhat.com [10.36.8.191]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7OB63UT030007; Mon, 24 Aug 2009 07:06:13 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 24 Aug 2009 13:03:28 +0200 Message-Id: <9052e745819c03d86640f258f86e2a5e9424d55c.1251111439.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 07/22] ne2000: Remove unneeded double indirection of PCINE2000State 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 Once there, do the right DO_UPCAST instead of cast. Note that we maintain pci_dev field in this case, because there exist ne2000 isa cards. They to diferentiate them is that isa ones don't set this link. Signed-off-by: Juan Quintela --- hw/ne2000.c | 27 ++++++++++----------------- 1 files changed, 10 insertions(+), 17 deletions(-) diff --git a/hw/ne2000.c b/hw/ne2000.c index 070afcc..7ac4fd3 100644 --- a/hw/ne2000.c +++ b/hw/ne2000.c @@ -122,6 +122,7 @@ #define NE2000_MEM_SIZE NE2000_PMEM_END typedef struct NE2000State { + PCIDevice dev; uint8_t cmd; uint32_t start; uint32_t stop; @@ -771,16 +772,10 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd) /***********************************************************/ /* PCI NE2000 definitions */ -typedef struct PCINE2000State { - PCIDevice dev; - NE2000State ne2000; -} PCINE2000State; - static void ne2000_map(PCIDevice *pci_dev, int region_num, uint32_t addr, uint32_t size, int type) { - PCINE2000State *d = (PCINE2000State *)pci_dev; - NE2000State *s = &d->ne2000; + NE2000State *s = DO_UPCAST(NE2000State, dev, pci_dev); register_ioport_write(addr, 16, 1, ne2000_ioport_write, s); register_ioport_read(addr, 16, 1, ne2000_ioport_read, s); @@ -805,25 +800,23 @@ static void ne2000_cleanup(VLANClientState *vc) static void pci_ne2000_init(PCIDevice *pci_dev) { - PCINE2000State *d = (PCINE2000State *)pci_dev; - NE2000State *s; + NE2000State *s = DO_UPCAST(NE2000State, dev, pci_dev); uint8_t *pci_conf; - pci_conf = d->dev.config; + pci_conf = s->dev.config; pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK); pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8029); pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET); pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type pci_conf[0x3d] = 1; // interrupt pin 0 - pci_register_bar(&d->dev, 0, 0x100, + pci_register_bar(&s->dev, 0, 0x100, PCI_ADDRESS_SPACE_IO, ne2000_map); - s = &d->ne2000; - s->irq = d->dev.irq[0]; - s->pci_dev = pci_dev; - qdev_get_macaddr(&d->dev.qdev, s->macaddr); + s->irq = s->dev.irq[0]; + s->pci_dev = &s->dev; + qdev_get_macaddr(&s->dev.qdev, s->macaddr); ne2000_reset(s); - s->vc = qdev_get_vlan_client(&d->dev.qdev, + s->vc = qdev_get_vlan_client(&s->dev.qdev, ne2000_can_receive, ne2000_receive, NULL, ne2000_cleanup, s); @@ -834,7 +827,7 @@ static void pci_ne2000_init(PCIDevice *pci_dev) static PCIDeviceInfo ne2000_info = { .qdev.name = "ne2k_pci", - .qdev.size = sizeof(PCINE2000State), + .qdev.size = sizeof(NE2000State), .init = pci_ne2000_init, };