mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 23:03:57 -04:00
drm/virtio: Add drm_panic support
Virtio gpu supports the drm_panic module, which displays a message to the screen when a kernel panic occurs. It is supported where it has vmapped shmem BO. Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com> Signed-off-by: Ryosuke Yasuoka <ryasuoka@redhat.com> Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250206104300.416014-1-ryasuoka@redhat.com
This commit is contained in:
committed by
Dmitry Osipenko
parent
05345cea4f
commit
6f3d9d0dd3
@@ -28,6 +28,8 @@
|
||||
#include <drm/drm_fourcc.h>
|
||||
#include <drm/drm_gem_atomic_helper.h>
|
||||
#include <linux/virtio_dma_buf.h>
|
||||
#include <drm/drm_managed.h>
|
||||
#include <drm/drm_panic.h>
|
||||
|
||||
#include "virtgpu_drv.h"
|
||||
|
||||
@@ -127,6 +129,30 @@ static int virtio_gpu_plane_atomic_check(struct drm_plane *plane,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* For drm panic */
|
||||
static int virtio_gpu_panic_update_dumb_bo(struct virtio_gpu_device *vgdev,
|
||||
struct drm_plane_state *state,
|
||||
struct drm_rect *rect)
|
||||
{
|
||||
struct virtio_gpu_object *bo =
|
||||
gem_to_virtio_gpu_obj(state->fb->obj[0]);
|
||||
struct virtio_gpu_object_array *objs;
|
||||
uint32_t w = rect->x2 - rect->x1;
|
||||
uint32_t h = rect->y2 - rect->y1;
|
||||
uint32_t x = rect->x1;
|
||||
uint32_t y = rect->y1;
|
||||
uint32_t off = x * state->fb->format->cpp[0] +
|
||||
y * state->fb->pitches[0];
|
||||
|
||||
objs = virtio_gpu_panic_array_alloc();
|
||||
if (!objs)
|
||||
return -ENOMEM;
|
||||
virtio_gpu_array_add_obj(objs, &bo->base.base);
|
||||
|
||||
return virtio_gpu_panic_cmd_transfer_to_host_2d(vgdev, off, w, h, x, y,
|
||||
objs);
|
||||
}
|
||||
|
||||
static void virtio_gpu_update_dumb_bo(struct virtio_gpu_device *vgdev,
|
||||
struct drm_plane_state *state,
|
||||
struct drm_rect *rect)
|
||||
@@ -150,6 +176,24 @@ static void virtio_gpu_update_dumb_bo(struct virtio_gpu_device *vgdev,
|
||||
objs, NULL);
|
||||
}
|
||||
|
||||
/* For drm_panic */
|
||||
static void virtio_gpu_panic_resource_flush(struct drm_plane *plane,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t width, uint32_t height)
|
||||
{
|
||||
struct drm_device *dev = plane->dev;
|
||||
struct virtio_gpu_device *vgdev = dev->dev_private;
|
||||
struct virtio_gpu_framebuffer *vgfb;
|
||||
struct virtio_gpu_object *bo;
|
||||
|
||||
vgfb = to_virtio_gpu_framebuffer(plane->state->fb);
|
||||
bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]);
|
||||
|
||||
virtio_gpu_panic_cmd_resource_flush(vgdev, bo->hw_res_handle, x, y,
|
||||
width, height);
|
||||
virtio_gpu_panic_notify(vgdev);
|
||||
}
|
||||
|
||||
static void virtio_gpu_resource_flush(struct drm_plane *plane,
|
||||
uint32_t x, uint32_t y,
|
||||
uint32_t width, uint32_t height)
|
||||
@@ -446,11 +490,63 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
|
||||
virtio_gpu_cursor_ping(vgdev, output);
|
||||
}
|
||||
|
||||
static int virtio_drm_get_scanout_buffer(struct drm_plane *plane,
|
||||
struct drm_scanout_buffer *sb)
|
||||
{
|
||||
struct virtio_gpu_object *bo;
|
||||
|
||||
if (!plane->state || !plane->state->fb || !plane->state->visible)
|
||||
return -ENODEV;
|
||||
|
||||
bo = gem_to_virtio_gpu_obj(plane->state->fb->obj[0]);
|
||||
|
||||
/* Only support mapped shmem bo */
|
||||
if (virtio_gpu_is_vram(bo) || bo->base.base.import_attach || !bo->base.vaddr)
|
||||
return -ENODEV;
|
||||
|
||||
iosys_map_set_vaddr(&sb->map[0], bo->base.vaddr);
|
||||
|
||||
sb->format = plane->state->fb->format;
|
||||
sb->height = plane->state->fb->height;
|
||||
sb->width = plane->state->fb->width;
|
||||
sb->pitch[0] = plane->state->fb->pitches[0];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void virtio_panic_flush(struct drm_plane *plane)
|
||||
{
|
||||
struct virtio_gpu_object *bo;
|
||||
struct drm_device *dev = plane->dev;
|
||||
struct virtio_gpu_device *vgdev = dev->dev_private;
|
||||
struct drm_rect rect;
|
||||
|
||||
rect.x1 = 0;
|
||||
rect.y1 = 0;
|
||||
rect.x2 = plane->state->fb->width;
|
||||
rect.y2 = plane->state->fb->height;
|
||||
|
||||
bo = gem_to_virtio_gpu_obj(plane->state->fb->obj[0]);
|
||||
|
||||
if (bo->dumb) {
|
||||
if (virtio_gpu_panic_update_dumb_bo(vgdev, plane->state,
|
||||
&rect))
|
||||
return;
|
||||
}
|
||||
|
||||
virtio_gpu_panic_resource_flush(plane,
|
||||
plane->state->src_x >> 16,
|
||||
plane->state->src_y >> 16,
|
||||
plane->state->src_w >> 16,
|
||||
plane->state->src_h >> 16);
|
||||
}
|
||||
|
||||
static const struct drm_plane_helper_funcs virtio_gpu_primary_helper_funcs = {
|
||||
.prepare_fb = virtio_gpu_plane_prepare_fb,
|
||||
.cleanup_fb = virtio_gpu_plane_cleanup_fb,
|
||||
.atomic_check = virtio_gpu_plane_atomic_check,
|
||||
.atomic_update = virtio_gpu_primary_plane_update,
|
||||
.get_scanout_buffer = virtio_drm_get_scanout_buffer,
|
||||
.panic_flush = virtio_panic_flush,
|
||||
};
|
||||
|
||||
static const struct drm_plane_helper_funcs virtio_gpu_cursor_helper_funcs = {
|
||||
|
||||
Reference in New Issue
Block a user