From nobody Tue Dec 24 04:52:29 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734705093; cv=none; d=zohomail.com; s=zohoarc; b=b5iEl8z+Ia5xt+8NY/FwWfaOxsplUa8mTjKM3QzTtZFOaQ0SDI6Ej6rR/r7RGXJ7ANBmzN3A3u0xHu7ZODmyenLnUZr8B5yCPEr7p75HugvlpPVAYNzIYKqr4VmRe6mpW9RAuy5N/soEY/78HCiek/iQNdaKe9HDOWhzbcqoptY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734705093; h=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=oLxf8SYyc8CAW4GO5JtinxFGsZxKuKqfgDppOT1xqOU=; b=bilaFIUREgAtjQpKh1qExmHxdTfIQscBJTQXqGlGhHUKXOAC6w1zmDmusZ0b8V4mypvMR6F0/OeVpUDXuIs1kZ9jxImMAuk/fyj3swg4iSestxt6EsNNOgYNDcIPhm782HeE5LD3jyjn8/xp7ON0Iq4ffGdpCiWN/I8jIrqtyVA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734705093217408.7779124923567; Fri, 20 Dec 2024 06:31:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOe1V-0004UG-1p; Fri, 20 Dec 2024 09:30:37 -0500 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 1tOe1N-0004SA-Lb for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOe1K-0006bF-SN for qemu-devel@nongnu.org; Fri, 20 Dec 2024 09:30:28 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-Qf08Vmz2PMOv96ystZmCyQ-1; Fri, 20 Dec 2024 09:30:21 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361a8fc3bdso11135455e9.2 for ; Fri, 20 Dec 2024 06:30:21 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c8a6abesm4186372f8f.90.2024.12.20.06.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2024 06:30:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734705026; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oLxf8SYyc8CAW4GO5JtinxFGsZxKuKqfgDppOT1xqOU=; b=Y8k9W6zO5586ykU6BdGydZnLEKMbaTIZ7z2gQDUW0IcmZ8mF2be1xAU/YoOYmUgEhYyKwl 7YV6LKWVXAq+pChZ8MkTOjl5Eil5C4isNthct1vMSTCzsvWNTf7C3AFLDn065sf8eULZ6g 9xUDASF7PEyUl39l4am9qj8iXITCtng= X-MC-Unique: Qf08Vmz2PMOv96ystZmCyQ-1 X-Mimecast-MFC-AGG-ID: Qf08Vmz2PMOv96ystZmCyQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734705020; x=1735309820; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oLxf8SYyc8CAW4GO5JtinxFGsZxKuKqfgDppOT1xqOU=; b=Jnym0RuAmTeZ4BEC5lbBsGxri8CWBcdJRiNCwUQS67/nIdUGfhCb7d2Oqq/S/Y/isX N7GBBt4iWTqKThs+UIyANitByKRK/GJ+ct8PA8yntMioQQSgVUtnyOniXQsFL/GtL9Xx FR27BsWuqrLhsnQGPbPeMjuVIzZsqueWVtC8mwWB8LQxbh1bhtxYD5nu56PLnzRAIdvV BjZkq+fqR4IR/OpPlgSQn/9ZMpkF811qJCXeJc7CycHzfA1g+BP/gfCyBZA+3UR9Ng4f UBOIHJZsbPatiuJQHJUQoagfReHQRp53gAL9WmglHiTMxlR2c9K2oByoCKvhcXMdOMBU 7FnQ== X-Gm-Message-State: AOJu0YzglDfwPxa9Vp4h9k6fEHx3v1MKFGboevyDc7M7vtY9tnnLz/Oh 84Z/XWZrayc2ofX9O9fZiu0fH3+1t51WX9YLtj435cd2LMtr1N8idklRwRBaQ1xOZR9WmtjGK/h fKvRwEq4RxGz2bpO6NBrsvUa6IY62YDWpDTLxnTlB0qhkNy2zSZdrJj3T6kFxvQgn9vH6/WJPx9 WmYIsVKZM/WAE4kkktiYKKu6EUjHvXhqF7q3n4 X-Gm-Gg: ASbGncsI1VyOsBWLNYdL2uTePlo1LJngWlpCzXqjNgACLm9oNatG3bHoYEP+lQzv2dc QKm0Lny5zb0fJ63cwWN5YRht6h/8KGFZR49VsrpiarbrlUboc+1h30RhG6gC/CiH3elOILwC/tD fpNVO30WvskP3bUxyvOTsj5CpmVtQYH5vdBOO1S3L/d3MWBfTM+83u0INR8iXZvMSRjLg2ATqqR 1eCU5UX/35SxN2LZy+B1Y3tAfYDmRUqJXz/28p2hOVLXDFR5edCanH7jNRy X-Received: by 2002:a05:600c:4f09:b0:434:a711:ace4 with SMTP id 5b1f17b1804b1-4366864636dmr28668225e9.17.1734705019643; Fri, 20 Dec 2024 06:30:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+NnV0YF5Sr7YZ3y8TjPcAqyNNQXLBS8X8FBLy35qksVx98k94lBzfvCM1SFQ8v9Rv56x/0w== X-Received: by 2002:a05:600c:4f09:b0:434:a711:ace4 with SMTP id 5b1f17b1804b1-4366864636dmr28667835e9.17.1734705019127; Fri, 20 Dec 2024 06:30:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: zhao1.liu@intel.com, junjie.mao@hotmail.com Subject: [PATCH 09/12] rust: qdev: expose inherited methods to subclasses of SysBusDevice Date: Fri, 20 Dec 2024 15:29:51 +0100 Message-ID: <20241220142955.652636-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220142955.652636-1-pbonzini@redhat.com> References: <20241220142955.652636-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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_H2=-1.129, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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-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: 1734705094969116600 Content-Type: text/plain; charset="utf-8" The ObjectDeref trait now provides all the magic that is required to fake inheritance. Replace the "impl SysBusDevice" block of qemu_api::sysbus with a trait, so that sysbus_init_irq() can be invoked as "self.init_irq()" without any intermediate upcast. Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 6 ++---- rust/qemu-api/src/irq.rs | 3 +-- rust/qemu-api/src/prelude.rs | 2 ++ rust/qemu-api/src/sysbus.rs | 17 +++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index 6792d13fb77..994c2fc0593 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -207,11 +207,9 @@ unsafe fn init(&mut self) { } =20 fn post_init(&self) { - let sbd: &SysBusDevice =3D self.upcast(); - - sbd.init_mmio(&self.iomem); + self.init_mmio(&self.iomem); for irq in self.interrupts.iter() { - sbd.init_irq(irq); + self.init_irq(irq); } } =20 diff --git a/rust/qemu-api/src/irq.rs b/rust/qemu-api/src/irq.rs index 6258141bdf0..378e5202951 100644 --- a/rust/qemu-api/src/irq.rs +++ b/rust/qemu-api/src/irq.rs @@ -24,8 +24,7 @@ /// /// 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 -/// [`SysBusDevice::init_irq`](crate::sysbus::SysBusDevice::init_irq), and +/// a function such as [`SysBusDeviceMethods::init_irq`], and /// initially leaves the pointer to a NULL value, representing an unconnec= ted /// interrupt. To connect it, whoever creates the device fills the pointer= with /// the sink's `IRQState *`, for example using `sysbus_connect_irq`. Beca= use diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs index 6f32deeb2ed..4ea70b9c823 100644 --- a/rust/qemu-api/src/prelude.rs +++ b/rust/qemu-api/src/prelude.rs @@ -16,3 +16,5 @@ pub use crate::qom::ObjectType; =20 pub use crate::qom_isa; + +pub use crate::sysbus::SysBusDeviceMethods; diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs index b96eaaf25f2..e6762b5c145 100644 --- a/rust/qemu-api/src/sysbus.rs +++ b/rust/qemu-api/src/sysbus.rs @@ -32,18 +32,17 @@ fn class_init(sdc: &mut SysBusDeviceClass) { } } =20 -impl SysBusDevice { - /// Return `self` cast to a mutable pointer, for use in calls to C cod= e. - const fn as_mut_ptr(&self) -> *mut SysBusDevice { - addr_of!(*self) as *mut _ - } - +/// Trait for methods of [`SysBusDevice`] and its subclasses. +pub trait SysBusDeviceMethods: ObjectDeref +where + Self::Target: IsA, +{ /// Expose a memory region to the board so that it can give it an addr= ess /// in guest memory. Note that the ordering of calls to `init_mmio` is /// important, since whoever creates the sysbus device will refer to t= he /// region with a number that corresponds to the order of calls to /// `init_mmio`. - pub fn init_mmio(&self, iomem: &bindings::MemoryRegion) { + fn init_mmio(&self, iomem: &bindings::MemoryRegion) { assert!(bql_locked()); unsafe { bindings::sysbus_init_mmio(self.as_mut_ptr(), addr_of!(*iomem)= as *mut _); @@ -54,10 +53,12 @@ pub fn init_mmio(&self, iomem: &bindings::MemoryRegion)= { /// Note that the ordering of calls to `init_irq` is important, since /// whoever creates the sysbus device will refer to the interrupts with /// a number that corresponds to the order of calls to `init_irq`. - pub fn init_irq(&self, irq: &InterruptSource) { + fn init_irq(&self, irq: &InterruptSource) { assert!(bql_locked()); unsafe { bindings::sysbus_init_irq(self.as_mut_ptr(), irq.as_ptr()); } } } + +impl SysBusDeviceMethods for R where R::Target: IsA {} --=20 2.47.1