mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-03 10:10:33 +02:00 
			
		
		
		
	I/O memory is typically either mapped through direct calls to ioremap() or subsystem / bus specific ones such as pci_iomap(). Even though subsystem / bus specific functions to map I/O memory are based on ioremap() / iounmap() it is not desirable to re-implement them in Rust. Instead, implement a base type for I/O mapped memory, which generically provides the corresponding accessors, such as `Io::readb` or `Io:try_readb`. `Io` supports an optional const generic, such that a driver can indicate the minimal expected and required size of the mapping at compile time. Correspondingly, calls to the 'non-try' accessors, support compile time checks of the I/O memory offset to read / write, while the 'try' accessors, provide boundary checks on runtime. `IoRaw` is meant to be embedded into a structure (e.g. pci::Bar or io::IoMem) which creates the actual I/O memory mapping and initializes `IoRaw` accordingly. To ensure that I/O mapped memory can't out-live the device it may be bound to, subsystems must embed the corresponding I/O memory type (e.g. pci::Bar) into a `Devres` container, such that it gets revoked once the device is unbound. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Tested-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Signed-off-by: Danilo Krummrich <dakr@kernel.org> Tested-by: Dirk Behme <dirk.behme@de.bosch.com> Link: https://lore.kernel.org/r/20241219170425.12036-8-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
		
			
				
	
	
		
			101 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			101 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
// SPDX-License-Identifier: GPL-2.0
 | 
						|
 | 
						|
#include <linux/io.h>
 | 
						|
 | 
						|
void __iomem *rust_helper_ioremap(phys_addr_t offset, size_t size)
 | 
						|
{
 | 
						|
	return ioremap(offset, size);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_iounmap(volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	iounmap(addr);
 | 
						|
}
 | 
						|
 | 
						|
u8 rust_helper_readb(const volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	return readb(addr);
 | 
						|
}
 | 
						|
 | 
						|
u16 rust_helper_readw(const volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	return readw(addr);
 | 
						|
}
 | 
						|
 | 
						|
u32 rust_helper_readl(const volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	return readl(addr);
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CONFIG_64BIT
 | 
						|
u64 rust_helper_readq(const volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	return readq(addr);
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
void rust_helper_writeb(u8 value, volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	writeb(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_writew(u16 value, volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	writew(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_writel(u32 value, volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	writel(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CONFIG_64BIT
 | 
						|
void rust_helper_writeq(u64 value, volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	writeq(value, addr);
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
u8 rust_helper_readb_relaxed(const volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	return readb_relaxed(addr);
 | 
						|
}
 | 
						|
 | 
						|
u16 rust_helper_readw_relaxed(const volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	return readw_relaxed(addr);
 | 
						|
}
 | 
						|
 | 
						|
u32 rust_helper_readl_relaxed(const volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	return readl_relaxed(addr);
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CONFIG_64BIT
 | 
						|
u64 rust_helper_readq_relaxed(const volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	return readq_relaxed(addr);
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
void rust_helper_writeb_relaxed(u8 value, volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	writeb_relaxed(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_writew_relaxed(u16 value, volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	writew_relaxed(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_writel_relaxed(u32 value, volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	writel_relaxed(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CONFIG_64BIT
 | 
						|
void rust_helper_writeq_relaxed(u64 value, volatile void __iomem *addr)
 | 
						|
{
 | 
						|
	writeq_relaxed(value, addr);
 | 
						|
}
 | 
						|
#endif
 |