/* * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved. * Description:Key slot driver.Provide all the kernel API and ioctl API. * Author : Hisilicon * Create: 2019/06/22 */ #include "drv_keyslot.h" #include "linux/huanglong/securec.h" #include "drv_keyslot_utils.h" #include "hal_keyslot.h" #include "drv_keyslot_func.h" #include "drv_keyslot_ext.h" #include "drv_keyslot_fmea.h" static ks_export_func g_ks_export_funcs; td_s32 drv_ks_init(td_void) { td_s32 ret; ret = osal_exportfunc_register(SOC_ID_KEYSLOT, "SOC_KS", (td_void *)&g_ks_export_funcs); if (ret != TD_SUCCESS) { print_err_func(osal_exportfunc_register, ret); return ret; } ret = osal_exportfunc_register(SOC_ID_USR, "SOC_USR", TD_NULL); if (ret != TD_SUCCESS) { osal_exportfunc_unregister(SOC_ID_KEYSLOT); print_err_func(osal_exportfunc_register, ret); goto out0; } ret = ks_mgmt_init(); if (ret != TD_SUCCESS) { print_err_func(osal_exportfunc_register, ret); goto out1; } keyslot_lock_init(); return TD_SUCCESS; out1: osal_exportfunc_unregister(SOC_ID_USR); out0: osal_exportfunc_unregister(SOC_ID_KEYSLOT); return ret; } td_void drv_ks_deinit(td_void) { ks_mgmt_exit(); osal_exportfunc_unregister(SOC_ID_KEYSLOT); osal_exportfunc_unregister(SOC_ID_USR); return; } td_s32 ext_drv_ks_create(const ext_keyslot_type slot_type, td_handle *ks_handle) { td_s32 ret; td_u32 slot_num = 0; if (ks_handle == TD_NULL) { print_err_code(SOC_ERR_KS_PTR_NULL); return SOC_ERR_KS_PTR_NULL; } ret = ks_mgmt_auto_lock(slot_type, &slot_num); *ks_handle = id_2_handle(slot_num, (td_u8)slot_type); return ret; } EXPORT_SYMBOL(ext_drv_ks_create); td_s32 ext_drv_ks_destory(const ext_keyslot_type slot_type, const td_handle ks_handle) { return ks_mgmt_unlock(slot_type, handle_2_id(ks_handle)); } EXPORT_SYMBOL(ext_drv_ks_destory); static ks_export_func g_ks_export_funcs = { .ext_ks_create = ext_drv_ks_create, .ext_ks_destory = ext_drv_ks_destory, };