drm/sysfb: Share framebuffer validation helpers
Subsystems (3)
Thomas Zimmermann
maintainerv2 cover drm/sysfb: Share framebuffer validation helpers
Drivers for system framebuffers validate the provided values against limits. Share most of the drivers' validation code in the sysfb helper library and update drivers.
v2:
- fix typos and style
Thomas Zimmermann (3):
drm/sysfb: Split source file
drm/sysfb: Share helpers for integer validation drm/sysfb: Share helpers for screen_info validation
drivers/gpu/drm/sysfb/Makefile | 4 +
drivers/gpu/drm/sysfb/drm_sysfb.c | 35 +++++
drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 48 +++++++
...drm_sysfb_helper.c => drm_sysfb_modeset.c} | 4 -
drivers/gpu/drm/sysfb/drm_sysfb_screen_info.c | 107 +++++++++++++++
drivers/gpu/drm/sysfb/efidrm.c | 126 ++----------------
drivers/gpu/drm/sysfb/ofdrm.c | 12 +-
drivers/gpu/drm/sysfb/simpledrm.c | 14 +-
drivers/gpu/drm/sysfb/vesadrm.c | 126 ++----------------
9 files changed, 216 insertions(+), 260 deletions(-)
create mode 100644 drivers/gpu/drm/sysfb/drm_sysfb.c
rename drivers/gpu/drm/sysfb/{drm_sysfb_helper.c => drm_sysfb_modeset.c} (98%)
create mode 100644 drivers/gpu/drm/sysfb/drm_sysfb_screen_info.cSignature · 1 line
2.49.0
Thomas Zimmermann
maintainerPATCH v2 1/3 drm/sysfb: Split source file
Split drm_sysfb_helper.c into two source files. There's now one source file for the mode-setting pipeline and one source file for module meta data. Prepares for adding additional source code to sysfb helpers.
v2:
- fix typo in commit message (Javier)
---
drivers/gpu/drm/sysfb/Makefile | 3 +++
drivers/gpu/drm/sysfb/drm_sysfb.c | 8 ++++++++
drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 5 +++++
.../drm/sysfb/{drm_sysfb_helper.c => drm_sysfb_modeset.c} | 4 ----
4 files changed, 16 insertions(+), 4 deletions(-)
create mode 100644 drivers/gpu/drm/sysfb/drm_sysfb.c
rename drivers/gpu/drm/sysfb/{drm_sysfb_helper.c => drm_sysfb_modeset.c} (98%)drivers/gpu/drm/sysfb/Makefile +3 -0
@@ -1,5 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only +drm_sysfb_helper-y := \ + drm_sysfb.o \ + drm_sysfb_modeset.o obj-$(CONFIG_DRM_SYSFB_HELPER) += drm_sysfb_helper.o obj-$(CONFIG_DRM_EFIDRM) += efidrm.o
drivers/gpu/drm/sysfb/drm_sysfb.c new file +8 -0
@@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/module.h> + +#include "drm_sysfb_helper.h" + +MODULE_DESCRIPTION ("Helpers for DRM sysfb drivers" ); +MODULE_LICENSE ("GPL" );
drivers/gpu/drm/sysfb/drm_sysfb_helper.h +5 -0
@@ -11,6 +11,11 @@#include <drm/drm_modes.h> struct drm_format_info ; +struct drm_scanout_buffer ; + +/* +* Display modes +*/ struct drm_display_mode drm_sysfb_mode(unsigned int width, unsigned int height,
drivers/gpu/drm/sysfb/drm_sysfb_modeset.c renamed from drivers/gpu/drm/sysfb/drm_sysfb_helper.c +0 -4
@@ -2,7 +2,6 @@#include <linux/export.h> #include <linux/slab.h> -#include <linux/module.h> #include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h>
@@ -20,9 +19,6 @@#include "drm_sysfb_helper.h" -MODULE_DESCRIPTION ("Helpers for DRM sysfb drivers" ); -MODULE_LICENSE ("GPL" ); - struct drm_display_mode drm_sysfb_mode(unsigned int width, unsigned int height, unsigned int width_mm,
Signature · 1 line
2.49.0
Thomas Zimmermann
maintainerPATCH v2 2/3 drm/sysfb: Share helpers for integer validation
In reply to Thomas ZimmermannProvide sysfb helpers for validating framebuffer integer values against limits. Update drivers. If a driver did not specify a limit for a certain value, use INT_MAX.
v2:
- declare module information near EOF (Javier)
--- drivers/gpu/drm/sysfb/drm_sysfb.c | 27 ++++++++++++++++++++++ drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 9 ++++++++ drivers/gpu/drm/sysfb/efidrm.c | 29 ++++-------------------- drivers/gpu/drm/sysfb/ofdrm.c | 12 ++-------- drivers/gpu/drm/sysfb/simpledrm.c | 14 ++---------- drivers/gpu/drm/sysfb/vesadrm.c | 29 ++++-------------------- 6 files changed, 48 insertions(+), 72 deletions(-)
drivers/gpu/drm/sysfb/drm_sysfb.c +27 -0
@@ -1,8 +1,35 @@// SPDX-License-Identifier: GPL-2.0-only +#include <linux/export.h> +#include <linux/limits.h> +#include <linux/minmax.h> #include <linux/module.h> +#include <drm/drm_print.h> +#include "drm_sysfb_helper.h" +int drm_sysfb_get_validated_int (struct drm_device *dev,const char *name, +u64 value,u32 max) +{ +if (value >min (max,INT_MAX )) { +drm_warn (dev,"%s of %llu exceeds maximum of %u\n" , name, value, max); +return -EINVAL ; + } +return value; +} +EXPORT_SYMBOL (drm_sysfb_get_validated_int); + +int drm_sysfb_get_validated_int0 (struct drm_device *dev,const char *name, +u64 value,u32 max) +{ +if (!value) { +drm_warn (dev,"%s of 0 not allowed\n" , name); +return -EINVAL ; + } +return drm_sysfb_get_validated_int (dev, name, value, max); +} +EXPORT_SYMBOL (drm_sysfb_get_validated_int0); +MODULE_DESCRIPTION ("Helpers for DRM sysfb drivers" );MODULE_LICENSE ("GPL" );
drivers/gpu/drm/sysfb/drm_sysfb_helper.h +9 -0
@@ -13,6 +13,15 @@struct drm_format_info ;struct drm_scanout_buffer ; +/* +* Input parsing +*/ + +int drm_sysfb_get_validated_int (struct drm_device *dev,const char *name, +u64 value,u32 max); +int drm_sysfb_get_validated_int0 (struct drm_device *dev,const char *name, +u64 value,u32 max); +/* * Display modes */
drivers/gpu/drm/sysfb/efidrm.c +4 -25
@@ -33,28 +33,6 @@#define DRIVER_MAJOR 1#define DRIVER_MINOR 0 -static int efidrm_get_validated_int (struct drm_device *dev,const char *name, -u64 value,u32 max) -{ -if (max >INT_MAX ) - max =INT_MAX ; -if (value > max) { -drm_err (dev,"%s of %llu exceeds maximum of %u\n" , name, value, max); -return -EINVAL ; - } -return value; -} - -static int efidrm_get_validated_int0 (struct drm_device *dev,const char *name, -u64 value,u32 max) -{ -if (!value) { -drm_err (dev,"%s of 0 not allowed\n" , name); -return -EINVAL ; - } -return efidrm_get_validated_int (dev, name, value, max); -} -static s64 efidrm_get_validated_size0 (struct drm_device *dev,const char *name,u64 value,u64 max) {
@@ -70,12 +48,12 @@ static s64 efidrm_get_validated_size0(struct drm_device *dev, const char *name,static int efidrm_get_width_si (struct drm_device *dev,const struct screen_info *si) { -return efidrm_get_validated_int0 (dev,"width" , si->lfb_width,U16_MAX ); +return drm_sysfb_get_validated_int0 (dev,"width" , si->lfb_width,U16_MAX ); }static int efidrm_get_height_si (struct drm_device *dev,const struct screen_info *si) { -return efidrm_get_validated_int0 (dev,"height" , si->lfb_height,U16_MAX ); +return drm_sysfb_get_validated_int0 (dev,"height" , si->lfb_height,U16_MAX ); } static struct resource *efidrm_get_memory_si(struct drm_device *dev,
@@ -102,7 +80,8 @@ static int efidrm_get_stride_si(struct drm_device *dev, const struct screen_infoif (!lfb_linelength) lfb_linelength =drm_format_info_min_pitch (format,0 , width); -return efidrm_get_validated_int0 (dev,"stride" , lfb_linelength,div64_u64 (size, height)); +return drm_sysfb_get_validated_int0 (dev,"stride" , lfb_linelength, +div64_u64 (size, height)); } static u64 efidrm_get_visible_size_si(struct drm_device *dev, const struct screen_info *si,
drivers/gpu/drm/sysfb/ofdrm.c +2 -10
@@ -78,20 +78,12 @@ enum ofdrm_model {static int display_get_validated_int (struct drm_device *dev,const char *name,uint32_t value) { -if (value >INT_MAX ) { -drm_err (dev,"invalid framebuffer %s of %u\n" , name, value); -return -EINVAL ; - } -return (int )value; +return drm_sysfb_get_validated_int (dev, name, value,INT_MAX ); }static int display_get_validated_int0 (struct drm_device *dev,const char *name,uint32_t value) { -if (!value) { -drm_err (dev,"invalid framebuffer %s of %u\n" , name, value); -return -EINVAL ; - } -return display_get_validated_int (dev, name, value); +return drm_sysfb_get_validated_int0 (dev, name, value,INT_MAX ); } static const struct drm_format_info *display_get_validated_format(struct drm_device *dev,
drivers/gpu/drm/sysfb/simpledrm.c +2 -12
@@ -42,24 +42,14 @@ static int simplefb_get_validated_int(struct drm_device *dev, const char *name, uint32_t value) { - if (value > INT_MAX) { - drm_err(dev, "simplefb: invalid framebuffer %s of %u\n", - name, value); -return -EINVAL ; - } -return (int )value; + return drm_sysfb_get_validated_int(dev, name, value, INT_MAX); }static int simplefb_get_validated_int0 (struct drm_device *dev,const char *name,uint32_t value) { -if (!value) { -drm_err (dev,"simplefb: invalid framebuffer %s of %u\n" , - name, value); -return -EINVAL ; - } -return simplefb_get_validated_int (dev, name, value); +return drm_sysfb_get_validated_int0 (dev, name, value,INT_MAX ); } static const struct drm_format_info *
drivers/gpu/drm/sysfb/vesadrm.c +4 -25
@@ -36,28 +36,6 @@#define VESADRM_GAMMA_LUT_SIZE 256 -static int vesadrm_get_validated_int (struct drm_device *dev,const char *name, -u64 value,u32 max) -{ -if (max >INT_MAX ) - max =INT_MAX ; -if (value > max) { -drm_err (dev,"%s of %llu exceeds maximum of %u\n" , name, value, max); -return -EINVAL ; - } -return value; -} - -static int vesadrm_get_validated_int0 (struct drm_device *dev,const char *name, -u64 value,u32 max) -{ -if (!value) { -drm_err (dev,"%s of 0 not allowed\n" , name); -return -EINVAL ; - } -return vesadrm_get_validated_int (dev, name, value, max); -} -static s64 vesadrm_get_validated_size0 (struct drm_device *dev,const char *name,u64 value,u64 max) {
@@ -73,12 +51,12 @@ static s64 vesadrm_get_validated_size0(struct drm_device *dev, const char *name,static int vesadrm_get_width_si (struct drm_device *dev,const struct screen_info *si) { -return vesadrm_get_validated_int0 (dev,"width" , si->lfb_width,U16_MAX ); +return drm_sysfb_get_validated_int0 (dev,"width" , si->lfb_width,U16_MAX ); }static int vesadrm_get_height_si (struct drm_device *dev,const struct screen_info *si) { -return vesadrm_get_validated_int0 (dev,"height" , si->lfb_height,U16_MAX ); +return drm_sysfb_get_validated_int0 (dev,"height" , si->lfb_height,U16_MAX ); } static struct resource *vesadrm_get_memory_si(struct drm_device *dev,
@@ -105,7 +83,8 @@ static int vesadrm_get_stride_si(struct drm_device *dev, const struct screen_infif (!lfb_linelength) lfb_linelength =drm_format_info_min_pitch (format,0 , width); -return vesadrm_get_validated_int0 (dev,"stride" , lfb_linelength,div64_u64 (size, height)); +return drm_sysfb_get_validated_int0 (dev,"stride" , lfb_linelength, +div64_u64 (size, height)); } static u64 vesadrm_get_visible_size_si(struct drm_device *dev, const struct screen_info *si,
Signature · 1 line
2.49.0
Thomas Zimmermann
maintainerPATCH v2 3/3 drm/sysfb: Share helpers for screen_info validation
In reply to Thomas ZimmermannShare efidrm's and vesadrm's validation of struct screen_info in shared helpers. Update the drivers.
Most validation helpers test individual values against limits and can be shared as they are. For color formats, a common helper looks up the correct DRM format info from a driver-provided list of color formats.
These screen_info helpers are only available if CONFIG_SCREEN_INFO has been selected, as done by efidrm and vesadrm.
--- drivers/gpu/drm/sysfb/Makefile | 1 + drivers/gpu/drm/sysfb/drm_sysfb_helper.h | 34 ++++++ drivers/gpu/drm/sysfb/drm_sysfb_screen_info.c | 107 ++++++++++++++++++ drivers/gpu/drm/sysfb/efidrm.c | 105 ++--------------- drivers/gpu/drm/sysfb/vesadrm.c | 105 ++--------------- 5 files changed, 160 insertions(+), 192 deletions(-) create mode 100644 drivers/gpu/drm/sysfb/drm_sysfb_screen_info.c
drivers/gpu/drm/sysfb/Makefile +1 -0
@@ -3,6 +3,7 @@ drm_sysfb_helper-y := \ drm_sysfb.o \ drm_sysfb_modeset.o +drm_sysfb_helper-$(CONFIG_SCREEN_INFO) += drm_sysfb_screen_info.o obj-$(CONFIG_DRM_SYSFB_HELPER) += drm_sysfb_helper.o obj-$(CONFIG_DRM_EFIDRM) += efidrm.o
drivers/gpu/drm/sysfb/drm_sysfb_helper.h +34 -0
@@ -6,12 +6,46 @@#include <linux/container_of.h> #include <linux/iosys-map.h> +#include <video/pixel_format.h> +#include <drm/drm_crtc.h> #include <drm/drm_device.h> #include <drm/drm_modes.h> struct drm_format_info ;struct drm_scanout_buffer ; +struct screen_info ; + +/* +* Input parsing +*/ + +struct drm_sysfb_format { +struct pixel_format pixel; +u32 fourcc; +}; + +int drm_sysfb_get_validated_int (struct drm_device *dev,const char *name, +u64 value,u32 max); +int drm_sysfb_get_validated_int0 (struct drm_device *dev,const char *name, +u64 value,u32 max); + +#if defined(CONFIG_SCREEN_INFO ) +int drm_sysfb_get_width_si (struct drm_device *dev,const struct screen_info *si); +int drm_sysfb_get_height_si (struct drm_device *dev,const struct screen_info *si); +struct resource *drm_sysfb_get_memory_si (struct drm_device *dev, +const struct screen_info *si, +struct resource *res); +int drm_sysfb_get_stride_si (struct drm_device *dev,const struct screen_info *si, +const struct drm_format_info *format, +unsigned int width,unsigned int height,u64 size); +u64 drm_sysfb_get_visible_size_si (struct drm_device *dev,const struct screen_info *si, +unsigned int height,unsigned int stride,u64 size); +const struct drm_format_info *drm_sysfb_get_format_si (struct drm_device *dev, +const struct drm_sysfb_format *formats, +size_t nformats, +const struct screen_info *si); +#endif /* * Input parsing
drivers/gpu/drm/sysfb/drm_sysfb_screen_info.c new file +107 -0
107 lines not on this page · raw message
drivers/gpu/drm/sysfb/efidrm.c +9 -96
135 lines not on this page · raw message
drivers/gpu/drm/sysfb/vesadrm.c +9 -96
135 lines not on this page · raw message
Signature · 1 line
2.49.0