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

Configure Feed

Select the types of activity you want to include in your feed.

drm/imagination: Simplify module parameters

We had a whole load of bloaty infrastructure to deal with module parameters
in a way that's wholly unnecessary. Strip it all back to basics to make
adding new parameters less of a headache.

Reviewed-by: Alessio Belle <alessio.belle@imgtec.com>
Link: https://patch.msgid.link/20260113-device-support-info-v1-1-91e5db7f7294@imgtec.com
Signed-off-by: Matt Coster <matt.coster@imgtec.com>

+42 -248
-1
drivers/gpu/drm/imagination/Makefile
··· 20 20 pvr_hwrt.o \ 21 21 pvr_job.o \ 22 22 pvr_mmu.o \ 23 - pvr_params.o \ 24 23 pvr_power.o \ 25 24 pvr_queue.o \ 26 25 pvr_stream.o \
-2
drivers/gpu/drm/imagination/pvr_debugfs.c
··· 5 5 6 6 #include "pvr_device.h" 7 7 #include "pvr_fw_trace.h" 8 - #include "pvr_params.h" 9 8 10 9 #include <linux/dcache.h> 11 10 #include <linux/debugfs.h> ··· 17 18 #include <drm/drm_print.h> 18 19 19 20 static const struct pvr_debugfs_entry pvr_debugfs_entries[] = { 20 - {"pvr_params", pvr_params_debugfs_init}, 21 21 {"pvr_fw", pvr_fw_trace_debugfs_init}, 22 22 }; 23 23
-9
drivers/gpu/drm/imagination/pvr_device.c
··· 5 5 #include "pvr_device_info.h" 6 6 7 7 #include "pvr_fw.h" 8 - #include "pvr_params.h" 9 8 #include "pvr_power.h" 10 9 #include "pvr_queue.h" 11 10 #include "pvr_rogue_cr_defs.h" ··· 605 606 606 607 /* Get the platform-specific data based on the compatible string. */ 607 608 pvr_dev->device_data = of_device_get_match_data(dev); 608 - 609 - /* 610 - * Setup device parameters. We do this first in case other steps 611 - * depend on them. 612 - */ 613 - err = pvr_device_params_init(&pvr_dev->params); 614 - if (err) 615 - return err; 616 609 617 610 /* Enable and initialize clocks required for the device to operate. */ 618 611 err = pvr_device_clk_init(pvr_dev);
-10
drivers/gpu/drm/imagination/pvr_device.h
··· 7 7 #include "pvr_ccb.h" 8 8 #include "pvr_device_info.h" 9 9 #include "pvr_fw.h" 10 - #include "pvr_params.h" 11 10 #include "pvr_rogue_fwif_stream.h" 12 11 #include "pvr_stream.h" 13 12 ··· 190 191 191 192 /** @fw_dev: Firmware related data. */ 192 193 struct pvr_fw_device fw_dev; 193 - 194 - /** 195 - * @params: Device-specific parameters. 196 - * 197 - * The values of these parameters are initialized from the 198 - * defaults specified as module parameters. They may be 199 - * modified at runtime via debugfs (if enabled). 200 - */ 201 - struct pvr_device_params params; 202 194 203 195 /** @stream_musthave_quirks: Bit array of "must-have" quirks for stream commands. */ 204 196 u32 stream_musthave_quirks[PVR_STREAM_TYPE_MAX][PVR_STREAM_EXTHDR_TYPE_MAX];
+42 -4
drivers/gpu/drm/imagination/pvr_fw_trace.c
··· 14 14 #include <linux/build_bug.h> 15 15 #include <linux/dcache.h> 16 16 #include <linux/debugfs.h> 17 + #include <linux/moduleparam.h> 17 18 #include <linux/sysfs.h> 18 19 #include <linux/types.h> 20 + 21 + /* 22 + * Don't gate this behind CONFIG_DEBUG_FS so that it can be used as an initial 23 + * value without further conditional code... 24 + */ 25 + static u32 pvr_fw_trace_init_mask; 26 + 27 + /* 28 + * ...but do only expose the module parameter if debugfs is enabled, since 29 + * there's no reason to turn on fw_trace without it. 30 + */ 31 + #if IS_ENABLED(CONFIG_DEBUG_FS) 32 + module_param_named(init_fw_trace_mask, pvr_fw_trace_init_mask, hexint, 0600); 33 + MODULE_PARM_DESC(init_fw_trace_mask, 34 + "Enable FW trace for the specified groups at device init time"); 35 + #endif 19 36 20 37 static void 21 38 tracebuf_ctrl_init(void *cpu_ptr, void *priv) ··· 143 126 * @group_mask: New log group mask. 144 127 * 145 128 * Returns: 129 + * * 0 if the provided @group_mask is the same as the current value (this is a 130 + * short-circuit evaluation), 146 131 * * 0 on success, 147 132 * * Any error returned by pvr_kccb_send_cmd(), or 148 133 * * -%EIO if the device is lost. ··· 156 137 struct rogue_fwif_kccb_cmd cmd; 157 138 int idx; 158 139 int err; 140 + 141 + /* No change in group_mask => nothing to update. */ 142 + if (fw_trace->group_mask == group_mask) 143 + return 0; 159 144 160 145 if (group_mask) 161 146 fw_trace->tracebuf_ctrl->log_type = ROGUE_FWIF_LOG_TYPE_TRACE | group_mask; ··· 460 437 .release = fw_trace_release, 461 438 }; 462 439 463 - void 464 - pvr_fw_trace_mask_update(struct pvr_device *pvr_dev, u32 old_mask, u32 new_mask) 440 + static int pvr_fw_trace_mask_get(void *data, u64 *value) 465 441 { 466 - if (IS_ENABLED(CONFIG_DEBUG_FS) && old_mask != new_mask) 467 - update_logtype(pvr_dev, new_mask); 442 + struct pvr_device *pvr_dev = data; 443 + 444 + *value = pvr_dev->fw_dev.fw_trace.group_mask; 445 + 446 + return 0; 468 447 } 448 + 449 + static int pvr_fw_trace_mask_set(void *data, u64 value) 450 + { 451 + struct pvr_device *pvr_dev = data; 452 + 453 + return update_logtype(pvr_dev, (u32)value); 454 + } 455 + 456 + DEFINE_DEBUGFS_ATTRIBUTE(pvr_fw_trace_mask_fops, pvr_fw_trace_mask_get, 457 + pvr_fw_trace_mask_set, "0x%08llx\n"); 469 458 470 459 void 471 460 pvr_fw_trace_debugfs_init(struct pvr_device *pvr_dev, struct dentry *dir) ··· 498 463 &fw_trace->buffers[thread_nr], 499 464 &pvr_fw_trace_fops); 500 465 } 466 + 467 + debugfs_create_file("trace_mask", 0600, dir, fw_trace, 468 + &pvr_fw_trace_mask_fops); 501 469 }
-3
drivers/gpu/drm/imagination/pvr_fw_trace.h
··· 68 68 /* Forward declaration from <linux/dcache.h>. */ 69 69 struct dentry; 70 70 71 - void pvr_fw_trace_mask_update(struct pvr_device *pvr_dev, u32 old_mask, 72 - u32 new_mask); 73 - 74 71 void pvr_fw_trace_debugfs_init(struct pvr_device *pvr_dev, struct dentry *dir); 75 72 76 73 #endif /* PVR_FW_TRACE_H */
-147
drivers/gpu/drm/imagination/pvr_params.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only OR MIT 2 - /* Copyright (c) 2023 Imagination Technologies Ltd. */ 3 - 4 - #include "pvr_params.h" 5 - 6 - #include <linux/cache.h> 7 - #include <linux/moduleparam.h> 8 - 9 - static struct pvr_device_params pvr_device_param_defaults __read_mostly = { 10 - #define X(type_, name_, value_, desc_, ...) .name_ = (value_), 11 - PVR_DEVICE_PARAMS 12 - #undef X 13 - }; 14 - 15 - #define PVR_DEVICE_PARAM_NAMED(name_, type_, desc_) \ 16 - module_param_named(name_, pvr_device_param_defaults.name_, type_, \ 17 - 0400); \ 18 - MODULE_PARM_DESC(name_, desc_); 19 - 20 - /* 21 - * This list of defines must contain every type specified in "pvr_params.h" as 22 - * ``PVR_PARAM_TYPE_*_C``. 23 - */ 24 - #define PVR_PARAM_TYPE_X32_MODPARAM uint 25 - 26 - #define X(type_, name_, value_, desc_, ...) \ 27 - PVR_DEVICE_PARAM_NAMED(name_, PVR_PARAM_TYPE_##type_##_MODPARAM, desc_); 28 - PVR_DEVICE_PARAMS 29 - #undef X 30 - 31 - int 32 - pvr_device_params_init(struct pvr_device_params *params) 33 - { 34 - /* 35 - * If heap-allocated parameters are added in the future (e.g. 36 - * modparam's charp type), they must be handled specially here (via 37 - * kstrdup() in the case of charp). Since that's not necessary yet, 38 - * a straight copy will do for now. This change will also require a 39 - * pvr_device_params_fini() function to free any heap-allocated copies. 40 - */ 41 - 42 - *params = pvr_device_param_defaults; 43 - 44 - return 0; 45 - } 46 - 47 - #if defined(CONFIG_DEBUG_FS) 48 - #include "pvr_device.h" 49 - 50 - #include <linux/dcache.h> 51 - #include <linux/debugfs.h> 52 - #include <linux/export.h> 53 - #include <linux/fs.h> 54 - #include <linux/stddef.h> 55 - 56 - /* 57 - * This list of defines must contain every type specified in "pvr_params.h" as 58 - * ``PVR_PARAM_TYPE_*_C``. 59 - */ 60 - #define PVR_PARAM_TYPE_X32_FMT "0x%08llx" 61 - 62 - #define X_SET(name_, mode_) X_SET_##mode_(name_) 63 - #define X_SET_DEF(name_, update_, mode_) X_SET_DEF_##mode_(name_, update_) 64 - 65 - #define X_SET_RO(name_) NULL 66 - #define X_SET_RW(name_) __pvr_device_param_##name_##set 67 - 68 - #define X_SET_DEF_RO(name_, update_) 69 - #define X_SET_DEF_RW(name_, update_) \ 70 - static int \ 71 - X_SET_RW(name_)(void *data, u64 val) \ 72 - { \ 73 - struct pvr_device *pvr_dev = data; \ 74 - /* This is not just (update_) to suppress -Waddress. */ \ 75 - if ((void *)(update_) != NULL) \ 76 - (update_)(pvr_dev, pvr_dev->params.name_, val); \ 77 - pvr_dev->params.name_ = val; \ 78 - return 0; \ 79 - } 80 - 81 - #define X(type_, name_, value_, desc_, mode_, update_) \ 82 - static int \ 83 - __pvr_device_param_##name_##_get(void *data, u64 *val) \ 84 - { \ 85 - struct pvr_device *pvr_dev = data; \ 86 - *val = pvr_dev->params.name_; \ 87 - return 0; \ 88 - } \ 89 - X_SET_DEF(name_, update_, mode_) \ 90 - static int \ 91 - __pvr_device_param_##name_##_open(struct inode *inode, \ 92 - struct file *file) \ 93 - { \ 94 - __simple_attr_check_format(PVR_PARAM_TYPE_##type_##_FMT, \ 95 - 0ull); \ 96 - return simple_attr_open(inode, file, \ 97 - __pvr_device_param_##name_##_get, \ 98 - X_SET(name_, mode_), \ 99 - PVR_PARAM_TYPE_##type_##_FMT); \ 100 - } 101 - PVR_DEVICE_PARAMS 102 - #undef X 103 - 104 - #undef X_SET 105 - #undef X_SET_RO 106 - #undef X_SET_RW 107 - #undef X_SET_DEF 108 - #undef X_SET_DEF_RO 109 - #undef X_SET_DEF_RW 110 - 111 - static struct { 112 - #define X(type_, name_, value_, desc_, mode_, update_) \ 113 - const struct file_operations name_; 114 - PVR_DEVICE_PARAMS 115 - #undef X 116 - } pvr_device_param_debugfs_fops = { 117 - #define X(type_, name_, value_, desc_, mode_, update_) \ 118 - .name_ = { \ 119 - .owner = THIS_MODULE, \ 120 - .open = __pvr_device_param_##name_##_open, \ 121 - .release = simple_attr_release, \ 122 - .read = simple_attr_read, \ 123 - .write = simple_attr_write, \ 124 - .llseek = generic_file_llseek, \ 125 - }, 126 - PVR_DEVICE_PARAMS 127 - #undef X 128 - }; 129 - 130 - void 131 - pvr_params_debugfs_init(struct pvr_device *pvr_dev, struct dentry *dir) 132 - { 133 - #define X_MODE(mode_) X_MODE_##mode_ 134 - #define X_MODE_RO 0400 135 - #define X_MODE_RW 0600 136 - 137 - #define X(type_, name_, value_, desc_, mode_, update_) \ 138 - debugfs_create_file(#name_, X_MODE(mode_), dir, pvr_dev, \ 139 - &pvr_device_param_debugfs_fops.name_); 140 - PVR_DEVICE_PARAMS 141 - #undef X 142 - 143 - #undef X_MODE 144 - #undef X_MODE_RO 145 - #undef X_MODE_RW 146 - } 147 - #endif
-72
drivers/gpu/drm/imagination/pvr_params.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only OR MIT */ 2 - /* Copyright (c) 2023 Imagination Technologies Ltd. */ 3 - 4 - #ifndef PVR_PARAMS_H 5 - #define PVR_PARAMS_H 6 - 7 - #include "pvr_rogue_fwif.h" 8 - 9 - #include <linux/cache.h> 10 - #include <linux/compiler_attributes.h> 11 - 12 - /* 13 - * This is the definitive list of types allowed in the definition of 14 - * %PVR_DEVICE_PARAMS. 15 - */ 16 - #define PVR_PARAM_TYPE_X32_C u32 17 - 18 - /* 19 - * This macro defines all device-specific parameters; that is parameters which 20 - * are set independently per device. 21 - * 22 - * The X-macro accepts the following arguments. Arguments marked with [debugfs] 23 - * are ignored when debugfs is disabled; values used for these arguments may 24 - * safely be gated behind CONFIG_DEBUG_FS. 25 - * 26 - * @type_: The definitive list of allowed values is PVR_PARAM_TYPE_*_C. 27 - * @name_: Name of the parameter. This is used both as the field name in C and 28 - * stringified as the parameter name. 29 - * @value_: Initial/default value. 30 - * @desc_: String literal used as help text to describe the usage of this 31 - * parameter. 32 - * @mode_: [debugfs] One of {RO,RW}. The access mode of the debugfs entry for 33 - * this parameter. 34 - * @update_: [debugfs] When debugfs support is enabled, parameters may be 35 - * updated at runtime. When this happens, this function will be 36 - * called to allow changes to propagate. The signature of this 37 - * function is: 38 - * 39 - * void (*)(struct pvr_device *pvr_dev, T old_val, T new_val) 40 - * 41 - * Where T is the C type associated with @type_. 42 - * 43 - * If @mode_ does not allow write access, this function will never be 44 - * called. In this case, or if no update callback is required, you 45 - * should specify NULL for this argument. 46 - */ 47 - #define PVR_DEVICE_PARAMS \ 48 - X(X32, fw_trace_mask, ROGUE_FWIF_LOG_TYPE_NONE, \ 49 - "Enable FW trace for the specified groups. Specifying 0 disables " \ 50 - "all FW tracing.", \ 51 - RW, pvr_fw_trace_mask_update) 52 - 53 - struct pvr_device_params { 54 - #define X(type_, name_, value_, desc_, ...) \ 55 - PVR_PARAM_TYPE_##type_##_C name_; 56 - PVR_DEVICE_PARAMS 57 - #undef X 58 - }; 59 - 60 - int pvr_device_params_init(struct pvr_device_params *params); 61 - 62 - #if defined(CONFIG_DEBUG_FS) 63 - /* Forward declaration from "pvr_device.h". */ 64 - struct pvr_device; 65 - 66 - /* Forward declaration from <linux/dcache.h>. */ 67 - struct dentry; 68 - 69 - void pvr_params_debugfs_init(struct pvr_device *pvr_dev, struct dentry *dir); 70 - #endif /* defined(CONFIG_DEBUG_FS) */ 71 - 72 - #endif /* PVR_PARAMS_H */