Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regmap: mmio: add config option to allow relaxed MMIO accesses

On some platforms (eg armv7 due to the CONFIG_ARM_DMA_MEM_BUFFERABLE)
MMIO R/W operations always add memory barriers which can increase load,
decrease battery life or in general reduce performance unnecessarily
on devices which access a lot of configuration registers and where
ordering does not matter (eg. media accelerators like the Verisilicon /
Hantro video decoders).

Drivers used to call the relaxed MMIO variants directly but since they
are now accessing the MMIO registers via regmaps (to compensate for
different VPU HW reg layouts via regmap fields), there is a need for a
relaxed API / config to preserve existing behaviour.

Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Link: https://lore.kernel.org/r/20201014203024.954369-1-adrian.ratiu@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Adrian Ratiu and committed by
Mark Brown
6e1e90ec 3650b228

+87 -8
+82 -8
drivers/base/regmap/regmap-mmio.c
··· 16 16 struct regmap_mmio_context { 17 17 void __iomem *regs; 18 18 unsigned val_bytes; 19 + bool relaxed_mmio; 19 20 20 21 bool attached_clk; 21 22 struct clk *clk; ··· 76 75 writeb(val, ctx->regs + reg); 77 76 } 78 77 78 + static void regmap_mmio_write8_relaxed(struct regmap_mmio_context *ctx, 79 + unsigned int reg, 80 + unsigned int val) 81 + { 82 + writeb_relaxed(val, ctx->regs + reg); 83 + } 84 + 79 85 static void regmap_mmio_write16le(struct regmap_mmio_context *ctx, 80 86 unsigned int reg, 81 87 unsigned int val) 82 88 { 83 89 writew(val, ctx->regs + reg); 90 + } 91 + 92 + static void regmap_mmio_write16le_relaxed(struct regmap_mmio_context *ctx, 93 + unsigned int reg, 94 + unsigned int val) 95 + { 96 + writew_relaxed(val, ctx->regs + reg); 84 97 } 85 98 86 99 static void regmap_mmio_write16be(struct regmap_mmio_context *ctx, ··· 111 96 writel(val, ctx->regs + reg); 112 97 } 113 98 99 + static void regmap_mmio_write32le_relaxed(struct regmap_mmio_context *ctx, 100 + unsigned int reg, 101 + unsigned int val) 102 + { 103 + writel_relaxed(val, ctx->regs + reg); 104 + } 105 + 114 106 static void regmap_mmio_write32be(struct regmap_mmio_context *ctx, 115 107 unsigned int reg, 116 108 unsigned int val) ··· 131 109 unsigned int val) 132 110 { 133 111 writeq(val, ctx->regs + reg); 112 + } 113 + 114 + static void regmap_mmio_write64le_relaxed(struct regmap_mmio_context *ctx, 115 + unsigned int reg, 116 + unsigned int val) 117 + { 118 + writeq_relaxed(val, ctx->regs + reg); 134 119 } 135 120 #endif 136 121 ··· 166 137 return readb(ctx->regs + reg); 167 138 } 168 139 140 + static unsigned int regmap_mmio_read8_relaxed(struct regmap_mmio_context *ctx, 141 + unsigned int reg) 142 + { 143 + return readb_relaxed(ctx->regs + reg); 144 + } 145 + 169 146 static unsigned int regmap_mmio_read16le(struct regmap_mmio_context *ctx, 170 147 unsigned int reg) 171 148 { 172 149 return readw(ctx->regs + reg); 150 + } 151 + 152 + static unsigned int regmap_mmio_read16le_relaxed(struct regmap_mmio_context *ctx, 153 + unsigned int reg) 154 + { 155 + return readw_relaxed(ctx->regs + reg); 173 156 } 174 157 175 158 static unsigned int regmap_mmio_read16be(struct regmap_mmio_context *ctx, ··· 196 155 return readl(ctx->regs + reg); 197 156 } 198 157 158 + static unsigned int regmap_mmio_read32le_relaxed(struct regmap_mmio_context *ctx, 159 + unsigned int reg) 160 + { 161 + return readl_relaxed(ctx->regs + reg); 162 + } 163 + 199 164 static unsigned int regmap_mmio_read32be(struct regmap_mmio_context *ctx, 200 165 unsigned int reg) 201 166 { ··· 213 166 unsigned int reg) 214 167 { 215 168 return readq(ctx->regs + reg); 169 + } 170 + 171 + static unsigned int regmap_mmio_read64le_relaxed(struct regmap_mmio_context *ctx, 172 + unsigned int reg) 173 + { 174 + return readq_relaxed(ctx->regs + reg); 216 175 } 217 176 #endif 218 177 ··· 290 237 291 238 ctx->regs = regs; 292 239 ctx->val_bytes = config->val_bits / 8; 240 + ctx->relaxed_mmio = config->use_relaxed_mmio; 293 241 ctx->clk = ERR_PTR(-ENODEV); 294 242 295 243 switch (regmap_get_val_endian(dev, &regmap_mmio, config)) { ··· 301 247 #endif 302 248 switch (config->val_bits) { 303 249 case 8: 304 - ctx->reg_read = regmap_mmio_read8; 305 - ctx->reg_write = regmap_mmio_write8; 250 + if (ctx->relaxed_mmio) { 251 + ctx->reg_read = regmap_mmio_read8_relaxed; 252 + ctx->reg_write = regmap_mmio_write8_relaxed; 253 + } else { 254 + ctx->reg_read = regmap_mmio_read8; 255 + ctx->reg_write = regmap_mmio_write8; 256 + } 306 257 break; 307 258 case 16: 308 - ctx->reg_read = regmap_mmio_read16le; 309 - ctx->reg_write = regmap_mmio_write16le; 259 + if (ctx->relaxed_mmio) { 260 + ctx->reg_read = regmap_mmio_read16le_relaxed; 261 + ctx->reg_write = regmap_mmio_write16le_relaxed; 262 + } else { 263 + ctx->reg_read = regmap_mmio_read16le; 264 + ctx->reg_write = regmap_mmio_write16le; 265 + } 310 266 break; 311 267 case 32: 312 - ctx->reg_read = regmap_mmio_read32le; 313 - ctx->reg_write = regmap_mmio_write32le; 268 + if (ctx->relaxed_mmio) { 269 + ctx->reg_read = regmap_mmio_read32le_relaxed; 270 + ctx->reg_write = regmap_mmio_write32le_relaxed; 271 + } else { 272 + ctx->reg_read = regmap_mmio_read32le; 273 + ctx->reg_write = regmap_mmio_write32le; 274 + } 314 275 break; 315 276 #ifdef CONFIG_64BIT 316 277 case 64: 317 - ctx->reg_read = regmap_mmio_read64le; 318 - ctx->reg_write = regmap_mmio_write64le; 278 + if (ctx->relaxed_mmio) { 279 + ctx->reg_read = regmap_mmio_read64le_relaxed; 280 + ctx->reg_write = regmap_mmio_write64le_relaxed; 281 + } else { 282 + ctx->reg_read = regmap_mmio_read64le; 283 + ctx->reg_write = regmap_mmio_write64le; 284 + } 319 285 break; 320 286 #endif 321 287 default:
+5
include/linux/regmap.h
··· 315 315 * masks are used. 316 316 * @zero_flag_mask: If set, read_flag_mask and write_flag_mask are used even 317 317 * if they are both empty. 318 + * @use_relaxed_mmio: If set, MMIO R/W operations will not use memory barriers. 319 + * This can avoid load on devices which don't require strict 320 + * orderings, but drivers should carefully add any explicit 321 + * memory barriers when they may require them. 318 322 * @use_single_read: If set, converts the bulk read operation into a series of 319 323 * single read operations. This is useful for a device that 320 324 * does not support bulk read. ··· 392 388 393 389 bool use_single_read; 394 390 bool use_single_write; 391 + bool use_relaxed_mmio; 395 392 bool can_multi_write; 396 393 397 394 enum regmap_endian reg_format_endian;