Improve SD controllers emulation
cover Improve SD controllers emulation
First patch of this patch set modifies existing VMStateField interface to ease save/restore functionality implementation for device's dynamically allocated buffers. This modification is used later in second patch to implement SD card's VMStateDescription structure.
Third patch adds imlementation of new device: SD host controller fully compliant with "SD host controller specification version 2.00". It also uses first patch modifications.
Mitsyanko Igor (3):
vmstate: introduce calc_size VMStateField hw/sd.c: add SD card save/load support
hw/: Introduce spec. ver. 2.00 compliant SD host controller
Makefile.target | 1 + hw/hw.h | 14 +- hw/milkymist-memcard.c | 2 + hw/sd.c | 115 +++-- hw/sd.h | 1 + hw/sdhc_ver2.c | 1579 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/sdhc_ver2.h | 327 ++++++++++ savevm.c | 14 +- 8 files changed, 2004 insertions(+), 49 deletions(-) create mode 100644 hw/sdhc_ver2.c create mode 100644 hw/sdhc_ver2.h
Signature · 1 line
1.7.4.1
PATCH 1/3 vmstate: introduce calc_size VMStateField
New calc_size field in VMStateField is supposed to help us easily add save/restore support of dynamically allocated buffers in device's states.
There are some cases when information on size of dynamically allocated buffer is already presented in specific device's state structure, but in such a form, that can not be used with existing VMStateField interface. Currently, we either can get size from another variable in device's state as it is with VMSTATE_VBUFFER_* macros, or we can also multiply value kept in a variable by a constant with VMSTATE_BUFFER_MULTIPLY macro. If we need to perform any other action, we're forced to add additional variable with size information to device state structure with the only intention to use it in VMStateDescription structure. This approach is not very pretty. Adding extra flags to VMStateFlags enum for every other possible operation with size field seems redundant, and still it would't cover cases when we need to perform a set of operations to get size value.
With this new .calc_size field we can calculate size of dynamic array in whichever way we need.
--- hw/hw.h | 14 +++++++------- savevm.c | 14 ++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-)
hw/hw.h +7 -7
@@ -303,9 +303,9 @@ enum VMStateFlags {VMS_ARRAY_OF_POINTER =0x040 ,VMS_VARRAY_UINT16 =0x080 ,/* Array with size in uint16_t field */ VMS_VBUFFER =0x100 ,/* Buffer with size in int32_t field */ -VMS_MULTIPLY =0x200 ,/* multiply "size" field by field_size */ -VMS_VARRAY_UINT8 =0x400 ,/* Array with size in uint8_t field*/ - VMS_VARRAY_UINT32 = 0x800, /* Array with size in uint32_t field*/ +VMS_CALC_SIZE =0x200 ,/* calculate size of dynamic buffer */ +VMS_VARRAY_UINT8 =0x400 ,/* Array with size in uint8_t field */ + VMS_VARRAY_UINT32 = 0x800, /* Array with size in uint32_t field */ }; typedef struct {
@@ -321,6 +321,7 @@ typedef struct {const VMStateDescription *vmsd;int version_id;bool (*field_exists)(void *opaque,int version_id); +int (*calc_size)(void *opaque,int version_id); } VMStateField; typedef struct VMStateSubsection {
@@ -584,14 +585,13 @@ extern const VMStateInfo vmstate_info_unused_buffer; .offset = vmstate_offset_buffer(_state, _field) + _start, \ } -#define VMSTATE_BUFFER_MULTIPLY (_field, _state, _version, _test, _start, _field_size, _multiply) { \ +#define VMSTATE_VBUFFER_CALCSIZE (_field, _state, _version, _test, _start, _calc_size) { \ .name = (stringify(_field)), \ .version_id = (_version), \ .field_exists = (_test), \ - .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ - .size = (_multiply), \ + .calc_size = (_calc_size), \ .info = &vmstate_info_buffer, \ - .flags = VMS_VBUFFER|VMS_MULTIPLY, \ + .flags = VMS_VBUFFER|VMS_CALC_SIZE|VMS_POINTER, \ .offset = offsetof(_state, _field), \ .start = (_start), \ }
savevm.c +8 -6
@@ -1412,9 +1412,10 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; +if (field->flags &VMS_CALC_SIZE ) { + size = field->calc_size (opaque, vmsd->version_id); + }else { + size = *(int32_t *)(opaque+field->size_offset); } }if (field->flags &VMS_ARRAY ) {
@@ -1476,9 +1477,10 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; +if (field->flags &VMS_CALC_SIZE ) { + size = field->calc_size (opaque, vmsd->version_id); + }else { + size = *(int32_t *)(opaque+field->size_offset); } }if (field->flags &VMS_ARRAY ) {
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 1/3] vmstate: introduce calc_size VMStateField
Quoted 16 lines · Mitsyanko Igor
New
calc_sizefield in VMStateField is supposed to help us easily add save/restore support of dynamically allocated buffers in device's states.
There are some cases when information on size of dynamically allocated buffer is already presented in specific device's state structure, but in such a form, that can not be used with existing VMStateField interface. Currently, we either can get size from another variable in device's state as it is with VMSTATE_VBUFFER_* macros, or we can also multiply value kept in a variable by a constant withVMSTATE_BUFFER_MULTIPLYmacro. If we need to perform any other action, we're forced to add additional variable with size information to device state structure with the only intention to use it in VMStateDescription structure. This approach is not very pretty. Adding extra flags to VMStateFlags enum for every other possible operation with size field seems redundant, and still it would't cover cases when we need to perform a set of operations to get size value.
With this new .calc_size field we can calculate size of dynamic array in whichever way we need.
Quoted 1 line
Signed-off-by Mitsyanko Igor <[email protected]>
It seems a bit curious that this patch removes the existing (although admittedly unused) VMSTATE_BUFFER_MULTIPLY but doesn't actually say so in the commit message.
Quoted 11 lines
---
hw/hw.h | 14 +++++++-------
savevm.c | 14 ++++++++------2 files changed, 15 insertions(+), 13 deletions(-)hw/hw.h +0
-0@@ -303,9 +303,9 @@ enum VMStateFlags { VMS_ARRAY_OF_POINTER = 0x040,
Quoted 8 lines
VMS_VARRAY_UINT16=0x080, /* Array with size inuint16_tfield */VMS_VBUFFER=0x100, /* Buffer with size inint32_tfield */
- VMS_MULTIPLY =0x200, /* multiply "size" field byfield_size*/
- VMS_VARRAY_UINT8 =0x400, /* Array with size inuint8_tfield*/
- VMS_VARRAY_UINT32 =0x800, /* Array with size inuint32_tfield*/
+ VMS_CALC_SIZE =0x200, /* calculate size of dynamic buffer */
+ VMS_VARRAY_UINT8 =0x400, /* Array with size inuint8_tfield */
+ VMS_VARRAY_UINT32 =0x800, /* Array with size inuint32_tfield */
These unrelated whitespace fixes are confusing -- please drop them.
-- PMM
Re: [Qemu-devel] [PATCH 1/3] vmstate: introduce calc_size VMStateField
Quoted 28 lines · Peter Maydell
Quoted 16 lines · Mitsyanko Igor
New
calc_sizefield in VMStateField is supposed to help us easily add save/restore support of dynamically allocated buffers in device's states.
There are some cases when information on size of dynamically allocated buffer is already presented in specific device's state structure, but in such a form, that can not be used with existing VMStateField interface. Currently, we either can get size from another variable in device's state as it is with VMSTATE_VBUFFER_* macros, or we can also multiply value kept in a variable by a constant withVMSTATE_BUFFER_MULTIPLYmacro. If we need to perform any other action, we're forced to add additional variable with size information to device state structure with the only intention to use it in VMStateDescription structure. This approach is not very pretty. Adding extra flags to VMStateFlags enum for every other possible operation with size field seems redundant, and still it would't cover cases when we need to perform a set of operations to get size value.
With this new .calc_size field we can calculate size of dynamic array in whichever way we need.Quoted 1 line
Signed-off-by Mitsyanko Igor<[email protected]>It seems a bit curious that this patch removes the existing (although admittedly unused)
VMSTATE_BUFFER_MULTIPLYbut doesn't actually say so in the commit message.Quoted 5 lines
--- hw/hw.h | 14 +++++++------- savevm.c | 14 ++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-)
Quoted 16 lines
Quoted 5 lines
hw/hw.h +0
-0hw/hw.h enum VMStateFlags { · line 308
Quoted 9 lines
hw/hw.h +3
-3@@ -303,9 +303,9 @@ enum VMStateFlags {VMS_ARRAY_OF_POINTER =0x040 ,VMS_VARRAY_UINT16 =0x080 ,/* Array with size in uint16_t field */ VMS_VBUFFER =0x100 ,/* Buffer with size in int32_t field */ -VMS_MULTIPLY =0x200 ,/* multiply "size" field by field_size */ -VMS_VARRAY_UINT8 =0x400 ,/* Array with size in uint8_t field*/ - VMS_VARRAY_UINT32 = 0x800, /* Array with size in uint32_t field*/ +VMS_CALC_SIZE =0x200 ,/* calculate size of dynamic buffer */ +VMS_VARRAY_UINT8 =0x400 ,/* Array with size in uint8_t field */ + VMS_VARRAY_UINT32 = 0x800, /* Array with size in uint32_t field */These unrelated whitespace fixes are confusing -- please drop them.
QEMU wiki here http://wiki.qemu.org/Contribute/SubmitAPatch states that it's ok :)
Quoted 1 line
It's OK to fix coding style issues in the immediate area (few lines) > of the lines you're changing.)
Given some thoughts to it, I didn't like that this patch increases memory consumed by VMStateField. Maybe we should drop existing .size_offset field and replace it with generic get_buffsize callback, like we did in second version of this patch. It seems reasonable to me, even though existing .size_offset usage is pretty neat.
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
Re: [Qemu-devel] [PATCH 1/3] vmstate: introduce calc_size VMStateField
Am 27.12.2011 09:11, schrieb Mitsyanko Igor:
Quoted 27 lines · Peter Maydell
Quoted 18 lines
Quoted 16 lines · Mitsyanko Igor
hw/hw.h +0
-0@@ -303,9 +303,9 @@ enum VMStateFlags {VMS_ARRAY_OF_POINTER =0x040 , VMS_VARRAY_UINT16 = 0x080, /* Array with size in uint16_tfield */
VMS_VBUFFER = 0x100, /* Buffer with size in int32_tfield */
-VMS_MULTIPLY=0x200, /* multiply "size" field byfield_size*/
-VMS_VARRAY_UINT8=0x400, /* Array with size inuint8_t
field*/
-VMS_VARRAY_UINT32=0x800, /* Array with size inuint32_t
field*/Quoted 8 lines
Quoted 6 lines
+
VMS_CALC_SIZE=0x200, /* calculate size of dynamic
buffer */
+VMS_VARRAY_UINT8=0x400, /* Array with size inuint8_t
field */
+VMS_VARRAY_UINT32=0x800, /* Array with size inuint32_t
field */These unrelated whitespace fixes are confusing -- please drop them.
Quoted 4 lines
QEMU wiki here http://wiki.qemu.org/Contribute/SubmitAPatch states that it's ok :)
Quoted 1 line
It's OK to fix coding style issues in the immediate area (few lines) >
of the lines you're changing.)
It's not really a Coding Style issue though (just an aesthetic one), what's meant by the quote is to fix braces around the lines you touch.
I'd suggest to put it in a separate preceding patch, then it gets fixed and we can still better see what you're changing here.
(I'm in need of a mechanism like this for AHCI so please cc Juan and me on v2 of this patch.)
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 1/3] vmstate: introduce calc_size VMStateField
Quoted 30 lines · Andreas Färber
Am 27.12.2011 09:11, schrieb Mitsyanko Igor:
Quoted 29 lines · Peter Maydell
Quoted 18 lines
Quoted 16 lines · Mitsyanko Igor
hw/hw.h +0
-0@@ -303,9 +303,9 @@ enum VMStateFlags {VMS_ARRAY_OF_POINTER =0x040 , VMS_VARRAY_UINT16 = 0x080, /* Array with size in uint16_tfield */
VMS_VBUFFER = 0x100, /* Buffer with size in int32_tfield */
-VMS_MULTIPLY=0x200, /* multiply "size" field byfield_size*/
-VMS_VARRAY_UINT8=0x400, /* Array with size inuint8_t
field*/
-VMS_VARRAY_UINT32=0x800, /* Array with size inuint32_t
field*/Quoted 8 lines
Quoted 6 lines
+
VMS_CALC_SIZE=0x200, /* calculate size of dynamic
buffer */
+VMS_VARRAY_UINT8=0x400, /* Array with size inuint8_t
field */
+VMS_VARRAY_UINT32=0x800, /* Array with size inuint32_t
field */These unrelated whitespace fixes are confusing -- please drop them.
QEMU wiki here http://wiki.qemu.org/Contribute/SubmitAPatch states that it's ok :)
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
It's OK to fix coding style issues in the immediate area (few lines)>
of the lines you're changing.)
It's not really a Coding Style issue though (just an aesthetic one), what's meant by the quote is to fix braces around the lines you touch.
I'd suggest to put it in a separate preceding patch, then it gets fixed and we can still better see what you're changing here.
If v2 of this patch will be accepted and we will drop VMS_MULTIPLY, I
could add required spaces together with changing values given to VMS_VARRAY_UINT8 and VMS_VARRAY_UINT32 flags. Or this can be done by Paolo Bonzini in his "split hw/hw.h" patch, I cc him just in case he wouldn't mind to do this.
Quoted 5 lines
(I'm in need of a mechanism like this for AHCI so please cc Juan and me on v2 of this patch.)
Andreas
I'm also considering to change local size variable in vmstate_load_state() and vmstate_save_state() to size_t, it makes no sense to convert size_t field->size to intermediate int type just to pass it again as size_t to get() function.
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
PATCH v2 1/3 vmstate: introduce get_bufsize entry in VMStateField
In reply to Mitsyanko IgorNew get_bufsize field in VMStateField is supposed to help us easily add save/restore support of dynamically allocated buffers in device's states.
There are some cases when information about size of dynamically allocated buffer is already presented in specific device's state structure, but in such a form that can not be used with existing VMStateField interface. Currently, we either can get size from another variable in device's state as it is with VMSTATE_VBUFFER_* macros, or we can also multiply value kept in a variable by a constant with VMSTATE_BUFFER_MULTIPLY macro. If we need to perform any other action, we're forced to add additional variable with size information to device state structure with the only intention to use it in VMStateDescription. This approach is not very pretty. Adding extra flags to VMStateFlags enum for every other possible operation with size field seems redundant, and still it would't cover cases when we need to perform a set of operations to get size value.
With get_bufsize callback we can calculate size of dynamic array in whichever way we need. We don't need .size_offset field anymore, so we can remove it from VMState Field structure to compensate for extra memory consuption because of get_bufsize addition. Macros VMSTATE_VBUFFER* are modified to use new callback instead of .size_offset. Macro VMSTATE_BUFFER_MULTIPLY and VMFlag VMS_MULTIPLY are removed completely as they are now redundant.
--- hw/g364fb.c | 7 ++++++- hw/hw.h | 41 +++++++---------------------------------- hw/m48t59.c | 7 ++++++- hw/mac_nvram.c | 8 +++++++- hw/onenand.c | 7 ++++++- savevm.c | 10 ++-------- 6 files changed, 34 insertions(+), 46 deletions(-)
hw/g364fb.c +6 -1
@@ -495,6 +495,11 @@ static int g364fb_post_load(void *opaque, int version_id)return 0 ; } +static int g364fb_get_vramsize (void *opaque,int version_id) +{ +return ((G364State *)opaque)->vram_size; +} +static const VMStateDescription vmstate_g364fb = { .name ="g364fb" , .version_id =1 ,
@@ -502,7 +507,7 @@ static const VMStateDescription vmstate_g364fb = { .minimum_version_id_old = 1, .post_load = g364fb_post_load, .fields = (VMStateField []) { -VMSTATE_VBUFFER_UINT32 (vram, G364State,1 ,NULL ,0 , vram_size), +VMSTATE_VBUFFER (vram, G364State,1 ,NULL ,0 , g364fb_get_vramsize),VMSTATE_BUFFER_UNSAFE (color_palette, G364State,0 ,256 *3 ),VMSTATE_BUFFER_UNSAFE (cursor_palette, G364State,0 ,9 ),VMSTATE_UINT16_ARRAY (cursor, G364State,512 ),
hw/hw.h +7 -34
74 lines not on this page · raw message
hw/m48t59.c +6 -1
@@ -582,6 +582,11 @@ static const MemoryRegionOps nvram_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static int m48t59_get_bufsize (void *opaque,int version_id) +{ +return ((M48t59State *)opaque)->size; +} +static const VMStateDescription vmstate_m48t59 = { .name ="m48t59" , .version_id =1 ,
@@ -590,7 +595,7 @@ static const VMStateDescription vmstate_m48t59 = { .fields = (VMStateField[]) {VMSTATE_UINT8 (lock, M48t59State),VMSTATE_UINT16 (addr, M48t59State), -VMSTATE_VBUFFER_UINT32 (buffer, M48t59State,0 ,NULL ,0 , size), +VMSTATE_VBUFFER (buffer, M48t59State,0 ,NULL ,0 , m48t59_get_bufsize),VMSTATE_END_OF_LIST () } };
hw/mac_nvram.c +7 -1
@@ -100,13 +100,19 @@ static const MemoryRegionOps macio_nvram_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static int macio_nvram_get_datasize (void *opaque,int version_id) +{ +return ((MacIONVRAMState *)opaque)->size; +} +static const VMStateDescription vmstate_macio_nvram = { .name ="macio_nvram" , .version_id =1 , .minimum_version_id =1 , .minimum_version_id_old =1 , .fields = (VMStateField []) { -VMSTATE_VBUFFER_UINT32 (data, MacIONVRAMState,0 ,NULL ,0 , size), +VMSTATE_VBUFFER (data, MacIONVRAMState,0 ,NULL ,0 , + macio_nvram_get_datasize),VMSTATE_END_OF_LIST () } };
hw/onenand.c +6 -1
@@ -160,6 +160,11 @@ static int onenand_post_load(void *opaque, int version_id)return 0 ; } +static int onenand_get_blockwpsize (void *opaque,int version_id) +{ +return ((OneNANDState *)opaque)->blocks; +} +static const VMStateDescription vmstate_onenand = { .name ="onenand" , .version_id =1 ,
@@ -181,7 +186,7 @@ static const VMStateDescription vmstate_onenand = {VMSTATE_UINT16 (intstatus, OneNANDState),VMSTATE_UINT16 (wpstatus, OneNANDState),VMSTATE_INT32 (secs_cur, OneNANDState), -VMSTATE_PARTIAL_VBUFFER (blockwp, OneNANDState, blocks), +VMSTATE_PARTIAL_VBUFFER (blockwp, OneNANDState, onenand_get_blockwpsize),VMSTATE_UINT8 (ecc.cp, OneNANDState),VMSTATE_UINT16_ARRAY (ecc.lp, OneNANDState,2 ), VMSTATE_UINT16(ecc.count, OneNANDState),
savevm.c +2 -8
@@ -1412,10 +1412,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } + size = field->get_bufsize (opaque, version_id); }if (field->flags &VMS_ARRAY ) { n_elems = field->num;
@@ -1476,10 +1473,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } + size = field->get_bufsize (opaque, vmsd->version_id); }if (field->flags &VMS_ARRAY ) { n_elems = field->num;
Signature · 1 line
1.7.4.1
PATCH 2/3 hw/sd.c: add SD card save/load support
In reply to Mitsyanko IgorWe couldn't properly implement save/restore functionality of SD host controllers states without SD card's state VMStateDescription implementation. This patch updates SD card emulation to support save/load of card's state.
--- hw/milkymist-memcard.c | 2 + hw/sd.c | 115 +++++++++++++++++++++++++++++++++--------------- hw/sd.h | 1 + 3 files changed, 82 insertions(+), 36 deletions(-)
hw/milkymist-memcard.c +2 -0
@@ -266,6 +266,8 @@ static const VMStateDescription vmstate_milkymist_memcard = { .minimum_version_id = 1, .minimum_version_id_old = 1, .fields = (VMStateField []) { +VMSTATE_STRUCT_POINTER (card, MilkymistMemcardState, sd_vmstate, + SDState *),VMSTATE_INT32 (command_write_ptr, MilkymistMemcardState),VMSTATE_INT32 (response_read_ptr, MilkymistMemcardState),VMSTATE_INT32 (response_len, MilkymistMemcardState),
hw/sd.c +79 -36
193 lines not on this page · raw message
hw/sd.h +1 -0
@@ -66,6 +66,7 @@ typedef struct { } SDRequest;typedef struct SDState SDState ; +extern const VMStateDescription sd_vmstate;SDState *sd_init (BlockDriverState *bs,int is_spi); int sd_do_command(SDState *sd, SDRequest *req,
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 2/3] hw/sd.c: add SD card save/load support
Quoted 5 lines · Mitsyanko Igor
We couldn't properly implement save/restore functionality of SD host controllers states without SD card's state VMStateDescription implementation. This patch updates SD card emulation to support save/load of card's state.
Signed-off-by Mitsyanko Igor <[email protected]>
Ah, cool. I'd had a quick go at adding save/restore to sd.c but ran aground on the wp_groups array issue.
(cc'd Juan as vmstate/migration expert)
Quoted 11 lines
---
hw/milkymist-memcard.c | 2 +
hw/sd.c | 115 +++++++++++++++++++++++++++++++++---------------hw/sd.h| 1 +3 files changed, 82 insertions(+), 36 deletions(-)hw/milkymist-memcard.c +0
-0
hw/milkymist-memcard.c static const VMStateDescription vmstate_milkymist_memcard = { · line 270
Quoted 5 lines
hw/milkymist-memcard.c +2
-0@@ -266,6 +266,8 @@ static const VMStateDescription vmstate_milkymist_memcard = { .minimum_version_id = 1, .minimum_version_id_old = 1, .fields = (VMStateField[]) { + VMSTATE_STRUCT_POINTER(card, MilkymistMemcardState, sd_vmstate, + SDState *),
This doesn't seem like the right approach to me -- the migration state for the controller shouldn't have to include all the state for the card. Instead I think it would be better for sd.c to register a vmstate struct (by calling vmstate_register in sd_init) and thus handle its own saving/loading. Then if/when we make sd.c a proper qemu object we won't need to change the migration state for all the controllers.
Quoted 70 lines
hw/milkymist-memcard.c +0
-0VMSTATE_INT32(command_write_ptr, MilkymistMemcardState), VMSTATE_INT32(response_read_ptr, MilkymistMemcardState), VMSTATE_INT32(response_len, MilkymistMemcardState),hw/sd.c +25
-21@@ -54,24 +54,28 @@ typedef enum { sd_illegal = -2, } sd_rsp_type_t; +enum { + sd_inactive, + sd_card_identification_mode, + sd_data_transfer_mode, +}; + +enum { + sd_inactive_state = -1, + sd_idle_state = 0, + sd_ready_state, + sd_identification_state, + sd_standby_state, + sd_transfer_state, + sd_sendingdata_state, + sd_receivingdata_state, + sd_programming_state, + sd_disconnect_state, +}; + struct SDState { - enum { - sd_inactive, - sd_card_identification_mode, - sd_data_transfer_mode, - } mode; - enum { - sd_inactive_state = -1, - sd_idle_state = 0, - sd_ready_state, - sd_identification_state, - sd_standby_state, - sd_transfer_state, - sd_sendingdata_state, - sd_receivingdata_state, - sd_programming_state, - sd_disconnect_state, - } state; + uint32_t mode; + int32_t state; uint32_t ocr; uint8_t scr[8]; uint8_t cid[16];@@ -81,22 +85,22 @@ struct SDState { uint8_t sd_status[64]; uint32_t vhs; int wp_switch; - int *wp_groups; + uint8_t *wp_groups; uint64_t size; - int blk_len; + uint32_t blk_len; uint32_t erase_start; uint32_t erase_end; uint8_t pwd[16]; - int pwd_len; - int function_group[6]; + uint32_t pwd_len; + uint8_t function_group[6];
hw/sd.c struct SDState { · line 102
Quoted 10 lines
hw/sd.c +3
-4- int spi; - int current_cmd; + uint8_t 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! */ - int expecting_acmd; - int blk_written; + bool expecting_acmd;
Why have you changed expecting_acmd and enable to bool, but spi to a uint8_t and wp_groups[] to a uint8_t[] ? This isn't very consistent. (I'm vaguely against bool because you then end up making other changes to change '1' to 'true' and so on.)
Quoted 14 lines
hw/sd.c +2
-1+ uint32_t blk_written; uint64_t data_start; uint32_t data_offset; uint8_t data[512];@@ -105,7 +109,7 @@ struct SDState { BlockDriverState *bdrv; uint8_t *buf; - int enable; + bool enable; }; static void sd_set_mode(SDState *sd)
hw/sd.c static void sd_reset(SDState *sd, BlockDriverState *bdrv) · line 423
Quoted 7 lines
hw/sd.c +2
-2@@ -415,14 +419,14 @@ 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 = (int *) g_malloc0(sizeof(int) * sect); - memset(sd->function_group, 0, sizeof(int) * 6); + sd->wp_groups = (uint8_t *)g_malloc0(sect); + memset(sd->function_group, 0, 6);
Since you're touching this line anyway, can we have sizeof(sd->function_group) rather than that hardcoded 6 ?
Quoted 65 lines
hw/sd.c +3
-3sd->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)@@ -451,7 +455,7 @@ SDState *sd_init(BlockDriverState *bs, int is_spi) 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);@@ -534,7 +538,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 uint8_t sd_wp_addr (SDState *sd,uint32_t addr) {return sd->wp_groups[addr >>
(HWBLOCK_SHIFT+SECTOR_SHIFT+WPGROUP_SHIFT)];hw/sd.c +4
-4@@ -560,7 +564,7 @@ static void sd_lock_command(SDState *sd) sd->card_status |= LOCK_UNLOCK_FAILED; return; } - memset(sd->wp_groups, 0, sizeof(int) * (sd->size >> + memset(sd->wp_groups, 0, (sd->size >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT))); sd->csd[14] &= ~0x10; sd->card_status &= ~CARD_IS_LOCKED;@@ -1125,7 +1129,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;@@ -1307,7 +1311,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;@@ -1318,7 +1322,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);
hw/sd.c int sd_data_ready(SDState *sd) · line 1713
Quoted 5 lines
hw/sd.c +1
-1@@ -1706,5 +1710,44 @@ int sd_data_ready(SDState *sd) void sd_enable(SDState *sd, int enable) { - sd->enable = enable; + sd->enable = enable ? true : false;
This kind of thing is why I don't like bool :-)
Quoted 53 lines
hw/sd.c +39
-0+} + +static int sd_vmstate_get_wpgroups_size (void *opaque,int version_id) +{ + SDState *sd = (SDState *)opaque; + return sd->size >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT); } + +const VMStateDescription sd_vmstate = { + .name = "sd_card", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(mode, SDState), + VMSTATE_INT32(state, SDState), + VMSTATE_UINT8_ARRAY(cid, SDState, 16), + VMSTATE_UINT8_ARRAY(csd, SDState, 16), + VMSTATE_UINT16(rca, SDState), + VMSTATE_UINT32(card_status, SDState), + VMSTATE_PARTIAL_BUFFER(sd_status, SDState, 1), + VMSTATE_UINT32(vhs, SDState), + VMSTATE_VBUFFER_CALCSIZE(wp_groups, SDState, + 1, NULL, 0, sd_vmstate_get_wpgroups_size), + VMSTATE_UINT32(blk_len, SDState), + VMSTATE_UINT32(erase_start, SDState), + VMSTATE_UINT32(erase_end, SDState), + VMSTATE_UINT8_ARRAY(pwd, SDState, 16), + VMSTATE_UINT32(pwd_len, SDState), + VMSTATE_UINT8_ARRAY(function_group, SDState, 6), + VMSTATE_UINT8(current_cmd, 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_BOOL(enable, SDState), + VMSTATE_END_OF_LIST() + } +};hw/sd.h +1
-1@@ -66,6 +66,7 @@ typedef struct { } SDRequest; typedef struct SDState SDState; +extern const VMStateDescription sd_vmstate; SDState *sd_init(BlockDriverState *bs, int is_spi); int sd_do_command(SDState *sd, SDRequest *req, --
Quoted 1 line
1.7.4.1
-- PMM
Re: [Qemu-devel] [PATCH 2/3] hw/sd.c: add SD card save/load support
Quoted 27 lines · Peter Maydell
Quoted 5 lines · Mitsyanko Igor
We couldn't properly implement save/restore functionality of SD host controllers states without SD card's state VMStateDescription implementation. This patch updates SD card emulation to support save/load of card's state.
Signed-off-by Mitsyanko Igor<[email protected]>Ah, cool. I'd had a quick go at adding save/restore to
sd.cbut ran aground on thewp_groupsarray issue.(cc'd Juan as vmstate/migration expert)
Quoted 15 lines
--- hw/milkymist-memcard.c | 2 + hw/sd.c | 115 +++++++++++++++++++++++++++++++++--------------- hw/sd.h | 1 + 3 files changed, 82 insertions(+), 36 deletions(-)hw/milkymist-memcard.c +1
-0@@ -266,6 +266,8 @@ static const VMStateDescription vmstate_milkymist_memcard = { .minimum_version_id = 1, .minimum_version_id_old = 1, .fields = (VMStateField[]) { + VMSTATE_STRUCT_POINTER(card, MilkymistMemcardState, sd_vmstate,
Quoted 9 lines
hw/milkymist-memcard.c static const VMStateDescription vmstate_milkymist_memcard = { · line 270
Quoted 1 line
hw/milkymist-memcard.c +1
-0+ SDState *),This doesn't seem like the right approach to me -- the migration state for the controller shouldn't have to include all the state for the card. Instead I think it would be better for
sd.cto register a vmstate struct (by callingvmstate_registerinsd_init) and thus handle its own saving/loading. Then if/when we makesd.ca proper qemu object we won't need to change the migration state for all the controllers.
Good point, thanks.
Quoted 70 lines
Quoted 70 lines
hw/milkymist-memcard.c +0
-0VMSTATE_INT32 (command_write_ptr, MilkymistMemcardState),VMSTATE_INT32 (response_read_ptr, MilkymistMemcardState), VMSTATE_INT32(response_len, MilkymistMemcardState),hw/sd.c +25
-21@@ -54,24 +54,28 @@ typedef enum { sd_illegal =-2 , } sd_rsp_type_t; +enum { + sd_inactive, + sd_card_identification_mode, + sd_data_transfer_mode, +}; + +enum { + sd_inactive_state =-1 , + sd_idle_state =0 , + sd_ready_state, + sd_identification_state, + sd_standby_state, + sd_transfer_state, + sd_sendingdata_state, + sd_receivingdata_state, + sd_programming_state, + sd_disconnect_state, +}; +struct SDState { -enum { - sd_inactive, - sd_card_identification_mode, - sd_data_transfer_mode, - } mode; -enum { - sd_inactive_state =-1 , - sd_idle_state =0 , - sd_ready_state, - sd_identification_state, - sd_standby_state, - sd_transfer_state, - sd_sendingdata_state, - sd_receivingdata_state, - sd_programming_state, - sd_disconnect_state, - } state; +uint32_t mode; +int32_t state;uint32_t ocr;uint8_t scr[8 ];uint8_t cid[16 ];@@ -81,22 +85,22 @@ struct SDState {uint8_t sd_status[64 ];uint32_t vhs;int wp_switch; -int *wp_groups; +uint8_t *wp_groups;uint64_t size; -int blk_len; +uint32_t blk_len;uint32_t erase_start;uint32_t erase_end;uint8_t pwd[16 ]; -int pwd_len; -int function_group[6 ]; +uint32_t pwd_len; +uint8_t function_group[6 ];
Quoted 16 lines
hw/sd.c struct SDState { · line 102
Quoted 10 lines
hw/sd.c +3
-4-int spi; -int current_cmd; +uint8_t 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! */ -int expecting_acmd; -int blk_written; +bool expecting_acmd;Why have you changed
expecting_acmdand enable to bool, but spi to auint8_tand wp_groups[] to a uint8_t[] ? This isn't very consistent. (I'm vaguely against bool because you then end up making other changes to change '1' to 'true' and so on.)
I tried to preserve alignment and potentially avoid unnecessary memory consumption in arrays since bool size is implementation defined, otherwise I would have change everything to bool. I'll convert everything to uint8_t next time, you're right, this'll make things simpler.
Quoted 12 lines
Quoted 12 lines
hw/sd.c +2
-1+uint32_t blk_written;uint64_t data_start;uint32_t data_offset;uint8_t data[512 ];@@ -105,7 +109,7 @@ struct SDState {BlockDriverState *bdrv;uint8_t *buf; -int enable; +bool enable; };
Quoted 13 lines
hw/sd.c static void sd_reset(SDState *sd, BlockDriverState *bdrv) · line 423
Quoted 9 lines
hw/sd.c +2
-2static void sd_set_mode (SDState *sd)@@ -415,14 +419,14 @@ 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 = (int *)g_malloc0 (sizeof (int ) * sect); -memset (sd->function_group,0 ,sizeof (int ) *6 ); + sd->wp_groups = (uint8_t *)g_malloc0 (sect); +memset (sd->function_group,0 ,6 );Since you're touching this line anyway, can we have
sizeof(sd->function_group)rather than that hardcoded 6 ?
Sure.
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
Re: [Qemu-devel] [PATCH 2/3] hw/sd.c: add SD card save/load support
In reply to Peter MaydellAm 26.12.2011 15:58, schrieb Peter Maydell:
Quoted 38 lines
Quoted 22 lines
hw/sd.c +4
-4@@ -81,22 +85,22 @@ struct SDState {uint8_t sd_status[64 ];uint32_t vhs;int wp_switch; -int *wp_groups; +uint8_t *wp_groups;uint64_t size; -int blk_len; +uint32_t blk_len;uint32_t erase_start;uint32_t erase_end;uint8_t pwd[16 ]; -int pwd_len; -int function_group[6 ]; +uint32_t pwd_len; +uint8_t function_group[6 ];hw/sd.c struct SDState { · line 102
Quoted 10 lines
hw/sd.c +3
-4-int spi; -int current_cmd; +uint8_t 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! */ -int expecting_acmd; -int blk_written; +bool expecting_acmd;Why have you changed
expecting_acmdand enable to bool, but spi to auint8_tand wp_groups[] to a uint8_t[] ? This isn't very consistent. (I'm vaguely against bool because you then end up making other changes to change '1' to 'true' and so on.)
Quoted 8 lines
hw/sd.c int sd_data_ready(SDState *sd) · line 1713
Quoted 6 lines
hw/sd.c +1
-1@@ -1706,5 +1710,44 @@ int sd_data_ready(SDState *sd)void sd_enable (SDState *sd,int enable) { - sd->enable = enable; + sd->enable = enable ? true : false;This kind of thing is why I don't like bool :-)
x = 1 should work with bool when not doing x == true anywhere, here !!enable would be an alternative. Maybe change int enable to bool, too?
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 2/3] hw/sd.c: add SD card save/load support
Quoted 48 lines · Andreas Färber
Am 26.12.2011 15:58, schrieb Peter Maydell:
Quoted 38 lines
Quoted 22 lines
hw/sd.c +4
-4@@ -81,22 +85,22 @@ struct SDState {uint8_t sd_status[64 ];uint32_t vhs;int wp_switch; -int *wp_groups; +uint8_t *wp_groups;uint64_t size; -int blk_len; +uint32_t blk_len;uint32_t erase_start;uint32_t erase_end;uint8_t pwd[16 ]; -int pwd_len; -int function_group[6 ]; +uint32_t pwd_len; +uint8_t function_group[6 ];hw/sd.c struct SDState { · line 102
Quoted 10 lines
hw/sd.c +3
-4-int spi; -int current_cmd; +uint8_t 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! */ -int expecting_acmd; -int blk_written; +bool expecting_acmd;Why have you changed
expecting_acmdand enable to bool, but spi to auint8_tand wp_groups[] to a uint8_t[] ? This isn't very consistent. (I'm vaguely against bool because you then end up making other changes to change '1' to 'true' and so on.)Quoted 8 lines
hw/sd.c int sd_data_ready(SDState *sd) · line 1713
Quoted 6 lines
hw/sd.c +1
-1@@ -1706,5 +1710,44 @@ int sd_data_ready(SDState *sd)void sd_enable (SDState *sd,int enable) { - sd->enable = enable; + sd->enable = enable ? true : false;This kind of thing is why I don't like bool :-)
Quoted 5 lines
x = 1 should work with bool when not doing x == true anywhere, here !!enable would be an alternative. Maybe change int enable to bool, too?
Andreas
As Peter mentioned previously, we should use either uint8_t or bool for all binary variables for consistency, and we probably shouldn't use bool for wp_groups array since sizeof(bool) uncertainty. So I'm considering just make everything uint8_t.
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
Re: [Qemu-devel] [PATCH 2/3] hw/sd.c: add SD card save/load support
In reply to Peter MaydellQuoted 7 lines · Peter Maydell
hw/sd.c int sd_data_ready(SDState *sd) · line 1713
Quoted 5 lines
void
sd_enable(SDState *sd, int enable)
{hw/sd.c +1
-1- sd->enable = enable; + sd->enable = enable ? true : false;This kind of thing is why I don't like bool :-)
/me leaps to bool's defence:
sd->enable = enable should work just fine. The assignment is
equivalent to sd->enable = enable != 0, as conversion to bool coerces the value to true/false.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [Qemu-devel] [PATCH 2/3] hw/sd.c: add SD card save/load support
Quoted 11 lines · Avi Kivity
Quoted 6 lines · Peter Maydell
Quoted 4 lines
void
sd_enable(SDState *sd, int enable)
{
- sd->enable = enable;
+ sd->enable = enable ? true : false;This kind of thing is why I don't like bool :-)
/me leaps to bool's defence:
sd->enable = enable should work just fine.
This is true, but the code snippet also illustrates that it sits oddly to have the internal state variable be bool when the external facing function's API is clearly using the traditional C style of int-for-booleans.
Plus 'bool' gives me C++ flashbacks :-)
-- PMM
Re: [Qemu-devel] [PATCH 2/3] hw/sd.c: add SD card save/load support
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Avi Kivity
Quoted 6 lines · Peter Maydell
hw/sd.c int sd_data_ready(SDState *sd) · line 1713
Quoted 4 lines
void
sd_enable(SDState *sd, int enable)
{hw/sd.c +1
-1- sd->enable = enable; + sd->enable = enable ? true : false;This kind of thing is why I don't like bool :-)
Quoted 8 lines
Quoted 3 lines
/me leaps to bool's defence:
sd->enable= enable should work just fine.This is true, but the code snippet also illustrates that it sits oddly to have the internal state variable be bool when the external facing function's API is clearly using the traditional C style of int-for-booleans.
We should change those too. bool is self-documenting.
Quoted 1 line
Plus 'bool' gives me C++ flashbacks :-)
And QOM doesn't? How about glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)?
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 3/3 hw/: Introduce spec. ver. 2.00 compliant SD host controller
In reply to Mitsyanko IgorThis patch adds implementation of "SD specification version 2.00" compliant SD host controller. Also it provides interface to implement SoC-specific controllers on top of this specification-compliant one.
--- Makefile.target | 1 + hw/sdhc_ver2.c | 1579 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/sdhc_ver2.h | 327 ++++++++++++ 3 files changed, 1907 insertions(+), 0 deletions(-) create mode 100644 hw/sdhc_ver2.c create mode 100644 hw/sdhc_ver2.h
Makefile.target +1 -0
@@ -358,6 +358,7 @@ obj-arm-y += vexpress.o obj-arm-y += strongarm.o obj-arm-y += collie.o obj-arm-y += pl041.o lm4549.o +obj-arm-y += sdhc_ver2.o obj-sh4-y = shix.o r2d.o sh7750.o sh7750_regnames.o tc58128.o obj-sh4-y += sh_timer.o sh_serial.o sh_intc.o sh_pci.o sm501.o
hw/sdhc_ver2.c new file +1579 -0
1,579 lines not on this page · raw message
hw/sdhc_ver2.h new file +327 -0
327 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 3/3] hw/: Introduce spec. ver. 2.00 compliant SD host controller
Quoted 4 lines · Mitsyanko Igor
This patch adds implementation of "SD specification version 2.00" compliant SD host controller. Also it provides interface to implement SoC-specific controllers on top of this specification-compliant one.
[..snip..]
hw/sdhc_ver2.c line 208
Quoted 4 lines
hw/sdhc_ver2.c new file +4
-0+ +void sdhcv2_reset (SDHCv2State *s) +{ +unsigned long begin = (unsigned long )s + offsetof(SDHCv2State , sdmasysad);
This is wrong,
uintptr_t begin = (uintptr_t) &s->sdmasysad;
Caveat emptor: i haven't tried to understand what the code tries to accomplish, so maybe there's a way that doesn't involve even the above.
[..snip..]
Signature · 1 line
mailto:[email protected]
v2 cover Improve SD controllers emulation
In reply to Mitsyanko IgorChangelog v1->v2:
PATCH 1/3:
- .calc_size field replaced with .get_bufsize field in VMStateField;
- .size_offset removed completely, macros based on it rewritten to use new .get_bufsize field.
PATCH 2/3:
- all binary variables in SDState now have bool type;
- SDState structure rearranged to ensure alignement;
- sd_init(), sd_enable() now receive bool;
- new version of PATCH 1/3 now used to save wp_groups array; PATCH 3/3:
- DMA transfers modified and now operate with data blocks of BLKSIZE only, like real hardware does;
- reset procedure optimized;
- new version of PATCH 1/3 now used to save fifo_buffer.
First patch of this patch set modifies existing VMStateField interface to ease save/restore functionality implementation for device's dynamically allocated buffers. This modification is used later in second patch to implement SD card's VMStateDescription structure.
Third patch adds imlementation of new device: SD host controller fully compliant with "SD host controller specification version 2.00". It also uses first patch modifications.
Mitsyanko Igor (3):
vmstate: introduce get_bufsize entry in VMStateField hw/sd.c: add SD card save/load support
hw: Introduce spec. ver. 2.00 compliant SD host controller
Makefile.target | 1 + hw/g364fb.c | 7 +- hw/hw.h | 41 +-- hw/m48t59.c | 7 +- hw/mac_nvram.c | 8 +- hw/onenand.c | 7 +- hw/sd.c | 130 +++-- hw/sd.h | 4 +- hw/sdhc_ver2.c | 1569 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/sdhc_ver2.h | 327 ++++++++++++ savevm.c | 10 +- 11 files changed, 2020 insertions(+), 91 deletions(-) create mode 100644 hw/sdhc_ver2.c create mode 100644 hw/sdhc_ver2.h
Signature · 1 line
1.7.4.1
PATCH v2 1/3 vmstate: introduce get_bufsize entry in VMStateField
New get_bufsize field in VMStateField is supposed to help us easily add save/restore support of dynamically allocated buffers in device's states.
There are some cases when information about size of dynamically allocated buffer is already presented in specific device's state structure, but in such a form that can not be used with existing VMStateField interface. Currently, we either can get size from another variable in device's state as it is with VMSTATE_VBUFFER_* macros, or we can also multiply value kept in a variable by a constant with VMSTATE_BUFFER_MULTIPLY macro. If we need to perform any other action, we're forced to add additional variable with size information to device state structure with the only intention to use it in VMStateDescription. This approach is not very pretty. Adding extra flags to VMStateFlags enum for every other possible operation with size field seems redundant, and still it would't cover cases when we need to perform a set of operations to get size value.
With get_bufsize callback we can calculate size of dynamic array in whichever way we need. We don't need .size_offset field anymore, so we can remove it from VMState Field structure to compensate for extra memory consuption because of get_bufsize addition. Macros VMSTATE_VBUFFER* are modified to use new callback instead of .size_offset. Macro VMSTATE_BUFFER_MULTIPLY and VMFlag VMS_MULTIPLY are removed completely as they are now redundant.
--- hw/g364fb.c | 7 ++++++- hw/hw.h | 41 +++++++---------------------------------- hw/m48t59.c | 7 ++++++- hw/mac_nvram.c | 8 +++++++- hw/onenand.c | 7 ++++++- savevm.c | 10 ++-------- 6 files changed, 34 insertions(+), 46 deletions(-)
hw/g364fb.c +6 -1
@@ -495,6 +495,11 @@ static int g364fb_post_load(void *opaque, int version_id)return 0 ; } +static int g364fb_get_vramsize (void *opaque,int version_id) +{ +return ((G364State *)opaque)->vram_size; +} +static const VMStateDescription vmstate_g364fb = { .name ="g364fb" , .version_id =1 ,
@@ -502,7 +507,7 @@ static const VMStateDescription vmstate_g364fb = { .minimum_version_id_old = 1, .post_load = g364fb_post_load, .fields = (VMStateField []) { -VMSTATE_VBUFFER_UINT32 (vram, G364State,1 ,NULL ,0 , vram_size), +VMSTATE_VBUFFER (vram, G364State,1 ,NULL ,0 , g364fb_get_vramsize),VMSTATE_BUFFER_UNSAFE (color_palette, G364State,0 ,256 *3 ),VMSTATE_BUFFER_UNSAFE (cursor_palette, G364State,0 ,9 ),VMSTATE_UINT16_ARRAY (cursor, G364State,512 ),
hw/hw.h +7 -34
74 lines not on this page · raw message
hw/m48t59.c +6 -1
@@ -582,6 +582,11 @@ static const MemoryRegionOps nvram_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static int m48t59_get_bufsize (void *opaque,int version_id) +{ +return ((M48t59State *)opaque)->size; +} +static const VMStateDescription vmstate_m48t59 = { .name ="m48t59" , .version_id =1 ,
@@ -590,7 +595,7 @@ static const VMStateDescription vmstate_m48t59 = { .fields = (VMStateField[]) {VMSTATE_UINT8 (lock, M48t59State),VMSTATE_UINT16 (addr, M48t59State), -VMSTATE_VBUFFER_UINT32 (buffer, M48t59State,0 ,NULL ,0 , size), +VMSTATE_VBUFFER (buffer, M48t59State,0 ,NULL ,0 , m48t59_get_bufsize),VMSTATE_END_OF_LIST () } };
hw/mac_nvram.c +7 -1
@@ -100,13 +100,19 @@ static const MemoryRegionOps macio_nvram_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static int macio_nvram_get_datasize (void *opaque,int version_id) +{ +return ((MacIONVRAMState *)opaque)->size; +} +static const VMStateDescription vmstate_macio_nvram = { .name ="macio_nvram" , .version_id =1 , .minimum_version_id =1 , .minimum_version_id_old =1 , .fields = (VMStateField []) { -VMSTATE_VBUFFER_UINT32 (data, MacIONVRAMState,0 ,NULL ,0 , size), +VMSTATE_VBUFFER (data, MacIONVRAMState,0 ,NULL ,0 , + macio_nvram_get_datasize),VMSTATE_END_OF_LIST () } };
hw/onenand.c +6 -1
@@ -160,6 +160,11 @@ static int onenand_post_load(void *opaque, int version_id)return 0 ; } +static int onenand_get_blockwpsize (void *opaque,int version_id) +{ +return ((OneNANDState *)opaque)->blocks; +} +static const VMStateDescription vmstate_onenand = { .name ="onenand" , .version_id =1 ,
@@ -181,7 +186,7 @@ static const VMStateDescription vmstate_onenand = {VMSTATE_UINT16 (intstatus, OneNANDState),VMSTATE_UINT16 (wpstatus, OneNANDState),VMSTATE_INT32 (secs_cur, OneNANDState), -VMSTATE_PARTIAL_VBUFFER (blockwp, OneNANDState, blocks), +VMSTATE_PARTIAL_VBUFFER (blockwp, OneNANDState, onenand_get_blockwpsize),VMSTATE_UINT8 (ecc.cp, OneNANDState),VMSTATE_UINT16_ARRAY (ecc.lp, OneNANDState,2 ), VMSTATE_UINT16(ecc.count, OneNANDState),
savevm.c +2 -8
@@ -1412,10 +1412,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } + size = field->get_bufsize (opaque, version_id); }if (field->flags &VMS_ARRAY ) { n_elems = field->num;
@@ -1476,10 +1473,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } + size = field->get_bufsize (opaque, vmsd->version_id); }if (field->flags &VMS_ARRAY ) { n_elems = field->num;
Signature · 1 line
1.7.4.1
PATCH v2 2/3 hw/sd.c: add SD card save/load support
In reply to Mitsyanko IgorWe couldn't properly implement save/restore functionality of SD host controllers states without SD card's state VMStateDescription implementation. This patch updates SD card emulation to support save/load of card's state. Update requires changing of data type of several variables in SDState. Variables order rearranged to ensure proper data alignment in SDState structure.
For consistency, because several variables now have bool datatype, API was modified to use bool as well, 0 was changed to 'false' and 1 was changed to 'true' in those places where it was appropriate.
--- hw/sd.c | 130 ++++++++++++++++++++++++++++++++++++++++++--------------------- hw/sd.h | 4 +- 2 files changed, 89 insertions(+), 45 deletions(-)
hw/sd.c +87 -43
@@ -54,49 +54,53 @@ typedef enum { sd_illegal =-2 , } sd_rsp_type_t; +enum { + sd_inactive, + sd_card_identification_mode, + sd_data_transfer_mode, +}; + +enum { + sd_inactive_state =-1 , + sd_idle_state =0 , + sd_ready_state, + sd_identification_state, + sd_standby_state, + sd_transfer_state, + sd_sendingdata_state, + sd_receivingdata_state, + sd_programming_state, + sd_disconnect_state, +}; +struct SDState { -enum { - sd_inactive, - sd_card_identification_mode, - sd_data_transfer_mode, - } mode; -enum { - sd_inactive_state =-1 , - sd_idle_state =0 , - sd_ready_state, - sd_identification_state, - sd_standby_state, - sd_transfer_state, - sd_sendingdata_state, - sd_receivingdata_state, - sd_programming_state, - sd_disconnect_state, - } state; +int32_t state;uint32_t ocr;uint8_t scr[8 ];uint8_t cid[16 ];uint8_t csd[16 ]; -uint16_t rca;uint32_t card_status;uint8_t sd_status[64 ];uint32_t vhs; -int wp_switch; -int *wp_groups;uint64_t size; -int blk_len; +uint32_t blk_len;uint32_t erase_start;uint32_t erase_end;uint8_t pwd[16 ]; -int pwd_len; -int function_group[6 ]; - -int spi; -int current_cmd; +uint32_t pwd_len; +uint8_t function_group[6 ]; +uint8_t mode; +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! */ -int expecting_acmd; -int blk_written; +bool expecting_acmd; +bool spi; +bool enable; +bool wp_switch; +bool *wp_groups; + +uint32_t blk_written;uint64_t data_start;uint32_t data_offset;uint8_t data[512 ];
@@ -104,8 +108,7 @@ struct SDState {qemu_irq inserted_cb;BlockDriverState *bdrv;uint8_t *buf; - -int enable; +uint16_t rca; };static void sd_set_mode (SDState *sd)
@@ -415,14 +418,14 @@ 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 = (int *)g_malloc0 (sizeof (int ) * sect); -memset (sd->function_group,0 ,sizeof (int ) *6 ); + sd->wp_groups = (bool *)g_malloc0 (sizeof (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)
@@ -440,23 +443,64 @@ static const BlockDevOps sd_block_ops = { .change_media_cb = sd_cardchange, }; + +static int sd_get_wpgroups_size (void *opaque,int version_id) +{ +SDState *sd = (SDState *)opaque; +return sizeof (bool ) * (sd->size >> (HWBLOCK_SHIFT +SECTOR_SHIFT + +WPGROUP_SHIFT )); +} + +static const VMStateDescription sd_vmstate = { + .name ="sd_card" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_INT32 (state, SDState), +VMSTATE_UINT8_ARRAY (cid, SDState,16 ), +VMSTATE_UINT8_ARRAY (csd, SDState,16 ), +VMSTATE_UINT32 (card_status, SDState), +VMSTATE_PARTIAL_BUFFER (sd_status, SDState,1 ), +VMSTATE_UINT32 (vhs, SDState), +VMSTATE_UINT32 (blk_len, SDState), +VMSTATE_UINT32 (erase_start, SDState), +VMSTATE_UINT32 (erase_end, SDState), +VMSTATE_UINT8_ARRAY (pwd, SDState,16 ), +VMSTATE_UINT32 (pwd_len, SDState), +VMSTATE_UINT8_ARRAY (function_group, SDState,6 ), +VMSTATE_UINT8 (mode, SDState), +VMSTATE_UINT8 (current_cmd, SDState), +VMSTATE_BOOL (expecting_acmd, SDState), +VMSTATE_BOOL (enable, SDState), +VMSTATE_VBUFFER (wp_groups, SDState,1 ,NULL ,0 , sd_get_wpgroups_size), +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_UINT16 (rca, SDState), +VMSTATE_END_OF_LIST () + } +}; +/* We do not model the chip select pin, so allow the board to select 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);bdrv_set_dev_ops (sd->bdrv, &sd_block_ops, sd); } +vmstate_register (NULL ,-1 , &sd_vmstate, sd);return sd; }
@@ -534,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 )];
@@ -560,7 +604,7 @@ static void sd_lock_command(SDState *sd) sd->card_status |=LOCK_UNLOCK_FAILED ;return ; } -memset (sd->wp_groups,0 ,sizeof (int ) * (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 ;
@@ -1008,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;
@@ -1028,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;
@@ -1125,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;
@@ -1307,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;
@@ -1318,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);
@@ -1704,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; }
hw/sd.h +2 -2
@@ -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 */
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH V2 2/3] hw/sd.c: add SD card save/load support
Quoted 8 lines · Mitsyanko Igor
We couldn't properly implement save/restore functionality of SD host controllers states without SD card's state VMStateDescription implementation. This patch updates SD card emulation to support save/load of card's state. Update requires changing of data type of several variables in SDState. Variables order rearranged to ensure proper data alignment in SDState structure.
For consistency, because several variables now have bool datatype, API was modified to use bool as well, 0 was changed to 'false' and 1 was changed to 'true' in those places where it was appropriate.
If you're going to switch things to bool, can you break those out into separate patches for the individual things you're changing, please? Otherwise this patch is trying to do too many things at once.
Also, why should we care particularly about the order of fields in SDState? There will be at most a handful of copies of this struct in qemu, costing a handful of bytes in extra padding. ("ensure proper data alignment" is wrong -- the compiler does this for us.) If you feel you must rearrange things, again, please put it in a separate patch so it's easier to read.
hw/sd.c static void sd_reset(SDState *sd, BlockDriverState *bdrv) · line 421
Quoted 7 lines
hw/sd.c +1
-2@@ -415,14 +418,14 @@ 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 = (int *) g_malloc0(sizeof(int) * sect); - memset(sd->function_group, 0, sizeof(int) * 6); + sd->wp_groups = (bool *)g_malloc0(sizeof(bool) * sect);
sd->wp_groups = g_new0(bool, sect);
-- PMM
Re: [Qemu-devel] [PATCH V2 2/3] hw/sd.c: add SD card save/load support
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Mitsyanko Igor
We couldn't properly implement save/restore functionality of SD host controllers states without SD card's state VMStateDescription implementation. This patch updates SD card emulation to support save/load of card's state. Update requires changing of data type of several variables in SDState. Variables order rearranged to ensure proper data alignment in SDState structure.
For consistency, because several variables now have bool datatype, API was modified to use bool as well, 0 was changed to 'false' and 1 was changed to 'true' in those places where it was appropriate.
Quoted 4 lines
If you're going to switch things to bool, can you break those out into separate patches for the individual things you're changing, please? Otherwise this patch is trying to do too many things at once.
Sure, I'll split this patch into a few smaller ones, thanks.
Quoted 7 lines
Also, why should we care particularly about the order of fields in SDState? There will be at most a handful of copies of this struct in qemu, costing a handful of bytes in extra padding. ("ensure proper data alignment" is wrong -- the compiler does this for us.) If you feel you must rearrange things, again, please put it in a separate patch so it's easier to read.
Why not, it wouldn't hurt anyone.
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
Re: [Qemu-devel] [PATCH V2 2/3] hw/sd.c: add SD card save/load support
Quoted 9 lines · Mitsyanko Igor
Quoted 7 lines · Peter Maydell
Also, why should we care particularly about the order of fields in SDState? There will be at most a handful of copies of this struct in qemu, costing a handful of bytes in extra padding. ("ensure proper data alignment" is wrong -- the compiler does this for us.) If you feel you must rearrange things, again, please put it in a separate patch so it's easier to read.
Why not, it wouldn't hurt anyone.
Basically I think this is pointless microoptimisation. If you haven't measured something and determined that this is a useful change because it makes things faster or usefully decreases memory use by some non-trivial amount, then this kind of change is a poor use of your time and also mine (as reviewer) and of whoever eventually commits the patch to git.
-- PMM
PATCH v2 3/3 hw: Introduce spec. ver. 2.00 compliant SD host controller
In reply to Mitsyanko IgorThis patch adds implementation of "SD specification version 2.00" compliant SD host controller. Also it provides interface to implement SoC-specific controllers on top of this specification-compliant one.
--- Makefile.target | 1 + hw/sdhc_ver2.c | 1569 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/sdhc_ver2.h | 327 ++++++++++++ 3 files changed, 1897 insertions(+), 0 deletions(-) create mode 100644 hw/sdhc_ver2.c create mode 100644 hw/sdhc_ver2.h
Makefile.target +1 -0
@@ -358,6 +358,7 @@ obj-arm-y += vexpress.o obj-arm-y += strongarm.o obj-arm-y += collie.o obj-arm-y += pl041.o lm4549.o +obj-arm-y += sdhc_ver2.o obj-sh4-y = shix.o r2d.o sh7750.o sh7750_regnames.o tc58128.o obj-sh4-y += sh_timer.o sh_serial.o sh_intc.o sh_pci.o sm501.o
hw/sdhc_ver2.c new file +1569 -0
1,569 lines not on this page · raw message
hw/sdhc_ver2.h new file +327 -0
327 lines not on this page · raw message
Signature · 1 line
1.7.4.1
v3 cover Improve SD controllers emulation
In reply to Mitsyanko IgorChangelogv2->v3:
- PATCH 2/3 splitted into smaller patches 2-4/5.
- SDState structure rearrengment dropped.
v1->v2:
PATCH 1/3:
- .calc_size field replaced with .get_bufsize field in VMStateField;
- .size_offset removed completely, macros based on it rewritten to use new .get_bufsize field.
PATCH 2/3:
- all binary variables in SDState now have bool type;
- SDState structure rearranged to ensure alignement;
- sd_init(), sd_enable() now receive bool;
- new version of PATCH 1/3 now used to save wp_groups array; PATCH 3/3:
- DMA transfers modified and now operate with data blocks of BLKSIZE only, like real hardware does;
- reset procedure optimized;
- new version of PATCH 1/3 now used to save fifo_buffer.
First patch of this patch set modifies existing VMStateField interface to ease save/restore functionality implementation for device's dynamically allocated buffers. This modification is used later in second patch to implement SD card's VMStateDescription structure.
Third patch adds imlementation of new device: SD host controller fully compliant with "SD host controller specification version 2.00". It also uses first patch modifications.
Mitsyanko Igor (5):
vmstate: introduce get_bufsize entry in VMStateField hw/sd.c: add SD card save/load support
hw/sd.c: convert wp_groups, expecting_acmd and enable to bool hw/sd.c: convert wp_switch and spi to bool
hw: Introduce spec. ver. 2.00 compliant SD host controller
Makefile.target | 1 + hw/g364fb.c | 7 +- hw/hw.h | 41 +-- hw/m48t59.c | 7 +- hw/mac_nvram.c | 8 +- hw/onenand.c | 7 +- hw/sd.c | 126 +++-- hw/sd.h | 4 +- hw/sdhc_ver2.c | 1569 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/sdhc_ver2.h | 327 ++++++++++++ savevm.c | 10 +- 11 files changed, 2018 insertions(+), 89 deletions(-) create mode 100644 hw/sdhc_ver2.c create mode 100644 hw/sdhc_ver2.h
Signature · 1 line
1.7.4.1
PATCH v3 1/5 vmstate: introduce get_bufsize entry in VMStateField
New get_bufsize field in VMStateField is supposed to help us easily add save/restore support of dynamically allocated buffers in device's states.
There are some cases when information about size of dynamically allocated buffer is already presented in specific device's state structure, but in such a form that can not be used with existing VMStateField interface. Currently, we either can get size from another variable in device's state as it is with VMSTATE_VBUFFER_* macros, or we can also multiply value kept in a variable by a constant with VMSTATE_BUFFER_MULTIPLY macro. If we need to perform any other action, we're forced to add additional variable with size information to device state structure with the only intention to use it in VMStateDescription. This approach is not very pretty. Adding extra flags to VMStateFlags enum for every other possible operation with size field seems redundant, and still it would't cover cases when we need to perform a set of operations to get size value.
With get_bufsize callback we can calculate size of dynamic array in whichever way we need. We don't need .size_offset field anymore, so we can remove it from VMState Field structure to compensate for extra memory consuption because of get_bufsize addition. Macros VMSTATE_VBUFFER* are modified to use new callback instead of .size_offset. Macro VMSTATE_BUFFER_MULTIPLY and VMFlag VMS_MULTIPLY are removed completely as they are now redundant.
--- hw/g364fb.c | 7 ++++++- hw/hw.h | 41 +++++++---------------------------------- hw/m48t59.c | 7 ++++++- hw/mac_nvram.c | 8 +++++++- hw/onenand.c | 7 ++++++- savevm.c | 10 ++-------- 6 files changed, 34 insertions(+), 46 deletions(-)
hw/g364fb.c +6 -1
@@ -495,6 +495,11 @@ static int g364fb_post_load(void *opaque, int version_id)return 0 ; } +static int g364fb_get_vramsize (void *opaque,int version_id) +{ +return ((G364State *)opaque)->vram_size; +} +static const VMStateDescription vmstate_g364fb = { .name ="g364fb" , .version_id =1 ,
@@ -502,7 +507,7 @@ static const VMStateDescription vmstate_g364fb = { .minimum_version_id_old = 1, .post_load = g364fb_post_load, .fields = (VMStateField []) { -VMSTATE_VBUFFER_UINT32 (vram, G364State,1 ,NULL ,0 , vram_size), +VMSTATE_VBUFFER (vram, G364State,1 ,NULL ,0 , g364fb_get_vramsize),VMSTATE_BUFFER_UNSAFE (color_palette, G364State,0 ,256 *3 ),VMSTATE_BUFFER_UNSAFE (cursor_palette, G364State,0 ,9 ),VMSTATE_UINT16_ARRAY (cursor, G364State,512 ),
hw/hw.h +7 -34
74 lines not on this page · raw message
hw/m48t59.c +6 -1
@@ -582,6 +582,11 @@ static const MemoryRegionOps nvram_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static int m48t59_get_bufsize (void *opaque,int version_id) +{ +return ((M48t59State *)opaque)->size; +} +static const VMStateDescription vmstate_m48t59 = { .name ="m48t59" , .version_id =1 ,
@@ -590,7 +595,7 @@ static const VMStateDescription vmstate_m48t59 = { .fields = (VMStateField[]) {VMSTATE_UINT8 (lock, M48t59State),VMSTATE_UINT16 (addr, M48t59State), -VMSTATE_VBUFFER_UINT32 (buffer, M48t59State,0 ,NULL ,0 , size), +VMSTATE_VBUFFER (buffer, M48t59State,0 ,NULL ,0 , m48t59_get_bufsize),VMSTATE_END_OF_LIST () } };
hw/mac_nvram.c +7 -1
@@ -100,13 +100,19 @@ static const MemoryRegionOps macio_nvram_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static int macio_nvram_get_datasize (void *opaque,int version_id) +{ +return ((MacIONVRAMState *)opaque)->size; +} +static const VMStateDescription vmstate_macio_nvram = { .name ="macio_nvram" , .version_id =1 , .minimum_version_id =1 , .minimum_version_id_old =1 , .fields = (VMStateField []) { -VMSTATE_VBUFFER_UINT32 (data, MacIONVRAMState,0 ,NULL ,0 , size), +VMSTATE_VBUFFER (data, MacIONVRAMState,0 ,NULL ,0 , + macio_nvram_get_datasize),VMSTATE_END_OF_LIST () } };
hw/onenand.c +6 -1
@@ -160,6 +160,11 @@ static int onenand_post_load(void *opaque, int version_id)return 0 ; } +static int onenand_get_blockwpsize (void *opaque,int version_id) +{ +return ((OneNANDState *)opaque)->blocks; +} +static const VMStateDescription vmstate_onenand = { .name ="onenand" , .version_id =1 ,
@@ -181,7 +186,7 @@ static const VMStateDescription vmstate_onenand = {VMSTATE_UINT16 (intstatus, OneNANDState),VMSTATE_UINT16 (wpstatus, OneNANDState),VMSTATE_INT32 (secs_cur, OneNANDState), -VMSTATE_PARTIAL_VBUFFER (blockwp, OneNANDState, blocks), +VMSTATE_PARTIAL_VBUFFER (blockwp, OneNANDState, onenand_get_blockwpsize),VMSTATE_UINT8 (ecc.cp, OneNANDState),VMSTATE_UINT16_ARRAY (ecc.lp, OneNANDState,2 ), VMSTATE_UINT16(ecc.count, OneNANDState),
savevm.c +2 -8
@@ -1412,10 +1412,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } + size = field->get_bufsize (opaque, version_id); }if (field->flags &VMS_ARRAY ) { n_elems = field->num;
@@ -1476,10 +1473,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } + size = field->get_bufsize (opaque, vmsd->version_id); }if (field->flags &VMS_ARRAY ) { n_elems = field->num;
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH V3 1/5] vmstate: introduce get_bufsize entry in VMStateField
Am 28.12.2011 16:32, schrieb Mitsyanko Igor:
Quoted 20 lines
New
get_bufsizefield in VMStateField is supposed to help us easily add save/restore support of dynamically allocated buffers in device's states.
There are some cases when information about size of dynamically allocated buffer is already presented in specific device's state structure, but in such a form that can not be used with existing VMStateField interface. Currently, we either can get size from another variable in device's state as it is with VMSTATE_VBUFFER_* macros, or we can also multiply value kept in a variable by a constant withVMSTATE_BUFFER_MULTIPLYmacro. If we need to perform any other action, we're forced to add additional variable with size information to device state structure with the only intention to use it in VMStateDescription. This approach is not very pretty. Adding extra flags to VMStateFlags enum for every other possible operation with size field seems redundant, and still it would't cover cases when we need to perform a set of operations to get size value.
Withget_bufsizecallback we can calculate size of dynamic array in whichever way we need. We don't need .size_offset field anymore, so we can remove it from VMState Field structure to compensate for extra memory consuption because ofget_bufsizeaddition. Macros VMSTATE_VBUFFER* are modified to use new callback instead of .size_offset. MacroVMSTATE_BUFFER_MULTIPLYand VMFlagVMS_MULTIPLYare removed completely as they are now redundant.
Quoted 1 line
Signed-off-by Mitsyanko Igor <[email protected]>
Ping! Juan, what do you think?
Andreas
Quoted 219 lines
--- hw/g364fb.c | 7 ++++++- hw/hw.h | 41 +++++++---------------------------------- hw/m48t59.c | 7 ++++++- hw/mac_nvram.c | 8 +++++++- hw/onenand.c | 7 ++++++- savevm.c | 10 ++-------- 6 files changed, 34 insertions(+), 46 deletions(-)hw/g364fb.c +6
-1@@ -495,6 +495,11 @@ static int g364fb_post_load(void *opaque, int version_id)return 0 ; } +static int g364fb_get_vramsize (void *opaque,int version_id) +{ +return ((G364State *)opaque)->vram_size; +} +static const VMStateDescription vmstate_g364fb = { .name ="g364fb" , .version_id =1 ,@@ -502,7 +507,7 @@ static const VMStateDescription vmstate_g364fb = { .minimum_version_id_old = 1, .post_load = g364fb_post_load, .fields = (VMStateField []) { -VMSTATE_VBUFFER_UINT32 (vram, G364State,1 ,NULL ,0 , vram_size), +VMSTATE_VBUFFER (vram, G364State,1 ,NULL ,0 , g364fb_get_vramsize),VMSTATE_BUFFER_UNSAFE (color_palette, G364State,0 ,256 *3 ),VMSTATE_BUFFER_UNSAFE (cursor_palette, G364State,0 ,9 ),VMSTATE_UINT16_ARRAY (cursor, G364State,512 ),hw/hw.h +7
-34@@ -303,7 +303,6 @@ enum VMStateFlags {VMS_ARRAY_OF_POINTER =0x040 ,VMS_VARRAY_UINT16 =0x080 ,/* Array with size in uint16_t field */ VMS_VBUFFER =0x100 ,/* Buffer with size in int32_t field */ -VMS_MULTIPLY =0x200 ,/* multiply "size" field by field_size */ VMS_VARRAY_UINT8 =0x400 ,/* Array with size in uint8_t field*/ VMS_VARRAY_UINT32 = 0x800, /* Array with size in uint32_t field*/ };@@ -315,12 +314,12 @@ typedef struct {size_t start;int num;size_t num_offset; -size_t size_offset;const VMStateInfo *info;enum VMStateFlags flags;const VMStateDescription *vmsd;int version_id;bool (*field_exists)(void *opaque,int version_id); +int (*get_bufsize)(void *opaque,int version_id); } VMStateField; typedef struct VMStateSubsection {@@ -584,34 +583,11 @@ extern const VMStateInfo vmstate_info_unused_buffer; .offset = vmstate_offset_buffer(_state, _field) + _start, \ } -#define VMSTATE_BUFFER_MULTIPLY (_field, _state, _version, _test, _start, _field_size, _multiply) { \ +#define VMSTATE_VBUFFER (_field, _state, _version, _test, _start, _get_bufsize) { \ .name = (stringify(_field)), \ .version_id = (_version), \ .field_exists = (_test), \ - .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ - .size = (_multiply), \ - .info = &vmstate_info_buffer, \ - .flags = VMS_VBUFFER|VMS_MULTIPLY, \ - .offset = offsetof(_state, _field), \ - .start = (_start), \ -} - -#define VMSTATE_VBUFFER (_field, _state, _version, _test, _start, _field_size) { \ - .name = (stringify(_field)), \ - .version_id = (_version), \ - .field_exists = (_test), \ - .size_offset = vmstate_offset_value(_state, _field_size, int32_t),\ - .info = &vmstate_info_buffer, \ - .flags = VMS_VBUFFER|VMS_POINTER, \ - .offset = offsetof(_state, _field), \ - .start = (_start), \ -} - -#define VMSTATE_VBUFFER_UINT32 (_field, _state, _version, _test, _start, _field_size) { \ - .name = (stringify(_field)), \ - .version_id = (_version), \ - .field_exists = (_test), \ - .size_offset = vmstate_offset_value(_state, _field_size, uint32_t),\ + .get_bufsize = (_get_bufsize), \ .info = &vmstate_info_buffer, \ .flags = VMS_VBUFFER|VMS_POINTER, \ .offset = offsetof(_state, _field), \@@ -891,14 +867,11 @@ extern const VMStateDescription vmstate_hid_ptr_device;#define VMSTATE_BUFFER_START_MIDDLE (_f, _s, _start) \ VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, _f))) -#define VMSTATE_PARTIAL_VBUFFER (_f, _s, _size) \ - VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size) - -#define VMSTATE_PARTIAL_VBUFFER_UINT32 (_f, _s, _size) \ - VMSTATE_VBUFFER_UINT32(_f, _s, 0, NULL, 0, _size) +#define VMSTATE_PARTIAL_VBUFFER (_f, _s, _get_bufsize) \ + VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _get_bufsize) -#define VMSTATE_SUB_VBUFFER (_f, _s, _start, _size) \ - VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size) +#define VMSTATE_SUB_VBUFFER (_f, _s, _start, _get_bufsize) \ + VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _get_bufsize)#define VMSTATE_BUFFER_TEST (_f, _s, _test) \ VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))hw/m48t59.c +6
-1@@ -582,6 +582,11 @@ static const MemoryRegionOps nvram_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static int m48t59_get_bufsize (void *opaque,int version_id) +{ +return ((M48t59State *)opaque)->size; +} +static const VMStateDescription vmstate_m48t59 = { .name ="m48t59" , .version_id =1 ,@@ -590,7 +595,7 @@ static const VMStateDescription vmstate_m48t59 = { .fields = (VMStateField[]) {VMSTATE_UINT8 (lock, M48t59State),VMSTATE_UINT16 (addr, M48t59State), -VMSTATE_VBUFFER_UINT32 (buffer, M48t59State,0 ,NULL ,0 , size), +VMSTATE_VBUFFER (buffer, M48t59State,0 ,NULL ,0 , m48t59_get_bufsize),VMSTATE_END_OF_LIST () } };hw/mac_nvram.c +7
-1@@ -100,13 +100,19 @@ static const MemoryRegionOps macio_nvram_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static int macio_nvram_get_datasize (void *opaque,int version_id) +{ +return ((MacIONVRAMState *)opaque)->size; +} +static const VMStateDescription vmstate_macio_nvram = { .name ="macio_nvram" , .version_id =1 , .minimum_version_id =1 , .minimum_version_id_old =1 , .fields = (VMStateField []) { -VMSTATE_VBUFFER_UINT32 (data, MacIONVRAMState,0 ,NULL ,0 , size), +VMSTATE_VBUFFER (data, MacIONVRAMState,0 ,NULL ,0 , + macio_nvram_get_datasize),VMSTATE_END_OF_LIST () } };hw/onenand.c +6
-1@@ -160,6 +160,11 @@ static int onenand_post_load(void *opaque, int version_id)return 0 ; } +static int onenand_get_blockwpsize (void *opaque,int version_id) +{ +return ((OneNANDState *)opaque)->blocks; +} +static const VMStateDescription vmstate_onenand = { .name ="onenand" , .version_id =1 ,@@ -181,7 +186,7 @@ static const VMStateDescription vmstate_onenand = {VMSTATE_UINT16 (intstatus, OneNANDState),VMSTATE_UINT16 (wpstatus, OneNANDState),VMSTATE_INT32 (secs_cur, OneNANDState), -VMSTATE_PARTIAL_VBUFFER (blockwp, OneNANDState, blocks), +VMSTATE_PARTIAL_VBUFFER (blockwp, OneNANDState, onenand_get_blockwpsize),VMSTATE_UINT8 (ecc.cp, OneNANDState),VMSTATE_UINT16_ARRAY (ecc.lp, OneNANDState,2 ), VMSTATE_UINT16(ecc.count, OneNANDState),savevm.c +2
-8@@ -1412,10 +1412,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } + size = field->get_bufsize (opaque, version_id); }if (field->flags &VMS_ARRAY ) { n_elems = field->num;@@ -1476,10 +1473,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,int size = field->size;if (field->flags &VMS_VBUFFER ) { - size = *(int32_t *)(opaque+field->size_offset); -if (field->flags &VMS_MULTIPLY ) { - size *= field->size; - } + size = field->get_bufsize (opaque, vmsd->version_id); }if (field->flags &VMS_ARRAY ) { n_elems = field->num;
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH v3 2/5 hw/sd.c: add SD card save/load support
In reply to Mitsyanko IgorWe couldn't properly implement save/restore functionality of SD host controllers states without SD card's state VMStateDescription implementation. This patch updates SD card emulation to support save/load of card's state.
--- hw/sd.c | 100 +++++++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 72 insertions(+), 28 deletions(-)
hw/sd.c +72 -28
@@ -54,24 +54,28 @@ typedef enum { sd_illegal =-2 , } sd_rsp_type_t; +enum { + sd_inactive, + sd_card_identification_mode, + sd_data_transfer_mode, +}; + +enum { + sd_inactive_state =-1 , + sd_idle_state =0 , + sd_ready_state, + sd_identification_state, + sd_standby_state, + sd_transfer_state, + sd_sendingdata_state, + sd_receivingdata_state, + sd_programming_state, + sd_disconnect_state, +} state; +struct SDState { -enum { - sd_inactive, - sd_card_identification_mode, - sd_data_transfer_mode, - } mode; -enum { - sd_inactive_state =-1 , - sd_idle_state =0 , - sd_ready_state, - sd_identification_state, - sd_standby_state, - sd_transfer_state, - sd_sendingdata_state, - sd_receivingdata_state, - sd_programming_state, - sd_disconnect_state, - } state; +uint32_t mode; +int32_t state;uint32_t ocr;uint8_t scr[8 ];uint8_t cid[16 ];
@@ -81,22 +85,22 @@ struct SDState {uint8_t sd_status[64 ];uint32_t vhs;int wp_switch; -int *wp_groups; +bool *wp_groups;uint64_t size; -int blk_len; +uint32_t blk_len;uint32_t erase_start;uint32_t erase_end;uint8_t pwd[16 ]; -int pwd_len; -int function_group[6 ]; +uint32_t pwd_len; +uint8_t function_group[6 ];int spi; -int current_cmd; +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! */ -int expecting_acmd; -int blk_written; +bool expecting_acmd; +uint32_t blk_written;uint64_t data_start;uint32_t data_offset;uint8_t data[512 ];
@@ -105,7 +109,7 @@ struct SDState {BlockDriverState *bdrv;uint8_t *buf; -int enable; +bool enable; };static void sd_set_mode (SDState *sd)
@@ -415,8 +419,8 @@ 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 = (int *)g_malloc0 (sizeof (int ) * sect); -memset (sd->function_group,0 ,sizeof (int ) *6 ); + 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;
@@ -440,6 +444,45 @@ static const BlockDevOps sd_block_ops = { .change_media_cb = sd_cardchange, }; +static int sd_get_wpgroups_size (void *opaque,int version_id) +{ +SDState *sd = (SDState *)opaque; +return sizeof (bool ) * (sd->size >> (HWBLOCK_SHIFT +SECTOR_SHIFT + +WPGROUP_SHIFT )); +} + +static const VMStateDescription sd_vmstate = { + .name ="sd_card" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (mode, SDState), +VMSTATE_INT32 (state, SDState), +VMSTATE_UINT8_ARRAY (cid, SDState,16 ), +VMSTATE_UINT8_ARRAY (csd, SDState,16 ), +VMSTATE_UINT16 (rca, SDState), +VMSTATE_UINT32 (card_status, SDState), +VMSTATE_PARTIAL_BUFFER (sd_status, SDState,1 ), +VMSTATE_UINT32 (vhs, SDState), +VMSTATE_VBUFFER (wp_groups, SDState,1 ,NULL ,0 , sd_get_wpgroups_size), +VMSTATE_UINT32 (blk_len, SDState), +VMSTATE_UINT32 (erase_start, SDState), +VMSTATE_UINT32 (erase_end, SDState), +VMSTATE_UINT8_ARRAY (pwd, SDState,16 ), +VMSTATE_UINT32 (pwd_len, SDState), +VMSTATE_UINT8_ARRAY (function_group, SDState,6 ), +VMSTATE_UINT8 (current_cmd, 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_BOOL (enable, SDState), +VMSTATE_END_OF_LIST () + } +}; +/* We do not model the chip select pin, so allow the board to select 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
@@ -457,6 +500,7 @@ SDState *sd_init(BlockDriverState *bs, int is_spi)bdrv_attach_dev_nofail (sd->bdrv, sd);bdrv_set_dev_ops (sd->bdrv, &sd_block_ops, sd); } +vmstate_register (NULL ,-1 , &sd_vmstate, sd);return sd; }
@@ -560,7 +604,7 @@ static void sd_lock_command(SDState *sd) sd->card_status |=LOCK_UNLOCK_FAILED ;return ; } -memset (sd->wp_groups,0 ,sizeof (int ) * (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 ;
Signature · 1 line
1.7.4.1
PATCH v3 3/5 hw/sd.c: convert wp_groups, expecting_acmd and enable to bool
In reply to Mitsyanko IgorSDState variables wp_groups, expecting_acmd and enable are of bool data type but are currently treated as int type variables by rest of the code. This patch updates sd_enable() and sd_wp_addr() so now they explicitly work with bool type, and replaces 0 and 1 with 'false' and 'true' where it's required.
--- hw/sd.c | 18 +++++++++--------- hw/sd.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-)
hw/sd.c +9 -9
@@ -426,7 +426,7 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv) 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)
@@ -494,7 +494,7 @@ SDState *sd_init(BlockDriverState *bs, int is_spi) 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 )];
@@ -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; }
hw/sd.h +1 -1
@@ -74,6 +74,6 @@ 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 */
Signature · 1 line
1.7.4.1
PATCH v3 4/5 hw/sd.c: convert wp_switch and spi to bool
In reply to Mitsyanko IgorCurrently several binary variables in SDState represented as bool type while several other represented as int. This patch converts wp_switch and spi variables to bool and modifies rest of the code to treat this variables as bool instead of int.
--- hw/sd.c | 8 ++++---- hw/sd.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
hw/sd.c +4 -4
@@ -84,7 +84,7 @@ struct SDState {uint32_t card_status;uint8_t sd_status[64 ];uint32_t vhs; -int wp_switch; +bool wp_switch;bool *wp_groups;uint64_t size;uint32_t blk_len;
@@ -94,7 +94,7 @@ 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!
@@ -418,7 +418,7 @@ 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_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 ;
@@ -487,7 +487,7 @@ 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;
hw/sd.h +1 -1
@@ -67,7 +67,7 @@ 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);
Signature · 1 line
1.7.4.1
PATCH v3 5/5 hw: Introduce spec. ver. 2.00 compliant SD host controller
In reply to Mitsyanko IgorThis patch adds implementation of "SD specification version 2.00" compliant SD host controller. Also it provides interface to implement SoC-specific controllers on top of this specification-compliant one.
--- Makefile.target | 1 + hw/sdhc_ver2.c | 1569 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/sdhc_ver2.h | 327 ++++++++++++ 3 files changed, 1897 insertions(+), 0 deletions(-) create mode 100644 hw/sdhc_ver2.c create mode 100644 hw/sdhc_ver2.h
Makefile.target +1 -0
@@ -358,6 +358,7 @@ obj-arm-y += vexpress.o obj-arm-y += strongarm.o obj-arm-y += collie.o obj-arm-y += pl041.o lm4549.o +obj-arm-y += sdhc_ver2.o obj-sh4-y = shix.o r2d.o sh7750.o sh7750_regnames.o tc58128.o obj-sh4-y += sh_timer.o sh_serial.o sh_intc.o sh_pci.o sm501.o
hw/sdhc_ver2.c new file +1569 -0
1,569 lines not on this page · raw message
hw/sdhc_ver2.h new file +327 -0
327 lines not on this page · raw message
Signature · 1 line
1.7.4.1