#include <drm/drm_plane_helper.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_atomic.h>
+#include <drm/drm_gem_framebuffer_helper.h>
#include "qxl_drv.h"
#include "qxl_object.h"
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
};
-void qxl_user_framebuffer_destroy(struct drm_framebuffer *fb)
-{
- struct qxl_framebuffer *qxl_fb = to_qxl_framebuffer(fb);
- struct qxl_bo *bo = gem_to_qxl_bo(qxl_fb->obj);
-
- WARN_ON(bo->shadow);
- drm_gem_object_put_unlocked(qxl_fb->obj);
- drm_framebuffer_cleanup(fb);
- kfree(qxl_fb);
-}
-
static int qxl_framebuffer_surface_dirty(struct drm_framebuffer *fb,
struct drm_file *file_priv,
unsigned flags, unsigned color,
unsigned num_clips)
{
/* TODO: vmwgfx where this was cribbed from had locking. Why? */
- struct qxl_framebuffer *qxl_fb = to_qxl_framebuffer(fb);
- struct qxl_device *qdev = qxl_fb->base.dev->dev_private;
+ struct qxl_device *qdev = fb->dev->dev_private;
struct drm_clip_rect norect;
struct qxl_bo *qobj;
int inc = 1;
drm_modeset_lock_all(fb->dev);
- qobj = gem_to_qxl_bo(qxl_fb->obj);
+ qobj = gem_to_qxl_bo(fb->obj[0]);
/* if we aren't primary surface ignore this */
if (!qobj->is_primary) {
drm_modeset_unlock_all(fb->dev);
inc = 2; /* skip source rects */
}
- qxl_draw_dirty_fb(qdev, qxl_fb, qobj, flags, color,
+ qxl_draw_dirty_fb(qdev, fb, qobj, flags, color,
clips, num_clips, inc);
drm_modeset_unlock_all(fb->dev);
}
static const struct drm_framebuffer_funcs qxl_fb_funcs = {
- .destroy = qxl_user_framebuffer_destroy,
+ .destroy = drm_gem_fb_destroy,
.dirty = qxl_framebuffer_surface_dirty,
-/* TODO?
- * .create_handle = qxl_user_framebuffer_create_handle, */
+ .create_handle = drm_gem_fb_create_handle,
};
-int
-qxl_framebuffer_init(struct drm_device *dev,
- struct qxl_framebuffer *qfb,
- const struct drm_mode_fb_cmd2 *mode_cmd,
- struct drm_gem_object *obj,
- const struct drm_framebuffer_funcs *funcs)
-{
- int ret;
-
- qfb->obj = obj;
- drm_helper_mode_fill_fb_struct(dev, &qfb->base, mode_cmd);
- ret = drm_framebuffer_init(dev, &qfb->base, funcs);
- if (ret) {
- qfb->obj = NULL;
- return ret;
- }
- return 0;
-}
-
static void qxl_crtc_atomic_enable(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
struct drm_plane_state *state)
{
struct qxl_device *qdev = plane->dev->dev_private;
- struct qxl_framebuffer *qfb;
struct qxl_bo *bo;
if (!state->crtc || !state->fb)
return 0;
- qfb = to_qxl_framebuffer(state->fb);
- bo = gem_to_qxl_bo(qfb->obj);
+ bo = gem_to_qxl_bo(state->fb->obj[0]);
if (bo->surf.stride * bo->surf.height > qdev->vram_size) {
DRM_ERROR("Mode doesn't fit in vram size (vgamem)");
struct drm_plane_state *old_state)
{
struct qxl_device *qdev = plane->dev->dev_private;
- struct qxl_framebuffer *qfb =
- to_qxl_framebuffer(plane->state->fb);
- struct qxl_framebuffer *qfb_old;
- struct qxl_bo *bo = gem_to_qxl_bo(qfb->obj);
+ struct qxl_bo *bo = gem_to_qxl_bo(plane->state->fb->obj[0]);
struct qxl_bo *bo_old;
struct drm_clip_rect norect = {
.x1 = 0,
.y1 = 0,
- .x2 = qfb->base.width,
- .y2 = qfb->base.height
+ .x2 = plane->state->fb->width,
+ .y2 = plane->state->fb->height
};
int ret;
bool same_shadow = false;
if (old_state->fb) {
- qfb_old = to_qxl_framebuffer(old_state->fb);
- bo_old = gem_to_qxl_bo(qfb_old->obj);
+ bo_old = gem_to_qxl_bo(old_state->fb->obj[0]);
} else {
bo_old = NULL;
}
bo->is_primary = true;
}
- qxl_draw_dirty_fb(qdev, qfb, bo, 0, 0, &norect, 1, 1);
+ qxl_draw_dirty_fb(qdev, plane->state->fb, bo, 0, 0, &norect, 1, 1);
}
static void qxl_primary_atomic_disable(struct drm_plane *plane,
struct qxl_device *qdev = plane->dev->dev_private;
if (old_state->fb) {
- struct qxl_framebuffer *qfb =
- to_qxl_framebuffer(old_state->fb);
- struct qxl_bo *bo = gem_to_qxl_bo(qfb->obj);
+ struct qxl_bo *bo = gem_to_qxl_bo(old_state->fb->obj[0]);
if (bo->is_primary) {
qxl_io_destroy_primary(qdev);
return;
if (fb != old_state->fb) {
- obj = to_qxl_framebuffer(fb)->obj;
+ obj = fb->obj[0];
user_bo = gem_to_qxl_bo(obj);
/* pinning is done in the prepare/cleanup framevbuffer */
if (!new_state->fb)
return 0;
- obj = to_qxl_framebuffer(new_state->fb)->obj;
+ obj = new_state->fb->obj[0];
user_bo = gem_to_qxl_bo(obj);
if (plane->type == DRM_PLANE_TYPE_PRIMARY &&
user_bo->is_dumb && !user_bo->shadow) {
if (plane->state->fb) {
- obj = to_qxl_framebuffer(plane->state->fb)->obj;
+ obj = plane->state->fb->obj[0];
old_bo = gem_to_qxl_bo(obj);
}
if (old_bo && old_bo->shadow &&
return;
}
- obj = to_qxl_framebuffer(old_state->fb)->obj;
+ obj = old_state->fb->obj[0];
user_bo = gem_to_qxl_bo(obj);
qxl_bo_unpin(user_bo);
struct drm_file *file_priv,
const struct drm_mode_fb_cmd2 *mode_cmd)
{
- struct drm_gem_object *obj;
- struct qxl_framebuffer *qxl_fb;
- int ret;
-
- obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[0]);
- if (!obj)
- return NULL;
-
- qxl_fb = kzalloc(sizeof(*qxl_fb), GFP_KERNEL);
- if (qxl_fb == NULL)
- return NULL;
-
- ret = qxl_framebuffer_init(dev, qxl_fb, mode_cmd, obj, &qxl_fb_funcs);
- if (ret) {
- kfree(qxl_fb);
- drm_gem_object_put_unlocked(obj);
- return NULL;
- }
-
- return &qxl_fb->base;
+ return drm_gem_fb_create_with_funcs(dev, file_priv, mode_cmd,
+ &qxl_fb_funcs);
}
static const struct drm_mode_config_funcs qxl_mode_funcs = {
}
qxl_display_read_client_monitors_config(qdev);
- qdev->mode_info.mode_config_initialized = true;
drm_mode_config_reset(&qdev->ddev);
qxl_fbdev_fini(qdev);
qxl_destroy_monitors_object(qdev);
- if (qdev->mode_info.mode_config_initialized) {
- drm_mode_config_cleanup(&qdev->ddev);
- qdev->mode_info.mode_config_initialized = false;
- }
+ drm_mode_config_cleanup(&qdev->ddev);
}
* by treating them differently in the server.
*/
void qxl_draw_dirty_fb(struct qxl_device *qdev,
- struct qxl_framebuffer *qxl_fb,
+ struct drm_framebuffer *fb,
struct qxl_bo *bo,
unsigned flags, unsigned color,
struct drm_clip_rect *clips,
struct qxl_drawable *drawable;
struct qxl_rect drawable_rect;
struct qxl_rect *rects;
- int stride = qxl_fb->base.pitches[0];
+ int stride = fb->pitches[0];
/* depth is not actually interesting, we don't mask with it */
- int depth = qxl_fb->base.format->cpp[0] * 8;
+ int depth = fb->format->cpp[0] * 8;
uint8_t *surface_base;
struct qxl_release *release;
struct qxl_bo *clips_bo;
#include <drm/drm_crtc.h>
#include <drm/drm_encoder.h>
+#include <drm/drm_fb_helper.h>
#include <drm/drm_gem.h>
#include <drm/drmP.h>
#include <drm/ttm/ttm_bo_api.h>
struct drm_encoder enc;
};
-struct qxl_framebuffer {
- struct drm_framebuffer base;
- struct drm_gem_object *obj;
-};
-
#define to_qxl_crtc(x) container_of(x, struct qxl_crtc, base)
#define drm_connector_to_qxl_output(x) container_of(x, struct qxl_output, base)
#define drm_encoder_to_qxl_output(x) container_of(x, struct qxl_output, enc)
-#define to_qxl_framebuffer(x) container_of(x, struct qxl_framebuffer, base)
struct qxl_mman {
struct ttm_bo_global_ref bo_global_ref;
struct ttm_bo_device bdev;
};
-struct qxl_mode_info {
- bool mode_config_initialized;
-
- /* pointer to fbdev info structure */
- struct qxl_fbdev *qfbdev;
-};
-
struct qxl_memslot {
uint8_t generation;
void *ram;
struct qxl_mman mman;
struct qxl_gem gem;
- struct qxl_mode_info mode_info;
- struct fb_info *fbdev_info;
- struct qxl_framebuffer *fbdev_qfb;
+ struct drm_fb_helper fb_helper;
+
void *ram_physical;
struct qxl_ring *release_ring;
int qxl_fbdev_init(struct qxl_device *qdev);
void qxl_fbdev_fini(struct qxl_device *qdev);
-int qxl_get_handle_for_primary_fb(struct qxl_device *qdev,
- struct drm_file *file_priv,
- uint32_t *handle);
-void qxl_fbdev_set_suspend(struct qxl_device *qdev, int state);
/* qxl_display.c */
-void qxl_user_framebuffer_destroy(struct drm_framebuffer *fb);
-int
-qxl_framebuffer_init(struct drm_device *dev,
- struct qxl_framebuffer *rfb,
- const struct drm_mode_fb_cmd2 *mode_cmd,
- struct drm_gem_object *obj,
- const struct drm_framebuffer_funcs *funcs);
void qxl_display_read_client_monitors_config(struct qxl_device *qdev);
int qxl_create_monitors_object(struct qxl_device *qdev);
int qxl_destroy_monitors_object(struct qxl_device *qdev);
int stride /* filled in if 0 */);
void qxl_draw_dirty_fb(struct qxl_device *qdev,
- struct qxl_framebuffer *qxl_fb,
+ struct drm_framebuffer *fb,
struct qxl_bo *bo,
unsigned flags, unsigned color,
struct drm_clip_rect *clips,
#include <drm/drm_crtc.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_fb_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
#include "qxl_drv.h"
#include "qxl_object.h"
-#define QXL_DIRTY_DELAY (HZ / 30)
-
-struct qxl_fbdev {
- struct drm_fb_helper helper;
- struct qxl_framebuffer qfb;
- struct qxl_device *qdev;
-
- spinlock_t delayed_ops_lock;
- struct list_head delayed_ops;
- void *shadow;
- int size;
-};
-
static void qxl_fb_image_init(struct qxl_fb_image *qxl_fb_image,
struct qxl_device *qdev, struct fb_info *info,
const struct fb_image *image)
}
}
-#ifdef CONFIG_DRM_FBDEV_EMULATION
-static struct fb_deferred_io qxl_defio = {
- .delay = QXL_DIRTY_DELAY,
- .deferred_io = drm_fb_helper_deferred_io,
-};
-#endif
-
static struct fb_ops qxlfb_ops = {
.owner = THIS_MODULE,
DRM_FB_HELPER_DEFAULT_OPS,
drm_gem_object_put_unlocked(gobj);
}
-int qxl_get_handle_for_primary_fb(struct qxl_device *qdev,
- struct drm_file *file_priv,
- uint32_t *handle)
-{
- int r;
- struct drm_gem_object *gobj = qdev->fbdev_qfb->obj;
-
- BUG_ON(!gobj);
- /* drm_get_handle_create adds a reference - good */
- r = drm_gem_handle_create(file_priv, gobj, handle);
- if (r)
- return r;
- return 0;
-}
-
-static int qxlfb_create_pinned_object(struct qxl_fbdev *qfbdev,
+static int qxlfb_create_pinned_object(struct qxl_device *qdev,
const struct drm_mode_fb_cmd2 *mode_cmd,
struct drm_gem_object **gobj_p)
{
- struct qxl_device *qdev = qfbdev->qdev;
struct drm_gem_object *gobj = NULL;
struct qxl_bo *qbo = NULL;
int ret;
unsigned num_clips)
{
struct qxl_device *qdev = fb->dev->dev_private;
- struct fb_info *info = qdev->fbdev_info;
- struct qxl_fbdev *qfbdev = info->par;
+ struct fb_info *info = qdev->fb_helper.fbdev;
struct qxl_fb_image qxl_fb_image;
struct fb_image *image = &qxl_fb_image.fb_image;
/* TODO: hard coding 32 bpp */
- int stride = qfbdev->qfb.base.pitches[0];
+ int stride = fb->pitches[0];
/*
* we are using a shadow draw buffer, at qdev->surface0_shadow
image->cmap.green = NULL;
image->cmap.blue = NULL;
image->cmap.transp = NULL;
- image->data = qfbdev->shadow + (clips->x1 * 4) + (stride * clips->y1);
+ image->data = info->screen_base + (clips->x1 * 4) + (stride * clips->y1);
qxl_fb_image_init(&qxl_fb_image, qdev, info, NULL);
qxl_draw_opaque_fb(&qxl_fb_image, stride);
}
static const struct drm_framebuffer_funcs qxlfb_fb_funcs = {
- .destroy = qxl_user_framebuffer_destroy,
+ .destroy = drm_gem_fb_destroy,
+ .create_handle = drm_gem_fb_create_handle,
.dirty = qxlfb_framebuffer_dirty,
};
-static int qxlfb_create(struct qxl_fbdev *qfbdev,
+static int qxlfb_create(struct drm_fb_helper *helper,
struct drm_fb_helper_surface_size *sizes)
{
- struct qxl_device *qdev = qfbdev->qdev;
+ struct qxl_device *qdev =
+ container_of(helper, struct qxl_device, fb_helper);
struct fb_info *info;
struct drm_framebuffer *fb = NULL;
struct drm_mode_fb_cmd2 mode_cmd;
struct drm_gem_object *gobj = NULL;
struct qxl_bo *qbo = NULL;
int ret;
- int size;
int bpp = sizes->surface_bpp;
int depth = sizes->surface_depth;
void *shadow;
mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((bpp + 1) / 8), 64);
mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
- ret = qxlfb_create_pinned_object(qfbdev, &mode_cmd, &gobj);
+ ret = qxlfb_create_pinned_object(qdev, &mode_cmd, &gobj);
if (ret < 0)
return ret;
DRM_DEBUG_DRIVER("surface0 at gpu offset %lld, mmap_offset %lld (virt %p, shadow %p)\n",
qxl_bo_gpu_offset(qbo), qxl_bo_mmap_offset(qbo),
qbo->kptr, shadow);
- size = mode_cmd.pitches[0] * mode_cmd.height;
- info = drm_fb_helper_alloc_fbi(&qfbdev->helper);
+ info = drm_fb_helper_alloc_fbi(helper);
if (IS_ERR(info)) {
ret = PTR_ERR(info);
goto out_unref;
}
- info->par = qfbdev;
-
- qxl_framebuffer_init(&qdev->ddev, &qfbdev->qfb, &mode_cmd, gobj,
- &qxlfb_fb_funcs);
+ info->par = helper;
- fb = &qfbdev->qfb.base;
+ fb = drm_gem_fbdev_fb_create(&qdev->ddev, sizes, 64, gobj,
+ &qxlfb_fb_funcs);
+ if (IS_ERR(fb)) {
+ DRM_ERROR("Failed to create framebuffer: %ld\n", PTR_ERR(fb));
+ ret = PTR_ERR(fb);
+ goto out_unref;
+ }
/* setup helper with fb data */
- qfbdev->helper.fb = fb;
+ qdev->fb_helper.fb = fb;
- qfbdev->shadow = shadow;
strcpy(info->fix.id, "qxldrmfb");
drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format->depth);
*/
info->fix.smem_start = qdev->vram_base; /* TODO - correct? */
info->fix.smem_len = gobj->size;
- info->screen_base = qfbdev->shadow;
+ info->screen_base = shadow;
info->screen_size = gobj->size;
- drm_fb_helper_fill_var(info, &qfbdev->helper, sizes->fb_width,
+ drm_fb_helper_fill_var(info, &qdev->fb_helper, sizes->fb_width,
sizes->fb_height);
/* setup aperture base/size for vesafb takeover */
goto out_unref;
}
-#ifdef CONFIG_DRM_FBDEV_EMULATION
- info->fbdefio = &qxl_defio;
- fb_deferred_io_init(info);
-#endif
+ /* XXX error handling. */
+ drm_fb_helper_defio_init(helper);
- qdev->fbdev_info = info;
- qdev->fbdev_qfb = &qfbdev->qfb;
DRM_INFO("fb mappable at 0x%lX, size %lu\n", info->fix.smem_start, (unsigned long)info->screen_size);
DRM_INFO("fb: depth %d, pitch %d, width %d, height %d\n",
fb->format->depth, fb->pitches[0], fb->width, fb->height);
qxl_bo_kunmap(qbo);
qxl_bo_unpin(qbo);
}
- if (fb && ret) {
- drm_gem_object_put_unlocked(gobj);
- drm_framebuffer_cleanup(fb);
- kfree(fb);
- }
drm_gem_object_put_unlocked(gobj);
return ret;
}
-static int qxl_fb_find_or_create_single(
- struct drm_fb_helper *helper,
- struct drm_fb_helper_surface_size *sizes)
-{
- struct qxl_fbdev *qfbdev =
- container_of(helper, struct qxl_fbdev, helper);
- int new_fb = 0;
- int ret;
-
- if (!helper->fb) {
- ret = qxlfb_create(qfbdev, sizes);
- if (ret)
- return ret;
- new_fb = 1;
- }
- return new_fb;
-}
-
-static int qxl_fbdev_destroy(struct drm_device *dev, struct qxl_fbdev *qfbdev)
-{
- struct qxl_framebuffer *qfb = &qfbdev->qfb;
-
- drm_fb_helper_unregister_fbi(&qfbdev->helper);
-
- if (qfb->obj) {
- qxlfb_destroy_pinned_object(qfb->obj);
- qfb->obj = NULL;
- }
- drm_fb_helper_fini(&qfbdev->helper);
- vfree(qfbdev->shadow);
- drm_framebuffer_cleanup(&qfb->base);
-
- return 0;
-}
-
static const struct drm_fb_helper_funcs qxl_fb_helper_funcs = {
- .fb_probe = qxl_fb_find_or_create_single,
+ .fb_probe = qxlfb_create,
};
int qxl_fbdev_init(struct qxl_device *qdev)
{
- int ret = 0;
-
-#ifdef CONFIG_DRM_FBDEV_EMULATION
- struct qxl_fbdev *qfbdev;
- int bpp_sel = 32; /* TODO: parameter from somewhere? */
-
- qfbdev = kzalloc(sizeof(struct qxl_fbdev), GFP_KERNEL);
- if (!qfbdev)
- return -ENOMEM;
-
- qfbdev->qdev = qdev;
- qdev->mode_info.qfbdev = qfbdev;
- spin_lock_init(&qfbdev->delayed_ops_lock);
- INIT_LIST_HEAD(&qfbdev->delayed_ops);
-
- drm_fb_helper_prepare(&qdev->ddev, &qfbdev->helper,
- &qxl_fb_helper_funcs);
-
- ret = drm_fb_helper_init(&qdev->ddev, &qfbdev->helper,
- QXLFB_CONN_LIMIT);
- if (ret)
- goto free;
-
- ret = drm_fb_helper_single_add_all_connectors(&qfbdev->helper);
- if (ret)
- goto fini;
-
- ret = drm_fb_helper_initial_config(&qfbdev->helper, bpp_sel);
- if (ret)
- goto fini;
-
- return 0;
-
-fini:
- drm_fb_helper_fini(&qfbdev->helper);
-free:
- kfree(qfbdev);
-#endif
-
- return ret;
+ return drm_fb_helper_fbdev_setup(&qdev->ddev, &qdev->fb_helper,
+ &qxl_fb_helper_funcs, 32,
+ QXLFB_CONN_LIMIT);
}
void qxl_fbdev_fini(struct qxl_device *qdev)
{
- if (!qdev->mode_info.qfbdev)
- return;
+ struct fb_info *fbi = qdev->fb_helper.fbdev;
+ void *shadow = fbi ? fbi->screen_buffer : NULL;
- qxl_fbdev_destroy(&qdev->ddev, qdev->mode_info.qfbdev);
- kfree(qdev->mode_info.qfbdev);
- qdev->mode_info.qfbdev = NULL;
-}
-
-void qxl_fbdev_set_suspend(struct qxl_device *qdev, int state)
-{
- if (!qdev->mode_info.qfbdev)
- return;
-
- drm_fb_helper_set_suspend(&qdev->mode_info.qfbdev->helper, state);
-}
-
-bool qxl_fbdev_qobj_is_fb(struct qxl_device *qdev, struct qxl_bo *qobj)
-{
- if (qobj == gem_to_qxl_bo(qdev->mode_info.qfbdev->qfb.obj))
- return true;
- return false;
+ drm_fb_helper_fbdev_teardown(&qdev->ddev);
+ vfree(shadow);
}