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