coresight.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. };
  37. enum coresight_dev_subtype_sink {
  38. CORESIGHT_DEV_SUBTYPE_SINK_NONE,
  39. CORESIGHT_DEV_SUBTYPE_SINK_PORT,
  40. CORESIGHT_DEV_SUBTYPE_SINK_BUFFER,
  41. };
  42. enum coresight_dev_subtype_link {
  43. CORESIGHT_DEV_SUBTYPE_LINK_NONE,
  44. CORESIGHT_DEV_SUBTYPE_LINK_MERG,
  45. CORESIGHT_DEV_SUBTYPE_LINK_SPLIT,
  46. CORESIGHT_DEV_SUBTYPE_LINK_FIFO,
  47. };
  48. enum coresight_dev_subtype_source {
  49. CORESIGHT_DEV_SUBTYPE_SOURCE_NONE,
  50. CORESIGHT_DEV_SUBTYPE_SOURCE_PROC,
  51. CORESIGHT_DEV_SUBTYPE_SOURCE_BUS,
  52. CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE,
  53. };
  54. /**
  55. * struct coresight_dev_subtype - further characterisation of a type
  56. * @sink_subtype: type of sink this component is, as defined
  57. by @coresight_dev_subtype_sink.
  58. * @link_subtype: type of link this component is, as defined
  59. by @coresight_dev_subtype_link.
  60. * @source_subtype: type of source this component is, as defined
  61. by @coresight_dev_subtype_source.
  62. */
  63. struct coresight_dev_subtype {
  64. enum coresight_dev_subtype_sink sink_subtype;
  65. enum coresight_dev_subtype_link link_subtype;
  66. enum coresight_dev_subtype_source source_subtype;
  67. };
  68. /**
  69. * struct coresight_platform_data - data harvested from the DT specification
  70. * @cpu: the CPU a source belongs to. Only applicable for ETM/PTMs.
  71. * @name: name of the component as shown under sysfs.
  72. * @nr_inport: number of input ports for this component.
  73. * @outports: list of remote endpoint port number.
  74. * @child_names:name of all child components connected to this device.
  75. * @child_ports:child component port number the current component is
  76. connected to.
  77. * @nr_outport: number of output ports for this component.
  78. * @clk: The clock this component is associated to.
  79. */
  80. struct coresight_platform_data {
  81. int cpu;
  82. const char *name;
  83. int nr_inport;
  84. int *outports;
  85. const char **child_names;
  86. int *child_ports;
  87. int nr_outport;
  88. struct clk *clk;
  89. };
  90. /**
  91. * struct coresight_desc - description of a component required from drivers
  92. * @type: as defined by @coresight_dev_type.
  93. * @subtype: as defined by @coresight_dev_subtype.
  94. * @ops: generic operations for this component, as defined
  95. by @coresight_ops.
  96. * @pdata: platform data collected from DT.
  97. * @dev: The device entity associated to this component.
  98. * @groups: operations specific to this component. These will end up
  99. in the component's sysfs sub-directory.
  100. */
  101. struct coresight_desc {
  102. enum coresight_dev_type type;
  103. struct coresight_dev_subtype subtype;
  104. const struct coresight_ops *ops;
  105. struct coresight_platform_data *pdata;
  106. struct device *dev;
  107. const struct attribute_group **groups;
  108. };
  109. /**
  110. * struct coresight_connection - representation of a single connection
  111. * @outport: a connection's output port number.
  112. * @chid_name: remote component's name.
  113. * @child_port: remote component's port number @output is connected to.
  114. * @child_dev: a @coresight_device representation of the component
  115. connected to @outport.
  116. */
  117. struct coresight_connection {
  118. int outport;
  119. const char *child_name;
  120. int child_port;
  121. struct coresight_device *child_dev;
  122. };
  123. /**
  124. * struct coresight_device - representation of a device as used by the framework
  125. * @conns: array of coresight_connections associated to this component.
  126. * @nr_inport: number of input port associated to this component.
  127. * @nr_outport: number of output port associated to this component.
  128. * @type: as defined by @coresight_dev_type.
  129. * @subtype: as defined by @coresight_dev_subtype.
  130. * @ops: generic operations for this component, as defined
  131. by @coresight_ops.
  132. * @dev: The device entity associated to this component.
  133. * @refcnt: keep track of what is in use.
  134. * @orphan: true if the component has connections that haven't been linked.
  135. * @enable: 'true' if component is currently part of an active path.
  136. * @activated: 'true' only if a _sink_ has been activated. A sink can be
  137. activated but not yet enabled. Enabling for a _sink_
  138. happens when a source has been selected for that it.
  139. */
  140. struct coresight_device {
  141. struct coresight_connection *conns;
  142. int nr_inport;
  143. int nr_outport;
  144. enum coresight_dev_type type;
  145. struct coresight_dev_subtype subtype;
  146. const struct coresight_ops *ops;
  147. struct device dev;
  148. atomic_t *refcnt;
  149. bool orphan;
  150. bool enable; /* true only if configured as part of a path */
  151. bool activated; /* true only if a sink is part of a path */
  152. };
  153. #define to_coresight_device(d) container_of(d, struct coresight_device, dev)
  154. #define source_ops(csdev) csdev->ops->source_ops
  155. #define sink_ops(csdev) csdev->ops->sink_ops
  156. #define link_ops(csdev) csdev->ops->link_ops
  157. /**
  158. * struct coresight_ops_sink - basic operations for a sink
  159. * Operations available for sinks
  160. * @enable: enables the sink.
  161. * @disable: disables the sink.
  162. * @alloc_buffer: initialises perf's ring buffer for trace collection.
  163. * @free_buffer: release memory allocated in @get_config.
  164. * @set_buffer: initialises buffer mechanic before a trace session.
  165. * @reset_buffer: finalises buffer mechanic after a trace session.
  166. * @update_buffer: update buffer pointers after a trace session.
  167. */
  168. struct coresight_ops_sink {
  169. int (*enable)(struct coresight_device *csdev, u32 mode);
  170. void (*disable)(struct coresight_device *csdev);
  171. void *(*alloc_buffer)(struct coresight_device *csdev, int cpu,
  172. void **pages, int nr_pages, bool overwrite);
  173. void (*free_buffer)(void *config);
  174. int (*set_buffer)(struct coresight_device *csdev,
  175. struct perf_output_handle *handle,
  176. void *sink_config);
  177. unsigned long (*reset_buffer)(struct coresight_device *csdev,
  178. struct perf_output_handle *handle,
  179. void *sink_config);
  180. void (*update_buffer)(struct coresight_device *csdev,
  181. struct perf_output_handle *handle,
  182. void *sink_config);
  183. };
  184. /**
  185. * struct coresight_ops_link - basic operations for a link
  186. * Operations available for links.
  187. * @enable: enables flow between iport and oport.
  188. * @disable: disables flow between iport and oport.
  189. */
  190. struct coresight_ops_link {
  191. int (*enable)(struct coresight_device *csdev, int iport, int oport);
  192. void (*disable)(struct coresight_device *csdev, int iport, int oport);
  193. };
  194. /**
  195. * struct coresight_ops_source - basic operations for a source
  196. * Operations available for sources.
  197. * @cpu_id: returns the value of the CPU number this component
  198. * is associated to.
  199. * @trace_id: returns the value of the component's trace ID as known
  200. * to the HW.
  201. * @enable: enables tracing for a source.
  202. * @disable: disables tracing for a source.
  203. */
  204. struct coresight_ops_source {
  205. int (*cpu_id)(struct coresight_device *csdev);
  206. int (*trace_id)(struct coresight_device *csdev);
  207. int (*enable)(struct coresight_device *csdev,
  208. struct perf_event *event, u32 mode);
  209. void (*disable)(struct coresight_device *csdev,
  210. struct perf_event *event);
  211. };
  212. struct coresight_ops {
  213. const struct coresight_ops_sink *sink_ops;
  214. const struct coresight_ops_link *link_ops;
  215. const struct coresight_ops_source *source_ops;
  216. };
  217. #ifdef CONFIG_CORESIGHT
  218. extern struct coresight_device *
  219. coresight_register(struct coresight_desc *desc);
  220. extern void coresight_unregister(struct coresight_device *csdev);
  221. extern int coresight_enable(struct coresight_device *csdev);
  222. extern void coresight_disable(struct coresight_device *csdev);
  223. extern int coresight_timeout(void __iomem *addr, u32 offset,
  224. int position, int value);
  225. #else
  226. static inline struct coresight_device *
  227. coresight_register(struct coresight_desc *desc) { return NULL; }
  228. static inline void coresight_unregister(struct coresight_device *csdev) {}
  229. static inline int
  230. coresight_enable(struct coresight_device *csdev) { return -ENOSYS; }
  231. static inline void coresight_disable(struct coresight_device *csdev) {}
  232. static inline int coresight_timeout(void __iomem *addr, u32 offset,
  233. int position, int value) { return 1; }
  234. #endif
  235. #ifdef CONFIG_OF
  236. extern int of_coresight_get_cpu(const struct device_node *node);
  237. extern struct coresight_platform_data *
  238. of_get_coresight_platform_data(struct device *dev,
  239. const struct device_node *node);
  240. #else
  241. static inline int of_coresight_get_cpu(const struct device_node *node)
  242. { return 0; }
  243. static inline struct coresight_platform_data *of_get_coresight_platform_data(
  244. struct device *dev, const struct device_node *node) { return NULL; }
  245. #endif
  246. #ifdef CONFIG_PID_NS
  247. static inline unsigned long
  248. coresight_vpid_to_pid(unsigned long vpid)
  249. {
  250. struct task_struct *task = NULL;
  251. unsigned long pid = 0;
  252. rcu_read_lock();
  253. task = find_task_by_vpid(vpid);
  254. if (task)
  255. pid = task_pid_nr(task);
  256. rcu_read_unlock();
  257. return pid;
  258. }
  259. #else
  260. static inline unsigned long
  261. coresight_vpid_to_pid(unsigned long vpid) { return vpid; }
  262. #endif
  263. #endif