hw/sd.c: convert wp_groups in SDState to bitfield

Representing each group write protection flag with only one bit instead of int
variable significantly reduces memory consumption.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: make sd_wp_addr() accept 64 bit address argument

Currently sd_wp_addr() accepts 32 bit address arguments therefore implicitly
restricting SD card address range. Change address argument type to uint64_t.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: introduce wrapper for conversion address to wp group

Add wrapper function sd_addr_to_wpnum() to replace long address-->wg_group
conversion line.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: favour SD card type (SDSC or SDHC) when performing erase

SDSC cards use byte unit address and SDHC and SDXC Cards use block unit address
(512 bytes) when setting ERASE_START and ERASE_END with CMD32 and CMD33, we need
to account for this.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: convert binary variables to bool

Several members of SDState have type int when they actually are binary variables.
Change type of these variables to bool to improve code readability. Change SD API
to be in consistency with new variables type.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: make sd_dataready() return bool

For the sake of code clarity

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: make sd_wp_addr() return bool

For the sake of code clarity

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: add SD card save/load support

This patch updates SD card emulation to support save/load of card's state.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: convert SD state to QOM object

A straightforward conversion of SD card implementation to a proper QEMU object.
Wrapper functions were introduced for SDClass methods in order to avoid SD card
users modification. Because of this, name change for several functions in hw/sd.c
was required.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
SD card users: optimize access to SDClass methods

Rather that repeatedly call SD_GET_CLASS() in a loop, call it once before
a loop starts.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
SD card: introduce "spi" property for SD card objects

And drop passing is_spi argument to SDCardClass::init function.
"spi" property could be set while SD card is in IDLE state. It defaults to "false".

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: introduce SD card "device-id" property

Setting "device-id" SD card property ties SD card with BlockDriverState of the
same name. This property can be set dynamically, allowing for SD card hot-insert.

With "device-id" property we no longer need SDClass::init method, all work is
done in property setter.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/sd.c: introduce "eject" property for SD card objects

Boolean property "eject" could be used to query if virtual media is inserted into
SD card object, or to deattach BlockDriverState from SD card object.

Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>