intel_th.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. * @multiblock: true for multiblock output configuration
  31. * @active: true when this output is enabled
  32. *
  33. * Output port descriptor, used by switch driver to tell which output
  34. * port this output device corresponds to. Filled in at output device's
  35. * probe time by switch::assign(). Passed from output device driver to
  36. * switch related code to enable/disable its port.
  37. */
  38. struct intel_th_output {
  39. int port;
  40. unsigned int type;
  41. bool multiblock;
  42. bool active;
  43. };
  44. /**
  45. * struct intel_th_device - device on the intel_th bus
  46. * @dev: device
  47. * @resource: array of resources available to this device
  48. * @num_resources: number of resources in @resource array
  49. * @type: INTEL_TH_{SOURCE,OUTPUT,SWITCH}
  50. * @id: device instance or -1
  51. * @output: output descriptor for INTEL_TH_OUTPUT devices
  52. * @name: device name to match the driver
  53. */
  54. struct intel_th_device {
  55. struct device dev;
  56. struct resource *resource;
  57. unsigned int num_resources;
  58. unsigned int type;
  59. int id;
  60. /* INTEL_TH_OUTPUT specific */
  61. struct intel_th_output output;
  62. char name[];
  63. };
  64. #define to_intel_th_device(_d) \
  65. container_of((_d), struct intel_th_device, dev)
  66. /**
  67. * intel_th_device_get_resource() - obtain @num'th resource of type @type
  68. * @thdev: the device to search the resource for
  69. * @type: resource type
  70. * @num: number of the resource
  71. */
  72. static inline struct resource *
  73. intel_th_device_get_resource(struct intel_th_device *thdev, unsigned int type,
  74. unsigned int num)
  75. {
  76. int i;
  77. for (i = 0; i < thdev->num_resources; i++)
  78. if (resource_type(&thdev->resource[i]) == type && !num--)
  79. return &thdev->resource[i];
  80. return NULL;
  81. }
  82. /**
  83. * intel_th_output_assigned() - if an output device is assigned to a switch port
  84. * @thdev: the output device
  85. *
  86. * Return: true if the device is INTEL_TH_OUTPUT *and* is assigned a port
  87. */
  88. static inline bool
  89. intel_th_output_assigned(struct intel_th_device *thdev)
  90. {
  91. return thdev->type == INTEL_TH_OUTPUT &&
  92. thdev->output.port >= 0;
  93. }
  94. /**
  95. * struct intel_th_driver - driver for an intel_th_device device
  96. * @driver: generic driver
  97. * @probe: probe method
  98. * @remove: remove method
  99. * @assign: match a given output type device against available outputs
  100. * @unassign: deassociate an output type device from an output port
  101. * @enable: enable tracing for a given output device
  102. * @disable: disable tracing for a given output device
  103. * @fops: file operations for device nodes
  104. *
  105. * Callbacks @probe and @remove are required for all device types.
  106. * Switch device driver needs to fill in @assign, @enable and @disable
  107. * callbacks.
  108. */
  109. struct intel_th_driver {
  110. struct device_driver driver;
  111. int (*probe)(struct intel_th_device *thdev);
  112. void (*remove)(struct intel_th_device *thdev);
  113. /* switch (GTH) ops */
  114. int (*assign)(struct intel_th_device *thdev,
  115. struct intel_th_device *othdev);
  116. void (*unassign)(struct intel_th_device *thdev,
  117. struct intel_th_device *othdev);
  118. void (*enable)(struct intel_th_device *thdev,
  119. struct intel_th_output *output);
  120. void (*disable)(struct intel_th_device *thdev,
  121. struct intel_th_output *output);
  122. /* output ops */
  123. void (*irq)(struct intel_th_device *thdev);
  124. int (*activate)(struct intel_th_device *thdev);
  125. void (*deactivate)(struct intel_th_device *thdev);
  126. /* file_operations for those who want a device node */
  127. const struct file_operations *fops;
  128. /* source ops */
  129. int (*set_output)(struct intel_th_device *thdev,
  130. unsigned int master);
  131. };
  132. #define to_intel_th_driver(_d) \
  133. container_of((_d), struct intel_th_driver, driver)
  134. static inline struct intel_th_device *
  135. to_intel_th_hub(struct intel_th_device *thdev)
  136. {
  137. struct device *parent = thdev->dev.parent;
  138. if (!parent)
  139. return NULL;
  140. return to_intel_th_device(parent);
  141. }
  142. struct intel_th *
  143. intel_th_alloc(struct device *dev, struct resource *devres,
  144. unsigned int ndevres, int irq);
  145. void intel_th_free(struct intel_th *th);
  146. int intel_th_driver_register(struct intel_th_driver *thdrv);
  147. void intel_th_driver_unregister(struct intel_th_driver *thdrv);
  148. int intel_th_trace_enable(struct intel_th_device *thdev);
  149. int intel_th_trace_disable(struct intel_th_device *thdev);
  150. int intel_th_set_output(struct intel_th_device *thdev,
  151. unsigned int master);
  152. enum {
  153. TH_MMIO_CONFIG = 0,
  154. TH_MMIO_SW = 2,
  155. TH_MMIO_END,
  156. };
  157. #define TH_SUBDEVICE_MAX 6
  158. #define TH_POSSIBLE_OUTPUTS 8
  159. #define TH_CONFIGURABLE_MASTERS 256
  160. #define TH_MSC_MAX 2
  161. /**
  162. * struct intel_th - Intel TH controller
  163. * @dev: driver core's device
  164. * @thdev: subdevices
  165. * @hub: "switch" subdevice (GTH)
  166. * @id: this Intel TH controller's device ID in the system
  167. * @major: device node major for output devices
  168. */
  169. struct intel_th {
  170. struct device *dev;
  171. struct intel_th_device *thdev[TH_SUBDEVICE_MAX];
  172. struct intel_th_device *hub;
  173. int id;
  174. int major;
  175. #ifdef CONFIG_MODULES
  176. struct work_struct request_module_work;
  177. #endif /* CONFIG_MODULES */
  178. #ifdef CONFIG_INTEL_TH_DEBUG
  179. struct dentry *dbg;
  180. #endif
  181. };
  182. /*
  183. * Register windows
  184. */
  185. enum {
  186. /* Global Trace Hub (GTH) */
  187. REG_GTH_OFFSET = 0x0000,
  188. REG_GTH_LENGTH = 0x2000,
  189. /* Software Trace Hub (STH) [0x4000..0x4fff] */
  190. REG_STH_OFFSET = 0x4000,
  191. REG_STH_LENGTH = 0x2000,
  192. /* Memory Storage Unit (MSU) [0xa0000..0xa1fff] */
  193. REG_MSU_OFFSET = 0xa0000,
  194. REG_MSU_LENGTH = 0x02000,
  195. /* Internal MSU trace buffer [0x80000..0x9ffff] */
  196. BUF_MSU_OFFSET = 0x80000,
  197. BUF_MSU_LENGTH = 0x20000,
  198. /* PTI output == same window as GTH */
  199. REG_PTI_OFFSET = REG_GTH_OFFSET,
  200. REG_PTI_LENGTH = REG_GTH_LENGTH,
  201. /* DCI Handler (DCIH) == some window as MSU */
  202. REG_DCIH_OFFSET = REG_MSU_OFFSET,
  203. REG_DCIH_LENGTH = REG_MSU_LENGTH,
  204. };
  205. /*
  206. * GTH, output ports configuration
  207. */
  208. enum {
  209. GTH_NONE = 0,
  210. GTH_MSU, /* memory/usb */
  211. GTH_CTP, /* Common Trace Port */
  212. GTH_PTI = 4, /* MIPI-PTI */
  213. };
  214. #endif