Commit 8b4f49e0 authored by Jesse Barnes's avatar Jesse Barnes Committed by Daniel Vetter

drm/i915: split fb allocation and initialization v2

If we use a stolen buffer, our probe callback shouldn't allocate a new
buffer; we should re-use the one from the BIOS instead if possible.

v2: fix locking (Jesse)
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 67e5871b
...@@ -57,18 +57,14 @@ static struct fb_ops intelfb_ops = { ...@@ -57,18 +57,14 @@ static struct fb_ops intelfb_ops = {
.fb_debug_leave = drm_fb_helper_debug_leave, .fb_debug_leave = drm_fb_helper_debug_leave,
}; };
static int intelfb_create(struct drm_fb_helper *helper, static int intelfb_alloc(struct drm_fb_helper *helper,
struct drm_fb_helper_surface_size *sizes) struct drm_fb_helper_surface_size *sizes)
{ {
struct intel_fbdev *ifbdev = struct intel_fbdev *ifbdev =
container_of(helper, struct intel_fbdev, helper); container_of(helper, struct intel_fbdev, helper);
struct drm_device *dev = helper->dev; struct drm_device *dev = helper->dev;
struct drm_i915_private *dev_priv = dev->dev_private;
struct fb_info *info;
struct drm_framebuffer *fb;
struct drm_mode_fb_cmd2 mode_cmd = {}; struct drm_mode_fb_cmd2 mode_cmd = {};
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct device *device = &dev->pdev->dev;
int size, ret; int size, ret;
/* we don't do packed 24bpp */ /* we don't do packed 24bpp */
...@@ -94,8 +90,6 @@ static int intelfb_create(struct drm_fb_helper *helper, ...@@ -94,8 +90,6 @@ static int intelfb_create(struct drm_fb_helper *helper,
goto out; goto out;
} }
mutex_lock(&dev->struct_mutex);
/* Flush everything out, we'll be doing GTT only from now on */ /* Flush everything out, we'll be doing GTT only from now on */
ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
if (ret) { if (ret) {
...@@ -103,7 +97,49 @@ static int intelfb_create(struct drm_fb_helper *helper, ...@@ -103,7 +97,49 @@ static int intelfb_create(struct drm_fb_helper *helper,
goto out_unref; goto out_unref;
} }
info = framebuffer_alloc(0, device); ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, obj);
if (ret)
goto out_unpin;
return 0;
out_unpin:
i915_gem_object_unpin(obj);
out_unref:
drm_gem_object_unreference(&obj->base);
out:
return ret;
}
static int intelfb_create(struct drm_fb_helper *helper,
struct drm_fb_helper_surface_size *sizes)
{
struct intel_fbdev *ifbdev =
container_of(helper, struct intel_fbdev, helper);
struct intel_framebuffer *intel_fb = &ifbdev->ifb;
struct drm_device *dev = helper->dev;
struct drm_i915_private *dev_priv = dev->dev_private;
struct fb_info *info;
struct drm_framebuffer *fb;
struct drm_i915_gem_object *obj;
int size, ret;
mutex_lock(&dev->struct_mutex);
if (!intel_fb->obj) {
DRM_ERROR("no BIOS fb, allocating a new one\n");
ret = intelfb_alloc(helper, sizes);
if (ret)
goto out_unlock;
} else {
sizes->fb_width = intel_fb->base.width;
sizes->fb_height = intel_fb->base.height;
}
obj = intel_fb->obj;
size = obj->base.size;
info = framebuffer_alloc(0, &dev->pdev->dev);
if (!info) { if (!info) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_unpin; goto out_unpin;
...@@ -111,10 +147,6 @@ static int intelfb_create(struct drm_fb_helper *helper, ...@@ -111,10 +147,6 @@ static int intelfb_create(struct drm_fb_helper *helper,
info->par = helper; info->par = helper;
ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, obj);
if (ret)
goto out_unpin;
fb = &ifbdev->ifb.base; fb = &ifbdev->ifb.base;
ifbdev->helper.fb = fb; ifbdev->helper.fb = fb;
...@@ -170,17 +202,15 @@ static int intelfb_create(struct drm_fb_helper *helper, ...@@ -170,17 +202,15 @@ static int intelfb_create(struct drm_fb_helper *helper,
fb->width, fb->height, fb->width, fb->height,
i915_gem_obj_ggtt_offset(obj), obj); i915_gem_obj_ggtt_offset(obj), obj);
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
vga_switcheroo_client_fb_set(dev->pdev, info); vga_switcheroo_client_fb_set(dev->pdev, info);
return 0; return 0;
out_unpin: out_unpin:
i915_gem_object_unpin(obj); i915_gem_object_unpin(obj);
out_unref:
drm_gem_object_unreference(&obj->base); drm_gem_object_unreference(&obj->base);
out_unlock:
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
out:
return ret; return ret;
} }
......
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