mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-03 18:20:25 +02:00 
			
		
		
		
	Add a generic iomem abstraction to safely read and write ioremapped regions. This abstraction requires a previously acquired IoRequest instance. This makes it so that both the resource and the device match, or, in other words, that the resource is indeed a valid resource for a given bound device. A subsequent patch will add the ability to retrieve IoRequest instances from platform devices. The reads and writes are done through IoRaw, and are thus checked either at compile-time, if the size of the region is known at that point, or at runtime otherwise. Non-exclusive access to the underlying memory region is made possible to cater to cases where overlapped regions are unavoidable. Acked-by: Miguel Ojeda <ojeda@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com> Link: https://lore.kernel.org/r/20250717-topics-tyr-platform_iomem-v15-2-beca780b77e3@collabora.com [ Add #[expect(dead_code)] to avoid a temporary warning, remove unnecessary OF_ID_TABLE constants in doc-tests and ignore doc-tests for now to avoid a temporary build failure. - Danilo ] Signed-off-by: Danilo Krummrich <dakr@kernel.org>
		
			
				
	
	
		
			142 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			142 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
// SPDX-License-Identifier: GPL-2.0
 | 
						|
 | 
						|
#include <linux/io.h>
 | 
						|
#include <linux/ioport.h>
 | 
						|
 | 
						|
void __iomem *rust_helper_ioremap(phys_addr_t offset, size_t size)
 | 
						|
{
 | 
						|
	return ioremap(offset, size);
 | 
						|
}
 | 
						|
 | 
						|
void __iomem *rust_helper_ioremap_np(phys_addr_t offset, size_t size)
 | 
						|
{
 | 
						|
	return ioremap_np(offset, size);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_iounmap(void __iomem *addr)
 | 
						|
{
 | 
						|
	iounmap(addr);
 | 
						|
}
 | 
						|
 | 
						|
u8 rust_helper_readb(const void __iomem *addr)
 | 
						|
{
 | 
						|
	return readb(addr);
 | 
						|
}
 | 
						|
 | 
						|
u16 rust_helper_readw(const void __iomem *addr)
 | 
						|
{
 | 
						|
	return readw(addr);
 | 
						|
}
 | 
						|
 | 
						|
u32 rust_helper_readl(const void __iomem *addr)
 | 
						|
{
 | 
						|
	return readl(addr);
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CONFIG_64BIT
 | 
						|
u64 rust_helper_readq(const void __iomem *addr)
 | 
						|
{
 | 
						|
	return readq(addr);
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
void rust_helper_writeb(u8 value, void __iomem *addr)
 | 
						|
{
 | 
						|
	writeb(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_writew(u16 value, void __iomem *addr)
 | 
						|
{
 | 
						|
	writew(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_writel(u32 value, void __iomem *addr)
 | 
						|
{
 | 
						|
	writel(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CONFIG_64BIT
 | 
						|
void rust_helper_writeq(u64 value, void __iomem *addr)
 | 
						|
{
 | 
						|
	writeq(value, addr);
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
u8 rust_helper_readb_relaxed(const void __iomem *addr)
 | 
						|
{
 | 
						|
	return readb_relaxed(addr);
 | 
						|
}
 | 
						|
 | 
						|
u16 rust_helper_readw_relaxed(const void __iomem *addr)
 | 
						|
{
 | 
						|
	return readw_relaxed(addr);
 | 
						|
}
 | 
						|
 | 
						|
u32 rust_helper_readl_relaxed(const void __iomem *addr)
 | 
						|
{
 | 
						|
	return readl_relaxed(addr);
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CONFIG_64BIT
 | 
						|
u64 rust_helper_readq_relaxed(const void __iomem *addr)
 | 
						|
{
 | 
						|
	return readq_relaxed(addr);
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
void rust_helper_writeb_relaxed(u8 value, void __iomem *addr)
 | 
						|
{
 | 
						|
	writeb_relaxed(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_writew_relaxed(u16 value, void __iomem *addr)
 | 
						|
{
 | 
						|
	writew_relaxed(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_writel_relaxed(u32 value, void __iomem *addr)
 | 
						|
{
 | 
						|
	writel_relaxed(value, addr);
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CONFIG_64BIT
 | 
						|
void rust_helper_writeq_relaxed(u64 value, void __iomem *addr)
 | 
						|
{
 | 
						|
	writeq_relaxed(value, addr);
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
resource_size_t rust_helper_resource_size(struct resource *res)
 | 
						|
{
 | 
						|
	return resource_size(res);
 | 
						|
}
 | 
						|
 | 
						|
struct resource *rust_helper_request_mem_region(resource_size_t start,
 | 
						|
						resource_size_t n,
 | 
						|
						const char *name)
 | 
						|
{
 | 
						|
	return request_mem_region(start, n, name);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_release_mem_region(resource_size_t start, resource_size_t n)
 | 
						|
{
 | 
						|
	release_mem_region(start, n);
 | 
						|
}
 | 
						|
 | 
						|
struct resource *rust_helper_request_region(resource_size_t start,
 | 
						|
					    resource_size_t n, const char *name)
 | 
						|
{
 | 
						|
	return request_region(start, n, name);
 | 
						|
}
 | 
						|
 | 
						|
struct resource *rust_helper_request_muxed_region(resource_size_t start,
 | 
						|
						  resource_size_t n,
 | 
						|
						  const char *name)
 | 
						|
{
 | 
						|
	return request_muxed_region(start, n, name);
 | 
						|
}
 | 
						|
 | 
						|
void rust_helper_release_region(resource_size_t start, resource_size_t n)
 | 
						|
{
 | 
						|
	release_region(start, n);
 | 
						|
}
 |