hwspinlock.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
  2. /*
  3. * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
  4. */
  5. #ifndef _HWSPINLOCK_H_
  6. #define _HWSPINLOCK_H_
  7. /**
  8. * Implement a hwspinlock uclass.
  9. * Hardware spinlocks are used to perform hardware protection of
  10. * critical sections and synchronisation between multiprocessors.
  11. */
  12. struct udevice;
  13. /**
  14. * struct hwspinlock - A handle to (allowing control of) a single hardware
  15. * spinlock.
  16. *
  17. * @dev: The device which implements the hardware spinlock.
  18. * @id: The hardware spinlock ID within the provider.
  19. */
  20. struct hwspinlock {
  21. struct udevice *dev;
  22. unsigned long id;
  23. };
  24. #if CONFIG_IS_ENABLED(DM_HWSPINLOCK)
  25. /**
  26. * hwspinlock_get_by_index - Get a hardware spinlock by integer index
  27. *
  28. * This looks up and request a hardware spinlock. The index is relative to the
  29. * client device; each device is assumed to have n hardware spinlock associated
  30. * with it somehow, and this function finds and requests one of them.
  31. *
  32. * @dev: The client device.
  33. * @index: The index of the hardware spinlock to request, within the
  34. * client's list of hardware spinlock.
  35. * @hws: A pointer to a hardware spinlock struct to initialize.
  36. * @return 0 if OK, or a negative error code.
  37. */
  38. int hwspinlock_get_by_index(struct udevice *dev,
  39. int index, struct hwspinlock *hws);
  40. /**
  41. * Lock the hardware spinlock
  42. *
  43. * @hws: A hardware spinlock struct that previously requested by
  44. * hwspinlock_get_by_index
  45. * @timeout: Timeout value in msecs
  46. * @return: 0 if OK, -ETIMEDOUT if timeout, -ve on other errors
  47. */
  48. int hwspinlock_lock_timeout(struct hwspinlock *hws, unsigned int timeout);
  49. /**
  50. * Unlock the hardware spinlock
  51. *
  52. * @hws: A hardware spinlock struct that previously requested by
  53. * hwspinlock_get_by_index
  54. * @return: 0 if OK, -ve on error
  55. */
  56. int hwspinlock_unlock(struct hwspinlock *hws);
  57. #else
  58. static inline int hwspinlock_get_by_index(struct udevice *dev,
  59. int index,
  60. struct hwspinlock *hws)
  61. {
  62. return -ENOSYS;
  63. }
  64. static inline int hwspinlock_lock_timeout(struct hwspinlock *hws,
  65. int timeout)
  66. {
  67. return -ENOSYS;
  68. }
  69. static inline int hwspinlock_unlock(struct hwspinlock *hws)
  70. {
  71. return -ENOSYS;
  72. }
  73. #endif /* CONFIG_DM_HWSPINLOCK */
  74. struct ofnode_phandle_args;
  75. /**
  76. * struct hwspinlock_ops - Driver model hwspinlock operations
  77. *
  78. * The uclass interface is implemented by all hwspinlock devices which use
  79. * driver model.
  80. */
  81. struct hwspinlock_ops {
  82. /**
  83. * of_xlate - Translate a client's device-tree (OF) hardware specifier.
  84. *
  85. * The hardware core calls this function as the first step in
  86. * implementing a client's hwspinlock_get_by_*() call.
  87. *
  88. * @hws: The hardware spinlock struct to hold the translation
  89. * result.
  90. * @args: The hardware spinlock specifier values from device tree.
  91. * @return 0 if OK, or a negative error code.
  92. */
  93. int (*of_xlate)(struct hwspinlock *hws,
  94. struct ofnode_phandle_args *args);
  95. /**
  96. * Lock the hardware spinlock
  97. *
  98. * @dev: hwspinlock Device
  99. * @index: index of the lock to be used
  100. * @return 0 if OK, -ve on error
  101. */
  102. int (*lock)(struct udevice *dev, int index);
  103. /**
  104. * Unlock the hardware spinlock
  105. *
  106. * @dev: hwspinlock Device
  107. * @index: index of the lock to be unlocked
  108. * @return 0 if OK, -ve on error
  109. */
  110. int (*unlock)(struct udevice *dev, int index);
  111. /**
  112. * Relax - optional
  113. * Platform-specific relax method, called by hwspinlock core
  114. * while spinning on a lock, between two successive call to
  115. * lock
  116. *
  117. * @dev: hwspinlock Device
  118. */
  119. void (*relax)(struct udevice *dev);
  120. };
  121. #endif /* _HWSPINLOCK_H_ */