Commit 957a2d0e authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/gma500: Allocate GTT ranges in stolen memory with psb_gem_create()

Support private objects for stolen memory in psb_gem_create() and
convert users to psb_gem_create(). For stolen memory, psb_gem_create()
now initializes the GEM object via drm_gem_private_object_init().

In the fbdev setup, replace the open-coded initialization of struct
gtt_range with a call to psb_gem_create(). Use drm_gem_object_put()
for release.

In the cursor setup, use psb_gem_create() and get a real GEM object.
Previously the allocated instance of struct gtt_range was only partially
initialized. Release the cursor GEM object in gma_crtc_destroy(). The
release was missing from the original code.

With the conversion of all callers to psb_gem_create(), the extern
declarations of psb_gtt_alloc_range, psb_gtt_free_range and
psb_gem_object_func are not required any longer. Declare them as
static.
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Acked-by: default avatarPatrik Jakobsson <patrik.r.jakobsson@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20211015084053.13708-5-tzimmermann@suse.de
parent 576d4d2d
......@@ -224,31 +224,6 @@ static struct drm_framebuffer *psb_framebuffer_create
return fb;
}
/**
* psbfb_alloc - allocate frame buffer memory
* @dev: the DRM device
* @aligned_size: space needed
*
* Allocate the frame buffer. In the usual case we get a GTT range that
* is stolen memory backed and life is simple. If there isn't sufficient
* we fail as we don't have the virtual mapping space to really vmap it
* and the kernel console code can't handle non linear framebuffers.
*
* Re-address this as and if the framebuffer layer grows this ability.
*/
static struct gtt_range *psbfb_alloc(struct drm_device *dev, int aligned_size)
{
struct gtt_range *backing;
/* Begin by trying to use stolen memory backing */
backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1, PAGE_SIZE);
if (backing) {
backing->gem.funcs = &psb_gem_object_funcs;
drm_gem_private_object_init(dev, &backing->gem, aligned_size);
return backing;
}
return NULL;
}
/**
* psbfb_create - create a framebuffer
* @fb_helper: the framebuffer helper
......@@ -268,6 +243,7 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
int size;
int ret;
struct gtt_range *backing;
struct drm_gem_object *obj;
u32 bpp, depth;
mode_cmd.width = sizes->surface_width;
......@@ -285,24 +261,25 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
size = ALIGN(size, PAGE_SIZE);
/* Allocate the framebuffer in the GTT with stolen page backing */
backing = psbfb_alloc(dev, size);
if (backing == NULL)
return -ENOMEM;
backing = psb_gem_create(dev, size, "fb", true, PAGE_SIZE);
if (IS_ERR(backing))
return PTR_ERR(backing);
obj = &backing->gem;
memset(dev_priv->vram_addr + backing->offset, 0, size);
info = drm_fb_helper_alloc_fbi(fb_helper);
if (IS_ERR(info)) {
ret = PTR_ERR(info);
goto out;
goto err_drm_gem_object_put;
}
mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
fb = psb_framebuffer_create(dev, &mode_cmd, &backing->gem);
fb = psb_framebuffer_create(dev, &mode_cmd, obj);
if (IS_ERR(fb)) {
ret = PTR_ERR(fb);
goto out;
goto err_drm_gem_object_put;
}
fb_helper->fb = fb;
......@@ -333,8 +310,9 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
dev_dbg(dev->dev, "allocated %dx%d fb\n", fb->width, fb->height);
return 0;
out:
psb_gtt_free_range(dev, backing);
err_drm_gem_object_put:
drm_gem_object_put(obj);
return ret;
}
......
......@@ -101,7 +101,7 @@ void psb_gtt_unpin(struct gtt_range *gt)
mutex_unlock(&dev_priv->gtt_mutex);
}
void psb_gtt_free_range(struct drm_device *dev, struct gtt_range *gt)
static void psb_gtt_free_range(struct drm_device *dev, struct gtt_range *gt)
{
/* Undo the mmap pin if we are destroying the object */
if (gt->mmapping) {
......@@ -133,13 +133,13 @@ static const struct vm_operations_struct psb_gem_vm_ops = {
.close = drm_gem_vm_close,
};
const struct drm_gem_object_funcs psb_gem_object_funcs = {
static const struct drm_gem_object_funcs psb_gem_object_funcs = {
.free = psb_gem_free_object,
.vm_ops = &psb_gem_vm_ops,
};
struct gtt_range *psb_gtt_alloc_range(struct drm_device *dev, int len,
const char *name, int backed, u32 align)
static struct gtt_range *psb_gtt_alloc_range(struct drm_device *dev, int len,
const char *name, int backed, u32 align)
{
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
struct gtt_range *gt;
......@@ -193,12 +193,16 @@ psb_gem_create(struct drm_device *dev, u64 size, const char *name, bool stolen,
obj->funcs = &psb_gem_object_funcs;
ret = drm_gem_object_init(dev, obj, size);
if (ret)
goto err_psb_gtt_free_range;
if (stolen) {
drm_gem_private_object_init(dev, obj, size);
} else {
ret = drm_gem_object_init(dev, obj, size);
if (ret)
goto err_psb_gtt_free_range;
/* Limit the object to 32-bit mappings */
mapping_set_gfp_mask(obj->filp->f_mapping, GFP_KERNEL | __GFP_DMA32);
/* Limit the object to 32-bit mappings */
mapping_set_gfp_mask(obj->filp->f_mapping, GFP_KERNEL | __GFP_DMA32);
}
return gt;
......
......@@ -12,14 +12,9 @@
struct drm_device;
extern const struct drm_gem_object_funcs psb_gem_object_funcs;
struct gtt_range *
psb_gem_create(struct drm_device *dev, u64 size, const char *name, bool stolen, u32 align);
struct gtt_range *psb_gtt_alloc_range(struct drm_device *dev, int len, const char *name,
int backed, u32 align);
void psb_gtt_free_range(struct drm_device *dev, struct gtt_range *gt);
int psb_gtt_pin(struct gtt_range *gt);
void psb_gtt_unpin(struct gtt_range *gt);
......
......@@ -498,6 +498,9 @@ void gma_crtc_destroy(struct drm_crtc *crtc)
{
struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
if (gma_crtc->cursor_gt)
drm_gem_object_put(&gma_crtc->cursor_gt->gem);
kfree(gma_crtc->crtc_state);
drm_crtc_cleanup(crtc);
kfree(gma_crtc);
......
......@@ -461,9 +461,8 @@ static void psb_intel_cursor_init(struct drm_device *dev,
/* Allocate 4 pages of stolen mem for a hardware cursor. That
* is enough for the 64 x 64 ARGB cursors we support.
*/
cursor_gt = psb_gtt_alloc_range(dev, 4 * PAGE_SIZE, "cursor", 1,
PAGE_SIZE);
if (!cursor_gt) {
cursor_gt = psb_gem_create(dev, 4 * PAGE_SIZE, "cursor", true, PAGE_SIZE);
if (IS_ERR(cursor_gt)) {
gma_crtc->cursor_gt = NULL;
goto out;
}
......
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