Skip to content

Commit 46006ce

Browse files
Linu CherianSuzuki K Poulose
authored andcommitted
coresight: core: Add provision for panic callbacks
Panic callback handlers allows coresight device drivers to sync relevant trace data and trace metadata to reserved memory regions so that they can be retrieved later in the subsequent boot or in the crashdump kernel. Signed-off-by: Linu Cherian <[email protected]> Reviewed-by: James Clark <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 91a2086 commit 46006ce

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

drivers/hwtracing/coresight/coresight-core.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/property.h>
2020
#include <linux/delay.h>
2121
#include <linux/pm_runtime.h>
22+
#include <linux/panic_notifier.h>
2223

2324
#include "coresight-etm-perf.h"
2425
#include "coresight-priv.h"
@@ -1453,6 +1454,36 @@ const struct bus_type coresight_bustype = {
14531454
.name = "coresight",
14541455
};
14551456

1457+
static int coresight_panic_sync(struct device *dev, void *data)
1458+
{
1459+
int mode;
1460+
struct coresight_device *csdev;
1461+
1462+
/* Run through panic sync handlers for all enabled devices */
1463+
csdev = container_of(dev, struct coresight_device, dev);
1464+
mode = coresight_get_mode(csdev);
1465+
1466+
if ((mode == CS_MODE_SYSFS) || (mode == CS_MODE_PERF)) {
1467+
if (panic_ops(csdev))
1468+
panic_ops(csdev)->sync(csdev);
1469+
}
1470+
1471+
return 0;
1472+
}
1473+
1474+
static int coresight_panic_cb(struct notifier_block *self,
1475+
unsigned long v, void *p)
1476+
{
1477+
bus_for_each_dev(&coresight_bustype, NULL, NULL,
1478+
coresight_panic_sync);
1479+
1480+
return 0;
1481+
}
1482+
1483+
static struct notifier_block coresight_notifier = {
1484+
.notifier_call = coresight_panic_cb,
1485+
};
1486+
14561487
static int __init coresight_init(void)
14571488
{
14581489
int ret;
@@ -1465,11 +1496,20 @@ static int __init coresight_init(void)
14651496
if (ret)
14661497
goto exit_bus_unregister;
14671498

1499+
/* Register function to be called for panic */
1500+
ret = atomic_notifier_chain_register(&panic_notifier_list,
1501+
&coresight_notifier);
1502+
if (ret)
1503+
goto exit_perf;
1504+
14681505
/* initialise the coresight syscfg API */
14691506
ret = cscfg_init();
14701507
if (!ret)
14711508
return 0;
14721509

1510+
atomic_notifier_chain_unregister(&panic_notifier_list,
1511+
&coresight_notifier);
1512+
exit_perf:
14731513
etm_perf_exit();
14741514
exit_bus_unregister:
14751515
bus_unregister(&coresight_bustype);
@@ -1479,6 +1519,8 @@ static int __init coresight_init(void)
14791519
static void __exit coresight_exit(void)
14801520
{
14811521
cscfg_exit();
1522+
atomic_notifier_chain_unregister(&panic_notifier_list,
1523+
&coresight_notifier);
14821524
etm_perf_exit();
14831525
bus_unregister(&coresight_bustype);
14841526
}

include/linux/coresight.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ enum cs_mode {
340340
#define link_ops(csdev) csdev->ops->link_ops
341341
#define helper_ops(csdev) csdev->ops->helper_ops
342342
#define ect_ops(csdev) csdev->ops->ect_ops
343+
#define panic_ops(csdev) csdev->ops->panic_ops
343344

344345
/**
345346
* struct coresight_ops_sink - basic operations for a sink
@@ -409,11 +410,22 @@ struct coresight_ops_helper {
409410
int (*disable)(struct coresight_device *csdev, void *data);
410411
};
411412

413+
414+
/**
415+
* struct coresight_ops_panic - Generic device ops for panic handing
416+
*
417+
* @sync : Sync the device register state/trace data
418+
*/
419+
struct coresight_ops_panic {
420+
int (*sync)(struct coresight_device *csdev);
421+
};
422+
412423
struct coresight_ops {
413424
const struct coresight_ops_sink *sink_ops;
414425
const struct coresight_ops_link *link_ops;
415426
const struct coresight_ops_source *source_ops;
416427
const struct coresight_ops_helper *helper_ops;
428+
const struct coresight_ops_panic *panic_ops;
417429
};
418430

419431
static inline u32 csdev_access_relaxed_read32(struct csdev_access *csa,

0 commit comments

Comments
 (0)