blob: 3d40a2b135f16297927fbfc3ba007975f90f57b2 [file] [log] [blame]
Mathieu Poirierad0dfdf2018-05-09 12:06:04 -06001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Pratik Patela06ae862014-11-03 11:07:35 -07004 */
5
6#ifndef _LINUX_CORESIGHT_H
7#define _LINUX_CORESIGHT_H
8
9#include <linux/device.h>
Mathieu Poirier882d5e12016-02-17 17:51:57 -070010#include <linux/perf_event.h>
Mark Brownff63ec12015-07-31 09:37:30 -060011#include <linux/sched.h>
Pratik Patela06ae862014-11-03 11:07:35 -070012
13/* Peripheral id registers (0xFD0-0xFEC) */
14#define CORESIGHT_PERIPHIDR4 0xfd0
15#define CORESIGHT_PERIPHIDR5 0xfd4
16#define CORESIGHT_PERIPHIDR6 0xfd8
17#define CORESIGHT_PERIPHIDR7 0xfdC
18#define CORESIGHT_PERIPHIDR0 0xfe0
19#define CORESIGHT_PERIPHIDR1 0xfe4
20#define CORESIGHT_PERIPHIDR2 0xfe8
21#define CORESIGHT_PERIPHIDR3 0xfeC
22/* Component id registers (0xFF0-0xFFC) */
23#define CORESIGHT_COMPIDR0 0xff0
24#define CORESIGHT_COMPIDR1 0xff4
25#define CORESIGHT_COMPIDR2 0xff8
26#define CORESIGHT_COMPIDR3 0xffC
27
28#define ETM_ARCH_V3_3 0x23
29#define ETM_ARCH_V3_5 0x25
30#define PFT_ARCH_V1_0 0x30
31#define PFT_ARCH_V1_1 0x31
32
33#define CORESIGHT_UNLOCK 0xc5acce55
34
35extern struct bus_type coresight_bustype;
36
37enum coresight_dev_type {
38 CORESIGHT_DEV_TYPE_NONE,
39 CORESIGHT_DEV_TYPE_SINK,
40 CORESIGHT_DEV_TYPE_LINK,
41 CORESIGHT_DEV_TYPE_LINKSINK,
42 CORESIGHT_DEV_TYPE_SOURCE,
Suzuki K Poulose8a091d82018-07-11 13:40:30 -060043 CORESIGHT_DEV_TYPE_HELPER,
Pratik Patela06ae862014-11-03 11:07:35 -070044};
45
46enum coresight_dev_subtype_sink {
47 CORESIGHT_DEV_SUBTYPE_SINK_NONE,
48 CORESIGHT_DEV_SUBTYPE_SINK_PORT,
49 CORESIGHT_DEV_SUBTYPE_SINK_BUFFER,
50};
51
52enum coresight_dev_subtype_link {
53 CORESIGHT_DEV_SUBTYPE_LINK_NONE,
54 CORESIGHT_DEV_SUBTYPE_LINK_MERG,
55 CORESIGHT_DEV_SUBTYPE_LINK_SPLIT,
56 CORESIGHT_DEV_SUBTYPE_LINK_FIFO,
57};
58
59enum coresight_dev_subtype_source {
60 CORESIGHT_DEV_SUBTYPE_SOURCE_NONE,
61 CORESIGHT_DEV_SUBTYPE_SOURCE_PROC,
62 CORESIGHT_DEV_SUBTYPE_SOURCE_BUS,
63 CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE,
64};
65
Suzuki K Poulose8a091d82018-07-11 13:40:30 -060066enum coresight_dev_subtype_helper {
67 CORESIGHT_DEV_SUBTYPE_HELPER_NONE,
68};
69
Pratik Patela06ae862014-11-03 11:07:35 -070070/**
Suzuki K Poulose00b78e82018-07-11 13:40:29 -060071 * union coresight_dev_subtype - further characterisation of a type
Pratik Patela06ae862014-11-03 11:07:35 -070072 * @sink_subtype: type of sink this component is, as defined
Suzuki K Poulose00b78e82018-07-11 13:40:29 -060073 * by @coresight_dev_subtype_sink.
Pratik Patela06ae862014-11-03 11:07:35 -070074 * @link_subtype: type of link this component is, as defined
Suzuki K Poulose00b78e82018-07-11 13:40:29 -060075 * by @coresight_dev_subtype_link.
Pratik Patela06ae862014-11-03 11:07:35 -070076 * @source_subtype: type of source this component is, as defined
Suzuki K Poulose00b78e82018-07-11 13:40:29 -060077 * by @coresight_dev_subtype_source.
Suzuki K Poulose8a091d82018-07-11 13:40:30 -060078 * @helper_subtype: type of helper this component is, as defined
79 * by @coresight_dev_subtype_helper.
Pratik Patela06ae862014-11-03 11:07:35 -070080 */
Suzuki K Poulose00b78e82018-07-11 13:40:29 -060081union coresight_dev_subtype {
82 /* We have some devices which acts as LINK and SINK */
83 struct {
84 enum coresight_dev_subtype_sink sink_subtype;
85 enum coresight_dev_subtype_link link_subtype;
86 };
Pratik Patela06ae862014-11-03 11:07:35 -070087 enum coresight_dev_subtype_source source_subtype;
Suzuki K Poulose8a091d82018-07-11 13:40:30 -060088 enum coresight_dev_subtype_helper helper_subtype;
Pratik Patela06ae862014-11-03 11:07:35 -070089};
90
91/**
92 * struct coresight_platform_data - data harvested from the DT specification
93 * @cpu: the CPU a source belongs to. Only applicable for ETM/PTMs.
94 * @name: name of the component as shown under sysfs.
95 * @nr_inport: number of input ports for this component.
Pankaj Dubey8ee885a2014-11-13 14:12:48 +053096 * @outports: list of remote endpoint port number.
Pratik Patela06ae862014-11-03 11:07:35 -070097 * @child_names:name of all child components connected to this device.
98 * @child_ports:child component port number the current component is
99 connected to.
100 * @nr_outport: number of output ports for this component.
Pratik Patela06ae862014-11-03 11:07:35 -0700101 */
102struct coresight_platform_data {
103 int cpu;
104 const char *name;
105 int nr_inport;
106 int *outports;
107 const char **child_names;
108 int *child_ports;
109 int nr_outport;
Pratik Patela06ae862014-11-03 11:07:35 -0700110};
111
112/**
113 * struct coresight_desc - description of a component required from drivers
114 * @type: as defined by @coresight_dev_type.
115 * @subtype: as defined by @coresight_dev_subtype.
116 * @ops: generic operations for this component, as defined
117 by @coresight_ops.
118 * @pdata: platform data collected from DT.
119 * @dev: The device entity associated to this component.
Pankaj Dubey8ee885a2014-11-13 14:12:48 +0530120 * @groups: operations specific to this component. These will end up
Pratik Patela06ae862014-11-03 11:07:35 -0700121 in the component's sysfs sub-directory.
122 */
123struct coresight_desc {
124 enum coresight_dev_type type;
Suzuki K Poulose00b78e82018-07-11 13:40:29 -0600125 union coresight_dev_subtype subtype;
Pratik Patela06ae862014-11-03 11:07:35 -0700126 const struct coresight_ops *ops;
127 struct coresight_platform_data *pdata;
128 struct device *dev;
129 const struct attribute_group **groups;
130};
131
132/**
133 * struct coresight_connection - representation of a single connection
Pratik Patela06ae862014-11-03 11:07:35 -0700134 * @outport: a connection's output port number.
135 * @chid_name: remote component's name.
136 * @child_port: remote component's port number @output is connected to.
137 * @child_dev: a @coresight_device representation of the component
138 connected to @outport.
139 */
140struct coresight_connection {
141 int outport;
142 const char *child_name;
143 int child_port;
144 struct coresight_device *child_dev;
145};
146
147/**
148 * struct coresight_device - representation of a device as used by the framework
Pankaj Dubey8ee885a2014-11-13 14:12:48 +0530149 * @conns: array of coresight_connections associated to this component.
Pratik Patela06ae862014-11-03 11:07:35 -0700150 * @nr_inport: number of input port associated to this component.
151 * @nr_outport: number of output port associated to this component.
152 * @type: as defined by @coresight_dev_type.
153 * @subtype: as defined by @coresight_dev_subtype.
154 * @ops: generic operations for this component, as defined
155 by @coresight_ops.
156 * @dev: The device entity associated to this component.
157 * @refcnt: keep track of what is in use.
Pratik Patela06ae862014-11-03 11:07:35 -0700158 * @orphan: true if the component has connections that haven't been linked.
159 * @enable: 'true' if component is currently part of an active path.
160 * @activated: 'true' only if a _sink_ has been activated. A sink can be
161 activated but not yet enabled. Enabling for a _sink_
162 happens when a source has been selected for that it.
163 */
164struct coresight_device {
165 struct coresight_connection *conns;
166 int nr_inport;
167 int nr_outport;
168 enum coresight_dev_type type;
Suzuki K Poulose00b78e82018-07-11 13:40:29 -0600169 union coresight_dev_subtype subtype;
Pratik Patela06ae862014-11-03 11:07:35 -0700170 const struct coresight_ops *ops;
171 struct device dev;
172 atomic_t *refcnt;
Pratik Patela06ae862014-11-03 11:07:35 -0700173 bool orphan;
174 bool enable; /* true only if configured as part of a path */
175 bool activated; /* true only if a sink is part of a path */
176};
177
178#define to_coresight_device(d) container_of(d, struct coresight_device, dev)
179
180#define source_ops(csdev) csdev->ops->source_ops
181#define sink_ops(csdev) csdev->ops->sink_ops
182#define link_ops(csdev) csdev->ops->link_ops
Suzuki K Poulose8a091d82018-07-11 13:40:30 -0600183#define helper_ops(csdev) csdev->ops->helper_ops
Pratik Patela06ae862014-11-03 11:07:35 -0700184
Pratik Patela06ae862014-11-03 11:07:35 -0700185/**
186 * struct coresight_ops_sink - basic operations for a sink
187 * Operations available for sinks
Mathieu Poirier2997aa42016-02-17 17:52:00 -0700188 * @enable: enables the sink.
189 * @disable: disables the sink.
190 * @alloc_buffer: initialises perf's ring buffer for trace collection.
191 * @free_buffer: release memory allocated in @get_config.
192 * @set_buffer: initialises buffer mechanic before a trace session.
193 * @reset_buffer: finalises buffer mechanic after a trace session.
194 * @update_buffer: update buffer pointers after a trace session.
Pratik Patela06ae862014-11-03 11:07:35 -0700195 */
196struct coresight_ops_sink {
Mathieu Poiriere827d452016-02-17 17:51:59 -0700197 int (*enable)(struct coresight_device *csdev, u32 mode);
Pratik Patela06ae862014-11-03 11:07:35 -0700198 void (*disable)(struct coresight_device *csdev);
Mathieu Poirier2997aa42016-02-17 17:52:00 -0700199 void *(*alloc_buffer)(struct coresight_device *csdev, int cpu,
200 void **pages, int nr_pages, bool overwrite);
201 void (*free_buffer)(void *config);
202 int (*set_buffer)(struct coresight_device *csdev,
203 struct perf_output_handle *handle,
204 void *sink_config);
205 unsigned long (*reset_buffer)(struct coresight_device *csdev,
206 struct perf_output_handle *handle,
Will Deaconf4c0b0a2017-02-20 15:33:50 +0200207 void *sink_config);
Mathieu Poirier2997aa42016-02-17 17:52:00 -0700208 void (*update_buffer)(struct coresight_device *csdev,
209 struct perf_output_handle *handle,
210 void *sink_config);
Pratik Patela06ae862014-11-03 11:07:35 -0700211};
212
213/**
214 * struct coresight_ops_link - basic operations for a link
215 * Operations available for links.
216 * @enable: enables flow between iport and oport.
217 * @disable: disables flow between iport and oport.
218 */
219struct coresight_ops_link {
220 int (*enable)(struct coresight_device *csdev, int iport, int oport);
221 void (*disable)(struct coresight_device *csdev, int iport, int oport);
222};
223
224/**
225 * struct coresight_ops_source - basic operations for a source
226 * Operations available for sources.
Mathieu Poirier52210c82016-02-02 14:14:01 -0700227 * @cpu_id: returns the value of the CPU number this component
228 * is associated to.
Pratik Patela06ae862014-11-03 11:07:35 -0700229 * @trace_id: returns the value of the component's trace ID as known
Mathieu Poirier882d5e12016-02-17 17:51:57 -0700230 * to the HW.
Mathieu Poirier1d27ff52015-10-07 09:26:39 -0600231 * @enable: enables tracing for a source.
Pratik Patela06ae862014-11-03 11:07:35 -0700232 * @disable: disables tracing for a source.
233 */
234struct coresight_ops_source {
Mathieu Poirier52210c82016-02-02 14:14:01 -0700235 int (*cpu_id)(struct coresight_device *csdev);
Pratik Patela06ae862014-11-03 11:07:35 -0700236 int (*trace_id)(struct coresight_device *csdev);
Mathieu Poirier882d5e12016-02-17 17:51:57 -0700237 int (*enable)(struct coresight_device *csdev,
Mathieu Poirier68905d72016-08-25 15:19:10 -0600238 struct perf_event *event, u32 mode);
239 void (*disable)(struct coresight_device *csdev,
240 struct perf_event *event);
Pratik Patela06ae862014-11-03 11:07:35 -0700241};
242
Suzuki K Poulose8a091d82018-07-11 13:40:30 -0600243/**
244 * struct coresight_ops_helper - Operations for a helper device.
245 *
246 * All operations could pass in a device specific data, which could
247 * help the helper device to determine what to do.
248 *
249 * @enable : Enable the device
250 * @disable : Disable the device
251 */
252struct coresight_ops_helper {
253 int (*enable)(struct coresight_device *csdev, void *data);
254 int (*disable)(struct coresight_device *csdev, void *data);
255};
256
Pratik Patela06ae862014-11-03 11:07:35 -0700257struct coresight_ops {
258 const struct coresight_ops_sink *sink_ops;
259 const struct coresight_ops_link *link_ops;
260 const struct coresight_ops_source *source_ops;
Suzuki K Poulose8a091d82018-07-11 13:40:30 -0600261 const struct coresight_ops_helper *helper_ops;
Pratik Patela06ae862014-11-03 11:07:35 -0700262};
263
264#ifdef CONFIG_CORESIGHT
265extern struct coresight_device *
266coresight_register(struct coresight_desc *desc);
267extern void coresight_unregister(struct coresight_device *csdev);
268extern int coresight_enable(struct coresight_device *csdev);
269extern void coresight_disable(struct coresight_device *csdev);
Pratik Patela06ae862014-11-03 11:07:35 -0700270extern int coresight_timeout(void __iomem *addr, u32 offset,
271 int position, int value);
Pratik Patela06ae862014-11-03 11:07:35 -0700272#else
273static inline struct coresight_device *
274coresight_register(struct coresight_desc *desc) { return NULL; }
275static inline void coresight_unregister(struct coresight_device *csdev) {}
276static inline int
277coresight_enable(struct coresight_device *csdev) { return -ENOSYS; }
278static inline void coresight_disable(struct coresight_device *csdev) {}
Pratik Patela06ae862014-11-03 11:07:35 -0700279static inline int coresight_timeout(void __iomem *addr, u32 offset,
280 int position, int value) { return 1; }
Mathieu Poirierc61c4b52015-01-09 16:57:20 -0700281#endif
282
Pratik Patela06ae862014-11-03 11:07:35 -0700283#ifdef CONFIG_OF
Leo Yanc56cdd72017-06-05 14:15:15 -0600284extern int of_coresight_get_cpu(const struct device_node *node);
Leo Yanf42fe522017-06-05 14:15:06 -0600285extern struct coresight_platform_data *
286of_get_coresight_platform_data(struct device *dev,
287 const struct device_node *node);
Mathieu Poirierc61c4b52015-01-09 16:57:20 -0700288#else
Leo Yanc56cdd72017-06-05 14:15:15 -0600289static inline int of_coresight_get_cpu(const struct device_node *node)
290{ return 0; }
Pratik Patela06ae862014-11-03 11:07:35 -0700291static inline struct coresight_platform_data *of_get_coresight_platform_data(
Leo Yanf42fe522017-06-05 14:15:06 -0600292 struct device *dev, const struct device_node *node) { return NULL; }
Pratik Patela06ae862014-11-03 11:07:35 -0700293#endif
Pratik Patela06ae862014-11-03 11:07:35 -0700294
Pratik Patela06ae862014-11-03 11:07:35 -0700295#endif