[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/2] hw/sd: Add medium insertion status
From: |
John Snow |
Subject: |
Re: [Qemu-devel] [PATCH 1/2] hw/sd: Add medium insertion status |
Date: |
Thu, 7 Jan 2016 16:38:42 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
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 <address@hidden>
> Signed-off-by: Max Reitz <address@hidden>
> ---
> 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 <address@hidden>