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)
72
84
FASTRPC_BUILD_SCALARS(0, method, in, out, 0, 0)
73
85
74
86
#define FASTRPC_CREATE_PROCESS_NARGS 6
87
+ #define FASTRPC_CREATE_STATIC_PROCESS_NARGS 3
75
88
/* Remote Method id table */
76
89
#define FASTRPC_RMID_INIT_ATTACH 0
77
90
#define FASTRPC_RMID_INIT_RELEASE 1
@@ -261,6 +274,7 @@ struct fastrpc_channel_ctx {
261
274
u32 dsp_attributes [FASTRPC_MAX_DSP_ATTRIBUTES ];
262
275
struct fastrpc_device * secure_fdevice ;
263
276
struct fastrpc_device * fdevice ;
277
+ struct fastrpc_buf * remote_heap ;
264
278
bool secure ;
265
279
bool unsigned_support ;
266
280
};
@@ -1157,6 +1171,7 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl, u32 kernel,
1157
1171
spin_unlock (& fl -> lock );
1158
1172
fastrpc_context_put (ctx );
1159
1173
}
1174
+
1160
1175
if (err )
1161
1176
dev_dbg (fl -> sctx -> dev , "Error: Invoke Failed %d\n" , err );
1162
1177
@@ -1181,6 +1196,120 @@ static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_reques
1181
1196
return false;
1182
1197
}
1183
1198
1199
+ static int fastrpc_init_create_static_process (struct fastrpc_user * fl ,
1200
+ char __user * argp )
1201
+ {
1202
+ struct fastrpc_init_create_static init ;
1203
+ struct fastrpc_invoke_args * args ;
1204
+ struct fastrpc_phy_page pages [1 ];
1205
+ char * name ;
1206
+ int err ;
1207
+ struct {
1208
+ int pgid ;
1209
+ u32 namelen ;
1210
+ u32 pageslen ;
1211
+ } inbuf ;
1212
+ u32 sc ;
1213
+
1214
+ args = kcalloc (FASTRPC_CREATE_STATIC_PROCESS_NARGS , sizeof (* args ), GFP_KERNEL );
1215
+ if (!args )
1216
+ return - ENOMEM ;
1217
+
1218
+ if (copy_from_user (& init , argp , sizeof (init ))) {
1219
+ err = - EFAULT ;
1220
+ goto err ;
1221
+ }
1222
+
1223
+ if (init .namelen > INIT_FILE_NAMELEN_MAX ) {
1224
+ err = - EINVAL ;
1225
+ goto err ;
1226
+ }
1227
+
1228
+ name = kzalloc (init .namelen , GFP_KERNEL );
1229
+ if (!name ) {
1230
+ err = - ENOMEM ;
1231
+ goto err ;
1232
+ }
1233
+
1234
+ if (copy_from_user (name , (void __user * )(uintptr_t )init .name , init .namelen )) {
1235
+ err = - EFAULT ;
1236
+ goto err_name ;
1237
+ }
1238
+
1239
+ if (!fl -> cctx -> remote_heap ) {
1240
+ err = fastrpc_remote_heap_alloc (fl , fl -> sctx -> dev , init .memlen ,
1241
+ & fl -> cctx -> remote_heap );
1242
+ if (err )
1243
+ goto err_name ;
1244
+
1245
+ /* Map if we have any heap VMIDs associated with this ADSP Static Process. */
1246
+ if (fl -> cctx -> vmcount ) {
1247
+ unsigned int perms = BIT (QCOM_SCM_VMID_HLOS );
1248
+
1249
+ err = qcom_scm_assign_mem (fl -> cctx -> remote_heap -> phys ,
1250
+ (u64 )fl -> cctx -> remote_heap -> size , & perms ,
1251
+ fl -> cctx -> vmperms , fl -> cctx -> vmcount );
1252
+ if (err ) {
1253
+ dev_err (fl -> sctx -> dev , "Failed to assign memory with phys 0x%llx size 0x%llx err %d" ,
1254
+ fl -> cctx -> remote_heap -> phys , fl -> cctx -> remote_heap -> size , err );
1255
+ goto err_map ;
1256
+ }
1257
+ }
1258
+ }
1259
+
1260
+ inbuf .pgid = fl -> tgid ;
1261
+ inbuf .namelen = init .namelen ;
1262
+ inbuf .pageslen = 0 ;
1263
+ fl -> pd = USER_PD ;
1264
+
1265
+ args [0 ].ptr = (u64 )(uintptr_t )& inbuf ;
1266
+ args [0 ].length = sizeof (inbuf );
1267
+ args [0 ].fd = -1 ;
1268
+
1269
+ args [1 ].ptr = (u64 )(uintptr_t )name ;
1270
+ args [1 ].length = inbuf .namelen ;
1271
+ args [1 ].fd = -1 ;
1272
+
1273
+ pages [0 ].addr = fl -> cctx -> remote_heap -> phys ;
1274
+ pages [0 ].size = fl -> cctx -> remote_heap -> size ;
1275
+
1276
+ args [2 ].ptr = (u64 )(uintptr_t ) pages ;
1277
+ args [2 ].length = sizeof (* pages );
1278
+ args [2 ].fd = -1 ;
1279
+
1280
+ sc = FASTRPC_SCALARS (FASTRPC_RMID_INIT_CREATE_STATIC , 3 , 0 );
1281
+
1282
+ err = fastrpc_internal_invoke (fl , true, FASTRPC_INIT_HANDLE ,
1283
+ sc , args );
1284
+ if (err )
1285
+ goto err_invoke ;
1286
+
1287
+ kfree (args );
1288
+
1289
+ return 0 ;
1290
+ err_invoke :
1291
+ if (fl -> cctx -> vmcount ) {
1292
+ struct qcom_scm_vmperm perm ;
1293
+
1294
+ perm .vmid = QCOM_SCM_VMID_HLOS ;
1295
+ perm .perm = QCOM_SCM_PERM_RWX ;
1296
+ err = qcom_scm_assign_mem (fl -> cctx -> remote_heap -> phys ,
1297
+ (u64 )fl -> cctx -> remote_heap -> size ,
1298
+ & (fl -> cctx -> vmperms [0 ].vmid ), & perm , 1 );
1299
+ if (err )
1300
+ dev_err (fl -> sctx -> dev , "Failed to assign memory phys 0x%llx size 0x%llx err %d" ,
1301
+ fl -> cctx -> remote_heap -> phys , fl -> cctx -> remote_heap -> size , err );
1302
+ }
1303
+ err_map :
1304
+ fastrpc_buf_free (fl -> cctx -> remote_heap );
1305
+ err_name :
1306
+ kfree (name );
1307
+ err :
1308
+ kfree (args );
1309
+
1310
+ return err ;
1311
+ }
1312
+
1184
1313
static int fastrpc_init_create_process (struct fastrpc_user * fl ,
1185
1314
char __user * argp )
1186
1315
{
@@ -1915,6 +2044,9 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd,
1915
2044
case FASTRPC_IOCTL_INIT_ATTACH_SNS :
1916
2045
err = fastrpc_init_attach (fl , SENSORS_PD );
1917
2046
break ;
2047
+ case FASTRPC_IOCTL_INIT_CREATE_STATIC :
2048
+ err = fastrpc_init_create_static_process (fl , argp );
2049
+ break ;
1918
2050
case FASTRPC_IOCTL_INIT_CREATE :
1919
2051
err = fastrpc_init_create_process (fl , argp );
1920
2052
break ;
@@ -2184,6 +2316,9 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
2184
2316
if (cctx -> secure_fdevice )
2185
2317
misc_deregister (& cctx -> secure_fdevice -> miscdev );
2186
2318
2319
+ if (cctx -> remote_heap )
2320
+ fastrpc_buf_free (cctx -> remote_heap );
2321
+
2187
2322
of_platform_depopulate (& rpdev -> dev );
2188
2323
2189
2324
cctx -> rpdev = NULL ;
0 commit comments