intel_th.h 11 KB

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