Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: io: move MIN_SIZE and io_addr_assert to IoKnownSize

`MIN_SIZE` and `io_addr_assert` are only ever used for IO types which
implement `IoKnownSize` and do not make sense for types that don't.

It looks like they should have been there since the beginning, so move
them while the code is still fresh.

Also update `IoKnownSize`'s documentation since it is not just a marker
trait anymore.

Fixes: 121d87b28e1d ("rust: io: separate generic I/O helpers from MMIO implementation")
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://patch.msgid.link/20260130-io-min-size-v1-1-65a546e3104d@nvidia.com
[ Fix typo in commit message. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by

Alexandre Courbot and committed by
Danilo Krummrich
726c2620 72bfbe50

+21 -22
+18 -18
rust/kernel/io.rs
··· 301 301 /// For MMIO regions, all widths (u8, u16, u32, and u64 on 64-bit systems) are typically 302 302 /// supported. For PCI configuration space, u8, u16, and u32 are supported but u64 is not. 303 303 pub trait Io { 304 - /// Minimum usable size of this region. 305 - const MIN_SIZE: usize; 306 - 307 304 /// Returns the base address of this mapping. 308 305 fn addr(&self) -> usize; 309 306 ··· 318 321 // Probably no need to check, since the safety requirements of `Self::new` guarantee that 319 322 // this can't overflow. 320 323 self.addr().checked_add(offset).ok_or(EINVAL) 321 - } 322 - 323 - /// Returns the absolute I/O address for a given `offset`, 324 - /// performing compile-time bound checks. 325 - // Always inline to optimize out error path of `build_assert`. 326 - #[inline(always)] 327 - fn io_addr_assert<U>(&self, offset: usize) -> usize { 328 - build_assert!(offset_valid::<U>(offset, Self::MIN_SIZE)); 329 - 330 - self.addr() + offset 331 324 } 332 325 333 326 /// Fallible 8-bit read with runtime bounds check. ··· 465 478 } 466 479 } 467 480 468 - /// Marker trait for types with a known size at compile time. 481 + /// Trait for types with a known size at compile time. 469 482 /// 470 483 /// This trait is implemented by I/O backends that have a compile-time known size, 471 484 /// enabling the use of infallible I/O accessors with compile-time bounds checking. 472 485 /// 473 486 /// Types implementing this trait can use the infallible methods in [`Io`] trait 474 487 /// (e.g., `read8`, `write32`), which require `Self: IoKnownSize` bound. 475 - pub trait IoKnownSize: Io {} 488 + pub trait IoKnownSize: Io { 489 + /// Minimum usable size of this region. 490 + const MIN_SIZE: usize; 491 + 492 + /// Returns the absolute I/O address for a given `offset`, 493 + /// performing compile-time bound checks. 494 + // Always inline to optimize out error path of `build_assert`. 495 + #[inline(always)] 496 + fn io_addr_assert<U>(&self, offset: usize) -> usize { 497 + build_assert!(offset_valid::<U>(offset, Self::MIN_SIZE)); 498 + 499 + self.addr() + offset 500 + } 501 + } 476 502 477 503 // MMIO regions support 8, 16, and 32-bit accesses. 478 504 impl<const SIZE: usize> IoCapable<u8> for Mmio<SIZE> {} ··· 497 497 impl<const SIZE: usize> IoCapable<u64> for Mmio<SIZE> {} 498 498 499 499 impl<const SIZE: usize> Io for Mmio<SIZE> { 500 - const MIN_SIZE: usize = SIZE; 501 - 502 500 /// Returns the base address of this mapping. 503 501 #[inline] 504 502 fn addr(&self) -> usize { ··· 550 552 ); 551 553 } 552 554 553 - impl<const SIZE: usize> IoKnownSize for Mmio<SIZE> {} 555 + impl<const SIZE: usize> IoKnownSize for Mmio<SIZE> { 556 + const MIN_SIZE: usize = SIZE; 557 + } 554 558 555 559 impl<const SIZE: usize> Mmio<SIZE> { 556 560 /// Converts an `MmioRaw` into an `Mmio` instance, providing the accessors to the MMIO mapping.
+3 -4
rust/kernel/pci/io.rs
··· 148 148 impl<'a, S: ConfigSpaceKind> IoCapable<u32> for ConfigSpace<'a, S> {} 149 149 150 150 impl<'a, S: ConfigSpaceKind> Io for ConfigSpace<'a, S> { 151 - const MIN_SIZE: usize = S::SIZE; 152 - 153 151 /// Returns the base address of the I/O region. It is always 0 for configuration space. 154 152 #[inline] 155 153 fn addr(&self) -> usize { ··· 172 174 define_write!(infallible, write32, call_config_write(pci_write_config_dword) <- u32); 173 175 } 174 176 175 - /// Marker trait indicating ConfigSpace has a known size at compile time. 176 - impl<'a, S: ConfigSpaceKind> IoKnownSize for ConfigSpace<'a, S> {} 177 + impl<'a, S: ConfigSpaceKind> IoKnownSize for ConfigSpace<'a, S> { 178 + const MIN_SIZE: usize = S::SIZE; 179 + } 177 180 178 181 /// A PCI BAR to perform I/O-Operations on. 179 182 ///