aboutsummaryrefslogtreecommitdiff
path: root/hw/sd/sd.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/sd/sd.c')
-rw-r--r--hw/sd/sd.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 3c06a0a..7070a11 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -83,6 +83,10 @@ enum SDCardStates {
struct SDState {
DeviceState parent_obj;
+ /* If true, created by sd_init() for a non-qdevified caller */
+ /* TODO purge them with fire */
+ bool me_no_qdev_me_kill_mammoth_with_rocks;
+
/* SD Memory Card Registers */
uint32_t ocr;
uint8_t scr[8];
@@ -129,6 +133,8 @@ struct SDState {
bool cmd_line;
};
+static void sd_realize(DeviceState *dev, Error **errp);
+
static const char *sd_state_name(enum SDCardStates state)
{
static const char *state_name[] = {
@@ -590,7 +596,7 @@ static void sd_cardchange(void *opaque, bool load, Error **errp)
{
SDState *sd = opaque;
DeviceState *dev = DEVICE(sd);
- SDBus *sdbus = SD_BUS(qdev_get_parent_bus(dev));
+ SDBus *sdbus;
bool inserted = sd_get_inserted(sd);
bool readonly = sd_get_readonly(sd);
@@ -601,18 +607,16 @@ static void sd_cardchange(void *opaque, bool load, Error **errp)
trace_sdcard_ejected();
}
- /* The IRQ notification is for legacy non-QOM SD controller devices;
- * QOMified controllers use the SDBus APIs.
- */
- if (sdbus) {
- sdbus_set_inserted(sdbus, inserted);
+ if (sd->me_no_qdev_me_kill_mammoth_with_rocks) {
+ qemu_set_irq(sd->inserted_cb, inserted);
if (inserted) {
- sdbus_set_readonly(sdbus, readonly);
+ qemu_set_irq(sd->readonly_cb, readonly);
}
} else {
- qemu_set_irq(sd->inserted_cb, inserted);
+ sdbus = SD_BUS(qdev_get_parent_bus(dev));
+ sdbus_set_inserted(sdbus, inserted);
if (inserted) {
- qemu_set_irq(sd->readonly_cb, readonly);
+ sdbus_set_readonly(sdbus, readonly);
}
}
}
@@ -697,6 +701,7 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
{
Object *obj;
DeviceState *dev;
+ SDState *sd;
Error *err = NULL;
obj = object_new(TYPE_SD_CARD);
@@ -707,13 +712,24 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
return NULL;
}
qdev_prop_set_bit(dev, "spi", is_spi);
- object_property_set_bool(obj, true, "realized", &err);
+
+ /*
+ * Realizing the device properly would put it into the QOM
+ * composition tree even though it is not plugged into an
+ * appropriate bus. That's a no-no. Hide the device from
+ * QOM/qdev, and call its qdev realize callback directly.
+ */
+ object_ref(obj);
+ object_unparent(obj);
+ sd_realize(dev, &err);
if (err) {
error_reportf_err(err, "sd_init failed: ");
return NULL;
}
- return SD_CARD(dev);
+ sd = SD_CARD(dev);
+ sd->me_no_qdev_me_kill_mammoth_with_rocks = true;
+ return sd;
}
void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert)