1 /*
2  * Copyright (C) 2018 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 #pragma once
18 
19 #include <cstdint>
20 
21 #define MAKE_TAG_CONSTANT(A, B, C, D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
22 
23 #define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
24 #define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
25 
26 #define HARDWARE_MAKE_API_VERSION(maj, min) ((((maj)&0xff) << 8) | ((min)&0xff))
27 
28 #define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
29 
30 struct hw_module_methods_t;
31 
32 struct hw_module_t {
33     uint32_t tag;
34     uint16_t module_api_version;
35     uint16_t hal_api_version;
36     const char* id;
37     const char* name;
38     const char* author;
39     hw_module_methods_t* methods;
40     void* dso;
41 #ifdef __LP64__
42     uint64_t reserved[32 - 7];
43 #else
44     uint32_t reserved[32 - 7];
45 #endif
46 };
47 
48 struct hw_device_t {
49     uint32_t tag;
50     uint32_t version;
51     struct hw_module_t* module;
52 #ifdef __LP64__
53     uint64_t reserved[12];
54 #else
55     uint32_t reserved[12];
56 #endif
57     int (*close)(hw_device_t* device);
58 };
59 
60 struct hw_module_methods_t {
61     int (*open)(const hw_module_t*, const char*, hw_device_t**);
62 };
63 
64 extern "C" {
65 int hw_get_module(const char* id, const hw_module_t** module);
66 };
67