coresight-config.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2020 Linaro Limited, All rights reserved.
  4. * Author: Mike Leach <mike.leach@linaro.org>
  5. */
  6. #ifndef _CORESIGHT_CORESIGHT_CONFIG_H
  7. #define _CORESIGHT_CORESIGHT_CONFIG_H
  8. #include <linux/coresight.h>
  9. #include <linux/types.h>
  10. /* CoreSight Configuration Management - component and system wide configuration */
  11. /*
  12. * Register type flags for register value descriptor:
  13. * describe how the value is interpreted, and handled.
  14. */
  15. #define CS_CFG_REG_TYPE_STD 0x80 /* reg is standard reg */
  16. #define CS_CFG_REG_TYPE_RESOURCE 0x40 /* reg is a resource */
  17. #define CS_CFG_REG_TYPE_VAL_PARAM 0x08 /* reg value uses param */
  18. #define CS_CFG_REG_TYPE_VAL_MASK 0x04 /* reg value bit masked */
  19. #define CS_CFG_REG_TYPE_VAL_64BIT 0x02 /* reg value 64 bit */
  20. #define CS_CFG_REG_TYPE_VAL_SAVE 0x01 /* reg value save on disable */
  21. /*
  22. * flags defining what device class a feature will match to when processing a
  23. * system configuration - used by config data and devices.
  24. */
  25. #define CS_CFG_MATCH_CLASS_SRC_ALL 0x0001 /* match any source */
  26. #define CS_CFG_MATCH_CLASS_SRC_ETM4 0x0002 /* match any ETMv4 device */
  27. /* flags defining device instance matching - used in config match desc data. */
  28. #define CS_CFG_MATCH_INST_ANY 0x80000000 /* any instance of a class */
  29. /*
  30. * Limit number of presets in a configuration
  31. * This is related to the number of bits (4) we use to select the preset on
  32. * the perf command line. Preset 0 is always none selected.
  33. * See PMU_FORMAT_ATTR(preset, "config:0-3") in coresight-etm-perf.c
  34. */
  35. #define CS_CFG_CONFIG_PRESET_MAX 15
  36. /**
  37. * Parameter descriptor for a device feature.
  38. *
  39. * @name: Name of parameter.
  40. * @value: Initial or default value.
  41. */
  42. struct cscfg_parameter_desc {
  43. const char *name;
  44. u64 value;
  45. };
  46. /**
  47. * Representation of register value and a descriptor of register usage.
  48. *
  49. * Used as a descriptor in the feature descriptors.
  50. * Used as a value in when in a feature loading into a csdev.
  51. *
  52. * Supports full 64 bit register value, or 32 bit value with optional mask
  53. * value.
  54. *
  55. * @type: define register usage and interpretation.
  56. * @offset: the address offset for register in the hardware device (per device specification).
  57. * @hw_info: optional hardware device type specific information. (ETM / CTI specific etc)
  58. * @val64: 64 bit value.
  59. * @val32: 32 bit value.
  60. * @mask32: 32 bit mask when using 32 bit value to access device register - if mask type.
  61. * @param_idx: parameter index value into parameter array if param type.
  62. */
  63. struct cscfg_regval_desc {
  64. struct {
  65. u32 type:8;
  66. u32 offset:12;
  67. u32 hw_info:12;
  68. };
  69. union {
  70. u64 val64;
  71. struct {
  72. u32 val32;
  73. u32 mask32;
  74. };
  75. u32 param_idx;
  76. };
  77. };
  78. /**
  79. * Device feature descriptor - combination of registers and parameters to
  80. * program a device to implement a specific complex function.
  81. *
  82. * @name: feature name.
  83. * @description: brief description of the feature.
  84. * @item: List entry.
  85. * @match_flags: matching information if loading into a device
  86. * @nr_params: number of parameters used.
  87. * @params_desc: array of parameters used.
  88. * @nr_regs: number of registers used.
  89. * @regs_desc: array of registers used.
  90. * @load_owner: handle to load owner for dynamic load and unload of features.
  91. * @fs_group: reference to configfs group for dynamic unload.
  92. */
  93. struct cscfg_feature_desc {
  94. const char *name;
  95. const char *description;
  96. struct list_head item;
  97. u32 match_flags;
  98. int nr_params;
  99. struct cscfg_parameter_desc *params_desc;
  100. int nr_regs;
  101. struct cscfg_regval_desc *regs_desc;
  102. void *load_owner;
  103. struct config_group *fs_group;
  104. };
  105. /**
  106. * Configuration descriptor - describes selectable system configuration.
  107. *
  108. * A configuration describes device features in use, and may provide preset
  109. * values for the parameters in those features.
  110. *
  111. * A single set of presets is the sum of the parameters declared by
  112. * all the features in use - this value is @nr_total_params.
  113. *
  114. * @name: name of the configuration - used for selection.
  115. * @description: description of the purpose of the configuration.
  116. * @item: list entry.
  117. * @nr_feat_refs: Number of features used in this configuration.
  118. * @feat_ref_names: references to features used in this configuration.
  119. * @nr_presets: Number of sets of presets supplied by this configuration.
  120. * @nr_total_params: Sum of all parameters declared by used features
  121. * @presets: Array of preset values.
  122. * @event_ea: Extended attribute for perf event value
  123. * @active_cnt: ref count for activate on this configuration.
  124. * @load_owner: handle to load owner for dynamic load and unload of configs.
  125. * @fs_group: reference to configfs group for dynamic unload.
  126. * @available: config can be activated - multi-stage load sets true on completion.
  127. */
  128. struct cscfg_config_desc {
  129. const char *name;
  130. const char *description;
  131. struct list_head item;
  132. int nr_feat_refs;
  133. const char **feat_ref_names;
  134. int nr_presets;
  135. int nr_total_params;
  136. const u64 *presets; /* nr_presets * nr_total_params */
  137. struct dev_ext_attribute *event_ea;
  138. atomic_t active_cnt;
  139. void *load_owner;
  140. struct config_group *fs_group;
  141. bool available;
  142. };
  143. /**
  144. * config register instance - part of a loaded feature.
  145. * maps register values to csdev driver structures
  146. *
  147. * @reg_desc: value to use when setting feature on device / store for
  148. * readback of volatile values.
  149. * @driver_regval: pointer to internal driver element used to set the value
  150. * in hardware.
  151. */
  152. struct cscfg_regval_csdev {
  153. struct cscfg_regval_desc reg_desc;
  154. void *driver_regval;
  155. };
  156. /**
  157. * config parameter instance - part of a loaded feature.
  158. *
  159. * @feat_csdev: parent feature
  160. * @reg_csdev: register value updated by this parameter.
  161. * @current_value: current value of parameter - may be set by user via
  162. * sysfs, or modified during device operation.
  163. * @val64: true if 64 bit value
  164. */
  165. struct cscfg_parameter_csdev {
  166. struct cscfg_feature_csdev *feat_csdev;
  167. struct cscfg_regval_csdev *reg_csdev;
  168. u64 current_value;
  169. bool val64;
  170. };
  171. /**
  172. * Feature instance loaded into a CoreSight device.
  173. *
  174. * When a feature is loaded into a specific device, then this structure holds
  175. * the connections between the register / parameter values used and the
  176. * internal data structures that are written when the feature is enabled.
  177. *
  178. * Since applying a feature modifies internal data structures in the device,
  179. * then we have a reference to the device spinlock to protect access to these
  180. * structures (@drv_spinlock).
  181. *
  182. * @feat_desc: pointer to the static descriptor for this feature.
  183. * @csdev: parent CoreSight device instance.
  184. * @node: list entry into feature list for this device.
  185. * @drv_spinlock: device spinlock for access to driver register data.
  186. * @nr_params: number of parameters.
  187. * @params_csdev: current parameter values on this device
  188. * @nr_regs: number of registers to be programmed.
  189. * @regs_csdev: Programming details for the registers
  190. */
  191. struct cscfg_feature_csdev {
  192. const struct cscfg_feature_desc *feat_desc;
  193. struct coresight_device *csdev;
  194. struct list_head node;
  195. spinlock_t *drv_spinlock;
  196. int nr_params;
  197. struct cscfg_parameter_csdev *params_csdev;
  198. int nr_regs;
  199. struct cscfg_regval_csdev *regs_csdev;
  200. };
  201. /**
  202. * Configuration instance when loaded into a CoreSight device.
  203. *
  204. * The instance contains references to loaded features on this device that are
  205. * used by the configuration.
  206. *
  207. * @config_desc:reference to the descriptor for this configuration
  208. * @csdev: parent coresight device for this configuration instance.
  209. * @enabled: true if configuration is enabled on this device.
  210. * @node: list entry within the coresight device
  211. * @nr_feat: Number of features on this device that are used in the
  212. * configuration.
  213. * @feats_csdev:references to the device features to enable.
  214. */
  215. struct cscfg_config_csdev {
  216. const struct cscfg_config_desc *config_desc;
  217. struct coresight_device *csdev;
  218. bool enabled;
  219. struct list_head node;
  220. int nr_feat;
  221. struct cscfg_feature_csdev *feats_csdev[];
  222. };
  223. /**
  224. * Coresight device operations.
  225. *
  226. * Registered coresight devices provide these operations to manage feature
  227. * instances compatible with the device hardware and drivers
  228. *
  229. * @load_feat: Pass a feature descriptor into the device and create the
  230. * loaded feature instance (struct cscfg_feature_csdev).
  231. */
  232. struct cscfg_csdev_feat_ops {
  233. int (*load_feat)(struct coresight_device *csdev,
  234. struct cscfg_feature_csdev *feat_csdev);
  235. };
  236. /* coresight config helper functions*/
  237. /* enable / disable config on a device - called with appropriate locks set.*/
  238. int cscfg_csdev_enable_config(struct cscfg_config_csdev *config_csdev, int preset);
  239. void cscfg_csdev_disable_config(struct cscfg_config_csdev *config_csdev);
  240. /* reset a feature to default values */
  241. void cscfg_reset_feat(struct cscfg_feature_csdev *feat_csdev);
  242. #endif /* _CORESIGHT_CORESIGHT_CONFIG_H */