From patchwork Mon Aug 24 16:42:39 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 31965 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 F213AB7B63 for ; Tue, 25 Aug 2009 03:10:56 +1000 (EST) Received: from localhost ([127.0.0.1]:50619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mfd4I-0002Ec-3Y for incoming@patchwork.ozlabs.org; Mon, 24 Aug 2009 13:10:54 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mfcfo-0000sV-DK for qemu-devel@nongnu.org; Mon, 24 Aug 2009 12:45:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mfcfi-0000j6-CL for qemu-devel@nongnu.org; Mon, 24 Aug 2009 12:45:34 -0400 Received: from [199.232.76.173] (port=33806 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mfcfh-0000im-P2 for qemu-devel@nongnu.org; Mon, 24 Aug 2009 12:45:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10168) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mfcfh-000336-6P for qemu-devel@nongnu.org; Mon, 24 Aug 2009 12:45:29 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7OGjSdJ018885 for ; Mon, 24 Aug 2009 12:45:28 -0400 Received: from localhost.localdomain (vpn1-4-157.ams2.redhat.com [10.36.4.157]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7OGjKTv024317; Mon, 24 Aug 2009 12:45:27 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 24 Aug 2009 18:42:39 +0200 Message-Id: <0c016cde7800838c12def950aeb49c196dec85f2.1251131364.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 05/26] rtl8139: Remove unneeded double indirection of PCIRTL8139State 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 Signed-off-by: Juan Quintela --- hw/rtl8139.c | 38 +++++++++++++------------------------- 1 files changed, 13 insertions(+), 25 deletions(-) diff --git a/hw/rtl8139.c b/hw/rtl8139.c index fcd6d95..a79b066 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -423,6 +423,7 @@ static void RTL8139TallyCounters_load(QEMUFile* f, RTL8139TallyCounters *tally_c static void RTL8139TallyCounters_save(QEMUFile* f, RTL8139TallyCounters *tally_counters); typedef struct RTL8139State { + PCIDevice dev; uint8_t phys[8]; /* mac address */ uint8_t mult[8]; /* multicast mask array */ @@ -463,7 +464,6 @@ typedef struct RTL8139State { uint16_t CpCmd; uint8_t TxThresh; - PCIDevice *pci_dev; VLANClientState *vc; uint8_t macaddr[6]; int rtl8139_mmio_io_addr; @@ -692,7 +692,7 @@ static void rtl8139_update_irq(RTL8139State *s) DEBUG_PRINT(("RTL8139: Set IRQ to %d (%04x %04x)\n", isr ? 1 : 0, s->IntrStatus, s->IntrMask)); - qemu_set_irq(s->pci_dev->irq[0], (isr != 0)); + qemu_set_irq(s->dev.irq[0], (isr != 0)); } #define POLYNOMIAL 0x04c11db6 @@ -3121,7 +3121,7 @@ static void rtl8139_save(QEMUFile* f,void* opaque) RTL8139State* s=(RTL8139State*)opaque; unsigned int i; - pci_device_save(s->pci_dev, f); + pci_device_save(&s->dev, f); qemu_put_buffer(f, s->phys, 6); qemu_put_buffer(f, s->mult, 8); @@ -3215,7 +3215,7 @@ static int rtl8139_load(QEMUFile* f,void* opaque,int version_id) return -EINVAL; if (version_id >= 3) { - ret = pci_device_load(s->pci_dev, f); + ret = pci_device_load(&s->dev, f); if (ret < 0) return ret; } @@ -3323,16 +3323,10 @@ static int rtl8139_load(QEMUFile* f,void* opaque,int version_id) /***********************************************************/ /* PCI RTL8139 definitions */ -typedef struct PCIRTL8139State { - PCIDevice dev; - RTL8139State rtl8139; -} PCIRTL8139State; - static void rtl8139_mmio_map(PCIDevice *pci_dev, int region_num, uint32_t addr, uint32_t size, int type) { - PCIRTL8139State *d = (PCIRTL8139State *)pci_dev; - RTL8139State *s = &d->rtl8139; + RTL8139State *s = DO_UPCAST(RTL8139State, dev, pci_dev); cpu_register_physical_memory(addr + 0, 0x100, s->rtl8139_mmio_io_addr); } @@ -3340,8 +3334,7 @@ static void rtl8139_mmio_map(PCIDevice *pci_dev, int region_num, static void rtl8139_ioport_map(PCIDevice *pci_dev, int region_num, uint32_t addr, uint32_t size, int type) { - PCIRTL8139State *d = (PCIRTL8139State *)pci_dev; - RTL8139State *s = &d->rtl8139; + RTL8139State *s = DO_UPCAST(RTL8139State, dev, pci_dev); register_ioport_write(addr, 0x100, 1, rtl8139_ioport_writeb, s); register_ioport_read( addr, 0x100, 1, rtl8139_ioport_readb, s); @@ -3437,8 +3430,7 @@ static void rtl8139_cleanup(VLANClientState *vc) static int pci_rtl8139_uninit(PCIDevice *dev) { - PCIRTL8139State *d = (PCIRTL8139State *)dev; - RTL8139State *s = &d->rtl8139; + RTL8139State *s = DO_UPCAST(RTL8139State, dev, dev); cpu_unregister_io_memory(s->rtl8139_mmio_io_addr); @@ -3447,13 +3439,12 @@ static int pci_rtl8139_uninit(PCIDevice *dev) static void pci_rtl8139_init(PCIDevice *dev) { - PCIRTL8139State *d = (PCIRTL8139State *)dev; - RTL8139State *s; + RTL8139State * s = DO_UPCAST(RTL8139State, dev, dev); uint8_t *pci_conf; - d->dev.unregister = pci_rtl8139_uninit; + s->dev.unregister = pci_rtl8139_uninit; - 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_8139); pci_conf[0x04] = 0x05; /* command = I/O space, Bus Master */ @@ -3463,19 +3454,16 @@ static void pci_rtl8139_init(PCIDevice *dev) pci_conf[0x3d] = 1; /* interrupt pin 0 */ pci_conf[0x34] = 0xdc; - s = &d->rtl8139; - /* I/O handler for memory-mapped I/O */ s->rtl8139_mmio_io_addr = cpu_register_io_memory(rtl8139_mmio_read, rtl8139_mmio_write, s); - pci_register_bar(&d->dev, 0, 0x100, + pci_register_bar(&s->dev, 0, 0x100, PCI_ADDRESS_SPACE_IO, rtl8139_ioport_map); - pci_register_bar(&d->dev, 1, 0x100, + pci_register_bar(&s->dev, 1, 0x100, PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map); - s->pci_dev = (PCIDevice *)d; qdev_get_macaddr(&dev->qdev, s->macaddr); qemu_register_reset(rtl8139_reset, s); rtl8139_reset(s); @@ -3501,7 +3489,7 @@ static void pci_rtl8139_init(PCIDevice *dev) static PCIDeviceInfo rtl8139_info = { .qdev.name = "rtl8139", - .qdev.size = sizeof(PCIRTL8139State), + .qdev.size = sizeof(RTL8139State), .init = pci_rtl8139_init, };