[Intel-gfx] [RFC PATCH 11/11] drm/i915/params: hide i915_modparams within i915_params.c

Jani Nikula jani.nikula at intel.com
Fri Dec 21 13:31:47 UTC 2018


Prevent accidental use of i915_modparams throughout the driver by hiding
it in i915_params.c. Add accessors for the legitimate uses.

Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
 drivers/gpu/drm/i915/i915_drv.c    |  2 +-
 drivers/gpu/drm/i915/i915_drv.h    |  2 +-
 drivers/gpu/drm/i915/i915_params.c | 20 +++++++++++++++++++-
 drivers/gpu/drm/i915/i915_params.h |  6 ++++--
 drivers/gpu/drm/i915/i915_pci.c    |  6 +++---
 5 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index cfe1f93f9683..2f03d47c4a1f 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1643,7 +1643,7 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 
 	/* Device parameters start as a copy of module parameters. */
-	i915_params_copy(&i915->params, &i915_modparams);
+	i915_params_copy(&i915->params, NULL);
 
 	i915->drm.pdev = pdev;
 	i915->drm.dev_private = i915;
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index baacd37c7259..97ac33ac34c0 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -103,7 +103,7 @@
 #define I915_STATE_WARN(condition, format...) ({			\
 	int __ret_warn_on = !!(condition);				\
 	if (unlikely(__ret_warn_on))					\
-		if (!WARN(i915_modparams.verbose_state_checks, format))	\
+		if (!WARN(i915_params_verbose_state_checks(), format))	\
 			DRM_ERROR(format);				\
 	unlikely(__ret_warn_on);					\
 })
diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c
index 61cde445346e..c14ad496f9ab 100644
--- a/drivers/gpu/drm/i915/i915_params.c
+++ b/drivers/gpu/drm/i915/i915_params.c
@@ -34,12 +34,27 @@
 	module_param_named_unsafe(name, i915_modparams.name, T, perm); \
 	MODULE_PARM_DESC(name, desc)
 
-struct i915_params i915_modparams __read_mostly = {
+static struct i915_params i915_modparams __read_mostly = {
 #define MEMBER(T, member, value, ...) .member = (value),
 	I915_PARAMS_FOR_EACH(MEMBER)
 #undef MEMBER
 };
 
+int i915_params_modeset(void)
+{
+	return i915_modparams.modeset;
+}
+
+bool i915_params_verbose_state_checks(void)
+{
+	return i915_modparams.verbose_state_checks;
+}
+
+bool i915_params_alpha_support(void)
+{
+	return i915_modparams.alpha_support;
+}
+
 /*
  * Note: As a rule, keep module parameter sysfs permissions read-only
  * 0400. Runtime changes are only supported through i915 debugfs.
@@ -217,6 +232,9 @@ static __always_inline void dup_param(const char *type, void *x)
 
 void i915_params_copy(struct i915_params *dest, const struct i915_params *src)
 {
+	if (!src)
+		src = &i915_modparams;
+
 	*dest = *src;
 #define DUP(T, x, ...) dup_param(#T, &dest->x);
 	I915_PARAMS_FOR_EACH(DUP);
diff --git a/drivers/gpu/drm/i915/i915_params.h b/drivers/gpu/drm/i915/i915_params.h
index 30c32e288efe..61de08446c4b 100644
--- a/drivers/gpu/drm/i915/i915_params.h
+++ b/drivers/gpu/drm/i915/i915_params.h
@@ -85,11 +85,13 @@ struct i915_params {
 };
 #undef MEMBER
 
-extern struct i915_params i915_modparams __read_mostly;
-
 void i915_params_dump(const struct i915_params *params, struct drm_printer *p);
 void i915_params_copy(struct i915_params *dest, const struct i915_params *src);
 void i915_params_free(struct i915_params *params);
 
+int i915_params_modeset(void);
+bool i915_params_verbose_state_checks(void);
+bool i915_params_alpha_support(void);
+
 #endif
 
diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c
index 6350db5503cd..34ec4d2d23d0 100644
--- a/drivers/gpu/drm/i915/i915_pci.c
+++ b/drivers/gpu/drm/i915/i915_pci.c
@@ -734,7 +734,7 @@ static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		(struct intel_device_info *) ent->driver_data;
 	int err;
 
-	if (IS_ALPHA_SUPPORT(intel_info) && !i915_modparams.alpha_support) {
+	if (IS_ALPHA_SUPPORT(intel_info) && !i915_params_alpha_support()) {
 		DRM_INFO("The driver support for your hardware in this kernel version is alpha quality\n"
 			 "See CONFIG_DRM_I915_ALPHA_SUPPORT or i915.alpha_support module parameter\n"
 			 "to enable support in this kernel version, or check for kernel updates.\n");
@@ -797,10 +797,10 @@ static int __init i915_init(void)
 	 * vga_text_mode_force boot option.
 	 */
 
-	if (i915_modparams.modeset == 0)
+	if (i915_params_modeset() == 0)
 		use_kms = false;
 
-	if (vgacon_text_force() && i915_modparams.modeset == -1)
+	if (vgacon_text_force() && i915_params_modeset() == -1)
 		use_kms = false;
 
 	if (!use_kms) {
-- 
2.11.0



More information about the Intel-gfx mailing list