rust: split "system" crate
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20250827104147.717203-15-marcandre.lureau@redhat.com Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
fef932ef09
commit
ee4ffbf239
24 changed files with 177 additions and 33 deletions
|
|
@ -3523,6 +3523,7 @@ F: rust/qemu-api
|
|||
F: rust/qemu-api-macros
|
||||
F: rust/qom/
|
||||
F: rust/rustfmt.toml
|
||||
F: rust/system/
|
||||
F: rust/util/
|
||||
F: scripts/get-wraps-from-cargo-registry.py
|
||||
|
||||
|
|
|
|||
13
rust/Cargo.lock
generated
13
rust/Cargo.lock
generated
|
|
@ -95,6 +95,7 @@ dependencies = [
|
|||
"qemu_api",
|
||||
"qemu_api_macros",
|
||||
"qom",
|
||||
"system",
|
||||
"util",
|
||||
]
|
||||
|
||||
|
|
@ -136,6 +137,7 @@ dependencies = [
|
|||
"qemu_api",
|
||||
"qemu_api_macros",
|
||||
"qom",
|
||||
"system",
|
||||
"util",
|
||||
]
|
||||
|
||||
|
|
@ -181,6 +183,7 @@ dependencies = [
|
|||
"migration",
|
||||
"qemu_api_macros",
|
||||
"qom",
|
||||
"system",
|
||||
"util",
|
||||
]
|
||||
|
||||
|
|
@ -224,6 +227,16 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"common",
|
||||
"qemu_api_macros",
|
||||
"qom",
|
||||
"util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ members = [
|
|||
"qemu-api-macros",
|
||||
"qemu-api",
|
||||
"qom",
|
||||
"system",
|
||||
"hw/char/pl011",
|
||||
"hw/timer/hpet",
|
||||
"util",
|
||||
|
|
|
|||
|
|
@ -77,9 +77,8 @@
|
|||
//!
|
||||
//! ```ignore
|
||||
//! # use bql::BqlRefCell;
|
||||
//! # use qemu_api::prelude::*;
|
||||
//! # use qemu_api::{irq::InterruptSource, irq::IRQState};
|
||||
//! # use qemu_api::{sysbus::SysBusDevice, qom::Owned, qom::ParentField};
|
||||
//! # use qom::{Owned, ParentField};
|
||||
//! # use system::{InterruptSource, IRQState, SysBusDevice};
|
||||
//! # const N_GPIOS: usize = 8;
|
||||
//! # struct PL061Registers { /* ... */ }
|
||||
//! # unsafe impl ObjectType for PL061State {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ bql = { path = "../../../bql" }
|
|||
migration = { path = "../../../migration" }
|
||||
qom = { path = "../../../qom" }
|
||||
chardev = { path = "../../../chardev" }
|
||||
system = { path = "../../../system" }
|
||||
qemu_api = { path = "../../../qemu-api" }
|
||||
qemu_api_macros = { path = "../../../qemu-api-macros" }
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ _libpl011_rs = static_library(
|
|||
qemu_api_macros,
|
||||
qom_rs,
|
||||
chardev_rs,
|
||||
system_rs,
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ use migration::{
|
|||
};
|
||||
use qemu_api::{
|
||||
irq::{IRQState, InterruptSource},
|
||||
memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder},
|
||||
prelude::*,
|
||||
qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, ResetType, ResettablePhasesImpl},
|
||||
sysbus::{SysBusDevice, SysBusDeviceImpl},
|
||||
};
|
||||
use qom::{prelude::*, ObjectImpl, Owned, ParentField, ParentInit};
|
||||
use system::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder};
|
||||
use util::{log::Log, log_mask_ln};
|
||||
|
||||
use crate::registers::{self, Interrupt, RegisterOffset};
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ util = { path = "../../../util" }
|
|||
migration = { path = "../../../migration" }
|
||||
bql = { path = "../../../bql" }
|
||||
qom = { path = "../../../qom" }
|
||||
system = { path = "../../../system" }
|
||||
qemu_api = { path = "../../../qemu-api" }
|
||||
qemu_api_macros = { path = "../../../qemu-api-macros" }
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ _libhpet_rs = static_library(
|
|||
bql_rs,
|
||||
qemu_api_macros,
|
||||
qom_rs,
|
||||
system_rs,
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,19 +17,17 @@ use migration::{
|
|||
VMStateDescription, VMStateDescriptionBuilder,
|
||||
};
|
||||
use qemu_api::{
|
||||
bindings::{
|
||||
address_space_memory, address_space_stl_le, qdev_prop_bit, qdev_prop_bool,
|
||||
qdev_prop_uint32, qdev_prop_usize,
|
||||
},
|
||||
bindings::{qdev_prop_bit, qdev_prop_bool, qdev_prop_uint32, qdev_prop_usize},
|
||||
irq::InterruptSource,
|
||||
memory::{
|
||||
hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder, MEMTXATTRS_UNSPECIFIED,
|
||||
},
|
||||
prelude::*,
|
||||
qdev::{DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl},
|
||||
sysbus::{SysBusDevice, SysBusDeviceImpl},
|
||||
};
|
||||
use qom::{prelude::*, ObjectImpl, ParentField, ParentInit};
|
||||
use system::{
|
||||
bindings::{address_space_memory, address_space_stl_le, hwaddr},
|
||||
MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder, MEMTXATTRS_UNSPECIFIED,
|
||||
};
|
||||
use util::timer::{Timer, CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND};
|
||||
|
||||
use crate::fw_cfg::HPETFwConfig;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ subdir('util')
|
|||
subdir('migration')
|
||||
subdir('bql')
|
||||
subdir('qom')
|
||||
subdir('system')
|
||||
subdir('chardev')
|
||||
subdir('qemu-api')
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ migration = { path = "../migration" }
|
|||
util = { path = "../util" }
|
||||
bql = { path = "../bql" }
|
||||
qom = { path = "../qom" }
|
||||
system = { path = "../system" }
|
||||
qemu_api_macros = { path = "../qemu-api-macros" }
|
||||
|
||||
[lints]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ c_enums = [
|
|||
'MachineInitPhase',
|
||||
'MemoryDeviceInfoKind',
|
||||
'ResetType',
|
||||
'device_endian',
|
||||
]
|
||||
_qemu_api_bindgen_args = []
|
||||
foreach enum : c_enums
|
||||
|
|
@ -24,8 +23,11 @@ endforeach
|
|||
blocked_type = [
|
||||
'Chardev',
|
||||
'Error',
|
||||
'MemTxAttrs',
|
||||
'MemoryRegion',
|
||||
'ObjectClass',
|
||||
'VMStateDescription',
|
||||
'device_endian',
|
||||
]
|
||||
foreach type: blocked_type
|
||||
_qemu_api_bindgen_args += ['--blocklist-type', type]
|
||||
|
|
@ -54,7 +56,6 @@ _qemu_api_rs = static_library(
|
|||
'src/lib.rs',
|
||||
'src/bindings.rs',
|
||||
'src/irq.rs',
|
||||
'src/memory.rs',
|
||||
'src/prelude.rs',
|
||||
'src/qdev.rs',
|
||||
'src/sysbus.rs',
|
||||
|
|
@ -65,7 +66,7 @@ _qemu_api_rs = static_library(
|
|||
rust_abi: 'rust',
|
||||
rust_args: _qemu_api_cfg,
|
||||
dependencies: [anyhow_rs, bql_rs, chardev_rs, common_rs, foreign_rs, libc_rs, migration_rs, qemu_api_macros,
|
||||
qom_rs, util_rs, hwcore],
|
||||
qom_rs, system_rs, util_rs, hwcore],
|
||||
)
|
||||
|
||||
qemu_api_rs = declare_dependency(link_with: [_qemu_api_rs],
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use chardev::bindings::Chardev;
|
|||
use common::Zeroable;
|
||||
use migration::bindings::VMStateDescription;
|
||||
use qom::bindings::ObjectClass;
|
||||
use system::bindings::{device_endian, MemTxAttrs, MemoryRegion};
|
||||
use util::bindings::Error;
|
||||
|
||||
#[cfg(MESON)]
|
||||
|
|
@ -32,15 +33,6 @@ include!("bindings.inc.rs");
|
|||
#[cfg(not(MESON))]
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
|
||||
|
||||
// SAFETY: this is a pure data struct
|
||||
unsafe impl Send for CoalescedMemoryRange {}
|
||||
unsafe impl Sync for CoalescedMemoryRange {}
|
||||
|
||||
// SAFETY: these are constants and vtables; the Send and Sync requirements
|
||||
// are deferred to the unsafe callbacks that they contain
|
||||
unsafe impl Send for MemoryRegionOps {}
|
||||
unsafe impl Sync for MemoryRegionOps {}
|
||||
|
||||
unsafe impl Send for Property {}
|
||||
unsafe impl Sync for Property {}
|
||||
|
||||
|
|
@ -49,7 +41,3 @@ unsafe impl Sync for TypeInfo {}
|
|||
|
||||
unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {}
|
||||
unsafe impl Zeroable for crate::bindings::Property {}
|
||||
unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {}
|
||||
unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {}
|
||||
unsafe impl Zeroable for crate::bindings::MemoryRegionOps {}
|
||||
unsafe impl Zeroable for crate::bindings::MemTxAttrs {}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ pub mod bindings;
|
|||
pub mod prelude;
|
||||
|
||||
pub mod irq;
|
||||
pub mod memory;
|
||||
pub mod qdev;
|
||||
pub mod sysbus;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ use std::{ffi::CStr, ptr::addr_of_mut};
|
|||
pub use bindings::SysBusDeviceClass;
|
||||
use common::Opaque;
|
||||
use qom::{prelude::*, Owned};
|
||||
use system::MemoryRegion;
|
||||
|
||||
use crate::{
|
||||
bindings,
|
||||
irq::{IRQState, InterruptSource},
|
||||
memory::MemoryRegion,
|
||||
qdev::{DeviceImpl, DeviceState},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -49,14 +49,11 @@ typedef enum memory_order {
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-io.h"
|
||||
#include "system/system.h"
|
||||
#include "hw/sysbus.h"
|
||||
#include "system/memory.h"
|
||||
#include "hw/clock.h"
|
||||
#include "hw/qdev-clock.h"
|
||||
#include "hw/qdev-properties.h"
|
||||
#include "hw/qdev-properties-system.h"
|
||||
#include "hw/irq.h"
|
||||
#include "exec/memattrs.h"
|
||||
#include "system/address-spaces.h"
|
||||
#include "hw/char/pl011.h"
|
||||
|
|
|
|||
22
rust/system/Cargo.toml
Normal file
22
rust/system/Cargo.toml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
[package]
|
||||
name = "system"
|
||||
version = "0.1.0"
|
||||
description = "Rust bindings for QEMU/system"
|
||||
resolver = "2"
|
||||
publish = false
|
||||
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
qom = { path = "../qom" }
|
||||
util = { path = "../util" }
|
||||
qemu_api_macros = { path = "../qemu-api-macros" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
1
rust/system/build.rs
Symbolic link
1
rust/system/build.rs
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../util/build.rs
|
||||
42
rust/system/meson.build
Normal file
42
rust/system/meson.build
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
c_enums = [
|
||||
'device_endian',
|
||||
]
|
||||
_system_bindgen_args = []
|
||||
foreach enum : c_enums
|
||||
_system_bindgen_args += ['--rustified-enum', enum]
|
||||
endforeach
|
||||
|
||||
# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
|
||||
#
|
||||
# Rust bindings generation with `bindgen` might fail in some cases where the
|
||||
# detected `libclang` does not match the expected `clang` version/target. In
|
||||
# this case you must pass the path to `clang` and `libclang` to your build
|
||||
# command invocation using the environment variables CLANG_PATH and
|
||||
# LIBCLANG_PATH
|
||||
_system_bindings_inc_rs = rust.bindgen(
|
||||
input: 'wrapper.h',
|
||||
dependencies: common_ss.all_dependencies(),
|
||||
output: 'bindings.inc.rs',
|
||||
include_directories: bindings_incdir,
|
||||
bindgen_version: ['>=0.60.0'],
|
||||
args: bindgen_args_common + _system_bindgen_args,
|
||||
)
|
||||
|
||||
_system_rs = static_library(
|
||||
'system',
|
||||
structured_sources(
|
||||
[
|
||||
'src/lib.rs',
|
||||
'src/bindings.rs',
|
||||
'src/memory.rs',
|
||||
],
|
||||
{'.': _system_bindings_inc_rs}
|
||||
),
|
||||
override_options: ['rust_std=2021', 'build.rust_std=2021'],
|
||||
rust_abi: 'rust',
|
||||
link_with: [_bql_rs, _migration_rs, _qom_rs, _util_rs],
|
||||
dependencies: [common_rs, qemu_api_macros],
|
||||
)
|
||||
|
||||
system_rs = declare_dependency(link_with: [_system_rs],
|
||||
dependencies: [qemu_api_macros, hwcore])
|
||||
41
rust/system/src/bindings.rs
Normal file
41
rust/system/src/bindings.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#![allow(
|
||||
dead_code,
|
||||
improper_ctypes_definitions,
|
||||
improper_ctypes,
|
||||
non_camel_case_types,
|
||||
non_snake_case,
|
||||
non_upper_case_globals,
|
||||
unnecessary_transmutes,
|
||||
unsafe_op_in_unsafe_fn,
|
||||
clippy::pedantic,
|
||||
clippy::restriction,
|
||||
clippy::style,
|
||||
clippy::missing_const_for_fn,
|
||||
clippy::ptr_offset_with_cast,
|
||||
clippy::useless_transmute,
|
||||
clippy::missing_safety_doc,
|
||||
clippy::too_many_arguments
|
||||
)]
|
||||
|
||||
use common::Zeroable;
|
||||
|
||||
#[cfg(MESON)]
|
||||
include!("bindings.inc.rs");
|
||||
|
||||
#[cfg(not(MESON))]
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs"));
|
||||
|
||||
// SAFETY: these are constants and vtables; the Send and Sync requirements
|
||||
// are deferred to the unsafe callbacks that they contain
|
||||
unsafe impl Send for MemoryRegionOps {}
|
||||
unsafe impl Sync for MemoryRegionOps {}
|
||||
|
||||
// SAFETY: this is a pure data struct
|
||||
unsafe impl Send for CoalescedMemoryRange {}
|
||||
unsafe impl Sync for CoalescedMemoryRange {}
|
||||
|
||||
unsafe impl Zeroable for MemoryRegionOps__bindgen_ty_1 {}
|
||||
unsafe impl Zeroable for MemoryRegionOps__bindgen_ty_2 {}
|
||||
unsafe impl Zeroable for MemoryRegionOps {}
|
||||
unsafe impl Zeroable for MemTxAttrs {}
|
||||
6
rust/system/src/lib.rs
Normal file
6
rust/system/src/lib.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
pub mod bindings;
|
||||
|
||||
mod memory;
|
||||
pub use memory::*;
|
||||
|
|
@ -9,11 +9,11 @@ use std::{
|
|||
marker::PhantomData,
|
||||
};
|
||||
|
||||
pub use bindings::{hwaddr, MemTxAttrs};
|
||||
use common::{callbacks::FnCall, uninit::MaybeUninitField, zeroable::Zeroable, Opaque};
|
||||
use qom::prelude::*;
|
||||
|
||||
use crate::bindings::{self, device_endian, memory_region_init_io};
|
||||
pub use crate::bindings::{hwaddr, MemTxAttrs};
|
||||
|
||||
pub struct MemoryRegionOps<T>(
|
||||
bindings::MemoryRegionOps,
|
||||
29
rust/system/wrapper.h
Normal file
29
rust/system/wrapper.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/*
|
||||
* This header file is meant to be used as input to the `bindgen` application
|
||||
* in order to generate C FFI compatible Rust bindings.
|
||||
*/
|
||||
|
||||
#ifndef __CLANG_STDATOMIC_H
|
||||
#define __CLANG_STDATOMIC_H
|
||||
/*
|
||||
* Fix potential missing stdatomic.h error in case bindgen does not insert the
|
||||
* correct libclang header paths on its own. We do not use stdatomic.h symbols
|
||||
* in QEMU code, so it's fine to declare dummy types instead.
|
||||
*/
|
||||
typedef enum memory_order {
|
||||
memory_order_relaxed,
|
||||
memory_order_consume,
|
||||
memory_order_acquire,
|
||||
memory_order_release,
|
||||
memory_order_acq_rel,
|
||||
memory_order_seq_cst,
|
||||
} memory_order;
|
||||
#endif /* __CLANG_STDATOMIC_H */
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "system/system.h"
|
||||
#include "system/memory.h"
|
||||
#include "system/address-spaces.h"
|
||||
Loading…
Add table
Add a link
Reference in a new issue