xref: /linux-6.15/include/linux/coresight.h (revision 8ce00296)
1ad0dfdfdSMathieu Poirier /* SPDX-License-Identifier: GPL-2.0 */
2ad0dfdfdSMathieu Poirier /*
3ad0dfdfdSMathieu Poirier  * Copyright (c) 2012, The Linux Foundation. All rights reserved.
4a06ae860SPratik Patel  */
5a06ae860SPratik Patel 
6a06ae860SPratik Patel #ifndef _LINUX_CORESIGHT_H
7a06ae860SPratik Patel #define _LINUX_CORESIGHT_H
8a06ae860SPratik Patel 
9a06ae860SPratik Patel #include <linux/device.h>
106e736c60SSuzuki K Poulose #include <linux/io.h>
11882d5e11SMathieu Poirier #include <linux/perf_event.h>
12ff63ec13SMark Brown #include <linux/sched.h>
13a06ae860SPratik Patel 
14a06ae860SPratik Patel /* Peripheral id registers (0xFD0-0xFEC) */
15a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR4	0xfd0
16a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR5	0xfd4
17a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR6	0xfd8
18a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR7	0xfdC
19a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR0	0xfe0
20a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR1	0xfe4
21a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR2	0xfe8
22a06ae860SPratik Patel #define CORESIGHT_PERIPHIDR3	0xfeC
23a06ae860SPratik Patel /* Component id registers (0xFF0-0xFFC) */
24a06ae860SPratik Patel #define CORESIGHT_COMPIDR0	0xff0
25a06ae860SPratik Patel #define CORESIGHT_COMPIDR1	0xff4
26a06ae860SPratik Patel #define CORESIGHT_COMPIDR2	0xff8
27a06ae860SPratik Patel #define CORESIGHT_COMPIDR3	0xffC
28a06ae860SPratik Patel 
29a06ae860SPratik Patel #define ETM_ARCH_V3_3		0x23
30a06ae860SPratik Patel #define ETM_ARCH_V3_5		0x25
31a06ae860SPratik Patel #define PFT_ARCH_V1_0		0x30
32a06ae860SPratik Patel #define PFT_ARCH_V1_1		0x31
33a06ae860SPratik Patel 
34a06ae860SPratik Patel #define CORESIGHT_UNLOCK	0xc5acce55
35a06ae860SPratik Patel 
36a06ae860SPratik Patel extern struct bus_type coresight_bustype;
37a06ae860SPratik Patel 
38a06ae860SPratik Patel enum coresight_dev_type {
39a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_NONE,
40a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_SINK,
41a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_LINK,
42a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_LINKSINK,
43a06ae860SPratik Patel 	CORESIGHT_DEV_TYPE_SOURCE,
448a091d84SSuzuki K Poulose 	CORESIGHT_DEV_TYPE_HELPER,
45835d722bSMike Leach 	CORESIGHT_DEV_TYPE_ECT,
46a06ae860SPratik Patel };
47a06ae860SPratik Patel 
48a06ae860SPratik Patel enum coresight_dev_subtype_sink {
49a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SINK_NONE,
50a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SINK_PORT,
51a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SINK_BUFFER,
520336bdfdSMike Leach 	CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM,
53a06ae860SPratik Patel };
54a06ae860SPratik Patel 
55a06ae860SPratik Patel enum coresight_dev_subtype_link {
56a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_LINK_NONE,
57a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_LINK_MERG,
58a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_LINK_SPLIT,
59a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_LINK_FIFO,
60a06ae860SPratik Patel };
61a06ae860SPratik Patel 
62a06ae860SPratik Patel enum coresight_dev_subtype_source {
63a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SOURCE_NONE,
64a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SOURCE_PROC,
65a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SOURCE_BUS,
66a06ae860SPratik Patel 	CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE,
67a06ae860SPratik Patel };
68a06ae860SPratik Patel 
698a091d84SSuzuki K Poulose enum coresight_dev_subtype_helper {
708a091d84SSuzuki K Poulose 	CORESIGHT_DEV_SUBTYPE_HELPER_NONE,
71fcacb5c1SSuzuki K Poulose 	CORESIGHT_DEV_SUBTYPE_HELPER_CATU,
728a091d84SSuzuki K Poulose };
738a091d84SSuzuki K Poulose 
74835d722bSMike Leach /* Embedded Cross Trigger (ECT) sub-types */
75835d722bSMike Leach enum coresight_dev_subtype_ect {
76835d722bSMike Leach 	CORESIGHT_DEV_SUBTYPE_ECT_NONE,
77835d722bSMike Leach 	CORESIGHT_DEV_SUBTYPE_ECT_CTI,
78835d722bSMike Leach };
79835d722bSMike Leach 
80a06ae860SPratik Patel /**
8100b78e8bSSuzuki K Poulose  * union coresight_dev_subtype - further characterisation of a type
82a06ae860SPratik Patel  * @sink_subtype:	type of sink this component is, as defined
8300b78e8bSSuzuki K Poulose  *			by @coresight_dev_subtype_sink.
84a06ae860SPratik Patel  * @link_subtype:	type of link this component is, as defined
8500b78e8bSSuzuki K Poulose  *			by @coresight_dev_subtype_link.
86a06ae860SPratik Patel  * @source_subtype:	type of source this component is, as defined
8700b78e8bSSuzuki K Poulose  *			by @coresight_dev_subtype_source.
888a091d84SSuzuki K Poulose  * @helper_subtype:	type of helper this component is, as defined
898a091d84SSuzuki K Poulose  *			by @coresight_dev_subtype_helper.
90835d722bSMike Leach  * @ect_subtype:        type of cross trigger this component is, as
91835d722bSMike Leach  *			defined by @coresight_dev_subtype_ect
92a06ae860SPratik Patel  */
9300b78e8bSSuzuki K Poulose union coresight_dev_subtype {
9400b78e8bSSuzuki K Poulose 	/* We have some devices which acts as LINK and SINK */
9500b78e8bSSuzuki K Poulose 	struct {
96a06ae860SPratik Patel 		enum coresight_dev_subtype_sink sink_subtype;
97a06ae860SPratik Patel 		enum coresight_dev_subtype_link link_subtype;
9800b78e8bSSuzuki K Poulose 	};
99a06ae860SPratik Patel 	enum coresight_dev_subtype_source source_subtype;
1008a091d84SSuzuki K Poulose 	enum coresight_dev_subtype_helper helper_subtype;
101835d722bSMike Leach 	enum coresight_dev_subtype_ect ect_subtype;
102a06ae860SPratik Patel };
103a06ae860SPratik Patel 
104a06ae860SPratik Patel /**
105d375b356SSuzuki K Poulose  * struct coresight_platform_data - data harvested from the firmware
106d375b356SSuzuki K Poulose  * specification.
107d375b356SSuzuki K Poulose  *
108d375b356SSuzuki K Poulose  * @nr_inport:	Number of elements for the input connections.
109d375b356SSuzuki K Poulose  * @nr_outport:	Number of elements for the output connections.
110d375b356SSuzuki K Poulose  * @conns:	Sparse array of nr_outport connections from this component.
111a06ae860SPratik Patel  */
112a06ae860SPratik Patel struct coresight_platform_data {
113a06ae860SPratik Patel 	int nr_inport;
114a06ae860SPratik Patel 	int nr_outport;
115c2c72941SSuzuki K Poulose 	struct coresight_connection *conns;
116a06ae860SPratik Patel };
117a06ae860SPratik Patel 
118a06ae860SPratik Patel /**
1196e736c60SSuzuki K Poulose  * struct csdev_access - Abstraction of a CoreSight device access.
1206e736c60SSuzuki K Poulose  *
1216e736c60SSuzuki K Poulose  * @io_mem	: True if the device has memory mapped I/O
1226e736c60SSuzuki K Poulose  * @base	: When io_mem == true, base address of the component
1236e736c60SSuzuki K Poulose  * @read	: Read from the given "offset" of the given instance.
1246e736c60SSuzuki K Poulose  * @write	: Write "val" to the given "offset".
1256e736c60SSuzuki K Poulose  */
1266e736c60SSuzuki K Poulose struct csdev_access {
1276e736c60SSuzuki K Poulose 	bool io_mem;
1286e736c60SSuzuki K Poulose 	union {
1296e736c60SSuzuki K Poulose 		void __iomem *base;
1306e736c60SSuzuki K Poulose 		struct {
1316e736c60SSuzuki K Poulose 			u64 (*read)(u32 offset, bool relaxed, bool _64bit);
1326e736c60SSuzuki K Poulose 			void (*write)(u64 val, u32 offset, bool relaxed,
1336e736c60SSuzuki K Poulose 				      bool _64bit);
1346e736c60SSuzuki K Poulose 		};
1356e736c60SSuzuki K Poulose 	};
1366e736c60SSuzuki K Poulose };
1376e736c60SSuzuki K Poulose 
1386e736c60SSuzuki K Poulose #define CSDEV_ACCESS_IOMEM(_addr)		\
1396e736c60SSuzuki K Poulose 	((struct csdev_access)	{		\
1406e736c60SSuzuki K Poulose 		.io_mem		= true,		\
1416e736c60SSuzuki K Poulose 		.base		= (_addr),	\
1426e736c60SSuzuki K Poulose 	})
1436e736c60SSuzuki K Poulose 
1446e736c60SSuzuki K Poulose /**
145a06ae860SPratik Patel  * struct coresight_desc - description of a component required from drivers
146a06ae860SPratik Patel  * @type:	as defined by @coresight_dev_type.
147a06ae860SPratik Patel  * @subtype:	as defined by @coresight_dev_subtype.
148a06ae860SPratik Patel  * @ops:	generic operations for this component, as defined
1492ede79a6SSuzuki K Poulose  *		by @coresight_ops.
150a06ae860SPratik Patel  * @pdata:	platform data collected from DT.
151a06ae860SPratik Patel  * @dev:	The device entity associated to this component.
152a06ae860SPratik Patel  * @groups:	operations specific to this component. These will end up
1532ede79a6SSuzuki K Poulose  *		in the component's sysfs sub-directory.
1542ede79a6SSuzuki K Poulose  * @name:	name for the coresight device, also shown under sysfs.
1556e736c60SSuzuki K Poulose  * @access:	Describe access to the device
156a06ae860SPratik Patel  */
157a06ae860SPratik Patel struct coresight_desc {
158a06ae860SPratik Patel 	enum coresight_dev_type type;
15900b78e8bSSuzuki K Poulose 	union coresight_dev_subtype subtype;
160a06ae860SPratik Patel 	const struct coresight_ops *ops;
161a06ae860SPratik Patel 	struct coresight_platform_data *pdata;
162a06ae860SPratik Patel 	struct device *dev;
163a06ae860SPratik Patel 	const struct attribute_group **groups;
1642ede79a6SSuzuki K Poulose 	const char *name;
1656e736c60SSuzuki K Poulose 	struct csdev_access access;
166a06ae860SPratik Patel };
167a06ae860SPratik Patel 
168a06ae860SPratik Patel /**
169a06ae860SPratik Patel  * struct coresight_connection - representation of a single connection
170a06ae860SPratik Patel  * @outport:	a connection's output port number.
171a06ae860SPratik Patel  * @child_port:	remote component's port number @output is connected to.
17237ea1ffdSSuzuki K Poulose  * @chid_fwnode: remote component's fwnode handle.
173a06ae860SPratik Patel  * @child_dev:	a @coresight_device representation of the component
174a06ae860SPratik Patel 		connected to @outport.
1758a7365c2SSuzuki K Poulose  * @link: Representation of the connection as a sysfs link.
176a06ae860SPratik Patel  */
177a06ae860SPratik Patel struct coresight_connection {
178a06ae860SPratik Patel 	int outport;
179a06ae860SPratik Patel 	int child_port;
18037ea1ffdSSuzuki K Poulose 	struct fwnode_handle *child_fwnode;
181a06ae860SPratik Patel 	struct coresight_device *child_dev;
1828a7365c2SSuzuki K Poulose 	struct coresight_sysfs_link *link;
183a06ae860SPratik Patel };
184a06ae860SPratik Patel 
185a06ae860SPratik Patel /**
18680961525SMike Leach  * struct coresight_sysfs_link - representation of a connection in sysfs.
18780961525SMike Leach  * @orig:		Originating (master) coresight device for the link.
18880961525SMike Leach  * @orig_name:		Name to use for the link orig->target.
18980961525SMike Leach  * @target:		Target (slave) coresight device for the link.
19080961525SMike Leach  * @target_name:	Name to use for the link target->orig.
19180961525SMike Leach  */
19280961525SMike Leach struct coresight_sysfs_link {
19380961525SMike Leach 	struct coresight_device *orig;
19480961525SMike Leach 	const char *orig_name;
19580961525SMike Leach 	struct coresight_device *target;
19680961525SMike Leach 	const char *target_name;
19780961525SMike Leach };
19880961525SMike Leach 
19980961525SMike Leach /**
200a06ae860SPratik Patel  * struct coresight_device - representation of a device as used by the framework
201b77e3ed0SSuzuki K Poulose  * @pdata:	Platform data with device connections associated to this device.
202a06ae860SPratik Patel  * @type:	as defined by @coresight_dev_type.
203a06ae860SPratik Patel  * @subtype:	as defined by @coresight_dev_subtype.
204a06ae860SPratik Patel  * @ops:	generic operations for this component, as defined
2056e736c60SSuzuki K Poulose  *		by @coresight_ops.
2066e736c60SSuzuki K Poulose  * @access:	Device i/o access abstraction for this device.
207a06ae860SPratik Patel  * @dev:	The device entity associated to this component.
208a06ae860SPratik Patel  * @refcnt:	keep track of what is in use.
209a06ae860SPratik Patel  * @orphan:	true if the component has connections that haven't been linked.
210a06ae860SPratik Patel  * @enable:	'true' if component is currently part of an active path.
211a06ae860SPratik Patel  * @activated:	'true' only if a _sink_ has been activated.  A sink can be
212bb8e370bSMathieu Poirier  *		activated but not yet enabled.  Enabling for a _sink_
213d061cd73SMike Leach  *		happens when a source has been selected and a path is enabled
214d061cd73SMike Leach  *		from source to that sink.
215bb8e370bSMathieu Poirier  * @ea:		Device attribute for sink representation under PMU directory.
2160336bdfdSMike Leach  * @def_sink:	cached reference to default sink found for this device.
217177af828SMike Leach  * @ect_dev:	Associated cross trigger device. Not part of the trace data
218177af828SMike Leach  *		path or connections.
21980961525SMike Leach  * @nr_links:   number of sysfs links created to other components from this
22080961525SMike Leach  *		device. These will appear in the "connections" group.
22180961525SMike Leach  * @has_conns_grp: Have added a "connections" group for sysfs links.
222a06ae860SPratik Patel  */
223a06ae860SPratik Patel struct coresight_device {
224b77e3ed0SSuzuki K Poulose 	struct coresight_platform_data *pdata;
225a06ae860SPratik Patel 	enum coresight_dev_type type;
22600b78e8bSSuzuki K Poulose 	union coresight_dev_subtype subtype;
227a06ae860SPratik Patel 	const struct coresight_ops *ops;
2286e736c60SSuzuki K Poulose 	struct csdev_access access;
229a06ae860SPratik Patel 	struct device dev;
230a06ae860SPratik Patel 	atomic_t *refcnt;
231a06ae860SPratik Patel 	bool orphan;
232a06ae860SPratik Patel 	bool enable;	/* true only if configured as part of a path */
233bb8e370bSMathieu Poirier 	/* sink specific fields */
234a06ae860SPratik Patel 	bool activated;	/* true only if a sink is part of a path */
235bb8e370bSMathieu Poirier 	struct dev_ext_attribute *ea;
2360336bdfdSMike Leach 	struct coresight_device *def_sink;
237177af828SMike Leach 	/* cross trigger handling */
238177af828SMike Leach 	struct coresight_device *ect_dev;
23980961525SMike Leach 	/* sysfs links between components */
24080961525SMike Leach 	int nr_links;
24180961525SMike Leach 	bool has_conns_grp;
242f2ccc7b7STingwei Zhang 	bool ect_enabled; /* true only if associated ect device is enabled */
243a06ae860SPratik Patel };
244a06ae860SPratik Patel 
2450f5f9b6bSSuzuki K Poulose /*
2460f5f9b6bSSuzuki K Poulose  * coresight_dev_list - Mapping for devices to "name" index for device
2470f5f9b6bSSuzuki K Poulose  * names.
2480f5f9b6bSSuzuki K Poulose  *
2490f5f9b6bSSuzuki K Poulose  * @nr_idx:		Number of entries already allocated.
2500f5f9b6bSSuzuki K Poulose  * @pfx:		Prefix pattern for device name.
2510f5f9b6bSSuzuki K Poulose  * @fwnode_list:	Array of fwnode_handles associated with each allocated
2520f5f9b6bSSuzuki K Poulose  *			index, upto nr_idx entries.
2530f5f9b6bSSuzuki K Poulose  */
2540f5f9b6bSSuzuki K Poulose struct coresight_dev_list {
2550f5f9b6bSSuzuki K Poulose 	int			nr_idx;
2560f5f9b6bSSuzuki K Poulose 	const char		*pfx;
2570f5f9b6bSSuzuki K Poulose 	struct fwnode_handle	**fwnode_list;
2580f5f9b6bSSuzuki K Poulose };
2590f5f9b6bSSuzuki K Poulose 
2600f5f9b6bSSuzuki K Poulose #define DEFINE_CORESIGHT_DEVLIST(var, dev_pfx)				\
2610f5f9b6bSSuzuki K Poulose static struct coresight_dev_list (var) = {				\
2620f5f9b6bSSuzuki K Poulose 						.pfx = dev_pfx,		\
2630f5f9b6bSSuzuki K Poulose 						.nr_idx = 0,		\
2640f5f9b6bSSuzuki K Poulose 						.fwnode_list = NULL,	\
2650f5f9b6bSSuzuki K Poulose }
2660f5f9b6bSSuzuki K Poulose 
267a06ae860SPratik Patel #define to_coresight_device(d) container_of(d, struct coresight_device, dev)
268a06ae860SPratik Patel 
269a06ae860SPratik Patel #define source_ops(csdev)	csdev->ops->source_ops
270a06ae860SPratik Patel #define sink_ops(csdev)		csdev->ops->sink_ops
271a06ae860SPratik Patel #define link_ops(csdev)		csdev->ops->link_ops
2728a091d84SSuzuki K Poulose #define helper_ops(csdev)	csdev->ops->helper_ops
273835d722bSMike Leach #define ect_ops(csdev)		csdev->ops->ect_ops
274a06ae860SPratik Patel 
275a06ae860SPratik Patel /**
276a06ae860SPratik Patel  * struct coresight_ops_sink - basic operations for a sink
277a06ae860SPratik Patel  * Operations available for sinks
278a06ae860SPratik Patel  * @enable:		enables the sink.
279a06ae860SPratik Patel  * @disable:		disables the sink.
2802997aa40SMathieu Poirier  * @alloc_buffer:	initialises perf's ring buffer for trace collection.
2812997aa40SMathieu Poirier  * @free_buffer:	release memory allocated in @get_config.
2822997aa40SMathieu Poirier  * @update_buffer:	update buffer pointers after a trace session.
283a06ae860SPratik Patel  */
284a06ae860SPratik Patel struct coresight_ops_sink {
2853d6e8935SSuzuki K Poulose 	int (*enable)(struct coresight_device *csdev, u32 mode, void *data);
2866c817a95SMathieu Poirier 	int (*disable)(struct coresight_device *csdev);
287a0f08a6aSMathieu Poirier 	void *(*alloc_buffer)(struct coresight_device *csdev,
288a0f08a6aSMathieu Poirier 			      struct perf_event *event, void **pages,
289a0f08a6aSMathieu Poirier 			      int nr_pages, bool overwrite);
2902997aa40SMathieu Poirier 	void (*free_buffer)(void *config);
2917ec786adSSuzuki K Poulose 	unsigned long (*update_buffer)(struct coresight_device *csdev,
2922997aa40SMathieu Poirier 			      struct perf_output_handle *handle,
2932997aa40SMathieu Poirier 			      void *sink_config);
294a06ae860SPratik Patel };
295a06ae860SPratik Patel 
296a06ae860SPratik Patel /**
297a06ae860SPratik Patel  * struct coresight_ops_link - basic operations for a link
298a06ae860SPratik Patel  * Operations available for links.
299a06ae860SPratik Patel  * @enable:	enables flow between iport and oport.
300a06ae860SPratik Patel  * @disable:	disables flow between iport and oport.
301a06ae860SPratik Patel  */
302a06ae860SPratik Patel struct coresight_ops_link {
303a06ae860SPratik Patel 	int (*enable)(struct coresight_device *csdev, int iport, int oport);
304a06ae860SPratik Patel 	void (*disable)(struct coresight_device *csdev, int iport, int oport);
305a06ae860SPratik Patel };
306a06ae860SPratik Patel 
307a06ae860SPratik Patel /**
308a06ae860SPratik Patel  * struct coresight_ops_source - basic operations for a source
309a06ae860SPratik Patel  * Operations available for sources.
31052210c87SMathieu Poirier  * @cpu_id:	returns the value of the CPU number this component
31152210c87SMathieu Poirier  *		is associated to.
312a06ae860SPratik Patel  * @trace_id:	returns the value of the component's trace ID as known
313882d5e11SMathieu Poirier  *		to the HW.
3141d27ff5aSMathieu Poirier  * @enable:	enables tracing for a source.
315a06ae860SPratik Patel  * @disable:	disables tracing for a source.
316a06ae860SPratik Patel  */
317a06ae860SPratik Patel struct coresight_ops_source {
31852210c87SMathieu Poirier 	int (*cpu_id)(struct coresight_device *csdev);
319a06ae860SPratik Patel 	int (*trace_id)(struct coresight_device *csdev);
320882d5e11SMathieu Poirier 	int (*enable)(struct coresight_device *csdev,
32168905d73SMathieu Poirier 		      struct perf_event *event,  u32 mode);
32268905d73SMathieu Poirier 	void (*disable)(struct coresight_device *csdev,
32368905d73SMathieu Poirier 			struct perf_event *event);
324a06ae860SPratik Patel };
325a06ae860SPratik Patel 
3268a091d84SSuzuki K Poulose /**
3278a091d84SSuzuki K Poulose  * struct coresight_ops_helper - Operations for a helper device.
3288a091d84SSuzuki K Poulose  *
3298a091d84SSuzuki K Poulose  * All operations could pass in a device specific data, which could
3308a091d84SSuzuki K Poulose  * help the helper device to determine what to do.
3318a091d84SSuzuki K Poulose  *
3328a091d84SSuzuki K Poulose  * @enable	: Enable the device
3338a091d84SSuzuki K Poulose  * @disable	: Disable the device
3348a091d84SSuzuki K Poulose  */
3358a091d84SSuzuki K Poulose struct coresight_ops_helper {
3368a091d84SSuzuki K Poulose 	int (*enable)(struct coresight_device *csdev, void *data);
3378a091d84SSuzuki K Poulose 	int (*disable)(struct coresight_device *csdev, void *data);
3388a091d84SSuzuki K Poulose };
3398a091d84SSuzuki K Poulose 
340835d722bSMike Leach /**
341835d722bSMike Leach  * struct coresight_ops_ect - Ops for an embedded cross trigger device
342835d722bSMike Leach  *
343835d722bSMike Leach  * @enable	: Enable the device
344835d722bSMike Leach  * @disable	: Disable the device
345835d722bSMike Leach  */
346835d722bSMike Leach struct coresight_ops_ect {
347835d722bSMike Leach 	int (*enable)(struct coresight_device *csdev);
348835d722bSMike Leach 	int (*disable)(struct coresight_device *csdev);
349835d722bSMike Leach };
350835d722bSMike Leach 
351a06ae860SPratik Patel struct coresight_ops {
352a06ae860SPratik Patel 	const struct coresight_ops_sink *sink_ops;
353a06ae860SPratik Patel 	const struct coresight_ops_link *link_ops;
354a06ae860SPratik Patel 	const struct coresight_ops_source *source_ops;
3558a091d84SSuzuki K Poulose 	const struct coresight_ops_helper *helper_ops;
356835d722bSMike Leach 	const struct coresight_ops_ect *ect_ops;
357a06ae860SPratik Patel };
358a06ae860SPratik Patel 
359b8127113SKim Phillips #if IS_ENABLED(CONFIG_CORESIGHT)
3606e736c60SSuzuki K Poulose 
3616e736c60SSuzuki K Poulose static inline u32 csdev_access_relaxed_read32(struct csdev_access *csa,
3626e736c60SSuzuki K Poulose 					      u32 offset)
3636e736c60SSuzuki K Poulose {
3646e736c60SSuzuki K Poulose 	if (likely(csa->io_mem))
3656e736c60SSuzuki K Poulose 		return readl_relaxed(csa->base + offset);
3666e736c60SSuzuki K Poulose 
3676e736c60SSuzuki K Poulose 	return csa->read(offset, true, false);
3686e736c60SSuzuki K Poulose }
3696e736c60SSuzuki K Poulose 
3706e736c60SSuzuki K Poulose static inline u32 csdev_access_read32(struct csdev_access *csa, u32 offset)
3716e736c60SSuzuki K Poulose {
3726e736c60SSuzuki K Poulose 	if (likely(csa->io_mem))
3736e736c60SSuzuki K Poulose 		return readl(csa->base + offset);
3746e736c60SSuzuki K Poulose 
3756e736c60SSuzuki K Poulose 	return csa->read(offset, false, false);
3766e736c60SSuzuki K Poulose }
3776e736c60SSuzuki K Poulose 
3786e736c60SSuzuki K Poulose static inline void csdev_access_relaxed_write32(struct csdev_access *csa,
3796e736c60SSuzuki K Poulose 						u32 val, u32 offset)
3806e736c60SSuzuki K Poulose {
3816e736c60SSuzuki K Poulose 	if (likely(csa->io_mem))
3826e736c60SSuzuki K Poulose 		writel_relaxed(val, csa->base + offset);
3836e736c60SSuzuki K Poulose 	else
3846e736c60SSuzuki K Poulose 		csa->write(val, offset, true, false);
3856e736c60SSuzuki K Poulose }
3866e736c60SSuzuki K Poulose 
3876e736c60SSuzuki K Poulose static inline void csdev_access_write32(struct csdev_access *csa, u32 val, u32 offset)
3886e736c60SSuzuki K Poulose {
3896e736c60SSuzuki K Poulose 	if (likely(csa->io_mem))
3906e736c60SSuzuki K Poulose 		writel(val, csa->base + offset);
3916e736c60SSuzuki K Poulose 	else
3926e736c60SSuzuki K Poulose 		csa->write(val, offset, false, false);
3936e736c60SSuzuki K Poulose }
3946e736c60SSuzuki K Poulose 
3956e736c60SSuzuki K Poulose #ifdef CONFIG_64BIT
3966e736c60SSuzuki K Poulose 
3976e736c60SSuzuki K Poulose static inline u64 csdev_access_relaxed_read64(struct csdev_access *csa,
3986e736c60SSuzuki K Poulose 					      u32 offset)
3996e736c60SSuzuki K Poulose {
4006e736c60SSuzuki K Poulose 	if (likely(csa->io_mem))
4016e736c60SSuzuki K Poulose 		return readq_relaxed(csa->base + offset);
4026e736c60SSuzuki K Poulose 
4036e736c60SSuzuki K Poulose 	return csa->read(offset, true, true);
4046e736c60SSuzuki K Poulose }
4056e736c60SSuzuki K Poulose 
4066e736c60SSuzuki K Poulose static inline u64 csdev_access_read64(struct csdev_access *csa, u32 offset)
4076e736c60SSuzuki K Poulose {
4086e736c60SSuzuki K Poulose 	if (likely(csa->io_mem))
4096e736c60SSuzuki K Poulose 		return readq(csa->base + offset);
4106e736c60SSuzuki K Poulose 
4116e736c60SSuzuki K Poulose 	return csa->read(offset, false, true);
4126e736c60SSuzuki K Poulose }
4136e736c60SSuzuki K Poulose 
4146e736c60SSuzuki K Poulose static inline void csdev_access_relaxed_write64(struct csdev_access *csa,
4156e736c60SSuzuki K Poulose 						u64 val, u32 offset)
4166e736c60SSuzuki K Poulose {
4176e736c60SSuzuki K Poulose 	if (likely(csa->io_mem))
4186e736c60SSuzuki K Poulose 		writeq_relaxed(val, csa->base + offset);
4196e736c60SSuzuki K Poulose 	else
4206e736c60SSuzuki K Poulose 		csa->write(val, offset, true, true);
4216e736c60SSuzuki K Poulose }
4226e736c60SSuzuki K Poulose 
4236e736c60SSuzuki K Poulose static inline void csdev_access_write64(struct csdev_access *csa, u64 val, u32 offset)
4246e736c60SSuzuki K Poulose {
4256e736c60SSuzuki K Poulose 	if (likely(csa->io_mem))
4266e736c60SSuzuki K Poulose 		writeq(val, csa->base + offset);
4276e736c60SSuzuki K Poulose 	else
4286e736c60SSuzuki K Poulose 		csa->write(val, offset, false, true);
4296e736c60SSuzuki K Poulose }
4306e736c60SSuzuki K Poulose 
4316e736c60SSuzuki K Poulose #else	/* !CONFIG_64BIT */
4326e736c60SSuzuki K Poulose 
4336e736c60SSuzuki K Poulose static inline u64 csdev_access_relaxed_read64(struct csdev_access *csa,
4346e736c60SSuzuki K Poulose 					      u32 offset)
4356e736c60SSuzuki K Poulose {
4366e736c60SSuzuki K Poulose 	WARN_ON(1);
4376e736c60SSuzuki K Poulose 	return 0;
4386e736c60SSuzuki K Poulose }
4396e736c60SSuzuki K Poulose 
4406e736c60SSuzuki K Poulose static inline u64 csdev_access_read64(struct csdev_access *csa, u32 offset)
4416e736c60SSuzuki K Poulose {
4426e736c60SSuzuki K Poulose 	WARN_ON(1);
4436e736c60SSuzuki K Poulose 	return 0;
4446e736c60SSuzuki K Poulose }
4456e736c60SSuzuki K Poulose 
4466e736c60SSuzuki K Poulose static inline void csdev_access_relaxed_write64(struct csdev_access *csa,
4476e736c60SSuzuki K Poulose 						u64 val, u32 offset)
4486e736c60SSuzuki K Poulose {
4496e736c60SSuzuki K Poulose 	WARN_ON(1);
4506e736c60SSuzuki K Poulose }
4516e736c60SSuzuki K Poulose 
4526e736c60SSuzuki K Poulose static inline void csdev_access_write64(struct csdev_access *csa, u64 val, u32 offset)
4536e736c60SSuzuki K Poulose {
4546e736c60SSuzuki K Poulose 	WARN_ON(1);
4556e736c60SSuzuki K Poulose }
4566e736c60SSuzuki K Poulose #endif	/* CONFIG_64BIT */
4576e736c60SSuzuki K Poulose 
458a06ae860SPratik Patel extern struct coresight_device *
459a06ae860SPratik Patel coresight_register(struct coresight_desc *desc);
460a06ae860SPratik Patel extern void coresight_unregister(struct coresight_device *csdev);
461a06ae860SPratik Patel extern int coresight_enable(struct coresight_device *csdev);
462a06ae860SPratik Patel extern void coresight_disable(struct coresight_device *csdev);
46302005282SSuzuki K Poulose extern int coresight_timeout(struct csdev_access *csa, u32 offset,
464a06ae860SPratik Patel 			     int position, int value);
4652478a6aeSSuzuki K Poulose 
466*8ce00296SSuzuki K Poulose extern int coresight_claim_device(struct coresight_device *csdev);
467*8ce00296SSuzuki K Poulose extern int coresight_claim_device_unlocked(struct coresight_device *csdev);
4682478a6aeSSuzuki K Poulose 
469*8ce00296SSuzuki K Poulose extern void coresight_disclaim_device(struct coresight_device *csdev);
470*8ce00296SSuzuki K Poulose extern void coresight_disclaim_device_unlocked(struct coresight_device *csdev);
4710f5f9b6bSSuzuki K Poulose extern char *coresight_alloc_device_name(struct coresight_dev_list *devs,
4720f5f9b6bSSuzuki K Poulose 					 struct device *dev);
473f188b5e7SAndrew Murray 
474f188b5e7SAndrew Murray extern bool coresight_loses_context_with_cpu(struct device *dev);
4756e736c60SSuzuki K Poulose 
4766e736c60SSuzuki K Poulose u32 coresight_relaxed_read32(struct coresight_device *csdev, u32 offset);
4776e736c60SSuzuki K Poulose u32 coresight_read32(struct coresight_device *csdev, u32 offset);
4786e736c60SSuzuki K Poulose void coresight_write32(struct coresight_device *csdev, u32 val, u32 offset);
4796e736c60SSuzuki K Poulose void coresight_relaxed_write32(struct coresight_device *csdev,
4806e736c60SSuzuki K Poulose 			       u32 val, u32 offset);
4816e736c60SSuzuki K Poulose u64 coresight_relaxed_read64(struct coresight_device *csdev, u32 offset);
4826e736c60SSuzuki K Poulose u64 coresight_read64(struct coresight_device *csdev, u32 offset);
4836e736c60SSuzuki K Poulose void coresight_relaxed_write64(struct coresight_device *csdev,
4846e736c60SSuzuki K Poulose 			       u64 val, u32 offset);
4856e736c60SSuzuki K Poulose void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset);
4866e736c60SSuzuki K Poulose 
487a06ae860SPratik Patel #else
488a06ae860SPratik Patel static inline struct coresight_device *
489a06ae860SPratik Patel coresight_register(struct coresight_desc *desc) { return NULL; }
490a06ae860SPratik Patel static inline void coresight_unregister(struct coresight_device *csdev) {}
491a06ae860SPratik Patel static inline int
492a06ae860SPratik Patel coresight_enable(struct coresight_device *csdev) { return -ENOSYS; }
493a06ae860SPratik Patel static inline void coresight_disable(struct coresight_device *csdev) {}
49402005282SSuzuki K Poulose 
49502005282SSuzuki K Poulose static inline int coresight_timeout(struct csdev_access *csa, u32 offset,
49602005282SSuzuki K Poulose 				    int position, int value)
49702005282SSuzuki K Poulose {
49802005282SSuzuki K Poulose 	return 1;
49902005282SSuzuki K Poulose }
50002005282SSuzuki K Poulose 
501*8ce00296SSuzuki K Poulose static inline int coresight_claim_device_unlocked(struct coresight_device *csdev)
5022478a6aeSSuzuki K Poulose {
5032478a6aeSSuzuki K Poulose 	return -EINVAL;
5042478a6aeSSuzuki K Poulose }
5052478a6aeSSuzuki K Poulose 
506*8ce00296SSuzuki K Poulose static inline int coresight_claim_device(struct coresight_device *csdev)
5072478a6aeSSuzuki K Poulose {
5082478a6aeSSuzuki K Poulose 	return -EINVAL;
5092478a6aeSSuzuki K Poulose }
5102478a6aeSSuzuki K Poulose 
511*8ce00296SSuzuki K Poulose static inline void coresight_disclaim_device(struct coresight_device *csdev) {}
512*8ce00296SSuzuki K Poulose static inline void coresight_disclaim_device_unlocked(struct coresight_device *csdev) {}
5132478a6aeSSuzuki K Poulose 
514f188b5e7SAndrew Murray static inline bool coresight_loses_context_with_cpu(struct device *dev)
515f188b5e7SAndrew Murray {
516f188b5e7SAndrew Murray 	return false;
517f188b5e7SAndrew Murray }
5186e736c60SSuzuki K Poulose 
5196e736c60SSuzuki K Poulose static inline u32 coresight_relaxed_read32(struct coresight_device *csdev, u32 offset)
5206e736c60SSuzuki K Poulose {
5216e736c60SSuzuki K Poulose 	WARN_ON_ONCE(1);
5226e736c60SSuzuki K Poulose 	return 0;
5236e736c60SSuzuki K Poulose }
5246e736c60SSuzuki K Poulose 
5256e736c60SSuzuki K Poulose static inline u32 coresight_read32(struct coresight_device *csdev, u32 offset)
5266e736c60SSuzuki K Poulose {
5276e736c60SSuzuki K Poulose 	WARN_ON_ONCE(1);
5286e736c60SSuzuki K Poulose 	return 0;
5296e736c60SSuzuki K Poulose }
5306e736c60SSuzuki K Poulose 
5316e736c60SSuzuki K Poulose static inline void coresight_write32(struct coresight_device *csdev, u32 val, u32 offset)
5326e736c60SSuzuki K Poulose {
5336e736c60SSuzuki K Poulose }
5346e736c60SSuzuki K Poulose 
5356e736c60SSuzuki K Poulose static inline void coresight_relaxed_write32(struct coresight_device *csdev,
5366e736c60SSuzuki K Poulose 					     u32 val, u32 offset)
5376e736c60SSuzuki K Poulose {
5386e736c60SSuzuki K Poulose }
5396e736c60SSuzuki K Poulose 
5406e736c60SSuzuki K Poulose static inline u64 coresight_relaxed_read64(struct coresight_device *csdev,
5416e736c60SSuzuki K Poulose 					   u32 offset)
5426e736c60SSuzuki K Poulose {
5436e736c60SSuzuki K Poulose 	WARN_ON_ONCE(1);
5446e736c60SSuzuki K Poulose 	return 0;
5456e736c60SSuzuki K Poulose }
5466e736c60SSuzuki K Poulose 
5476e736c60SSuzuki K Poulose static inline u64 coresight_read64(struct coresight_device *csdev, u32 offset)
5486e736c60SSuzuki K Poulose {
5496e736c60SSuzuki K Poulose 	WARN_ON_ONCE(1);
5506e736c60SSuzuki K Poulose 	return 0;
5516e736c60SSuzuki K Poulose }
5526e736c60SSuzuki K Poulose 
5536e736c60SSuzuki K Poulose static inline void coresight_relaxed_write64(struct coresight_device *csdev,
5546e736c60SSuzuki K Poulose 					     u64 val, u32 offset)
5556e736c60SSuzuki K Poulose {
5566e736c60SSuzuki K Poulose }
5576e736c60SSuzuki K Poulose 
5586e736c60SSuzuki K Poulose static inline void coresight_write64(struct coresight_device *csdev, u64 val, u32 offset)
5596e736c60SSuzuki K Poulose {
5606e736c60SSuzuki K Poulose }
5616e736c60SSuzuki K Poulose 
5626e736c60SSuzuki K Poulose #endif		/* IS_ENABLED(CONFIG_CORESIGHT) */
563c61c4b5dSMathieu Poirier 
56491824db2SSuzuki K Poulose extern int coresight_get_cpu(struct device *dev);
565a06ae860SPratik Patel 
566f03631daSSuzuki K Poulose struct coresight_platform_data *coresight_get_platform_data(struct device *dev);
567f03631daSSuzuki K Poulose 
5686e736c60SSuzuki K Poulose #endif		/* _LINUX_COREISGHT_H */
569