[RFC PREVIEW 0/4] rust: hw: Add the I2C and the first GPIO device

9 views
Skip to first unread message

chenmiao

unread,
Oct 23, 2025, 1:22:19 PMOct 23
to chao...@openatom.club, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com, Chao Liu, Chen Miao
We have implemented I2C and the first GPIO device in Rust for QEMU.
Additionally, in the respective patches, we have shared our insights and
experiences regarding the use of Rust for device modeling within QEMU.

1. The first patch implements the I2CBus and I2CSlave infrastructure, along
with a discussion of the challenges encountered during the implementation.
2. The second patch moves the struct definition of the PCF8574 to the
corresponding header file.
3. The third patch provides a set of necessary helper functions for the PCF8574
GPIO device.
4. The fourth patch implements the PCF8574 GPIO device, along with a discussion
of the issues and considerations addressed during the implementation.

Signed-off-by: Chao Liu <chao...@openatom.club>
Signed-off-by: Chen Miao <chen...@openatom.club>

Chao Liu (1):
rust: hw: add rust bindings/funcs for i2c bus

chenmiao (3):
hw: gpio: Move the pcf8574 struct to header
rust: hw: core: Provide some interfaces for the GPIO device.
rust: hw: gpio: Add the the first gpio device pcf8574

hw/gpio/Kconfig | 5 +
hw/gpio/meson.build | 2 +-
hw/gpio/pcf8574.c | 32 ---
include/hw/gpio/pcf8574.h | 36 +++
rust/Cargo.lock | 21 +-
rust/Cargo.toml | 1 +
rust/hw/Kconfig | 1 +
rust/hw/core/meson.build | 1 +
rust/hw/core/src/i2cbus.rs | 337 +++++++++++++++++++++++++++
rust/hw/core/src/irq.rs | 6 +-
rust/hw/core/src/lib.rs | 3 +
rust/hw/core/src/qdev.rs | 28 ++-
rust/hw/core/wrapper.h | 1 +
rust/hw/gpio/Kconfig | 2 +
rust/hw/gpio/meson.build | 1 +
rust/hw/gpio/pcf8574/Cargo.toml | 31 +++
rust/hw/gpio/pcf8574/build.rs | 1 +
rust/hw/gpio/pcf8574/meson.build | 50 ++++
rust/hw/gpio/pcf8574/src/bindings.rs | 29 +++
rust/hw/gpio/pcf8574/src/device.rs | 180 ++++++++++++++
rust/hw/gpio/pcf8574/src/lib.rs | 4 +
rust/hw/gpio/pcf8574/wrapper.h | 51 ++++
rust/hw/meson.build | 1 +
23 files changed, 786 insertions(+), 38 deletions(-)
create mode 100644 rust/hw/core/src/i2cbus.rs
create mode 100644 rust/hw/gpio/Kconfig
create mode 100644 rust/hw/gpio/meson.build
create mode 100644 rust/hw/gpio/pcf8574/Cargo.toml
create mode 120000 rust/hw/gpio/pcf8574/build.rs
create mode 100644 rust/hw/gpio/pcf8574/meson.build
create mode 100644 rust/hw/gpio/pcf8574/src/bindings.rs
create mode 100644 rust/hw/gpio/pcf8574/src/device.rs
create mode 100644 rust/hw/gpio/pcf8574/src/lib.rs
create mode 100644 rust/hw/gpio/pcf8574/wrapper.h

--
2.43.0

chenmiao

unread,
Oct 23, 2025, 9:41:19 PMOct 23
to chao...@openatom.club, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com, Chao Liu, Chen Miao

Chao Liu

unread,
Oct 23, 2025, 10:34:26 PMOct 23
to chenmiao, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com
On 10/24/2025 9:40 AM, chenmiao wrote:
> We have implemented I2C and the first GPIO device in Rust for QEMU.
> Additionally, in the respective patches, we have shared our insights and
> experiences regarding the use of Rust for device modeling within QEMU.
>
> 1. The first patch implements the I2CBus and I2CSlave infrastructure, along
> with a discussion of the challenges encountered during the implementation.
> 2. The second patch moves the struct definition of the PCF8574 to the
> corresponding header file.
> 3. The third patch provides a set of necessary helper functions for the PCF8574
> GPIO device.
> 4. The fourth patch implements the PCF8574 GPIO device, along with a discussion
> of the issues and considerations addressed during the implementation.
>

We can discuss the Rust development experience and documentation from PATCH v1 here.

Meanwhile, we can supplement the incomplete documentation to have in-depth
discussions with the upstream community on Rust for QEMU's implementation
principles.

The upstream community previously focused on code iteration and lacked capacity
to improve documentation – this is a great chance for us.

Thanks,
Chao

chenmiao

unread,
Oct 24, 2025, 3:51:53 AMOct 24
to chao...@openatom.club, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com, Chao Liu, Chen Miao
We have implemented I2C and the first GPIO device in Rust for QEMU.
Additionally, in the respective patches, we have shared our insights and
experiences regarding the use of Rust for device modeling within QEMU.

1. The first patch implements the BusState for the I2CBus infrastructure.
2. The second patch implements the I2CBus and I2CSlave infrastructure, along
with a discussion of the challenges encountered during the implementation.
3. The third patch moves the struct definition of the PCF8574 to the
corresponding header file.
4. The fourth patch provides a set of necessary helper functions for the PCF8574
GPIO device.
5. The fifth patch implements the PCF8574 GPIO device, along with a discussion
of the issues and considerations addressed during the implementation.

Signed-off-by: Chao Liu <chao...@openatom.club>
Signed-off-by: Chen Miao <chen...@openatom.club>

chenmiao (5):
rust: hw: core: Add the BusState of rust version
rust: hw: core: Add rust bindings/funcs for i2c bus
hw: gpio: Move the pcf8574 struct to header
rust: hw: core: Provide some interfaces for the GPIO device
rust: hw: gpio: Add the the first gpio device pcf8574

hw/gpio/Kconfig | 5 +
hw/gpio/meson.build | 2 +-
hw/gpio/pcf8574.c | 32 ---
include/hw/gpio/pcf8574.h | 36 +++
rust/Cargo.lock | 21 +-
rust/Cargo.toml | 1 +
rust/hw/Kconfig | 1 +
rust/hw/core/meson.build | 2 +
rust/hw/core/src/bus.rs | 47 ++++
rust/hw/core/src/i2cbus.rs | 313 +++++++++++++++++++++++++++
rust/hw/core/src/irq.rs | 6 +-
rust/hw/core/src/lib.rs | 6 +
rust/hw/core/src/qdev.rs | 12 +-
rust/hw/core/wrapper.h | 1 +
rust/hw/gpio/Kconfig | 2 +
rust/hw/gpio/meson.build | 1 +
rust/hw/gpio/pcf8574/Cargo.toml | 31 +++
rust/hw/gpio/pcf8574/build.rs | 1 +
rust/hw/gpio/pcf8574/meson.build | 50 +++++
rust/hw/gpio/pcf8574/src/bindings.rs | 29 +++
rust/hw/gpio/pcf8574/src/device.rs | 174 +++++++++++++++
rust/hw/gpio/pcf8574/src/lib.rs | 4 +
rust/hw/gpio/pcf8574/wrapper.h | 51 +++++
rust/hw/meson.build | 1 +
24 files changed, 791 insertions(+), 38 deletions(-)
create mode 100644 rust/hw/core/src/bus.rs
create mode 100644 rust/hw/core/src/i2cbus.rs
create mode 100644 rust/hw/gpio/Kconfig
create mode 100644 rust/hw/gpio/meson.build
create mode 100644 rust/hw/gpio/pcf8574/Cargo.toml
create mode 120000 rust/hw/gpio/pcf8574/build.rs
create mode 100644 rust/hw/gpio/pcf8574/meson.build
create mode 100644 rust/hw/gpio/pcf8574/src/bindings.rs
create mode 100644 rust/hw/gpio/pcf8574/src/device.rs
create mode 100644 rust/hw/gpio/pcf8574/src/lib.rs
create mode 100644 rust/hw/gpio/pcf8574/wrapper.h

--
2.43.0

chenmiao

unread,
Oct 24, 2025, 4:53:49 AMOct 24
to chao...@openatom.club, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com, Chao Liu, Chen Miao
We have implemented I2C and the first GPIO device in Rust for QEMU.
Additionally, in the respective patches, we have shared our insights and
experiences regarding the use of Rust for device modeling within QEMU.

1. The first patch implements the BusState for the I2CBus infrastructure.
2. The second patch implements the I2CBus and I2CSlave infrastructure, along
with a discussion of the challenges encountered during the implementation.
3. The third patch moves the struct definition of the PCF8574 to the
corresponding header file.
4. The fourth patch provides a set of necessary helper functions for the PCF8574
GPIO device.
5. The fifth patch implements the PCF8574 GPIO device, along with a discussion
of the issues and considerations addressed during the implementation.

Regarding this series of patches, we have found that Rust for QEMU is indeed
still not mature enough and requires continuous iteration. Additionally, the
lack of basic documentation also needs to be addressed. In this regard, I hope
our team(HUST OpenAtom Open Source Club) can contribute to the documentation
efforts for Rust for QEMU.

Dongliang Mu

unread,
Oct 24, 2025, 8:19:56 AMOct 24
to chenmiao, chao...@openatom.club, luo...@openatom.club, dz...@openatom.club, plu...@openatom.club, hust-os-ker...@googlegroups.com

On 10/24/25 3:51 PM, chenmiao wrote:
> We have implemented I2C and the first GPIO device in Rust for QEMU.
> Additionally, in the respective patches, we have shared our insights and
> experiences regarding the use of Rust for device modeling within QEMU.
>
> 1. The first patch implements the BusState for the I2CBus infrastructure.
> 2. The second patch implements the I2CBus and I2CSlave infrastructure, along
> with a discussion of the challenges encountered during the implementation.
> 3. The third patch moves the struct definition of the PCF8574 to the
> corresponding header file.
> 4. The fourth patch provides a set of necessary helper functions for the PCF8574
> GPIO device.
> 5. The fifth patch implements the PCF8574 GPIO device, along with a discussion
> of the issues and considerations addressed during the implementation.

A small advice: we can add a Link tag to refer to.

Link: https://groups.google.com/g/hust-os-kernel-patches/c/z7vHWg3xvDc

chenmiao

unread,
Oct 25, 2025, 8:39:04 AMOct 25
to pbon...@redhat.com, manos.pit...@linaro.org, richard....@linaro.org, phi...@linaro.org, qemu...@nongnu.org, qemu-...@nongnu.org, hust-os-ker...@googlegroups.com, Chao Liu, Chen Miao
We have implemented I2C and the first GPIO device in Rust for QEMU.
Additionally, in the respective patches, we have shared our insights and
experiences regarding the use of Rust for device modeling within QEMU.

1. The first patch implements the BusState for the I2CBus infrastructure.
2. The second patch implements the I2CBus and I2CSlave infrastructure, along
with a discussion of the challenges encountered during the implementation.
3. The third patch moves the struct definition of the PCF8574 to the
corresponding header file.
4. The fourth patch provides a set of necessary helper functions for the PCF8574
GPIO device.
5. The fifth patch implements the PCF8574 GPIO device, along with a discussion
of the issues and considerations addressed during the implementation.

Regarding this series of patches, we have found that Rust for QEMU is indeed
still not mature enough and requires continuous iteration. Additionally, the
lack of basic documentation also needs to be addressed. In this regard, I hope
our team(HUST OpenAtom Open Source Club) can contribute to the documentation
efforts for Rust for QEMU.

Link: https://groups.google.com/g/hust-os-kernel-patches/c/z7vHWg3xvDc

Signed-off-by: Chao Liu <chao...@openatom.club>
Signed-off-by: Chen Miao <chen...@openatom.club>

chenmiao (5):
rust: hw: core: Add the BusState of rust version
rust: hw: core: Add rust bindings/funcs for i2c bus
hw: gpio: Move the pcf8574 struct to header
rust: hw: core: Provide some interfaces for the GPIO device
rust: hw: gpio: Add the the first gpio device pcf8574

hw/gpio/Kconfig | 5 +
hw/gpio/meson.build | 2 +-
hw/gpio/pcf8574.c | 32 ---
include/hw/gpio/pcf8574.h | 36 +++
rust/Cargo.lock | 21 +-
rust/Cargo.toml | 1 +
rust/hw/Kconfig | 1 +
rust/hw/core/meson.build | 2 +
rust/hw/core/src/bus.rs | 51 +++++
rust/hw/core/src/i2cbus.rs | 313 +++++++++++++++++++++++++++
rust/hw/core/src/irq.rs | 6 +-
rust/hw/core/src/lib.rs | 6 +
rust/hw/core/src/qdev.rs | 12 +-
rust/hw/core/wrapper.h | 1 +
rust/hw/gpio/Kconfig | 2 +
rust/hw/gpio/meson.build | 1 +
rust/hw/gpio/pcf8574/Cargo.toml | 31 +++
rust/hw/gpio/pcf8574/build.rs | 1 +
rust/hw/gpio/pcf8574/meson.build | 50 +++++
rust/hw/gpio/pcf8574/src/bindings.rs | 29 +++
rust/hw/gpio/pcf8574/src/device.rs | 174 +++++++++++++++
rust/hw/gpio/pcf8574/src/lib.rs | 4 +
rust/hw/gpio/pcf8574/wrapper.h | 51 +++++
rust/hw/meson.build | 1 +
24 files changed, 795 insertions(+), 38 deletions(-)
create mode 100644 rust/hw/core/src/bus.rs
create mode 100644 rust/hw/core/src/i2cbus.rs
create mode 100644 rust/hw/gpio/Kconfig
create mode 100644 rust/hw/gpio/meson.build
create mode 100644 rust/hw/gpio/pcf8574/Cargo.toml
create mode 120000 rust/hw/gpio/pcf8574/build.rs
create mode 100644 rust/hw/gpio/pcf8574/meson.build
create mode 100644 rust/hw/gpio/pcf8574/src/bindings.rs
create mode 100644 rust/hw/gpio/pcf8574/src/device.rs
create mode 100644 rust/hw/gpio/pcf8574/src/lib.rs
create mode 100644 rust/hw/gpio/pcf8574/wrapper.h

--
2.43.0
Reply all
Reply to author
Forward
0 new messages