Skip to content

Commit 5ed7191

Browse files
author
Thomas Zimmermann
committed
drm/ast: Replace struct ast_framebuffer with GEM framebuffer helpers
The ast driver's struct ast_framebuffer is a buffer object with GEM interface. There are already GEM framebuffer helpers that implement the same functionality. Convert ast to these. Signed-off-by: Thomas Zimmermann <[email protected]> Acked-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 66ab700 commit 5ed7191

File tree

4 files changed

+22
-104
lines changed

4 files changed

+22
-104
lines changed

drivers/gpu/drm/ast/ast_drv.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,8 @@ struct ast_encoder {
239239
struct drm_encoder base;
240240
};
241241

242-
struct ast_framebuffer {
243-
struct drm_framebuffer base;
244-
struct drm_gem_object *obj;
245-
};
246-
247242
struct ast_fbdev {
248243
struct drm_fb_helper helper; /* must be first */
249-
struct ast_framebuffer afb;
250244
void *sysram;
251245
int size;
252246
int x1, y1, x2, y2; /* dirty rect */
@@ -256,7 +250,6 @@ struct ast_fbdev {
256250
#define to_ast_crtc(x) container_of(x, struct ast_crtc, base)
257251
#define to_ast_connector(x) container_of(x, struct ast_connector, base)
258252
#define to_ast_encoder(x) container_of(x, struct ast_encoder, base)
259-
#define to_ast_framebuffer(x) container_of(x, struct ast_framebuffer, base)
260253

261254
struct ast_vbios_stdtable {
262255
u8 misc;
@@ -296,11 +289,6 @@ struct ast_vbios_mode_info {
296289
extern int ast_mode_init(struct drm_device *dev);
297290
extern void ast_mode_fini(struct drm_device *dev);
298291

299-
int ast_framebuffer_init(struct drm_device *dev,
300-
struct ast_framebuffer *ast_fb,
301-
const struct drm_mode_fb_cmd2 *mode_cmd,
302-
struct drm_gem_object *obj);
303-
304292
int ast_fbdev_init(struct drm_device *dev);
305293
void ast_fbdev_fini(struct drm_device *dev);
306294
void ast_fbdev_set_suspend(struct drm_device *dev, int state);

drivers/gpu/drm/ast/ast_fb.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838

3939
#include <drm/drmP.h>
4040
#include <drm/drm_crtc.h>
41+
#include <drm/drm_crtc_helper.h>
4142
#include <drm/drm_fb_helper.h>
43+
#include <drm/drm_gem_framebuffer_helper.h>
4244
#include <drm/drm_util.h>
43-
#include <drm/drm_crtc_helper.h>
4445

4546
#include "ast_drv.h"
4647

@@ -50,15 +51,16 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,
5051
int i;
5152
struct drm_gem_vram_object *gbo;
5253
int src_offset, dst_offset;
53-
int bpp = afbdev->afb.base.format->cpp[0];
5454
int ret;
5555
u8 *dst;
5656
bool unmap = false;
5757
bool store_for_later = false;
5858
int x2, y2;
5959
unsigned long flags;
60+
struct drm_framebuffer *fb = afbdev->helper.fb;
61+
int bpp = fb->format->cpp[0];
6062

61-
gbo = drm_gem_vram_of_gem(afbdev->afb.obj);
63+
gbo = drm_gem_vram_of_gem(fb->obj[0]);
6264

6365
if (drm_can_sleep()) {
6466
/* We pin the BO so it won't be moved during the
@@ -116,8 +118,7 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,
116118

117119
for (i = y; i <= y2; i++) {
118120
/* assume equal stride for now */
119-
src_offset = dst_offset =
120-
i * afbdev->afb.base.pitches[0] + (x * bpp);
121+
src_offset = dst_offset = i * fb->pitches[0] + (x * bpp);
121122
memcpy_toio(dst + dst_offset, afbdev->sysram + src_offset,
122123
(x2 - x + 1) * bpp);
123124
}
@@ -222,14 +223,15 @@ static int astfb_create(struct drm_fb_helper *helper,
222223
ret = PTR_ERR(info);
223224
goto out;
224225
}
225-
ret = ast_framebuffer_init(dev, &afbdev->afb, &mode_cmd, gobj);
226-
if (ret)
226+
fb = drm_gem_fbdev_fb_create(dev, sizes, 0, gobj, NULL);
227+
if (IS_ERR(fb)) {
228+
ret = PTR_ERR(fb);
227229
goto out;
230+
}
228231

229232
afbdev->sysram = sysram;
230233
afbdev->size = size;
231234

232-
fb = &afbdev->afb.base;
233235
afbdev->helper.fb = fb;
234236

235237
info->fbops = &astfb_ops;
@@ -261,20 +263,13 @@ static const struct drm_fb_helper_funcs ast_fb_helper_funcs = {
261263
static void ast_fbdev_destroy(struct drm_device *dev,
262264
struct ast_fbdev *afbdev)
263265
{
264-
struct ast_framebuffer *afb = &afbdev->afb;
265-
266266
drm_helper_force_disable_all(dev);
267267
drm_fb_helper_unregister_fbi(&afbdev->helper);
268268

269-
if (afb->obj) {
270-
drm_gem_object_put_unlocked(afb->obj);
271-
afb->obj = NULL;
272-
}
273269
drm_fb_helper_fini(&afbdev->helper);
270+
drm_framebuffer_put(afbdev->helper.fb);
274271

275272
vfree(afbdev->sysram);
276-
drm_framebuffer_unregister_private(&afb->base);
277-
drm_framebuffer_cleanup(&afb->base);
278273
}
279274

280275
int ast_fbdev_init(struct drm_device *dev)

drivers/gpu/drm/ast/ast_main.c

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
#include <drm/drmP.h>
2929
#include "ast_drv.h"
3030

31-
32-
#include <drm/drm_fb_helper.h>
3331
#include <drm/drm_crtc_helper.h>
32+
#include <drm/drm_fb_helper.h>
33+
#include <drm/drm_gem_framebuffer_helper.h>
3434

3535
void ast_set_index_reg_mask(struct ast_private *ast,
3636
uint32_t base, uint8_t index,
@@ -383,67 +383,8 @@ static int ast_get_dram_info(struct drm_device *dev)
383383
return 0;
384384
}
385385

386-
static void ast_user_framebuffer_destroy(struct drm_framebuffer *fb)
387-
{
388-
struct ast_framebuffer *ast_fb = to_ast_framebuffer(fb);
389-
390-
drm_gem_object_put_unlocked(ast_fb->obj);
391-
drm_framebuffer_cleanup(fb);
392-
kfree(ast_fb);
393-
}
394-
395-
static const struct drm_framebuffer_funcs ast_fb_funcs = {
396-
.destroy = ast_user_framebuffer_destroy,
397-
};
398-
399-
400-
int ast_framebuffer_init(struct drm_device *dev,
401-
struct ast_framebuffer *ast_fb,
402-
const struct drm_mode_fb_cmd2 *mode_cmd,
403-
struct drm_gem_object *obj)
404-
{
405-
int ret;
406-
407-
drm_helper_mode_fill_fb_struct(dev, &ast_fb->base, mode_cmd);
408-
ast_fb->obj = obj;
409-
ret = drm_framebuffer_init(dev, &ast_fb->base, &ast_fb_funcs);
410-
if (ret) {
411-
DRM_ERROR("framebuffer init failed %d\n", ret);
412-
return ret;
413-
}
414-
return 0;
415-
}
416-
417-
static struct drm_framebuffer *
418-
ast_user_framebuffer_create(struct drm_device *dev,
419-
struct drm_file *filp,
420-
const struct drm_mode_fb_cmd2 *mode_cmd)
421-
{
422-
struct drm_gem_object *obj;
423-
struct ast_framebuffer *ast_fb;
424-
int ret;
425-
426-
obj = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
427-
if (obj == NULL)
428-
return ERR_PTR(-ENOENT);
429-
430-
ast_fb = kzalloc(sizeof(*ast_fb), GFP_KERNEL);
431-
if (!ast_fb) {
432-
drm_gem_object_put_unlocked(obj);
433-
return ERR_PTR(-ENOMEM);
434-
}
435-
436-
ret = ast_framebuffer_init(dev, ast_fb, mode_cmd, obj);
437-
if (ret) {
438-
drm_gem_object_put_unlocked(obj);
439-
kfree(ast_fb);
440-
return ERR_PTR(ret);
441-
}
442-
return &ast_fb->base;
443-
}
444-
445386
static const struct drm_mode_config_funcs ast_mode_funcs = {
446-
.fb_create = ast_user_framebuffer_create,
387+
.fb_create = drm_gem_fb_create
447388
};
448389

449390
static u32 ast_get_vram_info(struct drm_device *dev)

drivers/gpu/drm/ast/ast_mode.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -526,27 +526,21 @@ static int ast_crtc_do_set_base(struct drm_crtc *crtc,
526526
int x, int y, int atomic)
527527
{
528528
struct ast_private *ast = crtc->dev->dev_private;
529-
struct drm_gem_object *obj;
530-
struct ast_framebuffer *ast_fb;
531529
struct drm_gem_vram_object *gbo;
532530
int ret;
533531
s64 gpu_addr;
534532
void *base;
535533

536534
if (!atomic && fb) {
537-
ast_fb = to_ast_framebuffer(fb);
538-
obj = ast_fb->obj;
539-
gbo = drm_gem_vram_of_gem(obj);
535+
gbo = drm_gem_vram_of_gem(fb->obj[0]);
540536

541537
/* unmap if console */
542-
if (&ast->fbdev->afb == ast_fb)
538+
if (ast->fbdev->helper.fb == fb)
543539
drm_gem_vram_kunmap(gbo);
544540
drm_gem_vram_unpin(gbo);
545541
}
546542

547-
ast_fb = to_ast_framebuffer(crtc->primary->fb);
548-
obj = ast_fb->obj;
549-
gbo = drm_gem_vram_of_gem(obj);
543+
gbo = drm_gem_vram_of_gem(crtc->primary->fb->obj[0]);
550544

551545
ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM);
552546
if (ret)
@@ -557,7 +551,7 @@ static int ast_crtc_do_set_base(struct drm_crtc *crtc,
557551
goto err_drm_gem_vram_unpin;
558552
}
559553

560-
if (&ast->fbdev->afb == ast_fb) {
554+
if (ast->fbdev->helper.fb == crtc->primary->fb) {
561555
/* if pushing console in kmap it */
562556
base = drm_gem_vram_kmap(gbo, true, NULL);
563557
if (IS_ERR(base)) {
@@ -625,12 +619,12 @@ static void ast_crtc_disable(struct drm_crtc *crtc)
625619
ast_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
626620
if (crtc->primary->fb) {
627621
struct ast_private *ast = crtc->dev->dev_private;
628-
struct ast_framebuffer *ast_fb = to_ast_framebuffer(crtc->primary->fb);
629-
struct drm_gem_object *obj = ast_fb->obj;
630-
struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(obj);
622+
struct drm_framebuffer *fb = crtc->primary->fb;
623+
struct drm_gem_vram_object *gbo =
624+
drm_gem_vram_of_gem(fb->obj[0]);
631625

632626
/* unmap if console */
633-
if (&ast->fbdev->afb == ast_fb)
627+
if (ast->fbdev->helper.fb == fb)
634628
drm_gem_vram_kunmap(gbo);
635629
drm_gem_vram_unpin(gbo);
636630
}

0 commit comments

Comments
 (0)