xref: /linux-6.15/include/linux/coresight.h (revision c61c4b5d)
1a06ae860SPratik Patel /* Copyright (c) 2012, The Linux Foundation. All rights reserved.
2a06ae860SPratik Patel  *
3a06ae860SPratik Patel  * This program is free software; you can redistribute it and/or modify
4a06ae860SPratik Patel  * it under the terms of the GNU General Public License version 2 and
5a06ae860SPratik Patel  * only version 2 as published by the Free Software Foundation.
6a06ae860SPratik Patel  *
7a06ae860SPratik Patel  * This program is distributed in the hope that it will be useful,
8a06ae860SPratik Patel  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9a06ae860SPratik Patel  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10a06ae860SPratik Patel  * GNU General Public License for more details.
11a06ae860SPratik Patel  */
12a06ae860SPratik Patel 
13a06ae860SPratik Patel #ifndef _LINUX_CORESIGHT_H
14a06ae860SPratik Patel #define _LINUX_CORESIGHT_H
15a06ae860SPratik Patel 
16a06ae860SPratik Patel #include <linux/device.h>
17a06ae860SPratik Patel 
18a06ae860SPratik Patel /* Peripheral id registers (0xFD0-0xFEC) */
19a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR4	0xfd0
20a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR5	0xfd4
21a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR6	0xfd8
22a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR7	0xfdC
23a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR0	0xfe0
24a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR1	0xfe4
25a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR2	0xfe8
26a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR3	0xfeC
27a06ae860SPratik Patel /* Component id registers (0xFF0-0xFFC) */
28a06ae860SPratik Patel #define CORESIGHT_COMPIDR0	0xff0
29a06ae860SPratik Patel #define CORESIGHT_COMPIDR1	0xff4
30a06ae860SPratik Patel #define CORESIGHT_COMPIDR2	0xff8
31a06ae860SPratik Patel #define CORESIGHT_COMPIDR3	0xffC
32a06ae860SPratik Patel 
33a06ae860SPratik Patel #define ETM_ARCH_V3_3		0x23
34a06ae860SPratik Patel #define ETM_ARCH_V3_5		0x25
35a06ae860SPratik Patel #define PFT_ARCH_V1_0		0x30
36a06ae860SPratik Patel #define PFT_ARCH_V1_1		0x31
37a06ae860SPratik Patel 
38a06ae860SPratik Patel #define CORESIGHT_UNLOCK	0xc5acce55
39a06ae860SPratik Patel 
40a06ae860SPratik Patel extern struct bus_type coresight_bustype;
41a06ae860SPratik Patel 
42a06ae860SPratik Patel enum coresight_dev_type {
43a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_NONE,
44a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_SINK,
45a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_LINK,
46a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_LINKSINK,
47a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_SOURCE,
48a06ae860SPratik Patel };
49a06ae860SPratik Patel 
50a06ae860SPratik Patel enum coresight_dev_subtype_sink {
51a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SINK_NONE,
52a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SINK_PORT,
53a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SINK_BUFFER,
54a06ae860SPratik Patel };
55a06ae860SPratik Patel 
56a06ae860SPratik Patel enum coresight_dev_subtype_link {
57a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_LINK_NONE,
58a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_LINK_MERG,
59a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_LINK_SPLIT,
60a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_LINK_FIFO,
61a06ae860SPratik Patel };
62a06ae860SPratik Patel 
63a06ae860SPratik Patel enum coresight_dev_subtype_source {
64a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SOURCE_NONE,
65a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SOURCE_PROC,
66a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SOURCE_BUS,
67a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE,
68a06ae860SPratik Patel };
69a06ae860SPratik Patel 
70a06ae860SPratik Patel /**
71a06ae860SPratik Patel  * struct coresight_dev_subtype - further characterisation of a type
72a06ae860SPratik Patel  * @sink_subtype:	type of sink this component is, as defined
73a06ae860SPratik Patel 			by @coresight_dev_subtype_sink.
74a06ae860SPratik Patel  * @link_subtype:	type of link this component is, as defined
75a06ae860SPratik Patel 			by @coresight_dev_subtype_link.
76a06ae860SPratik Patel  * @source_subtype:	type of source this component is, as defined
77a06ae860SPratik Patel 			by @coresight_dev_subtype_source.
78a06ae860SPratik Patel  */
79a06ae860SPratik Patel struct coresight_dev_subtype {
80a06ae860SPratik Patel 	enum coresight_dev_subtype_sink sink_subtype;
81a06ae860SPratik Patel 	enum coresight_dev_subtype_link link_subtype;
82a06ae860SPratik Patel 	enum coresight_dev_subtype_source source_subtype;
83a06ae860SPratik Patel };
84a06ae860SPratik Patel 
85a06ae860SPratik Patel /**
86a06ae860SPratik Patel  * struct coresight_platform_data - data harvested from the DT specification
87a06ae860SPratik Patel  * @cpu:	the CPU a source belongs to. Only applicable for ETM/PTMs.
88a06ae860SPratik Patel  * @name:	name of the component as shown under sysfs.
89a06ae860SPratik Patel  * @nr_inport:	number of input ports for this component.
908ee885a9SPankaj Dubey  * @outports:	list of remote endpoint port number.
91a06ae860SPratik Patel  * @child_names:name of all child components connected to this device.
92a06ae860SPratik Patel  * @child_ports:child component port number the current component is
93a06ae860SPratik Patel 		connected  to.
94a06ae860SPratik Patel  * @nr_outport:	number of output ports for this component.
95a06ae860SPratik Patel  * @clk:	The clock this component is associated to.
96a06ae860SPratik Patel  */
97a06ae860SPratik Patel struct coresight_platform_data {
98a06ae860SPratik Patel 	int cpu;
99a06ae860SPratik Patel 	const char *name;
100a06ae860SPratik Patel 	int nr_inport;
101a06ae860SPratik Patel 	int *outports;
102a06ae860SPratik Patel 	const char **child_names;
103a06ae860SPratik Patel 	int *child_ports;
104a06ae860SPratik Patel 	int nr_outport;
105a06ae860SPratik Patel 	struct clk *clk;
106a06ae860SPratik Patel };
107a06ae860SPratik Patel 
108a06ae860SPratik Patel /**
109a06ae860SPratik Patel  * struct coresight_desc - description of a component required from drivers
110a06ae860SPratik Patel  * @type:	as defined by @coresight_dev_type.
111a06ae860SPratik Patel  * @subtype:	as defined by @coresight_dev_subtype.
112a06ae860SPratik Patel  * @ops:	generic operations for this component, as defined
113a06ae860SPratik Patel 		by @coresight_ops.
114a06ae860SPratik Patel  * @pdata:	platform data collected from DT.
115a06ae860SPratik Patel  * @dev:	The device entity associated to this component.
116a06ae860SPratik Patel  * @groups:	operations specific to this component. These will end up
117a06ae860SPratik Patel 		in the component's sysfs sub-directory.
118a06ae860SPratik Patel  */
119a06ae860SPratik Patel struct coresight_desc {
120a06ae860SPratik Patel 	enum coresight_dev_type type;
121a06ae860SPratik Patel 	struct coresight_dev_subtype subtype;
122a06ae860SPratik Patel 	const struct coresight_ops *ops;
123a06ae860SPratik Patel 	struct coresight_platform_data *pdata;
124a06ae860SPratik Patel 	struct device *dev;
125a06ae860SPratik Patel 	const struct attribute_group **groups;
126a06ae860SPratik Patel };
127a06ae860SPratik Patel 
128a06ae860SPratik Patel /**
129a06ae860SPratik Patel  * struct coresight_connection - representation of a single connection
130a06ae860SPratik Patel  * @outport:	a connection's output port number.
131a06ae860SPratik Patel  * @chid_name:	remote component's name.
132a06ae860SPratik Patel  * @child_port:	remote component's port number @output is connected to.
133a06ae860SPratik Patel  * @child_dev:	a @coresight_device representation of the component
134a06ae860SPratik Patel 		connected to @outport.
135a06ae860SPratik Patel  */
136a06ae860SPratik Patel struct coresight_connection {
137a06ae860SPratik Patel 	int outport;
138a06ae860SPratik Patel 	const char *child_name;
139a06ae860SPratik Patel 	int child_port;
140a06ae860SPratik Patel 	struct coresight_device *child_dev;
141a06ae860SPratik Patel };
142a06ae860SPratik Patel 
143a06ae860SPratik Patel /**
144a06ae860SPratik Patel  * struct coresight_device - representation of a device as used by the framework
1458ee885a9SPankaj Dubey  * @conns:	array of coresight_connections associated to this component.
146a06ae860SPratik Patel  * @nr_inport:	number of input port associated to this component.
147a06ae860SPratik Patel  * @nr_outport:	number of output port associated to this component.
148a06ae860SPratik Patel  * @type:	as defined by @coresight_dev_type.
149a06ae860SPratik Patel  * @subtype:	as defined by @coresight_dev_subtype.
150a06ae860SPratik Patel  * @ops:	generic operations for this component, as defined
151a06ae860SPratik Patel 		by @coresight_ops.
152a06ae860SPratik Patel  * @dev:	The device entity associated to this component.
153a06ae860SPratik Patel  * @refcnt:	keep track of what is in use.
154a06ae860SPratik Patel  * @path_link:	link of current component into the path being enabled.
155a06ae860SPratik Patel  * @orphan:	true if the component has connections that haven't been linked.
156a06ae860SPratik Patel  * @enable:	'true' if component is currently part of an active path.
157a06ae860SPratik Patel  * @activated:	'true' only if a _sink_ has been activated.  A sink can be
158a06ae860SPratik Patel 		activated but not yet enabled.  Enabling for a _sink_
159a06ae860SPratik Patel 		happens when a source has been selected for that it.
160a06ae860SPratik Patel  */
161a06ae860SPratik Patel struct coresight_device {
162a06ae860SPratik Patel 	struct coresight_connection *conns;
163a06ae860SPratik Patel 	int nr_inport;
164a06ae860SPratik Patel 	int nr_outport;
165a06ae860SPratik Patel 	enum coresight_dev_type type;
166a06ae860SPratik Patel 	struct coresight_dev_subtype subtype;
167a06ae860SPratik Patel 	const struct coresight_ops *ops;
168a06ae860SPratik Patel 	struct device dev;
169a06ae860SPratik Patel 	atomic_t *refcnt;
170a06ae860SPratik Patel 	struct list_head path_link;
171a06ae860SPratik Patel 	bool orphan;
172a06ae860SPratik Patel 	bool enable;	/* true only if configured as part of a path */
173a06ae860SPratik Patel 	bool activated;	/* true only if a sink is part of a path */
174a06ae860SPratik Patel };
175a06ae860SPratik Patel 
176a06ae860SPratik Patel #define to_coresight_device(d) container_of(d, struct coresight_device, dev)
177a06ae860SPratik Patel 
178a06ae860SPratik Patel #define source_ops(csdev)	csdev->ops->source_ops
179a06ae860SPratik Patel #define sink_ops(csdev)		csdev->ops->sink_ops
180a06ae860SPratik Patel #define link_ops(csdev)		csdev->ops->link_ops
181a06ae860SPratik Patel 
182a06ae860SPratik Patel /**
183a06ae860SPratik Patel  * struct coresight_ops_sink - basic operations for a sink
184a06ae860SPratik Patel  * Operations available for sinks
185a06ae860SPratik Patel  * @enable:	enables the sink.
186a06ae860SPratik Patel  * @disable:	disables the sink.
187a06ae860SPratik Patel  */
188a06ae860SPratik Patel struct coresight_ops_sink {
189a06ae860SPratik Patel 	int (*enable)(struct coresight_device *csdev);
190a06ae860SPratik Patel 	void (*disable)(struct coresight_device *csdev);
191a06ae860SPratik Patel };
192a06ae860SPratik Patel 
193a06ae860SPratik Patel /**
194a06ae860SPratik Patel  * struct coresight_ops_link - basic operations for a link
195a06ae860SPratik Patel  * Operations available for links.
196a06ae860SPratik Patel  * @enable:	enables flow between iport and oport.
197a06ae860SPratik Patel  * @disable:	disables flow between iport and oport.
198a06ae860SPratik Patel  */
199a06ae860SPratik Patel struct coresight_ops_link {
200a06ae860SPratik Patel 	int (*enable)(struct coresight_device *csdev, int iport, int oport);
201a06ae860SPratik Patel 	void (*disable)(struct coresight_device *csdev, int iport, int oport);
202a06ae860SPratik Patel };
203a06ae860SPratik Patel 
204a06ae860SPratik Patel /**
205a06ae860SPratik Patel  * struct coresight_ops_source - basic operations for a source
206a06ae860SPratik Patel  * Operations available for sources.
207a06ae860SPratik Patel  * @trace_id:	returns the value of the component's trace ID as known
208a06ae860SPratik Patel 		to the HW.
209a06ae860SPratik Patel  * @enable:	enables tracing from a source.
210a06ae860SPratik Patel  * @disable:	disables tracing for a source.
211a06ae860SPratik Patel  */
212a06ae860SPratik Patel struct coresight_ops_source {
213a06ae860SPratik Patel 	int (*trace_id)(struct coresight_device *csdev);
214a06ae860SPratik Patel 	int (*enable)(struct coresight_device *csdev);
215a06ae860SPratik Patel 	void (*disable)(struct coresight_device *csdev);
216a06ae860SPratik Patel };
217a06ae860SPratik Patel 
218a06ae860SPratik Patel struct coresight_ops {
219a06ae860SPratik Patel 	const struct coresight_ops_sink *sink_ops;
220a06ae860SPratik Patel 	const struct coresight_ops_link *link_ops;
221a06ae860SPratik Patel 	const struct coresight_ops_source *source_ops;
222a06ae860SPratik Patel };
223a06ae860SPratik Patel 
224a06ae860SPratik Patel #ifdef CONFIG_CORESIGHT
225a06ae860SPratik Patel extern struct coresight_device *
226a06ae860SPratik Patel coresight_register(struct coresight_desc *desc);
227a06ae860SPratik Patel extern void coresight_unregister(struct coresight_device *csdev);
228a06ae860SPratik Patel extern int coresight_enable(struct coresight_device *csdev);
229a06ae860SPratik Patel extern void coresight_disable(struct coresight_device *csdev);
230a06ae860SPratik Patel extern int coresight_is_bit_set(u32 val, int position, int value);
231a06ae860SPratik Patel extern int coresight_timeout(void __iomem *addr, u32 offset,
232a06ae860SPratik Patel 			     int position, int value);
233a06ae860SPratik Patel #else
234a06ae860SPratik Patel static inline struct coresight_device *
235a06ae860SPratik Patel coresight_register(struct coresight_desc *desc) { return NULL; }
236a06ae860SPratik Patel static inline void coresight_unregister(struct coresight_device *csdev) {}
237a06ae860SPratik Patel static inline int
238a06ae860SPratik Patel coresight_enable(struct coresight_device *csdev) { return -ENOSYS; }
239a06ae860SPratik Patel static inline void coresight_disable(struct coresight_device *csdev) {}
240a06ae860SPratik Patel static inline int coresight_is_bit_set(u32 val, int position, int value)
241a06ae860SPratik Patel 					 { return 0; }
242a06ae860SPratik Patel static inline int coresight_timeout(void __iomem *addr, u32 offset,
243a06ae860SPratik Patel 				     int position, int value) { return 1; }
244*c61c4b5dSMathieu Poirier #endif
245*c61c4b5dSMathieu Poirier 
246a06ae860SPratik Patel #ifdef CONFIG_OF
247*c61c4b5dSMathieu Poirier extern struct coresight_platform_data *of_get_coresight_platform_data(
248*c61c4b5dSMathieu Poirier 				struct device *dev, struct device_node *node);
249*c61c4b5dSMathieu Poirier #else
250a06ae860SPratik Patel static inline struct coresight_platform_data *of_get_coresight_platform_data(
251a06ae860SPratik Patel 	struct device *dev, struct device_node *node) { return NULL; }
252a06ae860SPratik Patel #endif
253a06ae860SPratik Patel 
254a06ae860SPratik Patel #endif
255