The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H |
| 18 | #define ANDROID_INCLUDE_HARDWARE_HARDWARE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/cdefs.h> |
| 22 | |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 23 | #include <cutils/native_handle.h> |
Iliyan Malchev | c12d0e9 | 2011-04-14 20:00:02 -0700 | [diff] [blame] | 24 | #include <system/graphics.h> |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 25 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 26 | __BEGIN_DECLS |
| 27 | |
| 28 | /* |
| 29 | * Value for the hw_module_t.tag field |
| 30 | */ |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 31 | |
| 32 | #define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D)) |
| 33 | |
| 34 | #define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T') |
| 35 | #define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T') |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 36 | |
| 37 | struct hw_module_t; |
| 38 | struct hw_module_methods_t; |
| 39 | struct hw_device_t; |
| 40 | |
| 41 | /** |
| 42 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 43 | * and the fields of this data structure must begin with hw_module_t |
| 44 | * followed by module specific information. |
| 45 | */ |
Mathias Agopian | 9d82c1a | 2009-08-19 11:20:55 -0700 | [diff] [blame] | 46 | typedef struct hw_module_t { |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 47 | /** tag must be initialized to HARDWARE_MODULE_TAG */ |
| 48 | uint32_t tag; |
| 49 | |
Dima Zavin | 2b57780 | 2012-03-19 22:38:15 -0700 | [diff] [blame^] | 50 | /** |
| 51 | * The API version of the implemented module. The module owner is |
| 52 | * responsible for updating the version when a module interface has |
| 53 | * changed. |
| 54 | * |
| 55 | * The derived modules such as gralloc and audio own and manage this field. |
| 56 | * The module user must interpret the version field to decide whether or |
| 57 | * not to inter-operate with the supplied module implementation. |
| 58 | * For example, SurfaceFlinger is responsible for making sure that |
| 59 | * it knows how to manage different versions of the gralloc-module API, |
| 60 | * and AudioFlinger must know how to do the same for audio-module API. |
| 61 | * |
| 62 | * The module API version should include a major and a minor component. |
| 63 | * For example, version 1.0 could be represented as 0x0100. This format |
| 64 | * implies that versions 0x0100-0x01ff are all API-compatible. |
| 65 | * |
| 66 | * In the future, libhardware will expose a hw_get_module_version() |
| 67 | * (or equivalent) function that will take minimum/maximum supported |
| 68 | * versions as arguments and would be able to reject modules with |
| 69 | * versions outside of the supplied range. |
| 70 | */ |
| 71 | uint16_t module_api_version; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 72 | |
Dima Zavin | 2b57780 | 2012-03-19 22:38:15 -0700 | [diff] [blame^] | 73 | /** |
| 74 | * The API version of the HAL module interface. This is meant to |
| 75 | * version the hw_module_t, hw_module_methods_t, and hw_device_t |
| 76 | * structures and definitions. |
| 77 | * |
| 78 | * The HAL interface owns this field. Module users/implementations |
| 79 | * must NOT rely on this value for version information. |
| 80 | * |
| 81 | * Presently, 0 is the only valid value. |
| 82 | */ |
| 83 | uint16_t hal_api_version; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 84 | |
| 85 | /** Identifier of module */ |
| 86 | const char *id; |
| 87 | |
| 88 | /** Name of this module */ |
| 89 | const char *name; |
| 90 | |
| 91 | /** Author/owner/implementor of the module */ |
| 92 | const char *author; |
| 93 | |
| 94 | /** Modules methods */ |
| 95 | struct hw_module_methods_t* methods; |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 96 | |
| 97 | /** module's dso */ |
| 98 | void* dso; |
| 99 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 100 | /** padding to 128 bytes, reserved for future use */ |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 101 | uint32_t reserved[32-7]; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 102 | |
Mathias Agopian | 9d82c1a | 2009-08-19 11:20:55 -0700 | [diff] [blame] | 103 | } hw_module_t; |
| 104 | |
| 105 | typedef struct hw_module_methods_t { |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 106 | /** Open a specific device */ |
| 107 | int (*open)(const struct hw_module_t* module, const char* id, |
| 108 | struct hw_device_t** device); |
Mathias Agopian | 9d82c1a | 2009-08-19 11:20:55 -0700 | [diff] [blame] | 109 | |
| 110 | } hw_module_methods_t; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * Every device data structure must begin with hw_device_t |
| 114 | * followed by module specific public methods and attributes. |
| 115 | */ |
Mathias Agopian | 9d82c1a | 2009-08-19 11:20:55 -0700 | [diff] [blame] | 116 | typedef struct hw_device_t { |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 117 | /** tag must be initialized to HARDWARE_DEVICE_TAG */ |
| 118 | uint32_t tag; |
| 119 | |
Dima Zavin | 2b57780 | 2012-03-19 22:38:15 -0700 | [diff] [blame^] | 120 | /** |
| 121 | * Version of the module-specific device API. This value is used by |
| 122 | * the derived-module user to manage different device implementations. |
| 123 | * |
| 124 | * The module user is responsible for checking the module_api_version |
| 125 | * and device version fields to ensure that the user is capable of |
| 126 | * communicating with the specific module implementation. |
| 127 | * |
| 128 | * One module can support multiple devices with different versions. This |
| 129 | * can be useful when a device interface changes in an incompatible way |
| 130 | * but it is still necessary to support older implementations at the same |
| 131 | * time. One such example is the Camera 2.0 API. |
| 132 | * |
| 133 | * This field is interpreted by the module user and is ignored by the |
| 134 | * HAL interface itself. |
| 135 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 136 | uint32_t version; |
| 137 | |
| 138 | /** reference to the module this device belongs to */ |
| 139 | struct hw_module_t* module; |
| 140 | |
| 141 | /** padding reserved for future use */ |
| 142 | uint32_t reserved[12]; |
| 143 | |
| 144 | /** Close this device */ |
| 145 | int (*close)(struct hw_device_t* device); |
Mathias Agopian | 9d82c1a | 2009-08-19 11:20:55 -0700 | [diff] [blame] | 146 | |
| 147 | } hw_device_t; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 148 | |
| 149 | /** |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 150 | * Name of the hal_module_info |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 151 | */ |
| 152 | #define HAL_MODULE_INFO_SYM HMI |
| 153 | |
| 154 | /** |
| 155 | * Name of the hal_module_info as a string |
| 156 | */ |
| 157 | #define HAL_MODULE_INFO_SYM_AS_STR "HMI" |
| 158 | |
| 159 | /** |
| 160 | * Get the module info associated with a module by id. |
Dima Zavin | 54921de | 2011-04-18 10:55:37 -0700 | [diff] [blame] | 161 | * |
| 162 | * @return: 0 == success, <0 == error and *module == NULL |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 163 | */ |
| 164 | int hw_get_module(const char *id, const struct hw_module_t **module); |
| 165 | |
Dima Zavin | 54921de | 2011-04-18 10:55:37 -0700 | [diff] [blame] | 166 | /** |
| 167 | * Get the module info associated with a module instance by class 'class_id' |
| 168 | * and instance 'inst'. |
| 169 | * |
| 170 | * Some modules types necessitate multiple instances. For example audio supports |
| 171 | * multiple concurrent interfaces and thus 'audio' is the module class |
| 172 | * and 'primary' or 'a2dp' are module interfaces. This implies that the files |
| 173 | * providing these modules would be named audio.primary.<variant>.so and |
| 174 | * audio.a2dp.<variant>.so |
| 175 | * |
| 176 | * @return: 0 == success, <0 == error and *module == NULL |
| 177 | */ |
| 178 | int hw_get_module_by_class(const char *class_id, const char *inst, |
| 179 | const struct hw_module_t **module); |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 180 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 181 | __END_DECLS |
| 182 | |
| 183 | #endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */ |