From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from LO2P265CU024.outbound.protection.outlook.com (mail-uksouthazon11021114.outbound.protection.outlook.com [52.101.95.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD1B1430CD5; Mon, 6 Jul 2026 12:44:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.95.114 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783341881; cv=fail; b=XiqMt/rp4YItptvYiP9t9mUwsRzsO08OidxgiQfQ0jmj+5DrJ4GQyJQDa29q7qQlQgsOlr0nrWiHD5alSXyJu8XgxfG46XXM3QR2fMXoUGjD+q/cW4lrvIpE9AqSTLKTOsCDp+Zt5S/3W1ep0yPCmVjEiwMfoOQvog7SELiz5gk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783341881; c=relaxed/simple; bh=F5bGCqFkVx5u0fZSyaG/xN6wOWqT7osen1PoYUXenCc=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=UlA+s6T0MWae7Ls2gfj0Y2RMNJqz3qTet6LJ+B5V8+XgtO389jIWrzwzJHv68wkoMNCPnW3uVmcSCpwu4qj945IYHYw16KA4XP7ILsQdAmcECBTXKhva3C5wKT8PdY5+3qNacUt3S89Gwe7DE1Vl3PXtilziV6lhcAcjc52jqrA= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b=Mh4yebiY; arc=fail smtp.client-ip=52.101.95.114 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b="Mh4yebiY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TKJdzU3x3rpDE85LZIYJoydeNP1o438S34pQ0urghFz/6UnD7r4dvTH2EzY5PG0Xe/lXOcRjuYl+CTR1cQBfPB+ydyrY7u01DkhOWnPB/NBD/8LND4L3j7HDYFpL3+zSq2eBtwwgilsolYDExUuAzKI4ocvNR2UFer0Z6FyQREPNMcoWxkRnEQdPSOr5RhqrNBiUSyJpvPkLDGzY8PaFwU4xcTU6DZFYdcN48W4Ex64vOumOPSUgzNyUvLK4O/bjbGIce0b66OmUHzBJbtHFANtaEf0n67vnEzSOaLObdmSmDxCTfg6o8AqAGTeMJEyYhUaJDY324sZazEOEBa3v5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3mexKlJxPHt69pUM8edn80nNxxWqmpkg22miiWh9UYI=; b=CVTSFhPjpvT9QpmQW9OA1QNhv0rt4ltsgqbJo7sldNAD3PrQssEdynkrW0gcGURdtKa+RCAju84glgB3SJYRRARjin2Nm1SqHD0+IDVNZQofYv5IkIyQuZiqShoPZ5yzzSQJ4SSyIsU2HVw4mr/gg7ieVEmg9ffQyCwtkkMQOA9h518huXoMVgN3OiUEf0VO9fqII545lq3C0JOBcMy3vXi29bjeeq4ZriTiokO6F8p/CQqdfR+44Q+DldC2oqbraMcw4rxdYhaLcDK1BKh8nkRDOVjFPL0bBckNk/+nct1nAtG3P6FwLm4vn4+fO/kjgfBV50sWAMj4jmrbSVpSNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3mexKlJxPHt69pUM8edn80nNxxWqmpkg22miiWh9UYI=; b=Mh4yebiYB6l9BsQcUOkuTO5+JjDa5g5GqLxkcT1L0fJrUvJK4GaCV+NSENshNlQOSVhbLNL7f8k7lBaqoIK8beOq/K/u6eNkFiVzjr3oriy98LxPSHmQMEPHG3rVXX7ae2Vmify+Q6sSeFJLoRCofCOi2yrG4HcS2dszzwu1z98= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) by LO7P265MB7617.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:40c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.10; Mon, 6 Jul 2026 12:44:26 +0000 Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986]) by LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986%4]) with mapi id 15.21.0181.008; Mon, 6 Jul 2026 12:44:26 +0000 From: Gary Guo Date: Mon, 06 Jul 2026 13:44:17 +0100 Subject: [PATCH v6 04/20] rust: io: implement `Io` on reference types instead Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260706-io_projection-v6-4-72cd5d055d54@garyguo.net> References: <20260706-io_projection-v6-0-72cd5d055d54@garyguo.net> In-Reply-To: <20260706-io_projection-v6-0-72cd5d055d54@garyguo.net> To: Alice Ryhl , Daniel Almeida , Greg Kroah-Hartman , "Rafael J. Wysocki" , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Tamir Duberstein , =?utf-8?q?Onur_=C3=96zkan?= , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Abdiel Janulgue , Robin Murphy , Alexandre Courbot , David Airlie , Simona Vetter , Michal Wilczynski , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Cc: Danilo Krummrich , driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-pwm@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1783341863; l=16372; i=gary@garyguo.net; s=20221204; h=from:subject:message-id; bh=F5bGCqFkVx5u0fZSyaG/xN6wOWqT7osen1PoYUXenCc=; b=YD+3k30uCSSZ4blIJWfRKpTJFnYiHrYRnJv7zhVATGUSGfnriSEUMprAQ3tyF/AQtSvHKjH7w zqeJwVjE+FyAkqnVX6dt0d0evNNfdtDEuq6tsdSqFjwRtiA9WA6szX0 X-Developer-Key: i=gary@garyguo.net; a=ed25519; pk=vB3uIX95SM4eVrIqo1DWNWKDKD2xzB+yLLLr0yOPYMo= X-ClientProxiedBy: LO4P265CA0177.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:312::20) To LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LOVP265MB8871:EE_|LO7P265MB7617:EE_ X-MS-Office365-Filtering-Correlation-Id: dff11e40-bb54-4525-51ce-08dedb5c5049 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|7416014|10070799003|18002099003|921020|5023799004|6133799003|56012099006|22082099003; X-Microsoft-Antispam-Message-Info: CADHAevmwL7U014Ru8OWKPTm31M+J+5bZd7uiYPrZTbUO1Mtw4PQY/LNodxEGpK07eRwEb77xmQ+nFhUJum8xQlFLhe0NEePOpB2zg8+i7KUVX6QMjgfF5lk62RiaBlSpH/UBeYZyJHKAmuT2dryOvhaZRYCjWTwNa2reHlce+gsR0/+A7PuVYP9pwaqgiPpB0pIw+pXqveMyn0j4s0aMt6k/FP025RAKPi5+t36vPG9LJc28mjrfcrtWUEudY5uNMp5WMUyCheffypcpqG216pOb8TxbHu/gSBqCE+gkTdnIDlKx4q6R4mxlmoq55URRqHDfuHDqAGvHsxgZQlPvBmF+LL1cWbFYRCLEWRun/h6/CCzahxAmZhxAQUl//yfBLjvmufmOSp7q4vSkuTzfufz8hwrlm8FSqE5owpIsrvg1GFM/CXI1YkRqm+pkYdtZBI52zysak4lhYLjheJtg+UeSnQDBn2mzQY4Tub95It/gcICs2b/vswmwes1pgKDraKL3QO8bEOGxJl4r3raXyn79+N/a+nQAyNgcrg9rMjTd9xTiTV4GXmuEV4wDvYpb5D8WNhugpH84Lc5iF743S9OAjQwojzHmGAJg+98gXIZmgTYYbo/5RFotLHhtupxkt8vv8F4+KVL0UlTl7dSFVdZkD4OE7Gqv9UWMZ8mVyUyv4wwyai3S1MDKzETfPabELe4bFrgA+Rf5ifTKjOxiA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(7416014)(10070799003)(18002099003)(921020)(5023799004)(6133799003)(56012099006)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OHUxWUErNXp6WjVXbVo2R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VnFTajYyb1Ew?= =?utf-8?B?TFFZcVBCVGVCcWljT05FR2N3dW94Z1gyMVBkRGtYME5hd0hLdU1PSUh4R2h6?= =?utf-8?B?Um9vRGN0Z3J4WVp6dkhtUDVtL3hNUGZrWFpBUGFsS0ZJQVI1RTNHRW5NKzdk?= =?utf-8?B?cG1xcDhVZEVrZTMrZ3VFVDhETXNibHgzK3ZjUU43a3Z2OVp0Y2FQMmVFQkpI?= =?utf-8?B?eVFkV3p0bGdLTUorVFBmdVNNS2RpQmRoOFpGSUVzYmNUaHpVWWxrVjFQdXN6?= =?utf-8?B?TFFsckdDdHdoZG9KOHJEd3dBcmZCQzFrSXE4eUtoTUJYclcxckl6MmVsYmUr?= =?utf-8?B?eXhsa3M1RjN6VnBYblZVWTduTCtSMHNUN3dTTlJWY0xTRVZTVXdBeE9ZTHFu?= =?utf-8?B?Q3RkTUxDdUN4TkJHUWVPTGZ4L0ZvUld4Qm9ndjlYaWVacE4vRXBvZFVJRUxS?= =?utf-8?B?TFFaYVI3bER2ZGpxc0FaYm14aGF6TlJmTEVUTHNjbkZLMCtSVFJNanRHOUFl?= =?utf-8?B?N2UwbjJWWEtMTlhYVDZHclpQTHBFREg5ejVTUkdML3hQRUp1UWx5UT09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: dff11e40-bb54-4525-51ce-08dedb5c5049 X-MS-Exchange-CrossTenant-AuthSource: LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2026 12:44:26.4491 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RfiLHI8SxUxjksFV4PucrswAWTqr3i/SyNU7/2y3j1VrKKf6sU+9oh3lA9lgbmEkV9v0mBh14YJXGlbfjwkDOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO7P265MB7617 Currently, `Io` is implemented on owned I/O objects (e.g. `Bar`). This is going to change with I/O projections, as then `Io` needs to work both for owned objects and views of them. Views are themselves reference-like (however they obviously cannot be references, because they belong to a different address space). To facilitate the change, change `Io` to be implemented on reference types for the owned I/O objects, and make methods take `self` instead of `&self`. When I/O views are implemented, we can then naturally implement `Io` for these objects. Reviewed-by: Alexandre Courbot Signed-off-by: Gary Guo --- rust/kernel/io.rs | 82 ++++++++++++++++++++++++++------------------------- rust/kernel/pci/io.rs | 12 ++++---- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs index 87141eb07056..9f060dd29182 100644 --- a/rust/kernel/io.rs +++ b/rust/kernel/io.rs @@ -223,7 +223,7 @@ pub trait IoCapable { /// /// - The range `[address..address + size_of::()]` must be within the bounds of `Self`. /// - `address` must be aligned. - unsafe fn io_read(&self, address: usize) -> T; + unsafe fn io_read(self, address: usize) -> T; /// Performs an I/O write of `value` at `address`. /// @@ -231,7 +231,7 @@ pub trait IoCapable { /// /// - The range `[address..address + size_of::()]` must be within the bounds of `Self`. /// - `address` must be aligned. - unsafe fn io_write(&self, value: T, address: usize); + unsafe fn io_write(self, value: T, address: usize); } /// Describes a given I/O location: its offset, width, and type to convert the raw value from and @@ -294,25 +294,27 @@ fn offset(self) -> usize { /// Which I/O methods are available depends on which [`IoCapable`] traits /// are implemented for the type. /// +/// This should be implemented on cheaply copyable handles, such as references or view types. +/// /// # Examples /// /// For MMIO regions, all widths (u8, u16, u32, and u64 on 64-bit systems) are typically /// supported. For PCI configuration space, u8, u16, and u32 are supported but u64 is not. -pub trait Io { +pub trait Io: Copy { /// Type of this I/O region. For untyped regions, [`Region`] can be used. type Target: ?Sized + KnownSize; /// Returns the base address of this mapping. - fn addr(&self) -> usize; + fn addr(self) -> usize; /// Returns the maximum size of this mapping. - fn maxsize(&self) -> usize; + fn maxsize(self) -> usize; /// Returns the absolute I/O address for a given `offset`, /// performing compile-time bound checks. // Always inline to optimize out error path of `build_assert`. #[inline(always)] - fn io_addr_assert(&self, offset: usize) -> usize { + fn io_addr_assert(self, offset: usize) -> usize { // We cannot check alignment with `offset_valid` using `self.addr()`. So set 0 for it and // ensure alignment by checking that the alignment of `U` is smaller or equal to the // alignment of `Self::Target`. @@ -325,7 +327,7 @@ fn io_addr_assert(&self, offset: usize) -> usize { /// Returns the absolute I/O address for a given `offset`, /// performing runtime bound checks. #[inline] - fn io_addr(&self, offset: usize) -> Result { + fn io_addr(self, offset: usize) -> Result { if !offset_valid::(self.addr(), offset, self.maxsize()) { return Err(EINVAL); } @@ -337,7 +339,7 @@ fn io_addr(&self, offset: usize) -> Result { /// Fallible 8-bit read with runtime bounds check. #[inline(always)] - fn try_read8(&self, offset: usize) -> Result + fn try_read8(self, offset: usize) -> Result where usize: IoLoc, Self: IoCapable, @@ -347,7 +349,7 @@ fn try_read8(&self, offset: usize) -> Result /// Fallible 16-bit read with runtime bounds check. #[inline(always)] - fn try_read16(&self, offset: usize) -> Result + fn try_read16(self, offset: usize) -> Result where usize: IoLoc, Self: IoCapable, @@ -357,7 +359,7 @@ fn try_read16(&self, offset: usize) -> Result /// Fallible 32-bit read with runtime bounds check. #[inline(always)] - fn try_read32(&self, offset: usize) -> Result + fn try_read32(self, offset: usize) -> Result where usize: IoLoc, Self: IoCapable, @@ -367,7 +369,7 @@ fn try_read32(&self, offset: usize) -> Result /// Fallible 64-bit read with runtime bounds check. #[inline(always)] - fn try_read64(&self, offset: usize) -> Result + fn try_read64(self, offset: usize) -> Result where usize: IoLoc, Self: IoCapable, @@ -377,7 +379,7 @@ fn try_read64(&self, offset: usize) -> Result /// Fallible 8-bit write with runtime bounds check. #[inline(always)] - fn try_write8(&self, value: u8, offset: usize) -> Result + fn try_write8(self, value: u8, offset: usize) -> Result where usize: IoLoc, Self: IoCapable, @@ -387,7 +389,7 @@ fn try_write8(&self, value: u8, offset: usize) -> Result /// Fallible 16-bit write with runtime bounds check. #[inline(always)] - fn try_write16(&self, value: u16, offset: usize) -> Result + fn try_write16(self, value: u16, offset: usize) -> Result where usize: IoLoc, Self: IoCapable, @@ -397,7 +399,7 @@ fn try_write16(&self, value: u16, offset: usize) -> Result /// Fallible 32-bit write with runtime bounds check. #[inline(always)] - fn try_write32(&self, value: u32, offset: usize) -> Result + fn try_write32(self, value: u32, offset: usize) -> Result where usize: IoLoc, Self: IoCapable, @@ -407,7 +409,7 @@ fn try_write32(&self, value: u32, offset: usize) -> Result /// Fallible 64-bit write with runtime bounds check. #[inline(always)] - fn try_write64(&self, value: u64, offset: usize) -> Result + fn try_write64(self, value: u64, offset: usize) -> Result where usize: IoLoc, Self: IoCapable, @@ -417,7 +419,7 @@ fn try_write64(&self, value: u64, offset: usize) -> Result /// Infallible 8-bit read with compile-time bounds check. #[inline(always)] - fn read8(&self, offset: usize) -> u8 + fn read8(self, offset: usize) -> u8 where usize: IoLoc, Self: IoCapable, @@ -427,7 +429,7 @@ fn read8(&self, offset: usize) -> u8 /// Infallible 16-bit read with compile-time bounds check. #[inline(always)] - fn read16(&self, offset: usize) -> u16 + fn read16(self, offset: usize) -> u16 where usize: IoLoc, Self: IoCapable, @@ -437,7 +439,7 @@ fn read16(&self, offset: usize) -> u16 /// Infallible 32-bit read with compile-time bounds check. #[inline(always)] - fn read32(&self, offset: usize) -> u32 + fn read32(self, offset: usize) -> u32 where usize: IoLoc, Self: IoCapable, @@ -447,7 +449,7 @@ fn read32(&self, offset: usize) -> u32 /// Infallible 64-bit read with compile-time bounds check. #[inline(always)] - fn read64(&self, offset: usize) -> u64 + fn read64(self, offset: usize) -> u64 where usize: IoLoc, Self: IoCapable, @@ -457,7 +459,7 @@ fn read64(&self, offset: usize) -> u64 /// Infallible 8-bit write with compile-time bounds check. #[inline(always)] - fn write8(&self, value: u8, offset: usize) + fn write8(self, value: u8, offset: usize) where usize: IoLoc, Self: IoCapable, @@ -467,7 +469,7 @@ fn write8(&self, value: u8, offset: usize) /// Infallible 16-bit write with compile-time bounds check. #[inline(always)] - fn write16(&self, value: u16, offset: usize) + fn write16(self, value: u16, offset: usize) where usize: IoLoc, Self: IoCapable, @@ -477,7 +479,7 @@ fn write16(&self, value: u16, offset: usize) /// Infallible 32-bit write with compile-time bounds check. #[inline(always)] - fn write32(&self, value: u32, offset: usize) + fn write32(self, value: u32, offset: usize) where usize: IoLoc, Self: IoCapable, @@ -487,7 +489,7 @@ fn write32(&self, value: u32, offset: usize) /// Infallible 64-bit write with compile-time bounds check. #[inline(always)] - fn write64(&self, value: u64, offset: usize) + fn write64(self, value: u64, offset: usize) where usize: IoLoc, Self: IoCapable, @@ -518,7 +520,7 @@ fn write64(&self, value: u64, offset: usize) /// } /// ``` #[inline(always)] - fn try_read(&self, location: L) -> Result + fn try_read(self, location: L) -> Result where L: IoLoc, Self: IoCapable, @@ -552,7 +554,7 @@ fn try_read(&self, location: L) -> Result /// } /// ``` #[inline(always)] - fn try_write(&self, location: L, value: T) -> Result + fn try_write(self, location: L, value: T) -> Result where L: IoLoc, Self: IoCapable, @@ -598,7 +600,7 @@ fn try_write(&self, location: L, value: T) -> Result /// } /// ``` #[inline(always)] - fn try_write_reg(&self, value: V) -> Result + fn try_write_reg(self, value: V) -> Result where L: IoLoc, V: LocatedRegister, @@ -631,7 +633,7 @@ fn try_write_reg(&self, value: V) -> Result /// } /// ``` #[inline(always)] - fn try_update(&self, location: L, f: F) -> Result + fn try_update(self, location: L, f: F) -> Result where L: IoLoc, Self: IoCapable, @@ -670,7 +672,7 @@ fn try_update(&self, location: L, f: F) -> Result /// } /// ``` #[inline(always)] - fn read(&self, location: L) -> T + fn read(self, location: L) -> T where L: IoLoc, Self: IoCapable, @@ -702,7 +704,7 @@ fn read(&self, location: L) -> T /// } /// ``` #[inline(always)] - fn write(&self, location: L, value: T) + fn write(self, location: L, value: T) where L: IoLoc, Self: IoCapable, @@ -745,7 +747,7 @@ fn write(&self, location: L, value: T) /// } /// ``` #[inline(always)] - fn write_reg(&self, value: V) + fn write_reg(self, value: V) where L: IoLoc, V: LocatedRegister, @@ -778,7 +780,7 @@ fn write_reg(&self, value: V) /// } /// ``` #[inline(always)] - fn update(&self, location: L, f: F) + fn update(self, location: L, f: F) where L: IoLoc, Self: IoCapable, @@ -799,13 +801,13 @@ fn update(&self, location: L, f: F) macro_rules! impl_mmio_io_capable { ($mmio:ident, $(#[$attr:meta])* $ty:ty, $read_fn:ident, $write_fn:ident) => { $(#[$attr])* - impl IoCapable<$ty> for $mmio { - unsafe fn io_read(&self, address: usize) -> $ty { + impl IoCapable<$ty> for &$mmio { + unsafe fn io_read(self, address: usize) -> $ty { // SAFETY: By the trait invariant `address` is a valid address for MMIO operations. unsafe { bindings::$read_fn(address as *const c_void) } } - unsafe fn io_write(&self, value: $ty, address: usize) { + unsafe fn io_write(self, value: $ty, address: usize) { // SAFETY: By the trait invariant `address` is a valid address for MMIO operations. unsafe { bindings::$write_fn(value, address as *mut c_void) } } @@ -826,18 +828,18 @@ unsafe fn io_write(&self, value: $ty, address: usize) { writeq ); -impl Io for Mmio { +impl<'a, const SIZE: usize> Io for &'a Mmio { type Target = Region; /// Returns the base address of this mapping. #[inline] - fn addr(&self) -> usize { + fn addr(self) -> usize { self.0.addr() } /// Returns the maximum size of this mapping. #[inline] - fn maxsize(&self) -> usize { + fn maxsize(self) -> usize { self.0.maxsize() } } @@ -864,16 +866,16 @@ pub unsafe fn from_raw(raw: &MmioRaw) -> &Self { #[repr(transparent)] pub struct RelaxedMmio(Mmio); -impl Io for RelaxedMmio { +impl<'a, const SIZE: usize> Io for &'a RelaxedMmio { type Target = Region; #[inline] - fn addr(&self) -> usize { + fn addr(self) -> usize { self.0.addr() } #[inline] - fn maxsize(&self) -> usize { + fn maxsize(self) -> usize { self.0.maxsize() } } diff --git a/rust/kernel/pci/io.rs b/rust/kernel/pci/io.rs index b4996aa059d8..505305cd9b86 100644 --- a/rust/kernel/pci/io.rs +++ b/rust/kernel/pci/io.rs @@ -79,8 +79,8 @@ pub struct ConfigSpace<'a, S: ?Sized + ConfigSpaceKind = Extended> { /// Implements [`IoCapable`] on [`ConfigSpace`] for `$ty` using `$read_fn` and `$write_fn`. macro_rules! impl_config_space_io_capable { ($ty:ty, $read_fn:ident, $write_fn:ident) => { - impl<'a, S: ?Sized + ConfigSpaceKind> IoCapable<$ty> for ConfigSpace<'a, S> { - unsafe fn io_read(&self, address: usize) -> $ty { + impl<'a, S: ?Sized + ConfigSpaceKind> IoCapable<$ty> for &ConfigSpace<'a, S> { + unsafe fn io_read(self, address: usize) -> $ty { let mut val: $ty = 0; // Return value from C function is ignored in infallible accessors. @@ -94,7 +94,7 @@ unsafe fn io_read(&self, address: usize) -> $ty { val } - unsafe fn io_write(&self, value: $ty, address: usize) { + unsafe fn io_write(self, value: $ty, address: usize) { // Return value from C function is ignored in infallible accessors. let _ret = // SAFETY: By the type invariant `self.pdev` is a valid address. @@ -112,18 +112,18 @@ unsafe fn io_write(&self, value: $ty, address: usize) { impl_config_space_io_capable!(u16, pci_read_config_word, pci_write_config_word); impl_config_space_io_capable!(u32, pci_read_config_dword, pci_write_config_dword); -impl<'a, S: ?Sized + ConfigSpaceKind> Io for ConfigSpace<'a, S> { +impl<'a, S: ?Sized + ConfigSpaceKind> Io for &ConfigSpace<'a, S> { type Target = S; /// Returns the base address of the I/O region. It is always 0 for configuration space. #[inline] - fn addr(&self) -> usize { + fn addr(self) -> usize { 0 } /// Returns the maximum size of the configuration space. #[inline] - fn maxsize(&self) -> usize { + fn maxsize(self) -> usize { self.pdev.cfg_size().into_raw() } } -- 2.54.0