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