4 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
28 #define EXPORT __attribute__ ((visibility("default")))
32 const char *hal_common_get_backend_library_name(enum hal_module module)
36 /* Check parameter whether is valid or not */
37 if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) {
38 _E("Invalid parameter of HAL module (%d)\n", module);
42 #if defined(__aarch64__)
43 library_name = hal_module_info[module].library_name_64bit;
45 library_name = hal_module_info[module].library_name;
49 _E("%s backend library name is NULL\n",
50 hal_module_info[module].module_name);
57 const char *hal_common_get_backend_symbol_name(enum hal_module module)
59 /* Check parameter whether is valid or not */
60 if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) {
61 _E("Invalid paramer of HAL module (%d)\n", module);
65 if (!hal_module_info[module].symbol_name) {
66 _E("%s backend library name is NULL\n",
67 hal_module_info[module].module_name);
71 return hal_module_info[module].symbol_name;
75 int hal_common_get_backend(enum hal_module module, void **data)
79 const char *library_name, *symbol_name;
83 library_name = hal_common_get_backend_library_name(HAL_MODULE_FOO);
85 _E("Failed to get backend library name of %s\n",
86 hal_module_info[module].module_name);
87 return TIZEN_ERROR_INVALID_PARAMETER;
90 handle = dlopen(library_name, RTLD_LAZY);
92 _E("Failed to load shared library (%s)\n", dlerror());
93 return TIZEN_ERROR_INVALID_PARAMETER;
96 symbol_name = hal_common_get_backend_symbol_name(HAL_MODULE_FOO);
98 _E("Failed to get backend symbol name of %s\n",
99 hal_module_info[module].module_name);
100 ret = TIZEN_ERROR_INVALID_PARAMETER;
104 backend = dlsym(handle, symbol_name);
106 _E("Failed to find backend data (%s)\n", dlerror());
107 ret = TIZEN_ERROR_INVALID_PARAMETER;
111 /* Print backend module and vendor name */
113 /* Check HAL ABI Version */
114 ret = hal_common_check_backend_abi_version(HAL_MODULE_FOO,
115 backend->abi_version);
117 _E("Failed to check ABI version of %s\n",
118 hal_module_info[module].module_name);
119 ret = TIZEN_ERROR_INVALID_PARAMETER;
123 /* Get the backend module data */
124 if (!backend->init) {
125 _E("hal_backend->init() is NULL for %s\n",
126 hal_module_info[module].module_name);
127 ret = TIZEN_ERROR_INVALID_PARAMETER;
131 ret = backend->init(data);
133 _E("Failed to initialize backend: name(%s)/vendor(%s)\n",
134 backend->name, backend->vendor);
135 ret = TIZEN_ERROR_INVALID_PARAMETER;
139 hal_module_info[module].library_backend = backend;
140 hal_module_info[module].library_handle = handle;
142 _I("Get HAL backend: name(%s)/vendor(%s)\n",
143 backend->name, backend->vendor);
145 return TIZEN_ERROR_NONE;
152 int hal_common_put_backend(enum hal_module module, void *data)
154 hal_backend *backend = NULL;
158 /* Check parameter whether is valid or not */
159 if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) {
160 _E("Invalid parameter of HAL module (%d)\n", module);
161 return TIZEN_ERROR_INVALID_PARAMETER;
164 backend = hal_module_info[module].library_backend;
165 handle = hal_module_info[module].library_handle;
167 if (backend && backend->exit) {
168 ret = backend->exit(data);
170 _E("Failed to exit backend: name(%s)/vendor(%s)\n",
171 backend->name, backend->vendor);
172 return TIZEN_ERROR_INVALID_PARAMETER;
179 _I("Put HAL backend: name(%s)/vendor(%s)\n",
180 backend->name, backend->vendor);
182 return TIZEN_ERROR_NONE;
186 int hal_common_check_backend_abi_version(enum hal_module module,
187 enum hal_abi_version abi_version)
191 /* Check parameter whether is valid or not */
192 if (module <= HAL_MODULE_UNKNOWN || module >= HAL_MODULE_END) {
193 _E("Invalid paramer of HAL module (%d)\n", module);
194 return TIZEN_ERROR_INVALID_PARAMETER;
197 if (abi_version <= HAL_ABI_VERSION_UNKNOWN
198 || abi_version >= HAL_ABI_VERSION_END) {
199 _E("Invalid paramer of HAL ABI version (%d)\n", abi_version);
200 return TIZEN_ERROR_INVALID_PARAMETER;
203 /* Check abi_version whether is supported or not */
204 if (!hal_module_info[module].hal_api) {
205 _E("HAL module(%d) doesn't support HAL API\n", module);
206 return TIZEN_ERROR_INVALID_PARAMETER;
209 if (!hal_module_info[module].num_abi_versions
210 || !hal_module_info[module].abi_versions) {
211 _E("HAL module(%d) doesn't have the ABI version information\n",
213 return TIZEN_ERROR_INVALID_PARAMETER;
216 for (i = 0; i < hal_module_info[module].num_abi_versions; i++) {
217 struct hal_abi_version_match *data
218 = &hal_module_info[module].abi_versions[i];
220 if (g_curr_hal_abi_version != data->curr_version)
223 if (abi_version <= data->curr_version
224 && abi_version >= data->compat_version)
225 return TIZEN_ERROR_NONE;
228 return TIZEN_ERROR_INVALID_PARAMETER;