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