From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 14/28] ccid: convert to QEMU Object Model
Date: Tue, 24 Jan 2012 13:33:06 -0600 [thread overview]
Message-ID: <1327433600-7403-15-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1327433600-7403-1-git-send-email-aliguori@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/ccid-card-emulated.c | 27 ++++++++++------
hw/ccid-card-passthru.c | 27 ++++++++++------
hw/ccid.h | 28 +++++++++++------
hw/usb-ccid.c | 76 +++++++++++++++++++++++++++++++++++------------
4 files changed, 109 insertions(+), 49 deletions(-)
diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c
index 2d2ebce..6dabe7a 100644
--- a/hw/ccid-card-emulated.c
+++ b/hw/ccid-card-emulated.c
@@ -564,16 +564,23 @@ static int emulated_exitfn(CCIDCardState *base)
return 0;
}
-static CCIDCardInfo emulated_card_info = {
- .qdev.name = EMULATED_DEV_NAME,
- .qdev.desc = "emulated smartcard",
- .qdev.size = sizeof(EmulatedState),
- .initfn = emulated_initfn,
- .exitfn = emulated_exitfn,
- .get_atr = emulated_get_atr,
- .apdu_from_guest = emulated_apdu_from_guest,
- .qdev.unplug = qdev_simple_unplug_cb,
- .qdev.props = (Property[]) {
+static void emulated_class_initfn(ObjectClass *klass, void *data)
+{
+ CCIDCardClass *cc = CCID_CARD_CLASS(klass);
+
+ cc->initfn = emulated_initfn;
+ cc->exitfn = emulated_exitfn;
+ cc->get_atr = emulated_get_atr;
+ cc->apdu_from_guest = emulated_apdu_from_guest;
+}
+
+static DeviceInfo emulated_card_info = {
+ .name = EMULATED_DEV_NAME,
+ .desc = "emulated smartcard",
+ .size = sizeof(EmulatedState),
+ .unplug = qdev_simple_unplug_cb,
+ .class_init = emulated_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_STRING("backend", EmulatedState, backend_str),
DEFINE_PROP_STRING("cert1", EmulatedState, cert1),
DEFINE_PROP_STRING("cert2", EmulatedState, cert2),
diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c
index 9f51c6c..f563d97 100644
--- a/hw/ccid-card-passthru.c
+++ b/hw/ccid-card-passthru.c
@@ -316,16 +316,23 @@ static VMStateDescription passthru_vmstate = {
}
};
-static CCIDCardInfo passthru_card_info = {
- .qdev.name = PASSTHRU_DEV_NAME,
- .qdev.desc = "passthrough smartcard",
- .qdev.size = sizeof(PassthruState),
- .qdev.vmsd = &passthru_vmstate,
- .initfn = passthru_initfn,
- .exitfn = passthru_exitfn,
- .get_atr = passthru_get_atr,
- .apdu_from_guest = passthru_apdu_from_guest,
- .qdev.props = (Property[]) {
+static void passthru_class_initfn(ObjectClass *klass, void *data)
+{
+ CCIDCardClass *cc = CCID_CARD_CLASS(klass);
+
+ cc->initfn = passthru_initfn;
+ cc->exitfn = passthru_exitfn;
+ cc->get_atr = passthru_get_atr;
+ cc->apdu_from_guest = passthru_apdu_from_guest;
+}
+
+static DeviceInfo passthru_card_info = {
+ .name = PASSTHRU_DEV_NAME,
+ .desc = "passthrough smartcard",
+ .size = sizeof(PassthruState),
+ .vmsd = &passthru_vmstate,
+ .class_init = passthru_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_CHR("chardev", PassthruState, cs),
DEFINE_PROP_UINT8("debug", PassthruState, debug, 0),
DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/ccid.h b/hw/ccid.h
index 9e3abe1..9e4979c 100644
--- a/hw/ccid.h
+++ b/hw/ccid.h
@@ -15,26 +15,34 @@
typedef struct CCIDCardState CCIDCardState;
typedef struct CCIDCardInfo CCIDCardInfo;
-/*
- * state of the CCID Card device (i.e. hw/ccid-card-*.c)
- */
-struct CCIDCardState {
- DeviceState qdev;
- uint32_t slot; /* For future use with multiple slot reader. */
-};
+#define TYPE_CCID_CARD "ccid-card"
+#define CCID_CARD(obj) \
+ OBJECT_CHECK(CCIDCardState, (obj), TYPE_CCID_CARD)
+#define CCID_CARD_CLASS(klass) \
+ OBJECT_CLASS_CHECK(CCIDCardClass, (klass), TYPE_CCID_CARD)
+#define CCID_CARD_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(CCIDCardClass, (obj), TYPE_CCID_CARD)
/*
* callbacks to be used by the CCID device (hw/usb-ccid.c) to call
* into the smartcard device (hw/ccid-card-*.c)
*/
-struct CCIDCardInfo {
- DeviceInfo qdev;
+typedef struct CCIDCardClass {
+ DeviceClass parent_class;
const uint8_t *(*get_atr)(CCIDCardState *card, uint32_t *len);
void (*apdu_from_guest)(CCIDCardState *card,
const uint8_t *apdu,
uint32_t len);
int (*exitfn)(CCIDCardState *card);
int (*initfn)(CCIDCardState *card);
+} CCIDCardClass;
+
+/*
+ * state of the CCID Card device (i.e. hw/ccid-card-*.c)
+ */
+struct CCIDCardState {
+ DeviceState qdev;
+ uint32_t slot; /* For future use with multiple slot reader. */
};
/*
@@ -46,7 +54,7 @@ void ccid_card_send_apdu_to_guest(CCIDCardState *card,
void ccid_card_card_removed(CCIDCardState *card);
void ccid_card_card_inserted(CCIDCardState *card);
void ccid_card_card_error(CCIDCardState *card, uint64_t error);
-void ccid_card_qdev_register(CCIDCardInfo *card);
+void ccid_card_qdev_register(DeviceInfo *card);
/*
* support guest visible insertion/removal of ccid devices based on actual
diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index eb63dfc..aff81fa 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -269,7 +269,6 @@ typedef struct USBCCIDState {
USBDevice dev;
CCIDBus bus;
CCIDCardState *card;
- CCIDCardInfo *cardinfo; /* caching the info pointer */
BulkIn bulk_in_pending[BULK_IN_PENDING_NUM]; /* circular */
uint32_t bulk_in_pending_start;
uint32_t bulk_in_pending_end; /* first free */
@@ -468,6 +467,43 @@ static const USBDesc desc_ccid = {
.str = desc_strings,
};
+static const uint8_t *ccid_card_get_atr(CCIDCardState *card, uint32_t *len)
+{
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
+ if (cc->get_atr) {
+ return cc->get_atr(card, len);
+ }
+ return NULL;
+}
+
+static void ccid_card_apdu_from_guest(CCIDCardState *card,
+ const uint8_t *apdu,
+ uint32_t len)
+{
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
+ if (cc->apdu_from_guest) {
+ cc->apdu_from_guest(card, apdu, len);
+ }
+}
+
+static int ccid_card_exitfn(CCIDCardState *card)
+{
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
+ if (cc->exitfn) {
+ return cc->exitfn(card);
+ }
+ return 0;
+}
+
+static int ccid_card_initfn(CCIDCardState *card)
+{
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
+ if (cc->initfn) {
+ return cc->initfn(card);
+ }
+ return 0;
+}
+
static bool ccid_has_pending_answers(USBCCIDState *s)
{
return s->pending_answers_num > 0;
@@ -741,7 +777,7 @@ static void ccid_write_data_block_atr(USBCCIDState *s, CCID_Header *recv)
uint32_t len = 0;
if (s->card) {
- atr = s->cardinfo->get_atr(s->card, &len);
+ atr = ccid_card_get_atr(s->card, &len);
}
ccid_write_data_block(s, recv->bSlot, recv->bSeq, atr, len);
}
@@ -827,7 +863,7 @@ static void ccid_on_apdu_from_guest(USBCCIDState *s, CCID_XferBlock *recv)
recv->hdr.bSeq, len);
ccid_add_pending_answer(s, (CCID_Header *)recv);
if (s->card) {
- s->cardinfo->apdu_from_guest(s->card, recv->abData, len);
+ ccid_card_apdu_from_guest(s->card, recv->abData, len);
} else {
DPRINTF(s, D_WARN, "warning: discarded apdu\n");
}
@@ -1113,26 +1149,21 @@ void ccid_card_card_inserted(CCIDCardState *card)
static int ccid_card_exit(DeviceState *qdev)
{
int ret = 0;
- CCIDCardState *card = DO_UPCAST(CCIDCardState, qdev, qdev);
- CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, qdev_get_info(qdev));
+ CCIDCardState *card = CCID_CARD(qdev);
USBCCIDState *s =
DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
if (ccid_card_inserted(s)) {
ccid_card_card_removed(card);
}
- if (info->exitfn) {
- ret = info->exitfn(card);
- }
+ ret = ccid_card_exitfn(card);
s->card = NULL;
- s->cardinfo = NULL;
return ret;
}
static int ccid_card_init(DeviceState *qdev, DeviceInfo *base)
{
- CCIDCardState *card = DO_UPCAST(CCIDCardState, qdev, qdev);
- CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, base);
+ CCIDCardState *card = CCID_CARD(qdev);
USBCCIDState *s =
DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
int ret = 0;
@@ -1146,20 +1177,19 @@ static int ccid_card_init(DeviceState *qdev, DeviceInfo *base)
error_report("Warning: usb-ccid card already full, not adding");
return -1;
}
- ret = info->initfn ? info->initfn(card) : ret;
+ ret = ccid_card_initfn(card);
if (ret == 0) {
s->card = card;
- s->cardinfo = info;
}
return ret;
}
-void ccid_card_qdev_register(CCIDCardInfo *card)
+void ccid_card_qdev_register(DeviceInfo *info)
{
- card->qdev.bus_info = &ccid_bus_info;
- card->qdev.init = ccid_card_init;
- card->qdev.exit = ccid_card_exit;
- qdev_register(&card->qdev);
+ info->bus_info = &ccid_bus_info;
+ info->init = ccid_card_init;
+ info->exit = ccid_card_exit;
+ qdev_register_subclass(info, TYPE_CCID_CARD);
}
static int ccid_initfn(USBDevice *dev)
@@ -1170,7 +1200,6 @@ static int ccid_initfn(USBDevice *dev)
qbus_create_inplace(&s->bus.qbus, &ccid_bus_info, &dev->qdev, NULL);
s->bus.qbus.allow_hotplug = 1;
s->card = NULL;
- s->cardinfo = NULL;
s->migration_state = MIGRATION_NONE;
s->migration_target_ip = 0;
s->migration_target_port = 0;
@@ -1312,8 +1341,17 @@ static struct DeviceInfo ccid_info = {
},
};
+static TypeInfo ccid_card_type_info = {
+ .name = TYPE_CCID_CARD,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(CCIDCardState),
+ .abstract = true,
+ .class_size = sizeof(CCIDCardClass),
+};
+
static void ccid_register_devices(void)
{
+ type_register_static(&ccid_card_type_info);
usb_qdev_register(&ccid_info, "ccid", NULL);
}
device_init(ccid_register_devices)
--
1.7.4.1
next prev parent reply other threads:[~2012-01-24 19:34 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-24 19:32 [Qemu-devel] [PATCH v3 0/28] qom: add QEMU Object Model type hierarchy to qdev Anthony Liguori
2012-01-24 19:32 ` [Qemu-devel] [PATCH 01/28] macio: convert " Anthony Liguori
2012-01-26 23:17 ` [Qemu-devel] [PATCH] macio: Convert " Andreas Färber
2012-03-06 22:56 ` Alexander Graf
2012-01-24 19:32 ` [Qemu-devel] [PATCH 02/28] openpic: remove dead code to make a PCI device version Anthony Liguori
2012-01-26 23:57 ` Andreas Färber
2012-01-24 19:32 ` [Qemu-devel] [PATCH 03/28] pci: call reset unconditionally Anthony Liguori
2012-01-25 12:42 ` Michael S. Tsirkin
2012-01-25 13:28 ` Anthony Liguori
2012-01-24 19:32 ` [Qemu-devel] [PATCH 04/28] qom: add the base Object class (v2) Anthony Liguori
2012-01-25 21:30 ` Andreas Färber
2012-01-25 21:37 ` Anthony Liguori
2012-01-26 7:43 ` Paolo Bonzini
2012-01-27 15:05 ` Andreas Färber
2012-01-27 15:42 ` Anthony Liguori
2012-01-27 15:43 ` Andreas Färber
2012-01-24 19:32 ` [Qemu-devel] [PATCH 05/28] qdev: integrate with QEMU Object Model (v2) Anthony Liguori
2012-01-24 19:32 ` [Qemu-devel] [PATCH 06/28] qdev: move qdev->info to class Anthony Liguori
2012-01-24 19:32 ` [Qemu-devel] [PATCH 07/28] qdev: don't access name through info Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 08/28] qdev: use a wrapper to access reset and promote reset to a class method Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 09/28] qdev: add a interface to register subclasses Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 10/28] qdev: add class_init to DeviceInfo Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 11/28] qdev: prepare source tree for code conversion Anthony Liguori
2012-01-26 17:35 ` [Qemu-devel] [PATCH 1/3] es1370: Drop dead code Andreas Färber
2012-01-26 17:35 ` [Qemu-devel] [PATCH 2/3] marvell_88w8618_audio: Use DEFINE_PROP_* macros Andreas Färber
2012-01-26 17:35 ` [Qemu-devel] [PATCH 3/3] qdev: prepare source tree for code conversion Andreas Färber
2012-01-24 19:33 ` [Qemu-devel] [PATCH 12/28] isa: pic: convert to QEMU Object Model Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 13/28] usb: " Anthony Liguori
2012-01-24 19:33 ` Anthony Liguori [this message]
2012-01-24 19:33 ` [Qemu-devel] [PATCH 15/28] ssi: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 16/28] i2c: rename i2c_slave -> I2CSlave Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 17/28] i2c: smbus: convert to QEMU Object Model Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 18/28] hda-codec: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 19/28] ide: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 20/28] scsi: " Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 21/28] spapr: convert to QEMU Object Model (v2) Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 22/28] virtio-serial: convert to QEMU Object Model Anthony Liguori
2012-01-24 19:59 ` Amit Shah
2012-01-24 20:13 ` Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 23/28] unin_pci: Clean up qdev names Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 24/28] unin_pci: Drop duplicate busdev Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 25/28] unin_pci: Drop unused reset handler Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 26/28] pci: convert to QEMU Object Model Anthony Liguori
2012-01-25 12:41 ` Michael S. Tsirkin
2012-01-25 13:34 ` Anthony Liguori
2012-01-24 19:33 ` [Qemu-devel] [PATCH 27/28] sysbus: apic: ioapic: " Anthony Liguori
2012-01-24 20:01 ` Jan Kiszka
2012-01-24 20:21 ` Anthony Liguori
2012-01-24 21:01 ` Jan Kiszka
2012-01-24 21:11 ` Anthony Liguori
2012-01-24 21:31 ` Jan Kiszka
2012-01-24 21:53 ` Anthony Liguori
2012-01-24 22:06 ` Jan Kiszka
2012-01-24 23:03 ` Anthony Liguori
2012-01-25 8:33 ` Andreas Färber
2012-01-25 12:09 ` Avi Kivity
2012-01-25 13:02 ` Paul Brook
2012-01-25 14:25 ` Anthony Liguori
2012-01-25 8:37 ` Jan Kiszka
2012-01-25 10:15 ` Paolo Bonzini
2012-01-25 10:27 ` Jan Kiszka
2012-01-25 11:15 ` Paolo Bonzini
2012-01-25 14:00 ` Anthony Liguori
2012-01-25 14:23 ` Jan Kiszka
2012-01-25 14:40 ` Anthony Liguori
2012-01-25 15:18 ` Andreas Färber
2012-01-25 15:34 ` Eric Blake
2012-01-24 19:33 ` [Qemu-devel] [PATCH 28/28] virtio-s390: " Anthony Liguori
2012-01-24 23:13 ` [Qemu-devel] [PATCH v3 0/28] qom: add QEMU Object Model type hierarchy to qdev Peter Maydell
2012-01-24 23:16 ` Anthony Liguori
2012-01-25 18:31 ` Blue Swirl
2012-01-25 19:43 ` Anthony Liguori
2012-01-25 20:09 ` Blue Swirl
2012-01-27 17:34 ` 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=1327433600-7403-15-git-send-email-aliguori@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=kraxel@redhat.com \
--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).