Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 1 | /*Qualcomm Secure Execution Environment Communicator (QSEECOM) driver |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2 | * |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 3 | * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 and |
| 7 | * only version 2 as published by the Free Software Foundation. |
| 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 | |
| 15 | #define pr_fmt(fmt) "QSEECOM: %s: " fmt, __func__ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/fs.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/debugfs.h> |
| 23 | #include <linux/cdev.h> |
| 24 | #include <linux/uaccess.h> |
| 25 | #include <linux/sched.h> |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/mutex.h> |
| 28 | #include <linux/io.h> |
Mitchel Humpherys | 4f8be2e | 2012-09-06 10:41:41 -0700 | [diff] [blame] | 29 | #include <linux/msm_ion.h> |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 30 | #include <linux/types.h> |
| 31 | #include <linux/clk.h> |
| 32 | #include <linux/qseecom.h> |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 33 | #include <linux/elf.h> |
| 34 | #include <linux/firmware.h> |
Mona Hossain | acea102 | 2012-04-09 13:37:27 -0700 | [diff] [blame] | 35 | #include <linux/freezer.h> |
Mona Hossain | f1f2ed6 | 2012-11-15 19:51:33 -0800 | [diff] [blame] | 36 | #include <linux/scatterlist.h> |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 37 | #include <mach/board.h> |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 38 | #include <mach/msm_bus.h> |
| 39 | #include <mach/msm_bus_board.h> |
| 40 | #include <mach/scm.h> |
Stephen Boyd | 77db8bb | 2012-06-27 15:15:16 -0700 | [diff] [blame] | 41 | #include <mach/subsystem_restart.h> |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 42 | #include <mach/socinfo.h> |
Mona Hossain | 803c3d9 | 2012-11-21 13:33:42 -0800 | [diff] [blame] | 43 | #include <mach/qseecomi.h> |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 44 | #include <asm/cacheflush.h> |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 45 | #include "qseecom_legacy.h" |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 46 | #include "qseecom_kernel.h" |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 47 | |
| 48 | #define QSEECOM_DEV "qseecom" |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 49 | #define QSEOS_VERSION_14 0x14 |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 50 | #define QSEEE_VERSION_00 0x400000 |
Mona Hossain | 5b76a62 | 2012-11-15 20:09:08 -0800 | [diff] [blame] | 51 | #define QSEE_VERSION_01 0x401000 |
| 52 | #define QSEE_VERSION_02 0x402000 |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 53 | #define QSEE_VERSION_03 0x403000 |
Amir Samuelov | d1fc741 | 2013-03-10 16:56:13 +0200 | [diff] [blame] | 54 | #define QSEE_VERSION_04 0x404000 |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 55 | #define QSEE_VERSION_05 0x405000 |
| 56 | |
Mona Hossain | 5b76a62 | 2012-11-15 20:09:08 -0800 | [diff] [blame] | 57 | |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 58 | |
| 59 | #define QSEOS_CHECK_VERSION_CMD 0x00001803 |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 60 | |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 61 | #define QSEE_CE_CLK_100MHZ 100000000 |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 62 | |
Mona Hossain | 13dd892 | 2013-01-03 06:11:09 -0800 | [diff] [blame] | 63 | #define QSEECOM_MAX_SG_ENTRY 512 |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 64 | #define QSEECOM_INVALID_KEY_ID 0xff |
Mona Hossain | f1f2ed6 | 2012-11-15 19:51:33 -0800 | [diff] [blame] | 65 | |
Amir Samuelov | d1fc741 | 2013-03-10 16:56:13 +0200 | [diff] [blame] | 66 | /* Save partition image hash for authentication check */ |
| 67 | #define SCM_SAVE_PARTITION_HASH_ID 0x01 |
| 68 | |
| 69 | /* Check if enterprise security is activate */ |
| 70 | #define SCM_IS_ACTIVATED_ID 0x02 |
| 71 | |
Zhen Kong | 7812dc1 | 2013-07-09 17:12:55 -0700 | [diff] [blame] | 72 | #define RPMB_SERVICE 0x2000 |
| 73 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 74 | #define QSEECOM_SEND_CMD_CRYPTO_TIMEOUT 2000 |
| 75 | #define QSEECOM_LOAD_APP_CRYPTO_TIMEOUT 2000 |
| 76 | |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 77 | enum qseecom_clk_definitions { |
| 78 | CLK_DFAB = 0, |
| 79 | CLK_SFPB, |
| 80 | }; |
| 81 | |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 82 | enum qseecom_client_handle_type { |
AnilKumar Chimata | f732bbe | 2013-07-24 00:44:09 +0530 | [diff] [blame] | 83 | QSEECOM_CLIENT_APP = 1, |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 84 | QSEECOM_LISTENER_SERVICE, |
| 85 | QSEECOM_SECURE_SERVICE, |
| 86 | QSEECOM_GENERIC, |
AnilKumar Chimata | f732bbe | 2013-07-24 00:44:09 +0530 | [diff] [blame] | 87 | QSEECOM_UNAVAILABLE_CLIENT_APP, |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 90 | enum qseecom_ce_hw_instance { |
| 91 | CLK_QSEE = 0, |
| 92 | CLK_CE_DRV, |
| 93 | }; |
| 94 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 95 | static struct class *driver_class; |
| 96 | static dev_t qseecom_device_no; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 97 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 98 | static DEFINE_MUTEX(qsee_bw_mutex); |
| 99 | static DEFINE_MUTEX(app_access_lock); |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 100 | static DEFINE_MUTEX(clk_access_lock); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 101 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 102 | struct qseecom_registered_listener_list { |
| 103 | struct list_head list; |
| 104 | struct qseecom_register_listener_req svc; |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 105 | uint32_t user_virt_sb_base; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 106 | u8 *sb_virt; |
| 107 | s32 sb_phys; |
| 108 | size_t sb_length; |
| 109 | struct ion_handle *ihandle; /* Retrieve phy addr */ |
| 110 | |
| 111 | wait_queue_head_t rcv_req_wq; |
| 112 | int rcv_req_flag; |
| 113 | }; |
| 114 | |
| 115 | struct qseecom_registered_app_list { |
| 116 | struct list_head list; |
| 117 | u32 app_id; |
| 118 | u32 ref_cnt; |
| 119 | }; |
| 120 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 121 | struct qseecom_registered_kclient_list { |
| 122 | struct list_head list; |
| 123 | struct qseecom_handle *handle; |
| 124 | }; |
| 125 | |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 126 | struct ce_hw_usage_info { |
| 127 | uint32_t qsee_ce_hw_instance; |
| 128 | uint32_t hlos_ce_hw_instance; |
| 129 | uint32_t disk_encrypt_pipe; |
Zhen Kong | 4ffeacf | 2014-02-27 17:21:08 -0800 | [diff] [blame] | 130 | uint32_t file_encrypt_pipe; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 131 | }; |
| 132 | |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 133 | struct qseecom_clk { |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 134 | enum qseecom_ce_hw_instance instance; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 135 | struct clk *ce_core_clk; |
| 136 | struct clk *ce_clk; |
| 137 | struct clk *ce_core_src_clk; |
| 138 | struct clk *ce_bus_clk; |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 139 | uint32_t clk_access_cnt; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 142 | struct qseecom_control { |
| 143 | struct ion_client *ion_clnt; /* Ion client */ |
| 144 | struct list_head registered_listener_list_head; |
| 145 | spinlock_t registered_listener_list_lock; |
| 146 | |
| 147 | struct list_head registered_app_list_head; |
| 148 | spinlock_t registered_app_list_lock; |
| 149 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 150 | struct list_head registered_kclient_list_head; |
| 151 | spinlock_t registered_kclient_list_lock; |
| 152 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 153 | wait_queue_head_t send_resp_wq; |
| 154 | int send_resp_flag; |
| 155 | |
| 156 | uint32_t qseos_version; |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 157 | uint32_t qsee_version; |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 158 | struct device *pdev; |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 159 | bool commonlib_loaded; |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 160 | struct ion_handle *cmnlib_ion_handle; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 161 | struct ce_hw_usage_info ce_info; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 162 | |
| 163 | int qsee_bw_count; |
| 164 | int qsee_sfpb_bw_count; |
| 165 | |
| 166 | uint32_t qsee_perf_client; |
| 167 | struct qseecom_clk qsee; |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 168 | struct qseecom_clk ce_drv; |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 169 | |
| 170 | bool support_bus_scaling; |
Zhen Kong | 4ffeacf | 2014-02-27 17:21:08 -0800 | [diff] [blame] | 171 | bool support_fde; |
| 172 | bool support_pfe; |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 173 | uint32_t cumulative_mode; |
| 174 | enum qseecom_bandwidth_request_mode current_mode; |
| 175 | struct timer_list bw_scale_down_timer; |
| 176 | struct work_struct bw_inactive_req_ws; |
Zhen Kong | ea5d4bb | 2014-02-18 14:59:53 -0800 | [diff] [blame] | 177 | struct cdev cdev; |
| 178 | bool timer_running; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | struct qseecom_client_handle { |
| 182 | u32 app_id; |
| 183 | u8 *sb_virt; |
| 184 | s32 sb_phys; |
| 185 | uint32_t user_virt_sb_base; |
| 186 | size_t sb_length; |
| 187 | struct ion_handle *ihandle; /* Retrieve phy addr */ |
| 188 | }; |
| 189 | |
| 190 | struct qseecom_listener_handle { |
| 191 | u32 id; |
| 192 | }; |
| 193 | |
| 194 | static struct qseecom_control qseecom; |
| 195 | |
| 196 | struct qseecom_dev_handle { |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 197 | enum qseecom_client_handle_type type; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 198 | union { |
| 199 | struct qseecom_client_handle client; |
| 200 | struct qseecom_listener_handle listener; |
| 201 | }; |
| 202 | bool released; |
| 203 | int abort; |
| 204 | wait_queue_head_t abort_wq; |
| 205 | atomic_t ioctl_count; |
Mona Hossain | c9c83c7 | 2013-04-11 12:43:48 -0700 | [diff] [blame] | 206 | bool perf_enabled; |
| 207 | bool fast_load_enabled; |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 208 | enum qseecom_bandwidth_request_mode mode; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 209 | }; |
| 210 | |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 211 | enum qseecom_set_clear_key_flag { |
| 212 | QSEECOM_CLEAR_CE_KEY_CMD = 0, |
| 213 | QSEECOM_SET_CE_KEY_CMD, |
| 214 | }; |
| 215 | |
| 216 | struct qseecom_set_key_parameter { |
| 217 | uint32_t ce_hw; |
| 218 | uint32_t pipe; |
| 219 | uint32_t flags; |
| 220 | uint8_t key_id[QSEECOM_KEY_ID_SIZE]; |
| 221 | unsigned char hash32[QSEECOM_HASH_SIZE]; |
| 222 | enum qseecom_set_clear_key_flag set_clear_key_flag; |
| 223 | }; |
| 224 | |
Mona Hossain | f1f2ed6 | 2012-11-15 19:51:33 -0800 | [diff] [blame] | 225 | struct qseecom_sg_entry { |
| 226 | uint32_t phys_addr; |
| 227 | uint32_t len; |
| 228 | }; |
| 229 | |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 230 | struct qseecom_key_id_usage_desc { |
| 231 | uint8_t desc[QSEECOM_KEY_ID_SIZE]; |
| 232 | }; |
| 233 | |
| 234 | static struct qseecom_key_id_usage_desc key_id_array[] = { |
| 235 | { |
| 236 | .desc = "Undefined Usage Index", |
| 237 | }, |
| 238 | |
| 239 | { |
| 240 | .desc = "Full Disk Encryption", |
| 241 | }, |
| 242 | |
| 243 | { |
| 244 | .desc = "Per File Encryption", |
| 245 | }, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 246 | }; |
| 247 | |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 248 | /* Function proto types */ |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 249 | static int qsee_vote_for_clock(struct qseecom_dev_handle *, int32_t); |
| 250 | static void qsee_disable_clock_vote(struct qseecom_dev_handle *, int32_t); |
Zhen Kong | 7812dc1 | 2013-07-09 17:12:55 -0700 | [diff] [blame] | 251 | static int __qseecom_enable_clk(enum qseecom_ce_hw_instance ce); |
| 252 | static void __qseecom_disable_clk(enum qseecom_ce_hw_instance ce); |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 253 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 254 | static int __qseecom_is_svc_unique(struct qseecom_dev_handle *data, |
Mona Hossain | 0af10ab | 2012-02-28 18:26:41 -0800 | [diff] [blame] | 255 | struct qseecom_register_listener_req *svc) |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 256 | { |
| 257 | struct qseecom_registered_listener_list *ptr; |
| 258 | int unique = 1; |
| 259 | unsigned long flags; |
| 260 | |
| 261 | spin_lock_irqsave(&qseecom.registered_listener_list_lock, flags); |
| 262 | list_for_each_entry(ptr, &qseecom.registered_listener_list_head, list) { |
Mona Hossain | 0af10ab | 2012-02-28 18:26:41 -0800 | [diff] [blame] | 263 | if (ptr->svc.listener_id == svc->listener_id) { |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 264 | pr_err("Service id: %u is already registered\n", |
| 265 | ptr->svc.listener_id); |
| 266 | unique = 0; |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | spin_unlock_irqrestore(&qseecom.registered_listener_list_lock, flags); |
| 271 | return unique; |
| 272 | } |
| 273 | |
| 274 | static struct qseecom_registered_listener_list *__qseecom_find_svc( |
| 275 | int32_t listener_id) |
| 276 | { |
| 277 | struct qseecom_registered_listener_list *entry = NULL; |
| 278 | unsigned long flags; |
| 279 | |
| 280 | spin_lock_irqsave(&qseecom.registered_listener_list_lock, flags); |
| 281 | list_for_each_entry(entry, &qseecom.registered_listener_list_head, list) |
| 282 | { |
| 283 | if (entry->svc.listener_id == listener_id) |
| 284 | break; |
| 285 | } |
| 286 | spin_unlock_irqrestore(&qseecom.registered_listener_list_lock, flags); |
AnilKumar Chimata | 69b857a | 2013-07-23 23:03:26 +0530 | [diff] [blame] | 287 | |
| 288 | if ((entry != NULL) && (entry->svc.listener_id != listener_id)) { |
| 289 | pr_err("Service id: %u is not found\n", listener_id); |
| 290 | return NULL; |
| 291 | } |
| 292 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 293 | return entry; |
| 294 | } |
| 295 | |
| 296 | static int __qseecom_set_sb_memory(struct qseecom_registered_listener_list *svc, |
| 297 | struct qseecom_dev_handle *handle, |
| 298 | struct qseecom_register_listener_req *listener) |
| 299 | { |
| 300 | int ret = 0; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 301 | struct qseecom_register_listener_ireq req; |
| 302 | struct qseecom_command_scm_resp resp; |
| 303 | ion_phys_addr_t pa; |
| 304 | |
| 305 | /* Get the handle of the shared fd */ |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 306 | svc->ihandle = ion_import_dma_buf(qseecom.ion_clnt, |
| 307 | listener->ifd_data_fd); |
Hariprasad Dhalinarasimha | 1401bc0 | 2014-02-18 13:46:37 -0800 | [diff] [blame] | 308 | if (IS_ERR_OR_NULL(svc->ihandle)) { |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 309 | pr_err("Ion client could not retrieve the handle\n"); |
| 310 | return -ENOMEM; |
| 311 | } |
| 312 | |
| 313 | /* Get the physical address of the ION BUF */ |
| 314 | ret = ion_phys(qseecom.ion_clnt, svc->ihandle, &pa, &svc->sb_length); |
Zhen Kong | 05ed446 | 2014-01-28 18:21:30 -0800 | [diff] [blame] | 315 | if (ret) { |
| 316 | pr_err("Cannot get phys_addr for the Ion Client, ret = %d\n", |
| 317 | ret); |
| 318 | return ret; |
| 319 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 320 | /* Populate the structure for sending scm call to load image */ |
Mitchel Humpherys | 911b4b7 | 2012-09-12 14:42:50 -0700 | [diff] [blame] | 321 | svc->sb_virt = (char *) ion_map_kernel(qseecom.ion_clnt, svc->ihandle); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 322 | svc->sb_phys = pa; |
| 323 | |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 324 | req.qsee_cmd_id = QSEOS_REGISTER_LISTENER; |
| 325 | req.listener_id = svc->svc.listener_id; |
| 326 | req.sb_len = svc->sb_length; |
| 327 | req.sb_ptr = (void *)svc->sb_phys; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 328 | |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 329 | resp.result = QSEOS_RESULT_INCOMPLETE; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 330 | |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 331 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &req, |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 332 | sizeof(req), &resp, sizeof(resp)); |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 333 | if (ret) { |
| 334 | pr_err("qseecom_scm_call failed with err: %d\n", ret); |
| 335 | return -EINVAL; |
| 336 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 337 | |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 338 | if (resp.result != QSEOS_RESULT_SUCCESS) { |
| 339 | pr_err("Error SB registration req: resp.result = %d\n", |
| 340 | resp.result); |
| 341 | return -EPERM; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 342 | } |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static int qseecom_register_listener(struct qseecom_dev_handle *data, |
| 347 | void __user *argp) |
| 348 | { |
| 349 | int ret = 0; |
| 350 | unsigned long flags; |
| 351 | struct qseecom_register_listener_req rcvd_lstnr; |
| 352 | struct qseecom_registered_listener_list *new_entry; |
| 353 | |
| 354 | ret = copy_from_user(&rcvd_lstnr, argp, sizeof(rcvd_lstnr)); |
| 355 | if (ret) { |
| 356 | pr_err("copy_from_user failed\n"); |
| 357 | return ret; |
| 358 | } |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 359 | if (!access_ok(VERIFY_WRITE, (void __user *)rcvd_lstnr.virt_sb_base, |
| 360 | rcvd_lstnr.sb_size)) |
| 361 | return -EFAULT; |
| 362 | |
Mona Hossain | 0af10ab | 2012-02-28 18:26:41 -0800 | [diff] [blame] | 363 | data->listener.id = 0; |
Mona Hossain | 0af10ab | 2012-02-28 18:26:41 -0800 | [diff] [blame] | 364 | if (!__qseecom_is_svc_unique(data, &rcvd_lstnr)) { |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 365 | pr_err("Service is not unique and is already registered\n"); |
Mona Hossain | 0af10ab | 2012-02-28 18:26:41 -0800 | [diff] [blame] | 366 | data->released = true; |
| 367 | return -EBUSY; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | new_entry = kmalloc(sizeof(*new_entry), GFP_KERNEL); |
| 371 | if (!new_entry) { |
| 372 | pr_err("kmalloc failed\n"); |
| 373 | return -ENOMEM; |
| 374 | } |
| 375 | memcpy(&new_entry->svc, &rcvd_lstnr, sizeof(rcvd_lstnr)); |
| 376 | new_entry->rcv_req_flag = 0; |
| 377 | |
| 378 | new_entry->svc.listener_id = rcvd_lstnr.listener_id; |
| 379 | new_entry->sb_length = rcvd_lstnr.sb_size; |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 380 | new_entry->user_virt_sb_base = rcvd_lstnr.virt_sb_base; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 381 | if (__qseecom_set_sb_memory(new_entry, data, &rcvd_lstnr)) { |
| 382 | pr_err("qseecom_set_sb_memoryfailed\n"); |
| 383 | kzfree(new_entry); |
| 384 | return -ENOMEM; |
| 385 | } |
Mona Hossain | 0af10ab | 2012-02-28 18:26:41 -0800 | [diff] [blame] | 386 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 387 | data->listener.id = rcvd_lstnr.listener_id; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 388 | init_waitqueue_head(&new_entry->rcv_req_wq); |
| 389 | |
| 390 | spin_lock_irqsave(&qseecom.registered_listener_list_lock, flags); |
| 391 | list_add_tail(&new_entry->list, &qseecom.registered_listener_list_head); |
| 392 | spin_unlock_irqrestore(&qseecom.registered_listener_list_lock, flags); |
Mona Hossain | 0af10ab | 2012-02-28 18:26:41 -0800 | [diff] [blame] | 393 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 394 | return ret; |
| 395 | } |
| 396 | |
| 397 | static int qseecom_unregister_listener(struct qseecom_dev_handle *data) |
| 398 | { |
| 399 | int ret = 0; |
| 400 | unsigned long flags; |
| 401 | uint32_t unmap_mem = 0; |
| 402 | struct qseecom_register_listener_ireq req; |
| 403 | struct qseecom_registered_listener_list *ptr_svc = NULL; |
| 404 | struct qseecom_command_scm_resp resp; |
| 405 | struct ion_handle *ihandle = NULL; /* Retrieve phy addr */ |
| 406 | |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 407 | req.qsee_cmd_id = QSEOS_DEREGISTER_LISTENER; |
| 408 | req.listener_id = data->listener.id; |
| 409 | resp.result = QSEOS_RESULT_INCOMPLETE; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 410 | |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 411 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &req, |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 412 | sizeof(req), &resp, sizeof(resp)); |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 413 | if (ret) { |
| 414 | pr_err("scm_call() failed with err: %d (lstnr id=%d)\n", |
| 415 | ret, data->listener.id); |
| 416 | return ret; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 417 | } |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 418 | |
| 419 | if (resp.result != QSEOS_RESULT_SUCCESS) { |
| 420 | pr_err("Failed resp.result=%d,(lstnr id=%d)\n", |
| 421 | resp.result, data->listener.id); |
| 422 | return -EPERM; |
| 423 | } |
| 424 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 425 | data->abort = 1; |
| 426 | spin_lock_irqsave(&qseecom.registered_listener_list_lock, flags); |
| 427 | list_for_each_entry(ptr_svc, &qseecom.registered_listener_list_head, |
| 428 | list) { |
| 429 | if (ptr_svc->svc.listener_id == data->listener.id) { |
| 430 | wake_up_all(&ptr_svc->rcv_req_wq); |
| 431 | break; |
| 432 | } |
| 433 | } |
| 434 | spin_unlock_irqrestore(&qseecom.registered_listener_list_lock, flags); |
| 435 | |
| 436 | while (atomic_read(&data->ioctl_count) > 1) { |
Mona Hossain | acea102 | 2012-04-09 13:37:27 -0700 | [diff] [blame] | 437 | if (wait_event_freezable(data->abort_wq, |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 438 | atomic_read(&data->ioctl_count) <= 1)) { |
| 439 | pr_err("Interrupted from abort\n"); |
| 440 | ret = -ERESTARTSYS; |
| 441 | break; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | spin_lock_irqsave(&qseecom.registered_listener_list_lock, flags); |
| 446 | list_for_each_entry(ptr_svc, |
| 447 | &qseecom.registered_listener_list_head, |
| 448 | list) |
| 449 | { |
| 450 | if (ptr_svc->svc.listener_id == data->listener.id) { |
| 451 | if (ptr_svc->sb_virt) { |
| 452 | unmap_mem = 1; |
| 453 | ihandle = ptr_svc->ihandle; |
| 454 | } |
| 455 | list_del(&ptr_svc->list); |
| 456 | kzfree(ptr_svc); |
| 457 | break; |
| 458 | } |
| 459 | } |
| 460 | spin_unlock_irqrestore(&qseecom.registered_listener_list_lock, flags); |
| 461 | |
| 462 | /* Unmap the memory */ |
| 463 | if (unmap_mem) { |
| 464 | if (!IS_ERR_OR_NULL(ihandle)) { |
| 465 | ion_unmap_kernel(qseecom.ion_clnt, ihandle); |
| 466 | ion_free(qseecom.ion_clnt, ihandle); |
| 467 | } |
| 468 | } |
| 469 | data->released = true; |
| 470 | return ret; |
| 471 | } |
| 472 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 473 | static int __qseecom_set_msm_bus_request(uint32_t mode) |
| 474 | { |
| 475 | int ret = 0; |
| 476 | struct qseecom_clk *qclk; |
| 477 | |
| 478 | qclk = &qseecom.qsee; |
| 479 | if (qclk->ce_core_src_clk != NULL) { |
| 480 | if (mode == INACTIVE) { |
| 481 | __qseecom_disable_clk(CLK_QSEE); |
| 482 | } else { |
| 483 | ret = __qseecom_enable_clk(CLK_QSEE); |
| 484 | if (ret) |
| 485 | pr_err("CLK enabling failed (%d) MODE (%d)\n", |
| 486 | ret, mode); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | if ((!ret) && (qseecom.current_mode != mode)) { |
| 491 | ret = msm_bus_scale_client_update_request( |
| 492 | qseecom.qsee_perf_client, mode); |
| 493 | if (ret) { |
| 494 | pr_err("Bandwidth req failed(%d) MODE (%d)\n", |
| 495 | ret, mode); |
| 496 | if (qclk->ce_core_src_clk != NULL) { |
| 497 | if (mode == INACTIVE) |
| 498 | __qseecom_enable_clk(CLK_QSEE); |
| 499 | else |
| 500 | __qseecom_disable_clk(CLK_QSEE); |
| 501 | } |
| 502 | } |
| 503 | qseecom.current_mode = mode; |
| 504 | } |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | static void qseecom_bw_inactive_req_work(struct work_struct *work) |
| 509 | { |
| 510 | mutex_lock(&app_access_lock); |
| 511 | mutex_lock(&qsee_bw_mutex); |
| 512 | __qseecom_set_msm_bus_request(INACTIVE); |
| 513 | pr_debug("current_mode = %d, cumulative_mode = %d\n", |
| 514 | qseecom.current_mode, qseecom.cumulative_mode); |
Zhen Kong | ea5d4bb | 2014-02-18 14:59:53 -0800 | [diff] [blame] | 515 | qseecom.timer_running = false; |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 516 | mutex_unlock(&qsee_bw_mutex); |
| 517 | mutex_unlock(&app_access_lock); |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | static void qseecom_scale_bus_bandwidth_timer_callback(unsigned long data) |
| 522 | { |
| 523 | schedule_work(&qseecom.bw_inactive_req_ws); |
| 524 | return; |
| 525 | } |
| 526 | |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 527 | static int __qseecom_decrease_clk_ref_count(enum qseecom_ce_hw_instance ce) |
Zhen Kong | ea5d4bb | 2014-02-18 14:59:53 -0800 | [diff] [blame] | 528 | { |
| 529 | struct qseecom_clk *qclk; |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 530 | int ret = 0; |
Zhen Kong | ea5d4bb | 2014-02-18 14:59:53 -0800 | [diff] [blame] | 531 | mutex_lock(&clk_access_lock); |
| 532 | if (ce == CLK_QSEE) |
| 533 | qclk = &qseecom.qsee; |
| 534 | else |
| 535 | qclk = &qseecom.ce_drv; |
| 536 | |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 537 | if (qclk->clk_access_cnt > 2) { |
| 538 | pr_err("Invalid clock ref count %d\n", qclk->clk_access_cnt); |
| 539 | ret = -EINVAL; |
| 540 | goto err_dec_ref_cnt; |
Zhen Kong | ea5d4bb | 2014-02-18 14:59:53 -0800 | [diff] [blame] | 541 | } |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 542 | if (qclk->clk_access_cnt == 2) |
| 543 | qclk->clk_access_cnt--; |
| 544 | |
| 545 | err_dec_ref_cnt: |
Zhen Kong | ea5d4bb | 2014-02-18 14:59:53 -0800 | [diff] [blame] | 546 | mutex_unlock(&clk_access_lock); |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 547 | return ret; |
Zhen Kong | ea5d4bb | 2014-02-18 14:59:53 -0800 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | |
Zhen Kong | af95019 | 2014-02-05 17:36:23 -0800 | [diff] [blame] | 551 | static int qseecom_scale_bus_bandwidth_timer(uint32_t mode) |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 552 | { |
| 553 | int32_t ret = 0; |
| 554 | int32_t request_mode = INACTIVE; |
| 555 | |
| 556 | mutex_lock(&qsee_bw_mutex); |
| 557 | if (mode == 0) { |
| 558 | if (qseecom.cumulative_mode > MEDIUM) |
| 559 | request_mode = HIGH; |
| 560 | else |
| 561 | request_mode = qseecom.cumulative_mode; |
| 562 | } else { |
| 563 | request_mode = mode; |
| 564 | } |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 565 | |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 566 | ret = __qseecom_set_msm_bus_request(request_mode); |
| 567 | if (ret) { |
| 568 | pr_err("set msm bus request failed (%d),request_mode (%d)\n", |
| 569 | ret, request_mode); |
| 570 | goto err_scale_timer; |
Zhen Kong | ea5d4bb | 2014-02-18 14:59:53 -0800 | [diff] [blame] | 571 | } |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 572 | |
| 573 | if (qseecom.timer_running) { |
| 574 | ret = __qseecom_decrease_clk_ref_count(CLK_QSEE); |
| 575 | if (ret) { |
| 576 | pr_err("Failed to decrease clk ref count.\n"); |
| 577 | goto err_scale_timer; |
| 578 | } |
| 579 | del_timer_sync(&(qseecom.bw_scale_down_timer)); |
| 580 | qseecom.timer_running = false; |
| 581 | } |
| 582 | err_scale_timer: |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 583 | mutex_unlock(&qsee_bw_mutex); |
| 584 | return ret; |
| 585 | } |
| 586 | |
| 587 | |
| 588 | static int qseecom_unregister_bus_bandwidth_needs( |
| 589 | struct qseecom_dev_handle *data) |
| 590 | { |
| 591 | int32_t ret = 0; |
| 592 | |
| 593 | qseecom.cumulative_mode -= data->mode; |
| 594 | data->mode = INACTIVE; |
| 595 | |
| 596 | return ret; |
| 597 | } |
| 598 | |
| 599 | static int __qseecom_register_bus_bandwidth_needs( |
| 600 | struct qseecom_dev_handle *data, uint32_t request_mode) |
| 601 | { |
| 602 | int32_t ret = 0; |
| 603 | |
| 604 | if (data->mode == INACTIVE) { |
| 605 | qseecom.cumulative_mode += request_mode; |
| 606 | data->mode = request_mode; |
| 607 | } else { |
| 608 | if (data->mode != request_mode) { |
| 609 | qseecom.cumulative_mode -= data->mode; |
| 610 | qseecom.cumulative_mode += request_mode; |
| 611 | data->mode = request_mode; |
| 612 | } |
| 613 | } |
| 614 | return ret; |
| 615 | } |
| 616 | |
| 617 | static int qseecom_scale_bus_bandwidth(struct qseecom_dev_handle *data, |
| 618 | void __user *argp) |
| 619 | { |
| 620 | int32_t ret = 0; |
| 621 | int32_t req_mode; |
| 622 | |
| 623 | ret = copy_from_user(&req_mode, argp, sizeof(req_mode)); |
| 624 | if (ret) { |
| 625 | pr_err("copy_from_user failed\n"); |
| 626 | return ret; |
| 627 | } |
| 628 | if (req_mode > HIGH) { |
| 629 | pr_err("Invalid bandwidth mode (%d)\n", req_mode); |
| 630 | return ret; |
| 631 | } |
| 632 | mutex_lock(&qsee_bw_mutex); |
| 633 | ret = __qseecom_register_bus_bandwidth_needs(data, req_mode); |
| 634 | mutex_unlock(&qsee_bw_mutex); |
| 635 | |
| 636 | return ret; |
| 637 | } |
| 638 | |
Zhen Kong | af95019 | 2014-02-05 17:36:23 -0800 | [diff] [blame] | 639 | static void __qseecom_add_bw_scale_down_timer(uint32_t duration) |
| 640 | { |
| 641 | mutex_lock(&qsee_bw_mutex); |
| 642 | qseecom.bw_scale_down_timer.expires = jiffies + |
| 643 | msecs_to_jiffies(duration); |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 644 | mod_timer(&(qseecom.bw_scale_down_timer), |
| 645 | qseecom.bw_scale_down_timer.expires); |
Zhen Kong | af95019 | 2014-02-05 17:36:23 -0800 | [diff] [blame] | 646 | qseecom.timer_running = true; |
| 647 | mutex_unlock(&qsee_bw_mutex); |
| 648 | } |
| 649 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 650 | static void __qseecom_disable_clk_scale_down(struct qseecom_dev_handle *data) |
| 651 | { |
| 652 | if (!qseecom.support_bus_scaling) |
| 653 | qsee_disable_clock_vote(data, CLK_SFPB); |
Zhen Kong | af95019 | 2014-02-05 17:36:23 -0800 | [diff] [blame] | 654 | else |
| 655 | __qseecom_add_bw_scale_down_timer( |
| 656 | QSEECOM_LOAD_APP_CRYPTO_TIMEOUT); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 657 | return; |
| 658 | } |
| 659 | |
| 660 | static int __qseecom_enable_clk_scale_up(struct qseecom_dev_handle *data) |
| 661 | { |
| 662 | int ret = 0; |
| 663 | if (qseecom.support_bus_scaling) { |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 664 | ret = qseecom_scale_bus_bandwidth_timer(MEDIUM); |
| 665 | if (ret) |
| 666 | pr_err("Failed to set bw MEDIUM.\n"); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 667 | } else { |
| 668 | ret = qsee_vote_for_clock(data, CLK_SFPB); |
| 669 | if (ret) |
| 670 | pr_err("Fail vote for clk SFPB ret %d\n", ret); |
| 671 | } |
| 672 | return ret; |
| 673 | } |
| 674 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 675 | static int qseecom_set_client_mem_param(struct qseecom_dev_handle *data, |
| 676 | void __user *argp) |
| 677 | { |
| 678 | ion_phys_addr_t pa; |
| 679 | int32_t ret; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 680 | struct qseecom_set_sb_mem_param_req req; |
| 681 | uint32_t len; |
| 682 | |
| 683 | /* Copy the relevant information needed for loading the image */ |
Hariprasad Dhalinarasimha | e201495 | 2013-10-01 18:25:21 -0700 | [diff] [blame] | 684 | if (copy_from_user(&req, (void __user *)argp, sizeof(req))) |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 685 | return -EFAULT; |
| 686 | |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 687 | if ((req.ifd_data_fd <= 0) || (req.virt_sb_base == 0) || |
| 688 | (req.sb_len == 0)) { |
| 689 | pr_err("Inavlid input(s)ion_fd(%d), sb_len(%d), vaddr(0x%x)\n", |
| 690 | req.ifd_data_fd, req.sb_len, req.virt_sb_base); |
| 691 | return -EFAULT; |
| 692 | } |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 693 | if (!access_ok(VERIFY_WRITE, (void __user *)req.virt_sb_base, |
| 694 | req.sb_len)) |
| 695 | return -EFAULT; |
| 696 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 697 | /* Get the handle of the shared fd */ |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 698 | data->client.ihandle = ion_import_dma_buf(qseecom.ion_clnt, |
| 699 | req.ifd_data_fd); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 700 | if (IS_ERR_OR_NULL(data->client.ihandle)) { |
| 701 | pr_err("Ion client could not retrieve the handle\n"); |
| 702 | return -ENOMEM; |
| 703 | } |
| 704 | /* Get the physical address of the ION BUF */ |
| 705 | ret = ion_phys(qseecom.ion_clnt, data->client.ihandle, &pa, &len); |
Zhen Kong | 05ed446 | 2014-01-28 18:21:30 -0800 | [diff] [blame] | 706 | if (ret) { |
| 707 | |
| 708 | pr_err("Cannot get phys_addr for the Ion Client, ret = %d\n", |
| 709 | ret); |
| 710 | return ret; |
| 711 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 712 | /* Populate the structure for sending scm call to load image */ |
| 713 | data->client.sb_virt = (char *) ion_map_kernel(qseecom.ion_clnt, |
Mitchel Humpherys | 911b4b7 | 2012-09-12 14:42:50 -0700 | [diff] [blame] | 714 | data->client.ihandle); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 715 | data->client.sb_phys = pa; |
| 716 | data->client.sb_length = req.sb_len; |
| 717 | data->client.user_virt_sb_base = req.virt_sb_base; |
| 718 | return 0; |
| 719 | } |
| 720 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 721 | static int __qseecom_listener_has_sent_rsp(struct qseecom_dev_handle *data) |
| 722 | { |
| 723 | int ret; |
| 724 | ret = (qseecom.send_resp_flag != 0); |
| 725 | return ret || data->abort; |
| 726 | } |
| 727 | |
| 728 | static int __qseecom_process_incomplete_cmd(struct qseecom_dev_handle *data, |
| 729 | struct qseecom_command_scm_resp *resp) |
| 730 | { |
| 731 | int ret = 0; |
Mona Hossain | 0b3a279 | 2013-02-05 17:38:55 -0800 | [diff] [blame] | 732 | int rc = 0; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 733 | uint32_t lstnr; |
| 734 | unsigned long flags; |
| 735 | struct qseecom_client_listener_data_irsp send_data_rsp; |
| 736 | struct qseecom_registered_listener_list *ptr_svc = NULL; |
Mona Hossain | 91da2c5 | 2013-03-29 17:28:31 -0700 | [diff] [blame] | 737 | sigset_t new_sigset; |
| 738 | sigset_t old_sigset; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 739 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 740 | while (resp->result == QSEOS_RESULT_INCOMPLETE) { |
| 741 | lstnr = resp->data; |
| 742 | /* |
| 743 | * Wake up blocking lsitener service with the lstnr id |
| 744 | */ |
| 745 | spin_lock_irqsave(&qseecom.registered_listener_list_lock, |
| 746 | flags); |
| 747 | list_for_each_entry(ptr_svc, |
| 748 | &qseecom.registered_listener_list_head, list) { |
| 749 | if (ptr_svc->svc.listener_id == lstnr) { |
| 750 | ptr_svc->rcv_req_flag = 1; |
| 751 | wake_up_interruptible(&ptr_svc->rcv_req_wq); |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | spin_unlock_irqrestore(&qseecom.registered_listener_list_lock, |
| 756 | flags); |
Zhen Kong | c4d4951 | 2013-10-03 13:47:23 -0700 | [diff] [blame] | 757 | |
| 758 | if (ptr_svc == NULL) { |
| 759 | pr_err("Listener Svc %d does not exist\n", lstnr); |
| 760 | return -EINVAL; |
| 761 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 762 | if (ptr_svc->svc.listener_id != lstnr) { |
| 763 | pr_warning("Service requested for does on exist\n"); |
| 764 | return -ERESTARTSYS; |
| 765 | } |
| 766 | pr_debug("waking up rcv_req_wq and " |
| 767 | "waiting for send_resp_wq\n"); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 768 | |
Mona Hossain | 91da2c5 | 2013-03-29 17:28:31 -0700 | [diff] [blame] | 769 | /* initialize the new signal mask with all signals*/ |
| 770 | sigfillset(&new_sigset); |
| 771 | /* block all signals */ |
| 772 | sigprocmask(SIG_SETMASK, &new_sigset, &old_sigset); |
| 773 | |
| 774 | do { |
| 775 | if (!wait_event_freezable(qseecom.send_resp_wq, |
| 776 | __qseecom_listener_has_sent_rsp(data))) |
| 777 | break; |
| 778 | } while (1); |
| 779 | |
| 780 | /* restore signal mask */ |
| 781 | sigprocmask(SIG_SETMASK, &old_sigset, NULL); |
| 782 | if (data->abort) { |
Mona Hossain | eaa69b7 | 2013-04-15 17:20:15 -0700 | [diff] [blame] | 783 | pr_err("Abort clnt %d waiting on lstnr svc %d, ret %d", |
| 784 | data->client.app_id, lstnr, ret); |
Mona Hossain | 91da2c5 | 2013-03-29 17:28:31 -0700 | [diff] [blame] | 785 | rc = -ENODEV; |
Mona Hossain | 0b3a279 | 2013-02-05 17:38:55 -0800 | [diff] [blame] | 786 | send_data_rsp.status = QSEOS_RESULT_FAILURE; |
| 787 | } else { |
| 788 | send_data_rsp.status = QSEOS_RESULT_SUCCESS; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 789 | } |
Mona Hossain | 0b3a279 | 2013-02-05 17:38:55 -0800 | [diff] [blame] | 790 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 791 | qseecom.send_resp_flag = 0; |
| 792 | send_data_rsp.qsee_cmd_id = QSEOS_LISTENER_DATA_RSP_COMMAND; |
| 793 | send_data_rsp.listener_id = lstnr ; |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 794 | if (ptr_svc) |
| 795 | msm_ion_do_cache_op(qseecom.ion_clnt, ptr_svc->ihandle, |
| 796 | ptr_svc->sb_virt, ptr_svc->sb_length, |
| 797 | ION_IOC_CLEAN_INV_CACHES); |
Zhen Kong | 7812dc1 | 2013-07-09 17:12:55 -0700 | [diff] [blame] | 798 | |
| 799 | if (lstnr == RPMB_SERVICE) |
| 800 | __qseecom_enable_clk(CLK_QSEE); |
| 801 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 802 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, |
| 803 | (const void *)&send_data_rsp, |
| 804 | sizeof(send_data_rsp), resp, |
| 805 | sizeof(*resp)); |
| 806 | if (ret) { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 807 | pr_err("scm_call() failed with err: %d (app_id = %d)\n", |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 808 | ret, data->client.app_id); |
Zhen Kong | 7812dc1 | 2013-07-09 17:12:55 -0700 | [diff] [blame] | 809 | if (lstnr == RPMB_SERVICE) |
| 810 | __qseecom_disable_clk(CLK_QSEE); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 811 | return ret; |
| 812 | } |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 813 | if ((resp->result != QSEOS_RESULT_SUCCESS) && |
| 814 | (resp->result != QSEOS_RESULT_INCOMPLETE)) { |
| 815 | pr_err("fail:resp res= %d,app_id = %d,lstr = %d\n", |
| 816 | resp->result, data->client.app_id, lstnr); |
| 817 | ret = -EINVAL; |
Mona Hossain | bb0bca1 | 2012-04-12 11:47:45 -0700 | [diff] [blame] | 818 | } |
Zhen Kong | 7812dc1 | 2013-07-09 17:12:55 -0700 | [diff] [blame] | 819 | if (lstnr == RPMB_SERVICE) |
| 820 | __qseecom_disable_clk(CLK_QSEE); |
| 821 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 822 | } |
Mona Hossain | 0b3a279 | 2013-02-05 17:38:55 -0800 | [diff] [blame] | 823 | if (rc) |
| 824 | return rc; |
| 825 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 826 | return ret; |
| 827 | } |
| 828 | |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 829 | static int __qseecom_check_app_exists(struct qseecom_check_app_ireq req) |
| 830 | { |
| 831 | int32_t ret; |
| 832 | struct qseecom_command_scm_resp resp; |
| 833 | |
| 834 | /* SCM_CALL to check if app_id for the mentioned app exists */ |
| 835 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &req, |
| 836 | sizeof(struct qseecom_check_app_ireq), |
| 837 | &resp, sizeof(resp)); |
| 838 | if (ret) { |
| 839 | pr_err("scm_call to check if app is already loaded failed\n"); |
| 840 | return -EINVAL; |
| 841 | } |
| 842 | |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 843 | if (resp.result == QSEOS_RESULT_FAILURE) { |
| 844 | return 0; |
| 845 | } else { |
| 846 | switch (resp.resp_type) { |
| 847 | /*qsee returned listener type response */ |
| 848 | case QSEOS_LISTENER_ID: |
| 849 | pr_err("resp type is of listener type instead of app"); |
| 850 | return -EINVAL; |
| 851 | break; |
| 852 | case QSEOS_APP_ID: |
| 853 | return resp.data; |
| 854 | default: |
| 855 | pr_err("invalid resp type (%d) from qsee", |
| 856 | resp.resp_type); |
| 857 | return -ENODEV; |
| 858 | break; |
| 859 | } |
| 860 | } |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 863 | static int qseecom_load_app(struct qseecom_dev_handle *data, void __user *argp) |
| 864 | { |
| 865 | struct qseecom_registered_app_list *entry = NULL; |
| 866 | unsigned long flags = 0; |
| 867 | u32 app_id = 0; |
| 868 | struct ion_handle *ihandle; /* Ion handle */ |
| 869 | struct qseecom_load_img_req load_img_req; |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 870 | int32_t ret = 0; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 871 | ion_phys_addr_t pa = 0; |
| 872 | uint32_t len; |
| 873 | struct qseecom_command_scm_resp resp; |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 874 | struct qseecom_check_app_ireq req; |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 875 | struct qseecom_load_app_ireq load_req; |
| 876 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 877 | /* Copy the relevant information needed for loading the image */ |
Hariprasad Dhalinarasimha | e201495 | 2013-10-01 18:25:21 -0700 | [diff] [blame] | 878 | if (copy_from_user(&load_img_req, |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 879 | (void __user *)argp, |
| 880 | sizeof(struct qseecom_load_img_req))) { |
| 881 | pr_err("copy_from_user failed\n"); |
| 882 | return -EFAULT; |
| 883 | } |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 884 | |
| 885 | if (qseecom.support_bus_scaling) { |
| 886 | mutex_lock(&qsee_bw_mutex); |
| 887 | ret = __qseecom_register_bus_bandwidth_needs(data, MEDIUM); |
| 888 | mutex_unlock(&qsee_bw_mutex); |
| 889 | if (ret) |
| 890 | return ret; |
| 891 | } |
| 892 | |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 893 | /* Vote for the SFPB clock */ |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 894 | ret = __qseecom_enable_clk_scale_up(data); |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 895 | if (ret) |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 896 | goto enable_clk_err; |
| 897 | |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 898 | req.qsee_cmd_id = QSEOS_APP_LOOKUP_COMMAND; |
Hariprasad Dhalinarasimha | 7a01882 | 2013-10-03 16:52:16 -0700 | [diff] [blame] | 899 | load_img_req.img_name[MAX_APP_NAME_SIZE-1] = '\0'; |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 900 | memcpy(req.app_name, load_img_req.img_name, MAX_APP_NAME_SIZE); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 901 | |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 902 | ret = __qseecom_check_app_exists(req); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 903 | if (ret < 0) |
| 904 | goto loadapp_err; |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 905 | |
AnilKumar Chimata | 5370c7a | 2013-06-12 12:43:55 +0530 | [diff] [blame] | 906 | app_id = ret; |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 907 | if (app_id) { |
Mona Hossain | 7c44320 | 2013-04-18 12:08:58 -0700 | [diff] [blame] | 908 | pr_debug("App id %d (%s) already exists\n", app_id, |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 909 | (char *)(req.app_name)); |
| 910 | spin_lock_irqsave(&qseecom.registered_app_list_lock, flags); |
| 911 | list_for_each_entry(entry, |
| 912 | &qseecom.registered_app_list_head, list){ |
| 913 | if (entry->app_id == app_id) { |
| 914 | entry->ref_cnt++; |
| 915 | break; |
| 916 | } |
| 917 | } |
| 918 | spin_unlock_irqrestore( |
| 919 | &qseecom.registered_app_list_lock, flags); |
| 920 | } else { |
| 921 | pr_warn("App (%s) does'nt exist, loading apps for first time\n", |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 922 | (char *)(load_img_req.img_name)); |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 923 | /* Get the handle of the shared fd */ |
| 924 | ihandle = ion_import_dma_buf(qseecom.ion_clnt, |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 925 | load_img_req.ifd_data_fd); |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 926 | if (IS_ERR_OR_NULL(ihandle)) { |
| 927 | pr_err("Ion client could not retrieve the handle\n"); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 928 | ret = -ENOMEM; |
| 929 | goto loadapp_err; |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 930 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 931 | |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 932 | /* Get the physical address of the ION BUF */ |
| 933 | ret = ion_phys(qseecom.ion_clnt, ihandle, &pa, &len); |
Zhen Kong | 05ed446 | 2014-01-28 18:21:30 -0800 | [diff] [blame] | 934 | if (ret) { |
| 935 | pr_err("Cannot get phys_addr for the Ion Client, ret = %d\n", |
| 936 | ret); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 937 | goto loadapp_err; |
Zhen Kong | 05ed446 | 2014-01-28 18:21:30 -0800 | [diff] [blame] | 938 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 939 | |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 940 | /* Populate the structure for sending scm call to load image */ |
| 941 | memcpy(load_req.app_name, load_img_req.img_name, |
| 942 | MAX_APP_NAME_SIZE); |
| 943 | load_req.qsee_cmd_id = QSEOS_APP_START_COMMAND; |
| 944 | load_req.mdt_len = load_img_req.mdt_len; |
| 945 | load_req.img_len = load_img_req.img_len; |
| 946 | load_req.phy_addr = pa; |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 947 | msm_ion_do_cache_op(qseecom.ion_clnt, ihandle, NULL, len, |
| 948 | ION_IOC_CLEAN_INV_CACHES); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 949 | |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 950 | /* SCM_CALL to load the app and get the app_id back */ |
| 951 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &load_req, |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 952 | sizeof(struct qseecom_load_app_ireq), |
| 953 | &resp, sizeof(resp)); |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 954 | if (ret) { |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 955 | pr_err("scm_call to load app failed\n"); |
Hariprasad Dhalinarasimha | 56d3512 | 2013-02-28 17:55:51 -0800 | [diff] [blame] | 956 | if (!IS_ERR_OR_NULL(ihandle)) |
| 957 | ion_free(qseecom.ion_clnt, ihandle); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 958 | ret = -EINVAL; |
| 959 | goto loadapp_err; |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | if (resp.result == QSEOS_RESULT_FAILURE) { |
| 963 | pr_err("scm_call rsp.result is QSEOS_RESULT_FAILURE\n"); |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 964 | if (!IS_ERR_OR_NULL(ihandle)) |
| 965 | ion_free(qseecom.ion_clnt, ihandle); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 966 | ret = -EFAULT; |
| 967 | goto loadapp_err; |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 968 | } |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 969 | |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 970 | if (resp.result == QSEOS_RESULT_INCOMPLETE) { |
| 971 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
| 972 | if (ret) { |
| 973 | pr_err("process_incomplete_cmd failed err: %d\n", |
| 974 | ret); |
| 975 | if (!IS_ERR_OR_NULL(ihandle)) |
| 976 | ion_free(qseecom.ion_clnt, ihandle); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 977 | ret = -EFAULT; |
| 978 | goto loadapp_err; |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
| 982 | if (resp.result != QSEOS_RESULT_SUCCESS) { |
| 983 | pr_err("scm_call failed resp.result unknown, %d\n", |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 984 | resp.result); |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 985 | if (!IS_ERR_OR_NULL(ihandle)) |
| 986 | ion_free(qseecom.ion_clnt, ihandle); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 987 | ret = -EFAULT; |
| 988 | goto loadapp_err; |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | app_id = resp.data; |
| 992 | |
| 993 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
| 994 | if (!entry) { |
| 995 | pr_err("kmalloc failed\n"); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 996 | ret = -ENOMEM; |
| 997 | goto loadapp_err; |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 998 | } |
| 999 | entry->app_id = app_id; |
| 1000 | entry->ref_cnt = 1; |
| 1001 | |
| 1002 | /* Deallocate the handle */ |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 1003 | if (!IS_ERR_OR_NULL(ihandle)) |
| 1004 | ion_free(qseecom.ion_clnt, ihandle); |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 1005 | |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 1006 | spin_lock_irqsave(&qseecom.registered_app_list_lock, flags); |
| 1007 | list_add_tail(&entry->list, &qseecom.registered_app_list_head); |
| 1008 | spin_unlock_irqrestore(&qseecom.registered_app_list_lock, |
| 1009 | flags); |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 1010 | |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 1011 | pr_warn("App with id %d (%s) now loaded\n", app_id, |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 1012 | (char *)(load_img_req.img_name)); |
Mona Hossain | 436b75f | 2012-11-20 17:10:40 -0800 | [diff] [blame] | 1013 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1014 | data->client.app_id = app_id; |
| 1015 | load_img_req.app_id = app_id; |
| 1016 | if (copy_to_user(argp, &load_img_req, sizeof(load_img_req))) { |
| 1017 | pr_err("copy_to_user failed\n"); |
| 1018 | kzfree(entry); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1019 | ret = -EFAULT; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1020 | } |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1021 | |
| 1022 | loadapp_err: |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1023 | __qseecom_disable_clk_scale_down(data); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1024 | enable_clk_err: |
| 1025 | if (qseecom.support_bus_scaling) { |
| 1026 | mutex_lock(&qsee_bw_mutex); |
| 1027 | qseecom_unregister_bus_bandwidth_needs(data); |
| 1028 | mutex_unlock(&qsee_bw_mutex); |
| 1029 | } |
| 1030 | return ret; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static int __qseecom_cleanup_app(struct qseecom_dev_handle *data) |
| 1034 | { |
| 1035 | wake_up_all(&qseecom.send_resp_wq); |
| 1036 | while (atomic_read(&data->ioctl_count) > 1) { |
Mona Hossain | acea102 | 2012-04-09 13:37:27 -0700 | [diff] [blame] | 1037 | if (wait_event_freezable(data->abort_wq, |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1038 | atomic_read(&data->ioctl_count) <= 1)) { |
| 1039 | pr_err("Interrupted from abort\n"); |
| 1040 | return -ERESTARTSYS; |
| 1041 | break; |
| 1042 | } |
| 1043 | } |
| 1044 | /* Set unload app */ |
| 1045 | return 1; |
| 1046 | } |
| 1047 | |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1048 | static int qseecom_unmap_ion_allocated_memory(struct qseecom_dev_handle *data) |
| 1049 | { |
| 1050 | int ret = 0; |
| 1051 | if (!IS_ERR_OR_NULL(data->client.ihandle)) { |
| 1052 | ion_unmap_kernel(qseecom.ion_clnt, data->client.ihandle); |
| 1053 | ion_free(qseecom.ion_clnt, data->client.ihandle); |
| 1054 | data->client.ihandle = NULL; |
| 1055 | } |
| 1056 | return ret; |
| 1057 | } |
| 1058 | |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 1059 | static int qseecom_unload_app(struct qseecom_dev_handle *data, |
Hariprasad Dhalinarasimha | ba30614 | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 1060 | bool app_crash) |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1061 | { |
| 1062 | unsigned long flags; |
| 1063 | int ret = 0; |
| 1064 | struct qseecom_command_scm_resp resp; |
| 1065 | struct qseecom_registered_app_list *ptr_app; |
Mona Hossain | 340dba8 | 2012-08-07 19:54:46 -0700 | [diff] [blame] | 1066 | bool unload = false; |
| 1067 | bool found_app = false; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1068 | |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 1069 | if (data->client.app_id > 0) { |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1070 | spin_lock_irqsave(&qseecom.registered_app_list_lock, flags); |
| 1071 | list_for_each_entry(ptr_app, &qseecom.registered_app_list_head, |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 1072 | list) { |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1073 | if (ptr_app->app_id == data->client.app_id) { |
Mona Hossain | 340dba8 | 2012-08-07 19:54:46 -0700 | [diff] [blame] | 1074 | found_app = true; |
Hariprasad Dhalinarasimha | ba30614 | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 1075 | if (app_crash) { |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 1076 | ptr_app->ref_cnt = 0; |
Mona Hossain | 340dba8 | 2012-08-07 19:54:46 -0700 | [diff] [blame] | 1077 | unload = true; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1078 | break; |
| 1079 | } else { |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 1080 | if (ptr_app->ref_cnt == 1) { |
| 1081 | unload = true; |
| 1082 | break; |
| 1083 | } else { |
| 1084 | ptr_app->ref_cnt--; |
| 1085 | pr_debug("Can't unload app(%d) inuse\n", |
| 1086 | ptr_app->app_id); |
| 1087 | break; |
| 1088 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | spin_unlock_irqrestore(&qseecom.registered_app_list_lock, |
| 1093 | flags); |
Mona Hossain | 1fb538f | 2012-08-30 16:19:38 -0700 | [diff] [blame] | 1094 | if (found_app == false) { |
| 1095 | pr_err("Cannot find app with id = %d\n", |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 1096 | data->client.app_id); |
Mona Hossain | 1fb538f | 2012-08-30 16:19:38 -0700 | [diff] [blame] | 1097 | return -EINVAL; |
| 1098 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1099 | } |
| 1100 | |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 1101 | if (unload) { |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1102 | struct qseecom_unload_app_ireq req; |
| 1103 | |
Mona Hossain | 340dba8 | 2012-08-07 19:54:46 -0700 | [diff] [blame] | 1104 | __qseecom_cleanup_app(data); |
| 1105 | spin_lock_irqsave(&qseecom.registered_app_list_lock, flags); |
| 1106 | list_del(&ptr_app->list); |
| 1107 | kzfree(ptr_app); |
| 1108 | spin_unlock_irqrestore(&qseecom.registered_app_list_lock, |
| 1109 | flags); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1110 | /* Populate the structure for sending scm call to load image */ |
| 1111 | req.qsee_cmd_id = QSEOS_APP_SHUTDOWN_COMMAND; |
| 1112 | req.app_id = data->client.app_id; |
| 1113 | |
| 1114 | /* SCM_CALL to unload the app */ |
| 1115 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &req, |
| 1116 | sizeof(struct qseecom_unload_app_ireq), |
| 1117 | &resp, sizeof(resp)); |
| 1118 | if (ret) { |
Mona Hossain | bb0bca1 | 2012-04-12 11:47:45 -0700 | [diff] [blame] | 1119 | pr_err("scm_call to unload app (id = %d) failed\n", |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 1120 | req.app_id); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1121 | return -EFAULT; |
Mona Hossain | bb0bca1 | 2012-04-12 11:47:45 -0700 | [diff] [blame] | 1122 | } else { |
| 1123 | pr_warn("App id %d now unloaded\n", req.app_id); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1124 | } |
| 1125 | if (resp.result == QSEOS_RESULT_INCOMPLETE) { |
| 1126 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
| 1127 | if (ret) { |
| 1128 | pr_err("process_incomplete_cmd fail err: %d\n", |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 1129 | ret); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1130 | return ret; |
| 1131 | } |
| 1132 | } |
| 1133 | } |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1134 | qseecom_unmap_ion_allocated_memory(data); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1135 | data->released = true; |
| 1136 | return ret; |
| 1137 | } |
| 1138 | |
| 1139 | static uint32_t __qseecom_uvirt_to_kphys(struct qseecom_dev_handle *data, |
| 1140 | uint32_t virt) |
| 1141 | { |
| 1142 | return data->client.sb_phys + (virt - data->client.user_virt_sb_base); |
| 1143 | } |
| 1144 | |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 1145 | static uint32_t __qseecom_uvirt_to_kvirt(struct qseecom_dev_handle *data, |
| 1146 | uint32_t virt) |
| 1147 | { |
| 1148 | return (uint32_t)data->client.sb_virt + |
| 1149 | (virt - data->client.user_virt_sb_base); |
| 1150 | } |
| 1151 | |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1152 | int __qseecom_process_rpmb_svc_cmd(struct qseecom_dev_handle *data_ptr, |
| 1153 | struct qseecom_send_svc_cmd_req *req_ptr, |
| 1154 | struct qseecom_client_send_service_ireq *send_svc_ireq_ptr) |
| 1155 | { |
| 1156 | int ret = 0; |
Hariprasad Dhalinarasimha | fd86ecd | 2013-09-27 18:38:53 -0700 | [diff] [blame] | 1157 | void *req_buf = NULL; |
| 1158 | |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1159 | if ((req_ptr == NULL) || (send_svc_ireq_ptr == NULL)) { |
| 1160 | pr_err("Error with pointer: req_ptr = %p, send_svc_ptr = %p\n", |
| 1161 | req_ptr, send_svc_ireq_ptr); |
| 1162 | return -EINVAL; |
| 1163 | } |
Hariprasad Dhalinarasimha | fd86ecd | 2013-09-27 18:38:53 -0700 | [diff] [blame] | 1164 | |
Hariprasad Dhalinarasimha | 10aed74 | 2013-11-18 11:54:03 -0800 | [diff] [blame] | 1165 | if ((!req_ptr->cmd_req_buf) || (!req_ptr->resp_buf)) { |
| 1166 | pr_err("Invalid req/resp buffer, exiting\n"); |
| 1167 | return -EINVAL; |
| 1168 | } |
| 1169 | |
Hariprasad Dhalinarasimha | 4b61e2a | 2014-02-12 19:43:02 -0800 | [diff] [blame] | 1170 | /* Clients need to ensure req_buf is at base offset of shared buffer */ |
| 1171 | if ((uint32_t)req_ptr->cmd_req_buf != |
| 1172 | data_ptr->client.user_virt_sb_base) { |
| 1173 | pr_err("cmd buf not pointing to base offset of shared buffer\n"); |
Hariprasad Dhalinarasimha | fd86ecd | 2013-09-27 18:38:53 -0700 | [diff] [blame] | 1174 | return -EINVAL; |
| 1175 | } |
| 1176 | |
Hariprasad Dhalinarasimha | fd86ecd | 2013-09-27 18:38:53 -0700 | [diff] [blame] | 1177 | if (((uint32_t)req_ptr->resp_buf < data_ptr->client.user_virt_sb_base) |
| 1178 | || ((uint32_t)req_ptr->resp_buf >= |
| 1179 | (data_ptr->client.user_virt_sb_base + |
| 1180 | data_ptr->client.sb_length))){ |
| 1181 | pr_err("response buffer address not within shared bufffer\n"); |
| 1182 | return -EINVAL; |
| 1183 | } |
| 1184 | |
| 1185 | req_buf = data_ptr->client.sb_virt; |
| 1186 | |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1187 | send_svc_ireq_ptr->qsee_cmd_id = req_ptr->cmd_id; |
| 1188 | send_svc_ireq_ptr->key_type = |
Hariprasad Dhalinarasimha | fd86ecd | 2013-09-27 18:38:53 -0700 | [diff] [blame] | 1189 | ((struct qseecom_rpmb_provision_key *)req_buf)->key_type; |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1190 | send_svc_ireq_ptr->req_len = req_ptr->cmd_req_len; |
| 1191 | send_svc_ireq_ptr->rsp_ptr = (void *)(__qseecom_uvirt_to_kphys(data_ptr, |
| 1192 | (uint32_t)req_ptr->resp_buf)); |
| 1193 | send_svc_ireq_ptr->rsp_len = req_ptr->resp_len; |
| 1194 | |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1195 | return ret; |
| 1196 | } |
| 1197 | |
| 1198 | static int qseecom_send_service_cmd(struct qseecom_dev_handle *data, |
| 1199 | void __user *argp) |
| 1200 | { |
| 1201 | int ret = 0; |
| 1202 | struct qseecom_client_send_service_ireq send_svc_ireq; |
| 1203 | struct qseecom_command_scm_resp resp; |
| 1204 | struct qseecom_send_svc_cmd_req req; |
| 1205 | /*struct qseecom_command_scm_resp resp;*/ |
| 1206 | |
Hariprasad Dhalinarasimha | e201495 | 2013-10-01 18:25:21 -0700 | [diff] [blame] | 1207 | if (copy_from_user(&req, |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1208 | (void __user *)argp, |
| 1209 | sizeof(req))) { |
| 1210 | pr_err("copy_from_user failed\n"); |
| 1211 | return -EFAULT; |
| 1212 | } |
| 1213 | |
| 1214 | if (req.resp_buf == NULL) { |
| 1215 | pr_err("cmd buffer or response buffer is null\n"); |
| 1216 | return -EINVAL; |
| 1217 | } |
| 1218 | |
Hariprasad Dhalinarasimha | 4b61e2a | 2014-02-12 19:43:02 -0800 | [diff] [blame] | 1219 | if (data->client.sb_virt == NULL) { |
| 1220 | pr_err("sb_virt null\n"); |
| 1221 | return -EINVAL; |
| 1222 | } |
| 1223 | |
| 1224 | if (data->client.user_virt_sb_base == 0) { |
| 1225 | pr_err("user_virt_sb_base is null\n"); |
| 1226 | return -EINVAL; |
| 1227 | } |
| 1228 | |
| 1229 | if (data->client.sb_length == 0) { |
| 1230 | pr_err("sb_length is 0\n"); |
| 1231 | return -EINVAL; |
| 1232 | } |
| 1233 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1234 | data->type = QSEECOM_SECURE_SERVICE; |
| 1235 | |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1236 | switch (req.cmd_id) { |
Hariprasad Dhalinarasimha | b383224 | 2013-07-23 15:35:26 -0700 | [diff] [blame] | 1237 | case QSEOS_RPMB_PROVISION_KEY_COMMAND: |
| 1238 | case QSEOS_RPMB_ERASE_COMMAND: |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1239 | if (__qseecom_process_rpmb_svc_cmd(data, &req, |
| 1240 | &send_svc_ireq)) |
| 1241 | return -EINVAL; |
| 1242 | break; |
| 1243 | default: |
| 1244 | pr_err("Unsupported cmd_id %d\n", req.cmd_id); |
| 1245 | return -EINVAL; |
| 1246 | } |
AnilKumar Chimata | 80f1d1b | 2013-08-03 05:16:14 +0530 | [diff] [blame] | 1247 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1248 | if (qseecom.support_bus_scaling) { |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 1249 | ret = qseecom_scale_bus_bandwidth_timer(HIGH); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1250 | if (ret) { |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 1251 | pr_err("Fail to set bw HIGH\n"); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1252 | return ret; |
| 1253 | } |
| 1254 | } else { |
| 1255 | ret = qsee_vote_for_clock(data, CLK_DFAB); |
| 1256 | if (ret) { |
| 1257 | pr_err("Failed to vote for DFAB clock%d\n", ret); |
| 1258 | return ret; |
| 1259 | } |
| 1260 | ret = qsee_vote_for_clock(data, CLK_SFPB); |
| 1261 | if (ret) { |
| 1262 | qsee_disable_clock_vote(data, CLK_DFAB); |
| 1263 | pr_err("Failed to vote for SFPB clock%d\n", ret); |
| 1264 | goto exit; |
| 1265 | } |
AnilKumar Chimata | 80f1d1b | 2013-08-03 05:16:14 +0530 | [diff] [blame] | 1266 | } |
| 1267 | |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 1268 | msm_ion_do_cache_op(qseecom.ion_clnt, data->client.ihandle, |
| 1269 | data->client.sb_virt, data->client.sb_length, |
| 1270 | ION_IOC_CLEAN_INV_CACHES); |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1271 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, (const void *) &send_svc_ireq, |
| 1272 | sizeof(send_svc_ireq), |
| 1273 | &resp, sizeof(resp)); |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 1274 | msm_ion_do_cache_op(qseecom.ion_clnt, data->client.ihandle, |
| 1275 | data->client.sb_virt, data->client.sb_length, |
| 1276 | ION_IOC_INV_CACHES); |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1277 | if (ret) { |
| 1278 | pr_err("qseecom_scm_call failed with err: %d\n", ret); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1279 | if (!qseecom.support_bus_scaling) { |
| 1280 | qsee_disable_clock_vote(data, CLK_DFAB); |
| 1281 | qsee_disable_clock_vote(data, CLK_SFPB); |
Zhen Kong | af95019 | 2014-02-05 17:36:23 -0800 | [diff] [blame] | 1282 | } else { |
| 1283 | __qseecom_add_bw_scale_down_timer( |
| 1284 | QSEECOM_SEND_CMD_CRYPTO_TIMEOUT); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1285 | } |
| 1286 | goto exit; |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | switch (resp.result) { |
| 1290 | case QSEOS_RESULT_SUCCESS: |
| 1291 | break; |
| 1292 | case QSEOS_RESULT_INCOMPLETE: |
| 1293 | pr_err("qseos_result_incomplete\n"); |
| 1294 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
| 1295 | if (ret) { |
| 1296 | pr_err("process_incomplete_cmd fail: err: %d\n", |
| 1297 | ret); |
| 1298 | } |
| 1299 | break; |
| 1300 | case QSEOS_RESULT_FAILURE: |
| 1301 | pr_err("process_incomplete_cmd failed err: %d\n", ret); |
| 1302 | break; |
| 1303 | default: |
| 1304 | pr_err("Response result %d not supported\n", |
| 1305 | resp.result); |
| 1306 | ret = -EINVAL; |
| 1307 | break; |
| 1308 | } |
Zhen Kong | af95019 | 2014-02-05 17:36:23 -0800 | [diff] [blame] | 1309 | if (!qseecom.support_bus_scaling) { |
| 1310 | qsee_disable_clock_vote(data, CLK_DFAB); |
| 1311 | qsee_disable_clock_vote(data, CLK_SFPB); |
| 1312 | } else { |
| 1313 | __qseecom_add_bw_scale_down_timer( |
| 1314 | QSEECOM_SEND_CMD_CRYPTO_TIMEOUT); |
| 1315 | } |
| 1316 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1317 | exit: |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1318 | return ret; |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1321 | static int __qseecom_send_cmd(struct qseecom_dev_handle *data, |
| 1322 | struct qseecom_send_cmd_req *req) |
| 1323 | { |
| 1324 | int ret = 0; |
| 1325 | u32 reqd_len_sb_in = 0; |
| 1326 | struct qseecom_client_send_data_ireq send_data_req; |
| 1327 | struct qseecom_command_scm_resp resp; |
| 1328 | |
| 1329 | if (req->cmd_req_buf == NULL || req->resp_buf == NULL) { |
| 1330 | pr_err("cmd buffer or response buffer is null\n"); |
| 1331 | return -EINVAL; |
| 1332 | } |
Mona Hossain | dddf444 | 2013-10-01 14:08:20 -0700 | [diff] [blame] | 1333 | if (((uint32_t)req->cmd_req_buf < data->client.user_virt_sb_base) || |
| 1334 | ((uint32_t)req->cmd_req_buf >= (data->client.user_virt_sb_base + |
| 1335 | data->client.sb_length))) { |
| 1336 | pr_err("cmd buffer address not within shared bufffer\n"); |
| 1337 | return -EINVAL; |
| 1338 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1339 | |
Mona Hossain | dddf444 | 2013-10-01 14:08:20 -0700 | [diff] [blame] | 1340 | |
| 1341 | if (((uint32_t)req->resp_buf < data->client.user_virt_sb_base) || |
| 1342 | ((uint32_t)req->resp_buf >= (data->client.user_virt_sb_base + |
| 1343 | data->client.sb_length))){ |
| 1344 | pr_err("response buffer address not within shared bufffer\n"); |
| 1345 | return -EINVAL; |
| 1346 | } |
| 1347 | |
| 1348 | if ((req->cmd_req_len == 0) || (req->resp_len == 0) || |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1349 | req->cmd_req_len > data->client.sb_length || |
| 1350 | req->resp_len > data->client.sb_length) { |
| 1351 | pr_err("cmd buffer length or " |
| 1352 | "response buffer length not valid\n"); |
| 1353 | return -EINVAL; |
| 1354 | } |
| 1355 | |
Hariprasad Dhalinarasimha | 528400a | 2013-10-03 16:43:39 -0700 | [diff] [blame] | 1356 | if (req->cmd_req_len > UINT_MAX - req->resp_len) { |
| 1357 | pr_err("Integer overflow detected in req_len & rsp_len, exiting now\n"); |
| 1358 | return -EINVAL; |
| 1359 | } |
| 1360 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1361 | reqd_len_sb_in = req->cmd_req_len + req->resp_len; |
| 1362 | if (reqd_len_sb_in > data->client.sb_length) { |
| 1363 | pr_debug("Not enough memory to fit cmd_buf and " |
| 1364 | "resp_buf. Required: %u, Available: %u\n", |
| 1365 | reqd_len_sb_in, data->client.sb_length); |
| 1366 | return -ENOMEM; |
| 1367 | } |
| 1368 | |
| 1369 | send_data_req.qsee_cmd_id = QSEOS_CLIENT_SEND_DATA_COMMAND; |
| 1370 | send_data_req.app_id = data->client.app_id; |
| 1371 | send_data_req.req_ptr = (void *)(__qseecom_uvirt_to_kphys(data, |
| 1372 | (uint32_t)req->cmd_req_buf)); |
| 1373 | send_data_req.req_len = req->cmd_req_len; |
| 1374 | send_data_req.rsp_ptr = (void *)(__qseecom_uvirt_to_kphys(data, |
| 1375 | (uint32_t)req->resp_buf)); |
| 1376 | send_data_req.rsp_len = req->resp_len; |
| 1377 | |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 1378 | msm_ion_do_cache_op(qseecom.ion_clnt, data->client.ihandle, |
| 1379 | data->client.sb_virt, |
Hariprasad Dhalinarasimha | 528400a | 2013-10-03 16:43:39 -0700 | [diff] [blame] | 1380 | reqd_len_sb_in, |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 1381 | ION_IOC_CLEAN_INV_CACHES); |
| 1382 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1383 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, (const void *) &send_data_req, |
| 1384 | sizeof(send_data_req), |
| 1385 | &resp, sizeof(resp)); |
| 1386 | if (ret) { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 1387 | pr_err("scm_call() failed with err: %d (app_id = %d)\n", |
| 1388 | ret, data->client.app_id); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1389 | return ret; |
| 1390 | } |
| 1391 | |
| 1392 | if (resp.result == QSEOS_RESULT_INCOMPLETE) { |
| 1393 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
| 1394 | if (ret) { |
| 1395 | pr_err("process_incomplete_cmd failed err: %d\n", ret); |
| 1396 | return ret; |
| 1397 | } |
Mona Hossain | bb0bca1 | 2012-04-12 11:47:45 -0700 | [diff] [blame] | 1398 | } else { |
| 1399 | if (resp.result != QSEOS_RESULT_SUCCESS) { |
| 1400 | pr_err("Response result %d not supported\n", |
| 1401 | resp.result); |
| 1402 | ret = -EINVAL; |
| 1403 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1404 | } |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 1405 | msm_ion_do_cache_op(qseecom.ion_clnt, data->client.ihandle, |
| 1406 | data->client.sb_virt, data->client.sb_length, |
| 1407 | ION_IOC_INV_CACHES); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1408 | return ret; |
| 1409 | } |
| 1410 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1411 | static int qseecom_send_cmd(struct qseecom_dev_handle *data, void __user *argp) |
| 1412 | { |
| 1413 | int ret = 0; |
| 1414 | struct qseecom_send_cmd_req req; |
| 1415 | |
| 1416 | ret = copy_from_user(&req, argp, sizeof(req)); |
| 1417 | if (ret) { |
| 1418 | pr_err("copy_from_user failed\n"); |
| 1419 | return ret; |
| 1420 | } |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 1421 | ret = __qseecom_send_cmd(data, &req); |
| 1422 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1423 | if (ret) |
| 1424 | return ret; |
| 1425 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1426 | return ret; |
| 1427 | } |
| 1428 | |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 1429 | static int __qseecom_update_cmd_buf(void *msg, bool cleanup, |
| 1430 | struct qseecom_dev_handle *data, |
| 1431 | bool listener_svc) |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1432 | { |
| 1433 | struct ion_handle *ihandle; |
| 1434 | char *field; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1435 | int ret = 0; |
| 1436 | int i = 0; |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 1437 | uint32_t len = 0; |
| 1438 | struct scatterlist *sg; |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 1439 | struct qseecom_send_modfd_cmd_req *cmd_req = NULL; |
| 1440 | struct qseecom_send_modfd_listener_resp *lstnr_resp = NULL; |
| 1441 | struct qseecom_registered_listener_list *this_lstnr = NULL; |
| 1442 | |
| 1443 | if (msg == NULL) { |
| 1444 | pr_err("Invalid address\n"); |
| 1445 | return -EINVAL; |
| 1446 | } |
| 1447 | if (listener_svc) { |
| 1448 | lstnr_resp = (struct qseecom_send_modfd_listener_resp *)msg; |
| 1449 | this_lstnr = __qseecom_find_svc(data->listener.id); |
| 1450 | if (IS_ERR_OR_NULL(this_lstnr)) { |
| 1451 | pr_err("Invalid listener ID\n"); |
| 1452 | return -ENOMEM; |
| 1453 | } |
| 1454 | } else { |
| 1455 | cmd_req = (struct qseecom_send_modfd_cmd_req *)msg; |
| 1456 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1457 | |
| 1458 | for (i = 0; i < MAX_ION_FD; i++) { |
Mona Hossain | f1f2ed6 | 2012-11-15 19:51:33 -0800 | [diff] [blame] | 1459 | struct sg_table *sg_ptr = NULL; |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 1460 | if ((!listener_svc) && (cmd_req->ifd_data[i].fd > 0)) { |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 1461 | ihandle = ion_import_dma_buf(qseecom.ion_clnt, |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 1462 | cmd_req->ifd_data[i].fd); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1463 | if (IS_ERR_OR_NULL(ihandle)) { |
| 1464 | pr_err("Ion client can't retrieve the handle\n"); |
| 1465 | return -ENOMEM; |
| 1466 | } |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 1467 | field = (char *) cmd_req->cmd_req_buf + |
| 1468 | cmd_req->ifd_data[i].cmd_buf_offset; |
| 1469 | } else if ((listener_svc) && |
| 1470 | (lstnr_resp->ifd_data[i].fd > 0)) { |
| 1471 | ihandle = ion_import_dma_buf(qseecom.ion_clnt, |
| 1472 | lstnr_resp->ifd_data[i].fd); |
| 1473 | if (IS_ERR_OR_NULL(ihandle)) { |
| 1474 | pr_err("Ion client can't retrieve the handle\n"); |
| 1475 | return -ENOMEM; |
Mona Hossain | f1f2ed6 | 2012-11-15 19:51:33 -0800 | [diff] [blame] | 1476 | } |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 1477 | field = lstnr_resp->resp_buf_ptr + |
| 1478 | lstnr_resp->ifd_data[i].cmd_buf_offset; |
| 1479 | } else { |
| 1480 | return ret; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1481 | } |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 1482 | /* Populate the cmd data structure with the phys_addr */ |
| 1483 | sg_ptr = ion_sg_table(qseecom.ion_clnt, ihandle); |
| 1484 | if (sg_ptr == NULL) { |
| 1485 | pr_err("IOn client could not retrieve sg table\n"); |
| 1486 | goto err; |
| 1487 | } |
| 1488 | if (sg_ptr->nents == 0) { |
| 1489 | pr_err("Num of scattered entries is 0\n"); |
| 1490 | goto err; |
| 1491 | } |
| 1492 | if (sg_ptr->nents > QSEECOM_MAX_SG_ENTRY) { |
| 1493 | pr_err("Num of scattered entries"); |
| 1494 | pr_err(" (%d) is greater than max supported %d\n", |
| 1495 | sg_ptr->nents, QSEECOM_MAX_SG_ENTRY); |
| 1496 | goto err; |
| 1497 | } |
| 1498 | sg = sg_ptr->sgl; |
| 1499 | if (sg_ptr->nents == 1) { |
| 1500 | uint32_t *update; |
| 1501 | update = (uint32_t *) field; |
| 1502 | if (cleanup) |
| 1503 | *update = 0; |
| 1504 | else |
| 1505 | *update = (uint32_t)sg_dma_address( |
| 1506 | sg_ptr->sgl); |
| 1507 | len += (uint32_t)sg->length; |
| 1508 | } else { |
| 1509 | struct qseecom_sg_entry *update; |
| 1510 | int j = 0; |
| 1511 | update = (struct qseecom_sg_entry *) field; |
| 1512 | for (j = 0; j < sg_ptr->nents; j++) { |
| 1513 | if (cleanup) { |
| 1514 | update->phys_addr = 0; |
| 1515 | update->len = 0; |
| 1516 | } else { |
| 1517 | update->phys_addr = (uint32_t) |
| 1518 | sg_dma_address(sg); |
| 1519 | update->len = sg->length; |
| 1520 | } |
| 1521 | len += sg->length; |
| 1522 | update++; |
| 1523 | sg = sg_next(sg); |
| 1524 | } |
| 1525 | } |
| 1526 | if (cleanup) |
| 1527 | msm_ion_do_cache_op(qseecom.ion_clnt, |
| 1528 | ihandle, NULL, len, |
| 1529 | ION_IOC_INV_CACHES); |
| 1530 | else |
| 1531 | msm_ion_do_cache_op(qseecom.ion_clnt, |
| 1532 | ihandle, NULL, len, |
| 1533 | ION_IOC_CLEAN_INV_CACHES); |
| 1534 | /* Deallocate the handle */ |
| 1535 | if (!IS_ERR_OR_NULL(ihandle)) |
| 1536 | ion_free(qseecom.ion_clnt, ihandle); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1537 | } |
| 1538 | return ret; |
Mona Hossain | f1f2ed6 | 2012-11-15 19:51:33 -0800 | [diff] [blame] | 1539 | err: |
| 1540 | if (!IS_ERR_OR_NULL(ihandle)) |
| 1541 | ion_free(qseecom.ion_clnt, ihandle); |
| 1542 | return -ENOMEM; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | static int qseecom_send_modfd_cmd(struct qseecom_dev_handle *data, |
| 1546 | void __user *argp) |
| 1547 | { |
| 1548 | int ret = 0; |
Mona Hossain | dddf444 | 2013-10-01 14:08:20 -0700 | [diff] [blame] | 1549 | int i; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1550 | struct qseecom_send_modfd_cmd_req req; |
| 1551 | struct qseecom_send_cmd_req send_cmd_req; |
| 1552 | |
| 1553 | ret = copy_from_user(&req, argp, sizeof(req)); |
| 1554 | if (ret) { |
| 1555 | pr_err("copy_from_user failed\n"); |
| 1556 | return ret; |
| 1557 | } |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 1558 | |
| 1559 | if (req.cmd_req_buf == NULL || req.resp_buf == NULL) { |
| 1560 | pr_err("cmd buffer or response buffer is null\n"); |
| 1561 | return -EINVAL; |
| 1562 | } |
| 1563 | if (((uint32_t)req.cmd_req_buf < data->client.user_virt_sb_base) || |
| 1564 | ((uint32_t)req.cmd_req_buf >= (data->client.user_virt_sb_base + |
| 1565 | data->client.sb_length))) { |
| 1566 | pr_err("cmd buffer address not within shared bufffer\n"); |
| 1567 | return -EINVAL; |
| 1568 | } |
| 1569 | |
| 1570 | if (((uint32_t)req.resp_buf < data->client.user_virt_sb_base) || |
| 1571 | ((uint32_t)req.resp_buf >= (data->client.user_virt_sb_base + |
| 1572 | data->client.sb_length))){ |
| 1573 | pr_err("response buffer address not within shared bufffer\n"); |
| 1574 | return -EINVAL; |
| 1575 | } |
Zhen Kong | a69c16e | 2014-03-27 12:44:15 -0700 | [diff] [blame] | 1576 | |
| 1577 | if (req.cmd_req_len == 0 || req.cmd_req_len > data->client.sb_length || |
| 1578 | req.resp_len > data->client.sb_length) { |
| 1579 | pr_err("cmd or response buffer length not valid\n"); |
| 1580 | return -EINVAL; |
| 1581 | } |
| 1582 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1583 | send_cmd_req.cmd_req_buf = req.cmd_req_buf; |
| 1584 | send_cmd_req.cmd_req_len = req.cmd_req_len; |
| 1585 | send_cmd_req.resp_buf = req.resp_buf; |
| 1586 | send_cmd_req.resp_len = req.resp_len; |
| 1587 | |
Mona Hossain | dddf444 | 2013-10-01 14:08:20 -0700 | [diff] [blame] | 1588 | /* validate offsets */ |
| 1589 | for (i = 0; i < MAX_ION_FD; i++) { |
| 1590 | if (req.ifd_data[i].cmd_buf_offset >= req.cmd_req_len) { |
| 1591 | pr_err("Invalid offset %d = 0x%x\n", |
| 1592 | i, req.ifd_data[i].cmd_buf_offset); |
| 1593 | return -EINVAL; |
| 1594 | } |
| 1595 | } |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 1596 | req.cmd_req_buf = (void *)__qseecom_uvirt_to_kvirt(data, |
| 1597 | (uint32_t)req.cmd_req_buf); |
| 1598 | req.resp_buf = (void *)__qseecom_uvirt_to_kvirt(data, |
| 1599 | (uint32_t)req.resp_buf); |
| 1600 | |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 1601 | ret = __qseecom_update_cmd_buf(&req, false, data, false); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1602 | if (ret) |
| 1603 | return ret; |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 1604 | ret = __qseecom_send_cmd(data, &send_cmd_req); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1605 | if (ret) |
| 1606 | return ret; |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 1607 | ret = __qseecom_update_cmd_buf(&req, true, data, false); |
Mona Hossain | c56584d | 2013-05-28 09:06:26 -0700 | [diff] [blame] | 1608 | if (ret) |
| 1609 | return ret; |
Zhen Kong | 04f65b8 | 2013-10-03 13:58:45 -0700 | [diff] [blame] | 1610 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1611 | return ret; |
| 1612 | } |
| 1613 | |
| 1614 | static int __qseecom_listener_has_rcvd_req(struct qseecom_dev_handle *data, |
| 1615 | struct qseecom_registered_listener_list *svc) |
| 1616 | { |
| 1617 | int ret; |
| 1618 | ret = (svc->rcv_req_flag != 0); |
| 1619 | return ret || data->abort; |
| 1620 | } |
| 1621 | |
| 1622 | static int qseecom_receive_req(struct qseecom_dev_handle *data) |
| 1623 | { |
| 1624 | int ret = 0; |
| 1625 | struct qseecom_registered_listener_list *this_lstnr; |
| 1626 | |
| 1627 | this_lstnr = __qseecom_find_svc(data->listener.id); |
AnilKumar Chimata | 69b857a | 2013-07-23 23:03:26 +0530 | [diff] [blame] | 1628 | if (!this_lstnr) { |
| 1629 | pr_err("Invalid listener ID\n"); |
| 1630 | return -ENODATA; |
| 1631 | } |
| 1632 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1633 | while (1) { |
Mona Hossain | acea102 | 2012-04-09 13:37:27 -0700 | [diff] [blame] | 1634 | if (wait_event_freezable(this_lstnr->rcv_req_wq, |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1635 | __qseecom_listener_has_rcvd_req(data, |
| 1636 | this_lstnr))) { |
Hariprasad Dhalinarasimha | f44cbd2 | 2013-07-20 04:49:34 +0530 | [diff] [blame] | 1637 | pr_debug("Interrupted: exiting Listener Service = %d\n", |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 1638 | (uint32_t)data->listener.id); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1639 | /* woken up for different reason */ |
| 1640 | return -ERESTARTSYS; |
| 1641 | } |
| 1642 | |
| 1643 | if (data->abort) { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 1644 | pr_err("Aborting Listener Service = %d\n", |
| 1645 | (uint32_t)data->listener.id); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1646 | return -ENODEV; |
| 1647 | } |
| 1648 | this_lstnr->rcv_req_flag = 0; |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 1649 | break; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 1650 | } |
| 1651 | return ret; |
| 1652 | } |
| 1653 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 1654 | static bool __qseecom_is_fw_image_valid(const struct firmware *fw_entry) |
| 1655 | { |
| 1656 | struct elf32_hdr *ehdr; |
| 1657 | |
| 1658 | if (fw_entry->size < sizeof(*ehdr)) { |
| 1659 | pr_err("%s: Not big enough to be an elf header\n", |
| 1660 | qseecom.pdev->init_name); |
| 1661 | return false; |
| 1662 | } |
| 1663 | ehdr = (struct elf32_hdr *)fw_entry->data; |
| 1664 | if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG)) { |
| 1665 | pr_err("%s: Not an elf header\n", |
| 1666 | qseecom.pdev->init_name); |
| 1667 | return false; |
| 1668 | } |
| 1669 | |
| 1670 | if (ehdr->e_phnum == 0) { |
| 1671 | pr_err("%s: No loadable segments\n", |
| 1672 | qseecom.pdev->init_name); |
| 1673 | return false; |
| 1674 | } |
| 1675 | if (sizeof(struct elf32_phdr) * ehdr->e_phnum + |
| 1676 | sizeof(struct elf32_hdr) > fw_entry->size) { |
| 1677 | pr_err("%s: Program headers not within mdt\n", |
| 1678 | qseecom.pdev->init_name); |
| 1679 | return false; |
| 1680 | } |
| 1681 | return true; |
| 1682 | } |
| 1683 | |
| 1684 | static int __qseecom_get_fw_size(char *appname, uint32_t *fw_size) |
| 1685 | { |
| 1686 | int ret = -1; |
| 1687 | int i = 0, rc = 0; |
| 1688 | const struct firmware *fw_entry = NULL; |
| 1689 | struct elf32_phdr *phdr; |
| 1690 | char fw_name[MAX_APP_NAME_SIZE]; |
| 1691 | struct elf32_hdr *ehdr; |
| 1692 | int num_images = 0; |
| 1693 | |
| 1694 | snprintf(fw_name, sizeof(fw_name), "%s.mdt", appname); |
| 1695 | rc = request_firmware(&fw_entry, fw_name, qseecom.pdev); |
| 1696 | if (rc) { |
| 1697 | pr_err("error with request_firmware\n"); |
| 1698 | ret = -EIO; |
| 1699 | goto err; |
| 1700 | } |
| 1701 | if (!__qseecom_is_fw_image_valid(fw_entry)) { |
| 1702 | ret = -EIO; |
| 1703 | goto err; |
| 1704 | } |
| 1705 | *fw_size = fw_entry->size; |
| 1706 | phdr = (struct elf32_phdr *)(fw_entry->data + sizeof(struct elf32_hdr)); |
| 1707 | ehdr = (struct elf32_hdr *)fw_entry->data; |
| 1708 | num_images = ehdr->e_phnum; |
| 1709 | release_firmware(fw_entry); |
| 1710 | for (i = 0; i < num_images; i++, phdr++) { |
| 1711 | memset(fw_name, 0, sizeof(fw_name)); |
| 1712 | snprintf(fw_name, ARRAY_SIZE(fw_name), "%s.b%02d", appname, i); |
| 1713 | ret = request_firmware(&fw_entry, fw_name, qseecom.pdev); |
| 1714 | if (ret) |
| 1715 | goto err; |
| 1716 | *fw_size += fw_entry->size; |
| 1717 | release_firmware(fw_entry); |
| 1718 | } |
| 1719 | return ret; |
| 1720 | err: |
| 1721 | if (fw_entry) |
| 1722 | release_firmware(fw_entry); |
| 1723 | *fw_size = 0; |
| 1724 | return ret; |
| 1725 | } |
| 1726 | |
| 1727 | static int __qseecom_get_fw_data(char *appname, u8 *img_data, |
| 1728 | struct qseecom_load_app_ireq *load_req) |
| 1729 | { |
| 1730 | int ret = -1; |
| 1731 | int i = 0, rc = 0; |
| 1732 | const struct firmware *fw_entry = NULL; |
| 1733 | char fw_name[MAX_APP_NAME_SIZE]; |
| 1734 | u8 *img_data_ptr = img_data; |
| 1735 | struct elf32_hdr *ehdr; |
| 1736 | int num_images = 0; |
| 1737 | |
| 1738 | snprintf(fw_name, sizeof(fw_name), "%s.mdt", appname); |
| 1739 | rc = request_firmware(&fw_entry, fw_name, qseecom.pdev); |
| 1740 | if (rc) { |
| 1741 | ret = -EIO; |
| 1742 | goto err; |
| 1743 | } |
| 1744 | load_req->img_len = fw_entry->size; |
| 1745 | memcpy(img_data_ptr, fw_entry->data, fw_entry->size); |
| 1746 | img_data_ptr = img_data_ptr + fw_entry->size; |
| 1747 | load_req->mdt_len = fw_entry->size; /*Get MDT LEN*/ |
| 1748 | ehdr = (struct elf32_hdr *)fw_entry->data; |
| 1749 | num_images = ehdr->e_phnum; |
| 1750 | release_firmware(fw_entry); |
| 1751 | for (i = 0; i < num_images; i++) { |
| 1752 | snprintf(fw_name, ARRAY_SIZE(fw_name), "%s.b%02d", appname, i); |
| 1753 | ret = request_firmware(&fw_entry, fw_name, qseecom.pdev); |
| 1754 | if (ret) { |
| 1755 | pr_err("Failed to locate blob %s\n", fw_name); |
| 1756 | goto err; |
| 1757 | } |
| 1758 | memcpy(img_data_ptr, fw_entry->data, fw_entry->size); |
| 1759 | img_data_ptr = img_data_ptr + fw_entry->size; |
| 1760 | load_req->img_len += fw_entry->size; |
| 1761 | release_firmware(fw_entry); |
| 1762 | } |
| 1763 | load_req->phy_addr = virt_to_phys(img_data); |
| 1764 | return ret; |
| 1765 | err: |
| 1766 | release_firmware(fw_entry); |
| 1767 | return ret; |
| 1768 | } |
| 1769 | |
| 1770 | static int __qseecom_load_fw(struct qseecom_dev_handle *data, char *appname) |
| 1771 | { |
| 1772 | int ret = -1; |
| 1773 | uint32_t fw_size = 0; |
| 1774 | struct qseecom_load_app_ireq load_req = {0, 0, 0, 0}; |
| 1775 | struct qseecom_command_scm_resp resp; |
| 1776 | u8 *img_data = NULL; |
| 1777 | |
| 1778 | if (__qseecom_get_fw_size(appname, &fw_size)) |
| 1779 | return -EIO; |
| 1780 | |
| 1781 | img_data = kzalloc(fw_size, GFP_KERNEL); |
| 1782 | if (!img_data) { |
| 1783 | pr_err("Failied to allocate memory for copying image data\n"); |
| 1784 | return -ENOMEM; |
| 1785 | } |
| 1786 | ret = __qseecom_get_fw_data(appname, img_data, &load_req); |
| 1787 | if (ret) { |
| 1788 | kzfree(img_data); |
| 1789 | return -EIO; |
| 1790 | } |
| 1791 | |
| 1792 | /* Populate the remaining parameters */ |
| 1793 | load_req.qsee_cmd_id = QSEOS_APP_START_COMMAND; |
| 1794 | memcpy(load_req.app_name, appname, MAX_APP_NAME_SIZE); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1795 | |
| 1796 | if (qseecom.support_bus_scaling) { |
| 1797 | mutex_lock(&qsee_bw_mutex); |
| 1798 | ret = __qseecom_register_bus_bandwidth_needs(data, MEDIUM); |
| 1799 | mutex_unlock(&qsee_bw_mutex); |
| 1800 | if (ret) { |
| 1801 | kzfree(img_data); |
| 1802 | return ret; |
| 1803 | } |
| 1804 | } |
| 1805 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1806 | ret = __qseecom_enable_clk_scale_up(data); |
Mona Hossain | 60f9fb0 | 2012-11-05 13:51:50 -0800 | [diff] [blame] | 1807 | if (ret) { |
| 1808 | kzfree(img_data); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1809 | ret = -EIO; |
| 1810 | goto loadfw_err; |
Mona Hossain | 60f9fb0 | 2012-11-05 13:51:50 -0800 | [diff] [blame] | 1811 | } |
| 1812 | |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 1813 | __cpuc_flush_dcache_area((void *)img_data, fw_size); |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 1814 | /* SCM_CALL to load the image */ |
| 1815 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &load_req, |
| 1816 | sizeof(struct qseecom_load_app_ireq), |
| 1817 | &resp, sizeof(resp)); |
| 1818 | kzfree(img_data); |
| 1819 | if (ret) { |
| 1820 | pr_err("scm_call to load failed : ret %d\n", ret); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1821 | ret = -EIO; |
| 1822 | goto loadfw_err; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | switch (resp.result) { |
| 1826 | case QSEOS_RESULT_SUCCESS: |
| 1827 | ret = resp.data; |
| 1828 | break; |
| 1829 | case QSEOS_RESULT_INCOMPLETE: |
| 1830 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
| 1831 | if (ret) |
| 1832 | pr_err("process_incomplete_cmd FAILED\n"); |
| 1833 | else |
| 1834 | ret = resp.data; |
| 1835 | break; |
| 1836 | case QSEOS_RESULT_FAILURE: |
| 1837 | pr_err("scm call failed with response QSEOS_RESULT FAILURE\n"); |
| 1838 | break; |
| 1839 | default: |
| 1840 | pr_err("scm call return unknown response %d\n", resp.result); |
| 1841 | ret = -EINVAL; |
| 1842 | break; |
| 1843 | } |
Mona Hossain | 60f9fb0 | 2012-11-05 13:51:50 -0800 | [diff] [blame] | 1844 | |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1845 | loadfw_err: |
| 1846 | __qseecom_disable_clk_scale_down(data); |
| 1847 | if (qseecom.support_bus_scaling) { |
| 1848 | mutex_lock(&qsee_bw_mutex); |
| 1849 | qseecom_unregister_bus_bandwidth_needs(data); |
| 1850 | mutex_unlock(&qsee_bw_mutex); |
| 1851 | } |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 1852 | return ret; |
| 1853 | } |
| 1854 | |
Mona Hossain | 9498f5e | 2013-01-23 18:08:45 -0800 | [diff] [blame] | 1855 | static int qseecom_load_commonlib_image(struct qseecom_dev_handle *data) |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1856 | { |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1857 | int ret = 0; |
Zhen Kong | fd64c98 | 2013-12-19 16:35:43 -0800 | [diff] [blame] | 1858 | int len = 0; |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1859 | uint32_t fw_size = 0; |
| 1860 | struct qseecom_load_app_ireq load_req = {0, 0, 0, 0}; |
| 1861 | struct qseecom_command_scm_resp resp; |
| 1862 | u8 *img_data = NULL; |
Zhen Kong | fd64c98 | 2013-12-19 16:35:43 -0800 | [diff] [blame] | 1863 | ion_phys_addr_t pa; |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1864 | |
Hariprasad Dhalinarasimha | a3b9644 | 2013-01-02 10:40:40 -0800 | [diff] [blame] | 1865 | if (__qseecom_get_fw_size("cmnlib", &fw_size)) |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1866 | return -EIO; |
| 1867 | |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1868 | qseecom.cmnlib_ion_handle = ion_alloc(qseecom.ion_clnt, fw_size, |
| 1869 | SZ_4K, ION_HEAP(ION_QSECOM_HEAP_ID), 0); |
| 1870 | if (IS_ERR_OR_NULL(qseecom.cmnlib_ion_handle)) { |
Zhen Kong | fd64c98 | 2013-12-19 16:35:43 -0800 | [diff] [blame] | 1871 | pr_err("ION alloc failed\n"); |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1872 | return -ENOMEM; |
| 1873 | } |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1874 | |
| 1875 | img_data = (u8 *)ion_map_kernel(qseecom.ion_clnt, |
| 1876 | qseecom.cmnlib_ion_handle); |
| 1877 | if (IS_ERR_OR_NULL(img_data)) { |
Zhen Kong | fd64c98 | 2013-12-19 16:35:43 -0800 | [diff] [blame] | 1878 | pr_err("ION memory mapping for cmnlib failed\n"); |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1879 | ret = -ENOMEM; |
| 1880 | goto exit_ion_free; |
| 1881 | } |
Hariprasad Dhalinarasimha | a3b9644 | 2013-01-02 10:40:40 -0800 | [diff] [blame] | 1882 | ret = __qseecom_get_fw_data("cmnlib", img_data, &load_req); |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1883 | if (ret) { |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1884 | ret = -EIO; |
| 1885 | goto exit_ion_unmap_kernel; |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1886 | } |
Zhen Kong | fd64c98 | 2013-12-19 16:35:43 -0800 | [diff] [blame] | 1887 | /* Get the physical address of the ION BUF */ |
| 1888 | ret = ion_phys(qseecom.ion_clnt, qseecom.cmnlib_ion_handle, |
| 1889 | &pa, &len); |
| 1890 | load_req.phy_addr = (s32)pa; |
| 1891 | if (ret) { |
| 1892 | pr_err("physical memory retrieval failure\n"); |
| 1893 | ret = -EIO; |
| 1894 | goto exit_ion_unmap_kernel; |
| 1895 | } |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1896 | /* Populate the remaining parameters */ |
| 1897 | load_req.qsee_cmd_id = QSEOS_LOAD_SERV_IMAGE_COMMAND; |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1898 | |
| 1899 | if (qseecom.support_bus_scaling) { |
| 1900 | mutex_lock(&qsee_bw_mutex); |
| 1901 | ret = __qseecom_register_bus_bandwidth_needs(data, MEDIUM); |
| 1902 | mutex_unlock(&qsee_bw_mutex); |
| 1903 | if (ret) { |
| 1904 | ret = -EIO; |
| 1905 | goto exit_ion_unmap_kernel; |
| 1906 | } |
| 1907 | } |
| 1908 | |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 1909 | /* Vote for the SFPB clock */ |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1910 | ret = __qseecom_enable_clk_scale_up(data); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 1911 | if (ret) { |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1912 | ret = -EIO; |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1913 | goto exit_unregister_bus_bw_need; |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 1914 | } |
| 1915 | |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 1916 | __cpuc_flush_dcache_area((void *)img_data, fw_size); |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1917 | /* SCM_CALL to load the image */ |
| 1918 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &load_req, |
| 1919 | sizeof(struct qseecom_load_lib_image_ireq), |
| 1920 | &resp, sizeof(resp)); |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1921 | if (ret) { |
| 1922 | pr_err("scm_call to load failed : ret %d\n", ret); |
| 1923 | ret = -EIO; |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1924 | goto exit_disable_clk_vote; |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1925 | } |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1926 | |
| 1927 | switch (resp.result) { |
| 1928 | case QSEOS_RESULT_SUCCESS: |
| 1929 | break; |
| 1930 | case QSEOS_RESULT_FAILURE: |
| 1931 | pr_err("scm call failed w/response result%d\n", resp.result); |
| 1932 | ret = -EINVAL; |
| 1933 | goto exit_disable_clk_vote; |
| 1934 | case QSEOS_RESULT_INCOMPLETE: |
| 1935 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
| 1936 | if (ret) { |
| 1937 | pr_err("process_incomplete_cmd failed err: %d\n", ret); |
| 1938 | goto exit_disable_clk_vote; |
| 1939 | } |
| 1940 | break; |
| 1941 | default: |
| 1942 | pr_err("scm call return unknown response %d\n", resp.result); |
| 1943 | ret = -EINVAL; |
| 1944 | goto exit_disable_clk_vote; |
| 1945 | } |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 1946 | __qseecom_disable_clk_scale_down(data); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1947 | if (qseecom.support_bus_scaling) { |
| 1948 | mutex_lock(&qsee_bw_mutex); |
| 1949 | qseecom_unregister_bus_bandwidth_needs(data); |
| 1950 | mutex_unlock(&qsee_bw_mutex); |
| 1951 | } |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1952 | return ret; |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1953 | |
| 1954 | exit_disable_clk_vote: |
| 1955 | __qseecom_disable_clk_scale_down(data); |
| 1956 | |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 1957 | exit_unregister_bus_bw_need: |
| 1958 | if (qseecom.support_bus_scaling) { |
| 1959 | mutex_lock(&qsee_bw_mutex); |
| 1960 | qseecom_unregister_bus_bandwidth_needs(data); |
| 1961 | mutex_unlock(&qsee_bw_mutex); |
| 1962 | } |
| 1963 | |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 1964 | exit_ion_unmap_kernel: |
| 1965 | ion_unmap_kernel(qseecom.ion_clnt, qseecom.cmnlib_ion_handle); |
| 1966 | |
| 1967 | exit_ion_free: |
| 1968 | ion_free(qseecom.ion_clnt, qseecom.cmnlib_ion_handle); |
| 1969 | qseecom.cmnlib_ion_handle = NULL; |
| 1970 | return ret; |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | static int qseecom_unload_commonlib_image(void) |
| 1974 | { |
| 1975 | int ret = -EINVAL; |
| 1976 | struct qseecom_unload_lib_image_ireq unload_req = {0}; |
| 1977 | struct qseecom_command_scm_resp resp; |
| 1978 | |
| 1979 | /* Populate the remaining parameters */ |
| 1980 | unload_req.qsee_cmd_id = QSEOS_UNLOAD_SERV_IMAGE_COMMAND; |
| 1981 | /* SCM_CALL to load the image */ |
| 1982 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &unload_req, |
| 1983 | sizeof(struct qseecom_unload_lib_image_ireq), |
| 1984 | &resp, sizeof(resp)); |
| 1985 | if (ret) { |
| 1986 | pr_err("scm_call to unload lib failed : ret %d\n", ret); |
| 1987 | ret = -EIO; |
| 1988 | } else { |
| 1989 | switch (resp.result) { |
| 1990 | case QSEOS_RESULT_SUCCESS: |
| 1991 | break; |
| 1992 | case QSEOS_RESULT_FAILURE: |
| 1993 | pr_err("scm fail resp.result QSEOS_RESULT FAILURE\n"); |
| 1994 | break; |
| 1995 | default: |
| 1996 | pr_err("scm call return unknown response %d\n", |
| 1997 | resp.result); |
| 1998 | ret = -EINVAL; |
| 1999 | break; |
| 2000 | } |
| 2001 | } |
Zhen Kong | c46b584 | 2013-12-12 13:09:16 +0530 | [diff] [blame] | 2002 | |
| 2003 | ion_unmap_kernel(qseecom.ion_clnt, qseecom.cmnlib_ion_handle); |
| 2004 | ion_free(qseecom.ion_clnt, qseecom.cmnlib_ion_handle); |
| 2005 | qseecom.cmnlib_ion_handle = NULL; |
| 2006 | |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 2007 | return ret; |
| 2008 | } |
| 2009 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2010 | int qseecom_start_app(struct qseecom_handle **handle, |
| 2011 | char *app_name, uint32_t size) |
| 2012 | { |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 2013 | int32_t ret = 0; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2014 | unsigned long flags = 0; |
| 2015 | struct qseecom_dev_handle *data = NULL; |
| 2016 | struct qseecom_check_app_ireq app_ireq; |
| 2017 | struct qseecom_registered_app_list *entry = NULL; |
| 2018 | struct qseecom_registered_kclient_list *kclient_entry = NULL; |
| 2019 | bool found_app = false; |
| 2020 | uint32_t len; |
| 2021 | ion_phys_addr_t pa; |
| 2022 | |
Mona Hossain | 823f988 | 2012-11-23 14:42:20 -0800 | [diff] [blame] | 2023 | *handle = kzalloc(sizeof(struct qseecom_handle), GFP_KERNEL); |
| 2024 | if (!(*handle)) { |
| 2025 | pr_err("failed to allocate memory for kernel client handle\n"); |
| 2026 | return -ENOMEM; |
| 2027 | } |
| 2028 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2029 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2030 | if (!data) { |
| 2031 | pr_err("kmalloc failed\n"); |
| 2032 | if (ret == 0) { |
| 2033 | kfree(*handle); |
| 2034 | *handle = NULL; |
| 2035 | } |
| 2036 | return -ENOMEM; |
| 2037 | } |
| 2038 | data->abort = 0; |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 2039 | data->type = QSEECOM_CLIENT_APP; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2040 | data->released = false; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2041 | data->client.sb_length = size; |
| 2042 | data->client.user_virt_sb_base = 0; |
| 2043 | data->client.ihandle = NULL; |
| 2044 | |
| 2045 | init_waitqueue_head(&data->abort_wq); |
| 2046 | atomic_set(&data->ioctl_count, 0); |
| 2047 | |
| 2048 | data->client.ihandle = ion_alloc(qseecom.ion_clnt, size, 4096, |
| 2049 | ION_HEAP(ION_QSECOM_HEAP_ID), 0); |
| 2050 | if (IS_ERR_OR_NULL(data->client.ihandle)) { |
| 2051 | pr_err("Ion client could not retrieve the handle\n"); |
| 2052 | kfree(data); |
| 2053 | kfree(*handle); |
| 2054 | *handle = NULL; |
| 2055 | return -EINVAL; |
| 2056 | } |
Mona Hossain | b2dc0f8 | 2013-05-22 09:26:50 -0700 | [diff] [blame] | 2057 | mutex_lock(&app_access_lock); |
Mona Hossain | 9498f5e | 2013-01-23 18:08:45 -0800 | [diff] [blame] | 2058 | if (qseecom.qsee_version > QSEEE_VERSION_00) { |
Mona Hossain | 9498f5e | 2013-01-23 18:08:45 -0800 | [diff] [blame] | 2059 | if (qseecom.commonlib_loaded == false) { |
| 2060 | ret = qseecom_load_commonlib_image(data); |
| 2061 | if (ret == 0) |
| 2062 | qseecom.commonlib_loaded = true; |
| 2063 | } |
Mona Hossain | 9498f5e | 2013-01-23 18:08:45 -0800 | [diff] [blame] | 2064 | } |
Mona Hossain | 9498f5e | 2013-01-23 18:08:45 -0800 | [diff] [blame] | 2065 | if (ret) { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2066 | pr_err("Failed to load commonlib image\n"); |
Mona Hossain | b2dc0f8 | 2013-05-22 09:26:50 -0700 | [diff] [blame] | 2067 | ret = -EIO; |
| 2068 | goto err; |
Mona Hossain | 9498f5e | 2013-01-23 18:08:45 -0800 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | app_ireq.qsee_cmd_id = QSEOS_APP_LOOKUP_COMMAND; |
| 2072 | memcpy(app_ireq.app_name, app_name, MAX_APP_NAME_SIZE); |
| 2073 | ret = __qseecom_check_app_exists(app_ireq); |
Mona Hossain | b2dc0f8 | 2013-05-22 09:26:50 -0700 | [diff] [blame] | 2074 | if (ret < 0) |
| 2075 | goto err; |
| 2076 | |
Hariprasad Dhalinarasimha | efecbfd | 2013-04-10 15:13:03 -0700 | [diff] [blame] | 2077 | data->client.app_id = ret; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2078 | if (ret > 0) { |
| 2079 | pr_warn("App id %d for [%s] app exists\n", ret, |
| 2080 | (char *)app_ireq.app_name); |
| 2081 | spin_lock_irqsave(&qseecom.registered_app_list_lock, flags); |
| 2082 | list_for_each_entry(entry, |
| 2083 | &qseecom.registered_app_list_head, list){ |
| 2084 | if (entry->app_id == ret) { |
| 2085 | entry->ref_cnt++; |
| 2086 | found_app = true; |
| 2087 | break; |
| 2088 | } |
| 2089 | } |
| 2090 | spin_unlock_irqrestore( |
| 2091 | &qseecom.registered_app_list_lock, flags); |
| 2092 | if (!found_app) |
| 2093 | pr_warn("App_id %d [%s] was loaded but not registered\n", |
| 2094 | ret, (char *)app_ireq.app_name); |
| 2095 | } else { |
| 2096 | /* load the app and get the app_id */ |
| 2097 | pr_debug("%s: Loading app for the first time'\n", |
| 2098 | qseecom.pdev->init_name); |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2099 | ret = __qseecom_load_fw(data, app_name); |
Mona Hossain | b2dc0f8 | 2013-05-22 09:26:50 -0700 | [diff] [blame] | 2100 | if (ret < 0) |
| 2101 | goto err; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2102 | data->client.app_id = ret; |
| 2103 | } |
| 2104 | if (!found_app) { |
| 2105 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
| 2106 | if (!entry) { |
Mona Hossain | b2dc0f8 | 2013-05-22 09:26:50 -0700 | [diff] [blame] | 2107 | pr_err("kmalloc for app entry failed\n"); |
| 2108 | ret = -ENOMEM; |
| 2109 | goto err; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2110 | } |
| 2111 | entry->app_id = ret; |
| 2112 | entry->ref_cnt = 1; |
| 2113 | |
| 2114 | spin_lock_irqsave(&qseecom.registered_app_list_lock, flags); |
| 2115 | list_add_tail(&entry->list, &qseecom.registered_app_list_head); |
| 2116 | spin_unlock_irqrestore(&qseecom.registered_app_list_lock, |
| 2117 | flags); |
| 2118 | } |
| 2119 | |
| 2120 | /* Get the physical address of the ION BUF */ |
| 2121 | ret = ion_phys(qseecom.ion_clnt, data->client.ihandle, &pa, &len); |
Zhen Kong | 05ed446 | 2014-01-28 18:21:30 -0800 | [diff] [blame] | 2122 | if (ret) { |
| 2123 | pr_err("Cannot get phys_addr for the Ion Client, ret = %d\n", |
| 2124 | ret); |
| 2125 | goto err; |
| 2126 | } |
| 2127 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2128 | /* Populate the structure for sending scm call to load image */ |
| 2129 | data->client.sb_virt = (char *) ion_map_kernel(qseecom.ion_clnt, |
| 2130 | data->client.ihandle); |
Hariprasad Dhalinarasimha | acfb09c | 2013-01-10 13:16:15 -0800 | [diff] [blame] | 2131 | data->client.user_virt_sb_base = (uint32_t)data->client.sb_virt; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2132 | data->client.sb_phys = pa; |
| 2133 | (*handle)->dev = (void *)data; |
| 2134 | (*handle)->sbuf = (unsigned char *)data->client.sb_virt; |
| 2135 | (*handle)->sbuf_len = data->client.sb_length; |
| 2136 | |
| 2137 | kclient_entry = kzalloc(sizeof(*kclient_entry), GFP_KERNEL); |
| 2138 | if (!kclient_entry) { |
| 2139 | pr_err("kmalloc failed\n"); |
Mona Hossain | b2dc0f8 | 2013-05-22 09:26:50 -0700 | [diff] [blame] | 2140 | ret = -ENOMEM; |
| 2141 | goto err; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2142 | } |
| 2143 | kclient_entry->handle = *handle; |
| 2144 | |
| 2145 | spin_lock_irqsave(&qseecom.registered_kclient_list_lock, flags); |
| 2146 | list_add_tail(&kclient_entry->list, |
| 2147 | &qseecom.registered_kclient_list_head); |
| 2148 | spin_unlock_irqrestore(&qseecom.registered_kclient_list_lock, flags); |
| 2149 | |
Mona Hossain | b2dc0f8 | 2013-05-22 09:26:50 -0700 | [diff] [blame] | 2150 | mutex_unlock(&app_access_lock); |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2151 | return 0; |
Mona Hossain | b2dc0f8 | 2013-05-22 09:26:50 -0700 | [diff] [blame] | 2152 | |
| 2153 | err: |
| 2154 | kfree(data); |
| 2155 | kfree(*handle); |
| 2156 | *handle = NULL; |
| 2157 | mutex_unlock(&app_access_lock); |
| 2158 | return ret; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2159 | } |
| 2160 | EXPORT_SYMBOL(qseecom_start_app); |
| 2161 | |
| 2162 | int qseecom_shutdown_app(struct qseecom_handle **handle) |
| 2163 | { |
| 2164 | int ret = -EINVAL; |
Mona Hossain | 3382402 | 2013-02-25 09:32:33 -0800 | [diff] [blame] | 2165 | struct qseecom_dev_handle *data; |
| 2166 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2167 | struct qseecom_registered_kclient_list *kclient = NULL; |
| 2168 | unsigned long flags = 0; |
| 2169 | bool found_handle = false; |
| 2170 | |
Mona Hossain | 3382402 | 2013-02-25 09:32:33 -0800 | [diff] [blame] | 2171 | if ((handle == NULL) || (*handle == NULL)) { |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2172 | pr_err("Handle is not initialized\n"); |
| 2173 | return -EINVAL; |
| 2174 | } |
Mona Hossain | 3382402 | 2013-02-25 09:32:33 -0800 | [diff] [blame] | 2175 | data = (struct qseecom_dev_handle *) ((*handle)->dev); |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2176 | spin_lock_irqsave(&qseecom.registered_kclient_list_lock, flags); |
| 2177 | list_for_each_entry(kclient, &qseecom.registered_kclient_list_head, |
| 2178 | list) { |
| 2179 | if (kclient->handle == (*handle)) { |
| 2180 | list_del(&kclient->list); |
| 2181 | found_handle = true; |
| 2182 | break; |
| 2183 | } |
| 2184 | } |
| 2185 | spin_unlock_irqrestore(&qseecom.registered_kclient_list_lock, flags); |
| 2186 | if (!found_handle) |
| 2187 | pr_err("Unable to find the handle, exiting\n"); |
| 2188 | else |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 2189 | ret = qseecom_unload_app(data, false); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 2190 | |
| 2191 | if (qseecom.support_bus_scaling) { |
| 2192 | mutex_lock(&qsee_bw_mutex); |
| 2193 | if (data->mode != INACTIVE) { |
| 2194 | qseecom_unregister_bus_bandwidth_needs(data); |
| 2195 | if (qseecom.cumulative_mode == INACTIVE) { |
| 2196 | ret = __qseecom_set_msm_bus_request(INACTIVE); |
| 2197 | if (ret) |
| 2198 | pr_err("Fail to scale down bus\n"); |
| 2199 | } |
| 2200 | } |
| 2201 | mutex_unlock(&qsee_bw_mutex); |
| 2202 | } else { |
| 2203 | if (data->fast_load_enabled == true) |
| 2204 | qsee_disable_clock_vote(data, CLK_SFPB); |
| 2205 | if (data->perf_enabled == true) |
| 2206 | qsee_disable_clock_vote(data, CLK_DFAB); |
| 2207 | } |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2208 | if (ret == 0) { |
| 2209 | kzfree(data); |
| 2210 | kzfree(*handle); |
| 2211 | kzfree(kclient); |
| 2212 | *handle = NULL; |
| 2213 | } |
| 2214 | return ret; |
| 2215 | } |
| 2216 | EXPORT_SYMBOL(qseecom_shutdown_app); |
| 2217 | |
| 2218 | int qseecom_send_command(struct qseecom_handle *handle, void *send_buf, |
| 2219 | uint32_t sbuf_len, void *resp_buf, uint32_t rbuf_len) |
| 2220 | { |
| 2221 | int ret = 0; |
| 2222 | struct qseecom_send_cmd_req req = {0, 0, 0, 0}; |
| 2223 | struct qseecom_dev_handle *data; |
| 2224 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2225 | if (handle == NULL) { |
| 2226 | pr_err("Handle is not initialized\n"); |
| 2227 | return -EINVAL; |
| 2228 | } |
| 2229 | data = handle->dev; |
| 2230 | |
| 2231 | req.cmd_req_len = sbuf_len; |
| 2232 | req.resp_len = rbuf_len; |
| 2233 | req.cmd_req_buf = send_buf; |
| 2234 | req.resp_buf = resp_buf; |
| 2235 | |
| 2236 | mutex_lock(&app_access_lock); |
| 2237 | atomic_inc(&data->ioctl_count); |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 2238 | if (qseecom.support_bus_scaling) { |
| 2239 | ret = qseecom_scale_bus_bandwidth_timer(INACTIVE); |
| 2240 | if (ret) { |
| 2241 | pr_err("Failed to set bw.\n"); |
| 2242 | atomic_dec(&data->ioctl_count); |
| 2243 | mutex_unlock(&app_access_lock); |
| 2244 | return ret; |
| 2245 | } |
| 2246 | } |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2247 | ret = __qseecom_send_cmd(data, &req); |
Zhen Kong | af95019 | 2014-02-05 17:36:23 -0800 | [diff] [blame] | 2248 | if (qseecom.support_bus_scaling) |
| 2249 | __qseecom_add_bw_scale_down_timer( |
| 2250 | QSEECOM_SEND_CMD_CRYPTO_TIMEOUT); |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 2251 | |
| 2252 | atomic_dec(&data->ioctl_count); |
| 2253 | mutex_unlock(&app_access_lock); |
| 2254 | |
| 2255 | if (ret) |
| 2256 | return ret; |
| 2257 | |
| 2258 | pr_debug("sending cmd_req->rsp size: %u, ptr: 0x%p\n", |
| 2259 | req.resp_len, req.resp_buf); |
| 2260 | return ret; |
| 2261 | } |
| 2262 | EXPORT_SYMBOL(qseecom_send_command); |
| 2263 | |
Mona Hossain | 91a8fc9 | 2012-11-07 19:58:30 -0800 | [diff] [blame] | 2264 | int qseecom_set_bandwidth(struct qseecom_handle *handle, bool high) |
| 2265 | { |
Mona Hossain | fca6f42 | 2013-01-12 13:00:35 -0800 | [diff] [blame] | 2266 | int ret = 0; |
Mona Hossain | 91a8fc9 | 2012-11-07 19:58:30 -0800 | [diff] [blame] | 2267 | if ((handle == NULL) || (handle->dev == NULL)) { |
| 2268 | pr_err("No valid kernel client\n"); |
| 2269 | return -EINVAL; |
| 2270 | } |
Mona Hossain | fca6f42 | 2013-01-12 13:00:35 -0800 | [diff] [blame] | 2271 | if (high) { |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 2272 | if (qseecom.support_bus_scaling) { |
| 2273 | mutex_lock(&qsee_bw_mutex); |
| 2274 | __qseecom_register_bus_bandwidth_needs(handle->dev, |
| 2275 | HIGH); |
| 2276 | mutex_unlock(&qsee_bw_mutex); |
| 2277 | if (ret) |
| 2278 | pr_err("Failed to scale bus (med) %d\n", ret); |
| 2279 | } else { |
| 2280 | ret = qsee_vote_for_clock(handle->dev, CLK_DFAB); |
| 2281 | if (ret) |
| 2282 | pr_err("Failed to vote for DFAB clock%d\n", |
| 2283 | ret); |
| 2284 | ret = qsee_vote_for_clock(handle->dev, CLK_SFPB); |
| 2285 | if (ret) { |
| 2286 | pr_err("Failed to vote for SFPB clock%d\n", |
| 2287 | ret); |
| 2288 | qsee_disable_clock_vote(handle->dev, CLK_DFAB); |
| 2289 | } |
Mona Hossain | fca6f42 | 2013-01-12 13:00:35 -0800 | [diff] [blame] | 2290 | } |
| 2291 | } else { |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 2292 | if (!qseecom.support_bus_scaling) { |
| 2293 | qsee_disable_clock_vote(handle->dev, CLK_DFAB); |
| 2294 | qsee_disable_clock_vote(handle->dev, CLK_SFPB); |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 2295 | } else { |
| 2296 | mutex_lock(&qsee_bw_mutex); |
| 2297 | qseecom_unregister_bus_bandwidth_needs(handle->dev); |
| 2298 | mutex_unlock(&qsee_bw_mutex); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 2299 | } |
Mona Hossain | 91a8fc9 | 2012-11-07 19:58:30 -0800 | [diff] [blame] | 2300 | } |
Mona Hossain | fca6f42 | 2013-01-12 13:00:35 -0800 | [diff] [blame] | 2301 | return ret; |
Mona Hossain | 91a8fc9 | 2012-11-07 19:58:30 -0800 | [diff] [blame] | 2302 | } |
| 2303 | EXPORT_SYMBOL(qseecom_set_bandwidth); |
| 2304 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2305 | static int qseecom_send_resp(void) |
| 2306 | { |
| 2307 | qseecom.send_resp_flag = 1; |
| 2308 | wake_up_interruptible(&qseecom.send_resp_wq); |
| 2309 | return 0; |
| 2310 | } |
| 2311 | |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 2312 | |
| 2313 | static int qseecom_send_modfd_resp(struct qseecom_dev_handle *data, |
| 2314 | void __user *argp) |
| 2315 | { |
| 2316 | struct qseecom_send_modfd_listener_resp resp; |
Mona Hossain | dddf444 | 2013-10-01 14:08:20 -0700 | [diff] [blame] | 2317 | int i; |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 2318 | struct qseecom_registered_listener_list *this_lstnr = NULL; |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 2319 | |
| 2320 | if (copy_from_user(&resp, argp, sizeof(resp))) { |
| 2321 | pr_err("copy_from_user failed"); |
| 2322 | return -EINVAL; |
| 2323 | } |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 2324 | this_lstnr = __qseecom_find_svc(data->listener.id); |
| 2325 | if (this_lstnr == NULL) |
| 2326 | return -EINVAL; |
| 2327 | |
| 2328 | if (resp.resp_buf_ptr == NULL) { |
| 2329 | pr_err("Invalid resp_buf_ptr\n"); |
| 2330 | return -EINVAL; |
| 2331 | } |
Mona Hossain | dddf444 | 2013-10-01 14:08:20 -0700 | [diff] [blame] | 2332 | /* validate offsets */ |
| 2333 | for (i = 0; i < MAX_ION_FD; i++) { |
| 2334 | if (resp.ifd_data[i].cmd_buf_offset >= resp.resp_len) { |
| 2335 | pr_err("Invalid offset %d = 0x%x\n", |
| 2336 | i, resp.ifd_data[i].cmd_buf_offset); |
| 2337 | return -EINVAL; |
| 2338 | } |
| 2339 | } |
Zhen Kong | f494819 | 2013-11-25 13:05:35 -0800 | [diff] [blame] | 2340 | |
| 2341 | if (((uint32_t)resp.resp_buf_ptr < |
| 2342 | this_lstnr->user_virt_sb_base) |
| 2343 | || ((uint32_t)resp.resp_buf_ptr >= |
| 2344 | (this_lstnr->user_virt_sb_base + |
| 2345 | this_lstnr->sb_length))) { |
| 2346 | pr_err("resp_buf_ptr address not within shared buffer\n"); |
| 2347 | return -EINVAL; |
| 2348 | } |
| 2349 | resp.resp_buf_ptr = (uint32_t)this_lstnr->sb_virt + |
| 2350 | (resp.resp_buf_ptr - this_lstnr->user_virt_sb_base); |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 2351 | __qseecom_update_cmd_buf(&resp, false, data, true); |
| 2352 | qseecom.send_resp_flag = 1; |
| 2353 | wake_up_interruptible(&qseecom.send_resp_wq); |
| 2354 | return 0; |
| 2355 | } |
| 2356 | |
| 2357 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2358 | static int qseecom_get_qseos_version(struct qseecom_dev_handle *data, |
| 2359 | void __user *argp) |
| 2360 | { |
| 2361 | struct qseecom_qseos_version_req req; |
| 2362 | |
| 2363 | if (copy_from_user(&req, argp, sizeof(req))) { |
| 2364 | pr_err("copy_from_user failed"); |
| 2365 | return -EINVAL; |
| 2366 | } |
| 2367 | req.qseos_version = qseecom.qseos_version; |
| 2368 | if (copy_to_user(argp, &req, sizeof(req))) { |
| 2369 | pr_err("copy_to_user failed"); |
| 2370 | return -EINVAL; |
| 2371 | } |
| 2372 | return 0; |
| 2373 | } |
| 2374 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2375 | static int __qseecom_enable_clk(enum qseecom_ce_hw_instance ce) |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2376 | { |
| 2377 | int rc = 0; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2378 | struct qseecom_clk *qclk; |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2379 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2380 | if (ce == CLK_QSEE) |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2381 | qclk = &qseecom.qsee; |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2382 | else |
| 2383 | qclk = &qseecom.ce_drv; |
| 2384 | |
| 2385 | mutex_lock(&clk_access_lock); |
Zhen Kong | 1f09c769 | 2013-05-03 17:50:32 -0700 | [diff] [blame] | 2386 | |
| 2387 | if (qclk->clk_access_cnt == ULONG_MAX) |
| 2388 | goto err; |
| 2389 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2390 | if (qclk->clk_access_cnt > 0) { |
| 2391 | qclk->clk_access_cnt++; |
| 2392 | mutex_unlock(&clk_access_lock); |
| 2393 | return rc; |
| 2394 | } |
| 2395 | |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2396 | /* Enable CE core clk */ |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2397 | rc = clk_prepare_enable(qclk->ce_core_clk); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2398 | if (rc) { |
| 2399 | pr_err("Unable to enable/prepare CE core clk\n"); |
| 2400 | goto err; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2401 | } |
| 2402 | /* Enable CE clk */ |
| 2403 | rc = clk_prepare_enable(qclk->ce_clk); |
| 2404 | if (rc) { |
| 2405 | pr_err("Unable to enable/prepare CE iface clk\n"); |
| 2406 | goto ce_clk_err; |
| 2407 | } |
| 2408 | /* Enable AXI clk */ |
| 2409 | rc = clk_prepare_enable(qclk->ce_bus_clk); |
| 2410 | if (rc) { |
| 2411 | pr_err("Unable to enable/prepare CE bus clk\n"); |
| 2412 | goto ce_bus_clk_err; |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2413 | } |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2414 | qclk->clk_access_cnt++; |
| 2415 | mutex_unlock(&clk_access_lock); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2416 | return 0; |
| 2417 | |
| 2418 | ce_bus_clk_err: |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2419 | clk_disable_unprepare(qclk->ce_clk); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2420 | ce_clk_err: |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2421 | clk_disable_unprepare(qclk->ce_core_clk); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2422 | err: |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2423 | mutex_unlock(&clk_access_lock); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2424 | return -EIO; |
| 2425 | } |
| 2426 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2427 | static void __qseecom_disable_clk(enum qseecom_ce_hw_instance ce) |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2428 | { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2429 | struct qseecom_clk *qclk; |
| 2430 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2431 | if (ce == CLK_QSEE) |
| 2432 | qclk = &qseecom.qsee; |
| 2433 | else |
| 2434 | qclk = &qseecom.ce_drv; |
| 2435 | |
| 2436 | mutex_lock(&clk_access_lock); |
Zhen Kong | 1f09c769 | 2013-05-03 17:50:32 -0700 | [diff] [blame] | 2437 | |
| 2438 | if (qclk->clk_access_cnt == 0) { |
| 2439 | mutex_unlock(&clk_access_lock); |
| 2440 | return; |
| 2441 | } |
| 2442 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2443 | if (qclk->clk_access_cnt == 1) { |
| 2444 | if (qclk->ce_clk != NULL) |
| 2445 | clk_disable_unprepare(qclk->ce_clk); |
| 2446 | if (qclk->ce_core_clk != NULL) |
| 2447 | clk_disable_unprepare(qclk->ce_core_clk); |
| 2448 | if (qclk->ce_bus_clk != NULL) |
| 2449 | clk_disable_unprepare(qclk->ce_bus_clk); |
| 2450 | } |
| 2451 | qclk->clk_access_cnt--; |
| 2452 | mutex_unlock(&clk_access_lock); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2453 | } |
| 2454 | |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2455 | static int qsee_vote_for_clock(struct qseecom_dev_handle *data, |
| 2456 | int32_t clk_type) |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2457 | { |
| 2458 | int ret = 0; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2459 | struct qseecom_clk *qclk; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2460 | |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2461 | qclk = &qseecom.qsee; |
| 2462 | if (!qseecom.qsee_perf_client) |
Ramesh Masavarapu | e640e84 | 2012-04-03 11:21:54 -0700 | [diff] [blame] | 2463 | return ret; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2464 | |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2465 | switch (clk_type) { |
| 2466 | case CLK_DFAB: |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2467 | mutex_lock(&qsee_bw_mutex); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2468 | if (!qseecom.qsee_bw_count) { |
| 2469 | if (qseecom.qsee_sfpb_bw_count > 0) |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2470 | ret = msm_bus_scale_client_update_request( |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2471 | qseecom.qsee_perf_client, 3); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 2472 | else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2473 | if (qclk->ce_core_src_clk != NULL) |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2474 | ret = __qseecom_enable_clk(CLK_QSEE); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2475 | if (!ret) { |
| 2476 | ret = |
| 2477 | msm_bus_scale_client_update_request( |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2478 | qseecom.qsee_perf_client, 1); |
| 2479 | if ((ret) && |
| 2480 | (qclk->ce_core_src_clk != NULL)) |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2481 | __qseecom_disable_clk(CLK_QSEE); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2482 | } |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 2483 | } |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2484 | if (ret) |
| 2485 | pr_err("DFAB Bandwidth req failed (%d)\n", |
| 2486 | ret); |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2487 | else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2488 | qseecom.qsee_bw_count++; |
Mona Hossain | c9c83c7 | 2013-04-11 12:43:48 -0700 | [diff] [blame] | 2489 | data->perf_enabled = true; |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2490 | } |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2491 | } else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2492 | qseecom.qsee_bw_count++; |
Mona Hossain | c9c83c7 | 2013-04-11 12:43:48 -0700 | [diff] [blame] | 2493 | data->perf_enabled = true; |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2494 | } |
| 2495 | mutex_unlock(&qsee_bw_mutex); |
| 2496 | break; |
| 2497 | case CLK_SFPB: |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2498 | mutex_lock(&qsee_bw_mutex); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2499 | if (!qseecom.qsee_sfpb_bw_count) { |
| 2500 | if (qseecom.qsee_bw_count > 0) |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2501 | ret = msm_bus_scale_client_update_request( |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2502 | qseecom.qsee_perf_client, 3); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 2503 | else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2504 | if (qclk->ce_core_src_clk != NULL) |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2505 | ret = __qseecom_enable_clk(CLK_QSEE); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2506 | if (!ret) { |
| 2507 | ret = |
| 2508 | msm_bus_scale_client_update_request( |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2509 | qseecom.qsee_perf_client, 2); |
| 2510 | if ((ret) && |
| 2511 | (qclk->ce_core_src_clk != NULL)) |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2512 | __qseecom_disable_clk(CLK_QSEE); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2513 | } |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 2514 | } |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2515 | |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2516 | if (ret) |
| 2517 | pr_err("SFPB Bandwidth req failed (%d)\n", |
| 2518 | ret); |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2519 | else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2520 | qseecom.qsee_sfpb_bw_count++; |
Mona Hossain | c9c83c7 | 2013-04-11 12:43:48 -0700 | [diff] [blame] | 2521 | data->fast_load_enabled = true; |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2522 | } |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2523 | } else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2524 | qseecom.qsee_sfpb_bw_count++; |
Mona Hossain | c9c83c7 | 2013-04-11 12:43:48 -0700 | [diff] [blame] | 2525 | data->fast_load_enabled = true; |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2526 | } |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2527 | mutex_unlock(&qsee_bw_mutex); |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2528 | break; |
| 2529 | default: |
| 2530 | pr_err("Clock type not defined\n"); |
| 2531 | break; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2532 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2533 | return ret; |
| 2534 | } |
| 2535 | |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2536 | static void qsee_disable_clock_vote(struct qseecom_dev_handle *data, |
| 2537 | int32_t clk_type) |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2538 | { |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2539 | int32_t ret = 0; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2540 | struct qseecom_clk *qclk; |
Ramesh Masavarapu | a1bc0e4 | 2012-03-05 07:42:48 -0800 | [diff] [blame] | 2541 | |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2542 | qclk = &qseecom.qsee; |
| 2543 | if (!qseecom.qsee_perf_client) |
Ramesh Masavarapu | a1bc0e4 | 2012-03-05 07:42:48 -0800 | [diff] [blame] | 2544 | return; |
| 2545 | |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2546 | switch (clk_type) { |
| 2547 | case CLK_DFAB: |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2548 | mutex_lock(&qsee_bw_mutex); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2549 | if (qseecom.qsee_bw_count == 0) { |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2550 | pr_err("Client error.Extra call to disable DFAB clk\n"); |
| 2551 | mutex_unlock(&qsee_bw_mutex); |
| 2552 | return; |
| 2553 | } |
| 2554 | |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2555 | if (qseecom.qsee_bw_count == 1) { |
| 2556 | if (qseecom.qsee_sfpb_bw_count > 0) |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2557 | ret = msm_bus_scale_client_update_request( |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2558 | qseecom.qsee_perf_client, 2); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 2559 | else { |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2560 | ret = msm_bus_scale_client_update_request( |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2561 | qseecom.qsee_perf_client, 0); |
| 2562 | if ((!ret) && (qclk->ce_core_src_clk != NULL)) |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2563 | __qseecom_disable_clk(CLK_QSEE); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 2564 | } |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2565 | if (ret) |
| 2566 | pr_err("SFPB Bandwidth req fail (%d)\n", |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2567 | ret); |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2568 | else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2569 | qseecom.qsee_bw_count--; |
Mona Hossain | c9c83c7 | 2013-04-11 12:43:48 -0700 | [diff] [blame] | 2570 | data->perf_enabled = false; |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2571 | } |
| 2572 | } else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2573 | qseecom.qsee_bw_count--; |
Mona Hossain | c9c83c7 | 2013-04-11 12:43:48 -0700 | [diff] [blame] | 2574 | data->perf_enabled = false; |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2575 | } |
| 2576 | mutex_unlock(&qsee_bw_mutex); |
| 2577 | break; |
| 2578 | case CLK_SFPB: |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2579 | mutex_lock(&qsee_bw_mutex); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2580 | if (qseecom.qsee_sfpb_bw_count == 0) { |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2581 | pr_err("Client error.Extra call to disable SFPB clk\n"); |
| 2582 | mutex_unlock(&qsee_bw_mutex); |
| 2583 | return; |
| 2584 | } |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2585 | if (qseecom.qsee_sfpb_bw_count == 1) { |
| 2586 | if (qseecom.qsee_bw_count > 0) |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2587 | ret = msm_bus_scale_client_update_request( |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2588 | qseecom.qsee_perf_client, 1); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 2589 | else { |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2590 | ret = msm_bus_scale_client_update_request( |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2591 | qseecom.qsee_perf_client, 0); |
| 2592 | if ((!ret) && (qclk->ce_core_src_clk != NULL)) |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2593 | __qseecom_disable_clk(CLK_QSEE); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 2594 | } |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2595 | if (ret) |
| 2596 | pr_err("SFPB Bandwidth req fail (%d)\n", |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2597 | ret); |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2598 | else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2599 | qseecom.qsee_sfpb_bw_count--; |
Mona Hossain | c9c83c7 | 2013-04-11 12:43:48 -0700 | [diff] [blame] | 2600 | data->fast_load_enabled = false; |
Mona Hossain | 04d3fac | 2012-12-03 10:10:37 -0800 | [diff] [blame] | 2601 | } |
| 2602 | } else { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 2603 | qseecom.qsee_sfpb_bw_count--; |
Mona Hossain | c9c83c7 | 2013-04-11 12:43:48 -0700 | [diff] [blame] | 2604 | data->fast_load_enabled = false; |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2605 | } |
Ramesh Masavarapu | 8d75658 | 2012-10-03 10:18:06 -0700 | [diff] [blame] | 2606 | mutex_unlock(&qsee_bw_mutex); |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 2607 | break; |
| 2608 | default: |
| 2609 | pr_err("Clock type not defined\n"); |
| 2610 | break; |
Ramesh Masavarapu | e640e84 | 2012-04-03 11:21:54 -0700 | [diff] [blame] | 2611 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2612 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2613 | } |
| 2614 | |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2615 | static int qseecom_load_external_elf(struct qseecom_dev_handle *data, |
| 2616 | void __user *argp) |
| 2617 | { |
| 2618 | struct ion_handle *ihandle; /* Ion handle */ |
| 2619 | struct qseecom_load_img_req load_img_req; |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2620 | int ret; |
| 2621 | int set_cpu_ret = 0; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2622 | ion_phys_addr_t pa = 0; |
| 2623 | uint32_t len; |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2624 | struct cpumask mask; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2625 | struct qseecom_load_app_ireq load_req; |
| 2626 | struct qseecom_command_scm_resp resp; |
| 2627 | |
| 2628 | /* Copy the relevant information needed for loading the image */ |
Hariprasad Dhalinarasimha | e201495 | 2013-10-01 18:25:21 -0700 | [diff] [blame] | 2629 | if (copy_from_user(&load_img_req, |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2630 | (void __user *)argp, |
| 2631 | sizeof(struct qseecom_load_img_req))) { |
| 2632 | pr_err("copy_from_user failed\n"); |
| 2633 | return -EFAULT; |
| 2634 | } |
| 2635 | |
| 2636 | /* Get the handle of the shared fd */ |
Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 2637 | ihandle = ion_import_dma_buf(qseecom.ion_clnt, |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2638 | load_img_req.ifd_data_fd); |
| 2639 | if (IS_ERR_OR_NULL(ihandle)) { |
| 2640 | pr_err("Ion client could not retrieve the handle\n"); |
| 2641 | return -ENOMEM; |
| 2642 | } |
| 2643 | |
| 2644 | /* Get the physical address of the ION BUF */ |
| 2645 | ret = ion_phys(qseecom.ion_clnt, ihandle, &pa, &len); |
Zhen Kong | 05ed446 | 2014-01-28 18:21:30 -0800 | [diff] [blame] | 2646 | if (ret) { |
| 2647 | pr_err("Cannot get phys_addr for the Ion Client, ret = %d\n", |
| 2648 | ret); |
| 2649 | return ret; |
| 2650 | } |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2651 | /* Populate the structure for sending scm call to load image */ |
| 2652 | load_req.qsee_cmd_id = QSEOS_LOAD_EXTERNAL_ELF_COMMAND; |
| 2653 | load_req.mdt_len = load_img_req.mdt_len; |
| 2654 | load_req.img_len = load_img_req.img_len; |
| 2655 | load_req.phy_addr = pa; |
| 2656 | |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2657 | /* SCM_CALL tied to Core0 */ |
| 2658 | mask = CPU_MASK_CPU0; |
| 2659 | set_cpu_ret = set_cpus_allowed_ptr(current, &mask); |
| 2660 | if (set_cpu_ret) { |
| 2661 | pr_err("set_cpus_allowed_ptr failed : ret %d\n", |
| 2662 | set_cpu_ret); |
| 2663 | ret = -EFAULT; |
AnilKumar Chimata | c470bc9 | 2013-06-12 13:08:37 +0530 | [diff] [blame] | 2664 | goto exit_ion_free; |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2665 | } |
AnilKumar Chimata | c470bc9 | 2013-06-12 13:08:37 +0530 | [diff] [blame] | 2666 | |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 2667 | if (qseecom.support_bus_scaling) { |
| 2668 | mutex_lock(&qsee_bw_mutex); |
| 2669 | ret = __qseecom_register_bus_bandwidth_needs(data, MEDIUM); |
| 2670 | mutex_unlock(&qsee_bw_mutex); |
| 2671 | if (ret) { |
| 2672 | ret = -EIO; |
| 2673 | goto exit_cpu_restore; |
| 2674 | } |
| 2675 | } |
| 2676 | |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2677 | /* Vote for the SFPB clock */ |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 2678 | ret = __qseecom_enable_clk_scale_up(data); |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2679 | if (ret) { |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2680 | ret = -EIO; |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 2681 | goto exit_register_bus_bandwidth_needs; |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 2682 | } |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 2683 | msm_ion_do_cache_op(qseecom.ion_clnt, ihandle, NULL, len, |
| 2684 | ION_IOC_CLEAN_INV_CACHES); |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2685 | /* SCM_CALL to load the external elf */ |
| 2686 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &load_req, |
| 2687 | sizeof(struct qseecom_load_app_ireq), |
| 2688 | &resp, sizeof(resp)); |
| 2689 | if (ret) { |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2690 | pr_err("scm_call to load failed : ret %d\n", |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2691 | ret); |
| 2692 | ret = -EFAULT; |
AnilKumar Chimata | c470bc9 | 2013-06-12 13:08:37 +0530 | [diff] [blame] | 2693 | goto exit_disable_clock; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
AnilKumar Chimata | c470bc9 | 2013-06-12 13:08:37 +0530 | [diff] [blame] | 2696 | switch (resp.result) { |
| 2697 | case QSEOS_RESULT_SUCCESS: |
| 2698 | break; |
| 2699 | case QSEOS_RESULT_INCOMPLETE: |
| 2700 | pr_err("%s: qseos result incomplete\n", __func__); |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2701 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
| 2702 | if (ret) |
AnilKumar Chimata | c470bc9 | 2013-06-12 13:08:37 +0530 | [diff] [blame] | 2703 | pr_err("process_incomplete_cmd failed: err: %d\n", ret); |
| 2704 | break; |
| 2705 | case QSEOS_RESULT_FAILURE: |
| 2706 | pr_err("scm_call rsp.result is QSEOS_RESULT_FAILURE\n"); |
| 2707 | ret = -EFAULT; |
| 2708 | break; |
| 2709 | default: |
| 2710 | pr_err("scm_call response result %d not supported\n", |
| 2711 | resp.result); |
| 2712 | ret = -EFAULT; |
| 2713 | break; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2714 | } |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2715 | |
AnilKumar Chimata | c470bc9 | 2013-06-12 13:08:37 +0530 | [diff] [blame] | 2716 | exit_disable_clock: |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 2717 | __qseecom_disable_clk_scale_down(data); |
Zhen Kong | 4bead3c | 2014-04-14 15:07:13 -0700 | [diff] [blame] | 2718 | |
| 2719 | exit_register_bus_bandwidth_needs: |
| 2720 | if (qseecom.support_bus_scaling) { |
| 2721 | mutex_lock(&qsee_bw_mutex); |
| 2722 | ret = qseecom_unregister_bus_bandwidth_needs(data); |
| 2723 | mutex_unlock(&qsee_bw_mutex); |
| 2724 | } |
| 2725 | |
AnilKumar Chimata | c470bc9 | 2013-06-12 13:08:37 +0530 | [diff] [blame] | 2726 | exit_cpu_restore: |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2727 | /* Restore the CPU mask */ |
| 2728 | mask = CPU_MASK_ALL; |
| 2729 | set_cpu_ret = set_cpus_allowed_ptr(current, &mask); |
| 2730 | if (set_cpu_ret) { |
| 2731 | pr_err("set_cpus_allowed_ptr failed to restore mask: ret %d\n", |
| 2732 | set_cpu_ret); |
| 2733 | ret = -EFAULT; |
| 2734 | } |
AnilKumar Chimata | c470bc9 | 2013-06-12 13:08:37 +0530 | [diff] [blame] | 2735 | exit_ion_free: |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2736 | /* Deallocate the handle */ |
| 2737 | if (!IS_ERR_OR_NULL(ihandle)) |
| 2738 | ion_free(qseecom.ion_clnt, ihandle); |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2739 | return ret; |
| 2740 | } |
| 2741 | |
| 2742 | static int qseecom_unload_external_elf(struct qseecom_dev_handle *data) |
| 2743 | { |
| 2744 | int ret = 0; |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2745 | int set_cpu_ret = 0; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2746 | struct qseecom_command_scm_resp resp; |
| 2747 | struct qseecom_unload_app_ireq req; |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2748 | struct cpumask mask; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2749 | |
AnilKumar Chimata | f732bbe | 2013-07-24 00:44:09 +0530 | [diff] [blame] | 2750 | /* unavailable client app */ |
| 2751 | data->type = QSEECOM_UNAVAILABLE_CLIENT_APP; |
| 2752 | |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2753 | /* Populate the structure for sending scm call to unload image */ |
| 2754 | req.qsee_cmd_id = QSEOS_UNLOAD_EXTERNAL_ELF_COMMAND; |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2755 | |
| 2756 | /* SCM_CALL tied to Core0 */ |
| 2757 | mask = CPU_MASK_CPU0; |
| 2758 | ret = set_cpus_allowed_ptr(current, &mask); |
| 2759 | if (ret) { |
| 2760 | pr_err("set_cpus_allowed_ptr failed : ret %d\n", |
| 2761 | ret); |
| 2762 | return -EFAULT; |
| 2763 | } |
| 2764 | |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2765 | /* SCM_CALL to unload the external elf */ |
| 2766 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, &req, |
| 2767 | sizeof(struct qseecom_unload_app_ireq), |
| 2768 | &resp, sizeof(resp)); |
| 2769 | if (ret) { |
| 2770 | pr_err("scm_call to unload failed : ret %d\n", |
| 2771 | ret); |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2772 | ret = -EFAULT; |
| 2773 | goto qseecom_unload_external_elf_scm_err; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2774 | } |
| 2775 | if (resp.result == QSEOS_RESULT_INCOMPLETE) { |
| 2776 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
| 2777 | if (ret) |
| 2778 | pr_err("process_incomplete_cmd fail err: %d\n", |
| 2779 | ret); |
| 2780 | } else { |
| 2781 | if (resp.result != QSEOS_RESULT_SUCCESS) { |
| 2782 | pr_err("scm_call to unload image failed resp.result =%d\n", |
| 2783 | resp.result); |
| 2784 | ret = -EFAULT; |
| 2785 | } |
| 2786 | } |
Ramesh Masavarapu | 41af8ab | 2012-05-21 11:08:00 -0700 | [diff] [blame] | 2787 | |
| 2788 | qseecom_unload_external_elf_scm_err: |
| 2789 | /* Restore the CPU mask */ |
| 2790 | mask = CPU_MASK_ALL; |
| 2791 | set_cpu_ret = set_cpus_allowed_ptr(current, &mask); |
| 2792 | if (set_cpu_ret) { |
| 2793 | pr_err("set_cpus_allowed_ptr failed to restore mask: ret %d\n", |
| 2794 | set_cpu_ret); |
| 2795 | ret = -EFAULT; |
| 2796 | } |
| 2797 | |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 2798 | return ret; |
| 2799 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 2800 | |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 2801 | static int qseecom_query_app_loaded(struct qseecom_dev_handle *data, |
| 2802 | void __user *argp) |
| 2803 | { |
| 2804 | |
| 2805 | int32_t ret; |
| 2806 | struct qseecom_qseos_app_load_query query_req; |
| 2807 | struct qseecom_check_app_ireq req; |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 2808 | struct qseecom_registered_app_list *entry = NULL; |
| 2809 | unsigned long flags = 0; |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 2810 | |
| 2811 | /* Copy the relevant information needed for loading the image */ |
Hariprasad Dhalinarasimha | e201495 | 2013-10-01 18:25:21 -0700 | [diff] [blame] | 2812 | if (copy_from_user(&query_req, |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 2813 | (void __user *)argp, |
| 2814 | sizeof(struct qseecom_qseos_app_load_query))) { |
| 2815 | pr_err("copy_from_user failed\n"); |
| 2816 | return -EFAULT; |
| 2817 | } |
| 2818 | |
| 2819 | req.qsee_cmd_id = QSEOS_APP_LOOKUP_COMMAND; |
Hariprasad Dhalinarasimha | 7a01882 | 2013-10-03 16:52:16 -0700 | [diff] [blame] | 2820 | query_req.app_name[MAX_APP_NAME_SIZE-1] = '\0'; |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 2821 | memcpy(req.app_name, query_req.app_name, MAX_APP_NAME_SIZE); |
| 2822 | |
| 2823 | ret = __qseecom_check_app_exists(req); |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 2824 | |
| 2825 | if ((ret == -EINVAL) || (ret == -ENODEV)) { |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 2826 | pr_err(" scm call to check if app is loaded failed"); |
| 2827 | return ret; /* scm call failed */ |
| 2828 | } else if (ret > 0) { |
Mona Hossain | 7c44320 | 2013-04-18 12:08:58 -0700 | [diff] [blame] | 2829 | pr_debug("App id %d (%s) already exists\n", ret, |
Ramesh Masavarapu | 13d9967 | 2012-07-17 11:05:15 -0700 | [diff] [blame] | 2830 | (char *)(req.app_name)); |
| 2831 | spin_lock_irqsave(&qseecom.registered_app_list_lock, flags); |
| 2832 | list_for_each_entry(entry, |
| 2833 | &qseecom.registered_app_list_head, list){ |
| 2834 | if (entry->app_id == ret) { |
| 2835 | entry->ref_cnt++; |
| 2836 | break; |
| 2837 | } |
| 2838 | } |
| 2839 | spin_unlock_irqrestore( |
| 2840 | &qseecom.registered_app_list_lock, flags); |
| 2841 | data->client.app_id = ret; |
| 2842 | query_req.app_id = ret; |
| 2843 | |
| 2844 | if (copy_to_user(argp, &query_req, sizeof(query_req))) { |
| 2845 | pr_err("copy_to_user failed\n"); |
| 2846 | return -EFAULT; |
| 2847 | } |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 2848 | return -EEXIST; /* app already loaded */ |
| 2849 | } else { |
| 2850 | return 0; /* app not loaded */ |
| 2851 | } |
| 2852 | } |
| 2853 | |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2854 | static int __qseecom_get_ce_pipe_info( |
| 2855 | enum qseecom_key_management_usage_type usage, |
| 2856 | uint32_t *pipe, uint32_t *ce_hw) |
| 2857 | { |
| 2858 | int ret; |
| 2859 | switch (usage) { |
| 2860 | case QSEOS_KM_USAGE_DISK_ENCRYPTION: |
Zhen Kong | 4ffeacf | 2014-02-27 17:21:08 -0800 | [diff] [blame] | 2861 | if (qseecom.support_fde) { |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2862 | *pipe = qseecom.ce_info.disk_encrypt_pipe; |
| 2863 | *ce_hw = qseecom.ce_info.hlos_ce_hw_instance; |
| 2864 | ret = 0; |
Zhen Kong | 4ffeacf | 2014-02-27 17:21:08 -0800 | [diff] [blame] | 2865 | |
| 2866 | } else { |
| 2867 | pr_err("info unavailable: disk encr pipe %d ce_hw %d\n", |
| 2868 | qseecom.ce_info.disk_encrypt_pipe, |
| 2869 | qseecom.ce_info.hlos_ce_hw_instance); |
| 2870 | ret = -EINVAL; |
| 2871 | } |
| 2872 | break; |
| 2873 | case QSEOS_KM_USAGE_FILE_ENCRYPTION: |
| 2874 | if (qseecom.support_pfe) { |
| 2875 | *pipe = qseecom.ce_info.file_encrypt_pipe; |
| 2876 | *ce_hw = qseecom.ce_info.hlos_ce_hw_instance; |
| 2877 | ret = 0; |
| 2878 | } else { |
| 2879 | pr_err("info unavailable: file encr pipe %d ce_hw %d\n", |
| 2880 | qseecom.ce_info.file_encrypt_pipe, |
| 2881 | qseecom.ce_info.hlos_ce_hw_instance); |
| 2882 | ret = -EINVAL; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2883 | } |
| 2884 | break; |
| 2885 | default: |
| 2886 | ret = -EINVAL; |
| 2887 | break; |
| 2888 | } |
| 2889 | return ret; |
| 2890 | } |
| 2891 | |
| 2892 | static int __qseecom_generate_and_save_key(struct qseecom_dev_handle *data, |
| 2893 | enum qseecom_key_management_usage_type usage, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 2894 | struct qseecom_key_generate_ireq *ireq) |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2895 | { |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2896 | struct qseecom_command_scm_resp resp; |
| 2897 | int ret; |
| 2898 | |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 2899 | if (usage < QSEOS_KM_USAGE_DISK_ENCRYPTION || |
| 2900 | usage >= QSEOS_KM_USAGE_MAX) { |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2901 | pr_err("Error:: unsupported usage %d\n", usage); |
| 2902 | return -EFAULT; |
| 2903 | } |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2904 | __qseecom_enable_clk(CLK_QSEE); |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 2905 | |
| 2906 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 2907 | ireq, sizeof(struct qseecom_key_generate_ireq), |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2908 | &resp, sizeof(resp)); |
| 2909 | if (ret) { |
| 2910 | pr_err("scm call to generate key failed : %d\n", ret); |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2911 | __qseecom_disable_clk(CLK_QSEE); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 2912 | return -EFAULT; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | switch (resp.result) { |
| 2916 | case QSEOS_RESULT_SUCCESS: |
| 2917 | break; |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 2918 | case QSEOS_RESULT_FAIL_KEY_ID_EXISTS: |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 2919 | pr_debug("Key ID exists.\n"); |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 2920 | break; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2921 | case QSEOS_RESULT_INCOMPLETE: |
| 2922 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 2923 | if (ret) { |
| 2924 | if (resp.result == QSEOS_RESULT_FAIL_KEY_ID_EXISTS) { |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 2925 | pr_debug("Key ID exists.\n"); |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 2926 | ret = 0; |
| 2927 | } else { |
| 2928 | pr_err("process_incomplete_cmd FAILED, resp.result %d\n", |
| 2929 | resp.result); |
| 2930 | } |
| 2931 | } |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2932 | break; |
| 2933 | case QSEOS_RESULT_FAILURE: |
| 2934 | default: |
| 2935 | pr_err("gen key scm call failed resp.result %d\n", resp.result); |
| 2936 | ret = -EINVAL; |
| 2937 | break; |
| 2938 | } |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2939 | __qseecom_disable_clk(CLK_QSEE); |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2940 | return ret; |
| 2941 | } |
| 2942 | |
| 2943 | static int __qseecom_delete_saved_key(struct qseecom_dev_handle *data, |
| 2944 | enum qseecom_key_management_usage_type usage, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 2945 | struct qseecom_key_delete_ireq *ireq) |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2946 | { |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2947 | struct qseecom_command_scm_resp resp; |
| 2948 | int ret; |
| 2949 | |
| 2950 | if (usage != QSEOS_KM_USAGE_DISK_ENCRYPTION) { |
| 2951 | pr_err("Error:: unsupported usage %d\n", usage); |
| 2952 | return -EFAULT; |
| 2953 | } |
| 2954 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2955 | __qseecom_enable_clk(CLK_QSEE); |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 2956 | |
| 2957 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 2958 | ireq, sizeof(struct qseecom_key_delete_ireq), |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2959 | &resp, sizeof(struct qseecom_command_scm_resp)); |
| 2960 | if (ret) { |
| 2961 | pr_err("scm call to delete key failed : %d\n", ret); |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2962 | __qseecom_disable_clk(CLK_QSEE); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 2963 | return -EFAULT; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | switch (resp.result) { |
| 2967 | case QSEOS_RESULT_SUCCESS: |
| 2968 | break; |
| 2969 | case QSEOS_RESULT_INCOMPLETE: |
| 2970 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 2971 | if (ret) { |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 2972 | pr_err("process_incomplete_cmd FAILED, resp.result %d\n", |
| 2973 | resp.result); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 2974 | if (resp.result == QSEOS_RESULT_FAIL_MAX_ATTEMPT) { |
| 2975 | pr_debug("Max attempts to input password reached.\n"); |
| 2976 | ret = -ERANGE; |
| 2977 | } |
| 2978 | } |
| 2979 | break; |
| 2980 | case QSEOS_RESULT_FAIL_MAX_ATTEMPT: |
| 2981 | pr_debug("Max attempts to input password reached.\n"); |
| 2982 | ret = -ERANGE; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2983 | break; |
| 2984 | case QSEOS_RESULT_FAILURE: |
| 2985 | default: |
| 2986 | pr_err("Delete key scm call failed resp.result %d\n", |
| 2987 | resp.result); |
| 2988 | ret = -EINVAL; |
| 2989 | break; |
| 2990 | } |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 2991 | __qseecom_disable_clk(CLK_QSEE); |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2992 | return ret; |
| 2993 | } |
| 2994 | |
| 2995 | static int __qseecom_set_clear_ce_key(struct qseecom_dev_handle *data, |
| 2996 | enum qseecom_key_management_usage_type usage, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 2997 | struct qseecom_key_select_ireq *ireq) |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2998 | { |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 2999 | struct qseecom_command_scm_resp resp; |
| 3000 | int ret; |
| 3001 | |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3002 | if (usage < QSEOS_KM_USAGE_DISK_ENCRYPTION || |
| 3003 | usage >= QSEOS_KM_USAGE_MAX) { |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3004 | pr_err("Error:: unsupported usage %d\n", usage); |
| 3005 | return -EFAULT; |
| 3006 | } |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3007 | |
Zhen Kong | db2bf74 | 2013-05-13 23:55:42 -0700 | [diff] [blame] | 3008 | __qseecom_enable_clk(CLK_QSEE); |
| 3009 | if (qseecom.qsee.instance != qseecom.ce_drv.instance) |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3010 | __qseecom_enable_clk(CLK_CE_DRV); |
| 3011 | |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 3012 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3013 | ireq, sizeof(struct qseecom_key_select_ireq), |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3014 | &resp, sizeof(struct qseecom_command_scm_resp)); |
| 3015 | if (ret) { |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 3016 | pr_err("scm call to set QSEOS_PIPE_ENC key failed : %d\n", ret); |
Zhen Kong | db2bf74 | 2013-05-13 23:55:42 -0700 | [diff] [blame] | 3017 | __qseecom_disable_clk(CLK_QSEE); |
| 3018 | if (qseecom.qsee.instance != qseecom.ce_drv.instance) |
| 3019 | __qseecom_disable_clk(CLK_CE_DRV); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 3020 | return -EFAULT; |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3023 | switch (resp.result) { |
| 3024 | case QSEOS_RESULT_SUCCESS: |
| 3025 | break; |
| 3026 | case QSEOS_RESULT_INCOMPLETE: |
| 3027 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 3028 | if (ret) { |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 3029 | pr_err("process_incomplete_cmd FAILED, resp.result %d\n", |
| 3030 | resp.result); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 3031 | if (resp.result == QSEOS_RESULT_FAIL_MAX_ATTEMPT) { |
| 3032 | pr_debug("Max attempts to input password reached.\n"); |
| 3033 | ret = -ERANGE; |
| 3034 | } |
| 3035 | } |
| 3036 | break; |
| 3037 | case QSEOS_RESULT_FAIL_MAX_ATTEMPT: |
| 3038 | pr_debug("Max attempts to input password reached.\n"); |
| 3039 | ret = -ERANGE; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3040 | break; |
| 3041 | case QSEOS_RESULT_FAILURE: |
| 3042 | default: |
| 3043 | pr_err("Set key scm call failed resp.result %d\n", resp.result); |
| 3044 | ret = -EINVAL; |
| 3045 | break; |
| 3046 | } |
| 3047 | |
Zhen Kong | db2bf74 | 2013-05-13 23:55:42 -0700 | [diff] [blame] | 3048 | __qseecom_disable_clk(CLK_QSEE); |
| 3049 | if (qseecom.qsee.instance != qseecom.ce_drv.instance) |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3050 | __qseecom_disable_clk(CLK_CE_DRV); |
| 3051 | |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3052 | return ret; |
| 3053 | } |
| 3054 | |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3055 | static int __qseecom_update_current_key_user_info( |
| 3056 | struct qseecom_dev_handle *data, |
| 3057 | enum qseecom_key_management_usage_type usage, |
| 3058 | struct qseecom_key_userinfo_update_ireq *ireq) |
| 3059 | { |
| 3060 | struct qseecom_command_scm_resp resp; |
| 3061 | int ret; |
| 3062 | |
| 3063 | if (usage < QSEOS_KM_USAGE_DISK_ENCRYPTION || |
| 3064 | usage >= QSEOS_KM_USAGE_MAX) { |
| 3065 | pr_err("Error:: unsupported usage %d\n", usage); |
| 3066 | return -EFAULT; |
| 3067 | } |
| 3068 | |
| 3069 | __qseecom_enable_clk(CLK_QSEE); |
| 3070 | |
| 3071 | ret = scm_call(SCM_SVC_TZSCHEDULER, 1, |
| 3072 | ireq, sizeof(struct qseecom_key_userinfo_update_ireq), |
| 3073 | &resp, sizeof(struct qseecom_command_scm_resp)); |
| 3074 | if (ret) { |
| 3075 | pr_err("scm call to update key userinfo failed : %d\n", ret); |
| 3076 | __qseecom_disable_clk(CLK_QSEE); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 3077 | return -EFAULT; |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | switch (resp.result) { |
| 3081 | case QSEOS_RESULT_SUCCESS: |
| 3082 | break; |
| 3083 | case QSEOS_RESULT_INCOMPLETE: |
| 3084 | ret = __qseecom_process_incomplete_cmd(data, &resp); |
| 3085 | if (ret) |
| 3086 | pr_err("process_incomplete_cmd FAILED, resp.result %d\n", |
| 3087 | resp.result); |
| 3088 | break; |
| 3089 | case QSEOS_RESULT_FAILURE: |
| 3090 | default: |
| 3091 | pr_err("Set key scm call failed resp.result %d\n", resp.result); |
| 3092 | ret = -EINVAL; |
| 3093 | break; |
| 3094 | } |
| 3095 | |
| 3096 | __qseecom_disable_clk(CLK_QSEE); |
| 3097 | return ret; |
| 3098 | } |
| 3099 | |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3100 | static int qseecom_create_key(struct qseecom_dev_handle *data, |
| 3101 | void __user *argp) |
| 3102 | { |
| 3103 | uint32_t ce_hw = 0; |
| 3104 | uint32_t pipe = 0; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3105 | int ret = 0; |
| 3106 | uint32_t flags = 0; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3107 | struct qseecom_create_key_req create_key_req; |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3108 | struct qseecom_key_generate_ireq generate_key_ireq; |
| 3109 | struct qseecom_key_select_ireq set_key_ireq; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3110 | |
| 3111 | ret = copy_from_user(&create_key_req, argp, sizeof(create_key_req)); |
| 3112 | if (ret) { |
| 3113 | pr_err("copy_from_user failed\n"); |
| 3114 | return ret; |
| 3115 | } |
| 3116 | |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3117 | if (create_key_req.usage < QSEOS_KM_USAGE_DISK_ENCRYPTION || |
| 3118 | create_key_req.usage >= QSEOS_KM_USAGE_MAX) { |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3119 | pr_err("Error:: unsupported usage %d\n", create_key_req.usage); |
| 3120 | return -EFAULT; |
| 3121 | } |
| 3122 | |
| 3123 | ret = __qseecom_get_ce_pipe_info(create_key_req.usage, &pipe, &ce_hw); |
| 3124 | if (ret) { |
| 3125 | pr_err("Failed to retrieve pipe/ce_hw info: %d\n", ret); |
| 3126 | return -EINVAL; |
| 3127 | } |
| 3128 | |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3129 | generate_key_ireq.flags = flags; |
| 3130 | generate_key_ireq.qsee_command_id = QSEOS_GENERATE_KEY; |
| 3131 | memset((void *)generate_key_ireq.key_id, 0, QSEECOM_KEY_ID_SIZE); |
| 3132 | memset((void *)generate_key_ireq.hash32, 0, QSEECOM_HASH_SIZE); |
| 3133 | memcpy((void *)generate_key_ireq.key_id, |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 3134 | (void *)key_id_array[create_key_req.usage].desc, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3135 | QSEECOM_KEY_ID_SIZE); |
| 3136 | memcpy((void *)generate_key_ireq.hash32, |
| 3137 | (void *)create_key_req.hash32, QSEECOM_HASH_SIZE); |
| 3138 | |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3139 | ret = __qseecom_generate_and_save_key(data, create_key_req.usage, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3140 | &generate_key_ireq); |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3141 | if (ret) { |
| 3142 | pr_err("Failed to generate key on storage: %d\n", ret); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 3143 | return ret; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3144 | } |
| 3145 | |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3146 | set_key_ireq.qsee_command_id = QSEOS_SET_KEY; |
| 3147 | set_key_ireq.ce = ce_hw; |
| 3148 | set_key_ireq.pipe = pipe; |
| 3149 | set_key_ireq.flags = flags; |
| 3150 | |
| 3151 | /* set both PIPE_ENC and PIPE_ENC_XTS*/ |
| 3152 | set_key_ireq.pipe_type = QSEOS_PIPE_ENC|QSEOS_PIPE_ENC_XTS; |
| 3153 | memset((void *)set_key_ireq.key_id, 0, QSEECOM_KEY_ID_SIZE); |
| 3154 | memset((void *)set_key_ireq.hash32, 0, QSEECOM_HASH_SIZE); |
| 3155 | memcpy((void *)set_key_ireq.key_id, |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 3156 | (void *)key_id_array[create_key_req.usage].desc, |
| 3157 | QSEECOM_KEY_ID_SIZE); |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3158 | memcpy((void *)set_key_ireq.hash32, (void *)create_key_req.hash32, |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3159 | QSEECOM_HASH_SIZE); |
| 3160 | |
| 3161 | ret = __qseecom_set_clear_ce_key(data, create_key_req.usage, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3162 | &set_key_ireq); |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3163 | if (ret) { |
| 3164 | pr_err("Failed to create key: pipe %d, ce %d: %d\n", |
| 3165 | pipe, ce_hw, ret); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 3166 | return ret; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | return ret; |
| 3170 | } |
| 3171 | |
| 3172 | static int qseecom_wipe_key(struct qseecom_dev_handle *data, |
| 3173 | void __user *argp) |
| 3174 | { |
| 3175 | uint32_t ce_hw = 0; |
| 3176 | uint32_t pipe = 0; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3177 | int ret = 0; |
| 3178 | uint32_t flags = 0; |
| 3179 | int i; |
| 3180 | struct qseecom_wipe_key_req wipe_key_req; |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3181 | struct qseecom_key_delete_ireq delete_key_ireq; |
| 3182 | struct qseecom_key_select_ireq clear_key_ireq; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3183 | |
| 3184 | ret = copy_from_user(&wipe_key_req, argp, sizeof(wipe_key_req)); |
| 3185 | if (ret) { |
| 3186 | pr_err("copy_from_user failed\n"); |
| 3187 | return ret; |
| 3188 | } |
| 3189 | |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3190 | if (wipe_key_req.usage < QSEOS_KM_USAGE_DISK_ENCRYPTION || |
| 3191 | wipe_key_req.usage >= QSEOS_KM_USAGE_MAX) { |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3192 | pr_err("Error:: unsupported usage %d\n", wipe_key_req.usage); |
| 3193 | return -EFAULT; |
| 3194 | } |
| 3195 | |
| 3196 | ret = __qseecom_get_ce_pipe_info(wipe_key_req.usage, &pipe, &ce_hw); |
| 3197 | if (ret) { |
| 3198 | pr_err("Failed to retrieve pipe/ce_hw info: %d\n", ret); |
| 3199 | return -EINVAL; |
| 3200 | } |
| 3201 | |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 3202 | if (wipe_key_req.wipe_key_flag) { |
| 3203 | delete_key_ireq.flags = flags; |
| 3204 | delete_key_ireq.qsee_command_id = QSEOS_DELETE_KEY; |
| 3205 | memset((void *)delete_key_ireq.key_id, 0, QSEECOM_KEY_ID_SIZE); |
| 3206 | memcpy((void *)delete_key_ireq.key_id, |
| 3207 | (void *)key_id_array[wipe_key_req.usage].desc, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3208 | QSEECOM_KEY_ID_SIZE); |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 3209 | memset((void *)delete_key_ireq.hash32, 0, QSEECOM_HASH_SIZE); |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3210 | |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 3211 | ret = __qseecom_delete_saved_key(data, wipe_key_req.usage, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3212 | &delete_key_ireq); |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 3213 | if (ret) { |
| 3214 | pr_err("Failed to delete key from ssd storage: %d\n", |
| 3215 | ret); |
| 3216 | return -EFAULT; |
| 3217 | } |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3218 | } |
| 3219 | |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3220 | clear_key_ireq.qsee_command_id = QSEOS_SET_KEY; |
| 3221 | clear_key_ireq.ce = ce_hw; |
| 3222 | clear_key_ireq.pipe = pipe; |
| 3223 | clear_key_ireq.flags = flags; |
| 3224 | clear_key_ireq.pipe_type = QSEOS_PIPE_ENC|QSEOS_PIPE_ENC_XTS; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3225 | for (i = 0; i < QSEECOM_KEY_ID_SIZE; i++) |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 3226 | clear_key_ireq.key_id[i] = QSEECOM_INVALID_KEY_ID; |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3227 | memset((void *)clear_key_ireq.hash32, 0, QSEECOM_HASH_SIZE); |
| 3228 | |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3229 | ret = __qseecom_set_clear_ce_key(data, wipe_key_req.usage, |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3230 | &clear_key_ireq); |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3231 | if (ret) { |
| 3232 | pr_err("Failed to wipe key: pipe %d, ce %d: %d\n", |
| 3233 | pipe, ce_hw, ret); |
| 3234 | return -EFAULT; |
| 3235 | } |
| 3236 | |
| 3237 | return ret; |
| 3238 | } |
| 3239 | |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3240 | static int qseecom_update_key_user_info(struct qseecom_dev_handle *data, |
| 3241 | void __user *argp) |
| 3242 | { |
| 3243 | int ret = 0; |
| 3244 | uint32_t flags = 0; |
| 3245 | struct qseecom_update_key_userinfo_req update_key_req; |
| 3246 | struct qseecom_key_userinfo_update_ireq ireq; |
| 3247 | |
| 3248 | ret = copy_from_user(&update_key_req, argp, sizeof(update_key_req)); |
| 3249 | if (ret) { |
| 3250 | pr_err("copy_from_user failed\n"); |
| 3251 | return ret; |
| 3252 | } |
| 3253 | |
| 3254 | if (update_key_req.usage < QSEOS_KM_USAGE_DISK_ENCRYPTION || |
| 3255 | update_key_req.usage >= QSEOS_KM_USAGE_MAX) { |
| 3256 | pr_err("Error:: unsupported usage %d\n", update_key_req.usage); |
| 3257 | return -EFAULT; |
| 3258 | } |
| 3259 | |
| 3260 | ireq.qsee_command_id = QSEOS_UPDATE_KEY_USERINFO; |
| 3261 | ireq.flags = flags; |
| 3262 | memset(ireq.key_id, 0, QSEECOM_KEY_ID_SIZE); |
| 3263 | memset((void *)ireq.current_hash32, 0, QSEECOM_HASH_SIZE); |
| 3264 | memset((void *)ireq.new_hash32, 0, QSEECOM_HASH_SIZE); |
Zhen Kong | ba69dfe | 2014-02-28 15:19:53 -0800 | [diff] [blame] | 3265 | memcpy((void *)ireq.key_id, |
| 3266 | (void *)key_id_array[update_key_req.usage].desc, |
| 3267 | QSEECOM_KEY_ID_SIZE); |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3268 | memcpy((void *)ireq.current_hash32, |
| 3269 | (void *)update_key_req.current_hash32, QSEECOM_HASH_SIZE); |
| 3270 | memcpy((void *)ireq.new_hash32, |
| 3271 | (void *)update_key_req.new_hash32, QSEECOM_HASH_SIZE); |
| 3272 | |
| 3273 | ret = __qseecom_update_current_key_user_info(data, update_key_req.usage, |
| 3274 | &ireq); |
| 3275 | if (ret) { |
| 3276 | pr_err("Failed to update key info: %d\n", ret); |
Zhen Kong | ca39e44 | 2013-12-25 22:57:08 -0800 | [diff] [blame] | 3277 | return ret; |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3278 | } |
| 3279 | return ret; |
| 3280 | |
| 3281 | } |
| 3282 | |
Amir Samuelov | d1fc741 | 2013-03-10 16:56:13 +0200 | [diff] [blame] | 3283 | static int qseecom_is_es_activated(void __user *argp) |
| 3284 | { |
| 3285 | struct qseecom_is_es_activated_req req; |
| 3286 | int ret; |
| 3287 | int resp_buf; |
| 3288 | |
| 3289 | if (qseecom.qsee_version < QSEE_VERSION_04) { |
| 3290 | pr_err("invalid qsee version"); |
| 3291 | return -ENODEV; |
| 3292 | } |
| 3293 | |
| 3294 | if (argp == NULL) { |
| 3295 | pr_err("arg is null"); |
| 3296 | return -EINVAL; |
| 3297 | } |
| 3298 | |
| 3299 | ret = scm_call(SCM_SVC_ES, SCM_IS_ACTIVATED_ID, NULL, 0, |
| 3300 | (void *) &resp_buf, sizeof(resp_buf)); |
| 3301 | if (ret) { |
| 3302 | pr_err("scm_call failed"); |
| 3303 | return ret; |
| 3304 | } |
| 3305 | |
| 3306 | req.is_activated = resp_buf; |
| 3307 | ret = copy_to_user(argp, &req, sizeof(req)); |
| 3308 | if (ret) { |
| 3309 | pr_err("copy_to_user failed"); |
| 3310 | return ret; |
| 3311 | } |
| 3312 | |
| 3313 | return 0; |
| 3314 | } |
| 3315 | |
| 3316 | static int qseecom_save_partition_hash(void __user *argp) |
| 3317 | { |
| 3318 | struct qseecom_save_partition_hash_req req; |
| 3319 | int ret; |
| 3320 | |
| 3321 | if (qseecom.qsee_version < QSEE_VERSION_04) { |
| 3322 | pr_err("invalid qsee version "); |
| 3323 | return -ENODEV; |
| 3324 | } |
| 3325 | |
| 3326 | if (argp == NULL) { |
| 3327 | pr_err("arg is null"); |
| 3328 | return -EINVAL; |
| 3329 | } |
| 3330 | |
| 3331 | ret = copy_from_user(&req, argp, sizeof(req)); |
| 3332 | if (ret) { |
| 3333 | pr_err("copy_from_user failed"); |
| 3334 | return ret; |
| 3335 | } |
| 3336 | |
| 3337 | ret = scm_call(SCM_SVC_ES, SCM_SAVE_PARTITION_HASH_ID, |
| 3338 | (void *) &req, sizeof(req), NULL, 0); |
| 3339 | if (ret) { |
Hariprasad Dhalinarasimha | 682d1c3 | 2013-05-19 21:22:10 -0700 | [diff] [blame] | 3340 | pr_err("qseecom_scm_call failed"); |
Amir Samuelov | d1fc741 | 2013-03-10 16:56:13 +0200 | [diff] [blame] | 3341 | return ret; |
| 3342 | } |
| 3343 | |
| 3344 | return 0; |
| 3345 | } |
| 3346 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3347 | static long qseecom_ioctl(struct file *file, unsigned cmd, |
| 3348 | unsigned long arg) |
| 3349 | { |
| 3350 | int ret = 0; |
| 3351 | struct qseecom_dev_handle *data = file->private_data; |
| 3352 | void __user *argp = (void __user *) arg; |
| 3353 | |
AnilKumar Chimata | 11e1f52 | 2013-07-23 06:02:23 +0530 | [diff] [blame] | 3354 | if (!data) { |
| 3355 | pr_err("Invalid/uninitialized device handle\n"); |
| 3356 | return -EINVAL; |
| 3357 | } |
| 3358 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3359 | if (data->abort) { |
| 3360 | pr_err("Aborting qseecom driver\n"); |
| 3361 | return -ENODEV; |
| 3362 | } |
| 3363 | |
| 3364 | switch (cmd) { |
| 3365 | case QSEECOM_IOCTL_REGISTER_LISTENER_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3366 | if (data->type != QSEECOM_GENERIC) { |
| 3367 | pr_err("reg lstnr req: invalid handle (%d)\n", |
| 3368 | data->type); |
| 3369 | ret = -EINVAL; |
| 3370 | break; |
| 3371 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3372 | pr_debug("ioctl register_listener_req()\n"); |
| 3373 | atomic_inc(&data->ioctl_count); |
Hariprasad Dhalinarasimha | 492530f | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3374 | data->type = QSEECOM_LISTENER_SERVICE; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3375 | ret = qseecom_register_listener(data, argp); |
| 3376 | atomic_dec(&data->ioctl_count); |
| 3377 | wake_up_all(&data->abort_wq); |
| 3378 | if (ret) |
| 3379 | pr_err("failed qseecom_register_listener: %d\n", ret); |
| 3380 | break; |
| 3381 | } |
| 3382 | case QSEECOM_IOCTL_UNREGISTER_LISTENER_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3383 | if ((data->listener.id == 0) || |
| 3384 | (data->type != QSEECOM_LISTENER_SERVICE)) { |
| 3385 | pr_err("unreg lstnr req: invalid handle (%d) lid(%d)\n", |
| 3386 | data->type, data->listener.id); |
| 3387 | ret = -EINVAL; |
| 3388 | break; |
| 3389 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3390 | pr_debug("ioctl unregister_listener_req()\n"); |
| 3391 | atomic_inc(&data->ioctl_count); |
| 3392 | ret = qseecom_unregister_listener(data); |
| 3393 | atomic_dec(&data->ioctl_count); |
| 3394 | wake_up_all(&data->abort_wq); |
| 3395 | if (ret) |
| 3396 | pr_err("failed qseecom_unregister_listener: %d\n", ret); |
| 3397 | break; |
| 3398 | } |
| 3399 | case QSEECOM_IOCTL_SEND_CMD_REQ: { |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 3400 | pr_debug("qseecom.current_mode %d\n", qseecom.current_mode); |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3401 | if ((data->client.app_id == 0) || |
| 3402 | (data->type != QSEECOM_CLIENT_APP)) { |
| 3403 | pr_err("send cmd req: invalid handle (%d) app_id(%d)\n", |
| 3404 | data->type, data->client.app_id); |
| 3405 | ret = -EINVAL; |
| 3406 | break; |
| 3407 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3408 | /* Only one client allowed here at a time */ |
Ramesh Masavarapu | d861011 | 2012-06-26 15:32:52 -0700 | [diff] [blame] | 3409 | mutex_lock(&app_access_lock); |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 3410 | if (qseecom.support_bus_scaling) { |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 3411 | /* register bus bw in case the client doesn't do it */ |
| 3412 | if (!data->mode) { |
| 3413 | mutex_lock(&qsee_bw_mutex); |
| 3414 | __qseecom_register_bus_bandwidth_needs( |
| 3415 | data, HIGH); |
| 3416 | mutex_unlock(&qsee_bw_mutex); |
| 3417 | } |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 3418 | ret = qseecom_scale_bus_bandwidth_timer(INACTIVE); |
| 3419 | if (ret) { |
| 3420 | pr_err("Failed to set bw.\n"); |
| 3421 | ret = -EINVAL; |
| 3422 | mutex_unlock(&app_access_lock); |
| 3423 | break; |
| 3424 | } |
| 3425 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3426 | atomic_inc(&data->ioctl_count); |
| 3427 | ret = qseecom_send_cmd(data, argp); |
Zhen Kong | af95019 | 2014-02-05 17:36:23 -0800 | [diff] [blame] | 3428 | if (qseecom.support_bus_scaling) |
| 3429 | __qseecom_add_bw_scale_down_timer( |
| 3430 | QSEECOM_SEND_CMD_CRYPTO_TIMEOUT); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3431 | atomic_dec(&data->ioctl_count); |
| 3432 | wake_up_all(&data->abort_wq); |
Ramesh Masavarapu | d861011 | 2012-06-26 15:32:52 -0700 | [diff] [blame] | 3433 | mutex_unlock(&app_access_lock); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3434 | if (ret) |
| 3435 | pr_err("failed qseecom_send_cmd: %d\n", ret); |
| 3436 | break; |
| 3437 | } |
| 3438 | case QSEECOM_IOCTL_SEND_MODFD_CMD_REQ: { |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 3439 | pr_debug("qseecom.current_mode %d\n", qseecom.current_mode); |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3440 | if ((data->client.app_id == 0) || |
| 3441 | (data->type != QSEECOM_CLIENT_APP)) { |
| 3442 | pr_err("send mdfd cmd: invalid handle (%d) appid(%d)\n", |
| 3443 | data->type, data->client.app_id); |
| 3444 | ret = -EINVAL; |
| 3445 | break; |
| 3446 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3447 | /* Only one client allowed here at a time */ |
Ramesh Masavarapu | d861011 | 2012-06-26 15:32:52 -0700 | [diff] [blame] | 3448 | mutex_lock(&app_access_lock); |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 3449 | if (qseecom.support_bus_scaling) { |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 3450 | if (!data->mode) { |
| 3451 | mutex_lock(&qsee_bw_mutex); |
| 3452 | __qseecom_register_bus_bandwidth_needs( |
| 3453 | data, HIGH); |
| 3454 | mutex_unlock(&qsee_bw_mutex); |
| 3455 | } |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 3456 | ret = qseecom_scale_bus_bandwidth_timer(INACTIVE); |
| 3457 | if (ret) { |
| 3458 | pr_err("Failed to set bw.\n"); |
| 3459 | mutex_unlock(&app_access_lock); |
| 3460 | ret = -EINVAL; |
| 3461 | break; |
| 3462 | } |
| 3463 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3464 | atomic_inc(&data->ioctl_count); |
| 3465 | ret = qseecom_send_modfd_cmd(data, argp); |
Zhen Kong | af95019 | 2014-02-05 17:36:23 -0800 | [diff] [blame] | 3466 | if (qseecom.support_bus_scaling) |
| 3467 | __qseecom_add_bw_scale_down_timer( |
| 3468 | QSEECOM_SEND_CMD_CRYPTO_TIMEOUT); |
Zhen Kong | e8a0208 | 2014-03-11 17:36:50 -0700 | [diff] [blame] | 3469 | atomic_dec(&data->ioctl_count); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3470 | wake_up_all(&data->abort_wq); |
Ramesh Masavarapu | d861011 | 2012-06-26 15:32:52 -0700 | [diff] [blame] | 3471 | mutex_unlock(&app_access_lock); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3472 | if (ret) |
| 3473 | pr_err("failed qseecom_send_cmd: %d\n", ret); |
| 3474 | break; |
| 3475 | } |
| 3476 | case QSEECOM_IOCTL_RECEIVE_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3477 | if ((data->listener.id == 0) || |
| 3478 | (data->type != QSEECOM_LISTENER_SERVICE)) { |
| 3479 | pr_err("receive req: invalid handle (%d), lid(%d)\n", |
| 3480 | data->type, data->listener.id); |
| 3481 | ret = -EINVAL; |
| 3482 | break; |
| 3483 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3484 | atomic_inc(&data->ioctl_count); |
| 3485 | ret = qseecom_receive_req(data); |
| 3486 | atomic_dec(&data->ioctl_count); |
| 3487 | wake_up_all(&data->abort_wq); |
Hariprasad Dhalinarasimha | f44cbd2 | 2013-07-20 04:49:34 +0530 | [diff] [blame] | 3488 | if (ret && (ret != -ERESTARTSYS)) |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3489 | pr_err("failed qseecom_receive_req: %d\n", ret); |
| 3490 | break; |
| 3491 | } |
| 3492 | case QSEECOM_IOCTL_SEND_RESP_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3493 | if ((data->listener.id == 0) || |
| 3494 | (data->type != QSEECOM_LISTENER_SERVICE)) { |
| 3495 | pr_err("send resp req: invalid handle (%d), lid(%d)\n", |
| 3496 | data->type, data->listener.id); |
| 3497 | ret = -EINVAL; |
| 3498 | break; |
| 3499 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3500 | atomic_inc(&data->ioctl_count); |
| 3501 | ret = qseecom_send_resp(); |
| 3502 | atomic_dec(&data->ioctl_count); |
| 3503 | wake_up_all(&data->abort_wq); |
| 3504 | if (ret) |
| 3505 | pr_err("failed qseecom_send_resp: %d\n", ret); |
| 3506 | break; |
| 3507 | } |
| 3508 | case QSEECOM_IOCTL_SET_MEM_PARAM_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3509 | if ((data->type != QSEECOM_CLIENT_APP) && |
| 3510 | (data->type != QSEECOM_GENERIC) && |
| 3511 | (data->type != QSEECOM_SECURE_SERVICE)) { |
| 3512 | pr_err("set mem param req: invalid handle (%d)\n", |
| 3513 | data->type); |
| 3514 | ret = -EINVAL; |
| 3515 | break; |
| 3516 | } |
Hariprasad Dhalinarasimha | ba30614 | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3517 | data->type = QSEECOM_CLIENT_APP; |
Hariprasad Dhalinarasimha | 492530f | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3518 | pr_debug("SET_MEM_PARAM: qseecom addr = 0x%x\n", (u32)data); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3519 | ret = qseecom_set_client_mem_param(data, argp); |
| 3520 | if (ret) |
| 3521 | pr_err("failed Qqseecom_set_mem_param request: %d\n", |
| 3522 | ret); |
| 3523 | break; |
| 3524 | } |
| 3525 | case QSEECOM_IOCTL_LOAD_APP_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3526 | if ((data->type != QSEECOM_GENERIC) && |
| 3527 | (data->type != QSEECOM_CLIENT_APP)) { |
| 3528 | pr_err("load app req: invalid handle (%d)\n", |
| 3529 | data->type); |
| 3530 | ret = -EINVAL; |
| 3531 | break; |
| 3532 | } |
Hariprasad Dhalinarasimha | 492530f | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3533 | data->type = QSEECOM_CLIENT_APP; |
| 3534 | pr_debug("LOAD_APP_REQ: qseecom_addr = 0x%x\n", (u32)data); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3535 | mutex_lock(&app_access_lock); |
| 3536 | atomic_inc(&data->ioctl_count); |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 3537 | if (qseecom.qsee_version > QSEEE_VERSION_00) { |
| 3538 | if (qseecom.commonlib_loaded == false) { |
Mona Hossain | 9498f5e | 2013-01-23 18:08:45 -0800 | [diff] [blame] | 3539 | ret = qseecom_load_commonlib_image(data); |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 3540 | if (ret == 0) |
| 3541 | qseecom.commonlib_loaded = true; |
| 3542 | } |
| 3543 | } |
| 3544 | if (ret == 0) |
| 3545 | ret = qseecom_load_app(data, argp); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3546 | atomic_dec(&data->ioctl_count); |
| 3547 | mutex_unlock(&app_access_lock); |
| 3548 | if (ret) |
| 3549 | pr_err("failed load_app request: %d\n", ret); |
| 3550 | break; |
| 3551 | } |
| 3552 | case QSEECOM_IOCTL_UNLOAD_APP_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3553 | if ((data->client.app_id == 0) || |
| 3554 | (data->type != QSEECOM_CLIENT_APP)) { |
| 3555 | pr_err("unload app req:invalid handle(%d) app_id(%d)\n", |
| 3556 | data->type, data->client.app_id); |
| 3557 | ret = -EINVAL; |
| 3558 | break; |
| 3559 | } |
Hariprasad Dhalinarasimha | 492530f | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3560 | pr_debug("UNLOAD_APP: qseecom_addr = 0x%x\n", (u32)data); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3561 | mutex_lock(&app_access_lock); |
| 3562 | atomic_inc(&data->ioctl_count); |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 3563 | ret = qseecom_unload_app(data, false); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3564 | atomic_dec(&data->ioctl_count); |
| 3565 | mutex_unlock(&app_access_lock); |
| 3566 | if (ret) |
| 3567 | pr_err("failed unload_app request: %d\n", ret); |
| 3568 | break; |
| 3569 | } |
| 3570 | case QSEECOM_IOCTL_GET_QSEOS_VERSION_REQ: { |
| 3571 | atomic_inc(&data->ioctl_count); |
| 3572 | ret = qseecom_get_qseos_version(data, argp); |
| 3573 | if (ret) |
| 3574 | pr_err("qseecom_get_qseos_version: %d\n", ret); |
| 3575 | atomic_dec(&data->ioctl_count); |
| 3576 | break; |
| 3577 | } |
| 3578 | case QSEECOM_IOCTL_PERF_ENABLE_REQ:{ |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3579 | if ((data->type != QSEECOM_GENERIC) && |
| 3580 | (data->type != QSEECOM_CLIENT_APP)) { |
| 3581 | pr_err("perf enable req: invalid handle (%d)\n", |
| 3582 | data->type); |
| 3583 | ret = -EINVAL; |
| 3584 | break; |
| 3585 | } |
| 3586 | if ((data->type == QSEECOM_CLIENT_APP) && |
| 3587 | (data->client.app_id == 0)) { |
| 3588 | pr_err("perf enable req:invalid handle(%d) appid(%d)\n", |
| 3589 | data->type, data->client.app_id); |
| 3590 | ret = -EINVAL; |
| 3591 | break; |
| 3592 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3593 | atomic_inc(&data->ioctl_count); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 3594 | if (qseecom.support_bus_scaling) { |
| 3595 | mutex_lock(&qsee_bw_mutex); |
| 3596 | __qseecom_register_bus_bandwidth_needs(data, HIGH); |
| 3597 | mutex_unlock(&qsee_bw_mutex); |
| 3598 | } else { |
| 3599 | ret = qsee_vote_for_clock(data, CLK_DFAB); |
| 3600 | if (ret) |
| 3601 | pr_err("Fail to vote for DFAB clock%d\n", ret); |
| 3602 | ret = qsee_vote_for_clock(data, CLK_SFPB); |
| 3603 | if (ret) |
| 3604 | pr_err("Fail to vote for SFPB clock%d\n", ret); |
| 3605 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3606 | atomic_dec(&data->ioctl_count); |
| 3607 | break; |
| 3608 | } |
| 3609 | case QSEECOM_IOCTL_PERF_DISABLE_REQ:{ |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3610 | if ((data->type != QSEECOM_SECURE_SERVICE) && |
| 3611 | (data->type != QSEECOM_CLIENT_APP)) { |
| 3612 | pr_err("perf disable req: invalid handle (%d)\n", |
| 3613 | data->type); |
| 3614 | ret = -EINVAL; |
| 3615 | break; |
| 3616 | } |
| 3617 | if ((data->type == QSEECOM_CLIENT_APP) && |
| 3618 | (data->client.app_id == 0)) { |
| 3619 | pr_err("perf disable: invalid handle (%d)app_id(%d)\n", |
| 3620 | data->type, data->client.app_id); |
| 3621 | ret = -EINVAL; |
| 3622 | break; |
| 3623 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3624 | atomic_inc(&data->ioctl_count); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 3625 | if (!qseecom.support_bus_scaling) { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3626 | qsee_disable_clock_vote(data, CLK_DFAB); |
| 3627 | qsee_disable_clock_vote(data, CLK_SFPB); |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 3628 | } else { |
| 3629 | mutex_lock(&qsee_bw_mutex); |
| 3630 | qseecom_unregister_bus_bandwidth_needs(data); |
| 3631 | mutex_unlock(&qsee_bw_mutex); |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 3632 | } |
| 3633 | atomic_dec(&data->ioctl_count); |
| 3634 | break; |
| 3635 | } |
| 3636 | |
| 3637 | case QSEECOM_IOCTL_SET_BUS_SCALING_REQ: { |
| 3638 | if ((data->client.app_id == 0) || |
| 3639 | (data->type != QSEECOM_CLIENT_APP)) { |
| 3640 | pr_err("set bus scale: invalid handle (%d) appid(%d)\n", |
| 3641 | data->type, data->client.app_id); |
| 3642 | ret = -EINVAL; |
| 3643 | break; |
| 3644 | } |
| 3645 | atomic_inc(&data->ioctl_count); |
| 3646 | ret = qseecom_scale_bus_bandwidth(data, argp); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3647 | atomic_dec(&data->ioctl_count); |
| 3648 | break; |
| 3649 | } |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 3650 | case QSEECOM_IOCTL_LOAD_EXTERNAL_ELF_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3651 | if (data->type != QSEECOM_GENERIC) { |
| 3652 | pr_err("load ext elf req: invalid client handle (%d)\n", |
| 3653 | data->type); |
| 3654 | ret = -EINVAL; |
| 3655 | break; |
| 3656 | } |
Hariprasad Dhalinarasimha | 492530f | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3657 | data->type = QSEECOM_UNAVAILABLE_CLIENT_APP; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 3658 | data->released = true; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 3659 | mutex_lock(&app_access_lock); |
| 3660 | atomic_inc(&data->ioctl_count); |
| 3661 | ret = qseecom_load_external_elf(data, argp); |
| 3662 | atomic_dec(&data->ioctl_count); |
| 3663 | mutex_unlock(&app_access_lock); |
| 3664 | if (ret) |
| 3665 | pr_err("failed load_external_elf request: %d\n", ret); |
| 3666 | break; |
| 3667 | } |
| 3668 | case QSEECOM_IOCTL_UNLOAD_EXTERNAL_ELF_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3669 | if (data->type != QSEECOM_UNAVAILABLE_CLIENT_APP) { |
| 3670 | pr_err("unload ext elf req: invalid handle (%d)\n", |
| 3671 | data->type); |
| 3672 | ret = -EINVAL; |
| 3673 | break; |
| 3674 | } |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 3675 | data->released = true; |
Mona Hossain | 5ab9d77 | 2012-04-11 21:00:40 -0700 | [diff] [blame] | 3676 | mutex_lock(&app_access_lock); |
| 3677 | atomic_inc(&data->ioctl_count); |
| 3678 | ret = qseecom_unload_external_elf(data); |
| 3679 | atomic_dec(&data->ioctl_count); |
| 3680 | mutex_unlock(&app_access_lock); |
| 3681 | if (ret) |
| 3682 | pr_err("failed unload_app request: %d\n", ret); |
| 3683 | break; |
| 3684 | } |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 3685 | case QSEECOM_IOCTL_APP_LOADED_QUERY_REQ: { |
Hariprasad Dhalinarasimha | 492530f | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3686 | data->type = QSEECOM_CLIENT_APP; |
Hariprasad Dhalinarasimha | ba30614 | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3687 | pr_debug("APP_LOAD_QUERY: qseecom_addr = 0x%x\n", (u32)data); |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 3688 | mutex_lock(&app_access_lock); |
| 3689 | atomic_inc(&data->ioctl_count); |
Hariprasad Dhalinarasimha | 492530f | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3690 | pr_debug("APP_LOAD_QUERY: qseecom_addr = 0x%x\n", (u32)data); |
Ramesh Masavarapu | 1ee4ac8 | 2012-06-22 15:38:34 -0700 | [diff] [blame] | 3691 | ret = qseecom_query_app_loaded(data, argp); |
| 3692 | atomic_dec(&data->ioctl_count); |
| 3693 | mutex_unlock(&app_access_lock); |
| 3694 | break; |
| 3695 | } |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3696 | case QSEECOM_IOCTL_SEND_CMD_SERVICE_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3697 | if (data->type != QSEECOM_GENERIC) { |
| 3698 | pr_err("send cmd svc req: invalid handle (%d)\n", |
| 3699 | data->type); |
| 3700 | ret = -EINVAL; |
| 3701 | break; |
| 3702 | } |
Hariprasad Dhalinarasimha | 492530f | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3703 | data->type = QSEECOM_SECURE_SERVICE; |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3704 | if (qseecom.qsee_version < QSEE_VERSION_03) { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3705 | pr_err("SEND_CMD_SERVICE_REQ: Invalid qsee ver %u\n", |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3706 | qseecom.qsee_version); |
| 3707 | return -EINVAL; |
| 3708 | } |
| 3709 | mutex_lock(&app_access_lock); |
| 3710 | atomic_inc(&data->ioctl_count); |
| 3711 | ret = qseecom_send_service_cmd(data, argp); |
| 3712 | atomic_dec(&data->ioctl_count); |
| 3713 | mutex_unlock(&app_access_lock); |
| 3714 | break; |
| 3715 | } |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3716 | case QSEECOM_IOCTL_CREATE_KEY_REQ: { |
Zhen Kong | a10dcab | 2014-03-19 10:32:27 -0700 | [diff] [blame] | 3717 | if (!(qseecom.support_pfe || qseecom.support_fde)) |
| 3718 | pr_err("Features requiring key init not supported\n"); |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3719 | if (data->type != QSEECOM_GENERIC) { |
| 3720 | pr_err("create key req: invalid handle (%d)\n", |
| 3721 | data->type); |
| 3722 | ret = -EINVAL; |
| 3723 | break; |
| 3724 | } |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 3725 | if (qseecom.qsee_version < QSEE_VERSION_05) { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3726 | pr_err("Create Key feature unsupported: qsee ver %u\n", |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 3727 | qseecom.qsee_version); |
| 3728 | return -EINVAL; |
| 3729 | } |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3730 | data->released = true; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3731 | atomic_inc(&data->ioctl_count); |
| 3732 | ret = qseecom_create_key(data, argp); |
| 3733 | if (ret) |
| 3734 | pr_err("failed to create encryption key: %d\n", ret); |
| 3735 | |
| 3736 | atomic_dec(&data->ioctl_count); |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3737 | break; |
| 3738 | } |
| 3739 | case QSEECOM_IOCTL_WIPE_KEY_REQ: { |
Zhen Kong | a10dcab | 2014-03-19 10:32:27 -0700 | [diff] [blame] | 3740 | if (!(qseecom.support_pfe || qseecom.support_fde)) |
| 3741 | pr_err("Features requiring key init not supported\n"); |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3742 | if (data->type != QSEECOM_GENERIC) { |
| 3743 | pr_err("wipe key req: invalid handle (%d)\n", |
| 3744 | data->type); |
| 3745 | ret = -EINVAL; |
| 3746 | break; |
| 3747 | } |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 3748 | if (qseecom.qsee_version < QSEE_VERSION_05) { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3749 | pr_err("Wipe Key feature unsupported in qsee ver %u\n", |
Zhen Kong | 336636e | 2013-04-15 11:04:54 -0700 | [diff] [blame] | 3750 | qseecom.qsee_version); |
| 3751 | return -EINVAL; |
| 3752 | } |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3753 | data->released = true; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3754 | atomic_inc(&data->ioctl_count); |
| 3755 | ret = qseecom_wipe_key(data, argp); |
| 3756 | if (ret) |
| 3757 | pr_err("failed to wipe encryption key: %d\n", ret); |
| 3758 | atomic_dec(&data->ioctl_count); |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3759 | break; |
| 3760 | } |
| 3761 | case QSEECOM_IOCTL_UPDATE_KEY_USER_INFO_REQ: { |
Zhen Kong | a10dcab | 2014-03-19 10:32:27 -0700 | [diff] [blame] | 3762 | if (!(qseecom.support_pfe || qseecom.support_fde)) |
| 3763 | pr_err("Features requiring key init not supported\n"); |
Zhen Kong | 9730ddf | 2013-12-17 16:49:43 -0800 | [diff] [blame] | 3764 | if (data->type != QSEECOM_GENERIC) { |
| 3765 | pr_err("update key req: invalid handle (%d)\n", |
| 3766 | data->type); |
| 3767 | ret = -EINVAL; |
| 3768 | break; |
| 3769 | } |
| 3770 | if (qseecom.qsee_version < QSEE_VERSION_05) { |
| 3771 | pr_err("Update Key feature unsupported in qsee ver %u\n", |
| 3772 | qseecom.qsee_version); |
| 3773 | return -EINVAL; |
| 3774 | } |
| 3775 | data->released = true; |
| 3776 | atomic_inc(&data->ioctl_count); |
| 3777 | ret = qseecom_update_key_user_info(data, argp); |
| 3778 | if (ret) |
| 3779 | pr_err("failed to update key user info: %d\n", ret); |
| 3780 | atomic_dec(&data->ioctl_count); |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 3781 | break; |
| 3782 | } |
Amir Samuelov | d1fc741 | 2013-03-10 16:56:13 +0200 | [diff] [blame] | 3783 | case QSEECOM_IOCTL_SAVE_PARTITION_HASH_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3784 | if (data->type != QSEECOM_GENERIC) { |
| 3785 | pr_err("save part hash req: invalid handle (%d)\n", |
| 3786 | data->type); |
| 3787 | ret = -EINVAL; |
| 3788 | break; |
| 3789 | } |
Amir Samuelov | d1fc741 | 2013-03-10 16:56:13 +0200 | [diff] [blame] | 3790 | data->released = true; |
| 3791 | mutex_lock(&app_access_lock); |
| 3792 | atomic_inc(&data->ioctl_count); |
| 3793 | ret = qseecom_save_partition_hash(argp); |
| 3794 | atomic_dec(&data->ioctl_count); |
| 3795 | mutex_unlock(&app_access_lock); |
| 3796 | break; |
| 3797 | } |
| 3798 | case QSEECOM_IOCTL_IS_ES_ACTIVATED_REQ: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3799 | if (data->type != QSEECOM_GENERIC) { |
| 3800 | pr_err("ES activated req: invalid handle (%d)\n", |
| 3801 | data->type); |
| 3802 | ret = -EINVAL; |
| 3803 | break; |
| 3804 | } |
Amir Samuelov | d1fc741 | 2013-03-10 16:56:13 +0200 | [diff] [blame] | 3805 | data->released = true; |
| 3806 | mutex_lock(&app_access_lock); |
| 3807 | atomic_inc(&data->ioctl_count); |
| 3808 | ret = qseecom_is_es_activated(argp); |
| 3809 | atomic_dec(&data->ioctl_count); |
| 3810 | mutex_unlock(&app_access_lock); |
| 3811 | break; |
| 3812 | } |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 3813 | case QSEECOM_IOCTL_SEND_MODFD_RESP: { |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3814 | if ((data->listener.id == 0) || |
| 3815 | (data->type != QSEECOM_LISTENER_SERVICE)) { |
| 3816 | pr_err("receive req: invalid handle (%d), lid(%d)\n", |
| 3817 | data->type, data->listener.id); |
| 3818 | ret = -EINVAL; |
| 3819 | break; |
| 3820 | } |
Hariprasad Dhalinarasimha | 23fdcd9 | 2013-05-01 14:51:09 -0700 | [diff] [blame] | 3821 | /* Only one client allowed here at a time */ |
| 3822 | atomic_inc(&data->ioctl_count); |
| 3823 | ret = qseecom_send_modfd_resp(data, argp); |
| 3824 | atomic_dec(&data->ioctl_count); |
| 3825 | wake_up_all(&data->abort_wq); |
| 3826 | if (ret) |
| 3827 | pr_err("failed qseecom_send_mod_resp: %d\n", ret); |
| 3828 | break; |
| 3829 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3830 | default: |
Mona Hossain | a1124de | 2013-10-01 13:41:09 -0700 | [diff] [blame] | 3831 | pr_err("Invalid IOCTL: %d\n", cmd); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3832 | return -EINVAL; |
| 3833 | } |
| 3834 | return ret; |
| 3835 | } |
| 3836 | |
| 3837 | static int qseecom_open(struct inode *inode, struct file *file) |
| 3838 | { |
| 3839 | int ret = 0; |
| 3840 | struct qseecom_dev_handle *data; |
| 3841 | |
| 3842 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3843 | if (!data) { |
| 3844 | pr_err("kmalloc failed\n"); |
| 3845 | return -ENOMEM; |
| 3846 | } |
| 3847 | file->private_data = data; |
| 3848 | data->abort = 0; |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3849 | data->type = QSEECOM_GENERIC; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3850 | data->released = false; |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 3851 | data->mode = INACTIVE; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3852 | init_waitqueue_head(&data->abort_wq); |
| 3853 | atomic_set(&data->ioctl_count, 0); |
Mona Hossain | d4613de | 2013-05-15 16:49:29 -0700 | [diff] [blame] | 3854 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3855 | return ret; |
| 3856 | } |
| 3857 | |
| 3858 | static int qseecom_release(struct inode *inode, struct file *file) |
| 3859 | { |
| 3860 | struct qseecom_dev_handle *data = file->private_data; |
| 3861 | int ret = 0; |
| 3862 | |
| 3863 | if (data->released == false) { |
Hariprasad Dhalinarasimha | ba30614 | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3864 | pr_warn("data: released = false, type = %d, data = 0x%x\n", |
| 3865 | data->type, (u32)data); |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3866 | switch (data->type) { |
| 3867 | case QSEECOM_LISTENER_SERVICE: |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3868 | ret = qseecom_unregister_listener(data); |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3869 | break; |
| 3870 | case QSEECOM_CLIENT_APP: |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 3871 | ret = qseecom_unload_app(data, true); |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3872 | break; |
| 3873 | case QSEECOM_SECURE_SERVICE: |
Mona Hossain | d4b70573 | 2013-04-05 21:56:28 -0700 | [diff] [blame] | 3874 | case QSEECOM_GENERIC: |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3875 | ret = qseecom_unmap_ion_allocated_memory(data); |
Hariprasad Dhalinarasimha | 492530f | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3876 | if (ret) |
Hariprasad Dhalinarasimha | ba30614 | 2013-08-19 12:45:18 -0700 | [diff] [blame] | 3877 | pr_err("Ion Unmap failed\n"); |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3878 | break; |
AnilKumar Chimata | f732bbe | 2013-07-24 00:44:09 +0530 | [diff] [blame] | 3879 | case QSEECOM_UNAVAILABLE_CLIENT_APP: |
| 3880 | break; |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3881 | default: |
| 3882 | pr_err("Unsupported clnt_handle_type %d", |
| 3883 | data->type); |
| 3884 | break; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3885 | } |
| 3886 | } |
Hariprasad Dhalinarasimha | adf27a8 | 2013-02-11 15:07:59 -0800 | [diff] [blame] | 3887 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 3888 | if (qseecom.support_bus_scaling) { |
| 3889 | mutex_lock(&qsee_bw_mutex); |
| 3890 | if (data->mode != INACTIVE) { |
| 3891 | qseecom_unregister_bus_bandwidth_needs(data); |
| 3892 | if (qseecom.cumulative_mode == INACTIVE) { |
| 3893 | ret = __qseecom_set_msm_bus_request(INACTIVE); |
| 3894 | if (ret) |
| 3895 | pr_err("Fail to scale down bus\n"); |
| 3896 | } |
| 3897 | } |
| 3898 | mutex_unlock(&qsee_bw_mutex); |
| 3899 | } else { |
| 3900 | if (data->fast_load_enabled == true) |
| 3901 | qsee_disable_clock_vote(data, CLK_SFPB); |
| 3902 | if (data->perf_enabled == true) |
| 3903 | qsee_disable_clock_vote(data, CLK_DFAB); |
| 3904 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3905 | kfree(data); |
Ramesh Masavarapu | a1bc0e4 | 2012-03-05 07:42:48 -0800 | [diff] [blame] | 3906 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3907 | return ret; |
| 3908 | } |
| 3909 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 3910 | static const struct file_operations qseecom_fops = { |
| 3911 | .owner = THIS_MODULE, |
| 3912 | .unlocked_ioctl = qseecom_ioctl, |
| 3913 | .open = qseecom_open, |
| 3914 | .release = qseecom_release |
| 3915 | }; |
| 3916 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3917 | static int __qseecom_init_clk(enum qseecom_ce_hw_instance ce) |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3918 | { |
| 3919 | int rc = 0; |
| 3920 | struct device *pdev; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3921 | struct qseecom_clk *qclk; |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3922 | char *core_clk_src = NULL; |
| 3923 | char *core_clk = NULL; |
| 3924 | char *iface_clk = NULL; |
| 3925 | char *bus_clk = NULL; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3926 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3927 | switch (ce) { |
| 3928 | case CLK_QSEE: { |
| 3929 | core_clk_src = "core_clk_src"; |
| 3930 | core_clk = "core_clk"; |
| 3931 | iface_clk = "iface_clk"; |
| 3932 | bus_clk = "bus_clk"; |
| 3933 | qclk = &qseecom.qsee; |
| 3934 | qclk->instance = CLK_QSEE; |
| 3935 | break; |
| 3936 | }; |
| 3937 | case CLK_CE_DRV: { |
| 3938 | core_clk_src = "ce_drv_core_clk_src"; |
| 3939 | core_clk = "ce_drv_core_clk"; |
| 3940 | iface_clk = "ce_drv_iface_clk"; |
| 3941 | bus_clk = "ce_drv_bus_clk"; |
| 3942 | qclk = &qseecom.ce_drv; |
| 3943 | qclk->instance = CLK_CE_DRV; |
| 3944 | break; |
| 3945 | }; |
| 3946 | default: |
| 3947 | pr_err("Invalid ce hw instance: %d!\n", ce); |
| 3948 | return -EIO; |
| 3949 | } |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3950 | pdev = qseecom.pdev; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3951 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3952 | /* Get CE3 src core clk. */ |
| 3953 | qclk->ce_core_src_clk = clk_get(pdev, core_clk_src); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3954 | if (!IS_ERR(qclk->ce_core_src_clk)) { |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 3955 | /* Set the core src clk @100Mhz */ |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3956 | rc = clk_set_rate(qclk->ce_core_src_clk, QSEE_CE_CLK_100MHZ); |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3957 | if (rc) { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3958 | clk_put(qclk->ce_core_src_clk); |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3959 | pr_err("Unable to set the core src clk @100Mhz.\n"); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 3960 | return -EIO; |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3961 | } |
| 3962 | } else { |
| 3963 | pr_warn("Unable to get CE core src clk, set to NULL\n"); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3964 | qclk->ce_core_src_clk = NULL; |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | /* Get CE core clk */ |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3968 | qclk->ce_core_clk = clk_get(pdev, core_clk); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3969 | if (IS_ERR(qclk->ce_core_clk)) { |
| 3970 | rc = PTR_ERR(qclk->ce_core_clk); |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3971 | pr_err("Unable to get CE core clk\n"); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3972 | if (qclk->ce_core_src_clk != NULL) |
| 3973 | clk_put(qclk->ce_core_src_clk); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 3974 | return -EIO; |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | /* Get CE Interface clk */ |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3978 | qclk->ce_clk = clk_get(pdev, iface_clk); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3979 | if (IS_ERR(qclk->ce_clk)) { |
| 3980 | rc = PTR_ERR(qclk->ce_clk); |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3981 | pr_err("Unable to get CE interface clk\n"); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3982 | if (qclk->ce_core_src_clk != NULL) |
| 3983 | clk_put(qclk->ce_core_src_clk); |
| 3984 | clk_put(qclk->ce_core_clk); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 3985 | return -EIO; |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | /* Get CE AXI clk */ |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 3989 | qclk->ce_bus_clk = clk_get(pdev, bus_clk); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3990 | if (IS_ERR(qclk->ce_bus_clk)) { |
| 3991 | rc = PTR_ERR(qclk->ce_bus_clk); |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3992 | pr_err("Unable to get CE BUS interface clk\n"); |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 3993 | if (qclk->ce_core_src_clk != NULL) |
| 3994 | clk_put(qclk->ce_core_src_clk); |
| 3995 | clk_put(qclk->ce_core_clk); |
| 3996 | clk_put(qclk->ce_clk); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 3997 | return -EIO; |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3998 | } |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 3999 | return rc; |
| 4000 | } |
| 4001 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 4002 | static void __qseecom_deinit_clk(enum qseecom_ce_hw_instance ce) |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 4003 | { |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4004 | struct qseecom_clk *qclk; |
| 4005 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 4006 | if (ce == CLK_QSEE) |
| 4007 | qclk = &qseecom.qsee; |
| 4008 | else |
| 4009 | qclk = &qseecom.ce_drv; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4010 | |
| 4011 | if (qclk->ce_clk != NULL) { |
| 4012 | clk_put(qclk->ce_clk); |
| 4013 | qclk->ce_clk = NULL; |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 4014 | } |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4015 | if (qclk->ce_core_clk != NULL) { |
| 4016 | clk_put(qclk->ce_core_clk); |
| 4017 | qclk->ce_clk = NULL; |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 4018 | } |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4019 | if (qclk->ce_bus_clk != NULL) { |
| 4020 | clk_put(qclk->ce_bus_clk); |
| 4021 | qclk->ce_clk = NULL; |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 4022 | } |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4023 | if (qclk->ce_core_src_clk != NULL) { |
| 4024 | clk_put(qclk->ce_core_src_clk); |
| 4025 | qclk->ce_core_src_clk = NULL; |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 4026 | } |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 4029 | static int __devinit qseecom_probe(struct platform_device *pdev) |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4030 | { |
| 4031 | int rc; |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 4032 | int ret = 0; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4033 | struct device *class_dev; |
| 4034 | char qsee_not_legacy = 0; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4035 | struct msm_bus_scale_pdata *qseecom_platform_support = NULL; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4036 | uint32_t system_call_id = QSEOS_CHECK_VERSION_CMD; |
| 4037 | |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4038 | qseecom.qsee_bw_count = 0; |
| 4039 | qseecom.qsee_perf_client = 0; |
| 4040 | qseecom.qsee_sfpb_bw_count = 0; |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 4041 | |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4042 | qseecom.qsee.ce_core_clk = NULL; |
| 4043 | qseecom.qsee.ce_clk = NULL; |
| 4044 | qseecom.qsee.ce_core_src_clk = NULL; |
| 4045 | qseecom.qsee.ce_bus_clk = NULL; |
Ramesh Masavarapu | e640e84 | 2012-04-03 11:21:54 -0700 | [diff] [blame] | 4046 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 4047 | qseecom.cumulative_mode = 0; |
| 4048 | qseecom.current_mode = INACTIVE; |
| 4049 | qseecom.support_bus_scaling = false; |
Zhen Kong | 4ffeacf | 2014-02-27 17:21:08 -0800 | [diff] [blame] | 4050 | qseecom.support_fde = false; |
| 4051 | qseecom.support_pfe = false; |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 4052 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 4053 | qseecom.ce_drv.ce_core_clk = NULL; |
| 4054 | qseecom.ce_drv.ce_clk = NULL; |
| 4055 | qseecom.ce_drv.ce_core_src_clk = NULL; |
| 4056 | qseecom.ce_drv.ce_bus_clk = NULL; |
| 4057 | |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4058 | rc = alloc_chrdev_region(&qseecom_device_no, 0, 1, QSEECOM_DEV); |
| 4059 | if (rc < 0) { |
| 4060 | pr_err("alloc_chrdev_region failed %d\n", rc); |
| 4061 | return rc; |
| 4062 | } |
| 4063 | |
| 4064 | driver_class = class_create(THIS_MODULE, QSEECOM_DEV); |
| 4065 | if (IS_ERR(driver_class)) { |
| 4066 | rc = -ENOMEM; |
| 4067 | pr_err("class_create failed %d\n", rc); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4068 | goto exit_unreg_chrdev_region; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | class_dev = device_create(driver_class, NULL, qseecom_device_no, NULL, |
| 4072 | QSEECOM_DEV); |
| 4073 | if (!class_dev) { |
| 4074 | pr_err("class_device_create failed %d\n", rc); |
| 4075 | rc = -ENOMEM; |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4076 | goto exit_destroy_class; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4077 | } |
| 4078 | |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4079 | cdev_init(&qseecom.cdev, &qseecom_fops); |
| 4080 | qseecom.cdev.owner = THIS_MODULE; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4081 | |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4082 | rc = cdev_add(&qseecom.cdev, MKDEV(MAJOR(qseecom_device_no), 0), 1); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4083 | if (rc < 0) { |
| 4084 | pr_err("cdev_add failed %d\n", rc); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4085 | goto exit_destroy_device; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | INIT_LIST_HEAD(&qseecom.registered_listener_list_head); |
| 4089 | spin_lock_init(&qseecom.registered_listener_list_lock); |
| 4090 | INIT_LIST_HEAD(&qseecom.registered_app_list_head); |
| 4091 | spin_lock_init(&qseecom.registered_app_list_lock); |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4092 | INIT_LIST_HEAD(&qseecom.registered_kclient_list_head); |
| 4093 | spin_lock_init(&qseecom.registered_kclient_list_lock); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4094 | init_waitqueue_head(&qseecom.send_resp_wq); |
| 4095 | qseecom.send_resp_flag = 0; |
| 4096 | |
| 4097 | rc = scm_call(6, 1, &system_call_id, sizeof(system_call_id), |
| 4098 | &qsee_not_legacy, sizeof(qsee_not_legacy)); |
| 4099 | if (rc) { |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 4100 | pr_err("Failed to retrieve QSEOS version information %d\n", rc); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4101 | goto exit_del_cdev; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4102 | } |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 4103 | if (qsee_not_legacy) { |
| 4104 | uint32_t feature = 10; |
| 4105 | |
| 4106 | qseecom.qsee_version = QSEEE_VERSION_00; |
| 4107 | rc = scm_call(6, 3, &feature, sizeof(feature), |
| 4108 | &qseecom.qsee_version, sizeof(qseecom.qsee_version)); |
| 4109 | if (rc) { |
| 4110 | pr_err("Failed to get QSEE version info %d\n", rc); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4111 | goto exit_del_cdev; |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 4112 | } |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4113 | qseecom.qseos_version = QSEOS_VERSION_14; |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 4114 | } else { |
Mona Hossain | 9c1f6c5 | 2013-05-19 21:27:26 -0700 | [diff] [blame] | 4115 | pr_err("QSEE legacy version is not supported:"); |
| 4116 | pr_err("Support for TZ1.3 and earlier is deprecated\n"); |
| 4117 | rc = -EINVAL; |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4118 | goto exit_del_cdev; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4119 | } |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 4120 | qseecom.commonlib_loaded = false; |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 4121 | qseecom.pdev = class_dev; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4122 | /* Create ION msm client */ |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4123 | qseecom.ion_clnt = msm_ion_client_create(-1, "qseecom-kernel"); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4124 | if (qseecom.ion_clnt == NULL) { |
| 4125 | pr_err("Ion client cannot be created\n"); |
| 4126 | rc = -ENOMEM; |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4127 | goto exit_del_cdev; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4128 | } |
| 4129 | |
| 4130 | /* register client for bus scaling */ |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 4131 | if (pdev->dev.of_node) { |
AnilKumar Chimata | bb51272 | 2014-01-29 00:12:35 +0530 | [diff] [blame] | 4132 | qseecom.pdev->of_node = pdev->dev.of_node; |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 4133 | qseecom.support_bus_scaling = |
| 4134 | of_property_read_bool((&pdev->dev)->of_node, |
| 4135 | "qcom,support-bus-scaling"); |
| 4136 | pr_warn("support_bus_scaling=0x%x", |
| 4137 | qseecom.support_bus_scaling); |
Zhen Kong | 4ffeacf | 2014-02-27 17:21:08 -0800 | [diff] [blame] | 4138 | qseecom.support_fde = |
| 4139 | of_property_read_bool((&pdev->dev)->of_node, |
| 4140 | "qcom,support-fde"); |
| 4141 | if (qseecom.support_fde) { |
| 4142 | if (of_property_read_u32((&pdev->dev)->of_node, |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 4143 | "qcom,disk-encrypt-pipe-pair", |
| 4144 | &qseecom.ce_info.disk_encrypt_pipe)) { |
Zhen Kong | 4ffeacf | 2014-02-27 17:21:08 -0800 | [diff] [blame] | 4145 | pr_err("Fail to get FDE pipe information.\n"); |
| 4146 | rc = -EINVAL; |
| 4147 | goto exit_destroy_ion_client; |
| 4148 | } else { |
| 4149 | pr_warn("disk-encrypt-pipe-pair=0x%x", |
| 4150 | qseecom.ce_info.disk_encrypt_pipe); |
| 4151 | } |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 4152 | } else { |
Zhen Kong | 4ffeacf | 2014-02-27 17:21:08 -0800 | [diff] [blame] | 4153 | pr_warn("Device does not support FDE"); |
| 4154 | qseecom.ce_info.disk_encrypt_pipe = 0xff; |
| 4155 | } |
| 4156 | qseecom.support_pfe = |
| 4157 | of_property_read_bool((&pdev->dev)->of_node, |
| 4158 | "qcom,support-pfe"); |
| 4159 | if (qseecom.support_pfe) { |
| 4160 | if (of_property_read_u32((&pdev->dev)->of_node, |
| 4161 | "qcom,file-encrypt-pipe-pair", |
| 4162 | &qseecom.ce_info.disk_encrypt_pipe)) { |
| 4163 | pr_err("Fail to get PFE pipe information.\n"); |
| 4164 | rc = -EINVAL; |
| 4165 | goto exit_destroy_ion_client; |
| 4166 | } else { |
| 4167 | pr_warn("file-encrypt-pipe-pair=0x%x", |
| 4168 | qseecom.ce_info.file_encrypt_pipe); |
| 4169 | } |
| 4170 | } else { |
| 4171 | pr_warn("Device does not support PFE"); |
| 4172 | qseecom.ce_info.file_encrypt_pipe = 0xff; |
| 4173 | } |
| 4174 | if (qseecom.support_pfe || qseecom.support_fde) { |
| 4175 | if (of_property_read_u32((&pdev->dev)->of_node, |
| 4176 | "qcom,hlos-ce-hw-instance", |
| 4177 | &qseecom.ce_info.hlos_ce_hw_instance)) { |
| 4178 | pr_err("Fail: get hlos ce hw instanc info\n"); |
| 4179 | rc = -EINVAL; |
| 4180 | goto exit_destroy_ion_client; |
| 4181 | } else { |
| 4182 | pr_warn("hlos-ce-hw-instance=0x%x", |
| 4183 | qseecom.ce_info.hlos_ce_hw_instance); |
| 4184 | } |
| 4185 | } else { |
| 4186 | pr_warn("Device does not support PFE/FDE"); |
| 4187 | qseecom.ce_info.hlos_ce_hw_instance = 0xff; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | if (of_property_read_u32((&pdev->dev)->of_node, |
| 4191 | "qcom,qsee-ce-hw-instance", |
| 4192 | &qseecom.ce_info.qsee_ce_hw_instance)) { |
| 4193 | pr_err("Fail to get qsee ce hw instance information.\n"); |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 4194 | rc = -EINVAL; |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4195 | goto exit_destroy_ion_client; |
Mona Hossain | 4cf78a9 | 2013-02-14 12:06:41 -0800 | [diff] [blame] | 4196 | } else { |
| 4197 | pr_warn("qsee-ce-hw-instance=0x%x", |
| 4198 | qseecom.ce_info.qsee_ce_hw_instance); |
| 4199 | } |
| 4200 | |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 4201 | qseecom.qsee.instance = qseecom.ce_info.qsee_ce_hw_instance; |
| 4202 | qseecom.ce_drv.instance = qseecom.ce_info.hlos_ce_hw_instance; |
| 4203 | |
| 4204 | ret = __qseecom_init_clk(CLK_QSEE); |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 4205 | if (ret) |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4206 | goto exit_destroy_ion_client; |
Mona Hossain | 6311d57 | 2013-03-01 15:54:02 -0800 | [diff] [blame] | 4207 | |
Zhen Kong | a10dcab | 2014-03-19 10:32:27 -0700 | [diff] [blame] | 4208 | if ((qseecom.qsee.instance != qseecom.ce_drv.instance) && |
| 4209 | (qseecom.support_pfe || qseecom.support_fde)) { |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 4210 | ret = __qseecom_init_clk(CLK_CE_DRV); |
| 4211 | if (ret) { |
| 4212 | __qseecom_deinit_clk(CLK_QSEE); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4213 | goto exit_destroy_ion_client; |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 4214 | } |
| 4215 | } else { |
| 4216 | struct qseecom_clk *qclk; |
| 4217 | |
| 4218 | qclk = &qseecom.qsee; |
| 4219 | qseecom.ce_drv.ce_core_clk = qclk->ce_core_clk; |
| 4220 | qseecom.ce_drv.ce_clk = qclk->ce_clk; |
| 4221 | qseecom.ce_drv.ce_core_src_clk = qclk->ce_core_src_clk; |
| 4222 | qseecom.ce_drv.ce_bus_clk = qclk->ce_bus_clk; |
| 4223 | } |
| 4224 | |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 4225 | qseecom_platform_support = (struct msm_bus_scale_pdata *) |
| 4226 | msm_bus_cl_get_pdata(pdev); |
Mona Hossain | 5b76a62 | 2012-11-15 20:09:08 -0800 | [diff] [blame] | 4227 | if (qseecom.qsee_version >= (QSEE_VERSION_02)) { |
| 4228 | struct resource *resource = NULL; |
| 4229 | struct qsee_apps_region_info_ireq req; |
| 4230 | struct qseecom_command_scm_resp resp; |
| 4231 | |
| 4232 | resource = platform_get_resource_byname(pdev, |
| 4233 | IORESOURCE_MEM, "secapp-region"); |
| 4234 | if (resource) { |
| 4235 | req.qsee_cmd_id = QSEOS_APP_REGION_NOTIFICATION; |
| 4236 | req.addr = resource->start; |
| 4237 | req.size = resource_size(resource); |
| 4238 | pr_warn("secure app region addr=0x%x size=0x%x", |
| 4239 | req.addr, req.size); |
| 4240 | } else { |
| 4241 | pr_err("Fail to get secure app region info\n"); |
| 4242 | rc = -EINVAL; |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4243 | goto exit_destroy_ion_client; |
Mona Hossain | 5b76a62 | 2012-11-15 20:09:08 -0800 | [diff] [blame] | 4244 | } |
| 4245 | rc = scm_call(SCM_SVC_TZSCHEDULER, 1, &req, sizeof(req), |
| 4246 | &resp, sizeof(resp)); |
Mona Hossain | 32deb98 | 2013-08-06 16:25:44 -0700 | [diff] [blame] | 4247 | if (rc || (resp.result != QSEOS_RESULT_SUCCESS)) { |
| 4248 | pr_err("send secapp reg fail %d resp.res %d\n", |
| 4249 | rc, resp.result); |
| 4250 | rc = -EINVAL; |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4251 | goto exit_destroy_ion_client; |
Mona Hossain | 5b76a62 | 2012-11-15 20:09:08 -0800 | [diff] [blame] | 4252 | } |
| 4253 | } |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 4254 | } else { |
Ramesh Masavarapu | fb1f01e | 2012-06-14 09:40:40 -0700 | [diff] [blame] | 4255 | qseecom_platform_support = (struct msm_bus_scale_pdata *) |
| 4256 | pdev->dev.platform_data; |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4257 | } |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 4258 | if (qseecom.support_bus_scaling) { |
| 4259 | init_timer(&(qseecom.bw_scale_down_timer)); |
| 4260 | INIT_WORK(&qseecom.bw_inactive_req_ws, |
| 4261 | qseecom_bw_inactive_req_work); |
| 4262 | qseecom.bw_scale_down_timer.function = |
| 4263 | qseecom_scale_bus_bandwidth_timer_callback; |
| 4264 | } |
Zhen Kong | ea5d4bb | 2014-02-18 14:59:53 -0800 | [diff] [blame] | 4265 | qseecom.timer_running = false; |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4266 | qseecom.qsee_perf_client = msm_bus_scale_register_client( |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 4267 | qseecom_platform_support); |
| 4268 | |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4269 | if (!qseecom.qsee_perf_client) |
Ramesh Masavarapu | ff37703 | 2012-09-14 12:11:32 -0700 | [diff] [blame] | 4270 | pr_err("Unable to register bus client\n"); |
| 4271 | return 0; |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4272 | |
| 4273 | exit_destroy_ion_client: |
| 4274 | ion_client_destroy(qseecom.ion_clnt); |
| 4275 | exit_del_cdev: |
| 4276 | cdev_del(&qseecom.cdev); |
| 4277 | exit_destroy_device: |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4278 | device_destroy(driver_class, qseecom_device_no); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4279 | exit_destroy_class: |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4280 | class_destroy(driver_class); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4281 | exit_unreg_chrdev_region: |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4282 | unregister_chrdev_region(qseecom_device_no, 1); |
| 4283 | return rc; |
| 4284 | } |
| 4285 | |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 4286 | static int __devinit qseecom_remove(struct platform_device *pdev) |
| 4287 | { |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4288 | struct qseecom_registered_kclient_list *kclient = NULL; |
| 4289 | unsigned long flags = 0; |
| 4290 | int ret = 0; |
| 4291 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4292 | spin_lock_irqsave(&qseecom.registered_kclient_list_lock, flags); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4293 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4294 | list_for_each_entry(kclient, &qseecom.registered_kclient_list_head, |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4295 | list) { |
| 4296 | if (!kclient) |
| 4297 | goto exit_irqrestore; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4298 | |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4299 | /* Break the loop if client handle is NULL */ |
| 4300 | if (!kclient->handle) |
| 4301 | goto exit_free_kclient; |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4302 | |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4303 | if (list_empty(&kclient->list)) |
| 4304 | goto exit_free_kc_handle; |
| 4305 | |
| 4306 | list_del(&kclient->list); |
Hariprasad Dhalinarasimha | bd0c545 | 2013-06-21 18:40:50 -0700 | [diff] [blame] | 4307 | ret = qseecom_unload_app(kclient->handle->dev, false); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4308 | if (!ret) { |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4309 | kzfree(kclient->handle->dev); |
| 4310 | kzfree(kclient->handle); |
| 4311 | kzfree(kclient); |
| 4312 | } |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4313 | } |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4314 | |
| 4315 | exit_free_kc_handle: |
| 4316 | kzfree(kclient->handle); |
| 4317 | exit_free_kclient: |
| 4318 | kzfree(kclient); |
| 4319 | exit_irqrestore: |
| 4320 | spin_unlock_irqrestore(&qseecom.registered_kclient_list_lock, flags); |
| 4321 | |
| 4322 | if (qseecom.qseos_version > QSEEE_VERSION_00) |
Mona Hossain | 05c7356 | 2012-10-29 17:49:01 -0700 | [diff] [blame] | 4323 | qseecom_unload_commonlib_image(); |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 4324 | |
Mona Hossain | 17a4faf | 2013-03-22 16:40:56 -0700 | [diff] [blame] | 4325 | if (qseecom.qsee_perf_client) |
| 4326 | msm_bus_scale_client_update_request(qseecom.qsee_perf_client, |
| 4327 | 0); |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4328 | if (pdev->dev.platform_data != NULL) |
| 4329 | msm_bus_scale_unregister_client(qseecom.qsee_perf_client); |
| 4330 | |
Zhen Kong | 2edf90d | 2013-08-27 12:05:06 -0700 | [diff] [blame] | 4331 | if (qseecom.support_bus_scaling) { |
| 4332 | cancel_work_sync(&qseecom.bw_inactive_req_ws); |
| 4333 | del_timer_sync(&qseecom.bw_scale_down_timer); |
| 4334 | } |
| 4335 | |
Mona Hossain | d39e33b | 2012-11-05 13:36:40 -0800 | [diff] [blame] | 4336 | /* register client for bus scaling */ |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 4337 | if (pdev->dev.of_node) { |
| 4338 | __qseecom_deinit_clk(CLK_QSEE); |
Zhen Kong | a10dcab | 2014-03-19 10:32:27 -0700 | [diff] [blame] | 4339 | if ((qseecom.qsee.instance != qseecom.ce_drv.instance) && |
| 4340 | (qseecom.support_pfe || qseecom.support_fde)) |
Mona Hossain | c92629e | 2013-04-01 13:37:46 -0700 | [diff] [blame] | 4341 | __qseecom_deinit_clk(CLK_CE_DRV); |
| 4342 | } |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4343 | |
| 4344 | ion_client_destroy(qseecom.ion_clnt); |
| 4345 | |
| 4346 | cdev_del(&qseecom.cdev); |
| 4347 | |
| 4348 | device_destroy(driver_class, qseecom_device_no); |
| 4349 | |
| 4350 | class_destroy(driver_class); |
| 4351 | |
| 4352 | unregister_chrdev_region(qseecom_device_no, 1); |
| 4353 | |
Mona Hossain | d44a384 | 2012-10-15 09:41:35 -0700 | [diff] [blame] | 4354 | return ret; |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4355 | } |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 4356 | |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4357 | static int qseecom_suspend(struct platform_device *pdev, pm_message_t state) |
| 4358 | { |
| 4359 | int ret = 0; |
| 4360 | struct qseecom_clk *qclk; |
| 4361 | qclk = &qseecom.qsee; |
| 4362 | |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4363 | mutex_lock(&qsee_bw_mutex); |
| 4364 | mutex_lock(&clk_access_lock); |
| 4365 | |
| 4366 | if (qseecom.cumulative_mode != INACTIVE && |
| 4367 | qseecom.current_mode != INACTIVE) { |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 4368 | ret = msm_bus_scale_client_update_request( |
| 4369 | qseecom.qsee_perf_client, INACTIVE); |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4370 | if (ret) |
| 4371 | pr_err("Fail to scale down bus\n"); |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4372 | else |
| 4373 | qseecom.current_mode = INACTIVE; |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4374 | } |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4375 | |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4376 | if (qclk->clk_access_cnt) { |
| 4377 | if (qclk->ce_clk != NULL) |
| 4378 | clk_disable_unprepare(qclk->ce_clk); |
| 4379 | if (qclk->ce_core_clk != NULL) |
| 4380 | clk_disable_unprepare(qclk->ce_core_clk); |
| 4381 | if (qclk->ce_bus_clk != NULL) |
| 4382 | clk_disable_unprepare(qclk->ce_bus_clk); |
| 4383 | } |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4384 | |
| 4385 | del_timer_sync(&(qseecom.bw_scale_down_timer)); |
| 4386 | qseecom.timer_running = false; |
| 4387 | |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4388 | mutex_unlock(&clk_access_lock); |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4389 | mutex_unlock(&qsee_bw_mutex); |
| 4390 | |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4391 | return 0; |
| 4392 | } |
| 4393 | |
| 4394 | static int qseecom_resume(struct platform_device *pdev) |
| 4395 | { |
| 4396 | int mode = 0; |
| 4397 | int ret = 0; |
| 4398 | struct qseecom_clk *qclk; |
| 4399 | qclk = &qseecom.qsee; |
| 4400 | |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4401 | mutex_lock(&qsee_bw_mutex); |
| 4402 | mutex_lock(&clk_access_lock); |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4403 | if (qseecom.cumulative_mode >= HIGH) |
| 4404 | mode = HIGH; |
| 4405 | else |
| 4406 | mode = qseecom.cumulative_mode; |
| 4407 | |
| 4408 | if (qseecom.cumulative_mode != INACTIVE) { |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 4409 | ret = msm_bus_scale_client_update_request( |
Zhen Kong | 98b0e51 | 2014-04-04 10:12:24 -0700 | [diff] [blame] | 4410 | qseecom.qsee_perf_client, mode); |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4411 | if (ret) |
Zhen Kong | 98b0e51 | 2014-04-04 10:12:24 -0700 | [diff] [blame] | 4412 | pr_err("Fail to scale up bus to %d\n", mode); |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4413 | else |
| 4414 | qseecom.current_mode = mode; |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4415 | } |
| 4416 | |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4417 | if (qclk->clk_access_cnt) { |
| 4418 | |
| 4419 | ret = clk_prepare_enable(qclk->ce_core_clk); |
| 4420 | if (ret) { |
| 4421 | pr_err("Unable to enable/prepare CE core clk\n"); |
| 4422 | qclk->clk_access_cnt = 0; |
| 4423 | goto err; |
| 4424 | } |
| 4425 | |
| 4426 | ret = clk_prepare_enable(qclk->ce_clk); |
| 4427 | if (ret) { |
| 4428 | pr_err("Unable to enable/prepare CE iface clk\n"); |
| 4429 | qclk->clk_access_cnt = 0; |
| 4430 | goto ce_clk_err; |
| 4431 | } |
| 4432 | |
| 4433 | ret = clk_prepare_enable(qclk->ce_bus_clk); |
| 4434 | if (ret) { |
| 4435 | pr_err("Unable to enable/prepare CE bus clk\n"); |
| 4436 | qclk->clk_access_cnt = 0; |
| 4437 | goto ce_bus_clk_err; |
| 4438 | } |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | if (qclk->clk_access_cnt || qseecom.cumulative_mode) { |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 4442 | qseecom.bw_scale_down_timer.expires = jiffies + |
| 4443 | msecs_to_jiffies(QSEECOM_SEND_CMD_CRYPTO_TIMEOUT); |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4444 | mod_timer(&(qseecom.bw_scale_down_timer), |
| 4445 | qseecom.bw_scale_down_timer.expires); |
Zhen Kong | ca4c2d5 | 2014-03-12 13:22:46 -0700 | [diff] [blame] | 4446 | qseecom.timer_running = true; |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4447 | } |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4448 | |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4449 | mutex_unlock(&clk_access_lock); |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4450 | mutex_unlock(&qsee_bw_mutex); |
| 4451 | |
| 4452 | |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4453 | return 0; |
| 4454 | |
| 4455 | ce_bus_clk_err: |
| 4456 | clk_disable_unprepare(qclk->ce_clk); |
| 4457 | ce_clk_err: |
| 4458 | clk_disable_unprepare(qclk->ce_core_clk); |
| 4459 | err: |
| 4460 | mutex_unlock(&clk_access_lock); |
Zhen Kong | e5b434e | 2014-04-17 16:47:06 -0700 | [diff] [blame] | 4461 | mutex_unlock(&qsee_bw_mutex); |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4462 | return -EIO; |
| 4463 | } |
Ramesh Masavarapu | fb1f01e | 2012-06-14 09:40:40 -0700 | [diff] [blame] | 4464 | static struct of_device_id qseecom_match[] = { |
| 4465 | { |
| 4466 | .compatible = "qcom,qseecom", |
| 4467 | }, |
| 4468 | {} |
| 4469 | }; |
| 4470 | |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 4471 | static struct platform_driver qseecom_plat_driver = { |
| 4472 | .probe = qseecom_probe, |
| 4473 | .remove = qseecom_remove, |
Zhen Kong | a0944b8 | 2013-11-06 17:02:00 -0800 | [diff] [blame] | 4474 | .suspend = qseecom_suspend, |
| 4475 | .resume = qseecom_resume, |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 4476 | .driver = { |
| 4477 | .name = "qseecom", |
| 4478 | .owner = THIS_MODULE, |
Ramesh Masavarapu | fb1f01e | 2012-06-14 09:40:40 -0700 | [diff] [blame] | 4479 | .of_match_table = qseecom_match, |
Ramesh Masavarapu | a26cce7 | 2012-04-09 12:32:25 -0700 | [diff] [blame] | 4480 | }, |
| 4481 | }; |
| 4482 | |
| 4483 | static int __devinit qseecom_init(void) |
| 4484 | { |
| 4485 | return platform_driver_register(&qseecom_plat_driver); |
| 4486 | } |
| 4487 | |
| 4488 | static void __devexit qseecom_exit(void) |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4489 | { |
AnilKumar Chimata | a253a03 | 2013-10-04 18:53:42 +0530 | [diff] [blame] | 4490 | platform_driver_unregister(&qseecom_plat_driver); |
Mona Hossain | 2892b6b | 2012-02-17 13:53:11 -0800 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | MODULE_LICENSE("GPL v2"); |
| 4494 | MODULE_DESCRIPTION("Qualcomm Secure Execution Environment Communicator"); |
| 4495 | |
| 4496 | module_init(qseecom_init); |
| 4497 | module_exit(qseecom_exit); |