Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 1 | /* |
Tharun Kumar Merugu | 35a94a5 | 2018-02-01 21:09:04 +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 | #ifndef ADSPRPC_SHARED_H |
| 15 | #define ADSPRPC_SHARED_H |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | |
| 19 | #define FASTRPC_IOCTL_INVOKE _IOWR('R', 1, struct fastrpc_ioctl_invoke) |
| 20 | #define FASTRPC_IOCTL_MMAP _IOWR('R', 2, struct fastrpc_ioctl_mmap) |
| 21 | #define FASTRPC_IOCTL_MUNMAP _IOWR('R', 3, struct fastrpc_ioctl_munmap) |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 22 | #define FASTRPC_IOCTL_MMAP_64 _IOWR('R', 14, struct fastrpc_ioctl_mmap_64) |
| 23 | #define FASTRPC_IOCTL_MUNMAP_64 _IOWR('R', 15, struct fastrpc_ioctl_munmap_64) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 24 | #define FASTRPC_IOCTL_INVOKE_FD _IOWR('R', 4, struct fastrpc_ioctl_invoke_fd) |
| 25 | #define FASTRPC_IOCTL_SETMODE _IOWR('R', 5, uint32_t) |
| 26 | #define FASTRPC_IOCTL_INIT _IOWR('R', 6, struct fastrpc_ioctl_init) |
| 27 | #define FASTRPC_IOCTL_INVOKE_ATTRS \ |
| 28 | _IOWR('R', 7, struct fastrpc_ioctl_invoke_attrs) |
| 29 | #define FASTRPC_IOCTL_GETINFO _IOWR('R', 8, uint32_t) |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 30 | #define FASTRPC_IOCTL_GETPERF _IOWR('R', 9, struct fastrpc_ioctl_perf) |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 31 | #define FASTRPC_IOCTL_INIT_ATTRS _IOWR('R', 10, struct fastrpc_ioctl_init_attrs) |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 32 | #define FASTRPC_IOCTL_INVOKE_CRC _IOWR('R', 11, struct fastrpc_ioctl_invoke_crc) |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 33 | #define FASTRPC_IOCTL_CONTROL _IOWR('R', 12, struct fastrpc_ioctl_control) |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 34 | #define FASTRPC_IOCTL_MUNMAP_FD _IOWR('R', 13, struct fastrpc_ioctl_munmap_fd) |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 35 | |
| 36 | #define FASTRPC_GLINK_GUID "fastrpcglink-apps-dsp" |
| 37 | #define FASTRPC_SMD_GUID "fastrpcsmd-apps-dsp" |
| 38 | #define DEVICE_NAME "adsprpc-smd" |
| 39 | |
| 40 | /* Set for buffers that have no virtual mapping in userspace */ |
| 41 | #define FASTRPC_ATTR_NOVA 0x1 |
| 42 | |
Tharun Kumar Merugu | 2e5f12e | 2017-07-06 12:04:40 +0530 | [diff] [blame] | 43 | /* Set for buffers that are NOT dma coherent */ |
| 44 | #define FASTRPC_ATTR_NON_COHERENT 0x2 |
| 45 | |
| 46 | /* Set for buffers that are dma coherent */ |
| 47 | #define FASTRPC_ATTR_COHERENT 0x4 |
| 48 | |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 49 | /* Fastrpc attribute for keeping the map persistent */ |
| 50 | #define FASTRPC_ATTR_KEEP_MAP 0x8 |
| 51 | |
Tharun Kumar Merugu | 35a94a5 | 2018-02-01 21:09:04 +0530 | [diff] [blame] | 52 | /* Fastrpc attribute for no map */ |
| 53 | #define FASTRPC_ATTR_NOMAP (16) |
| 54 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 55 | /* Driver should operate in parallel with the co-processor */ |
| 56 | #define FASTRPC_MODE_PARALLEL 0 |
| 57 | |
| 58 | /* Driver should operate in serial mode with the co-processor */ |
| 59 | #define FASTRPC_MODE_SERIAL 1 |
| 60 | |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 61 | /* Driver should operate in profile mode with the co-processor */ |
| 62 | #define FASTRPC_MODE_PROFILE 2 |
| 63 | |
Tharun Kumar Merugu | d4d07948 | 2017-09-06 11:22:19 +0530 | [diff] [blame] | 64 | /* Set FastRPC session ID to 1 */ |
| 65 | #define FASTRPC_MODE_SESSION 4 |
| 66 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 67 | /* INIT a new process or attach to guestos */ |
| 68 | #define FASTRPC_INIT_ATTACH 0 |
| 69 | #define FASTRPC_INIT_CREATE 1 |
c_mtharu | e1a5ce1 | 2017-10-13 20:47:09 +0530 | [diff] [blame] | 70 | #define FASTRPC_INIT_CREATE_STATIC 2 |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 71 | #define FASTRPC_INIT_ATTACH_SENSORS 3 |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 72 | |
| 73 | /* Retrives number of input buffers from the scalars parameter */ |
| 74 | #define REMOTE_SCALARS_INBUFS(sc) (((sc) >> 16) & 0x0ff) |
| 75 | |
| 76 | /* Retrives number of output buffers from the scalars parameter */ |
| 77 | #define REMOTE_SCALARS_OUTBUFS(sc) (((sc) >> 8) & 0x0ff) |
| 78 | |
| 79 | /* Retrives number of input handles from the scalars parameter */ |
| 80 | #define REMOTE_SCALARS_INHANDLES(sc) (((sc) >> 4) & 0x0f) |
| 81 | |
| 82 | /* Retrives number of output handles from the scalars parameter */ |
| 83 | #define REMOTE_SCALARS_OUTHANDLES(sc) ((sc) & 0x0f) |
| 84 | |
| 85 | #define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\ |
| 86 | REMOTE_SCALARS_OUTBUFS(sc) +\ |
| 87 | REMOTE_SCALARS_INHANDLES(sc) +\ |
| 88 | REMOTE_SCALARS_OUTHANDLES(sc)) |
| 89 | |
| 90 | #define REMOTE_SCALARS_MAKEX(attr, method, in, out, oin, oout) \ |
| 91 | ((((uint32_t) (attr) & 0x7) << 29) | \ |
| 92 | (((uint32_t) (method) & 0x1f) << 24) | \ |
| 93 | (((uint32_t) (in) & 0xff) << 16) | \ |
| 94 | (((uint32_t) (out) & 0xff) << 8) | \ |
| 95 | (((uint32_t) (oin) & 0x0f) << 4) | \ |
| 96 | ((uint32_t) (oout) & 0x0f)) |
| 97 | |
| 98 | #define REMOTE_SCALARS_MAKE(method, in, out) \ |
| 99 | REMOTE_SCALARS_MAKEX(0, method, in, out, 0, 0) |
| 100 | |
| 101 | |
| 102 | #ifndef VERIFY_PRINT_ERROR |
| 103 | #define VERIFY_EPRINTF(format, args) (void)0 |
| 104 | #endif |
| 105 | |
| 106 | #ifndef VERIFY_PRINT_INFO |
| 107 | #define VERIFY_IPRINTF(args) (void)0 |
| 108 | #endif |
| 109 | |
| 110 | #ifndef VERIFY |
| 111 | #define __STR__(x) #x ":" |
| 112 | #define __TOSTR__(x) __STR__(x) |
| 113 | #define __FILE_LINE__ __FILE__ ":" __TOSTR__(__LINE__) |
| 114 | |
| 115 | #define VERIFY(err, val) \ |
| 116 | do {\ |
| 117 | VERIFY_IPRINTF(__FILE_LINE__"info: calling: " #val "\n");\ |
Tharun Kumar Merugu | e3edf3e | 2017-07-27 12:34:07 +0530 | [diff] [blame] | 118 | if ((val) == 0) {\ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 119 | (err) = (err) == 0 ? -1 : (err);\ |
| 120 | VERIFY_EPRINTF(__FILE_LINE__"error: %d: " #val "\n", (err));\ |
| 121 | } else {\ |
| 122 | VERIFY_IPRINTF(__FILE_LINE__"info: passed: " #val "\n");\ |
| 123 | } \ |
| 124 | } while (0) |
| 125 | #endif |
| 126 | |
| 127 | #define remote_arg64_t union remote_arg64 |
| 128 | |
| 129 | struct remote_buf64 { |
| 130 | uint64_t pv; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 131 | uint64_t len; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 134 | struct remote_dma_handle64 { |
| 135 | int fd; |
| 136 | uint32_t offset; |
| 137 | uint32_t len; |
| 138 | }; |
| 139 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 140 | union remote_arg64 { |
| 141 | struct remote_buf64 buf; |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 142 | struct remote_dma_handle64 dma; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 143 | uint32_t h; |
| 144 | }; |
| 145 | |
| 146 | #define remote_arg_t union remote_arg |
| 147 | |
| 148 | struct remote_buf { |
| 149 | void *pv; /* buffer pointer */ |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 150 | size_t len; /* length of buffer */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 153 | struct remote_dma_handle { |
| 154 | int fd; |
| 155 | uint32_t offset; |
| 156 | }; |
| 157 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 158 | union remote_arg { |
| 159 | struct remote_buf buf; /* buffer info */ |
Sathish Ambley | 58dc64d | 2016-11-29 17:11:53 -0800 | [diff] [blame] | 160 | struct remote_dma_handle dma; |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 161 | uint32_t h; /* remote handle */ |
| 162 | }; |
| 163 | |
| 164 | struct fastrpc_ioctl_invoke { |
| 165 | uint32_t handle; /* remote handle */ |
| 166 | uint32_t sc; /* scalars describing the data */ |
| 167 | remote_arg_t *pra; /* remote arguments list */ |
| 168 | }; |
| 169 | |
| 170 | struct fastrpc_ioctl_invoke_fd { |
| 171 | struct fastrpc_ioctl_invoke inv; |
| 172 | int *fds; /* fd list */ |
| 173 | }; |
| 174 | |
| 175 | struct fastrpc_ioctl_invoke_attrs { |
| 176 | struct fastrpc_ioctl_invoke inv; |
| 177 | int *fds; /* fd list */ |
| 178 | unsigned int *attrs; /* attribute list */ |
| 179 | }; |
| 180 | |
Sathish Ambley | bae5190 | 2017-07-03 15:00:49 -0700 | [diff] [blame] | 181 | struct fastrpc_ioctl_invoke_crc { |
| 182 | struct fastrpc_ioctl_invoke inv; |
| 183 | int *fds; /* fd list */ |
| 184 | unsigned int *attrs; /* attribute list */ |
| 185 | unsigned int *crc; |
| 186 | }; |
| 187 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 188 | struct fastrpc_ioctl_init { |
| 189 | uint32_t flags; /* one of FASTRPC_INIT_* macros */ |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 190 | uintptr_t file; /* pointer to elf file */ |
| 191 | uint32_t filelen; /* elf file length */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 192 | int32_t filefd; /* ION fd for the file */ |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 193 | uintptr_t mem; /* mem for the PD */ |
| 194 | uint32_t memlen; /* mem length */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 195 | int32_t memfd; /* ION fd for the mem */ |
| 196 | }; |
| 197 | |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 198 | struct fastrpc_ioctl_init_attrs { |
| 199 | struct fastrpc_ioctl_init init; |
| 200 | int attrs; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 201 | unsigned int siglen; |
Sathish Ambley | d6300c3 | 2017-01-18 09:50:43 -0800 | [diff] [blame] | 202 | }; |
| 203 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 204 | struct fastrpc_ioctl_munmap { |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 205 | uintptr_t vaddrout; /* address to unmap */ |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 206 | size_t size; /* size */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 209 | struct fastrpc_ioctl_munmap_64 { |
| 210 | uint64_t vaddrout; /* address to unmap */ |
| 211 | size_t size; /* size */ |
| 212 | }; |
| 213 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 214 | struct fastrpc_ioctl_mmap { |
| 215 | int fd; /* ion fd */ |
| 216 | uint32_t flags; /* flags for dsp to map with */ |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 217 | uintptr_t vaddrin; /* optional virtual address */ |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 218 | size_t size; /* size */ |
Tharun Kumar Merugu | 6c7d37d | 2018-04-18 12:14:22 +0530 | [diff] [blame] | 219 | uintptr_t vaddrout; /* dsps virtual address */ |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 220 | }; |
| 221 | |
Tharun Kumar Merugu | 55be90d | 2018-05-31 11:41:03 +0530 | [diff] [blame] | 222 | struct fastrpc_ioctl_mmap_64 { |
| 223 | int fd; /* ion fd */ |
| 224 | uint32_t flags; /* flags for dsp to map with */ |
| 225 | uint64_t vaddrin; /* optional virtual address */ |
| 226 | size_t size; /* size */ |
| 227 | uint64_t vaddrout; /* dsps virtual address */ |
| 228 | }; |
| 229 | |
c_mtharu | 7bd6a42 | 2017-10-17 18:15:37 +0530 | [diff] [blame] | 230 | struct fastrpc_ioctl_munmap_fd { |
| 231 | int fd; /* fd */ |
| 232 | uint32_t flags; /* control flags */ |
| 233 | uintptr_t va; /* va */ |
| 234 | ssize_t len; /* length */ |
| 235 | }; |
| 236 | |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 237 | struct fastrpc_ioctl_perf { /* kernel performance data */ |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 238 | uintptr_t data; |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 239 | uint32_t numkeys; |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 240 | uintptr_t keys; |
Sathish Ambley | a21b5b5 | 2017-01-11 16:11:01 -0800 | [diff] [blame] | 241 | }; |
| 242 | |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 243 | #define FASTRPC_CONTROL_LATENCY (1) |
| 244 | struct fastrpc_ctrl_latency { |
| 245 | uint32_t enable; //!latency control enable |
| 246 | uint32_t level; //!level of control |
| 247 | }; |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 248 | #define FASTRPC_CONTROL_SMMU (2) |
| 249 | struct fastrpc_ctrl_smmu { |
| 250 | uint32_t sharedcb; |
| 251 | }; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 252 | struct fastrpc_ioctl_control { |
| 253 | uint32_t req; |
| 254 | union { |
| 255 | struct fastrpc_ctrl_latency lp; |
Tharun Kumar Merugu | 848c095 | 2018-02-07 21:37:19 +0530 | [diff] [blame] | 256 | struct fastrpc_ctrl_smmu smmu; |
Tharun Kumar Merugu | 5f6ca61c | 2017-08-11 11:43:11 +0530 | [diff] [blame] | 257 | }; |
| 258 | }; |
| 259 | |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 260 | struct smq_null_invoke { |
| 261 | uint64_t ctx; /* invoke caller context */ |
| 262 | uint32_t handle; /* handle to invoke */ |
| 263 | uint32_t sc; /* scalars structure describing the data */ |
| 264 | }; |
| 265 | |
| 266 | struct smq_phy_page { |
| 267 | uint64_t addr; /* physical address */ |
| 268 | uint64_t size; /* size of contiguous region */ |
| 269 | }; |
| 270 | |
| 271 | struct smq_invoke_buf { |
| 272 | int num; /* number of contiguous regions */ |
| 273 | int pgidx; /* index to start of contiguous region */ |
| 274 | }; |
| 275 | |
| 276 | struct smq_invoke { |
| 277 | struct smq_null_invoke header; |
| 278 | struct smq_phy_page page; /* remote arg and list of pages address */ |
| 279 | }; |
| 280 | |
| 281 | struct smq_msg { |
| 282 | uint32_t pid; /* process group id */ |
| 283 | uint32_t tid; /* thread id */ |
| 284 | struct smq_invoke invoke; |
| 285 | }; |
| 286 | |
| 287 | struct smq_invoke_rsp { |
| 288 | uint64_t ctx; /* invoke caller context */ |
| 289 | int retval; /* invoke return value */ |
| 290 | }; |
| 291 | |
| 292 | static inline struct smq_invoke_buf *smq_invoke_buf_start(remote_arg64_t *pra, |
| 293 | uint32_t sc) |
| 294 | { |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 295 | unsigned int len = REMOTE_SCALARS_LENGTH(sc); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 296 | |
| 297 | return (struct smq_invoke_buf *)(&pra[len]); |
| 298 | } |
| 299 | |
| 300 | static inline struct smq_phy_page *smq_phy_page_start(uint32_t sc, |
| 301 | struct smq_invoke_buf *buf) |
| 302 | { |
Tharun Kumar Merugu | fb51f94 | 2017-12-07 10:32:15 +0530 | [diff] [blame] | 303 | unsigned int nTotal = REMOTE_SCALARS_LENGTH(sc); |
Sathish Ambley | 69e1ab0 | 2016-10-18 10:28:15 -0700 | [diff] [blame] | 304 | |
| 305 | return (struct smq_phy_page *)(&buf[nTotal]); |
| 306 | } |
| 307 | |
| 308 | #endif |