* [RFC PATCH v2 3/5] hw/gpio: Move the pcf8574 struct to header
@ 2025-10-28 10:18 chenmiao
2025-10-28 10:46 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: chenmiao @ 2025-10-28 10:18 UTC (permalink / raw)
To: zhao1.liu, pbonzini, manos.pitsidianakis, richard.henderson,
philmd
Cc: chao.liu, qemu-rust, qemu-devel, hust-os-kernel-patches
To better implement the Rust PCF8574 bindings, move its struct definition to
the header file.
Signed-off-by: chenmiao <chenmiao@openatom.club>
---
hw/gpio/pcf8574.c | 32 --------------------------------
include/hw/gpio/pcf8574.h | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/hw/gpio/pcf8574.c b/hw/gpio/pcf8574.c
index 274b44bb61..670fc006bb 100644
--- a/hw/gpio/pcf8574.c
+++ b/hw/gpio/pcf8574.c
@@ -15,38 +15,6 @@
#include "qemu/module.h"
#include "qom/object.h"
-/*
- * PCF8574 and compatible chips incorporate quasi-bidirectional
- * IO. Electrically it means that device sustain pull-up to line
- * unless IO port is configured as output _and_ driven low.
- *
- * IO access is implemented as simple I2C single-byte read
- * or write operation. So, to configure line to input user write 1
- * to corresponding bit. To configure line to output and drive it low
- * user write 0 to corresponding bit.
- *
- * In essence, user can think of quasi-bidirectional IO as
- * open-drain line, except presence of builtin rising edge acceleration
- * embedded in PCF8574 IC
- *
- * PCF8574 has interrupt request line, which is being pulled down when
- * port line state differs from last read. Port read operation clears
- * state and INT line returns to high state via pullup.
- */
-
-OBJECT_DECLARE_SIMPLE_TYPE(PCF8574State, PCF8574)
-
-#define PORTS_COUNT (8)
-
-struct PCF8574State {
- I2CSlave parent_obj;
- uint8_t lastrq; /* Last requested state. If changed - assert irq */
- uint8_t input; /* external electrical line state */
- uint8_t output; /* Pull-up (1) or drive low (0) on bit */
- qemu_irq handler[PORTS_COUNT];
- qemu_irq intrq; /* External irq request */
-};
-
static void pcf8574_reset(DeviceState *dev)
{
PCF8574State *s = PCF8574(dev);
diff --git a/include/hw/gpio/pcf8574.h b/include/hw/gpio/pcf8574.h
index 3291d7dbbc..fe1ce891b7 100644
--- a/include/hw/gpio/pcf8574.h
+++ b/include/hw/gpio/pcf8574.h
@@ -10,6 +10,42 @@
#ifndef _HW_GPIO_PCF8574
#define _HW_GPIO_PCF8574
+#include "qemu/osdep.h"
+#include "hw/i2c/i2c.h"
+#include "qom/object.h"
+
#define TYPE_PCF8574 "pcf8574"
+/*
+ * PCF8574 and compatible chips incorporate quasi-bidirectional
+ * IO. Electrically it means that device sustain pull-up to line
+ * unless IO port is configured as output _and_ driven low.
+ *
+ * IO access is implemented as simple I2C single-byte read
+ * or write operation. So, to configure line to input user write 1
+ * to corresponding bit. To configure line to output and drive it low
+ * user write 0 to corresponding bit.
+ *
+ * In essence, user can think of quasi-bidirectional IO as
+ * open-drain line, except presence of builtin rising edge acceleration
+ * embedded in PCF8574 IC
+ *
+ * PCF8574 has interrupt request line, which is being pulled down when
+ * port line state differs from last read. Port read operation clears
+ * state and INT line returns to high state via pullup.
+ */
+
+OBJECT_DECLARE_SIMPLE_TYPE(PCF8574State, PCF8574)
+
+#define PORTS_COUNT (8)
+
+struct PCF8574State {
+ I2CSlave parent_obj;
+ uint8_t lastrq; /* Last requested state. If changed - assert irq */
+ uint8_t input; /* external electrical line state */
+ uint8_t output; /* Pull-up (1) or drive low (0) on bit */
+ qemu_irq handler[PORTS_COUNT];
+ qemu_irq intrq; /* External irq request */
+};
+
#endif /* _HW_GPIO_PCF8574 */
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [RFC PATCH v2 3/5] hw/gpio: Move the pcf8574 struct to header
2025-10-28 10:18 [RFC PATCH v2 3/5] hw/gpio: Move the pcf8574 struct to header chenmiao
@ 2025-10-28 10:46 ` Paolo Bonzini
2025-10-28 11:21 ` Chen Miao
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2025-10-28 10:46 UTC (permalink / raw)
To: chenmiao
Cc: zhao1.liu, manos.pitsidianakis, richard.henderson, philmd,
chao.liu, qemu-rust, qemu-devel, hust-os-kernel-patches
On Tue, Oct 28, 2025 at 11:18 AM chenmiao <chenmiao@openatom.club> wrote:
>
> To better implement the Rust PCF8574 bindings, move its struct definition to
> the header file.
This should not be needed, the struct is entirely hidden within the C
implementation and the same should be true for the Rust one.
Paolo
> Signed-off-by: chenmiao <chenmiao@openatom.club>
> ---
> hw/gpio/pcf8574.c | 32 --------------------------------
> include/hw/gpio/pcf8574.h | 36 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 36 insertions(+), 32 deletions(-)
>
> diff --git a/hw/gpio/pcf8574.c b/hw/gpio/pcf8574.c
> index 274b44bb61..670fc006bb 100644
> --- a/hw/gpio/pcf8574.c
> +++ b/hw/gpio/pcf8574.c
> @@ -15,38 +15,6 @@
> #include "qemu/module.h"
> #include "qom/object.h"
>
> -/*
> - * PCF8574 and compatible chips incorporate quasi-bidirectional
> - * IO. Electrically it means that device sustain pull-up to line
> - * unless IO port is configured as output _and_ driven low.
> - *
> - * IO access is implemented as simple I2C single-byte read
> - * or write operation. So, to configure line to input user write 1
> - * to corresponding bit. To configure line to output and drive it low
> - * user write 0 to corresponding bit.
> - *
> - * In essence, user can think of quasi-bidirectional IO as
> - * open-drain line, except presence of builtin rising edge acceleration
> - * embedded in PCF8574 IC
> - *
> - * PCF8574 has interrupt request line, which is being pulled down when
> - * port line state differs from last read. Port read operation clears
> - * state and INT line returns to high state via pullup.
> - */
> -
> -OBJECT_DECLARE_SIMPLE_TYPE(PCF8574State, PCF8574)
> -
> -#define PORTS_COUNT (8)
> -
> -struct PCF8574State {
> - I2CSlave parent_obj;
> - uint8_t lastrq; /* Last requested state. If changed - assert irq */
> - uint8_t input; /* external electrical line state */
> - uint8_t output; /* Pull-up (1) or drive low (0) on bit */
> - qemu_irq handler[PORTS_COUNT];
> - qemu_irq intrq; /* External irq request */
> -};
> -
> static void pcf8574_reset(DeviceState *dev)
> {
> PCF8574State *s = PCF8574(dev);
> diff --git a/include/hw/gpio/pcf8574.h b/include/hw/gpio/pcf8574.h
> index 3291d7dbbc..fe1ce891b7 100644
> --- a/include/hw/gpio/pcf8574.h
> +++ b/include/hw/gpio/pcf8574.h
> @@ -10,6 +10,42 @@
> #ifndef _HW_GPIO_PCF8574
> #define _HW_GPIO_PCF8574
>
> +#include "qemu/osdep.h"
> +#include "hw/i2c/i2c.h"
> +#include "qom/object.h"
> +
> #define TYPE_PCF8574 "pcf8574"
>
> +/*
> + * PCF8574 and compatible chips incorporate quasi-bidirectional
> + * IO. Electrically it means that device sustain pull-up to line
> + * unless IO port is configured as output _and_ driven low.
> + *
> + * IO access is implemented as simple I2C single-byte read
> + * or write operation. So, to configure line to input user write 1
> + * to corresponding bit. To configure line to output and drive it low
> + * user write 0 to corresponding bit.
> + *
> + * In essence, user can think of quasi-bidirectional IO as
> + * open-drain line, except presence of builtin rising edge acceleration
> + * embedded in PCF8574 IC
> + *
> + * PCF8574 has interrupt request line, which is being pulled down when
> + * port line state differs from last read. Port read operation clears
> + * state and INT line returns to high state via pullup.
> + */
> +
> +OBJECT_DECLARE_SIMPLE_TYPE(PCF8574State, PCF8574)
> +
> +#define PORTS_COUNT (8)
> +
> +struct PCF8574State {
> + I2CSlave parent_obj;
> + uint8_t lastrq; /* Last requested state. If changed - assert irq */
> + uint8_t input; /* external electrical line state */
> + uint8_t output; /* Pull-up (1) or drive low (0) on bit */
> + qemu_irq handler[PORTS_COUNT];
> + qemu_irq intrq; /* External irq request */
> +};
> +
> #endif /* _HW_GPIO_PCF8574 */
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [RFC PATCH v2 3/5] hw/gpio: Move the pcf8574 struct to header
2025-10-28 10:46 ` Paolo Bonzini
@ 2025-10-28 11:21 ` Chen Miao
0 siblings, 0 replies; 3+ messages in thread
From: Chen Miao @ 2025-10-28 11:21 UTC (permalink / raw)
To: Paolo Bonzini
Cc: zhao1.liu, manos.pitsidianakis, richard.henderson, philmd,
chao.liu, qemu-rust, qemu-devel, hust-os-kernel-patches
On 10/28/2025 6:46 PM, Paolo Bonzini wrote:
> On Tue, Oct 28, 2025 at 11:18 AM chenmiao <chenmiao@openatom.club> wrote:
>> To better implement the Rust PCF8574 bindings, move its struct definition to
>> the header file.
> This should not be needed, the struct is entirely hidden within the C
> implementation and the same should be true for the Rust one.
>
> Paolo
Ok, delete it in subsequent versions.
Chen Miao
>> Signed-off-by: chenmiao <chenmiao@openatom.club>
>> ---
>> hw/gpio/pcf8574.c | 32 --------------------------------
>> include/hw/gpio/pcf8574.h | 36 ++++++++++++++++++++++++++++++++++++
>> 2 files changed, 36 insertions(+), 32 deletions(-)
>>
>> diff --git a/hw/gpio/pcf8574.c b/hw/gpio/pcf8574.c
>> index 274b44bb61..670fc006bb 100644
>> --- a/hw/gpio/pcf8574.c
>> +++ b/hw/gpio/pcf8574.c
>> @@ -15,38 +15,6 @@
>> #include "qemu/module.h"
>> #include "qom/object.h"
>>
>> -/*
>> - * PCF8574 and compatible chips incorporate quasi-bidirectional
>> - * IO. Electrically it means that device sustain pull-up to line
>> - * unless IO port is configured as output _and_ driven low.
>> - *
>> - * IO access is implemented as simple I2C single-byte read
>> - * or write operation. So, to configure line to input user write 1
>> - * to corresponding bit. To configure line to output and drive it low
>> - * user write 0 to corresponding bit.
>> - *
>> - * In essence, user can think of quasi-bidirectional IO as
>> - * open-drain line, except presence of builtin rising edge acceleration
>> - * embedded in PCF8574 IC
>> - *
>> - * PCF8574 has interrupt request line, which is being pulled down when
>> - * port line state differs from last read. Port read operation clears
>> - * state and INT line returns to high state via pullup.
>> - */
>> -
>> -OBJECT_DECLARE_SIMPLE_TYPE(PCF8574State, PCF8574)
>> -
>> -#define PORTS_COUNT (8)
>> -
>> -struct PCF8574State {
>> - I2CSlave parent_obj;
>> - uint8_t lastrq; /* Last requested state. If changed - assert irq */
>> - uint8_t input; /* external electrical line state */
>> - uint8_t output; /* Pull-up (1) or drive low (0) on bit */
>> - qemu_irq handler[PORTS_COUNT];
>> - qemu_irq intrq; /* External irq request */
>> -};
>> -
>> static void pcf8574_reset(DeviceState *dev)
>> {
>> PCF8574State *s = PCF8574(dev);
>> diff --git a/include/hw/gpio/pcf8574.h b/include/hw/gpio/pcf8574.h
>> index 3291d7dbbc..fe1ce891b7 100644
>> --- a/include/hw/gpio/pcf8574.h
>> +++ b/include/hw/gpio/pcf8574.h
>> @@ -10,6 +10,42 @@
>> #ifndef _HW_GPIO_PCF8574
>> #define _HW_GPIO_PCF8574
>>
>> +#include "qemu/osdep.h"
>> +#include "hw/i2c/i2c.h"
>> +#include "qom/object.h"
>> +
>> #define TYPE_PCF8574 "pcf8574"
>>
>> +/*
>> + * PCF8574 and compatible chips incorporate quasi-bidirectional
>> + * IO. Electrically it means that device sustain pull-up to line
>> + * unless IO port is configured as output _and_ driven low.
>> + *
>> + * IO access is implemented as simple I2C single-byte read
>> + * or write operation. So, to configure line to input user write 1
>> + * to corresponding bit. To configure line to output and drive it low
>> + * user write 0 to corresponding bit.
>> + *
>> + * In essence, user can think of quasi-bidirectional IO as
>> + * open-drain line, except presence of builtin rising edge acceleration
>> + * embedded in PCF8574 IC
>> + *
>> + * PCF8574 has interrupt request line, which is being pulled down when
>> + * port line state differs from last read. Port read operation clears
>> + * state and INT line returns to high state via pullup.
>> + */
>> +
>> +OBJECT_DECLARE_SIMPLE_TYPE(PCF8574State, PCF8574)
>> +
>> +#define PORTS_COUNT (8)
>> +
>> +struct PCF8574State {
>> + I2CSlave parent_obj;
>> + uint8_t lastrq; /* Last requested state. If changed - assert irq */
>> + uint8_t input; /* external electrical line state */
>> + uint8_t output; /* Pull-up (1) or drive low (0) on bit */
>> + qemu_irq handler[PORTS_COUNT];
>> + qemu_irq intrq; /* External irq request */
>> +};
>> +
>> #endif /* _HW_GPIO_PCF8574 */
>> --
>> 2.43.0
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-28 11:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-28 10:18 [RFC PATCH v2 3/5] hw/gpio: Move the pcf8574 struct to header chenmiao
2025-10-28 10:46 ` Paolo Bonzini
2025-10-28 11:21 ` Chen Miao
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).