hardware.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* SPDX-License-Identifier: Apache-2.0 */
  2. /*
  3. * Copyright (C) 2008 The Android Open Source Project
  4. *
  5. */
  6. #ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H
  7. #define ANDROID_INCLUDE_HARDWARE_HARDWARE_H
  8. #include <stdint.h>
  9. #include <sys/cdefs.h>
  10. __BEGIN_DECLS
  11. /*
  12. * Value for the hw_module_t.tag field
  13. */
  14. #define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
  15. #define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
  16. #define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
  17. #define HARDWARE_MAKE_API_VERSION(maj,min) \
  18. ((((maj) & 0xff) << 8) | ((min) & 0xff))
  19. #define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \
  20. ((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff))
  21. #define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff0000
  22. #define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff
  23. /*
  24. * The current HAL API version.
  25. *
  26. * All module implementations must set the hw_module_t.hal_api_version field
  27. * to this value when declaring the module with HAL_MODULE_INFO_SYM.
  28. *
  29. * Note that previous implementations have always set this field to 0.
  30. * Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
  31. * to be 100% binary compatible.
  32. *
  33. */
  34. #define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
  35. /*
  36. * Helper macros for module implementors.
  37. *
  38. * The derived modules should provide convenience macros for supported
  39. * versions so that implementations can explicitly specify module/device
  40. * versions at definition time.
  41. *
  42. * Use this macro to set the hw_module_t.module_api_version field.
  43. */
  44. #define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
  45. #define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
  46. /*
  47. * Use this macro to set the hw_device_t.version field
  48. */
  49. #define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
  50. #define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
  51. struct hw_module_t;
  52. struct hw_module_methods_t;
  53. struct hw_device_t;
  54. /**
  55. * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
  56. * and the fields of this data structure must begin with hw_module_t
  57. * followed by module specific information.
  58. */
  59. typedef struct hw_module_t {
  60. /** tag must be initialized to HARDWARE_MODULE_TAG */
  61. uint32_t tag;
  62. /**
  63. * The API version of the implemented module. The module owner is
  64. * responsible for updating the version when a module interface has
  65. * changed.
  66. *
  67. * The derived modules such as gralloc and audio own and manage this field.
  68. * The module user must interpret the version field to decide whether or
  69. * not to inter-operate with the supplied module implementation.
  70. * For example, SurfaceFlinger is responsible for making sure that
  71. * it knows how to manage different versions of the gralloc-module API,
  72. * and AudioFlinger must know how to do the same for audio-module API.
  73. *
  74. * The module API version should include a major and a minor component.
  75. * For example, version 1.0 could be represented as 0x0100. This format
  76. * implies that versions 0x0100-0x01ff are all API-compatible.
  77. *
  78. * In the future, libhardware will expose a hw_get_module_version()
  79. * (or equivalent) function that will take minimum/maximum supported
  80. * versions as arguments and would be able to reject modules with
  81. * versions outside of the supplied range.
  82. */
  83. uint16_t module_api_version;
  84. #define version_major module_api_version
  85. /**
  86. * version_major/version_minor defines are supplied here for temporary
  87. * source code compatibility. They will be removed in the next version.
  88. * ALL clients must convert to the new version format.
  89. */
  90. /**
  91. * The API version of the HAL module interface. This is meant to
  92. * version the hw_module_t, hw_module_methods_t, and hw_device_t
  93. * structures and definitions.
  94. *
  95. * The HAL interface owns this field. Module users/implementations
  96. * must NOT rely on this value for version information.
  97. *
  98. * Presently, 0 is the only valid value.
  99. */
  100. uint16_t hal_api_version;
  101. #define version_minor hal_api_version
  102. /** Identifier of module */
  103. const char *id;
  104. /** Name of this module */
  105. const char *name;
  106. /** Author/owner/implementor of the module */
  107. const char *author;
  108. /** Modules methods */
  109. struct hw_module_methods_t* methods;
  110. /** module's dso */
  111. void* dso;
  112. /** padding to 128 bytes, reserved for future use */
  113. uint32_t reserved[32-7];
  114. } hw_module_t;
  115. typedef struct hw_module_methods_t {
  116. /** Open a specific device */
  117. int (*open)(const struct hw_module_t* module, const char* id,
  118. struct hw_device_t** device);
  119. } hw_module_methods_t;
  120. /**
  121. * Every device data structure must begin with hw_device_t
  122. * followed by module specific public methods and attributes.
  123. */
  124. typedef struct hw_device_t {
  125. /** tag must be initialized to HARDWARE_DEVICE_TAG */
  126. uint32_t tag;
  127. /**
  128. * Version of the module-specific device API. This value is used by
  129. * the derived-module user to manage different device implementations.
  130. *
  131. * The module user is responsible for checking the module_api_version
  132. * and device version fields to ensure that the user is capable of
  133. * communicating with the specific module implementation.
  134. *
  135. * One module can support multiple devices with different versions. This
  136. * can be useful when a device interface changes in an incompatible way
  137. * but it is still necessary to support older implementations at the same
  138. * time. One such example is the Camera 2.0 API.
  139. *
  140. * This field is interpreted by the module user and is ignored by the
  141. * HAL interface itself.
  142. */
  143. uint32_t version;
  144. /** reference to the module this device belongs to */
  145. struct hw_module_t* module;
  146. /** padding reserved for future use */
  147. uint32_t reserved[12];
  148. /** Close this device */
  149. int (*close)(struct hw_device_t* device);
  150. } hw_device_t;
  151. /**
  152. * Name of the hal_module_info
  153. */
  154. #define HAL_MODULE_INFO_SYM HMI
  155. /**
  156. * Name of the hal_module_info as a string
  157. */
  158. #define HAL_MODULE_INFO_SYM_AS_STR "HMI"
  159. /**
  160. * Get the module info associated with a module by id.
  161. *
  162. * @return: 0 == success, <0 == error and *module == NULL
  163. */
  164. int hw_get_module(const char *id, const struct hw_module_t **module);
  165. /**
  166. * Get the module info associated with a module instance by class 'class_id'
  167. * and instance 'inst'.
  168. *
  169. * Some modules types necessitate multiple instances. For example audio supports
  170. * multiple concurrent interfaces and thus 'audio' is the module class
  171. * and 'primary' or 'a2dp' are module interfaces. This implies that the files
  172. * providing these modules would be named audio.primary.<variant>.so and
  173. * audio.a2dp.<variant>.so
  174. *
  175. * @return: 0 == success, <0 == error and *module == NULL
  176. */
  177. int hw_get_module_by_class(const char *class_id, const char *inst,
  178. const struct hw_module_t **module);
  179. __END_DECLS
  180. #endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */