Skip to contentSkip to conversation

drm/panic: Add a drm panic handler

RFC PATCH Superseded Jocelyn Falempe 7 participants 40 messages Oct 3, 2023 – Oct 16, 2023

Subsystems (4)

v4 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Jocelyn Falempe

author maintainer
#0 lore raw

v4 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.

With mgag200 support, I was able to test that the xrgb8888 to rgb565 conversion is working.

A few more though:
1) what about gpu with multiple monitor connected ?
maybe get_scanout_buffer() could return a list of scanout buffers ?
2) I think for some GPU drivers, there might need a flush_scanout_buffer() function, that should be called after the scanout buffer has been filled ?

Best regards,

Jocelyn Falempe (4):
drm/format-helper: Export line conversion helper for drm_panic drm/panic: Add a drm panic handler
drm/simpledrm: Add drm_panic support
drm/mgag200: Add drm_panic support

 drivers/gpu/drm/Kconfig               |  22 ++
 drivers/gpu/drm/Makefile              |   1 +
 drivers/gpu/drm/drm_drv.c             |   8 +
 drivers/gpu/drm/drm_format_helper.c   |  88 +++++-
 drivers/gpu/drm/drm_panic.c           | 413 ++++++++++++++++++++++++++
 drivers/gpu/drm/mgag200/mgag200_drv.c |  24 ++
 drivers/gpu/drm/tiny/simpledrm.c      |  15 +
 include/drm/drm_drv.h                 |  14 +
 include/drm/drm_format_helper.h       |   9 +
 include/drm/drm_panic.h               |  41 +++
 10 files changed, 627 insertions(+), 8 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_panic.c
 create mode 100644 include/drm/drm_panic.h

base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c

Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH v4 1/4 drm/format-helper: Export line conversion helper for drm_panic

drm_panic will need the low-level drm_fb_xxxx_line functions. Also add drm_fb_r1_to_xrgb8888 to render the fonts.

---
 drivers/gpu/drm/drm_format_helper.c | 88 ++++++++++++++++++++++++++---
 include/drm/drm_format_helper.h     |  9 +++
 2 files changed, 89 insertions(+), 8 deletions(-)
drivers/gpu/drm/drm_format_helper.c +80 -8
index f93a4efcee90..c238e5d84f1f 100644
@@ -270,7 +270,30 @@ void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch,
 
 	drm_fb_xfrm(dst, dst_pitch, &cpp, src, fb, clip, cached, swab_line);
 }
-EXPORT_SYMBOL(drm_fb_swab);
+
+/**
+ * drm_fb_r1_to_32bit_line - Convert one line from monochrome to any 32bit pixel format
+ * @dbuf: Pointer to the destination line (in any 32bit format)
+ * @sbuf: Pointer to the source line (in monochrome)
+ * @pixels: Number of pixels to convert.
+ * @fg_color: Foreground color, applied when R1 is 1
+ * @bg_color: Background color, applied when R1 is 0
+ *
+ * Convert monochrome to any format with 32bit pixel.
+ * There is a limitation, as sbuf is a pointer, it can only points to a multiple
+ * of 8 pixels in the source buffer.
+ */
+void drm_fb_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+				u32 fg_color, u32 bg_color)
+{
+	unsigned int x;
+	const u8 *sbuf8 = sbuf;
+	u32 *dubf32 = dbuf;
+
+	for (x = 0; x < pixels; x++)
+		dubf32[x] = (sbuf8[x / 8] & (0x80 >> (x % 8))) ? fg_color : bg_color;
+}
+EXPORT_SYMBOL(drm_fb_r1_to_32bit_line);
 
 static void drm_fb_xrgb8888_to_rgb332_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
@@ -320,7 +343,13 @@ void drm_fb_xrgb8888_to_rgb332(struct iosys_map *dst, const unsigned int *dst_pi
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
 
-static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to RGB565
+ * @dbuf: Pointer to the destination line (in RGB565)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le16 *dbuf16 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -336,6 +365,7 @@ static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigne
 		dbuf16[x] = cpu_to_le16(val16);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565_line);
 
 /* TODO: implement this helper as conversion to RGB565|BIG_ENDIAN */
 static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf,
@@ -396,7 +426,13 @@ void drm_fb_xrgb8888_to_rgb565(struct iosys_map *dst, const unsigned int *dst_pi
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565);
 
-static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to XRGB1555
+ * @dbuf: Pointer to the destination line (in XRGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le16 *dbuf16 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -412,6 +448,7 @@ static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsig
 		dbuf16[x] = cpu_to_le16(val16);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555_line);
 
 /**
  * drm_fb_xrgb8888_to_xrgb1555 - Convert XRGB8888 to XRGB1555 clip buffer
@@ -447,7 +484,13 @@ void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555);
 
-static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to ARGB1555
+ * @dbuf: Pointer to the destination line (in ARGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le16 *dbuf16 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -464,6 +507,7 @@ static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsig
 		dbuf16[x] = cpu_to_le16(val16);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555_line);
 
 /**
  * drm_fb_xrgb8888_to_argb1555 - Convert XRGB8888 to ARGB1555 clip buffer
@@ -499,7 +543,13 @@ void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555);
 
-static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgba5551_line - Convert one line from XRGB8888 to ARGB5551
+ * @dbuf: Pointer to the destination line (in ARGB5551)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le16 *dbuf16 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -516,6 +566,7 @@ static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsig
 		dbuf16[x] = cpu_to_le16(val16);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551_line);
 
 /**
  * drm_fb_xrgb8888_to_rgba5551 - Convert XRGB8888 to RGBA5551 clip buffer
@@ -551,7 +602,13 @@ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551);
 
-static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to RGB888
+ * @dbuf: Pointer to the destination line (in RGB888)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	u8 *dbuf8 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -566,6 +623,7 @@ static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigne
 		*dbuf8++ = (pix & 0x00FF0000) >> 16;
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_line);
 
 /**
  * drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer
@@ -709,7 +767,13 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned in
 		    drm_fb_xrgb8888_to_xbgr8888_line);
 }
 
-static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to XRGB2101010
+ * @dbuf: Pointer to the destination line (in XRGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le32 *dbuf32 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -726,6 +790,7 @@ static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, un
 		*dbuf32++ = cpu_to_le32(pix);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_line);
 
 /**
  * drm_fb_xrgb8888_to_xrgb2101010 - Convert XRGB8888 to XRGB2101010 clip buffer
@@ -761,7 +826,13 @@ void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *d
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010);
 
-static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to ARGB2101010
+ * @dbuf: Pointer to the destination line (in ARGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le32 *dbuf32 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -779,6 +850,7 @@ static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, un
 		*dbuf32++ = cpu_to_le32(pix);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb2101010_line);
 
 /**
  * drm_fb_xrgb8888_to_argb2101010 - Convert XRGB8888 to ARGB2101010 clip buffer
include/drm/drm_format_helper.h +9 -0
index 291deb09475b..31ab699128d5 100644
@@ -24,30 +24,39 @@ 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_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+			     u32 fg_color, u32 bg_color);
 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);
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_rgb565(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 swab);
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
 				 const struct iosys_map *src, const struct drm_framebuffer *fb,
 				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
 				 const struct iosys_map *src, const struct drm_framebuffer *fb,
 				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_pitch,
 				 const struct iosys_map *src, const struct drm_framebuffer *fb,
 				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch,
 			       const struct iosys_map *src, const struct drm_framebuffer *fb,
 			       const struct drm_rect *clip);
 void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch,
 				 const struct iosys_map *src, const struct drm_framebuffer *fb,
 				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch,
 				    const struct iosys_map *src, const struct drm_framebuffer *fb,
 				    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_argb2101010(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
#2 lore raw

Re: [PATCH v4 1/4] drm/format-helper: Export line conversion helper for drm_panic

kernel test robot noticed the following build warnings:

Hi Jocelyn,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 2dde18cd1d8fac735875f2e4987f11817cc0bc2c]

url:    https://github.com/intel-lab-lkp/linux/commits/Jocelyn-Falempe/drm-format-helper-Export-line-conversion-helper-for-drm_panic/20231003-222642
base:   2dde18cd1d8fac735875f2e4987f11817cc0bc2c
patch link:    https://lore.kernel.org/r/20231003142508.190246-2-jfalempe%40redhat.com
patch subject: [PATCH v4 1/4] drm/format-helper: Export line conversion helper for drm_panic
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20231003/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231003/[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:436: warning: expecting prototype for drm_fb_xrgb8888_to_rgb565_line(). Prototype was for drm_fb_xrgb8888_to_xrgb1555_line() instead
>> drivers/gpu/drm/drm_format_helper.c:494: warning: expecting prototype for drm_fb_xrgb8888_to_rgb565_line(). Prototype was for drm_fb_xrgb8888_to_argb1555_line() instead
>> drivers/gpu/drm/drm_format_helper.c:777: warning: expecting prototype for drm_fb_xrgb8888_to_rgb888_line(). Prototype was for drm_fb_xrgb8888_to_xrgb2101010_line() instead
>> drivers/gpu/drm/drm_format_helper.c:836: warning: expecting prototype for drm_fb_xrgb8888_to_rgb888_line(). Prototype was for drm_fb_xrgb8888_to_argb2101010_line() instead

vim +436 drivers/gpu/drm/drm_format_helper.c

7415287e1f3675 Gerd Hoffmann     2019-04-05  428  
ce913131bdeb03 Jocelyn Falempe   2023-10-03  429  /**
ce913131bdeb03 Jocelyn Falempe   2023-10-03  430   * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to XRGB1555
ce913131bdeb03 Jocelyn Falempe   2023-10-03  431   * @dbuf: Pointer to the destination line (in XRGB1555)
ce913131bdeb03 Jocelyn Falempe   2023-10-03  432   * @sbuf: Pointer to the source line (in XRGB8888)
ce913131bdeb03 Jocelyn Falempe   2023-10-03  433   * @pixels: Number of pixels to convert.
ce913131bdeb03 Jocelyn Falempe   2023-10-03  434   */
ce913131bdeb03 Jocelyn Falempe   2023-10-03  435  void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
10cd592e639edc Thomas Zimmermann 2023-01-02 @436  {
10cd592e639edc Thomas Zimmermann 2023-01-02  437  	__le16 *dbuf16 = dbuf;
10cd592e639edc Thomas Zimmermann 2023-01-02  438  	const __le32 *sbuf32 = sbuf;
10cd592e639edc Thomas Zimmermann 2023-01-02  439  	unsigned int x;
10cd592e639edc Thomas Zimmermann 2023-01-02  440  	u16 val16;
10cd592e639edc Thomas Zimmermann 2023-01-02  441  	u32 pix;
10cd592e639edc Thomas Zimmermann 2023-01-02  442  
10cd592e639edc Thomas Zimmermann 2023-01-02  443  	for (x = 0; x < pixels; x++) {
10cd592e639edc Thomas Zimmermann 2023-01-02  444  		pix = le32_to_cpu(sbuf32[x]);
10cd592e639edc Thomas Zimmermann 2023-01-02  445  		val16 = ((pix & 0x00f80000) >> 9) |
10cd592e639edc Thomas Zimmermann 2023-01-02  446  			((pix & 0x0000f800) >> 6) |
10cd592e639edc Thomas Zimmermann 2023-01-02  447  			((pix & 0x000000f8) >> 3);
10cd592e639edc Thomas Zimmermann 2023-01-02  448  		dbuf16[x] = cpu_to_le16(val16);
10cd592e639edc Thomas Zimmermann 2023-01-02  449  	}
10cd592e639edc Thomas Zimmermann 2023-01-02  450  }
ce913131bdeb03 Jocelyn Falempe   2023-10-03  451  EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555_line);
10cd592e639edc Thomas Zimmermann 2023-01-02  452  
10cd592e639edc Thomas Zimmermann 2023-01-02  453  /**
10cd592e639edc Thomas Zimmermann 2023-01-02  454   * drm_fb_xrgb8888_to_xrgb1555 - Convert XRGB8888 to XRGB1555 clip buffer
10cd592e639edc Thomas Zimmermann 2023-01-02  455   * @dst: Array of XRGB1555 destination buffers
10cd592e639edc Thomas Zimmermann 2023-01-02  456   * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
10cd592e639edc Thomas Zimmermann 2023-01-02  457   *             within @dst; can be NULL if scanlines are stored next to each other.
10cd592e639edc Thomas Zimmermann 2023-01-02  458   * @src: Array of XRGB8888 source buffer
10cd592e639edc Thomas Zimmermann 2023-01-02  459   * @fb: DRM framebuffer
10cd592e639edc Thomas Zimmermann 2023-01-02  460   * @clip: Clip rectangle area to copy
10cd592e639edc Thomas Zimmermann 2023-01-02  461   *
10cd592e639edc Thomas Zimmermann 2023-01-02  462   * This function copies parts of a framebuffer to display memory and converts
10cd592e639edc Thomas Zimmermann 2023-01-02  463   * the color format during the process. The parameters @dst, @dst_pitch and
10cd592e639edc Thomas Zimmermann 2023-01-02  464   * @src refer to arrays. Each array must have at least as many entries as
10cd592e639edc Thomas Zimmermann 2023-01-02  465   * there are planes in @fb's format. Each entry stores the value for the
10cd592e639edc Thomas Zimmermann 2023-01-02  466   * format's respective color plane at the same index.
10cd592e639edc Thomas Zimmermann 2023-01-02  467   *
10cd592e639edc Thomas Zimmermann 2023-01-02  468   * This function does not apply clipping on @dst (i.e. the destination is at the
10cd592e639edc Thomas Zimmermann 2023-01-02  469   * top-left corner).
10cd592e639edc Thomas Zimmermann 2023-01-02  470   *
10cd592e639edc Thomas Zimmermann 2023-01-02  471   * Drivers can use this function for XRGB1555 devices that don't support
10cd592e639edc Thomas Zimmermann 2023-01-02  472   * XRGB8888 natively.
10cd592e639edc Thomas Zimmermann 2023-01-02  473   */
10cd592e639edc Thomas Zimmermann 2023-01-02  474  void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
10cd592e639edc Thomas Zimmermann 2023-01-02  475  				 const struct iosys_map *src, const struct drm_framebuffer *fb,
10cd592e639edc Thomas Zimmermann 2023-01-02  476  				 const struct drm_rect *clip)
10cd592e639edc Thomas Zimmermann 2023-01-02  477  {
10cd592e639edc Thomas Zimmermann 2023-01-02  478  	static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
10cd592e639edc Thomas Zimmermann 2023-01-02  479  		2,
10cd592e639edc Thomas Zimmermann 2023-01-02  480  	};
10cd592e639edc Thomas Zimmermann 2023-01-02  481  
10cd592e639edc Thomas Zimmermann 2023-01-02  482  	drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false,
10cd592e639edc Thomas Zimmermann 2023-01-02  483  		    drm_fb_xrgb8888_to_xrgb1555_line);
10cd592e639edc Thomas Zimmermann 2023-01-02  484  }
10cd592e639edc Thomas Zimmermann 2023-01-02  485  EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555);
10cd592e639edc Thomas Zimmermann 2023-01-02  486  
ce913131bdeb03 Jocelyn Falempe   2023-10-03  487  /**
ce913131bdeb03 Jocelyn Falempe   2023-10-03  488   * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to ARGB1555
ce913131bdeb03 Jocelyn Falempe   2023-10-03  489   * @dbuf: Pointer to the destination line (in ARGB1555)
ce913131bdeb03 Jocelyn Falempe   2023-10-03  490   * @sbuf: Pointer to the source line (in XRGB8888)
ce913131bdeb03 Jocelyn Falempe   2023-10-03  491   * @pixels: Number of pixels to convert.
ce913131bdeb03 Jocelyn Falempe   2023-10-03  492   */
ce913131bdeb03 Jocelyn Falempe   2023-10-03  493  void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
10cd592e639edc Thomas Zimmermann 2023-01-02 @494  {
10cd592e639edc Thomas Zimmermann 2023-01-02  495  	__le16 *dbuf16 = dbuf;
10cd592e639edc Thomas Zimmermann 2023-01-02  496  	const __le32 *sbuf32 = sbuf;
10cd592e639edc Thomas Zimmermann 2023-01-02  497  	unsigned int x;
10cd592e639edc Thomas Zimmermann 2023-01-02  498  	u16 val16;
10cd592e639edc Thomas Zimmermann 2023-01-02  499  	u32 pix;
10cd592e639edc Thomas Zimmermann 2023-01-02  500  
10cd592e639edc Thomas Zimmermann 2023-01-02  501  	for (x = 0; x < pixels; x++) {
10cd592e639edc Thomas Zimmermann 2023-01-02  502  		pix = le32_to_cpu(sbuf32[x]);
10cd592e639edc Thomas Zimmermann 2023-01-02  503  		val16 = BIT(15) | /* set alpha bit */
10cd592e639edc Thomas Zimmermann 2023-01-02  504  			((pix & 0x00f80000) >> 9) |
10cd592e639edc Thomas Zimmermann 2023-01-02  505  			((pix & 0x0000f800) >> 6) |
10cd592e639edc Thomas Zimmermann 2023-01-02  506  			((pix & 0x000000f8) >> 3);
10cd592e639edc Thomas Zimmermann 2023-01-02  507  		dbuf16[x] = cpu_to_le16(val16);
10cd592e639edc Thomas Zimmermann 2023-01-02  508  	}
10cd592e639edc Thomas Zimmermann 2023-01-02  509  }
ce913131bdeb03 Jocelyn Falempe   2023-10-03  510  EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555_line);
10cd592e639edc Thomas Zimmermann 2023-01-02  511  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

Re: [PATCH v4 1/4] drm/format-helper: Export line conversion helper for drm_panic

In reply to Jocelyn Falempe
Quoted 14 lines · EDT Jocelyn Falempe

drm_panic will need the low-level drm_fb_xxxx_line functions. Also add drm_fb_r1_to_xrgb8888 to render the fonts.

---
 drivers/gpu/drm/drm_format_helper.c | 88 ++++++++++++++++++++++++++---
 include/drm/drm_format_helper.h     |  9 +++
 2 files changed, 89 insertions(+), 8 deletions(-)
drivers/gpu/drm/drm_format_helper.c +0 -0
index f93a4efcee90..c238e5d84f1f 100644

drivers/gpu/drm/drm_format_helper.c void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch, · line 273

Quoted 4 lines
drivers/gpu/drm/drm_format_helper.c +0 -1
@@ -270,7 +270,30 @@ void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch,
 
 	drm_fb_xfrm(dst, dst_pitch, &cpp, src, fb, clip, cached, swab_line);
 }
-EXPORT_SYMBOL(drm_fb_swab);

I had to add this line back to get it to build, but once I did, it worked.

Quoted 233 lines
drivers/gpu/drm/drm_format_helper.c +80 -7
+
+/**
+ * drm_fb_r1_to_32bit_line - Convert one line from monochrome to any 32bit pixel format
+ * @dbuf: Pointer to the destination line (in any 32bit format)
+ * @sbuf: Pointer to the source line (in monochrome)
+ * @pixels: Number of pixels to convert.
+ * @fg_color: Foreground color, applied when R1 is 1
+ * @bg_color: Background color, applied when R1 is 0
+ *
+ * Convert monochrome to any format with 32bit pixel.
+ * There is a limitation, as sbuf is a pointer, it can only points to a multiple
+ * of 8 pixels in the source buffer.
+ */
+void drm_fb_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+				u32 fg_color, u32 bg_color)
+{
+	unsigned int x;
+	const u8 *sbuf8 = sbuf;
+	u32 *dubf32 = dbuf;
+
+	for (x = 0; x < pixels; x++)
+		dubf32[x] = (sbuf8[x / 8] & (0x80 >> (x % 8))) ? fg_color : bg_color;
+}
+EXPORT_SYMBOL(drm_fb_r1_to_32bit_line);
 
 static void drm_fb_xrgb8888_to_rgb332_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
@@ -320,7 +343,13 @@ void drm_fb_xrgb8888_to_rgb332(struct iosys_map *dst, const unsigned int *dst_pi
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
 
-static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to RGB565
+ * @dbuf: Pointer to the destination line (in RGB565)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le16 *dbuf16 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -336,6 +365,7 @@ static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigne
 		dbuf16[x] = cpu_to_le16(val16);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565_line);
 
 /* TODO: implement this helper as conversion to RGB565|BIG_ENDIAN */
 static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf,
@@ -396,7 +426,13 @@ void drm_fb_xrgb8888_to_rgb565(struct iosys_map *dst, const unsigned int *dst_pi
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565);
 
-static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to XRGB1555
+ * @dbuf: Pointer to the destination line (in XRGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le16 *dbuf16 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -412,6 +448,7 @@ static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsig
 		dbuf16[x] = cpu_to_le16(val16);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555_line);
 
 /**
  * drm_fb_xrgb8888_to_xrgb1555 - Convert XRGB8888 to XRGB1555 clip buffer
@@ -447,7 +484,13 @@ void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555);
 
-static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to ARGB1555
+ * @dbuf: Pointer to the destination line (in ARGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le16 *dbuf16 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -464,6 +507,7 @@ static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsig
 		dbuf16[x] = cpu_to_le16(val16);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555_line);
 
 /**
  * drm_fb_xrgb8888_to_argb1555 - Convert XRGB8888 to ARGB1555 clip buffer
@@ -499,7 +543,13 @@ void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555);
 
-static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgba5551_line - Convert one line from XRGB8888 to ARGB5551
+ * @dbuf: Pointer to the destination line (in ARGB5551)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le16 *dbuf16 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -516,6 +566,7 @@ static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsig
 		dbuf16[x] = cpu_to_le16(val16);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551_line);
 
 /**
  * drm_fb_xrgb8888_to_rgba5551 - Convert XRGB8888 to RGBA5551 clip buffer
@@ -551,7 +602,13 @@ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551);
 
-static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to RGB888
+ * @dbuf: Pointer to the destination line (in RGB888)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	u8 *dbuf8 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -566,6 +623,7 @@ static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigne
 		*dbuf8++ = (pix & 0x00FF0000) >> 16;
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_line);
 
 /**
  * drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer
@@ -709,7 +767,13 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned in
 		    drm_fb_xrgb8888_to_xbgr8888_line);
 }
 
-static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to XRGB2101010
+ * @dbuf: Pointer to the destination line (in XRGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le32 *dbuf32 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -726,6 +790,7 @@ static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, un
 		*dbuf32++ = cpu_to_le32(pix);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_line);
 
 /**
  * drm_fb_xrgb8888_to_xrgb2101010 - Convert XRGB8888 to XRGB2101010 clip buffer
@@ -761,7 +826,13 @@ void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *d
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010);
 
-static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to ARGB2101010
+ * @dbuf: Pointer to the destination line (in ARGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	__le32 *dbuf32 = dbuf;
 	const __le32 *sbuf32 = sbuf;
@@ -779,6 +850,7 @@ static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, un
 		*dbuf32++ = cpu_to_le32(pix);
 	}
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb2101010_line);
 
 /**
  * drm_fb_xrgb8888_to_argb2101010 - Convert XRGB8888 to ARGB2101010 clip buffer
include/drm/drm_format_helper.h +9 -0
index 291deb09475b..31ab699128d5 100644
@@ -24,30 +24,39 @@ 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_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+			     u32 fg_color, u32 bg_color);
 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);
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_rgb565(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 swab);
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
 				 const struct iosys_map *src, const struct drm_framebuffer *fb,
 				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
 				 const struct iosys_map *src, const struct drm_framebuffer *fb,
 				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_pitch,
 				 const struct iosys_map *src, const struct drm_framebuffer *fb,
 				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch,
 			       const struct iosys_map *src, const struct drm_framebuffer *fb,
 			       const struct drm_rect *clip);
 void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch,
 				 const struct iosys_map *src, const struct drm_framebuffer *fb,
 				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch,
 				    const struct iosys_map *src, const struct drm_framebuffer *fb,
 				    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels);
 void drm_fb_xrgb8888_to_argb2101010(struct iosys_map *dst, const unsigned int *dst_pitch,
 				    const struct iosys_map *src, const struct drm_framebuffer *fb,
 				    const struct drm_rect *clip);
author maintainer
#4 lore raw

Re: [PATCH v4 1/4] drm/format-helper: Export line conversion helper for drm_panic

Quoted 16 lines · nerdopolis
Quoted 15 lines · EDT Jocelyn Falempe

drm_panic will need the low-level drm_fb_xxxx_line functions. Also add drm_fb_r1_to_xrgb8888 to render the fonts.

---
  drivers/gpu/drm/drm_format_helper.c | 88 ++++++++++++++++++++++++++---
  include/drm/drm_format_helper.h     |  9 +++
  2 files changed, 89 insertions(+), 8 deletions(-)
drivers/gpu/drm/drm_format_helper.c +0 -0
index f93a4efcee90..c238e5d84f1f 100644
@@ -270,7 +270,30 @@ void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch,
 
Quoted 4 lines

drivers/gpu/drm/drm_format_helper.c void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch, · line 273

Quoted 3 lines
drivers/gpu/drm/drm_format_helper.c +0 -1
  	drm_fb_xfrm(dst, dst_pitch, &cpp, src, fb, clip, cached, swab_line);
  }
-EXPORT_SYMBOL(drm_fb_swab);

I had to add this line back to get it to build, but once I did, it worked.

Thanks, you're right that line shouldn't be removed.

Best regards,

Signature · 1 line
Jocelyn
#5 lore raw

Re: [PATCH v4 1/4] drm/format-helper: Export line conversion helper for drm_panic

In reply to Jocelyn Falempe

Hi

Am 03.10.23 um 16:22 schrieb Jocelyn Falempe:

Quoted 1 line

drm_panic will need the low-level drm_fb_xxxx_line functions.

It seems like premature optimization to not use drm_fb_blit(); especially since drm_panic is not performance critical.

Quoted 1 line

Also add drm_fb_r1_to_xrgb8888 to render the fonts.

I think we should provide a helper function that returns a pointer to the correct function for each supported case. Essentially, it would move that if-else branching from drm_fb_blit() into its own function. It's not typical DRM style, but cleaner than retyping the if-elses in drm_panic.

Something like:

typedef int (*drm_format_conv_func)(/* args here */);

drm_format_conv_func drm_format_conv(u32 dst_fourcc, u32 src_fourcc)

{
	// do if-else from drm_fb_blit here
	
	return <correct-format-conv-helper>
}

EXPORT_SYMBOL(drm_format_conv)

That would be callable from anywhere. You can integrate any helpers for _R1 here as well.

Best regards
Thomas

Quoted 248 lines
---
  drivers/gpu/drm/drm_format_helper.c | 88 ++++++++++++++++++++++++++---
  include/drm/drm_format_helper.h     |  9 +++
  2 files changed, 89 insertions(+), 8 deletions(-)
drivers/gpu/drm/drm_format_helper.c +80 -8
index f93a4efcee90..c238e5d84f1f 100644
@@ -270,7 +270,30 @@ void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch,
 
  	drm_fb_xfrm(dst, dst_pitch, &cpp, src, fb, clip, cached, swab_line);
  }
-EXPORT_SYMBOL(drm_fb_swab);
+
+/**
+ * drm_fb_r1_to_32bit_line - Convert one line from monochrome to any 32bit pixel format
+ * @dbuf: Pointer to the destination line (in any 32bit format)
+ * @sbuf: Pointer to the source line (in monochrome)
+ * @pixels: Number of pixels to convert.
+ * @fg_color: Foreground color, applied when R1 is 1
+ * @bg_color: Background color, applied when R1 is 0
+ *
+ * Convert monochrome to any format with 32bit pixel.
+ * There is a limitation, as sbuf is a pointer, it can only points to a multiple
+ * of 8 pixels in the source buffer.
+ */
+void drm_fb_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+				u32 fg_color, u32 bg_color)
+{
+	unsigned int x;
+	const u8 *sbuf8 = sbuf;
+	u32 *dubf32 = dbuf;
+
+	for (x = 0; x < pixels; x++)
+		dubf32[x] = (sbuf8[x / 8] & (0x80 >> (x % 8))) ? fg_color : bg_color;
+}
+EXPORT_SYMBOL(drm_fb_r1_to_32bit_line);
 
  static void drm_fb_xrgb8888_to_rgb332_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
@@ -320,7 +343,13 @@ void drm_fb_xrgb8888_to_rgb332(struct iosys_map *dst, const unsigned int *dst_pi
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
 
-static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to RGB565
+ * @dbuf: Pointer to the destination line (in RGB565)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
  	__le16 *dbuf16 = dbuf;
  	const __le32 *sbuf32 = sbuf;
@@ -336,6 +365,7 @@ static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigne
  		dbuf16[x] = cpu_to_le16(val16);
  	}
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565_line);
 
  /* TODO: implement this helper as conversion to RGB565|BIG_ENDIAN */
  static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf,
@@ -396,7 +426,13 @@ void drm_fb_xrgb8888_to_rgb565(struct iosys_map *dst, const unsigned int *dst_pi
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565);
 
-static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to XRGB1555
+ * @dbuf: Pointer to the destination line (in XRGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
  	__le16 *dbuf16 = dbuf;
  	const __le32 *sbuf32 = sbuf;
@@ -412,6 +448,7 @@ static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsig
  		dbuf16[x] = cpu_to_le16(val16);
  	}
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555_line);
 
  /**
   * drm_fb_xrgb8888_to_xrgb1555 - Convert XRGB8888 to XRGB1555 clip buffer
@@ -447,7 +484,13 @@ void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555);
 
-static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to ARGB1555
+ * @dbuf: Pointer to the destination line (in ARGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
  	__le16 *dbuf16 = dbuf;
  	const __le32 *sbuf32 = sbuf;
@@ -464,6 +507,7 @@ static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsig
  		dbuf16[x] = cpu_to_le16(val16);
  	}
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555_line);
 
  /**
   * drm_fb_xrgb8888_to_argb1555 - Convert XRGB8888 to ARGB1555 clip buffer
@@ -499,7 +543,13 @@ void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555);
 
-static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgba5551_line - Convert one line from XRGB8888 to ARGB5551
+ * @dbuf: Pointer to the destination line (in ARGB5551)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
  	__le16 *dbuf16 = dbuf;
  	const __le32 *sbuf32 = sbuf;
@@ -516,6 +566,7 @@ static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsig
  		dbuf16[x] = cpu_to_le16(val16);
  	}
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551_line);
 
  /**
   * drm_fb_xrgb8888_to_rgba5551 - Convert XRGB8888 to RGBA5551 clip buffer
@@ -551,7 +602,13 @@ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551);
 
-static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to RGB888
+ * @dbuf: Pointer to the destination line (in RGB888)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
  	u8 *dbuf8 = dbuf;
  	const __le32 *sbuf32 = sbuf;
@@ -566,6 +623,7 @@ static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigne
  		*dbuf8++ = (pix & 0x00FF0000) >> 16;
  	}
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_line);
 
  /**
   * drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer
@@ -709,7 +767,13 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned in
  		    drm_fb_xrgb8888_to_xbgr8888_line);
  }
 
-static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to XRGB2101010
+ * @dbuf: Pointer to the destination line (in XRGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
  	__le32 *dbuf32 = dbuf;
  	const __le32 *sbuf32 = sbuf;
@@ -726,6 +790,7 @@ static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, un
  		*dbuf32++ = cpu_to_le32(pix);
  	}
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_line);
 
  /**
   * drm_fb_xrgb8888_to_xrgb2101010 - Convert XRGB8888 to XRGB2101010 clip buffer
@@ -761,7 +826,13 @@ void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *d
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010);
 
-static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to ARGB2101010
+ * @dbuf: Pointer to the destination line (in ARGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
  	__le32 *dbuf32 = dbuf;
  	const __le32 *sbuf32 = sbuf;
@@ -779,6 +850,7 @@ static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, un
  		*dbuf32++ = cpu_to_le32(pix);
  	}
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb2101010_line);
 
  /**
   * drm_fb_xrgb8888_to_argb2101010 - Convert XRGB8888 to ARGB2101010 clip buffer
include/drm/drm_format_helper.h +9 -0
index 291deb09475b..31ab699128d5 100644
@@ -24,30 +24,39 @@ 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_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+			     u32 fg_color, u32 bg_color);
  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);
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_rgb565(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 swab);
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
  				 const struct iosys_map *src, const struct drm_framebuffer *fb,
  				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
  				 const struct iosys_map *src, const struct drm_framebuffer *fb,
  				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_pitch,
  				 const struct iosys_map *src, const struct drm_framebuffer *fb,
  				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch,
  			       const struct iosys_map *src, const struct drm_framebuffer *fb,
  			       const struct drm_rect *clip);
  void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch,
  				 const struct iosys_map *src, const struct drm_framebuffer *fb,
  				 const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch,
  				    const struct iosys_map *src, const struct drm_framebuffer *fb,
  				    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_argb2101010(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 · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#6 lore raw

Re: [PATCH v4 1/4] drm/format-helper: Export line conversion helper for drm_panic

Hi

Am 16.10.23 um 12:47 schrieb Thomas Zimmermann:

Quoted 6 lines

Hi

Am 03.10.23 um 16:22 schrieb Jocelyn Falempe:

Quoted 1 line

drm_panic will need the low-level drm_fb_xxxx_line functions.

It seems like premature optimization to not use drm_fb_blit(); especially since drm_panic is not performance critical.

We should especially not export any _line fnctions. Those are callbacks for drm_fb_xfrm(). They are artifacts of the implementation.

Best regards
Thomas

Quoted 304 lines
Quoted 2 lines

Also add drm_fb_r1_to_xrgb8888 to render the fonts.

I think we should provide a helper function that returns a pointer to the correct function for each supported case. Essentially, it would move that if-else branching from drm_fb_blit() into its own function.  It's not typical DRM style, but cleaner than retyping the if-elses in drm_panic.

Something like:

typedef int (*drm_format_conv_func)(/* args here */);

drm_format_conv_func  drm_format_conv(u32 dst_fourcc, u32 src_fourcc) {
    // do if-else from drm_fb_blit here

    return <correct-format-conv-helper>
}
EXPORT_SYMBOL(drm_format_conv)

That would be callable from anywhere. You can integrate any helpers for _R1 here as well.

Best regards
Thomas

Quoted 281 lines

---
  drivers/gpu/drm/drm_format_helper.c | 88 ++++++++++++++++++++++++++--- include/drm/drm_format_helper.h     |  9 +++

  2 files changed, 89 insertions(+), 8 deletions(-)
drivers/gpu/drm/drm_format_helper.c +3 -1
index f93a4efcee90..c238e5d84f1f 100644
@@ -270,7 +270,30 @@ void drm_fb_swab(struct iosys_map *dst, const 
 unsigned int *dst_pitch,
       drm_fb_xfrm(dst, dst_pitch, &cpp, src, fb, clip, cached, swab_line);
   }
-EXPORT_SYMBOL(drm_fb_swab);
+
+/**
+ * drm_fb_r1_to_32bit_line - Convert one line from monochrome to any 

32bit pixel format
+ * @dbuf: Pointer to the destination line (in any 32bit format)
+ * @sbuf: Pointer to the source line (in monochrome)
+ * @pixels: Number of pixels to convert.
+ * @fg_color: Foreground color, applied when R1 is 1
+ * @bg_color: Background color, applied when R1 is 0
+ *
+ * Convert monochrome to any format with 32bit pixel.
+ * There is a limitation, as sbuf is a pointer, it can only points to a multiple
+ * of 8 pixels in the source buffer.
+ */
+void drm_fb_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+                u32 fg_color, u32 bg_color)

drivers/gpu/drm/drm_format_helper.c +7 -0
+{
+    unsigned int x;
+    const u8 *sbuf8 = sbuf;
+    u32 *dubf32 = dbuf;
+
+    for (x = 0; x < pixels; x++)
+        dubf32[x] = (sbuf8[x / 8] & (0x80 >> (x % 8))) ? fg_color : 

bg_color;

drivers/gpu/drm/drm_format_helper.c +2 -0
+}
+EXPORT_SYMBOL(drm_fb_r1_to_32bit_line);

  static void drm_fb_xrgb8888_to_rgb332_line(void *dbuf, const void *sbuf, unsigned int pixels) {

drivers/gpu/drm/drm_format_helper.c +2 -1
@@ -320,7 +343,13 @@ void drm_fb_xrgb8888_to_rgb332(struct iosys_map 
 *dst, const unsigned int *dst_pi
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
-static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to 

RGB565
+ * @dbuf: Pointer to the destination line (in RGB565)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +3 -1
@@ -336,6 +365,7 @@ static void drm_fb_xrgb8888_to_rgb565_line(void 
 *dbuf, const void *sbuf, unsigne
           dbuf16[x] = cpu_to_le16(val16);
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565_line);
   /* TODO: implement this helper as conversion to RGB565|BIG_ENDIAN */
   static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf,
@@ -396,7 +426,13 @@ void drm_fb_xrgb8888_to_rgb565(struct iosys_map 
 *dst, const unsigned int *dst_pi
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565);
-static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to 

XRGB1555
+ * @dbuf: Pointer to the destination line (in XRGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +3 -1
@@ -412,6 +448,7 @@ static void drm_fb_xrgb8888_to_xrgb1555_line(void 
 *dbuf, const void *sbuf, unsig
           dbuf16[x] = cpu_to_le16(val16);
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555_line);
   /**
    * drm_fb_xrgb8888_to_xrgb1555 - Convert XRGB8888 to XRGB1555 clip buffer
@@ -447,7 +484,13 @@ void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map 
 *dst, const unsigned int *dst_
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555);
-static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to 

ARGB1555
+ * @dbuf: Pointer to the destination line (in ARGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +3 -1
@@ -464,6 +507,7 @@ static void drm_fb_xrgb8888_to_argb1555_line(void 
 *dbuf, const void *sbuf, unsig
           dbuf16[x] = cpu_to_le16(val16);
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555_line);
   /**
    * drm_fb_xrgb8888_to_argb1555 - Convert XRGB8888 to ARGB1555 clip buffer
@@ -499,7 +543,13 @@ void drm_fb_xrgb8888_to_argb1555(struct iosys_map 
 *dst, const unsigned int *dst_
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555);
-static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgba5551_line - Convert one line from XRGB8888 

to ARGB5551
+ * @dbuf: Pointer to the destination line (in ARGB5551)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +3 -1
@@ -516,6 +566,7 @@ static void drm_fb_xrgb8888_to_rgba5551_line(void 
 *dbuf, const void *sbuf, unsig
           dbuf16[x] = cpu_to_le16(val16);
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551_line);
   /**
    * drm_fb_xrgb8888_to_rgba5551 - Convert XRGB8888 to RGBA5551 clip buffer
@@ -551,7 +602,13 @@ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map 
 *dst, const unsigned int *dst_
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551);
-static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to 

RGB888
+ * @dbuf: Pointer to the destination line (in RGB888)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      u8 *dbuf8 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +1 -0
@@ -566,6 +623,7 @@ static void drm_fb_xrgb8888_to_rgb888_line(void 
 *dbuf, const void *sbuf, unsigne
           *dbuf8++ = (pix & 0x00FF0000) >> 16;
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_line);
   /**
    * drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer
@@ -709,7 +767,13 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct 

iosys_map *dst, const unsigned in drm_fb_xrgb8888_to_xbgr8888_line);
  }
-static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to XRGB2101010
+ * @dbuf: Pointer to the destination line (in XRGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le32 *dbuf32 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +0 -0
@@ -726,6 +790,7 @@ static void 

drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, un *dbuf32++ = cpu_to_le32(pix);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_line);
  /**
   * drm_fb_xrgb8888_to_xrgb2101010 - Convert XRGB8888 to XRGB2101010 clip buffer

drivers/gpu/drm/drm_format_helper.c +0 -0
@@ -761,7 +826,13 @@ void drm_fb_xrgb8888_to_xrgb2101010(struct 

iosys_map *dst, const unsigned int *d
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010);
-static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to ARGB2101010
+ * @dbuf: Pointer to the destination line (in ARGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le32 *dbuf32 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +0 -0
@@ -779,6 +850,7 @@ static void 

drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, un *dbuf32++ = cpu_to_le32(pix);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb2101010_line);
  /**
   * drm_fb_xrgb8888_to_argb2101010 - Convert XRGB8888 to ARGB2101010 clip buffer

include/drm/drm_format_helper.h +7 -0
index 291deb09475b..31ab699128d5 100644
@@ -24,30 +24,39 @@ 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_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned 
 int pixels,
+                 u32 fg_color, u32 bg_color);
   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);
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_rgb565(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 swab);
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_pitch,
                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch,
                      const struct iosys_map *src, const struct drm_framebuffer *fb,
                      const struct drm_rect *clip);
   void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch,
                    const struct iosys_map *src, const struct drm_framebuffer *fb,

                   const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void
*sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch, const struct iosys_map *src, const struct drm_framebuffer *fb, const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void
*sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_argb2101010(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 · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author maintainer
#7 lore raw

Re: [PATCH v4 1/4] drm/format-helper: Export line conversion helper for drm_panic

In reply to Thomas Zimmermann
Quoted 19 lines · Thomas Zimmermann

Hi

Am 03.10.23 um 16:22 schrieb Jocelyn Falempe:

Quoted 1 line

drm_panic will need the low-level drm_fb_xxxx_line functions.

It seems like premature optimization to not use drm_fb_blit(); especially since drm_panic is not performance critical.

Quoted 1 line

Also add drm_fb_r1_to_xrgb8888 to render the fonts.

I think we should provide a helper function that returns a pointer to the correct function for each supported case. Essentially, it would move that if-else branching from drm_fb_blit() into its own function.  It's not typical DRM style, but cleaner than retyping the if-elses in drm_panic.

Something like:

typedef int (*drm_format_conv_func)(/* args here */);

drm_format_conv_func  drm_format_conv(u32 dst_fourcc, u32 src_fourcc) {
    // do if-else from drm_fb_blit here

Quoted 5 lines

    return <correct-format-conv-helper>
}
EXPORT_SYMBOL(drm_format_conv)

That would be callable from anywhere. You can integrate any helpers for _R1 here as well.

Regarding the color conversion approach, I think we don't need to convert the whole buffer, like drm_fb_blit() or the xxxx_line() do. Just converting the fg_color and bg_color is enough, and then only the pixel size matters, when converting from R1.

So instead of having plenty of conversion functions, I will only need R1_to_8bit(), R1_to_16bit(), R1_to_24bit() and R1_to_32bit()

I can encapsulate this in a drm_blit_from_r1(), that will also take the fg_color and bg_color as parameter.

If you agree with that, I will do it for the v5.

Signature · 1 line
Jocelyn
Quoted 286 lines

Best regards
Thomas

Quoted 281 lines

---
  drivers/gpu/drm/drm_format_helper.c | 88 ++++++++++++++++++++++++++--- include/drm/drm_format_helper.h     |  9 +++

  2 files changed, 89 insertions(+), 8 deletions(-)
drivers/gpu/drm/drm_format_helper.c +3 -1
index f93a4efcee90..c238e5d84f1f 100644
@@ -270,7 +270,30 @@ void drm_fb_swab(struct iosys_map *dst, const 
 unsigned int *dst_pitch,
       drm_fb_xfrm(dst, dst_pitch, &cpp, src, fb, clip, cached, swab_line);
   }
-EXPORT_SYMBOL(drm_fb_swab);
+
+/**
+ * drm_fb_r1_to_32bit_line - Convert one line from monochrome to any 

32bit pixel format
+ * @dbuf: Pointer to the destination line (in any 32bit format)
+ * @sbuf: Pointer to the source line (in monochrome)
+ * @pixels: Number of pixels to convert.
+ * @fg_color: Foreground color, applied when R1 is 1
+ * @bg_color: Background color, applied when R1 is 0
+ *
+ * Convert monochrome to any format with 32bit pixel.
+ * There is a limitation, as sbuf is a pointer, it can only points to a multiple
+ * of 8 pixels in the source buffer.
+ */
+void drm_fb_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+                u32 fg_color, u32 bg_color)

drivers/gpu/drm/drm_format_helper.c +7 -0
+{
+    unsigned int x;
+    const u8 *sbuf8 = sbuf;
+    u32 *dubf32 = dbuf;
+
+    for (x = 0; x < pixels; x++)
+        dubf32[x] = (sbuf8[x / 8] & (0x80 >> (x % 8))) ? fg_color : 

bg_color;

drivers/gpu/drm/drm_format_helper.c +2 -0
+}
+EXPORT_SYMBOL(drm_fb_r1_to_32bit_line);

  static void drm_fb_xrgb8888_to_rgb332_line(void *dbuf, const void *sbuf, unsigned int pixels) {

drivers/gpu/drm/drm_format_helper.c +2 -1
@@ -320,7 +343,13 @@ void drm_fb_xrgb8888_to_rgb332(struct iosys_map 
 *dst, const unsigned int *dst_pi
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
-static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to 

RGB565
+ * @dbuf: Pointer to the destination line (in RGB565)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +3 -1
@@ -336,6 +365,7 @@ static void drm_fb_xrgb8888_to_rgb565_line(void 
 *dbuf, const void *sbuf, unsigne
           dbuf16[x] = cpu_to_le16(val16);
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565_line);
   /* TODO: implement this helper as conversion to RGB565|BIG_ENDIAN */
   static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf,
@@ -396,7 +426,13 @@ void drm_fb_xrgb8888_to_rgb565(struct iosys_map 
 *dst, const unsigned int *dst_pi
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565);
-static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to 

XRGB1555
+ * @dbuf: Pointer to the destination line (in XRGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +3 -1
@@ -412,6 +448,7 @@ static void drm_fb_xrgb8888_to_xrgb1555_line(void 
 *dbuf, const void *sbuf, unsig
           dbuf16[x] = cpu_to_le16(val16);
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555_line);
   /**
    * drm_fb_xrgb8888_to_xrgb1555 - Convert XRGB8888 to XRGB1555 clip buffer
@@ -447,7 +484,13 @@ void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map 
 *dst, const unsigned int *dst_
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555);
-static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to 

ARGB1555
+ * @dbuf: Pointer to the destination line (in ARGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +3 -1
@@ -464,6 +507,7 @@ static void drm_fb_xrgb8888_to_argb1555_line(void 
 *dbuf, const void *sbuf, unsig
           dbuf16[x] = cpu_to_le16(val16);
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555_line);
   /**
    * drm_fb_xrgb8888_to_argb1555 - Convert XRGB8888 to ARGB1555 clip buffer
@@ -499,7 +543,13 @@ void drm_fb_xrgb8888_to_argb1555(struct iosys_map 
 *dst, const unsigned int *dst_
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555);
-static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgba5551_line - Convert one line from XRGB8888 

to ARGB5551
+ * @dbuf: Pointer to the destination line (in ARGB5551)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +3 -1
@@ -516,6 +566,7 @@ static void drm_fb_xrgb8888_to_rgba5551_line(void 
 *dbuf, const void *sbuf, unsig
           dbuf16[x] = cpu_to_le16(val16);
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551_line);
   /**
    * drm_fb_xrgb8888_to_rgba5551 - Convert XRGB8888 to RGBA5551 clip buffer
@@ -551,7 +602,13 @@ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map 
 *dst, const unsigned int *dst_
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551);
-static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void 
 *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to 

RGB888
+ * @dbuf: Pointer to the destination line (in RGB888)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      u8 *dbuf8 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +1 -0
@@ -566,6 +623,7 @@ static void drm_fb_xrgb8888_to_rgb888_line(void 
 *dbuf, const void *sbuf, unsigne
           *dbuf8++ = (pix & 0x00FF0000) >> 16;
       }
   }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_line);
   /**
    * drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer
@@ -709,7 +767,13 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct 

iosys_map *dst, const unsigned in drm_fb_xrgb8888_to_xbgr8888_line);
  }
-static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to XRGB2101010
+ * @dbuf: Pointer to the destination line (in XRGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le32 *dbuf32 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +0 -0
@@ -726,6 +790,7 @@ static void 

drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, un *dbuf32++ = cpu_to_le32(pix);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_line);
  /**
   * drm_fb_xrgb8888_to_xrgb2101010 - Convert XRGB8888 to XRGB2101010 clip buffer

drivers/gpu/drm/drm_format_helper.c +0 -0
@@ -761,7 +826,13 @@ void drm_fb_xrgb8888_to_xrgb2101010(struct 

iosys_map *dst, const unsigned int *d
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010);
-static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to ARGB2101010
+ * @dbuf: Pointer to the destination line (in ARGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le32 *dbuf32 = dbuf;
      const __le32 *sbuf32 = sbuf;

drivers/gpu/drm/drm_format_helper.c +0 -0
@@ -779,6 +850,7 @@ static void 

drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, un *dbuf32++ = cpu_to_le32(pix);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb2101010_line);
  /**
   * drm_fb_xrgb8888_to_argb2101010 - Convert XRGB8888 to ARGB2101010 clip buffer

include/drm/drm_format_helper.h +7 -0
index 291deb09475b..31ab699128d5 100644
@@ -24,30 +24,39 @@ 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_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned 
 int pixels,
+                 u32 fg_color, u32 bg_color);
   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);
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_rgb565(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 swab);
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_pitch,
                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_pitch,
                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, 
 unsigned int pixels);
   void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch,
                      const struct iosys_map *src, const struct drm_framebuffer *fb,
                      const struct drm_rect *clip);
   void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch,
                    const struct iosys_map *src, const struct drm_framebuffer *fb,

                   const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void
*sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch, const struct iosys_map *src, const struct drm_framebuffer *fb, const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void
*sbuf, unsigned int pixels);
  void drm_fb_xrgb8888_to_argb2101010(struct iosys_map *dst, const unsigned int *dst_pitch, const struct iosys_map *src, const struct drm_framebuffer *fb, const struct drm_rect *clip);

author maintainer
#8 lore raw

PATCH v4 2/4 drm/panic: Add a drm panic handler

In reply to Jocelyn Falempe

This 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)

---
 drivers/gpu/drm/Kconfig     |  22 ++
 drivers/gpu/drm/Makefile    |   1 +
 drivers/gpu/drm/drm_drv.c   |   8 +
 drivers/gpu/drm/drm_panic.c | 413 ++++++++++++++++++++++++++++++++++++
 include/drm/drm_drv.h       |  14 ++
 include/drm/drm_panic.h     |  41 ++++
 6 files changed, 499 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_panic.c
 create mode 100644 include/drm/drm_panic.h
drivers/gpu/drm/Kconfig +22 -0
index afb3b2f5f425..17986f630a86 100644
@@ -99,6 +99,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
index 7a09a89b493b..a525dd9a2751 100644
@@ -72,6 +72,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
index 12687dd9e1ac..41e211aadb15 100644
@@ -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 +413 -0

413 lines not on this page · raw message

include/drm/drm_drv.h +14 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
 
 /**
@@ -408,6 +409,19 @@ 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.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * 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 +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.41.0
#9 lore raw
kernel test robot noticed the following build warnings:

Hi Jocelyn,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 2dde18cd1d8fac735875f2e4987f11817cc0bc2c]

url:    https://github.com/intel-lab-lkp/linux/commits/Jocelyn-Falempe/drm-format-helper-Export-line-conversion-helper-for-drm_panic/20231003-222642
base:   2dde18cd1d8fac735875f2e4987f11817cc0bc2c
patch link:    https://lore.kernel.org/r/20231003142508.190246-3-jfalempe%40redhat.com
patch subject: [PATCH v4 2/4] drm/panic: Add a drm panic handler
config: i386-randconfig-063-20231005 (https://download.01.org/0day-ci/archive/20231005/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231005/[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_panic.c:339:23: sparse: sparse: symbol 'drm_panic_notifier' was not declared. Should it be static?
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#10 lore raw
In reply to Jocelyn Falempe

Hi,

Quoted 19 lines · Jocelyn Falempe
include/drm/drm_drv.h +4 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
 
 /**
@@ -408,6 +409,19 @@ struct drm_driver {
 	 */
 	void (*show_fdinfo)(struct drm_printer *p, struct drm_file *f);
 
+	/**
+	 * @get_scanout_buffer:
+	 *

include/drm/drm_drv.h struct drm_driver { · line 424

Quoted 10 lines
include/drm/drm_drv.h +10 -0
+	 * Get the current scanout buffer, to display a panic message with drm_panic.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
+	 */
+	int (*get_scanout_buffer)(struct drm_device *dev,
+				  struct drm_scanout_buffer *sb);
+

What is the format of that buffer? What is supposed to happen if the planes / CRTC are setup in a way that is incompatible with the buffer format?

I've said it in that other series, but I really think we should be having a proper state on the side to deal with those properly.

Maxime

author maintainer
#11 lore raw
Quoted 28 lines · Maxime Ripard

Hi,

Quoted 25 lines · Jocelyn Falempe
include/drm/drm_drv.h +10 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
 
  /**
@@ -408,6 +409,19 @@ 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.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 424

Quoted 4 lines
include/drm/drm_drv.h +4 -0
+	 */
+	int (*get_scanout_buffer)(struct drm_device *dev,
+				  struct drm_scanout_buffer *sb);
+

What is the format of that buffer? What is supposed to happen if the planes / CRTC are setup in a way that is incompatible with the buffer format?

Currently, it only supports linear format, either in system memory, or iomem.
But really what is needed is the screen size, and a way to write pixels to it.
For more complex GPU, I don't know if it's easier to reprogram the GPU to linear format, or to add a simple "tiled" support to drm_panic. What would you propose as a panic interface to handle those complex format ?

Sometime it's also just not possible to write pixels to the screen, like if the panic occurs in the middle of suspend/resume, or during a mode-setting, and the hardware state is broken. In this case it's ok to return an error, and nothing will get displayed.

Best regards,

--

Jocelyn

Quoted 5 lines

I've said it in that other series, but I really think we should be having a proper state on the side to deal with those properly.

Maxime

maintainer
#12 lore raw

Hi Jocelyn,

Quoted 36 lines · Jocelyn Falempe
Quoted 26 lines · Maxime Ripard

Hi,

Quoted 23 lines · Jocelyn Falempe
include/drm/drm_drv.h +10 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
  /**
@@ -408,6 +409,19 @@ 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.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 424

Quoted 4 lines
include/drm/drm_drv.h +4 -0
+	 */
+	int (*get_scanout_buffer)(struct drm_device *dev,
+				  struct drm_scanout_buffer *sb);
+

What is the format of that buffer? What is supposed to happen if the planes / CRTC are setup in a way that is incompatible with the buffer format?

Quoted 7 lines

Currently, it only supports linear format, either in system memory, or iomem.
But really what is needed is the screen size, and a way to write pixels to it.
For more complex GPU, I don't know if it's easier to reprogram the GPU to linear format, or to add a simple "tiled" support to drm_panic. What would you propose as a panic interface to handle those complex format ?

It's not just about tiling, but also about YUV formats. If the display engine is currently playing a video at the moment, it's probably going to output some variation of multi-planar YUV and you won't have an RGB buffer available.

Same story if you're using a dma-buf buffer. You might not even be able to access that buffer at all from the CPU or the kernel.

I really think we should have some emergency state ready to commit on the side, and possibly a panic_commit function to prevent things like sleeping or waiting that regular atomic_commit can use.

That way, you know have all the resources available to you any time.

Quoted 4 lines

Sometime it's also just not possible to write pixels to the screen, like if the panic occurs in the middle of suspend/resume, or during a mode-setting, and the hardware state is broken. In this case it's ok to return an error, and nothing will get displayed.

And yeah, you won't be able to do it every time, but if it's never for some workload it's going to be a concern.

Anyway, we should at the very least document what we expect here.

Maxime

#13 lore raw
Quoted 47 lines · Maxime Ripard

Hi Jocelyn,

Quoted 36 lines · Jocelyn Falempe
Quoted 26 lines · Maxime Ripard

Hi,

Quoted 23 lines · Jocelyn Falempe
include/drm/drm_drv.h +10 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
  /**
@@ -408,6 +409,19 @@ 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.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 424

Quoted 4 lines
include/drm/drm_drv.h +4 -0
+	 */
+	int (*get_scanout_buffer)(struct drm_device *dev,
+				  struct drm_scanout_buffer *sb);
+

What is the format of that buffer? What is supposed to happen if the planes / CRTC are setup in a way that is incompatible with the buffer format?

Quoted 7 lines

Currently, it only supports linear format, either in system memory, or iomem.
But really what is needed is the screen size, and a way to write pixels to it.
For more complex GPU, I don't know if it's easier to reprogram the GPU to linear format, or to add a simple "tiled" support to drm_panic. What would you propose as a panic interface to handle those complex format ?

Quoted 5 lines

It's not just about tiling, but also about YUV formats. If the display engine is currently playing a video at the moment, it's probably going to output some variation of multi-planar YUV and you won't have an RGB buffer available.

I had support for some YUV formats in my 2019 attempt on a panic handler[1] and I made a recording of a test run as well[2] (see 4:30 for YUV). There was a discussion about challenges and i915 can disable tiling by flipping a bit in a register[3] and AMD has a debug interface[4] they can use to write pixels.

Noralf.

[1]
https://lore.kernel.org/dri-devel/[email protected]/
[2] https://youtu.be/lZ80vL4dgpE
[3]
https://lore.kernel.org/dri-devel/[email protected]/
[4]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 20 lines

Same story if you're using a dma-buf buffer. You might not even be able to access that buffer at all from the CPU or the kernel.

I really think we should have some emergency state ready to commit on the side, and possibly a panic_commit function to prevent things like sleeping or waiting that regular atomic_commit can use.

That way, you know have all the resources available to you any time.

Quoted 4 lines

Sometime it's also just not possible to write pixels to the screen, like if the panic occurs in the middle of suspend/resume, or during a mode-setting, and the hardware state is broken. In this case it's ok to return an error, and nothing will get displayed.

And yeah, you won't be able to do it every time, but if it's never for some workload it's going to be a concern.

Anyway, we should at the very least document what we expect here.

Maxime

author maintainer
#14 lore raw
Quoted 56 lines · Noralf Trønnes
Quoted 47 lines · Maxime Ripard

Hi Jocelyn,

Quoted 36 lines · Jocelyn Falempe
Quoted 26 lines · Maxime Ripard

Hi,

Quoted 23 lines · Jocelyn Falempe
include/drm/drm_drv.h +10 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
   /**
@@ -408,6 +409,19 @@ 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.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 424

Quoted 4 lines
include/drm/drm_drv.h +4 -0
+	 */
+	int (*get_scanout_buffer)(struct drm_device *dev,
+				  struct drm_scanout_buffer *sb);
+

What is the format of that buffer? What is supposed to happen if the planes / CRTC are setup in a way that is incompatible with the buffer format?

Quoted 7 lines

Currently, it only supports linear format, either in system memory, or iomem.
But really what is needed is the screen size, and a way to write pixels to it.
For more complex GPU, I don't know if it's easier to reprogram the GPU to linear format, or to add a simple "tiled" support to drm_panic. What would you propose as a panic interface to handle those complex format ?

Quoted 5 lines

It's not just about tiling, but also about YUV formats. If the display engine is currently playing a video at the moment, it's probably going to output some variation of multi-planar YUV and you won't have an RGB buffer available.

Quoted 5 lines

I had support for some YUV formats in my 2019 attempt on a panic handler[1] and I made a recording of a test run as well[2] (see 4:30 for YUV). There was a discussion about challenges and i915 can disable tiling by flipping a bit in a register[3] and AMD has a debug interface[4] they can use to write pixels.

I only added support for the format used by simpledrm, because I don't want to add support for all possible format if no driver are using it. It should be possible to add YUV format too.

I also prefer to convert only the foreground/background color, and then write directly into the buffers, instead of converting line by line. It works for all format where pixel size is a multiple of byte.

Quoted 19 lines

Noralf.

[1]
https://lore.kernel.org/dri-devel/[email protected]/
[2] https://youtu.be/lZ80vL4dgpE
[3]
https://lore.kernel.org/dri-devel/[email protected]/
[4]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 8 lines

Same story if you're using a dma-buf buffer. You might not even be able to access that buffer at all from the CPU or the kernel.

I really think we should have some emergency state ready to commit on the side, and possibly a panic_commit function to prevent things like sleeping or waiting that regular atomic_commit can use.

That way, you know have all the resources available to you any time.

I think reusing the atomic commit functions might be hard, because there are locks/allocation/threads hidden in drivers callback. I'm more in favor of an emergency function, that each driver has to implement, and use what the hardware can do to display a simple frame quickly. get_scanout_buffer() is a good start for simple driver, but will need refactoring for the more complex case, like adding a callback to write pixels one by one, if there is no memory mapped buffer available.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

Sometime it's also just not possible to write pixels to the screen, like if the panic occurs in the middle of suspend/resume, or during a mode-setting, and the hardware state is broken. In this case it's ok to return an error, and nothing will get displayed.

And yeah, you won't be able to do it every time, but if it's never for some workload it's going to be a concern.

Anyway, we should at the very least document what we expect here.

Yes I should better document the drm panic feature, and the get_scanout_buffer() interface.

Quoted 3 lines
Quoted 2 lines

Maxime

Signature · 1 line
Jocelyn
maintainer
#15 lore raw

Hi,

Quoted 57 lines · Jocelyn Falempe
Quoted 56 lines · Noralf Trønnes
Quoted 52 lines · Maxime Ripard

Hi Jocelyn,

Quoted 36 lines · Jocelyn Falempe
Quoted 26 lines · Maxime Ripard

Hi,

Quoted 23 lines · Jocelyn Falempe
include/drm/drm_drv.h +10 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
   /**
@@ -408,6 +409,19 @@ 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.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 424

Quoted 4 lines
include/drm/drm_drv.h +4 -0
+	 */
+	int (*get_scanout_buffer)(struct drm_device *dev,
+				  struct drm_scanout_buffer *sb);
+

What is the format of that buffer? What is supposed to happen if the planes / CRTC are setup in a way that is incompatible with the buffer format?

Quoted 7 lines

Currently, it only supports linear format, either in system memory, or iomem.
But really what is needed is the screen size, and a way to write pixels to it.
For more complex GPU, I don't know if it's easier to reprogram the GPU to linear format, or to add a simple "tiled" support to drm_panic. What would you propose as a panic interface to handle those complex format ?

It's not just about tiling, but also about YUV formats. If the display engine is currently playing a video at the moment, it's probably going to output some variation of multi-planar YUV and you won't have an RGB buffer available.

Quoted 8 lines
Quoted 5 lines

I had support for some YUV formats in my 2019 attempt on a panic handler[1] and I made a recording of a test run as well[2] (see 4:30 for YUV). There was a discussion about challenges and i915 can disable tiling by flipping a bit in a register[3] and AMD has a debug interface[4] they can use to write pixels.

I only added support for the format used by simpledrm, because I don't want to add support for all possible format if no driver are using it.

Sure.

Quoted 5 lines

It should be possible to add YUV format too.

I also prefer to convert only the foreground/background color, and then write directly into the buffers, instead of converting line by line. It works for all format where pixel size is a multiple of byte.

My point was that there might not be a buffer to write to. DMA_ATTR_NO_KERNEL_MAPPING exists, dma-buf might be unaccessible, unsafe or be completely out of control of the kernel space, or even not be accessible by the system at all (when doing secure playback for example, where the "trusted" component will do the decoding and will only give back a dma-buf handle to a secure memory buffer).

I appreciate that we probably don't want to address these scenarios right now, but we should have a path forward to support them eventually. Copying the panic handler content to the buffer is optimistic and won't work in all the scenarios described above, pretty much requiring to start from scratch that effort.

Quoted 10 lines
Quoted 10 lines

https://lore.kernel.org/dri-devel/[email protected]/
[2] https://youtu.be/lZ80vL4dgpE
[3]
https://lore.kernel.org/dri-devel/[email protected]/
[4]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 3 lines

Same story if you're using a dma-buf buffer. You might not even be able to access that buffer at all from the CPU or the kernel.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

I really think we should have some emergency state ready to commit on the side, and possibly a panic_commit function to prevent things like sleeping or waiting that regular atomic_commit can use.

That way, you know have all the resources available to you any time.

I think reusing the atomic commit functions might be hard, because there are locks/allocation/threads hidden in drivers callback.

Allocations are bugs as far as I'm concerned. Allocations in atomic_commit path are pretty big hint that you're doing something wrong so I wouldn't worry too much about them. For locking, yeah... Which is why I was suggesting an emergency atomic_commit of some sorts (for planes only?). Switching back to whatever we were doing to an RGB plane should be simple enough for most drivers and probably can be done safely enough on most drivers without any locks.

And you don't need to support all kinds of tiling, YUV or RGB variants.

Quoted 6 lines

I'm more in favor of an emergency function, that each driver has to implement, and use what the hardware can do to display a simple frame quickly. get_scanout_buffer() is a good start for simple driver, but will need refactoring for the more complex case, like adding a callback to write pixels one by one, if there is no memory mapped buffer available.

Sorry, I'm not quite sure what you mean there, where would you write the pixel to?

Maxime

author maintainer
#16 lore raw
Quoted 117 lines · Maxime Ripard

Hi,

Quoted 57 lines · Jocelyn Falempe
Quoted 56 lines · Noralf Trønnes
Quoted 52 lines · Maxime Ripard

Hi Jocelyn,

Quoted 36 lines · Jocelyn Falempe
Quoted 26 lines · Maxime Ripard

Hi,

Quoted 23 lines · Jocelyn Falempe
include/drm/drm_drv.h +10 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
    /**
@@ -408,6 +409,19 @@ 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.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 423

Quoted 4 lines
include/drm/drm_drv.h +4 -0
+	 */
+	int (*get_scanout_buffer)(struct drm_device *dev,
+				  struct drm_scanout_buffer *sb);
+

What is the format of that buffer? What is supposed to happen if the planes / CRTC are setup in a way that is incompatible with the buffer format?

Quoted 7 lines

Currently, it only supports linear format, either in system memory, or iomem.
But really what is needed is the screen size, and a way to write pixels to it.
For more complex GPU, I don't know if it's easier to reprogram the GPU to linear format, or to add a simple "tiled" support to drm_panic. What would you propose as a panic interface to handle those complex format ?

It's not just about tiling, but also about YUV formats. If the display engine is currently playing a video at the moment, it's probably going to output some variation of multi-planar YUV and you won't have an RGB buffer available.

Quoted 8 lines
Quoted 5 lines

I had support for some YUV formats in my 2019 attempt on a panic handler[1] and I made a recording of a test run as well[2] (see 4:30 for YUV). There was a discussion about challenges and i915 can disable tiling by flipping a bit in a register[3] and AMD has a debug interface[4] they can use to write pixels.

I only added support for the format used by simpledrm, because I don't want to add support for all possible format if no driver are using it.

Sure.

Quoted 5 lines

It should be possible to add YUV format too.

I also prefer to convert only the foreground/background color, and then write directly into the buffers, instead of converting line by line. It works for all format where pixel size is a multiple of byte.

My point was that there might not be a buffer to write to. DMA_ATTR_NO_KERNEL_MAPPING exists, dma-buf might be unaccessible, unsafe or be completely out of control of the kernel space, or even not be accessible by the system at all (when doing secure playback for example, where the "trusted" component will do the decoding and will only give back a dma-buf handle to a secure memory buffer).

I appreciate that we probably don't want to address these scenarios right now, but we should have a path forward to support them eventually. Copying the panic handler content to the buffer is optimistic and won't work in all the scenarios described above, pretty much requiring to start from scratch that effort.

Quoted 10 lines
Quoted 10 lines

https://lore.kernel.org/dri-devel/[email protected]/
[2] https://youtu.be/lZ80vL4dgpE
[3]
https://lore.kernel.org/dri-devel/[email protected]/
[4]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 3 lines

Same story if you're using a dma-buf buffer. You might not even be able to access that buffer at all from the CPU or the kernel.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

I really think we should have some emergency state ready to commit on the side, and possibly a panic_commit function to prevent things like sleeping or waiting that regular atomic_commit can use.

That way, you know have all the resources available to you any time.

I think reusing the atomic commit functions might be hard, because there are locks/allocation/threads hidden in drivers callback.

Allocations are bugs as far as I'm concerned. Allocations in atomic_commit path are pretty big hint that you're doing something wrong so I wouldn't worry too much about them. For locking, yeah... Which is why I was suggesting an emergency atomic_commit of some sorts (for planes only?). Switching back to whatever we were doing to an RGB plane should be simple enough for most drivers and probably can be done safely enough on most drivers without any locks.

Quoted 1 line

And you don't need to support all kinds of tiling, YUV or RGB variants.

So if I understand correctly, drm_panic would pre-allocate a plane/commit, and use that when a panic occurs ? I have two concern about this approach:
- How much memory would be allocated for this ? a whole framebuffer can be big for just this use case.
- I find it risky to completely reconfigure the hardware in a panic handler.

Also how many drivers would need this ?

Currently I was mostly considering x86 platform, so:

simpledrm/ast/mgag200 which works well with the get_scanout_buffer().

i915/amdgpu/nouveau, which are quite complex, and will need to do their own thing anyway.

Quoted 10 lines
Quoted 7 lines

I'm more in favor of an emergency function, that each driver has to implement, and use what the hardware can do to display a simple frame quickly. get_scanout_buffer() is a good start for simple driver, but will need refactoring for the more complex case, like adding a callback to write pixels one by one, if there is no memory mapped buffer available.

Sorry, I'm not quite sure what you mean there, where would you write the pixel to?

It was mentioned by Noralf, about the amdgpu driver:

https://lore.kernel.org/dri-devel/[email protected]/

They have a slow "debug interface" that you can write to, and can be used for the panic handler. It's not memory mapped, so you have to write pixels one by one.

So for the struct drm_scanout_buffer, I can add a function pointer to a write_pixel(u32 x, u32 y, u32 color) So if the iosys map is null, it will use that instead.

Quoted 2 lines

Maxime

maintainer
#17 lore raw
Quoted 118 lines · Jocelyn Falempe
Quoted 117 lines · Maxime Ripard

Hi,

Quoted 57 lines · Jocelyn Falempe
Quoted 56 lines · Noralf Trønnes
Quoted 52 lines · Maxime Ripard

Hi Jocelyn,

Quoted 36 lines · Jocelyn Falempe
Quoted 26 lines · Maxime Ripard

Hi,

Quoted 23 lines · Jocelyn Falempe
include/drm/drm_drv.h +10 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
    /**
@@ -408,6 +409,19 @@ 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.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 423

Quoted 4 lines
include/drm/drm_drv.h +4 -0
+	 */
+	int (*get_scanout_buffer)(struct drm_device *dev,
+				  struct drm_scanout_buffer *sb);
+

What is the format of that buffer? What is supposed to happen if the planes / CRTC are setup in a way that is incompatible with the buffer format?

Quoted 7 lines

Currently, it only supports linear format, either in system memory, or iomem.
But really what is needed is the screen size, and a way to write pixels to it.
For more complex GPU, I don't know if it's easier to reprogram the GPU to linear format, or to add a simple "tiled" support to drm_panic. What would you propose as a panic interface to handle those complex format ?

It's not just about tiling, but also about YUV formats. If the display engine is currently playing a video at the moment, it's probably going to output some variation of multi-planar YUV and you won't have an RGB buffer available.

Quoted 8 lines
Quoted 5 lines

I had support for some YUV formats in my 2019 attempt on a panic handler[1] and I made a recording of a test run as well[2] (see 4:30 for YUV). There was a discussion about challenges and i915 can disable tiling by flipping a bit in a register[3] and AMD has a debug interface[4] they can use to write pixels.

I only added support for the format used by simpledrm, because I don't want to add support for all possible format if no driver are using it.

Sure.

Quoted 5 lines

It should be possible to add YUV format too.

I also prefer to convert only the foreground/background color, and then write directly into the buffers, instead of converting line by line. It works for all format where pixel size is a multiple of byte.

My point was that there might not be a buffer to write to. DMA_ATTR_NO_KERNEL_MAPPING exists, dma-buf might be unaccessible, unsafe or be completely out of control of the kernel space, or even not be accessible by the system at all (when doing secure playback for example, where the "trusted" component will do the decoding and will only give back a dma-buf handle to a secure memory buffer).

I appreciate that we probably don't want to address these scenarios right now, but we should have a path forward to support them eventually. Copying the panic handler content to the buffer is optimistic and won't work in all the scenarios described above, pretty much requiring to start from scratch that effort.

Quoted 10 lines
Quoted 10 lines

https://lore.kernel.org/dri-devel/[email protected]/
[2] https://youtu.be/lZ80vL4dgpE
[3]
https://lore.kernel.org/dri-devel/[email protected]/
[4]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 3 lines

Same story if you're using a dma-buf buffer. You might not even be able to access that buffer at all from the CPU or the kernel.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

I really think we should have some emergency state ready to commit on the side, and possibly a panic_commit function to prevent things like sleeping or waiting that regular atomic_commit can use.

That way, you know have all the resources available to you any time.

I think reusing the atomic commit functions might be hard, because there are locks/allocation/threads hidden in drivers callback.

Allocations are bugs as far as I'm concerned. Allocations in atomic_commit path are pretty big hint that you're doing something wrong so I wouldn't worry too much about them. For locking, yeah... Which is why I was suggesting an emergency atomic_commit of some sorts (for planes only?). Switching back to whatever we were doing to an RGB plane should be simple enough for most drivers and probably can be done safely enough on most drivers without any locks.

Quoted 4 lines
Quoted 1 line

And you don't need to support all kinds of tiling, YUV or RGB variants.

So if I understand correctly, drm_panic would pre-allocate a plane/commit, and use that when a panic occurs ?

And have it checked already, yes. We would only wait for a panic to happen to pull the trigger on the commit.

Quoted 3 lines

I have two concern about this approach:
- How much memory would be allocated for this ? a whole framebuffer can be big for just this use case.

I'dd expect a whole framebuffer for the current configuration/resolution. It would be typically 4MB for a full-HD system which isn't a lot really and I guess we can always add an option to disable the mechanism if needed.

Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

Quoted 8 lines

Also how many drivers would need this ?

Currently I was mostly considering x86 platform, so:

simpledrm/ast/mgag200 which works well with the get_scanout_buffer().

i915/amdgpu/nouveau, which are quite complex, and will need to do their own thing anyway.

I guess we're not entirely aligned there then. I would expect that mechanism to work with any atomic KMS driver. You are right that i915, amdgpu and nouveau are special enough that some extra internal plumbing is going to be required, but I'd expect it to be easy to support with any other driver for a memory-mapped device.

I guess what I'm trying to say is, even though it's totally fine that you only support those drivers at first, supporting in vc4 for example shouldn't require to rewrite the whole thing.

Quoted 14 lines
Quoted 9 lines
Quoted 6 lines

I'm more in favor of an emergency function, that each driver has to implement, and use what the hardware can do to display a simple frame quickly. get_scanout_buffer() is a good start for simple driver, but will need refactoring for the more complex case, like adding a callback to write pixels one by one, if there is no memory mapped buffer available.

Sorry, I'm not quite sure what you mean there, where would you write the pixel to?

It was mentioned by Noralf, about the amdgpu driver:

https://lore.kernel.org/dri-devel/[email protected]/

Quoted 7 lines

They have a slow "debug interface" that you can write to, and can be used for the panic handler. It's not memory mapped, so you have to write pixels one by one.

So for the struct drm_scanout_buffer, I can add a function pointer to a write_pixel(u32 x, u32 y, u32 color)
So if the iosys map is null, it will use that instead.

It would be nice to support indeed, but it's a fairly rare feature afaik so I'd rather focus on getting something that can work for everyone first

Maxime

author maintainer
#18 lore raw
Quoted 127 lines · Maxime Ripard
Quoted 118 lines · Jocelyn Falempe
Quoted 117 lines · Maxime Ripard

Hi,

Quoted 57 lines · Jocelyn Falempe
Quoted 56 lines · Noralf Trønnes
Quoted 52 lines · Maxime Ripard

Hi Jocelyn,

Quoted 36 lines · Jocelyn Falempe
Quoted 26 lines · Maxime Ripard

Hi,

Quoted 23 lines · Jocelyn Falempe
include/drm/drm_drv.h +10 -0
index 89e2706cac56..e538c87116d3 100644
@@ -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;
     /**
@@ -408,6 +409,19 @@ 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.
+	 * It is called from a panic callback, and must follow its restrictions.
+	 *
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
Quoted 8 lines

include/drm/drm_drv.h struct drm_driver { · line 423

Quoted 4 lines
include/drm/drm_drv.h +4 -0
+	 */
+	int (*get_scanout_buffer)(struct drm_device *dev,
+				  struct drm_scanout_buffer *sb);
+

What is the format of that buffer? What is supposed to happen if the planes / CRTC are setup in a way that is incompatible with the buffer format?

Quoted 7 lines

Currently, it only supports linear format, either in system memory, or iomem.
But really what is needed is the screen size, and a way to write pixels to it.
For more complex GPU, I don't know if it's easier to reprogram the GPU to linear format, or to add a simple "tiled" support to drm_panic. What would you propose as a panic interface to handle those complex format ?

It's not just about tiling, but also about YUV formats. If the display engine is currently playing a video at the moment, it's probably going to output some variation of multi-planar YUV and you won't have an RGB buffer available.

Quoted 8 lines
Quoted 5 lines

I had support for some YUV formats in my 2019 attempt on a panic handler[1] and I made a recording of a test run as well[2] (see 4:30 for YUV). There was a discussion about challenges and i915 can disable tiling by flipping a bit in a register[3] and AMD has a debug interface[4] they can use to write pixels.

I only added support for the format used by simpledrm, because I don't want to add support for all possible format if no driver are using it.

Sure.

Quoted 5 lines

It should be possible to add YUV format too.

I also prefer to convert only the foreground/background color, and then write directly into the buffers, instead of converting line by line. It works for all format where pixel size is a multiple of byte.

My point was that there might not be a buffer to write to. DMA_ATTR_NO_KERNEL_MAPPING exists, dma-buf might be unaccessible, unsafe or be completely out of control of the kernel space, or even not be accessible by the system at all (when doing secure playback for example, where the "trusted" component will do the decoding and will only give back a dma-buf handle to a secure memory buffer).

I appreciate that we probably don't want to address these scenarios right now, but we should have a path forward to support them eventually. Copying the panic handler content to the buffer is optimistic and won't work in all the scenarios described above, pretty much requiring to start from scratch that effort.

Quoted 10 lines
Quoted 10 lines

https://lore.kernel.org/dri-devel/[email protected]/
[2] https://youtu.be/lZ80vL4dgpE
[3]
https://lore.kernel.org/dri-devel/[email protected]/
[4]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 3 lines

Same story if you're using a dma-buf buffer. You might not even be able to access that buffer at all from the CPU or the kernel.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

I really think we should have some emergency state ready to commit on the side, and possibly a panic_commit function to prevent things like sleeping or waiting that regular atomic_commit can use.

That way, you know have all the resources available to you any time.

I think reusing the atomic commit functions might be hard, because there are locks/allocation/threads hidden in drivers callback.

Allocations are bugs as far as I'm concerned. Allocations in atomic_commit path are pretty big hint that you're doing something wrong so I wouldn't worry too much about them. For locking, yeah... Which is why I was suggesting an emergency atomic_commit of some sorts (for planes only?). Switching back to whatever we were doing to an RGB plane should be simple enough for most drivers and probably can be done safely enough on most drivers without any locks.

Quoted 4 lines
Quoted 1 line

And you don't need to support all kinds of tiling, YUV or RGB variants.

So if I understand correctly, drm_panic would pre-allocate a plane/commit, and use that when a panic occurs ?

And have it checked already, yes. We would only wait for a panic to happen to pull the trigger on the commit.

Quoted 8 lines
Quoted 3 lines

I have two concern about this approach:
- How much memory would be allocated for this ? a whole framebuffer can be big for just this use case.

I'dd expect a whole framebuffer for the current configuration/resolution. It would be typically 4MB for a full-HD system which isn't a lot really and I guess we can always add an option to disable the mechanism if needed.

Ok, that's a bit big, but if there is no other way.

Quoted 7 lines
Quoted 2 lines

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

In this case it can work, but by using generic drm api, it's hard to know what the driver will do.

Quoted 15 lines
Quoted 8 lines

Also how many drivers would need this ?

Currently I was mostly considering x86 platform, so:

simpledrm/ast/mgag200 which works well with the get_scanout_buffer().

i915/amdgpu/nouveau, which are quite complex, and will need to do their own thing anyway.

I guess we're not entirely aligned there then. I would expect that mechanism to work with any atomic KMS driver. You are right that i915, amdgpu and nouveau are special enough that some extra internal plumbing is going to be required, but I'd expect it to be easy to support with any other driver for a memory-mapped device.

Quoted 3 lines

I guess what I'm trying to say is, even though it's totally fine that you only support those drivers at first, supporting in vc4 for example shouldn't require to rewrite the whole thing.

Would that work for you to put that in a drm_panic_helper.c, so that drivers can opt-in ?

So the driver can call a drm_panic_helper_prepare_commit() at initialization, and then in the get_scanout_buffer() function, run the atomic_update() on it, and return this commit's framebuffer ?

That way each driver have a better control on what the panic handler will do.
It can even call directly its internal functions, to avoid the locks of the drm generic functions, and make sure it will only change the format and base address. That's a bit more work for each driver, but should be more reliable I think.

Signature · 1 line
Jocelyn
Quoted 27 lines
Quoted 15 lines
Quoted 10 lines
Quoted 7 lines

I'm more in favor of an emergency function, that each driver has to implement, and use what the hardware can do to display a simple frame quickly. get_scanout_buffer() is a good start for simple driver, but will need refactoring for the more complex case, like adding a callback to write pixels one by one, if there is no memory mapped buffer available.

Sorry, I'm not quite sure what you mean there, where would you write the pixel to?

It was mentioned by Noralf, about the amdgpu driver:

https://lore.kernel.org/dri-devel/[email protected]/

Quoted 7 lines

They have a slow "debug interface" that you can write to, and can be used for the panic handler. It's not memory mapped, so you have to write pixels one by one.

So for the struct drm_scanout_buffer, I can add a function pointer to a write_pixel(u32 x, u32 y, u32 color)
So if the iosys map is null, it will use that instead.

It would be nice to support indeed, but it's a fairly rare feature afaik so I'd rather focus on getting something that can work for everyone first

Maxime

maintainer
#19 lore raw
Quoted 8 lines · Jocelyn Falempe
Quoted 6 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

In this case it can work, but by using generic drm api, it's hard to know what the driver will do.

We should document extensively what we expect drivers to do in those hooks, and possibly call cant_sleep() in the framework function to have some reporting at least.

Quoted 19 lines
Quoted 15 lines
Quoted 8 lines

Also how many drivers would need this ?

Currently I was mostly considering x86 platform, so:

simpledrm/ast/mgag200 which works well with the get_scanout_buffer().

i915/amdgpu/nouveau, which are quite complex, and will need to do their own thing anyway.

I guess we're not entirely aligned there then. I would expect that mechanism to work with any atomic KMS driver. You are right that i915, amdgpu and nouveau are special enough that some extra internal plumbing is going to be required, but I'd expect it to be easy to support with any other driver for a memory-mapped device.

Quoted 3 lines

I guess what I'm trying to say is, even though it's totally fine that you only support those drivers at first, supporting in vc4 for example shouldn't require to rewrite the whole thing.

Quoted 5 lines

Would that work for you to put that in a drm_panic_helper.c, so that drivers can opt-in ?

So the driver can call a drm_panic_helper_prepare_commit() at initialization, and then in the get_scanout_buffer() function

If we have a full blown commit with a new framebuffer, why do we need get_scanout_buffer? It should be either the framebuffer itself, or in the plane state if you have a conversion.

Quoted 8 lines

run the atomic_update() on it, and return this commit's framebuffer ?

That way each driver have a better control on what the panic handler will do.
It can even call directly its internal functions, to avoid the locks of the drm generic functions, and make sure it will only change the format and base address.
That's a bit more work for each driver, but should be more reliable I think.

I don't think that better control there is a good idea, it's a path that won't get tested much so we'd be better off not allowing drivers to deviate too much from the "ideal" design.

What I had in mind is something like:

- Add a panic hook in drm_mode_config_funcs, with a

    drm_atomic_helper_panic helper;

- Provide an atomic_panic hook or something in drm_plane_helper_funcs;

- If they are set, we register the drm_panic handler;

- The handler will call drm_mode_config_funcs.panic, which will take its prepared state, fill the framebuffer it allocated with the penguin and backtrace, call drm_plane_helper_funcs.atomic_panic().

- The driver now updates the format and fb address.

- Halt and catch fire

Does that make sense?
Maxime

author maintainer
#20 lore raw
Quoted 69 lines · Maxime Ripard
Quoted 8 lines · Jocelyn Falempe
Quoted 6 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

In this case it can work, but by using generic drm api, it's hard to know what the driver will do.

We should document extensively what we expect drivers to do in those hooks, and possibly call cant_sleep() in the framework function to have some reporting at least.

Quoted 19 lines
Quoted 15 lines
Quoted 8 lines

Also how many drivers would need this ?

Currently I was mostly considering x86 platform, so:

simpledrm/ast/mgag200 which works well with the get_scanout_buffer().

i915/amdgpu/nouveau, which are quite complex, and will need to do their own thing anyway.

I guess we're not entirely aligned there then. I would expect that mechanism to work with any atomic KMS driver. You are right that i915, amdgpu and nouveau are special enough that some extra internal plumbing is going to be required, but I'd expect it to be easy to support with any other driver for a memory-mapped device.

Quoted 3 lines

I guess what I'm trying to say is, even though it's totally fine that you only support those drivers at first, supporting in vc4 for example shouldn't require to rewrite the whole thing.

Quoted 5 lines

Would that work for you to put that in a drm_panic_helper.c, so that drivers can opt-in ?

So the driver can call a drm_panic_helper_prepare_commit() at initialization, and then in the get_scanout_buffer() function

If we have a full blown commit with a new framebuffer, why do we need get_scanout_buffer? It should be either the framebuffer itself, or in the plane state if you have a conversion.

Quoted 8 lines

run the atomic_update() on it, and return this commit's framebuffer ?

That way each driver have a better control on what the panic handler will do.
It can even call directly its internal functions, to avoid the locks of the drm generic functions, and make sure it will only change the format and base address.
That's a bit more work for each driver, but should be more reliable I think.

I don't think that better control there is a good idea, it's a path that won't get tested much so we'd be better off not allowing drivers to deviate too much from the "ideal" design.

What I had in mind is something like:

- Add a panic hook in drm_mode_config_funcs, with a

     drm_atomic_helper_panic helper;

- Provide an atomic_panic hook or something in drm_plane_helper_funcs;

- If they are set, we register the drm_panic handler;

- The handler will call drm_mode_config_funcs.panic, which will take its prepared state, fill the framebuffer it allocated with the penguin and backtrace, call drm_plane_helper_funcs.atomic_panic().

Quoted 5 lines

- The driver now updates the format and fb address.

- Halt and catch fire

Does that make sense?

Yes, I will do some experiment with that, and see if I can make it work this way.
If possible I still want to have a way for simple drivers like simpledrm/mgag200 to not allocate a full framebuffer.

Quoted 1 line

Maxime

Signature · 1 line
Jocelyn
maintainer
#21 lore raw
Quoted 70 lines · Jocelyn Falempe
Quoted 69 lines · Maxime Ripard
Quoted 8 lines · Jocelyn Falempe
Quoted 6 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

In this case it can work, but by using generic drm api, it's hard to know what the driver will do.

We should document extensively what we expect drivers to do in those hooks, and possibly call cant_sleep() in the framework function to have some reporting at least.

Quoted 19 lines
Quoted 15 lines
Quoted 8 lines

Also how many drivers would need this ?

Currently I was mostly considering x86 platform, so:

simpledrm/ast/mgag200 which works well with the get_scanout_buffer().

i915/amdgpu/nouveau, which are quite complex, and will need to do their own thing anyway.

I guess we're not entirely aligned there then. I would expect that mechanism to work with any atomic KMS driver. You are right that i915, amdgpu and nouveau are special enough that some extra internal plumbing is going to be required, but I'd expect it to be easy to support with any other driver for a memory-mapped device.

Quoted 3 lines

I guess what I'm trying to say is, even though it's totally fine that you only support those drivers at first, supporting in vc4 for example shouldn't require to rewrite the whole thing.

Quoted 5 lines

Would that work for you to put that in a drm_panic_helper.c, so that drivers can opt-in ?

So the driver can call a drm_panic_helper_prepare_commit() at initialization, and then in the get_scanout_buffer() function

If we have a full blown commit with a new framebuffer, why do we need get_scanout_buffer? It should be either the framebuffer itself, or in the plane state if you have a conversion.

Quoted 8 lines

run the atomic_update() on it, and return this commit's framebuffer ?

That way each driver have a better control on what the panic handler will do.
It can even call directly its internal functions, to avoid the locks of the drm generic functions, and make sure it will only change the format and base address.
That's a bit more work for each driver, but should be more reliable I think.

I don't think that better control there is a good idea, it's a path that won't get tested much so we'd be better off not allowing drivers to deviate too much from the "ideal" design.

What I had in mind is something like:

- Add a panic hook in drm_mode_config_funcs, with a

     drm_atomic_helper_panic helper;

- Provide an atomic_panic hook or something in drm_plane_helper_funcs;

- If they are set, we register the drm_panic handler;

- The handler will call drm_mode_config_funcs.panic, which will take its prepared state, fill the framebuffer it allocated with the penguin and backtrace, call drm_plane_helper_funcs.atomic_panic().

Quoted 8 lines
Quoted 5 lines

- The driver now updates the format and fb address.

- Halt and catch fire

Does that make sense?

Yes, I will do some experiment with that, and see if I can make it work this way.

Thanks :)

Quoted 2 lines

If possible I still want to have a way for simple drivers like simpledrm/mgag200 to not allocate a full framebuffer.

I guess the split isn't going to be whether the driver is simple or not, but whether it always has access to the buffer used by the scanout.

Like for simpledrm, we have that guarantee so it makes sense. For other, if we allow "direct" dma-buf, it's game over and we just can't.

Maxime

#22 lore raw
In reply to Maxime Ripard

Hi

Am 09.10.23 um 18:07 schrieb Maxime Ripard:

Quoted 36 lines · Jocelyn Falempe
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

In this case it can work, but by using generic drm api, it's hard to know what the driver will do.

We should document extensively what we expect drivers to do in those hooks, and possibly call cant_sleep() in the framework function to have some reporting at least.

Quoted 22 lines
Quoted 15 lines
Quoted 8 lines

Also how many drivers would need this ?

Currently I was mostly considering x86 platform, so:

simpledrm/ast/mgag200 which works well with the get_scanout_buffer().

i915/amdgpu/nouveau, which are quite complex, and will need to do their own thing anyway.

I guess we're not entirely aligned there then. I would expect that mechanism to work with any atomic KMS driver. You are right that i915, amdgpu and nouveau are special enough that some extra internal plumbing is going to be required, but I'd expect it to be easy to support with any other driver for a memory-mapped device.

Quoted 3 lines

I guess what I'm trying to say is, even though it's totally fine that you only support those drivers at first, supporting in vc4 for example shouldn't require to rewrite the whole thing.

Would that work for you to put that in a drm_panic_helper.c, so that drivers can opt-in ?

Quoted 6 lines
Quoted 2 lines

So the driver can call a drm_panic_helper_prepare_commit() at initialization, and then in the get_scanout_buffer() function

If we have a full blown commit with a new framebuffer, why do we need get_scanout_buffer? It should be either the framebuffer itself, or in the plane state if you have a conversion.

We also have discussions about kexec/kdump support. Here we'd need to retrieve the scanout address, forward it to the kexec kernel and put simpledrm onto that framebuffer until the regular driver takes over. An interface like get_scanout_buffer will be helpful for this use case. So it makes sense to use it for the panic handler as well.

Quoted 27 lines
Quoted 9 lines

run the atomic_update() on it, and return this commit's framebuffer ?

That way each driver have a better control on what the panic handler will do.
It can even call directly its internal functions, to avoid the locks of the drm generic functions, and make sure it will only change the format and base address.
That's a bit more work for each driver, but should be more reliable I think.

I don't think that better control there is a good idea, it's a path that won't get tested much so we'd be better off not allowing drivers to deviate too much from the "ideal" design.

What I had in mind is something like:

- Add a panic hook in drm_mode_config_funcs, with a

     drm_atomic_helper_panic helper;

- Provide an atomic_panic hook or something in drm_plane_helper_funcs;

- If they are set, we register the drm_panic handler;

- The handler will call drm_mode_config_funcs.panic, which will take its prepared state, fill the framebuffer it allocated with the penguin and backtrace, call drm_plane_helper_funcs.atomic_panic().

Quoted 5 lines

- The driver now updates the format and fb address.

- Halt and catch fire

Does that make sense?

Please see my other replies. I find this fragile, and unnecessary for cases where there already is a working scanout buffer in place. It's something a driver could implement internally to provide a scanout buffer if none has been set up already.

Best regards
Thomas

Quoted 1 line

Maxime

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
maintainer
#23 lore raw
Quoted 40 lines · Thomas Zimmermann

Am 09.10.23 um 18:07 schrieb Maxime Ripard:

Quoted 39 lines · Jocelyn Falempe
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

In this case it can work, but by using generic drm api, it's hard to know what the driver will do.

We should document extensively what we expect drivers to do in those hooks, and possibly call cant_sleep() in the framework function to have some reporting at least.

Quoted 24 lines
Quoted 15 lines
Quoted 8 lines

Also how many drivers would need this ?

Currently I was mostly considering x86 platform, so:

simpledrm/ast/mgag200 which works well with the get_scanout_buffer().

i915/amdgpu/nouveau, which are quite complex, and will need to do their own thing anyway.

I guess we're not entirely aligned there then. I would expect that mechanism to work with any atomic KMS driver. You are right that i915, amdgpu and nouveau are special enough that some extra internal plumbing is going to be required, but I'd expect it to be easy to support with any other driver for a memory-mapped device.

Quoted 3 lines

I guess what I'm trying to say is, even though it's totally fine that you only support those drivers at first, supporting in vc4 for example shouldn't require to rewrite the whole thing.

Would that work for you to put that in a drm_panic_helper.c, so that drivers can opt-in ?

So the driver can call a drm_panic_helper_prepare_commit() at initialization, and then in the get_scanout_buffer() function

Quoted 7 lines
Quoted 3 lines

If we have a full blown commit with a new framebuffer, why do we need get_scanout_buffer? It should be either the framebuffer itself, or in the plane state if you have a conversion.

We also have discussions about kexec/kdump support. Here we'd need to retrieve the scanout address, forward it to the kexec kernel and put simpledrm onto that framebuffer until the regular driver takes over.

Generically speaking, there's strictly no guarantee that the current scanout buffer is accessible by the CPU. It's not even a driver issue, it's a workload issue, so it will affect 100% of the times some users, and some 0% of the time.

Quoted 2 lines

An interface like get_scanout_buffer will be helpful for this use case. So it makes sense to use it for the panic handler as well.

It won't be helpful because the vast majority of the ARM drivers (and thus the vast majority of the KMS drivers) won't be able to implement it properly and reliably.

Quoted 26 lines
Quoted 26 lines
Quoted 8 lines

run the atomic_update() on it, and return this commit's framebuffer ?

That way each driver have a better control on what the panic handler will do.
It can even call directly its internal functions, to avoid the locks of the drm generic functions, and make sure it will only change the format and base address.
That's a bit more work for each driver, but should be more reliable I think.

I don't think that better control there is a good idea, it's a path that won't get tested much so we'd be better off not allowing drivers to deviate too much from the "ideal" design.

What I had in mind is something like:

- Add a panic hook in drm_mode_config_funcs, with a

     drm_atomic_helper_panic helper;

- Provide an atomic_panic hook or something in drm_plane_helper_funcs;

- If they are set, we register the drm_panic handler;

- The handler will call drm_mode_config_funcs.panic, which will take its prepared state, fill the framebuffer it allocated with the penguin and backtrace, call drm_plane_helper_funcs.atomic_panic().

Quoted 8 lines
Quoted 5 lines

- The driver now updates the format and fb address.

- Halt and catch fire

Does that make sense?

Please see my other replies. I find this fragile, and unnecessary for cases where there already is a working scanout buffer in place.

And please see my other replies. Depending on a working scanout buffer in place being accessible by the CPU is incredibly limiting. Ignoring it when I'm pointing that out won't get us to a solution acceptable for everyone.

Quoted 2 lines

It's something a driver could implement internally to provide a scanout buffer if none has been set up already.

Some drivers need extra resources when setting up a plane. VC4 for example need for every plane to allocate multiple internal SRAM buffers. Just allocating an extra framebuffer won't cut it.

This is tied to the state so far, so I guess we would need to allocate a new state. Oh, and if we have several drivers that need to allocate that extra framebuffer and state, we could make it part of the core or turn it into a helper?

Maxime

#24 lore raw

Hi

Am 10.10.23 um 11:33 schrieb Maxime Ripard:
[...]

Quoted 8 lines
Quoted 3 lines

We also have discussions about kexec/kdump support. Here we'd need to retrieve the scanout address, forward it to the kexec kernel and put simpledrm onto that framebuffer until the regular driver takes over.

Generically speaking, there's strictly no guarantee that the current scanout buffer is accessible by the CPU. It's not even a driver issue, it's a workload issue, so it will affect 100% of the times some users, and some 0% of the time.

And I'd be OK with that. It's all best effort anyway.

Quoted 7 lines
Quoted 3 lines

An interface like get_scanout_buffer will be helpful for this use case. So it makes sense to use it for the panic handler as well.

It won't be helpful because the vast majority of the ARM drivers (and thus the vast majority of the KMS drivers) won't be able to implement it properly and reliably.

The barrier for firmware-based drivers is low: a pre-configured display and mmap'able framebuffer memory. And it's assumed that a callback for kexec would attempt to configure hardware accordingly. If a system really cannot provide this, so be it.

Quoted 44 lines
Quoted 27 lines
Quoted 27 lines
Quoted 9 lines

run the atomic_update() on it, and return this commit's framebuffer ?

That way each driver have a better control on what the panic handler will do.
It can even call directly its internal functions, to avoid the locks of the drm generic functions, and make sure it will only change the format and base address.
That's a bit more work for each driver, but should be more reliable I think.

I don't think that better control there is a good idea, it's a path that won't get tested much so we'd be better off not allowing drivers to deviate too much from the "ideal" design.

What I had in mind is something like:

- Add a panic hook in drm_mode_config_funcs, with a drm_atomic_helper_panic helper;

- Provide an atomic_panic hook or something in drm_plane_helper_funcs;

- If they are set, we register the drm_panic handler;

- The handler will call drm_mode_config_funcs.panic, which will take its prepared state, fill the framebuffer it allocated with the penguin and backtrace, call drm_plane_helper_funcs.atomic_panic().

Quoted 8 lines
Quoted 5 lines

- The driver now updates the format and fb address.

- Halt and catch fire

Does that make sense?

Please see my other replies. I find this fragile, and unnecessary for cases where there already is a working scanout buffer in place.

And please see my other replies. Depending on a working scanout buffer in place being accessible by the CPU is incredibly limiting. Ignoring it when I'm pointing that out won't get us to a solution acceptable for everyone.

Quoted 2 lines

It's something a driver could implement internally to provide a scanout buffer if none has been set up already.

Quoted 8 lines

Some drivers need extra resources when setting up a plane. VC4 for example need for every plane to allocate multiple internal SRAM buffers. Just allocating an extra framebuffer won't cut it.

This is tied to the state so far, so I guess we would need to allocate a new state. Oh, and if we have several drivers that need to allocate that extra framebuffer and state, we could make it part of the core or turn it into a helper?

I mentioned that even the simple drivers hold locks during the atomic commit. Some of the drivers use vmap/vunmap, which might make problems as well. It's used in the context of damage handling, which also makes no sense here. So the regular atomic helpers most likely won't work.

It sounds to me as if you're essentially asking for something like a flush or sync operation.

Stepping back from get_scanout_buffer for a moment and adopting your proposal from above, I can see something like this working:

- the driver provides a panic callback in struct drm_driver

- DRM registers a panic handler to invokes the callback

- the panic callback has a scanout buffer from somewhere (currently
active, prepared, from firmware, plain memory, etc)

- we provide a helper that fills the scanout buffer with information

- the driver then updates the hardware from/with the scanout buffer;
details depend on the hardware

The final step is like a flush or commit operation. To give some examples: The simple drivers of this patchset probably don't have to do anything. Drivers with command/packet queues could attempt to send the necessary commands to the device.

Best regards
Thomas

Quoted 2 lines

Maxime

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author maintainer
#25 lore raw
Quoted 91 lines · Thomas Zimmermann

Hi

Am 10.10.23 um 11:33 schrieb Maxime Ripard:
[...]

Quoted 8 lines
Quoted 3 lines

We also have discussions about kexec/kdump support. Here we'd need to retrieve the scanout address, forward it to the kexec kernel and put simpledrm onto that framebuffer until the regular driver takes over.

Generically speaking, there's strictly no guarantee that the current scanout buffer is accessible by the CPU. It's not even a driver issue, it's a workload issue, so it will affect 100% of the times some users, and some 0% of the time.

And I'd be OK with that. It's all best effort anyway.

Quoted 7 lines
Quoted 3 lines

An interface like get_scanout_buffer will be helpful for this use case. So it makes sense to use it for the panic handler as well.

It won't be helpful because the vast majority of the ARM drivers (and thus the vast majority of the KMS drivers) won't be able to implement it properly and reliably.

The barrier for firmware-based drivers is low: a pre-configured display and mmap'able framebuffer memory. And it's assumed that a callback for kexec would attempt to configure hardware accordingly. If a system really cannot provide this, so be it.

Quoted 44 lines
Quoted 27 lines
Quoted 27 lines
Quoted 9 lines

run the atomic_update() on it, and return this commit's framebuffer ?

That way each driver have a better control on what the panic handler will do.
It can even call directly its internal functions, to avoid the locks of the drm generic functions, and make sure it will only change the format and base address.
That's a bit more work for each driver, but should be more reliable I think.

I don't think that better control there is a good idea, it's a path that won't get tested much so we'd be better off not allowing drivers to deviate too much from the "ideal" design.

What I had in mind is something like:

    - Add a panic hook in drm_mode_config_funcs, with a drm_atomic_helper_panic helper;

    - Provide an atomic_panic hook or something in drm_plane_helper_funcs;

    - If they are set, we register the drm_panic handler;

    - The handler will call drm_mode_config_funcs.panic, which will take its prepared state, fill the framebuffer it allocated with the penguin and backtrace, call drm_plane_helper_funcs.atomic_panic().

Quoted 8 lines
Quoted 5 lines

    - The driver now updates the format and fb address.

    - Halt and catch fire

Does that make sense?

Please see my other replies. I find this fragile, and unnecessary for cases where there already is a working scanout buffer in place.

And please see my other replies. Depending on a working scanout buffer in place being accessible by the CPU is incredibly limiting. Ignoring it when I'm pointing that out won't get us to a solution acceptable for everyone.

Quoted 2 lines

It's something a driver could implement internally to provide a scanout buffer if none has been set up already.

Quoted 8 lines

Some drivers need extra resources when setting up a plane. VC4 for example need for every plane to allocate multiple internal SRAM buffers. Just allocating an extra framebuffer won't cut it.

This is tied to the state so far, so I guess we would need to allocate a new state. Oh, and if we have several drivers that need to allocate that extra framebuffer and state, we could make it part of the core or turn it into a helper?

I mentioned that even the simple drivers hold locks during the atomic commit. Some of the drivers use vmap/vunmap, which might make problems as well. It's used in the context of damage handling, which also makes no sense here. So the regular atomic helpers most likely won't work.

It sounds to me as if you're essentially asking for something like a flush or sync operation.

Stepping back from get_scanout_buffer for a moment and adopting your proposal from above, I can see something like this working:

  - the driver provides a panic callback in struct drm_driver

  - DRM registers a panic handler to invokes the callback

  - the panic callback has a scanout buffer from somewhere (currently
active, prepared, from firmware, plain memory, etc)

Quoted 6 lines

  - we provide a helper that fills the scanout buffer with information

  - the driver then updates the hardware from/with the scanout buffer;
details depend on the hardware

The final step is like a flush or commit operation. To give some examples: The simple drivers of this patchset probably don't have to do anything. Drivers with command/packet queues could attempt to send the necessary commands to the device.

Yes that was the second question in the cover letter.
Some drivers probably want a flush_scanout_buffer() to send the framebuffer to the hardware. That callback can be in struct drm_driver as well.

Signature · 1 line
Jocelyn
Quoted 7 lines

Best regards
Thomas

Quoted 2 lines

Maxime

#26 lore raw
In reply to Maxime Ripard

Hi

Am 09.10.23 um 13:33 schrieb Maxime Ripard:
[...]

Quoted 1 line
Quoted 1 line
Quoted 1 line

And you don't need to support all kinds of tiling, YUV or RGB variants.

We should indeed not use YUV at all. For RGB, we already have plenty of conversion code from XRGB8888-to-<whatever>, so we are more flexible there.

Quoted 10 lines
Quoted 3 lines

So if I understand correctly, drm_panic would pre-allocate a plane/commit, and use that when a panic occurs ?

And have it checked already, yes. We would only wait for a panic to happen to pull the trigger on the commit.

Quoted 3 lines

I have two concern about this approach:
- How much memory would be allocated for this ? a whole framebuffer can be big for just this use case.

As I outlined in my email at [1], there are a number of different scenarios. The question of atomic state and commits is entirely separate from the DRM panic handler. We should not throw them together. Whatever is necessary is get a scanout buffer, should happen on the driver side of get_scanout_buffer, not on the drm_panic side.

[1] https://lore.kernel.org/dri-devel/[email protected]/T/#m22f116e9438e00a5f0a9dc43987d4153424f8be1

Quoted 11 lines

I'dd expect a whole framebuffer for the current configuration/resolution. It would be typically 4MB for a full-HD system which isn't a lot really and I guess we can always add an option to disable the mechanism if needed.

Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

The one thing I don't understand is: Why should we use atomic commits in the first place? It doesn't make sense for firmware-based drivers. In some drivers, even the simple ast, we hold locks during the regular commit. Trying to run the panic commit concurrently will likely give a deadlock.

In the end it's a per-driver decision, but in most cases, the driver can easily switch to a default mode with some ad-hoc code.

Best regards
Thomas

Quoted 46 lines
Quoted 9 lines

Also how many drivers would need this ?

Currently I was mostly considering x86 platform, so:

simpledrm/ast/mgag200 which works well with the get_scanout_buffer().

i915/amdgpu/nouveau, which are quite complex, and will need to do their own thing anyway.

I guess we're not entirely aligned there then. I would expect that mechanism to work with any atomic KMS driver. You are right that i915, amdgpu and nouveau are special enough that some extra internal plumbing is going to be required, but I'd expect it to be easy to support with any other driver for a memory-mapped device.

I guess what I'm trying to say is, even though it's totally fine that you only support those drivers at first, supporting in vc4 for example shouldn't require to rewrite the whole thing.

Quoted 14 lines
Quoted 9 lines
Quoted 6 lines

I'm more in favor of an emergency function, that each driver has to implement, and use what the hardware can do to display a simple frame quickly. get_scanout_buffer() is a good start for simple driver, but will need refactoring for the more complex case, like adding a callback to write pixels one by one, if there is no memory mapped buffer available.

Sorry, I'm not quite sure what you mean there, where would you write the pixel to?

It was mentioned by Noralf, about the amdgpu driver:

https://lore.kernel.org/dri-devel/[email protected]/

Quoted 7 lines

They have a slow "debug interface" that you can write to, and can be used for the panic handler. It's not memory mapped, so you have to write pixels one by one.

So for the struct drm_scanout_buffer, I can add a function pointer to a write_pixel(u32 x, u32 y, u32 color)
So if the iosys map is null, it will use that instead.

It would be nice to support indeed, but it's a fairly rare feature afaik so I'd rather focus on getting something that can work for everyone first

Maxime

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
maintainer
#27 lore raw
Quoted 24 lines · Thomas Zimmermann
Quoted 9 lines
Quoted 2 lines

So if I understand correctly, drm_panic would pre-allocate a plane/commit, and use that when a panic occurs ?

And have it checked already, yes. We would only wait for a panic to happen to pull the trigger on the commit.

Quoted 3 lines

I have two concern about this approach:
- How much memory would be allocated for this ? a whole framebuffer can be big for just this use case.

As I outlined in my email at [1], there are a number of different scenarios. The question of atomic state and commits is entirely separate from the DRM panic handler. We should not throw them together. Whatever is necessary is get a scanout buffer, should happen on the driver side of get_scanout_buffer, not on the drm_panic side.

[1] https://lore.kernel.org/dri-devel/[email protected]/T/#m22f116e9438e00a5f0a9dc43987d4153424f8be1

Quoted 6 lines

I'dd expect a whole framebuffer for the current configuration/resolution. It would be typically 4MB for a full-HD system which isn't a lot really and I guess we can always add an option to disable the mechanism if needed.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

The one thing I don't understand is: Why should we use atomic commits in the first place? It doesn't make sense for firmware-based drivers.

Because this is generic infrastructure that is valuable for any drivers and not only firmware-based drivers?

Quoted 3 lines

In some drivers, even the simple ast, we hold locks during the regular commit. Trying to run the panic commit concurrently will likely give a deadlock.

You're in the middle of a panic. Don't take any locks and you won't deadlock.

Quoted 2 lines

In the end it's a per-driver decision, but in most cases, the driver can easily switch to a default mode with some ad-hoc code.

When was the last time a per-driver decision has been a good thing? I'm sorry, but the get_scanout_buffer approach buffer won't work for any driver out there.

I'm fine with discussing alternatives if you don't like the ones I suggested, but they must allow the panic handler infrastructure to work with any driver we have, not just 4.

Maxime

#28 lore raw
Quoted 48 lines · Maxime Ripard
Quoted 24 lines · Thomas Zimmermann
Quoted 9 lines
Quoted 2 lines

So if I understand correctly, drm_panic would pre-allocate a plane/commit, and use that when a panic occurs ?

And have it checked already, yes. We would only wait for a panic to happen to pull the trigger on the commit.

Quoted 3 lines

I have two concern about this approach:
- How much memory would be allocated for this ? a whole framebuffer can be big for just this use case.

As I outlined in my email at [1], there are a number of different scenarios. The question of atomic state and commits is entirely separate from the DRM panic handler. We should not throw them together. Whatever is necessary is get a scanout buffer, should happen on the driver side of get_scanout_buffer, not on the drm_panic side.

[1] https://lore.kernel.org/dri-devel/[email protected]/T/#m22f116e9438e00a5f0a9dc43987d4153424f8be1

Quoted 6 lines

I'dd expect a whole framebuffer for the current configuration/resolution. It would be typically 4MB for a full-HD system which isn't a lot really and I guess we can always add an option to disable the mechanism if needed.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

The one thing I don't understand is: Why should we use atomic commits in the first place? It doesn't make sense for firmware-based drivers.

Because this is generic infrastructure that is valuable for any drivers and not only firmware-based drivers?

Quoted 3 lines

In some drivers, even the simple ast, we hold locks during the regular commit. Trying to run the panic commit concurrently will likely give a deadlock.

You're in the middle of a panic. Don't take any locks and you won't deadlock.

Quoted 2 lines

In the end it's a per-driver decision, but in most cases, the driver can easily switch to a default mode with some ad-hoc code.

Quoted 8 lines

When was the last time a per-driver decision has been a good thing? I'm sorry, but the get_scanout_buffer approach buffer won't work for any driver out there.

I'm fine with discussing alternatives if you don't like the ones I suggested, but they must allow the panic handler infrastructure to work with any driver we have, not just 4.

Why can't we use the model[1] suggested by Daniel using a draw_pixel callback giving drivers full control on how they can put a pixel on the display?

This will even work for the AMD debug interface.
In the linear CPU accessible buffer case, we can provide a helper for that, maybe we can do helpers for other common cases as well.

Adding to that we would need a panic_setup/enter and panic_teardown/exit callback.

Noralf.

[1]
https://lore.kernel.org/dri-devel/[email protected]/

maintainer
#29 lore raw
Quoted 55 lines · Noralf Trønnes
Quoted 52 lines · Maxime Ripard
Quoted 24 lines · Thomas Zimmermann
Quoted 9 lines
Quoted 2 lines

So if I understand correctly, drm_panic would pre-allocate a plane/commit, and use that when a panic occurs ?

And have it checked already, yes. We would only wait for a panic to happen to pull the trigger on the commit.

Quoted 3 lines

I have two concern about this approach:
- How much memory would be allocated for this ? a whole framebuffer can be big for just this use case.

As I outlined in my email at [1], there are a number of different scenarios. The question of atomic state and commits is entirely separate from the DRM panic handler. We should not throw them together. Whatever is necessary is get a scanout buffer, should happen on the driver side of get_scanout_buffer, not on the drm_panic side.

[1] https://lore.kernel.org/dri-devel/[email protected]/T/#m22f116e9438e00a5f0a9dc43987d4153424f8be1

Quoted 6 lines

I'dd expect a whole framebuffer for the current configuration/resolution. It would be typically 4MB for a full-HD system which isn't a lot really and I guess we can always add an option to disable the mechanism if needed.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

The one thing I don't understand is: Why should we use atomic commits in the first place? It doesn't make sense for firmware-based drivers.

Because this is generic infrastructure that is valuable for any drivers and not only firmware-based drivers?

Quoted 3 lines

In some drivers, even the simple ast, we hold locks during the regular commit. Trying to run the panic commit concurrently will likely give a deadlock.

You're in the middle of a panic. Don't take any locks and you won't deadlock.

Quoted 2 lines

In the end it's a per-driver decision, but in most cases, the driver can easily switch to a default mode with some ad-hoc code.

When was the last time a per-driver decision has been a good thing? I'm sorry, but the get_scanout_buffer approach buffer won't work for any driver out there.

Quoted 8 lines
Quoted 4 lines

I'm fine with discussing alternatives if you don't like the ones I suggested, but they must allow the panic handler infrastructure to work with any driver we have, not just 4.

Why can't we use the model[1] suggested by Daniel using a draw_pixel callback giving drivers full control on how they can put a pixel on the display?

I share kind of the same general ideas/conclusions: "qthe idea is that all the fb selection and lookup is handled in shared code (and with proper locking, but only for atomic drivers)."

2016 is a bit old though and multiple developments happened since (secure playback is a thing now, framebuffer compression too), so I still think that their expectation that the framebuffer is accessible to / writable by the CPU no longer holds true.

Quoted 3 lines

This will even work for the AMD debug interface.
In the linear CPU accessible buffer case, we can provide a helper for that, maybe we can do helpers for other common cases as well.

Yeah, their idea of a panic_draw would work great for that.

Quoted 2 lines

Adding to that we would need a panic_setup/enter and panic_teardown/exit callback.

What for?

Maxime

#30 lore raw
Quoted 65 lines · Maxime Ripard
Quoted 55 lines · Noralf Trønnes
Quoted 52 lines · Maxime Ripard
Quoted 24 lines · Thomas Zimmermann
Quoted 9 lines
Quoted 2 lines

So if I understand correctly, drm_panic would pre-allocate a plane/commit, and use that when a panic occurs ?

And have it checked already, yes. We would only wait for a panic to happen to pull the trigger on the commit.

Quoted 3 lines

I have two concern about this approach:
- How much memory would be allocated for this ? a whole framebuffer can be big for just this use case.

As I outlined in my email at [1], there are a number of different scenarios. The question of atomic state and commits is entirely separate from the DRM panic handler. We should not throw them together. Whatever is necessary is get a scanout buffer, should happen on the driver side of get_scanout_buffer, not on the drm_panic side.

[1] https://lore.kernel.org/dri-devel/[email protected]/T/#m22f116e9438e00a5f0a9dc43987d4153424f8be1

Quoted 6 lines

I'dd expect a whole framebuffer for the current configuration/resolution. It would be typically 4MB for a full-HD system which isn't a lot really and I guess we can always add an option to disable the mechanism if needed.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

The one thing I don't understand is: Why should we use atomic commits in the first place? It doesn't make sense for firmware-based drivers.

Because this is generic infrastructure that is valuable for any drivers and not only firmware-based drivers?

Quoted 3 lines

In some drivers, even the simple ast, we hold locks during the regular commit. Trying to run the panic commit concurrently will likely give a deadlock.

You're in the middle of a panic. Don't take any locks and you won't deadlock.

Quoted 2 lines

In the end it's a per-driver decision, but in most cases, the driver can easily switch to a default mode with some ad-hoc code.

When was the last time a per-driver decision has been a good thing? I'm sorry, but the get_scanout_buffer approach buffer won't work for any driver out there.

Quoted 8 lines
Quoted 4 lines

I'm fine with discussing alternatives if you don't like the ones I suggested, but they must allow the panic handler infrastructure to work with any driver we have, not just 4.

Why can't we use the model[1] suggested by Daniel using a draw_pixel callback giving drivers full control on how they can put a pixel on the display?

Quoted 8 lines

I share kind of the same general ideas/conclusions: "qthe idea is that all the fb selection and lookup is handled in shared code (and with proper locking, but only for atomic drivers)."

2016 is a bit old though and multiple developments happened since (secure playback is a thing now, framebuffer compression too), so I still think that their expectation that the framebuffer is accessible to / writable by the CPU no longer holds true.

I think largely it should still be ok, because the idea behind the draw_xy callback was that the driver could take care of anything special, like
- tiling
- clearing compression bits so that just writing the raw pixels works (if your compression format allows for that)
- handling any differences in how the pixels need to be written, like cache flushing, mmio_write vs normal memory, amd also has peek/poke registers to be able to write even into unmappable memory

What would probably be a good idea is to do an s/void */uinptr_t/ over my interface proposal, or maybe an even more opaque cookie since really the only thing you can do is get the void * that ->panic_vmap returns and pass it into ->panic_draw_xy.

I thought (but I didn't dig through details) that the panic fb struct is essentially meant to serve this purpose in the current series?

Quoted 10 lines
Quoted 3 lines

This will even work for the AMD debug interface.
In the linear CPU accessible buffer case, we can provide a helper for that, maybe we can do helpers for other common cases as well.

Yeah, their idea of a panic_draw would work great for that.

Quoted 2 lines

Adding to that we would need a panic_setup/enter and panic_teardown/exit callback.

What for?

So panic teardown would be for testing in CI, to make it non-destructive and clean up anything panic_vmap (or _enter or whatever you call it) has done. I thought John Oggness was also looking into how the new panic handlers/consoles could be made testable in the panic paths, including lock stealing and getting called from nmi.
-Sima

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#31 lore raw

Hi

Am 10.10.23 um 14:59 schrieb Daniel Vetter:
[...]

Quoted 24 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

Why can't we use the model[1] suggested by Daniel using a draw_pixel callback giving drivers full control on how they can put a pixel on the display?

Quoted 8 lines

I share kind of the same general ideas/conclusions: "qthe idea is that all the fb selection and lookup is handled in shared code (and with proper locking, but only for atomic drivers)."

2016 is a bit old though and multiple developments happened since (secure playback is a thing now, framebuffer compression too), so I still think that their expectation that the framebuffer is accessible to / writable by the CPU no longer holds true.

I think largely it should still be ok, because the idea behind the draw_xy callback was that the driver could take care of anything special, like
- tiling
- clearing compression bits so that just writing the raw pixels works (if your compression format allows for that)
- handling any differences in how the pixels need to be written, like cache flushing, mmio_write vs normal memory, amd also has peek/poke registers to be able to write even into unmappable memory

Quoted 7 lines

What would probably be a good idea is to do an s/void */uinptr_t/ over my interface proposal, or maybe an even more opaque cookie since really the only thing you can do is get the void * that ->panic_vmap returns and pass it into ->panic_draw_xy.

I thought (but I didn't dig through details) that the panic fb struct is essentially meant to serve this purpose in the current series?

I have one detail about the code: While working on the format-conversion code, I've always found struct drm_framebuffer to be clunky to work with. It's build around the idea of managing GEM buffers, but not accessing them.

So I've been thinking about something like a drm_pixmap that contains size, color format and data pointers in one place. Reads and writes would be callbacks. It could abstract access to any kind of buffer. IIRC Jocelyn had something like that in the very first patchset. or maybe fb_pixmap could be repurposed.

Best regards
Thomas

Quoted 18 lines
Quoted 11 lines
Quoted 4 lines

This will even work for the AMD debug interface.
In the linear CPU accessible buffer case, we can provide a helper for that, maybe we can do helpers for other common cases as well.

Yeah, their idea of a panic_draw would work great for that.

Quoted 2 lines

Adding to that we would need a panic_setup/enter and panic_teardown/exit callback.

What for?

So panic teardown would be for testing in CI, to make it non-destructive and clean up anything panic_vmap (or _enter or whatever you call it) has done. I thought John Oggness was also looking into how the new panic handlers/consoles could be made testable in the panic paths, including lock stealing and getting called from nmi.
-Sima

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author maintainer
#32 lore raw
In reply to Daniel Vetter
Quoted 84 lines · Daniel Vetter
Quoted 65 lines · Maxime Ripard
Quoted 55 lines · Noralf Trønnes
Quoted 52 lines · Maxime Ripard
Quoted 24 lines · Thomas Zimmermann
Quoted 9 lines
Quoted 2 lines

So if I understand correctly, drm_panic would pre-allocate a plane/commit, and use that when a panic occurs ?

And have it checked already, yes. We would only wait for a panic to happen to pull the trigger on the commit.

Quoted 3 lines

I have two concern about this approach:
- How much memory would be allocated for this ? a whole framebuffer can be big for just this use case.

As I outlined in my email at [1], there are a number of different scenarios. The question of atomic state and commits is entirely separate from the DRM panic handler. We should not throw them together. Whatever is necessary is get a scanout buffer, should happen on the driver side of get_scanout_buffer, not on the drm_panic side.

[1] https://lore.kernel.org/dri-devel/[email protected]/T/#m22f116e9438e00a5f0a9dc43987d4153424f8be1

Quoted 6 lines

I'dd expect a whole framebuffer for the current configuration/resolution. It would be typically 4MB for a full-HD system which isn't a lot really and I guess we can always add an option to disable the mechanism if needed.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

- I find it risky to completely reconfigure the hardware in a panic handler.

I would expect to only change the format and base address of the framebuffer. I guess it can fail, but it doesn't seem that different to the async plane update we already have and works well.

The one thing I don't understand is: Why should we use atomic commits in the first place? It doesn't make sense for firmware-based drivers.

Because this is generic infrastructure that is valuable for any drivers and not only firmware-based drivers?

Quoted 3 lines

In some drivers, even the simple ast, we hold locks during the regular commit. Trying to run the panic commit concurrently will likely give a deadlock.

You're in the middle of a panic. Don't take any locks and you won't deadlock.

Quoted 2 lines

In the end it's a per-driver decision, but in most cases, the driver can easily switch to a default mode with some ad-hoc code.

When was the last time a per-driver decision has been a good thing? I'm sorry, but the get_scanout_buffer approach buffer won't work for any driver out there.

Quoted 8 lines
Quoted 4 lines

I'm fine with discussing alternatives if you don't like the ones I suggested, but they must allow the panic handler infrastructure to work with any driver we have, not just 4.

Why can't we use the model[1] suggested by Daniel using a draw_pixel callback giving drivers full control on how they can put a pixel on the display?

Quoted 8 lines

I share kind of the same general ideas/conclusions: "qthe idea is that all the fb selection and lookup is handled in shared code (and with proper locking, but only for atomic drivers)."

2016 is a bit old though and multiple developments happened since (secure playback is a thing now, framebuffer compression too), so I still think that their expectation that the framebuffer is accessible to / writable by the CPU no longer holds true.

I think largely it should still be ok, because the idea behind the draw_xy callback was that the driver could take care of anything special, like
- tiling
- clearing compression bits so that just writing the raw pixels works (if your compression format allows for that)
- handling any differences in how the pixels need to be written, like cache flushing, mmio_write vs normal memory, amd also has peek/poke registers to be able to write even into unmappable memory

Quoted 8 lines

What would probably be a good idea is to do an s/void */uinptr_t/ over my interface proposal, or maybe an even more opaque cookie since really the only thing you can do is get the void * that ->panic_vmap returns and pass it into ->panic_draw_xy.

I thought (but I didn't dig through details) that the panic fb struct is essentially meant to serve this purpose in the current series?

Yes, in this series there is a struct drm_scanout_buffer, that the driver has to provide when a panic occurs:

struct drm_scanout_buffer {
	const struct drm_format_info *format;
	struct iosys_map map;
	unsigned int pitch;
	unsigned int width;
	unsigned int height;
};

That works well for CPU accessible, linear format.
It should be possible to support YUV, or simple tiling with that, but for the more complex case, I proposed to add a draw_pixel() callback.

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

This will even work for the AMD debug interface.
In the linear CPU accessible buffer case, we can provide a helper for that, maybe we can do helpers for other common cases as well.

Yeah, their idea of a panic_draw would work great for that.

Quoted 2 lines

Adding to that we would need a panic_setup/enter and panic_teardown/exit callback.

Quoted 7 lines
Quoted 1 line

What for?

So panic teardown would be for testing in CI, to make it non-destructive and clean up anything panic_vmap (or _enter or whatever you call it) has done. I thought John Oggness was also looking into how the new panic handlers/consoles could be made testable in the panic paths, including lock stealing and getting called from nmi.

Thanks, I was also wondering why a panic teardown would be necessary, since after the panic handler has run, the system will probably halt. (or maybe run kdump and reboot).

Quoted 1 line

-Sima

#33 lore raw
In reply to Jocelyn Falempe
Quoted 39 lines · Jocelyn Falempe

This 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)

---
 drivers/gpu/drm/Kconfig     |  22 ++
 drivers/gpu/drm/Makefile    |   1 +
 drivers/gpu/drm/drm_drv.c   |   8 +
 drivers/gpu/drm/drm_panic.c | 413 ++++++++++++++++++++++++++++++++++++
 include/drm/drm_drv.h       |  14 ++
 include/drm/drm_panic.h     |  41 ++++
 6 files changed, 499 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_panic.c
 create mode 100644 include/drm/drm_panic.h
drivers/gpu/drm/drm_panic.c new file +0 -0
new file mode 100644

drivers/gpu/drm/drm_panic.c line 320

Quoted 10 lines
drivers/gpu/drm/drm_panic.c new file +9 -0
 
+static void draw_panic_device(struct drm_device *dev, const char *msg)
+{
+	struct drm_scanout_buffer sb;
+
+	if (dev->driver->get_scanout_buffer(dev, &sb))
+		return;
+	if (!drm_panic_line_buf)
+		return;
+

Unless something has changed since 2019 we need to make sure fbcon hasn't already printed the panic to avoid jumbled output. See [1] for more info.

Noralf.

[1]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 6 lines
drivers/gpu/drm/drm_panic.c new file +6 -0
+	/* to avoid buffer overflow on drm_panic_line_buf */
+	if (sb.width > DRM_PANIC_MAX_WIDTH)
+		sb.width = DRM_PANIC_MAX_WIDTH;
+
+	draw_panic_static(&sb, msg);
+}
author maintainer
#34 lore raw
Quoted 43 lines · Noralf Trønnes
Quoted 39 lines · Jocelyn Falempe

This 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)

---
  drivers/gpu/drm/Kconfig     |  22 ++
  drivers/gpu/drm/Makefile    |   1 +
  drivers/gpu/drm/drm_drv.c   |   8 +
  drivers/gpu/drm/drm_panic.c | 413 ++++++++++++++++++++++++++++++++++++
  include/drm/drm_drv.h       |  14 ++
  include/drm/drm_panic.h     |  41 ++++
  6 files changed, 499 insertions(+)

create mode 100644 drivers/gpu/drm/drm_panic.c
create mode 100644 include/drm/drm_panic.h

drivers/gpu/drm/drm_panic.c new file +0 -0
new file mode 100644
Quoted 13 lines

drivers/gpu/drm/drm_panic.c line 320

Quoted 9 lines
drivers/gpu/drm/drm_panic.c new file +9 -0
+static void draw_panic_device(struct drm_device *dev, const char *msg)
+{
+	struct drm_scanout_buffer sb;
+
+	if (dev->driver->get_scanout_buffer(dev, &sb))
+		return;
+	if (!drm_panic_line_buf)
+		return;
+

Unless something has changed since 2019 we need to make sure fbcon hasn't already printed the panic to avoid jumbled output. See [1] for more info.

I think DRM_PANIC and fbcon are incompatible, so in Kconfig I prevent them to be built together:

config DRM_PANIC
bool "Display a user-friendly message when a kernel panic occurs" depends on DRM && !FRAMEBUFFER_CONSOLE

So DRM_PANIC should be used with a userspace console, either kmscon, or some lightweight terminal emulator/wayland compositor, like cage/foot.

As fbcon has lost scrolling support, it's time to switch to something better. [1]

Signature · 4 lines
Jocelyn

[1]
https://www.reddit.com/r/linux/comments/10eccv9/config_vtn_in_2023/
Quoted 13 lines

Noralf.

[1]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 6 lines
drivers/gpu/drm/drm_panic.c new file +6 -0
+	/* to avoid buffer overflow on drm_panic_line_buf */
+	if (sb.width > DRM_PANIC_MAX_WIDTH)
+		sb.width = DRM_PANIC_MAX_WIDTH;
+
+	draw_panic_static(&sb, msg);
+}
author maintainer
#35 lore raw

PATCH v4 3/4 drm/simpledrm: Add drm_panic support

In reply to Jocelyn Falempe

Add 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
index 25e11ef11c4c..ee62303ef68a 100644
@@ -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
author maintainer
#36 lore raw

PATCH v4 4/4 drm/mgag200: Add drm_panic support

In reply to Jocelyn Falempe

Add support for the drm_panic module, which displays a message to the screen when a kernel panic occurs.

---
 drivers/gpu/drm/mgag200/mgag200_drv.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/gpu/drm/mgag200/mgag200_drv.c +24 -0
index 976f0ab2006b..229d9c116b42 100644
@@ -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,27 @@ 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);
+
+	/* mgag200 has only one plane */
+	drm_for_each_plane(plane, dev) {
+		if (!plane->state || !plane->state->fb)
+			return -ENODEV;
+		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 +121,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
#37 lore raw

Re: [PATCH v4 4/4] drm/mgag200: Add drm_panic support

Quoted 28 lines · Jocelyn Falempe

Add support for the drm_panic module, which displays a message to the screen when a kernel panic occurs.

---
 drivers/gpu/drm/mgag200/mgag200_drv.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/gpu/drm/mgag200/mgag200_drv.c +2 -0
index 976f0ab2006b..229d9c116b42 100644
@@ -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,27 @@ resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size)
 	return offset - 65536;
 }

drivers/gpu/drm/mgag200/mgag200_drv.c resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size) · line 96

Quoted 10 lines
drivers/gpu/drm/mgag200/mgag200_drv.c +9 -0
 
+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);
+
+	/* mgag200 has only one plane */
+	drm_for_each_plane(plane, dev) {

In my first 2016 attempt on a panic handler I was told to trylock crtc and plane and skip if it wasn't possible:

- We need locking. One of the biggest problems with the old oops handling was that it was very good at trampling over driver state, causing more (unrelated) oopses in kms code and making sure the original oops was no longer visible. I think the shared code must take care of all the locking needs to avoid fragile code in drivers. ww_mutex_trylock on the drm_crtc and drm_plane should be enough (we need both for drivers where planes can be reassigned between drivers).

See [1] for a list of other things to consider.

Noralf.

[1]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 23 lines
drivers/gpu/drm/mgag200/mgag200_drv.c +13 -0
+		if (!plane->state || !plane->state->fb)
+			return -ENODEV;
+		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 +121,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,
 };
 
author maintainer
#38 lore raw

Re: [PATCH v4 4/4] drm/mgag200: Add drm_panic support

Quoted 45 lines · Noralf Trønnes
Quoted 28 lines · Jocelyn Falempe

Add support for the drm_panic module, which displays a message to the screen when a kernel panic occurs.

---
  drivers/gpu/drm/mgag200/mgag200_drv.c | 24 ++++++++++++++++++++++++
  1 file changed, 24 insertions(+)
drivers/gpu/drm/mgag200/mgag200_drv.c +2 -0
index 976f0ab2006b..229d9c116b42 100644
@@ -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,27 @@ resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size)
  	return offset - 65536;
  }

drivers/gpu/drm/mgag200/mgag200_drv.c resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size) · line 96

Quoted 10 lines
drivers/gpu/drm/mgag200/mgag200_drv.c +9 -0
 
+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);
+
+	/* mgag200 has only one plane */
+	drm_for_each_plane(plane, dev) {

In my first 2016 attempt on a panic handler I was told to trylock crtc and plane and skip if it wasn't possible:

Quoted 7 lines

- We need locking. One of the biggest problems with the old oops handling was that it was very good at trampling over driver state, causing more (unrelated) oopses in kms code and making sure the original oops was no longer visible. I think the shared code must take care of all the locking needs to avoid fragile code in drivers. ww_mutex_trylock on the drm_crtc and drm_plane should be enough (we need both for drivers where planes can be reassigned between drivers).

drm_panic register a panic handler, so it won't get called on oopses.
So when the panic handler is called, no other task can run in parallel, and no drm code will run after it.

Also for the Matrox driver, it's always safe to write to the VRAM. The only risk is that if you're in the middle of a modeset, you may get garbage output. There might still be a race condition for fb->format, width, height and pitches, and looping through the plane list.

I also need to check if crtc and plane locks are not taken when the driver is copying the damage region to the VRAM, otherwise the probability to actually see the panic will be very low.

I also need to wake up the monitor, if it's currently in DPMS off.

Signature · 1 line
Jocelyn
Quoted 32 lines

See [1] for a list of other things to consider.

Noralf.

[1]
https://lore.kernel.org/dri-devel/[email protected]/

Quoted 23 lines
drivers/gpu/drm/mgag200/mgag200_drv.c +13 -0
+		if (!plane->state || !plane->state->fb)
+			return -ENODEV;
+		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 +121,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,
  };
 
#39 lore raw

Re: [PATCH v4 4/4] drm/mgag200: Add drm_panic support

In reply to Jocelyn Falempe

Hi

Am 03.10.23 um 16:22 schrieb Jocelyn Falempe:

Quoted 29 lines

Add support for the drm_panic module, which displays a message to the screen when a kernel panic occurs.

---
  drivers/gpu/drm/mgag200/mgag200_drv.c | 24 ++++++++++++++++++++++++
  1 file changed, 24 insertions(+)
drivers/gpu/drm/mgag200/mgag200_drv.c +2 -0
index 976f0ab2006b..229d9c116b42 100644
@@ -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,27 @@ resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size)
  	return offset - 65536;
  }
 

drivers/gpu/drm/mgag200/mgag200_drv.c resource_size_t mgag200_probe_vram(void __iomem *mem, resource_size_t size) · line 97

Quoted 10 lines
drivers/gpu/drm/mgag200/mgag200_drv.c +10 -0
+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);
+
+	/* mgag200 has only one plane */
+	drm_for_each_plane(plane, dev) {
+		if (!plane->state || !plane->state->fb)

Better test for plane->state->visible. You should also check if it's a primary plane.

Best regards
Thomas

Quoted 22 lines
drivers/gpu/drm/mgag200/mgag200_drv.c +12 -0
+			return -ENODEV;
+		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 +121,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 · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)