coresight.h 9.7 KB

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