intel_th.h 10 KB

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