intel_th.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Intel(R) Trace Hub data structures
  3. *
  4. * Copyright (C) 2014-2015 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. */
  15. #ifndef __INTEL_TH_H__
  16. #define __INTEL_TH_H__
  17. /* intel_th_device device types */
  18. enum {
  19. /* Devices that generate trace data */
  20. INTEL_TH_SOURCE = 0,
  21. /* Output ports (MSC, PTI) */
  22. INTEL_TH_OUTPUT,
  23. /* Switch, the Global Trace Hub (GTH) */
  24. INTEL_TH_SWITCH,
  25. };
  26. /**
  27. * struct intel_th_output - descriptor INTEL_TH_OUTPUT type devices
  28. * @port: output port number, assigned by the switch
  29. * @type: GTH_{MSU,CTP,PTI}
  30. * @scratchpad: scratchpad bits to flag when this output is enabled
  31. * @multiblock: true for multiblock output configuration
  32. * @active: true when this output is enabled
  33. *
  34. * Output port descriptor, used by switch driver to tell which output
  35. * port this output device corresponds to. Filled in at output device's
  36. * probe time by switch::assign(). Passed from output device driver to
  37. * switch related code to enable/disable its port.
  38. */
  39. struct intel_th_output {
  40. int port;
  41. unsigned int type;
  42. unsigned int scratchpad;
  43. bool multiblock;
  44. bool active;
  45. };
  46. /**
  47. * struct intel_th_device - device on the intel_th bus
  48. * @dev: device
  49. * @resource: array of resources available to this device
  50. * @num_resources: number of resources in @resource array
  51. * @type: INTEL_TH_{SOURCE,OUTPUT,SWITCH}
  52. * @id: device instance or -1
  53. * @output: output descriptor for INTEL_TH_OUTPUT devices
  54. * @name: device name to match the driver
  55. */
  56. struct intel_th_device {
  57. struct device dev;
  58. struct resource *resource;
  59. unsigned int num_resources;
  60. unsigned int type;
  61. int id;
  62. /* INTEL_TH_OUTPUT specific */
  63. struct intel_th_output output;
  64. char name[];
  65. };
  66. #define to_intel_th_device(_d) \
  67. container_of((_d), struct intel_th_device, dev)
  68. /**
  69. * intel_th_device_get_resource() - obtain @num'th resource of type @type
  70. * @thdev: the device to search the resource for
  71. * @type: resource type
  72. * @num: number of the resource
  73. */
  74. static inline struct resource *
  75. intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type,
  76. unsigned int num)
  77. {
  78. int i;
  79. for (i = 0; i < thdev->num_resources; i++)
  80. if (resource_type(&thdev->resource[i]) == type && !num--)
  81. return &thdev->resource[i];
  82. return NULL;
  83. }
  84. /**
  85. * intel_th_output_assigned() - if an output device is assigned to a switch port
  86. * @thdev: the output device
  87. *
  88. * Return: true if the device is INTEL_TH_OUTPUT *and* is assigned a port
  89. */
  90. static inline bool
  91. intel_th_output_assigned(struct intel_th_device *thdev)
  92. {
  93. return thdev->type == INTEL_TH_OUTPUT &&
  94. thdev->output.port >= 0;
  95. }
  96. /**
  97. * struct intel_th_driver - driver for an intel_th_device device
  98. * @driver: generic driver
  99. * @probe: probe method
  100. * @remove: remove method
  101. * @assign: match a given output type device against available outputs
  102. * @unassign: deassociate an output type device from an output port
  103. * @enable: enable tracing for a given output device
  104. * @disable: disable tracing for a given output device
  105. * @irq: interrupt callback
  106. * @activate: enable tracing on the output's side
  107. * @deactivate: disable tracing on the output's side
  108. * @fops: file operations for device nodes
  109. * @attr_group: attributes provided by the driver
  110. *
  111. * Callbacks @probe and @remove are required for all device types.
  112. * Switch device driver needs to fill in @assign, @enable and @disable
  113. * callbacks.
  114. */
  115. struct intel_th_driver {
  116. struct device_driver driver;
  117. int (*probe)(struct intel_th_device *thdev);
  118. void (*remove)(struct intel_th_device *thdev);
  119. /* switch (GTH) ops */
  120. int (*assign)(struct intel_th_device *thdev,
  121. struct intel_th_device *othdev);
  122. void (*unassign)(struct intel_th_device *thdev,
  123. struct intel_th_device *othdev);
  124. void (*enable)(struct intel_th_device *thdev,
  125. struct intel_th_output *output);
  126. void (*disable)(struct intel_th_device *thdev,
  127. struct intel_th_output *output);
  128. /* output ops */
  129. void (*irq)(struct intel_th_device *thdev);
  130. int (*activate)(struct intel_th_device *thdev);
  131. void (*deactivate)(struct intel_th_device *thdev);
  132. /* file_operations for those who want a device node */
  133. const struct file_operations *fops;
  134. /* optional attributes */
  135. struct attribute_group *attr_group;
  136. /* source ops */
  137. int (*set_output)(struct intel_th_device *thdev,
  138. unsigned int master);
  139. };
  140. #define to_intel_th_driver(_d) \
  141. container_of((_d), struct intel_th_driver, driver)
  142. #define to_intel_th_driver_or_null(_d) \
  143. ((_d) ? to_intel_th_driver(_d) : NULL)
  144. static inline struct intel_th_device *
  145. to_intel_th_hub(struct intel_th_device *thdev)
  146. {
  147. struct device *parent = thdev->dev.parent;
  148. if (!parent)
  149. return NULL;
  150. return to_intel_th_device(parent);
  151. }
  152. struct intel_th *
  153. intel_th_alloc(struct device *dev, struct resource *devres,
  154. unsigned int ndevres, int irq);
  155. void intel_th_free(struct intel_th *th);
  156. int intel_th_driver_register(struct intel_th_driver *thdrv);
  157. void intel_th_driver_unregister(struct intel_th_driver *thdrv);
  158. int intel_th_trace_enable(struct intel_th_device *thdev);
  159. int intel_th_trace_disable(struct intel_th_device *thdev);
  160. int intel_th_set_output(struct intel_th_device *thdev,
  161. unsigned int master);
  162. enum {
  163. TH_MMIO_CONFIG = 0,
  164. TH_MMIO_SW = 2,
  165. TH_MMIO_END,
  166. };
  167. #define TH_SUBDEVICE_MAX 6
  168. #define TH_POSSIBLE_OUTPUTS 8
  169. #define TH_CONFIGURABLE_MASTERS 256
  170. #define TH_MSC_MAX 2
  171. /**
  172. * struct intel_th - Intel TH controller
  173. * @dev: driver core's device
  174. * @thdev: subdevices
  175. * @hub: "switch" subdevice (GTH)
  176. * @id: this Intel TH controller's device ID in the system
  177. * @major: device node major for output devices
  178. */
  179. struct intel_th {
  180. struct device *dev;
  181. struct intel_th_device *thdev[TH_SUBDEVICE_MAX];
  182. struct intel_th_device *hub;
  183. int id;
  184. int major;
  185. #ifdef CONFIG_MODULES
  186. struct work_struct request_module_work;
  187. #endif /* CONFIG_MODULES */
  188. #ifdef CONFIG_INTEL_TH_DEBUG
  189. struct dentry *dbg;
  190. #endif
  191. };
  192. /*
  193. * Register windows
  194. */
  195. enum {
  196. /* Global Trace Hub (GTH) */
  197. REG_GTH_OFFSET = 0x0000,
  198. REG_GTH_LENGTH = 0x2000,
  199. /* Software Trace Hub (STH) [0x4000..0x4fff] */
  200. REG_STH_OFFSET = 0x4000,
  201. REG_STH_LENGTH = 0x2000,
  202. /* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */
  203. REG_MSU_OFFSET = 0xa0000,
  204. REG_MSU_LENGTH = 0x02000,
  205. /* Internal MSU trace buffer [0x80000..0x9ffff] */
  206. BUF_MSU_OFFSET = 0x80000,
  207. BUF_MSU_LENGTH = 0x20000,
  208. /* PTI output == same window as GTH */
  209. REG_PTI_OFFSET = REG_GTH_OFFSET,
  210. REG_PTI_LENGTH = REG_GTH_LENGTH,
  211. /* DCI Handler (DCIH) == some window as MSU */
  212. REG_DCIH_OFFSET = REG_MSU_OFFSET,
  213. REG_DCIH_LENGTH = REG_MSU_LENGTH,
  214. };
  215. /*
  216. * GTH, output ports configuration
  217. */
  218. enum {
  219. GTH_NONE = 0,
  220. GTH_MSU, /* memory/usb */
  221. GTH_CTP, /* Common Trace Port */
  222. GTH_PTI = 4, /* MIPI-PTI */
  223. };
  224. /*
  225. * Scratchpad bits: tell firmware and external debuggers
  226. * what we are up to.
  227. */
  228. enum {
  229. /* Memory is the primary destination */
  230. SCRPD_MEM_IS_PRIM_DEST = BIT(0),
  231. /* XHCI DbC is the primary destination */
  232. SCRPD_DBC_IS_PRIM_DEST = BIT(1),
  233. /* PTI is the primary destination */
  234. SCRPD_PTI_IS_PRIM_DEST = BIT(2),
  235. /* BSSB is the primary destination */
  236. SCRPD_BSSB_IS_PRIM_DEST = BIT(3),
  237. /* PTI is the alternate destination */
  238. SCRPD_PTI_IS_ALT_DEST = BIT(4),
  239. /* BSSB is the alternate destination */
  240. SCRPD_BSSB_IS_ALT_DEST = BIT(5),
  241. /* DeepSx exit occurred */
  242. SCRPD_DEEPSX_EXIT = BIT(6),
  243. /* S4 exit occurred */
  244. SCRPD_S4_EXIT = BIT(7),
  245. /* S5 exit occurred */
  246. SCRPD_S5_EXIT = BIT(8),
  247. /* MSU controller 0/1 is enabled */
  248. SCRPD_MSC0_IS_ENABLED = BIT(9),
  249. SCRPD_MSC1_IS_ENABLED = BIT(10),
  250. /* Sx exit occurred */
  251. SCRPD_SX_EXIT = BIT(11),
  252. /* Trigger Unit is enabled */
  253. SCRPD_TRIGGER_IS_ENABLED = BIT(12),
  254. SCRPD_ODLA_IS_ENABLED = BIT(13),
  255. SCRPD_SOCHAP_IS_ENABLED = BIT(14),
  256. SCRPD_STH_IS_ENABLED = BIT(15),
  257. SCRPD_DCIH_IS_ENABLED = BIT(16),
  258. SCRPD_VER_IS_ENABLED = BIT(17),
  259. /* External debugger is using Intel TH */
  260. SCRPD_DEBUGGER_IN_USE = BIT(24),
  261. };
  262. #endif