1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2020 Linaro Limited, All rights reserved.
7 #ifndef _CORESIGHT_CORESIGHT_CONFIG_H
8 #define _CORESIGHT_CORESIGHT_CONFIG_H
10 #include <linux/coresight.h>
11 #include <linux/types.h>
13 /* CoreSight Configuration Management - component and system wide configuration */
16 * Register type flags for register value descriptor:
17 * describe how the value is interpreted, and handled.
19 #define CS_CFG_REG_TYPE_STD 0x80 /* reg is standard reg */
20 #define CS_CFG_REG_TYPE_RESOURCE 0x40 /* reg is a resource */
21 #define CS_CFG_REG_TYPE_VAL_PARAM 0x08 /* reg value uses param */
22 #define CS_CFG_REG_TYPE_VAL_MASK 0x04 /* reg value bit masked */
23 #define CS_CFG_REG_TYPE_VAL_64BIT 0x02 /* reg value 64 bit */
24 #define CS_CFG_REG_TYPE_VAL_SAVE 0x01 /* reg value save on disable */
27 * flags defining what device class a feature will match to when processing a
28 * system configuration - used by config data and devices.
30 #define CS_CFG_MATCH_CLASS_SRC_ALL 0x0001 /* match any source */
31 #define CS_CFG_MATCH_CLASS_SRC_ETM4 0x0002 /* match any ETMv4 device */
33 /* flags defining device instance matching - used in config match desc data. */
34 #define CS_CFG_MATCH_INST_ANY 0x80000000 /* any instance of a class */
37 * Limit number of presets in a configuration
38 * This is related to the number of bits (4) we use to select the preset on
39 * the perf command line. Preset 0 is always none selected.
40 * See PMU_FORMAT_ATTR(preset, "config:0-3") in coresight-etm-perf.c
42 #define CS_CFG_CONFIG_PRESET_MAX 15
45 * Parameter descriptor for a device feature.
47 * @name: Name of parameter.
48 * @value: Initial or default value.
50 struct cscfg_parameter_desc {
56 * Representation of register value and a descriptor of register usage.
58 * Used as a descriptor in the feature descriptors.
59 * Used as a value in when in a feature loading into a csdev.
61 * Supports full 64 bit register value, or 32 bit value with optional mask
64 * @type: define register usage and interpretation.
65 * @offset: the address offset for register in the hardware device (per device specification).
66 * @hw_info: optional hardware device type specific information. (ETM / CTI specific etc)
67 * @val64: 64 bit value.
68 * @val32: 32 bit value.
69 * @mask32: 32 bit mask when using 32 bit value to access device register - if mask type.
70 * @param_idx: parameter index value into parameter array if param type.
72 struct cscfg_regval_desc {
89 * Device feature descriptor - combination of registers and parameters to
90 * program a device to implement a specific complex function.
92 * @name: feature name.
93 * @description: brief description of the feature.
95 * @match_flags: matching information if loading into a device
96 * @nr_params: number of parameters used.
97 * @params_desc: array of parameters used.
98 * @nr_regs: number of registers used.
99 * @regs_desc: array of registers used.
101 struct cscfg_feature_desc {
103 const char *description;
104 struct list_head item;
107 struct cscfg_parameter_desc *params_desc;
109 struct cscfg_regval_desc *regs_desc;
113 * Configuration descriptor - describes selectable system configuration.
115 * A configuration describes device features in use, and may provide preset
116 * values for the parameters in those features.
118 * A single set of presets is the sum of the parameters declared by
119 * all the features in use - this value is @nr_total_params.
121 * @name: name of the configuration - used for selection.
122 * @description: description of the purpose of the configuration.
124 * @nr_feat_refs: Number of features used in this configuration.
125 * @feat_ref_names: references to features used in this configuration.
126 * @nr_presets: Number of sets of presets supplied by this configuration.
127 * @nr_total_params: Sum of all parameters declared by used features
128 * @presets: Array of preset values.
129 * @event_ea: Extended attribute for perf event value
130 * @active_cnt: ref count for activate on this configuration.
133 struct cscfg_config_desc {
135 const char *description;
136 struct list_head item;
138 const char **feat_ref_names;
141 const u64 *presets; /* nr_presets * nr_total_params */
142 struct dev_ext_attribute *event_ea;
147 * config register instance - part of a loaded feature.
148 * maps register values to csdev driver structures
150 * @reg_desc: value to use when setting feature on device / store for
151 * readback of volatile values.
152 * @driver_regval: pointer to internal driver element used to set the value
155 struct cscfg_regval_csdev {
156 struct cscfg_regval_desc reg_desc;
161 * config parameter instance - part of a loaded feature.
163 * @feat_csdev: parent feature
164 * @reg_csdev: register value updated by this parameter.
165 * @current_value: current value of parameter - may be set by user via
166 * sysfs, or modified during device operation.
167 * @val64: true if 64 bit value
169 struct cscfg_parameter_csdev {
170 struct cscfg_feature_csdev *feat_csdev;
171 struct cscfg_regval_csdev *reg_csdev;
177 * Feature instance loaded into a CoreSight device.
179 * When a feature is loaded into a specific device, then this structure holds
180 * the connections between the register / parameter values used and the
181 * internal data structures that are written when the feature is enabled.
183 * Since applying a feature modifies internal data structures in the device,
184 * then we have a reference to the device spinlock to protect access to these
185 * structures (@drv_spinlock).
187 * @feat_desc: pointer to the static descriptor for this feature.
188 * @csdev: parent CoreSight device instance.
189 * @node: list entry into feature list for this device.
190 * @drv_spinlock: device spinlock for access to driver register data.
191 * @nr_params: number of parameters.
192 * @params_csdev: current parameter values on this device
193 * @nr_regs: number of registers to be programmed.
194 * @regs_csdev: Programming details for the registers
196 struct cscfg_feature_csdev {
197 const struct cscfg_feature_desc *feat_desc;
198 struct coresight_device *csdev;
199 struct list_head node;
200 spinlock_t *drv_spinlock;
202 struct cscfg_parameter_csdev *params_csdev;
204 struct cscfg_regval_csdev *regs_csdev;
208 * Configuration instance when loaded into a CoreSight device.
210 * The instance contains references to loaded features on this device that are
211 * used by the configuration.
213 * @config_desc:reference to the descriptor for this configuration
214 * @csdev: parent coresight device for this configuration instance.
215 * @enabled: true if configuration is enabled on this device.
216 * @node: list entry within the coresight device
217 * @nr_feat: Number of features on this device that are used in the
219 * @feats_csdev:references to the device features to enable.
221 struct cscfg_config_csdev {
222 const struct cscfg_config_desc *config_desc;
223 struct coresight_device *csdev;
225 struct list_head node;
227 struct cscfg_feature_csdev *feats_csdev[0];
231 * Coresight device operations.
233 * Registered coresight devices provide these operations to manage feature
234 * instances compatible with the device hardware and drivers
236 * @load_feat: Pass a feature descriptor into the device and create the
237 * loaded feature instance (struct cscfg_feature_csdev).
239 struct cscfg_csdev_feat_ops {
240 int (*load_feat)(struct coresight_device *csdev,
241 struct cscfg_feature_csdev *feat_csdev);
244 /* coresight config helper functions*/
246 /* enable / disable config on a device - called with appropriate locks set.*/
247 int cscfg_csdev_enable_config(struct cscfg_config_csdev *config_csdev, int preset);
248 void cscfg_csdev_disable_config(struct cscfg_config_csdev *config_csdev);
250 /* reset a feature to default values */
251 void cscfg_reset_feat(struct cscfg_feature_csdev *feat_csdev);
253 #endif /* _CORESIGHT_CORESIGHT_CONFIG_H */