Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 1 | #ifndef ARCH_MMIO_H |
| 2 | #define ARCH_MMIO_H 1 |
| 3 | |
| 4 | |
Arne Georg Gleditsch | d6689ed | 2010-09-09 14:54:07 +0000 | [diff] [blame] | 5 | // Extended read, constrain to use registers as mandated by AMD MMCONFIG mechanism. |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 6 | |
| 7 | static inline __attribute__((always_inline)) uint8_t read8x(uint32_t addr) |
| 8 | { |
| 9 | uint8_t value; |
| 10 | __asm__ volatile ( |
Arne Georg Gleditsch | d6689ed | 2010-09-09 14:54:07 +0000 | [diff] [blame] | 11 | "movb (%1), %%al\n\t" |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 12 | :"=a"(value): "b" (addr) |
| 13 | ); |
| 14 | return value; |
| 15 | } |
| 16 | |
| 17 | static inline __attribute__((always_inline)) uint16_t read16x(uint32_t addr) |
| 18 | { |
| 19 | uint16_t value; |
| 20 | __asm__ volatile ( |
Arne Georg Gleditsch | d6689ed | 2010-09-09 14:54:07 +0000 | [diff] [blame] | 21 | "movw (%1), %%ax\n\t" |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 22 | :"=a"(value): "b" (addr) |
| 23 | ); |
| 24 | |
| 25 | return value; |
| 26 | |
| 27 | } |
| 28 | |
| 29 | static inline __attribute__((always_inline)) uint32_t read32x(uint32_t addr) |
| 30 | { |
| 31 | uint32_t value; |
| 32 | __asm__ volatile ( |
Arne Georg Gleditsch | d6689ed | 2010-09-09 14:54:07 +0000 | [diff] [blame] | 33 | "movl (%1), %%eax\n\t" |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 34 | :"=a"(value): "b" (addr) |
| 35 | ); |
| 36 | |
| 37 | return value; |
| 38 | |
| 39 | } |
| 40 | |
| 41 | static inline __attribute__((always_inline)) void write8x(uint32_t addr, uint8_t value) |
| 42 | { |
| 43 | __asm__ volatile ( |
Arne Georg Gleditsch | d6689ed | 2010-09-09 14:54:07 +0000 | [diff] [blame] | 44 | "movb %%al, (%0)\n\t" |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 45 | :: "b" (addr), "a" (value) |
| 46 | ); |
| 47 | |
| 48 | } |
| 49 | |
| 50 | static inline __attribute__((always_inline)) void write16x(uint32_t addr, uint16_t value) |
| 51 | { |
| 52 | __asm__ volatile ( |
Arne Georg Gleditsch | d6689ed | 2010-09-09 14:54:07 +0000 | [diff] [blame] | 53 | "movw %%ax, (%0)\n\t" |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 54 | :: "b" (addr), "a" (value) |
| 55 | ); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | static inline __attribute__((always_inline)) void write32x(uint32_t addr, uint32_t value) |
| 60 | { |
| 61 | __asm__ volatile ( |
Arne Georg Gleditsch | d6689ed | 2010-09-09 14:54:07 +0000 | [diff] [blame] | 62 | "movl %%eax, (%0)\n\t" |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 63 | :: "b" (addr), "a" (value) |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | #endif /* ARCH_MMIO_H */ |