Skip to contentSkip to conversation

Rework PCMCIA subsystem

PATCH Superseded Dmitry Eremin-Solenikov 1 participant 10 messages Apr 11, 2011 – Apr 21, 2011 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Rework PCMCIA subsystem

Please pull the following changeset that makes PCMCIA subsystem to use QBus and Qdev for managing devices. Currently the only implementation of PCMCIA host is a PXA2xx host and the only possible PCMCIA device is IDE MicroDrive (dscm1xxxx).

With this patchset I can create a microdrive device from command line:
-device dscm1xxxx -device ide-drive,drive=test -drive if=none,id=test,file=/dev/null

Dmitry Eremin-Solenikov (7):
pxa2xx_pcmcia: qdevify
PCMCIA: start qdev'ication
microdrive: qdevify
pcmcia: move all card callbacks to PCMCIACardInfo
pcmcia: move attach and detach socket methods to PCMCIASocket
pxa: change order of pcmcia devices instantiation, so that the socket 0 will be default
ide-core: allocate metadata storage for CFATA drives

 Makefile.objs       |    3 +
 hw/ide/core.c       |    4 ++
 hw/ide/internal.h   |    2 +
 hw/ide/microdrive.c |   88 +++++++++++++++++++-----------
 hw/mainstone.c      |   14 +++--
 hw/pcmcia.c         |  145 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pcmcia.h         |   49 ++++++++++++-----
 hw/pxa.h            |    9 +---
 hw/pxa2xx.c         |    9 ++--
 hw/pxa2xx_pcmcia.c  |  148 ++++++++++++++++++++++++++++++---------------------
 hw/spitz.c          |   26 ++++++----
 hw/tosa.c           |   18 ++++---
 vl.c                |   43 ---------------
 13 files changed, 372 insertions(+), 186 deletions(-)
 create mode 100644 hw/pcmcia.c
#2 lore raw

PATCH 2/7 PCMCIA: start qdev'ication

Convert PCMCIA bus handling code to use QBus internally. MicroDrive code is still unaffected.

---
 Makefile.objs      |    3 ++
 hw/pcmcia.c        |  102 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pcmcia.h        |   15 +++++++-
 hw/pxa2xx_pcmcia.c |    2 +-
 vl.c               |   43 ----------------------
 5 files changed, 120 insertions(+), 45 deletions(-)
 create mode 100644 hw/pcmcia.c
Makefile.objs +3 -0
index 44ce368..153a148 100644
@@ -289,6 +289,9 @@ hw-obj-$(CONFIG_REALLY_VIRTFS) += virtio-9p-debug.o
 hw-obj-$(CONFIG_VIRTFS) += virtio-9p-local.o virtio-9p-xattr.o
 hw-obj-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
 
+# PCMCIA
+hw-obj-y += pcmcia.o
+
 ######################################################################
 # libdis
 # NOTE: the disassembler code is only needed for debugging
hw/pcmcia.c new file +102 -0

102 lines not on this page · raw message

hw/pcmcia.h +14 -1
index f0b16b8..561d86c 100644
@@ -1,19 +1,30 @@
 /* PCMCIA/Cardbus */
 
 #include "qemu-common.h"
+#include "qdev.h"
 
 typedef struct {
+    BusState qbus;
     qemu_irq irq;
     int attached;
     const char *slot_string;
     const char *card_string;
 } PCMCIASocket;
 
-void pcmcia_socket_register(PCMCIASocket *socket);
+void pcmcia_socket_register(PCMCIASocket *socket, DeviceState *parent);
 void pcmcia_socket_unregister(PCMCIASocket *socket);
 void pcmcia_info(Monitor *mon);
 
+typedef struct PCMCIACardInfo {
+    DeviceInfo qdev;
+
+    int (*init)(PCMCIACardState *state);
+} PCMCIACardInfo;
+
 struct PCMCIACardState {
+    DeviceState dev;
+    PCMCIACardInfo *info;
+
     void *state;
     PCMCIASocket *slot;
     int (*attach)(void *state);
@@ -30,6 +41,8 @@ struct PCMCIACardState {
     void (*io_write)(void *state, uint32_t address, uint16_t value);
 };
 
+void pcmcia_card_register(PCMCIACardInfo *info);
+
 #define CISTPL_DEVICE		0x01	/* 5V Device Information Tuple */
 #define CISTPL_NO_LINK		0x14	/* No Link Tuple */
 #define CISTPL_VERS_1		0x15	/* Level 1 Version Tuple */
hw/pxa2xx_pcmcia.c +1 -1
index 3d93829..61afaf1 100644
@@ -187,7 +187,7 @@ static int pxa2xx_pcmcia_initfn(SysBusDevice *dev)
     s->slot.slot_string = str;
 
     s->slot.irq = qemu_allocate_irqs(pxa2xx_pcmcia_set_irq, s, 1)[0];
-    pcmcia_socket_register(&s->slot);
+    pcmcia_socket_register(&s->slot, &s->busdev.qdev);
     return 0;
 }
 
vl.c +0 -43

49 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/7 pxa2xx_pcmcia: qdevify

In reply to Dmitry Eremin-Solenikov

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).

---
 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(-)
hw/mainstone.c +8 -6
index 50691ca..77b224c 100644
@@ -149,12 +149,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));
hw/pcmcia.h +3 -0
index 50648c9..f0b16b8 100644
@@ -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);
hw/pxa.h +1 -4
index d982f00..25176ef 100644
@@ -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;
hw/pxa2xx.c +5 -4
index 9b95e2c..ef4c0a2 100644
@@ -13,6 +13,7 @@
 #include "pc.h"
 #include "i2c.h"
 #include "ssi.h"
+#include "pcmcia.h"
 #include "qemu-char.h"
 #include "blockdev.h"
 
@@ -2221,8 +2222,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));
@@ -2357,8 +2358,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));
hw/pxa2xx_pcmcia.c +56 -21

120 lines not on this page · raw message

hw/spitz.c +12 -8
index 006f7a9..ce19b5a 100644
@@ -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.  */
hw/tosa.c +6 -6
index b8b6c4f..a988507 100644
@@ -102,13 +102,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]);
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 3/7 microdrive: qdevify

In reply to Dmitry Eremin-Solenikov

Switch dscm1xxxx microdrive driver to use qdev infrastructure.

---
 hw/ide/microdrive.c |   49 +++++++++++++++++++++++++++++++++++++++----------
 hw/pcmcia.h         |    2 +-
 hw/spitz.c          |    5 ++++-
 hw/tosa.c           |    5 ++++-
 4 files changed, 48 insertions(+), 13 deletions(-)
hw/ide/microdrive.c +39 -10
index 2ceeb87..167ec09 100644
@@ -39,8 +39,8 @@
 
 /* DSCM-1XXXX Microdrive hard disk with CF+ II / PCMCIA interface.  */
 typedef struct {
-    IDEBus bus;
     PCMCIACardState card;
+    IDEBus bus;
     uint32_t attr_base;
     uint32_t io_base;
 
@@ -530,22 +530,51 @@ static int dscm1xxxx_detach(void *opaque)
     return 0;
 }
 
-PCMCIACardState *dscm1xxxx_init(DriveInfo *bdrv)
+PCMCIACardState *dscm1xxxx_init(PCMCIASocket *socket, DriveInfo *bdrv)
+{
+    DeviceState *dev;
+    MicroDriveState *md;
+
+    dev = qdev_create(&socket->qbus, "dscm1xxxx");
+    qdev_init_nofail(dev);
+    md = DO_UPCAST(MicroDriveState, card.dev, dev);
+
+    ide_create_drive(&md->bus, 0, bdrv);
+    md->bus.ifs[0].drive_kind = IDE_CFATA;
+    md->bus.ifs[0].mdata_size = METADATA_SIZE;
+    md->bus.ifs[0].mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE);
+
+    return &md->card;
+}
+
+static int dscm1xxxx_initfn(PCMCIACardState *state)
 {
-    MicroDriveState *md = (MicroDriveState *) qemu_mallocz(sizeof(MicroDriveState));
+    MicroDriveState *md;
+    md = DO_UPCAST(MicroDriveState, card, state);
+
     md->card.state = md;
     md->card.attach = dscm1xxxx_attach;
     md->card.detach = dscm1xxxx_detach;
     md->card.cis = dscm1xxxx_cis;
     md->card.cis_len = sizeof(dscm1xxxx_cis);
 
-    ide_init2_with_non_qdev_drives(&md->bus, bdrv, NULL,
-                                   qemu_allocate_irqs(md_set_irq, md, 1)[0]);
-    md->bus.ifs[0].drive_kind = IDE_CFATA;
-    md->bus.ifs[0].mdata_size = METADATA_SIZE;
-    md->bus.ifs[0].mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE);
+    ide_bus_new(&md->bus, &state->dev, 0);
+    qdev_init_gpio_in(&state->dev, md_set_irq, 1);
+    ide_init2(&md->bus, qdev_get_gpio_in(&state->dev, 0));
 
-    vmstate_register(NULL, -1, &vmstate_microdrive, md);
+    return 0;
+}
 
-    return &md->card;
+static PCMCIACardInfo dscm1xxxx_info = {
+    .qdev.name      = "dscm1xxxx",
+    .qdev.desc      = "QEMU CF MicroDrive emulation",
+    .init           = dscm1xxxx_initfn,
+    .qdev.size      = sizeof(MicroDriveState),
+    .qdev.vmsd      = &vmstate_microdrive,
+};
+
+static void dscm1xxxx_register(void)
+{
+    pcmcia_card_register(&dscm1xxxx_info);
 }
+device_init(dscm1xxxx_register);
hw/pcmcia.h +1 -1
index 561d86c..c6b8100 100644
@@ -64,4 +64,4 @@ void pcmcia_card_register(PCMCIACardInfo *info);
 DeviceState *pxa2xx_pcmcia_init(target_phys_addr_t base, uint8_t id);
 
 /* dscm1xxxx.c */
-PCMCIACardState *dscm1xxxx_init(DriveInfo *bdrv);
+PCMCIACardState *dscm1xxxx_init(PCMCIASocket *socket, DriveInfo *bdrv);
hw/spitz.c +4 -1
index ce19b5a..51cc08c 100644
@@ -714,7 +714,10 @@ static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
         return;
     bs = dinfo->bdrv;
     if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
-        md = dscm1xxxx_init(dinfo);
+        md = dscm1xxxx_init(
+                        DO_UPCAST(PCMCIASocket, qbus,
+                            qdev_get_child_bus(cpu->pcmcia[slot], "pcmcia")),
+                        dinfo);
         pxa2xx_pcmcia_attach(cpu->pcmcia[slot], md);
     }
 }
hw/tosa.c +4 -1
index a988507..1435ea2 100644
@@ -60,7 +60,10 @@ static void tosa_microdrive_attach(PXA2xxState *cpu)
         return;
     bs = dinfo->bdrv;
     if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
-        md = dscm1xxxx_init(dinfo);
+        md = dscm1xxxx_init(
+                        DO_UPCAST(PCMCIASocket, qbus,
+                            qdev_get_child_bus(cpu->pcmcia[0], "pcmcia")),
+                        dinfo);
         pxa2xx_pcmcia_attach(cpu->pcmcia[0], md);
     }
 }
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH 5/7 pcmcia: move attach and detach socket methods to PCMCIASocket

In reply to Dmitry Eremin-Solenikov

Make attach and detach calls to be automatically called by PCMCIA card instantiation code, rather than calling them by hand from the board code.

---
 hw/pcmcia.c        |   45 +++++++++++++++++++++++++++++++-
 hw/pcmcia.h        |    2 +
 hw/pxa.h           |    4 ---
 hw/pxa2xx_pcmcia.c |   73 +++++++++++++++++++++++----------------------------
 hw/spitz.c         |    1 -
 hw/tosa.c          |    1 -
 6 files changed, 79 insertions(+), 47 deletions(-)
hw/pcmcia.c +44 -1
index 17a49b6..d661663 100644
@@ -86,16 +86,59 @@ static int pcmcia_device_init(DeviceState *dev, DeviceInfo *info)
 {
     PCMCIACardState *state = DO_UPCAST(PCMCIACardState, dev, dev);
     PCMCIACardInfo *pinfo = DO_UPCAST(PCMCIACardInfo, qdev, info);
+    PCMCIASocket *socket = DO_UPCAST(PCMCIASocket, qbus, dev->parent_bus);
     int rc;
 
+    if (socket->attached) {
+        return -1;
+    }
+
     state->info = pinfo;
     rc = pinfo->init(state);
-    return rc;
+    if (rc) {
+        return rc;
+    }
+
+    socket->attached = 1;
+    state->slot = socket;
+
+    rc = socket->attach(socket, state);
+    if (rc) {
+        return rc;
+    }
+
+    rc = state->info->attach(state);
+    if (rc) {
+        socket->detach(socket);
+        return rc;
+    }
+
+    return 0;
+}
+
+static int pcmcia_device_exit(DeviceState *dev)
+{
+    PCMCIACardState *state = DO_UPCAST(PCMCIACardState, dev, dev);
+    PCMCIASocket *socket = DO_UPCAST(PCMCIASocket, qbus, dev->parent_bus);
+
+    if (!socket->attached) {
+        return -ENOENT;
+    }
+
+    state->info->detach(state);
+    state->slot = NULL;
+
+    socket->detach(socket);
+
+    socket->attached = 0;
+
+    return 0;
 }
 
 void pcmcia_card_register(PCMCIACardInfo *info)
 {
     info->qdev.init = pcmcia_device_init;
+    info->qdev.exit = pcmcia_device_exit;
     info->qdev.bus_info = &pcmcia_bus_info;
     assert(info->qdev.size >= sizeof(PCMCIACardState));
     qdev_register(&info->qdev);
hw/pcmcia.h +2 -0
index 2c012d9..4f90af7 100644
@@ -11,6 +11,8 @@ struct PCMCIASocket {
     int attached;
     const char *slot_string;
     const char *card_string;
+    int (*attach)(PCMCIASocket *socket, PCMCIACardState *card);
+    int (*detach)(PCMCIASocket *socket);
 };
 
 void pcmcia_socket_register(PCMCIASocket *socket, DeviceState *parent);
hw/pxa.h +0 -4
index 25176ef..c145029 100644
@@ -89,10 +89,6 @@ PXA2xxMMCIState *pxa2xx_mmci_init(target_phys_addr_t base,
 void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly,
                 qemu_irq coverswitch);
 
-/* pxa2xx_pcmcia.c */
-int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card);
-int pxa2xx_pcmcia_dettach(void *opaque);
-
 /* pxa2xx_keypad.c */
 struct  keymap {
     int column;
hw/pxa2xx_pcmcia.c +33 -40

87 lines not on this page · raw message

hw/spitz.c +0 -1
index 51cc08c..cf2ee82 100644
@@ -718,7 +718,6 @@ static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
                         DO_UPCAST(PCMCIASocket, qbus,
                             qdev_get_child_bus(cpu->pcmcia[slot], "pcmcia")),
                         dinfo);
-        pxa2xx_pcmcia_attach(cpu->pcmcia[slot], md);
     }
 }
 
hw/tosa.c +0 -1
index 1435ea2..d1777b7 100644
@@ -64,7 +64,6 @@ static void tosa_microdrive_attach(PXA2xxState *cpu)
                         DO_UPCAST(PCMCIASocket, qbus,
                             qdev_get_child_bus(cpu->pcmcia[0], "pcmcia")),
                         dinfo);
-        pxa2xx_pcmcia_attach(cpu->pcmcia[0], md);
     }
 }
 
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH 4/7 pcmcia: move all card callbacks to PCMCIACardInfo

In reply to Dmitry Eremin-Solenikov

last commit fixup

Revert "microdrive fixup"

This reverts commit 6a9f969b0626e218ff910d84ed1c9eec285cbcd5.

---
 hw/ide/microdrive.c |   41 ++++++++++++++++++++---------------------
 hw/pcmcia.h         |   29 +++++++++++++++--------------
 hw/pxa2xx_pcmcia.c  |   16 ++++++++--------
 3 files changed, 43 insertions(+), 43 deletions(-)
hw/ide/microdrive.c +20 -21
index 167ec09..a251544 100644
@@ -113,9 +113,9 @@ static void md_reset(MicroDriveState *s)
     ide_bus_reset(&s->bus);
 }
 
-static uint8_t md_attr_read(void *opaque, uint32_t at)
+static uint8_t md_attr_read(PCMCIACardState *opaque, uint32_t at)
 {
-    MicroDriveState *s = opaque;
+    MicroDriveState *s = DO_UPCAST(MicroDriveState, card, opaque);
     if (at < s->attr_base) {
         if (at < s->card.cis_len)
             return s->card.cis[at];
@@ -146,9 +146,9 @@ static uint8_t md_attr_read(void *opaque, uint32_t at)
     return 0;
 }
 
-static void md_attr_write(void *opaque, uint32_t at, uint8_t value)
+static void md_attr_write(PCMCIACardState *opaque, uint32_t at, uint8_t value)
 {
-    MicroDriveState *s = opaque;
+    MicroDriveState *s = DO_UPCAST(MicroDriveState, card, opaque);
     at -= s->attr_base;
 
     switch (at) {
@@ -177,9 +177,9 @@ static void md_attr_write(void *opaque, uint32_t at, uint8_t value)
     }
 }
 
-static uint16_t md_common_read(void *opaque, uint32_t at)
+static uint16_t md_common_read(PCMCIACardState *opaque, uint32_t at)
 {
-    MicroDriveState *s = opaque;
+    MicroDriveState *s = DO_UPCAST(MicroDriveState, card, opaque);
     IDEState *ifs;
     uint16_t ret;
     at -= s->io_base;
@@ -239,9 +239,9 @@ static uint16_t md_common_read(void *opaque, uint32_t at)
     return 0;
 }
 
-static void md_common_write(void *opaque, uint32_t at, uint16_t value)
+static void md_common_write(PCMCIACardState *opaque, uint32_t at, uint16_t value)
 {
-    MicroDriveState *s = opaque;
+    MicroDriveState *s = DO_UPCAST(MicroDriveState, card, opaque);
     at -= s->io_base;
 
     switch (s->opt & OPT_MODE) {
@@ -503,15 +503,9 @@ static const uint8_t dscm1xxxx_cis[0x14a] = {
     [0x146] = CISTPL_END,	/* Tuple End */
 };
 
-static int dscm1xxxx_attach(void *opaque)
+static int dscm1xxxx_attach(PCMCIACardState *opaque)
 {
-    MicroDriveState *md = opaque;
-    md->card.attr_read = md_attr_read;
-    md->card.attr_write = md_attr_write;
-    md->card.common_read = md_common_read;
-    md->card.common_write = md_common_write;
-    md->card.io_read = md_common_read;
-    md->card.io_write = md_common_write;
+    MicroDriveState *md = DO_UPCAST(MicroDriveState, card, opaque);
 
     md->attr_base = md->card.cis[0x74] | (md->card.cis[0x76] << 8);
     md->io_base = 0x0;
@@ -523,9 +517,9 @@ static int dscm1xxxx_attach(void *opaque)
     return 0;
 }
 
-static int dscm1xxxx_detach(void *opaque)
+static int dscm1xxxx_detach(PCMCIACardState *opaque)
 {
-    MicroDriveState *md = opaque;
+    MicroDriveState *md = DO_UPCAST(MicroDriveState, card, opaque);
     md_reset(md);
     return 0;
 }
@@ -552,9 +546,6 @@ static int dscm1xxxx_initfn(PCMCIACardState *state)
     MicroDriveState *md;
     md = DO_UPCAST(MicroDriveState, card, state);
 
-    md->card.state = md;
-    md->card.attach = dscm1xxxx_attach;
-    md->card.detach = dscm1xxxx_detach;
     md->card.cis = dscm1xxxx_cis;
     md->card.cis_len = sizeof(dscm1xxxx_cis);
 
@@ -571,6 +562,14 @@ static PCMCIACardInfo dscm1xxxx_info = {
     .init           = dscm1xxxx_initfn,
     .qdev.size      = sizeof(MicroDriveState),
     .qdev.vmsd      = &vmstate_microdrive,
+    .attach         = dscm1xxxx_attach,
+    .detach         = dscm1xxxx_detach,
+    .attr_read      = md_attr_read,
+    .attr_write     = md_attr_write,
+    .common_read    = md_common_read,
+    .common_write   = md_common_write,
+    .io_read        = md_common_read,
+    .io_write       = md_common_write,
 };
 
 static void dscm1xxxx_register(void)
hw/pcmcia.h +15 -14
index c6b8100..2c012d9 100644
@@ -3,13 +3,15 @@
 #include "qemu-common.h"
 #include "qdev.h"
 
-typedef struct {
+typedef struct PCMCIASocket PCMCIASocket;
+
+struct PCMCIASocket {
     BusState qbus;
     qemu_irq irq;
     int attached;
     const char *slot_string;
     const char *card_string;
-} PCMCIASocket;
+};
 
 void pcmcia_socket_register(PCMCIASocket *socket, DeviceState *parent);
 void pcmcia_socket_unregister(PCMCIASocket *socket);
@@ -19,26 +21,25 @@ typedef struct PCMCIACardInfo {
     DeviceInfo qdev;
 
     int (*init)(PCMCIACardState *state);
+
+    int (*attach)(PCMCIACardState *state);
+    int (*detach)(PCMCIACardState *state);
+
+    /* Only valid if attached */
+    uint8_t (*attr_read)(PCMCIACardState *state, uint32_t address);
+    void (*attr_write)(PCMCIACardState *state, uint32_t address, uint8_t value);
+    uint16_t (*common_read)(PCMCIACardState *state, uint32_t address);
+    void (*common_write)(PCMCIACardState *state, uint32_t address, uint16_t value);
+    uint16_t (*io_read)(PCMCIACardState *state, uint32_t address);
+    void (*io_write)(PCMCIACardState *state, uint32_t address, uint16_t value);
 } PCMCIACardInfo;
 
 struct PCMCIACardState {
     DeviceState dev;
     PCMCIACardInfo *info;
-
-    void *state;
     PCMCIASocket *slot;
-    int (*attach)(void *state);
-    int (*detach)(void *state);
     const uint8_t *cis;
     int cis_len;
-
-    /* Only valid if attached */
-    uint8_t (*attr_read)(void *state, uint32_t address);
-    void (*attr_write)(void *state, uint32_t address, uint8_t value);
-    uint16_t (*common_read)(void *state, uint32_t address);
-    void (*common_write)(void *state, uint32_t address, uint16_t value);
-    uint16_t (*io_read)(void *state, uint32_t address);
-    void (*io_write)(void *state, uint32_t address, uint16_t value);
 };
 
 void pcmcia_card_register(PCMCIACardInfo *info);
hw/pxa2xx_pcmcia.c +8 -8
index 61afaf1..ae7d01a 100644
@@ -29,7 +29,7 @@ static uint32_t pxa2xx_pcmcia_common_read(void *opaque,
     PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
 
     if (s->slot.attached) {
-        return s->card->common_read(s->card->state, offset);
+        return s->card->info->common_read(s->card, offset);
     }
 
     return 0;
@@ -41,7 +41,7 @@ static void pxa2xx_pcmcia_common_write(void *opaque,
     PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
 
     if (s->slot.attached) {
-        s->card->common_write(s->card->state, offset, value);
+        s->card->info->common_write(s->card, offset, value);
     }
 }
 
@@ -51,7 +51,7 @@ static uint32_t pxa2xx_pcmcia_attr_read(void *opaque,
     PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
 
     if (s->slot.attached) {
-        return s->card->attr_read(s->card->state, offset);
+        return s->card->info->attr_read(s->card, offset);
     }
 
     return 0;
@@ -63,7 +63,7 @@ static void pxa2xx_pcmcia_attr_write(void *opaque,
     PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
 
     if (s->slot.attached) {
-        s->card->attr_write(s->card->state, offset, value);
+        s->card->info->attr_write(s->card, offset, value);
     }
 }
 
@@ -73,7 +73,7 @@ static uint32_t pxa2xx_pcmcia_io_read(void *opaque,
     PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
 
     if (s->slot.attached) {
-        return s->card->io_read(s->card->state, offset);
+        return s->card->info->io_read(s->card, offset);
     }
 
     return 0;
@@ -85,7 +85,7 @@ static void pxa2xx_pcmcia_io_write(void *opaque,
     PXA2xxPCMCIAState *s = (PXA2xxPCMCIAState *) opaque;
 
     if (s->slot.attached) {
-        s->card->io_write(s->card->state, offset, value);
+        s->card->info->io_write(s->card, offset, value);
     }
 }
 
@@ -206,7 +206,7 @@ int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card)
 
     s->slot.attached = 1;
     s->card->slot = &s->slot;
-    s->card->attach(s->card->state);
+    s->card->info->attach(s->card);
 
     return 0;
 }
@@ -218,7 +218,7 @@ int pxa2xx_pcmcia_dettach(void *opaque)
     if (!s->slot.attached)
         return -ENOENT;
 
-    s->card->detach(s->card->state);
+    s->card->info->detach(s->card);
     s->card->slot = NULL;
     s->card = NULL;
 
Signature · 1 line
1.7.4.1
#6 lore raw

PATCH 6/7 pxa: change order of pcmcia devices instantiation, so that the socket 0 will be default

In reply to Dmitry Eremin-Solenikov
---
 hw/pxa2xx.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/pxa2xx.c +2 -2
index ef4c0a2..bcb42cf 100644
@@ -2222,8 +2222,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, 0);
     s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000, 1);
+    s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000, 0);
 
     sysbus_create_simple("pxa2xx_rtc", 0x40900000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_RTCALARM));
@@ -2358,8 +2358,8 @@ PXA2xxState *pxa255_init(unsigned int sdram_size)
                         qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
     }
 
-    s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000, 0);
     s->pcmcia[1] = pxa2xx_pcmcia_init(0x30000000, 1);
+    s->pcmcia[0] = pxa2xx_pcmcia_init(0x20000000, 0);
 
     sysbus_create_simple("pxa2xx_rtc", 0x40900000,
                     qdev_get_gpio_in(s->pic, PXA2XX_PIC_RTCALARM));
Signature · 1 line
1.7.4.1
#7 lore raw

PATCH 7/7 ide-core: allocate metadata storage for CFATA drives

In reply to Dmitry Eremin-Solenikov

Currently it's done by hw/ide/microdrive.c To simplify that part, move this initialization to ide core.

---
 hw/ide/core.c       |    4 ++++
 hw/ide/internal.h   |    2 ++
 hw/ide/microdrive.c |    6 +-----
 3 files changed, 7 insertions(+), 5 deletions(-)
hw/ide/core.c +4 -0
index c11d457..f6f7c04 100644
@@ -2556,6 +2556,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs,
             return -1;
         }
     }
+    if (s->drive_kind == IDE_CFATA) {
+        s->mdata_size = CFA_METADATA_SIZE;
+        s->mdata_storage = qemu_mallocz(CFA_METADATA_SIZE);
+    }
     if (serial) {
         strncpy(s->drive_serial_str, serial, sizeof(s->drive_serial_str));
     } else {
hw/ide/internal.h +2 -0
index d533fb6..d1e0528 100644
@@ -364,6 +364,8 @@ typedef struct IDEDMAOps IDEDMAOps;
 #define SMART_DISABLE         0xd9
 #define SMART_STATUS          0xda
 
+#define CFA_METADATA_SIZE     0x20
+
 typedef enum { IDE_HD, IDE_CD, IDE_CFATA } IDEDriveKind;
 
 typedef void EndTransferFunc(IDEState *);
hw/ide/microdrive.c +1 -5
index a251544..898ad15 100644
@@ -35,8 +35,6 @@
 /***********************************************************/
 /* CF-ATA Microdrive */
 
-#define METADATA_SIZE	0x20
-
 /* DSCM-1XXXX Microdrive hard disk with CF+ II / PCMCIA interface.  */
 typedef struct {
     PCMCIACardState card;
@@ -534,9 +532,6 @@ PCMCIACardState *dscm1xxxx_init(PCMCIASocket *socket, DriveInfo *bdrv)
     md = DO_UPCAST(MicroDriveState, card.dev, dev);
 
     ide_create_drive(&md->bus, 0, bdrv);
-    md->bus.ifs[0].drive_kind = IDE_CFATA;
-    md->bus.ifs[0].mdata_size = METADATA_SIZE;
-    md->bus.ifs[0].mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE);
 
     return &md->card;
 }
@@ -553,6 +548,7 @@ static int dscm1xxxx_initfn(PCMCIACardState *state)
     qdev_init_gpio_in(&state->dev, md_set_irq, 1);
     ide_init2(&md->bus, qdev_get_gpio_in(&state->dev, 0));
 
+    md->bus.ifs[0].drive_kind = IDE_CFATA;
     return 0;
 }
 
Signature · 1 line
1.7.4.1
#8 lore raw
In reply to Dmitry Eremin-Solenikov

Hi,

What about this serie of patches?

Quoted 39 lines · Dmitry Eremin-Solenikov

Please pull the following changeset that makes PCMCIA subsystem to use QBus and Qdev for managing devices. Currently the only implementation of PCMCIA host is a PXA2xx host and the only possible PCMCIA device is IDE MicroDrive (dscm1xxxx).

With this patchset I can create a microdrive device from command line:
-device dscm1xxxx -device ide-drive,drive=test -drive if=none,id=test,file=/dev/null

Dmitry Eremin-Solenikov (7):
pxa2xx_pcmcia: qdevify
PCMCIA: start qdev'ication
microdrive: qdevify
pcmcia: move all card callbacks to PCMCIACardInfo
pcmcia: move attach and detach socket methods to PCMCIASocket
pxa: change order of pcmcia devices instantiation, so that the socket
0 will be default
ide-core: allocate metadata storage for CFATA drives

 Makefile.objs       |    3 +
 hw/ide/core.c       |    4 ++
 hw/ide/internal.h   |    2 +
 hw/ide/microdrive.c |   88 +++++++++++++++++++-----------
 hw/mainstone.c      |   14 +++--
 hw/pcmcia.c         |  145
+++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pcmcia.h         |   49 ++++++++++++-----
 hw/pxa.h            |    9 +---
 hw/pxa2xx.c         |    9 ++--
 hw/pxa2xx_pcmcia.c  |  148
++++++++++++++++++++++++++++++---------------------
 hw/spitz.c          |   26 ++++++----
 hw/tosa.c           |   18 ++++---
 vl.c                |   43 ---------------
 13 files changed, 372 insertions(+), 186 deletions(-)
 create mode 100644 hw/pcmcia.c
Signature · 2 lines
With best wishes
Dmitry
#9 lore raw
In reply to Dmitry Eremin-Solenikov

Hello,

Quoted 29 lines · Dmitry Eremin-Solenikov

Please pull the following changeset that makes PCMCIA subsystem to use QBus and Qdev for managing devices. Currently the only implementation of PCMCIA host is a PXA2xx host and the only possible PCMCIA device is IDE MicroDrive (dscm1xxxx).

With this patchset I can create a microdrive device from command line:
-device dscm1xxxx -device ide-drive,drive=test -drive if=none,id=test,file=/dev/null

Dmitry Eremin-Solenikov (7):
pxa2xx_pcmcia: qdevify
PCMCIA: start qdev'ication
microdrive: qdevify
pcmcia: move all card callbacks to PCMCIACardInfo
pcmcia: move attach and detach socket methods to PCMCIASocket
pxa: change order of pcmcia devices instantiation, so that the socket
0 will be default
ide-core: allocate metadata storage for CFATA drives

 Makefile.objs       |    3 +
 hw/ide/core.c       |    4 ++
 hw/ide/internal.h   |    2 +
 hw/ide/microdrive.c |   88 +++++++++++++++++++-----------
 hw/mainstone.c      |   14 +++--
 hw/pcmcia.c         |  145
+++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pcmcia.h         |   49 ++++++++++++-----
 hw/pxa.h            |    9 +---
Quoted 8 lines
 hw/pxa2xx.c         |    9 ++--
 hw/pxa2xx_pcmcia.c  |  148
++++++++++++++++++++++++++++++---------------------
 hw/spitz.c          |   26 ++++++----
 hw/tosa.c           |   18 ++++---
 vl.c                |   43 ---------------
 13 files changed, 372 insertions(+), 186 deletions(-)
 create mode 100644 hw/pcmcia.c

Pinging again about this patchset. Any objections? Comments? Etc.?

Signature · 2 lines
With best wishes
Dmitry