Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 2 | /* |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 3 | * Copyright (C) 2013-2014, 2020 Synopsys, Inc. All rights reserved. |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __ASM_ARC_IO_H |
| 7 | #define __ASM_ARC_IO_H |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | #include <asm/byteorder.h> |
| 11 | |
Alexey Brodkin | 0f18418 | 2018-02-21 12:58:00 +0300 | [diff] [blame] | 12 | #ifdef __ARCHS__ |
Alexey Brodkin | b686ce7 | 2016-06-08 08:24:54 +0300 | [diff] [blame] | 13 | |
| 14 | /* |
| 15 | * ARCv2 based HS38 cores are in-order issue, but still weakly ordered |
| 16 | * due to micro-arch buffering/queuing of load/store, cache hit vs. miss ... |
| 17 | * |
| 18 | * Explicit barrier provided by DMB instruction |
| 19 | * - Operand supports fine grained load/store/load+store semantics |
| 20 | * - Ensures that selected memory operation issued before it will complete |
| 21 | * before any subsequent memory operation of same type |
| 22 | * - DMB guarantees SMP as well as local barrier semantics |
| 23 | * (asm-generic/barrier.h ensures sane smp_*mb if not defined here, i.e. |
| 24 | * UP: barrier(), SMP: smp_*mb == *mb) |
| 25 | * - DSYNC provides DMB+completion_of_cache_bpu_maintenance_ops hence not needed |
| 26 | * in the general case. Plus it only provides full barrier. |
| 27 | */ |
| 28 | |
| 29 | #define mb() asm volatile("dmb 3\n" : : : "memory") |
| 30 | #define rmb() asm volatile("dmb 1\n" : : : "memory") |
| 31 | #define wmb() asm volatile("dmb 2\n" : : : "memory") |
| 32 | |
| 33 | #else |
| 34 | |
| 35 | /* |
| 36 | * ARCompact based cores (ARC700) only have SYNC instruction which is super |
| 37 | * heavy weight as it flushes the pipeline as well. |
| 38 | * There are no real SMP implementations of such cores. |
| 39 | */ |
| 40 | |
| 41 | #define mb() asm volatile("sync\n" : : : "memory") |
| 42 | #endif |
| 43 | |
Alexey Brodkin | 0f18418 | 2018-02-21 12:58:00 +0300 | [diff] [blame] | 44 | #ifdef __ARCHS__ |
Alexey Brodkin | b686ce7 | 2016-06-08 08:24:54 +0300 | [diff] [blame] | 45 | #define __iormb() rmb() |
| 46 | #define __iowmb() wmb() |
| 47 | #else |
Alexey Brodkin | 0f18418 | 2018-02-21 12:58:00 +0300 | [diff] [blame] | 48 | #define __iormb() asm volatile("" : : : "memory") |
| 49 | #define __iowmb() asm volatile("" : : : "memory") |
Alexey Brodkin | b686ce7 | 2016-06-08 08:24:54 +0300 | [diff] [blame] | 50 | #endif |
| 51 | |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 52 | static inline void sync(void) |
| 53 | { |
| 54 | /* Not yet implemented */ |
| 55 | } |
| 56 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 57 | #define __arch_getb(a) (*(unsigned char *)(a)) |
| 58 | #define __arch_getw(a) (*(unsigned short *)(a)) |
| 59 | #define __arch_getl(a) (*(unsigned int *)(a)) |
| 60 | #define __arch_getq(a) (*(unsigned long long *)(a)) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 61 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 62 | #define __arch_putb(v, a) (*(unsigned char *)(a) = (v)) |
| 63 | #define __arch_putw(v, a) (*(unsigned short *)(a) = (v)) |
| 64 | #define __arch_putl(v, a) (*(unsigned int *)(a) = (v)) |
| 65 | #define __arch_putq(v, a) (*(unsigned long long *)(a) = (v)) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 66 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 67 | #define __raw_writeb(v, a) __arch_putb(v, a) |
| 68 | #define __raw_writew(v, a) __arch_putw(v, a) |
| 69 | #define __raw_writel(v, a) __arch_putl(v, a) |
| 70 | #define __raw_writeq(v, a) __arch_putq(v, a) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 71 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 72 | #define __raw_readb(a) __arch_getb(a) |
| 73 | #define __raw_readw(a) __arch_getw(a) |
| 74 | #define __raw_readl(a) __arch_getl(a) |
| 75 | #define __raw_readq(a) __arch_getq(a) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 76 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 77 | static inline void __raw_writesb(unsigned long addr, const void *data, |
| 78 | int bytelen) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 79 | { |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 80 | u8 *buf = (uint8_t *)data; |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 81 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 82 | while (bytelen--) |
| 83 | __arch_putb(*buf++, addr); |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 84 | } |
| 85 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 86 | static inline void __raw_writesw(unsigned long addr, const void *data, |
| 87 | int wordlen) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 88 | { |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 89 | u16 *buf = (uint16_t *)data; |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 90 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 91 | while (wordlen--) |
| 92 | __arch_putw(*buf++, addr); |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 93 | } |
| 94 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 95 | static inline void __raw_writesl(unsigned long addr, const void *data, |
| 96 | int longlen) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 97 | { |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 98 | u32 *buf = (uint32_t *)data; |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 99 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 100 | while (longlen--) |
| 101 | __arch_putl(*buf++, addr); |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 102 | } |
| 103 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 104 | static inline void __raw_readsb(unsigned long addr, void *data, int bytelen) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 105 | { |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 106 | u8 *buf = (uint8_t *)data; |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 107 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 108 | while (bytelen--) |
| 109 | *buf++ = __arch_getb(addr); |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 110 | } |
| 111 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 112 | static inline void __raw_readsw(unsigned long addr, void *data, int wordlen) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 113 | { |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 114 | u16 *buf = (uint16_t *)data; |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 115 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 116 | while (wordlen--) |
| 117 | *buf++ = __arch_getw(addr); |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 118 | } |
| 119 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 120 | static inline void __raw_readsl(unsigned long addr, void *data, int longlen) |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 121 | { |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 122 | u32 *buf = (uint32_t *)data; |
| 123 | |
| 124 | while (longlen--) |
| 125 | *buf++ = __arch_getl(addr); |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 126 | } |
| 127 | |
Alexey Brodkin | b686ce7 | 2016-06-08 08:24:54 +0300 | [diff] [blame] | 128 | /* |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 129 | * Relaxed I/O memory access primitives. These follow the Device memory |
| 130 | * ordering rules but do not guarantee any ordering relative to Normal memory |
| 131 | * accesses. |
| 132 | */ |
| 133 | #define readb_relaxed(c) ({ u8 __r = __raw_readb(c); __r; }) |
| 134 | #define readw_relaxed(c) ({ u16 __r = le16_to_cpu((__force __le16) \ |
| 135 | __raw_readw(c)); __r; }) |
| 136 | #define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32) \ |
| 137 | __raw_readl(c)); __r; }) |
| 138 | #define readq_relaxed(c) ({ u64 __r = le64_to_cpu((__force __le64) \ |
| 139 | __raw_readq(c)); __r; }) |
| 140 | |
| 141 | #define writeb_relaxed(v, c) ((void)__raw_writeb((v), (c))) |
| 142 | #define writew_relaxed(v, c) ((void)__raw_writew((__force u16) \ |
| 143 | cpu_to_le16(v), (c))) |
| 144 | #define writel_relaxed(v, c) ((void)__raw_writel((__force u32) \ |
| 145 | cpu_to_le32(v), (c))) |
| 146 | #define writeq_relaxed(v, c) ((void)__raw_writeq((__force u64) \ |
| 147 | cpu_to_le64(v), (c))) |
| 148 | |
| 149 | /* |
Alexey Brodkin | b686ce7 | 2016-06-08 08:24:54 +0300 | [diff] [blame] | 150 | * MMIO can also get buffered/optimized in micro-arch, so barriers needed |
| 151 | * Based on ARM model for the typical use case |
| 152 | * |
| 153 | * <ST [DMA buffer]> |
| 154 | * <writel MMIO "go" reg> |
| 155 | * or: |
| 156 | * <readl MMIO "status" reg> |
| 157 | * <LD [DMA buffer]> |
| 158 | * |
| 159 | * http://lkml.kernel.org/r/20150622133656.GG1583@arm.com |
| 160 | */ |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 161 | #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; }) |
| 162 | #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; }) |
| 163 | #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; }) |
| 164 | #define readq(c) ({ u64 __v = readq_relaxed(c); __iormb(); __v; }) |
Alexey Brodkin | b686ce7 | 2016-06-08 08:24:54 +0300 | [diff] [blame] | 165 | |
Alexey Brodkin | 5af2aa8 | 2020-01-20 13:37:38 +0300 | [diff] [blame^] | 166 | #define writeb(v, c) ({ __iowmb(); writeb_relaxed(v, c); }) |
| 167 | #define writew(v, c) ({ __iowmb(); writew_relaxed(v, c); }) |
| 168 | #define writel(v, c) ({ __iowmb(); writel_relaxed(v, c); }) |
| 169 | #define writeq(v, c) ({ __iowmb(); writeq_relaxed(v, c); }) |
Alexey Brodkin | b686ce7 | 2016-06-08 08:24:54 +0300 | [diff] [blame] | 170 | |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 171 | #define out_arch(type, endian, a, v) __raw_write##type(cpu_to_##endian(v), a) |
| 172 | #define in_arch(type, endian, a) endian##_to_cpu(__raw_read##type(a)) |
| 173 | |
| 174 | #define out_le32(a, v) out_arch(l, le32, a, v) |
| 175 | #define out_le16(a, v) out_arch(w, le16, a, v) |
| 176 | |
| 177 | #define in_le32(a) in_arch(l, le32, a) |
| 178 | #define in_le16(a) in_arch(w, le16, a) |
| 179 | |
| 180 | #define out_be32(a, v) out_arch(l, be32, a, v) |
| 181 | #define out_be16(a, v) out_arch(w, be16, a, v) |
| 182 | |
| 183 | #define in_be32(a) in_arch(l, be32, a) |
| 184 | #define in_be16(a) in_arch(w, be16, a) |
| 185 | |
| 186 | #define out_8(a, v) __raw_writeb(v, a) |
| 187 | #define in_8(a) __raw_readb(a) |
| 188 | |
| 189 | /* |
| 190 | * Clear and set bits in one shot. These macros can be used to clear and |
| 191 | * set multiple bits in a register using a single call. These macros can |
| 192 | * also be used to set a multiple-bit bit pattern using a mask, by |
| 193 | * specifying the mask in the 'clear' parameter and the new bit pattern |
| 194 | * in the 'set' parameter. |
| 195 | */ |
| 196 | |
| 197 | #define clrbits(type, addr, clear) \ |
| 198 | out_##type((addr), in_##type(addr) & ~(clear)) |
| 199 | |
| 200 | #define setbits(type, addr, set) \ |
| 201 | out_##type((addr), in_##type(addr) | (set)) |
| 202 | |
| 203 | #define clrsetbits(type, addr, clear, set) \ |
| 204 | out_##type((addr), (in_##type(addr) & ~(clear)) | (set)) |
| 205 | |
| 206 | #define clrbits_be32(addr, clear) clrbits(be32, addr, clear) |
| 207 | #define setbits_be32(addr, set) setbits(be32, addr, set) |
| 208 | #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set) |
| 209 | |
| 210 | #define clrbits_le32(addr, clear) clrbits(le32, addr, clear) |
| 211 | #define setbits_le32(addr, set) setbits(le32, addr, set) |
| 212 | #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) |
| 213 | |
| 214 | #define clrbits_be16(addr, clear) clrbits(be16, addr, clear) |
| 215 | #define setbits_be16(addr, set) setbits(be16, addr, set) |
| 216 | #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set) |
| 217 | |
| 218 | #define clrbits_le16(addr, clear) clrbits(le16, addr, clear) |
| 219 | #define setbits_le16(addr, set) setbits(le16, addr, set) |
| 220 | #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set) |
| 221 | |
| 222 | #define clrbits_8(addr, clear) clrbits(8, addr, clear) |
| 223 | #define setbits_8(addr, set) setbits(8, addr, set) |
| 224 | #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) |
| 225 | |
Paul Burton | 1fdceda | 2017-09-14 15:05:02 -0700 | [diff] [blame] | 226 | #include <asm-generic/io.h> |
Alexey Brodkin | cc2ea6c | 2016-04-08 09:21:12 -0700 | [diff] [blame] | 227 | |
Alexey Brodkin | 544c5f5 | 2014-02-04 12:56:13 +0400 | [diff] [blame] | 228 | #endif /* __ASM_ARC_IO_H */ |