1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #include <linux/moduleparam.h> 7 #include <linux/slab.h> 8 #include <linux/string_choices.h> 9 10 #include <drm/drm_print.h> 11 12 #include "intel_display_params.h" 13 14 #define intel_display_param_named(name, T, perm, desc) \ 15 module_param_named(name, intel_display_modparams.name, T, perm); \ 16 MODULE_PARM_DESC(name, desc) 17 #define intel_display_param_named_unsafe(name, T, perm, desc) \ 18 module_param_named_unsafe(name, intel_display_modparams.name, T, perm); \ 19 MODULE_PARM_DESC(name, desc) 20 21 static struct intel_display_params intel_display_modparams __read_mostly = { 22 #define MEMBER(T, member, value, ...) .member = (value), 23 INTEL_DISPLAY_PARAMS_FOR_EACH(MEMBER) 24 #undef MEMBER 25 }; 26 /* 27 * Note: As a rule, keep module parameter sysfs permissions read-only 28 * 0400. Runtime changes are only supported through i915 debugfs. 29 * 30 * For any exceptions requiring write access and runtime changes through module 31 * parameter sysfs, prevent debugfs file creation by setting the parameter's 32 * debugfs mode to 0. 33 */ 34 35 intel_display_param_named_unsafe(dmc_firmware_path, charp, 0400, 36 "DMC firmware path to use instead of the default one. " 37 "Use /dev/null to disable DMC and runtime PM."); 38 39 intel_display_param_named_unsafe(vbt_firmware, charp, 0400, 40 "Load VBT from specified file under /lib/firmware"); 41 42 intel_display_param_named_unsafe(lvds_channel_mode, int, 0400, 43 "Specify LVDS channel mode " 44 "(0=probe BIOS [default], 1=single-channel, 2=dual-channel)"); 45 46 intel_display_param_named_unsafe(panel_use_ssc, int, 0400, 47 "Use Spread Spectrum Clock with panels [LVDS/eDP] " 48 "(default: auto from VBT)"); 49 50 intel_display_param_named_unsafe(vbt_sdvo_panel_type, int, 0400, 51 "Override/Ignore selection of SDVO panel mode in the VBT " 52 "(-2=ignore, -1=auto [default], index in VBT BIOS table)"); 53 54 intel_display_param_named_unsafe(enable_dc, int, 0400, 55 "Enable power-saving display C-states. " 56 "(-1=auto [default]; 0=disable; 1=up to DC5; 2=up to DC6; " 57 "3=up to DC5 with DC3CO; 4=up to DC6 with DC3CO)"); 58 59 intel_display_param_named_unsafe(enable_dpt, bool, 0400, 60 "Enable display page table (DPT) (default: true)"); 61 62 intel_display_param_named_unsafe(enable_dsb, bool, 0400, 63 "Enable display state buffer (DSB) (default: true)"); 64 65 intel_display_param_named_unsafe(enable_sagv, bool, 0400, 66 "Enable system agent voltage/frequency scaling (SAGV) (default: true)"); 67 68 intel_display_param_named_unsafe(disable_power_well, int, 0400, 69 "Disable display power wells when possible " 70 "(-1=auto [default], 0=power wells always on, 1=power wells disabled when possible)"); 71 72 intel_display_param_named_unsafe(enable_ips, bool, 0400, "Enable IPS (default: true)"); 73 74 intel_display_param_named_unsafe(invert_brightness, int, 0400, 75 "Invert backlight brightness " 76 "(-1 force normal, 0 machine defaults, 1 force inversion), please " 77 "report PCI device ID, subsystem vendor and subsystem device ID " 78 "to dri-devel@lists.freedesktop.org, if your machine needs it. " 79 "It will then be included in an upcoming module version."); 80 81 /* WA to get away with the default setting in VBT for early platforms.Will be removed */ 82 intel_display_param_named_unsafe(edp_vswing, int, 0400, 83 "Ignore/Override vswing pre-emph table selection from VBT " 84 "(0=use value from vbt [default], 1=low power swing(200mV)," 85 "2=default swing(400mV))"); 86 87 intel_display_param_named(enable_dpcd_backlight, int, 0400, 88 "Enable support for DPCD backlight control" 89 "(-1=use per-VBT LFP backlight type setting [default], 0=disabled, 1=enable, 2=force VESA interface, 3=force Intel interface)"); 90 91 intel_display_param_named_unsafe(load_detect_test, bool, 0400, 92 "Force-enable the VGA load detect code for testing (default:false). " 93 "For developers only."); 94 95 intel_display_param_named_unsafe(force_reset_modeset_test, bool, 0400, 96 "Force a modeset during gpu reset for testing (default:false). " 97 "For developers only."); 98 99 intel_display_param_named(disable_display, bool, 0400, 100 "Disable display (default: false)"); 101 102 intel_display_param_named(verbose_state_checks, bool, 0400, 103 "Enable verbose logs (ie. WARN_ON()) in case of unexpected hw state conditions."); 104 105 intel_display_param_named_unsafe(nuclear_pageflip, bool, 0400, 106 "Force enable atomic functionality on platforms that don't have full support yet."); 107 108 intel_display_param_named_unsafe(enable_dp_mst, bool, 0400, 109 "Enable multi-stream transport (MST) for new DisplayPort sinks. (default: true)"); 110 111 intel_display_param_named_unsafe(enable_fbc, int, 0400, 112 "Enable frame buffer compression for power savings " 113 "(default: -1 (use per-chip default))"); 114 115 intel_display_param_named_unsafe(enable_psr, int, 0400, 116 "Enable PSR " 117 "(0=disabled, 1=enable up to PSR1, 2=enable up to PSR2) " 118 "Default: -1 (use per-chip default)"); 119 120 intel_display_param_named(psr_safest_params, bool, 0400, 121 "Replace PSR VBT parameters by the safest and not optimal ones. This " 122 "is helpful to detect if PSR issues are related to bad values set in " 123 " VBT. (0=use VBT parameters, 1=use safest parameters)" 124 "Default: 0"); 125 126 intel_display_param_named_unsafe(enable_psr2_sel_fetch, bool, 0400, 127 "Enable PSR2 and Panel Replay selective fetch " 128 "(0=disabled, 1=enabled) " 129 "Default: 1"); 130 131 intel_display_param_named_unsafe(enable_dmc_wl, int, 0400, 132 "Enable DMC wakelock " 133 "(-1=use per-chip default, 0=disabled, 1=enabled) " 134 "Default: -1"); 135 136 __maybe_unused 137 static void _param_print_bool(struct drm_printer *p, const char *driver_name, 138 const char *name, bool val) 139 { 140 drm_printf(p, "%s.%s=%s\n", driver_name, name, str_yes_no(val)); 141 } 142 143 __maybe_unused 144 static void _param_print_int(struct drm_printer *p, const char *driver_name, 145 const char *name, int val) 146 { 147 drm_printf(p, "%s.%s=%d\n", driver_name, name, val); 148 } 149 150 __maybe_unused 151 static void _param_print_uint(struct drm_printer *p, const char *driver_name, 152 const char *name, unsigned int val) 153 { 154 drm_printf(p, "%s.%s=%u\n", driver_name, name, val); 155 } 156 157 __maybe_unused 158 static void _param_print_ulong(struct drm_printer *p, const char *driver_name, 159 const char *name, unsigned long val) 160 { 161 drm_printf(p, "%s.%s=%lu\n", driver_name, name, val); 162 } 163 164 __maybe_unused 165 static void _param_print_charp(struct drm_printer *p, const char *driver_name, 166 const char *name, const char *val) 167 { 168 drm_printf(p, "%s.%s=%s\n", driver_name, name, val); 169 } 170 171 #define _param_print(p, driver_name, name, val) \ 172 _Generic(val, \ 173 bool : _param_print_bool, \ 174 int : _param_print_int, \ 175 unsigned int : _param_print_uint, \ 176 unsigned long : _param_print_ulong, \ 177 char * : _param_print_charp)(p, driver_name, name, val) 178 179 /** 180 * intel_display_params_dump - dump intel display modparams 181 * @params: display params 182 * @driver_name: driver name to use for printing 183 * @p: the &drm_printer 184 * 185 * Pretty printer for i915 modparams. 186 */ 187 void intel_display_params_dump(const struct intel_display_params *params, 188 const char *driver_name, struct drm_printer *p) 189 { 190 #define PRINT(T, x, ...) _param_print(p, driver_name, #x, params->x); 191 INTEL_DISPLAY_PARAMS_FOR_EACH(PRINT); 192 #undef PRINT 193 } 194 195 __maybe_unused static void _param_dup_charp(char **valp) 196 { 197 *valp = kstrdup(*valp ? *valp : "", GFP_ATOMIC); 198 } 199 200 __maybe_unused static void _param_nop(void *valp) 201 { 202 } 203 204 #define _param_dup(valp) \ 205 _Generic(valp, \ 206 char ** : _param_dup_charp, \ 207 default : _param_nop) \ 208 (valp) 209 210 void intel_display_params_copy(struct intel_display_params *dest) 211 { 212 *dest = intel_display_modparams; 213 #define DUP(T, x, ...) _param_dup(&dest->x); 214 INTEL_DISPLAY_PARAMS_FOR_EACH(DUP); 215 #undef DUP 216 } 217 218 __maybe_unused static void _param_free_charp(char **valp) 219 { 220 kfree(*valp); 221 *valp = NULL; 222 } 223 224 #define _param_free(valp) \ 225 _Generic(valp, \ 226 char ** : _param_free_charp, \ 227 default : _param_nop) \ 228 (valp) 229 230 /* free the allocated members, *not* the passed in params itself */ 231 void intel_display_params_free(struct intel_display_params *params) 232 { 233 #define FREE(T, x, ...) _param_free(¶ms->x); 234 INTEL_DISPLAY_PARAMS_FOR_EACH(FREE); 235 #undef FREE 236 } 237