Patchwork [RESEND,1/9] pxa2xx_pcmcia: qdevify

login
register
mail settings
Submitter Dmitry Eremin-Solenikov
Date April 25, 2011, 9:06 a.m.
Message ID <1303722395-10791-1-git-send-email-dbaryshkov@gmail.com>
Download mbox | patch
Permalink /patch/92710/
State New
Headers show

Comments

Dmitry Eremin-Solenikov - April 25, 2011, 9:06 a.m.
Use qdev insfrastructure for managing PXA PCMCIA devices. PCMCIA bus
itself isn't converted to QBus (yet). pxa2xx_pcmcia_init() function is
moved to pcmcia.h as it will be used by other cores/devices (like
StrongARM).

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
---
 hw/mainstone.c     |   14 +++++----
 hw/pcmcia.h        |    3 ++
 hw/pxa.h           |    5 +---
 hw/pxa2xx.c        |    9 +++---
 hw/pxa2xx_pcmcia.c |   77 +++++++++++++++++++++++++++++++++++++--------------
 hw/spitz.c         |   20 ++++++++-----
 hw/tosa.c          |   12 ++++----
 7 files changed, 91 insertions(+), 49 deletions(-)
Dmitry Eremin-Solenikov - April 29, 2011, 7:40 p.m.
Hello,

Any chance to get any response for this patches serie?

On 4/25/11, Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> wrote:
> Use qdev insfrastructure for managing PXA PCMCIA devices. PCMCIA bus
> itself isn't converted to QBus (yet). pxa2xx_pcmcia_init() function is
> moved to pcmcia.h as it will be used by other cores/devices (like
> StrongARM).
>
> Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Dmitry Eremin-Solenikov - May 3, 2011, 9:02 a.m.
Hello, colleagues,

On 4/29/11, Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> wrote:
> Hello,
>
> Any chance to get any response for this patches serie?

Still no response at all. Is there anything wrong with my approach? Is there
any problem with patch format? Am I just being ignored?

> On 4/25/11, Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> wrote:
>> Use qdev insfrastructure for managing PXA PCMCIA devices. PCMCIA bus
>> itself isn't converted to QBus (yet). pxa2xx_pcmcia_init() function is
>> moved to pcmcia.h as it will be used by other cores/devices (like
>> StrongARM).
>>
>> Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
>
> --
> With best wishes
> Dmitry
>

Patch

diff --git a/hw/mainstone.c b/hw/mainstone.c
index 4792f0e..11de723 100644
--- a/hw/mainstone.c
+++ b/hw/mainstone.c
@@ -148,12 +148,14 @@  static void mainstone_common_init(ram_addr_t ram_size,
     /* MMC/SD host */
     pxa2xx_mmci_handlers(cpu->mmc, NULL, qdev_get_gpio_in(mst_irq, MMC_IRQ));
 
-    pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[0],
-            qdev_get_gpio_in(mst_irq, S0_IRQ),
-            qdev_get_gpio_in(mst_irq, S0_CD_IRQ));
-    pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[1],
-            qdev_get_gpio_in(mst_irq, S1_IRQ),
-            qdev_get_gpio_in(mst_irq, S1_CD_IRQ));
+    sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[0]), 0,
+                    qdev_get_gpio_in(mst_irq, S0_IRQ));
+    sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[0]), 1,
+                    qdev_get_gpio_in(mst_irq, S0_CD_IRQ));
+    sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[1]), 0,
+                    qdev_get_gpio_in(mst_irq, S1_IRQ));
+    sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[1]), 1,
+                    qdev_get_gpio_in(mst_irq, S1_CD_IRQ));
 
     smc91c111_init(&nd_table[0], MST_ETH_PHYS,
                     qdev_get_gpio_in(mst_irq, ETHERNET_IRQ));
diff --git a/hw/pcmcia.h b/hw/pcmcia.h
index 50648c9..f0b16b8 100644
--- a/hw/pcmcia.h
+++ b/hw/pcmcia.h
@@ -47,5 +47,8 @@  struct PCMCIACardState {
 #define CISTPL_END		0xff	/* Tuple End */
 #define CISTPL_ENDMARK		0xff
 
+/* pxa2xx_pcmcia.h -- used also for StrongARM */
+DeviceState *pxa2xx_pcmcia_init(target_phys_addr_t base, uint8_t id);
+
 /* dscm1xxxx.c */
 PCMCIACardState *dscm1xxxx_init(DriveInfo *bdrv);
diff --git a/hw/pxa.h b/hw/pxa.h
index d982f00..25176ef 100644
--- a/hw/pxa.h
+++ b/hw/pxa.h
@@ -90,11 +90,8 @@  void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly,
                 qemu_irq coverswitch);
 
 /* pxa2xx_pcmcia.c */
-typedef struct PXA2xxPCMCIAState PXA2xxPCMCIAState;
-PXA2xxPCMCIAState *pxa2xx_pcmcia_init(target_phys_addr_t base);
 int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card);
 int pxa2xx_pcmcia_dettach(void *opaque);
-void pxa2xx_pcmcia_set_irq_cb(void *opaque, qemu_irq irq, qemu_irq cd_irq);
 
 /* pxa2xx_keypad.c */
 struct  keymap {
@@ -126,7 +123,7 @@  typedef struct {
     SSIBus **ssp;
     PXA2xxI2CState *i2c[2];
     PXA2xxMMCIState *mmc;
-    PXA2xxPCMCIAState *pcmcia[2];
+    DeviceState *pcmcia[2];
     PXA2xxI2SState *i2s;
     PXA2xxFIrState *fir;
     PXA2xxKeyPadState *kp;
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
index ac5d95d..6ae8c8c 100644
--- a/hw/pxa2xx.c
+++ b/hw/pxa2xx.c
@@ -13,6 +13,7 @@ 
 #include "pc.h"
 #include "i2c.h"
 #include "ssi.h"
+#include "pcmcia.h"
 #include "qemu-char.h"
 #include "blockdev.h"
 
@@ -2175,8 +2176,8 @@  PXA2xxState *pxa270_init(unsigned int sdram_size, const char *revision)
                         qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
     }
 
-    s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000);
-    s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000);
+    s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000, 0);
+    s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000, 1);
 
     sysbus_create_simple("pxa2xx_rtc", 0x40900000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_RTCALARM));
@@ -2311,8 +2312,8 @@  PXA2xxState *pxa255_init(unsigned int sdram_size)
                         qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
     }
 
-    s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000);
-    s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000);
+    s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000, 0);
+    s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000, 1);
 
     sysbus_create_simple("pxa2xx_rtc", 0x40900000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_RTCALARM));
diff --git a/hw/pxa2xx_pcmcia.c b/hw/pxa2xx_pcmcia.c
index 50d4649..3d93829 100644
--- a/hw/pxa2xx_pcmcia.c
+++ b/hw/pxa2xx_pcmcia.c
@@ -9,15 +9,19 @@ 
 
 #include "hw.h"
 #include "pcmcia.h"
+#include "sysbus.h"
 #include "pxa.h"
 
-struct PXA2xxPCMCIAState {
+typedef struct PXA2xxPCMCIAState {
+    SysBusDevice busdev;
+
+    uint8_t id;
     PCMCIASocket slot;
     PCMCIACardState *card;
 
     qemu_irq irq;
     qemu_irq cd_irq;
-};
+} PXA2xxPCMCIAState;
 
 static uint32_t pxa2xx_pcmcia_common_read(void *opaque,
                 target_phys_addr_t offset)
@@ -130,39 +134,61 @@  static void pxa2xx_pcmcia_set_irq(void *opaque, int line, int level)
     qemu_set_irq(s->irq, level);
 }
 
-PXA2xxPCMCIAState *pxa2xx_pcmcia_init(target_phys_addr_t base)
+DeviceState *pxa2xx_pcmcia_init(target_phys_addr_t base, uint8_t id)
 {
-    int iomemtype;
-    PXA2xxPCMCIAState *s;
+    SysBusDevice *dev;
+
+    dev = sysbus_from_qdev(qdev_create(NULL, "pxa2xx-pcmcia"));
+    qdev_prop_set_uint8(&dev->qdev, "id", id);
+    qdev_init_nofail(&dev->qdev);
+
+    sysbus_mmio_map(dev, 0, base | 0x00000000);
+    sysbus_mmio_map(dev, 1, base | 0x08000000);
+    sysbus_mmio_map(dev, 2, base | 0x0c000000);
+    /* IRQs are mapped in the board code */
 
-    s = (PXA2xxPCMCIAState *)
-            qemu_mallocz(sizeof(PXA2xxPCMCIAState));
+    return &dev->qdev;
+}
+
+static int pxa2xx_pcmcia_initfn(SysBusDevice *dev)
+{
+    int iomemtype;
+    char *str;
+    PXA2xxPCMCIAState *s = FROM_SYSBUS(PXA2xxPCMCIAState, dev);
 
     /* Socket I/O Memory Space */
     iomemtype = cpu_register_io_memory(pxa2xx_pcmcia_io_readfn,
                     pxa2xx_pcmcia_io_writefn, s, DEVICE_NATIVE_ENDIAN);
-    cpu_register_physical_memory(base | 0x00000000, 0x04000000, iomemtype);
+    sysbus_init_mmio(dev, 0x04000000, iomemtype);
 
     /* Then next 64 MB is reserved */
 
     /* Socket Attribute Memory Space */
     iomemtype = cpu_register_io_memory(pxa2xx_pcmcia_attr_readfn,
                     pxa2xx_pcmcia_attr_writefn, s, DEVICE_NATIVE_ENDIAN);
-    cpu_register_physical_memory(base | 0x08000000, 0x04000000, iomemtype);
+    sysbus_init_mmio(dev, 0x04000000, iomemtype);
 
     /* Socket Common Memory Space */
     iomemtype = cpu_register_io_memory(pxa2xx_pcmcia_common_readfn,
                     pxa2xx_pcmcia_common_writefn, s, DEVICE_NATIVE_ENDIAN);
-    cpu_register_physical_memory(base | 0x0c000000, 0x04000000, iomemtype);
+    sysbus_init_mmio(dev, 0x04000000, iomemtype);
+
+    sysbus_init_irq(dev, &s->irq);
+    sysbus_init_irq(dev, &s->cd_irq);
+
+    if (!dev->qdev.id) {
+        str = qemu_mallocz(256);
+        snprintf(str, 256, "pxa2xx-pcmcia.%d", s->id);
+        dev->qdev.id = str;
+    }
+
+    str = qemu_mallocz(256);
+    snprintf(str, 256, "PXA PC Card Socket %d", s->id);
+    s->slot.slot_string = str;
 
-    if (base == 0x30000000)
-        s->slot.slot_string = "PXA PC Card Socket 1";
-    else
-        s->slot.slot_string = "PXA PC Card Socket 0";
     s->slot.irq = qemu_allocate_irqs(pxa2xx_pcmcia_set_irq, s, 1)[0];
     pcmcia_socket_register(&s->slot);
-
-    return s;
+    return 0;
 }
 
 /* Insert a new card into a slot */
@@ -206,10 +232,19 @@  int pxa2xx_pcmcia_dettach(void *opaque)
     return 0;
 }
 
-/* Who to notify on card events */
-void pxa2xx_pcmcia_set_irq_cb(void *opaque, qemu_irq irq, qemu_irq cd_irq)
+static SysBusDeviceInfo pxa2xx_pcmcia_info = {
+    .init       = pxa2xx_pcmcia_initfn,
+    .qdev.name  = "pxa2xx-pcmcia",
+    .qdev.desc  = "PXA2xx PCMCIA controller",
+    .qdev.size  = sizeof(PXA2xxPCMCIAState),
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_UINT8("id", struct PXA2xxPCMCIAState, id, 0),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static void pxa2xx_pcmcia_register(void)
 {
-    PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
-    s->irq = irq;
-    s->cd_irq = cd_irq;
+    sysbus_register_withprop(&pxa2xx_pcmcia_info);
 }
+device_init(pxa2xx_pcmcia_register);
diff --git a/hw/spitz.c b/hw/spitz.c
index 006f7a9..ce19b5a 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -870,14 +870,18 @@  static void spitz_gpio_setup(PXA2xxState *cpu, int slots)
     qdev_connect_gpio_out(cpu->gpio, SPITZ_GPIO_ON_RESET, cpu->reset);
 
     /* PCMCIA signals: card's IRQ and Card-Detect */
-    if (slots >= 1)
-        pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[0],
-                        qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF1_IRQ),
-                        qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF1_CD));
-    if (slots >= 2)
-        pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[1],
-                        qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF2_IRQ),
-                        qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF2_CD));
+    if (slots >= 1) {
+        sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[0]), 0,
+                    qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF1_IRQ));
+        sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[0]), 1,
+                    qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF1_CD));
+    }
+    if (slots >= 2) {
+        sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[1]), 0,
+                    qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF2_IRQ));
+        sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[1]), 1,
+                    qdev_get_gpio_in(cpu->gpio, SPITZ_GPIO_CF2_CD));
+    }
 }
 
 /* Board init.  */
diff --git a/hw/tosa.c b/hw/tosa.c
index a7967a2..577b59f 100644
--- a/hw/tosa.c
+++ b/hw/tosa.c
@@ -101,13 +101,13 @@  static void tosa_gpio_setup(PXA2xxState *cpu,
     qdev_connect_gpio_out(cpu->gpio, TOSA_GPIO_ON_RESET, cpu->reset);
 
     /* PCMCIA signals: card's IRQ and Card-Detect */
-    pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[0],
-                        qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_CF_IRQ),
-                        qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_CF_CD));
+    sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[0]), 0,
+                    qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_CF_IRQ));
+    sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[0]), 1,
+                    qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_CF_CD));
 
-    pxa2xx_pcmcia_set_irq_cb(cpu->pcmcia[1],
-                        qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_JC_CF_IRQ),
-                        NULL);
+    sysbus_connect_irq(sysbus_from_qdev(cpu->pcmcia[1]), 0,
+                    qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_JC_CF_IRQ));
 
     qdev_connect_gpio_out(scp1, TOSA_GPIO_BT_LED, outsignals[0]);
     qdev_connect_gpio_out(scp1, TOSA_GPIO_NOTE_LED, outsignals[1]);