intel_th.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. * @fops: file operations for device nodes
  106. *
  107. * Callbacks @probe and @remove are required for all device types.
  108. * Switch device driver needs to fill in @assign, @enable and @disable
  109. * callbacks.
  110. */
  111. struct intel_th_driver {
  112. struct device_driver driver;
  113. int (*probe)(struct intel_th_device *thdev);
  114. void (*remove)(struct intel_th_device *thdev);
  115. /* switch (GTH) ops */
  116. int (*assign)(struct intel_th_device *thdev,
  117. struct intel_th_device *othdev);
  118. void (*unassign)(struct intel_th_device *thdev,
  119. struct intel_th_device *othdev);
  120. void (*enable)(struct intel_th_device *thdev,
  121. struct intel_th_output *output);
  122. void (*disable)(struct intel_th_device *thdev,
  123. struct intel_th_output *output);
  124. /* output ops */
  125. void (*irq)(struct intel_th_device *thdev);
  126. int (*activate)(struct intel_th_device *thdev);
  127. void (*deactivate)(struct intel_th_device *thdev);
  128. /* file_operations for those who want a device node */
  129. const struct file_operations *fops;
  130. /* source ops */
  131. int (*set_output)(struct intel_th_device *thdev,
  132. unsigned int master);
  133. };
  134. #define to_intel_th_driver(_d) \
  135. container_of((_d), struct intel_th_driver, driver)
  136. static inline struct intel_th_device *
  137. to_intel_th_hub(struct intel_th_device *thdev)
  138. {
  139. struct device *parent = thdev->dev.parent;
  140. if (!parent)
  141. return NULL;
  142. return to_intel_th_device(parent);
  143. }
  144. struct intel_th *
  145. intel_th_alloc(struct device *dev, struct resource *devres,
  146. unsigned int ndevres, int irq);
  147. void intel_th_free(struct intel_th *th);
  148. int intel_th_driver_register(struct intel_th_driver *thdrv);
  149. void intel_th_driver_unregister(struct intel_th_driver *thdrv);
  150. int intel_th_trace_enable(struct intel_th_device *thdev);
  151. int intel_th_trace_disable(struct intel_th_device *thdev);
  152. int intel_th_set_output(struct intel_th_device *thdev,
  153. unsigned int master);
  154. enum {
  155. TH_MMIO_CONFIG = 0,
  156. TH_MMIO_SW = 2,
  157. TH_MMIO_END,
  158. };
  159. #define TH_SUBDEVICE_MAX 6
  160. #define TH_POSSIBLE_OUTPUTS 8
  161. #define TH_CONFIGURABLE_MASTERS 256
  162. #define TH_MSC_MAX 2
  163. /**
  164. * struct intel_th - Intel TH controller
  165. * @dev: driver core's device
  166. * @thdev: subdevices
  167. * @hub: "switch" subdevice (GTH)
  168. * @id: this Intel TH controller's device ID in the system
  169. * @major: device node major for output devices
  170. */
  171. struct intel_th {
  172. struct device *dev;
  173. struct intel_th_device *thdev[TH_SUBDEVICE_MAX];
  174. struct intel_th_device *hub;
  175. int id;
  176. int major;
  177. #ifdef CONFIG_INTEL_TH_DEBUG
  178. struct dentry *dbg;
  179. #endif
  180. };
  181. /*
  182. * Register windows
  183. */
  184. enum {
  185. /* Global Trace Hub (GTH) */
  186. REG_GTH_OFFSET = 0x0000,
  187. REG_GTH_LENGTH = 0x2000,
  188. /* Software Trace Hub (STH) [0x4000..0x4fff] */
  189. REG_STH_OFFSET = 0x4000,
  190. REG_STH_LENGTH = 0x2000,
  191. /* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */
  192. REG_MSU_OFFSET = 0xa0000,
  193. REG_MSU_LENGTH = 0x02000,
  194. /* Internal MSU trace buffer [0x80000..0x9ffff] */
  195. BUF_MSU_OFFSET = 0x80000,
  196. BUF_MSU_LENGTH = 0x20000,
  197. /* PTI output == same window as GTH */
  198. REG_PTI_OFFSET = REG_GTH_OFFSET,
  199. REG_PTI_LENGTH = REG_GTH_LENGTH,
  200. /* DCI Handler (DCIH) == some window as MSU */
  201. REG_DCIH_OFFSET = REG_MSU_OFFSET,
  202. REG_DCIH_LENGTH = REG_MSU_LENGTH,
  203. };
  204. /*
  205. * GTH, output ports configuration
  206. */
  207. enum {
  208. GTH_NONE = 0,
  209. GTH_MSU, /* memory/usb */
  210. GTH_CTP, /* Common Trace Port */
  211. GTH_PTI = 4, /* MIPI-PTI */
  212. };
  213. /*
  214. * Scratchpad bits: tell firmware and external debuggers
  215. * what we are up to.
  216. */
  217. enum {
  218. /* Memory is the primary destination */
  219. SCRPD_MEM_IS_PRIM_DEST = BIT(0),
  220. /* XHCI DbC is the primary destination */
  221. SCRPD_DBC_IS_PRIM_DEST = BIT(1),
  222. /* PTI is the primary destination */
  223. SCRPD_PTI_IS_PRIM_DEST = BIT(2),
  224. /* BSSB is the primary destination */
  225. SCRPD_BSSB_IS_PRIM_DEST = BIT(3),
  226. /* PTI is the alternate destination */
  227. SCRPD_PTI_IS_ALT_DEST = BIT(4),
  228. /* BSSB is the alternate destination */
  229. SCRPD_BSSB_IS_ALT_DEST = BIT(5),
  230. /* DeepSx exit occurred */
  231. SCRPD_DEEPSX_EXIT = BIT(6),
  232. /* S4 exit occurred */
  233. SCRPD_S4_EXIT = BIT(7),
  234. /* S5 exit occurred */
  235. SCRPD_S5_EXIT = BIT(8),
  236. /* MSU controller 0/1 is enabled */
  237. SCRPD_MSC0_IS_ENABLED = BIT(9),
  238. SCRPD_MSC1_IS_ENABLED = BIT(10),
  239. /* Sx exit occurred */
  240. SCRPD_SX_EXIT = BIT(11),
  241. /* Trigger Unit is enabled */
  242. SCRPD_TRIGGER_IS_ENABLED = BIT(12),
  243. SCRPD_ODLA_IS_ENABLED = BIT(13),
  244. SCRPD_SOCHAP_IS_ENABLED = BIT(14),
  245. SCRPD_STH_IS_ENABLED = BIT(15),
  246. SCRPD_DCIH_IS_ENABLED = BIT(16),
  247. SCRPD_VER_IS_ENABLED = BIT(17),
  248. /* External debugger is using Intel TH */
  249. SCRPD_DEBUGGER_IN_USE = BIT(24),
  250. };
  251. #endif