halapi: Add support of RISC-V architecture type
[platform/hal/api/common.git] / src / common.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
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 __COMMON_H__
18 #define __COMMON_H__
19
20 #include <stdbool.h>
21
22 #include "hal-common.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #ifdef ENABLE_DLOG
29 #include <dlog.h>
30
31 #define _D(fmt, args...)        SLOGD(fmt, ##args)
32 #define _I(fmt, args...)        SLOGI(fmt, ##args)
33 #define _W(fmt, args...)        SLOGW(fmt, ##args)
34 #define _E(fmt, args...)        SLOGE(fmt, ##args)
35 #else
36 #define _D(fmt, args...)        do { } while(0)
37 #define _I(fmt, args...)        do { } while(0)
38 #define _W(fmt, args...)        do { } while(0)
39 #define _E(fmt, args...)        do { } while(0)
40 #endif
41
42 #define ARRAY_SIZE(name)        (sizeof(name)/sizeof(name[0]))
43
44 enum hal_license {
45         HAL_LICENSE_UNKNOWN = 0,
46         HAL_LICENSE_APACHE_2_0,
47         HAL_LICENSE_FLORA,
48         HAL_LICENSE_MIT,
49         HAL_LICENSE_END,
50 };
51
52 enum hal_group {
53         HAL_GROUP_UNKNOWN = 0,
54         HAL_GROUP_GRAPHICS,
55         HAL_GROUP_MULTIMEDIA,
56         HAL_GROUP_CONNECTIVITY,
57         HAL_GROUP_TELEPHONY,
58         HAL_GROUP_LOCATION,
59         HAL_GROUP_SYSTEM,
60         HAL_GROUP_END,
61 };
62
63 static const char *const hal_group_string[] = {
64         [HAL_GROUP_UNKNOWN] = "HAL_GROUP_UNKNOWN",
65         [HAL_GROUP_GRAPHICS] = "HAL_GROUP_GRAPHICS",
66         [HAL_GROUP_MULTIMEDIA] = "HAL_GROUP_MULTIMEDIA",
67         [HAL_GROUP_CONNECTIVITY] = "HAL_GROUP_CONNECTIVITY",
68         [HAL_GROUP_TELEPHONY] = "HAL_GROUP_TELEPHONY",
69         [HAL_GROUP_LOCATION] = "HAL_GROUP_LOCATION",
70         [HAL_GROUP_SYSTEM] = "HAL_GROUP_SYSTEM",
71 };
72
73 /**
74  * hal-api-common (/platform/hal/api/common) provides the HAL ABI
75  * (Application Binary Interface) version check feature which is used to check
76  * the ABI compatibility between HAL API package like hal-api-audio-*.rpm
77  * and HAL backend package like hal-backend-audio-*.rpm which is included
78  * in hal.img. In order to compare ABI version between two binary,
79  * Tizen core platform always must maintain the current HAL ABI version.
80  * So that, define the below global variable (g_platform_curr_abi_version).
81  *
82  * 'g_platform_curr_abi_version' will be used for all HAL API modules,
83  * to check whether HAL backend ABI version of each module in hal.img
84  * is supported or not with current Tizen core HAL ABI version.
85  *
86  * 'g_platform_curr_abi_version' must be updated when Tizen platform
87  * will be released officially.
88  */
89 struct hal_abi_version_match {
90         enum hal_abi_version platform_abi_version;
91         enum hal_abi_version backend_min_abi_version;
92 };
93
94 struct __hal_module_info {
95         int usage_count;
96
97         enum hal_group group;
98         enum hal_module module;
99         enum hal_license license;
100         char *module_name;
101         char *backend_module_name;
102
103         char *library_name;
104         char *library_name_64bit;
105         void *handle;
106         hal_backend *backend;
107         char *symbol_name;
108
109         unsigned int num_abi_versions;
110         struct hal_abi_version_match *abi_versions;
111
112         bool hal_api;
113         bool hal_backend_extension;
114 };
115
116 static inline const char* get_backend_library_name(struct __hal_module_info *info)
117 {
118         if (!info)
119                 return NULL;
120
121 #if defined(__aarch64__) || defined(__x86_64__) || defined (__riscv)
122         return info->library_name_64bit;
123 #else
124         return info->library_name;
125 #endif
126 }
127
128 #ifdef __cplusplus
129 }
130 #endif
131 #endif /* __COMMON_H__ */