unsigned int **major_versions, unsigned int **minor_versions,
enum hal_common_transport **transports, int *num_versions);
+/**
+ * @brief Get the transport that compatible with the current hal backend
+ * @details Compare to the hal_common_get_supported_interface_versions(), this function
+ * is distinctive in that it returns single transport that is compatible with backend,
+ * wherase the hal_common_get_supported_interface_versions() returns all the possible
+ * versions and transports specified on the manifest file.
+ * @param[in] module HAL id among enum hal_module
+ * @param[out] transport The transport of version that matching to the hal backend installed
+ * @return @c 0 on success, otherwise a negative error value
+ * @code
+ * // If a module manifest has specified transport like below, and the underlying
+ * // backend is version of 2.0, then it returns HAL_COMMON_TRANSPORT_PASSTHROUGH.
+ * // <hal>
+ * // <name>HAL_MODULE_FOO</name>
+ * // <version transport="ipc">1.0</version>
+ * // <version transport="passthrough">2.1</version>
+ * // </hal>
+ * int ret = hal_common_get_transport(HAL_MODULE_FOO, &transport); // HAL_COMMON_TRANSPORT_PASSTHROUGH
+ *
+ * // If there are multiple transport throughout the platform-version, then
+ * // the transport of the latest compatible platform-version will be returned. That is,
+ * // if a module manifest has specified transport like below, and the underlying
+ * // backend is version of 3.0, then it returns HAL_COMMON_TRANSPORT_IPC.
+ * // <manifest platform-version="9.0">
+ * // <hal>
+ * // <name>HAL_MODULE_BAR</name>
+ * // <version transport="passthrough">3.0</version>
+ * // </hal>
+ * // </manifest>
+ * // <manifest platform-version="10.0">
+ * // <hal>
+ * // <name>HAL_MODULE_BAR</name>
+ * // <version transport="ipc">3.1</version>
+ * // </hal>
+ * // </manifest>
+ * int ret = hal_common_get_transport(HAL_MODULE_BAR, &transport); // HAL_COMMON_TRANSPORT_IPC
+ * @endcode
+ */
+int hal_common_get_transport(enum hal_module module, enum hal_common_transport *transport);
+
/**
* @}
*/
return hal_api_cc_get_supported_interface_versions(module,
major_versions, minor_versions, transports, num_versions);
}
+
+EXPORT
+int hal_common_get_transport(enum hal_module module, enum hal_common_transport *transport)
+{
+ if (!transport)
+ return -EINVAL;
+
+ if (!HALCC_ENABLED) {
+ _W("Hal compatibility checker is disabled. Always passthrough mode");
+ *transport = HAL_COMMON_TRANSPORT_PASSTHROUGH;
+ return 0;
+ }
+
+ return hal_api_cc_get_transport(module, transport);
+}
return false;
}
+
+int halcc_hal_get_transport_by_version(halcc_hal *hal, int major, int minor, enum hal_common_transport *transport)
+{
+ int ret;
+ int version_list[64][3] = { 0 , };
+ int num_version_list = 0;
+
+ if (!hal || !transport)
+ return -EINVAL;
+
+ ret = halcc_hal_get_version_list(hal, version_list,
+ sizeof(version_list) / sizeof(version_list[0]),
+ &num_version_list);
+ if (ret < 0)
+ return ret;
+
+ for (size_t i = 0; i < num_version_list; ++i) {
+ if (version_list[i][0] != major)
+ continue;
+
+ if (version_list[i][1] < minor)
+ continue;
+
+ *transport = version_list[i][2];
+ return 0;
+ }
+
+ return -ENOENT;
+}
int halcc_hal_get_version_list(halcc_hal *hal,
int version_list[][3], int max_num_version_list, int *num_version_list);
bool halcc_hal_is_compatible_with_version(halcc_hal *hal, int major, int minor);
+int halcc_hal_get_transport_by_version(halcc_hal *hal, int major, int minor,
+ enum hal_common_transport *transport);
#ifdef __cplusplus
}
int version_list[HALCC_NUM_VERSION_LIST_MAX][3];
int num_version_list;
enum hal_common_backend_compatibility compatibility;
+ enum hal_common_transport compatible_transport;
};
static struct compatibility_info g_compatibility_info[HAL_MODULE_END];
info->compatibility = HAL_COMMON_BACKEND_COMPATIBILITY_UNKNOWN;
ret = hal_common_get_backend_version(module, &major, &minor);
- if (ret < 0)
+ if (ret < 0) {
+ _W("Failed to get backend version, %d", ret);
goto out;
+ }
- if (halcc_hal_is_compatible_with_version(hal, major, minor))
- info->compatibility = HAL_COMMON_BACKEND_COMPATIBILITY_COMPATIBLE;
- else
+ if (!halcc_hal_is_compatible_with_version(hal, major, minor)) {
+ _W("Failed to check compatibility, %d", ret);
info->compatibility = HAL_COMMON_BACKEND_COMPATIBILITY_INCOMPATIBLE;
+ goto out;
+ }
+
+ info->compatibility = HAL_COMMON_BACKEND_COMPATIBILITY_COMPATIBLE;
+
+ ret = halcc_hal_get_transport_by_version(hal, major, minor, &info->compatible_transport);
+ if (ret < 0)
+ _W("Failed to get transport, %d", ret);
out:
info->initialized = true;
return 0;
}
+
+int hal_api_cc_get_transport(enum hal_module module, enum hal_common_transport *transport)
+{
+ int ret;
+ struct compatibility_info info = { 0 , };
+
+ if (!transport)
+ return -EINVAL;
+
+ ret = load_module_compatibility_info(module, &info);
+ if (ret < 0) {
+ ret = load_module_compatibility_info_fallback(module, &info, false);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (info.compatibility != HAL_COMMON_BACKEND_COMPATIBILITY_COMPATIBLE)
+ return -ELIBBAD;
+
+ *transport = info.compatible_transport;
+
+ return 0;
+}
int hal_api_cc_get_supported_interface_versions(enum hal_module module,
unsigned int **major_versions, unsigned int **minor_versions,
enum hal_common_transport **transports, int *num_versions);
+int hal_api_cc_get_transport(enum hal_module module, enum hal_common_transport *transport);
#ifdef HAL_API_COMMON_UNITTEST /* For test use only */
void hal_api_cc_set_compatibility_result_path(const char *path);
hal_api_cc_unset_compatibility_result_path();
hal_api_cc_reset_compatibility_info();
}
+
+TEST_F(HalccObjectTest, hal_get_transport_with_result_file)
+{
+ int ret;
+ enum hal_common_transport transport;
+
+ hal_api_cc_set_compatibility_result_path(g_compatibility_result_path);
+
+ mock_hal_backend_data_set_version(HAL_MODULE_TBM, 1, 0);
+
+ ret = hal_common_get_transport(HAL_MODULE_TBM, &transport);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_PASSTHROUGH);
+
+ /* need to reset cache as the backend version will be changed */
+ ret = truncate(g_compatibility_result_path, 0);
+ ASSERT_EQ(ret, 0);
+ hal_api_cc_reset_compatibility_info();
+
+ mock_hal_backend_data_set_version(HAL_MODULE_TBM, 2, 0);
+
+ ret = hal_common_get_transport(HAL_MODULE_TBM, &transport);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_IPC);
+
+ /* need to remove cache as the backend version will be changed */
+ ret = truncate(g_compatibility_result_path, 0);
+ ASSERT_EQ(ret, 0);
+ hal_api_cc_reset_compatibility_info();
+
+ mock_hal_backend_data_set_version(HAL_MODULE_TBM, 3, 0);
+
+ ret = hal_common_get_transport(HAL_MODULE_TBM, &transport);
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_PASSTHROUGH);
+
+ /* need to remove cache as the backend version will be changed */
+ ret = truncate(g_compatibility_result_path, 0);
+ ASSERT_EQ(ret, 0);
+ hal_api_cc_reset_compatibility_info();
+
+ /* incompatible version should return error */
+ mock_hal_backend_data_set_version(HAL_MODULE_TBM, 4, 0);
+
+ ret = hal_common_get_transport(HAL_MODULE_TBM, &transport);
+ ASSERT_EQ(ret, -ELIBBAD);
+
+ unlink(g_compatibility_result_path);
+ hal_api_cc_unset_compatibility_result_path();
+ hal_api_cc_reset_compatibility_info();
+}