qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@intel.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Junjie Mao" <junjie.mao@hotmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Daniel P . Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org,
	Zhao Liu <zhao1.liu@intel.com>
Subject: [PATCH v2 00/10] rust: Add HPET timer device
Date: Mon, 10 Feb 2025 11:00:41 +0800	[thread overview]
Message-ID: <20250210030051.2562726-1-zhao1.liu@intel.com> (raw)

Hi folks,

This is Rust HPET normal patch series, and you can find the previous RFC
at [1].

This series is based on Paolo's rust-next branch at the commit
43c0ef3bfb3b ("rust: vmstate: remove redundant link targets") along with
another 2 more seperate patches:

* https://lore.kernel.org/qemu-devel/20241205203721.347233-1-pbonzini@redhat.com/
* https://lore.kernel.org/qemu-devel/20250121140121.84550-1-zhao1.liu@intel.com/

Overall, HPET in Rust maintains the same logic as the original C
version, adhering to the Intel IA PC-HPET spec v1.0a [2]. While keeping
the logic unchanged, it attempts to keep up with the current development
progress of Rust for QEMU, leveraging the latest and ongoing Rust binding
updates as much as possible, such as BqlCell / BqlRefCell, qom & qdev
enhancements, irq binding, and more.

Additionally, it introduces new bindings, including gpio_{in|out},
memattrs, and timer.

Welcome your comments and feedback!


TODOs
=====

* Add more documentations for new bindings and HPET.
* Live migration support for HPET.
* address-spaces binding (for address_space_memory, address_space_stl_le).


Introduction
============

.
│ 
...
└── timer
    ├── hpet
    │   ├── Cargo.toml
    │   ├── meson.build
    │   └── src
    │       ├── fw_cfg.rs
    │       ├── hpet.rs
    │       ├── lib.rs
    ├── Kconfig
    └── meson.build


HPET emulation contains 2 parts:
 * HPET device emulation:
   - hpet.rs:
     It includes basic operations for the HPET timer and HPET state
     (which actually represents the HPET timer block).

     Here, similar to the C implementation, it directly defines the
     registers and bit shifts as const variables, without a complete
     register space structure.

     And, it implements various QEMU qdev/qom required traits for the
     HPETState.

 * Global HPET firmwrie configuration:
   - fw_cfg.rs
     In the C code, there is a variable hpet_fw_cfg (old name: hpet_cfg)
     used to configure the number of HPET timer blocks and the basic
     HPET firmware configuration. It is defined in .c file and is
     referenced as extern in the .h file.

     For the Rust HPET, fw_cfg.rs also implementes hpet_fw_cfg so that
     the .h file can still reference it.


Change Log
==========

Main changes since Patch v1:
 * Reimplement InterruptSource::slice_as_ptr() by dereferring `slice[0]`.
 * Ensure the callback parameter of input GPIO/timer is not none.
 * Use Timer/TimerListGroup in Rust code instead of QEMUTimer/
   QEMUTimerListGroup.
 * Add MS/US/NS wrappers.
 * Enable workspace's lint configurations in hpet's Cargo.toml.
 * Add rust_version in Cargo.toml.
 * Fix complaints from cargo (+nightly) doc/clippy/fmt (v1.84.0).
 * Do `addr & !4` in timer's register read and write.
 * Mask the timer N's register address with 0x1F (timer_and_addr()).
 * Drop HPETClass.
 * Fix a memory leak issue by not destroying the timer instance in
   HPETTimer::del_timer().


[1]: https://lore.kernel.org/qemu-devel/20250125125137.1223277-1-zhao1.liu@intel.com/
[2]: https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/software-developers-hpet-spec-1-0a.pdf

Thanks and Best Rgards,
Zhao
---
Zhao Liu (10):
  i386/fw_cfg: move hpet_cfg definition to hpet.c
  rust/qdev: add the macro to define bit property
  rust/irq: Add a helper to convert [InterruptSource] to pointer
  rust: add bindings for gpio_{in|out} initialization
  rust: add bindings for memattrs
  rust: add bindings for timer
  rust/timer/hpet: define hpet_fw_cfg
  rust/timer/hpet: add basic HPET timer and HPETState
  rust/timer/hpet: add qom and qdev APIs support
  i386: enable rust hpet for pc when rust is enabled

 configs/devices/i386-softmmu/default.mak |   1 +
 hw/i386/fw_cfg.c                         |   6 +-
 hw/i386/pc.c                             |   2 +-
 hw/timer/Kconfig                         |   6 +-
 hw/timer/hpet.c                          |  14 +-
 include/hw/timer/hpet.h                  |   2 +-
 meson.build                              |   7 +
 rust/Cargo.lock                          |   8 +
 rust/Cargo.toml                          |   1 +
 rust/hw/Kconfig                          |   1 +
 rust/hw/meson.build                      |   1 +
 rust/hw/timer/Kconfig                    |   2 +
 rust/hw/timer/hpet/Cargo.toml            |  18 +
 rust/hw/timer/hpet/meson.build           |  18 +
 rust/hw/timer/hpet/src/fw_cfg.rs         |  78 ++
 rust/hw/timer/hpet/src/hpet.rs           | 890 +++++++++++++++++++++++
 rust/hw/timer/hpet/src/lib.rs            |  18 +
 rust/hw/timer/meson.build                |   1 +
 rust/qemu-api/meson.build                |   1 +
 rust/qemu-api/src/irq.rs                 |   5 +
 rust/qemu-api/src/lib.rs                 |   1 +
 rust/qemu-api/src/memory.rs              |  16 +-
 rust/qemu-api/src/qdev.rs                |  59 +-
 rust/qemu-api/src/timer.rs               |  98 +++
 rust/qemu-api/src/zeroable.rs            |   7 +-
 rust/wrapper.h                           |   3 +
 tests/qtest/meson.build                  |   3 +-
 27 files changed, 1245 insertions(+), 22 deletions(-)
 create mode 100644 rust/hw/timer/Kconfig
 create mode 100644 rust/hw/timer/hpet/Cargo.toml
 create mode 100644 rust/hw/timer/hpet/meson.build
 create mode 100644 rust/hw/timer/hpet/src/fw_cfg.rs
 create mode 100644 rust/hw/timer/hpet/src/hpet.rs
 create mode 100644 rust/hw/timer/hpet/src/lib.rs
 create mode 100644 rust/hw/timer/meson.build
 create mode 100644 rust/qemu-api/src/timer.rs

-- 
2.34.1



             reply	other threads:[~2025-02-10  2:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-10  3:00 Zhao Liu [this message]
2025-02-10  3:00 ` [PATCH v2 01/10] i386/fw_cfg: move hpet_cfg definition to hpet.c Zhao Liu
2025-02-13 11:25   ` Paolo Bonzini
2025-02-16 11:47     ` Zhao Liu
2025-02-10  3:00 ` [PATCH v2 02/10] rust/qdev: add the macro to define bit property Zhao Liu
2025-02-10  3:00 ` [PATCH v2 03/10] rust/irq: Add a helper to convert [InterruptSource] to pointer Zhao Liu
2025-02-10  3:00 ` [PATCH v2 04/10] rust: add bindings for gpio_{in|out} initialization Zhao Liu
2025-02-10  3:00 ` [PATCH v2 05/10] rust: add bindings for memattrs Zhao Liu
2025-02-10 10:03   ` Zhao Liu
2025-02-10  3:00 ` [PATCH v2 06/10] rust: add bindings for timer Zhao Liu
2025-02-10  3:00 ` [PATCH v2 07/10] rust/timer/hpet: define hpet_fw_cfg Zhao Liu
2025-02-10  3:00 ` [PATCH v2 08/10] rust/timer/hpet: add basic HPET timer and HPETState Zhao Liu
2025-02-10  3:00 ` [PATCH v2 09/10] rust/timer/hpet: add qom and qdev APIs support Zhao Liu
2025-02-10  3:00 ` [PATCH v2 10/10] i386: enable rust hpet for pc when rust is enabled Zhao Liu

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=20250210030051.2562726-1-zhao1.liu@intel.com \
    --to=zhao1.liu@intel.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=junjie.mao@hotmail.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=richard.henderson@linaro.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).