aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/regmap.h
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2015-07-08 02:30:18 -0400
committerMark Brown <broonie@kernel.org>2015-08-07 09:50:59 -0400
commit3cfe7a74d42b7e3644f8b2b26aa20146d4f90f0f (patch)
treeab9efb80f6e886934d6e003582cd40d0cb9a2d34 /include/linux/regmap.h
parent331a5fc9f2ed28033ddda89acb2a9b43592a545d (diff)
regmap: Use different lockdep class for each regmap init call
Lockdep validator complains about recursive locking and deadlock when two different regmap instances are called in a nested order. That happens anytime a regmap read/write call needs to access another regmap. This is because, for performance reason, lockdep groups all locks initialized by the same mutex_init() in the same lock class. Therefore all regmap mutexes are in the same lock class, leading to lockdep "nested locking" warnings if a regmap accesses another regmap. In general, it is impossible to establish in advance the hierarchy of regmaps, so we make sure that each regmap init call initializes its own static lock_class_key. This is done by wrapping all regmap_init calls into macros. This also allows us to give meaningful names to the lock_class_key. For example, in rt5677 case, we have in /proc/lockdep_chains: irq_context: 0 [ffffffc0018d2198] &dev->mutex [ffffffc0018d2198] &dev->mutex [ffffffc001bd7f60] rt5677:5104:(&rt5677_regmap)->_lock [ffffffc001bd7f58] rt5677:5096:(&rt5677_regmap_physical)->_lock [ffffffc001b95448] &(&base->lock)->rlock The above would have resulted in a lockdep recursive warning previously. This is not the case anymore as the lockdep validator now clearly identifies the 2 regmaps as separate. Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'include/linux/regmap.h')
-rw-r--r--include/linux/regmap.h192
1 files changed, 143 insertions, 49 deletions
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 59c55ea0f0b5..5d7027286032 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -17,6 +17,7 @@
17#include <linux/rbtree.h> 17#include <linux/rbtree.h>
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/bug.h> 19#include <linux/bug.h>
20#include <linux/lockdep.h>
20 21
21struct module; 22struct module;
22struct device; 23struct device;
@@ -324,46 +325,147 @@ struct regmap_bus {
324 enum regmap_endian val_format_endian_default; 325 enum regmap_endian val_format_endian_default;
325}; 326};
326 327
327struct regmap *regmap_init(struct device *dev, 328/*
328 const struct regmap_bus *bus, 329 * __regmap_init functions.
329 void *bus_context, 330 *
330 const struct regmap_config *config); 331 * These functions take a lock key and name parameter, and should not be called
331int regmap_attach_dev(struct device *dev, struct regmap *map, 332 * directly. Instead, use the regmap_init macros that generate a key and name
332 const struct regmap_config *config); 333 * for each call.
333struct regmap *regmap_init_i2c(struct i2c_client *i2c, 334 */
334 const struct regmap_config *config); 335struct regmap *__regmap_init(struct device *dev,
335struct regmap *regmap_init_spi(struct spi_device *dev, 336 const struct regmap_bus *bus,
336 const struct regmap_config *config); 337 void *bus_context,
337struct regmap *regmap_init_spmi_base(struct spmi_device *dev, 338 const struct regmap_config *config,
338 const struct regmap_config *config); 339 struct lock_class_key *lock_key,
339struct regmap *regmap_init_spmi_ext(struct spmi_device *dev, 340 const char *lock_name);
340 const struct regmap_config *config); 341struct regmap *__regmap_init_i2c(struct i2c_client *i2c,
341struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id, 342 const struct regmap_config *config,
342 void __iomem *regs, 343 struct lock_class_key *lock_key,
343 const struct regmap_config *config); 344 const char *lock_name);
344struct regmap *regmap_init_ac97(struct snd_ac97 *ac97, 345struct regmap *__regmap_init_spi(struct spi_device *dev,
345 const struct regmap_config *config); 346 const struct regmap_config *config,
346 347 struct lock_class_key *lock_key,
347struct regmap *devm_regmap_init(struct device *dev, 348 const char *lock_name);
348 const struct regmap_bus *bus, 349struct regmap *__regmap_init_spmi_base(struct spmi_device *dev,
349 void *bus_context, 350 const struct regmap_config *config,
350 const struct regmap_config *config); 351 struct lock_class_key *lock_key,
351struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c, 352 const char *lock_name);
352 const struct regmap_config *config); 353struct regmap *__regmap_init_spmi_ext(struct spmi_device *dev,
353struct regmap *devm_regmap_init_spi(struct spi_device *dev, 354 const struct regmap_config *config,
354 const struct regmap_config *config); 355 struct lock_class_key *lock_key,
355struct regmap *devm_regmap_init_spmi_base(struct spmi_device *dev, 356 const char *lock_name);
356 const struct regmap_config *config); 357struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
357struct regmap *devm_regmap_init_spmi_ext(struct spmi_device *dev, 358 void __iomem *regs,
358 const struct regmap_config *config); 359 const struct regmap_config *config,
359struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id, 360 struct lock_class_key *lock_key,
360 void __iomem *regs, 361 const char *lock_name);
361 const struct regmap_config *config); 362struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
362struct regmap *devm_regmap_init_ac97(struct snd_ac97 *ac97, 363 const struct regmap_config *config,
363 const struct regmap_config *config); 364 struct lock_class_key *lock_key,
365 const char *lock_name);
366
367struct regmap *__devm_regmap_init(struct device *dev,
368 const struct regmap_bus *bus,
369 void *bus_context,
370 const struct regmap_config *config,
371 struct lock_class_key *lock_key,
372 const char *lock_name);
373struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c,
374 const struct regmap_config *config,
375 struct lock_class_key *lock_key,
376 const char *lock_name);
377struct regmap *__devm_regmap_init_spi(struct spi_device *dev,
378 const struct regmap_config *config,
379 struct lock_class_key *lock_key,
380 const char *lock_name);
381struct regmap *__devm_regmap_init_spmi_base(struct spmi_device *dev,
382 const struct regmap_config *config,
383 struct lock_class_key *lock_key,
384 const char *lock_name);
385struct regmap *__devm_regmap_init_spmi_ext(struct spmi_device *dev,
386 const struct regmap_config *config,
387 struct lock_class_key *lock_key,
388 const char *lock_name);
389struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
390 const char *clk_id,
391 void __iomem *regs,
392 const struct regmap_config *config,
393 struct lock_class_key *lock_key,
394 const char *lock_name);
395struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
396 const struct regmap_config *config,
397 struct lock_class_key *lock_key,
398 const char *lock_name);
364 399
400/*
401 * Wrapper for regmap_init macros to include a unique lockdep key and name
402 * for each call. No-op if CONFIG_LOCKDEP is not set.
403 *
404 * @fn: Real function to call (in the form __[*_]regmap_init[_*])
405 * @name: Config variable name (#config in the calling macro)
406 **/
407#ifdef CONFIG_LOCKDEP
408#define __regmap_lockdep_wrapper(fn, name, ...) \
409( \
410 ({ \
411 static struct lock_class_key _key; \
412 fn(__VA_ARGS__, &_key, \
413 KBUILD_BASENAME ":" \
414 __stringify(__LINE__) ":" \
415 "(" name ")->lock"); \
416 }) \
417)
418#else
419#define __regmap_lockdep_wrapper(fn, name, ...) fn(__VA_ARGS__, NULL, NULL)
420#endif
421
422#define regmap_init(dev, bus, bus_context, config) \
423 __regmap_lockdep_wrapper(__regmap_init, #config, \
424 dev, bus, bus_context, config)
425int regmap_attach_dev(struct device *dev, struct regmap *map,
426 const struct regmap_config *config);
427#define regmap_init_i2c(i2c, config) \
428 __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \
429 i2c, config)
430#define regmap_init_spi(dev, config) \
431 __regmap_lockdep_wrapper(__regmap_init_spi, #config, \
432 dev, config)
433#define regmap_init_spmi_base(dev, config) \
434 __regmap_lockdep_wrapper(__regmap_init_spmi_base, #config, \
435 dev, config)
436#define regmap_init_spmi_ext(dev, config) \
437 __regmap_lockdep_wrapper(__regmap_init_spmi_ext, #config, \
438 dev, config)
439#define regmap_init_mmio_clk(dev, clk_id, regs, config) \
440 __regmap_lockdep_wrapper(__regmap_init_mmio_clk, #config, \
441 dev, clk_id, regs, config)
442#define regmap_init_ac97(ac97, config) \
443 __regmap_lockdep_wrapper(__regmap_init_ac97, #config, \
444 ac97, config)
365bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); 445bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
366 446
447#define devm_regmap_init(dev, bus, bus_context, config) \
448 __regmap_lockdep_wrapper(__devm_regmap_init, #config, \
449 dev, bus, bus_context, config)
450#define devm_regmap_init_i2c(i2c, config) \
451 __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \
452 i2c, config)
453#define devm_regmap_init_spi(dev, config) \
454 __regmap_lockdep_wrapper(__devm_regmap_init_spi, #config, \
455 dev, config)
456#define devm_regmap_init_spmi_base(dev, config) \
457 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_base, #config, \
458 dev, config)
459#define devm_regmap_init_spmi_ext(dev, config) \
460 __regmap_lockdep_wrapper(__devm_regmap_init_spmi_ext, #config, \
461 dev, config)
462#define devm_regmap_init_mmio_clk(dev, clk_id, regs, config) \
463 __regmap_lockdep_wrapper(__devm_regmap_init_mmio_clk, #config, \
464 dev, clk_id, regs, config)
465#define devm_regmap_init_ac97(ac97, config) \
466 __regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config, \
467 ac97, config)
468
367/** 469/**
368 * regmap_init_mmio(): Initialise register map 470 * regmap_init_mmio(): Initialise register map
369 * 471 *
@@ -374,12 +476,8 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
374 * The return value will be an ERR_PTR() on error or a valid pointer to 476 * The return value will be an ERR_PTR() on error or a valid pointer to
375 * a struct regmap. 477 * a struct regmap.
376 */ 478 */
377static inline struct regmap *regmap_init_mmio(struct device *dev, 479#define regmap_init_mmio(dev, regs, config) \
378 void __iomem *regs, 480 regmap_init_mmio_clk(dev, NULL, regs, config)
379 const struct regmap_config *config)
380{
381 return regmap_init_mmio_clk(dev, NULL, regs, config);
382}
383 481
384/** 482/**
385 * devm_regmap_init_mmio(): Initialise managed register map 483 * devm_regmap_init_mmio(): Initialise managed register map
@@ -392,12 +490,8 @@ static inline struct regmap *regmap_init_mmio(struct device *dev,
392 * to a struct regmap. The regmap will be automatically freed by the 490 * to a struct regmap. The regmap will be automatically freed by the
393 * device management code. 491 * device management code.
394 */ 492 */
395static inline struct regmap *devm_regmap_init_mmio(struct device *dev, 493#define devm_regmap_init_mmio(dev, regs, config) \
396 void __iomem *regs, 494 devm_regmap_init_mmio_clk(dev, NULL, regs, config)
397 const struct regmap_config *config)
398{
399 return devm_regmap_init_mmio_clk(dev, NULL, regs, config);
400}
401 495
402void regmap_exit(struct regmap *map); 496void regmap_exit(struct regmap *map);
403int regmap_reinit_cache(struct regmap *map, 497int regmap_reinit_cache(struct regmap *map,