On Fri, 29 Aug 2025 at 09:08, Philippe Mathieu-Daudé <[email protected]> wrote:
>
> Hi Titus,
>
> On 8/7/21 19:25, Titus Rwantare wrote:
> > QEMU has support for SMBus devices, and PMBus is a more specific
> > implementation of SMBus. The additions made in this commit makes it easier 
> > to
> > add new PMBus devices to QEMU.
> >
> > https://pmbus.org/specification-archives/
> >
> > Reviewed-by: Joel Stanley <[email protected]>
> > Reviewed-by: Hao Wu <[email protected]>
> > Signed-off-by: Titus Rwantare <[email protected]>
> > ---
> >   include/hw/i2c/pmbus_device.h |  517 +++++++++++
> >   hw/i2c/pmbus_device.c         | 1612 +++++++++++++++++++++++++++++++++
> >   hw/arm/Kconfig                |    1 +
> >   hw/i2c/Kconfig                |    4 +
> >   hw/i2c/meson.build            |    1 +
> >   5 files changed, 2135 insertions(+)
> >   create mode 100644 include/hw/i2c/pmbus_device.h
> >   create mode 100644 hw/i2c/pmbus_device.c
>
>
> > +static uint8_t pmbus_receive_byte(SMBusDevice *smd)
> > +{
> > +    PMBusDevice *pmdev = PMBUS_DEVICE(smd);
> > +    PMBusDeviceClass *pmdc = PMBUS_DEVICE_GET_CLASS(pmdev);

> > +        qemu_log_mask(LOG_GUEST_ERROR,
> > +                      "%s: reading from write only register 0x%02x\n",
> > +                      __func__, pmdev->code);
> > +        break;
> > +
> > +passthough:
> > +    default:
> > +        /* Pass through read request if not handled */
> > +        if (pmdc->receive_byte) {
> > +            ret = pmdc->receive_byte(pmdev);
>
> This returned value ...
>
> > +        }
> > +        break;
> > +    }
> > +
> > +    if (pmdev->out_buf_len != 0) {
> > +        ret = pmbus_out_buf_pop(pmdev);
>
> ... is overwritten here, is that expected?
>
> > +        return ret;
> > +    }

Yes, this is expected but it could be done more cleanly. I can only
return a byte out of pmbus_receive_byte() and this is sometimes data,
sometimes -1 for an error. At the time, I decided the valid data in
out_buf should take precedence over returns from the device
receive_byte.
-Titus

Reply via email to