Skip to content

Commit 8096152

Browse files
mikel-armbbgregkh
authored andcommitted
coresight: Add generic sysfs link creation functions
To allow the connections between coresight components to be represented in sysfs, generic methods for creating sysfs links between two coresight devices are added. Signed-off-by: Mike Leach <mike.leach@linaro.org> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Link: https://lore.kernel.org/r/20200518180242.7916-4-mathieu.poirier@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 68a5d5f commit 8096152

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed

drivers/hwtracing/coresight/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#
33
# Makefile for CoreSight drivers.
44
#
5-
obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o coresight-platform.o
5+
obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
6+
coresight-platform.o coresight-sysfs.o
67
obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o \
78
coresight-tmc-etf.o \
89
coresight-tmc-etr.o

drivers/hwtracing/coresight/coresight-priv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ struct coresight_device *coresight_get_sink_by_id(u32 id);
153153
struct list_head *coresight_build_path(struct coresight_device *csdev,
154154
struct coresight_device *sink);
155155
void coresight_release_path(struct list_head *path);
156+
int coresight_add_sysfs_link(struct coresight_sysfs_link *info);
157+
void coresight_remove_sysfs_link(struct coresight_sysfs_link *info);
158+
int coresight_create_conns_sysfs_group(struct coresight_device *csdev);
159+
void coresight_remove_conns_sysfs_group(struct coresight_device *csdev);
156160

157161
#ifdef CONFIG_CORESIGHT_SOURCE_ETM3X
158162
extern int etm_readl_cp14(u32 off, unsigned int *val);
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2019, Linaro Limited, All rights reserved.
4+
* Author: Mike Leach <mike.leach@linaro.org>
5+
*/
6+
7+
#include <linux/device.h>
8+
#include <linux/kernel.h>
9+
10+
#include "coresight-priv.h"
11+
12+
/*
13+
* Connections group - links attribute.
14+
* Count of created links between coresight components in the group.
15+
*/
16+
static ssize_t nr_links_show(struct device *dev,
17+
struct device_attribute *attr,
18+
char *buf)
19+
{
20+
struct coresight_device *csdev = to_coresight_device(dev);
21+
22+
return sprintf(buf, "%d\n", csdev->nr_links);
23+
}
24+
static DEVICE_ATTR_RO(nr_links);
25+
26+
static struct attribute *coresight_conns_attrs[] = {
27+
&dev_attr_nr_links.attr,
28+
NULL,
29+
};
30+
31+
static struct attribute_group coresight_conns_group = {
32+
.attrs = coresight_conns_attrs,
33+
.name = "connections",
34+
};
35+
36+
/*
37+
* Create connections group for CoreSight devices.
38+
* This group will then be used to collate the sysfs links between
39+
* devices.
40+
*/
41+
int coresight_create_conns_sysfs_group(struct coresight_device *csdev)
42+
{
43+
int ret = 0;
44+
45+
if (!csdev)
46+
return -EINVAL;
47+
48+
ret = sysfs_create_group(&csdev->dev.kobj, &coresight_conns_group);
49+
if (ret)
50+
return ret;
51+
52+
csdev->has_conns_grp = true;
53+
return ret;
54+
}
55+
56+
void coresight_remove_conns_sysfs_group(struct coresight_device *csdev)
57+
{
58+
if (!csdev)
59+
return;
60+
61+
if (csdev->has_conns_grp) {
62+
sysfs_remove_group(&csdev->dev.kobj, &coresight_conns_group);
63+
csdev->has_conns_grp = false;
64+
}
65+
}
66+
67+
int coresight_add_sysfs_link(struct coresight_sysfs_link *info)
68+
{
69+
int ret = 0;
70+
71+
if (!info)
72+
return -EINVAL;
73+
if (!info->orig || !info->target ||
74+
!info->orig_name || !info->target_name)
75+
return -EINVAL;
76+
if (!info->orig->has_conns_grp || !info->target->has_conns_grp)
77+
return -EINVAL;
78+
79+
/* first link orig->target */
80+
ret = sysfs_add_link_to_group(&info->orig->dev.kobj,
81+
coresight_conns_group.name,
82+
&info->target->dev.kobj,
83+
info->orig_name);
84+
if (ret)
85+
return ret;
86+
87+
/* second link target->orig */
88+
ret = sysfs_add_link_to_group(&info->target->dev.kobj,
89+
coresight_conns_group.name,
90+
&info->orig->dev.kobj,
91+
info->target_name);
92+
93+
/* error in second link - remove first - otherwise inc counts */
94+
if (ret) {
95+
sysfs_remove_link_from_group(&info->orig->dev.kobj,
96+
coresight_conns_group.name,
97+
info->orig_name);
98+
} else {
99+
info->orig->nr_links++;
100+
info->target->nr_links++;
101+
}
102+
103+
return ret;
104+
}
105+
106+
void coresight_remove_sysfs_link(struct coresight_sysfs_link *info)
107+
{
108+
if (!info)
109+
return;
110+
if (!info->orig || !info->target ||
111+
!info->orig_name || !info->target_name)
112+
return;
113+
114+
sysfs_remove_link_from_group(&info->orig->dev.kobj,
115+
coresight_conns_group.name,
116+
info->orig_name);
117+
118+
sysfs_remove_link_from_group(&info->target->dev.kobj,
119+
coresight_conns_group.name,
120+
info->target_name);
121+
122+
info->orig->nr_links--;
123+
info->target->nr_links--;
124+
}

include/linux/coresight.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ struct coresight_connection {
148148
struct coresight_device *child_dev;
149149
};
150150

151+
/**
152+
* struct coresight_sysfs_link - representation of a connection in sysfs.
153+
* @orig: Originating (master) coresight device for the link.
154+
* @orig_name: Name to use for the link orig->target.
155+
* @target: Target (slave) coresight device for the link.
156+
* @target_name: Name to use for the link target->orig.
157+
*/
158+
struct coresight_sysfs_link {
159+
struct coresight_device *orig;
160+
const char *orig_name;
161+
struct coresight_device *target;
162+
const char *target_name;
163+
};
164+
151165
/**
152166
* struct coresight_device - representation of a device as used by the framework
153167
* @pdata: Platform data with device connections associated to this device.
@@ -165,6 +179,9 @@ struct coresight_connection {
165179
* @ea: Device attribute for sink representation under PMU directory.
166180
* @ect_dev: Associated cross trigger device. Not part of the trace data
167181
* path or connections.
182+
* @nr_links: number of sysfs links created to other components from this
183+
* device. These will appear in the "connections" group.
184+
* @has_conns_grp: Have added a "connections" group for sysfs links.
168185
*/
169186
struct coresight_device {
170187
struct coresight_platform_data *pdata;
@@ -180,6 +197,9 @@ struct coresight_device {
180197
struct dev_ext_attribute *ea;
181198
/* cross trigger handling */
182199
struct coresight_device *ect_dev;
200+
/* sysfs links between components */
201+
int nr_links;
202+
bool has_conns_grp;
183203
};
184204

185205
/*

0 commit comments

Comments
 (0)