Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

misc: fastrpc: Add support for audiopd

In order to be able to start the adsp listener for audiopd using adsprpcd,
we need to add the corresponding ioctl for creating a static process.
On that ioctl call we need to allocate the heap. Allocating the heap needs
to be happening only once and needs to be kept between different device
open calls, so attach it to the channel context to make sure that remains
until the RPMSG driver is removed. Then, if there are any VMIDs associated
with the static ADSP process, do a call to SCM to assign it.
And then, send all the necessary info related to heap to the DSP.

Co-developed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20221125071405.148786-8-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Abel Vesa and committed by
Greg Kroah-Hartman
08715610 72fa6f78

+142
+135
drivers/misc/fastrpc.c
··· 37 37 #define FASTRPC_DSP_UTILITIES_HANDLE 2 38 38 #define FASTRPC_CTXID_MASK (0xFF0) 39 39 #define INIT_FILELEN_MAX (2 * 1024 * 1024) 40 + #define INIT_FILE_NAMELEN_MAX (128) 40 41 #define FASTRPC_DEVICE_NAME "fastrpc" 42 + 43 + /* Add memory to static PD pool, protection thru XPU */ 44 + #define ADSP_MMAP_HEAP_ADDR 4 45 + /* MAP static DMA buffer on DSP User PD */ 46 + #define ADSP_MMAP_DMA_BUFFER 6 47 + /* Add memory to static PD pool protection thru hypervisor */ 48 + #define ADSP_MMAP_REMOTE_HEAP_ADDR 8 49 + /* Add memory to userPD pool, for user heap */ 41 50 #define ADSP_MMAP_ADD_PAGES 0x1000 51 + /* Add memory to userPD pool, for LLC heap */ 52 + #define ADSP_MMAP_ADD_PAGES_LLC 0x3000, 53 + 42 54 #define DSP_UNSUPPORTED_API (0x80000414) 43 55 /* MAX NUMBER of DSP ATTRIBUTES SUPPORTED */ 44 56 #define FASTRPC_MAX_DSP_ATTRIBUTES (256) ··· 84 72 FASTRPC_BUILD_SCALARS(0, method, in, out, 0, 0) 85 73 86 74 #define FASTRPC_CREATE_PROCESS_NARGS 6 75 + #define FASTRPC_CREATE_STATIC_PROCESS_NARGS 3 87 76 /* Remote Method id table */ 88 77 #define FASTRPC_RMID_INIT_ATTACH 0 89 78 #define FASTRPC_RMID_INIT_RELEASE 1 ··· 274 261 u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES]; 275 262 struct fastrpc_device *secure_fdevice; 276 263 struct fastrpc_device *fdevice; 264 + struct fastrpc_buf *remote_heap; 277 265 bool secure; 278 266 bool unsigned_support; 279 267 }; ··· 1171 1157 spin_unlock(&fl->lock); 1172 1158 fastrpc_context_put(ctx); 1173 1159 } 1160 + 1174 1161 if (err) 1175 1162 dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err); 1176 1163 ··· 1194 1179 } 1195 1180 1196 1181 return false; 1182 + } 1183 + 1184 + static int fastrpc_init_create_static_process(struct fastrpc_user *fl, 1185 + char __user *argp) 1186 + { 1187 + struct fastrpc_init_create_static init; 1188 + struct fastrpc_invoke_args *args; 1189 + struct fastrpc_phy_page pages[1]; 1190 + char *name; 1191 + int err; 1192 + struct { 1193 + int pgid; 1194 + u32 namelen; 1195 + u32 pageslen; 1196 + } inbuf; 1197 + u32 sc; 1198 + 1199 + args = kcalloc(FASTRPC_CREATE_STATIC_PROCESS_NARGS, sizeof(*args), GFP_KERNEL); 1200 + if (!args) 1201 + return -ENOMEM; 1202 + 1203 + if (copy_from_user(&init, argp, sizeof(init))) { 1204 + err = -EFAULT; 1205 + goto err; 1206 + } 1207 + 1208 + if (init.namelen > INIT_FILE_NAMELEN_MAX) { 1209 + err = -EINVAL; 1210 + goto err; 1211 + } 1212 + 1213 + name = kzalloc(init.namelen, GFP_KERNEL); 1214 + if (!name) { 1215 + err = -ENOMEM; 1216 + goto err; 1217 + } 1218 + 1219 + if (copy_from_user(name, (void __user *)(uintptr_t)init.name, init.namelen)) { 1220 + err = -EFAULT; 1221 + goto err_name; 1222 + } 1223 + 1224 + if (!fl->cctx->remote_heap) { 1225 + err = fastrpc_remote_heap_alloc(fl, fl->sctx->dev, init.memlen, 1226 + &fl->cctx->remote_heap); 1227 + if (err) 1228 + goto err_name; 1229 + 1230 + /* Map if we have any heap VMIDs associated with this ADSP Static Process. */ 1231 + if (fl->cctx->vmcount) { 1232 + unsigned int perms = BIT(QCOM_SCM_VMID_HLOS); 1233 + 1234 + err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys, 1235 + (u64)fl->cctx->remote_heap->size, &perms, 1236 + fl->cctx->vmperms, fl->cctx->vmcount); 1237 + if (err) { 1238 + dev_err(fl->sctx->dev, "Failed to assign memory with phys 0x%llx size 0x%llx err %d", 1239 + fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); 1240 + goto err_map; 1241 + } 1242 + } 1243 + } 1244 + 1245 + inbuf.pgid = fl->tgid; 1246 + inbuf.namelen = init.namelen; 1247 + inbuf.pageslen = 0; 1248 + fl->pd = USER_PD; 1249 + 1250 + args[0].ptr = (u64)(uintptr_t)&inbuf; 1251 + args[0].length = sizeof(inbuf); 1252 + args[0].fd = -1; 1253 + 1254 + args[1].ptr = (u64)(uintptr_t)name; 1255 + args[1].length = inbuf.namelen; 1256 + args[1].fd = -1; 1257 + 1258 + pages[0].addr = fl->cctx->remote_heap->phys; 1259 + pages[0].size = fl->cctx->remote_heap->size; 1260 + 1261 + args[2].ptr = (u64)(uintptr_t) pages; 1262 + args[2].length = sizeof(*pages); 1263 + args[2].fd = -1; 1264 + 1265 + sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_CREATE_STATIC, 3, 0); 1266 + 1267 + err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, 1268 + sc, args); 1269 + if (err) 1270 + goto err_invoke; 1271 + 1272 + kfree(args); 1273 + 1274 + return 0; 1275 + err_invoke: 1276 + if (fl->cctx->vmcount) { 1277 + struct qcom_scm_vmperm perm; 1278 + 1279 + perm.vmid = QCOM_SCM_VMID_HLOS; 1280 + perm.perm = QCOM_SCM_PERM_RWX; 1281 + err = qcom_scm_assign_mem(fl->cctx->remote_heap->phys, 1282 + (u64)fl->cctx->remote_heap->size, 1283 + &(fl->cctx->vmperms[0].vmid), &perm, 1); 1284 + if (err) 1285 + dev_err(fl->sctx->dev, "Failed to assign memory phys 0x%llx size 0x%llx err %d", 1286 + fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err); 1287 + } 1288 + err_map: 1289 + fastrpc_buf_free(fl->cctx->remote_heap); 1290 + err_name: 1291 + kfree(name); 1292 + err: 1293 + kfree(args); 1294 + 1295 + return err; 1197 1296 } 1198 1297 1199 1298 static int fastrpc_init_create_process(struct fastrpc_user *fl, ··· 2044 1915 case FASTRPC_IOCTL_INIT_ATTACH_SNS: 2045 1916 err = fastrpc_init_attach(fl, SENSORS_PD); 2046 1917 break; 1918 + case FASTRPC_IOCTL_INIT_CREATE_STATIC: 1919 + err = fastrpc_init_create_static_process(fl, argp); 1920 + break; 2047 1921 case FASTRPC_IOCTL_INIT_CREATE: 2048 1922 err = fastrpc_init_create_process(fl, argp); 2049 1923 break; ··· 2315 2183 2316 2184 if (cctx->secure_fdevice) 2317 2185 misc_deregister(&cctx->secure_fdevice->miscdev); 2186 + 2187 + if (cctx->remote_heap) 2188 + fastrpc_buf_free(cctx->remote_heap); 2318 2189 2319 2190 of_platform_depopulate(&rpdev->dev); 2320 2191
+7
include/uapi/misc/fastrpc.h
··· 13 13 #define FASTRPC_IOCTL_MMAP _IOWR('R', 6, struct fastrpc_req_mmap) 14 14 #define FASTRPC_IOCTL_MUNMAP _IOWR('R', 7, struct fastrpc_req_munmap) 15 15 #define FASTRPC_IOCTL_INIT_ATTACH_SNS _IO('R', 8) 16 + #define FASTRPC_IOCTL_INIT_CREATE_STATIC _IOWR('R', 9, struct fastrpc_init_create_static) 16 17 #define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 10, struct fastrpc_mem_map) 17 18 #define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 11, struct fastrpc_mem_unmap) 18 19 #define FASTRPC_IOCTL_GET_DSP_INFO _IOWR('R', 13, struct fastrpc_ioctl_capability) ··· 86 85 __u32 attrs; 87 86 __u32 siglen; 88 87 __u64 file; /* pointer to elf file */ 88 + }; 89 + 90 + struct fastrpc_init_create_static { 91 + __u32 namelen; /* length of pd process name */ 92 + __u32 memlen; 93 + __u64 name; /* pd process name */ 89 94 }; 90 95 91 96 struct fastrpc_alloc_dma_buf {