xref: /aosp_15_r20/external/pciutils/lib/physmem-access.h (revision c2e0c6b56a71da9abe8df5c8348fb3eb5c2c9251)
1 /*
2  *      The PCI Library -- Compiler-specific wrappers for memory mapped I/O
3  *
4  *      Copyright (c) 2023 Pali Rohár <[email protected]>
5  *
6  *      Can be freely distributed and used under the terms of the GNU GPL v2+
7  *
8  *      SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 /*
12  * FIXME
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.
16  */
17 
18 static inline void
physmem_writeb(unsigned char value,volatile void * ptr)19 physmem_writeb(unsigned char value, volatile void *ptr)
20 {
21   *(volatile unsigned char *)ptr = value;
22 }
23 
24 static inline void
physmem_writew(unsigned short value,volatile void * ptr)25 physmem_writew(unsigned short value, volatile void *ptr)
26 {
27   *(volatile unsigned short *)ptr = value;
28 }
29 
30 static inline void
physmem_writel(u32 value,volatile void * ptr)31 physmem_writel(u32 value, volatile void *ptr)
32 {
33   *(volatile u32 *)ptr = value;
34 }
35 
36 static inline unsigned char
physmem_readb(volatile void * ptr)37 physmem_readb(volatile void *ptr)
38 {
39   return *(volatile unsigned char *)ptr;
40 }
41 
42 static inline unsigned short
physmem_readw(volatile void * ptr)43 physmem_readw(volatile void *ptr)
44 {
45   return *(volatile unsigned short *)ptr;
46 }
47 
48 static inline u32
physmem_readl(volatile void * ptr)49 physmem_readl(volatile void *ptr)
50 {
51   return *(volatile u32 *)ptr;
52 }
53