intel_th.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Intel(R) Trace Hub data structures
  4. *
  5. * Copyright (C) 2014-2015 Intel Corporation.
  6. */
  7. #ifndef __INTEL_TH_H__
  8. #define __INTEL_TH_H__
  9. /* intel_th_device device types */
  10. enum {
  11. /* Devices that generate trace data */
  12. INTEL_TH_SOURCE = 0,
  13. /* Output ports (MSC, PTI) */
  14. INTEL_TH_OUTPUT,
  15. /* Switch, the Global Trace Hub (GTH) */
  16. INTEL_TH_SWITCH,
  17. };
  18. /**
  19. * struct intel_th_output - descriptor INTEL_TH_OUTPUT type devices
  20. * @port: output port number, assigned by the switch
  21. * @type: GTH_{MSU,CTP,PTI}
  22. * @scratchpad: scratchpad bits to flag when this output is enabled
  23. * @multiblock: true for multiblock output configuration
  24. * @active: true when this output is enabled
  25. *
  26. * Output port descriptor, used by switch driver to tell which output
  27. * port this output device corresponds to. Filled in at output device's
  28. * probe time by switch::assign(). Passed from output device driver to
  29. * switch related code to enable/disable its port.
  30. */
  31. struct intel_th_output {
  32. int port;
  33. unsigned int type;
  34. unsigned int scratchpad;
  35. bool multiblock;
  36. bool active;
  37. };
  38. /**
  39. * struct intel_th_drvdata - describes hardware capabilities and quirks
  40. * @tscu_enable: device needs SW to enable time stamping unit
  41. * @host_mode_only: device can only operate in 'host debugger' mode
  42. */
  43. struct intel_th_drvdata {
  44. unsigned int tscu_enable : 1,
  45. host_mode_only : 1;
  46. };
  47. #define INTEL_TH_CAP(_th, _cap) ((_th)->drvdata ? (_th)->drvdata->_cap : 0)
  48. /**
  49. * struct intel_th_device - device on the intel_th bus
  50. * @dev: device
  51. * @drvdata: hardware capabilities/quirks
  52. * @resource: array of resources available to this device
  53. * @num_resources: number of resources in @resource array
  54. * @type: INTEL_TH_{SOURCE,OUTPUT,SWITCH}
  55. * @id: device instance or -1
  56. * @host_mode: Intel TH is controlled by an external debug host
  57. * @output: output descriptor for INTEL_TH_OUTPUT devices
  58. * @name: device name to match the driver
  59. */
  60. struct intel_th_device {
  61. struct device dev;
  62. struct intel_th_drvdata *drvdata;
  63. struct resource *resource;
  64. unsigned int num_resources;
  65. unsigned int type;
  66. int id;
  67. /* INTEL_TH_SWITCH specific */
  68. bool host_mode;
  69. /* INTEL_TH_OUTPUT specific */
  70. struct intel_th_output output;
  71. char name[];
  72. };
  73. #define to_intel_th_device(_d) \
  74. container_of((_d), struct intel_th_device, dev)
  75. /**
  76. * intel_th_device_get_resource() - obtain @num'th resource of type @type
  77. * @thdev: the device to search the resource for
  78. * @type: resource type
  79. * @num: number of the resource
  80. */
  81. static inline struct resource *
  82. intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type,
  83. unsigned int num)
  84. {
  85. int i;
  86. for (i = 0; i < thdev->num_resources; i++)
  87. if (resource_type(&thdev->resource[i]) == type && !num--)
  88. return &thdev->resource[i];
  89. return NULL;
  90. }
  91. /*
  92. * GTH, output ports configuration
  93. */
  94. enum {
  95. GTH_NONE = 0,
  96. GTH_MSU, /* memory/usb */
  97. GTH_CTP, /* Common Trace Port */
  98. GTH_LPP, /* Low Power Path */
  99. GTH_PTI, /* MIPI-PTI */
  100. };
  101. /**
  102. * intel_th_output_assigned() - if an output device is assigned to a switch port
  103. * @thdev: the output device
  104. *
  105. * Return: true if the device is INTEL_TH_OUTPUT *and* is assigned a port
  106. */
  107. static inline bool
  108. intel_th_output_assigned(struct intel_th_device *thdev)
  109. {
  110. return thdev->type == INTEL_TH_OUTPUT &&
  111. (thdev->output.port >= 0 ||
  112. thdev->output.type == GTH_NONE);
  113. }
  114. /**
  115. * struct intel_th_driver - driver for an intel_th_device device
  116. * @driver: generic driver
  117. * @probe: probe method
  118. * @remove: remove method
  119. * @assign: match a given output type device against available outputs
  120. * @unassign: deassociate an output type device from an output port
  121. * @enable: enable tracing for a given output device
  122. * @disable: disable tracing for a given output device
  123. * @irq: interrupt callback
  124. * @activate: enable tracing on the output's side
  125. * @deactivate: disable tracing on the output's side
  126. * @fops: file operations for device nodes
  127. * @attr_group: attributes provided by the driver
  128. *
  129. * Callbacks @probe and @remove are required for all device types.
  130. * Switch device driver needs to fill in @assign, @enable and @disable
  131. * callbacks.
  132. */
  133. struct intel_th_driver {
  134. struct device_driver driver;
  135. int (*probe)(struct intel_th_device *thdev);
  136. void (*remove)(struct intel_th_device *thdev);
  137. /* switch (GTH) ops */
  138. int (*assign)(struct intel_th_device *thdev,
  139. struct intel_th_device *othdev);
  140. void (*unassign)(struct intel_th_device *thdev,
  141. struct intel_th_device *othdev);
  142. void (*enable)(struct intel_th_device *thdev,
  143. struct intel_th_output *output);
  144. void (*disable)(struct intel_th_device *thdev,
  145. struct intel_th_output *output);
  146. /* output ops */
  147. void (*irq)(struct intel_th_device *thdev);
  148. int (*activate)(struct intel_th_device *thdev);
  149. void (*deactivate)(struct intel_th_device *thdev);
  150. /* file_operations for those who want a device node */
  151. const struct file_operations *fops;
  152. /* optional attributes */
  153. struct attribute_group *attr_group;
  154. /* source ops */
  155. int (*set_output)(struct intel_th_device *thdev,
  156. unsigned int master);
  157. };
  158. #define to_intel_th_driver(_d) \
  159. container_of((_d), struct intel_th_driver, driver)
  160. #define to_intel_th_driver_or_null(_d) \
  161. ((_d) ? to_intel_th_driver(_d) : NULL)
  162. /*
  163. * Subdevice tree structure is as follows:
  164. * + struct intel_th device (pci; dev_{get,set}_drvdata()
  165. * + struct intel_th_device INTEL_TH_SWITCH (GTH)
  166. * + struct intel_th_device INTEL_TH_OUTPUT (MSU, PTI)
  167. * + struct intel_th_device INTEL_TH_SOURCE (STH)
  168. *
  169. * In other words, INTEL_TH_OUTPUT devices are children of INTEL_TH_SWITCH;
  170. * INTEL_TH_SWITCH and INTEL_TH_SOURCE are children of the intel_th device.
  171. */
  172. static inline struct intel_th_device *
  173. to_intel_th_parent(struct intel_th_device *thdev)
  174. {
  175. struct device *parent = thdev->dev.parent;
  176. if (!parent)
  177. return NULL;
  178. return to_intel_th_device(parent);
  179. }
  180. static inline struct intel_th *to_intel_th(struct intel_th_device *thdev)
  181. {
  182. if (thdev->type == INTEL_TH_OUTPUT)
  183. thdev = to_intel_th_parent(thdev);
  184. if (WARN_ON_ONCE(!thdev || thdev->type == INTEL_TH_OUTPUT))
  185. return NULL;
  186. return dev_get_drvdata(thdev->dev.parent);
  187. }
  188. struct intel_th *
  189. intel_th_alloc(struct device *dev, struct intel_th_drvdata *drvdata,
  190. struct resource *devres, unsigned int ndevres, int irq);
  191. void intel_th_free(struct intel_th *th);
  192. int intel_th_driver_register(struct intel_th_driver *thdrv);
  193. void intel_th_driver_unregister(struct intel_th_driver *thdrv);
  194. int intel_th_trace_enable(struct intel_th_device *thdev);
  195. int intel_th_trace_disable(struct intel_th_device *thdev);
  196. int intel_th_set_output(struct intel_th_device *thdev,
  197. unsigned int master);
  198. int intel_th_output_enable(struct intel_th *th, unsigned int otype);
  199. enum {
  200. TH_MMIO_CONFIG = 0,
  201. TH_MMIO_SW = 2,
  202. TH_MMIO_END,
  203. };
  204. #define TH_POSSIBLE_OUTPUTS 8
  205. /* Total number of possible subdevices: outputs + GTH + STH */
  206. #define TH_SUBDEVICE_MAX (TH_POSSIBLE_OUTPUTS + 2)
  207. #define TH_CONFIGURABLE_MASTERS 256
  208. #define TH_MSC_MAX 2
  209. /**
  210. * struct intel_th - Intel TH controller
  211. * @dev: driver core's device
  212. * @thdev: subdevices
  213. * @hub: "switch" subdevice (GTH)
  214. * @resource: resources of the entire controller
  215. * @num_thdevs: number of devices in the @thdev array
  216. * @num_resources: number or resources in the @resource array
  217. * @irq: irq number
  218. * @id: this Intel TH controller's device ID in the system
  219. * @major: device node major for output devices
  220. */
  221. struct intel_th {
  222. struct device *dev;
  223. struct intel_th_device *thdev[TH_SUBDEVICE_MAX];
  224. struct intel_th_device *hub;
  225. struct intel_th_drvdata *drvdata;
  226. struct resource *resource;
  227. int (*activate)(struct intel_th *);
  228. void (*deactivate)(struct intel_th *);
  229. unsigned int num_thdevs;
  230. unsigned int num_resources;
  231. int irq;
  232. int id;
  233. int major;
  234. #ifdef CONFIG_MODULES
  235. struct work_struct request_module_work;
  236. #endif /* CONFIG_MODULES */
  237. #ifdef CONFIG_INTEL_TH_DEBUG
  238. struct dentry *dbg;
  239. #endif
  240. };
  241. static inline struct intel_th_device *
  242. to_intel_th_hub(struct intel_th_device *thdev)
  243. {
  244. if (thdev->type == INTEL_TH_SWITCH)
  245. return thdev;
  246. else if (thdev->type == INTEL_TH_OUTPUT)
  247. return to_intel_th_parent(thdev);
  248. return to_intel_th(thdev)->hub;
  249. }
  250. /*
  251. * Register windows
  252. */
  253. enum {
  254. /* Global Trace Hub (GTH) */
  255. REG_GTH_OFFSET = 0x0000,
  256. REG_GTH_LENGTH = 0x2000,
  257. /* Timestamp counter unit (TSCU) */
  258. REG_TSCU_OFFSET = 0x2000,
  259. REG_TSCU_LENGTH = 0x1000,
  260. /* Software Trace Hub (STH) [0x4000..0x4fff] */
  261. REG_STH_OFFSET = 0x4000,
  262. REG_STH_LENGTH = 0x2000,
  263. /* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */
  264. REG_MSU_OFFSET = 0xa0000,
  265. REG_MSU_LENGTH = 0x02000,
  266. /* Internal MSU trace buffer [0x80000..0x9ffff] */
  267. BUF_MSU_OFFSET = 0x80000,
  268. BUF_MSU_LENGTH = 0x20000,
  269. /* PTI output == same window as GTH */
  270. REG_PTI_OFFSET = REG_GTH_OFFSET,
  271. REG_PTI_LENGTH = REG_GTH_LENGTH,
  272. /* DCI Handler (DCIH) == some window as MSU */
  273. REG_DCIH_OFFSET = REG_MSU_OFFSET,
  274. REG_DCIH_LENGTH = REG_MSU_LENGTH,
  275. };
  276. /*
  277. * Scratchpad bits: tell firmware and external debuggers
  278. * what we are up to.
  279. */
  280. enum {
  281. /* Memory is the primary destination */
  282. SCRPD_MEM_IS_PRIM_DEST = BIT(0),
  283. /* XHCI DbC is the primary destination */
  284. SCRPD_DBC_IS_PRIM_DEST = BIT(1),
  285. /* PTI is the primary destination */
  286. SCRPD_PTI_IS_PRIM_DEST = BIT(2),
  287. /* BSSB is the primary destination */
  288. SCRPD_BSSB_IS_PRIM_DEST = BIT(3),
  289. /* PTI is the alternate destination */
  290. SCRPD_PTI_IS_ALT_DEST = BIT(4),
  291. /* BSSB is the alternate destination */
  292. SCRPD_BSSB_IS_ALT_DEST = BIT(5),
  293. /* DeepSx exit occurred */
  294. SCRPD_DEEPSX_EXIT = BIT(6),
  295. /* S4 exit occurred */
  296. SCRPD_S4_EXIT = BIT(7),
  297. /* S5 exit occurred */
  298. SCRPD_S5_EXIT = BIT(8),
  299. /* MSU controller 0/1 is enabled */
  300. SCRPD_MSC0_IS_ENABLED = BIT(9),
  301. SCRPD_MSC1_IS_ENABLED = BIT(10),
  302. /* Sx exit occurred */
  303. SCRPD_SX_EXIT = BIT(11),
  304. /* Trigger Unit is enabled */
  305. SCRPD_TRIGGER_IS_ENABLED = BIT(12),
  306. SCRPD_ODLA_IS_ENABLED = BIT(13),
  307. SCRPD_SOCHAP_IS_ENABLED = BIT(14),
  308. SCRPD_STH_IS_ENABLED = BIT(15),
  309. SCRPD_DCIH_IS_ENABLED = BIT(16),
  310. SCRPD_VER_IS_ENABLED = BIT(17),
  311. /* External debugger is using Intel TH */
  312. SCRPD_DEBUGGER_IN_USE = BIT(24),
  313. };
  314. #endif