From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHIGc-0006m4-1R for qemu-devel@nongnu.org; Thu, 07 Jan 2016 16:38:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aHIGb-0004eT-40 for qemu-devel@nongnu.org; Thu, 07 Jan 2016 16:38:45 -0500 References: <1452200608-524-1-git-send-email-mreitz@redhat.com> <1452200608-524-2-git-send-email-mreitz@redhat.com> From: John Snow Message-ID: <568EDAE2.2010002@redhat.com> Date: Thu, 7 Jan 2016 16:38:42 -0500 MIME-Version: 1.0 In-Reply-To: <1452200608-524-2-git-send-email-mreitz@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/2] hw/sd: Add medium insertion status List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , qemu-devel@nongnu.org Cc: Peter Maydell , Markus Armbruster , Stefan Hajnoczi , qemu-stable@nongnu.org On 01/07/2016 04:03 PM, Max Reitz wrote: > 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 > Signed-off-by: Max Reitz > --- > 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) { > Same thing you did to the floppy. Looks OK. Reviewed-by: John Snow