Fix build error
[platform/core/system/libdevice-node.git] / hw / common.h
1 /*
2  * libdevice-node
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #ifndef __HW_COMMON_H__
21 #define __HW_COMMON_H__
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #include <errno.h>
28 #include <stddef.h>
29 #include <stdint.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #define MAKE_TAG_CONSTANT(A,B,C,D)      (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
34 #define HARDWARE_INFO_TAG       MAKE_TAG_CONSTANT('T','H','I','T')
35
36 struct hw_common;
37 struct hw_info {
38         /* magic must be initialized to HARDWARE_INFO_TAG */
39         uint32_t magic;
40         /* HAL version */
41         uint16_t hal_version;
42         /* device version */
43         uint16_t device_version;
44         /* device id */
45         const char *id;
46         /* device name */
47         const char *name;
48         /* author name */
49         const char *author;
50         /* module's dso */
51         void *dso;
52         /* reserved for future use */
53         uint32_t reserved[8];
54         /* open device */
55         int (*open)(struct hw_info *info,
56                         const char *id, struct hw_common **common);
57         /* close device */
58         int (*close)(struct hw_common *common);
59 };
60
61 struct hw_common {
62         /* indicate to this device information structure */
63         struct hw_info *info;
64 };
65
66 #define MAKE_VERSION(maj,min) \
67         ((((maj) & 0xff) << 8) | ((min) & 0xff))
68
69 /**
70  * Version of the struct hw_info
71  */
72 #define HARDWARE_INFO_VERSION   MAKE_VERSION(1,0)
73
74 /**
75  * Name of the hardware info symbolic (Tizen Hardware Info)
76  */
77 #define HARDWARE_INFO_SYM               TizenHwInfo
78
79 int hw_get_info(const char *id, const struct hw_info **info);
80
81 /**
82  * Structure define of hardware info module
83  * All hardware module should be use below define
84  * to make a specific structure for Tizen HAL.
85  * hw_get_info function will load a hw_info structure
86  * by using TizenHwInfo name at runtime.
87  * TizenHwInfo means Tizen Hardware Info.
88  */
89 #define HARDWARE_MODULE_STRUCTURE       \
90         __attribute__ ((visibility("default"))) \
91         struct hw_info HARDWARE_INFO_SYM
92
93 #ifndef container_of
94 #define container_of(ptr, type, member) ({                      \
95         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
96         (type *)( (char *)__mptr - offsetof(type,member) );})
97 #endif
98
99
100 #ifdef __cplusplus
101 }
102 #endif
103
104 #endif
105