From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Markus Armbruster <armbru@redhat.com>,
qemu-stable@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH 1/2] hw/sd: Add medium insertion status
Date: Thu, 7 Jan 2016 22:03:27 +0100 [thread overview]
Message-ID: <1452200608-524-2-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1452200608-524-1-git-send-email-mreitz@redhat.com>
Right now, the change_media_cb (sd_cardchange()) completely ignores its
@load parameter. This means that issuing a blockdev-open-tray command
will actually not have any effect.
Fix this by keeping track of the medium insertion status in the SDState
and updating it in sd_init() and sd_cardchange().
Cc: qemu-stable <qemu-stable@nongnu.org>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
hw/sd/sd.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 1a9935c..0751ba2 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -114,6 +114,7 @@ struct SDState {
uint8_t *buf;
bool enable;
+ bool medium_inserted;
};
static void sd_set_mode(SDState *sd)
@@ -429,8 +430,10 @@ static void sd_cardchange(void *opaque, bool load)
{
SDState *sd = opaque;
- qemu_set_irq(sd->inserted_cb, blk_is_inserted(sd->blk));
- if (blk_is_inserted(sd->blk)) {
+ sd->medium_inserted = load && blk_is_inserted(sd->blk);
+
+ qemu_set_irq(sd->inserted_cb, sd->medium_inserted);
+ if (sd->medium_inserted) {
sd_reset(sd);
qemu_set_irq(sd->readonly_cb, sd->wp_switch);
}
@@ -497,6 +500,7 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
/* FIXME ignoring blk_attach_dev() failure is dangerously brittle */
blk_attach_dev(sd->blk, sd);
blk_set_dev_ops(sd->blk, &sd_block_ops, sd);
+ sd->medium_inserted = blk_is_inserted(sd->blk);
}
vmstate_register(NULL, -1, &sd_vmstate, sd);
return sd;
@@ -507,7 +511,7 @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert)
sd->readonly_cb = readonly;
sd->inserted_cb = insert;
qemu_set_irq(readonly, sd->blk ? blk_is_read_only(sd->blk) : 0);
- qemu_set_irq(insert, sd->blk ? blk_is_inserted(sd->blk) : 0);
+ qemu_set_irq(insert, sd->blk ? sd->medium_inserted : 0);
}
static void sd_erase(SDState *sd)
@@ -1349,7 +1353,7 @@ int sd_do_command(SDState *sd, SDRequest *req,
sd_rsp_type_t rtype;
int rsplen;
- if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable) {
+ if (!sd->blk || !sd->medium_inserted || !sd->enable) {
return 0;
}
@@ -1517,7 +1521,7 @@ void sd_write_data(SDState *sd, uint8_t value)
{
int i;
- if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable)
+ if (!sd->blk || !sd->medium_inserted || !sd->enable)
return;
if (sd->state != sd_receivingdata_state) {
@@ -1643,7 +1647,7 @@ uint8_t sd_read_data(SDState *sd)
uint8_t ret;
int io_len;
- if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable)
+ if (!sd->blk || !sd->medium_inserted || !sd->enable)
return 0x00;
if (sd->state != sd_sendingdata_state) {
--
2.6.4
next prev parent reply other threads:[~2016-01-07 21:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-07 21:03 [Qemu-devel] [PATCH 0/2] hw/sd: Fix medium change Max Reitz
2016-01-07 21:03 ` Max Reitz [this message]
2016-01-07 21:38 ` [Qemu-devel] [PATCH 1/2] hw/sd: Add medium insertion status John Snow
2016-01-07 21:45 ` Peter Maydell
2016-01-07 22:00 ` Max Reitz
2016-01-07 21:03 ` [Qemu-devel] [PATCH 2/2] hw/sd: Implement is_tray_open() BlockDevOp Max Reitz
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=1452200608-524-2-git-send-email-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=armbru@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=stefanha@redhat.com \
/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).