drm/panic: Add a drm panic handler
Subsystems (7)
Jocelyn Falempe
maintainerv5 cover drm/panic: Add a drm panic handler
This introduces a new drm panic handler, which displays a message when a panic occurs. So when fbcon is disabled, you can still see a kernel panic.
This is one of the missing feature, when disabling VT/fbcon in the kernel:
https://www.reddit.com/r/linux/comments/10eccv9/config_vtn_in_2023/
Fbcon can be replaced by a userspace kms console, but the panic screen must be done in the kernel.
This is a proof of concept, and works with simpledrm and mgag200, using a new get_scanout_buffer() api
To test it, make sure you're using the simpledrm driver, and trigger a panic:
echo c > /proc/sysrq-trigger
v2:
* Use get_scanout_buffer() instead of the drm client API. (Thomas Zimmermann)
* Add the panic reason to the panic message (Nerdopolis)
* Add an exclamation mark (Nerdopolis)
v3:
* Rework the drawing functions, to write the pixels line by line and to use the drm conversion helper to support other formats. (Thomas Zimmermann)
v4:
* Fully support all simpledrm formats using drm conversion helpers
* Rename dpanic_* to drm_panic_*, and have more coherent function name. (Thomas Zimmermann)
* Use drm_fb_r1_to_32bit for fonts (Thomas Zimmermann)
* Remove the default y to DRM_PANIC config option (Thomas Zimmermann)
* Add foreground/background color config option
* Fix the bottom lines not painted if the framebuffer height is not a multiple of the font height.
* Automatically register the driver to drm_panic, if the function get_scanout_buffer() exists. (Thomas Zimmermann)
* Add mgag200 support.
v5:
* Change the drawing API, use drm_fb_blit_from_r1() to draw the font. (Thomas Zimmermann)
* Also add drm_fb_fill() to fill area with background color.
* Add draw_pixel_xy() API for drivers that can't provide a linear buffer.
* Add a flush() callback for drivers that needs to synchronize the buffer.
* Add a void *private field, so drivers can pass private data to draw_pixel_xy() and flush().
* Add ast support.
* Add experimental imx/ipuv3 support, to test on an ARM hw. (Maxime Ripard)
With mgag200 support, I was able to test that the xrgb8888 to rgb565 conversion is working.
IMX/IPUV3 support is not complete, I wasn't able to have etnaviv working on my board. But it shows that it can still work on ARM with DMA buffer in this case.
Best regards,
Jocelyn Falempe (6):
drm/format-helper: Add drm_fb_blit_from_r1 and drm_fb_fill drm/panic: Add a drm panic handler drm/simpledrm: Add drm_panic support drm/mgag200: Add drm_panic support
drm/ast: Add drm_panic support
drm/imx: Add drm_panic support
drivers/gpu/drm/Kconfig | 22 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/ast/ast_drv.c | 4 +- drivers/gpu/drm/ast/ast_drv.h | 3 + drivers/gpu/drm/ast/ast_mode.c | 26 ++ drivers/gpu/drm/drm_drv.c | 8 + drivers/gpu/drm/drm_format_helper.c | 421 ++++++++++++++++++----- drivers/gpu/drm/drm_panic.c | 368 ++++++++++++++++++++ drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 30 ++ drivers/gpu/drm/mgag200/mgag200_drv.c | 25 ++ drivers/gpu/drm/tiny/simpledrm.c | 15 + include/drm/drm_drv.h | 21 ++ include/drm/drm_format_helper.h | 9 + include/drm/drm_panic.h | 96 ++++++ 14 files changed, 966 insertions(+), 83 deletions(-) create mode 100644 drivers/gpu/drm/drm_panic.c create mode 100644 include/drm/drm_panic.h
base-commit: ffc253263a1375a65fa6c9f62a893e9767fbebfa
Signature · 1 line
2.41.0
Jocelyn Falempe
maintainerPATCH v5 1/6 drm/format-helper: Add drm_fb_blit_from_r1 and drm_fb_fill
This is needed for drm_panic, to draw the font, and fill the background color, in multiple color format.
v5:
* Change the drawing API, use drm_fb_blit_from_r1() to draw the font.
* Also add drm_fb_fill() to fill area with background color.
--- drivers/gpu/drm/drm_format_helper.c | 421 ++++++++++++++++++++++------ include/drm/drm_format_helper.h | 9 + 2 files changed, 349 insertions(+), 81 deletions(-)
drivers/gpu/drm/drm_format_helper.c +340 -81
@@ -20,6 +20,147 @@#include <drm/drm_print.h> #include <drm/drm_rect.h> +static inline u16 drm_format_xrgb8888_to_rgb565 (u32 pix) +{ +u16 val16; + + pix =le32_to_cpu (pix); + val16 = ((pix &0x00F80000 ) >>8 ) | + ((pix &0x0000FC00 ) >>5 ) | + ((pix &0x000000F8 ) >>3 ); +return cpu_to_le16 (val16); +} + +static inline u16 drm_format_xrgb8888_to_rgba5551 (u32 pix) +{ +u16 val16; + + pix =le32_to_cpu (pix); + val16 = ((pix &0x00f80000 ) >>8 ) | + ((pix &0x0000f800 ) >>5 ) | + ((pix &0x000000f8 ) >>2 ) | +BIT (0 );/* set alpha bit */ +return cpu_to_le16 (val16); +} + +static inline u16 drm_format_xrgb8888_to_xrgb1555 (u32 pix) +{ +u16 val16; + + pix =le32_to_cpu (pix); + val16 = ((pix &0x00f80000 ) >>9 ) | + ((pix &0x0000f800 ) >>6 ) | + ((pix &0x000000f8 ) >>3 ); +return cpu_to_le16 (val16); +} + +static inline u16 drm_format_xrgb8888_to_argb1555 (u32 pix) +{ +u16 val16; + + pix =le32_to_cpu (pix); + val16 =BIT (15 ) |/* set alpha bit */ + ((pix &0x00f80000 ) >>9 ) | + ((pix &0x0000f800 ) >>6 ) | + ((pix &0x000000f8 ) >>3 ); +return cpu_to_le16 (val16); +} + +static inline u32 drm_format_xrgb8888_to_argb8888 (u32 pix) +{ +u32 val32; + + val32 =le32_to_cpu (pix); + val32 |=GENMASK (31 ,24 );/* fill alpha bits */ +return cpu_to_le32 (val32); +} + +static inline u32 drm_format_xrgb8888_to_xbgr8888 (u32 pix) +{ +u32 val32; + + pix =le32_to_cpu (pix); + val32 = ((pix &0x00ff0000 ) >>16 ) <<0 | + ((pix &0x0000ff00 ) >>8 ) <<8 | + ((pix &0x000000ff ) >>0 ) <<16 | + ((pix &0xff000000 ) >>24 ) <<24 ; +return cpu_to_le32 (val32); +} + +static inline u32 drm_format_xrgb8888_to_abgr8888 (u32 pix) +{ +u32 val32; + + pix =le32_to_cpu (pix); + val32 = ((pix &0x00ff0000 ) >>16 ) <<0 | + ((pix &0x0000ff00 ) >>8 ) <<8 | + ((pix &0x000000ff ) >>0 ) <<16 | +GENMASK (31 ,24 );/* fill alpha bits */ +return cpu_to_le32 (val32); +} + +static inline u32 drm_format_xrgb8888_to_xrgb2101010 (u32 pix) +{ +u32 val32; + + pix =le32_to_cpu (pix); + val32 = ((pix &0x000000FF ) <<2 ) | + ((pix &0x0000FF00 ) <<4 ) | + ((pix &0x00FF0000 ) <<6 ); + pix = val32 | ((val32 >>8 ) &0x00300C03 ); +return cpu_to_le32 (pix); +} + +static inline u32 drm_format_xrgb8888_to_argb2101010 (u32 pix) +{ +u32 val32; + + pix =le32_to_cpu (pix); + val32 = ((pix &0x000000FF ) <<2 ) | + ((pix &0x0000FF00 ) <<4 ) | + ((pix &0x00FF0000 ) <<6 ); + pix =GENMASK (31 ,30 ) |/* set alpha bits */ + val32 | ((val32 >>8 ) &0x00300c03 ); +return cpu_to_le32 (pix); +} + +/** +* drm_fb_convert_from_xrgb8888 - convert one pixel from xrgb8888 to the desired format +* @color: input color, in xrgb8888 format +* @format: output format +* +* Returns: +* Color in the format specified, casted to u32. +*/ +u32 drm_fb_convert_from_xrgb8888 (u32 color,u32 format) +{ +switch (format) { +case DRM_FORMAT_RGB565 : +return drm_format_xrgb8888_to_rgb565 (color); +case DRM_FORMAT_RGBA5551 : +return drm_format_xrgb8888_to_rgba5551 (color); +case DRM_FORMAT_XRGB1555 : +return drm_format_xrgb8888_to_xrgb1555 (color); +case DRM_FORMAT_ARGB1555 : +return drm_format_xrgb8888_to_argb1555 (color); +case DRM_FORMAT_RGB888 : +case DRM_FORMAT_XRGB8888 : +return color; +case DRM_FORMAT_ARGB8888 : +return drm_format_xrgb8888_to_argb8888 (color); +case DRM_FORMAT_XBGR8888 : +return drm_format_xrgb8888_to_xbgr8888 (color); +case DRM_FORMAT_XRGB2101010 : +return drm_format_xrgb8888_to_xrgb2101010 (color); +case DRM_FORMAT_ARGB2101010 : +return drm_format_xrgb8888_to_argb2101010 (color); +default : +WARN_ONCE (1 ,"Can't convert to %p4cc\n" , &format); +return color; + } +} +EXPORT_SYMBOL (drm_fb_convert_from_xrgb8888); +static unsigned int clip_offset (const struct drm_rect *clip,unsigned int pitch,unsigned int cpp) {return clip->y1 * pitch + clip->x1 * cpp;
@@ -272,6 +413,188 @@ void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch, }EXPORT_SYMBOL (drm_fb_swab); +static void drm_fb_r1_to_16bit (struct iosys_map *dmap,unsigned int dpitch, +const u8 *sbuf8,unsigned int spitch, +unsigned int height,unsigned int width, +u16 fg16,u16 bg16) +{ +unsigned int l, x; +u16 val16; + +for (l =0 ; l < height; l++) { +for (x =0 ; x < width; x++) { + val16 = (sbuf8[(l * spitch) + x /8 ] & (0x80 >> (x %8 ))) ? fg16 : bg16; +iosys_map_wr (dmap, l * dpitch + x *sizeof (u16), u16, val16); + } + } +} + +static void drm_fb_r1_to_24bit (struct iosys_map *dmap,unsigned int dpitch, +const u8 *sbuf8,unsigned int spitch, +unsigned int height,unsigned int width, +u32 fg32,u32 bg32) +{ +unsigned int l, x; +u32 val32; + +for (l =0 ; l < height; l++) { +for (x =0 ; x < width; x++) { +u32 off = l * dpitch + x *3 ; + + val32 = (sbuf8[(l * spitch) + x /8 ] & (0x80 >> (x %8 ))) ? fg32 : bg32; + val32 =le32_to_cpu (val32); + +/* write blue-green-red to output in little endianness */ +iosys_map_wr (dmap, off, u8, (val32 &0x000000FF ) >>0 ); +iosys_map_wr (dmap, off +1 , u8, (val32 &0x0000FF00 ) >>8 ); +iosys_map_wr (dmap, off +2 , u8, (val32 &0x00FF0000 ) >>16 ); + } + } +} + +static void drm_fb_r1_to_32bit (struct iosys_map *dmap,unsigned int dpitch, +const u8 *sbuf8,unsigned int spitch, +unsigned int height,unsigned int width, +u32 fg32,u32 bg32) +{ +unsigned int l, x; +u32 val32; + +for (l =0 ; l < height; l++) { +for (x =0 ; x < width; x++) { + val32 = (sbuf8[(l * spitch) + x /8 ] & (0x80 >> (x %8 ))) ? fg32 : bg32; +iosys_map_wr (dmap, l * dpitch + x *sizeof (u32), u32, val32); + } + } +} + +/** +* drm_fb_blit_from_r1 - convert a monochrome image to a linear framebuffer +* @dmap: destination iosys_map +* @dpich: destination pitch in bytes +* @sbuf8: source buffer, in monochrome format, 8 pixels per byte. +* @spitch: source pitch in bytes +* @height: height of the image to copy, in pixels +* @width: width of the image to copy, in pixels +* @fg_color: foreground color, in destination format +* @bg_color: background color, in destination format +* @pixel_width: pixel width in bytes. +* +* This can be used to draw font which are monochrome images, to a framebuffer +* in other supported format. +*/ +void drm_fb_blit_from_r1 (struct iosys_map *dmap,unsigned int dpitch, +const u8 *sbuf8,unsigned int spitch, +unsigned int height,unsigned int width, +u32 fg_color,u32 bg_color, +unsigned int pixel_width) +{ +switch (pixel_width) { +case 2 : +drm_fb_r1_to_16bit (dmap, dpitch, sbuf8, spitch, + height, width, fg_color, bg_color); +break ; +case 3 : +drm_fb_r1_to_24bit (dmap, dpitch, sbuf8, spitch, + height, width, fg_color, bg_color); +break ; +case 4 : +drm_fb_r1_to_32bit (dmap, dpitch, sbuf8, spitch, + height, width, fg_color, bg_color); +break ; +default : +WARN_ONCE (1 ,"Can't blit with pixel width %d\n" , pixel_width); + } +} +EXPORT_SYMBOL (drm_fb_blit_from_r1); + +static void drm_fb_fill8 (struct iosys_map *dmap,unsigned int dpitch, +unsigned int height,unsigned int width, +u8 color) +{ +unsigned int l, x; + +for (l =0 ; l < height; l++) +for (x =0 ; x < width; x++) +iosys_map_wr (dmap, l * dpitch + x *sizeof (u8), u8, color); +} + +static void drm_fb_fill16 (struct iosys_map *dmap,unsigned int dpitch, +unsigned int height,unsigned int width, +u16 color) +{ +unsigned int l, x; + +for (l =0 ; l < height; l++) +for (x =0 ; x < width; x++) +iosys_map_wr (dmap, l * dpitch + x *sizeof (u16), u16, color); +} + +static void drm_fb_fill24 (struct iosys_map *dmap,unsigned int dpitch, +unsigned int height,unsigned int width, +u32 color) +{ +unsigned int l, x; + +for (l =0 ; l < height; l++) { +for (x =0 ; x < width; x++) { +unsigned int off = l * dpitch + x *3 ; +u32 val32 =le32_to_cpu (color); + +/* write blue-green-red to output in little endianness */ +iosys_map_wr (dmap, off, u8, (val32 &0x000000FF ) >>0 ); +iosys_map_wr (dmap, off +1 , u8, (val32 &0x0000FF00 ) >>8 ); +iosys_map_wr (dmap, off +2 , u8, (val32 &0x00FF0000 ) >>16 ); + } + } +} + +static void drm_fb_fill32 (struct iosys_map *dmap,unsigned int dpitch, +unsigned int height,unsigned int width, +u32 color) +{ +unsigned int l, x; + +for (l =0 ; l < height; l++) +for (x =0 ; x < width; x++) +iosys_map_wr (dmap, l * dpitch + x *sizeof (u32), u32, color); +} + +/** +* drm_fb_fill - Fill a rectangle with a color +* @dmap: destination iosys_map, pointing to the top left corner of the rectangle +* @dpich: destination pitch in bytes +* @height: height of the rectangle, in pixels +* @width: width of the rectangle, in pixels +* @fg_color: foreground color, in destination format +* @bg_color: background color, in destination format +* @pixel_width: pixel width in bytes +* +* Fill a rectangle with a color, in a linear framebuffer. +*/ +void drm_fb_fill (struct iosys_map *dmap,unsigned int dpitch, +unsigned int height,unsigned int width, +u32 color,unsigned int pixel_width) +{ +switch (pixel_width) { +case 1 : +drm_fb_fill8 (dmap, dpitch, height, width, color); +break ; +case 2 : +drm_fb_fill16 (dmap, dpitch, height, width, color); +break ; +case 3 : +drm_fb_fill24 (dmap, dpitch, height, width, color); +break ; +case 4 : +drm_fb_fill32 (dmap, dpitch, height, width, color); +break ; +default : +WARN_ONCE (1 ,"Can't fill with pixel width %d\n" , pixel_width); + } +} +EXPORT_SYMBOL (drm_fb_fill); +static void drm_fb_xrgb8888_to_rgb332_line (void *dbuf,const void *sbuf,unsigned int pixels) {u8 *dbuf8 = dbuf;
@@ -325,15 +648,9 @@ static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigne__le16 *dbuf16 = dbuf;const __le32 *sbuf32 = sbuf;unsigned int x; -u16 val16; -u32 pix;for (x =0 ; x < pixels; x++) { - pix =le32_to_cpu (sbuf32[x]); - val16 = ((pix &0x00F80000 ) >>8 ) | - ((pix &0x0000FC00 ) >>5 ) | - ((pix &0x000000F8 ) >>3 ); - dbuf16[x] =cpu_to_le16 (val16); + dbuf16[x] =drm_format_xrgb8888_to_rgb565 (sbuf32[x]); } }
@@ -401,16 +718,9 @@ static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsig__le16 *dbuf16 = dbuf;const __le32 *sbuf32 = sbuf;unsigned int x; -u16 val16; -u32 pix; -for (x =0 ; x < pixels; x++) { - pix =le32_to_cpu (sbuf32[x]); - val16 = ((pix &0x00f80000 ) >>9 ) | - ((pix &0x0000f800 ) >>6 ) | - ((pix &0x000000f8 ) >>3 ); - dbuf16[x] =cpu_to_le16 (val16); - } +for (x =0 ; x < pixels; x++) + dbuf16[x] =drm_format_xrgb8888_to_xrgb1555 (sbuf32[x]); }/**
@@ -452,17 +762,9 @@ static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsig__le16 *dbuf16 = dbuf;const __le32 *sbuf32 = sbuf;unsigned int x; -u16 val16; -u32 pix; -for (x =0 ; x < pixels; x++) { - pix =le32_to_cpu (sbuf32[x]); - val16 =BIT (15 ) |/* set alpha bit */ - ((pix &0x00f80000 ) >>9 ) | - ((pix &0x0000f800 ) >>6 ) | - ((pix &0x000000f8 ) >>3 ); - dbuf16[x] =cpu_to_le16 (val16); - } +for (x =0 ; x < pixels; x++) + dbuf16[x] =drm_format_xrgb8888_to_argb1555 (sbuf32[x]); }/**
@@ -504,17 +806,9 @@ static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsig__le16 *dbuf16 = dbuf;const __le32 *sbuf32 = sbuf;unsigned int x; -u16 val16; -u32 pix; -for (x =0 ; x < pixels; x++) { - pix =le32_to_cpu (sbuf32[x]); - val16 = ((pix &0x00f80000 ) >>8 ) | - ((pix &0x0000f800 ) >>5 ) | - ((pix &0x000000f8 ) >>2 ) | -BIT (0 );/* set alpha bit */ - dbuf16[x] =cpu_to_le16 (val16); - } +for (x =0 ; x < pixels; x++) + dbuf16[x] =drm_format_xrgb8888_to_rgba5551 (sbuf32[x]); }/**
@@ -606,13 +900,9 @@ static void drm_fb_xrgb8888_to_argb8888_line(void *dbuf, const void *sbuf, unsig__le32 *dbuf32 = dbuf;const __le32 *sbuf32 = sbuf;unsigned int x; -u32 pix; -for (x =0 ; x < pixels; x++) { - pix =le32_to_cpu (sbuf32[x]); - pix |=GENMASK (31 ,24 );/* fill alpha bits */ - dbuf32[x] =cpu_to_le32 (pix); - } +for (x =0 ; x < pixels; x++) + dbuf32[x] =drm_format_xrgb8888_to_argb8888 (sbuf32[x]); }/**
@@ -654,16 +944,9 @@ static void drm_fb_xrgb8888_to_abgr8888_line(void *dbuf, const void *sbuf, unsig__le32 *dbuf32 = dbuf;const __le32 *sbuf32 = sbuf;unsigned int x; -u32 pix; -for (x =0 ; x < pixels; x++) { - pix =le32_to_cpu (sbuf32[x]); - pix = ((pix &0x00ff0000 ) >>16 ) <<0 | - ((pix &0x0000ff00 ) >>8 ) <<8 | - ((pix &0x000000ff ) >>0 ) <<16 | -GENMASK (31 ,24 );/* fill alpha bits */ - *dbuf32++ =cpu_to_le32 (pix); - } +for (x =0 ; x < pixels; x++) + *dbuf32++ =drm_format_xrgb8888_to_abgr8888 (sbuf32[x]); } static void drm_fb_xrgb8888_to_abgr8888(struct iosys_map *dst, const unsigned int *dst_pitch,
@@ -684,16 +967,9 @@ static void drm_fb_xrgb8888_to_xbgr8888_line(void *dbuf, const void *sbuf, unsig__le32 *dbuf32 = dbuf;const __le32 *sbuf32 = sbuf;unsigned int x; -u32 pix; -for (x =0 ; x < pixels; x++) { - pix =le32_to_cpu (sbuf32[x]); - pix = ((pix &0x00ff0000 ) >>16 ) <<0 | - ((pix &0x0000ff00 ) >>8 ) <<8 | - ((pix &0x000000ff ) >>0 ) <<16 | - ((pix &0xff000000 ) >>24 ) <<24 ; - *dbuf32++ =cpu_to_le32 (pix); - } +for (x =0 ; x < pixels; x++) + *dbuf32++ =drm_format_xrgb8888_to_xbgr8888 (sbuf32[x]); } static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned int *dst_pitch,
@@ -714,17 +990,9 @@ static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, un__le32 *dbuf32 = dbuf;const __le32 *sbuf32 = sbuf;unsigned int x; -u32 val32; -u32 pix; -for (x =0 ; x < pixels; x++) { - pix =le32_to_cpu (sbuf32[x]); - val32 = ((pix &0x000000FF ) <<2 ) | - ((pix &0x0000FF00 ) <<4 ) | - ((pix &0x00FF0000 ) <<6 ); - pix = val32 | ((val32 >>8 ) &0x00300C03 ); - *dbuf32++ =cpu_to_le32 (pix); - } +for (x =0 ; x < pixels; x++) + *dbuf32++ =drm_format_xrgb8888_to_xrgb2101010 (sbuf32[x]); }/**
@@ -766,18 +1034,9 @@ static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, un__le32 *dbuf32 = dbuf;const __le32 *sbuf32 = sbuf;unsigned int x; -u32 val32; -u32 pix; -for (x =0 ; x < pixels; x++) { - pix =le32_to_cpu (sbuf32[x]); - val32 = ((pix &0x000000ff ) <<2 ) | - ((pix &0x0000ff00 ) <<4 ) | - ((pix &0x00ff0000 ) <<6 ); - pix =GENMASK (31 ,30 ) |/* set alpha bits */ - val32 | ((val32 >>8 ) &0x00300c03 ); - *dbuf32++ =cpu_to_le32 (pix); - } +for (x =0 ; x < pixels; x++) + *dbuf32++ =drm_format_xrgb8888_to_argb2101010 (sbuf32[x]); }/**
include/drm/drm_format_helper.h +9 -0
@@ -15,6 +15,7 @@ struct drm_rect;struct iosys_map ; +u32 drm_fb_convert_from_xrgb8888 (u32 color,u32 format);unsigned int drm_fb_clip_offset (unsigned int pitch,const struct drm_format_info *format,const struct drm_rect *clip);
@@ -24,6 +25,14 @@ void drm_fb_memcpy(struct iosys_map *dst, const unsigned int *dst_pitch,void drm_fb_swab (struct iosys_map *dst,const unsigned int *dst_pitch,const struct iosys_map *src,const struct drm_framebuffer *fb,const struct drm_rect *clip,bool cached); +void drm_fb_blit_from_r1 (struct iosys_map *dmap,unsigned int dpitch, +const u8 *sbuf8,unsigned int spitch, +unsigned int height,unsigned int width, +u32 fg_color,u32 bg_color, +unsigned int pixel_width); +void drm_fb_fill (struct iosys_map *dmap,unsigned int dpitch, +unsigned int height,unsigned int width, +u32 color,unsigned int pixel_width);void drm_fb_xrgb8888_to_rgb332 (struct iosys_map *dst,const unsigned int *dst_pitch,const struct iosys_map *src,const struct drm_framebuffer *fb,const struct drm_rect *clip);
Signature · 1 line
2.41.0
kernel test robot
build botRe: [PATCH v5 1/6] drm/format-helper: Add drm_fb_blit_from_r1 and drm_fb_fill
kernel test robot noticed the following build warnings:
Hi Jocelyn,
kernel test robot noticed the following build warnings:
[auto build test WARNING on ffc253263a1375a65fa6c9f62a893e9767fbebfa]
url: https://github.com/intel-lab-lkp/linux/commits/Jocelyn-Falempe/drm-format-helper-Add-drm_fb_blit_from_r1-and-drm_fb_fill/20231103-225824 base: ffc253263a1375a65fa6c9f62a893e9767fbebfa patch link: https://lore.kernel.org/r/20231103145526.628138-2-jfalempe%40redhat.com patch subject: [PATCH v5 1/6] drm/format-helper: Add drm_fb_blit_from_r1 and drm_fb_fill config: csky-randconfig-002-20231104 (https://download.01.org/0day-ci/archive/20231104/[email protected]/config) compiler: csky-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/drm_format_helper.c:491: warning: Function parameter or member 'dpitch' not described in 'drm_fb_blit_from_r1' >> drivers/gpu/drm/drm_format_helper.c:491: warning: Excess function parameter 'dpich' description in 'drm_fb_blit_from_r1' >> drivers/gpu/drm/drm_format_helper.c:578: warning: Function parameter or member 'dpitch' not described in 'drm_fb_fill' >> drivers/gpu/drm/drm_format_helper.c:578: warning: Function parameter or member 'color' not described in 'drm_fb_fill' >> drivers/gpu/drm/drm_format_helper.c:578: warning: Excess function parameter 'dpich' description in 'drm_fb_fill' >> drivers/gpu/drm/drm_format_helper.c:578: warning: Excess function parameter 'fg_color' description in 'drm_fb_fill' >> drivers/gpu/drm/drm_format_helper.c:578: warning: Excess function parameter 'bg_color' description in 'drm_fb_fill'
vim +491 drivers/gpu/drm/drm_format_helper.c
470
471 /**
472 * drm_fb_blit_from_r1 - convert a monochrome image to a linear framebuffer
473 * @dmap: destination iosys_map
474 * @dpich: destination pitch in bytes
475 * @sbuf8: source buffer, in monochrome format, 8 pixels per byte.
476 * @spitch: source pitch in bytes
477 * @height: height of the image to copy, in pixels
478 * @width: width of the image to copy, in pixels
479 * @fg_color: foreground color, in destination format
480 * @bg_color: background color, in destination format
481 * @pixel_width: pixel width in bytes.
482 *
483 * This can be used to draw font which are monochrome images, to a framebuffer
484 * in other supported format.
485 */
486 void drm_fb_blit_from_r1(struct iosys_map *dmap, unsigned int dpitch,
487 const u8 *sbuf8, unsigned int spitch,
488 unsigned int height, unsigned int width,
489 u32 fg_color, u32 bg_color,
490 unsigned int pixel_width)
> 491 {
492 switch (pixel_width) {
493 case 2:
494 drm_fb_r1_to_16bit(dmap, dpitch, sbuf8, spitch,
495 height, width, fg_color, bg_color);
496 break;
497 case 3:
498 drm_fb_r1_to_24bit(dmap, dpitch, sbuf8, spitch,
499 height, width, fg_color, bg_color);
500 break;
501 case 4:
502 drm_fb_r1_to_32bit(dmap, dpitch, sbuf8, spitch,
503 height, width, fg_color, bg_color);
504 break;
505 default:
506 WARN_ONCE(1, "Can't blit with pixel width %d\n", pixel_width);
507 }
508 }
509 EXPORT_SYMBOL(drm_fb_blit_from_r1);
510
511 static void drm_fb_fill8(struct iosys_map *dmap, unsigned int dpitch,
512 unsigned int height, unsigned int width,
513 u8 color)
514 {
515 unsigned int l, x;
516
517 for (l = 0; l < height; l++)
518 for (x = 0; x < width; x++)
519 iosys_map_wr(dmap, l * dpitch + x * sizeof(u8), u8, color);
520 }
521
522 static void drm_fb_fill16(struct iosys_map *dmap, unsigned int dpitch,
523 unsigned int height, unsigned int width,
524 u16 color)
525 {
526 unsigned int l, x;
527
528 for (l = 0; l < height; l++)
529 for (x = 0; x < width; x++)
530 iosys_map_wr(dmap, l * dpitch + x * sizeof(u16), u16, color);
531 }
532
533 static void drm_fb_fill24(struct iosys_map *dmap, unsigned int dpitch,
534 unsigned int height, unsigned int width,
535 u32 color)
536 {
537 unsigned int l, x;
538
539 for (l = 0; l < height; l++) {
540 for (x = 0; x < width; x++) {
541 unsigned int off = l * dpitch + x * 3;
542 u32 val32 = le32_to_cpu(color);
543
544 /* write blue-green-red to output in little endianness */
545 iosys_map_wr(dmap, off, u8, (val32 & 0x000000FF) >> 0);
546 iosys_map_wr(dmap, off + 1, u8, (val32 & 0x0000FF00) >> 8);
547 iosys_map_wr(dmap, off + 2, u8, (val32 & 0x00FF0000) >> 16);
548 }
549 }
550 }
551
552 static void drm_fb_fill32(struct iosys_map *dmap, unsigned int dpitch,
553 unsigned int height, unsigned int width,
554 u32 color)
555 {
556 unsigned int l, x;
557
558 for (l = 0; l < height; l++)
559 for (x = 0; x < width; x++)
560 iosys_map_wr(dmap, l * dpitch + x * sizeof(u32), u32, color);
561 }
562
563 /**
564 * drm_fb_fill - Fill a rectangle with a color
565 * @dmap: destination iosys_map, pointing to the top left corner of the rectangle
566 * @dpich: destination pitch in bytes
567 * @height: height of the rectangle, in pixels
568 * @width: width of the rectangle, in pixels
569 * @fg_color: foreground color, in destination format
570 * @bg_color: background color, in destination format
571 * @pixel_width: pixel width in bytes
572 *
573 * Fill a rectangle with a color, in a linear framebuffer.
574 */
575 void drm_fb_fill(struct iosys_map *dmap, unsigned int dpitch,
576 unsigned int height, unsigned int width,
577 u32 color, unsigned int pixel_width)
> 578 { 579 switch (pixel_width) {
580 case 1:
581 drm_fb_fill8(dmap, dpitch, height, width, color);
582 break;
583 case 2:
584 drm_fb_fill16(dmap, dpitch, height, width, color);
585 break;
586 case 3:
587 drm_fb_fill24(dmap, dpitch, height, width, color);
588 break;
589 case 4:
590 drm_fb_fill32(dmap, dpitch, height, width, color);
591 break;
592 default:
593 WARN_ONCE(1, "Can't fill with pixel width %d\n", pixel_width);
594 }
595 }
596 EXPORT_SYMBOL(drm_fb_fill);
597
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v5 1/6] drm/format-helper: Add drm_fb_blit_from_r1 and drm_fb_fill
In reply to Jocelyn Falempekernel test robot noticed the following build warnings:
Hi Jocelyn,
kernel test robot noticed the following build warnings:
[auto build test WARNING on ffc253263a1375a65fa6c9f62a893e9767fbebfa]
url: https://github.com/intel-lab-lkp/linux/commits/Jocelyn-Falempe/drm-format-helper-Add-drm_fb_blit_from_r1-and-drm_fb_fill/20231103-225824 base: ffc253263a1375a65fa6c9f62a893e9767fbebfa patch link: https://lore.kernel.org/r/20231103145526.628138-2-jfalempe%40redhat.com patch subject: [PATCH v5 1/6] drm/format-helper: Add drm_fb_blit_from_r1 and drm_fb_fill config: i386-randconfig-062-20231104 (https://download.01.org/0day-ci/archive/20231104/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-12) 11.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/gpu/drm/drm_format_helper.c:445:33: sparse: sparse: cast to restricted __le32 drivers/gpu/drm/drm_format_helper.c:542:37: sparse: sparse: cast to restricted __le32 >> drivers/gpu/drm/drm_format_helper.c:653:65: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] pix @@ got restricted __le32 const [usertype] @@ drivers/gpu/drm/drm_format_helper.c:653:65: sparse: expected unsigned int [usertype] pix drivers/gpu/drm/drm_format_helper.c:653:65: sparse: got restricted __le32 const [usertype] >> drivers/gpu/drm/drm_format_helper.c:653:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le16 [usertype] @@ got unsigned short @@ drivers/gpu/drm/drm_format_helper.c:653:27: sparse: expected restricted __le16 [usertype] drivers/gpu/drm/drm_format_helper.c:653:27: sparse: got unsigned short drivers/gpu/drm/drm_format_helper.c:723:67: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] pix @@ got restricted __le32 const [usertype] @@ drivers/gpu/drm/drm_format_helper.c:723:67: sparse: expected unsigned int [usertype] pix drivers/gpu/drm/drm_format_helper.c:723:67: sparse: got restricted __le32 const [usertype] drivers/gpu/drm/drm_format_helper.c:723:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le16 [usertype] @@ got unsigned short @@ drivers/gpu/drm/drm_format_helper.c:723:27: sparse: expected restricted __le16 [usertype] drivers/gpu/drm/drm_format_helper.c:723:27: sparse: got unsigned short drivers/gpu/drm/drm_format_helper.c:767:67: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] pix @@ got restricted __le32 const [usertype] @@ drivers/gpu/drm/drm_format_helper.c:767:67: sparse: expected unsigned int [usertype] pix drivers/gpu/drm/drm_format_helper.c:767:67: sparse: got restricted __le32 const [usertype] drivers/gpu/drm/drm_format_helper.c:767:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le16 [usertype] @@ got unsigned short @@ drivers/gpu/drm/drm_format_helper.c:767:27: sparse: expected restricted __le16 [usertype] drivers/gpu/drm/drm_format_helper.c:767:27: sparse: got unsigned short drivers/gpu/drm/drm_format_helper.c:811:67: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] pix @@ got restricted __le32 const [usertype] @@ drivers/gpu/drm/drm_format_helper.c:811:67: sparse: expected unsigned int [usertype] pix drivers/gpu/drm/drm_format_helper.c:811:67: sparse: got restricted __le32 const [usertype] drivers/gpu/drm/drm_format_helper.c:811:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le16 [usertype] @@ got unsigned short @@ drivers/gpu/drm/drm_format_helper.c:811:27: sparse: expected restricted __le16 [usertype] drivers/gpu/drm/drm_format_helper.c:811:27: sparse: got unsigned short drivers/gpu/drm/drm_format_helper.c:905:67: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] pix @@ got restricted __le32 const [usertype] @@ drivers/gpu/drm/drm_format_helper.c:905:67: sparse: expected unsigned int [usertype] pix drivers/gpu/drm/drm_format_helper.c:905:67: sparse: got restricted __le32 const [usertype] >> drivers/gpu/drm/drm_format_helper.c:905:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] @@ got unsigned int @@ drivers/gpu/drm/drm_format_helper.c:905:27: sparse: expected restricted __le32 [usertype] drivers/gpu/drm/drm_format_helper.c:905:27: sparse: got unsigned int drivers/gpu/drm/drm_format_helper.c:949:67: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] pix @@ got restricted __le32 const [usertype] @@ drivers/gpu/drm/drm_format_helper.c:949:67: sparse: expected unsigned int [usertype] pix drivers/gpu/drm/drm_format_helper.c:949:67: sparse: got restricted __le32 const [usertype] drivers/gpu/drm/drm_format_helper.c:949:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] @@ got unsigned int @@ drivers/gpu/drm/drm_format_helper.c:949:27: sparse: expected restricted __le32 [usertype] drivers/gpu/drm/drm_format_helper.c:949:27: sparse: got unsigned int drivers/gpu/drm/drm_format_helper.c:972:67: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] pix @@ got restricted __le32 const [usertype] @@ drivers/gpu/drm/drm_format_helper.c:972:67: sparse: expected unsigned int [usertype] pix drivers/gpu/drm/drm_format_helper.c:972:67: sparse: got restricted __le32 const [usertype] drivers/gpu/drm/drm_format_helper.c:972:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] @@ got unsigned int @@ drivers/gpu/drm/drm_format_helper.c:972:27: sparse: expected restricted __le32 [usertype] drivers/gpu/drm/drm_format_helper.c:972:27: sparse: got unsigned int drivers/gpu/drm/drm_format_helper.c:995:70: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] pix @@ got restricted __le32 const [usertype] @@ drivers/gpu/drm/drm_format_helper.c:995:70: sparse: expected unsigned int [usertype] pix drivers/gpu/drm/drm_format_helper.c:995:70: sparse: got restricted __le32 const [usertype] drivers/gpu/drm/drm_format_helper.c:995:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] @@ got unsigned int @@ drivers/gpu/drm/drm_format_helper.c:995:27: sparse: expected restricted __le32 [usertype] drivers/gpu/drm/drm_format_helper.c:995:27: sparse: got unsigned int drivers/gpu/drm/drm_format_helper.c:1039:70: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected unsigned int [usertype] pix @@ got restricted __le32 const [usertype] @@ drivers/gpu/drm/drm_format_helper.c:1039:70: sparse: expected unsigned int [usertype] pix drivers/gpu/drm/drm_format_helper.c:1039:70: sparse: got restricted __le32 const [usertype] drivers/gpu/drm/drm_format_helper.c:1039:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] @@ got unsigned int @@ drivers/gpu/drm/drm_format_helper.c:1039:27: sparse: expected restricted __le32 [usertype] drivers/gpu/drm/drm_format_helper.c:1039:27: sparse: got unsigned int drivers/gpu/drm/drm_format_helper.c:27:15: sparse: sparse: cast to restricted __le32 >> drivers/gpu/drm/drm_format_helper.c:31:16: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned short @@ got restricted __le16 [usertype] @@ drivers/gpu/drm/drm_format_helper.c:31:16: sparse: expected unsigned short drivers/gpu/drm/drm_format_helper.c:31:16: sparse: got restricted __le16 [usertype] drivers/gpu/drm/drm_format_helper.c:38:15: sparse: sparse: cast to restricted __le32 drivers/gpu/drm/drm_format_helper.c:43:16: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned short @@ got restricted __le16 [usertype] @@ drivers/gpu/drm/drm_format_helper.c:43:16: sparse: expected unsigned short drivers/gpu/drm/drm_format_helper.c:43:16: sparse: got restricted __le16 [usertype] drivers/gpu/drm/drm_format_helper.c:50:15: sparse: sparse: cast to restricted __le32 drivers/gpu/drm/drm_format_helper.c:54:16: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned short @@ got restricted __le16 [usertype] @@ drivers/gpu/drm/drm_format_helper.c:54:16: sparse: expected unsigned short drivers/gpu/drm/drm_format_helper.c:54:16: sparse: got restricted __le16 [usertype] drivers/gpu/drm/drm_format_helper.c:61:15: sparse: sparse: cast to restricted __le32 drivers/gpu/drm/drm_format_helper.c:66:16: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned short @@ got restricted __le16 [usertype] @@ drivers/gpu/drm/drm_format_helper.c:66:16: sparse: expected unsigned short drivers/gpu/drm/drm_format_helper.c:66:16: sparse: got restricted __le16 [usertype] drivers/gpu/drm/drm_format_helper.c:73:17: sparse: sparse: cast to restricted __le32 >> drivers/gpu/drm/drm_format_helper.c:75:16: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned int @@ got restricted __le32 [usertype] @@
drivers/gpu/drm/drm_format_helper.c:75:16: sparse: expected unsigned int
drivers/gpu/drm/drm_format_helper.c:75:16: sparse: got restricted __le32 [usertype]
drivers/gpu/drm/drm_format_helper.c:82:15: sparse: sparse: cast to restricted __le32
drivers/gpu/drm/drm_format_helper.c:87:16: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned int @@ got restricted __le32 [usertype] @@
drivers/gpu/drm/drm_format_helper.c:87:16: sparse: expected unsigned int
drivers/gpu/drm/drm_format_helper.c:87:16: sparse: got restricted __le32 [usertype]
drivers/gpu/drm/drm_format_helper.c:106:15: sparse: sparse: cast to restricted __le32
drivers/gpu/drm/drm_format_helper.c:111:16: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned int @@ got restricted __le32 [usertype] @@
drivers/gpu/drm/drm_format_helper.c:111:16: sparse: expected unsigned int
drivers/gpu/drm/drm_format_helper.c:111:16: sparse: got restricted __le32 [usertype]
drivers/gpu/drm/drm_format_helper.c:118:15: sparse: sparse: cast to restricted __le32
drivers/gpu/drm/drm_format_helper.c:124:16: sparse: sparse: incorrect type in return expression (different base types) @@ expected unsigned int @@ got restricted __le32 [usertype] @@
drivers/gpu/drm/drm_format_helper.c:124:16: sparse: expected unsigned int
drivers/gpu/drm/drm_format_helper.c:124:16: sparse: got restricted __le32 [usertype]
vim +445 drivers/gpu/drm/drm_format_helper.c
431
432 static void drm_fb_r1_to_24bit(struct iosys_map *dmap, unsigned int dpitch,
433 const u8 *sbuf8, unsigned int spitch,
434 unsigned int height, unsigned int width,
435 u32 fg32, u32 bg32)
436 {
437 unsigned int l, x;
438 u32 val32;
439
440 for (l = 0; l < height; l++) {
441 for (x = 0; x < width; x++) {
442 u32 off = l * dpitch + x * 3;
443
444 val32 = (sbuf8[(l * spitch) + x / 8] & (0x80 >> (x % 8))) ? fg32 : bg32;
> 445 val32 = le32_to_cpu(val32); 446
447 /* write blue-green-red to output in little endianness */
448 iosys_map_wr(dmap, off, u8, (val32 & 0x000000FF) >> 0);
449 iosys_map_wr(dmap, off + 1, u8, (val32 & 0x0000FF00) >> 8);
450 iosys_map_wr(dmap, off + 2, u8, (val32 & 0x00FF0000) >> 16);
451 }
452 }
453 }
454
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Jocelyn Falempe
maintainerPATCH v5 2/6 drm/panic: Add a drm panic handler
In reply to Jocelyn FalempeThis module displays a user friendly message when a kernel panic occurs. It currently doesn't contain any debug information, but that can be added later.
v2
* Use get_scanout_buffer() instead of the drm client API. (Thomas Zimmermann)
* Add the panic reason to the panic message (Nerdopolis)
* Add an exclamation mark (Nerdopolis)
v3
* Rework the drawing functions, to write the pixels line by line and to use the drm conversion helper to support other formats. (Thomas Zimmermann)
v4
* Use drm_fb_r1_to_32bit for fonts (Thomas Zimmermann)
* Remove the default y to DRM_PANIC config option (Thomas Zimmermann)
* Add foreground/background color config option
* Fix the bottom lines not painted if the framebuffer height is not a multiple of the font height.
* Automatically register the device to drm_panic, if the function get_scanout_buffer exists. (Thomas Zimmermann)
v5
* Change the drawing API, use drm_fb_blit_from_r1() to draw the font.
* Also add drm_fb_fill() to fill area with background color.
* Add draw_pixel_xy() API for drivers that can't provide a linear buffer.
* Add a flush() callback for drivers that needs to synchronize the buffer.
* Add a void *private field, so drivers can pass private data to draw_pixel_xy() and flush().
--- drivers/gpu/drm/Kconfig | 22 +++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_drv.c | 8 + drivers/gpu/drm/drm_panic.c | 368 ++++++++++++++++++++++++++++++++++++ include/drm/drm_drv.h | 21 ++ include/drm/drm_panic.h | 96 ++++++++++ 6 files changed, 516 insertions(+) create mode 100644 drivers/gpu/drm/drm_panic.c create mode 100644 include/drm/drm_panic.h
drivers/gpu/drm/Kconfig +22 -0
@@ -102,6 +102,28 @@ config DRM_KMS_HELPER help CRTC helpers for KMS drivers. +config DRM_PANIC + bool "Display a user-friendly message when a kernel panic occurs" + depends on DRM && !FRAMEBUFFER_CONSOLE + select FONT_SUPPORT + help + Enable a drm panic handler, which will display a user-friendly message + when a kernel panic occurs. It's useful when using a user-space + console instead of fbcon. + It will only work if your graphic driver supports this feature. + To support Hi-DPI Display, you can enable bigger fonts like + FONT_TER16x32 + +config DRM_PANIC_FOREGROUND_COLOR + hex "Drm panic screen foreground color, in RGB" + depends on DRM_PANIC + default 0xffffff + +config DRM_PANIC_BACKGROUND_COLOR + hex "Drm panic screen background color, in RGB" + depends on DRM_PANIC + default 0x000000 + config DRM_DEBUG_DP_MST_TOPOLOGY_REFS bool "Enable refcount backtrace history in the DP MST helpers" depends on STACKTRACE_SUPPORT
drivers/gpu/drm/Makefile +1 -0
@@ -73,6 +73,7 @@ drm-$(CONFIG_DRM_PRIVACY_SCREEN) += \ drm_privacy_screen_x86.o drm-$(CONFIG_DRM_ACCEL) += ../../accel/drm_accel.o obj-$(CONFIG_DRM) += drm.o +drm-$(CONFIG_DRM_PANIC) += drm_panic.o obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o
drivers/gpu/drm/drm_drv.c +8 -0
@@ -43,6 +43,7 @@#include <drm/drm_file.h> #include <drm/drm_managed.h> #include <drm/drm_mode_object.h> +#include <drm/drm_panic.h> #include <drm/drm_print.h> #include <drm/drm_privacy_screen_machine.h>
@@ -943,6 +944,9 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)if (drm_core_check_feature (dev,DRIVER_MODESET ))drm_modeset_register_all (dev); +if (driver->get_scanout_buffer) +drm_panic_register (dev); + DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n", driver->name, driver->major, driver->minor, driver->patchlevel, driver->date,
@@ -986,6 +990,8 @@ void drm_dev_unregister(struct drm_device *dev) dev->registered = false; +drm_panic_unregister (dev); +drm_client_dev_unregister (dev);if (drm_core_check_feature (dev,DRIVER_MODESET ))
@@ -1067,6 +1073,7 @@ static void drm_core_exit(void)unregister_chrdev (DRM_MAJOR ,"drm" );debugfs_remove (drm_debugfs_root);drm_sysfs_destroy (); +drm_panic_exit ();idr_destroy (&drm_minors_idr);drm_connector_ida_destroy (); }
@@ -1078,6 +1085,7 @@ static int __init drm_core_init(void)drm_connector_ida_init ();idr_init (&drm_minors_idr);drm_memcpy_init_early (); +drm_panic_init (); ret =drm_sysfs_init ();if (ret <0 ) {
drivers/gpu/drm/drm_panic.c new file +368 -0
368 lines not on this page · raw message
include/drm/drm_drv.h +21 -0
@@ -43,6 +43,7 @@ struct dma_buf_attachment;struct drm_display_mode ;struct drm_mode_create_dumb ;struct drm_printer ; +struct drm_scanout_buffer ;struct sg_table ;/**
@@ -392,6 +393,26 @@ struct drm_driver {*/ void (*show_fdinfo)(struct drm_printer *p,struct drm_file *f); +/** +* @get_scanout_buffer: +* +* Get the current scanout buffer, to display a panic message with drm_panic. +* The driver should do the minimum changes to provide a linear buffer, that +* can be used to display the panic screen. +* It is called from a panic callback, and must follow its restrictions. +* (no locks, no memory allocation, no sleep, no thread/workqueue, ...) +* It's a best effort mode, so it's expected that in some complex cases the +* panic screen won't be displayed. +* Some hardware cannot provide a linear buffer, so there is a draw_pixel_xy() +* callback in the struct drm_scanout_buffer that can be used in this case. +* +* Returns: +* +* Zero on success, negative errno on failure. +*/ +int (*get_scanout_buffer)(struct drm_device *dev, +struct drm_scanout_buffer *sb); +/** @major: driver major number */ int major;/** @minor: driver minor number */
include/drm/drm_panic.h new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.41.0
Jocelyn Falempe
maintainerPATCH v5 3/6 drm/simpledrm: Add drm_panic support
In reply to Jocelyn FalempeAdd support for the drm_panic module, which displays a user-friendly message to the screen when a kernel panic occurs.
--- drivers/gpu/drm/tiny/simpledrm.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpu/drm/tiny/simpledrm.c +15 -0
@@ -23,6 +23,7 @@#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_managed.h> #include <drm/drm_modeset_helper_vtables.h> +#include <drm/drm_panic.h> #include <drm/drm_plane_helper.h> #include <drm/drm_probe_helper.h>
@@ -842,6 +843,19 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,return sdev; } +static int simpledrm_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb) +{ +struct simpledrm_device *sdev =simpledrm_device_of_dev (dev); + + sb->width = sdev->mode.hdisplay; + sb->height = sdev->mode.vdisplay; + sb->pitch = sdev->pitch; + sb->format = sdev->format; + sb->map = sdev->screen_base; +return 0 ; +} +/* * DRM driver */
@@ -857,6 +871,7 @@ static struct drm_driver simpledrm_driver = { .minor = DRIVER_MINOR, .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET, .fops = &simpledrm_fops, + .get_scanout_buffer = simpledrm_get_scanout_buffer, };/*
Signature · 1 line
2.41.0
Jocelyn Falempe
maintainerPATCH v5 4/6 drm/mgag200: Add drm_panic support
In reply to Jocelyn FalempeAdd support for the drm_panic module, which displays a message to the screen when a kernel panic occurs.
v5:
* Also check that the plane is visible and primary. (Thomas Zimmermann)
--- drivers/gpu/drm/mgag200/mgag200_drv.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/gpu/drm/mgag200/mgag200_drv.c +25 -0
@@ -12,10 +12,12 @@#include <drm/drm_aperture.h> #include <drm/drm_drv.h> #include <drm/drm_fbdev_generic.h> +#include <drm/drm_framebuffer.h> #include <drm/drm_file.h> #include <drm/drm_ioctl.h> #include <drm/drm_managed.h> #include <drm/drm_module.h> +#include <drm/drm_panic.h> #include <drm/drm_pciids.h> #include "mgag200_drv.h"
@@ -83,6 +85,28 @@ resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size)return offset -65536 ; } +static int mgag200_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb) +{ +struct drm_plane *plane; +struct mga_device *mdev =to_mga_device (dev); +struct iosys_map map =IOSYS_MAP_INIT_VADDR_IOMEM (mdev->vram); + +/* find the primary and visible plane */ +drm_for_each_plane (plane, dev) { +if (!plane->state || !plane->state->visible || !plane->state->fb || + plane->type !=DRM_PLANE_TYPE_PRIMARY ) +continue ; + sb->format = plane->state->fb->format; + sb->width = plane->state->fb->width; + sb->height = plane->state->fb->height; + sb->pitch = plane->state->fb->pitches[0 ]; + sb->map = map; +return 0 ; + } +return -ENODEV ; +} +/* * DRM driver */
@@ -98,6 +122,7 @@ static const struct drm_driver mgag200_driver = { .major = DRIVER_MAJOR, .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, + .get_scanout_buffer = mgag200_get_scanout_buffer, DRM_GEM_SHMEM_DRIVER_OPS, };
Signature · 1 line
2.41.0
Jocelyn Falempe
maintainerPATCH v5 5/6 drm/ast: Add drm_panic support
In reply to Jocelyn FalempeAdd support for the drm_panic module, which displays a message to the screen when a kernel panic occurs.
--- drivers/gpu/drm/ast/ast_drv.c | 4 ++-- drivers/gpu/drm/ast/ast_drv.h | 3 +++ drivers/gpu/drm/ast/ast_mode.c | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_drv.c +2 -2
@@ -62,8 +62,8 @@ static const struct drm_driver ast_driver = { .major = DRIVER_MAJOR, .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, - -DRM_GEM_SHMEM_DRIVER_OPS + .get_scanout_buffer = ast_get_scanout_buffer, + DRM_GEM_SHMEM_DRIVER_OPS, };/*
drivers/gpu/drm/ast/ast_drv.h +3 -0
@@ -504,6 +504,9 @@ int ast_mode_config_init(struct ast_device *ast);#define ASTDP_1366x768_60 0x1E#define ASTDP_1152x864_75 0x1F +int ast_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb); +int ast_mm_init (struct ast_device *ast);/* ast post */
drivers/gpu/drm/ast/ast_mode.c +26 -0
@@ -43,6 +43,7 @@#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_shmem_helper.h> #include <drm/drm_managed.h> +#include <drm/drm_panic.h> #include <drm/drm_probe_helper.h> #include <drm/drm_simple_kms_helper.h>
@@ -1930,3 +1931,28 @@ int ast_mode_config_init(struct ast_device *ast)return 0 ; } + +int ast_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb) +{ +struct drm_plane *plane; +struct ast_plane *ast_plane; +struct iosys_map map; + +drm_for_each_plane (plane, dev) { +if (!plane->state || !plane->state->visible || !plane->state->fb || + plane->type !=DRM_PLANE_TYPE_PRIMARY ) +continue ; + ast_plane =to_ast_plane (plane); +if (!ast_plane->vaddr) +continue ; + + sb->format = plane->state->fb->format; + sb->width = plane->state->fb->width; + sb->height = plane->state->fb->height; + sb->pitch = plane->state->fb->pitches[0 ]; +iosys_map_set_vaddr_iomem (&sb->map, ast_plane->vaddr); +return 0 ; + } +return -ENODEV ; +}
Signature · 1 line
2.41.0
kernel test robot
build botRe: [PATCH v5 5/6] drm/ast: Add drm_panic support
kernel test robot noticed the following build warnings:
Hi Jocelyn,
kernel test robot noticed the following build warnings:
[auto build test WARNING on ffc253263a1375a65fa6c9f62a893e9767fbebfa]
url: https://github.com/intel-lab-lkp/linux/commits/Jocelyn-Falempe/drm-format-helper-Add-drm_fb_blit_from_r1-and-drm_fb_fill/20231103-225824 base: ffc253263a1375a65fa6c9f62a893e9767fbebfa patch link: https://lore.kernel.org/r/20231103145526.628138-6-jfalempe%40redhat.com patch subject: [PATCH v5 5/6] drm/ast: Add drm_panic support config: csky-randconfig-001-20231104 (https://download.01.org/0day-ci/archive/20231104/[email protected]/config) compiler: csky-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from drivers/gpu/drm/ast/ast_i2c.c:27:
>> drivers/gpu/drm/ast/ast_drv.h:508:35: warning: 'struct drm_scanout_buffer' declared inside parameter list will not be visible outside of this definition or declaration
508 | struct drm_scanout_buffer *sb);
| ^~~~~~~~~~~~~~~~~~
--
drivers/gpu/drm/ast/ast_mode.c: In function 'ast_get_scanout_buffer':
>> drivers/gpu/drm/ast/ast_mode.c:1940:26: warning: unused variable 'map' [-Wunused-variable]
1940 | struct iosys_map map;
| ^~~vim +508 drivers/gpu/drm/ast/ast_drv.h
506
507 int ast_get_scanout_buffer(struct drm_device *dev,
> 508 struct drm_scanout_buffer *sb);
509
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v5 5/6] drm/ast: Add drm_panic support
In reply to Jocelyn Falempekernel test robot noticed the following build warnings:
Hi Jocelyn,
kernel test robot noticed the following build warnings:
[auto build test WARNING on ffc253263a1375a65fa6c9f62a893e9767fbebfa]
url: https://github.com/intel-lab-lkp/linux/commits/Jocelyn-Falempe/drm-format-helper-Add-drm_fb_blit_from_r1-and-drm_fb_fill/20231103-225824 base: ffc253263a1375a65fa6c9f62a893e9767fbebfa patch link: https://lore.kernel.org/r/20231103145526.628138-6-jfalempe%40redhat.com patch subject: [PATCH v5 5/6] drm/ast: Add drm_panic support config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20231104/[email protected]/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from drivers/gpu/drm/ast/ast_i2c.c:27:
>> drivers/gpu/drm/ast/ast_drv.h:508:14: warning: declaration of 'struct drm_scanout_buffer' will not be visible outside of this function [-Wvisibility]
struct drm_scanout_buffer *sb);
^1 warning generated.
vim +508 drivers/gpu/drm/ast/ast_drv.h
506
507 int ast_get_scanout_buffer(struct drm_device *dev,
> 508 struct drm_scanout_buffer *sb);
509
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Jocelyn Falempe
maintainerPATCH v5 6/6 drm/imx: Add drm_panic support
In reply to Jocelyn FalempeProof of concept to add drm_panic support on an arm based GPU. I've tested it with X11/llvmpipe, because I wasn't able to have 3d rendering with etnaviv on my imx6 board.
--- drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +30 -0
@@ -10,6 +10,7 @@#include <linux/dma-buf.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/iosys-map.h> #include <video/imx-ipu-v3.h>
@@ -17,9 +18,12 @@#include <drm/drm_atomic_helper.h> #include <drm/drm_drv.h> #include <drm/drm_fbdev_dma.h> +#include <drm/drm_fb_dma_helper.h> +#include <drm/drm_framebuffer.h> #include <drm/drm_gem_dma_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_managed.h> +#include <drm/drm_panic.h> #include <drm/drm_of.h> #include <drm/drm_probe_helper.h> #include <drm/drm_vblank.h>
@@ -160,6 +164,31 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,return ret; } +static int imx_drm_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb) +{ +struct drm_plane *plane; +struct drm_gem_dma_object *dma_obj; + +drm_for_each_plane (plane, dev) { +if (!plane->state || !plane->state->fb || !plane->state->visible || + plane->type !=DRM_PLANE_TYPE_PRIMARY ) +continue ; + + dma_obj =drm_fb_dma_get_gem_obj (plane->state->fb,0 ); +if (!dma_obj->vaddr) +continue ; + +iosys_map_set_vaddr (&sb->map, dma_obj->vaddr); + sb->format = plane->state->fb->format; + sb->height = plane->state->fb->height; + sb->width = plane->state->fb->width; + sb->pitch = plane->state->fb->pitches[0 ]; +return 0 ; + } +return -ENODEV ; +} +static const struct drm_driver imx_drm_driver = { .driver_features =DRIVER_MODESET |DRIVER_GEM |DRIVER_ATOMIC ,DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE (imx_drm_dumb_create),
@@ -172,6 +201,7 @@ static const struct drm_driver imx_drm_driver = { .major = 1, .minor = 0, .patchlevel = 0, + .get_scanout_buffer = imx_drm_get_scanout_buffer, };static int compare_of (struct device *dev,void *data)
Signature · 1 line
2.41.0
Maxime Ripard
maintainerRe: [PATCH v5 6/6] drm/imx: Add drm_panic support
Hi,
Quoted 5 lines · Jocelyn Falempe
Proof of concept to add
drm_panicsupport on an arm based GPU. I've tested it with X11/llvmpipe, because I wasn't able to have 3d rendering with etnaviv on my imx6 board.Signed-off-by Jocelyn Falempe <[email protected]>
Like I said in the v6, this shouldn't be dropped because it also kind of documents and shows what we are expecting from a "real" driver.
Quoted 40 lines
--- drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+)drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +11
-0@@ -10,6 +10,7 @@#include <linux/dma-buf.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/iosys-map.h> #include <video/imx-ipu-v3.h> @@ -17,9 +18,12 @@#include <drm/drm_atomic_helper.h> #include <drm/drm_drv.h> #include <drm/drm_fbdev_dma.h> +#include <drm/drm_fb_dma_helper.h> +#include <drm/drm_framebuffer.h> #include <drm/drm_gem_dma_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_managed.h> +#include <drm/drm_panic.h> #include <drm/drm_of.h> #include <drm/drm_probe_helper.h> #include <drm/drm_vblank.h> @@ -160,6 +164,31 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,return ret; } +static int imx_drm_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb) +{ +struct drm_plane *plane; +struct drm_gem_dma_object *dma_obj; + +drm_for_each_plane (plane, dev) {
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 183
Quoted 10 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +10
-0+if (!plane->state || !plane->state->fb || !plane->state->visible || + plane->type !=DRM_PLANE_TYPE_PRIMARY ) +continue ; + + dma_obj =drm_fb_dma_get_gem_obj (plane->state->fb,0 ); +if (!dma_obj->vaddr) +continue ; + +iosys_map_set_vaddr (&sb->map, dma_obj->vaddr); + sb->format = plane->state->fb->format;
Planes can be using a framebuffer in one of the numerous YUV format the driver advertises.
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 186
Quoted 3 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +3
-0+ sb->height = plane->state->fb->height; + sb->width = plane->state->fb->width; + sb->pitch = plane->state->fb->pitches[0 ];
And your code assumes that the buffer will be large enough for an RGB buffer, which probably isn't the case for a single-planar YUV format, and certainly not the case for a multi-planar one.
When the driver gives back its current framebuffer, the code should check:
* If the buffer backed by an actual buffer (and not a dma-buf handle)
* If the buffer is mappable by the CPU
* If the buffer is in a format that the panic code can handle
* If the buffer uses a linear modifier
Failing that, your code cannot work at the moment. We need to be clear about that and "gracefully" handle things instead of going forward and writing pixels to places we might not be able to write to.
Which kind of makes me think, why do we need to involve the driver at all there?
If in the panic code, we're going over all enabled CRTCs, finding the primary plane currently setup for them and getting the drm_framebuffer assigned to them, it should be enough to get us all the informations we need, right?
Maxime
Maxime Ripard
maintainerRe: [PATCH v5 6/6] drm/imx: Add drm_panic support
Quoted 74 lines · Maxime Ripard
Hi,
Quoted 5 lines · Jocelyn Falempe
Proof of concept to add
drm_panicsupport on an arm based GPU. I've tested it with X11/llvmpipe, because I wasn't able to have 3d rendering with etnaviv on my imx6 board.Signed-off-by Jocelyn Falempe <[email protected]>Like I said in the v6, this shouldn't be dropped because it also kind of documents and shows what we are expecting from a "real" driver.
Quoted 40 lines
--- drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+)drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +11
-0@@ -10,6 +10,7 @@#include <linux/dma-buf.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/iosys-map.h> #include <video/imx-ipu-v3.h> @@ -17,9 +18,12 @@#include <drm/drm_atomic_helper.h> #include <drm/drm_drv.h> #include <drm/drm_fbdev_dma.h> +#include <drm/drm_fb_dma_helper.h> +#include <drm/drm_framebuffer.h> #include <drm/drm_gem_dma_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_managed.h> +#include <drm/drm_panic.h> #include <drm/drm_of.h> #include <drm/drm_probe_helper.h> #include <drm/drm_vblank.h> @@ -160,6 +164,31 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,return ret; } +static int imx_drm_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb) +{ +struct drm_plane *plane; +struct drm_gem_dma_object *dma_obj; + +drm_for_each_plane (plane, dev) {drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 183
Quoted 10 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +10
-0+if (!plane->state || !plane->state->fb || !plane->state->visible || + plane->type !=DRM_PLANE_TYPE_PRIMARY ) +continue ; + + dma_obj =drm_fb_dma_get_gem_obj (plane->state->fb,0 ); +if (!dma_obj->vaddr) +continue ; + +iosys_map_set_vaddr (&sb->map, dma_obj->vaddr); + sb->format = plane->state->fb->format;Planes can be using a framebuffer in one of the numerous YUV format the driver advertises.
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 186
Quoted 3 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +3
-0+ sb->height = plane->state->fb->height; + sb->width = plane->state->fb->width; + sb->pitch = plane->state->fb->pitches[0 ];And your code assumes that the buffer will be large enough for an RGB buffer, which probably isn't the case for a single-planar YUV format, and certainly not the case for a multi-planar one.
Quoted 1 line
When the driver gives back its current framebuffer, the code should check:
Oh, and also, you need to keep an eye on the solid fill support:
https://lore.kernel.org/all/[email protected]/
Because with that, a plane might not have a framebuffer anymore.
Quoted 18 lines
* If the buffer backed by an actual buffer (and not a dma-buf handle)
* If the buffer is mappable by the CPU
* If the buffer is in a format that the panic code can handle
* If the buffer uses a linear modifierFailing that, your code cannot work at the moment. We need to be clear about that and "gracefully" handle things instead of going forward and writing pixels to places we might not be able to write to.
Which kind of makes me think, why do we need to involve the driver at all there?
If in the panic code, we're going over all enabled CRTCs, finding the primary plane currently setup for them and getting the
drm_framebufferassigned to them, it should be enough to get us all the informations we need, right?Maxime
Jocelyn Falempe
maintainerRe: [PATCH v5 6/6] drm/imx: Add drm_panic support
In reply to Maxime RipardQuoted 11 lines · Maxime Ripard
Hi,
Quoted 5 lines · Jocelyn Falempe
Proof of concept to add
drm_panicsupport on an arm based GPU. I've tested it with X11/llvmpipe, because I wasn't able to have 3d rendering with etnaviv on my imx6 board.Signed-off-by Jocelyn Falempe <[email protected]>Like I said in the v6, this shouldn't be dropped because it also kind of documents and shows what we are expecting from a "real" driver.
Ok, I can bring it back in v7.
Quoted 55 lines
Quoted 41 lines
--- drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+)drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +11
-0@@ -10,6 +10,7 @@#include <linux/dma-buf.h> #include <linux/module.h> #include <linux/platform_device.h> +#include <linux/iosys-map.h> #include <video/imx-ipu-v3.h> @@ -17,9 +18,12 @@#include <drm/drm_atomic_helper.h> #include <drm/drm_drv.h> #include <drm/drm_fbdev_dma.h> +#include <drm/drm_fb_dma_helper.h> +#include <drm/drm_framebuffer.h> #include <drm/drm_gem_dma_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_managed.h> +#include <drm/drm_panic.h> #include <drm/drm_of.h> #include <drm/drm_probe_helper.h> #include <drm/drm_vblank.h> @@ -160,6 +164,31 @@ static int imx_drm_dumb_create(struct drm_file *file_priv,return ret; } +static int imx_drm_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb) +{ +struct drm_plane *plane; +struct drm_gem_dma_object *dma_obj; + +drm_for_each_plane (plane, dev) {drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 183
Quoted 10 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +10
-0+if (!plane->state || !plane->state->fb || !plane->state->visible || + plane->type !=DRM_PLANE_TYPE_PRIMARY ) +continue ; + + dma_obj =drm_fb_dma_get_gem_obj (plane->state->fb,0 ); +if (!dma_obj->vaddr) +continue ; + +iosys_map_set_vaddr (&sb->map, dma_obj->vaddr); + sb->format = plane->state->fb->format;Planes can be using a framebuffer in one of the numerous YUV format the driver advertises.
Quoted 7 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 186
Quoted 3 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +3
-0+ sb->height = plane->state->fb->height; + sb->width = plane->state->fb->width; + sb->pitch = plane->state->fb->pitches[0 ];And your code assumes that the buffer will be large enough for an RGB buffer, which probably isn't the case for a single-planar YUV format, and certainly not the case for a multi-planar one.
Yes, this code is a bit hacky, and on my test setup the framebuffer was in RGB, so I didn't handle other formats. Also it should be possible to add YUV format later, but I would like to have a minimal drm_panic merged, before adding more features.
Quoted 4 lines
When the driver gives back its current framebuffer, the code should check:
* If the buffer backed by an actual buffer (and not a dma-buf handle)
Regarding the struct drm_framebuffer, I'm not sure how do you differentiate an actual buffer from a dma-buf handle ?
Quoted 1 line
* If the buffer is mappable by the CPU
If "dma_obj->vaddr" is not null, then it's already mapped by the CPU right ?
Quoted 2 lines
* If the buffer is in a format that the panic code can handle
* If the buffer uses a linear modifier
Yes, that must be checked too.
Quoted 5 lines
Failing that, your code cannot work at the moment. We need to be clear about that and "gracefully" handle things instead of going forward and writing pixels to places we might not be able to write to.
Quoted 7 lines
Which kind of makes me think, why do we need to involve the driver at all there?
If in the panic code, we're going over all enabled CRTCs, finding the primary plane currently setup for them and getting the
drm_framebufferassigned to them, it should be enough to get us all the informations we need, right?
Yes, I think I can do a generic implementation for the drivers using the drm_gem_dma helper like imx6.
But for simpledrm, ast, or mgag200, I need to retrieve the VRAM address, because it's not in the drm_framebuffer struct, so they won't be able to use this generic implementation.
Quoted 2 lines
Maxime
Thanks for the review,
Signature · 1 line
Jocelyn
Maxime Ripard
maintainerRe: [PATCH v5 6/6] drm/imx: Add drm_panic support
Quoted 29 lines · Jocelyn Falempe
Quoted 21 lines
Quoted 7 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +7
-0+static int imx_drm_get_scanout_buffer (struct drm_device *dev, +struct drm_scanout_buffer *sb) +{ +struct drm_plane *plane; +struct drm_gem_dma_object *dma_obj; + +drm_for_each_plane (plane, dev) {drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 183
Quoted 10 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +10
-0+if (!plane->state || !plane->state->fb || !plane->state->visible || + plane->type !=DRM_PLANE_TYPE_PRIMARY ) +continue ; + + dma_obj =drm_fb_dma_get_gem_obj (plane->state->fb,0 ); +if (!dma_obj->vaddr) +continue ; + +iosys_map_set_vaddr (&sb->map, dma_obj->vaddr); + sb->format = plane->state->fb->format;Planes can be using a framebuffer in one of the numerous YUV format the driver advertises.
Quoted 7 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c static int imx_drm_dumb_create(struct drm_file *file_priv, · line 186
Quoted 3 lines
drivers/gpu/drm/imx/ipuv3/imx-drm-core.c +3
-0+ sb->height = plane->state->fb->height; + sb->width = plane->state->fb->width; + sb->pitch = plane->state->fb->pitches[0 ];And your code assumes that the buffer will be large enough for an RGB buffer, which probably isn't the case for a single-planar YUV format, and certainly not the case for a multi-planar one.
Quoted 4 lines
Yes, this code is a bit hacky, and on my test setup the framebuffer was in RGB, so I didn't handle other formats.
Also it should be possible to add YUV format later, but I would like to have a minimaldrm_panicmerged, before adding more features.
Sure. Having a minimal panic code is reasonable, but we should properly handle not supporting them still :)
There's cases where, with the current architecture anyway, you just won't be able to print a panic message and that's fine. The important part is not crashing the kernel further and being as loud as we can that we couldn't print a panic message on the screen because of the setup.
Quoted 6 lines
Quoted 3 lines
When the driver gives back its current framebuffer, the code should check:
* If the buffer backed by an actual buffer (and not a dma-buf handle)
Regarding the struct
drm_framebuffer, I'm not sure how do you differentiate an actual buffer from a dma-buf handle ?
Its backing drm_gem_object should be set and have the field import_attach set
Quoted 3 lines
Quoted 1 line
* If the buffer is mappable by the CPU
If "
dma_obj->vaddr" is not null, then it's already mapped by the CPU right ?
I'm not sure. drm_gem_dma_create will only ever create CPU-mappable buffers, but drm_gem_dma_prime_import_sg_table won't for example.
Quoted 18 lines
Quoted 2 lines
* If the buffer is in a format that the panic code can handle
* If the buffer uses a linear modifierYes, that must be checked too.
Quoted 5 lines
Failing that, your code cannot work at the moment. We need to be clear about that and "gracefully" handle things instead of going forward and writing pixels to places we might not be able to write to.
Quoted 7 lines
Which kind of makes me think, why do we need to involve the driver at all there?
If in the panic code, we're going over all enabled CRTCs, finding the primary plane currently setup for them and getting the
drm_framebufferassigned to them, it should be enough to get us all the informations we need, right?
Quoted 5 lines
Yes, I think I can do a generic implementation for the drivers using the
drm_gem_dmahelper like imx6.
But for simpledrm, ast, or mgag200, I need to retrieve the VRAM address, because it's not in thedrm_framebufferstruct, so they won't be able to use this generic implementation.
Sure :)
I guess we could have a CRTC function then that by default will just return the current primary plane framebuffer (or could be a plane function?), and if it's not there just grabs the one from the current active state.
Maxime
Quoted 47 lines · EST Jocelyn Falempe
This introduces a new drm panic handler, which displays a message when a panic occurs. So when fbcon is disabled, you can still see a kernel panic.
This is one of the missing feature, when disabling VT/fbcon in the kernel:
https://www.reddit.com/r/linux/comments/10eccv9/config_vtn_in_2023/
Fbcon can be replaced by a userspace kms console, but the panic screen must be done in the kernel.This is a proof of concept, and works with simpledrm and mgag200, using a new
get_scanout_buffer()apiTo test it, make sure you're using the simpledrm driver, and trigger a panic:
echo c >/proc/sysrq-triggerv2:
* Useget_scanout_buffer()instead of the drm client API. (Thomas Zimmermann)
* Add the panic reason to the panic message (Nerdopolis)
* Add an exclamation mark (Nerdopolis)v3:
* Rework the drawing functions, to write the pixels line by line and to use the drm conversion helper to support other formats. (Thomas Zimmermann)v4:
* Fully support all simpledrm formats using drm conversion helpers
* Rename dpanic_* to drm_panic_*, and have more coherent function name. (Thomas Zimmermann)
* Usedrm_fb_r1_to_32bitfor fonts (Thomas Zimmermann)
* Remove the default y toDRM_PANICconfig option (Thomas Zimmermann)
* Add foreground/background color config option
* Fix the bottom lines not painted if the framebuffer height is not a multiple of the font height.
* Automatically register the driver todrm_panic, if the functionget_scanout_buffer()exists. (Thomas Zimmermann)
* Add mgag200 support.v5:
* Change the drawing API, usedrm_fb_blit_from_r1()to draw the font. (Thomas Zimmermann)
* Also adddrm_fb_fill()to fill area with background color.
* Adddraw_pixel_xy()API for drivers that can't provide a linear buffer.
* Add aflush()callback for drivers that needs to synchronize the buffer.
* Add a void *private field, so drivers can pass private data todraw_pixel_xy()andflush().
* Add ast support.
* Add experimental imx/ipuv3 support, to test on an ARM hw. (Maxime Ripard)
Quoted 2 lines
With mgag200 support, I was able to test that the xrgb8888 to rgb565 conversion is working.
I am unable to test with that hardware, but I am able to test with simpledrm, and it works pretty good
Quoted 35 lines
IMX/IPUV3 support is not complete, I wasn't able to have etnaviv working on my board. But it shows that it can still work on ARM with DMA buffer in this case.
Best regards,
Jocelyn Falempe (6):
drm/format-helper: Adddrm_fb_blit_from_r1anddrm_fb_filldrm/panic: Add a drm panic handler drm/simpledrm: Adddrm_panicsupport drm/mgag200: Adddrm_panicsupport
drm/ast: Adddrm_panicsupport
drm/imx: Adddrm_panicsupportdrivers/gpu/drm/Kconfig | 22 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/ast/ast_drv.c | 4 +- drivers/gpu/drm/ast/ast_drv.h | 3 + drivers/gpu/drm/ast/ast_mode.c | 26 ++ drivers/gpu/drm/drm_drv.c | 8 + drivers/gpu/drm/drm_format_helper.c | 421 ++++++++++++++++++----- drivers/gpu/drm/drm_panic.c | 368 ++++++++++++++++++++ drivers/gpu/drm/imx/ipuv3/imx-drm-core.c | 30 ++ drivers/gpu/drm/mgag200/mgag200_drv.c | 25 ++ drivers/gpu/drm/tiny/simpledrm.c | 15 + include/drm/drm_drv.h | 21 ++ include/drm/drm_format_helper.h | 9 + include/drm/drm_panic.h | 96 ++++++ 14 files changed, 966 insertions(+), 83 deletions(-) create mode 100644 drivers/gpu/drm/drm_panic.c create mode 100644 include/drm/drm_panic.hbase-commit:
ffc253263a1375a65fa6c9f62a893e9767fbebfa