qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Andreas Färber" <andreas.faerber@web.de>,
	"Gerd Hoffmann" <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 27/32] usb/ehci: Clean up SysBus and PCI EHCI split
Date: Tue,  8 Jan 2013 14:14:49 +0100	[thread overview]
Message-ID: <1357650894-16982-28-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1357650894-16982-1-git-send-email-kraxel@redhat.com>

From: Andreas Färber <andreas.faerber@web.de>

SysBus EHCI was introduced in a hurry before 1.3 Soft Freeze.
To use QOM casts in place of DO_UPCAST() / FROM_SYSBUS(), we need an
identifying type. Introduce generic abstract base types for PCI and
SysBus EHCI to allow multiple types to access the shared fields.

While at it, move the state structs being amended with macros to the
header file so that they can be embedded.

The VMSTATE_PCI_DEVICE() macro does not play nice with the QOM
parent_obj naming convention, so defer that cleanup.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/hcd-ehci-pci.c    |   39 ++++++++++++++++++++++++---------------
 hw/usb/hcd-ehci-sysbus.c |   19 ++++++++++---------
 hw/usb/hcd-ehci.h        |   26 ++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c
index ee77d41..0eb7826 100644
--- a/hw/usb/hcd-ehci-pci.c
+++ b/hw/usb/hcd-ehci-pci.c
@@ -16,14 +16,8 @@
  */
 
 #include "hw/usb/hcd-ehci.h"
-#include "hw/pci/pci.h"
 #include "qemu/range.h"
 
-typedef struct EHCIPCIState {
-    PCIDevice pcidev;
-    EHCIState ehci;
-} EHCIPCIState;
-
 typedef struct EHCIPCIInfo {
     const char *name;
     uint16_t vendor_id;
@@ -33,7 +27,7 @@ typedef struct EHCIPCIInfo {
 
 static int usb_ehci_pci_initfn(PCIDevice *dev)
 {
-    EHCIPCIState *i = DO_UPCAST(EHCIPCIState, pcidev, dev);
+    EHCIPCIState *i = PCI_EHCI(dev);
     EHCIState *s = &i->ehci;
     uint8_t *pci_conf = dev->config;
 
@@ -83,7 +77,7 @@ static int usb_ehci_pci_initfn(PCIDevice *dev)
 static void usb_ehci_pci_write_config(PCIDevice *dev, uint32_t addr,
                                       uint32_t val, int l)
 {
-    EHCIPCIState *i = DO_UPCAST(EHCIPCIState, pcidev, dev);
+    EHCIPCIState *i = PCI_EHCI(dev);
     bool busmaster;
 
     pci_default_write_config(dev, addr, val, l);
@@ -115,12 +109,8 @@ static void ehci_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-    EHCIPCIInfo *i = data;
 
     k->init = usb_ehci_pci_initfn;
-    k->vendor_id = i->vendor_id;
-    k->device_id = i->device_id;
-    k->revision = i->revision;
     k->class_id = PCI_CLASS_SERIAL_USB;
     k->config_write = usb_ehci_pci_write_config;
     k->no_hotplug = 1;
@@ -128,6 +118,24 @@ static void ehci_class_init(ObjectClass *klass, void *data)
     dc->props = ehci_pci_properties;
 }
 
+static const TypeInfo ehci_pci_type_info = {
+    .name = TYPE_PCI_EHCI,
+    .parent = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(EHCIPCIState),
+    .abstract = true,
+    .class_init = ehci_class_init,
+};
+
+static void ehci_data_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    EHCIPCIInfo *i = data;
+
+    k->vendor_id = i->vendor_id;
+    k->device_id = i->device_id;
+    k->revision = i->revision;
+}
+
 static struct EHCIPCIInfo ehci_pci_info[] = {
     {
         .name      = "usb-ehci",
@@ -150,12 +158,13 @@ static struct EHCIPCIInfo ehci_pci_info[] = {
 static void ehci_pci_register_types(void)
 {
     TypeInfo ehci_type_info = {
-        .parent        = TYPE_PCI_DEVICE,
-        .instance_size = sizeof(EHCIPCIState),
-        .class_init    = ehci_class_init,
+        .parent        = TYPE_PCI_EHCI,
+        .class_init    = ehci_data_class_init,
     };
     int i;
 
+    type_register_static(&ehci_pci_type_info);
+
     for (i = 0; i < ARRAY_SIZE(ehci_pci_info); i++) {
         ehci_type_info.name = ehci_pci_info[i].name;
         ehci_type_info.class_data = ehci_pci_info + i;
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
index 803df92..d431193 100644
--- a/hw/usb/hcd-ehci-sysbus.c
+++ b/hw/usb/hcd-ehci-sysbus.c
@@ -16,12 +16,6 @@
  */
 
 #include "hw/usb/hcd-ehci.h"
-#include "hw/sysbus.h"
-
-typedef struct EHCISysBusState {
-    SysBusDevice busdev;
-    EHCIState ehci;
-} EHCISysBusState;
 
 static const VMStateDescription vmstate_ehci_sysbus = {
     .name        = "ehci-sysbus",
@@ -40,7 +34,7 @@ static Property ehci_sysbus_properties[] = {
 
 static int usb_ehci_sysbus_initfn(SysBusDevice *dev)
 {
-    EHCISysBusState *i = FROM_SYSBUS(EHCISysBusState, dev);
+    EHCISysBusState *i = SYS_BUS_EHCI(dev);
     EHCIState *s = &i->ehci;
 
     s->capsbase = 0x100;
@@ -63,15 +57,22 @@ static void ehci_sysbus_class_init(ObjectClass *klass, void *data)
     dc->props = ehci_sysbus_properties;
 }
 
-TypeInfo ehci_xlnx_type_info = {
-    .name          = "xlnx,ps7-usb",
+static const TypeInfo ehci_type_info = {
+    .name          = TYPE_SYS_BUS_EHCI,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(EHCISysBusState),
+    .abstract      = true,
     .class_init    = ehci_sysbus_class_init,
 };
 
+static const TypeInfo ehci_xlnx_type_info = {
+    .name          = "xlnx,ps7-usb",
+    .parent        = TYPE_SYS_BUS_EHCI,
+};
+
 static void ehci_sysbus_register_types(void)
 {
+    type_register_static(&ehci_type_info);
     type_register_static(&ehci_xlnx_type_info);
 }
 
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index 14ee3be..5ba3faf 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -24,6 +24,8 @@
 #include "trace.h"
 #include "sysemu/dma.h"
 #include "sysemu/sysemu.h"
+#include "hw/pci/pci.h"
+#include "hw/sysbus.h"
 
 #ifndef EHCI_DEBUG
 #define EHCI_DEBUG   0
@@ -322,4 +324,28 @@ extern const VMStateDescription vmstate_ehci;
 
 void usb_ehci_initfn(EHCIState *s, DeviceState *dev);
 
+#define TYPE_PCI_EHCI "pci-ehci-usb"
+#define PCI_EHCI(obj) OBJECT_CHECK(EHCIPCIState, (obj), TYPE_PCI_EHCI)
+
+typedef struct EHCIPCIState {
+    /*< private >*/
+    PCIDevice pcidev;
+    /*< public >*/
+
+    EHCIState ehci;
+} EHCIPCIState;
+
+
+#define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"
+#define SYS_BUS_EHCI(obj) \
+    OBJECT_CHECK(EHCISysBusState, (obj), TYPE_SYS_BUS_EHCI)
+
+typedef struct EHCISysBusState {
+    /*< private >*/
+    SysBusDevice parent_obj;
+    /*< public >*/
+
+    EHCIState ehci;
+} EHCISysBusState;
+
 #endif
-- 
1.7.1

  parent reply	other threads:[~2013-01-08 13:56 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-08 13:14 [Qemu-devel] [PULL 00/32] usb patch queue Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 01/32] ehci: Add a ehci_writeback_async_complete_packet helper function Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 02/32] ehci: Add ehci_verify_qh and ehci_verify_qtd helper functions Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 03/32] ehci: Verify guest does not change the token of inflight qtd-s Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 04/32] ehci: Move get / put_dwords upwards Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 05/32] ehci: writeback_async_complete_packet: verify qh and qtd Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 06/32] ehci: Verify qtd for async completed packets Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 07/32] ehci: Add an ehci_get_pid helper function Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 08/32] ehci: Verify a queue's ep direction does not change Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 09/32] ehci: Use uframe precision for interrupt threshold checking (v2) Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 10/32] ehci: Further speedup rescanning if async schedule after raising an interrupt Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 11/32] ehci: Don't call commit_irq after raising PCD Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 12/32] uhci: Fix 1 ms delay in interrupt reporting to the guest Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 13/32] uhci: Fix pending interrupts getting lost on migration Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 14/32] uhci: Add a QH_VALID define Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 15/32] uhci: Limit amount of frames processed in one go Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 16/32] uhci: Maximize how many frames we catch up when behind Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 17/32] hid: Change idle handling to use a timer Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 18/32] usb: Fix usb_ep_find_packet_by_id Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 19/32] usb: Add an usb_device_ep_stopped USBDevice method Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 20/32] usbredir: Add an usbredir_stop_ep helper function Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 21/32] usbredir: Add USBEP2I and I2USBEP helper macros Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 22/32] usbredir: Add ep_stopped USBDevice method Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 23/32] usbredir: Verify we have 32 bits bulk length cap when redirecting to xhci Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 24/32] usbredir: Add usbredir_init_endpoints() helper Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 25/32] usb-redir: Add debugging to bufpq save / restore Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 26/32] xhci: call set-address with dummy usbpacket Gerd Hoffmann
2013-01-08 13:14 ` Gerd Hoffmann [this message]
2013-01-08 13:14 ` [Qemu-devel] [PATCH 28/32] usb/ehci: Move capsbase and opregbase into SysBus EHCI class Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 29/32] usb/ehci: Add SysBus EHCI device for Exynos4210 Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 30/32] exynos4210: Add EHCI support Gerd Hoffmann
2013-01-08 13:14 ` [Qemu-devel] [PATCH 31/32] usbredir: Add support for buffered bulk input (v2) Gerd Hoffmann
2013-01-09 20:52   ` Blue Swirl
2013-01-09 22:04     ` Hans de Goede
2013-01-12 10:21       ` Blue Swirl
2013-01-08 13:14 ` [Qemu-devel] [PATCH 32/32] uhci: stop using portio lists Gerd Hoffmann
2013-01-08 20:34 ` [Qemu-devel] [PULL 00/32] usb patch queue Anthony Liguori

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=1357650894-16982-28-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=andreas.faerber@web.de \
    --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).