coresight.h 9.9 KB

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