185e2414cSMike Leach /* SPDX-License-Identifier: GPL-2.0 */ 285e2414cSMike Leach /* 385e2414cSMike Leach * Copyright (c) 2020 Linaro Limited, All rights reserved. 485e2414cSMike Leach * Author: Mike Leach <mike.leach@linaro.org> 585e2414cSMike Leach */ 685e2414cSMike Leach 785e2414cSMike Leach #ifndef _CORESIGHT_CORESIGHT_CONFIG_H 885e2414cSMike Leach #define _CORESIGHT_CORESIGHT_CONFIG_H 985e2414cSMike Leach 1085e2414cSMike Leach #include <linux/coresight.h> 1185e2414cSMike Leach #include <linux/types.h> 1285e2414cSMike Leach 1385e2414cSMike Leach /* CoreSight Configuration Management - component and system wide configuration */ 1485e2414cSMike Leach 1585e2414cSMike Leach /* 1685e2414cSMike Leach * Register type flags for register value descriptor: 1785e2414cSMike Leach * describe how the value is interpreted, and handled. 1885e2414cSMike Leach */ 1985e2414cSMike Leach #define CS_CFG_REG_TYPE_STD 0x80 /* reg is standard reg */ 2085e2414cSMike Leach #define CS_CFG_REG_TYPE_RESOURCE 0x40 /* reg is a resource */ 2185e2414cSMike Leach #define CS_CFG_REG_TYPE_VAL_PARAM 0x08 /* reg value uses param */ 2285e2414cSMike Leach #define CS_CFG_REG_TYPE_VAL_MASK 0x04 /* reg value bit masked */ 2385e2414cSMike Leach #define CS_CFG_REG_TYPE_VAL_64BIT 0x02 /* reg value 64 bit */ 2485e2414cSMike Leach #define CS_CFG_REG_TYPE_VAL_SAVE 0x01 /* reg value save on disable */ 2585e2414cSMike Leach 2685e2414cSMike Leach /* 2785e2414cSMike Leach * flags defining what device class a feature will match to when processing a 2885e2414cSMike Leach * system configuration - used by config data and devices. 2985e2414cSMike Leach */ 3085e2414cSMike Leach #define CS_CFG_MATCH_CLASS_SRC_ALL 0x0001 /* match any source */ 3185e2414cSMike Leach #define CS_CFG_MATCH_CLASS_SRC_ETM4 0x0002 /* match any ETMv4 device */ 3285e2414cSMike Leach 3385e2414cSMike Leach /* flags defining device instance matching - used in config match desc data. */ 3485e2414cSMike Leach #define CS_CFG_MATCH_INST_ANY 0x80000000 /* any instance of a class */ 3585e2414cSMike Leach 3685e2414cSMike Leach /* 3785e2414cSMike Leach * Limit number of presets in a configuration 3885e2414cSMike Leach * This is related to the number of bits (4) we use to select the preset on 3985e2414cSMike Leach * the perf command line. Preset 0 is always none selected. 4085e2414cSMike Leach * See PMU_FORMAT_ATTR(preset, "config:0-3") in coresight-etm-perf.c 4185e2414cSMike Leach */ 4285e2414cSMike Leach #define CS_CFG_CONFIG_PRESET_MAX 15 4385e2414cSMike Leach 4485e2414cSMike Leach /** 4585e2414cSMike Leach * Parameter descriptor for a device feature. 4685e2414cSMike Leach * 4785e2414cSMike Leach * @name: Name of parameter. 4885e2414cSMike Leach * @value: Initial or default value. 4985e2414cSMike Leach */ 5085e2414cSMike Leach struct cscfg_parameter_desc { 5185e2414cSMike Leach const char *name; 5285e2414cSMike Leach u64 value; 5385e2414cSMike Leach }; 5485e2414cSMike Leach 5585e2414cSMike Leach /** 5685e2414cSMike Leach * Representation of register value and a descriptor of register usage. 5785e2414cSMike Leach * 5885e2414cSMike Leach * Used as a descriptor in the feature descriptors. 5985e2414cSMike Leach * Used as a value in when in a feature loading into a csdev. 6085e2414cSMike Leach * 6185e2414cSMike Leach * Supports full 64 bit register value, or 32 bit value with optional mask 6285e2414cSMike Leach * value. 6385e2414cSMike Leach * 6485e2414cSMike Leach * @type: define register usage and interpretation. 6585e2414cSMike Leach * @offset: the address offset for register in the hardware device (per device specification). 6685e2414cSMike Leach * @hw_info: optional hardware device type specific information. (ETM / CTI specific etc) 6785e2414cSMike Leach * @val64: 64 bit value. 6885e2414cSMike Leach * @val32: 32 bit value. 6985e2414cSMike Leach * @mask32: 32 bit mask when using 32 bit value to access device register - if mask type. 7085e2414cSMike Leach * @param_idx: parameter index value into parameter array if param type. 7185e2414cSMike Leach */ 7285e2414cSMike Leach struct cscfg_regval_desc { 7385e2414cSMike Leach struct { 7485e2414cSMike Leach u32 type:8; 7585e2414cSMike Leach u32 offset:12; 7685e2414cSMike Leach u32 hw_info:12; 7785e2414cSMike Leach }; 7885e2414cSMike Leach union { 7985e2414cSMike Leach u64 val64; 8085e2414cSMike Leach struct { 8185e2414cSMike Leach u32 val32; 8285e2414cSMike Leach u32 mask32; 8385e2414cSMike Leach }; 8485e2414cSMike Leach u32 param_idx; 8585e2414cSMike Leach }; 8685e2414cSMike Leach }; 8785e2414cSMike Leach 8885e2414cSMike Leach /** 8985e2414cSMike Leach * Device feature descriptor - combination of registers and parameters to 9085e2414cSMike Leach * program a device to implement a specific complex function. 9185e2414cSMike Leach * 9285e2414cSMike Leach * @name: feature name. 9385e2414cSMike Leach * @description: brief description of the feature. 9485e2414cSMike Leach * @item: List entry. 9585e2414cSMike Leach * @match_flags: matching information if loading into a device 9685e2414cSMike Leach * @nr_params: number of parameters used. 9785e2414cSMike Leach * @params_desc: array of parameters used. 9885e2414cSMike Leach * @nr_regs: number of registers used. 9985e2414cSMike Leach * @regs_desc: array of registers used. 100da7000e8SMike Leach * @load_owner: handle to load owner for dynamic load and unload of features. 10102bd588eSMike Leach * @fs_group: reference to configfs group for dynamic unload. 10285e2414cSMike Leach */ 10385e2414cSMike Leach struct cscfg_feature_desc { 10485e2414cSMike Leach const char *name; 10585e2414cSMike Leach const char *description; 10685e2414cSMike Leach struct list_head item; 10785e2414cSMike Leach u32 match_flags; 10885e2414cSMike Leach int nr_params; 10985e2414cSMike Leach struct cscfg_parameter_desc *params_desc; 11085e2414cSMike Leach int nr_regs; 11185e2414cSMike Leach struct cscfg_regval_desc *regs_desc; 112da7000e8SMike Leach void *load_owner; 11302bd588eSMike Leach struct config_group *fs_group; 11485e2414cSMike Leach }; 11585e2414cSMike Leach 11685e2414cSMike Leach /** 11785e2414cSMike Leach * Configuration descriptor - describes selectable system configuration. 11885e2414cSMike Leach * 11985e2414cSMike Leach * A configuration describes device features in use, and may provide preset 12085e2414cSMike Leach * values for the parameters in those features. 12185e2414cSMike Leach * 12285e2414cSMike Leach * A single set of presets is the sum of the parameters declared by 12385e2414cSMike Leach * all the features in use - this value is @nr_total_params. 12485e2414cSMike Leach * 12585e2414cSMike Leach * @name: name of the configuration - used for selection. 12685e2414cSMike Leach * @description: description of the purpose of the configuration. 12785e2414cSMike Leach * @item: list entry. 12885e2414cSMike Leach * @nr_feat_refs: Number of features used in this configuration. 12985e2414cSMike Leach * @feat_ref_names: references to features used in this configuration. 13085e2414cSMike Leach * @nr_presets: Number of sets of presets supplied by this configuration. 13185e2414cSMike Leach * @nr_total_params: Sum of all parameters declared by used features 13285e2414cSMike Leach * @presets: Array of preset values. 13394d2bac5SMike Leach * @event_ea: Extended attribute for perf event value 134f8cce2ffSMike Leach * @active_cnt: ref count for activate on this configuration. 135da7000e8SMike Leach * @load_owner: handle to load owner for dynamic load and unload of configs. 13602bd588eSMike Leach * @fs_group: reference to configfs group for dynamic unload. 137*8add26f7SMike Leach * @available: config can be activated - multi-stage load sets true on completion. 13885e2414cSMike Leach */ 13985e2414cSMike Leach struct cscfg_config_desc { 14085e2414cSMike Leach const char *name; 14185e2414cSMike Leach const char *description; 14285e2414cSMike Leach struct list_head item; 14385e2414cSMike Leach int nr_feat_refs; 14485e2414cSMike Leach const char **feat_ref_names; 14585e2414cSMike Leach int nr_presets; 14685e2414cSMike Leach int nr_total_params; 14785e2414cSMike Leach const u64 *presets; /* nr_presets * nr_total_params */ 14894d2bac5SMike Leach struct dev_ext_attribute *event_ea; 149f8cce2ffSMike Leach atomic_t active_cnt; 150da7000e8SMike Leach void *load_owner; 15102bd588eSMike Leach struct config_group *fs_group; 152*8add26f7SMike Leach bool available; 15385e2414cSMike Leach }; 15485e2414cSMike Leach 15542ff700fSMike Leach /** 15642ff700fSMike Leach * config register instance - part of a loaded feature. 15742ff700fSMike Leach * maps register values to csdev driver structures 15842ff700fSMike Leach * 15942ff700fSMike Leach * @reg_desc: value to use when setting feature on device / store for 16042ff700fSMike Leach * readback of volatile values. 16142ff700fSMike Leach * @driver_regval: pointer to internal driver element used to set the value 16242ff700fSMike Leach * in hardware. 16342ff700fSMike Leach */ 16442ff700fSMike Leach struct cscfg_regval_csdev { 16542ff700fSMike Leach struct cscfg_regval_desc reg_desc; 16642ff700fSMike Leach void *driver_regval; 16742ff700fSMike Leach }; 16842ff700fSMike Leach 16942ff700fSMike Leach /** 17042ff700fSMike Leach * config parameter instance - part of a loaded feature. 17142ff700fSMike Leach * 17242ff700fSMike Leach * @feat_csdev: parent feature 17342ff700fSMike Leach * @reg_csdev: register value updated by this parameter. 17442ff700fSMike Leach * @current_value: current value of parameter - may be set by user via 17542ff700fSMike Leach * sysfs, or modified during device operation. 17642ff700fSMike Leach * @val64: true if 64 bit value 17742ff700fSMike Leach */ 17842ff700fSMike Leach struct cscfg_parameter_csdev { 17942ff700fSMike Leach struct cscfg_feature_csdev *feat_csdev; 18042ff700fSMike Leach struct cscfg_regval_csdev *reg_csdev; 18142ff700fSMike Leach u64 current_value; 18242ff700fSMike Leach bool val64; 18342ff700fSMike Leach }; 18442ff700fSMike Leach 18542ff700fSMike Leach /** 18642ff700fSMike Leach * Feature instance loaded into a CoreSight device. 18742ff700fSMike Leach * 18842ff700fSMike Leach * When a feature is loaded into a specific device, then this structure holds 18942ff700fSMike Leach * the connections between the register / parameter values used and the 19042ff700fSMike Leach * internal data structures that are written when the feature is enabled. 19142ff700fSMike Leach * 19242ff700fSMike Leach * Since applying a feature modifies internal data structures in the device, 19342ff700fSMike Leach * then we have a reference to the device spinlock to protect access to these 19442ff700fSMike Leach * structures (@drv_spinlock). 19542ff700fSMike Leach * 19642ff700fSMike Leach * @feat_desc: pointer to the static descriptor for this feature. 19742ff700fSMike Leach * @csdev: parent CoreSight device instance. 19842ff700fSMike Leach * @node: list entry into feature list for this device. 19942ff700fSMike Leach * @drv_spinlock: device spinlock for access to driver register data. 20042ff700fSMike Leach * @nr_params: number of parameters. 20142ff700fSMike Leach * @params_csdev: current parameter values on this device 20242ff700fSMike Leach * @nr_regs: number of registers to be programmed. 20342ff700fSMike Leach * @regs_csdev: Programming details for the registers 20442ff700fSMike Leach */ 20542ff700fSMike Leach struct cscfg_feature_csdev { 20642ff700fSMike Leach const struct cscfg_feature_desc *feat_desc; 20742ff700fSMike Leach struct coresight_device *csdev; 20842ff700fSMike Leach struct list_head node; 20942ff700fSMike Leach spinlock_t *drv_spinlock; 21042ff700fSMike Leach int nr_params; 21142ff700fSMike Leach struct cscfg_parameter_csdev *params_csdev; 21242ff700fSMike Leach int nr_regs; 21342ff700fSMike Leach struct cscfg_regval_csdev *regs_csdev; 21442ff700fSMike Leach }; 21542ff700fSMike Leach 21642ff700fSMike Leach /** 21742ff700fSMike Leach * Configuration instance when loaded into a CoreSight device. 21842ff700fSMike Leach * 21942ff700fSMike Leach * The instance contains references to loaded features on this device that are 22042ff700fSMike Leach * used by the configuration. 22142ff700fSMike Leach * 22242ff700fSMike Leach * @config_desc:reference to the descriptor for this configuration 22342ff700fSMike Leach * @csdev: parent coresight device for this configuration instance. 22442ff700fSMike Leach * @enabled: true if configuration is enabled on this device. 22542ff700fSMike Leach * @node: list entry within the coresight device 22642ff700fSMike Leach * @nr_feat: Number of features on this device that are used in the 22742ff700fSMike Leach * configuration. 22842ff700fSMike Leach * @feats_csdev:references to the device features to enable. 22942ff700fSMike Leach */ 23042ff700fSMike Leach struct cscfg_config_csdev { 23142ff700fSMike Leach const struct cscfg_config_desc *config_desc; 23242ff700fSMike Leach struct coresight_device *csdev; 23342ff700fSMike Leach bool enabled; 23442ff700fSMike Leach struct list_head node; 23542ff700fSMike Leach int nr_feat; 2365224f790SGustavo A. R. Silva struct cscfg_feature_csdev *feats_csdev[]; 23742ff700fSMike Leach }; 23842ff700fSMike Leach 23942ff700fSMike Leach /** 24042ff700fSMike Leach * Coresight device operations. 24142ff700fSMike Leach * 24242ff700fSMike Leach * Registered coresight devices provide these operations to manage feature 24342ff700fSMike Leach * instances compatible with the device hardware and drivers 24442ff700fSMike Leach * 24542ff700fSMike Leach * @load_feat: Pass a feature descriptor into the device and create the 24642ff700fSMike Leach * loaded feature instance (struct cscfg_feature_csdev). 24742ff700fSMike Leach */ 24842ff700fSMike Leach struct cscfg_csdev_feat_ops { 24942ff700fSMike Leach int (*load_feat)(struct coresight_device *csdev, 25042ff700fSMike Leach struct cscfg_feature_csdev *feat_csdev); 25142ff700fSMike Leach }; 25242ff700fSMike Leach 253f53e93acSMike Leach /* coresight config helper functions*/ 254f53e93acSMike Leach 255f53e93acSMike Leach /* enable / disable config on a device - called with appropriate locks set.*/ 256f53e93acSMike Leach int cscfg_csdev_enable_config(struct cscfg_config_csdev *config_csdev, int preset); 257f53e93acSMike Leach void cscfg_csdev_disable_config(struct cscfg_config_csdev *config_csdev); 258f53e93acSMike Leach 259f53e93acSMike Leach /* reset a feature to default values */ 260f53e93acSMike Leach void cscfg_reset_feat(struct cscfg_feature_csdev *feat_csdev); 261f53e93acSMike Leach 26285e2414cSMike Leach #endif /* _CORESIGHT_CORESIGHT_CONFIG_H */ 263