blob: a6d9ad9038ca1c0ddc577a0b70d342373390c840 [file] [log] [blame]
Roman Stratiienko6a7ac122021-04-02 17:19:54 +03001// clang-format off
2/*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H
19#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H
20
21#include <stdint.h>
22#include <sys/cdefs.h>
23
24#include <cutils/native_handle.h>
25#include <system/graphics.h>
26
27__BEGIN_DECLS
28
29/*
30 * Value for the hw_module_t.tag field
31 */
32
33#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
34
35#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
36#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
37
38#define HARDWARE_MAKE_API_VERSION(maj,min) \
39 ((((maj) & 0xff) << 8) | ((min) & 0xff))
40
41#define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \
42 ((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff))
43#define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff0000
44#define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff
45
46
47/*
48 * The current HAL API version.
49 *
50 * All module implementations must set the hw_module_t.hal_api_version field
51 * to this value when declaring the module with HAL_MODULE_INFO_SYM.
52 *
53 * Note that previous implementations have always set this field to 0.
54 * Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
55 * to be 100% binary compatible.
56 *
57 */
58#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
59
60/*
61 * Helper macros for module implementors.
62 *
63 * The derived modules should provide convenience macros for supported
64 * versions so that implementations can explicitly specify module/device
65 * versions at definition time.
66 *
67 * Use this macro to set the hw_module_t.module_api_version field.
68 */
69#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
70#define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
71
72/*
73 * Use this macro to set the hw_device_t.version field
74 */
75#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
76#define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
77
78struct hw_module_t;
79struct hw_module_methods_t;
80struct hw_device_t;
81
82/**
83 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
84 * and the fields of this data structure must begin with hw_module_t
85 * followed by module specific information.
86 */
87typedef struct hw_module_t {
88 /** tag must be initialized to HARDWARE_MODULE_TAG */
89 uint32_t tag;
90
91 /**
92 * The API version of the implemented module. The module owner is
93 * responsible for updating the version when a module interface has
94 * changed.
95 *
96 * The derived modules such as gralloc and audio own and manage this field.
97 * The module user must interpret the version field to decide whether or
98 * not to inter-operate with the supplied module implementation.
99 * For example, SurfaceFlinger is responsible for making sure that
100 * it knows how to manage different versions of the gralloc-module API,
101 * and AudioFlinger must know how to do the same for audio-module API.
102 *
103 * The module API version should include a major and a minor component.
104 * For example, version 1.0 could be represented as 0x0100. This format
105 * implies that versions 0x0100-0x01ff are all API-compatible.
106 *
107 * In the future, libhardware will expose a hw_get_module_version()
108 * (or equivalent) function that will take minimum/maximum supported
109 * versions as arguments and would be able to reject modules with
110 * versions outside of the supplied range.
111 */
112 uint16_t module_api_version;
113#define version_major module_api_version
114 /**
115 * version_major/version_minor defines are supplied here for temporary
116 * source code compatibility. They will be removed in the next version.
117 * ALL clients must convert to the new version format.
118 */
119
120 /**
121 * The API version of the HAL module interface. This is meant to
122 * version the hw_module_t, hw_module_methods_t, and hw_device_t
123 * structures and definitions.
124 *
125 * The HAL interface owns this field. Module users/implementations
126 * must NOT rely on this value for version information.
127 *
128 * Presently, 0 is the only valid value.
129 */
130 uint16_t hal_api_version;
131#define version_minor hal_api_version
132
133 /** Identifier of module */
134 const char *id;
135
136 /** Name of this module */
137 const char *name;
138
139 /** Author/owner/implementor of the module */
140 const char *author;
141
142 /** Modules methods */
143 struct hw_module_methods_t* methods;
144
145 /** module's dso */
146 void* dso;
147
148#ifdef __LP64__
149 uint64_t reserved[32-7];
150#else
151 /** padding to 128 bytes, reserved for future use */
152 uint32_t reserved[32-7];
153#endif
154
155} hw_module_t;
156
157typedef struct hw_module_methods_t {
158 /** Open a specific device */
159 int (*open)(const struct hw_module_t* module, const char* id,
160 struct hw_device_t** device);
161
162} hw_module_methods_t;
163
164/**
165 * Every device data structure must begin with hw_device_t
166 * followed by module specific public methods and attributes.
167 */
168typedef struct hw_device_t {
169 /** tag must be initialized to HARDWARE_DEVICE_TAG */
170 uint32_t tag;
171
172 /**
173 * Version of the module-specific device API. This value is used by
174 * the derived-module user to manage different device implementations.
175 *
176 * The module user is responsible for checking the module_api_version
177 * and device version fields to ensure that the user is capable of
178 * communicating with the specific module implementation.
179 *
180 * One module can support multiple devices with different versions. This
181 * can be useful when a device interface changes in an incompatible way
182 * but it is still necessary to support older implementations at the same
183 * time. One such example is the Camera 2.0 API.
184 *
185 * This field is interpreted by the module user and is ignored by the
186 * HAL interface itself.
187 */
188 uint32_t version;
189
190 /** reference to the module this device belongs to */
191 struct hw_module_t* module;
192
193 /** padding reserved for future use */
194#ifdef __LP64__
195 uint64_t reserved[12];
196#else
197 uint32_t reserved[12];
198#endif
199
200 /** Close this device */
201 int (*close)(struct hw_device_t* device);
202
203} hw_device_t;
204
205#ifdef __cplusplus
206#define TO_HW_DEVICE_T_OPEN(x) reinterpret_cast<struct hw_device_t**>(x)
207#else
208#define TO_HW_DEVICE_T_OPEN(x) (struct hw_device_t**)(x)
209#endif
210
211/**
212 * Name of the hal_module_info
213 */
214#define HAL_MODULE_INFO_SYM HMI
215
216/**
217 * Name of the hal_module_info as a string
218 */
219#define HAL_MODULE_INFO_SYM_AS_STR "HMI"
220
221/**
222 * Get the module info associated with a module by id.
223 *
224 * @return: 0 == success, <0 == error and *module == NULL
225 */
226int hw_get_module(const char *id, const struct hw_module_t **module);
227
228/**
229 * Get the module info associated with a module instance by class 'class_id'
230 * and instance 'inst'.
231 *
232 * Some modules types necessitate multiple instances. For example audio supports
233 * multiple concurrent interfaces and thus 'audio' is the module class
234 * and 'primary' or 'a2dp' are module interfaces. This implies that the files
235 * providing these modules would be named audio.primary.<variant>.so and
236 * audio.a2dp.<variant>.so
237 *
238 * @return: 0 == success, <0 == error and *module == NULL
239 */
240int hw_get_module_by_class(const char *class_id, const char *inst,
241 const struct hw_module_t **module);
242
243__END_DECLS
244
245#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */