ipa_rm_resource.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* Copyright (c) 2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef _IPA_RM_RESOURCE_H_
  13. #define _IPA_RM_RESOURCE_H_
  14. #include <linux/list.h>
  15. #include <mach/ipa.h>
  16. #include "ipa_rm_peers_list.h"
  17. /**
  18. * enum ipa_rm_resource_state - resource state
  19. */
  20. enum ipa_rm_resource_state {
  21. IPA_RM_RELEASED,
  22. IPA_RM_REQUEST_IN_PROGRESS,
  23. IPA_RM_GRANTED,
  24. IPA_RM_RELEASE_IN_PROGRESS
  25. };
  26. /**
  27. * enum ipa_rm_resource_type - IPA resource manager resource type
  28. */
  29. enum ipa_rm_resource_type {
  30. IPA_RM_PRODUCER,
  31. IPA_RM_CONSUMER
  32. };
  33. /**
  34. * struct ipa_rm_notification_info - notification information
  35. * of IPA RM client
  36. * @reg_params: registration parameters
  37. * @explicit: registered explicitly by ipa_rm_register()
  38. * @link: link to the list of all registered clients information
  39. */
  40. struct ipa_rm_notification_info {
  41. struct ipa_rm_register_params reg_params;
  42. bool explicit;
  43. struct list_head link;
  44. };
  45. /**
  46. * struct ipa_rm_resource - IPA RM resource
  47. * @name: name identifying resource
  48. * @state: state of the resource
  49. * @state_lock: lock for all resource state related variables
  50. * @peers_list: list of the peers of the resource
  51. */
  52. struct ipa_rm_resource {
  53. enum ipa_rm_resource_name name;
  54. enum ipa_rm_resource_type type;
  55. enum ipa_rm_resource_state state;
  56. spinlock_t state_lock;
  57. struct ipa_rm_peers_list *peers_list;
  58. };
  59. /**
  60. * struct ipa_rm_resource_cons - IPA RM consumer
  61. * @resource: resource
  62. * @usage_count: number of producers in GRANTED / REQUESTED state
  63. * using this consumer
  64. * @request_resource: function which should be called to request resource
  65. * from resource manager
  66. * @release_resource: function which should be called to release resource
  67. * from resource manager
  68. * Add new fields after @resource only.
  69. */
  70. struct ipa_rm_resource_cons {
  71. struct ipa_rm_resource resource;
  72. int usage_count;
  73. int (*request_resource)(void);
  74. int (*release_resource)(void);
  75. };
  76. /**
  77. * struct ipa_rm_resource_prod - IPA RM producer
  78. * @resource: resource
  79. * @event_listeners: clients registered with this producer
  80. * for notifications in resource state
  81. * @event_listeners_lock: RW lock protecting the event listeners list
  82. * Add new fields after @resource only.
  83. */
  84. struct ipa_rm_resource_prod {
  85. struct ipa_rm_resource resource;
  86. struct list_head event_listeners;
  87. rwlock_t event_listeners_lock;
  88. int pending_request;
  89. int pending_release;
  90. };
  91. int ipa_rm_resource_create(
  92. struct ipa_rm_create_params *create_params,
  93. struct ipa_rm_resource **resource);
  94. int ipa_rm_resource_delete(struct ipa_rm_resource *resource);
  95. int ipa_rm_resource_producer_register(struct ipa_rm_resource_prod *producer,
  96. struct ipa_rm_register_params *reg_params,
  97. bool explicit);
  98. int ipa_rm_resource_producer_deregister(struct ipa_rm_resource_prod *producer,
  99. struct ipa_rm_register_params *reg_params);
  100. int ipa_rm_resource_add_dependency(struct ipa_rm_resource *resource,
  101. struct ipa_rm_resource *depends_on);
  102. int ipa_rm_resource_delete_dependency(struct ipa_rm_resource *resource,
  103. struct ipa_rm_resource *depends_on);
  104. int ipa_rm_resource_producer_request(struct ipa_rm_resource_prod *producer);
  105. int ipa_rm_resource_producer_release(struct ipa_rm_resource_prod *producer);
  106. void ipa_rm_resource_consumer_handle_cb(struct ipa_rm_resource_cons *consumer,
  107. enum ipa_rm_event event);
  108. void ipa_rm_resource_producer_notify_clients(
  109. struct ipa_rm_resource_prod *producer,
  110. enum ipa_rm_event event,
  111. bool notify_registered_only);
  112. int ipa_rm_resource_producer_print_stat(
  113. struct ipa_rm_resource *resource,
  114. char *buf,
  115. int size);
  116. #endif /* _IPA_RM_RESOURCE_H_ */