Commit 3823da3a authored by Daniel Stone's avatar Daniel Stone

drm/virtio: Place GEM BOs in drm_framebuffer

Since drm_framebuffer can now store GEM objects directly, place them
there rather than in our own subclass. As this makes the framebuffer
create_handle and destroy functions the same as the GEM framebuffer
helper, we can reuse those.
Signed-off-by: default avatarDaniel Stone <daniels@collabora.com>
Reviewed-by: default avatarThierry Reding <treding@nvidia.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Link: https://patchwork.freedesktop.org/patch/msgid/20180330141138.28987-3-daniels@collabora.com
parent 121df61e
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "virtgpu_drv.h" #include "virtgpu_drv.h"
#include <drm/drm_crtc_helper.h> #include <drm/drm_crtc_helper.h>
#include <drm/drm_atomic_helper.h> #include <drm/drm_atomic_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
#define XRES_MIN 32 #define XRES_MIN 32
#define YRES_MIN 32 #define YRES_MIN 32
...@@ -48,16 +49,6 @@ static const struct drm_crtc_funcs virtio_gpu_crtc_funcs = { ...@@ -48,16 +49,6 @@ static const struct drm_crtc_funcs virtio_gpu_crtc_funcs = {
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
}; };
static void virtio_gpu_user_framebuffer_destroy(struct drm_framebuffer *fb)
{
struct virtio_gpu_framebuffer *virtio_gpu_fb
= to_virtio_gpu_framebuffer(fb);
drm_gem_object_put_unlocked(virtio_gpu_fb->obj);
drm_framebuffer_cleanup(fb);
kfree(virtio_gpu_fb);
}
static int static int
virtio_gpu_framebuffer_surface_dirty(struct drm_framebuffer *fb, virtio_gpu_framebuffer_surface_dirty(struct drm_framebuffer *fb,
struct drm_file *file_priv, struct drm_file *file_priv,
...@@ -71,20 +62,9 @@ virtio_gpu_framebuffer_surface_dirty(struct drm_framebuffer *fb, ...@@ -71,20 +62,9 @@ virtio_gpu_framebuffer_surface_dirty(struct drm_framebuffer *fb,
return virtio_gpu_surface_dirty(virtio_gpu_fb, clips, num_clips); return virtio_gpu_surface_dirty(virtio_gpu_fb, clips, num_clips);
} }
static int
virtio_gpu_framebuffer_create_handle(struct drm_framebuffer *fb,
struct drm_file *file_priv,
unsigned int *handle)
{
struct virtio_gpu_framebuffer *virtio_gpu_fb =
to_virtio_gpu_framebuffer(fb);
return drm_gem_handle_create(file_priv, virtio_gpu_fb->obj, handle);
}
static const struct drm_framebuffer_funcs virtio_gpu_fb_funcs = { static const struct drm_framebuffer_funcs virtio_gpu_fb_funcs = {
.create_handle = virtio_gpu_framebuffer_create_handle, .create_handle = drm_gem_fb_create_handle,
.destroy = virtio_gpu_user_framebuffer_destroy, .destroy = drm_gem_fb_destroy,
.dirty = virtio_gpu_framebuffer_surface_dirty, .dirty = virtio_gpu_framebuffer_surface_dirty,
}; };
...@@ -97,7 +77,7 @@ virtio_gpu_framebuffer_init(struct drm_device *dev, ...@@ -97,7 +77,7 @@ virtio_gpu_framebuffer_init(struct drm_device *dev,
int ret; int ret;
struct virtio_gpu_object *bo; struct virtio_gpu_object *bo;
vgfb->obj = obj; vgfb->base.obj[0] = obj;
bo = gem_to_virtio_gpu_obj(obj); bo = gem_to_virtio_gpu_obj(obj);
...@@ -105,7 +85,7 @@ virtio_gpu_framebuffer_init(struct drm_device *dev, ...@@ -105,7 +85,7 @@ virtio_gpu_framebuffer_init(struct drm_device *dev,
ret = drm_framebuffer_init(dev, &vgfb->base, &virtio_gpu_fb_funcs); ret = drm_framebuffer_init(dev, &vgfb->base, &virtio_gpu_fb_funcs);
if (ret) { if (ret) {
vgfb->obj = NULL; vgfb->base.obj[0] = NULL;
return ret; return ret;
} }
......
...@@ -124,7 +124,6 @@ struct virtio_gpu_output { ...@@ -124,7 +124,6 @@ struct virtio_gpu_output {
struct virtio_gpu_framebuffer { struct virtio_gpu_framebuffer {
struct drm_framebuffer base; struct drm_framebuffer base;
struct drm_gem_object *obj;
int x1, y1, x2, y2; /* dirty rect */ int x1, y1, x2, y2; /* dirty rect */
spinlock_t dirty_lock; spinlock_t dirty_lock;
uint32_t hw_res_handle; uint32_t hw_res_handle;
......
...@@ -46,7 +46,7 @@ static int virtio_gpu_dirty_update(struct virtio_gpu_framebuffer *fb, ...@@ -46,7 +46,7 @@ static int virtio_gpu_dirty_update(struct virtio_gpu_framebuffer *fb,
int bpp = fb->base.format->cpp[0]; int bpp = fb->base.format->cpp[0];
int x2, y2; int x2, y2;
unsigned long flags; unsigned long flags;
struct virtio_gpu_object *obj = gem_to_virtio_gpu_obj(fb->obj); struct virtio_gpu_object *obj = gem_to_virtio_gpu_obj(fb->base.obj[0]);
if ((width <= 0) || if ((width <= 0) ||
(x + width > fb->base.width) || (x + width > fb->base.width) ||
...@@ -121,7 +121,7 @@ int virtio_gpu_surface_dirty(struct virtio_gpu_framebuffer *vgfb, ...@@ -121,7 +121,7 @@ int virtio_gpu_surface_dirty(struct virtio_gpu_framebuffer *vgfb,
unsigned int num_clips) unsigned int num_clips)
{ {
struct virtio_gpu_device *vgdev = vgfb->base.dev->dev_private; struct virtio_gpu_device *vgdev = vgfb->base.dev->dev_private;
struct virtio_gpu_object *obj = gem_to_virtio_gpu_obj(vgfb->obj); struct virtio_gpu_object *obj = gem_to_virtio_gpu_obj(vgfb->base.obj[0]);
struct drm_clip_rect norect; struct drm_clip_rect norect;
struct drm_clip_rect *clips_ptr; struct drm_clip_rect *clips_ptr;
int left, right, top, bottom; int left, right, top, bottom;
...@@ -305,8 +305,8 @@ static int virtio_gpu_fbdev_destroy(struct drm_device *dev, ...@@ -305,8 +305,8 @@ static int virtio_gpu_fbdev_destroy(struct drm_device *dev,
drm_fb_helper_unregister_fbi(&vgfbdev->helper); drm_fb_helper_unregister_fbi(&vgfbdev->helper);
if (vgfb->obj) if (vgfb->base.obj[0])
vgfb->obj = NULL; vgfb->base.obj[0] = NULL;
drm_fb_helper_fini(&vgfbdev->helper); drm_fb_helper_fini(&vgfbdev->helper);
drm_framebuffer_cleanup(&vgfb->base); drm_framebuffer_cleanup(&vgfb->base);
......
...@@ -154,7 +154,7 @@ static void virtio_gpu_primary_plane_update(struct drm_plane *plane, ...@@ -154,7 +154,7 @@ static void virtio_gpu_primary_plane_update(struct drm_plane *plane,
if (plane->state->fb) { if (plane->state->fb) {
vgfb = to_virtio_gpu_framebuffer(plane->state->fb); vgfb = to_virtio_gpu_framebuffer(plane->state->fb);
bo = gem_to_virtio_gpu_obj(vgfb->obj); bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]);
handle = bo->hw_res_handle; handle = bo->hw_res_handle;
if (bo->dumb) { if (bo->dumb) {
virtio_gpu_cmd_transfer_to_host_2d virtio_gpu_cmd_transfer_to_host_2d
...@@ -208,7 +208,7 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane, ...@@ -208,7 +208,7 @@ static void virtio_gpu_cursor_plane_update(struct drm_plane *plane,
if (plane->state->fb) { if (plane->state->fb) {
vgfb = to_virtio_gpu_framebuffer(plane->state->fb); vgfb = to_virtio_gpu_framebuffer(plane->state->fb);
bo = gem_to_virtio_gpu_obj(vgfb->obj); bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]);
handle = bo->hw_res_handle; handle = bo->hw_res_handle;
} else { } else {
handle = 0; handle = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment