From nobody Sun Sep 28 16:35:57 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1756217685; cv=none; d=zohomail.com; s=zohoarc; b=TFEuFkZjg2Ebj4S5KjoQVQ2uRkI8vn6su9TdE07ifVuBm035qGPaQNcFbWKl5lQFxheYTrl13aSfK9627o3D1HznaoBw+HpCrc6MKugIljo6pPpxnJ3X6Rdo5++pQKMZ3YXcBbdMYIN7GxXqteoAzLYHLuUgGjIW5OjIzGJBGdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756217685; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XvwCIrS0tHQ0/SPChJSCGSmNkNVeeZOxW+qU6kX3a0g=; b=YANL/t0N6A6lWEzJ1lsc01wZXVNMSTzDFMR6gDwDNeOfvXNTGShu5nws+2j3EUtap/As39So0sRSxsEOSsPIJnD3aoPG2dGjBYU+LZ2yJ+4tiwqUHos56aFXAl3f2e+X8T5Y125W0VQVYHMcTbm/DoIHwzZGhtXYC+1k10T4pNU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756217685318606.2749480680583; Tue, 26 Aug 2025 07:14:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uquJt-0006QU-TS; Tue, 26 Aug 2025 10:06:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uquJq-0006Px-F4 for qemu-devel@nongnu.org; Tue, 26 Aug 2025 10:06:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uquJh-0007A4-9W for qemu-devel@nongnu.org; Tue, 26 Aug 2025 10:06:38 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-XURCNVWuNMqroGeKeYQe3g-1; Tue, 26 Aug 2025 10:06:17 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2A63619560B6; Tue, 26 Aug 2025 14:06:09 +0000 (UTC) Received: from localhost (unknown [10.45.242.16]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DA41A19560AD; Tue, 26 Aug 2025 14:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756217182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XvwCIrS0tHQ0/SPChJSCGSmNkNVeeZOxW+qU6kX3a0g=; b=IaD3Gm+QAx8mHkQgfp/rblrUkol2dhCwOGcAsjQLfJcxsU+sUFap8C4zc6nP9GXdxo+tYA +2Xr1EQO4ZZFtihWhpvCmq2tGTVRo2E4Cru2E4Oz2JHrBgjBkS29VCgtr3X4GtdyqmOISE +KsCjrEdS+QfKQzLkzqaWi3JF9IgCCA= X-MC-Unique: XURCNVWuNMqroGeKeYQe3g-1 X-Mimecast-MFC-AGG-ID: XURCNVWuNMqroGeKeYQe3g_1756217169 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-rust@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Manos Pitsidianakis Subject: [RFC 13/18] rust: split "hwcore" crate Date: Tue, 26 Aug 2025 18:04:41 +0400 Message-ID: <20250826140449.4190022-14-marcandre.lureau@redhat.com> In-Reply-To: <20250826140449.4190022-1-marcandre.lureau@redhat.com> References: <20250826140449.4190022-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1756217687006116600 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau --- MAINTAINERS | 1 + rust/hw/core/wrapper.h | 32 ++++++++ rust/qemu-api/wrapper.h | 6 -- rust/Cargo.lock | 17 ++++ rust/Cargo.toml | 1 + rust/hw/char/pl011/Cargo.toml | 1 + rust/hw/char/pl011/meson.build | 1 + rust/hw/char/pl011/src/device.rs | 20 +++-- rust/hw/core/Cargo.toml | 26 +++++++ rust/hw/core/build.rs | 43 +++++++++++ rust/hw/core/meson.build | 94 +++++++++++++++++++++++ rust/hw/core/src/bindings.rs | 41 ++++++++++ rust/{qemu-api =3D> hw/core}/src/irq.rs | 0 rust/hw/core/src/lib.rs | 12 +++ rust/{qemu-api =3D> hw/core}/src/qdev.rs | 6 +- rust/{qemu-api =3D> hw/core}/src/sysbus.rs | 0 rust/{qemu-api =3D> hw/core}/tests/tests.rs | 20 ++--- rust/hw/timer/hpet/Cargo.toml | 1 + rust/hw/timer/hpet/meson.build | 1 + rust/hw/timer/hpet/src/device.rs | 22 +++--- rust/meson.build | 1 + rust/qemu-api/Cargo.toml | 1 + rust/qemu-api/meson.build | 17 +--- rust/qemu-api/src/bindings.rs | 10 --- rust/qemu-api/src/lib.rs | 4 - rust/qemu-api/src/prelude.rs | 4 - 26 files changed, 305 insertions(+), 77 deletions(-) create mode 100644 rust/hw/core/wrapper.h create mode 100644 rust/hw/core/Cargo.toml create mode 100644 rust/hw/core/build.rs create mode 100644 rust/hw/core/meson.build create mode 100644 rust/hw/core/src/bindings.rs rename rust/{qemu-api =3D> hw/core}/src/irq.rs (100%) create mode 100644 rust/hw/core/src/lib.rs rename rust/{qemu-api =3D> hw/core}/src/qdev.rs (98%) rename rust/{qemu-api =3D> hw/core}/src/sysbus.rs (100%) rename rust/{qemu-api =3D> hw/core}/tests/tests.rs (89%) diff --git a/MAINTAINERS b/MAINTAINERS index ce8bb3c076..3f40a80240 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3513,6 +3513,7 @@ S: Maintained F: rust/bql/ F: rust/chardev/ F: rust/common/ +F: rust/hw/core/ F: rust/migration/ F: rust/qemu-api F: rust/qemu-api-macros diff --git a/rust/hw/core/wrapper.h b/rust/hw/core/wrapper.h new file mode 100644 index 0000000000..3bdbd1249e --- /dev/null +++ b/rust/hw/core/wrapper.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* + * This header file is meant to be used as input to the `bindgen` applicat= ion + * 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 sym= bols + * 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 "hw/sysbus.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" diff --git a/rust/qemu-api/wrapper.h b/rust/qemu-api/wrapper.h index 564733b903..7c9c20b14f 100644 --- a/rust/qemu-api/wrapper.h +++ b/rust/qemu-api/wrapper.h @@ -49,11 +49,5 @@ typedef enum memory_order { =20 #include "qemu/osdep.h" #include "qemu-io.h" -#include "hw/sysbus.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 "hw/char/pl011.h" diff --git a/rust/Cargo.lock b/rust/Cargo.lock index e4946549c0..7ed22ca687 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -88,6 +88,7 @@ version =3D "0.1.0" dependencies =3D [ "bql", "common", + "hwcore", "migration", "qemu_api", "qemu_api_macros", @@ -96,6 +97,20 @@ dependencies =3D [ "util", ] =20 +[[package]] +name =3D "hwcore" +version =3D "0.1.0" +dependencies =3D [ + "bql", + "chardev", + "common", + "migration", + "qemu_api_macros", + "qom", + "system", + "util", +] + [[package]] name =3D "itertools" version =3D "0.11.0" @@ -130,6 +145,7 @@ dependencies =3D [ "bql", "chardev", "common", + "hwcore", "migration", "qemu_api", "qemu_api_macros", @@ -179,6 +195,7 @@ dependencies =3D [ "chardev", "common", "foreign", + "hwcore", "libc", "migration", "qemu_api_macros", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 1c18e69660..ca94d2cf40 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -9,6 +9,7 @@ members =3D [ "qemu-api", "qom", "system", + "hw/core", "hw/char/pl011", "hw/timer/hpet", "util", diff --git a/rust/hw/char/pl011/Cargo.toml b/rust/hw/char/pl011/Cargo.toml index e4b1c3f1eb..830d88586b 100644 --- a/rust/hw/char/pl011/Cargo.toml +++ b/rust/hw/char/pl011/Cargo.toml @@ -23,6 +23,7 @@ migration =3D { path =3D "../../../migration" } qom =3D { path =3D "../../../qom" } chardev =3D { path =3D "../../../chardev" } system =3D { path =3D "../../../system" } +hwcore =3D { path =3D "../../../hw/core" } qemu_api =3D { path =3D "../../../qemu-api" } qemu_api_macros =3D { path =3D "../../../qemu-api-macros" } =20 diff --git a/rust/hw/char/pl011/meson.build b/rust/hw/char/pl011/meson.build index 06ebaf7ab9..83030476de 100644 --- a/rust/hw/char/pl011/meson.build +++ b/rust/hw/char/pl011/meson.build @@ -16,6 +16,7 @@ _libpl011_rs =3D static_library( qom_rs, chardev_rs, system_rs, + hwcore_rs, ], ) =20 diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 5307ac480b..e0d89db28d 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -11,18 +11,16 @@ use bql::BqlRefCell; use chardev::{CharBackend, Chardev, Event}; use common::{static_assert, uninit_field_mut, Zeroable}; +use hwcore::{ + bindings::{qdev_prop_bool, qdev_prop_chr}, + declare_properties, define_property, vmstate_clock, Clock, ClockEvent,= DeviceImpl, + DeviceMethods, DeviceState, IRQState, InterruptSource, Property, Reset= Type, + ResettablePhasesImpl, SysBusDevice, SysBusDeviceImpl, SysBusDeviceMeth= ods, +}; use migration::{ impl_vmstate_forward, vmstate_fields, vmstate_of, vmstate_struct, vmst= ate_subsections, vmstate_unused, VMStateDescription, }; -use qemu_api::{ - bindings::{qdev_prop_bool, qdev_prop_chr}, - irq::{IRQState, InterruptSource}, - prelude::*, - qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, Property, ResetType= , ResettablePhasesImpl}, - sysbus::{SysBusDevice, SysBusDeviceImpl}, - vmstate_clock, -}; use qom::{ qom_isa, IsA, Object, ObjectClassMethods, ObjectDeref, ObjectImpl, Obj= ectMethods, ObjectType, Owned, ParentField, ParentInit, @@ -786,16 +784,16 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, ve= rsion_id: c_int) -> c_int { ..Zeroable::ZERO }; =20 -qemu_api::declare_properties! { +declare_properties! { PL011_PROPERTIES, - qemu_api::define_property!( + define_property!( c"chardev", PL011State, char_backend, unsafe { &qdev_prop_chr }, CharBackend ), - qemu_api::define_property!( + define_property!( c"migrate-clk", PL011State, migrate_clock, diff --git a/rust/hw/core/Cargo.toml b/rust/hw/core/Cargo.toml new file mode 100644 index 0000000000..0b35380264 --- /dev/null +++ b/rust/hw/core/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name =3D "hwcore" +version =3D "0.1.0" +description =3D "Rust bindings for QEMU/hwcore" +resolver =3D "2" +publish =3D false + +authors.workspace =3D true +edition.workspace =3D true +homepage.workspace =3D true +license.workspace =3D true +repository.workspace =3D true +rust-version.workspace =3D true + +[dependencies] +common =3D { path =3D "../../common" } +bql =3D { path =3D "../../bql" } +qom =3D { path =3D "../../qom" } +chardev =3D { path =3D "../../chardev" } +migration =3D { path =3D "../../migration" } +system =3D { path =3D "../../system" } +util =3D { path =3D "../../util" } +qemu_api_macros =3D { path =3D "../../qemu-api-macros" } + +[lints] +workspace =3D true diff --git a/rust/hw/core/build.rs b/rust/hw/core/build.rs new file mode 100644 index 0000000000..3f8e1bff89 --- /dev/null +++ b/rust/hw/core/build.rs @@ -0,0 +1,43 @@ +// Copyright 2024, Linaro Limited +// Author(s): Manos Pitsidianakis +// SPDX-License-Identifier: GPL-2.0-or-later + +#[cfg(unix)] +use std::os::unix::fs::symlink as symlink_file; +#[cfg(windows)] +use std::os::windows::fs::symlink_file; +use std::{env, fs::remove_file, io::Result, path::Path}; + +fn main() -> Result<()> { + let file =3D if let Ok(root) =3D env::var("MESON_BUILD_ROOT") { + format!("{root}/rust/hw/core/bindings.inc.rs") + } else { + // Placing bindings.inc.rs in the source directory is supported + // but not documented or encouraged. + format!("{}/src/bindings.inc.rs", env!("CARGO_MANIFEST_DIR")) + }; + + let file =3D Path::new(&file); + if !Path::new(&file).exists() { + panic!(concat!( + "\n", + " No generated C bindings found! Maybe you wanted one of\n", + " `make clippy`, `make rustfmt`, `make rustdoc`?\n", + "\n", + " For other uses of `cargo`, start a subshell with\n", + " `pyvenv/bin/meson devenv`, or point MESON_BUILD_ROOT to\n= ", + " the top of the build tree." + )); + } + + let out_dir =3D env::var("OUT_DIR").unwrap(); + let dest_path =3D format!("{out_dir}/bindings.inc.rs"); + let dest_path =3D Path::new(&dest_path); + if dest_path.symlink_metadata().is_ok() { + remove_file(dest_path)?; + } + symlink_file(file, dest_path)?; + + println!("cargo:rerun-if-changed=3Dbuild.rs"); + Ok(()) +} diff --git a/rust/hw/core/meson.build b/rust/hw/core/meson.build new file mode 100644 index 0000000000..d390f2d665 --- /dev/null +++ b/rust/hw/core/meson.build @@ -0,0 +1,94 @@ +_hwcore_cfg =3D run_command(rustc_args, + '--config-headers', config_host_h, '--features', files('Cargo.toml'), + capture: true, check: true).stdout().strip().splitlines() + +_hwcore_bindgen_args =3D [] +c_enums =3D [ + 'DeviceCategory', + 'GpioPolarity', + 'MachineInitPhase', + 'ResetType', +] +foreach enum : c_enums + _hwcore_bindgen_args +=3D ['--rustified-enum', enum] +endforeach + +blocked_type =3D [ + 'Chardev', + 'Error', + 'ObjectClass', + 'MemoryRegion', + 'VMStateDescription', +] +foreach type: blocked_type + _hwcore_bindgen_args +=3D ['--blocklist-type', type] +endforeach + +c_bitfields =3D [ + 'ClockEvent', +] +foreach enum : c_bitfields + _hwcore_bindgen_args +=3D ['--bitfield-enum', enum] +endforeach + +# TODO: Remove this comment when the clang/libclang mismatch issue is solv= ed. +# +# Rust bindings generation with `bindgen` might fail in some cases where t= he +# 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 +_hwcore_bindings_inc_rs =3D rust.bindgen( + input: 'wrapper.h', + dependencies: common_ss.all_dependencies(), + output: 'bindings.inc.rs', + include_directories: bindings_incdir, + bindgen_version: ['>=3D0.60.0'], + args: bindgen_args_common + _hwcore_bindgen_args, +) + +_hwcore_rs =3D static_library( + 'hwcore', + structured_sources( + [ + 'src/lib.rs', + 'src/bindings.rs', + 'src/irq.rs', + 'src/qdev.rs', + 'src/sysbus.rs', + ], + {'.': _hwcore_bindings_inc_rs} + ), + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_abi: 'rust', + rust_args: _hwcore_cfg, + dependencies: [qemu_api_macros, common_rs, bql_rs, chardev_rs, migration= _rs, qemuutil_rs, qom_rs, system_rs, util_rs, + qom, hwcore, chardev, migration], +) + +hwcore_rs =3D declare_dependency(link_with: [_hwcore_rs], + dependencies: [qom_rs, hwcore]) + +# Doctests are essentially integration tests, so they need the same depend= encies. +# Note that running them requires the object files for C code, so place th= em +# in a separate suite that is run by the "build" CI jobs rather than "chec= k". +rust.doctest('rust-hwcore-rs-doctests', + _hwcore_rs, + protocol: 'rust', + dependencies: hwcore_rs, + suite: ['doc', 'rust']) + +test('rust-hwcore-rs-integration', + executable( + 'rust-hwcore-rs-integration', + files('tests/tests.rs'), + override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], + rust_args: ['--test'], + install: false, + dependencies: [common_rs, hwcore_rs, bql_rs, migration_rs, qemu_ap= i_macros, util_rs]), + args: [ + '--test', '--test-threads', '1', + '--format', 'pretty', + ], + protocol: 'rust', + suite: ['unit', 'rust']) diff --git a/rust/hw/core/src/bindings.rs b/rust/hw/core/src/bindings.rs new file mode 100644 index 0000000000..919c02b56a --- /dev/null +++ b/rust/hw/core/src/bindings.rs @@ -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 chardev::bindings::Chardev; +use common::Zeroable; +use migration::bindings::VMStateDescription; +use qom::bindings::ObjectClass; +use system::bindings::MemoryRegion; +use util::bindings::Error; + +#[cfg(MESON)] +include!("bindings.inc.rs"); + +#[cfg(not(MESON))] +include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs")); + +unsafe impl Send for Property {} +unsafe impl Sync for Property {} + +unsafe impl Send for TypeInfo {} +unsafe impl Sync for TypeInfo {} + +unsafe impl Zeroable for Property__bindgen_ty_1 {} +unsafe impl Zeroable for Property {} diff --git a/rust/qemu-api/src/irq.rs b/rust/hw/core/src/irq.rs similarity index 100% rename from rust/qemu-api/src/irq.rs rename to rust/hw/core/src/irq.rs diff --git a/rust/hw/core/src/lib.rs b/rust/hw/core/src/lib.rs new file mode 100644 index 0000000000..c5c33f3dec --- /dev/null +++ b/rust/hw/core/src/lib.rs @@ -0,0 +1,12 @@ +pub use qom; + +pub mod bindings; + +mod irq; +pub use irq::*; + +mod qdev; +pub use qdev::*; + +mod sysbus; +pub use sysbus::*; diff --git a/rust/qemu-api/src/qdev.rs b/rust/hw/core/src/qdev.rs similarity index 98% rename from rust/qemu-api/src/qdev.rs rename to rust/hw/core/src/qdev.rs index 98d8593ca5..16a4769758 100644 --- a/rust/qemu-api/src/qdev.rs +++ b/rust/hw/core/src/qdev.rs @@ -9,7 +9,6 @@ ptr::NonNull, }; =20 -pub use bindings::{ClockEvent, DeviceClass, Property, ResetType}; use chardev::Chardev; use common::{callbacks::FnCall, Opaque}; use migration::vmstate::VMStateDescription; @@ -19,6 +18,7 @@ }; pub use util::{Error, Result}; =20 +pub use crate::bindings::{ClockEvent, DeviceClass, Property, ResetType}; use crate::{ bindings::{self, qdev_init_gpio_in, qdev_init_gpio_out, ResettableClas= s}, irq::InterruptSource, @@ -428,11 +428,11 @@ macro_rules! vmstate_clock { ::common::assert_field_type!( $struct_name, $field_name, - ::qom::Owned<$crate::qdev::Clock> $(, num =3D $num)? + ::qom::Owned<$crate::Clock> $(, num =3D $num)? ); ::std::mem::offset_of!($struct_name, $field_name) }, - size: ::core::mem::size_of::<*const $crate::qdev::Clock>(), + size: ::core::mem::size_of::<*const $crate::Clock>(), flags: ::migration::VMStateFlags( ::migration::VMStateFlags::VMS_STRUCT.0 | ::migration::VMStateFlags::VMS_POINTER.0, diff --git a/rust/qemu-api/src/sysbus.rs b/rust/hw/core/src/sysbus.rs similarity index 100% rename from rust/qemu-api/src/sysbus.rs rename to rust/hw/core/src/sysbus.rs diff --git a/rust/qemu-api/tests/tests.rs b/rust/hw/core/tests/tests.rs similarity index 89% rename from rust/qemu-api/tests/tests.rs rename to rust/hw/core/tests/tests.rs index 821aabe831..f11c15ac62 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/hw/core/tests/tests.rs @@ -6,21 +6,17 @@ =20 use bql::BqlCell; use common::Zeroable; -use migration::VMStateDescription; -use qemu_api::{ - bindings::qdev_prop_bool, - declare_properties, define_property, - qdev::{DeviceClassExt, DeviceImpl, DeviceState, Property, ResettablePh= asesImpl}, - sysbus::SysBusDevice, +use hwcore::{ + bindings::qdev_prop_bool, declare_properties, define_property, DeviceC= lassExt, DeviceImpl, + DeviceState, Property, ResettablePhasesImpl, SysBusDevice, }; +use migration::vmstate::VMStateDescription; use qom::{ - Object, ObjectCast, ObjectClassMethods, ObjectDeref, ObjectImpl, Objec= tMethods, ObjectType, - ParentField, + qom_isa, Object, ObjectCast, ObjectClassMethods, ObjectDeref, ObjectIm= pl, ObjectMethods, + ObjectType, ParentField, }; use util::bindings::{module_call_init, module_init_type}; =20 -mod vmstate_tests; - // Test that macros can compile. pub static VMSTATE: VMStateDescription =3D VMStateDescription { name: c"name".as_ptr(), @@ -35,7 +31,7 @@ pub struct DummyState { migrate_clock: bool, } =20 -qom::qom_isa!(DummyState: Object, DeviceState); +qom_isa!(DummyState: Object, DeviceState); =20 pub struct DummyClass { parent_class: ::Class, @@ -86,7 +82,7 @@ pub struct DummyChildState { parent: ParentField, } =20 -qom::qom_isa!(DummyChildState: Object, DeviceState, DummyState); +qom_isa!(DummyChildState: Object, DeviceState, DummyState); =20 pub struct DummyChildClass { parent_class: ::Class, diff --git a/rust/hw/timer/hpet/Cargo.toml b/rust/hw/timer/hpet/Cargo.toml index a95b1271c6..e28d66f645 100644 --- a/rust/hw/timer/hpet/Cargo.toml +++ b/rust/hw/timer/hpet/Cargo.toml @@ -19,6 +19,7 @@ qom =3D { path =3D "../../../qom" } system =3D { path =3D "../../../system" } qemu_api =3D { path =3D "../../../qemu-api" } qemu_api_macros =3D { path =3D "../../../qemu-api-macros" } +hwcore =3D { path =3D "../../../hw/core" } =20 [lints] workspace =3D true diff --git a/rust/hw/timer/hpet/meson.build b/rust/hw/timer/hpet/meson.build index 74cbe27df8..d65306c169 100644 --- a/rust/hw/timer/hpet/meson.build +++ b/rust/hw/timer/hpet/meson.build @@ -12,6 +12,7 @@ _libhpet_rs =3D static_library( qemu_api_macros, qom_rs, system_rs, + hwcore_rs, ], ) =20 diff --git a/rust/hw/timer/hpet/src/device.rs b/rust/hw/timer/hpet/src/devi= ce.rs index f5cc4ee0ad..2ea101bb7f 100644 --- a/rust/hw/timer/hpet/src/device.rs +++ b/rust/hw/timer/hpet/src/device.rs @@ -12,17 +12,15 @@ =20 use bql::{BqlCell, BqlRefCell}; use common::{bitops::IntegerExt, uninit_field_mut, Zeroable}; +use hwcore::{ + bindings::{qdev_prop_bit, qdev_prop_bool, qdev_prop_uint32, qdev_prop_= usize}, + declare_properties, define_property, DeviceImpl, DeviceMethods, Device= State, InterruptSource, + Property, ResetType, ResettablePhasesImpl, SysBusDevice, SysBusDeviceI= mpl, SysBusDeviceMethods, +}; use migration::{ vmstate_fields, vmstate_of, vmstate_struct, vmstate_subsections, vmsta= te_validate, VMStateDescription, VMStateFieldHelper, }; -use qemu_api::{ - bindings::{qdev_prop_bit, qdev_prop_bool, qdev_prop_uint32, qdev_prop_= usize}, - irq::InterruptSource, - prelude::*, - qdev::{DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesI= mpl}, - sysbus::{SysBusDevice, SysBusDeviceImpl}, -}; use qom::{qom_isa, Object, ObjectImpl, ObjectType, ParentField, ParentInit= }; use system::{ bindings::{address_space_memory, address_space_stl_le, hwaddr}, @@ -900,9 +898,9 @@ impl ObjectImpl for HPETState { } =20 // TODO: Make these properties user-configurable! -qemu_api::declare_properties! { +declare_properties! { HPET_PROPERTIES, - qemu_api::define_property!( + define_property!( c"timers", HPETState, num_timers, @@ -910,7 +908,7 @@ impl ObjectImpl for HPETState { u8, default =3D HPET_MIN_TIMERS ), - qemu_api::define_property!( + define_property!( c"msi", HPETState, flags, @@ -919,7 +917,7 @@ impl ObjectImpl for HPETState { bit =3D HPET_FLAG_MSI_SUPPORT_SHIFT as u8, default =3D false, ), - qemu_api::define_property!( + define_property!( c"hpet-intcap", HPETState, int_route_cap, @@ -927,7 +925,7 @@ impl ObjectImpl for HPETState { u32, default =3D 0 ), - qemu_api::define_property!( + define_property!( c"hpet-offset-saved", HPETState, hpet_offset_saved, diff --git a/rust/meson.build b/rust/meson.build index d8b71f5506..041b0a473e 100644 --- a/rust/meson.build +++ b/rust/meson.build @@ -31,6 +31,7 @@ subdir('bql') subdir('qom') subdir('system') subdir('chardev') +subdir('hw/core') subdir('qemu-api') =20 subdir('hw') diff --git a/rust/qemu-api/Cargo.toml b/rust/qemu-api/Cargo.toml index 2429c4eb9f..9f216e45a6 100644 --- a/rust/qemu-api/Cargo.toml +++ b/rust/qemu-api/Cargo.toml @@ -16,6 +16,7 @@ rust-version.workspace =3D true [dependencies] common =3D { path =3D "../common" } chardev =3D { path =3D "../chardev" } +hwcore =3D { path =3D "../hw/core" } migration =3D { path =3D "../migration" } util =3D { path =3D "../util" } bql =3D { path =3D "../bql" } diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 644ca44573..a4c90b2bf7 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -3,22 +3,12 @@ _qemu_api_cfg =3D run_command(rustc_args, capture: true, check: true).stdout().strip().splitlines() =20 c_enums =3D [ - 'DeviceCategory', - 'GpioPolarity', - 'MachineInitPhase', 'MemoryDeviceInfoKind', - 'ResetType', ] _qemu_api_bindgen_args =3D [] foreach enum : c_enums _qemu_api_bindgen_args +=3D ['--rustified-enum', enum] endforeach -c_bitfields =3D [ - 'ClockEvent', -] -foreach enum : c_bitfields - _qemu_api_bindgen_args +=3D ['--bitfield-enum', enum] -endforeach =20 blocked_type =3D [ 'Chardev', @@ -55,17 +45,14 @@ _qemu_api_rs =3D static_library( [ 'src/lib.rs', 'src/bindings.rs', - 'src/irq.rs', 'src/prelude.rs', - 'src/qdev.rs', - 'src/sysbus.rs', ], {'.' : _qemu_api_bindings_inc_rs}, ), override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_abi: 'rust', rust_args: _qemu_api_cfg, - dependencies: [anyhow_rs, common_rs, chardev_rs, foreign_rs, libc_rs, qe= mu_api_macros, qemuutil_rs, util_rs, migration_rs, bql_rs, qom_rs, system_r= s, + dependencies: [anyhow_rs, common_rs, chardev_rs, foreign_rs, libc_rs, qe= mu_api_macros, qemuutil_rs, util_rs, migration_rs, bql_rs, qom_rs, system_r= s, hwcore_rs, qom, hwcore, chardev, migration], ) =20 @@ -87,7 +74,7 @@ rust.doctest('rust-qemu-api-doctests', test('rust-qemu-api-integration', executable( 'rust-qemu-api-integration', - files('tests/tests.rs', 'tests/vmstate_tests.rs'), + files('tests/vmstate_tests.rs'), override_options: ['rust_std=3D2021', 'build.rust_std=3D2021'], rust_args: ['--test'], install: false, diff --git a/rust/qemu-api/src/bindings.rs b/rust/qemu-api/src/bindings.rs index 63b805c76e..9c863e9b5b 100644 --- a/rust/qemu-api/src/bindings.rs +++ b/rust/qemu-api/src/bindings.rs @@ -21,7 +21,6 @@ //! `bindgen`-generated declarations. =20 use chardev::bindings::Chardev; -use common::Zeroable; use migration::bindings::VMStateDescription; use qom::bindings::ObjectClass; use system::bindings::{device_endian, MemTxAttrs, MemoryRegion}; @@ -32,12 +31,3 @@ =20 #[cfg(not(MESON))] include!(concat!(env!("OUT_DIR"), "/bindings.inc.rs")); - -unsafe impl Send for Property {} -unsafe impl Sync for Property {} - -unsafe impl Send for TypeInfo {} -unsafe impl Sync for TypeInfo {} - -unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {} -unsafe impl Zeroable for crate::bindings::Property {} diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs index 38ff102b86..50fb2fa99d 100644 --- a/rust/qemu-api/src/lib.rs +++ b/rust/qemu-api/src/lib.rs @@ -12,7 +12,3 @@ // for prelude-like modules #[rustfmt::skip] pub mod prelude; - -pub mod irq; -pub mod qdev; -pub mod sysbus; diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs index 9e9d1c8247..8db56f9f81 100644 --- a/rust/qemu-api/src/prelude.rs +++ b/rust/qemu-api/src/prelude.rs @@ -3,7 +3,3 @@ // SPDX-License-Identifier: GPL-2.0-or-later =20 //! Commonly used traits and types for QEMU. - -pub use crate::qdev::DeviceMethods; - -pub use crate::sysbus::SysBusDeviceMethods; --=20 2.50.1