From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from LO0P265CU003.outbound.protection.outlook.com (mail-uksouthazon11022092.outbound.protection.outlook.com [52.101.96.92]) (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 A40BD43D518; Thu, 11 Jun 2026 16:28:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.96.92 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781195319; cv=fail; b=dqxicXqgARM3TxbR5ELLPZjcLDdkysQp3Vo/ThrGz6IqJ7OEGQMrfKDsEqyqmyAbFb3xtV1RKPKfh0BKwUc1Wv1iWWaY85ut/BKGaidPfBFL6wUq4dC4EMpqfcoQdE4pycRaZdRleJAV04yH5qyAf9sznn15ffyuKK5IM6IJEmg= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781195319; c=relaxed/simple; bh=zAUmlpx7qRmpak2aPShtkQ1ta2dTWYwEkvis5uE7440=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=S9Z0CAbptBPaO3XYwc9GZxKq5zS2G/BwIm/gAYKe1RmwuPBABOW1UV1CN/duGa/+DYID/UpXNiVUXNz58u+EuU2iv/TfDZ7yH9CdKRbRAPiAWoK7bqfh2ApjAKGr3qyoYTE2aAP37h+znfHZrDWxR4AuGC+70RfyiSIu2vDEOII= 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=0iqTK8y3; arc=fail smtp.client-ip=52.101.96.92 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="0iqTK8y3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rl1FTEe0HOeBzXIMp8qfgDAfy8b3tIz0YzQchSHa2I9I43xEtE/yXrJNhBYI4NaHtYZzslms5vj8wFuEQU8MXkrzPyCKqzuzIC3yMY08vUtcdMtc0wHdh7Xll7lph6oUjyP0pvkeNS69ebYaPEAX4Mf2TdmhCm0F5DKVUPKDlVqfLRjPdRA+5bcrj/qi1HpEwu+6fleF1F7rdIY0xIIR2lRfy01U8tZZWw6VONClARpLhviVfUAExCXZl8+XknM36sNX9DV5n6ol6+eNKQoi7N+07dyXOvX+h6j7INjYcNJpwM3rUZjyvaZVyEmb2Ecok5YqL1g6P8ERh+BxBneE9w== 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=Pgr7srKWqQ5y9Ad7bmawsaDw59mKVPoPKoj87/Fi+4E=; b=wAtPQU9RYu09rVVwPArvh9Z+ErCWLKm/xKVSew1AbzQiki+JkyqVGj7JqheEhplQJx1MGnYq9Lo35f9Zx31hRYsAt5Fd7RupDxb2nqg9RUSYSS5DQJ/KEP0S8tSx4bbU1MT9ANz+paXVhD1QFa4FsZZQEaNeNzjjXDcQu3w69XHf9KKX3qedhsUaaBvlhHfzOXTEVkSmc2RsqnEQaBuoH6t3VY1VHPWY8kBhs3rKOX/UYF9At/HpDPM8bT7tKW61/e+kKk0F5lA4lH0YhRUTGV022D8sqde4BFZzKk0LncMZwEnAtspNOT5tOpEDJu0hMoUAaSU63Uf4wBbH/4J1MA== 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=Pgr7srKWqQ5y9Ad7bmawsaDw59mKVPoPKoj87/Fi+4E=; b=0iqTK8y3Bnep6JDL13XaFL/1NCOS0w8iTtKiInMJlkzQVHGC310qCODKq8yJgmXhb1SpirHN1Db4ClWglLg2Gu7hhAiJeKLRECdctMnT9GfscsJMVQHGp+SFwKxmxS+tcERYs5l7bU5ntCgYHg1bKR2AGGqKYtsp0fEfpzt3DYY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from CW1P265MB8877.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:27c::13) by LO2P265MB3263.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:156::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.13; Thu, 11 Jun 2026 16:28:25 +0000 Received: from CW1P265MB8877.GBRP265.PROD.OUTLOOK.COM ([fe80::6c9e:93c8:10db:e995]) by CW1P265MB8877.GBRP265.PROD.OUTLOOK.COM ([fe80::6c9e:93c8:10db:e995%6]) with mapi id 15.21.0113.011; Thu, 11 Jun 2026 16:28:25 +0000 From: Gary Guo Date: Thu, 11 Jun 2026 17:28:06 +0100 Subject: [PATCH v4 04/20] rust: io: implement `Io` on reference types instead Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260611-io_projection-v4-4-1f7224b02dcb@garyguo.net> References: <20260611-io_projection-v4-0-1f7224b02dcb@garyguo.net> In-Reply-To: <20260611-io_projection-v4-0-1f7224b02dcb@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 , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Abdiel Janulgue , Robin Murphy , Alexandre Courbot , David Airlie , Simona Vetter 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 X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1781195301; l=16076; i=gary@garyguo.net; s=20221204; h=from:subject:message-id; bh=zAUmlpx7qRmpak2aPShtkQ1ta2dTWYwEkvis5uE7440=; b=+MsbIQhEGGJURZCK0Jdt0IdZEkCam4LJw+6+gxZeEHa5GEZm9I2OV4qtae3ko3I4Q/sw+OoMO RfLW9564I9YCxffBesGd2Z1SgSJqzzky4lE7wjDIOqa2A3Fl64Af1U1 X-Developer-Key: i=gary@garyguo.net; a=ed25519; pk=vB3uIX95SM4eVrIqo1DWNWKDKD2xzB+yLLLr0yOPYMo= X-ClientProxiedBy: LO6P265CA0015.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:339::8) To CW1P265MB8877.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:27c::13) 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: CW1P265MB8877:EE_|LO2P265MB3263:EE_ X-MS-Office365-Filtering-Correlation-Id: 825ffc85-bbda-4c94-a41e-08dec7d675f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|1800799024|7416014|376014|366016|23010399003|18002099003|22082099003|921020|5023799004|6133799003|56012099006; X-Microsoft-Antispam-Message-Info: T37cbllAk+3ZfVwhUS9lx4eI5L2wM1cjx1E/lzogHSV5IYdJG1GTLBWbr+iawZuDrmdcrJ+umdg0C7f1Z22qYIsS3JrprLOuPkIsaujMWtSyp8ETBPjjnGt6p1O8RDQa342jnzndaGPvAJw2OZVbua/J+DlIu6ZYECEh5hsxCfCfHM+kKJOqIqii2lmXN4LsuJO/DgbBABAeqp2MSpUTMRSO1tcMVZYF4PURnwldUqzS4bj45tlSiRF5wC67QFF9RXYuJk5Wz0QOVcLxCw+toHjW9tHC/sLq+NH8z+r82ACrW4kKnnqpI2lp7j/UuG7nhEYZ1t4Uk0ieGyUGxtGEk4NHtZOxy6IPFax/i95CGPTHxkdiPOd6Rcvx9Pma4HpKoXAGCwb6IAMMWi2NGdMj3yI7ao5/yHVhksEULvbex9pGdUBPiV7SGReNDdiGZoQUbULH1nyLcvYyXXhb9v2pzRZnIYH8O1OGW+8g3WlaGyHGNEkH6TY7iu56JScG8RlL8YkX24QGUy6vXl44rchE/L1Tc7Oi3WAzQee2JN0ym9ydxbKLFlRg+rFbJaytann0BIttYafH2PBuzkoM3jaib5yCAP/M/C3qE9pkt6Hk665CMYeNNJJgdQAJs1VFC18LnzzPXVgl+J8ZPkJ5ppFcWsfVwZqW6k/K7TH8tP6G7ep8x/Apij1jYOsC5ccD5YJBoVJCkjtrS9POHayc5IS1bdqK9DDlSugUNZccO18jNho= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CW1P265MB8877.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(1800799024)(7416014)(376014)(366016)(23010399003)(18002099003)(22082099003)(921020)(5023799004)(6133799003)(56012099006);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bjdhQXYyTXJjMHRHM3N5ZG9PZ3NSczR5WFN1c2pzdGZkUW0rdEkx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VlhaOEE4S2Z6ZmMzL1QzdzdpK0FiSDl5Wk96ZGhhc0hyQ0N3?= =?utf-8?B?azI0YjJDTXU4N2M5M2s5ejJWSGxPenRDZDluQ3BTeStnMVB6b00rL3hwU25G?= =?utf-8?B?dXhEQTJRdXEyWlpRa3NHWUJjQzNvQzh4ZzExRU51cUNDdXlTbUhkRGs2MkJZ?= =?utf-8?B?U20vY1FoTXJZc1VwVjdITjcxZHBVSU5jclZDYnJ0K3dRUTFZT1dvNUZhbDFK?= =?utf-8?B?Z2hicjllY3AvZTY0d2U1OXBBcjU3V0hSZndwZTg4MDlDU0FzYWc3WWdrejBI?= =?utf-8?B?by96NmZZR2hDUVVTUUhsaWlMM1gxVGR6c05zeWJIZFEvTHNXVlpyelNSMG93?= =?utf-8?B?OTZqcjNpRjBSNWJKS2lqU0pCamVVUks0REFWOGRKYmRkbTl2Y25BWlB0OThw?= =?utf-8?B?cHJvVmFjQmk0N1Jpb2NRU2NEOFBuSk9LWWlvRURrTHZqVXlVRXJtTmp4OUxm?= =?utf-8?B?Y3BMVm5LVGJlUlArSWtGekhLQ1RrYW45ek9OY1Q2YnIweXVKVzNaUT09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 825ffc85-bbda-4c94-a41e-08dec7d675f5 X-MS-Exchange-CrossTenant-AuthSource: CW1P265MB8877.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2026 16:28:25.0241 (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: chrt3XK1AfK20BKXvgk1KHGhXjgzdWLzDpEKiCsmgthejY1M8V8gToNuU2REKjC2ebmFwQHesrck7807ZiP8MQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO2P265MB3263 Currently, `Io` is implemented on owned I/O objects (e.g. `Bar`). This is going to change with I/O projections, as then `Io` need 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 faciliate 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. Signed-off-by: Gary Guo --- rust/kernel/io.rs | 80 +++++++++++++++++++++++++-------------------------- rust/kernel/pci/io.rs | 12 ++++---- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs index 38281636b4da..3b478dcf10f9 100644 --- a/rust/kernel/io.rs +++ b/rust/kernel/io.rs @@ -224,7 +224,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`. /// @@ -232,7 +232,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 @@ -299,21 +299,21 @@ fn offset(self) -> usize { /// /// 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`. @@ -326,7 +326,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); } @@ -338,7 +338,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, @@ -348,7 +348,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, @@ -358,7 +358,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, @@ -368,7 +368,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, @@ -378,7 +378,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, @@ -388,7 +388,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, @@ -398,7 +398,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, @@ -408,7 +408,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, @@ -418,7 +418,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, @@ -428,7 +428,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, @@ -438,7 +438,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, @@ -448,7 +448,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, @@ -458,7 +458,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, @@ -468,7 +468,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, @@ -478,7 +478,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, @@ -488,7 +488,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, @@ -519,7 +519,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, @@ -553,7 +553,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, @@ -599,7 +599,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, @@ -632,7 +632,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, @@ -671,7 +671,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, @@ -703,7 +703,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, @@ -746,7 +746,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, @@ -779,7 +779,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, @@ -800,13 +800,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) } } @@ -827,18 +827,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() } } @@ -865,16 +865,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