1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Decription: function declaration for sending smc cmd. 4 * 5 * This software is licensed under the terms of the GNU General Public 6 * License version 2, as published by the Free Software Foundation, and 7 * may be copied, distributed, and modified under those terms. 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 #ifndef SMC_SMP_H 15 #define SMC_SMP_H 16 17 #include <linux/of_device.h> 18 #include "teek_client_constants.h" 19 #include "teek_ns_client.h" 20 21 #if (KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE) 22 #define CURRENT_CPUS_ALLOWED (¤t->cpus_mask) 23 #else 24 #define CURRENT_CPUS_ALLOWED (¤t->cpus_allowed) 25 #endif 26 27 enum tc_ns_cmd_type { 28 TC_NS_CMD_TYPE_INVALID = 0, 29 TC_NS_CMD_TYPE_NS_TO_SECURE, 30 TC_NS_CMD_TYPE_SECURE_TO_NS, 31 TC_NS_CMD_TYPE_SECURE_TO_SECURE, 32 TC_NS_CMD_TYPE_SECURE_CONFIG = 0xf, 33 TC_NS_CMD_TYPE_MAX 34 }; 35 36 struct pending_entry { 37 atomic_t users; 38 struct task_struct *task; 39 #ifdef CONFIG_TA_AFFINITY 40 struct cpumask ca_mask; 41 struct cpumask ta_mask; 42 #endif 43 pid_t pid; 44 wait_queue_head_t wq; 45 atomic_t run; 46 struct list_head list; 47 }; 48 49 #ifdef CONFIG_BIG_SESSION 50 #define MAX_SMC_CMD CONFIG_BIG_SESSION 51 #else 52 #define MAX_SMC_CMD 18 53 #endif 54 55 #ifdef DIV_ROUND_UP 56 #undef DIV_ROUND_UP 57 #endif 58 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 59 60 #define BITS_PER_BYTE 8 61 62 #ifdef BITS_TO_LONGS 63 #undef BITS_TO_LONGS 64 #endif 65 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(uint64_t)) 66 67 #ifdef BIT_MASK 68 #undef BIT_MASK 69 #endif 70 #define BIT_MASK(nr) (1UL << (((uint64_t)(nr)) % sizeof(uint64_t))) 71 72 #ifdef BIT_WORD 73 #undef BIT_WORD 74 #endif 75 #define BIT_WORD(nr) ((nr) / sizeof(uint64_t)) 76 77 #ifdef DECLARE_BITMAP 78 #undef DECLARE_BITMAP 79 #endif 80 #define DECLARE_BITMAP(name, bits) uint64_t name[BITS_TO_LONGS(bits)] 81 82 #define SIQ_DUMP_TIMEOUT 1U 83 #define SIQ_DUMP_SHELL 2U 84 85 typedef uint32_t smc_buf_lock_t; 86 87 struct tc_ns_smc_queue { 88 /* set when CA send cmd_in, clear after cmd_out return */ 89 DECLARE_BITMAP(in_bitmap, MAX_SMC_CMD); 90 /* set when gtask get cmd_in, clear after cmd_out return */ 91 DECLARE_BITMAP(doing_bitmap, MAX_SMC_CMD); 92 /* set when gtask get cmd_out, clear after cmd_out return */ 93 DECLARE_BITMAP(out_bitmap, MAX_SMC_CMD); 94 smc_buf_lock_t smc_lock; 95 volatile uint32_t last_in; 96 struct tc_ns_smc_cmd in[MAX_SMC_CMD]; 97 volatile uint32_t last_out; 98 struct tc_ns_smc_cmd out[MAX_SMC_CMD]; 99 }; 100 101 #define SYM_NAME_LEN_MAX 16 102 #define SYM_NAME_LEN_1 7 103 #define SYM_NAME_LEN_2 4 104 #define CRASH_REG_NUM 3 105 #define LOW_FOUR_BITE 4 106 107 union crash_inf { 108 uint64_t crash_reg[CRASH_REG_NUM]; 109 struct { 110 uint8_t halt_reason : LOW_FOUR_BITE; 111 uint8_t app : LOW_FOUR_BITE; 112 char sym_name[SYM_NAME_LEN_1]; 113 uint16_t off; 114 uint16_t size; 115 uint32_t far; 116 uint32_t fault; 117 union { 118 char sym_name_append[SYM_NAME_LEN_2]; 119 uint32_t elr; 120 }; 121 } crash_msg; 122 }; 123 124 #define RESLEEP_TIMEOUT 15 125 126 bool sigkill_pending(struct task_struct *tsk); 127 int smc_context_init(const struct device *class_dev); 128 void free_smc_data(void); 129 int tc_ns_smc(struct tc_ns_smc_cmd *cmd); 130 int tc_ns_smc_with_no_nr(struct tc_ns_smc_cmd *cmd); 131 int teeos_log_exception_archive(unsigned int eventid, const char *exceptioninfo); 132 void set_cmd_send_state(void); 133 int init_smc_svc_thread(void); 134 int smc_wakeup_ca(pid_t ca); 135 int smc_wakeup_broadcast(void); 136 int smc_shadow_exit(pid_t ca); 137 int smc_queue_shadow_worker(uint64_t target); 138 void fiq_shadow_work_func(uint64_t target); 139 struct pending_entry *find_pending_entry(pid_t pid); 140 void foreach_pending_entry(void (*func)(struct pending_entry *)); 141 void put_pending_entry(struct pending_entry *pe); 142 void show_cmd_bitmap(void); 143 void wakeup_tc_siq(uint32_t siq_mode); 144 void smc_set_cmd_buffer(void); 145 unsigned long raw_smc_send(uint32_t cmd, phys_addr_t cmd_addr, uint32_t cmd_type, uint8_t wait); 146 void occupy_clean_cmd_buf(void); 147 void clr_system_crash_flag(void); 148 void svc_thread_release(void); 149 int send_smc_cmd_rebooting(uint32_t cmd_id, phys_addr_t cmd_addr, uint32_t cmd_type, 150 const struct tc_ns_smc_cmd *in_cmd); 151 void send_smc_reset_cmd_buffer(void); 152 153 #endif 154