DRM: add drm gem CMA helper
Subsystems (2)
PATCH 1/1 DRM: add drm gem CMA helper
Many embedded drm devices do not have a IOMMU and no dedicated memory for graphics. These devices use CMA (Contiguous Memory Allocator) backed graphics memory. This patch provides helper functions to be able to share the code. The code technically does not depend on CMA as the backend allocator, the name has been chosen because cma makes for a nice, short but still descriptive function prefix.
---
changes since v2:
- make drm_gem_cma_create_with_handle static
- use DIV_ROUND_UP(args->width * args->bpp, 8) to calculate the pitch
- make drm_gem_cma_vm_ops const
- add missing #include <linux/export.h>
changes since v1:
- map whole buffer at mmap time, not page by page at fault time
- several cleanups as suggested by Lars-Peter Clausen and Laurent Pinchart
drivers/gpu/drm/Kconfig | 6 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_gem_cma_helper.c | 250 ++++++++++++++++++++++++++++++++++ include/drm/drm_gem_cma_helper.h | 44 ++++++ 4 files changed, 301 insertions(+) create mode 100644 drivers/gpu/drm/drm_gem_cma_helper.c create mode 100644 include/drm/drm_gem_cma_helper.h
drivers/gpu/drm/Kconfig +6 -0
@@ -53,6 +53,12 @@ config DRM_TTM GPU memory types. Will be enabled automatically if a device driver uses it. +config DRM_GEM_CMA_HELPER + tristate + depends on DRM + help + Choose this if you need the GEM CMA helper functions + config DRM_TDFX tristate "3dfx Banshee/Voodoo3+" depends on DRM && PCI
drivers/gpu/drm/Makefile +1 -0
@@ -15,6 +15,7 @@ drm-y := drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \ drm_trace_points.o drm_global.o drm_prime.o drm-$(CONFIG_COMPAT) += drm_ioc32.o +drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o drm-usb-y := drm_usb.o
drivers/gpu/drm/drm_gem_cma_helper.c new file +250 -0
250 lines not on this page · raw message
include/drm/drm_gem_cma_helper.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
1.7.10
Hi Sascha,
Thanks for the patch.
Quoted 14 lines · On Wednesday 27 June 2012 15:00:05 Sascha Hauer wrote:
Many embedded drm devices do not have a IOMMU and no dedicated memory for graphics. These devices use CMA (Contiguous Memory Allocator) backed graphics memory. This patch provides helper functions to be able to share the code. The code technically does not depend on CMA as the backend allocator, the name has been chosen because cma makes for a nice, short but still descriptive function prefix.
Signed-off-by Sascha Hauer <[email protected]>---
changes since v2:
- makedrm_gem_cma_create_with_handlestatic
- useDIV_ROUND_UP(args->width * args->bpp, 8)to calculate the pitch
[snip]
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/gpu/drm/drm_gem_cma_helper.cnew file mode 100644 index 0000000..417f45e5drivers/gpu/drm/drm_gem_cma_helper.c new file +0
-0@@ -0,0 +1,250 @@
[snip]
drivers/gpu/drm/drm_gem_cma_helper.c line 24
Quoted 5 lines
drivers/gpu/drm/drm_gem_cma_helper.c new file +5
-0+#include <linux/mm.h> +#include <linux/slab.h> +#include <linux/mutex.h> +#include <linux/export.h> +#include <linux/dma-mapping.h>
Nitpicking, I usually sort headers alphabetically, that helps locating duplicates quickly. It's not mandatory though.
[snip]
Quoted 4 lines
drivers/gpu/drm/drm_gem_cma_helper.c new file +4
-0+/* +* drm_gem_cma_dumb_create - (struct drm_driver)->dumb_create callback +* function +*
drivers/gpu/drm/drm_gem_cma_helper.c line 169
Quoted 10 lines
drivers/gpu/drm/drm_gem_cma_helper.c new file +10
-0+* This aligns the pitch and size arguments to the minimum required. wrap +* this into your own function if you need bigger alignment. +*/ +int drm_gem_cma_dumb_create (struct drm_file *file_priv, +struct drm_device *dev,struct drm_mode_create_dumb *args) +{ +struct drm_gem_cma_object *cma_obj; + +if (args->pitch < args->width *DIV_ROUND_UP (args->bpp,8 )) + args->pitch = args->width *DIV_ROUND_UP (args->bpp,8 );
It's nice to mention in the changelog that you fixed the problem, but it would be even nicer to really fix it ;-)
Quoted 12 lines
drivers/gpu/drm/drm_gem_cma_helper.c new file +12
-0+ +if (args->size < args->pitch * args->height) + args->size = args->pitch * args->height; + + cma_obj =drm_gem_cma_create_with_handle (file_priv, dev, + args->size, &args->handle); +if (IS_ERR (cma_obj)) +return PTR_ERR (cma_obj); + +return 0 ; +} +EXPORT_SYMBOL_GPL (drm_gem_cma_dumb_create);
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 51 lines · Laurent Pinchart
Hi Sascha,
Thanks for the patch.
Quoted 14 lines · On Wednesday 27 June 2012 15:00:05 Sascha Hauer wrote:
Many embedded drm devices do not have a IOMMU and no dedicated memory for graphics. These devices use CMA (Contiguous Memory Allocator) backed graphics memory. This patch provides helper functions to be able to share the code. The code technically does not depend on CMA as the backend allocator, the name has been chosen because cma makes for a nice, short but still descriptive function prefix.
Signed-off-by Sascha Hauer <[email protected]>---
changes since v2:
- makedrm_gem_cma_create_with_handlestatic
- useDIV_ROUND_UP(args->width * args->bpp, 8)to calculate the pitch[snip]
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/gpu/drm/drm_gem_cma_helper.cnew file mode 100644 index 0000000..417f45e5drivers/gpu/drm/drm_gem_cma_helper.c new file +0
-0@@ -0,0 +1,250 @@[snip]
drivers/gpu/drm/drm_gem_cma_helper.c line 24
Quoted 5 lines
drivers/gpu/drm/drm_gem_cma_helper.c new file +5
-0+#include <linux/mm.h> +#include <linux/slab.h> +#include <linux/mutex.h> +#include <linux/export.h> +#include <linux/dma-mapping.h> Nitpicking, I usually sort headers alphabetically, that helps locating duplicates quickly. It's not mandatory though.
[snip]
Quoted 9 lines
drivers/gpu/drm/drm_gem_cma_helper.c new file +9
-0+/* +* drm_gem_cma_dumb_create - (struct drm_driver)->dumb_create callback +* function +* +* This aligns the pitch and size arguments to the minimum required. wrap +* this into your own function if you need bigger alignment. +*/ +int drm_gem_cma_dumb_create (struct drm_file *file_priv, +struct drm_device *dev,struct drm_mode_create_dumb *args)
Quoted 8 lines
drivers/gpu/drm/drm_gem_cma_helper.c line 169
Quoted 5 lines
drivers/gpu/drm/drm_gem_cma_helper.c new file +5
-0+{ +struct drm_gem_cma_object *cma_obj; + +if (args->pitch < args->width *DIV_ROUND_UP (args->bpp,8 )) + args->pitch = args->width *DIV_ROUND_UP (args->bpp,8 );It's nice to mention in the changelog that you fixed the problem, but it would be even nicer to really fix it ;-)
Damn ;)
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 |