/* protect the cscsg_data and device */ static DEFINE_MUTEX(cscfg_mutex);
/* only one of these */ staticstruct cscfg_manager *cscfg_mgr;
/* load features and configuations into the lists */
/* get name feature instance from a coresight device list of features */ staticstruct cscfg_feature_csdev *
cscfg_get_feat_csdev(struct coresight_device *csdev, constchar *name)
{ struct cscfg_feature_csdev *feat_csdev = NULL;
/* allocate the device config instance - with max number of used features */ staticstruct cscfg_config_csdev *
cscfg_alloc_csdev_cfg(struct coresight_device *csdev, int nr_feats)
{ struct cscfg_config_csdev *config_csdev = NULL; struct device *dev = csdev->dev.parent;
/* this is being allocated using the devm for the coresight device */
config_csdev = devm_kzalloc(dev,
offsetof(struct cscfg_config_csdev, feats_csdev[nr_feats]),
GFP_KERNEL); if (!config_csdev) return NULL;
/* Load a config into a device if there are any feature matches between config and device */ staticint cscfg_add_csdev_cfg(struct coresight_device *csdev, struct cscfg_config_desc *config_desc)
{ struct cscfg_config_csdev *config_csdev = NULL; struct cscfg_feature_csdev *feat_csdev; unsignedlong flags; int i;
/* look at each required feature and see if it matches any feature on the device */ for (i = 0; i < config_desc->nr_feat_refs; i++) { /* look for a matching name */
feat_csdev = cscfg_get_feat_csdev(csdev, config_desc->feat_ref_names[i]); if (feat_csdev) { /* *Atleastonefeatureonthisdevicematchestheconfig *addaconfiginstancetothedeviceandareferencetothefeature.
*/ if (!config_csdev) {
config_csdev = cscfg_alloc_csdev_cfg(csdev,
config_desc->nr_feat_refs); if (!config_csdev) return -ENOMEM;
config_csdev->config_desc = config_desc;
}
config_csdev->feats_csdev[config_csdev->nr_feat++] = feat_csdev;
}
} /* if matched features, add config to device.*/ if (config_csdev) {
raw_spin_lock_irqsave(&csdev->cscfg_csdev_lock, flags);
list_add(&config_csdev->node, &csdev->config_csdev_list);
raw_spin_unlock_irqrestore(&csdev->cscfg_csdev_lock, flags);
}
/* check feature list for a named feature - call with mutex locked. */ staticbool cscfg_match_list_feat(constchar *name)
{ struct cscfg_feature_desc *feat_desc;
/* check all feat needed for cfg are in the list - call with mutex locked. */ staticint cscfg_check_feat_for_cfg(struct cscfg_config_desc *config_desc)
{ int i;
for (i = 0; i < config_desc->nr_feat_refs; i++) if (!cscfg_match_list_feat(config_desc->feat_ref_names[i])) return -EINVAL; return0;
}
/* new feature must have unique name */
list_for_each_entry(feat_desc_exist, &cscfg_mgr->feat_desc_list, item) { if (!strcmp(feat_desc_exist->name, feat_desc->name)) return -EEXIST;
}
/* add feature to any matching registered devices */
err = cscfg_add_feat_to_csdevs(feat_desc); if (err) return err;
/* new configuration must have a unique name */
list_for_each_entry(config_desc_exist, &cscfg_mgr->config_desc_list, item) { if (!strcmp(config_desc_exist->name, config_desc->name)) return -EEXIST;
}
/* validate features are present */
err = cscfg_check_feat_for_cfg(config_desc); if (err) return err;
/* add config to any matching registered device */
err = cscfg_add_cfg_to_csdevs(config_desc); if (err) return err;
/* add config to perf fs to allow selection */
err = etm_perf_add_symlink_cscfg(cscfg_device(), config_desc); if (err) return err;
/* get a feature descriptor by name */ conststruct cscfg_feature_desc *cscfg_get_named_feat_desc(constchar *name)
{ conststruct cscfg_feature_desc *feat_desc = NULL, *feat_desc_item;
/* remove from each csdev instance feature and config lists */
list_for_each_entry(csdev_item, &cscfg_mgr->csdev_desc_list, item) { /* *foreachcsdev,checktheloadedlistsandremoveif *referenceddescriptorisowned
*/
cscfg_remove_owned_csdev_configs(csdev_item->csdev, load_owner);
cscfg_remove_owned_csdev_features(csdev_item->csdev, load_owner);
}
/* remove from the config descriptor lists */
list_for_each_entry_safe(config_desc, cfg_tmp, &cscfg_mgr->config_desc_list, item) { if (config_desc->load_owner == load_owner) {
etm_perf_del_symlink_cscfg(config_desc);
list_del(&config_desc->item);
}
}
/* remove from the feature descriptor lists */
list_for_each_entry_safe(feat_desc, feat_tmp, &cscfg_mgr->feat_desc_list, item) { if (feat_desc->load_owner == load_owner) {
list_del(&feat_desc->item);
}
}
}
/* *loadthefeaturesandconfigstothelists-calledwithlistmutexheld
*/ staticint cscfg_load_owned_cfgs_feats(struct cscfg_config_desc **config_descs, struct cscfg_feature_desc **feat_descs, struct cscfg_load_owner_info *owner_info)
{ int i, err;
lockdep_assert_held(&cscfg_mutex);
/* load features first */ if (feat_descs) { for (i = 0; feat_descs[i]; i++) {
err = cscfg_load_feat(feat_descs[i]); if (err) {
pr_err("coresight-syscfg: Failed to load feature %s\n",
feat_descs[i]->name); return err;
}
feat_descs[i]->load_owner = owner_info;
}
}
/* next any configurations to check feature dependencies */ if (config_descs) { for (i = 0; config_descs[i]; i++) {
err = cscfg_load_config(config_descs[i]); if (err) {
pr_err("coresight-syscfg: Failed to load configuration %s\n",
config_descs[i]->name); return err;
}
config_descs[i]->load_owner = owner_info;
config_descs[i]->available = false;
}
} return0;
}
/* set configurations as available to activate at the end of the load process */ staticvoid cscfg_set_configs_available(struct cscfg_config_desc **config_descs)
{ int i;
lockdep_assert_held(&cscfg_mutex);
if (config_descs) { for (i = 0; config_descs[i]; i++)
config_descs[i]->available = true;
}
}
/* *Createandregistereachoftheconfigurationsandfeatureswithconfigfs. *Calledwithoutmutexbeingheld.
*/ staticint cscfg_fs_register_cfgs_feats(struct cscfg_config_desc **config_descs, struct cscfg_feature_desc **feat_descs)
{ int i, err;
if (feat_descs) { for (i = 0; feat_descs[i]; i++) {
err = cscfg_configfs_add_feature(feat_descs[i]); if (err) return err;
}
} if (config_descs) { for (i = 0; config_descs[i]; i++) {
err = cscfg_configfs_add_config(config_descs[i]); if (err) return err;
}
} return0;
}
/* first load and add to the lists */
err = cscfg_load_owned_cfgs_feats(config_descs, feat_descs, owner_info); if (err) goto err_clean_load;
/* add the load owner to the load order list */
list_add_tail(&owner_info->item, &cscfg_mgr->load_order_list); if (!list_is_singular(&cscfg_mgr->load_order_list)) { /* lock previous item in load order list */
err = cscfg_owner_get(list_prev_entry(owner_info, item)); if (err) goto err_clean_owner_list;
}
mutex_lock(&cscfg_mutex); if (cscfg_mgr->load_state != CSCFG_NONE) {
mutex_unlock(&cscfg_mutex); return -EBUSY;
}
/* unload op in progress also prevents activation of any config */
cscfg_mgr->load_state = CSCFG_UNLOAD;
/* cannot unload if anything is active */ if (atomic_read(&cscfg_mgr->sys_active_cnt)) {
err = -EBUSY; goto exit_unlock;
}
/* cannot unload if not last loaded in load order */ if (!list_empty(&cscfg_mgr->load_order_list)) {
load_list_item = list_last_entry(&cscfg_mgr->load_order_list, struct cscfg_load_owner_info, item); if (load_list_item != owner_info)
load_list_item = NULL;
}
if (!load_list_item) {
err = -EINVAL; goto exit_unlock;
}
/* remove from configfs - again outside the scope of the list mutex */
mutex_unlock(&cscfg_mutex);
cscfg_fs_unregister_cfgs_feats(owner_info);
mutex_lock(&cscfg_mutex);
/* unload everything from lists belonging to load_owner */
cscfg_unload_owned_cfgs_feats(owner_info);
/* remove from load order list */ if (!list_is_singular(&cscfg_mgr->load_order_list)) { /* unlock previous item in load order list */
cscfg_owner_put(list_prev_entry(owner_info, item));
}
list_del(&owner_info->item);
/* Add coresight device to list and copy its matching info */ staticint cscfg_list_add_csdev(struct coresight_device *csdev,
u32 match_flags, struct cscfg_csdev_feat_ops *ops)
{ struct cscfg_registered_csdev *csdev_item;
/* allocate the list entry structure */
csdev_item = kzalloc(sizeof(struct cscfg_registered_csdev), GFP_KERNEL); if (!csdev_item) return -ENOMEM;
/* remove a coresight device from the list and free data */ staticvoid cscfg_list_remove_csdev(struct coresight_device *csdev)
{ struct cscfg_registered_csdev *csdev_item, *tmp;
/** *cscfg_register_csdev-registeracoresightdevicewiththesyscfgmanager. * *Registersthecoresightdevicewiththesystem.@match_flagsusedtocheck *ifthedeviceisamatchforregisteredfeatures.Anycurrentlyregistered *configurationsandfeaturesthatmatchthedevicewillbeloadedontoit. * *@csdev:Thecoresightdevicetoregister. *@match_flags:Matchinginformationtoloadfeatures. *@ops:Standardoperationssupportedbythedevice.
*/ int cscfg_register_csdev(struct coresight_device *csdev,
u32 match_flags, struct cscfg_csdev_feat_ops *ops)
{ int ret = 0;
mutex_lock(&cscfg_mutex);
/* add device to list of registered devices */
ret = cscfg_list_add_csdev(csdev, match_flags, ops); if (ret) goto reg_csdev_unlock;
/* now load any registered features and configs matching the device. */
ret = cscfg_add_feats_csdev(csdev, match_flags, ops); if (ret) {
cscfg_list_remove_csdev(csdev); goto reg_csdev_unlock;
}
ret = cscfg_add_cfgs_csdev(csdev); if (ret) {
cscfg_list_remove_csdev(csdev); goto reg_csdev_unlock;
}
staticbool cscfg_config_desc_get(struct cscfg_config_desc *config_desc)
{ if (!atomic_fetch_inc(&config_desc->active_cnt)) { /* must ensure that config cannot be unloaded in use */ if (unlikely(cscfg_owner_get(config_desc->load_owner))) {
atomic_dec(&config_desc->active_cnt); returnfalse;
}
}
returntrue;
}
staticvoid cscfg_config_desc_put(struct cscfg_config_desc *config_desc)
{ if (!atomic_dec_return(&config_desc->active_cnt))
cscfg_owner_put(config_desc->load_owner);
}
if (cscfg_mgr->load_state == CSCFG_UNLOAD) return -EBUSY;
list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { if ((unsignedlong)config_desc->event_ea->var == cfg_hash) { /* if we happen upon a partly loaded config, can't use it */ if (config_desc->available == false) return -EBUSY;
if (!cscfg_config_desc_get(config_desc)) {
err = -EINVAL; break;
}
if (activate) { /* cannot be a current active value to activate this */ if (cscfg_mgr->sysfs_active_config) {
err = -EBUSY; goto exit_unlock;
}
err = _cscfg_activate_config(cfg_hash); if (!err)
cscfg_mgr->sysfs_active_config = cfg_hash;
} else { /* disable if matching current value */ if (cscfg_mgr->sysfs_active_config == cfg_hash) {
_cscfg_deactivate_config(cfg_hash);
cscfg_mgr->sysfs_active_config = 0;
} else
err = -EINVAL;
}
/* true if there was an enabled active config */ if (config_csdev) {
cscfg_csdev_disable_config(config_csdev);
cscfg_config_desc_put(config_csdev->config_desc);
}
}
EXPORT_SYMBOL_GPL(cscfg_csdev_disable_active_config);
/* Initialise system configuration management device. */
/* Must have a release function or the kernel will complain on module unload */ staticvoid cscfg_dev_release(struct device *dev)
{
mutex_lock(&cscfg_mutex);
kfree(cscfg_mgr);
cscfg_mgr = NULL;
mutex_unlock(&cscfg_mutex);
}
/* a device is needed to "own" some kernel elements such as sysfs entries. */ staticint cscfg_create_device(void)
{ struct device *dev; int err = -ENOMEM;
mutex_lock(&cscfg_mutex); if (cscfg_mgr) {
err = -EINVAL; goto create_dev_exit_unlock;
}
cscfg_mgr = kzalloc(sizeof(struct cscfg_manager), GFP_KERNEL); if (!cscfg_mgr) goto create_dev_exit_unlock;
/* *grabthemutex-eventhoughweareexiting,someconfigfsfiles *maystillbelivetillwedumpthem,soensurelistdatais *protectedfromaracecondition.
*/
mutex_lock(&cscfg_mutex); while (!list_empty(&cscfg_mgr->load_order_list)) {
/* remove in reverse order of loading */
owner_info = list_last_entry(&cscfg_mgr->load_order_list, struct cscfg_load_owner_info, item);
/* action according to type */ switch (owner_info->type) { case CSCFG_OWNER_PRELOAD: /* *preloadeddescriptorsarestaticallyallocatedin *thismodule-justneedtounloaddynamicitemsfrom *csdevlists,andremovefromconfigfsdirectories.
*/
pr_info("cscfg: unloading preloaded configurations\n"); break;
case CSCFG_OWNER_MODULE: /* *thisisanerror-theloadablemodulemusthavebeenunloadedprior *tothecoresightmoduleunload.Thereforethatmodulehasnot *correctlyunloadedconfigsinitsownexitcode. *Nothingtodootherthanemitanerrorstringasthestaticdescriptor *referencesweneedtounloadwillhavedisappearedwiththemodule.
*/
pr_err("cscfg: ERROR: prior module failed to unload configuration\n"); goto list_remove;
}
/* remove from configfs - outside the scope of the list mutex */
mutex_unlock(&cscfg_mutex);
cscfg_fs_unregister_cfgs_feats(owner_info);
mutex_lock(&cscfg_mutex);
/* Next unload from csdev lists. */
cscfg_unload_owned_cfgs_feats(owner_info);
list_remove: /* remove from load order list */
list_del(&owner_info->item);
}
mutex_unlock(&cscfg_mutex);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.