From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: minyard@acm.org, qemu-devel@nongnu.org,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Corey Minyard <cminyard@mvista.com>
Subject: Re: [Qemu-devel] [PATCH v3 02/16] i2c: have I2C receive operation return uint8_t
Date: Mon, 26 Nov 2018 21:23:35 +0100 [thread overview]
Message-ID: <c982a937-7c5c-9dad-1940-f839349e4220@redhat.com> (raw)
In-Reply-To: <20181126200435.23408-3-minyard@acm.org>
Hi Corey,
On 26/11/18 21:04, minyard@acm.org wrote:
> From: Corey Minyard <cminyard@mvista.com>
>
> It is never supposed to fail and cannot return an error, so just
> have it return the proper type. Have it return 0xff on nothing
> available, since that's what would happen on a real bus.
>
> Signed-off-by: Corey Minyard <cminyard@mvista.com>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> hw/arm/pxa2xx.c | 2 +-
> hw/arm/tosa.c | 4 ++--
> hw/arm/z2.c | 2 +-
> hw/audio/wm8750.c | 2 +-
> hw/display/sii9022.c | 2 +-
> hw/display/ssd0303.c | 4 ++--
> hw/gpio/max7310.c | 2 +-
> hw/i2c/core.c | 32 +++++++++++++-------------------
> hw/i2c/i2c-ddc.c | 2 +-
> hw/i2c/smbus_slave.c | 4 ++--
> hw/input/lm832x.c | 2 +-
> hw/misc/pca9552.c | 2 +-
> hw/misc/tmp105.c | 2 +-
> hw/misc/tmp421.c | 2 +-
> hw/nvram/eeprom_at24c.c | 4 ++--
> hw/timer/ds1338.c | 2 +-
> hw/timer/m41t80.c | 2 +-
> hw/timer/twl92230.c | 2 +-
> include/hw/i2c/i2c.h | 7 +++----
> 19 files changed, 37 insertions(+), 44 deletions(-)
>
> diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
> index f598a1c053..3d7c88910e 100644
> --- a/hw/arm/pxa2xx.c
> +++ b/hw/arm/pxa2xx.c
> @@ -1286,7 +1286,7 @@ static int pxa2xx_i2c_event(I2CSlave *i2c, enum i2c_event event)
> return 0;
> }
>
> -static int pxa2xx_i2c_rx(I2CSlave *i2c)
> +static uint8_t pxa2xx_i2c_rx(I2CSlave *i2c)
> {
> PXA2xxI2CSlaveState *slave = PXA2XX_I2C_SLAVE(i2c);
> PXA2xxI2CState *s = slave->host;
> diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
> index 7a925fa5e6..eef9d427e7 100644
> --- a/hw/arm/tosa.c
> +++ b/hw/arm/tosa.c
> @@ -197,10 +197,10 @@ static int tosa_dac_event(I2CSlave *i2c, enum i2c_event event)
> return 0;
> }
>
> -static int tosa_dac_recv(I2CSlave *s)
> +static uint8_t tosa_dac_recv(I2CSlave *s)
> {
> printf("%s: recv not supported!!!\n", __func__);
> - return -1;
> + return 0xff;
> }
>
> static void tosa_tg_init(PXA2xxState *cpu)
> diff --git a/hw/arm/z2.c b/hw/arm/z2.c
> index 697a822f1e..6f18d924df 100644
> --- a/hw/arm/z2.c
> +++ b/hw/arm/z2.c
> @@ -243,7 +243,7 @@ static int aer915_event(I2CSlave *i2c, enum i2c_event event)
> return 0;
> }
>
> -static int aer915_recv(I2CSlave *slave)
> +static uint8_t aer915_recv(I2CSlave *slave)
> {
> AER915State *s = AER915(slave);
> int retval = 0x00;
> diff --git a/hw/audio/wm8750.c b/hw/audio/wm8750.c
> index f4aa838f62..169b006ade 100644
> --- a/hw/audio/wm8750.c
> +++ b/hw/audio/wm8750.c
> @@ -561,7 +561,7 @@ static int wm8750_tx(I2CSlave *i2c, uint8_t data)
> return 0;
> }
>
> -static int wm8750_rx(I2CSlave *i2c)
> +static uint8_t wm8750_rx(I2CSlave *i2c)
> {
> return 0x00;
> }
> diff --git a/hw/display/sii9022.c b/hw/display/sii9022.c
> index eaf11a6e7b..9994385c35 100644
> --- a/hw/display/sii9022.c
> +++ b/hw/display/sii9022.c
> @@ -79,7 +79,7 @@ static int sii9022_event(I2CSlave *i2c, enum i2c_event event)
> return 0;
> }
>
> -static int sii9022_rx(I2CSlave *i2c)
> +static uint8_t sii9022_rx(I2CSlave *i2c)
> {
> sii9022_state *s = SII9022(i2c);
> uint8_t res = 0x00;
> diff --git a/hw/display/ssd0303.c b/hw/display/ssd0303.c
> index eb90ba26be..8edf34986c 100644
> --- a/hw/display/ssd0303.c
> +++ b/hw/display/ssd0303.c
> @@ -62,10 +62,10 @@ typedef struct {
> uint8_t framebuffer[132*8];
> } ssd0303_state;
>
> -static int ssd0303_recv(I2CSlave *i2c)
> +static uint8_t ssd0303_recv(I2CSlave *i2c)
> {
> BADF("Reads not implemented\n");
> - return -1;
> + return 0xff;
> }
>
> static int ssd0303_send(I2CSlave *i2c, uint8_t data)
> diff --git a/hw/gpio/max7310.c b/hw/gpio/max7310.c
> index a560e3afd2..f35a930276 100644
> --- a/hw/gpio/max7310.c
> +++ b/hw/gpio/max7310.c
> @@ -39,7 +39,7 @@ static void max7310_reset(DeviceState *dev)
> s->command = 0x00;
> }
>
> -static int max7310_rx(I2CSlave *i2c)
> +static uint8_t max7310_rx(I2CSlave *i2c)
> {
> MAX7310State *s = MAX7310(i2c);
>
> diff --git a/hw/i2c/core.c b/hw/i2c/core.c
> index b54725985a..15237ad073 100644
> --- a/hw/i2c/core.c
> +++ b/hw/i2c/core.c
> @@ -191,23 +191,17 @@ int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send)
i2c_send_recv() could benefit the same improvement.
> }
> return ret ? -1 : 0;
> } else {
> - if ((QLIST_EMPTY(&bus->current_devs)) || (bus->broadcast)) {
> - return -1;
> - }
> -
> - sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt);
> - if (sc->recv) {
> - s = QLIST_FIRST(&bus->current_devs)->elt;
> - ret = sc->recv(s);
> - trace_i2c_recv(s->address, ret);
> - if (ret < 0) {
> - return ret;
> - } else {
> - *data = ret;
> - return 0;
> + ret = 0xff;
> + if (!QLIST_EMPTY(&bus->current_devs) && !bus->broadcast) {
> + sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt);
> + if (sc->recv) {
> + s = QLIST_FIRST(&bus->current_devs)->elt;
> + ret = sc->recv(s);
> + trace_i2c_recv(s->address, ret);
> }
> }
> - return -1;
> + *data = ret;
> + return 0;
> }
> }
>
> @@ -216,12 +210,12 @@ int i2c_send(I2CBus *bus, uint8_t data)
> return i2c_send_recv(bus, &data, true);
> }
>
> -int i2c_recv(I2CBus *bus)
> +uint8_t i2c_recv(I2CBus *bus)
> {
> - uint8_t data;
> - int ret = i2c_send_recv(bus, &data, false);
> + uint8_t data = 0xff;
>
> - return ret < 0 ? ret : data;
> + i2c_send_recv(bus, &data, false);
> + return data;
> }
>
> void i2c_nack(I2CBus *bus)
> diff --git a/hw/i2c/i2c-ddc.c b/hw/i2c/i2c-ddc.c
> index be34fe072c..95325358db 100644
> --- a/hw/i2c/i2c-ddc.c
> +++ b/hw/i2c/i2c-ddc.c
> @@ -51,7 +51,7 @@ static int i2c_ddc_event(I2CSlave *i2c, enum i2c_event event)
> return 0;
> }
>
> -static int i2c_ddc_rx(I2CSlave *i2c)
> +static uint8_t i2c_ddc_rx(I2CSlave *i2c)
> {
> I2CDDCState *s = I2CDDC(i2c);
>
> diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c
> index 1e734752d7..549e7ae933 100644
> --- a/hw/i2c/smbus_slave.c
> +++ b/hw/i2c/smbus_slave.c
> @@ -156,11 +156,11 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event)
> return 0;
> }
>
> -static int smbus_i2c_recv(I2CSlave *s)
> +static uint8_t smbus_i2c_recv(I2CSlave *s)
> {
> SMBusDevice *dev = SMBUS_DEVICE(s);
> SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
> - int ret;
> + uint8_t ret;
>
> switch (dev->mode) {
> case SMBUS_RECV_BYTE:
> diff --git a/hw/input/lm832x.c b/hw/input/lm832x.c
> index 74da30d9ca..9ae037953d 100644
> --- a/hw/input/lm832x.c
> +++ b/hw/input/lm832x.c
> @@ -401,7 +401,7 @@ static int lm_i2c_event(I2CSlave *i2c, enum i2c_event event)
> return 0;
> }
>
> -static int lm_i2c_rx(I2CSlave *i2c)
> +static uint8_t lm_i2c_rx(I2CSlave *i2c)
> {
> LM823KbdState *s = LM8323(i2c);
>
> diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c
> index 9775d5274a..7325d3f287 100644
> --- a/hw/misc/pca9552.c
> +++ b/hw/misc/pca9552.c
> @@ -115,7 +115,7 @@ static void pca9552_autoinc(PCA9552State *s)
> }
> }
>
> -static int pca9552_recv(I2CSlave *i2c)
> +static uint8_t pca9552_recv(I2CSlave *i2c)
> {
> PCA9552State *s = PCA9552(i2c);
> uint8_t ret;
> diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c
> index 0918f3a6ea..a4cae665b7 100644
> --- a/hw/misc/tmp105.c
> +++ b/hw/misc/tmp105.c
> @@ -147,7 +147,7 @@ static void tmp105_write(TMP105State *s)
> }
> }
>
> -static int tmp105_rx(I2CSlave *i2c)
> +static uint8_t tmp105_rx(I2CSlave *i2c)
> {
> TMP105State *s = TMP105(i2c);
>
> diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
> index c234044305..a75eb994a8 100644
> --- a/hw/misc/tmp421.c
> +++ b/hw/misc/tmp421.c
> @@ -249,7 +249,7 @@ static void tmp421_write(TMP421State *s)
> }
> }
>
> -static int tmp421_rx(I2CSlave *i2c)
> +static uint8_t tmp421_rx(I2CSlave *i2c)
> {
> TMP421State *s = TMP421(i2c);
>
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index 27cd01e615..d1456dafbd 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -74,10 +74,10 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
> }
>
> static
> -int at24c_eeprom_recv(I2CSlave *s)
> +uint8_t at24c_eeprom_recv(I2CSlave *s)
> {
> EEPROMState *ee = AT24C_EE(s);
> - int ret;
> + uint8_t ret;
>
> ret = ee->mem[ee->cur];
>
> diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c
> index 3849b74a68..03da75486b 100644
> --- a/hw/timer/ds1338.c
> +++ b/hw/timer/ds1338.c
> @@ -117,7 +117,7 @@ static int ds1338_event(I2CSlave *i2c, enum i2c_event event)
> return 0;
> }
>
> -static int ds1338_recv(I2CSlave *i2c)
> +static uint8_t ds1338_recv(I2CSlave *i2c)
> {
> DS1338State *s = DS1338(i2c);
> uint8_t res;
> diff --git a/hw/timer/m41t80.c b/hw/timer/m41t80.c
> index 734d7d95fc..c45b9297d8 100644
> --- a/hw/timer/m41t80.c
> +++ b/hw/timer/m41t80.c
> @@ -40,7 +40,7 @@ static int m41t80_send(I2CSlave *i2c, uint8_t data)
> return 0;
> }
>
> -static int m41t80_recv(I2CSlave *i2c)
> +static uint8_t m41t80_recv(I2CSlave *i2c)
> {
> M41t80State *s = M41T80(i2c);
> struct tm now;
> diff --git a/hw/timer/twl92230.c b/hw/timer/twl92230.c
> index 3b43b46199..659b216dca 100644
> --- a/hw/timer/twl92230.c
> +++ b/hw/timer/twl92230.c
> @@ -737,7 +737,7 @@ static int menelaus_tx(I2CSlave *i2c, uint8_t data)
> return 0;
> }
>
> -static int menelaus_rx(I2CSlave *i2c)
> +static uint8_t menelaus_rx(I2CSlave *i2c)
> {
> MenelausState *s = TWL92230(i2c);
>
> diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h
> index 5dc166158b..75c5bd638b 100644
> --- a/include/hw/i2c/i2c.h
> +++ b/include/hw/i2c/i2c.h
> @@ -33,10 +33,9 @@ typedef struct I2CSlaveClass {
>
> /*
> * Slave to master. This cannot fail, the device should always
> - * return something here. Negative values probably result in 0xff
> - * and a possible log from the driver, and shouldn't be used.
> + * return something here.
Maybe use simple comment as "Master receives the data sent by the Slave"
> */
> - int (*recv)(I2CSlave *s);
> + uint8_t (*recv)(I2CSlave *s);
>
> /*
> * Notify the slave of a bus state change. For start event,
> @@ -78,7 +77,7 @@ void i2c_end_transfer(I2CBus *bus);
> void i2c_nack(I2CBus *bus);
> int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send);
> int i2c_send(I2CBus *bus, uint8_t data);
> -int i2c_recv(I2CBus *bus);
> +uint8_t i2c_recv(I2CBus *bus);
>
> DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr);
>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
next prev parent reply other threads:[~2018-11-26 20:23 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-26 20:04 [Qemu-devel] [PATCH v3 00/16] Fix/add vmstate handling in some I2C code minyard
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 01/16] i2c: Split smbus into parts minyard
2018-11-26 20:23 ` Philippe Mathieu-Daudé
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 02/16] i2c: have I2C receive operation return uint8_t minyard
2018-11-26 20:23 ` Philippe Mathieu-Daudé [this message]
2018-11-27 0:14 ` Corey Minyard
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 03/16] arm:i2c: Don't mask return from i2c_recv() minyard
2018-11-26 20:29 ` Philippe Mathieu-Daudé
2018-11-30 17:26 ` Peter Maydell
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 04/16] i2c: Don't check return value " minyard
2018-11-30 17:25 ` Peter Maydell
2018-11-30 18:53 ` Corey Minyard
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 05/16] i2c: Simplify and correct the SMBus state machine minyard
2018-11-30 18:13 ` Peter Maydell
2018-11-30 21:03 ` Corey Minyard
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 06/16] i2c: Add a length check to the SMBus write handling minyard
2018-11-26 20:33 ` Philippe Mathieu-Daudé
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 07/16] i2c:pm_smbus: Fix pm_smbus handling of I2C block read minyard
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 08/16] boards.h: Ignore migration for SMBus devices on older machines minyard
2018-11-29 12:20 ` Dr. David Alan Gilbert
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 09/16] migration: Add a VMSTATE_BOOL_TEST() macro minyard
2018-11-29 12:22 ` Dr. David Alan Gilbert
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 10/16] i2c:pm_smbus: Fix state transfer minyard
2018-11-29 12:28 ` Dr. David Alan Gilbert
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 11/16] i2c:smbus_slave: Add an SMBus vmstate structure minyard
2018-11-29 13:09 ` Dr. David Alan Gilbert
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 12/16] i2c:smbus_eeprom: Add normal type name and cast to smbus_eeprom.c minyard
2018-11-26 20:35 ` Philippe Mathieu-Daudé
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 13/16] i2c:smbus_eeprom: Add a size constant for the smbus_eeprom size minyard
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 14/16] i2c:smbus_eeprom: Add vmstate handling to the smbus eeprom minyard
2018-11-29 13:29 ` Dr. David Alan Gilbert
2018-12-19 18:52 ` Corey Minyard
2019-01-03 10:44 ` Dr. David Alan Gilbert
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 15/16] hw/i2c/smbus_eeprom: Create at most SMBUS_EEPROM_MAX EEPROMs on a SMBus minyard
2018-11-30 17:39 ` Peter Maydell
2018-11-30 20:47 ` Corey Minyard
2018-12-01 11:57 ` Peter Maydell
2018-12-01 17:43 ` Philippe Mathieu-Daudé
2018-12-03 21:19 ` Corey Minyard
2018-11-26 20:04 ` [Qemu-devel] [PATCH v3 16/16] i2c:smbus_eeprom: Add a reset function to smbus_eeprom minyard
2018-11-26 20:42 ` Philippe Mathieu-Daudé
2018-11-26 22:41 ` Corey Minyard
2018-11-26 23:01 ` Philippe Mathieu-Daudé
2018-11-26 23:58 ` Corey Minyard
2018-11-27 10:54 ` Philippe Mathieu-Daudé
2018-11-27 12:58 ` Corey Minyard
2018-11-27 13:27 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c982a937-7c5c-9dad-1940-f839349e4220@redhat.com \
--to=philmd@redhat.com \
--cc=cminyard@mvista.com \
--cc=dgilbert@redhat.com \
--cc=minyard@acm.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).