From patchwork Wed Oct 7 14:56:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 35305 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 84AE5B7B9A for ; Thu, 8 Oct 2009 02:21:54 +1100 (EST) Received: from localhost ([127.0.0.1]:33121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvYKq-0005qL-KO for incoming@patchwork.ozlabs.org; Wed, 07 Oct 2009 11:21:48 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvXx0-00038e-98 for qemu-devel@nongnu.org; Wed, 07 Oct 2009 10:57:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvXwt-0002zM-9t for qemu-devel@nongnu.org; Wed, 07 Oct 2009 10:57:07 -0400 Received: from [199.232.76.173] (port=55165 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvXwt-0002z1-03 for qemu-devel@nongnu.org; Wed, 07 Oct 2009 10:57:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20384) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvXws-0003gB-HU for qemu-devel@nongnu.org; Wed, 07 Oct 2009 10:57:02 -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 n97Ev1cd023546 for ; Wed, 7 Oct 2009 10:57:01 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n97Eulnw016943; Wed, 7 Oct 2009 10:57:00 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 7 Oct 2009 16:56:27 +0200 Message-Id: <6b3ee4c5d9903529b091f5e8fde891890fe6006f.1254927187.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: 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. Subject: [Qemu-devel] [PATCH 10/12] ide: cmd646 we can get the pci device with container_of 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/ide/cmd646.c | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-) diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c index 37cfe01..a36c3b5 100644 --- a/hw/ide/cmd646.c +++ b/hw/ide/cmd646.c @@ -68,10 +68,19 @@ static void ide_map(PCIDevice *pci_dev, int region_num, } } +static PCIIDEState *pci_from_bm(BMDMAState *bm) +{ + if (bm->unit == 0) { + return container_of(bm, PCIIDEState, bmdma[0]); + } else { + return container_of(bm, PCIIDEState, bmdma[1]); + } +} + static uint32_t bmdma_readb(void *opaque, uint32_t addr) { BMDMAState *bm = opaque; - PCIIDEState *pci_dev; + PCIIDEState *pci_dev = pci_from_bm(bm); uint32_t val; switch(addr & 3) { @@ -79,14 +88,12 @@ static uint32_t bmdma_readb(void *opaque, uint32_t addr) val = bm->cmd; break; case 1: - pci_dev = bm->pci_dev; val = pci_dev->dev.config[MRDMODE]; break; case 2: val = bm->status; break; case 3: - pci_dev = bm->pci_dev; if (bm == &pci_dev->bmdma[0]) { val = pci_dev->dev.config[UDIDETCR0]; } else { @@ -106,13 +113,12 @@ static uint32_t bmdma_readb(void *opaque, uint32_t addr) static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val) { BMDMAState *bm = opaque; - PCIIDEState *pci_dev; + PCIIDEState *pci_dev = pci_from_bm(bm); #ifdef DEBUG_IDE printf("bmdma: writeb 0x%02x : 0x%02x\n", addr, val); #endif switch(addr & 3) { case 1: - pci_dev = bm->pci_dev; pci_dev->dev.config[MRDMODE] = (pci_dev->dev.config[MRDMODE] & ~0x30) | (val & 0x30); cmd646_update_irq(pci_dev); @@ -121,7 +127,6 @@ static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val) bm->status = (val & 0x60) | (bm->status & 1) | (bm->status & ~val & 0x06); break; case 3: - pci_dev = bm->pci_dev; if (bm == &pci_dev->bmdma[0]) pci_dev->dev.config[UDIDETCR0] = val; else