|
17 | 17 | #define __packed __attribute__((__packed__))
|
18 | 18 | #endif /* __packed */
|
19 | 19 |
|
20 |
| -static inline uint32_t mmio_read32(void *addr) |
| 20 | +/* |
| 21 | + * VMs on arm64 can only use a subset of instructions for MMIO that provide |
| 22 | + * the hypervisor with a complete instruction decode. Provide assembly MMIO |
| 23 | + * accessors to prevent the compiler from using a possibly unsupported |
| 24 | + * instruction. |
| 25 | + * |
| 26 | + * See kernel commit c726200dd106 ("KVM: arm/arm64: Allow reporting non-ISV |
| 27 | + * data aborts to userspace") for more details. |
| 28 | + */ |
| 29 | +#if defined(__aarch64__) |
| 30 | +static inline leint32_t __raw_readl(const volatile leint32_t *addr) |
| 31 | +{ |
| 32 | + leint32_t val; |
| 33 | + |
| 34 | + asm volatile("ldr %w0, %1" : "=r" (val) : "Qo" (*addr)); |
| 35 | + |
| 36 | + return val; |
| 37 | +} |
| 38 | + |
| 39 | +static inline void __raw_writel(volatile leint32_t *addr, leint32_t val) |
21 | 40 | {
|
22 |
| - leint32_t *p = addr; |
| 41 | + asm volatile("str %w0, %1" : : "r" (val), "Qo" (*addr)); |
| 42 | +} |
23 | 43 |
|
24 |
| - return le32_to_cpu(*p); |
| 44 | +static inline void __raw_writeq(volatile leint64_t *addr, leint64_t val) |
| 45 | +{ |
| 46 | + asm volatile("str %0, %1" : : "r" (val), "Qo" (*addr)); |
| 47 | +} |
| 48 | +#else |
| 49 | +static inline leint32_t __raw_readl(volatile leint32_t *addr) |
| 50 | +{ |
| 51 | + return *addr; |
| 52 | +} |
| 53 | + |
| 54 | +static inline void __raw_writel(volatile leint32_t *addr, leint32_t val) |
| 55 | +{ |
| 56 | + *addr = val; |
| 57 | +} |
| 58 | + |
| 59 | +static inline void __raw_writeq(volatile leint64_t *addr, leint64_t val) |
| 60 | +{ |
| 61 | + *addr = val; |
| 62 | +} |
| 63 | +#endif |
| 64 | + |
| 65 | +static inline uint32_t mmio_read32(void *addr) |
| 66 | +{ |
| 67 | + return le32_to_cpu(__raw_readl(addr)); |
25 | 68 | }
|
26 | 69 |
|
27 | 70 | /* Access 64-bit registers as 2 32-bit; Some devices fail 64-bit MMIO. */
|
28 | 71 | static inline uint64_t mmio_read64(void *addr)
|
29 | 72 | {
|
30 |
| - const volatile uint32_t *p = addr; |
31 | 73 | uint32_t low, high;
|
32 | 74 |
|
33 |
| - low = le32_to_cpu(*p); |
34 |
| - high = le32_to_cpu(*(p + 1)); |
| 75 | + low = le32_to_cpu(__raw_readl(addr)); |
| 76 | + high = le32_to_cpu(__raw_readl(addr + sizeof(leint32_t))); |
35 | 77 |
|
36 | 78 | return ((uint64_t)high << 32) | low;
|
37 | 79 | }
|
38 | 80 |
|
39 | 81 | static inline void mmio_write32(void *addr, uint32_t value)
|
40 | 82 | {
|
41 |
| - leint32_t *p = addr; |
42 |
| - |
43 |
| - *p = cpu_to_le32(value); |
| 83 | + __raw_writel(addr, cpu_to_le32(value)); |
44 | 84 | }
|
45 | 85 |
|
46 | 86 | /* Access 64-bit registers as 2 32-bit if write32 flag set; Some devices fail 64-bit MMIO. */
|
47 | 87 | static inline void mmio_write64(void *addr, uint64_t value, bool write32)
|
48 | 88 | {
|
49 |
| - uint64_t *p = addr; |
50 |
| - |
51 | 89 | if (write32) {
|
52 | 90 | mmio_write32(addr, value);
|
53 | 91 | mmio_write32((uint32_t *)addr + 1, value >> 32);
|
54 | 92 | return;
|
55 | 93 | }
|
56 | 94 |
|
57 |
| - *p = cpu_to_le64(value); |
| 95 | + __raw_writeq(addr, cpu_to_le64(value)); |
58 | 96 | }
|
59 | 97 | #endif
|
0 commit comments