1 /* 2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef __TDE_DEFINE_H__ 20 #define __TDE_DEFINE_H__ 21 22 #ifdef HI_BUILD_IN_BOOT 23 #include "exports.h" 24 #include "hi_common.h" 25 #include "hi_go_common.h" 26 #endif 27 #include "hi_type.h" 28 #include "hi_debug.h" 29 #include "wmalloc.h" 30 #include "tde_config.h" 31 #include "tde_adp.h" 32 #include "hi_osal.h" 33 #include "mm_ext.h" 34 #include "proc_ext.h" 35 #include "mod_ext.h" 36 37 #ifdef __cplusplus 38 #if __cplusplus 39 extern "C" { 40 #endif 41 #endif /* __cplusplus */ 42 43 /* Pixel format classify */ 44 typedef enum { 45 TDE_COLORFMT_CATEGORY_ARGB, 46 TDE_COLORFMT_CATEGORY_CLUT, 47 TDE_COLORFMT_CATEGORY_AN, 48 TDE_COLORFMT_CATEGORY_YCBCR, 49 TDE_COLORFMT_CATEGORY_BYTE, 50 TDE_COLORFMT_CATEGORY_HALFWORD, 51 TDE_COLORFMT_CATEGORY_MB, 52 TDE_COLORFMT_CATEGORY_BUTT 53 } tde_colorfmt_category; 54 55 /* Node submit type, Independent operation node, Operated head node, Operated middle node */ 56 typedef enum { 57 TDE_NODE_SUBM_ALONE = 0, /* current node submit as independent operated node */ 58 TDE_NODE_SUBM_PARENT = 1, /* current node submit as operated parent node */ 59 TDE_NODE_SUBM_CHILD /* current node submit as operated child node */ 60 } tde_node_subm_type; 61 62 /* Operation setting information node */ 63 typedef struct { 64 hi_void *buf; /* setting information node buffer */ 65 hi_u32 node_sz; /* current node occupied size, united in byte */ 66 hi_u64 update; /* current node update flag */ 67 hi_u64 phy_addr; /* current node addr in hardware list */ 68 } tde_node_buf; 69 70 /* Notified mode after current node's job end */ 71 typedef enum { 72 TDE_JOB_NONE_NOTIFY = 0, /* none notify after job end */ 73 TDE_JOB_COMPL_NOTIFY, /* notify after job end */ 74 TDE_JOB_WAKE_NOTIFY, /* wake noytify after job end */ 75 TDE_JOB_NOTIFY_BUTT 76 } tde_notify_mode; 77 78 #define TDE_MAX_WAIT_TIMEOUT 2000 79 80 #define MMB_ADDR_INVALID 1 81 82 #define tde_trace(level, fmt...) \ 83 do { \ 84 HI_TRACE(level, HI_ID_TDE, "[Func]:%s [Line]:%d [Info]:", __FUNCTION__, __LINE__); \ 85 HI_TRACE(level, HI_ID_TDE, ##fmt); \ 86 } while (0) 87 88 #define tde_fatal(fmt...) tde_trace(HI_DBG_EMERG, fmt) 89 #define tde_error(fmt...) tde_trace(HI_DBG_ERR, fmt) 90 #define tde_warning(fmt...) tde_trace(HI_DBG_WARN, fmt) 91 #define tde_info(fmt...) tde_trace(HI_DBG_INFO, fmt) 92 93 hi_void *tde_malloc(hi_u32 size); 94 hi_void tde_free(hi_void *ptr); 95 #ifdef CONFIG_TDE_PM_ENABLE 96 typedef struct { 97 hi_s32 id; 98 const hi_s8 *name; 99 struct device dev; 100 } pm_basedev; 101 #endif 102 #define tde_spin_lock(lock, flag) osal_spin_lock_irqsave((lock), &(flag)) 103 #define tde_spin_unlock(lock, flag) osal_spin_unlock_irqrestore((lock), &(flag)) 104 105 #define tde_free_mmb(phyaddr) \ 106 do { \ 107 if (phyaddr != MMB_ADDR_INVALID) { \ 108 cmpi_mmz_free(phyaddr, HI_NULL); \ 109 } \ 110 } while (0) 111 112 #define tde_get_phyaddr_mmb(bufname, size, phyaddr) \ 113 do { \ 114 phyaddr = cmpi_mmz_malloc(HI_NULL, bufname, size); \ 115 if (phyaddr == 0) { \ 116 tde_error("new_mmb failed!"); \ 117 phyaddr = 0; \ 118 } \ 119 } while (0) 120 121 #define tde_unmap_mmb(virtaddr) cmpi_unmap((hi_void *)virtaddr) 122 123 #define tde_flush_cached_mmb(virtaddr, phyaddr, len) \ 124 do { \ 125 osal_flush_dcache_area(virtaddr, phyaddr, len); \ 126 } while (0) 127 128 #define tde_unequal_eok_return(ret) \ 129 do { \ 130 if ((ret) != EOK) { \ 131 tde_error("secure function failure\n"); \ 132 return HI_ERR_TDE_INVALID_PARA; \ 133 } \ 134 } while (0) 135 136 #define tde_reg_map(base, size) osal_ioremap_nocache((base), (size)) 137 138 #define tde_reg_unmap(base) osal_iounmap((hi_void *)(base), 0) 139 140 #define tde_init_waitqueue_head(pqueue) osal_wait_init(pqueue) 141 142 #define tde_wait_event_interruptible_timeout(queue, condition, timeout) osal_wait_timeout(queue, condition, timeout) 143 144 #define tde_wakeup_interruptible(pqueue) osal_wakeup(pqueue) 145 146 typedef struct timeval tde_timeval; 147 148 #ifdef __cplusplus 149 #if __cplusplus 150 } 151 #endif 152 #endif /* __cplusplus */ 153 #endif /* __TDE_DEFINE_H__ */ 154