drm/ssd130x: Add drm_panic support
Subsystems (3)
Javier Martinez Canillas
maintainerPATCH 1/1 drm/ssd130x: Add drm_panic support
Add support for the drm_panic infrastructure, which allows to display a user friendly message on the screen when a Linux kernel panic occurs.
The display controller doesn't scanout the framebuffer, but instead the pixels are sent to the device using a transport bus. For this reason, a .panic_flush handler is needed to flush the panic image to the display.
---
drivers/gpu/drm/solomon/ssd130x.c | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
drivers/gpu/drm/solomon/ssd130x.c +64 -0
@@ -32,6 +32,7 @@#include <drm/drm_managed.h> #include <drm/drm_modes.h> #include <drm/drm_rect.h> +#include <drm/drm_panic.h> #include <drm/drm_probe_helper.h> #include "ssd130x.h"
@@ -1386,6 +1387,63 @@ static void ssd133x_primary_plane_atomic_disable(struct drm_plane *plane,drm_dev_exit (idx); } +static int ssd130x_primary_plane_helper_get_scanout_buffer (struct drm_plane *plane, +struct drm_scanout_buffer *sb) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_shadow_plane_state *shadow_plane_state; + +if (!plane_state || !plane_state->fb || !plane_state->crtc) +return -EINVAL ; + + shadow_plane_state =to_drm_shadow_plane_state (plane_state); + + sb->format = plane->state->fb->format; + sb->width = plane->state->fb->width; + sb->height = plane->state->fb->height; + sb->pitch[0 ] = plane->state->fb->pitches[0 ]; + sb->map[0 ] = shadow_plane_state->data[0 ]; + +return 0 ; +} + +static void ssd130x_primary_plane_helper_panic_flush (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct ssd130x_plane_state *ssd130x_plane_state =to_ssd130x_plane_state (plane_state); +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state); + +ssd130x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_plane_state->buffer, ssd130x_crtc_state->data_array, + &shadow_plane_state->fmtcnv_state); +} + +static void ssd132x_primary_plane_helper_panic_flush (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct ssd130x_plane_state *ssd130x_plane_state =to_ssd130x_plane_state (plane_state); +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state); + +ssd132x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_plane_state->buffer, ssd130x_crtc_state->data_array, + &shadow_plane_state->fmtcnv_state); +} + +static void ssd133x_primary_plane_helper_panic_flush (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state); + +ssd133x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_crtc_state->data_array, &shadow_plane_state->fmtcnv_state); +} +/* Called during init to allocate the plane's atomic state. */ static void ssd130x_primary_plane_reset (struct drm_plane *plane) {
@@ -1442,18 +1500,24 @@ static const struct drm_plane_helper_funcs ssd130x_primary_plane_helper_funcs[] .atomic_check = ssd130x_primary_plane_atomic_check, .atomic_update = ssd130x_primary_plane_atomic_update, .atomic_disable = ssd130x_primary_plane_atomic_disable, + .get_scanout_buffer = ssd130x_primary_plane_helper_get_scanout_buffer, + .panic_flush = ssd130x_primary_plane_helper_panic_flush, }, [SSD132X_FAMILY] = { DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, .atomic_check = ssd132x_primary_plane_atomic_check, .atomic_update = ssd132x_primary_plane_atomic_update, .atomic_disable = ssd132x_primary_plane_atomic_disable, + .get_scanout_buffer = ssd130x_primary_plane_helper_get_scanout_buffer, + .panic_flush = ssd132x_primary_plane_helper_panic_flush, }, [SSD133X_FAMILY] = { DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, .atomic_check = ssd133x_primary_plane_atomic_check, .atomic_update = ssd133x_primary_plane_atomic_update, .atomic_disable = ssd133x_primary_plane_atomic_disable, + .get_scanout_buffer = ssd130x_primary_plane_helper_get_scanout_buffer, + .panic_flush = ssd133x_primary_plane_helper_panic_flush, } };
Signature · 1 line
2.45.1
Quoted 6 lines · Javier Martinez Canillas
Add support for the
drm_panicinfrastructure, which allows to display a user friendly message on the screen when a Linux kernel panic occurs.The display controller doesn't scanout the framebuffer, but instead the pixels are sent to the device using a transport bus. For this reason, a .panic_flush handler is needed to flush the panic image to the display.
Thanks for this patch, that's really cool that drm_panic can work on this device too.
Quoted 44 lines
Signed-off-by Javier Martinez Canillas <[email protected]>---
drivers/gpu/drm/solomon/ssd130x.c | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)drivers/gpu/drm/solomon/ssd130x.c +22
-0@@ -32,6 +32,7 @@#include <drm/drm_managed.h> #include <drm/drm_modes.h> #include <drm/drm_rect.h> +#include <drm/drm_panic.h> #include <drm/drm_probe_helper.h> #include "ssd130x.h" @@ -1386,6 +1387,63 @@ static void ssd133x_primary_plane_atomic_disable(struct drm_plane *plane,drm_dev_exit (idx); } +static int ssd130x_primary_plane_helper_get_scanout_buffer (struct drm_plane *plane, +struct drm_scanout_buffer *sb) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_shadow_plane_state *shadow_plane_state; + +if (!plane_state || !plane_state->fb || !plane_state->crtc) +return -EINVAL ; + + shadow_plane_state =to_drm_shadow_plane_state (plane_state); + + sb->format = plane->state->fb->format; + sb->width = plane->state->fb->width; + sb->height = plane->state->fb->height; + sb->pitch[0 ] = plane->state->fb->pitches[0 ]; + sb->map[0 ] = shadow_plane_state->data[0 ]; + +return 0 ; +} + +static void ssd130x_primary_plane_helper_panic_flush (struct drm_plane *plane)
drivers/gpu/drm/solomon/ssd130x.c static void ssd133x_primary_plane_atomic_disable(struct drm_plane *plane, · line 1420
Quoted 10 lines
drivers/gpu/drm/solomon/ssd130x.c +10
-0+{ +struct drm_plane_state *plane_state = plane->state; +struct ssd130x_plane_state *ssd130x_plane_state =to_ssd130x_plane_state (plane_state); +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state); + +ssd130x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_plane_state->buffer, ssd130x_crtc_state->data_array, + &shadow_plane_state->fmtcnv_state);
ssd130x_fb_blit_rect() will call regmap->write(), which involve mutex and might sleep. And if the mutex is taken when the panic occurs, it might deadlock the panic handling. One solution would be to configure the regmap with config->fast_io and config->use_raw_spinlock, and check that the lock is available with try_lock(map->raw_spin_lock) But that means it will waste cpu cycle with busy waiting for normal operation, which is not good.
So for this particular device, I think it's ok, because it's unlikely you'll run kdump or other kernel panic handlers. But I would like to know what others think about it, and if it's acceptable or not.
Signature · 1 line
Jocelyn
Quoted 54 lines
drivers/gpu/drm/solomon/ssd130x.c +32
-0+} + +static void ssd132x_primary_plane_helper_panic_flush (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct ssd130x_plane_state *ssd130x_plane_state =to_ssd130x_plane_state (plane_state); +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state); + +ssd132x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_plane_state->buffer, ssd130x_crtc_state->data_array, + &shadow_plane_state->fmtcnv_state); +} + +static void ssd133x_primary_plane_helper_panic_flush (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state); + +ssd133x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_crtc_state->data_array, &shadow_plane_state->fmtcnv_state); +} +/* Called during init to allocate the plane's atomic state. */ static void ssd130x_primary_plane_reset (struct drm_plane *plane) {@@ -1442,18 +1500,24 @@ static const struct drm_plane_helper_funcs ssd130x_primary_plane_helper_funcs[] .atomic_check = ssd130x_primary_plane_atomic_check, .atomic_update = ssd130x_primary_plane_atomic_update, .atomic_disable = ssd130x_primary_plane_atomic_disable, + .get_scanout_buffer = ssd130x_primary_plane_helper_get_scanout_buffer, + .panic_flush = ssd130x_primary_plane_helper_panic_flush, }, [SSD132X_FAMILY] = { DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, .atomic_check = ssd132x_primary_plane_atomic_check, .atomic_update = ssd132x_primary_plane_atomic_update, .atomic_disable = ssd132x_primary_plane_atomic_disable, + .get_scanout_buffer = ssd130x_primary_plane_helper_get_scanout_buffer, + .panic_flush = ssd132x_primary_plane_helper_panic_flush, }, [SSD133X_FAMILY] = { DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, .atomic_check = ssd133x_primary_plane_atomic_check, .atomic_update = ssd133x_primary_plane_atomic_update, .atomic_disable = ssd133x_primary_plane_atomic_disable, + .get_scanout_buffer = ssd130x_primary_plane_helper_get_scanout_buffer, + .panic_flush = ssd133x_primary_plane_helper_panic_flush, } };
Javier Martinez Canillas
maintainerJocelyn Falempe <[email protected]> writes:
Hello Jocelyn, thanks for your feedback!
Quoted 11 lines · Javier Martinez Canillas
Quoted 6 lines
Add support for the
drm_panicinfrastructure, which allows to display a user friendly message on the screen when a Linux kernel panic occurs.The display controller doesn't scanout the framebuffer, but instead the pixels are sent to the device using a transport bus. For this reason, a .panic_flush handler is needed to flush the panic image to the display.
Thanks for this patch, that's really cool that
drm_paniccan work on this device too.
Indeed, that's why I did it. Just to see if it could work :)
[...]
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/solomon/ssd130x.c +7
-0+static void ssd130x_primary_plane_helper_panic_flush (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct ssd130x_plane_state *ssd130x_plane_state =to_ssd130x_plane_state (plane_state); +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state);
Quoted 8 lines
drivers/gpu/drm/solomon/ssd130x.c static void ssd133x_primary_plane_atomic_disable(struct drm_plane *plane, · line 1420
Quoted 4 lines
drivers/gpu/drm/solomon/ssd130x.c +4
-0+ +ssd130x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_plane_state->buffer, ssd130x_crtc_state->data_array, + &shadow_plane_state->fmtcnv_state);
ssd130x_fb_blit_rect()will callregmap->write(), which involve mutex and might sleep. And if the mutex is taken when the panic occurs, it might deadlock the panic handling.
That's a good point and I something haven't considered...
Quoted 6 lines
One solution would be to configure the regmap with
config->fast_ioandconfig->use_raw_spinlock, and check that the lock is available withtry_lock(map->raw_spin_lock)
But that means it will waste cpu cycle with busy waiting for normal operation, which is not good.
Yeah, I would prefer to not change the driver for normal operation.
Quoted 5 lines
So for this particular device, I think it's ok, because it's unlikely you'll run kdump or other kernel panic handlers.
But I would like to know what others think about it, and if it's acceptable or not.
I don't know either. I guess that after a panic everything is best effort anyways so it may be acceptable? But let's see what others think about it.
Quoted 3 lines
Signature · 1 line
Jocelyn
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Javier Martinez Canillas
maintainerQuoted 38 lines · Javier Martinez Canillas
Jocelyn Falempe <[email protected]> writes:
Hello Jocelyn, thanks for your feedback!
Quoted 11 lines · Javier Martinez Canillas
Quoted 6 lines
Add support for the
drm_panicinfrastructure, which allows to display a user friendly message on the screen when a Linux kernel panic occurs.The display controller doesn't scanout the framebuffer, but instead the pixels are sent to the device using a transport bus. For this reason, a .panic_flush handler is needed to flush the panic image to the display.
Thanks for this patch, that's really cool that
drm_paniccan work on this device too.Indeed, that's why I did it. Just to see if it could work :)
[...]
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/solomon/ssd130x.c +7
-0+static void ssd130x_primary_plane_helper_panic_flush (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct ssd130x_plane_state *ssd130x_plane_state =to_ssd130x_plane_state (plane_state); +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state);Quoted 8 lines
drivers/gpu/drm/solomon/ssd130x.c static void ssd133x_primary_plane_atomic_disable(struct drm_plane *plane, · line 1420
Quoted 4 lines
drivers/gpu/drm/solomon/ssd130x.c +4
-0+ +ssd130x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_plane_state->buffer, ssd130x_crtc_state->data_array, + &shadow_plane_state->fmtcnv_state);
ssd130x_fb_blit_rect()will callregmap->write(), which involve mutex and might sleep. And if the mutex is taken when the panic occurs, it might deadlock the panic handling.That's a good point and I something haven't considered...
Quoted 9 lines
Quoted 6 lines
One solution would be to configure the regmap with
config->fast_ioandconfig->use_raw_spinlock, and check that the lock is available withtry_lock(map->raw_spin_lock)
But that means it will waste cpu cycle with busy waiting for normal operation, which is not good.Yeah, I would prefer to not change the driver for normal operation.
Another option, that I believe makes more sense, is to just disable the regmap locking (using struct regmap_config.disable_locking field [0]).
Since this regmap is not shared with other drivers and so any concurrent access should already be prevented by the DRM core locking scheme.
Is my understanding correct?
[0]: https://elixir.bootlin.com/linux/v6.10-rc1/source/include/linux/regmap.h#L326
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat
Quoted 50 lines · Javier Martinez Canillas
Quoted 38 lines · Javier Martinez Canillas
Jocelyn Falempe <[email protected]> writes:
Hello Jocelyn, thanks for your feedback!
Quoted 11 lines · Javier Martinez Canillas
Quoted 6 lines
Add support for the
drm_panicinfrastructure, which allows to display a user friendly message on the screen when a Linux kernel panic occurs.The display controller doesn't scanout the framebuffer, but instead the pixels are sent to the device using a transport bus. For this reason, a .panic_flush handler is needed to flush the panic image to the display.
Thanks for this patch, that's really cool that
drm_paniccan work on this device too.Indeed, that's why I did it. Just to see if it could work :)
[...]
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/solomon/ssd130x.c +7
-0+static void ssd130x_primary_plane_helper_panic_flush (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct ssd130x_plane_state *ssd130x_plane_state =to_ssd130x_plane_state (plane_state); +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state);Quoted 8 lines
drivers/gpu/drm/solomon/ssd130x.c static void ssd133x_primary_plane_atomic_disable(struct drm_plane *plane, · line 1420
Quoted 4 lines
drivers/gpu/drm/solomon/ssd130x.c +4
-0+ +ssd130x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_plane_state->buffer, ssd130x_crtc_state->data_array, + &shadow_plane_state->fmtcnv_state);
ssd130x_fb_blit_rect()will callregmap->write(), which involve mutex and might sleep. And if the mutex is taken when the panic occurs, it might deadlock the panic handling.That's a good point and I something haven't considered...
Quoted 9 lines
Quoted 6 lines
One solution would be to configure the regmap with
config->fast_ioandconfig->use_raw_spinlock, and check that the lock is available withtry_lock(map->raw_spin_lock)
But that means it will waste cpu cycle with busy waiting for normal operation, which is not good.Yeah, I would prefer to not change the driver for normal operation.
Quoted 7 lines
Another option, that I believe makes more sense, is to just disable the regmap locking (using struct regmap_config.disable_locking field [0]).
Since this regmap is not shared with other drivers and so any concurrent access should already be prevented by the DRM core locking scheme.
Is my understanding correct?
Quick irc discussion summary: Since these are panels that sit on i2c/spi buses, you need to put the raw spinlock panic locking into these subsystems. Which is going to be extreme amounts of fun, becuase:
- You need to protect innermost register access with a raw spinlock, but enough so that every access is still consistent.
- You need separate panic paths which avoid all the existing subsystem locking (i2c/spi have userspace apis, so they need mutexes) and only rely on the caller having done the raw spinlock trylocking.
- Bonus points: Who even owns that raw spinlock ...
I'm afraid, this is going to be a tough nut to crack :-/
Cheers, Sima
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Javier Martinez Canillas
maintainerDaniel Vetter <[email protected]> writes:
Hello Sima,
Thanks for your comment and explanations.
Quoted 66 lines · Javier Martinez Canillas
Quoted 50 lines
Quoted 38 lines · Javier Martinez Canillas
Jocelyn Falempe <[email protected]> writes:
Hello Jocelyn, thanks for your feedback!
Quoted 11 lines · Javier Martinez Canillas
Quoted 6 lines
Add support for the
drm_panicinfrastructure, which allows to display a user friendly message on the screen when a Linux kernel panic occurs.The display controller doesn't scanout the framebuffer, but instead the pixels are sent to the device using a transport bus. For this reason, a .panic_flush handler is needed to flush the panic image to the display.
Thanks for this patch, that's really cool that
drm_paniccan work on this device too.Indeed, that's why I did it. Just to see if it could work :)
[...]
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/solomon/ssd130x.c +7
-0+static void ssd130x_primary_plane_helper_panic_flush (struct drm_plane *plane) +{ +struct drm_plane_state *plane_state = plane->state; +struct ssd130x_plane_state *ssd130x_plane_state =to_ssd130x_plane_state (plane_state); +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_crtc *crtc = plane_state->crtc; +struct ssd130x_crtc_state *ssd130x_crtc_state =to_ssd130x_crtc_state (crtc->state);Quoted 8 lines
drivers/gpu/drm/solomon/ssd130x.c static void ssd133x_primary_plane_atomic_disable(struct drm_plane *plane, · line 1420
Quoted 4 lines
drivers/gpu/drm/solomon/ssd130x.c +4
-0+ +ssd130x_fb_blit_rect (plane_state->fb, &shadow_plane_state->data[0 ], &plane_state->dst, + ssd130x_plane_state->buffer, ssd130x_crtc_state->data_array, + &shadow_plane_state->fmtcnv_state);
ssd130x_fb_blit_rect()will callregmap->write(), which involve mutex and might sleep. And if the mutex is taken when the panic occurs, it might deadlock the panic handling.That's a good point and I something haven't considered...
Quoted 9 lines
Quoted 6 lines
One solution would be to configure the regmap with
config->fast_ioandconfig->use_raw_spinlock, and check that the lock is available withtry_lock(map->raw_spin_lock)
But that means it will waste cpu cycle with busy waiting for normal operation, which is not good.Yeah, I would prefer to not change the driver for normal operation.
Quoted 7 lines
Another option, that I believe makes more sense, is to just disable the regmap locking (using struct regmap_config.disable_locking field [0]).
Since this regmap is not shared with other drivers and so any concurrent access should already be prevented by the DRM core locking scheme.
Is my understanding correct?
Quick irc discussion summary: Since these are panels that sit on i2c/spi buses, you need to put the raw spinlock panic locking into these subsystems. Which is going to be extreme amounts of fun, becuase:
- You need to protect innermost register access with a raw spinlock, but enough so that every access is still consistent.
Quoted 8 lines
- You need separate panic paths which avoid all the existing subsystem locking (i2c/spi have userspace apis, so they need mutexes) and only rely on the caller having done the raw spinlock trylocking.
- Bonus points: Who even owns that raw spinlock ...
I'm afraid, this is going to be a tough nut to crack :-/
Yeah, not worth the effort then. I'll just drop this patch.
Quoted 6 lines
Cheers, Sima
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 5 lines
Best regards, Javier Martinez Canillas Core Platforms Red Hat