hwspinlock_internal.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Hardware spinlocks internal header
  3. *
  4. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
  5. *
  6. * Contact: Ohad Ben-Cohen <ohad@wizery.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #ifndef __HWSPINLOCK_HWSPINLOCK_H
  18. #define __HWSPINLOCK_HWSPINLOCK_H
  19. #include <linux/spinlock.h>
  20. #include <linux/device.h>
  21. struct hwspinlock_device;
  22. /**
  23. * struct hwspinlock_ops - platform-specific hwspinlock handlers
  24. *
  25. * @trylock: make a single attempt to take the lock. returns 0 on
  26. * failure and true on success. may _not_ sleep.
  27. * @unlock: release the lock. always succeed. may _not_ sleep.
  28. * @relax: optional, platform-specific relax handler, called by hwspinlock
  29. * core while spinning on a lock, between two successive
  30. * invocations of @trylock. may _not_ sleep.
  31. */
  32. struct hwspinlock_ops {
  33. int (*trylock)(struct hwspinlock *lock);
  34. void (*unlock)(struct hwspinlock *lock);
  35. void (*relax)(struct hwspinlock *lock);
  36. };
  37. /**
  38. * struct hwspinlock - this struct represents a single hwspinlock instance
  39. * @bank: the hwspinlock_device structure which owns this lock
  40. * @lock: initialized and used by hwspinlock core
  41. * @priv: private data, owned by the underlying platform-specific hwspinlock drv
  42. */
  43. struct hwspinlock {
  44. struct hwspinlock_device *bank;
  45. spinlock_t lock;
  46. void *priv;
  47. };
  48. /**
  49. * struct hwspinlock_device - a device which usually spans numerous hwspinlocks
  50. * @dev: underlying device, will be used to invoke runtime PM api
  51. * @ops: platform-specific hwspinlock handlers
  52. * @base_id: id index of the first lock in this device
  53. * @num_locks: number of locks in this device
  54. * @lock: dynamically allocated array of 'struct hwspinlock'
  55. */
  56. struct hwspinlock_device {
  57. struct device *dev;
  58. const struct hwspinlock_ops *ops;
  59. int base_id;
  60. int num_locks;
  61. struct hwspinlock lock[0];
  62. };
  63. static inline int hwlock_to_id(struct hwspinlock *hwlock)
  64. {
  65. int local_id = hwlock - &hwlock->bank->lock[0];
  66. return hwlock->bank->base_id + local_id;
  67. }
  68. #endif /* __HWSPINLOCK_HWSPINLOCK_H */