blob: 08962f02fa99ac7b7ac6eafcdf257c392607fe47 [file] [log] [blame]
Yinghai Lu5f9624d2006-10-04 22:56:21 +00001#ifndef ARCH_MMIO_H
2#define ARCH_MMIO_H 1
3
4
Arne Georg Gleditschd6689ed2010-09-09 14:54:07 +00005// Extended read, constrain to use registers as mandated by AMD MMCONFIG mechanism.
Yinghai Lu5f9624d2006-10-04 22:56:21 +00006
7static inline __attribute__((always_inline)) uint8_t read8x(uint32_t addr)
8{
9 uint8_t value;
10 __asm__ volatile (
Arne Georg Gleditschd6689ed2010-09-09 14:54:07 +000011 "movb (%1), %%al\n\t"
Yinghai Lu5f9624d2006-10-04 22:56:21 +000012 :"=a"(value): "b" (addr)
13 );
14 return value;
15}
16
17static inline __attribute__((always_inline)) uint16_t read16x(uint32_t addr)
18{
19 uint16_t value;
20 __asm__ volatile (
Arne Georg Gleditschd6689ed2010-09-09 14:54:07 +000021 "movw (%1), %%ax\n\t"
Yinghai Lu5f9624d2006-10-04 22:56:21 +000022 :"=a"(value): "b" (addr)
23 );
24
25 return value;
26
27}
28
29static inline __attribute__((always_inline)) uint32_t read32x(uint32_t addr)
30{
31 uint32_t value;
32 __asm__ volatile (
Arne Georg Gleditschd6689ed2010-09-09 14:54:07 +000033 "movl (%1), %%eax\n\t"
Yinghai Lu5f9624d2006-10-04 22:56:21 +000034 :"=a"(value): "b" (addr)
35 );
36
37 return value;
38
39}
40
41static inline __attribute__((always_inline)) void write8x(uint32_t addr, uint8_t value)
42{
43 __asm__ volatile (
Arne Georg Gleditschd6689ed2010-09-09 14:54:07 +000044 "movb %%al, (%0)\n\t"
Yinghai Lu5f9624d2006-10-04 22:56:21 +000045 :: "b" (addr), "a" (value)
46 );
47
48}
49
50static inline __attribute__((always_inline)) void write16x(uint32_t addr, uint16_t value)
51{
52 __asm__ volatile (
Arne Georg Gleditschd6689ed2010-09-09 14:54:07 +000053 "movw %%ax, (%0)\n\t"
Yinghai Lu5f9624d2006-10-04 22:56:21 +000054 :: "b" (addr), "a" (value)
55 );
56
57}
58
59static inline __attribute__((always_inline)) void write32x(uint32_t addr, uint32_t value)
60{
61 __asm__ volatile (
Arne Georg Gleditschd6689ed2010-09-09 14:54:07 +000062 "movl %%eax, (%0)\n\t"
Yinghai Lu5f9624d2006-10-04 22:56:21 +000063 :: "b" (addr), "a" (value)
64 );
65}
66
67#endif /* ARCH_MMIO_H */