Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

coresight: configuration: Update API to introduce load owner concept

Update the existing load API to introduce a "load owner" concept.

This allows the tracking of the loaded configurations and features against
the loading owner type, to allow later unload according to owner.

A list of loaded configurations by owner is created.

The load owner infrastructure will be used in following patches
to implement dynanic load and unload, alongside dependency tracking.

Signed-off-by: Mike Leach <mike.leach@linaro.org>
Link: https://lore.kernel.org/r/20211124200038.28662-2-mike.leach@linaro.org
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

authored by

Mike Leach and committed by
Mathieu Poirier
da7000e8 66bd1333

+56 -8
+7 -2
drivers/hwtracing/coresight/coresight-cfg-preload.c
··· 24 24 NULL 25 25 }; 26 26 27 + static struct cscfg_load_owner_info preload_owner = { 28 + .type = CSCFG_OWNER_PRELOAD, 29 + }; 30 + 27 31 /* preload called on initialisation */ 28 - int cscfg_preload(void) 32 + int cscfg_preload(void *owner_handle) 29 33 { 30 - return cscfg_load_config_sets(preload_cfgs, preload_feats); 34 + preload_owner.owner_handle = owner_handle; 35 + return cscfg_load_config_sets(preload_cfgs, preload_feats, &preload_owner); 31 36 }
+4 -1
drivers/hwtracing/coresight/coresight-config.h
··· 97 97 * @params_desc: array of parameters used. 98 98 * @nr_regs: number of registers used. 99 99 * @regs_desc: array of registers used. 100 + * @load_owner: handle to load owner for dynamic load and unload of features. 100 101 */ 101 102 struct cscfg_feature_desc { 102 103 const char *name; ··· 108 107 struct cscfg_parameter_desc *params_desc; 109 108 int nr_regs; 110 109 struct cscfg_regval_desc *regs_desc; 110 + void *load_owner; 111 111 }; 112 112 113 113 /** ··· 130 128 * @presets: Array of preset values. 131 129 * @event_ea: Extended attribute for perf event value 132 130 * @active_cnt: ref count for activate on this configuration. 133 - * 131 + * @load_owner: handle to load owner for dynamic load and unload of configs. 134 132 */ 135 133 struct cscfg_config_desc { 136 134 const char *name; ··· 143 141 const u64 *presets; /* nr_presets * nr_total_params */ 144 142 struct dev_ext_attribute *event_ea; 145 143 atomic_t active_cnt; 144 + void *load_owner; 146 145 }; 147 146 148 147 /**
+18 -3
drivers/hwtracing/coresight/coresight-syscfg.c
··· 361 361 * descriptors and load into the system. 362 362 * Features are loaded first to ensure configuration dependencies can be met. 363 363 * 364 + * To facilitate dynamic loading and unloading, features and configurations 365 + * have a "load_owner", to allow later unload by the same owner. An owner may 366 + * be a loadable module or configuration dynamically created via configfs. 367 + * As later loaded configurations can use earlier loaded features, creating load 368 + * dependencies, a load order list is maintained. Unload is strictly in the 369 + * reverse order to load. 370 + * 364 371 * @config_descs: 0 terminated array of configuration descriptors. 365 372 * @feat_descs: 0 terminated array of feature descriptors. 373 + * @owner_info: Information on the owner of this set. 366 374 */ 367 375 int cscfg_load_config_sets(struct cscfg_config_desc **config_descs, 368 - struct cscfg_feature_desc **feat_descs) 376 + struct cscfg_feature_desc **feat_descs, 377 + struct cscfg_load_owner_info *owner_info) 369 378 { 370 - int err, i = 0; 379 + int err = 0, i = 0; 371 380 372 381 mutex_lock(&cscfg_mutex); 373 382 ··· 391 382 feat_descs[i]->name); 392 383 goto exit_unlock; 393 384 } 385 + feat_descs[i]->load_owner = owner_info; 394 386 i++; 395 387 } 396 388 } ··· 408 398 config_descs[i]->name); 409 399 goto exit_unlock; 410 400 } 401 + config_descs[i]->load_owner = owner_info; 411 402 i++; 412 403 } 413 404 } 405 + 406 + /* add the load owner to the load order list */ 407 + list_add_tail(&owner_info->item, &cscfg_mgr->load_order_list); 414 408 415 409 exit_unlock: 416 410 mutex_unlock(&cscfg_mutex); ··· 841 827 INIT_LIST_HEAD(&cscfg_mgr->csdev_desc_list); 842 828 INIT_LIST_HEAD(&cscfg_mgr->feat_desc_list); 843 829 INIT_LIST_HEAD(&cscfg_mgr->config_desc_list); 830 + INIT_LIST_HEAD(&cscfg_mgr->load_order_list); 844 831 atomic_set(&cscfg_mgr->sys_active_cnt, 0); 845 832 846 833 /* preload built-in configurations */ 847 - err = cscfg_preload(); 834 + err = cscfg_preload(THIS_MODULE); 848 835 if (err) 849 836 goto exit_err; 850 837
+27 -2
drivers/hwtracing/coresight/coresight-syscfg.h
··· 25 25 * @csdev_desc_list: List of coresight devices registered with the configuration manager. 26 26 * @feat_desc_list: List of feature descriptors to load into registered devices. 27 27 * @config_desc_list: List of system configuration descriptors to load into registered devices. 28 + * @load_order_list: Ordered list of owners for dynamically loaded configurations. 28 29 * @sys_active_cnt: Total number of active config descriptor references. 29 30 * @cfgfs_subsys: configfs subsystem used to manage configurations. 30 31 */ ··· 34 33 struct list_head csdev_desc_list; 35 34 struct list_head feat_desc_list; 36 35 struct list_head config_desc_list; 36 + struct list_head load_order_list; 37 37 atomic_t sys_active_cnt; 38 38 struct configfs_subsystem cfgfs_subsys; 39 39 }; ··· 58 56 struct list_head item; 59 57 }; 60 58 59 + /* owner types for loading and unloading of config and feature sets */ 60 + enum cscfg_load_owner_type { 61 + CSCFG_OWNER_PRELOAD, 62 + }; 63 + 64 + /** 65 + * Load item - item to add to the load order list allowing dynamic load and 66 + * unload of configurations and features. Caller loading a config 67 + * set provides a context handle for unload. API ensures that 68 + * items unloaded strictly in reverse order from load to ensure 69 + * dependencies are respected. 70 + * 71 + * @item: list entry for load order list. 72 + * @type: type of owner - allows interpretation of owner_handle. 73 + * @owner_handle: load context - handle for owner of loaded configs. 74 + */ 75 + struct cscfg_load_owner_info { 76 + struct list_head item; 77 + int type; 78 + void *owner_handle; 79 + }; 80 + 61 81 /* internal core operations for cscfg */ 62 82 int __init cscfg_init(void); 63 83 void cscfg_exit(void); 64 - int cscfg_preload(void); 84 + int cscfg_preload(void *owner_handle); 65 85 const struct cscfg_feature_desc *cscfg_get_named_feat_desc(const char *name); 66 86 int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, 67 87 int param_idx, u64 value); ··· 91 67 92 68 /* syscfg manager external API */ 93 69 int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs, 94 - struct cscfg_feature_desc **feat_descs); 70 + struct cscfg_feature_desc **feat_descs, 71 + struct cscfg_load_owner_info *owner_info); 95 72 int cscfg_register_csdev(struct coresight_device *csdev, u32 match_flags, 96 73 struct cscfg_csdev_feat_ops *ops); 97 74 void cscfg_unregister_csdev(struct coresight_device *csdev);