DRM: Add DRM kms/fb cma helper
Subsystems (2)
PATCH v2 1/1 DRM: Add DRM kms/fb cma helper
This patch introduces a set of helper function for implementing the KMS framebuffer layer for drivers which use the drm gem CMA helper function.
---
Changes since v1:
* Some spelling fixes
* Add missing kfree in drm_fb_cma_alloc error path
* Add multi-plane support. drm_fb_cma_get_gem_obj now takes a second parameter to specify the plane.
--- drivers/gpu/drm/Kconfig | 11 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_fb_cma_helper.c | 384 +++++++++++++++++++++++++++++++++++ include/drm/drm_fb_cma_helper.h | 27 +++ 4 files changed, 423 insertions(+) create mode 100644 drivers/gpu/drm/drm_fb_cma_helper.c create mode 100644 include/drm/drm_fb_cma_helper.h
drivers/gpu/drm/Kconfig +11 -0
@@ -41,6 +41,17 @@ config DRM_GEM_CMA_HELPER help Choose this if you need the GEM cma helper functions +config DRM_KMS_CMA_HELPER + tristate + select DRM_GEM_CMA_HELPER + select DRM_KMS_HELPER + select FB_SYS_FILLRECT + select FB_SYS_COPYAREA + select FB_SYS_IMAGEBLIT + help + Choose this if you need the KMS cma helper functions + + config DRM_TDFX tristate "3dfx Banshee/Voodoo3+" depends on DRM && PCI
drivers/gpu/drm/Makefile +1 -0
@@ -18,6 +18,7 @@ drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o drm_kms_helper-y := drm_fb_helper.o drm_crtc_helper.o drm_dp_i2c_helper.o +drm_kms_helper-$(CONFIG_DRM_KMS_CMA_HELPER) += drm_fb_cma_helper.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o
drivers/gpu/drm/drm_fb_cma_helper.c new file +384 -0
384 lines not on this page · raw message
include/drm/drm_fb_cma_helper.h new file +27 -0
@@ -0,0 +1,27 @@ +#ifndef __DRM_FB_CMA_HELPER_H__ +#define __DRM_FB_CMA_HELPER_H__ + +struct drm_fbdev_cma ; +struct drm_gem_cma_obj ; + +struct drm_framebuffer ; +struct drm_device ; +struct drm_file ; +struct drm_mode_fb_cmd2 ; + +struct drm_fbdev_cma *drm_fbdev_cma_init (struct drm_device *dev, +unsigned int preferred_bpp,unsigned int num_crtc, +unsigned int max_conn_count); +void drm_fbdev_cma_fini (struct drm_fbdev_cma *fbdev_cma); + +void drm_fbdev_cma_restore_mode (struct drm_fbdev_cma *fbdev_cma); +void drm_fbdev_cma_hotplug_event (struct drm_fbdev_cma *fbdev_cma); + +struct drm_framebuffer *drm_fb_cma_create (struct drm_device *dev, +struct drm_file *file_priv,struct drm_mode_fb_cmd2 *mode_cmd); + +struct drm_gem_cma_obj *drm_fb_cma_get_gem_obj (struct drm_framebuffer *fb, +unsigned int plane); + +#endif +
Signature · 1 line
1.7.10
Quoted 80 lines · Lars-Peter Clausen
This patch introduces a set of helper function for implementing the KMS framebuffer layer for drivers which use the drm gem CMA helper function.
Signed-off-by Lars-Peter Clausen <[email protected]>---
Changes since v1:
* Some spelling fixes
* Add missing kfree indrm_fb_cma_allocerror path
* Add multi-plane support.drm_fb_cma_get_gem_objnow takes a second parameter to specify the plane.--- drivers/gpu/drm/Kconfig | 11 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_fb_cma_helper.c | 384 +++++++++++++++++++++++++++++++++++ include/drm/drm_fb_cma_helper.h | 27 +++ 4 files changed, 423 insertions(+) create mode 100644 drivers/gpu/drm/drm_fb_cma_helper.c create mode 100644 include/drm/drm_fb_cma_helper.hdrivers/gpu/drm/Kconfig +11
-0@@ -41,6 +41,17 @@ config DRM_GEM_CMA_HELPER help Choose this if you need the GEM cma helper functions +config DRM_KMS_CMA_HELPER + tristate + select DRM_GEM_CMA_HELPER + select DRM_KMS_HELPER + select FB_SYS_FILLRECT + select FB_SYS_COPYAREA + select FB_SYS_IMAGEBLIT + help + Choose this if you need the KMS cma helper functions + + config DRM_TDFX tristate "3dfx Banshee/Voodoo3+" depends on DRM && PCIdrivers/gpu/drm/Makefile +1
-0@@ -18,6 +18,7 @@ drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o drm_kms_helper-y := drm_fb_helper.o drm_crtc_helper.o drm_dp_i2c_helper.o +drm_kms_helper-$(CONFIG_DRM_KMS_CMA_HELPER) += drm_fb_cma_helper.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.odrivers/gpu/drm/drm_fb_cma_helper.c new file +20
-0@@ -0,0 +1,384 @@ +/* +* drm kms/fb cma (contiguous memory allocator) helper functions +* +* Copyright (C) 2012 Analog Device Inc. +* Author: Lars-Peter Clausen <[email protected]> +* +* Based on udl_fbdev.c +* Copyright (C) 2012 Red Hat +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <drm/drmP.h>
drivers/gpu/drm/drm_fb_cma_helper.c line 30
Quoted 10 lines
drivers/gpu/drm/drm_fb_cma_helper.c new file +10
-0+#include <drm/drm_crtc.h> +#include <drm/drm_fb_helper.h> +#include <drm/drm_crtc_helper.h> +#include <drm/drm_gem_cma_helper.h> +#include <drm/drm_fb_cma_helper.h> +#include <linux/module.h> + +struct drm_fb_cma { +struct drm_framebuffer fb; +struct drm_gem_cma_obj *obj[4 ];
Can we have a define for this magic '4'? It is used several times in this patch.
Quoted 13 lines
drivers/gpu/drm/drm_fb_cma_helper.c new file +13
-0+static struct drm_fb_cma *drm_fb_cma_alloc (struct drm_device *dev, +struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_cma_obj **obj, +unsigned int num_planes) +{ +struct drm_fb_cma *fb_cma; +int ret; +int i; + + fb_cma =kzalloc (sizeof (*fb_cma),GFP_KERNEL ); +if (!fb_cma) +return ERR_PTR (-ENOMEM ); + + ret =drm_framebuffer_init (dev, &fb_cma->fb, &drm_fb_cma_funcs);
drivers/gpu/drm/drm_fb_cma_helper.c line 98
Quoted 10 lines
drivers/gpu/drm/drm_fb_cma_helper.c new file +10
-0+if (ret) { +dev_err (dev->dev,"Failed to initalize framebuffer: %d\n" , ret); +kfree (fb_cma); +return ERR_PTR (ret); + } + +drm_helper_mode_fill_fb_struct (&fb_cma->fb, mode_cmd); + +for (i =0 ; i < num_planes; i++) + fb_cma->obj[i] = obj[i];
Check for valid num_planes before this loop?
Note I have renamed struct drm_gem_cma_obj to struct drm_gem_cma_object in the patch I just sent.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 86 lines · Sascha Hauer
Quoted 85 lines · Lars-Peter Clausen
This patch introduces a set of helper function for implementing the KMS framebuffer layer for drivers which use the drm gem CMA helper function.
Signed-off-by Lars-Peter Clausen <[email protected]>---
Changes since v1:
* Some spelling fixes
* Add missing kfree indrm_fb_cma_allocerror path
* Add multi-plane support.drm_fb_cma_get_gem_objnow takes a second parameter to specify the plane.--- drivers/gpu/drm/Kconfig | 11 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_fb_cma_helper.c | 384 +++++++++++++++++++++++++++++++++++ include/drm/drm_fb_cma_helper.h | 27 +++ 4 files changed, 423 insertions(+) create mode 100644 drivers/gpu/drm/drm_fb_cma_helper.c create mode 100644 include/drm/drm_fb_cma_helper.hdrivers/gpu/drm/Kconfig +11
-0@@ -41,6 +41,17 @@ config DRM_GEM_CMA_HELPER help Choose this if you need the GEM cma helper functions +config DRM_KMS_CMA_HELPER + tristate + select DRM_GEM_CMA_HELPER + select DRM_KMS_HELPER + select FB_SYS_FILLRECT + select FB_SYS_COPYAREA + select FB_SYS_IMAGEBLIT + help + Choose this if you need the KMS cma helper functions + + config DRM_TDFX tristate "3dfx Banshee/Voodoo3+" depends on DRM && PCIdrivers/gpu/drm/Makefile +1
-0@@ -18,6 +18,7 @@ drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o drm_kms_helper-y := drm_fb_helper.o drm_crtc_helper.o drm_dp_i2c_helper.o +drm_kms_helper-$(CONFIG_DRM_KMS_CMA_HELPER) += drm_fb_cma_helper.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.odrivers/gpu/drm/drm_fb_cma_helper.c new file +25
-0@@ -0,0 +1,384 @@ +/* +* drm kms/fb cma (contiguous memory allocator) helper functions +* +* Copyright (C) 2012 Analog Device Inc. +* Author: Lars-Peter Clausen <[email protected]> +* +* Based on udl_fbdev.c +* Copyright (C) 2012 Red Hat +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <drm/drmP.h> +#include <drm/drm_crtc.h> +#include <drm/drm_fb_helper.h> +#include <drm/drm_crtc_helper.h> +#include <drm/drm_gem_cma_helper.h> +#include <drm/drm_fb_cma_helper.h>
Quoted 8 lines
drivers/gpu/drm/drm_fb_cma_helper.c line 30
Quoted 5 lines
drivers/gpu/drm/drm_fb_cma_helper.c new file +5
-0+#include <linux/module.h> + +struct drm_fb_cma { +struct drm_framebuffer fb; +struct drm_gem_cma_obj *obj[4 ];Can we have a define for this magic '4'? It is used several times in this patch.
Yes, had the same though. The magic 4 is actually used all through all of DRM. Something like '#define DRM_MAX_PLANES 4' probably makes sense.
Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/drm_fb_cma_helper.c new file +17
-0+static struct drm_fb_cma *drm_fb_cma_alloc (struct drm_device *dev, +struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_cma_obj **obj, +unsigned int num_planes) +{ +struct drm_fb_cma *fb_cma; +int ret; +int i; + + fb_cma =kzalloc (sizeof (*fb_cma),GFP_KERNEL ); +if (!fb_cma) +return ERR_PTR (-ENOMEM ); + + ret =drm_framebuffer_init (dev, &fb_cma->fb, &drm_fb_cma_funcs); +if (ret) { +dev_err (dev->dev,"Failed to initalize framebuffer: %d\n" , ret); +kfree (fb_cma); +return ERR_PTR (ret);
Quoted 9 lines
drivers/gpu/drm/drm_fb_cma_helper.c line 98
Quoted 6 lines
drivers/gpu/drm/drm_fb_cma_helper.c new file +6
-0+ } + +drm_helper_mode_fill_fb_struct (&fb_cma->fb, mode_cmd); + +for (i =0 ; i < num_planes; i++) + fb_cma->obj[i] = obj[i];Check for valid
num_planesbefore this loop?
Hm, I think the callers already take care of this. drm_format_num_planes will always return a valid number and the other caller passes 1 unconditionally.
Quoted 4 lines
Note I have renamed struct
drm_gem_cma_objto structdrm_gem_cma_objectin the patch I just sent.
Do you think it makes sense for you to carry this patch as part of your iMX DRM series?
Thanks,
- Lars
Quoted 10 lines · Lars-Peter Clausen
Quoted 7 lines
drivers/gpu/drm/drm_fb_cma_helper.c line 98
Quoted 4 lines
drivers/gpu/drm/drm_fb_cma_helper.c new file +4
-0+drm_helper_mode_fill_fb_struct (&fb_cma->fb, mode_cmd); + +for (i =0 ; i < num_planes; i++) + fb_cma->obj[i] = obj[i];Check for valid
num_planesbefore this loop?Hm, I think the callers already take care of this.
drm_format_num_planeswill always return a valid number and the other caller passes 1 unconditionally.
As long as the array always is big enough to hold the maximum number of planes I think it's fine. However, if there is some format with 5 planes (don't know if there is, I only know yuv with multiple planes) it's not obvious that this code does not support this.
Quoted 8 lines
Quoted 5 lines
Note I have renamed struct
drm_gem_cma_objto structdrm_gem_cma_objectin the patch I just sent.Do you think it makes sense for you to carry this patch as part of your iMX DRM series?
I can carry this, but it could be that Laurent has his driver in an acceptable state earlier. Let's see.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 9 lines · Sascha Hauer
Quoted 8 lines · Lars-Peter Clausen
Quoted 7 lines
drivers/gpu/drm/drm_fb_cma_helper.c line 98
Quoted 4 lines
drivers/gpu/drm/drm_fb_cma_helper.c new file +4
-0+drm_helper_mode_fill_fb_struct (&fb_cma->fb, mode_cmd); + +for (i =0 ; i < num_planes; i++) + fb_cma->obj[i] = obj[i];Check for valid
num_planesbefore this loop?
Quoted 7 lines
Quoted 2 lines
Hm, I think the callers already take care of this.
drm_format_num_planeswill always return a valid number and the other caller passes 1 unconditionally.As long as the array always is big enough to hold the maximum number of planes I think it's fine. However, if there is some format with 5 planes (don't know if there is, I only know yuv with multiple planes) it's not obvious that this code does not support this.
The DRM ABI limits the number of planes to 4. But adding a global DRM_MAX_PLANES is probably a good idea to avoid surprises if this ever changes.