• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description: cipher driver common header. \n
16  *
17  * History: \n
18  * 2023-03-22, Create file. \n
19  */
20 #ifndef DRV_COMMON_H
21 #define DRV_COMMON_H
22 
23 #include "crypto_type.h"
24 #include "crypto_common_struct.h"
25 #include "hal_common.h"
26 
27 #ifdef __cplusplus
28 #if __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 #endif /* __cplusplus */
32 
33 /************************************************** common check log start************************************/
34 #ifndef drv_crypto_check_param
35 #define drv_crypto_check_param(module, cond) do { \
36     crypto_check_param(ERROR_LAYER_DRV, module, cond, ERROR_INVALID_PARAM); \
37 } while (0)
38 #endif
39 
40 #ifndef drv_crypto_check_param_null
41 #define drv_crypto_check_param_null(module, _val) do { \
42     crypto_check_param_null(ERROR_LAYER_DRV, module, _val); \
43 } while (0)
44 #endif
45 
46 #ifndef drv_crypto_pke_check_param
47 #define drv_crypto_pke_check_param(cond) do { \
48     drv_crypto_check_param(ERROR_MODULE_PKE, cond); \
49 } while (0)
50 #endif
51 
52 #ifndef drv_crypto_pke_check_param_null
53 #define drv_crypto_pke_check_param_null(_val) do { \
54     drv_crypto_check_param_null(ERROR_MODULE_PKE, _val); \
55 } while (0)
56 #endif
57 /************************************************** common check log end************************************/
58 
59 typedef enum {
60     CRYPTO_MEM_TYPE_MMZ,
61     CRYPTO_MEM_TYPE_SMMU,
62 } crypto_mem_type;
63 
64 typedef void *(*func_malloc)(unsigned int size, crypto_mem_type mem_type);
65 typedef void (*func_free)(void *ptr);
66 typedef td_phys_addr_t (*func_get_phys_addr)(void *ptr);
67 typedef void *(*func_get_virt_addr)(void *ptr);
68 typedef td_bool (*func_get_smmu_table_addr)(unsigned long *table, unsigned long *rdaddr, unsigned long *wraddr);
69 typedef void *(*func_register_coherent_mem)(void *virt_addr, td_phys_addr_t phys_addr, unsigned int size);
70 typedef void (*func_unregister_coherent_mem)(void *virt_addr);
71 typedef crypto_cpu_type (*func_get_cpu_type)(void);
72 typedef td_u32 (*func_get_pke_rom_lib_start_addr)(td_void);
73 
74 typedef struct {
75     func_malloc malloc_coherent;
76     func_free free_coherent;
77     func_get_phys_addr get_phys_addr;
78     func_get_virt_addr get_virt_addr;
79     func_get_smmu_table_addr get_smmu_table_addr;
80     func_register_coherent_mem register_coherent_mem;
81     func_unregister_coherent_mem unregister_coherent_mem;
82     func_get_cpu_type get_cpu_type;
83     func_get_pke_rom_lib_start_addr get_pke_rom_lib_start_addr;
84 } crypto_drv_func;
85 
86 td_s32 drv_cipher_register_func(const crypto_drv_func *drv_func_list);
87 
88 #ifdef __cplusplus
89 #if __cplusplus
90 }
91 #endif /* __cplusplus */
92 #endif /* __cplusplus */
93 
94 #endif