hwspinlock_internal.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * @bust: optional, platform-specific bust handler, called by hwspinlock
  21. * core to bust a specific lock.
  22. * @relax: optional, platform-specific relax handler, called by hwspinlock
  23. * core while spinning on a lock, between two successive
  24. * invocations of @trylock. may _not_ sleep.
  25. */
  26. struct hwspinlock_ops {
  27. int (*trylock)(struct hwspinlock *lock);
  28. void (*unlock)(struct hwspinlock *lock);
  29. int (*bust)(struct hwspinlock *lock, unsigned int id);
  30. void (*relax)(struct hwspinlock *lock);
  31. };
  32. /**
  33. * struct hwspinlock - this struct represents a single hwspinlock instance
  34. * @bank: the hwspinlock_device structure which owns this lock
  35. * @lock: initialized and used by hwspinlock core
  36. * @priv: private data, owned by the underlying platform-specific hwspinlock drv
  37. */
  38. struct hwspinlock {
  39. struct hwspinlock_device *bank;
  40. spinlock_t lock;
  41. void *priv;
  42. };
  43. /**
  44. * struct hwspinlock_device - a device which usually spans numerous hwspinlocks
  45. * @dev: underlying device, will be used to invoke runtime PM api
  46. * @ops: platform-specific hwspinlock handlers
  47. * @base_id: id index of the first lock in this device
  48. * @num_locks: number of locks in this device
  49. * @lock: dynamically allocated array of 'struct hwspinlock'
  50. */
  51. struct hwspinlock_device {
  52. struct device *dev;
  53. const struct hwspinlock_ops *ops;
  54. int base_id;
  55. int num_locks;
  56. struct hwspinlock lock[];
  57. };
  58. static inline int hwlock_to_id(struct hwspinlock *hwlock)
  59. {
  60. int local_id = hwlock - &hwlock->bank->lock[0];
  61. return hwlock->bank->base_id + local_id;
  62. }
  63. #endif /* __HWSPINLOCK_HWSPINLOCK_H */