2 * The PCI Library -- Compiler-specific wrappers for memory mapped I/O
4 * Copyright (c) 2023 Pali Rohár <pali@kernel.org>
6 * Can be freely distributed and used under the terms of the GNU GPL v2+
8 * SPDX-License-Identifier: GPL-2.0-or-later
13 * Unfortunately gcc does not provide architecture independent way to read from
14 * or write to memory mapped I/O. The best approximation is to use volatile and
15 * for the write operation follow it by the read operation from the same address.
19 physmem_writeb(unsigned char value, volatile void *ptr)
21 *(volatile unsigned char *)ptr = value;
25 physmem_writew(unsigned short value, volatile void *ptr)
27 *(volatile unsigned short *)ptr = value;
31 physmem_writel(u32 value, volatile void *ptr)
33 *(volatile u32 *)ptr = value;
36 static inline unsigned char
37 physmem_readb(volatile void *ptr)
39 return *(volatile unsigned char *)ptr;
42 static inline unsigned short
43 physmem_readw(volatile void *ptr)
45 return *(volatile unsigned short *)ptr;
49 physmem_readl(volatile void *ptr)
51 return *(volatile u32 *)ptr;