From patchwork Tue Jul 28 16:22:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin O'Connor X-Patchwork-Id: 501299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6471E140D24 for ; Wed, 29 Jul 2015 02:23:20 +1000 (AEST) Received: from localhost ([::1]:59878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZK7ew-0002zU-9S for incoming@patchwork.ozlabs.org; Tue, 28 Jul 2015 12:23:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZK7eg-0002hJ-EF for qemu-devel@nongnu.org; Tue, 28 Jul 2015 12:23:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZK7ec-0005w9-0D for qemu-devel@nongnu.org; Tue, 28 Jul 2015 12:23:02 -0400 Received: from mail-qg0-f43.google.com ([209.85.192.43]:33895) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZK7eb-0005un-SD for qemu-devel@nongnu.org; Tue, 28 Jul 2015 12:22:57 -0400 Received: by qgeu79 with SMTP id u79so78546405qge.1 for ; Tue, 28 Jul 2015 09:22:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=C+PqSiML5fcX9q6gfAWoIPdKJ7kf/gpQ8cYh3IVgCzM=; b=OpVnyTSdNZcwrGU5nlbM6LA2VSNGpZFn+SltT3FVQy3nmgzGkot6egFhBjEI9mG7Uh YFxKx95KEQrpsBC5rGmPOArWMUDSn9QiwfLDx8lOJd8PExUs4CndEjrGA/n42U3hdCxT SU8F6YvLk9C+AcI5QIHoWweype3c0URHHMWIaGonkRCh8kK+W1AffIOC+Egh3gL0J9JZ LXnaLQOQZzcgRGstyluWM+rpUUQQQPW2+SGkVU5BIjQvvAJ+uEv1vtOV+BJ6Jdnl83A2 7jcHRXPf6vDhvjwl2H45sstvFn9wMy5j7AZY3GoEbR3A7YS15R35nY/T+BjAdWpqI5Q3 jzRA== X-Gm-Message-State: ALoCoQnfp8PzusZ9e+6RdbDGcEEn/9tE8cMwvq3VjziGTIrUfJqPSCcTm4P7Op/puHpSIn6JIsiH X-Received: by 10.140.38.138 with SMTP id t10mr17112479qgt.74.1438100576797; Tue, 28 Jul 2015 09:22:56 -0700 (PDT) Received: from localhost (209-122-232-221.c3-0.avec-ubr1.nyr-avec.ny.cable.rcn.com. [209.122.232.221]) by smtp.gmail.com with ESMTPSA id f31sm11404564qgf.19.2015.07.28.09.22.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jul 2015 09:22:56 -0700 (PDT) From: Kevin O'Connor To: qemu-devel@nongnu.org, Markus Armbruster , Paolo Bonzini , Stefan Hajnoczi Date: Tue, 28 Jul 2015 12:22:43 -0400 Message-Id: <1438100563-14453-1-git-send-email-kevin@koconnor.net> X-Mailer: git-send-email 1.9.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.43 Subject: [Qemu-devel] [PATCH] sdhci: Pass drive parameter to sdhci-pci via qdev property 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 Commit 19109131 disabled the sdhci-pci support because it used drive_get_next(). This patch reenables sdhci-pci and changes it to pass the drive via a qdev property - for example: -device sdhci-pci,drive=drive0 -drive id=drive0,if=sd,file=myimage Signed-off-by: Kevin O'Connor --- This patch only changes the SDHCI PCI code - the sysbus code continues to use drive_get_next(). The call to blk_detach_dev() is suspicious - I added it because sd.c:sd_init() calls blk_attach_dev_nofail() and that causes a crash if the drive is already attached to the PCI device. It's not clear to me how this should be wired up though. --- hw/sd/sdhci.c | 34 +++++++++++++++++++++------------- hw/sd/sdhci.h | 2 ++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index e63367b..296bf2a 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -1142,13 +1142,9 @@ static inline unsigned int sdhci_get_fifolen(SDHCIState *s) } } -static void sdhci_initfn(SDHCIState *s) +static void sdhci_initfn(SDHCIState *s, BlockBackend *blk) { - DriveInfo *di; - - /* FIXME use a qdev drive property instead of drive_get_next() */ - di = drive_get_next(IF_SD); - s->card = sd_init(di ? blk_by_legacy_dinfo(di) : NULL, false); + s->card = sd_init(blk, false); if (s->card == NULL) { exit(1); } @@ -1214,7 +1210,8 @@ const VMStateDescription sdhci_vmstate = { /* Capabilities registers provide information on supported features of this * specific host controller implementation */ -static Property sdhci_properties[] = { +static Property sdhci_pci_properties[] = { + DEFINE_BLOCK_PROPERTIES(SDHCIState, conf), DEFINE_PROP_UINT32("capareg", SDHCIState, capareg, SDHC_CAPAB_REG_DEFAULT), DEFINE_PROP_UINT32("maxcurr", SDHCIState, maxcurr, 0), @@ -1226,7 +1223,9 @@ static void sdhci_pci_realize(PCIDevice *dev, Error **errp) SDHCIState *s = PCI_SDHCI(dev); dev->config[PCI_CLASS_PROG] = 0x01; /* Standard Host supported DMA */ dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */ - sdhci_initfn(s); + if (s->conf.blk) + blk_detach_dev(s->conf.blk, dev); + sdhci_initfn(s, s->conf.blk); s->buf_maxsz = sdhci_get_fifolen(s); s->fifo_buffer = g_malloc0(s->buf_maxsz); s->irq = pci_allocate_irq(dev); @@ -1253,9 +1252,7 @@ static void sdhci_pci_class_init(ObjectClass *klass, void *data) k->class_id = PCI_CLASS_SYSTEM_SDHCI; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->vmsd = &sdhci_vmstate; - dc->props = sdhci_properties; - /* Reason: realize() method uses drive_get_next() */ - dc->cannot_instantiate_with_device_add_yet = true; + dc->props = sdhci_pci_properties; } static const TypeInfo sdhci_pci_info = { @@ -1265,10 +1262,21 @@ static const TypeInfo sdhci_pci_info = { .class_init = sdhci_pci_class_init, }; +static Property sdhci_sysbus_properties[] = { + DEFINE_PROP_UINT32("capareg", SDHCIState, capareg, + SDHC_CAPAB_REG_DEFAULT), + DEFINE_PROP_UINT32("maxcurr", SDHCIState, maxcurr, 0), + DEFINE_PROP_END_OF_LIST(), +}; + static void sdhci_sysbus_init(Object *obj) { SDHCIState *s = SYSBUS_SDHCI(obj); - sdhci_initfn(s); + DriveInfo *di; + + /* FIXME use a qdev drive property instead of drive_get_next() */ + di = drive_get_next(IF_SD); + sdhci_initfn(s, di ? blk_by_legacy_dinfo(di) : NULL); } static void sdhci_sysbus_finalize(Object *obj) @@ -1295,7 +1303,7 @@ static void sdhci_sysbus_class_init(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); dc->vmsd = &sdhci_vmstate; - dc->props = sdhci_properties; + dc->props = sdhci_sysbus_properties; dc->realize = sdhci_sysbus_realize; /* Reason: instance_init() method uses drive_get_next() */ dc->cannot_instantiate_with_device_add_yet = true; diff --git a/hw/sd/sdhci.h b/hw/sd/sdhci.h index 3352d23..e2de92d 100644 --- a/hw/sd/sdhci.h +++ b/hw/sd/sdhci.h @@ -26,6 +26,7 @@ #define SDHCI_H #include "qemu-common.h" +#include "hw/block/block.h" #include "hw/pci/pci.h" #include "hw/sysbus.h" #include "hw/sd.h" @@ -239,6 +240,7 @@ typedef struct SDHCIState { }; SDState *card; MemoryRegion iomem; + BlockConf conf; QEMUTimer *insert_timer; /* timer for 'changing' sd card. */ QEMUTimer *transfer_timer;