Mathieu Poirier | ad0dfdf | 2018-05-09 12:06:04 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _LINUX_CORESIGHT_H |
| 7 | #define _LINUX_CORESIGHT_H |
| 8 | |
| 9 | #include <linux/device.h> |
Mathieu Poirier | 882d5e1 | 2016-02-17 17:51:57 -0700 | [diff] [blame] | 10 | #include <linux/perf_event.h> |
Mark Brown | ff63ec1 | 2015-07-31 09:37:30 -0600 | [diff] [blame] | 11 | #include <linux/sched.h> |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 12 | |
| 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 | |
| 35 | extern struct bus_type coresight_bustype; |
| 36 | |
| 37 | enum 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, |
| 43 | }; |
| 44 | |
| 45 | enum coresight_dev_subtype_sink { |
| 46 | CORESIGHT_DEV_SUBTYPE_SINK_NONE, |
| 47 | CORESIGHT_DEV_SUBTYPE_SINK_PORT, |
| 48 | CORESIGHT_DEV_SUBTYPE_SINK_BUFFER, |
| 49 | }; |
| 50 | |
| 51 | enum coresight_dev_subtype_link { |
| 52 | CORESIGHT_DEV_SUBTYPE_LINK_NONE, |
| 53 | CORESIGHT_DEV_SUBTYPE_LINK_MERG, |
| 54 | CORESIGHT_DEV_SUBTYPE_LINK_SPLIT, |
| 55 | CORESIGHT_DEV_SUBTYPE_LINK_FIFO, |
| 56 | }; |
| 57 | |
| 58 | enum coresight_dev_subtype_source { |
| 59 | CORESIGHT_DEV_SUBTYPE_SOURCE_NONE, |
| 60 | CORESIGHT_DEV_SUBTYPE_SOURCE_PROC, |
| 61 | CORESIGHT_DEV_SUBTYPE_SOURCE_BUS, |
| 62 | CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE, |
| 63 | }; |
| 64 | |
| 65 | /** |
Suzuki K Poulose | 00b78e8 | 2018-07-11 13:40:29 -0600 | [diff] [blame^] | 66 | * union coresight_dev_subtype - further characterisation of a type |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 67 | * @sink_subtype: type of sink this component is, as defined |
Suzuki K Poulose | 00b78e8 | 2018-07-11 13:40:29 -0600 | [diff] [blame^] | 68 | * by @coresight_dev_subtype_sink. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 69 | * @link_subtype: type of link this component is, as defined |
Suzuki K Poulose | 00b78e8 | 2018-07-11 13:40:29 -0600 | [diff] [blame^] | 70 | * by @coresight_dev_subtype_link. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 71 | * @source_subtype: type of source this component is, as defined |
Suzuki K Poulose | 00b78e8 | 2018-07-11 13:40:29 -0600 | [diff] [blame^] | 72 | * by @coresight_dev_subtype_source. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 73 | */ |
Suzuki K Poulose | 00b78e8 | 2018-07-11 13:40:29 -0600 | [diff] [blame^] | 74 | union coresight_dev_subtype { |
| 75 | /* We have some devices which acts as LINK and SINK */ |
| 76 | struct { |
| 77 | enum coresight_dev_subtype_sink sink_subtype; |
| 78 | enum coresight_dev_subtype_link link_subtype; |
| 79 | }; |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 80 | enum coresight_dev_subtype_source source_subtype; |
| 81 | }; |
| 82 | |
| 83 | /** |
| 84 | * struct coresight_platform_data - data harvested from the DT specification |
| 85 | * @cpu: the CPU a source belongs to. Only applicable for ETM/PTMs. |
| 86 | * @name: name of the component as shown under sysfs. |
| 87 | * @nr_inport: number of input ports for this component. |
Pankaj Dubey | 8ee885a | 2014-11-13 14:12:48 +0530 | [diff] [blame] | 88 | * @outports: list of remote endpoint port number. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 89 | * @child_names:name of all child components connected to this device. |
| 90 | * @child_ports:child component port number the current component is |
| 91 | connected to. |
| 92 | * @nr_outport: number of output ports for this component. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 93 | */ |
| 94 | struct coresight_platform_data { |
| 95 | int cpu; |
| 96 | const char *name; |
| 97 | int nr_inport; |
| 98 | int *outports; |
| 99 | const char **child_names; |
| 100 | int *child_ports; |
| 101 | int nr_outport; |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * struct coresight_desc - description of a component required from drivers |
| 106 | * @type: as defined by @coresight_dev_type. |
| 107 | * @subtype: as defined by @coresight_dev_subtype. |
| 108 | * @ops: generic operations for this component, as defined |
| 109 | by @coresight_ops. |
| 110 | * @pdata: platform data collected from DT. |
| 111 | * @dev: The device entity associated to this component. |
Pankaj Dubey | 8ee885a | 2014-11-13 14:12:48 +0530 | [diff] [blame] | 112 | * @groups: operations specific to this component. These will end up |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 113 | in the component's sysfs sub-directory. |
| 114 | */ |
| 115 | struct coresight_desc { |
| 116 | enum coresight_dev_type type; |
Suzuki K Poulose | 00b78e8 | 2018-07-11 13:40:29 -0600 | [diff] [blame^] | 117 | union coresight_dev_subtype subtype; |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 118 | const struct coresight_ops *ops; |
| 119 | struct coresight_platform_data *pdata; |
| 120 | struct device *dev; |
| 121 | const struct attribute_group **groups; |
| 122 | }; |
| 123 | |
| 124 | /** |
| 125 | * struct coresight_connection - representation of a single connection |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 126 | * @outport: a connection's output port number. |
| 127 | * @chid_name: remote component's name. |
| 128 | * @child_port: remote component's port number @output is connected to. |
| 129 | * @child_dev: a @coresight_device representation of the component |
| 130 | connected to @outport. |
| 131 | */ |
| 132 | struct coresight_connection { |
| 133 | int outport; |
| 134 | const char *child_name; |
| 135 | int child_port; |
| 136 | struct coresight_device *child_dev; |
| 137 | }; |
| 138 | |
| 139 | /** |
| 140 | * struct coresight_device - representation of a device as used by the framework |
Pankaj Dubey | 8ee885a | 2014-11-13 14:12:48 +0530 | [diff] [blame] | 141 | * @conns: array of coresight_connections associated to this component. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 142 | * @nr_inport: number of input port associated to this component. |
| 143 | * @nr_outport: number of output port associated to this component. |
| 144 | * @type: as defined by @coresight_dev_type. |
| 145 | * @subtype: as defined by @coresight_dev_subtype. |
| 146 | * @ops: generic operations for this component, as defined |
| 147 | by @coresight_ops. |
| 148 | * @dev: The device entity associated to this component. |
| 149 | * @refcnt: keep track of what is in use. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 150 | * @orphan: true if the component has connections that haven't been linked. |
| 151 | * @enable: 'true' if component is currently part of an active path. |
| 152 | * @activated: 'true' only if a _sink_ has been activated. A sink can be |
| 153 | activated but not yet enabled. Enabling for a _sink_ |
| 154 | happens when a source has been selected for that it. |
| 155 | */ |
| 156 | struct coresight_device { |
| 157 | struct coresight_connection *conns; |
| 158 | int nr_inport; |
| 159 | int nr_outport; |
| 160 | enum coresight_dev_type type; |
Suzuki K Poulose | 00b78e8 | 2018-07-11 13:40:29 -0600 | [diff] [blame^] | 161 | union coresight_dev_subtype subtype; |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 162 | const struct coresight_ops *ops; |
| 163 | struct device dev; |
| 164 | atomic_t *refcnt; |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 165 | bool orphan; |
| 166 | bool enable; /* true only if configured as part of a path */ |
| 167 | bool activated; /* true only if a sink is part of a path */ |
| 168 | }; |
| 169 | |
| 170 | #define to_coresight_device(d) container_of(d, struct coresight_device, dev) |
| 171 | |
| 172 | #define source_ops(csdev) csdev->ops->source_ops |
| 173 | #define sink_ops(csdev) csdev->ops->sink_ops |
| 174 | #define link_ops(csdev) csdev->ops->link_ops |
| 175 | |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 176 | /** |
| 177 | * struct coresight_ops_sink - basic operations for a sink |
| 178 | * Operations available for sinks |
Mathieu Poirier | 2997aa4 | 2016-02-17 17:52:00 -0700 | [diff] [blame] | 179 | * @enable: enables the sink. |
| 180 | * @disable: disables the sink. |
| 181 | * @alloc_buffer: initialises perf's ring buffer for trace collection. |
| 182 | * @free_buffer: release memory allocated in @get_config. |
| 183 | * @set_buffer: initialises buffer mechanic before a trace session. |
| 184 | * @reset_buffer: finalises buffer mechanic after a trace session. |
| 185 | * @update_buffer: update buffer pointers after a trace session. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 186 | */ |
| 187 | struct coresight_ops_sink { |
Mathieu Poirier | e827d45 | 2016-02-17 17:51:59 -0700 | [diff] [blame] | 188 | int (*enable)(struct coresight_device *csdev, u32 mode); |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 189 | void (*disable)(struct coresight_device *csdev); |
Mathieu Poirier | 2997aa4 | 2016-02-17 17:52:00 -0700 | [diff] [blame] | 190 | void *(*alloc_buffer)(struct coresight_device *csdev, int cpu, |
| 191 | void **pages, int nr_pages, bool overwrite); |
| 192 | void (*free_buffer)(void *config); |
| 193 | int (*set_buffer)(struct coresight_device *csdev, |
| 194 | struct perf_output_handle *handle, |
| 195 | void *sink_config); |
| 196 | unsigned long (*reset_buffer)(struct coresight_device *csdev, |
| 197 | struct perf_output_handle *handle, |
Will Deacon | f4c0b0a | 2017-02-20 15:33:50 +0200 | [diff] [blame] | 198 | void *sink_config); |
Mathieu Poirier | 2997aa4 | 2016-02-17 17:52:00 -0700 | [diff] [blame] | 199 | void (*update_buffer)(struct coresight_device *csdev, |
| 200 | struct perf_output_handle *handle, |
| 201 | void *sink_config); |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | /** |
| 205 | * struct coresight_ops_link - basic operations for a link |
| 206 | * Operations available for links. |
| 207 | * @enable: enables flow between iport and oport. |
| 208 | * @disable: disables flow between iport and oport. |
| 209 | */ |
| 210 | struct coresight_ops_link { |
| 211 | int (*enable)(struct coresight_device *csdev, int iport, int oport); |
| 212 | void (*disable)(struct coresight_device *csdev, int iport, int oport); |
| 213 | }; |
| 214 | |
| 215 | /** |
| 216 | * struct coresight_ops_source - basic operations for a source |
| 217 | * Operations available for sources. |
Mathieu Poirier | 52210c8 | 2016-02-02 14:14:01 -0700 | [diff] [blame] | 218 | * @cpu_id: returns the value of the CPU number this component |
| 219 | * is associated to. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 220 | * @trace_id: returns the value of the component's trace ID as known |
Mathieu Poirier | 882d5e1 | 2016-02-17 17:51:57 -0700 | [diff] [blame] | 221 | * to the HW. |
Mathieu Poirier | 1d27ff5 | 2015-10-07 09:26:39 -0600 | [diff] [blame] | 222 | * @enable: enables tracing for a source. |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 223 | * @disable: disables tracing for a source. |
| 224 | */ |
| 225 | struct coresight_ops_source { |
Mathieu Poirier | 52210c8 | 2016-02-02 14:14:01 -0700 | [diff] [blame] | 226 | int (*cpu_id)(struct coresight_device *csdev); |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 227 | int (*trace_id)(struct coresight_device *csdev); |
Mathieu Poirier | 882d5e1 | 2016-02-17 17:51:57 -0700 | [diff] [blame] | 228 | int (*enable)(struct coresight_device *csdev, |
Mathieu Poirier | 68905d7 | 2016-08-25 15:19:10 -0600 | [diff] [blame] | 229 | struct perf_event *event, u32 mode); |
| 230 | void (*disable)(struct coresight_device *csdev, |
| 231 | struct perf_event *event); |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | struct coresight_ops { |
| 235 | const struct coresight_ops_sink *sink_ops; |
| 236 | const struct coresight_ops_link *link_ops; |
| 237 | const struct coresight_ops_source *source_ops; |
| 238 | }; |
| 239 | |
| 240 | #ifdef CONFIG_CORESIGHT |
| 241 | extern struct coresight_device * |
| 242 | coresight_register(struct coresight_desc *desc); |
| 243 | extern void coresight_unregister(struct coresight_device *csdev); |
| 244 | extern int coresight_enable(struct coresight_device *csdev); |
| 245 | extern void coresight_disable(struct coresight_device *csdev); |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 246 | extern int coresight_timeout(void __iomem *addr, u32 offset, |
| 247 | int position, int value); |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 248 | #else |
| 249 | static inline struct coresight_device * |
| 250 | coresight_register(struct coresight_desc *desc) { return NULL; } |
| 251 | static inline void coresight_unregister(struct coresight_device *csdev) {} |
| 252 | static inline int |
| 253 | coresight_enable(struct coresight_device *csdev) { return -ENOSYS; } |
| 254 | static inline void coresight_disable(struct coresight_device *csdev) {} |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 255 | static inline int coresight_timeout(void __iomem *addr, u32 offset, |
| 256 | int position, int value) { return 1; } |
Mathieu Poirier | c61c4b5 | 2015-01-09 16:57:20 -0700 | [diff] [blame] | 257 | #endif |
| 258 | |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 259 | #ifdef CONFIG_OF |
Leo Yan | c56cdd7 | 2017-06-05 14:15:15 -0600 | [diff] [blame] | 260 | extern int of_coresight_get_cpu(const struct device_node *node); |
Leo Yan | f42fe52 | 2017-06-05 14:15:06 -0600 | [diff] [blame] | 261 | extern struct coresight_platform_data * |
| 262 | of_get_coresight_platform_data(struct device *dev, |
| 263 | const struct device_node *node); |
Mathieu Poirier | c61c4b5 | 2015-01-09 16:57:20 -0700 | [diff] [blame] | 264 | #else |
Leo Yan | c56cdd7 | 2017-06-05 14:15:15 -0600 | [diff] [blame] | 265 | static inline int of_coresight_get_cpu(const struct device_node *node) |
| 266 | { return 0; } |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 267 | static inline struct coresight_platform_data *of_get_coresight_platform_data( |
Leo Yan | f42fe52 | 2017-06-05 14:15:06 -0600 | [diff] [blame] | 268 | struct device *dev, const struct device_node *node) { return NULL; } |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 269 | #endif |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 270 | |
Pratik Patel | a06ae86 | 2014-11-03 11:07:35 -0700 | [diff] [blame] | 271 | #endif |