summaryrefslogtreecommitdiffstats
path: root/lib/physmem-access.h
blob: a4e9744b166a2dd69f66fc339b71cf6ed0911965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 *      The PCI Library -- Compiler-specific wrappers for memory mapped I/O
 *
 *      Copyright (c) 2023 Pali Rohár <pali@kernel.org>
 *
 *      Can be freely distributed and used under the terms of the GNU GPL v2+
 *
 *      SPDX-License-Identifier: GPL-2.0-or-later
 */

/*
 * FIXME
 * Unfortunately gcc does not provide architecture independent way to read from
 * or write to memory mapped I/O. The best approximation is to use volatile and
 * for the write operation follow it by the read operation from the same address.
 */

static inline void
physmem_writeb(unsigned char value, volatile void *ptr)
{
  *(volatile unsigned char *)ptr = value;
}

static inline void
physmem_writew(unsigned short value, volatile void *ptr)
{
  *(volatile unsigned short *)ptr = value;
}

static inline void
physmem_writel(u32 value, volatile void *ptr)
{
  *(volatile u32 *)ptr = value;
}

static inline unsigned char
physmem_readb(volatile void *ptr)
{
  return *(volatile unsigned char *)ptr;
}

static inline unsigned short
physmem_readw(volatile void *ptr)
{
  return *(volatile unsigned short *)ptr;
}

static inline u32
physmem_readl(volatile void *ptr)
{
  return *(volatile u32 *)ptr;
}