hwspinlock_internal.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Hardware spinlocks internal header
  4. *
  5. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
  6. *
  7. * Contact: Ohad Ben-Cohen <ohad@wizery.com>
  8. */
  9. #ifndef __HWSPINLOCK_HWSPINLOCK_H
  10. #define __HWSPINLOCK_HWSPINLOCK_H
  11. #include <linux/spinlock.h>
  12. #include <linux/device.h>
  13. struct hwspinlock_device;
  14. /**
  15. * struct hwspinlock_ops - platform-specific hwspinlock handlers
  16. *
  17. * @trylock: make a single attempt to take the lock. returns 0 on
  18. * failure and true on success. may _not_ sleep.
  19. * @unlock: release the lock. always succeed. may _not_ sleep.
  20. * @relax: optional, platform-specific relax handler, called by hwspinlock
  21. * core while spinning on a lock, between two successive
  22. * invocations of @trylock. may _not_ sleep.
  23. */
  24. struct hwspinlock_ops {
  25. int (*trylock)(struct hwspinlock *lock);
  26. void (*unlock)(struct hwspinlock *lock);
  27. void (*relax)(struct hwspinlock *lock);
  28. };
  29. /**
  30. * struct hwspinlock - this struct represents a single hwspinlock instance
  31. * @bank: the hwspinlock_device structure which owns this lock
  32. * @lock: initialized and used by hwspinlock core
  33. * @priv: private data, owned by the underlying platform-specific hwspinlock drv
  34. */
  35. struct hwspinlock {
  36. struct hwspinlock_device *bank;
  37. spinlock_t lock;
  38. void *priv;
  39. };
  40. /**
  41. * struct hwspinlock_device - a device which usually spans numerous hwspinlocks
  42. * @dev: underlying device, will be used to invoke runtime PM api
  43. * @ops: platform-specific hwspinlock handlers
  44. * @base_id: id index of the first lock in this device
  45. * @num_locks: number of locks in this device
  46. * @lock: dynamically allocated array of 'struct hwspinlock'
  47. */
  48. struct hwspinlock_device {
  49. struct device *dev;
  50. const struct hwspinlock_ops *ops;
  51. int base_id;
  52. int num_locks;
  53. struct hwspinlock lock[0];
  54. };
  55. static inline int hwlock_to_id(struct hwspinlock *hwlock)
  56. {
  57. int local_id = hwlock - &hwlock->bank->lock[0];
  58. return hwlock->bank->base_id + local_id;
  59. }
  60. #endif /* __HWSPINLOCK_HWSPINLOCK_H */