Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1 | /* |
Tharun Kumar Merugu | bcd6fbf | 2018-01-04 17:49:34 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | #include <linux/dma-buf.h> |
| 15 | #include <linux/dma-mapping.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/completion.h> |
| 18 | #include <linux/pagemap.h> |
| 19 | #include <linux/mm.h> |
| 20 | #include <linux/fs.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/cdev.h> |
| 24 | #include <linux/list.h> |
| 25 | #include <linux/hash.h> |
| 26 | #include <linux/msm_ion.h> |
| 27 | #include <soc/qcom/secure_buffer.h> |
| 28 | #include <soc/qcom/glink.h> |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 29 | #include <soc/qcom/smd.h> |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 30 | #include <soc/qcom/subsystem_notif.h> |
| 31 | #include <soc/qcom/subsystem_restart.h> |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 32 | #include <soc/qcom/service-notifier.h> |
| 33 | #include <soc/qcom/service-locator.h> |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 34 | #include <linux/scatterlist.h> |
| 35 | #include <linux/fs.h> |
| 36 | #include <linux/uaccess.h> |
| 37 | #include <linux/device.h> |
| 38 | #include <linux/of.h> |
| 39 | #include <linux/of_address.h> |
| 40 | #include <linux/of_platform.h> |
| 41 | #include <linux/dma-contiguous.h> |
| 42 | #include <linux/cma.h> |
| 43 | #include <linux/iommu.h> |
| 44 | #include <linux/kref.h> |
| 45 | #include <linux/sort.h> |
| 46 | #include <linux/msm_dma_iommu_mapping.h> |
| 47 | #include <asm/dma-iommu.h> |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 48 | #include <soc/qcom/scm.h> |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 49 | #include "adsprpc_compat.h" |
| 50 | #include "adsprpc_shared.h" |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 51 | #include <soc/qcom/ramdump.h> |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 52 | #include <linux/debugfs.h> |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 53 | #include <linux/pm_qos.h> |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 54 | #define TZ_PIL_PROTECT_MEM_SUBSYS_ID 0x0C |
| 55 | #define TZ_PIL_CLEAR_PROTECT_MEM_SUBSYS_ID 0x0D |
| 56 | #define TZ_PIL_AUTH_QDSP6_PROC 1 |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 57 | #define ADSP_MMAP_HEAP_ADDR 4 |
| 58 | #define ADSP_MMAP_REMOTE_HEAP_ADDR 8 |
Tharun Kumar Merugu | 35a94a5 | 2018-02-01 21:09:04 +0530 | [diff] [blame] | 59 | #define FASTRPC_DMAHANDLE_NOMAP (16) |
| 60 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 61 | #define FASTRPC_ENOSUCH 39 |
| 62 | #define VMID_SSC_Q6 5 |
| 63 | #define VMID_ADSP_Q6 6 |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 64 | #define DEBUGFS_SIZE 1024 |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 65 | |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 66 | #define AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME "audio_pdr_adsprpc" |
| 67 | #define AUDIO_PDR_ADSP_SERVICE_NAME "avs/audio" |
| 68 | |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 69 | #define SENSORS_PDR_SERVICE_LOCATION_CLIENT_NAME "sensors_pdr_adsprpc" |
| 70 | #define SENSORS_PDR_ADSP_SERVICE_NAME "tms/servreg" |
| 71 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 72 | #define RPC_TIMEOUT (5 * HZ) |
| 73 | #define BALIGN 128 |
| 74 | #define NUM_CHANNELS 4 /* adsp, mdsp, slpi, cdsp*/ |
| 75 | #define NUM_SESSIONS 9 /*8 compute, 1 cpz*/ |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 76 | #define M_FDLIST (16) |
| 77 | #define M_CRCLIST (64) |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 78 | #define SESSION_ID_INDEX (30) |
c_mtharu | fdac689 | 2017-10-12 13:09:01 +0530 | [diff] [blame] | 79 | #define FASTRPC_CTX_MAGIC (0xbeeddeed) |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 80 | #define FASTRPC_CTX_MAX (256) |
| 81 | #define FASTRPC_CTXID_MASK (0xFF0) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 82 | |
| 83 | #define IS_CACHE_ALIGNED(x) (((x) & ((L1_CACHE_BYTES)-1)) == 0) |
| 84 | |
| 85 | #define FASTRPC_LINK_STATE_DOWN (0x0) |
| 86 | #define FASTRPC_LINK_STATE_UP (0x1) |
| 87 | #define FASTRPC_LINK_DISCONNECTED (0x0) |
| 88 | #define FASTRPC_LINK_CONNECTING (0x1) |
| 89 | #define FASTRPC_LINK_CONNECTED (0x3) |
| 90 | #define FASTRPC_LINK_DISCONNECTING (0x7) |
c_mtharu | 314a420 | 2017-11-15 22:09:17 +0530 | [diff] [blame] | 91 | #define FASTRPC_LINK_REMOTE_DISCONNECTING (0x8) |
| 92 | #define FASTRPC_GLINK_INTENT_LEN (64) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 93 | |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 94 | #define PERF_KEYS \ |
| 95 | "count:flush:map:copy:glink:getargs:putargs:invalidate:invoke:tid:ptr" |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 96 | #define FASTRPC_STATIC_HANDLE_LISTENER (3) |
| 97 | #define FASTRPC_STATIC_HANDLE_MAX (20) |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 98 | #define FASTRPC_LATENCY_CTRL_ENB (1) |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 99 | |
Tharun Kumar Merugu | d1f388a | 2017-10-01 10:51:11 +0530 | [diff] [blame] | 100 | #define INIT_FILELEN_MAX (2*1024*1024) |
| 101 | #define INIT_MEMLEN_MAX (8*1024*1024) |
| 102 | |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 103 | #define PERF_END (void)0 |
| 104 | |
| 105 | #define PERF(enb, cnt, ff) \ |
| 106 | {\ |
| 107 | struct timespec startT = {0};\ |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 108 | int64_t *counter = cnt;\ |
| 109 | if (enb && counter) {\ |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 110 | getnstimeofday(&startT);\ |
| 111 | } \ |
| 112 | ff ;\ |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 113 | if (enb && counter) {\ |
| 114 | *counter += getnstimediff(&startT);\ |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 115 | } \ |
| 116 | } |
| 117 | |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 118 | #define GET_COUNTER(perf_ptr, offset) \ |
| 119 | (perf_ptr != NULL ?\ |
| 120 | (((offset >= 0) && (offset < PERF_KEY_MAX)) ?\ |
| 121 | (int64_t *)(perf_ptr + offset)\ |
| 122 | : (int64_t *)NULL) : (int64_t *)NULL) |
| 123 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 124 | static int fastrpc_glink_open(int cid); |
| 125 | static void fastrpc_glink_close(void *chan, int cid); |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 126 | static int fastrpc_pdr_notifier_cb(struct notifier_block *nb, |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 127 | unsigned long code, |
| 128 | void *data); |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 129 | static struct dentry *debugfs_root; |
| 130 | static struct dentry *debugfs_global_file; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 131 | |
| 132 | static inline uint64_t buf_page_start(uint64_t buf) |
| 133 | { |
| 134 | uint64_t start = (uint64_t) buf & PAGE_MASK; |
| 135 | return start; |
| 136 | } |
| 137 | |
| 138 | static inline uint64_t buf_page_offset(uint64_t buf) |
| 139 | { |
| 140 | uint64_t offset = (uint64_t) buf & (PAGE_SIZE - 1); |
| 141 | return offset; |
| 142 | } |
| 143 | |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 144 | static inline uint64_t buf_num_pages(uint64_t buf, size_t len) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 145 | { |
| 146 | uint64_t start = buf_page_start(buf) >> PAGE_SHIFT; |
| 147 | uint64_t end = (((uint64_t) buf + len - 1) & PAGE_MASK) >> PAGE_SHIFT; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 148 | uint64_t nPages = end - start + 1; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 149 | return nPages; |
| 150 | } |
| 151 | |
| 152 | static inline uint64_t buf_page_size(uint32_t size) |
| 153 | { |
| 154 | uint64_t sz = (size + (PAGE_SIZE - 1)) & PAGE_MASK; |
| 155 | |
| 156 | return sz > PAGE_SIZE ? sz : PAGE_SIZE; |
| 157 | } |
| 158 | |
| 159 | static inline void *uint64_to_ptr(uint64_t addr) |
| 160 | { |
| 161 | void *ptr = (void *)((uintptr_t)addr); |
| 162 | |
| 163 | return ptr; |
| 164 | } |
| 165 | |
| 166 | static inline uint64_t ptr_to_uint64(void *ptr) |
| 167 | { |
| 168 | uint64_t addr = (uint64_t)((uintptr_t)ptr); |
| 169 | |
| 170 | return addr; |
| 171 | } |
| 172 | |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 173 | struct secure_vm { |
| 174 | int *vmid; |
| 175 | int *vmperm; |
| 176 | int vmcount; |
| 177 | }; |
| 178 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 179 | struct fastrpc_file; |
| 180 | |
| 181 | struct fastrpc_buf { |
| 182 | struct hlist_node hn; |
| 183 | struct fastrpc_file *fl; |
| 184 | void *virt; |
| 185 | uint64_t phys; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 186 | size_t size; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | struct fastrpc_ctx_lst; |
| 190 | |
| 191 | struct overlap { |
| 192 | uintptr_t start; |
| 193 | uintptr_t end; |
| 194 | int raix; |
| 195 | uintptr_t mstart; |
| 196 | uintptr_t mend; |
| 197 | uintptr_t offset; |
| 198 | }; |
| 199 | |
| 200 | struct smq_invoke_ctx { |
| 201 | struct hlist_node hn; |
| 202 | struct completion work; |
| 203 | int retval; |
| 204 | int pid; |
| 205 | int tgid; |
| 206 | remote_arg_t *lpra; |
| 207 | remote_arg64_t *rpra; |
| 208 | int *fds; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 209 | struct fastrpc_mmap **maps; |
| 210 | struct fastrpc_buf *buf; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 211 | size_t used; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 212 | struct fastrpc_file *fl; |
| 213 | uint32_t sc; |
| 214 | struct overlap *overs; |
| 215 | struct overlap **overps; |
| 216 | struct smq_msg msg; |
c_mtharu | fdac689 | 2017-10-12 13:09:01 +0530 | [diff] [blame] | 217 | unsigned int magic; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 218 | unsigned int *attrs; |
| 219 | uint32_t *crc; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 220 | uint64_t ctxid; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | struct fastrpc_ctx_lst { |
| 224 | struct hlist_head pending; |
| 225 | struct hlist_head interrupted; |
| 226 | }; |
| 227 | |
| 228 | struct fastrpc_smmu { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 229 | struct device *dev; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 230 | struct dma_iommu_mapping *mapping; |
| 231 | int cb; |
| 232 | int enabled; |
| 233 | int faults; |
| 234 | int secure; |
| 235 | int coherent; |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 236 | int sharedcb; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 237 | }; |
| 238 | |
| 239 | struct fastrpc_session_ctx { |
| 240 | struct device *dev; |
| 241 | struct fastrpc_smmu smmu; |
| 242 | int used; |
| 243 | }; |
| 244 | |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 245 | struct fastrpc_static_pd { |
| 246 | char *spdname; |
| 247 | struct notifier_block pdrnb; |
| 248 | struct notifier_block get_service_nb; |
| 249 | void *pdrhandle; |
| 250 | int pdrcount; |
| 251 | int prevpdrcount; |
| 252 | int ispdup; |
| 253 | }; |
| 254 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 255 | struct fastrpc_glink_info { |
| 256 | int link_state; |
| 257 | int port_state; |
| 258 | struct glink_open_config cfg; |
| 259 | struct glink_link_info link_info; |
| 260 | void *link_notify_handle; |
| 261 | }; |
| 262 | |
| 263 | struct fastrpc_channel_ctx { |
| 264 | char *name; |
| 265 | char *subsys; |
| 266 | void *chan; |
| 267 | struct device *dev; |
| 268 | struct fastrpc_session_ctx session[NUM_SESSIONS]; |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 269 | struct fastrpc_static_pd spd[NUM_SESSIONS]; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 270 | struct completion work; |
Tharun Kumar Merugu | 53a8ec9 | 2017-07-14 15:52:49 +0530 | [diff] [blame] | 271 | struct completion workport; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 272 | struct notifier_block nb; |
| 273 | struct kref kref; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 274 | int channel; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 275 | int sesscount; |
| 276 | int ssrcount; |
| 277 | void *handle; |
| 278 | int prevssrcount; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 279 | int issubsystemup; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 280 | int vmid; |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 281 | struct secure_vm rhvm; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 282 | int ramdumpenabled; |
| 283 | void *remoteheap_ramdump_dev; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 284 | struct fastrpc_glink_info link; |
| 285 | }; |
| 286 | |
| 287 | struct fastrpc_apps { |
| 288 | struct fastrpc_channel_ctx *channel; |
| 289 | struct cdev cdev; |
| 290 | struct class *class; |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 291 | struct mutex smd_mutex; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 292 | struct smq_phy_page range; |
| 293 | struct hlist_head maps; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 294 | uint32_t staticpd_flags; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 295 | dev_t dev_no; |
| 296 | int compat; |
| 297 | struct hlist_head drivers; |
| 298 | spinlock_t hlock; |
| 299 | struct ion_client *client; |
| 300 | struct device *dev; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 301 | unsigned int latency; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 302 | bool glink; |
| 303 | bool legacy; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 304 | spinlock_t ctxlock; |
| 305 | struct smq_invoke_ctx *ctxtable[FASTRPC_CTX_MAX]; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | struct fastrpc_mmap { |
| 309 | struct hlist_node hn; |
| 310 | struct fastrpc_file *fl; |
| 311 | struct fastrpc_apps *apps; |
| 312 | int fd; |
| 313 | uint32_t flags; |
| 314 | struct dma_buf *buf; |
| 315 | struct sg_table *table; |
| 316 | struct dma_buf_attachment *attach; |
| 317 | struct ion_handle *handle; |
| 318 | uint64_t phys; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 319 | size_t size; |
| 320 | uintptr_t va; |
| 321 | size_t len; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 322 | int refs; |
| 323 | uintptr_t raddr; |
| 324 | int uncached; |
| 325 | int secure; |
| 326 | uintptr_t attr; |
| 327 | }; |
| 328 | |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 329 | enum fastrpc_perfkeys { |
| 330 | PERF_COUNT = 0, |
| 331 | PERF_FLUSH = 1, |
| 332 | PERF_MAP = 2, |
| 333 | PERF_COPY = 3, |
| 334 | PERF_LINK = 4, |
| 335 | PERF_GETARGS = 5, |
| 336 | PERF_PUTARGS = 6, |
| 337 | PERF_INVARGS = 7, |
| 338 | PERF_INVOKE = 8, |
| 339 | PERF_KEY_MAX = 9, |
| 340 | }; |
| 341 | |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 342 | struct fastrpc_perf { |
| 343 | int64_t count; |
| 344 | int64_t flush; |
| 345 | int64_t map; |
| 346 | int64_t copy; |
| 347 | int64_t link; |
| 348 | int64_t getargs; |
| 349 | int64_t putargs; |
| 350 | int64_t invargs; |
| 351 | int64_t invoke; |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 352 | int64_t tid; |
| 353 | struct hlist_node hn; |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 354 | }; |
| 355 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 356 | struct fastrpc_file { |
| 357 | struct hlist_node hn; |
| 358 | spinlock_t hlock; |
| 359 | struct hlist_head maps; |
| 360 | struct hlist_head bufs; |
| 361 | struct fastrpc_ctx_lst clst; |
| 362 | struct fastrpc_session_ctx *sctx; |
| 363 | struct fastrpc_session_ctx *secsctx; |
| 364 | uint32_t mode; |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 365 | uint32_t profile; |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 366 | int sessionid; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 367 | int tgid; |
| 368 | int cid; |
| 369 | int ssrcount; |
| 370 | int pd; |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 371 | char *spdname; |
tharun kumar | 9f899ea | 2017-07-03 17:07:03 +0530 | [diff] [blame] | 372 | int file_close; |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 373 | int sharedcb; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 374 | struct fastrpc_apps *apps; |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 375 | struct hlist_head perf; |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 376 | struct dentry *debugfs_file; |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 377 | struct mutex perf_mutex; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 378 | struct pm_qos_request pm_qos_req; |
| 379 | int qos_request; |
Tharun Kumar Merugu | c31eac5 | 2018-01-02 11:42:45 +0530 | [diff] [blame] | 380 | struct mutex map_mutex; |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 381 | struct mutex fl_map_mutex; |
Tharun Kumar Merugu | 3517334 | 2018-02-08 16:13:17 +0530 | [diff] [blame] | 382 | int refcount; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | static struct fastrpc_apps gfa; |
| 386 | |
| 387 | static struct fastrpc_channel_ctx gcinfo[NUM_CHANNELS] = { |
| 388 | { |
| 389 | .name = "adsprpc-smd", |
| 390 | .subsys = "adsp", |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 391 | .channel = SMD_APPS_QDSP, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 392 | .link.link_info.edge = "lpass", |
| 393 | .link.link_info.transport = "smem", |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 394 | .spd = { |
| 395 | { |
| 396 | .spdname = |
| 397 | AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME, |
| 398 | .pdrnb.notifier_call = |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 399 | fastrpc_pdr_notifier_cb, |
| 400 | }, |
| 401 | { |
| 402 | .spdname = |
| 403 | SENSORS_PDR_SERVICE_LOCATION_CLIENT_NAME, |
| 404 | .pdrnb.notifier_call = |
| 405 | fastrpc_pdr_notifier_cb, |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 406 | } |
| 407 | }, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 408 | }, |
| 409 | { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 410 | .name = "mdsprpc-smd", |
| 411 | .subsys = "modem", |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 412 | .channel = SMD_APPS_MODEM, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 413 | .link.link_info.edge = "mpss", |
| 414 | .link.link_info.transport = "smem", |
| 415 | }, |
| 416 | { |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 417 | .name = "sdsprpc-smd", |
| 418 | .subsys = "slpi", |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 419 | .channel = SMD_APPS_DSPS, |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 420 | .link.link_info.edge = "dsps", |
| 421 | .link.link_info.transport = "smem", |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 422 | }, |
| 423 | { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 424 | .name = "cdsprpc-smd", |
| 425 | .subsys = "cdsp", |
| 426 | .link.link_info.edge = "cdsp", |
| 427 | .link.link_info.transport = "smem", |
| 428 | }, |
| 429 | }; |
| 430 | |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 431 | static int hlosvm[1] = {VMID_HLOS}; |
| 432 | static int hlosvmperm[1] = {PERM_READ | PERM_WRITE | PERM_EXEC}; |
| 433 | |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 434 | static inline int64_t getnstimediff(struct timespec *start) |
| 435 | { |
| 436 | int64_t ns; |
| 437 | struct timespec ts, b; |
| 438 | |
| 439 | getnstimeofday(&ts); |
| 440 | b = timespec_sub(ts, *start); |
| 441 | ns = timespec_to_ns(&b); |
| 442 | return ns; |
| 443 | } |
| 444 | |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 445 | static inline int64_t *getperfcounter(struct fastrpc_file *fl, int key) |
| 446 | { |
| 447 | int err = 0; |
| 448 | int64_t *val = NULL; |
| 449 | struct fastrpc_perf *perf = NULL, *fperf = NULL; |
| 450 | struct hlist_node *n = NULL; |
| 451 | |
| 452 | VERIFY(err, !IS_ERR_OR_NULL(fl)); |
| 453 | if (err) |
| 454 | goto bail; |
| 455 | |
| 456 | mutex_lock(&fl->perf_mutex); |
| 457 | hlist_for_each_entry_safe(perf, n, &fl->perf, hn) { |
| 458 | if (perf->tid == current->pid) { |
| 459 | fperf = perf; |
| 460 | break; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | if (IS_ERR_OR_NULL(fperf)) { |
| 465 | fperf = kzalloc(sizeof(*fperf), GFP_KERNEL); |
| 466 | |
| 467 | VERIFY(err, !IS_ERR_OR_NULL(fperf)); |
| 468 | if (err) { |
| 469 | mutex_unlock(&fl->perf_mutex); |
| 470 | kfree(fperf); |
| 471 | goto bail; |
| 472 | } |
| 473 | |
| 474 | fperf->tid = current->pid; |
| 475 | hlist_add_head(&fperf->hn, &fl->perf); |
| 476 | } |
| 477 | |
| 478 | val = ((int64_t *)fperf) + key; |
| 479 | mutex_unlock(&fl->perf_mutex); |
| 480 | bail: |
| 481 | return val; |
| 482 | } |
| 483 | |
| 484 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 485 | static void fastrpc_buf_free(struct fastrpc_buf *buf, int cache) |
| 486 | { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 487 | struct fastrpc_file *fl = buf == NULL ? NULL : buf->fl; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 488 | int vmid; |
| 489 | |
| 490 | if (!fl) |
| 491 | return; |
| 492 | if (cache) { |
| 493 | spin_lock(&fl->hlock); |
| 494 | hlist_add_head(&buf->hn, &fl->bufs); |
| 495 | spin_unlock(&fl->hlock); |
| 496 | return; |
| 497 | } |
| 498 | if (!IS_ERR_OR_NULL(buf->virt)) { |
| 499 | int destVM[1] = {VMID_HLOS}; |
| 500 | int destVMperm[1] = {PERM_READ | PERM_WRITE | PERM_EXEC}; |
| 501 | |
| 502 | if (fl->sctx->smmu.cb) |
| 503 | buf->phys &= ~((uint64_t)fl->sctx->smmu.cb << 32); |
| 504 | vmid = fl->apps->channel[fl->cid].vmid; |
| 505 | if (vmid) { |
| 506 | int srcVM[2] = {VMID_HLOS, vmid}; |
| 507 | |
| 508 | hyp_assign_phys(buf->phys, buf_page_size(buf->size), |
| 509 | srcVM, 2, destVM, destVMperm, 1); |
| 510 | } |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 511 | dma_free_coherent(fl->sctx->smmu.dev, buf->size, buf->virt, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 512 | buf->phys); |
| 513 | } |
| 514 | kfree(buf); |
| 515 | } |
| 516 | |
| 517 | static void fastrpc_buf_list_free(struct fastrpc_file *fl) |
| 518 | { |
| 519 | struct fastrpc_buf *buf, *free; |
| 520 | |
| 521 | do { |
| 522 | struct hlist_node *n; |
| 523 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 524 | free = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 525 | spin_lock(&fl->hlock); |
| 526 | hlist_for_each_entry_safe(buf, n, &fl->bufs, hn) { |
| 527 | hlist_del_init(&buf->hn); |
| 528 | free = buf; |
| 529 | break; |
| 530 | } |
| 531 | spin_unlock(&fl->hlock); |
| 532 | if (free) |
| 533 | fastrpc_buf_free(free, 0); |
| 534 | } while (free); |
| 535 | } |
| 536 | |
| 537 | static void fastrpc_mmap_add(struct fastrpc_mmap *map) |
| 538 | { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 539 | if (map->flags == ADSP_MMAP_HEAP_ADDR || |
| 540 | map->flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { |
| 541 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 542 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 543 | spin_lock(&me->hlock); |
| 544 | hlist_add_head(&map->hn, &me->maps); |
| 545 | spin_unlock(&me->hlock); |
| 546 | } else { |
| 547 | struct fastrpc_file *fl = map->fl; |
| 548 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 549 | hlist_add_head(&map->hn, &fl->maps); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 550 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 551 | } |
| 552 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 553 | static int fastrpc_mmap_find(struct fastrpc_file *fl, int fd, |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 554 | uintptr_t va, size_t len, int mflags, int refs, |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 555 | struct fastrpc_mmap **ppmap) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 556 | { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 557 | struct fastrpc_apps *me = &gfa; |
| 558 | struct fastrpc_mmap *match = NULL, *map = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 559 | struct hlist_node *n; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 560 | |
| 561 | if ((va + len) < va) |
| 562 | return -EOVERFLOW; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 563 | if (mflags == ADSP_MMAP_HEAP_ADDR || |
| 564 | mflags == ADSP_MMAP_REMOTE_HEAP_ADDR) { |
| 565 | spin_lock(&me->hlock); |
| 566 | hlist_for_each_entry_safe(map, n, &me->maps, hn) { |
| 567 | if (va >= map->va && |
| 568 | va + len <= map->va + map->len && |
| 569 | map->fd == fd) { |
| 570 | if (refs) |
| 571 | map->refs++; |
| 572 | match = map; |
| 573 | break; |
| 574 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 575 | } |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 576 | spin_unlock(&me->hlock); |
| 577 | } else { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 578 | hlist_for_each_entry_safe(map, n, &fl->maps, hn) { |
| 579 | if (va >= map->va && |
| 580 | va + len <= map->va + map->len && |
| 581 | map->fd == fd) { |
| 582 | if (refs) |
| 583 | map->refs++; |
| 584 | match = map; |
| 585 | break; |
| 586 | } |
| 587 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 588 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 589 | if (match) { |
| 590 | *ppmap = match; |
| 591 | return 0; |
| 592 | } |
| 593 | return -ENOTTY; |
| 594 | } |
| 595 | |
Tharun Kumar Merugu | 48d5ff3 | 2018-04-16 19:24:16 +0530 | [diff] [blame] | 596 | static int dma_alloc_memory(dma_addr_t *region_phys, size_t size) |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 597 | { |
| 598 | struct fastrpc_apps *me = &gfa; |
Tharun Kumar Merugu | 48d5ff3 | 2018-04-16 19:24:16 +0530 | [diff] [blame] | 599 | void *vaddr = NULL; |
| 600 | unsigned long dma_attrs = 0; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 601 | |
| 602 | if (me->dev == NULL) { |
| 603 | pr_err("device adsprpc-mem is not initialized\n"); |
| 604 | return -ENODEV; |
| 605 | } |
Tharun Kumar Merugu | 48d5ff3 | 2018-04-16 19:24:16 +0530 | [diff] [blame] | 606 | dma_attrs |= DMA_ATTR_SKIP_ZEROING | DMA_ATTR_NO_KERNEL_MAPPING; |
| 607 | vaddr = dma_alloc_attrs(me->dev, size, region_phys, GFP_KERNEL, |
| 608 | dma_attrs); |
| 609 | if (!vaddr) { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 610 | pr_err("ADSPRPC: Failed to allocate %x remote heap memory\n", |
| 611 | (unsigned int)size); |
| 612 | return -ENOMEM; |
| 613 | } |
| 614 | return 0; |
| 615 | } |
| 616 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 617 | static int fastrpc_mmap_remove(struct fastrpc_file *fl, uintptr_t va, |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 618 | size_t len, struct fastrpc_mmap **ppmap) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 619 | { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 620 | struct fastrpc_mmap *match = NULL, *map; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 621 | struct hlist_node *n; |
| 622 | struct fastrpc_apps *me = &gfa; |
| 623 | |
| 624 | spin_lock(&me->hlock); |
| 625 | hlist_for_each_entry_safe(map, n, &me->maps, hn) { |
| 626 | if (map->raddr == va && |
| 627 | map->raddr + map->len == va + len && |
| 628 | map->refs == 1) { |
| 629 | match = map; |
| 630 | hlist_del_init(&map->hn); |
| 631 | break; |
| 632 | } |
| 633 | } |
| 634 | spin_unlock(&me->hlock); |
| 635 | if (match) { |
| 636 | *ppmap = match; |
| 637 | return 0; |
| 638 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 639 | hlist_for_each_entry_safe(map, n, &fl->maps, hn) { |
| 640 | if (map->raddr == va && |
| 641 | map->raddr + map->len == va + len && |
| 642 | map->refs == 1) { |
| 643 | match = map; |
| 644 | hlist_del_init(&map->hn); |
| 645 | break; |
| 646 | } |
| 647 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 648 | if (match) { |
| 649 | *ppmap = match; |
| 650 | return 0; |
| 651 | } |
| 652 | return -ENOTTY; |
| 653 | } |
| 654 | |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 655 | static void fastrpc_mmap_free(struct fastrpc_mmap *map, uint32_t flags) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 656 | { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 657 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 658 | struct fastrpc_file *fl; |
| 659 | int vmid; |
| 660 | struct fastrpc_session_ctx *sess; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 661 | |
| 662 | if (!map) |
| 663 | return; |
| 664 | fl = map->fl; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 665 | if (map->flags == ADSP_MMAP_HEAP_ADDR || |
| 666 | map->flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { |
| 667 | spin_lock(&me->hlock); |
| 668 | map->refs--; |
| 669 | if (!map->refs) |
| 670 | hlist_del_init(&map->hn); |
| 671 | spin_unlock(&me->hlock); |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 672 | if (map->refs > 0) |
| 673 | return; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 674 | } else { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 675 | map->refs--; |
| 676 | if (!map->refs) |
| 677 | hlist_del_init(&map->hn); |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 678 | if (map->refs > 0 && !flags) |
| 679 | return; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 680 | } |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 681 | if (map->flags == ADSP_MMAP_HEAP_ADDR || |
| 682 | map->flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { |
Tharun Kumar Merugu | 48d5ff3 | 2018-04-16 19:24:16 +0530 | [diff] [blame] | 683 | unsigned long dma_attrs = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 684 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 685 | if (me->dev == NULL) { |
| 686 | pr_err("failed to free remote heap allocation\n"); |
| 687 | return; |
| 688 | } |
| 689 | if (map->phys) { |
Tharun Kumar Merugu | 48d5ff3 | 2018-04-16 19:24:16 +0530 | [diff] [blame] | 690 | dma_attrs |= |
| 691 | DMA_ATTR_SKIP_ZEROING | DMA_ATTR_NO_KERNEL_MAPPING; |
| 692 | dma_free_attrs(me->dev, map->size, (void *)map->va, |
| 693 | (dma_addr_t)map->phys, dma_attrs); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 694 | } |
Tharun Kumar Merugu | 35a94a5 | 2018-02-01 21:09:04 +0530 | [diff] [blame] | 695 | } else if (map->flags == FASTRPC_DMAHANDLE_NOMAP) { |
| 696 | if (!IS_ERR_OR_NULL(map->handle)) |
| 697 | ion_free(fl->apps->client, map->handle); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 698 | } else { |
| 699 | int destVM[1] = {VMID_HLOS}; |
| 700 | int destVMperm[1] = {PERM_READ | PERM_WRITE | PERM_EXEC}; |
| 701 | |
| 702 | if (map->secure) |
| 703 | sess = fl->secsctx; |
| 704 | else |
| 705 | sess = fl->sctx; |
| 706 | |
| 707 | if (!IS_ERR_OR_NULL(map->handle)) |
| 708 | ion_free(fl->apps->client, map->handle); |
| 709 | if (sess && sess->smmu.enabled) { |
| 710 | if (map->size || map->phys) |
| 711 | msm_dma_unmap_sg(sess->smmu.dev, |
| 712 | map->table->sgl, |
| 713 | map->table->nents, DMA_BIDIRECTIONAL, |
| 714 | map->buf); |
| 715 | } |
| 716 | vmid = fl->apps->channel[fl->cid].vmid; |
| 717 | if (vmid && map->phys) { |
| 718 | int srcVM[2] = {VMID_HLOS, vmid}; |
| 719 | |
| 720 | hyp_assign_phys(map->phys, buf_page_size(map->size), |
| 721 | srcVM, 2, destVM, destVMperm, 1); |
| 722 | } |
| 723 | |
| 724 | if (!IS_ERR_OR_NULL(map->table)) |
| 725 | dma_buf_unmap_attachment(map->attach, map->table, |
| 726 | DMA_BIDIRECTIONAL); |
| 727 | if (!IS_ERR_OR_NULL(map->attach)) |
| 728 | dma_buf_detach(map->buf, map->attach); |
| 729 | if (!IS_ERR_OR_NULL(map->buf)) |
| 730 | dma_buf_put(map->buf); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 731 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 732 | kfree(map); |
| 733 | } |
| 734 | |
| 735 | static int fastrpc_session_alloc(struct fastrpc_channel_ctx *chan, int secure, |
| 736 | struct fastrpc_session_ctx **session); |
| 737 | |
| 738 | static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd, |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 739 | unsigned int attr, uintptr_t va, size_t len, int mflags, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 740 | struct fastrpc_mmap **ppmap) |
| 741 | { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 742 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 743 | struct fastrpc_session_ctx *sess; |
| 744 | struct fastrpc_apps *apps = fl->apps; |
| 745 | int cid = fl->cid; |
| 746 | struct fastrpc_channel_ctx *chan = &apps->channel[cid]; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 747 | struct fastrpc_mmap *map = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 748 | unsigned long attrs; |
c_mtharu | f931ff9 | 2017-11-30 19:35:30 +0530 | [diff] [blame] | 749 | dma_addr_t region_phys = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 750 | unsigned long flags; |
| 751 | int err = 0, vmid; |
| 752 | |
Sathish Ambley | ae5ee54 | 2017-01-16 22:24:23 -0800 | [diff] [blame] | 753 | if (!fastrpc_mmap_find(fl, fd, va, len, mflags, 1, ppmap)) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 754 | return 0; |
| 755 | map = kzalloc(sizeof(*map), GFP_KERNEL); |
| 756 | VERIFY(err, !IS_ERR_OR_NULL(map)); |
| 757 | if (err) |
| 758 | goto bail; |
| 759 | INIT_HLIST_NODE(&map->hn); |
| 760 | map->flags = mflags; |
| 761 | map->refs = 1; |
| 762 | map->fl = fl; |
| 763 | map->fd = fd; |
| 764 | map->attr = attr; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 765 | if (mflags == ADSP_MMAP_HEAP_ADDR || |
| 766 | mflags == ADSP_MMAP_REMOTE_HEAP_ADDR) { |
| 767 | map->apps = me; |
| 768 | map->fl = NULL; |
Tharun Kumar Merugu | 48d5ff3 | 2018-04-16 19:24:16 +0530 | [diff] [blame] | 769 | VERIFY(err, !dma_alloc_memory(®ion_phys, len)); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 770 | if (err) |
| 771 | goto bail; |
c_mtharu | f931ff9 | 2017-11-30 19:35:30 +0530 | [diff] [blame] | 772 | map->phys = (uintptr_t)region_phys; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 773 | map->size = len; |
Tharun Kumar Merugu | 48d5ff3 | 2018-04-16 19:24:16 +0530 | [diff] [blame] | 774 | map->va = (uintptr_t)map->phys; |
Tharun Kumar Merugu | 35a94a5 | 2018-02-01 21:09:04 +0530 | [diff] [blame] | 775 | } else if (mflags == FASTRPC_DMAHANDLE_NOMAP) { |
| 776 | ion_phys_addr_t iphys; |
| 777 | |
| 778 | VERIFY(err, !IS_ERR_OR_NULL(map->handle = |
| 779 | ion_import_dma_buf_fd(fl->apps->client, fd))); |
| 780 | if (err) |
| 781 | goto bail; |
| 782 | |
| 783 | map->uncached = 1; |
| 784 | map->buf = NULL; |
| 785 | map->attach = NULL; |
| 786 | map->table = NULL; |
| 787 | map->va = 0; |
| 788 | map->phys = 0; |
| 789 | |
| 790 | err = ion_phys(fl->apps->client, map->handle, |
| 791 | &iphys, &map->size); |
| 792 | if (err) |
| 793 | goto bail; |
| 794 | map->phys = (uint64_t)iphys; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 795 | } else { |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 796 | if (map->attr && (map->attr & FASTRPC_ATTR_KEEP_MAP)) { |
| 797 | pr_info("adsprpc: buffer mapped with persist attr %x\n", |
| 798 | (unsigned int)map->attr); |
| 799 | map->refs = 2; |
| 800 | } |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 801 | VERIFY(err, !IS_ERR_OR_NULL(map->handle = |
| 802 | ion_import_dma_buf_fd(fl->apps->client, fd))); |
| 803 | if (err) |
| 804 | goto bail; |
| 805 | VERIFY(err, !ion_handle_get_flags(fl->apps->client, map->handle, |
| 806 | &flags)); |
| 807 | if (err) |
| 808 | goto bail; |
| 809 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 810 | map->secure = flags & ION_FLAG_SECURE; |
| 811 | if (map->secure) { |
| 812 | if (!fl->secsctx) |
| 813 | err = fastrpc_session_alloc(chan, 1, |
| 814 | &fl->secsctx); |
| 815 | if (err) |
| 816 | goto bail; |
| 817 | } |
| 818 | if (map->secure) |
| 819 | sess = fl->secsctx; |
| 820 | else |
| 821 | sess = fl->sctx; |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 822 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 823 | VERIFY(err, !IS_ERR_OR_NULL(sess)); |
| 824 | if (err) |
| 825 | goto bail; |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 826 | |
| 827 | map->uncached = !ION_IS_CACHED(flags); |
| 828 | if (map->attr & FASTRPC_ATTR_NOVA && !sess->smmu.coherent) |
| 829 | map->uncached = 1; |
| 830 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 831 | VERIFY(err, !IS_ERR_OR_NULL(map->buf = dma_buf_get(fd))); |
| 832 | if (err) |
| 833 | goto bail; |
| 834 | VERIFY(err, !IS_ERR_OR_NULL(map->attach = |
| 835 | dma_buf_attach(map->buf, sess->smmu.dev))); |
| 836 | if (err) |
| 837 | goto bail; |
| 838 | VERIFY(err, !IS_ERR_OR_NULL(map->table = |
| 839 | dma_buf_map_attachment(map->attach, |
| 840 | DMA_BIDIRECTIONAL))); |
| 841 | if (err) |
| 842 | goto bail; |
| 843 | if (sess->smmu.enabled) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 844 | attrs = DMA_ATTR_EXEC_MAPPING; |
Tharun Kumar Merugu | 2e5f12e | 2017-07-06 12:04:40 +0530 | [diff] [blame] | 845 | |
| 846 | if (map->attr & FASTRPC_ATTR_NON_COHERENT || |
| 847 | (sess->smmu.coherent && map->uncached)) |
| 848 | attrs |= DMA_ATTR_FORCE_NON_COHERENT; |
| 849 | else if (map->attr & FASTRPC_ATTR_COHERENT) |
| 850 | attrs |= DMA_ATTR_FORCE_COHERENT; |
| 851 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 852 | VERIFY(err, map->table->nents == |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 853 | msm_dma_map_sg_attrs(sess->smmu.dev, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 854 | map->table->sgl, map->table->nents, |
| 855 | DMA_BIDIRECTIONAL, map->buf, attrs)); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 856 | if (err) |
| 857 | goto bail; |
| 858 | } else { |
| 859 | VERIFY(err, map->table->nents == 1); |
| 860 | if (err) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 861 | goto bail; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 862 | } |
| 863 | map->phys = sg_dma_address(map->table->sgl); |
Tharun Kumar Merugu | 93f319a | 2018-02-01 17:35:42 +0530 | [diff] [blame] | 864 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 865 | if (sess->smmu.cb) { |
| 866 | map->phys += ((uint64_t)sess->smmu.cb << 32); |
| 867 | map->size = sg_dma_len(map->table->sgl); |
| 868 | } else { |
| 869 | map->size = buf_page_size(len); |
| 870 | } |
Tharun Kumar Merugu | 93f319a | 2018-02-01 17:35:42 +0530 | [diff] [blame] | 871 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 872 | vmid = fl->apps->channel[fl->cid].vmid; |
Tharun Kumar Merugu | 93f319a | 2018-02-01 17:35:42 +0530 | [diff] [blame] | 873 | if (!sess->smmu.enabled && !vmid) { |
| 874 | VERIFY(err, map->phys >= me->range.addr && |
| 875 | map->phys + map->size <= |
| 876 | me->range.addr + me->range.size); |
| 877 | if (err) { |
| 878 | pr_err("adsprpc: mmap fail out of range\n"); |
| 879 | goto bail; |
| 880 | } |
| 881 | } |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 882 | if (vmid) { |
| 883 | int srcVM[1] = {VMID_HLOS}; |
| 884 | int destVM[2] = {VMID_HLOS, vmid}; |
| 885 | int destVMperm[2] = {PERM_READ | PERM_WRITE, |
| 886 | PERM_READ | PERM_WRITE | PERM_EXEC}; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 887 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 888 | VERIFY(err, !hyp_assign_phys(map->phys, |
| 889 | buf_page_size(map->size), |
| 890 | srcVM, 1, destVM, destVMperm, 2)); |
| 891 | if (err) |
| 892 | goto bail; |
| 893 | } |
| 894 | map->va = va; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 895 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 896 | map->len = len; |
| 897 | |
| 898 | fastrpc_mmap_add(map); |
| 899 | *ppmap = map; |
| 900 | |
| 901 | bail: |
| 902 | if (err && map) |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 903 | fastrpc_mmap_free(map, 0); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 904 | return err; |
| 905 | } |
| 906 | |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 907 | static int fastrpc_buf_alloc(struct fastrpc_file *fl, size_t size, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 908 | struct fastrpc_buf **obuf) |
| 909 | { |
| 910 | int err = 0, vmid; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 911 | struct fastrpc_buf *buf = NULL, *fr = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 912 | struct hlist_node *n; |
| 913 | |
| 914 | VERIFY(err, size > 0); |
| 915 | if (err) |
| 916 | goto bail; |
| 917 | |
| 918 | /* find the smallest buffer that fits in the cache */ |
| 919 | spin_lock(&fl->hlock); |
| 920 | hlist_for_each_entry_safe(buf, n, &fl->bufs, hn) { |
| 921 | if (buf->size >= size && (!fr || fr->size > buf->size)) |
| 922 | fr = buf; |
| 923 | } |
| 924 | if (fr) |
| 925 | hlist_del_init(&fr->hn); |
| 926 | spin_unlock(&fl->hlock); |
| 927 | if (fr) { |
| 928 | *obuf = fr; |
| 929 | return 0; |
| 930 | } |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 931 | buf = NULL; |
| 932 | VERIFY(err, NULL != (buf = kzalloc(sizeof(*buf), GFP_KERNEL))); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 933 | if (err) |
| 934 | goto bail; |
| 935 | INIT_HLIST_NODE(&buf->hn); |
| 936 | buf->fl = fl; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 937 | buf->virt = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 938 | buf->phys = 0; |
| 939 | buf->size = size; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 940 | buf->virt = dma_alloc_coherent(fl->sctx->smmu.dev, buf->size, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 941 | (void *)&buf->phys, GFP_KERNEL); |
| 942 | if (IS_ERR_OR_NULL(buf->virt)) { |
| 943 | /* free cache and retry */ |
| 944 | fastrpc_buf_list_free(fl); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 945 | buf->virt = dma_alloc_coherent(fl->sctx->smmu.dev, buf->size, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 946 | (void *)&buf->phys, GFP_KERNEL); |
| 947 | VERIFY(err, !IS_ERR_OR_NULL(buf->virt)); |
| 948 | } |
| 949 | if (err) |
| 950 | goto bail; |
| 951 | if (fl->sctx->smmu.cb) |
| 952 | buf->phys += ((uint64_t)fl->sctx->smmu.cb << 32); |
| 953 | vmid = fl->apps->channel[fl->cid].vmid; |
| 954 | if (vmid) { |
| 955 | int srcVM[1] = {VMID_HLOS}; |
| 956 | int destVM[2] = {VMID_HLOS, vmid}; |
| 957 | int destVMperm[2] = {PERM_READ | PERM_WRITE, |
| 958 | PERM_READ | PERM_WRITE | PERM_EXEC}; |
| 959 | |
| 960 | VERIFY(err, !hyp_assign_phys(buf->phys, buf_page_size(size), |
| 961 | srcVM, 1, destVM, destVMperm, 2)); |
| 962 | if (err) |
| 963 | goto bail; |
| 964 | } |
| 965 | |
| 966 | *obuf = buf; |
| 967 | bail: |
| 968 | if (err && buf) |
| 969 | fastrpc_buf_free(buf, 0); |
| 970 | return err; |
| 971 | } |
| 972 | |
| 973 | |
| 974 | static int context_restore_interrupted(struct fastrpc_file *fl, |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 975 | struct fastrpc_ioctl_invoke_crc *inv, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 976 | struct smq_invoke_ctx **po) |
| 977 | { |
| 978 | int err = 0; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 979 | struct smq_invoke_ctx *ctx = NULL, *ictx = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 980 | struct hlist_node *n; |
| 981 | struct fastrpc_ioctl_invoke *invoke = &inv->inv; |
| 982 | |
| 983 | spin_lock(&fl->hlock); |
| 984 | hlist_for_each_entry_safe(ictx, n, &fl->clst.interrupted, hn) { |
| 985 | if (ictx->pid == current->pid) { |
| 986 | if (invoke->sc != ictx->sc || ictx->fl != fl) |
| 987 | err = -1; |
| 988 | else { |
| 989 | ctx = ictx; |
| 990 | hlist_del_init(&ctx->hn); |
| 991 | hlist_add_head(&ctx->hn, &fl->clst.pending); |
| 992 | } |
| 993 | break; |
| 994 | } |
| 995 | } |
| 996 | spin_unlock(&fl->hlock); |
| 997 | if (ctx) |
| 998 | *po = ctx; |
| 999 | return err; |
| 1000 | } |
| 1001 | |
| 1002 | #define CMP(aa, bb) ((aa) == (bb) ? 0 : (aa) < (bb) ? -1 : 1) |
| 1003 | static int overlap_ptr_cmp(const void *a, const void *b) |
| 1004 | { |
| 1005 | struct overlap *pa = *((struct overlap **)a); |
| 1006 | struct overlap *pb = *((struct overlap **)b); |
| 1007 | /* sort with lowest starting buffer first */ |
| 1008 | int st = CMP(pa->start, pb->start); |
| 1009 | /* sort with highest ending buffer first */ |
| 1010 | int ed = CMP(pb->end, pa->end); |
| 1011 | return st == 0 ? ed : st; |
| 1012 | } |
| 1013 | |
Sathish Ambley | 9466d67 | 2017-01-25 10:51:55 -0800 | [diff] [blame] | 1014 | static int context_build_overlap(struct smq_invoke_ctx *ctx) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1015 | { |
Sathish Ambley | 9466d67 | 2017-01-25 10:51:55 -0800 | [diff] [blame] | 1016 | int i, err = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1017 | remote_arg_t *lpra = ctx->lpra; |
| 1018 | int inbufs = REMOTE_SCALARS_INBUFS(ctx->sc); |
| 1019 | int outbufs = REMOTE_SCALARS_OUTBUFS(ctx->sc); |
| 1020 | int nbufs = inbufs + outbufs; |
| 1021 | struct overlap max; |
| 1022 | |
| 1023 | for (i = 0; i < nbufs; ++i) { |
| 1024 | ctx->overs[i].start = (uintptr_t)lpra[i].buf.pv; |
| 1025 | ctx->overs[i].end = ctx->overs[i].start + lpra[i].buf.len; |
Sathish Ambley | 9466d67 | 2017-01-25 10:51:55 -0800 | [diff] [blame] | 1026 | if (lpra[i].buf.len) { |
| 1027 | VERIFY(err, ctx->overs[i].end > ctx->overs[i].start); |
| 1028 | if (err) |
| 1029 | goto bail; |
| 1030 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1031 | ctx->overs[i].raix = i; |
| 1032 | ctx->overps[i] = &ctx->overs[i]; |
| 1033 | } |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1034 | sort(ctx->overps, nbufs, sizeof(*ctx->overps), overlap_ptr_cmp, NULL); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1035 | max.start = 0; |
| 1036 | max.end = 0; |
| 1037 | for (i = 0; i < nbufs; ++i) { |
| 1038 | if (ctx->overps[i]->start < max.end) { |
| 1039 | ctx->overps[i]->mstart = max.end; |
| 1040 | ctx->overps[i]->mend = ctx->overps[i]->end; |
| 1041 | ctx->overps[i]->offset = max.end - |
| 1042 | ctx->overps[i]->start; |
| 1043 | if (ctx->overps[i]->end > max.end) { |
| 1044 | max.end = ctx->overps[i]->end; |
| 1045 | } else { |
| 1046 | ctx->overps[i]->mend = 0; |
| 1047 | ctx->overps[i]->mstart = 0; |
| 1048 | } |
| 1049 | } else { |
| 1050 | ctx->overps[i]->mend = ctx->overps[i]->end; |
| 1051 | ctx->overps[i]->mstart = ctx->overps[i]->start; |
| 1052 | ctx->overps[i]->offset = 0; |
| 1053 | max = *ctx->overps[i]; |
| 1054 | } |
| 1055 | } |
Sathish Ambley | 9466d67 | 2017-01-25 10:51:55 -0800 | [diff] [blame] | 1056 | bail: |
| 1057 | return err; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | #define K_COPY_FROM_USER(err, kernel, dst, src, size) \ |
| 1061 | do {\ |
| 1062 | if (!(kernel))\ |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1063 | VERIFY(err, 0 == copy_from_user((dst),\ |
| 1064 | (void const __user *)(src),\ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1065 | (size)));\ |
| 1066 | else\ |
| 1067 | memmove((dst), (src), (size));\ |
| 1068 | } while (0) |
| 1069 | |
| 1070 | #define K_COPY_TO_USER(err, kernel, dst, src, size) \ |
| 1071 | do {\ |
| 1072 | if (!(kernel))\ |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1073 | VERIFY(err, 0 == copy_to_user((void __user *)(dst),\ |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1074 | (src), (size)));\ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1075 | else\ |
| 1076 | memmove((dst), (src), (size));\ |
| 1077 | } while (0) |
| 1078 | |
| 1079 | |
| 1080 | static void context_free(struct smq_invoke_ctx *ctx); |
| 1081 | |
| 1082 | static int context_alloc(struct fastrpc_file *fl, uint32_t kernel, |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1083 | struct fastrpc_ioctl_invoke_crc *invokefd, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1084 | struct smq_invoke_ctx **po) |
| 1085 | { |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1086 | struct fastrpc_apps *me = &gfa; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1087 | int err = 0, bufs, ii, size = 0; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1088 | struct smq_invoke_ctx *ctx = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1089 | struct fastrpc_ctx_lst *clst = &fl->clst; |
| 1090 | struct fastrpc_ioctl_invoke *invoke = &invokefd->inv; |
| 1091 | |
| 1092 | bufs = REMOTE_SCALARS_LENGTH(invoke->sc); |
| 1093 | size = bufs * sizeof(*ctx->lpra) + bufs * sizeof(*ctx->maps) + |
| 1094 | sizeof(*ctx->fds) * (bufs) + |
| 1095 | sizeof(*ctx->attrs) * (bufs) + |
| 1096 | sizeof(*ctx->overs) * (bufs) + |
| 1097 | sizeof(*ctx->overps) * (bufs); |
| 1098 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1099 | VERIFY(err, NULL != (ctx = kzalloc(sizeof(*ctx) + size, GFP_KERNEL))); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1100 | if (err) |
| 1101 | goto bail; |
| 1102 | |
| 1103 | INIT_HLIST_NODE(&ctx->hn); |
| 1104 | hlist_add_fake(&ctx->hn); |
| 1105 | ctx->fl = fl; |
| 1106 | ctx->maps = (struct fastrpc_mmap **)(&ctx[1]); |
| 1107 | ctx->lpra = (remote_arg_t *)(&ctx->maps[bufs]); |
| 1108 | ctx->fds = (int *)(&ctx->lpra[bufs]); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1109 | if (me->legacy) { |
| 1110 | ctx->overs = (struct overlap *)(&ctx->fds[bufs]); |
| 1111 | ctx->overps = (struct overlap **)(&ctx->overs[bufs]); |
| 1112 | } else { |
| 1113 | ctx->attrs = (unsigned int *)(&ctx->fds[bufs]); |
| 1114 | ctx->overs = (struct overlap *)(&ctx->attrs[bufs]); |
| 1115 | ctx->overps = (struct overlap **)(&ctx->overs[bufs]); |
| 1116 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1117 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1118 | K_COPY_FROM_USER(err, kernel, (void *)ctx->lpra, invoke->pra, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1119 | bufs * sizeof(*ctx->lpra)); |
| 1120 | if (err) |
| 1121 | goto bail; |
| 1122 | |
| 1123 | if (invokefd->fds) { |
| 1124 | K_COPY_FROM_USER(err, kernel, ctx->fds, invokefd->fds, |
| 1125 | bufs * sizeof(*ctx->fds)); |
| 1126 | if (err) |
| 1127 | goto bail; |
| 1128 | } |
| 1129 | if (invokefd->attrs) { |
| 1130 | K_COPY_FROM_USER(err, kernel, ctx->attrs, invokefd->attrs, |
| 1131 | bufs * sizeof(*ctx->attrs)); |
| 1132 | if (err) |
| 1133 | goto bail; |
| 1134 | } |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1135 | ctx->crc = (uint32_t *)invokefd->crc; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1136 | ctx->sc = invoke->sc; |
Sathish Ambley | 9466d67 | 2017-01-25 10:51:55 -0800 | [diff] [blame] | 1137 | if (bufs) { |
| 1138 | VERIFY(err, 0 == context_build_overlap(ctx)); |
| 1139 | if (err) |
| 1140 | goto bail; |
| 1141 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1142 | ctx->retval = -1; |
| 1143 | ctx->pid = current->pid; |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 1144 | ctx->tgid = fl->tgid; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1145 | init_completion(&ctx->work); |
c_mtharu | fdac689 | 2017-10-12 13:09:01 +0530 | [diff] [blame] | 1146 | ctx->magic = FASTRPC_CTX_MAGIC; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1147 | |
| 1148 | spin_lock(&fl->hlock); |
| 1149 | hlist_add_head(&ctx->hn, &clst->pending); |
| 1150 | spin_unlock(&fl->hlock); |
| 1151 | |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1152 | spin_lock(&me->ctxlock); |
| 1153 | for (ii = 0; ii < FASTRPC_CTX_MAX; ii++) { |
| 1154 | if (!me->ctxtable[ii]) { |
| 1155 | me->ctxtable[ii] = ctx; |
| 1156 | ctx->ctxid = (ptr_to_uint64(ctx) & ~0xFFF)|(ii << 4); |
| 1157 | break; |
| 1158 | } |
| 1159 | } |
| 1160 | spin_unlock(&me->ctxlock); |
| 1161 | VERIFY(err, ii < FASTRPC_CTX_MAX); |
| 1162 | if (err) { |
| 1163 | pr_err("adsprpc: out of context memory\n"); |
| 1164 | goto bail; |
| 1165 | } |
| 1166 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1167 | *po = ctx; |
| 1168 | bail: |
| 1169 | if (ctx && err) |
| 1170 | context_free(ctx); |
| 1171 | return err; |
| 1172 | } |
| 1173 | |
| 1174 | static void context_save_interrupted(struct smq_invoke_ctx *ctx) |
| 1175 | { |
| 1176 | struct fastrpc_ctx_lst *clst = &ctx->fl->clst; |
| 1177 | |
| 1178 | spin_lock(&ctx->fl->hlock); |
| 1179 | hlist_del_init(&ctx->hn); |
| 1180 | hlist_add_head(&ctx->hn, &clst->interrupted); |
| 1181 | spin_unlock(&ctx->fl->hlock); |
| 1182 | /* free the cache on power collapse */ |
| 1183 | fastrpc_buf_list_free(ctx->fl); |
| 1184 | } |
| 1185 | |
| 1186 | static void context_free(struct smq_invoke_ctx *ctx) |
| 1187 | { |
| 1188 | int i; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1189 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1190 | int nbufs = REMOTE_SCALARS_INBUFS(ctx->sc) + |
| 1191 | REMOTE_SCALARS_OUTBUFS(ctx->sc); |
| 1192 | spin_lock(&ctx->fl->hlock); |
| 1193 | hlist_del_init(&ctx->hn); |
| 1194 | spin_unlock(&ctx->fl->hlock); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1195 | mutex_lock(&ctx->fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1196 | for (i = 0; i < nbufs; ++i) |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 1197 | fastrpc_mmap_free(ctx->maps[i], 0); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1198 | |
| 1199 | mutex_unlock(&ctx->fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1200 | fastrpc_buf_free(ctx->buf, 1); |
c_mtharu | fdac689 | 2017-10-12 13:09:01 +0530 | [diff] [blame] | 1201 | ctx->magic = 0; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1202 | ctx->ctxid = 0; |
| 1203 | |
| 1204 | spin_lock(&me->ctxlock); |
| 1205 | for (i = 0; i < FASTRPC_CTX_MAX; i++) { |
| 1206 | if (me->ctxtable[i] == ctx) { |
| 1207 | me->ctxtable[i] = NULL; |
| 1208 | break; |
| 1209 | } |
| 1210 | } |
| 1211 | spin_unlock(&me->ctxlock); |
| 1212 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1213 | kfree(ctx); |
| 1214 | } |
| 1215 | |
| 1216 | static void context_notify_user(struct smq_invoke_ctx *ctx, int retval) |
| 1217 | { |
| 1218 | ctx->retval = retval; |
| 1219 | complete(&ctx->work); |
| 1220 | } |
| 1221 | |
| 1222 | |
| 1223 | static void fastrpc_notify_users(struct fastrpc_file *me) |
| 1224 | { |
| 1225 | struct smq_invoke_ctx *ictx; |
| 1226 | struct hlist_node *n; |
| 1227 | |
| 1228 | spin_lock(&me->hlock); |
| 1229 | hlist_for_each_entry_safe(ictx, n, &me->clst.pending, hn) { |
| 1230 | complete(&ictx->work); |
| 1231 | } |
| 1232 | hlist_for_each_entry_safe(ictx, n, &me->clst.interrupted, hn) { |
| 1233 | complete(&ictx->work); |
| 1234 | } |
| 1235 | spin_unlock(&me->hlock); |
| 1236 | |
| 1237 | } |
| 1238 | |
Tharun Kumar Merugu | 77dd587 | 2018-04-02 12:48:17 +0530 | [diff] [blame] | 1239 | |
| 1240 | static void fastrpc_notify_users_staticpd_pdr(struct fastrpc_file *me) |
| 1241 | { |
| 1242 | struct smq_invoke_ctx *ictx; |
| 1243 | struct hlist_node *n; |
| 1244 | |
| 1245 | spin_lock(&me->hlock); |
| 1246 | hlist_for_each_entry_safe(ictx, n, &me->clst.pending, hn) { |
| 1247 | if (ictx->msg.pid) |
| 1248 | complete(&ictx->work); |
| 1249 | } |
| 1250 | hlist_for_each_entry_safe(ictx, n, &me->clst.interrupted, hn) { |
| 1251 | if (ictx->msg.pid) |
| 1252 | complete(&ictx->work); |
| 1253 | } |
| 1254 | spin_unlock(&me->hlock); |
| 1255 | } |
| 1256 | |
| 1257 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1258 | static void fastrpc_notify_drivers(struct fastrpc_apps *me, int cid) |
| 1259 | { |
| 1260 | struct fastrpc_file *fl; |
| 1261 | struct hlist_node *n; |
| 1262 | |
| 1263 | spin_lock(&me->hlock); |
| 1264 | hlist_for_each_entry_safe(fl, n, &me->drivers, hn) { |
| 1265 | if (fl->cid == cid) |
| 1266 | fastrpc_notify_users(fl); |
| 1267 | } |
| 1268 | spin_unlock(&me->hlock); |
| 1269 | |
| 1270 | } |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 1271 | |
| 1272 | static void fastrpc_notify_pdr_drivers(struct fastrpc_apps *me, char *spdname) |
| 1273 | { |
| 1274 | struct fastrpc_file *fl; |
| 1275 | struct hlist_node *n; |
| 1276 | |
| 1277 | spin_lock(&me->hlock); |
| 1278 | hlist_for_each_entry_safe(fl, n, &me->drivers, hn) { |
| 1279 | if (fl->spdname && !strcmp(spdname, fl->spdname)) |
Tharun Kumar Merugu | 77dd587 | 2018-04-02 12:48:17 +0530 | [diff] [blame] | 1280 | fastrpc_notify_users_staticpd_pdr(fl); |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 1281 | } |
| 1282 | spin_unlock(&me->hlock); |
| 1283 | |
| 1284 | } |
| 1285 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1286 | static void context_list_ctor(struct fastrpc_ctx_lst *me) |
| 1287 | { |
| 1288 | INIT_HLIST_HEAD(&me->interrupted); |
| 1289 | INIT_HLIST_HEAD(&me->pending); |
| 1290 | } |
| 1291 | |
| 1292 | static void fastrpc_context_list_dtor(struct fastrpc_file *fl) |
| 1293 | { |
| 1294 | struct fastrpc_ctx_lst *clst = &fl->clst; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1295 | struct smq_invoke_ctx *ictx = NULL, *ctxfree; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1296 | struct hlist_node *n; |
| 1297 | |
| 1298 | do { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1299 | ctxfree = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1300 | spin_lock(&fl->hlock); |
| 1301 | hlist_for_each_entry_safe(ictx, n, &clst->interrupted, hn) { |
| 1302 | hlist_del_init(&ictx->hn); |
| 1303 | ctxfree = ictx; |
| 1304 | break; |
| 1305 | } |
| 1306 | spin_unlock(&fl->hlock); |
| 1307 | if (ctxfree) |
| 1308 | context_free(ctxfree); |
| 1309 | } while (ctxfree); |
| 1310 | do { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1311 | ctxfree = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1312 | spin_lock(&fl->hlock); |
| 1313 | hlist_for_each_entry_safe(ictx, n, &clst->pending, hn) { |
| 1314 | hlist_del_init(&ictx->hn); |
| 1315 | ctxfree = ictx; |
| 1316 | break; |
| 1317 | } |
| 1318 | spin_unlock(&fl->hlock); |
| 1319 | if (ctxfree) |
| 1320 | context_free(ctxfree); |
| 1321 | } while (ctxfree); |
| 1322 | } |
| 1323 | |
| 1324 | static int fastrpc_file_free(struct fastrpc_file *fl); |
| 1325 | static void fastrpc_file_list_dtor(struct fastrpc_apps *me) |
| 1326 | { |
| 1327 | struct fastrpc_file *fl, *free; |
| 1328 | struct hlist_node *n; |
| 1329 | |
| 1330 | do { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1331 | free = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1332 | spin_lock(&me->hlock); |
| 1333 | hlist_for_each_entry_safe(fl, n, &me->drivers, hn) { |
| 1334 | hlist_del_init(&fl->hn); |
| 1335 | free = fl; |
| 1336 | break; |
| 1337 | } |
| 1338 | spin_unlock(&me->hlock); |
| 1339 | if (free) |
| 1340 | fastrpc_file_free(free); |
| 1341 | } while (free); |
| 1342 | } |
| 1343 | |
| 1344 | static int get_args(uint32_t kernel, struct smq_invoke_ctx *ctx) |
| 1345 | { |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1346 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1347 | remote_arg64_t *rpra; |
| 1348 | remote_arg_t *lpra = ctx->lpra; |
| 1349 | struct smq_invoke_buf *list; |
| 1350 | struct smq_phy_page *pages, *ipage; |
| 1351 | uint32_t sc = ctx->sc; |
| 1352 | int inbufs = REMOTE_SCALARS_INBUFS(sc); |
| 1353 | int outbufs = REMOTE_SCALARS_OUTBUFS(sc); |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1354 | int handles, bufs = inbufs + outbufs; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1355 | uintptr_t args; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 1356 | size_t rlen = 0, copylen = 0, metalen = 0; |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1357 | int i, oix; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1358 | int err = 0; |
| 1359 | int mflags = 0; |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1360 | uint64_t *fdlist; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1361 | uint32_t *crclist; |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1362 | int64_t *perf_counter = getperfcounter(ctx->fl, PERF_COUNT); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1363 | |
| 1364 | /* calculate size of the metadata */ |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1365 | rpra = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1366 | list = smq_invoke_buf_start(rpra, sc); |
| 1367 | pages = smq_phy_page_start(sc, list); |
| 1368 | ipage = pages; |
| 1369 | |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1370 | PERF(ctx->fl->profile, GET_COUNTER(perf_counter, PERF_MAP), |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1371 | for (i = 0; i < bufs; ++i) { |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 1372 | uintptr_t buf = (uintptr_t)lpra[i].buf.pv; |
| 1373 | size_t len = lpra[i].buf.len; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1374 | |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1375 | mutex_lock(&ctx->fl->fl_map_mutex); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1376 | if (ctx->fds[i] && (ctx->fds[i] != -1)) { |
| 1377 | unsigned int attrs = 0; |
| 1378 | |
| 1379 | if (ctx->attrs) |
| 1380 | attrs = ctx->attrs[i]; |
| 1381 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1382 | fastrpc_mmap_create(ctx->fl, ctx->fds[i], |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1383 | attrs, buf, len, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1384 | mflags, &ctx->maps[i]); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1385 | } |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1386 | mutex_unlock(&ctx->fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1387 | ipage += 1; |
| 1388 | } |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1389 | PERF_END); |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1390 | handles = REMOTE_SCALARS_INHANDLES(sc) + REMOTE_SCALARS_OUTHANDLES(sc); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1391 | mutex_lock(&ctx->fl->fl_map_mutex); |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1392 | for (i = bufs; i < bufs + handles; i++) { |
Tharun Kumar Merugu | 35a94a5 | 2018-02-01 21:09:04 +0530 | [diff] [blame] | 1393 | int dmaflags = 0; |
| 1394 | |
| 1395 | if (ctx->attrs && (ctx->attrs[i] & FASTRPC_ATTR_NOMAP)) |
| 1396 | dmaflags = FASTRPC_DMAHANDLE_NOMAP; |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1397 | VERIFY(err, !fastrpc_mmap_create(ctx->fl, ctx->fds[i], |
Tharun Kumar Merugu | 35a94a5 | 2018-02-01 21:09:04 +0530 | [diff] [blame] | 1398 | FASTRPC_ATTR_NOVA, 0, 0, dmaflags, &ctx->maps[i])); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1399 | if (err) { |
| 1400 | mutex_unlock(&ctx->fl->fl_map_mutex); |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1401 | goto bail; |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1402 | } |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1403 | ipage += 1; |
| 1404 | } |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1405 | mutex_unlock(&ctx->fl->fl_map_mutex); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1406 | if (!me->legacy) { |
| 1407 | metalen = copylen = (size_t)&ipage[0] + |
| 1408 | (sizeof(uint64_t) * M_FDLIST) + |
| 1409 | (sizeof(uint32_t) * M_CRCLIST); |
| 1410 | } else { |
| 1411 | metalen = copylen = (size_t)&ipage[0]; |
| 1412 | } |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1413 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1414 | /* calculate len requreed for copying */ |
| 1415 | for (oix = 0; oix < inbufs + outbufs; ++oix) { |
| 1416 | int i = ctx->overps[oix]->raix; |
Sathish Ambley | d209c1e | 2016-12-13 15:27:30 -0800 | [diff] [blame] | 1417 | uintptr_t mstart, mend; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 1418 | size_t len = lpra[i].buf.len; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1419 | |
| 1420 | if (!len) |
| 1421 | continue; |
| 1422 | if (ctx->maps[i]) |
| 1423 | continue; |
| 1424 | if (ctx->overps[oix]->offset == 0) |
| 1425 | copylen = ALIGN(copylen, BALIGN); |
Sathish Ambley | d209c1e | 2016-12-13 15:27:30 -0800 | [diff] [blame] | 1426 | mstart = ctx->overps[oix]->mstart; |
| 1427 | mend = ctx->overps[oix]->mend; |
| 1428 | VERIFY(err, (mend - mstart) <= LONG_MAX); |
| 1429 | if (err) |
| 1430 | goto bail; |
| 1431 | copylen += mend - mstart; |
| 1432 | VERIFY(err, copylen >= 0); |
| 1433 | if (err) |
| 1434 | goto bail; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1435 | } |
| 1436 | ctx->used = copylen; |
| 1437 | |
| 1438 | /* allocate new buffer */ |
| 1439 | if (copylen) { |
| 1440 | VERIFY(err, !fastrpc_buf_alloc(ctx->fl, copylen, &ctx->buf)); |
| 1441 | if (err) |
| 1442 | goto bail; |
| 1443 | } |
Tharun Kumar Merugu | e3361f9 | 2017-06-22 10:45:43 +0530 | [diff] [blame] | 1444 | if (ctx->buf->virt && metalen <= copylen) |
| 1445 | memset(ctx->buf->virt, 0, metalen); |
| 1446 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1447 | /* copy metadata */ |
| 1448 | rpra = ctx->buf->virt; |
| 1449 | ctx->rpra = rpra; |
| 1450 | list = smq_invoke_buf_start(rpra, sc); |
| 1451 | pages = smq_phy_page_start(sc, list); |
| 1452 | ipage = pages; |
| 1453 | args = (uintptr_t)ctx->buf->virt + metalen; |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1454 | for (i = 0; i < bufs + handles; ++i) { |
| 1455 | if (lpra[i].buf.len) |
| 1456 | list[i].num = 1; |
| 1457 | else |
| 1458 | list[i].num = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1459 | list[i].pgidx = ipage - pages; |
| 1460 | ipage++; |
| 1461 | } |
Tharun Kumar Merugu | d1f388a | 2017-10-01 10:51:11 +0530 | [diff] [blame] | 1462 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1463 | /* map ion buffers */ |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1464 | PERF(ctx->fl->profile, GET_COUNTER(perf_counter, PERF_MAP), |
Tharun Kumar Merugu | d1f388a | 2017-10-01 10:51:11 +0530 | [diff] [blame] | 1465 | for (i = 0; rpra && i < inbufs + outbufs; ++i) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1466 | struct fastrpc_mmap *map = ctx->maps[i]; |
| 1467 | uint64_t buf = ptr_to_uint64(lpra[i].buf.pv); |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 1468 | size_t len = lpra[i].buf.len; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1469 | |
| 1470 | rpra[i].buf.pv = 0; |
| 1471 | rpra[i].buf.len = len; |
| 1472 | if (!len) |
| 1473 | continue; |
| 1474 | if (map) { |
| 1475 | struct vm_area_struct *vma; |
| 1476 | uintptr_t offset; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 1477 | uint64_t num = buf_num_pages(buf, len); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1478 | int idx = list[i].pgidx; |
| 1479 | |
| 1480 | if (map->attr & FASTRPC_ATTR_NOVA) { |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1481 | offset = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1482 | } else { |
| 1483 | down_read(¤t->mm->mmap_sem); |
| 1484 | VERIFY(err, NULL != (vma = find_vma(current->mm, |
| 1485 | map->va))); |
| 1486 | if (err) { |
| 1487 | up_read(¤t->mm->mmap_sem); |
| 1488 | goto bail; |
| 1489 | } |
| 1490 | offset = buf_page_start(buf) - vma->vm_start; |
| 1491 | up_read(¤t->mm->mmap_sem); |
| 1492 | VERIFY(err, offset < (uintptr_t)map->size); |
| 1493 | if (err) |
| 1494 | goto bail; |
| 1495 | } |
| 1496 | pages[idx].addr = map->phys + offset; |
| 1497 | pages[idx].size = num << PAGE_SHIFT; |
| 1498 | } |
| 1499 | rpra[i].buf.pv = buf; |
| 1500 | } |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1501 | PERF_END); |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1502 | for (i = bufs; i < bufs + handles; ++i) { |
| 1503 | struct fastrpc_mmap *map = ctx->maps[i]; |
| 1504 | |
| 1505 | pages[i].addr = map->phys; |
| 1506 | pages[i].size = map->size; |
| 1507 | } |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1508 | if (!me->legacy) { |
| 1509 | fdlist = (uint64_t *)&pages[bufs + handles]; |
| 1510 | for (i = 0; i < M_FDLIST; i++) |
| 1511 | fdlist[i] = 0; |
| 1512 | crclist = (uint32_t *)&fdlist[M_FDLIST]; |
| 1513 | memset(crclist, 0, sizeof(uint32_t)*M_CRCLIST); |
| 1514 | } |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1515 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1516 | /* copy non ion buffers */ |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1517 | PERF(ctx->fl->profile, GET_COUNTER(perf_counter, PERF_COPY), |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1518 | rlen = copylen - metalen; |
Tharun Kumar Merugu | c230bd7 | 2018-01-29 18:02:42 +0530 | [diff] [blame] | 1519 | for (oix = 0; rpra && oix < inbufs + outbufs; ++oix) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1520 | int i = ctx->overps[oix]->raix; |
| 1521 | struct fastrpc_mmap *map = ctx->maps[i]; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 1522 | size_t mlen; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1523 | uint64_t buf; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 1524 | size_t len = lpra[i].buf.len; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1525 | |
| 1526 | if (!len) |
| 1527 | continue; |
| 1528 | if (map) |
| 1529 | continue; |
| 1530 | if (ctx->overps[oix]->offset == 0) { |
| 1531 | rlen -= ALIGN(args, BALIGN) - args; |
| 1532 | args = ALIGN(args, BALIGN); |
| 1533 | } |
Sathish Ambley | d209c1e | 2016-12-13 15:27:30 -0800 | [diff] [blame] | 1534 | mlen = ctx->overps[oix]->mend - ctx->overps[oix]->mstart; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1535 | VERIFY(err, rlen >= mlen); |
| 1536 | if (err) |
| 1537 | goto bail; |
| 1538 | rpra[i].buf.pv = (args - ctx->overps[oix]->offset); |
| 1539 | pages[list[i].pgidx].addr = ctx->buf->phys - |
| 1540 | ctx->overps[oix]->offset + |
| 1541 | (copylen - rlen); |
| 1542 | pages[list[i].pgidx].addr = |
| 1543 | buf_page_start(pages[list[i].pgidx].addr); |
| 1544 | buf = rpra[i].buf.pv; |
| 1545 | pages[list[i].pgidx].size = buf_num_pages(buf, len) * PAGE_SIZE; |
| 1546 | if (i < inbufs) { |
| 1547 | K_COPY_FROM_USER(err, kernel, uint64_to_ptr(buf), |
| 1548 | lpra[i].buf.pv, len); |
| 1549 | if (err) |
| 1550 | goto bail; |
| 1551 | } |
| 1552 | args = args + mlen; |
| 1553 | rlen -= mlen; |
| 1554 | } |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1555 | PERF_END); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1556 | |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1557 | PERF(ctx->fl->profile, GET_COUNTER(perf_counter, PERF_FLUSH), |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1558 | for (oix = 0; oix < inbufs + outbufs; ++oix) { |
| 1559 | int i = ctx->overps[oix]->raix; |
| 1560 | struct fastrpc_mmap *map = ctx->maps[i]; |
| 1561 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1562 | if (map && map->uncached) |
| 1563 | continue; |
Tharun Kumar Merugu | 2e5f12e | 2017-07-06 12:04:40 +0530 | [diff] [blame] | 1564 | if (ctx->fl->sctx->smmu.coherent && |
| 1565 | !(map && (map->attr & FASTRPC_ATTR_NON_COHERENT))) |
| 1566 | continue; |
| 1567 | if (map && (map->attr & FASTRPC_ATTR_COHERENT)) |
| 1568 | continue; |
| 1569 | |
Tharun Kumar Merugu | c230bd7 | 2018-01-29 18:02:42 +0530 | [diff] [blame] | 1570 | if (rpra && rpra[i].buf.len && ctx->overps[oix]->mstart) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1571 | dmac_flush_range(uint64_to_ptr(rpra[i].buf.pv), |
| 1572 | uint64_to_ptr(rpra[i].buf.pv + rpra[i].buf.len)); |
| 1573 | } |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1574 | PERF_END); |
Tharun Kumar Merugu | d1f388a | 2017-10-01 10:51:11 +0530 | [diff] [blame] | 1575 | for (i = bufs; rpra && i < bufs + handles; i++) { |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1576 | rpra[i].dma.fd = ctx->fds[i]; |
| 1577 | rpra[i].dma.len = (uint32_t)lpra[i].buf.len; |
| 1578 | rpra[i].dma.offset = (uint32_t)(uintptr_t)lpra[i].buf.pv; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1579 | } |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1580 | |
| 1581 | if (!ctx->fl->sctx->smmu.coherent) { |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1582 | PERF(ctx->fl->profile, GET_COUNTER(perf_counter, PERF_FLUSH), |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1583 | dmac_flush_range((char *)rpra, (char *)rpra + ctx->used); |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1584 | PERF_END); |
| 1585 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1586 | bail: |
| 1587 | return err; |
| 1588 | } |
| 1589 | |
| 1590 | static int put_args(uint32_t kernel, struct smq_invoke_ctx *ctx, |
| 1591 | remote_arg_t *upra) |
| 1592 | { |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1593 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1594 | uint32_t sc = ctx->sc; |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1595 | struct smq_invoke_buf *list; |
| 1596 | struct smq_phy_page *pages; |
| 1597 | struct fastrpc_mmap *mmap; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1598 | uint64_t *fdlist = NULL; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1599 | uint32_t *crclist = NULL; |
| 1600 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1601 | remote_arg64_t *rpra = ctx->rpra; |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1602 | int i, inbufs, outbufs, handles; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1603 | int err = 0; |
| 1604 | |
| 1605 | inbufs = REMOTE_SCALARS_INBUFS(sc); |
| 1606 | outbufs = REMOTE_SCALARS_OUTBUFS(sc); |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1607 | handles = REMOTE_SCALARS_INHANDLES(sc) + REMOTE_SCALARS_OUTHANDLES(sc); |
| 1608 | list = smq_invoke_buf_start(ctx->rpra, sc); |
| 1609 | pages = smq_phy_page_start(sc, list); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1610 | if (!me->legacy) { |
| 1611 | fdlist = (uint64_t *)(pages + inbufs + outbufs + handles); |
| 1612 | crclist = (uint32_t *)(fdlist + M_FDLIST); |
| 1613 | } |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1614 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1615 | for (i = inbufs; i < inbufs + outbufs; ++i) { |
| 1616 | if (!ctx->maps[i]) { |
| 1617 | K_COPY_TO_USER(err, kernel, |
| 1618 | ctx->lpra[i].buf.pv, |
| 1619 | uint64_to_ptr(rpra[i].buf.pv), |
| 1620 | rpra[i].buf.len); |
| 1621 | if (err) |
| 1622 | goto bail; |
| 1623 | } else { |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1624 | mutex_lock(&ctx->fl->fl_map_mutex); |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 1625 | fastrpc_mmap_free(ctx->maps[i], 0); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1626 | mutex_unlock(&ctx->fl->fl_map_mutex); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1627 | ctx->maps[i] = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1628 | } |
| 1629 | } |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1630 | mutex_lock(&ctx->fl->fl_map_mutex); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1631 | if (fdlist && (inbufs + outbufs + handles)) { |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1632 | for (i = 0; i < M_FDLIST; i++) { |
| 1633 | if (!fdlist[i]) |
| 1634 | break; |
| 1635 | if (!fastrpc_mmap_find(ctx->fl, (int)fdlist[i], 0, 0, |
Sathish Ambley | ae5ee54 | 2017-01-16 22:24:23 -0800 | [diff] [blame] | 1636 | 0, 0, &mmap)) |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 1637 | fastrpc_mmap_free(mmap, 0); |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1638 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1639 | } |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 1640 | mutex_unlock(&ctx->fl->fl_map_mutex); |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1641 | if (ctx->crc && crclist && rpra) |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1642 | K_COPY_TO_USER(err, kernel, ctx->crc, |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1643 | crclist, M_CRCLIST*sizeof(uint32_t)); |
| 1644 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1645 | bail: |
| 1646 | return err; |
| 1647 | } |
| 1648 | |
| 1649 | static void inv_args_pre(struct smq_invoke_ctx *ctx) |
| 1650 | { |
| 1651 | int i, inbufs, outbufs; |
| 1652 | uint32_t sc = ctx->sc; |
| 1653 | remote_arg64_t *rpra = ctx->rpra; |
| 1654 | uintptr_t end; |
| 1655 | |
| 1656 | inbufs = REMOTE_SCALARS_INBUFS(sc); |
| 1657 | outbufs = REMOTE_SCALARS_OUTBUFS(sc); |
| 1658 | for (i = inbufs; i < inbufs + outbufs; ++i) { |
| 1659 | struct fastrpc_mmap *map = ctx->maps[i]; |
| 1660 | |
| 1661 | if (map && map->uncached) |
| 1662 | continue; |
| 1663 | if (!rpra[i].buf.len) |
| 1664 | continue; |
Tharun Kumar Merugu | 2e5f12e | 2017-07-06 12:04:40 +0530 | [diff] [blame] | 1665 | if (ctx->fl->sctx->smmu.coherent && |
| 1666 | !(map && (map->attr & FASTRPC_ATTR_NON_COHERENT))) |
| 1667 | continue; |
| 1668 | if (map && (map->attr & FASTRPC_ATTR_COHERENT)) |
| 1669 | continue; |
| 1670 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1671 | if (buf_page_start(ptr_to_uint64((void *)rpra)) == |
| 1672 | buf_page_start(rpra[i].buf.pv)) |
| 1673 | continue; |
| 1674 | if (!IS_CACHE_ALIGNED((uintptr_t)uint64_to_ptr(rpra[i].buf.pv))) |
| 1675 | dmac_flush_range(uint64_to_ptr(rpra[i].buf.pv), |
| 1676 | (char *)(uint64_to_ptr(rpra[i].buf.pv + 1))); |
| 1677 | end = (uintptr_t)uint64_to_ptr(rpra[i].buf.pv + |
| 1678 | rpra[i].buf.len); |
| 1679 | if (!IS_CACHE_ALIGNED(end)) |
| 1680 | dmac_flush_range((char *)end, |
| 1681 | (char *)end + 1); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | static void inv_args(struct smq_invoke_ctx *ctx) |
| 1686 | { |
| 1687 | int i, inbufs, outbufs; |
| 1688 | uint32_t sc = ctx->sc; |
| 1689 | remote_arg64_t *rpra = ctx->rpra; |
| 1690 | int used = ctx->used; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1691 | |
| 1692 | inbufs = REMOTE_SCALARS_INBUFS(sc); |
| 1693 | outbufs = REMOTE_SCALARS_OUTBUFS(sc); |
| 1694 | for (i = inbufs; i < inbufs + outbufs; ++i) { |
| 1695 | struct fastrpc_mmap *map = ctx->maps[i]; |
| 1696 | |
| 1697 | if (map && map->uncached) |
| 1698 | continue; |
| 1699 | if (!rpra[i].buf.len) |
| 1700 | continue; |
Tharun Kumar Merugu | 2e5f12e | 2017-07-06 12:04:40 +0530 | [diff] [blame] | 1701 | if (ctx->fl->sctx->smmu.coherent && |
| 1702 | !(map && (map->attr & FASTRPC_ATTR_NON_COHERENT))) |
| 1703 | continue; |
| 1704 | if (map && (map->attr & FASTRPC_ATTR_COHERENT)) |
| 1705 | continue; |
| 1706 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1707 | if (buf_page_start(ptr_to_uint64((void *)rpra)) == |
| 1708 | buf_page_start(rpra[i].buf.pv)) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1709 | continue; |
| 1710 | } |
| 1711 | if (map && map->handle) |
| 1712 | msm_ion_do_cache_op(ctx->fl->apps->client, map->handle, |
| 1713 | (char *)uint64_to_ptr(rpra[i].buf.pv), |
| 1714 | rpra[i].buf.len, ION_IOC_INV_CACHES); |
| 1715 | else |
| 1716 | dmac_inv_range((char *)uint64_to_ptr(rpra[i].buf.pv), |
| 1717 | (char *)uint64_to_ptr(rpra[i].buf.pv |
| 1718 | + rpra[i].buf.len)); |
| 1719 | } |
| 1720 | |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 1721 | if (rpra) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1722 | dmac_inv_range(rpra, (char *)rpra + used); |
| 1723 | } |
| 1724 | |
| 1725 | static int fastrpc_invoke_send(struct smq_invoke_ctx *ctx, |
| 1726 | uint32_t kernel, uint32_t handle) |
| 1727 | { |
| 1728 | struct smq_msg *msg = &ctx->msg; |
| 1729 | struct fastrpc_file *fl = ctx->fl; |
| 1730 | struct fastrpc_channel_ctx *channel_ctx = &fl->apps->channel[fl->cid]; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1731 | int err = 0, len; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1732 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1733 | VERIFY(err, NULL != channel_ctx->chan); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1734 | if (err) |
| 1735 | goto bail; |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 1736 | msg->pid = fl->tgid; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1737 | msg->tid = current->pid; |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 1738 | if (fl->sessionid) |
| 1739 | msg->tid |= (1 << SESSION_ID_INDEX); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1740 | if (kernel) |
| 1741 | msg->pid = 0; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1742 | msg->invoke.header.ctx = ctx->ctxid | fl->pd; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1743 | msg->invoke.header.handle = handle; |
| 1744 | msg->invoke.header.sc = ctx->sc; |
| 1745 | msg->invoke.page.addr = ctx->buf ? ctx->buf->phys : 0; |
| 1746 | msg->invoke.page.size = buf_page_size(ctx->used); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1747 | if (fl->apps->glink) { |
| 1748 | if (fl->ssrcount != channel_ctx->ssrcount) { |
| 1749 | err = -ECONNRESET; |
| 1750 | goto bail; |
| 1751 | } |
| 1752 | VERIFY(err, channel_ctx->link.port_state == |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1753 | FASTRPC_LINK_CONNECTED); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1754 | if (err) |
| 1755 | goto bail; |
| 1756 | err = glink_tx(channel_ctx->chan, |
| 1757 | (void *)&fl->apps->channel[fl->cid], msg, sizeof(*msg), |
| 1758 | GLINK_TX_REQ_INTENT); |
| 1759 | } else { |
| 1760 | spin_lock(&fl->apps->hlock); |
| 1761 | len = smd_write((smd_channel_t *) |
| 1762 | channel_ctx->chan, |
| 1763 | msg, sizeof(*msg)); |
| 1764 | spin_unlock(&fl->apps->hlock); |
| 1765 | VERIFY(err, len == sizeof(*msg)); |
| 1766 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1767 | bail: |
| 1768 | return err; |
| 1769 | } |
| 1770 | |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1771 | static void fastrpc_smd_read_handler(int cid) |
| 1772 | { |
| 1773 | struct fastrpc_apps *me = &gfa; |
| 1774 | struct smq_invoke_rsp rsp = {0}; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1775 | int ret = 0, err = 0; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1776 | uint32_t index; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1777 | |
| 1778 | do { |
| 1779 | ret = smd_read_from_cb(me->channel[cid].chan, &rsp, |
| 1780 | sizeof(rsp)); |
| 1781 | if (ret != sizeof(rsp)) |
| 1782 | break; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1783 | |
| 1784 | index = (uint32_t)((rsp.ctx & FASTRPC_CTXID_MASK) >> 4); |
| 1785 | VERIFY(err, index < FASTRPC_CTX_MAX); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1786 | if (err) |
| 1787 | goto bail; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1788 | |
| 1789 | VERIFY(err, !IS_ERR_OR_NULL(me->ctxtable[index])); |
| 1790 | if (err) |
| 1791 | goto bail; |
| 1792 | |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 1793 | VERIFY(err, ((me->ctxtable[index]->ctxid == (rsp.ctx & ~3)) && |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1794 | me->ctxtable[index]->magic == FASTRPC_CTX_MAGIC)); |
| 1795 | if (err) |
| 1796 | goto bail; |
| 1797 | |
| 1798 | context_notify_user(me->ctxtable[index], rsp.retval); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 1799 | } while (ret == sizeof(rsp)); |
| 1800 | bail: |
| 1801 | if (err) |
| 1802 | pr_err("adsprpc: invalid response or context\n"); |
| 1803 | |
| 1804 | } |
| 1805 | |
| 1806 | static void smd_event_handler(void *priv, unsigned int event) |
| 1807 | { |
| 1808 | struct fastrpc_apps *me = &gfa; |
| 1809 | int cid = (int)(uintptr_t)priv; |
| 1810 | |
| 1811 | switch (event) { |
| 1812 | case SMD_EVENT_OPEN: |
| 1813 | complete(&me->channel[cid].workport); |
| 1814 | break; |
| 1815 | case SMD_EVENT_CLOSE: |
| 1816 | fastrpc_notify_drivers(me, cid); |
| 1817 | break; |
| 1818 | case SMD_EVENT_DATA: |
| 1819 | fastrpc_smd_read_handler(cid); |
| 1820 | break; |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1825 | static void fastrpc_init(struct fastrpc_apps *me) |
| 1826 | { |
| 1827 | int i; |
| 1828 | |
| 1829 | INIT_HLIST_HEAD(&me->drivers); |
Tharun Kumar Merugu | bcd6fbf | 2018-01-04 17:49:34 +0530 | [diff] [blame] | 1830 | INIT_HLIST_HEAD(&me->maps); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1831 | spin_lock_init(&me->hlock); |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 1832 | spin_lock_init(&me->ctxlock); |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 1833 | mutex_init(&me->smd_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1834 | me->channel = &gcinfo[0]; |
| 1835 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 1836 | init_completion(&me->channel[i].work); |
Tharun Kumar Merugu | 53a8ec9 | 2017-07-14 15:52:49 +0530 | [diff] [blame] | 1837 | init_completion(&me->channel[i].workport); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1838 | me->channel[i].sesscount = 0; |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | static int fastrpc_release_current_dsp_process(struct fastrpc_file *fl); |
| 1843 | |
| 1844 | static int fastrpc_internal_invoke(struct fastrpc_file *fl, uint32_t mode, |
| 1845 | uint32_t kernel, |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1846 | struct fastrpc_ioctl_invoke_crc *inv) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1847 | { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1848 | struct smq_invoke_ctx *ctx = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1849 | struct fastrpc_ioctl_invoke *invoke = &inv->inv; |
| 1850 | int cid = fl->cid; |
| 1851 | int interrupted = 0; |
| 1852 | int err = 0; |
Maria Yu | 757199c | 2017-09-22 16:05:49 +0800 | [diff] [blame] | 1853 | struct timespec invoket = {0}; |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1854 | int64_t *perf_counter = getperfcounter(fl, PERF_COUNT); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1855 | |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1856 | if (fl->profile) |
| 1857 | getnstimeofday(&invoket); |
Tharun Kumar Merugu | e3edf3e | 2017-07-27 12:34:07 +0530 | [diff] [blame] | 1858 | |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 1859 | |
Tharun Kumar Merugu | e3edf3e | 2017-07-27 12:34:07 +0530 | [diff] [blame] | 1860 | VERIFY(err, fl->sctx != NULL); |
| 1861 | if (err) |
| 1862 | goto bail; |
| 1863 | VERIFY(err, fl->cid >= 0 && fl->cid < NUM_CHANNELS); |
| 1864 | if (err) |
| 1865 | goto bail; |
| 1866 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1867 | if (!kernel) { |
| 1868 | VERIFY(err, 0 == context_restore_interrupted(fl, inv, |
| 1869 | &ctx)); |
| 1870 | if (err) |
| 1871 | goto bail; |
| 1872 | if (fl->sctx->smmu.faults) |
| 1873 | err = FASTRPC_ENOSUCH; |
| 1874 | if (err) |
| 1875 | goto bail; |
| 1876 | if (ctx) |
| 1877 | goto wait; |
| 1878 | } |
| 1879 | |
| 1880 | VERIFY(err, 0 == context_alloc(fl, kernel, inv, &ctx)); |
| 1881 | if (err) |
| 1882 | goto bail; |
| 1883 | |
| 1884 | if (REMOTE_SCALARS_LENGTH(ctx->sc)) { |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1885 | PERF(fl->profile, GET_COUNTER(perf_counter, PERF_GETARGS), |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1886 | VERIFY(err, 0 == get_args(kernel, ctx)); |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1887 | PERF_END); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1888 | if (err) |
| 1889 | goto bail; |
| 1890 | } |
| 1891 | |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1892 | if (!fl->sctx->smmu.coherent) { |
| 1893 | PERF(fl->profile, GET_COUNTER(perf_counter, PERF_INVARGS), |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1894 | inv_args_pre(ctx); |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1895 | PERF_END); |
| 1896 | } |
| 1897 | |
| 1898 | PERF(fl->profile, GET_COUNTER(perf_counter, PERF_LINK), |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1899 | VERIFY(err, 0 == fastrpc_invoke_send(ctx, kernel, invoke->handle)); |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1900 | PERF_END); |
| 1901 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1902 | if (err) |
| 1903 | goto bail; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1904 | wait: |
| 1905 | if (kernel) |
| 1906 | wait_for_completion(&ctx->work); |
| 1907 | else { |
| 1908 | interrupted = wait_for_completion_interruptible(&ctx->work); |
| 1909 | VERIFY(err, 0 == (err = interrupted)); |
| 1910 | if (err) |
| 1911 | goto bail; |
| 1912 | } |
Sathish Ambley | c432b50 | 2017-06-05 12:03:42 -0700 | [diff] [blame] | 1913 | |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1914 | PERF(fl->profile, GET_COUNTER(perf_counter, PERF_INVARGS), |
Sathish Ambley | c432b50 | 2017-06-05 12:03:42 -0700 | [diff] [blame] | 1915 | if (!fl->sctx->smmu.coherent) |
| 1916 | inv_args(ctx); |
| 1917 | PERF_END); |
| 1918 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1919 | VERIFY(err, 0 == (err = ctx->retval)); |
| 1920 | if (err) |
| 1921 | goto bail; |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1922 | |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1923 | PERF(fl->profile, GET_COUNTER(perf_counter, PERF_PUTARGS), |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1924 | VERIFY(err, 0 == put_args(kernel, ctx, invoke->pra)); |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1925 | PERF_END); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1926 | if (err) |
| 1927 | goto bail; |
| 1928 | bail: |
| 1929 | if (ctx && interrupted == -ERESTARTSYS) |
| 1930 | context_save_interrupted(ctx); |
| 1931 | else if (ctx) |
| 1932 | context_free(ctx); |
| 1933 | if (fl->ssrcount != fl->apps->channel[cid].ssrcount) |
| 1934 | err = ECONNRESET; |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1935 | |
| 1936 | if (fl->profile && !interrupted) { |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 1937 | if (invoke->handle != FASTRPC_STATIC_HANDLE_LISTENER) { |
| 1938 | int64_t *count = GET_COUNTER(perf_counter, PERF_INVOKE); |
| 1939 | |
| 1940 | if (count) |
| 1941 | *count += getnstimediff(&invoket); |
| 1942 | } |
| 1943 | if (invoke->handle > FASTRPC_STATIC_HANDLE_MAX) { |
| 1944 | int64_t *count = GET_COUNTER(perf_counter, PERF_COUNT); |
| 1945 | |
| 1946 | if (count) |
| 1947 | *count = *count+1; |
| 1948 | } |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 1949 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1950 | return err; |
| 1951 | } |
| 1952 | |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 1953 | static int fastrpc_get_adsp_session(char *name, int *session) |
| 1954 | { |
| 1955 | struct fastrpc_apps *me = &gfa; |
| 1956 | int err = 0, i; |
| 1957 | |
| 1958 | for (i = 0; i < NUM_SESSIONS; i++) { |
| 1959 | if (!me->channel[0].spd[i].spdname) |
| 1960 | continue; |
| 1961 | if (!strcmp(name, me->channel[0].spd[i].spdname)) |
| 1962 | break; |
| 1963 | } |
| 1964 | VERIFY(err, i < NUM_SESSIONS); |
| 1965 | if (err) |
| 1966 | goto bail; |
| 1967 | *session = i; |
| 1968 | bail: |
| 1969 | return err; |
| 1970 | } |
| 1971 | |
| 1972 | static int fastrpc_mmap_remove_pdr(struct fastrpc_file *fl); |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 1973 | static int fastrpc_channel_open(struct fastrpc_file *fl); |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 1974 | static int fastrpc_mmap_remove_ssr(struct fastrpc_file *fl); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1975 | static int fastrpc_init_process(struct fastrpc_file *fl, |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 1976 | struct fastrpc_ioctl_init_attrs *uproc) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1977 | { |
| 1978 | int err = 0; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1979 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 1980 | struct fastrpc_ioctl_invoke_crc ioctl; |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 1981 | struct fastrpc_ioctl_init *init = &uproc->init; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1982 | struct smq_phy_page pages[1]; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1983 | struct fastrpc_mmap *file = NULL, *mem = NULL; |
| 1984 | char *proc_name = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1985 | |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 1986 | VERIFY(err, 0 == (err = fastrpc_channel_open(fl))); |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 1987 | if (err) |
| 1988 | goto bail; |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 1989 | if (init->flags == FASTRPC_INIT_ATTACH || |
| 1990 | init->flags == FASTRPC_INIT_ATTACH_SENSORS) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1991 | remote_arg_t ra[1]; |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 1992 | int tgid = fl->tgid; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1993 | |
| 1994 | ra[0].buf.pv = (void *)&tgid; |
| 1995 | ra[0].buf.len = sizeof(tgid); |
| 1996 | ioctl.inv.handle = 1; |
| 1997 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(0, 1, 0); |
| 1998 | ioctl.inv.pra = ra; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 1999 | ioctl.fds = NULL; |
| 2000 | ioctl.attrs = NULL; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 2001 | ioctl.crc = NULL; |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 2002 | if (init->flags == FASTRPC_INIT_ATTACH) |
| 2003 | fl->pd = 0; |
| 2004 | else if (init->flags == FASTRPC_INIT_ATTACH_SENSORS) { |
| 2005 | fl->spdname = SENSORS_PDR_SERVICE_LOCATION_CLIENT_NAME; |
| 2006 | fl->pd = 2; |
| 2007 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2008 | VERIFY(err, !(err = fastrpc_internal_invoke(fl, |
| 2009 | FASTRPC_MODE_PARALLEL, 1, &ioctl))); |
| 2010 | if (err) |
| 2011 | goto bail; |
| 2012 | } else if (init->flags == FASTRPC_INIT_CREATE) { |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 2013 | remote_arg_t ra[6]; |
| 2014 | int fds[6]; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2015 | int mflags = 0; |
| 2016 | struct { |
| 2017 | int pgid; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 2018 | unsigned int namelen; |
| 2019 | unsigned int filelen; |
| 2020 | unsigned int pageslen; |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 2021 | int attrs; |
| 2022 | int siglen; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2023 | } inbuf; |
| 2024 | |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 2025 | inbuf.pgid = fl->tgid; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2026 | inbuf.namelen = strlen(current->comm) + 1; |
| 2027 | inbuf.filelen = init->filelen; |
| 2028 | fl->pd = 1; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 2029 | |
Tharun Kumar Merugu | df85289 | 2017-12-07 16:27:37 +0530 | [diff] [blame] | 2030 | VERIFY(err, access_ok(0, (void __user *)init->file, |
| 2031 | init->filelen)); |
| 2032 | if (err) |
| 2033 | goto bail; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2034 | if (init->filelen) { |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2035 | mutex_lock(&fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2036 | VERIFY(err, !fastrpc_mmap_create(fl, init->filefd, 0, |
| 2037 | init->file, init->filelen, mflags, &file)); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2038 | mutex_unlock(&fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2039 | if (err) |
| 2040 | goto bail; |
| 2041 | } |
| 2042 | inbuf.pageslen = 1; |
Tharun Kumar Merugu | df85289 | 2017-12-07 16:27:37 +0530 | [diff] [blame] | 2043 | VERIFY(err, access_ok(1, (void __user *)init->mem, |
| 2044 | init->memlen)); |
| 2045 | if (err) |
| 2046 | goto bail; |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2047 | mutex_lock(&fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2048 | VERIFY(err, !fastrpc_mmap_create(fl, init->memfd, 0, |
| 2049 | init->mem, init->memlen, mflags, &mem)); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2050 | mutex_unlock(&fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2051 | if (err) |
| 2052 | goto bail; |
| 2053 | inbuf.pageslen = 1; |
| 2054 | ra[0].buf.pv = (void *)&inbuf; |
| 2055 | ra[0].buf.len = sizeof(inbuf); |
| 2056 | fds[0] = 0; |
| 2057 | |
| 2058 | ra[1].buf.pv = (void *)current->comm; |
| 2059 | ra[1].buf.len = inbuf.namelen; |
| 2060 | fds[1] = 0; |
| 2061 | |
| 2062 | ra[2].buf.pv = (void *)init->file; |
| 2063 | ra[2].buf.len = inbuf.filelen; |
| 2064 | fds[2] = init->filefd; |
| 2065 | |
| 2066 | pages[0].addr = mem->phys; |
| 2067 | pages[0].size = mem->size; |
| 2068 | ra[3].buf.pv = (void *)pages; |
| 2069 | ra[3].buf.len = 1 * sizeof(*pages); |
| 2070 | fds[3] = 0; |
| 2071 | |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 2072 | inbuf.attrs = uproc->attrs; |
| 2073 | ra[4].buf.pv = (void *)&(inbuf.attrs); |
| 2074 | ra[4].buf.len = sizeof(inbuf.attrs); |
| 2075 | fds[4] = 0; |
| 2076 | |
| 2077 | inbuf.siglen = uproc->siglen; |
| 2078 | ra[5].buf.pv = (void *)&(inbuf.siglen); |
| 2079 | ra[5].buf.len = sizeof(inbuf.siglen); |
| 2080 | fds[5] = 0; |
| 2081 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2082 | ioctl.inv.handle = 1; |
| 2083 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(6, 4, 0); |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 2084 | if (uproc->attrs) |
| 2085 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(7, 6, 0); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2086 | ioctl.inv.pra = ra; |
| 2087 | ioctl.fds = fds; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2088 | ioctl.attrs = NULL; |
| 2089 | ioctl.crc = NULL; |
| 2090 | VERIFY(err, !(err = fastrpc_internal_invoke(fl, |
| 2091 | FASTRPC_MODE_PARALLEL, 1, &ioctl))); |
| 2092 | if (err) |
| 2093 | goto bail; |
| 2094 | } else if (init->flags == FASTRPC_INIT_CREATE_STATIC) { |
| 2095 | remote_arg_t ra[3]; |
| 2096 | uint64_t phys = 0; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 2097 | size_t size = 0; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2098 | int fds[3]; |
| 2099 | struct { |
| 2100 | int pgid; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 2101 | unsigned int namelen; |
| 2102 | unsigned int pageslen; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2103 | } inbuf; |
| 2104 | |
| 2105 | if (!init->filelen) |
| 2106 | goto bail; |
| 2107 | |
| 2108 | proc_name = kzalloc(init->filelen, GFP_KERNEL); |
| 2109 | VERIFY(err, !IS_ERR_OR_NULL(proc_name)); |
| 2110 | if (err) |
| 2111 | goto bail; |
| 2112 | VERIFY(err, 0 == copy_from_user((void *)proc_name, |
| 2113 | (void __user *)init->file, init->filelen)); |
| 2114 | if (err) |
| 2115 | goto bail; |
| 2116 | |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 2117 | fl->pd = 1; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2118 | inbuf.pgid = current->tgid; |
c_mtharu | 81a0aa7 | 2017-11-07 16:13:21 +0530 | [diff] [blame] | 2119 | inbuf.namelen = init->filelen; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2120 | inbuf.pageslen = 0; |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 2121 | |
| 2122 | if (!strcmp(proc_name, "audiopd")) { |
| 2123 | fl->spdname = AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME; |
| 2124 | VERIFY(err, !fastrpc_mmap_remove_pdr(fl)); |
Tharun Kumar Merugu | 3517334 | 2018-02-08 16:13:17 +0530 | [diff] [blame] | 2125 | if (err) |
| 2126 | goto bail; |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 2127 | } |
| 2128 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2129 | if (!me->staticpd_flags) { |
| 2130 | inbuf.pageslen = 1; |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2131 | mutex_lock(&fl->fl_map_mutex); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2132 | VERIFY(err, !fastrpc_mmap_create(fl, -1, 0, init->mem, |
| 2133 | init->memlen, ADSP_MMAP_REMOTE_HEAP_ADDR, |
| 2134 | &mem)); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2135 | mutex_unlock(&fl->fl_map_mutex); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2136 | if (err) |
| 2137 | goto bail; |
| 2138 | phys = mem->phys; |
| 2139 | size = mem->size; |
| 2140 | VERIFY(err, !hyp_assign_phys(phys, (uint64_t)size, |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 2141 | hlosvm, 1, me->channel[fl->cid].rhvm.vmid, |
| 2142 | me->channel[fl->cid].rhvm.vmperm, |
| 2143 | me->channel[fl->cid].rhvm.vmcount)); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2144 | if (err) { |
| 2145 | pr_err("ADSPRPC: hyp_assign_phys fail err %d", |
| 2146 | err); |
| 2147 | pr_err("map->phys %llx, map->size %d\n", |
| 2148 | phys, (int)size); |
| 2149 | goto bail; |
| 2150 | } |
| 2151 | me->staticpd_flags = 1; |
| 2152 | } |
| 2153 | |
| 2154 | ra[0].buf.pv = (void *)&inbuf; |
| 2155 | ra[0].buf.len = sizeof(inbuf); |
| 2156 | fds[0] = 0; |
| 2157 | |
| 2158 | ra[1].buf.pv = (void *)proc_name; |
| 2159 | ra[1].buf.len = inbuf.namelen; |
| 2160 | fds[1] = 0; |
| 2161 | |
| 2162 | pages[0].addr = phys; |
| 2163 | pages[0].size = size; |
| 2164 | |
| 2165 | ra[2].buf.pv = (void *)pages; |
| 2166 | ra[2].buf.len = sizeof(*pages); |
| 2167 | fds[2] = 0; |
| 2168 | ioctl.inv.handle = 1; |
| 2169 | |
| 2170 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(8, 3, 0); |
| 2171 | ioctl.inv.pra = ra; |
| 2172 | ioctl.fds = NULL; |
| 2173 | ioctl.attrs = NULL; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 2174 | ioctl.crc = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2175 | VERIFY(err, !(err = fastrpc_internal_invoke(fl, |
| 2176 | FASTRPC_MODE_PARALLEL, 1, &ioctl))); |
| 2177 | if (err) |
| 2178 | goto bail; |
| 2179 | } else { |
| 2180 | err = -ENOTTY; |
| 2181 | } |
| 2182 | bail: |
c_mtharu | d91205a | 2017-11-07 16:01:06 +0530 | [diff] [blame] | 2183 | kfree(proc_name); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2184 | if (err && (init->flags == FASTRPC_INIT_CREATE_STATIC)) |
| 2185 | me->staticpd_flags = 0; |
| 2186 | if (mem && err) { |
| 2187 | if (mem->flags == ADSP_MMAP_REMOTE_HEAP_ADDR) |
| 2188 | hyp_assign_phys(mem->phys, (uint64_t)mem->size, |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 2189 | me->channel[fl->cid].rhvm.vmid, |
| 2190 | me->channel[fl->cid].rhvm.vmcount, |
| 2191 | hlosvm, hlosvmperm, 1); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2192 | mutex_lock(&fl->fl_map_mutex); |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 2193 | fastrpc_mmap_free(mem, 0); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2194 | mutex_unlock(&fl->fl_map_mutex); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2195 | } |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2196 | if (file) { |
| 2197 | mutex_lock(&fl->fl_map_mutex); |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 2198 | fastrpc_mmap_free(file, 0); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2199 | mutex_unlock(&fl->fl_map_mutex); |
| 2200 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2201 | return err; |
| 2202 | } |
| 2203 | |
| 2204 | static int fastrpc_release_current_dsp_process(struct fastrpc_file *fl) |
| 2205 | { |
| 2206 | int err = 0; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 2207 | struct fastrpc_ioctl_invoke_crc ioctl; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2208 | remote_arg_t ra[1]; |
| 2209 | int tgid = 0; |
| 2210 | |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 2211 | VERIFY(err, fl->cid >= 0 && fl->cid < NUM_CHANNELS); |
| 2212 | if (err) |
| 2213 | goto bail; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2214 | VERIFY(err, fl->apps->channel[fl->cid].chan != NULL); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2215 | if (err) |
| 2216 | goto bail; |
| 2217 | tgid = fl->tgid; |
| 2218 | ra[0].buf.pv = (void *)&tgid; |
| 2219 | ra[0].buf.len = sizeof(tgid); |
| 2220 | ioctl.inv.handle = 1; |
| 2221 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(1, 1, 0); |
| 2222 | ioctl.inv.pra = ra; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2223 | ioctl.fds = NULL; |
| 2224 | ioctl.attrs = NULL; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 2225 | ioctl.crc = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2226 | VERIFY(err, 0 == (err = fastrpc_internal_invoke(fl, |
| 2227 | FASTRPC_MODE_PARALLEL, 1, &ioctl))); |
| 2228 | bail: |
| 2229 | return err; |
| 2230 | } |
| 2231 | |
| 2232 | static int fastrpc_mmap_on_dsp(struct fastrpc_file *fl, uint32_t flags, |
| 2233 | struct fastrpc_mmap *map) |
| 2234 | { |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 2235 | struct fastrpc_ioctl_invoke_crc ioctl; |
c_mtharu | 63ffc01 | 2017-11-16 15:26:56 +0530 | [diff] [blame] | 2236 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2237 | struct smq_phy_page page; |
| 2238 | int num = 1; |
| 2239 | remote_arg_t ra[3]; |
| 2240 | int err = 0; |
| 2241 | struct { |
| 2242 | int pid; |
| 2243 | uint32_t flags; |
| 2244 | uintptr_t vaddrin; |
| 2245 | int num; |
| 2246 | } inargs; |
| 2247 | struct { |
| 2248 | uintptr_t vaddrout; |
| 2249 | } routargs; |
| 2250 | |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 2251 | inargs.pid = fl->tgid; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2252 | inargs.vaddrin = (uintptr_t)map->va; |
| 2253 | inargs.flags = flags; |
| 2254 | inargs.num = fl->apps->compat ? num * sizeof(page) : num; |
| 2255 | ra[0].buf.pv = (void *)&inargs; |
| 2256 | ra[0].buf.len = sizeof(inargs); |
| 2257 | page.addr = map->phys; |
| 2258 | page.size = map->size; |
| 2259 | ra[1].buf.pv = (void *)&page; |
| 2260 | ra[1].buf.len = num * sizeof(page); |
| 2261 | |
| 2262 | ra[2].buf.pv = (void *)&routargs; |
| 2263 | ra[2].buf.len = sizeof(routargs); |
| 2264 | |
| 2265 | ioctl.inv.handle = 1; |
| 2266 | if (fl->apps->compat) |
| 2267 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(4, 2, 1); |
| 2268 | else |
| 2269 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(2, 2, 1); |
| 2270 | ioctl.inv.pra = ra; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2271 | ioctl.fds = NULL; |
| 2272 | ioctl.attrs = NULL; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 2273 | ioctl.crc = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2274 | VERIFY(err, 0 == (err = fastrpc_internal_invoke(fl, |
| 2275 | FASTRPC_MODE_PARALLEL, 1, &ioctl))); |
| 2276 | map->raddr = (uintptr_t)routargs.vaddrout; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2277 | if (err) |
| 2278 | goto bail; |
| 2279 | if (flags == ADSP_MMAP_HEAP_ADDR) { |
| 2280 | struct scm_desc desc = {0}; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2281 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2282 | desc.args[0] = TZ_PIL_AUTH_QDSP6_PROC; |
| 2283 | desc.args[1] = map->phys; |
| 2284 | desc.args[2] = map->size; |
| 2285 | desc.arginfo = SCM_ARGS(3); |
| 2286 | err = scm_call2(SCM_SIP_FNID(SCM_SVC_PIL, |
| 2287 | TZ_PIL_PROTECT_MEM_SUBSYS_ID), &desc); |
| 2288 | } else if (flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2289 | VERIFY(err, !hyp_assign_phys(map->phys, (uint64_t)map->size, |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 2290 | hlosvm, 1, me->channel[fl->cid].rhvm.vmid, |
| 2291 | me->channel[fl->cid].rhvm.vmperm, |
| 2292 | me->channel[fl->cid].rhvm.vmcount)); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2293 | if (err) |
| 2294 | goto bail; |
| 2295 | } |
| 2296 | bail: |
| 2297 | return err; |
| 2298 | } |
| 2299 | |
| 2300 | static int fastrpc_munmap_on_dsp_rh(struct fastrpc_file *fl, |
| 2301 | struct fastrpc_mmap *map) |
| 2302 | { |
| 2303 | int err = 0; |
c_mtharu | 63ffc01 | 2017-11-16 15:26:56 +0530 | [diff] [blame] | 2304 | struct fastrpc_apps *me = &gfa; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2305 | int destVM[1] = {VMID_HLOS}; |
| 2306 | int destVMperm[1] = {PERM_READ | PERM_WRITE | PERM_EXEC}; |
| 2307 | |
| 2308 | if (map->flags == ADSP_MMAP_HEAP_ADDR) { |
| 2309 | struct fastrpc_ioctl_invoke_crc ioctl; |
| 2310 | struct scm_desc desc = {0}; |
| 2311 | remote_arg_t ra[1]; |
| 2312 | int err = 0; |
| 2313 | struct { |
| 2314 | uint8_t skey; |
| 2315 | } routargs; |
| 2316 | |
| 2317 | ra[0].buf.pv = (void *)&routargs; |
| 2318 | ra[0].buf.len = sizeof(routargs); |
| 2319 | |
| 2320 | ioctl.inv.handle = 1; |
| 2321 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(7, 0, 1); |
| 2322 | ioctl.inv.pra = ra; |
| 2323 | ioctl.fds = NULL; |
| 2324 | ioctl.attrs = NULL; |
| 2325 | ioctl.crc = NULL; |
| 2326 | if (fl == NULL) |
| 2327 | goto bail; |
| 2328 | |
| 2329 | VERIFY(err, 0 == (err = fastrpc_internal_invoke(fl, |
| 2330 | FASTRPC_MODE_PARALLEL, 1, &ioctl))); |
| 2331 | if (err) |
| 2332 | goto bail; |
| 2333 | desc.args[0] = TZ_PIL_AUTH_QDSP6_PROC; |
| 2334 | desc.args[1] = map->phys; |
| 2335 | desc.args[2] = map->size; |
| 2336 | desc.args[3] = routargs.skey; |
| 2337 | desc.arginfo = SCM_ARGS(4); |
| 2338 | err = scm_call2(SCM_SIP_FNID(SCM_SVC_PIL, |
| 2339 | TZ_PIL_CLEAR_PROTECT_MEM_SUBSYS_ID), &desc); |
| 2340 | } else if (map->flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { |
| 2341 | VERIFY(err, !hyp_assign_phys(map->phys, (uint64_t)map->size, |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 2342 | me->channel[fl->cid].rhvm.vmid, |
| 2343 | me->channel[fl->cid].rhvm.vmcount, |
| 2344 | destVM, destVMperm, 1)); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2345 | if (err) |
| 2346 | goto bail; |
| 2347 | } |
| 2348 | |
| 2349 | bail: |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2350 | return err; |
| 2351 | } |
| 2352 | |
| 2353 | static int fastrpc_munmap_on_dsp(struct fastrpc_file *fl, |
| 2354 | struct fastrpc_mmap *map) |
| 2355 | { |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 2356 | struct fastrpc_ioctl_invoke_crc ioctl; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2357 | remote_arg_t ra[1]; |
| 2358 | int err = 0; |
| 2359 | struct { |
| 2360 | int pid; |
| 2361 | uintptr_t vaddrout; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 2362 | size_t size; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2363 | } inargs; |
| 2364 | |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 2365 | inargs.pid = fl->tgid; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2366 | inargs.size = map->size; |
| 2367 | inargs.vaddrout = map->raddr; |
| 2368 | ra[0].buf.pv = (void *)&inargs; |
| 2369 | ra[0].buf.len = sizeof(inargs); |
| 2370 | |
| 2371 | ioctl.inv.handle = 1; |
| 2372 | if (fl->apps->compat) |
| 2373 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(5, 1, 0); |
| 2374 | else |
| 2375 | ioctl.inv.sc = REMOTE_SCALARS_MAKE(3, 1, 0); |
| 2376 | ioctl.inv.pra = ra; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2377 | ioctl.fds = NULL; |
| 2378 | ioctl.attrs = NULL; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 2379 | ioctl.crc = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2380 | VERIFY(err, 0 == (err = fastrpc_internal_invoke(fl, |
| 2381 | FASTRPC_MODE_PARALLEL, 1, &ioctl))); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2382 | if (err) |
| 2383 | goto bail; |
| 2384 | if (map->flags == ADSP_MMAP_HEAP_ADDR || |
| 2385 | map->flags == ADSP_MMAP_REMOTE_HEAP_ADDR) { |
| 2386 | VERIFY(err, !fastrpc_munmap_on_dsp_rh(fl, map)); |
| 2387 | if (err) |
| 2388 | goto bail; |
| 2389 | } |
| 2390 | bail: |
| 2391 | return err; |
| 2392 | } |
| 2393 | |
| 2394 | static int fastrpc_mmap_remove_ssr(struct fastrpc_file *fl) |
| 2395 | { |
| 2396 | struct fastrpc_mmap *match = NULL, *map = NULL; |
| 2397 | struct hlist_node *n = NULL; |
| 2398 | int err = 0, ret = 0; |
| 2399 | struct fastrpc_apps *me = &gfa; |
| 2400 | struct ramdump_segment *ramdump_segments_rh = NULL; |
| 2401 | |
| 2402 | do { |
| 2403 | match = NULL; |
| 2404 | spin_lock(&me->hlock); |
| 2405 | hlist_for_each_entry_safe(map, n, &me->maps, hn) { |
| 2406 | match = map; |
| 2407 | hlist_del_init(&map->hn); |
| 2408 | break; |
| 2409 | } |
| 2410 | spin_unlock(&me->hlock); |
| 2411 | |
| 2412 | if (match) { |
| 2413 | VERIFY(err, !fastrpc_munmap_on_dsp_rh(fl, match)); |
| 2414 | if (err) |
| 2415 | goto bail; |
| 2416 | if (me->channel[0].ramdumpenabled) { |
| 2417 | ramdump_segments_rh = kcalloc(1, |
| 2418 | sizeof(struct ramdump_segment), GFP_KERNEL); |
| 2419 | if (ramdump_segments_rh) { |
| 2420 | ramdump_segments_rh->address = |
| 2421 | match->phys; |
| 2422 | ramdump_segments_rh->size = match->size; |
| 2423 | ret = do_elf_ramdump( |
| 2424 | me->channel[0].remoteheap_ramdump_dev, |
| 2425 | ramdump_segments_rh, 1); |
| 2426 | if (ret < 0) |
| 2427 | pr_err("ADSPRPC: unable to dump heap"); |
| 2428 | kfree(ramdump_segments_rh); |
| 2429 | } |
| 2430 | } |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 2431 | fastrpc_mmap_free(match, 0); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2432 | } |
| 2433 | } while (match); |
| 2434 | bail: |
| 2435 | if (err && match) |
| 2436 | fastrpc_mmap_add(match); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2437 | return err; |
| 2438 | } |
| 2439 | |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 2440 | static int fastrpc_mmap_remove_pdr(struct fastrpc_file *fl) |
| 2441 | { |
| 2442 | struct fastrpc_apps *me = &gfa; |
| 2443 | int session = 0, err = 0; |
| 2444 | |
| 2445 | VERIFY(err, !fastrpc_get_adsp_session( |
| 2446 | AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME, &session)); |
| 2447 | if (err) |
| 2448 | goto bail; |
| 2449 | if (me->channel[fl->cid].spd[session].pdrcount != |
| 2450 | me->channel[fl->cid].spd[session].prevpdrcount) { |
| 2451 | if (fastrpc_mmap_remove_ssr(fl)) |
| 2452 | pr_err("ADSPRPC: SSR: Failed to unmap remote heap\n"); |
| 2453 | me->channel[fl->cid].spd[session].prevpdrcount = |
| 2454 | me->channel[fl->cid].spd[session].pdrcount; |
| 2455 | } |
| 2456 | if (!me->channel[fl->cid].spd[session].ispdup) { |
| 2457 | VERIFY(err, 0); |
| 2458 | if (err) { |
| 2459 | err = -ENOTCONN; |
| 2460 | goto bail; |
| 2461 | } |
| 2462 | } |
| 2463 | bail: |
| 2464 | return err; |
| 2465 | } |
| 2466 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2467 | static int fastrpc_mmap_remove(struct fastrpc_file *fl, uintptr_t va, |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 2468 | size_t len, struct fastrpc_mmap **ppmap); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2469 | |
| 2470 | static void fastrpc_mmap_add(struct fastrpc_mmap *map); |
| 2471 | |
| 2472 | static int fastrpc_internal_munmap(struct fastrpc_file *fl, |
| 2473 | struct fastrpc_ioctl_munmap *ud) |
| 2474 | { |
| 2475 | int err = 0; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2476 | struct fastrpc_mmap *map = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2477 | |
Tharun Kumar Merugu | c31eac5 | 2018-01-02 11:42:45 +0530 | [diff] [blame] | 2478 | mutex_lock(&fl->map_mutex); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2479 | mutex_lock(&fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2480 | VERIFY(err, !fastrpc_mmap_remove(fl, ud->vaddrout, ud->size, &map)); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2481 | mutex_unlock(&fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2482 | if (err) |
| 2483 | goto bail; |
| 2484 | VERIFY(err, !fastrpc_munmap_on_dsp(fl, map)); |
| 2485 | if (err) |
| 2486 | goto bail; |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2487 | mutex_lock(&fl->fl_map_mutex); |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 2488 | fastrpc_mmap_free(map, 0); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2489 | mutex_unlock(&fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2490 | bail: |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2491 | if (err && map) { |
| 2492 | mutex_lock(&fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2493 | fastrpc_mmap_add(map); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2494 | mutex_unlock(&fl->fl_map_mutex); |
| 2495 | } |
Tharun Kumar Merugu | c31eac5 | 2018-01-02 11:42:45 +0530 | [diff] [blame] | 2496 | mutex_unlock(&fl->map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2497 | return err; |
| 2498 | } |
| 2499 | |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 2500 | static int fastrpc_internal_munmap_fd(struct fastrpc_file *fl, |
| 2501 | struct fastrpc_ioctl_munmap_fd *ud) { |
| 2502 | int err = 0; |
| 2503 | struct fastrpc_mmap *map = NULL; |
| 2504 | |
| 2505 | VERIFY(err, (fl && ud)); |
| 2506 | if (err) |
| 2507 | goto bail; |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2508 | mutex_lock(&fl->fl_map_mutex); |
Tharun Kumar Merugu | 09fc615 | 2018-02-16 13:13:12 +0530 | [diff] [blame] | 2509 | if (fastrpc_mmap_find(fl, ud->fd, ud->va, ud->len, 0, 0, &map)) { |
| 2510 | pr_err("adsprpc: mapping not found to unmap %d va %llx %x\n", |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 2511 | ud->fd, (unsigned long long)ud->va, |
| 2512 | (unsigned int)ud->len); |
| 2513 | err = -1; |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2514 | mutex_unlock(&fl->fl_map_mutex); |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 2515 | goto bail; |
| 2516 | } |
| 2517 | if (map) |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2518 | fastrpc_mmap_free(map, 0); |
| 2519 | mutex_unlock(&fl->fl_map_mutex); |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 2520 | bail: |
| 2521 | return err; |
| 2522 | } |
| 2523 | |
| 2524 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2525 | static int fastrpc_internal_mmap(struct fastrpc_file *fl, |
| 2526 | struct fastrpc_ioctl_mmap *ud) |
| 2527 | { |
| 2528 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2529 | struct fastrpc_mmap *map = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2530 | int err = 0; |
| 2531 | |
Tharun Kumar Merugu | c31eac5 | 2018-01-02 11:42:45 +0530 | [diff] [blame] | 2532 | mutex_lock(&fl->map_mutex); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2533 | mutex_lock(&fl->fl_map_mutex); |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 2534 | if (!fastrpc_mmap_find(fl, ud->fd, (uintptr_t)ud->vaddrin, |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2535 | ud->size, ud->flags, 1, &map)) { |
| 2536 | mutex_unlock(&fl->fl_map_mutex); |
Tharun Kumar Merugu | c31eac5 | 2018-01-02 11:42:45 +0530 | [diff] [blame] | 2537 | mutex_unlock(&fl->map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2538 | return 0; |
Tharun Kumar Merugu | c31eac5 | 2018-01-02 11:42:45 +0530 | [diff] [blame] | 2539 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2540 | VERIFY(err, !fastrpc_mmap_create(fl, ud->fd, 0, |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 2541 | (uintptr_t)ud->vaddrin, ud->size, |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2542 | ud->flags, &map)); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2543 | mutex_unlock(&fl->fl_map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2544 | if (err) |
| 2545 | goto bail; |
| 2546 | VERIFY(err, 0 == fastrpc_mmap_on_dsp(fl, ud->flags, map)); |
| 2547 | if (err) |
| 2548 | goto bail; |
| 2549 | ud->vaddrout = map->raddr; |
| 2550 | bail: |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2551 | if (err && map) { |
| 2552 | mutex_lock(&fl->fl_map_mutex); |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 2553 | fastrpc_mmap_free(map, 0); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2554 | mutex_unlock(&fl->fl_map_mutex); |
| 2555 | } |
Tharun Kumar Merugu | c31eac5 | 2018-01-02 11:42:45 +0530 | [diff] [blame] | 2556 | mutex_unlock(&fl->map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2557 | return err; |
| 2558 | } |
| 2559 | |
| 2560 | static void fastrpc_channel_close(struct kref *kref) |
| 2561 | { |
| 2562 | struct fastrpc_apps *me = &gfa; |
| 2563 | struct fastrpc_channel_ctx *ctx; |
| 2564 | int cid; |
| 2565 | |
| 2566 | ctx = container_of(kref, struct fastrpc_channel_ctx, kref); |
| 2567 | cid = ctx - &gcinfo[0]; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 2568 | if (!me->glink) |
| 2569 | smd_close(ctx->chan); |
| 2570 | else |
| 2571 | fastrpc_glink_close(ctx->chan, cid); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2572 | ctx->chan = NULL; |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 2573 | mutex_unlock(&me->smd_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2574 | pr_info("'closed /dev/%s c %d %d'\n", gcinfo[cid].name, |
| 2575 | MAJOR(me->dev_no), cid); |
| 2576 | } |
| 2577 | |
| 2578 | static void fastrpc_context_list_dtor(struct fastrpc_file *fl); |
| 2579 | |
| 2580 | static int fastrpc_session_alloc_locked(struct fastrpc_channel_ctx *chan, |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 2581 | int secure, int sharedcb, struct fastrpc_session_ctx **session) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2582 | { |
| 2583 | struct fastrpc_apps *me = &gfa; |
| 2584 | int idx = 0, err = 0; |
| 2585 | |
| 2586 | if (chan->sesscount) { |
| 2587 | for (idx = 0; idx < chan->sesscount; ++idx) { |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 2588 | if ((sharedcb && chan->session[idx].smmu.sharedcb) || |
| 2589 | (!chan->session[idx].used && |
| 2590 | chan->session[idx].smmu.secure |
| 2591 | == secure && !sharedcb)) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2592 | chan->session[idx].used = 1; |
| 2593 | break; |
| 2594 | } |
| 2595 | } |
| 2596 | VERIFY(err, idx < chan->sesscount); |
| 2597 | if (err) |
| 2598 | goto bail; |
| 2599 | chan->session[idx].smmu.faults = 0; |
| 2600 | } else { |
| 2601 | VERIFY(err, me->dev != NULL); |
| 2602 | if (err) |
| 2603 | goto bail; |
| 2604 | chan->session[0].dev = me->dev; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2605 | chan->session[0].smmu.dev = me->dev; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | *session = &chan->session[idx]; |
| 2609 | bail: |
| 2610 | return err; |
| 2611 | } |
| 2612 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2613 | static bool fastrpc_glink_notify_rx_intent_req(void *h, const void *priv, |
| 2614 | size_t size) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2615 | { |
| 2616 | if (glink_queue_rx_intent(h, NULL, size)) |
| 2617 | return false; |
| 2618 | return true; |
| 2619 | } |
| 2620 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2621 | static void fastrpc_glink_notify_tx_done(void *handle, const void *priv, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2622 | const void *pkt_priv, const void *ptr) |
| 2623 | { |
| 2624 | } |
| 2625 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2626 | static void fastrpc_glink_notify_rx(void *handle, const void *priv, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2627 | const void *pkt_priv, const void *ptr, size_t size) |
| 2628 | { |
| 2629 | struct smq_invoke_rsp *rsp = (struct smq_invoke_rsp *)ptr; |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 2630 | struct fastrpc_apps *me = &gfa; |
| 2631 | uint32_t index; |
c_mtharu | fdac689 | 2017-10-12 13:09:01 +0530 | [diff] [blame] | 2632 | int err = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2633 | |
c_mtharu | fdac689 | 2017-10-12 13:09:01 +0530 | [diff] [blame] | 2634 | VERIFY(err, (rsp && size >= sizeof(*rsp))); |
| 2635 | if (err) |
Tharun Kumar Merugu | 622d871 | 2017-09-15 15:30:06 +0530 | [diff] [blame] | 2636 | goto bail; |
| 2637 | |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 2638 | index = (uint32_t)((rsp->ctx & FASTRPC_CTXID_MASK) >> 4); |
| 2639 | VERIFY(err, index < FASTRPC_CTX_MAX); |
c_mtharu | fdac689 | 2017-10-12 13:09:01 +0530 | [diff] [blame] | 2640 | if (err) |
Tharun Kumar Merugu | 622d871 | 2017-09-15 15:30:06 +0530 | [diff] [blame] | 2641 | goto bail; |
Tharun Kumar Merugu | 622d871 | 2017-09-15 15:30:06 +0530 | [diff] [blame] | 2642 | |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 2643 | VERIFY(err, !IS_ERR_OR_NULL(me->ctxtable[index])); |
| 2644 | if (err) |
| 2645 | goto bail; |
| 2646 | |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 2647 | VERIFY(err, ((me->ctxtable[index]->ctxid == (rsp->ctx & ~3)) && |
Tharun Kumar Merugu | 9c908aa | 2018-02-06 12:03:48 +0530 | [diff] [blame] | 2648 | me->ctxtable[index]->magic == FASTRPC_CTX_MAGIC)); |
| 2649 | if (err) |
| 2650 | goto bail; |
| 2651 | |
| 2652 | context_notify_user(me->ctxtable[index], rsp->retval); |
Tharun Kumar Merugu | 622d871 | 2017-09-15 15:30:06 +0530 | [diff] [blame] | 2653 | bail: |
c_mtharu | fdac689 | 2017-10-12 13:09:01 +0530 | [diff] [blame] | 2654 | if (err) |
| 2655 | pr_err("adsprpc: invalid response or context\n"); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2656 | glink_rx_done(handle, ptr, true); |
| 2657 | } |
| 2658 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2659 | static void fastrpc_glink_notify_state(void *handle, const void *priv, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2660 | unsigned int event) |
| 2661 | { |
| 2662 | struct fastrpc_apps *me = &gfa; |
| 2663 | int cid = (int)(uintptr_t)priv; |
| 2664 | struct fastrpc_glink_info *link; |
| 2665 | |
| 2666 | if (cid < 0 || cid >= NUM_CHANNELS) |
| 2667 | return; |
| 2668 | link = &me->channel[cid].link; |
| 2669 | switch (event) { |
| 2670 | case GLINK_CONNECTED: |
| 2671 | link->port_state = FASTRPC_LINK_CONNECTED; |
Tharun Kumar Merugu | 53a8ec9 | 2017-07-14 15:52:49 +0530 | [diff] [blame] | 2672 | complete(&me->channel[cid].workport); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2673 | break; |
| 2674 | case GLINK_LOCAL_DISCONNECTED: |
| 2675 | link->port_state = FASTRPC_LINK_DISCONNECTED; |
| 2676 | break; |
| 2677 | case GLINK_REMOTE_DISCONNECTED: |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2678 | break; |
| 2679 | default: |
| 2680 | break; |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | static int fastrpc_session_alloc(struct fastrpc_channel_ctx *chan, int secure, |
| 2685 | struct fastrpc_session_ctx **session) |
| 2686 | { |
| 2687 | int err = 0; |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 2688 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2689 | |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 2690 | mutex_lock(&me->smd_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2691 | if (!*session) |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 2692 | err = fastrpc_session_alloc_locked(chan, secure, 0, session); |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 2693 | mutex_unlock(&me->smd_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2694 | return err; |
| 2695 | } |
| 2696 | |
| 2697 | static void fastrpc_session_free(struct fastrpc_channel_ctx *chan, |
| 2698 | struct fastrpc_session_ctx *session) |
| 2699 | { |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 2700 | struct fastrpc_apps *me = &gfa; |
| 2701 | |
| 2702 | mutex_lock(&me->smd_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2703 | session->used = 0; |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 2704 | mutex_unlock(&me->smd_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | static int fastrpc_file_free(struct fastrpc_file *fl) |
| 2708 | { |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 2709 | struct hlist_node *n = NULL; |
Tharun Kumar Merugu | 3e96676 | 2018-04-04 10:56:44 +0530 | [diff] [blame] | 2710 | struct fastrpc_mmap *map = NULL, *lmap = NULL; |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 2711 | struct fastrpc_perf *perf = NULL, *fperf = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2712 | int cid; |
| 2713 | |
| 2714 | if (!fl) |
| 2715 | return 0; |
| 2716 | cid = fl->cid; |
| 2717 | |
Tharun Kumar Merugu | 622d871 | 2017-09-15 15:30:06 +0530 | [diff] [blame] | 2718 | (void)fastrpc_release_current_dsp_process(fl); |
| 2719 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2720 | spin_lock(&fl->apps->hlock); |
| 2721 | hlist_del_init(&fl->hn); |
| 2722 | spin_unlock(&fl->apps->hlock); |
| 2723 | |
Sathish Ambley | d7fbcbb | 2017-03-08 10:55:48 -0800 | [diff] [blame] | 2724 | if (!fl->sctx) { |
| 2725 | kfree(fl); |
| 2726 | return 0; |
| 2727 | } |
tharun kumar | 9f899ea | 2017-07-03 17:07:03 +0530 | [diff] [blame] | 2728 | spin_lock(&fl->hlock); |
| 2729 | fl->file_close = 1; |
| 2730 | spin_unlock(&fl->hlock); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2731 | fastrpc_context_list_dtor(fl); |
| 2732 | fastrpc_buf_list_free(fl); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2733 | mutex_lock(&fl->fl_map_mutex); |
Tharun Kumar Merugu | 3e96676 | 2018-04-04 10:56:44 +0530 | [diff] [blame] | 2734 | do { |
| 2735 | lmap = NULL; |
| 2736 | hlist_for_each_entry_safe(map, n, &fl->maps, hn) { |
| 2737 | hlist_del_init(&map->hn); |
| 2738 | lmap = map; |
| 2739 | break; |
| 2740 | } |
| 2741 | fastrpc_mmap_free(lmap, 1); |
| 2742 | } while (lmap); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2743 | mutex_unlock(&fl->fl_map_mutex); |
Tharun Kumar Merugu | 3517334 | 2018-02-08 16:13:17 +0530 | [diff] [blame] | 2744 | if (fl->refcount && (fl->ssrcount == fl->apps->channel[cid].ssrcount)) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2745 | kref_put_mutex(&fl->apps->channel[cid].kref, |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 2746 | fastrpc_channel_close, &fl->apps->smd_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2747 | if (fl->sctx) |
| 2748 | fastrpc_session_free(&fl->apps->channel[cid], fl->sctx); |
| 2749 | if (fl->secsctx) |
| 2750 | fastrpc_session_free(&fl->apps->channel[cid], fl->secsctx); |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 2751 | |
| 2752 | mutex_lock(&fl->perf_mutex); |
| 2753 | do { |
| 2754 | struct hlist_node *pn = NULL; |
| 2755 | |
| 2756 | fperf = NULL; |
| 2757 | hlist_for_each_entry_safe(perf, pn, &fl->perf, hn) { |
| 2758 | hlist_del_init(&perf->hn); |
| 2759 | fperf = perf; |
| 2760 | break; |
| 2761 | } |
| 2762 | kfree(fperf); |
| 2763 | } while (fperf); |
| 2764 | mutex_unlock(&fl->perf_mutex); |
| 2765 | mutex_destroy(&fl->perf_mutex); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 2766 | mutex_destroy(&fl->fl_map_mutex); |
Tharun Kumar Merugu | 8714e64 | 2018-05-17 15:21:08 +0530 | [diff] [blame] | 2767 | mutex_destroy(&fl->map_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2768 | kfree(fl); |
| 2769 | return 0; |
| 2770 | } |
| 2771 | |
| 2772 | static int fastrpc_device_release(struct inode *inode, struct file *file) |
| 2773 | { |
| 2774 | struct fastrpc_file *fl = (struct fastrpc_file *)file->private_data; |
| 2775 | |
| 2776 | if (fl) { |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 2777 | if (fl->qos_request && pm_qos_request_active(&fl->pm_qos_req)) |
| 2778 | pm_qos_remove_request(&fl->pm_qos_req); |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 2779 | if (fl->debugfs_file != NULL) |
| 2780 | debugfs_remove(fl->debugfs_file); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2781 | fastrpc_file_free(fl); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2782 | file->private_data = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2783 | } |
| 2784 | return 0; |
| 2785 | } |
| 2786 | |
| 2787 | static void fastrpc_link_state_handler(struct glink_link_state_cb_info *cb_info, |
| 2788 | void *priv) |
| 2789 | { |
| 2790 | struct fastrpc_apps *me = &gfa; |
| 2791 | int cid = (int)((uintptr_t)priv); |
| 2792 | struct fastrpc_glink_info *link; |
| 2793 | |
| 2794 | if (cid < 0 || cid >= NUM_CHANNELS) |
| 2795 | return; |
| 2796 | |
| 2797 | link = &me->channel[cid].link; |
| 2798 | switch (cb_info->link_state) { |
| 2799 | case GLINK_LINK_STATE_UP: |
| 2800 | link->link_state = FASTRPC_LINK_STATE_UP; |
| 2801 | complete(&me->channel[cid].work); |
| 2802 | break; |
| 2803 | case GLINK_LINK_STATE_DOWN: |
| 2804 | link->link_state = FASTRPC_LINK_STATE_DOWN; |
| 2805 | break; |
| 2806 | default: |
| 2807 | pr_err("adsprpc: unknown link state %d\n", cb_info->link_state); |
| 2808 | break; |
| 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | static int fastrpc_glink_register(int cid, struct fastrpc_apps *me) |
| 2813 | { |
| 2814 | int err = 0; |
| 2815 | struct fastrpc_glink_info *link; |
| 2816 | |
| 2817 | VERIFY(err, (cid >= 0 && cid < NUM_CHANNELS)); |
| 2818 | if (err) |
| 2819 | goto bail; |
| 2820 | |
| 2821 | link = &me->channel[cid].link; |
| 2822 | if (link->link_notify_handle != NULL) |
| 2823 | goto bail; |
| 2824 | |
| 2825 | link->link_info.glink_link_state_notif_cb = fastrpc_link_state_handler; |
| 2826 | link->link_notify_handle = glink_register_link_state_cb( |
| 2827 | &link->link_info, |
| 2828 | (void *)((uintptr_t)cid)); |
| 2829 | VERIFY(err, !IS_ERR_OR_NULL(me->channel[cid].link.link_notify_handle)); |
| 2830 | if (err) { |
| 2831 | link->link_notify_handle = NULL; |
| 2832 | goto bail; |
| 2833 | } |
| 2834 | VERIFY(err, wait_for_completion_timeout(&me->channel[cid].work, |
| 2835 | RPC_TIMEOUT)); |
| 2836 | bail: |
| 2837 | return err; |
| 2838 | } |
| 2839 | |
| 2840 | static void fastrpc_glink_close(void *chan, int cid) |
| 2841 | { |
| 2842 | int err = 0; |
| 2843 | struct fastrpc_glink_info *link; |
| 2844 | |
| 2845 | VERIFY(err, (cid >= 0 && cid < NUM_CHANNELS)); |
| 2846 | if (err) |
| 2847 | return; |
| 2848 | link = &gfa.channel[cid].link; |
| 2849 | |
c_mtharu | 314a420 | 2017-11-15 22:09:17 +0530 | [diff] [blame] | 2850 | if (link->port_state == FASTRPC_LINK_CONNECTED || |
| 2851 | link->port_state == FASTRPC_LINK_REMOTE_DISCONNECTING) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2852 | link->port_state = FASTRPC_LINK_DISCONNECTING; |
| 2853 | glink_close(chan); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | static int fastrpc_glink_open(int cid) |
| 2858 | { |
| 2859 | int err = 0; |
| 2860 | void *handle = NULL; |
| 2861 | struct fastrpc_apps *me = &gfa; |
| 2862 | struct glink_open_config *cfg; |
| 2863 | struct fastrpc_glink_info *link; |
| 2864 | |
| 2865 | VERIFY(err, (cid >= 0 && cid < NUM_CHANNELS)); |
| 2866 | if (err) |
| 2867 | goto bail; |
| 2868 | link = &me->channel[cid].link; |
| 2869 | cfg = &me->channel[cid].link.cfg; |
| 2870 | VERIFY(err, (link->link_state == FASTRPC_LINK_STATE_UP)); |
| 2871 | if (err) |
| 2872 | goto bail; |
| 2873 | |
Tharun Kumar Merugu | ca0db526 | 2017-05-10 12:53:12 +0530 | [diff] [blame] | 2874 | VERIFY(err, (link->port_state == FASTRPC_LINK_DISCONNECTED)); |
| 2875 | if (err) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2876 | goto bail; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2877 | |
| 2878 | link->port_state = FASTRPC_LINK_CONNECTING; |
| 2879 | cfg->priv = (void *)(uintptr_t)cid; |
| 2880 | cfg->edge = gcinfo[cid].link.link_info.edge; |
| 2881 | cfg->transport = gcinfo[cid].link.link_info.transport; |
| 2882 | cfg->name = FASTRPC_GLINK_GUID; |
| 2883 | cfg->notify_rx = fastrpc_glink_notify_rx; |
| 2884 | cfg->notify_tx_done = fastrpc_glink_notify_tx_done; |
| 2885 | cfg->notify_state = fastrpc_glink_notify_state; |
| 2886 | cfg->notify_rx_intent_req = fastrpc_glink_notify_rx_intent_req; |
| 2887 | handle = glink_open(cfg); |
| 2888 | VERIFY(err, !IS_ERR_OR_NULL(handle)); |
c_mtharu | 6e1d26b | 2017-10-09 16:05:24 +0530 | [diff] [blame] | 2889 | if (err) { |
| 2890 | if (link->port_state == FASTRPC_LINK_CONNECTING) |
| 2891 | link->port_state = FASTRPC_LINK_DISCONNECTED; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2892 | goto bail; |
c_mtharu | 6e1d26b | 2017-10-09 16:05:24 +0530 | [diff] [blame] | 2893 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 2894 | me->channel[cid].chan = handle; |
| 2895 | bail: |
| 2896 | return err; |
| 2897 | } |
| 2898 | |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 2899 | static int fastrpc_debugfs_open(struct inode *inode, struct file *filp) |
| 2900 | { |
| 2901 | filp->private_data = inode->i_private; |
| 2902 | return 0; |
| 2903 | } |
| 2904 | |
| 2905 | static ssize_t fastrpc_debugfs_read(struct file *filp, char __user *buffer, |
| 2906 | size_t count, loff_t *position) |
| 2907 | { |
| 2908 | struct fastrpc_file *fl = filp->private_data; |
| 2909 | struct hlist_node *n; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 2910 | struct fastrpc_buf *buf = NULL; |
| 2911 | struct fastrpc_mmap *map = NULL; |
| 2912 | struct smq_invoke_ctx *ictx = NULL; |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 2913 | struct fastrpc_channel_ctx *chan; |
| 2914 | struct fastrpc_session_ctx *sess; |
| 2915 | unsigned int len = 0; |
| 2916 | int i, j, ret = 0; |
| 2917 | char *fileinfo = NULL; |
| 2918 | |
| 2919 | fileinfo = kzalloc(DEBUGFS_SIZE, GFP_KERNEL); |
| 2920 | if (!fileinfo) |
| 2921 | goto bail; |
| 2922 | if (fl == NULL) { |
| 2923 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 2924 | chan = &gcinfo[i]; |
| 2925 | len += scnprintf(fileinfo + len, |
| 2926 | DEBUGFS_SIZE - len, "%s\n\n", |
| 2927 | chan->name); |
| 2928 | len += scnprintf(fileinfo + len, |
| 2929 | DEBUGFS_SIZE - len, "%s %d\n", |
| 2930 | "sesscount:", chan->sesscount); |
| 2931 | for (j = 0; j < chan->sesscount; j++) { |
| 2932 | sess = &chan->session[j]; |
| 2933 | len += scnprintf(fileinfo + len, |
| 2934 | DEBUGFS_SIZE - len, |
| 2935 | "%s%d\n\n", "SESSION", j); |
| 2936 | len += scnprintf(fileinfo + len, |
| 2937 | DEBUGFS_SIZE - len, |
| 2938 | "%s %d\n", "sid:", |
| 2939 | sess->smmu.cb); |
| 2940 | len += scnprintf(fileinfo + len, |
| 2941 | DEBUGFS_SIZE - len, |
| 2942 | "%s %d\n", "SECURE:", |
| 2943 | sess->smmu.secure); |
| 2944 | } |
| 2945 | } |
| 2946 | } else { |
| 2947 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
| 2948 | "%s %d\n\n", |
| 2949 | "PROCESS_ID:", fl->tgid); |
| 2950 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
| 2951 | "%s %d\n\n", |
| 2952 | "CHANNEL_ID:", fl->cid); |
| 2953 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
| 2954 | "%s %d\n\n", |
| 2955 | "SSRCOUNT:", fl->ssrcount); |
| 2956 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
| 2957 | "%s\n", |
| 2958 | "LIST OF BUFS:"); |
| 2959 | spin_lock(&fl->hlock); |
| 2960 | hlist_for_each_entry_safe(buf, n, &fl->bufs, hn) { |
| 2961 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
Tharun Kumar Merugu | ce56645 | 2017-08-17 15:29:59 +0530 | [diff] [blame] | 2962 | "%s %pK %s %pK %s %llx\n", "buf:", |
| 2963 | buf, "buf->virt:", buf->virt, |
| 2964 | "buf->phys:", buf->phys); |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 2965 | } |
| 2966 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
| 2967 | "\n%s\n", |
| 2968 | "LIST OF MAPS:"); |
| 2969 | hlist_for_each_entry_safe(map, n, &fl->maps, hn) { |
| 2970 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
Tharun Kumar Merugu | ce56645 | 2017-08-17 15:29:59 +0530 | [diff] [blame] | 2971 | "%s %pK %s %lx %s %llx\n", |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 2972 | "map:", map, |
| 2973 | "map->va:", map->va, |
| 2974 | "map->phys:", map->phys); |
| 2975 | } |
| 2976 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
| 2977 | "\n%s\n", |
| 2978 | "LIST OF PENDING SMQCONTEXTS:"); |
| 2979 | hlist_for_each_entry_safe(ictx, n, &fl->clst.pending, hn) { |
| 2980 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
Tharun Kumar Merugu | ce56645 | 2017-08-17 15:29:59 +0530 | [diff] [blame] | 2981 | "%s %pK %s %u %s %u %s %u\n", |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 2982 | "smqcontext:", ictx, |
| 2983 | "sc:", ictx->sc, |
| 2984 | "tid:", ictx->pid, |
| 2985 | "handle", ictx->rpra->h); |
| 2986 | } |
| 2987 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
| 2988 | "\n%s\n", |
| 2989 | "LIST OF INTERRUPTED SMQCONTEXTS:"); |
| 2990 | hlist_for_each_entry_safe(ictx, n, &fl->clst.interrupted, hn) { |
| 2991 | len += scnprintf(fileinfo + len, DEBUGFS_SIZE - len, |
Tharun Kumar Merugu | ce56645 | 2017-08-17 15:29:59 +0530 | [diff] [blame] | 2992 | "%s %pK %s %u %s %u %s %u\n", |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 2993 | "smqcontext:", ictx, |
| 2994 | "sc:", ictx->sc, |
| 2995 | "tid:", ictx->pid, |
| 2996 | "handle", ictx->rpra->h); |
| 2997 | } |
| 2998 | spin_unlock(&fl->hlock); |
| 2999 | } |
| 3000 | if (len > DEBUGFS_SIZE) |
| 3001 | len = DEBUGFS_SIZE; |
| 3002 | ret = simple_read_from_buffer(buffer, count, position, fileinfo, len); |
| 3003 | kfree(fileinfo); |
| 3004 | bail: |
| 3005 | return ret; |
| 3006 | } |
| 3007 | |
| 3008 | static const struct file_operations debugfs_fops = { |
| 3009 | .open = fastrpc_debugfs_open, |
| 3010 | .read = fastrpc_debugfs_read, |
| 3011 | }; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3012 | static int fastrpc_channel_open(struct fastrpc_file *fl) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3013 | { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3014 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3015 | int cid, err = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3016 | |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3017 | mutex_lock(&me->smd_mutex); |
| 3018 | |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3019 | VERIFY(err, fl && fl->sctx); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3020 | if (err) |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3021 | goto bail; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3022 | cid = fl->cid; |
c_mtharu | 314a420 | 2017-11-15 22:09:17 +0530 | [diff] [blame] | 3023 | VERIFY(err, cid >= 0 && cid < NUM_CHANNELS); |
| 3024 | if (err) |
| 3025 | goto bail; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3026 | if (me->channel[cid].ssrcount != |
| 3027 | me->channel[cid].prevssrcount) { |
| 3028 | if (!me->channel[cid].issubsystemup) { |
| 3029 | VERIFY(err, 0); |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3030 | if (err) { |
| 3031 | err = -ENOTCONN; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3032 | goto bail; |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3033 | } |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3034 | } |
| 3035 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3036 | fl->ssrcount = me->channel[cid].ssrcount; |
Tharun Kumar Merugu | 3517334 | 2018-02-08 16:13:17 +0530 | [diff] [blame] | 3037 | fl->refcount = 1; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3038 | if ((kref_get_unless_zero(&me->channel[cid].kref) == 0) || |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3039 | (me->channel[cid].chan == NULL)) { |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3040 | if (me->glink) { |
| 3041 | VERIFY(err, 0 == fastrpc_glink_register(cid, me)); |
| 3042 | if (err) |
| 3043 | goto bail; |
| 3044 | VERIFY(err, 0 == fastrpc_glink_open(cid)); |
| 3045 | } else { |
| 3046 | VERIFY(err, !smd_named_open_on_edge(FASTRPC_SMD_GUID, |
| 3047 | gcinfo[cid].channel, |
| 3048 | (smd_channel_t **)&me->channel[cid].chan, |
| 3049 | (void *)(uintptr_t)cid, |
| 3050 | smd_event_handler)); |
| 3051 | } |
Tharun Kumar Merugu | 53a8ec9 | 2017-07-14 15:52:49 +0530 | [diff] [blame] | 3052 | VERIFY(err, |
| 3053 | wait_for_completion_timeout(&me->channel[cid].workport, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3054 | RPC_TIMEOUT)); |
| 3055 | if (err) { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3056 | me->channel[cid].chan = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3057 | goto bail; |
| 3058 | } |
| 3059 | kref_init(&me->channel[cid].kref); |
| 3060 | pr_info("'opened /dev/%s c %d %d'\n", gcinfo[cid].name, |
| 3061 | MAJOR(me->dev_no), cid); |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3062 | if (me->glink) { |
| 3063 | err = glink_queue_rx_intent(me->channel[cid].chan, NULL, |
| 3064 | FASTRPC_GLINK_INTENT_LEN); |
| 3065 | err |= glink_queue_rx_intent(me->channel[cid].chan, |
| 3066 | NULL, FASTRPC_GLINK_INTENT_LEN); |
| 3067 | if (err) |
| 3068 | pr_warn("adsprpc: initial intent fail for %d err %d\n", |
| 3069 | cid, err); |
| 3070 | } |
Tharun Kumar Merugu | d86fc8c | 2018-01-04 16:35:31 +0530 | [diff] [blame] | 3071 | if (cid == 0 && me->channel[cid].ssrcount != |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3072 | me->channel[cid].prevssrcount) { |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3073 | if (fastrpc_mmap_remove_ssr(fl)) |
| 3074 | pr_err("ADSPRPC: SSR: Failed to unmap remote heap\n"); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3075 | me->channel[cid].prevssrcount = |
| 3076 | me->channel[cid].ssrcount; |
| 3077 | } |
| 3078 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3079 | |
| 3080 | bail: |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3081 | mutex_unlock(&me->smd_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3082 | return err; |
| 3083 | } |
| 3084 | |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3085 | static int fastrpc_device_open(struct inode *inode, struct file *filp) |
| 3086 | { |
| 3087 | int err = 0; |
Sathish Ambley | 567012b | 2017-03-06 11:55:04 -0800 | [diff] [blame] | 3088 | struct dentry *debugfs_file; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3089 | struct fastrpc_file *fl = NULL; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3090 | struct fastrpc_apps *me = &gfa; |
| 3091 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3092 | VERIFY(err, NULL != (fl = kzalloc(sizeof(*fl), GFP_KERNEL))); |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3093 | if (err) |
| 3094 | return err; |
Sathish Ambley | 567012b | 2017-03-06 11:55:04 -0800 | [diff] [blame] | 3095 | debugfs_file = debugfs_create_file(current->comm, 0644, debugfs_root, |
| 3096 | fl, &debugfs_fops); |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3097 | context_list_ctor(&fl->clst); |
| 3098 | spin_lock_init(&fl->hlock); |
| 3099 | INIT_HLIST_HEAD(&fl->maps); |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 3100 | INIT_HLIST_HEAD(&fl->perf); |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3101 | INIT_HLIST_HEAD(&fl->bufs); |
| 3102 | INIT_HLIST_NODE(&fl->hn); |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 3103 | fl->sessionid = 0; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3104 | fl->tgid = current->tgid; |
| 3105 | fl->apps = me; |
| 3106 | fl->mode = FASTRPC_MODE_SERIAL; |
| 3107 | fl->cid = -1; |
Sathish Ambley | 567012b | 2017-03-06 11:55:04 -0800 | [diff] [blame] | 3108 | if (debugfs_file != NULL) |
| 3109 | fl->debugfs_file = debugfs_file; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 3110 | fl->qos_request = 0; |
Tharun Kumar Merugu | 3517334 | 2018-02-08 16:13:17 +0530 | [diff] [blame] | 3111 | fl->refcount = 0; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3112 | filp->private_data = fl; |
Tharun Kumar Merugu | c31eac5 | 2018-01-02 11:42:45 +0530 | [diff] [blame] | 3113 | mutex_init(&fl->map_mutex); |
Tharun Kumar Merugu | ed7a847 | 2018-01-25 12:10:15 +0530 | [diff] [blame] | 3114 | mutex_init(&fl->fl_map_mutex); |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3115 | spin_lock(&me->hlock); |
| 3116 | hlist_add_head(&fl->hn, &me->drivers); |
| 3117 | spin_unlock(&me->hlock); |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 3118 | mutex_init(&fl->perf_mutex); |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3119 | return 0; |
| 3120 | } |
| 3121 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3122 | static int fastrpc_get_info(struct fastrpc_file *fl, uint32_t *info) |
| 3123 | { |
| 3124 | int err = 0; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3125 | uint32_t cid; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3126 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3127 | VERIFY(err, fl != NULL); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3128 | if (err) |
| 3129 | goto bail; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3130 | if (fl->cid == -1) { |
| 3131 | cid = *info; |
| 3132 | VERIFY(err, cid < NUM_CHANNELS); |
| 3133 | if (err) |
| 3134 | goto bail; |
| 3135 | fl->cid = cid; |
| 3136 | fl->ssrcount = fl->apps->channel[cid].ssrcount; |
| 3137 | VERIFY(err, !fastrpc_session_alloc_locked( |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 3138 | &fl->apps->channel[cid], 0, fl->sharedcb, &fl->sctx)); |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3139 | if (err) |
| 3140 | goto bail; |
| 3141 | } |
Tharun Kumar Merugu | 80be7d6 | 2017-08-02 11:03:22 +0530 | [diff] [blame] | 3142 | VERIFY(err, fl->sctx != NULL); |
| 3143 | if (err) |
| 3144 | goto bail; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3145 | *info = (fl->sctx->smmu.enabled ? 1 : 0); |
| 3146 | bail: |
| 3147 | return err; |
| 3148 | } |
| 3149 | |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 3150 | static int fastrpc_internal_control(struct fastrpc_file *fl, |
| 3151 | struct fastrpc_ioctl_control *cp) |
| 3152 | { |
| 3153 | int err = 0; |
| 3154 | int latency; |
| 3155 | |
| 3156 | VERIFY(err, !IS_ERR_OR_NULL(fl) && !IS_ERR_OR_NULL(fl->apps)); |
| 3157 | if (err) |
| 3158 | goto bail; |
| 3159 | VERIFY(err, !IS_ERR_OR_NULL(cp)); |
| 3160 | if (err) |
| 3161 | goto bail; |
| 3162 | |
| 3163 | switch (cp->req) { |
| 3164 | case FASTRPC_CONTROL_LATENCY: |
| 3165 | latency = cp->lp.enable == FASTRPC_LATENCY_CTRL_ENB ? |
| 3166 | fl->apps->latency : PM_QOS_DEFAULT_VALUE; |
| 3167 | VERIFY(err, latency != 0); |
| 3168 | if (err) |
| 3169 | goto bail; |
| 3170 | if (!fl->qos_request) { |
| 3171 | pm_qos_add_request(&fl->pm_qos_req, |
| 3172 | PM_QOS_CPU_DMA_LATENCY, latency); |
| 3173 | fl->qos_request = 1; |
| 3174 | } else |
| 3175 | pm_qos_update_request(&fl->pm_qos_req, latency); |
| 3176 | break; |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 3177 | case FASTRPC_CONTROL_SMMU: |
| 3178 | fl->sharedcb = cp->smmu.sharedcb; |
| 3179 | break; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 3180 | default: |
| 3181 | err = -ENOTTY; |
| 3182 | break; |
| 3183 | } |
| 3184 | bail: |
| 3185 | return err; |
| 3186 | } |
| 3187 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3188 | static long fastrpc_device_ioctl(struct file *file, unsigned int ioctl_num, |
| 3189 | unsigned long ioctl_param) |
| 3190 | { |
| 3191 | union { |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 3192 | struct fastrpc_ioctl_invoke_crc inv; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3193 | struct fastrpc_ioctl_mmap mmap; |
| 3194 | struct fastrpc_ioctl_munmap munmap; |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 3195 | struct fastrpc_ioctl_munmap_fd munmap_fd; |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 3196 | struct fastrpc_ioctl_init_attrs init; |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 3197 | struct fastrpc_ioctl_perf perf; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 3198 | struct fastrpc_ioctl_control cp; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3199 | } p; |
| 3200 | void *param = (char *)ioctl_param; |
| 3201 | struct fastrpc_file *fl = (struct fastrpc_file *)file->private_data; |
| 3202 | int size = 0, err = 0; |
| 3203 | uint32_t info; |
| 3204 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3205 | p.inv.fds = NULL; |
| 3206 | p.inv.attrs = NULL; |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 3207 | p.inv.crc = NULL; |
tharun kumar | 9f899ea | 2017-07-03 17:07:03 +0530 | [diff] [blame] | 3208 | spin_lock(&fl->hlock); |
| 3209 | if (fl->file_close == 1) { |
| 3210 | err = EBADF; |
| 3211 | pr_warn("ADSPRPC: fastrpc_device_release is happening, So not sending any new requests to DSP"); |
| 3212 | spin_unlock(&fl->hlock); |
| 3213 | goto bail; |
| 3214 | } |
| 3215 | spin_unlock(&fl->hlock); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3216 | |
| 3217 | switch (ioctl_num) { |
| 3218 | case FASTRPC_IOCTL_INVOKE: |
| 3219 | size = sizeof(struct fastrpc_ioctl_invoke); |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 3220 | /* fall through */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3221 | case FASTRPC_IOCTL_INVOKE_FD: |
| 3222 | if (!size) |
| 3223 | size = sizeof(struct fastrpc_ioctl_invoke_fd); |
| 3224 | /* fall through */ |
| 3225 | case FASTRPC_IOCTL_INVOKE_ATTRS: |
| 3226 | if (!size) |
| 3227 | size = sizeof(struct fastrpc_ioctl_invoke_attrs); |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 3228 | /* fall through */ |
| 3229 | case FASTRPC_IOCTL_INVOKE_CRC: |
| 3230 | if (!size) |
| 3231 | size = sizeof(struct fastrpc_ioctl_invoke_crc); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3232 | K_COPY_FROM_USER(err, 0, &p.inv, param, size); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3233 | if (err) |
| 3234 | goto bail; |
| 3235 | VERIFY(err, 0 == (err = fastrpc_internal_invoke(fl, fl->mode, |
| 3236 | 0, &p.inv))); |
| 3237 | if (err) |
| 3238 | goto bail; |
| 3239 | break; |
| 3240 | case FASTRPC_IOCTL_MMAP: |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3241 | K_COPY_FROM_USER(err, 0, &p.mmap, param, |
| 3242 | sizeof(p.mmap)); |
Tharun Kumar Merugu | d1f388a | 2017-10-01 10:51:11 +0530 | [diff] [blame] | 3243 | if (err) |
| 3244 | goto bail; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3245 | VERIFY(err, 0 == (err = fastrpc_internal_mmap(fl, &p.mmap))); |
| 3246 | if (err) |
| 3247 | goto bail; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3248 | K_COPY_TO_USER(err, 0, param, &p.mmap, sizeof(p.mmap)); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3249 | if (err) |
| 3250 | goto bail; |
| 3251 | break; |
| 3252 | case FASTRPC_IOCTL_MUNMAP: |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3253 | K_COPY_FROM_USER(err, 0, &p.munmap, param, |
| 3254 | sizeof(p.munmap)); |
Tharun Kumar Merugu | d1f388a | 2017-10-01 10:51:11 +0530 | [diff] [blame] | 3255 | if (err) |
| 3256 | goto bail; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3257 | VERIFY(err, 0 == (err = fastrpc_internal_munmap(fl, |
| 3258 | &p.munmap))); |
| 3259 | if (err) |
| 3260 | goto bail; |
| 3261 | break; |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 3262 | case FASTRPC_IOCTL_MMAP_64: |
| 3263 | K_COPY_FROM_USER(err, 0, &p.mmap, param, |
| 3264 | sizeof(p.mmap)); |
| 3265 | if (err) |
| 3266 | goto bail; |
| 3267 | VERIFY(err, 0 == (err = fastrpc_internal_mmap(fl, &p.mmap))); |
| 3268 | if (err) |
| 3269 | goto bail; |
| 3270 | K_COPY_TO_USER(err, 0, param, &p.mmap, sizeof(p.mmap)); |
| 3271 | if (err) |
| 3272 | goto bail; |
| 3273 | break; |
| 3274 | case FASTRPC_IOCTL_MUNMAP_64: |
| 3275 | K_COPY_FROM_USER(err, 0, &p.munmap, param, |
| 3276 | sizeof(p.munmap)); |
| 3277 | if (err) |
| 3278 | goto bail; |
| 3279 | VERIFY(err, 0 == (err = fastrpc_internal_munmap(fl, |
| 3280 | &p.munmap))); |
| 3281 | if (err) |
| 3282 | goto bail; |
| 3283 | break; |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 3284 | case FASTRPC_IOCTL_MUNMAP_FD: |
| 3285 | K_COPY_FROM_USER(err, 0, &p.munmap_fd, param, |
| 3286 | sizeof(p.munmap_fd)); |
| 3287 | if (err) |
| 3288 | goto bail; |
| 3289 | VERIFY(err, 0 == (err = fastrpc_internal_munmap_fd(fl, |
| 3290 | &p.munmap_fd))); |
| 3291 | if (err) |
| 3292 | goto bail; |
| 3293 | break; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3294 | case FASTRPC_IOCTL_SETMODE: |
| 3295 | switch ((uint32_t)ioctl_param) { |
| 3296 | case FASTRPC_MODE_PARALLEL: |
| 3297 | case FASTRPC_MODE_SERIAL: |
| 3298 | fl->mode = (uint32_t)ioctl_param; |
| 3299 | break; |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 3300 | case FASTRPC_MODE_PROFILE: |
| 3301 | fl->profile = (uint32_t)ioctl_param; |
| 3302 | break; |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 3303 | case FASTRPC_MODE_SESSION: |
| 3304 | fl->sessionid = 1; |
| 3305 | fl->tgid |= (1 << SESSION_ID_INDEX); |
| 3306 | break; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3307 | default: |
| 3308 | err = -ENOTTY; |
| 3309 | break; |
| 3310 | } |
| 3311 | break; |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 3312 | case FASTRPC_IOCTL_GETPERF: |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3313 | K_COPY_FROM_USER(err, 0, &p.perf, |
| 3314 | param, sizeof(p.perf)); |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 3315 | if (err) |
| 3316 | goto bail; |
| 3317 | p.perf.numkeys = sizeof(struct fastrpc_perf)/sizeof(int64_t); |
| 3318 | if (p.perf.keys) { |
| 3319 | char *keys = PERF_KEYS; |
| 3320 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3321 | K_COPY_TO_USER(err, 0, (void *)p.perf.keys, |
| 3322 | keys, strlen(keys)+1); |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 3323 | if (err) |
| 3324 | goto bail; |
| 3325 | } |
| 3326 | if (p.perf.data) { |
Tharun Kumar Merugu | 7c966dd | 2018-01-04 18:07:03 +0530 | [diff] [blame] | 3327 | struct fastrpc_perf *perf = NULL, *fperf = NULL; |
| 3328 | struct hlist_node *n = NULL; |
| 3329 | |
| 3330 | mutex_lock(&fl->perf_mutex); |
| 3331 | hlist_for_each_entry_safe(perf, n, &fl->perf, hn) { |
| 3332 | if (perf->tid == current->pid) { |
| 3333 | fperf = perf; |
| 3334 | break; |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | mutex_unlock(&fl->perf_mutex); |
| 3339 | |
| 3340 | if (fperf) { |
| 3341 | K_COPY_TO_USER(err, 0, (void *)p.perf.data, |
| 3342 | fperf, sizeof(*fperf)); |
| 3343 | } |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 3344 | } |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3345 | K_COPY_TO_USER(err, 0, param, &p.perf, sizeof(p.perf)); |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 3346 | if (err) |
| 3347 | goto bail; |
| 3348 | break; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 3349 | case FASTRPC_IOCTL_CONTROL: |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3350 | K_COPY_FROM_USER(err, 0, &p.cp, param, |
| 3351 | sizeof(p.cp)); |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 3352 | if (err) |
| 3353 | goto bail; |
| 3354 | VERIFY(err, 0 == (err = fastrpc_internal_control(fl, &p.cp))); |
| 3355 | if (err) |
| 3356 | goto bail; |
| 3357 | break; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3358 | case FASTRPC_IOCTL_GETINFO: |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3359 | K_COPY_FROM_USER(err, 0, &info, param, sizeof(info)); |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3360 | if (err) |
| 3361 | goto bail; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3362 | VERIFY(err, 0 == (err = fastrpc_get_info(fl, &info))); |
| 3363 | if (err) |
| 3364 | goto bail; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3365 | K_COPY_TO_USER(err, 0, param, &info, sizeof(info)); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3366 | if (err) |
| 3367 | goto bail; |
| 3368 | break; |
| 3369 | case FASTRPC_IOCTL_INIT: |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 3370 | p.init.attrs = 0; |
| 3371 | p.init.siglen = 0; |
| 3372 | size = sizeof(struct fastrpc_ioctl_init); |
| 3373 | /* fall through */ |
| 3374 | case FASTRPC_IOCTL_INIT_ATTRS: |
| 3375 | if (!size) |
| 3376 | size = sizeof(struct fastrpc_ioctl_init_attrs); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3377 | K_COPY_FROM_USER(err, 0, &p.init, param, size); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3378 | if (err) |
| 3379 | goto bail; |
Tharun Kumar Merugu | 4ea0eac | 2017-08-22 11:42:51 +0530 | [diff] [blame] | 3380 | VERIFY(err, p.init.init.filelen >= 0 && |
Tharun Kumar Merugu | d1f388a | 2017-10-01 10:51:11 +0530 | [diff] [blame] | 3381 | p.init.init.filelen < INIT_FILELEN_MAX); |
| 3382 | if (err) |
| 3383 | goto bail; |
| 3384 | VERIFY(err, p.init.init.memlen >= 0 && |
| 3385 | p.init.init.memlen < INIT_MEMLEN_MAX); |
Tharun Kumar Merugu | 4ea0eac | 2017-08-22 11:42:51 +0530 | [diff] [blame] | 3386 | if (err) |
| 3387 | goto bail; |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3388 | VERIFY(err, 0 == (err = fastrpc_init_process(fl, &p.init))); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3389 | if (err) |
| 3390 | goto bail; |
| 3391 | break; |
| 3392 | |
| 3393 | default: |
| 3394 | err = -ENOTTY; |
| 3395 | pr_info("bad ioctl: %d\n", ioctl_num); |
| 3396 | break; |
| 3397 | } |
| 3398 | bail: |
| 3399 | return err; |
| 3400 | } |
| 3401 | |
| 3402 | static int fastrpc_restart_notifier_cb(struct notifier_block *nb, |
| 3403 | unsigned long code, |
| 3404 | void *data) |
| 3405 | { |
| 3406 | struct fastrpc_apps *me = &gfa; |
| 3407 | struct fastrpc_channel_ctx *ctx; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3408 | struct notif_data *notifdata = data; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3409 | int cid; |
| 3410 | |
| 3411 | ctx = container_of(nb, struct fastrpc_channel_ctx, nb); |
| 3412 | cid = ctx - &me->channel[0]; |
| 3413 | if (code == SUBSYS_BEFORE_SHUTDOWN) { |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3414 | mutex_lock(&me->smd_mutex); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3415 | ctx->ssrcount++; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3416 | ctx->issubsystemup = 0; |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3417 | if (ctx->chan) { |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3418 | if (me->glink) |
| 3419 | fastrpc_glink_close(ctx->chan, cid); |
| 3420 | else |
| 3421 | smd_close(ctx->chan); |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3422 | ctx->chan = NULL; |
| 3423 | pr_info("'restart notifier: closed /dev/%s c %d %d'\n", |
| 3424 | gcinfo[cid].name, MAJOR(me->dev_no), cid); |
| 3425 | } |
| 3426 | mutex_unlock(&me->smd_mutex); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3427 | if (cid == 0) |
| 3428 | me->staticpd_flags = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3429 | fastrpc_notify_drivers(me, cid); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3430 | } else if (code == SUBSYS_RAMDUMP_NOTIFICATION) { |
| 3431 | if (me->channel[0].remoteheap_ramdump_dev && |
| 3432 | notifdata->enable_ramdump) { |
| 3433 | me->channel[0].ramdumpenabled = 1; |
| 3434 | } |
| 3435 | } else if (code == SUBSYS_AFTER_POWERUP) { |
| 3436 | ctx->issubsystemup = 1; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | return NOTIFY_DONE; |
| 3440 | } |
| 3441 | |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 3442 | static int fastrpc_pdr_notifier_cb(struct notifier_block *pdrnb, |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 3443 | unsigned long code, |
| 3444 | void *data) |
| 3445 | { |
| 3446 | struct fastrpc_apps *me = &gfa; |
| 3447 | struct fastrpc_static_pd *spd; |
| 3448 | struct notif_data *notifdata = data; |
| 3449 | |
| 3450 | spd = container_of(pdrnb, struct fastrpc_static_pd, pdrnb); |
| 3451 | if (code == SERVREG_NOTIF_SERVICE_STATE_DOWN_V01) { |
| 3452 | mutex_lock(&me->smd_mutex); |
| 3453 | spd->pdrcount++; |
| 3454 | spd->ispdup = 0; |
| 3455 | pr_info("ADSPRPC: Audio PDR notifier %d %s\n", |
| 3456 | MAJOR(me->dev_no), spd->spdname); |
| 3457 | mutex_unlock(&me->smd_mutex); |
| 3458 | if (!strcmp(spd->spdname, |
| 3459 | AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME)) |
| 3460 | me->staticpd_flags = 0; |
| 3461 | fastrpc_notify_pdr_drivers(me, spd->spdname); |
| 3462 | } else if (code == SUBSYS_RAMDUMP_NOTIFICATION) { |
| 3463 | if (me->channel[0].remoteheap_ramdump_dev && |
| 3464 | notifdata->enable_ramdump) { |
| 3465 | me->channel[0].ramdumpenabled = 1; |
| 3466 | } |
| 3467 | } else if (code == SERVREG_NOTIF_SERVICE_STATE_UP_V01) { |
| 3468 | spd->ispdup = 1; |
| 3469 | } |
| 3470 | |
| 3471 | return NOTIFY_DONE; |
| 3472 | } |
| 3473 | |
| 3474 | static int fastrpc_get_service_location_notify(struct notifier_block *nb, |
| 3475 | unsigned long opcode, void *data) |
| 3476 | { |
| 3477 | struct fastrpc_static_pd *spd; |
| 3478 | struct pd_qmi_client_data *pdr = data; |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 3479 | int curr_state = 0, i = 0; |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 3480 | |
| 3481 | spd = container_of(nb, struct fastrpc_static_pd, get_service_nb); |
| 3482 | if (opcode == LOCATOR_DOWN) { |
| 3483 | pr_err("ADSPRPC: Audio PD restart notifier locator down\n"); |
| 3484 | return NOTIFY_DONE; |
| 3485 | } |
| 3486 | |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 3487 | for (i = 0; i < pdr->total_domains; i++) { |
| 3488 | if ((!strcmp(pdr->domain_list[i].name, |
| 3489 | "msm/adsp/audio_pd")) || |
| 3490 | (!strcmp(pdr->domain_list[i].name, |
| 3491 | "msm/adsp/sensor_pd"))) { |
| 3492 | spd->pdrhandle = |
| 3493 | service_notif_register_notifier( |
| 3494 | pdr->domain_list[i].name, |
| 3495 | pdr->domain_list[i].instance_id, |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 3496 | &spd->pdrnb, &curr_state); |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 3497 | if (IS_ERR(spd->pdrhandle)) |
| 3498 | pr_err("ADSPRPC: Unable to register notifier\n"); |
| 3499 | break; |
| 3500 | } |
| 3501 | } |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 3502 | |
| 3503 | return NOTIFY_DONE; |
| 3504 | } |
| 3505 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3506 | static const struct file_operations fops = { |
| 3507 | .open = fastrpc_device_open, |
| 3508 | .release = fastrpc_device_release, |
| 3509 | .unlocked_ioctl = fastrpc_device_ioctl, |
| 3510 | .compat_ioctl = compat_fastrpc_device_ioctl, |
| 3511 | }; |
| 3512 | |
| 3513 | static const struct of_device_id fastrpc_match_table[] = { |
| 3514 | { .compatible = "qcom,msm-fastrpc-adsp", }, |
| 3515 | { .compatible = "qcom,msm-fastrpc-compute", }, |
| 3516 | { .compatible = "qcom,msm-fastrpc-compute-cb", }, |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3517 | { .compatible = "qcom,msm-fastrpc-legacy-compute", }, |
| 3518 | { .compatible = "qcom,msm-fastrpc-legacy-compute-cb", }, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3519 | { .compatible = "qcom,msm-adsprpc-mem-region", }, |
| 3520 | {} |
| 3521 | }; |
| 3522 | |
| 3523 | static int fastrpc_cb_probe(struct device *dev) |
| 3524 | { |
| 3525 | struct fastrpc_channel_ctx *chan; |
| 3526 | struct fastrpc_session_ctx *sess; |
| 3527 | struct of_phandle_args iommuspec; |
| 3528 | const char *name; |
| 3529 | unsigned int start = 0x80000000; |
| 3530 | int err = 0, i; |
| 3531 | int secure_vmid = VMID_CP_PIXEL; |
| 3532 | |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3533 | VERIFY(err, NULL != (name = of_get_property(dev->of_node, |
| 3534 | "label", NULL))); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3535 | if (err) |
| 3536 | goto bail; |
| 3537 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 3538 | if (!gcinfo[i].name) |
| 3539 | continue; |
| 3540 | if (!strcmp(name, gcinfo[i].name)) |
| 3541 | break; |
| 3542 | } |
| 3543 | VERIFY(err, i < NUM_CHANNELS); |
| 3544 | if (err) |
| 3545 | goto bail; |
| 3546 | chan = &gcinfo[i]; |
| 3547 | VERIFY(err, chan->sesscount < NUM_SESSIONS); |
| 3548 | if (err) |
| 3549 | goto bail; |
| 3550 | |
| 3551 | VERIFY(err, !of_parse_phandle_with_args(dev->of_node, "iommus", |
| 3552 | "#iommu-cells", 0, &iommuspec)); |
| 3553 | if (err) |
| 3554 | goto bail; |
| 3555 | sess = &chan->session[chan->sesscount]; |
| 3556 | sess->smmu.cb = iommuspec.args[0] & 0xf; |
| 3557 | sess->used = 0; |
| 3558 | sess->smmu.coherent = of_property_read_bool(dev->of_node, |
| 3559 | "dma-coherent"); |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 3560 | sess->smmu.sharedcb = of_property_read_bool(dev->of_node, |
| 3561 | "shared-cb"); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3562 | sess->smmu.secure = of_property_read_bool(dev->of_node, |
| 3563 | "qcom,secure-context-bank"); |
| 3564 | if (sess->smmu.secure) |
| 3565 | start = 0x60000000; |
| 3566 | VERIFY(err, !IS_ERR_OR_NULL(sess->smmu.mapping = |
| 3567 | arm_iommu_create_mapping(&platform_bus_type, |
Tharun Kumar Merugu | ca183f9 | 2017-04-27 17:43:27 +0530 | [diff] [blame] | 3568 | start, 0x78000000))); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3569 | if (err) |
| 3570 | goto bail; |
| 3571 | |
| 3572 | if (sess->smmu.secure) |
| 3573 | iommu_domain_set_attr(sess->smmu.mapping->domain, |
| 3574 | DOMAIN_ATTR_SECURE_VMID, |
| 3575 | &secure_vmid); |
| 3576 | |
| 3577 | VERIFY(err, !arm_iommu_attach_device(dev, sess->smmu.mapping)); |
| 3578 | if (err) |
| 3579 | goto bail; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3580 | sess->smmu.dev = dev; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3581 | sess->smmu.enabled = 1; |
| 3582 | chan->sesscount++; |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 3583 | debugfs_global_file = debugfs_create_file("global", 0644, debugfs_root, |
| 3584 | NULL, &debugfs_fops); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3585 | bail: |
| 3586 | return err; |
| 3587 | } |
| 3588 | |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3589 | static int fastrpc_cb_legacy_probe(struct device *dev) |
| 3590 | { |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3591 | struct fastrpc_channel_ctx *chan; |
| 3592 | struct fastrpc_session_ctx *first_sess = NULL, *sess = NULL; |
| 3593 | const char *name; |
| 3594 | unsigned int *sids = NULL, sids_size = 0; |
| 3595 | int err = 0, ret = 0, i; |
| 3596 | |
| 3597 | unsigned int start = 0x80000000; |
| 3598 | |
| 3599 | VERIFY(err, NULL != (name = of_get_property(dev->of_node, |
| 3600 | "label", NULL))); |
| 3601 | if (err) |
| 3602 | goto bail; |
| 3603 | |
| 3604 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 3605 | if (!gcinfo[i].name) |
| 3606 | continue; |
| 3607 | if (!strcmp(name, gcinfo[i].name)) |
| 3608 | break; |
| 3609 | } |
| 3610 | VERIFY(err, i < NUM_CHANNELS); |
| 3611 | if (err) |
| 3612 | goto bail; |
| 3613 | |
| 3614 | chan = &gcinfo[i]; |
| 3615 | VERIFY(err, chan->sesscount < NUM_SESSIONS); |
| 3616 | if (err) |
| 3617 | goto bail; |
| 3618 | |
| 3619 | first_sess = &chan->session[chan->sesscount]; |
| 3620 | |
| 3621 | VERIFY(err, NULL != of_get_property(dev->of_node, |
| 3622 | "sids", &sids_size)); |
| 3623 | if (err) |
| 3624 | goto bail; |
| 3625 | |
| 3626 | VERIFY(err, NULL != (sids = kzalloc(sids_size, GFP_KERNEL))); |
| 3627 | if (err) |
| 3628 | goto bail; |
| 3629 | ret = of_property_read_u32_array(dev->of_node, "sids", sids, |
| 3630 | sids_size/sizeof(unsigned int)); |
| 3631 | if (ret) |
| 3632 | goto bail; |
| 3633 | |
| 3634 | VERIFY(err, !IS_ERR_OR_NULL(first_sess->smmu.mapping = |
| 3635 | arm_iommu_create_mapping(&platform_bus_type, |
| 3636 | start, 0x78000000))); |
| 3637 | if (err) |
| 3638 | goto bail; |
| 3639 | |
| 3640 | VERIFY(err, !arm_iommu_attach_device(dev, first_sess->smmu.mapping)); |
| 3641 | if (err) |
| 3642 | goto bail; |
| 3643 | |
| 3644 | |
| 3645 | for (i = 0; i < sids_size/sizeof(unsigned int); i++) { |
| 3646 | VERIFY(err, chan->sesscount < NUM_SESSIONS); |
| 3647 | if (err) |
| 3648 | goto bail; |
| 3649 | sess = &chan->session[chan->sesscount]; |
| 3650 | sess->smmu.cb = sids[i]; |
| 3651 | sess->smmu.dev = dev; |
| 3652 | sess->smmu.mapping = first_sess->smmu.mapping; |
| 3653 | sess->smmu.enabled = 1; |
| 3654 | sess->used = 0; |
| 3655 | sess->smmu.coherent = false; |
| 3656 | sess->smmu.secure = false; |
| 3657 | chan->sesscount++; |
| 3658 | } |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3659 | bail: |
| 3660 | kfree(sids); |
| 3661 | return err; |
| 3662 | } |
| 3663 | |
| 3664 | |
| 3665 | |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 3666 | static void init_secure_vmid_list(struct device *dev, char *prop_name, |
| 3667 | struct secure_vm *destvm) |
| 3668 | { |
| 3669 | int err = 0; |
| 3670 | u32 len = 0, i = 0; |
| 3671 | u32 *rhvmlist = NULL; |
| 3672 | u32 *rhvmpermlist = NULL; |
| 3673 | |
| 3674 | if (!of_find_property(dev->of_node, prop_name, &len)) |
| 3675 | goto bail; |
| 3676 | if (len == 0) |
| 3677 | goto bail; |
| 3678 | len /= sizeof(u32); |
| 3679 | VERIFY(err, NULL != (rhvmlist = kcalloc(len, sizeof(u32), GFP_KERNEL))); |
| 3680 | if (err) |
| 3681 | goto bail; |
| 3682 | VERIFY(err, NULL != (rhvmpermlist = kcalloc(len, sizeof(u32), |
| 3683 | GFP_KERNEL))); |
| 3684 | if (err) |
| 3685 | goto bail; |
| 3686 | for (i = 0; i < len; i++) { |
| 3687 | err = of_property_read_u32_index(dev->of_node, prop_name, i, |
| 3688 | &rhvmlist[i]); |
| 3689 | rhvmpermlist[i] = PERM_READ | PERM_WRITE | PERM_EXEC; |
| 3690 | pr_info("ADSPRPC: Secure VMID = %d", rhvmlist[i]); |
| 3691 | if (err) { |
| 3692 | pr_err("ADSPRPC: Failed to read VMID\n"); |
| 3693 | goto bail; |
| 3694 | } |
| 3695 | } |
| 3696 | destvm->vmid = rhvmlist; |
| 3697 | destvm->vmperm = rhvmpermlist; |
| 3698 | destvm->vmcount = len; |
| 3699 | bail: |
| 3700 | if (err) { |
| 3701 | kfree(rhvmlist); |
| 3702 | kfree(rhvmpermlist); |
| 3703 | } |
| 3704 | } |
| 3705 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3706 | static int fastrpc_probe(struct platform_device *pdev) |
| 3707 | { |
| 3708 | int err = 0; |
| 3709 | struct fastrpc_apps *me = &gfa; |
| 3710 | struct device *dev = &pdev->dev; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3711 | struct device_node *ion_node, *node; |
| 3712 | struct platform_device *ion_pdev; |
| 3713 | struct cma *cma; |
| 3714 | uint32_t val; |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 3715 | int ret = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3716 | |
c_mtharu | 63ffc01 | 2017-11-16 15:26:56 +0530 | [diff] [blame] | 3717 | |
| 3718 | if (of_device_is_compatible(dev->of_node, |
| 3719 | "qcom,msm-fastrpc-compute")) { |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 3720 | init_secure_vmid_list(dev, "qcom,adsp-remoteheap-vmid", |
| 3721 | &gcinfo[0].rhvm); |
c_mtharu | 63ffc01 | 2017-11-16 15:26:56 +0530 | [diff] [blame] | 3722 | |
c_mtharu | 63ffc01 | 2017-11-16 15:26:56 +0530 | [diff] [blame] | 3723 | |
| 3724 | of_property_read_u32(dev->of_node, "qcom,rpc-latency-us", |
| 3725 | &me->latency); |
| 3726 | } |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3727 | if (of_device_is_compatible(dev->of_node, |
| 3728 | "qcom,msm-fastrpc-compute-cb")) |
| 3729 | return fastrpc_cb_probe(dev); |
| 3730 | |
| 3731 | if (of_device_is_compatible(dev->of_node, |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3732 | "qcom,msm-fastrpc-legacy-compute")) { |
| 3733 | me->glink = false; |
Tharun Kumar Merugu | 4f2dcc8 | 2018-03-29 00:35:49 +0530 | [diff] [blame] | 3734 | me->legacy = 1; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | if (of_device_is_compatible(dev->of_node, |
| 3738 | "qcom,msm-fastrpc-legacy-compute-cb")){ |
| 3739 | return fastrpc_cb_legacy_probe(dev); |
| 3740 | } |
| 3741 | |
| 3742 | if (of_device_is_compatible(dev->of_node, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3743 | "qcom,msm-adsprpc-mem-region")) { |
| 3744 | me->dev = dev; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3745 | ion_node = of_find_compatible_node(NULL, NULL, "qcom,msm-ion"); |
| 3746 | if (ion_node) { |
| 3747 | for_each_available_child_of_node(ion_node, node) { |
| 3748 | if (of_property_read_u32(node, "reg", &val)) |
| 3749 | continue; |
| 3750 | if (val != ION_ADSP_HEAP_ID) |
| 3751 | continue; |
| 3752 | ion_pdev = of_find_device_by_node(node); |
| 3753 | if (!ion_pdev) |
| 3754 | break; |
| 3755 | cma = dev_get_cma_area(&ion_pdev->dev); |
| 3756 | if (cma) { |
Tharun Kumar Merugu | 4f2dcc8 | 2018-03-29 00:35:49 +0530 | [diff] [blame] | 3757 | me->range.addr = cma_get_base(cma); |
| 3758 | me->range.size = |
| 3759 | (size_t)cma_get_size(cma); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3760 | } |
| 3761 | break; |
| 3762 | } |
| 3763 | } |
Tharun Kumar Merugu | 4f2dcc8 | 2018-03-29 00:35:49 +0530 | [diff] [blame] | 3764 | if (me->range.addr && !of_property_read_bool(dev->of_node, |
Tharun Kumar Merugu | 6b7a4a2 | 2018-01-17 16:08:07 +0530 | [diff] [blame] | 3765 | "restrict-access")) { |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3766 | int srcVM[1] = {VMID_HLOS}; |
| 3767 | int destVM[4] = {VMID_HLOS, VMID_MSS_MSA, VMID_SSC_Q6, |
| 3768 | VMID_ADSP_Q6}; |
Sathish Ambley | 84d1186 | 2017-05-15 14:36:05 -0700 | [diff] [blame] | 3769 | int destVMperm[4] = {PERM_READ | PERM_WRITE | PERM_EXEC, |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3770 | PERM_READ | PERM_WRITE | PERM_EXEC, |
| 3771 | PERM_READ | PERM_WRITE | PERM_EXEC, |
| 3772 | PERM_READ | PERM_WRITE | PERM_EXEC, |
| 3773 | }; |
| 3774 | |
Tharun Kumar Merugu | 4f2dcc8 | 2018-03-29 00:35:49 +0530 | [diff] [blame] | 3775 | VERIFY(err, !hyp_assign_phys(me->range.addr, |
| 3776 | me->range.size, srcVM, 1, |
| 3777 | destVM, destVMperm, 4)); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3778 | if (err) |
| 3779 | goto bail; |
| 3780 | } |
| 3781 | return 0; |
| 3782 | } |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 3783 | if (of_property_read_bool(dev->of_node, |
| 3784 | "qcom,fastrpc-adsp-audio-pdr")) { |
| 3785 | int session; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3786 | |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 3787 | VERIFY(err, !fastrpc_get_adsp_session( |
| 3788 | AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME, &session)); |
| 3789 | if (err) |
| 3790 | goto spdbail; |
| 3791 | me->channel[0].spd[session].get_service_nb.notifier_call = |
| 3792 | fastrpc_get_service_location_notify; |
| 3793 | ret = get_service_location( |
| 3794 | AUDIO_PDR_SERVICE_LOCATION_CLIENT_NAME, |
| 3795 | AUDIO_PDR_ADSP_SERVICE_NAME, |
| 3796 | &me->channel[0].spd[session].get_service_nb); |
| 3797 | if (ret) |
| 3798 | pr_err("ADSPRPC: Get service location failed: %d\n", |
| 3799 | ret); |
| 3800 | } |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 3801 | if (of_property_read_bool(dev->of_node, |
| 3802 | "qcom,fastrpc-adsp-sensors-pdr")) { |
| 3803 | int session; |
| 3804 | |
| 3805 | VERIFY(err, !fastrpc_get_adsp_session( |
| 3806 | SENSORS_PDR_SERVICE_LOCATION_CLIENT_NAME, &session)); |
| 3807 | if (err) |
| 3808 | goto spdbail; |
| 3809 | me->channel[0].spd[session].get_service_nb.notifier_call = |
| 3810 | fastrpc_get_service_location_notify; |
| 3811 | ret = get_service_location( |
| 3812 | SENSORS_PDR_SERVICE_LOCATION_CLIENT_NAME, |
| 3813 | SENSORS_PDR_ADSP_SERVICE_NAME, |
| 3814 | &me->channel[0].spd[session].get_service_nb); |
| 3815 | if (ret) |
| 3816 | pr_err("ADSPRPC: Get service location failed: %d\n", |
| 3817 | ret); |
| 3818 | } |
Tharun Kumar Merugu | df86066 | 2018-01-17 19:59:50 +0530 | [diff] [blame] | 3819 | spdbail: |
| 3820 | err = 0; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3821 | VERIFY(err, !of_platform_populate(pdev->dev.of_node, |
| 3822 | fastrpc_match_table, |
| 3823 | NULL, &pdev->dev)); |
| 3824 | if (err) |
| 3825 | goto bail; |
| 3826 | bail: |
| 3827 | return err; |
| 3828 | } |
| 3829 | |
| 3830 | static void fastrpc_deinit(void) |
| 3831 | { |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3832 | struct fastrpc_apps *me = &gfa; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3833 | struct fastrpc_channel_ctx *chan = gcinfo; |
| 3834 | int i, j; |
| 3835 | |
| 3836 | for (i = 0; i < NUM_CHANNELS; i++, chan++) { |
| 3837 | if (chan->chan) { |
| 3838 | kref_put_mutex(&chan->kref, |
Tharun Kumar Merugu | 642fcce | 2017-12-07 19:22:10 +0530 | [diff] [blame] | 3839 | fastrpc_channel_close, &me->smd_mutex); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3840 | chan->chan = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3841 | } |
| 3842 | for (j = 0; j < NUM_SESSIONS; j++) { |
| 3843 | struct fastrpc_session_ctx *sess = &chan->session[j]; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3844 | if (sess->smmu.dev) { |
| 3845 | arm_iommu_detach_device(sess->smmu.dev); |
| 3846 | sess->smmu.dev = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3847 | } |
| 3848 | if (sess->smmu.mapping) { |
| 3849 | arm_iommu_release_mapping(sess->smmu.mapping); |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3850 | sess->smmu.mapping = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3851 | } |
| 3852 | } |
Tharun Kumar Merugu | 3937e91 | 2017-12-21 16:24:37 +0530 | [diff] [blame] | 3853 | kfree(chan->rhvm.vmid); |
| 3854 | kfree(chan->rhvm.vmperm); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3855 | } |
| 3856 | } |
| 3857 | |
| 3858 | static struct platform_driver fastrpc_driver = { |
| 3859 | .probe = fastrpc_probe, |
| 3860 | .driver = { |
| 3861 | .name = "fastrpc", |
| 3862 | .owner = THIS_MODULE, |
| 3863 | .of_match_table = fastrpc_match_table, |
| 3864 | }, |
| 3865 | }; |
| 3866 | |
| 3867 | static int __init fastrpc_device_init(void) |
| 3868 | { |
| 3869 | struct fastrpc_apps *me = &gfa; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3870 | struct device *dev = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3871 | int err = 0, i; |
| 3872 | |
| 3873 | memset(me, 0, sizeof(*me)); |
| 3874 | |
| 3875 | fastrpc_init(me); |
| 3876 | me->dev = NULL; |
Tharun Kumar Merugu | bbc78f2 | 2018-01-22 19:26:44 +0530 | [diff] [blame] | 3877 | me->glink = true; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3878 | VERIFY(err, 0 == platform_driver_register(&fastrpc_driver)); |
| 3879 | if (err) |
| 3880 | goto register_bail; |
| 3881 | VERIFY(err, 0 == alloc_chrdev_region(&me->dev_no, 0, NUM_CHANNELS, |
| 3882 | DEVICE_NAME)); |
| 3883 | if (err) |
| 3884 | goto alloc_chrdev_bail; |
| 3885 | cdev_init(&me->cdev, &fops); |
| 3886 | me->cdev.owner = THIS_MODULE; |
| 3887 | VERIFY(err, 0 == cdev_add(&me->cdev, MKDEV(MAJOR(me->dev_no), 0), |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3888 | 1)); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3889 | if (err) |
| 3890 | goto cdev_init_bail; |
| 3891 | me->class = class_create(THIS_MODULE, "fastrpc"); |
| 3892 | VERIFY(err, !IS_ERR(me->class)); |
| 3893 | if (err) |
| 3894 | goto class_create_bail; |
| 3895 | me->compat = (fops.compat_ioctl == NULL) ? 0 : 1; |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3896 | dev = device_create(me->class, NULL, |
| 3897 | MKDEV(MAJOR(me->dev_no), 0), |
| 3898 | NULL, gcinfo[0].name); |
| 3899 | VERIFY(err, !IS_ERR_OR_NULL(dev)); |
| 3900 | if (err) |
| 3901 | goto device_create_bail; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3902 | for (i = 0; i < NUM_CHANNELS; i++) { |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3903 | me->channel[i].dev = dev; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3904 | me->channel[i].ssrcount = 0; |
| 3905 | me->channel[i].prevssrcount = 0; |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 3906 | me->channel[i].issubsystemup = 1; |
| 3907 | me->channel[i].ramdumpenabled = 0; |
| 3908 | me->channel[i].remoteheap_ramdump_dev = NULL; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3909 | me->channel[i].nb.notifier_call = fastrpc_restart_notifier_cb; |
| 3910 | me->channel[i].handle = subsys_notif_register_notifier( |
| 3911 | gcinfo[i].subsys, |
| 3912 | &me->channel[i].nb); |
| 3913 | } |
| 3914 | |
| 3915 | me->client = msm_ion_client_create(DEVICE_NAME); |
| 3916 | VERIFY(err, !IS_ERR_OR_NULL(me->client)); |
| 3917 | if (err) |
| 3918 | goto device_create_bail; |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 3919 | debugfs_root = debugfs_create_dir("adsprpc", NULL); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3920 | return 0; |
| 3921 | device_create_bail: |
| 3922 | for (i = 0; i < NUM_CHANNELS; i++) { |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3923 | if (me->channel[i].handle) |
| 3924 | subsys_notif_unregister_notifier(me->channel[i].handle, |
| 3925 | &me->channel[i].nb); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3926 | } |
Sathish Ambley | 36849af | 2017-02-02 09:35:55 -0800 | [diff] [blame] | 3927 | if (!IS_ERR_OR_NULL(dev)) |
| 3928 | device_destroy(me->class, MKDEV(MAJOR(me->dev_no), 0)); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3929 | class_destroy(me->class); |
| 3930 | class_create_bail: |
| 3931 | cdev_del(&me->cdev); |
| 3932 | cdev_init_bail: |
| 3933 | unregister_chrdev_region(me->dev_no, NUM_CHANNELS); |
| 3934 | alloc_chrdev_bail: |
| 3935 | register_bail: |
| 3936 | fastrpc_deinit(); |
| 3937 | return err; |
| 3938 | } |
| 3939 | |
| 3940 | static void __exit fastrpc_device_exit(void) |
| 3941 | { |
| 3942 | struct fastrpc_apps *me = &gfa; |
| 3943 | int i; |
| 3944 | |
| 3945 | fastrpc_file_list_dtor(me); |
| 3946 | fastrpc_deinit(); |
| 3947 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 3948 | if (!gcinfo[i].name) |
| 3949 | continue; |
| 3950 | device_destroy(me->class, MKDEV(MAJOR(me->dev_no), i)); |
| 3951 | subsys_notif_unregister_notifier(me->channel[i].handle, |
| 3952 | &me->channel[i].nb); |
| 3953 | } |
| 3954 | class_destroy(me->class); |
| 3955 | cdev_del(&me->cdev); |
| 3956 | unregister_chrdev_region(me->dev_no, NUM_CHANNELS); |
| 3957 | ion_client_destroy(me->client); |
Sathish Ambley | 1ca6823 | 2017-01-19 10:32:55 -0800 | [diff] [blame] | 3958 | debugfs_remove_recursive(debugfs_root); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 3959 | } |
| 3960 | |
| 3961 | late_initcall(fastrpc_device_init); |
| 3962 | module_exit(fastrpc_device_exit); |
| 3963 | |
| 3964 | MODULE_LICENSE("GPL v2"); |