intel_th.h 8.3 KB

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