SDstate members wp_switch, wp_groups, spi, expecting_acmd and enable are in fact binary variables s converting them to type "bool" makes code a little bit more clear. API modified to reflect new variables types.
Signed-off-by: Mitsyanko Igor <i.mitsya...@samsung.com> --- hw/sd.c | 42 +++++++++++++++++++++--------------------- hw/sd.h | 4 ++-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/hw/sd.c b/hw/sd.c index bfe7f58..3c954fd 100644 --- a/hw/sd.c +++ b/hw/sd.c @@ -84,8 +84,8 @@ struct SDState { uint32_t card_status; uint8_t sd_status[64]; uint32_t vhs; - uint32_t wp_switch; - uint32_t *wp_groups; + bool wp_switch; + bool *wp_groups; uint64_t size; uint32_t blk_len; uint32_t erase_start; @@ -94,12 +94,12 @@ struct SDState { uint32_t pwd_len; uint8_t function_group[6]; - int spi; + bool spi; uint8_t current_cmd; /* True if we will handle the next command as an ACMD. Note that this does * *not* track the APP_CMD status bit! */ - uint32_t expecting_acmd; + bool expecting_acmd; uint32_t blk_written; uint64_t data_start; uint32_t data_offset; @@ -109,7 +109,7 @@ struct SDState { BlockDriverState *bdrv; uint8_t *buf; - uint32_t enable; + bool enable; }; static void sd_set_mode(SDState *sd) @@ -418,15 +418,15 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv) if (sd->wp_groups) g_free(sd->wp_groups); - sd->wp_switch = bdrv ? bdrv_is_read_only(bdrv) : 0; - sd->wp_groups = g_new0(uint32_t, sect); + sd->wp_switch = bdrv ? bdrv_is_read_only(bdrv) : false; + sd->wp_groups = g_new0(bool, sect); memset(sd->function_group, 0, sizeof(sd->function_group)); sd->erase_start = 0; sd->erase_end = 0; sd->size = size; sd->blk_len = 0x200; sd->pwd_len = 0; - sd->expecting_acmd = 0; + sd->expecting_acmd = false; } static void sd_cardchange(void *opaque, bool load) @@ -447,7 +447,7 @@ static const BlockDevOps sd_block_ops = { static size_t sd_get_wpgroups_size(void *opaque, int version_id) { SDState *sd = (SDState *)opaque; - return sizeof(uint32_t) * (sd->size >> (HWBLOCK_SHIFT + SECTOR_SHIFT + + return sizeof(bool) * (sd->size >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT)); } @@ -472,13 +472,13 @@ static const VMStateDescription sd_vmstate = { VMSTATE_UINT32(pwd_len, SDState), VMSTATE_UINT8_ARRAY(function_group, SDState, 6), VMSTATE_UINT8(current_cmd, SDState), - VMSTATE_UINT32(expecting_acmd, SDState), + VMSTATE_BOOL(expecting_acmd, SDState), VMSTATE_UINT32(blk_written, SDState), VMSTATE_UINT64(data_start, SDState), VMSTATE_UINT32(data_offset, SDState), VMSTATE_UINT8_ARRAY(data, SDState, 512), VMSTATE_BUFFER_UNSAFE(buf, SDState, 1, 512), - VMSTATE_UINT32(enable, SDState), + VMSTATE_BOOL(enable, SDState), VMSTATE_END_OF_LIST() } }; @@ -487,14 +487,14 @@ static const VMStateDescription sd_vmstate = { whether card should be in SSI or MMC/SD mode. It is also up to the board to ensure that ssi transfers only occur when the chip select is asserted. */ -SDState *sd_init(BlockDriverState *bs, int is_spi) +SDState *sd_init(BlockDriverState *bs, bool is_spi) { SDState *sd; sd = (SDState *) g_malloc0(sizeof(SDState)); sd->buf = qemu_blockalign(bs, 512); sd->spi = is_spi; - sd->enable = 1; + sd->enable = true; sd_reset(sd, bs); if (sd->bdrv) { bdrv_attach_dev_nofail(sd->bdrv, sd); @@ -578,7 +578,7 @@ static void sd_function_switch(SDState *sd, uint32_t arg) sd->data[66] = crc & 0xff; } -static inline int sd_wp_addr(SDState *sd, uint32_t addr) +static inline bool sd_wp_addr(SDState *sd, uint32_t addr) { return sd->wp_groups[addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT)]; @@ -604,7 +604,7 @@ static void sd_lock_command(SDState *sd) sd->card_status |= LOCK_UNLOCK_FAILED; return; } - memset(sd->wp_groups, 0, sizeof(uint32_t) * (sd->size >> + memset(sd->wp_groups, 0, sizeof(bool) * (sd->size >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT))); sd->csd[14] &= ~0x10; sd->card_status &= ~CARD_IS_LOCKED; @@ -1052,7 +1052,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, sd->state = sd_programming_state; sd->wp_groups[addr >> (HWBLOCK_SHIFT + - SECTOR_SHIFT + WPGROUP_SHIFT)] = 1; + SECTOR_SHIFT + WPGROUP_SHIFT)] = true; /* Bzzzzzzztt .... Operation complete. */ sd->state = sd_transfer_state; return sd_r1b; @@ -1072,7 +1072,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, sd->state = sd_programming_state; sd->wp_groups[addr >> (HWBLOCK_SHIFT + - SECTOR_SHIFT + WPGROUP_SHIFT)] = 0; + SECTOR_SHIFT + WPGROUP_SHIFT)] = false; /* Bzzzzzzztt .... Operation complete. */ sd->state = sd_transfer_state; return sd_r1b; @@ -1169,7 +1169,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, if (sd->rca != rca) return sd_r0; - sd->expecting_acmd = 1; + sd->expecting_acmd = true; sd->card_status |= APP_CMD; return sd_r1; @@ -1351,7 +1351,7 @@ int sd_do_command(SDState *sd, SDRequest *req, if (sd->card_status & CARD_IS_LOCKED) { if (!cmd_valid_while_locked(sd, req)) { sd->card_status |= ILLEGAL_COMMAND; - sd->expecting_acmd = 0; + sd->expecting_acmd = false; fprintf(stderr, "SD: Card is locked\n"); rtype = sd_illegal; goto send_response; @@ -1362,7 +1362,7 @@ int sd_do_command(SDState *sd, SDRequest *req, sd_set_mode(sd); if (sd->expecting_acmd) { - sd->expecting_acmd = 0; + sd->expecting_acmd = false; rtype = sd_app_command(sd, *req); } else { rtype = sd_normal_command(sd, *req); @@ -1748,7 +1748,7 @@ int sd_data_ready(SDState *sd) return sd->state == sd_sendingdata_state; } -void sd_enable(SDState *sd, int enable) +void sd_enable(SDState *sd, bool enable) { sd->enable = enable; } diff --git a/hw/sd.h b/hw/sd.h index ac4b7c4..d25342f 100644 --- a/hw/sd.h +++ b/hw/sd.h @@ -67,13 +67,13 @@ typedef struct { typedef struct SDState SDState; -SDState *sd_init(BlockDriverState *bs, int is_spi); +SDState *sd_init(BlockDriverState *bs, bool is_spi); int sd_do_command(SDState *sd, SDRequest *req, uint8_t *response); void sd_write_data(SDState *sd, uint8_t value); uint8_t sd_read_data(SDState *sd); void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert); int sd_data_ready(SDState *sd); -void sd_enable(SDState *sd, int enable); +void sd_enable(SDState *sd, bool enable); #endif /* __hw_sd_h */ -- 1.7.4.1