Browse Source

rust: move hwcore::sysbus to system crate

This inverts the dependency from hwcore to system, replacing it with
a dependency from system to hwcore.  It also matches how hw/core/sysbus.h
is part of the system-sys crate, and hw/core/sysbus.c is part of system_ss
on the C side.

This fixes a linker error in hwcore integration tests on msys2.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pull/319/head
Paolo Bonzini 3 months ago
parent
commit
1713498c0d
  1. 1
      rust/hw/core/Cargo.toml
  2. 2
      rust/hw/core/meson.build
  3. 8
      rust/hw/core/src/irq.rs
  4. 3
      rust/hw/core/src/lib.rs
  5. 5
      rust/hw/core/src/prelude.rs
  6. 4
      rust/hw/core/tests/tests.rs
  7. 2
      rust/meson.build
  8. 1
      rust/system/Cargo.toml
  9. 2
      rust/system/meson.build
  10. 3
      rust/system/src/lib.rs
  11. 5
      rust/system/src/prelude.rs
  12. 7
      rust/system/src/sysbus.rs

1
rust/hw/core/Cargo.toml

@ -21,7 +21,6 @@ bql = { path = "../../bql" }
qom = { path = "../../qom" }
chardev = { path = "../../chardev" }
migration = { path = "../../migration" }
system = { path = "../../system" }
util = { path = "../../util" }
[lints]

2
rust/hw/core/meson.build

@ -3,7 +3,7 @@ _hwcore_rs = static_library(
'src/lib.rs',
override_options: ['rust_std=2021', 'build.rust_std=2021'],
rust_abi: 'rust',
link_with: [_bql_rs, _chardev_rs, _migration_rs, _qom_rs, _system_rs, _util_rs],
link_with: [_bql_rs, _chardev_rs, _migration_rs, _qom_rs, _util_rs],
dependencies: [glib_sys_rs, qemu_macros, common_rs, hwcore_sys_rs],
)

8
rust/hw/core/src/irq.rs

@ -33,10 +33,10 @@ pub struct IRQState(Opaque<bindings::IRQState>);
///
/// Interrupts are implemented as a pointer to the interrupt "sink", which has
/// type [`IRQState`]. A device exposes its source as a QOM link property using
/// a function such as [`crate::sysbus::SysBusDeviceMethods::init_irq`], and
/// a function such as [`crate::DeviceMethods::init_gpio_out`], and
/// initially leaves the pointer to a NULL value, representing an unconnected
/// interrupt. To connect it, whoever creates the device fills the pointer with
/// the sink's `IRQState *`, for example using `sysbus_connect_irq`. Because
/// the sink's `IRQState *`, for example using `qdev_connect_gpio_out`. Because
/// devices are generally shared objects, interrupt sources are an example of
/// the interior mutability pattern.
///
@ -87,11 +87,11 @@ where
}
}
pub(crate) const fn as_ptr(&self) -> *mut *mut bindings::IRQState {
pub const fn as_ptr(&self) -> *mut *mut bindings::IRQState {
self.cell.as_ptr()
}
pub(crate) const fn slice_as_ptr(slice: &[Self]) -> *mut *mut bindings::IRQState {
pub const fn slice_as_ptr(slice: &[Self]) -> *mut *mut bindings::IRQState {
assert!(!slice.is_empty());
slice[0].as_ptr()
}

3
rust/hw/core/src/lib.rs

@ -14,6 +14,3 @@ pub mod prelude;
mod qdev;
pub use qdev::*;
mod sysbus;
pub use sysbus::*;

5
rust/hw/core/src/prelude.rs

@ -9,9 +9,4 @@ pub use crate::qdev::DeviceMethods;
pub use crate::qdev::ResettablePhasesImpl;
pub use crate::qdev::ResetType;
pub use crate::sysbus::SysBusDevice;
pub use crate::sysbus::SysBusDeviceClassExt;
pub use crate::sysbus::SysBusDeviceImpl;
pub use crate::sysbus::SysBusDeviceMethods;
pub use crate::irq::InterruptSource;

4
rust/hw/core/tests/tests.rs

@ -142,7 +142,7 @@ fn test_cast() {
let obj_ref: &Object = p_ref.upcast();
assert_eq!(addr_of!(*obj_ref), p_ptr.cast());
let sbd_ref: Option<&SysBusDevice> = obj_ref.dynamic_cast();
let sbd_ref: Option<&DummyChildState> = obj_ref.dynamic_cast();
assert!(sbd_ref.is_none());
let dev_ref: Option<&DeviceState> = obj_ref.downcast();
@ -150,7 +150,7 @@ fn test_cast() {
// SAFETY: the cast is wrong, but the value is only used for comparison
unsafe {
let sbd_ref: &SysBusDevice = obj_ref.unsafe_cast();
let sbd_ref: &DummyChildState = obj_ref.unsafe_cast();
assert_eq!(addr_of!(*sbd_ref), p_ptr.cast());
}
}

2
rust/meson.build

@ -42,9 +42,9 @@ subdir('util')
subdir('bql')
subdir('migration')
subdir('qom')
subdir('system')
subdir('chardev')
subdir('hw/core')
subdir('system')
subdir('tests')
subdir('trace')
subdir('hw')

1
rust/system/Cargo.toml

@ -16,6 +16,7 @@ rust-version.workspace = true
common = { path = "../common" }
system-sys = { path = "../bindings/system-sys" }
bql = { path = "../bql" }
hwcore = { path = "../hw/core" }
migration = { path = "../migration" }
qom = { path = "../qom" }
util = { path = "../util" }

2
rust/system/meson.build

@ -1,7 +1,7 @@
_system_rs = static_library(
'system',
'src/lib.rs',
link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs],
link_with: [_bql_rs, _hwcore_rs, _migration_rs, _qom_rs, _util_rs],
dependencies: [glib_sys_rs, common_rs, qemu_macros, system_sys_rs],
)

3
rust/system/src/lib.rs

@ -9,3 +9,6 @@ pub use memory::*;
// for prelude-like modules
#[rustfmt::skip]
pub mod prelude;
mod sysbus;
pub use sysbus::*;

5
rust/system/src/prelude.rs

@ -6,3 +6,8 @@ pub use crate::memory::MemoryRegion;
pub use crate::memory::MemoryRegionOps;
pub use crate::memory::MemoryRegionOpsBuilder;
pub use crate::memory::MemTxAttrs;
pub use crate::sysbus::SysBusDevice;
pub use crate::sysbus::SysBusDeviceClassExt;
pub use crate::sysbus::SysBusDeviceImpl;
pub use crate::sysbus::SysBusDeviceMethods;

7
rust/hw/core/src/sysbus.rs → rust/system/src/sysbus.rs

@ -7,15 +7,12 @@
use std::ffi::CStr;
use common::Opaque;
use hwcore::{prelude::*, IRQState};
use qom::prelude::*;
use system::MemoryRegion;
pub use system_sys::SysBusDeviceClass;
use util::{Error, Result};
use crate::{
irq::{IRQState, InterruptSource},
qdev::{DeviceClassExt, DeviceImpl, DeviceState},
};
use crate::MemoryRegion;
/// A safe wrapper around [`system_sys::SysBusDevice`].
#[repr(transparent)]
Loading…
Cancel
Save