@@ -1169,7 +1169,7 @@ void tmc_etr_disable_hw(struct tmc_drvdata *drvdata)
1169
1169
drvdata -> etr_buf = NULL ;
1170
1170
}
1171
1171
1172
- static int tmc_enable_etr_sink_sysfs (struct coresight_device * csdev )
1172
+ static struct etr_buf * tmc_etr_get_sysfs_buffer (struct coresight_device * csdev )
1173
1173
{
1174
1174
int ret = 0 ;
1175
1175
unsigned long flags ;
@@ -1192,7 +1192,7 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev)
1192
1192
/* Allocate memory with the locks released */
1193
1193
free_buf = new_buf = tmc_etr_setup_sysfs_buf (drvdata );
1194
1194
if (IS_ERR (new_buf ))
1195
- return PTR_ERR ( new_buf ) ;
1195
+ return new_buf ;
1196
1196
1197
1197
/* Let's try again */
1198
1198
spin_lock_irqsave (& drvdata -> spinlock , flags );
@@ -1223,24 +1223,60 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev)
1223
1223
drvdata -> sysfs_buf = new_buf ;
1224
1224
}
1225
1225
1226
- ret = tmc_etr_enable_hw (drvdata , drvdata -> sysfs_buf );
1227
- if (!ret ) {
1228
- drvdata -> mode = CS_MODE_SYSFS ;
1229
- atomic_inc (& csdev -> refcnt );
1230
- }
1231
1226
out :
1232
1227
spin_unlock_irqrestore (& drvdata -> spinlock , flags );
1233
1228
1234
1229
/* Free memory outside the spinlock if need be */
1235
1230
if (free_buf )
1236
1231
tmc_etr_free_sysfs_buf (free_buf );
1232
+ return ret ? ERR_PTR (ret ) : drvdata -> sysfs_buf ;
1233
+ }
1234
+
1235
+ static int tmc_enable_etr_sink_sysfs (struct coresight_device * csdev )
1236
+ {
1237
+ int ret ;
1238
+ unsigned long flags ;
1239
+ struct tmc_drvdata * drvdata = dev_get_drvdata (csdev -> dev .parent );
1240
+ struct etr_buf * sysfs_buf = tmc_etr_get_sysfs_buffer (csdev );
1241
+
1242
+ if (IS_ERR (sysfs_buf ))
1243
+ return PTR_ERR (sysfs_buf );
1244
+
1245
+ spin_lock_irqsave (& drvdata -> spinlock , flags );
1246
+ ret = tmc_etr_enable_hw (drvdata , sysfs_buf );
1247
+ if (!ret ) {
1248
+ drvdata -> mode = CS_MODE_SYSFS ;
1249
+ atomic_inc (& csdev -> refcnt );
1250
+ }
1251
+
1252
+ spin_unlock_irqrestore (& drvdata -> spinlock , flags );
1237
1253
1238
1254
if (!ret )
1239
1255
dev_dbg (& csdev -> dev , "TMC-ETR enabled\n" );
1240
1256
1241
1257
return ret ;
1242
1258
}
1243
1259
1260
+ struct etr_buf * tmc_etr_get_buffer (struct coresight_device * csdev ,
1261
+ enum cs_mode mode , void * data )
1262
+ {
1263
+ struct perf_output_handle * handle = data ;
1264
+ struct etr_perf_buffer * etr_perf ;
1265
+
1266
+ switch (mode ) {
1267
+ case CS_MODE_SYSFS :
1268
+ return tmc_etr_get_sysfs_buffer (csdev );
1269
+ case CS_MODE_PERF :
1270
+ etr_perf = etm_perf_sink_config (handle );
1271
+ if (WARN_ON (!etr_perf || !etr_perf -> etr_buf ))
1272
+ return ERR_PTR (- EINVAL );
1273
+ return etr_perf -> etr_buf ;
1274
+ default :
1275
+ return ERR_PTR (- EINVAL );
1276
+ }
1277
+ }
1278
+ EXPORT_SYMBOL_GPL (tmc_etr_get_buffer );
1279
+
1244
1280
/*
1245
1281
* alloc_etr_buf: Allocate ETR buffer for use by perf.
1246
1282
* The size of the hardware buffer is dependent on the size configured
0 commit comments