From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86150CCD1BF for ; Tue, 28 Oct 2025 10:20:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDgoo-0005sd-M4; Tue, 28 Oct 2025 06:20:48 -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 1vDgoE-0005aH-Ch for qemu-rust@nongnu.org; Tue, 28 Oct 2025 06:20:15 -0400 Received: from sg-1-12.ptr.blmpb.com ([118.26.132.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vDgo1-0001sD-Lu for qemu-rust@nongnu.org; Tue, 28 Oct 2025 06:20:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=s1; d=openatom-club.20200927.dkim.feishu.cn; t=1761646715; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=OH4Oe6W5Z3AuH260sYJtxczopVvleZqTZ9FAidoBgIU=; b=WYGu2G5J3L6Z3dWl7RkIibIsC0uG3hxjWY3D/kz4hAn8/ppOIkoLfs7rG+EN4/vFcUcWWu AuEwDeCz5uiwUC0NFWAyAEjRfbZy0HKHS8RD2aRG5M1lgxyzy0ObHAGK1S7h4p9S26xEHT J2VHsFzRqA6G+YcSEIG0fa0C5dl6Ea6uGt2epWVibBjT5EyfpKkdFdKmbLms2w1Qp6WmNK DwmTN5I3MXY13lNy7EERKm54lCHHfKsKG2kYNHxOFRsxvNpO2fO/CnGFbPBk1GyE77/XFs 3XnLWyx112ftw3ZvPkCwR+N7iaW+5R9Ni0Kvs9a3JncXm5qXmUd5zWshJG/pig== Cc: , , , Received: from nyaos.localdomain ([114.249.194.57]) by smtp.feishu.cn with ESMTPS; Tue, 28 Oct 2025 18:18:32 +0800 X-Mailer: git-send-email 2.43.0 From: "chenmiao" Message-Id: <12c58ca355cd04d7157e4c20f074683abfe14e7c.1761644606.git.chenmiao@openatom.club> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 Subject: [RFC PATCH v2 1/5] rust/hw/core: Add the BusState of rust version Date: Tue, 28 Oct 2025 10:18:25 +0000 X-Original-From: chenmiao To: , , , , Mime-Version: 1.0 X-Lms-Return-Path: Received-SPF: pass client-ip=118.26.132.12; envelope-from=chenmiao@openatom.club; helo=sg-1-12.ptr.blmpb.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-rust-bounces+qemu-rust=archiver.kernel.org@nongnu.org Sender: qemu-rust-bounces+qemu-rust=archiver.kernel.org@nongnu.org A Rust version implementation has been designed for BusState, which will be used for the subsequent I2CBus implementation. Signed-off-by: chenmiao Signed-off-by: Chao Liu --- Changes in V2: - Rename the BusMethods and add some Safety comment. - Remove the unnecessary realize function. --- rust/hw/core/meson.build | 1 + rust/hw/core/src/bus.rs | 44 ++++++++++++++++++++++++++++++++++++++++ rust/hw/core/src/lib.rs | 3 +++ 3 files changed, 48 insertions(+) create mode 100644 rust/hw/core/src/bus.rs diff --git a/rust/hw/core/meson.build b/rust/hw/core/meson.build index 1560dd20c6..efcda50fef 100644 --- a/rust/hw/core/meson.build +++ b/rust/hw/core/meson.build @@ -50,6 +50,7 @@ _hwcore_rs = static_library( [ 'src/lib.rs', 'src/bindings.rs', + 'src/bus.rs', 'src/irq.rs', 'src/qdev.rs', 'src/sysbus.rs', diff --git a/rust/hw/core/src/bus.rs b/rust/hw/core/src/bus.rs new file mode 100644 index 0000000000..d3fbf519d4 --- /dev/null +++ b/rust/hw/core/src/bus.rs @@ -0,0 +1,44 @@ +// Copyright 2025 HUST OpenAtom Open Source Club. +// Author(s): Chen Miao +// SPDX-License-Identifier: GPL-2.0-or-later + +use std::ffi::CStr; + +pub use bindings::BusClass; +use common::Opaque; +use qom::{qom_isa, IsA, Object, ObjectDeref, ObjectType}; + +use crate::{bindings, DeviceImpl}; + +#[repr(transparent)] +#[derive(Debug, common::Wrapper)] +pub struct BusState(Opaque); + +unsafe impl Send for BusState {} +unsafe impl Sync for BusState {} + +unsafe impl ObjectType for BusState { + type Class = BusClass; + const TYPE_NAME: &'static std::ffi::CStr = + unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_BUS) }; +} + +qom_isa!(BusState: Object); + +pub trait BusStateImpl: DeviceImpl + IsA {} + +impl BusClass { + pub fn class_init(self: &mut BusClass) { + self.parent_class.class_init::(); + } +} + +pub trait BusMethods: ObjectDeref +where + Self::Target: IsA, +{ + // TODO: Since the bus does not currently provide services to other + // components, we have not implemented any functions yet. +} + +impl BusMethods for R where R::Target: IsA {} diff --git a/rust/hw/core/src/lib.rs b/rust/hw/core/src/lib.rs index b40801eb84..10cc516664 100644 --- a/rust/hw/core/src/lib.rs +++ b/rust/hw/core/src/lib.rs @@ -13,3 +13,6 @@ mod sysbus; pub use sysbus::*; + +mod bus; +pub use bus::*; -- 2.43.0