qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin O'Connor <kevin@koconnor.net>
Subject: [Qemu-devel] [PULL 47/47] sdhci: Support SDHCI devices on PCI
Date: Mon, 15 Dec 2014 17:38:31 +0100	[thread overview]
Message-ID: <1418661511-22348-48-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1418661511-22348-1-git-send-email-pbonzini@redhat.com>

From: Kevin O'Connor <kevin@koconnor.net>

Support for PCI devices following the "SD Host Controller Simplified
Specification Version 2.00" spec.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 default-configs/pci.mak |  2 ++
 hw/sd/sdhci.c           | 44 ++++++++++++++++++++++++++++++++++++++++++++
 hw/sd/sdhci.h           |  9 ++++++++-
 3 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index 91b1e92..a186c39 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -30,3 +30,5 @@ CONFIG_IPACK=y
 CONFIG_WDT_IB6300ESB=y
 CONFIG_PCI_TESTDEV=y
 CONFIG_NVME_PCI=y
+CONFIG_SD=y
+CONFIG_SDHCI=y
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index d7ca0c0..15064d3 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1220,6 +1220,49 @@ static Property sdhci_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
+static int sdhci_pci_init(PCIDevice *dev)
+{
+    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);
+    s->buf_maxsz = sdhci_get_fifolen(s);
+    s->fifo_buffer = g_malloc0(s->buf_maxsz);
+    s->irq = pci_allocate_irq(dev);
+    memory_region_init_io(&s->iomem, OBJECT(s), &sdhci_mmio_ops, s, "sdhci",
+            SDHC_REGISTERS_MAP_SIZE);
+    pci_register_bar(dev, 0, 0, &s->iomem);
+    return 0;
+}
+
+static void sdhci_pci_exit(PCIDevice *dev)
+{
+    SDHCIState *s = PCI_SDHCI(dev);
+    sdhci_uninitfn(s);
+}
+
+static void sdhci_pci_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->init = sdhci_pci_init;
+    k->exit = sdhci_pci_exit;
+    k->vendor_id = PCI_VENDOR_ID_REDHAT;
+    k->device_id = PCI_DEVICE_ID_REDHAT_SDHCI;
+    k->class_id = PCI_CLASS_SYSTEM_SDHCI;
+    set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
+    dc->vmsd = &sdhci_vmstate;
+    dc->props = sdhci_properties;
+}
+
+static const TypeInfo sdhci_pci_info = {
+    .name = TYPE_PCI_SDHCI,
+    .parent = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(SDHCIState),
+    .class_init = sdhci_pci_class_init,
+};
+
 static void sdhci_sysbus_init(Object *obj)
 {
     SDHCIState *s = SYSBUS_SDHCI(obj);
@@ -1265,6 +1308,7 @@ static const TypeInfo sdhci_sysbus_info = {
 
 static void sdhci_register_types(void)
 {
+    type_register_static(&sdhci_pci_info);
     type_register_static(&sdhci_sysbus_info);
 }
 
diff --git a/hw/sd/sdhci.h b/hw/sd/sdhci.h
index 9fbf682..3352d23 100644
--- a/hw/sd/sdhci.h
+++ b/hw/sd/sdhci.h
@@ -26,6 +26,7 @@
 #define SDHCI_H
 
 #include "qemu-common.h"
+#include "hw/pci/pci.h"
 #include "hw/sysbus.h"
 #include "hw/sd.h"
 
@@ -232,7 +233,10 @@ enum {
 
 /* SD/MMC host controller state */
 typedef struct SDHCIState {
-    SysBusDevice busdev;
+    union {
+        PCIDevice pcidev;
+        SysBusDevice busdev;
+    };
     SDState *card;
     MemoryRegion iomem;
 
@@ -281,6 +285,9 @@ typedef struct SDHCIState {
 
 extern const VMStateDescription sdhci_vmstate;
 
+#define TYPE_PCI_SDHCI "sdhci-pci"
+#define PCI_SDHCI(obj) OBJECT_CHECK(SDHCIState, (obj), TYPE_PCI_SDHCI)
+
 #define TYPE_SYSBUS_SDHCI "generic-sdhci"
 #define SYSBUS_SDHCI(obj)                               \
      OBJECT_CHECK(SDHCIState, (obj), TYPE_SYSBUS_SDHCI)
-- 
1.8.3.1

  parent reply	other threads:[~2014-12-15 16:40 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-15 16:37 [Qemu-devel] [PULL 00/47] Patches for KVM, x86, SCSI, migration fixes (2014-12-15) Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 01/47] Add bootloader name to multiboot implementation Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 02/47] target-i386: simplify AES emulation Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 03/47] KVM_CAP_IRQFD and KVM_CAP_IRQFD_RESAMPLE checks Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 04/47] vfio: use kvm_resamplefds_enabled() Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 05/47] valgrind: avoid false positives in KVM_GET_DIRTY_LOG ioctl Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 06/47] valgrind/i386: avoid false positives on KVM_SET_CLOCK ioctl Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 07/47] valgrind/i386: avoid false positives on KVM_SET_PIT ioctl Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 08/47] valgrind/i386: avoid false positives on KVM_SET_XCRS ioctl Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 09/47] valgrind/i386: avoid false positives on KVM_SET_MSRS ioctl Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 10/47] valgrind/i386: avoid false positives on KVM_GET_MSRS ioctl Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 11/47] valgrind/i386: avoid false positives on KVM_SET_VCPU_EVENTS ioctl Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 12/47] valgrind/s390x: avoid false positives on KVM_SET_FPU ioctl Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 13/47] coverity/s390x: avoid false positive in kvm_irqchip_add_adapter_route Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 14/47] target-i386: add feature flags for CPUID[EAX=0xd, ECX=1] Paolo Bonzini
2014-12-15 16:37 ` [Qemu-devel] [PULL 15/47] target-mips: kvm: do not use get_clock() Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 16/47] target-i386: get/set/migrate XSAVES state Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 17/47] x86: Drop superfluous conditionals around g_free() Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 18/47] x86: Fuse g_malloc(); memset() into g_malloc0() Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 19/47] x86: Use g_new() & friends where that makes obvious sense Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 20/47] x86: Drop some superfluous casts from void * Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 21/47] scsi: Drop superfluous conditionals around g_free() Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 22/47] scsi: Fuse g_malloc(); memset() into g_malloc0() Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 23/47] scsi: Use g_new() & friends where that makes obvious sense Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 24/47] scsi-disk: provide maximum transfer length Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 25/47] cpu-exec: fix cpu_exec_nocache Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 26/47] cpu-exec: reset exception_index correctly Paolo Bonzini
2014-12-19  2:19   ` Eduardo Habkost
2014-12-23  6:55     ` Pavel Dovgaluk
     [not found]     ` <2162.40673694319$1419317788@news.gmane.org>
2014-12-23  8:54       ` Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 27/47] icount: set can_do_io outside TB execution Paolo Bonzini
2014-12-17  8:53   ` Pavel Dovgaluk
2014-12-17  9:19     ` Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 28/47] icount: introduce cpu_get_icount_raw Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 29/47] cpu-exec: invalidate nocache translation if they are interrupted Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 30/47] timer: introduce new QEMU_CLOCK_VIRTUAL_RT clock Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 31/47] cpus: make icount warp behave well with respect to stop/cont Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 32/47] i386: do not cross the pages boundaries in replay mode Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 33/47] pc: add 2.3 machine types Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 34/47] target-i386: add VME to all CPUs Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 35/47] target-i386: add f16c and rdrand to Haswell and Broadwell Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 36/47] target-i386: add Ivy Bridge CPU model Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 37/47] kvm/apic: fix 2.2->2.1 migration Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 38/47] linuxboot: fix loading old kernels Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 39/47] serial: reset thri_pending on IER writes with THRI=0 Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 40/47] serial: clean up THRE/TEMT handling Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 41/47] serial: update LSR on enabling/disabling FIFOs Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 42/47] serial: only resample THR interrupt on rising edge of IER.THRI Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 43/47] sdhci: Set a default frequency clock Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 44/47] sdhci: Remove class "virtual" methods Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 45/47] sdhci: Add "sysbus" to sdhci QOM types and methods Paolo Bonzini
2014-12-15 16:38 ` [Qemu-devel] [PULL 46/47] sdhci: Define SDHCI PCI ids Paolo Bonzini
2014-12-15 16:38 ` Paolo Bonzini [this message]
2014-12-16 12:33 ` [Qemu-devel] [PULL 00/47] Patches for KVM, x86, SCSI, migration fixes (2014-12-15) Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418661511-22348-48-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kevin@koconnor.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).