fc22d650 | 14-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qdev: wrap Clock and DeviceState with Opaque<>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
7fb4a99d | 14-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qom: wrap Object with Opaque<>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
9c9a6a88 | 14-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: irq: wrap IRQState with Opaque<>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
a32b2396 | 14-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: timer: wrap QEMUTimer with Opaque<> and express pinning requirements
Timers must be pinned in memory, because modify() stores a pointer to them in the TimerList. To express this requirement,
rust: timer: wrap QEMUTimer with Opaque<> and express pinning requirements
Timers must be pinned in memory, because modify() stores a pointer to them in the TimerList. To express this requirement, change init_full() to take a pinned reference. Because the only way to obtain a Timer is through Timer::new(), which is unsafe, modify() can assume that the timer it got was later initialized; and because the initialization takes a Pin<&mut Timer> modify() can assume that the timer is pinned. In the future the pinning requirement will be expressed through the pin_init crate instead.
Note that Timer is a bit different from other users of Opaque, in that it is created in Rust code rather than C code. This is why it has to use the unsafe constructors provided by Opaque; and in fact Timer::new() is also unsafe, because it leaves it to the caller to invoke init_full() before modify(). Without a call to init_full(), modify() will cause a NULL pointer dereference.
An alternative could be to combine new() + init_full() by returning a pinned box; however, using a reference makes it easier to express the requirement that the opaque outlives the timer.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
d7f5ae8b | 25-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: add std::pin::Pin as transparent wrapper
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
f07a5674 | 14-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qemu_api_macros: add Wrapper derive macro
Add a derive macro that makes it easy to peel off all the layers of specialness (UnsafeCell, MaybeUninit, etc.) and just get a pointer to the wrapped
rust: qemu_api_macros: add Wrapper derive macro
Add a derive macro that makes it easy to peel off all the layers of specialness (UnsafeCell, MaybeUninit, etc.) and just get a pointer to the wrapped type; and likewise add them back starting from a *mut.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
0b9d05e3 | 14-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: cell: add wrapper for FFI types
Inspired by the same-named type in Linux. This type provides the compiler with a correct view of what goes on with FFI types. In addition, it separates the gl
rust: cell: add wrapper for FFI types
Inspired by the same-named type in Linux. This type provides the compiler with a correct view of what goes on with FFI types. In addition, it separates the glue code from the bindgen-generated code, allowing traits such as Send, Sync or Zeroable to be specified independently for C and Rust structs.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
d556226d | 13-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qom: get rid of ClassInitImpl
Complete the conversion from the ClassInitImpl trait to class_init() methods. This will provide more freedom to split the qemu_api crate in separate parts.
Revie
rust: qom: get rid of ClassInitImpl
Complete the conversion from the ClassInitImpl trait to class_init() methods. This will provide more freedom to split the qemu_api crate in separate parts.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
4551f342 | 12-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qom: add ObjectImpl::CLASS_INIT
As shown in the PL011 device, the orphan rules required a manual implementation of ClassInitImpl for anything not in the qemu_api crate; this gets in the way of
rust: qom: add ObjectImpl::CLASS_INIT
As shown in the PL011 device, the orphan rules required a manual implementation of ClassInitImpl for anything not in the qemu_api crate; this gets in the way of moving system emulation-specific code (including DeviceClass, which as a blanket ClassInitImpl<DeviceClass> implementation) into its own crate.
Make ClassInitImpl optional, at the cost of having to specify the CLASS_INIT member by hand in every implementation of ObjectImpl. The next commits will get rid of it, replacing all the "impl<T> ClassInitImpl<Class> for T" blocks with a generic class_init<T> method on Class.
Right now the definition is always the same, but do not provide a default as that will not be true once ClassInitImpl goes away.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
3212da00 | 12-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: add SysBusDeviceImpl
The only function, right now, is to ensure that anything with a SysBusDeviceClass class is a SysBusDevice.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paol
rust: add SysBusDeviceImpl
The only function, right now, is to ensure that anything with a SysBusDeviceClass class is a SysBusDevice.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
ac5699c5 | 12-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: add IsA bounds to QOM implementation traits
Check that the right bounds are provided to the qom_isa! macro whenever the class is defined to implement a certain class. This removes the need to
rust: add IsA bounds to QOM implementation traits
Check that the right bounds are provided to the qom_isa! macro whenever the class is defined to implement a certain class. This removes the need to add IsA<> bounds together with the *Impl trait bounds.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
c48700e8 | 18-Feb-2025 |
Zhao Liu <zhao1.liu@intel.com> |
rust: prefer importing std::ptr over core::ptr
The std::ptr is same as core::ptr, but std has already been used in many cases and there's no need to choose non-std library.
So, use std::ptr directl
rust: prefer importing std::ptr over core::ptr
The std::ptr is same as core::ptr, but std has already been used in many cases and there's no need to choose non-std library.
So, use std::ptr directly to make the used ptr library as consistent as possible.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250218080835.3341082-1-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
8a420dd1 | 14-Nov-2024 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: add module to convert between success/-errno and io::Result
It is a common convention in QEMU to return a positive value in case of success, and a negated errno value in case of error. Unfort
rust: add module to convert between success/-errno and io::Result
It is a common convention in QEMU to return a positive value in case of success, and a negated errno value in case of error. Unfortunately, using errno portably in Rust is a bit complicated; on Unix the errno values are supported natively by io::Error, but on Windows they are not; so, use the libc crate.
This is a set of utility functions that are used by both chardev and block layer bindings.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
16534af5 | 11-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: fix doctests
Doctests were not being run by CI, and have broken. Fix them.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
ee7d3aec | 30-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: vmstate: remove redundant link targets
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
ebacd14a | 30-Jan-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: qemu_api: add a documentation header for all modules
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
0534248a | 09-Feb-2025 |
Zhao Liu <zhao1.liu@intel.com> |
rust/timer/hpet: define hpet_fw_cfg
Define HPETFwEntry structure with the same memory layout as hpet_fw_entry in C.
Further, define the global hpet_cfg variable in Rust which is the same as the C v
rust/timer/hpet: define hpet_fw_cfg
Define HPETFwEntry structure with the same memory layout as hpet_fw_entry in C.
Further, define the global hpet_cfg variable in Rust which is the same as the C version. This hpet_cfg variable in Rust will replace the C version one and allows both Rust code and C code to access it.
The Rust version of hpet_cfg is self-contained, avoiding unsafe access to C code.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250210030051.2562726-8-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
eadb83f9 | 09-Feb-2025 |
Zhao Liu <zhao1.liu@intel.com> |
rust: add bindings for timer
Add timer bindings to help handle idiomatic Rust callbacks.
Additionally, wrap QEMUClockType in ClockType binding to avoid unsafe calls in device code.
Signed-off-by:
rust: add bindings for timer
Add timer bindings to help handle idiomatic Rust callbacks.
Additionally, wrap QEMUClockType in ClockType binding to avoid unsafe calls in device code.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250210030051.2562726-7-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
d015d4cb | 25-Jan-2025 |
Zhao Liu <zhao1.liu@intel.com> |
rust: add bindings for memattrs
The MemTxAttrs structure contains bitfield members, and bindgen is unable to generate an equivalent macro definition for MEMTXATTRS_UNSPECIFIED.
Therefore, manually
rust: add bindings for memattrs
The MemTxAttrs structure contains bitfield members, and bindgen is unable to generate an equivalent macro definition for MEMTXATTRS_UNSPECIFIED.
Therefore, manually define a global constant variable MEMTXATTRS_UNSPECIFIED to support calls from Rust code.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250125125137.1223277-6-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
9a96d410 | 09-Feb-2025 |
Zhao Liu <zhao1.liu@intel.com> |
rust: add bindings for gpio_{in|out} initialization
Wrap qdev_init_gpio_{in|out} as methods in DeviceMethods. And for qdev_init_gpio_in, based on FnCall, it can support idiomatic Rust callback witho
rust: add bindings for gpio_{in|out} initialization
Wrap qdev_init_gpio_{in|out} as methods in DeviceMethods. And for qdev_init_gpio_in, based on FnCall, it can support idiomatic Rust callback without the need for C style wrapper.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250210030051.2562726-5-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
e6f1195f | 09-Feb-2025 |
Zhao Liu <zhao1.liu@intel.com> |
rust/irq: Add a helper to convert [InterruptSource] to pointer
This is useful when taking an InterruptSource slice and passing it to C function.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Si
rust/irq: Add a helper to convert [InterruptSource] to pointer
This is useful when taking an InterruptSource slice and passing it to C function.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250210030051.2562726-4-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
7f2d4181 | 09-Feb-2025 |
Zhao Liu <zhao1.liu@intel.com> |
rust/qdev: add the macro to define bit property
HPET device (Rust device) needs to define the bit type property.
Add a variant of define_property macro to define bit type property.
Signed-off-by:
rust/qdev: add the macro to define bit property
HPET device (Rust device) needs to define the bit type property.
Add a variant of define_property macro to define bit type property.
Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Link: https://lore.kernel.org/r/20250210030051.2562726-3-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
7630ca2a | 10-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: pl011: convert pl011_create to safe Rust
Not a major change but, as a small but significant step in creating qdev bindings, show how pl011_create can be written without "unsafe" calls (apart f
rust: pl011: convert pl011_create to safe Rust
Not a major change but, as a small but significant step in creating qdev bindings, show how pl011_create can be written without "unsafe" calls (apart from converting pointers to references).
This also provides a starting point for creating Error** bindings.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
a22bd55f | 03-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: chardev, qdev: add bindings to qdev_prop_set_chr
Because the argument to the function is an Owned<Chardev>, this also adds an ObjectType implementation to Chardev.
Reviewed-by: Zhao Liu <zhao
rust: chardev, qdev: add bindings to qdev_prop_set_chr
Because the argument to the function is an Owned<Chardev>, this also adds an ObjectType implementation to Chardev.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
show more ...
|
61faf6ac | 03-Feb-2025 |
Paolo Bonzini <pbonzini@redhat.com> |
rust: irq: define ObjectType for IRQState
This is a small preparation in order to use an Owned<IRQState> for the argument to sysbus_connect_irq.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |