[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 09/10] i2c: Add an SMBus vmstate structure
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [Qemu-devel] [PATCH v2 09/10] i2c: Add an SMBus vmstate structure |
Date: |
Wed, 29 Aug 2018 12:59:32 +0100 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
* address@hidden (address@hidden) wrote:
> From: Corey Minyard <address@hidden>
>
> Signed-off-by: Corey Minyard <address@hidden>
> Cc: Paolo Bonzini <address@hidden>
> Cc: "Michael S . Tsirkin" <address@hidden>
> Cc: Dr. David Alan Gilbert <address@hidden>
> ---
> hw/i2c/smbus.c | 14 ++++++++++++++
> include/hw/i2c/smbus.h | 18 +++++++++++++++---
> 2 files changed, 29 insertions(+), 3 deletions(-)
>
> diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c
> index 6ff77c5..b0774d7 100644
> --- a/hw/i2c/smbus.c
> +++ b/hw/i2c/smbus.c
> @@ -349,6 +349,20 @@ int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t
> command, uint8_t *data,
> return 0;
> }
>
> +const VMStateDescription vmstate_smbus_device = {
> + .name = TYPE_SMBUS_DEVICE,
> + .version_id = 1,
> + .minimum_version_id = 1,
As with the other patch, I suggest the .needed and property to enable it
only for newer machine types.
> + .fields = (VMStateField[]) {
> + VMSTATE_I2C_SLAVE(i2c, SMBusDevice),
> + VMSTATE_INT32(mode, SMBusDevice),
> + VMSTATE_INT32(data_len, SMBusDevice),
> + VMSTATE_UINT8_ARRAY(data_buf, SMBusDevice, SMBUS_DATA_MAX_LEN),
> + VMSTATE_UINT8(command, SMBusDevice),
Do you need a post_load to validate that data_len isn't silly?
Maybe command/mode also need checks.
Dave
> + VMSTATE_END_OF_LIST()
> + }
> +};
> +
> static void smbus_device_class_init(ObjectClass *klass, void *data)
> {
> I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
> diff --git a/include/hw/i2c/smbus.h b/include/hw/i2c/smbus.h
> index d8b1b9e..7b52020 100644
> --- a/include/hw/i2c/smbus.h
> +++ b/include/hw/i2c/smbus.h
> @@ -53,14 +53,16 @@ typedef struct SMBusDeviceClass
> uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n);
> } SMBusDeviceClass;
>
> +#define SMBUS_DATA_MAX_LEN 34 /* command + len + 32 bytes of data. */
> +
> struct SMBusDevice {
> /* The SMBus protocol is implemented on top of I2C. */
> I2CSlave i2c;
>
> /* Remaining fields for internal use only. */
> - int mode;
> - int data_len;
> - uint8_t data_buf[34]; /* command + len + 32 bytes of data. */
> + int32_t mode;
> + int32_t data_len;
> + uint8_t data_buf[SMBUS_DATA_MAX_LEN];
> uint8_t command;
> };
>
> @@ -93,4 +95,14 @@ void smbus_eeprom_init_one(I2CBus *smbus, uint8_t address,
> uint8_t *eeprom_buf);
> void smbus_eeprom_init(I2CBus *smbus, int nb_eeprom,
> const uint8_t *eeprom_spd, int size);
>
> +extern const VMStateDescription vmstate_smbus_device;
> +
> +#define VMSTATE_SMBUS_DEVICE(_field, _state) { \
> + .name = (stringify(_field)), \
> + .size = sizeof(SMBusDevice), \
> + .vmsd = &vmstate_smbus_device, \
> + .flags = VMS_STRUCT, \
> + .offset = vmstate_offset_value(_state, _field, SMBusDevice), \
> +}
> +
> #endif
> --
> 2.7.4
>
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK
- [Qemu-devel] [PATCH v2 0/8] Make the pm_smbus code more correct, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 02/10] i2c:pm_smbus: Fix the semantics of block I2C transfers, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 04/10] i2c:pm_smbus: Add block transfer capability, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 01/10] i2c:pm_smbus: Clean up some style issues, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 08/10] i2c:pm_smbus: Add the ability to force block transfer enable, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 09/10] i2c: Add an SMBus vmstate structure, minyard, 2018/08/20
- Re: [Qemu-devel] [PATCH v2 09/10] i2c: Add an SMBus vmstate structure,
Dr. David Alan Gilbert <=
- [Qemu-devel] [PATCH v2 05/10] i2c:pm_smbus: Fix state transfer, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 10/10] i2c: Add vmstate handling to the smbus eeprom, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 03/10] i2c:pm_smbus: Make the I2C block read command read-only, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 06/10] i2c:pm_smbus: Add interrupt handling, minyard, 2018/08/20
- [Qemu-devel] [PATCH v2 07/10] Don't delay host status register busy bit when interrupts are enabled, minyard, 2018/08/20