drm: Add shmem GEM library
Subsystems (3)
v3 cover drm: Add shmem GEM library
This patchset adds a library for shmem backed GEM objects and makes use of it in tinydrm.
When I made tinydrm I used the CMA helper because it was very easy to use. July last year I learned that this limits which drivers to PRIME import from, since CMA requires continuous memory. tinydrm drivers don't require that. So I set out to change that looking first at shmem, but that wasn't working since shmem didn't work with fbdev deferred I/O. Then I did a vmalloc buffer attempt which worked with deferred I/O, but maybe wouldn't be of so much use as a library for other drivers to use. As my work to split out stuff from the CMA helper for shared use came to an end, I had a generic fbdev emulation that uses a shadow buffer for deferred I/O.
This means that I can now use shmem buffers after all.
I have looked at the other drivers that use drm_gem_get_pages() and several supports different cache modes so I've done that even though tinydrm only uses the cached one.
tinydrm can both use vmalloc and shmem buffers, it doesn't matter as far as I can see. So the question is what will benefit the rest of DRM the most.
Note:
Sparse has this complaint, but the problem is in kvmalloc_array():include/linux/mm.h:592:13: error: undefined identifier '__builtin_mul_overflow'
Noralf.
Changes since version 2:
- Grammar (Sam Ravnborg)
- s/drm_gem_shmem_put_pages_unlocked/drm_gem_shmem_put_pages_locked/ (Sam Ravnborg)
- Add debug ouput in error path (Sam Ravnborg)
Changes since version 1:
- Fix missing argument in docs (kbuild test robot)
- Fix: sparse: expression using sizeof(void) (kbuild test robot)
- Rebasing gave a new checkpatch warning, so I changed to bitfields:
CHECK: Avoid using bool structure members because of possible alignment issues - see: https://lkml.org/lkml/2017/11/21/384
#834: FILE: include/drm/drm_gem_shmem_helper.h:84:
+ bool pages_mark_dirty_on_put;
#841: FILE: include/drm/drm_gem_shmem_helper.h:91:
+ bool pages_mark_accessed_on_put;
Noralf Trønnes (2):
drm: Add library for shmem backed GEM objects
drm/tinydrm: Switch from CMA to shmem buffers
Documentation/gpu/drm-kms-helpers.rst | 12 + drivers/gpu/drm/Kconfig | 6 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_gem_shmem_helper.c | 678 +++++++++++++++++++++++++ drivers/gpu/drm/tinydrm/Kconfig | 2 +- drivers/gpu/drm/tinydrm/core/tinydrm-core.c | 91 +--- drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 5 + drivers/gpu/drm/tinydrm/ili9225.c | 14 +- drivers/gpu/drm/tinydrm/ili9341.c | 6 +- drivers/gpu/drm/tinydrm/mi0283qt.c | 6 +- drivers/gpu/drm/tinydrm/mipi-dbi.c | 38 +- drivers/gpu/drm/tinydrm/repaper.c | 24 +- drivers/gpu/drm/tinydrm/st7586.c | 15 +- drivers/gpu/drm/tinydrm/st7735r.c | 6 +- include/drm/drm_gem_shmem_helper.h | 198 ++++++++ include/drm/tinydrm/tinydrm.h | 36 +- 16 files changed, 984 insertions(+), 154 deletions(-) create mode 100644 drivers/gpu/drm/drm_gem_shmem_helper.c create mode 100644 include/drm/drm_gem_shmem_helper.h
Signature · 6 lines
2.15.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 1/2 drm: Add library for shmem backed GEM objects
This adds a library for shmem backed GEM objects with the necessary drm_driver callbacks.
---
Changes since version 2:
- Grammar (Sam Ravnborg)
- s/drm_gem_shmem_put_pages_unlocked/drm_gem_shmem_put_pages_locked/ (Sam Ravnborg)
- Add debug ouput in error path (Sam Ravnborg)
Changes since version 1:
- Fix missing argument in docs (kbuild test robot)
- Fix: sparse: expression using sizeof(void) (kbuild test robot)
- Rebasing gave a new checkpatch warning, so I changed to bitfields:
CHECK: Avoid using bool structure members because of possible alignment issues - see: https://lkml.org/lkml/2017/11/21/384
#834: FILE: include/drm/drm_gem_shmem_helper.h:84:
+ bool pages_mark_dirty_on_put;
#841: FILE: include/drm/drm_gem_shmem_helper.h:91:
+ bool pages_mark_accessed_on_put;
Documentation/gpu/drm-kms-helpers.rst | 12 + drivers/gpu/drm/Kconfig | 6 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_gem_shmem_helper.c | 678 +++++++++++++++++++++++++++++++++ include/drm/drm_gem_shmem_helper.h | 198 ++++++++++ 5 files changed, 895 insertions(+) create mode 100644 drivers/gpu/drm/drm_gem_shmem_helper.c create mode 100644 include/drm/drm_gem_shmem_helper.h
Documentation/gpu/drm-kms-helpers.rst +12 -0
@@ -326,3 +326,15 @@ Legacy CRTC/Modeset Helper Functions Reference .. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c :export: + +SHMEM GEM Helper Reference +========================== + +.. kernel-doc:: drivers/gpu/drm/drm_gem_shmem_helper.c + :doc: overview + +.. kernel-doc:: include/drm/drm_gem_shmem_helper.h + :internal: + +.. kernel-doc:: drivers/gpu/drm/drm_gem_shmem_helper.c + :export:
drivers/gpu/drm/Kconfig +6 -0
@@ -157,6 +157,12 @@ config DRM_KMS_CMA_HELPER help Choose this if you need the KMS CMA helper functions +config DRM_GEM_SHMEM_HELPER + bool + depends on DRM + help + Choose this if you need the GEM shmem helper functions + config DRM_VM bool depends on DRM && MMU
drivers/gpu/drm/Makefile +1 -0
@@ -24,6 +24,7 @@ drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o drm-$(CONFIG_DRM_VM) += drm_vm.o drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o +drm-$(CONFIG_DRM_GEM_SHMEM_HELPER) += drm_gem_shmem_helper.o drm-$(CONFIG_PCI) += ati_pcigart.o drm-$(CONFIG_DRM_PANEL) += drm_panel.o drm-$(CONFIG_OF) += drm_of.o
drivers/gpu/drm/drm_gem_shmem_helper.c new file +678 -0
678 lines not on this page · raw message
include/drm/drm_gem_shmem_helper.h new file +198 -0
198 lines not on this page · raw message
Signature · 6 lines
2.15.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 1/2] drm: Add library for shmem backed GEM objects
Quoted 6 lines · Noralf Trønnes
This adds a library for shmem backed GEM objects with the necessary
drm_drivercallbacks.Signed-off-by Noralf Trønnes <[email protected]>---
...
Quoted 27 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +27
-0+static int drm_gem_shmem_vmap_locked (struct drm_gem_shmem_object *shmem) +{ +struct drm_gem_object *obj = &shmem->base; +int ret; + +if (shmem->vmap_use_count++ >0 ) +return 0 ; + + ret =drm_gem_shmem_get_pages (shmem); +if (ret) + goto err_zero_use; + +if (obj->import_attach) { + shmem->vaddr =dma_buf_vmap (obj->import_attach->dmabuf); + }else { +pgprot_t prot; + +switch (shmem->cache_mode) { +case DRM_GEM_SHMEM_BO_UNKNOWN : +DRM_DEBUG_KMS ("Can't vmap cache mode is unknown\n" ); + ret = -EINVAL ; + goto err_put_pages; + +case DRM_GEM_SHMEM_BO_WRITECOMBINED : + prot =pgprot_writecombine (PAGE_KERNEL ); +break ; +
drivers/gpu/drm/drm_gem_shmem_helper.c line 220
Quoted 10 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +10
-0+case DRM_GEM_SHMEM_BO_UNCACHED : + prot =pgprot_noncached (PAGE_KERNEL ); +break ; + +case DRM_GEM_SHMEM_BO_CACHED : + prot =PAGE_KERNEL ; +break ; + } + + shmem->vaddr =vmap (shmem->pages, obj->size >>PAGE_SHIFT ,VM_MAP , prot);
I get a gcc warning here:
/home/david/work/ev3dev2/ev3dev-kernel/drivers/gpu/drm/drm_gem_shmem_helper.c:220:18: warning: ‘prot’ may be used uninitialized in this function [-Wmaybe-uninitialized]
shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT, VM_MAP, prot);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/david/work/ev3dev2/ev3dev-kernel/drivers/gpu/drm/drm_gem_shmem_helper.c:199:12: note: ‘prot’ was declared here
pgprot_t prot;
^~~~---
And since I am making a comment anyway, it is not clear to me what BO means in the enum names. I didn't see any hints in the doc comments either.
Quoted 7 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +7
-0+ } + +if (!shmem->vaddr) { +DRM_DEBUG_KMS ("Failed to vmap pages\n" ); + ret = -ENOMEM ; + goto err_put_pages; + }
drivers/gpu/drm/drm_gem_shmem_helper.c line 237
Quoted 10 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +10
-0+ +return 0 ; + +err_put_pages: +drm_gem_shmem_put_pages (shmem); +err_zero_use: + shmem->vmap_use_count =0 ; + +return ret; +}
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 1/2] drm: Add library for shmem backed GEM objects
Quoted 50 lines · David Lechner
Quoted 6 lines · Noralf Trønnes
This adds a library for shmem backed GEM objects with the necessary
drm_drivercallbacks.Signed-off-by Noralf Trønnes <[email protected]>---
...
Quoted 27 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +27
-0+static int drm_gem_shmem_vmap_locked (struct drm_gem_shmem_object *shmem) +{ +struct drm_gem_object *obj = &shmem->base; +int ret; + +if (shmem->vmap_use_count++ >0 ) +return 0 ; + + ret =drm_gem_shmem_get_pages (shmem); +if (ret) + goto err_zero_use; + +if (obj->import_attach) { + shmem->vaddr =dma_buf_vmap (obj->import_attach->dmabuf); + }else { +pgprot_t prot; + +switch (shmem->cache_mode) { +case DRM_GEM_SHMEM_BO_UNKNOWN : +DRM_DEBUG_KMS ("Can't vmap cache mode is unknown\n" ); + ret = -EINVAL ; + goto err_put_pages; + +case DRM_GEM_SHMEM_BO_WRITECOMBINED : + prot =pgprot_writecombine (PAGE_KERNEL ); +break ; +drivers/gpu/drm/drm_gem_shmem_helper.c line 220
Quoted 10 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +10
-0+case DRM_GEM_SHMEM_BO_UNCACHED : + prot =pgprot_noncached (PAGE_KERNEL ); +break ; + +case DRM_GEM_SHMEM_BO_CACHED : + prot =PAGE_KERNEL ; +break ; + } + + shmem->vaddr =vmap (shmem->pages, obj->size >>PAGE_SHIFT ,VM_MAP , prot);I get a gcc warning here:
Quoted 6 lines
/home/david/work/ev3dev2/ev3dev-kernel/drivers/gpu/drm/drm_gem_shmem_helper.c:220:18: warning: ‘prot’ may be used uninitialized in this function [-Wmaybe-uninitialized]shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT, VM_MAP, prot); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/david/work/ev3dev2/ev3dev-kernel/drivers/gpu/drm/drm_gem_shmem_helper.c:199:12: note: ‘prot’ was declared here pgprot_t prot; ^~~~
This warning is saying that the vmap could be reached without hitting any cases in the switch, which is technically true if one sets the cache_mode to some garbage, but not if only existing enums from enum drm_gem_shmem_cache_mode are used.
I think we should just add a default: next to the DRM_GEM_SHMEM_BO_UNKNOWN case.
Quoted 6 lines
---
And since I am making a comment anyway, it is not clear to me what BO means in the enum names. I didn't see any hints in the doc comments either.
Buffer Object, but yeah I guess it's not necessary in the enum names.
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +13
-0+ } + +if (!shmem->vaddr) { +DRM_DEBUG_KMS ("Failed to vmap pages\n" ); + ret = -ENOMEM ; + goto err_put_pages; + } + +return 0 ; + +err_put_pages: +drm_gem_shmem_put_pages (shmem); +err_zero_use:
Quoted 8 lines
drivers/gpu/drm/drm_gem_shmem_helper.c line 237
Quoted 4 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +4
-0+ shmem->vmap_use_count =0 ; + +return ret; +}_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 1/2] drm: Add library for shmem backed GEM objects
Den 14.09.2018 12.10, skrev Eric Engestrom:
Quoted 63 lines · David Lechner
Quoted 48 lines · Noralf Trønnes
Quoted 6 lines
This adds a library for shmem backed GEM objects with the necessary
drm_drivercallbacks.Signed-off-by Noralf Trønnes <[email protected]>---
...
Quoted 27 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +27
-0+static int drm_gem_shmem_vmap_locked (struct drm_gem_shmem_object *shmem) +{ +struct drm_gem_object *obj = &shmem->base; +int ret; + +if (shmem->vmap_use_count++ >0 ) +return 0 ; + + ret =drm_gem_shmem_get_pages (shmem); +if (ret) + goto err_zero_use; + +if (obj->import_attach) { + shmem->vaddr =dma_buf_vmap (obj->import_attach->dmabuf); + }else { +pgprot_t prot; + +switch (shmem->cache_mode) { +case DRM_GEM_SHMEM_BO_UNKNOWN : +DRM_DEBUG_KMS ("Can't vmap cache mode is unknown\n" ); + ret = -EINVAL ; + goto err_put_pages; + +case DRM_GEM_SHMEM_BO_WRITECOMBINED : + prot =pgprot_writecombine (PAGE_KERNEL ); +break ; +drivers/gpu/drm/drm_gem_shmem_helper.c line 220
Quoted 10 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +10
-0+case DRM_GEM_SHMEM_BO_UNCACHED : + prot =pgprot_noncached (PAGE_KERNEL ); +break ; + +case DRM_GEM_SHMEM_BO_CACHED : + prot =PAGE_KERNEL ; +break ; + } + + shmem->vaddr =vmap (shmem->pages, obj->size >>PAGE_SHIFT ,VM_MAP , prot);I get a gcc warning here:
Quoted 6 lines
/home/david/work/ev3dev2/ev3dev-kernel/drivers/gpu/drm/drm_gem_shmem_helper.c:220:18: warning: ‘prot’ may be used uninitialized in this function [-Wmaybe-uninitialized]shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT, VM_MAP, prot); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/david/work/ev3dev2/ev3dev-kernel/drivers/gpu/drm/drm_gem_shmem_helper.c:199:12: note: ‘prot’ was declared here pgprot_t prot; ^~~~This warning is saying that the vmap could be reached without hitting any cases in the switch, which is technically true if one sets the
cache_modeto some garbage, but not if only existing enums fromenum drm_gem_shmem_cache_modeare used.I think we should just add a
default:next to theDRM_GEM_SHMEM_BO_UNKNOWNcase.
Quoted 6 lines
Quoted 5 lines
---
And since I am making a comment anyway, it is not clear to me what BO means in the enum names. I didn't see any hints in the doc comments either.
Buffer Object, but yeah I guess it's not necessary in the enum names.
Yeah, the helper was called drm_shem_bo_helper in an earlier version, forgot to remove the BO from the enum.
Noralf.
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +13
-0+ } + +if (!shmem->vaddr) { +DRM_DEBUG_KMS ("Failed to vmap pages\n" ); + ret = -ENOMEM ; + goto err_put_pages; + } + +return 0 ; + +err_put_pages: +drm_gem_shmem_put_pages (shmem); +err_zero_use:
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_gem_shmem_helper.c line 237
Quoted 4 lines
drivers/gpu/drm/drm_gem_shmem_helper.c new file +4
-0+ shmem->vmap_use_count =0 ; + +return ret; +}_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 2/2 drm/tinydrm: Switch from CMA to shmem buffers
In reply to Noralf TrønnesThis move makes tinydrm useful for more drivers. tinydrm doesn't need continuous memory, but at the time it was convenient to use the CMA library. The spi core can do dma on is_vmalloc() addresses making this possible.
--- drivers/gpu/drm/tinydrm/Kconfig | 2 +- drivers/gpu/drm/tinydrm/core/tinydrm-core.c | 91 +++++++------------------- drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 5 ++ drivers/gpu/drm/tinydrm/ili9225.c | 14 ++-- drivers/gpu/drm/tinydrm/ili9341.c | 6 +- drivers/gpu/drm/tinydrm/mi0283qt.c | 6 +- drivers/gpu/drm/tinydrm/mipi-dbi.c | 38 ++++------- drivers/gpu/drm/tinydrm/repaper.c | 24 +++---- drivers/gpu/drm/tinydrm/st7586.c | 15 +++-- drivers/gpu/drm/tinydrm/st7735r.c | 6 +- include/drm/tinydrm/tinydrm.h | 36 +++------- 11 files changed, 89 insertions(+), 154 deletions(-)
drivers/gpu/drm/tinydrm/Kconfig +1 -1
@@ -2,7 +2,7 @@ menuconfig DRM_TINYDRM tristate "Support for simple displays" depends on DRM select DRM_KMS_HELPER - select DRM_KMS_CMA_HELPER + select DRM_GEM_SHMEM_HELPER help Choose this option if you have a tinydrm supported display. If M is selected the module will be called tinydrm.
drivers/gpu/drm/tinydrm/core/tinydrm-core.c +23 -68
120 lines not on this page · raw message
drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +5 -0
@@ -9,12 +9,17 @@#include <linux/backlight.h> #include <linux/dma-buf.h> +#include <linux/module.h> #include <linux/pm.h> #include <linux/spi/spi.h> #include <linux/swab.h> +#include <drm/drm_device.h> +#include <drm/drm_drv.h> +#include <drm/drm_fourcc.h> #include <drm/tinydrm/tinydrm.h> #include <drm/tinydrm/tinydrm-helpers.h> +#include <drm/drm_print.h> static unsigned int spi_max;module_param (spi_max, uint,0400 );
drivers/gpu/drm/tinydrm/ili9225.c +9 -5
@@ -20,8 +20,11 @@#include <linux/spi/spi.h> #include <video/mipi_display.h> +#include <drm/drm_drv.h> #include <drm/drm_fb_helper.h> +#include <drm/drm_fourcc.h> #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/tinydrm/mipi-dbi.h> #include <drm/tinydrm/tinydrm-helpers.h>
@@ -77,7 +80,8 @@ static int ili9225_fb_dirty(struct drm_framebuffer *fb, unsigned int color, struct drm_clip_rect *clips, unsigned int num_clips) { - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); + struct drm_gem_object *gem = drm_gem_fb_get_obj(fb, 0); +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (gem);struct tinydrm_device *tdev = fb->dev->dev_private;struct mipi_dbi *mipi =mipi_dbi_from_tinydrm (tdev);bool swap = mipi->swap_bytes;
@@ -104,7 +108,7 @@ static int ili9225_fb_dirty(struct drm_framebuffer *fb,if (ret)return ret; }else { - tr = cma_obj->vaddr; + tr = shmem->vaddr; }switch (mipi->rotation) {
@@ -157,7 +161,7 @@ static int ili9225_fb_dirty(struct drm_framebuffer *fb, }static const struct drm_framebuffer_funcs ili9225_fb_funcs = { - .destroy = drm_gem_fb_destroy, + .destroy = tinydrm_fb_destroy, .create_handle = drm_gem_fb_create_handle, .dirty = tinydrm_fb_dirty, };
@@ -361,13 +365,13 @@ static const struct drm_display_mode ili9225_mode = {TINYDRM_MODE (176 ,220 ,35 ,44 ), }; -DEFINE_DRM_GEM_CMA_FOPS (ili9225_fops); +DEFINE_DRM_GEM_SHMEM_FOPS (ili9225_fops);static struct drm_driver ili9225_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_ATOMIC , .fops = &ili9225_fops, -TINYDRM_GEM_DRIVER_OPS , +DRM_GEM_SHMEM_DRIVER_OPS , .name ="ili9225" , .desc ="Ilitek ILI9225" , .date = "20171106",
drivers/gpu/drm/tinydrm/ili9341.c +4 -2
@@ -15,8 +15,10 @@#include <linux/property.h> #include <linux/spi/spi.h> +#include <drm/drm_drv.h> #include <drm/drm_fb_helper.h> #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_modeset_helper.h> #include <drm/tinydrm/mipi-dbi.h> #include <drm/tinydrm/tinydrm-helpers.h>
@@ -139,12 +141,12 @@ static const struct drm_display_mode yx240qv29_mode = {TINYDRM_MODE (240 ,320 ,37 ,49 ), }; -DEFINE_DRM_GEM_CMA_FOPS (ili9341_fops); +DEFINE_DRM_GEM_SHMEM_FOPS (ili9341_fops);static struct drm_driver ili9341_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_ATOMIC , .fops = &ili9341_fops, -TINYDRM_GEM_DRIVER_OPS , +DRM_GEM_SHMEM_DRIVER_OPS , .debugfs_init = mipi_dbi_debugfs_init, .name ="ili9341" , .desc = "Ilitek ILI9341",
drivers/gpu/drm/tinydrm/mi0283qt.c +4 -2
@@ -17,9 +17,11 @@#include <linux/regulator/consumer.h> #include <linux/spi/spi.h> +#include <drm/drm_drv.h> #include <drm/drm_fb_helper.h> #include <drm/drm_modeset_helper.h> #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/tinydrm/mipi-dbi.h> #include <drm/tinydrm/tinydrm-helpers.h> #include <video/mipi_display.h>
@@ -147,13 +149,13 @@ static const struct drm_display_mode mi0283qt_mode = {TINYDRM_MODE (320 ,240 ,58 ,43 ), }; -DEFINE_DRM_GEM_CMA_FOPS (mi0283qt_fops); +DEFINE_DRM_GEM_SHMEM_FOPS (mi0283qt_fops);static struct drm_driver mi0283qt_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_ATOMIC , .fops = &mi0283qt_fops, -TINYDRM_GEM_DRIVER_OPS , +DRM_GEM_SHMEM_DRIVER_OPS , .debugfs_init = mipi_dbi_debugfs_init, .name ="mi0283qt" , .desc = "Multi-Inno MI0283QT",
drivers/gpu/drm/tinydrm/mipi-dbi.c +13 -25
@@ -9,10 +9,15 @@* (at your option) any later version. */ +#include <drm/drm_device.h> +#include <drm/drm_drv.h> +#include <drm/drm_fourcc.h> #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/tinydrm/mipi-dbi.h> #include <drm/tinydrm/tinydrm-helpers.h> #include <linux/debugfs.h> +#include <linux/delay.h> #include <linux/dma-buf.h> #include <linux/gpio/consumer.h> #include <linux/module.h>
@@ -167,10 +172,11 @@ EXPORT_SYMBOL(mipi_dbi_command_buf);int mipi_dbi_buf_copy (void *dst,struct drm_framebuffer *fb,struct drm_clip_rect *clip,bool swap) { -struct drm_gem_cma_object *cma_obj =drm_fb_cma_get_gem_obj (fb,0 ); -struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; +struct drm_gem_object *gem =drm_gem_fb_get_obj (fb,0 ); +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (gem); +struct dma_buf_attachment *import_attach = gem->import_attach;struct drm_format_name_buf format_name; -void *src = cma_obj->vaddr; +void *src = shmem->vaddr;int ret =0 ;if (import_attach) {
@@ -210,7 +216,8 @@ static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb,struct drm_clip_rect *clips, unsigned int num_clips) { - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); + struct drm_gem_object *gem = drm_gem_fb_get_obj(fb, 0); +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (gem);struct tinydrm_device *tdev = fb->dev->dev_private;struct mipi_dbi *mipi =mipi_dbi_from_tinydrm (tdev);bool swap = mipi->swap_bytes;
@@ -235,7 +242,7 @@ static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb,if (ret)return ret; }else { - tr = cma_obj->vaddr; + tr = shmem->vaddr; } mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS,
@@ -252,7 +259,7 @@ static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb, }static const struct drm_framebuffer_funcs mipi_dbi_fb_funcs = { - .destroy = drm_gem_fb_destroy, + .destroy = tinydrm_fb_destroy, .create_handle = drm_gem_fb_create_handle, .dirty = tinydrm_fb_dirty, };
@@ -882,31 +889,12 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi, {size_t tx_size =tinydrm_spi_max_transfer_size (spi,0 );struct device *dev = &spi->dev; -int ret;if (tx_size <16 ) {DRM_ERROR ("SPI transmit buffer too small: %zu\n" , tx_size);return -EINVAL ; } -/* -* Even though it's not the SPI device that does DMA (the master does), -* the dma mask is necessary for the dma_alloc_wc() in -* drm_gem_cma_create(). The dma_addr returned will be a physical -* adddress which might be different from the bus address, but this is -* not a problem since the address will not be used. -* The virtual address is used in the transfer and the SPI core -* re-maps it on the SPI master device using the DMA streaming API -* (spi_map_buf()). -*/ -if (!dev->coherent_dma_mask) { - ret =dma_coerce_mask_and_coherent (dev,DMA_BIT_MASK (32 )); -if (ret) { -dev_warn (dev,"Failed to set dma mask %d\n" , ret); -return ret; - } - } - mipi->spi = spi; mipi->read_commands = mipi_dbi_dcs_read_commands;
drivers/gpu/drm/tinydrm/repaper.c +9 -15
@@ -26,7 +26,9 @@#include <linux/spi/spi.h> #include <linux/thermal.h> +#include <drm/drm_drv.h> #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/tinydrm/tinydrm.h> #include <drm/tinydrm/tinydrm-helpers.h>
@@ -526,8 +528,9 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb,struct drm_clip_rect *clips, unsigned int num_clips) { - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); -struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; + struct drm_gem_object *gem = drm_gem_fb_get_obj(fb, 0); +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (gem); +struct dma_buf_attachment *import_attach = gem->import_attach;struct tinydrm_device *tdev = fb->dev->dev_private;struct repaper_epd *epd =epd_from_tinydrm (tdev);struct drm_clip_rect clip;
@@ -559,7 +562,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, goto out_free; } -tinydrm_xrgb8888_to_gray8 (buf, cma_obj->vaddr, fb, &clip); +tinydrm_xrgb8888_to_gray8 (buf, shmem->vaddr, fb, &clip);if (import_attach) { ret = dma_buf_end_cpu_access(import_attach->dmabuf,
@@ -624,7 +627,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, }static const struct drm_framebuffer_funcs repaper_fb_funcs = { - .destroy = drm_gem_fb_destroy, + .destroy = tinydrm_fb_destroy, .create_handle = drm_gem_fb_create_handle, .dirty = tinydrm_fb_dirty, };
@@ -876,13 +879,13 @@ static const struct drm_display_mode repaper_e2271cs021_mode = {static const u8 repaper_e2271cs021_cs[] = {0x00 ,0x00 ,0x00 ,0x7f ,0xff ,0xfe ,0x00 ,0x00 }; -DEFINE_DRM_GEM_CMA_FOPS (repaper_fops); +DEFINE_DRM_GEM_SHMEM_FOPS (repaper_fops);static struct drm_driver repaper_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_ATOMIC , .fops = &repaper_fops, -TINYDRM_GEM_DRIVER_OPS , +DRM_GEM_SHMEM_DRIVER_OPS , .name ="repaper" , .desc ="Pervasive Displays RePaper e-ink panels" , .date ="20170405" ,
@@ -929,15 +932,6 @@ static int repaper_probe(struct spi_device *spi) model = spi_id->driver_data; } -/* The SPI device is used to allocate dma memory */ -if (!dev->coherent_dma_mask) { - ret =dma_coerce_mask_and_coherent (dev,DMA_BIT_MASK (32 )); -if (ret) { -dev_warn (dev,"Failed to set dma mask %d\n" , ret); -return ret; - } - } - epd =devm_kzalloc (dev,sizeof (*epd),GFP_KERNEL );if (!epd)return -ENOMEM ;
drivers/gpu/drm/tinydrm/st7586.c +9 -6
@@ -17,8 +17,10 @@#include <linux/spi/spi.h> #include <video/mipi_display.h> +#include <drm/drm_drv.h> #include <drm/drm_fb_helper.h> #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/tinydrm/mipi-dbi.h> #include <drm/tinydrm/tinydrm-helpers.h>
@@ -88,9 +90,10 @@ static void st7586_xrgb8888_to_gray332(u8 *dst, void *vaddr,static int st7586_buf_copy (void *dst,struct drm_framebuffer *fb,struct drm_clip_rect *clip) { -struct drm_gem_cma_object *cma_obj =drm_fb_cma_get_gem_obj (fb,0 ); -struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; -void *src = cma_obj->vaddr; +struct drm_gem_object *gem =drm_gem_fb_get_obj (fb,0 ); +struct dma_buf_attachment *import_attach = gem->import_attach; +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (gem); +void *src = shmem->vaddr;int ret =0 ;if (import_attach) {
@@ -156,7 +159,7 @@ static int st7586_fb_dirty(struct drm_framebuffer *fb, }static const struct drm_framebuffer_funcs st7586_fb_funcs = { - .destroy = drm_gem_fb_destroy, + .destroy = tinydrm_fb_destroy, .create_handle = drm_gem_fb_create_handle, .dirty = tinydrm_fb_dirty, };
@@ -297,13 +300,13 @@ static const struct drm_display_mode st7586_mode = {TINYDRM_MODE (178 ,128 ,37 ,27 ), }; -DEFINE_DRM_GEM_CMA_FOPS (st7586_fops); +DEFINE_DRM_GEM_SHMEM_FOPS (st7586_fops);static struct drm_driver st7586_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_ATOMIC , .fops = &st7586_fops, -TINYDRM_GEM_DRIVER_OPS , +DRM_GEM_SHMEM_DRIVER_OPS , .debugfs_init = mipi_dbi_debugfs_init, .name ="st7586" , .desc = "Sitronix ST7586",
drivers/gpu/drm/tinydrm/st7735r.c +4 -2
@@ -14,8 +14,10 @@#include <linux/spi/spi.h> #include <video/mipi_display.h> +#include <drm/drm_drv.h> #include <drm/drm_fb_helper.h> #include <drm/drm_gem_framebuffer_helper.h> +#include <drm/drm_gem_shmem_helper.h> #include <drm/tinydrm/mipi-dbi.h> #include <drm/tinydrm/tinydrm-helpers.h>
@@ -113,13 +115,13 @@ static const struct drm_display_mode jd_t18003_t01_mode = {TINYDRM_MODE (128 ,160 ,28 ,35 ), }; -DEFINE_DRM_GEM_CMA_FOPS (st7735r_fops); +DEFINE_DRM_GEM_SHMEM_FOPS (st7735r_fops);static struct drm_driver st7735r_driver = { .driver_features =DRIVER_GEM |DRIVER_MODESET |DRIVER_PRIME |DRIVER_ATOMIC , .fops = &st7735r_fops, -TINYDRM_GEM_DRIVER_OPS , +DRM_GEM_SHMEM_DRIVER_OPS , .debugfs_init = mipi_dbi_debugfs_init, .name ="st7735r" , .desc = "Sitronix ST7735R",
include/drm/tinydrm/tinydrm.h +8 -28
@@ -10,10 +10,15 @@#ifndef __LINUX_TINYDRM_H#define __LINUX_TINYDRM_H -#include <drm/drm_gem_cma_helper.h> -#include <drm/drm_fb_cma_helper.h> +#include <linux/mutex.h> #include <drm/drm_simple_kms_helper.h> +struct drm_driver ; +struct drm_framebuffer ; +struct drm_file ; +struct drm_clip_rect ; +struct drm_framebuffer_funcs ; +/** * struct tinydrm_device - tinydrm device */
@@ -53,27 +58,6 @@ pipe_to_tinydrm(struct drm_simple_display_pipe *pipe) return container_of(pipe, struct tinydrm_device, pipe); } -/** -* TINYDRM_GEM_DRIVER_OPS - default tinydrm gem operations -* -* This macro provides a shortcut for setting the tinydrm GEM operations in -* the &drm_driver structure. -*/ -#define TINYDRM_GEM_DRIVER_OPS \ - .gem_free_object_unlocked = tinydrm_gem_cma_free_object, \ - .gem_print_info = drm_gem_cma_print_info, \ - .gem_vm_ops = &drm_gem_cma_vm_ops, \ - .prime_handle_to_fd = drm_gem_prime_handle_to_fd, \ - .prime_fd_to_handle = drm_gem_prime_fd_to_handle, \ - .gem_prime_import = drm_gem_prime_import, \ - .gem_prime_export = drm_gem_prime_export, \ - .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, \ - .gem_prime_import_sg_table = tinydrm_gem_cma_prime_import_sg_table, \ - .gem_prime_vmap = drm_gem_cma_prime_vmap, \ - .gem_prime_vunmap = drm_gem_cma_prime_vunmap, \ - .gem_prime_mmap = drm_gem_cma_prime_mmap, \ - .dumb_create = drm_gem_cma_dumb_create -/** * TINYDRM_MODE - tinydrm display mode * @hd: Horizontal resolution, width
@@ -97,11 +81,7 @@ pipe_to_tinydrm(struct drm_simple_display_pipe *pipe) .type = DRM_MODE_TYPE_DRIVER, \ .clock = 1 /* pass validation */ -void tinydrm_gem_cma_free_object (struct drm_gem_object *gem_obj); -struct drm_gem_object * -tinydrm_gem_cma_prime_import_sg_table (struct drm_device *drm, -struct dma_buf_attachment *attach, -struct sg_table *sgt); +void tinydrm_fb_destroy (struct drm_framebuffer *fb);int devm_tinydrm_init (struct device *parent,struct tinydrm_device *tdev,const struct drm_framebuffer_funcs *fb_funcs,struct drm_driver *driver);
Signature · 6 lines
2.15.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 2/2] drm/tinydrm: Switch from CMA to shmem buffers
Quoted 8 lines · Noralf Trønnes
This move makes tinydrm useful for more drivers. tinydrm doesn't need continuous memory, but at the time it was convenient to use the CMA library. The spi core can do dma on
is_vmalloc()addresses making this possible.Cc David Lechner <[email protected]>Signed-off-by Noralf Trønnes <[email protected]>---
tested on st7586
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi, Noralf,
Quoted 15 lines · Noralf Trønnes
This patchset adds a library for shmem backed GEM objects and makes use of it in tinydrm.
When I made tinydrm I used the CMA helper because it was very easy to use. July last year I learned that this limits which drivers to PRIME import from, since CMA requires continuous memory. tinydrm drivers don't require that. So I set out to change that looking first at shmem, but that wasn't working since shmem didn't work with fbdev deferred I/O. Then I did a vmalloc buffer attempt which worked with deferred I/O, but maybe wouldn't be of so much use as a library for other drivers to use. As my work to split out stuff from the CMA helper for shared use came to an end, I had a generic fbdev emulation that uses a shadow buffer for deferred I/O.
This means that I can now use shmem buffers after all.
Quoted 3 lines
I have looked at the other drivers that use
drm_gem_get_pages()and several supports different cache modes so I've done that even though tinydrm only uses the cached one.
Out if interest, how can you use writecombine and uncached with shared memory? as typically the linear kernel map of the affected pages also needs changing?
Thanks,
Thomas
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 19 lines · Thomas Hellstrom
Hi, Noralf,
Quoted 16 lines · Noralf Trønnes
This patchset adds a library for shmem backed GEM objects and makes use of it in tinydrm.
When I made tinydrm I used the CMA helper because it was very easy to use. July last year I learned that this limits which drivers to PRIME import from, since CMA requires continuous memory. tinydrm drivers don't require that. So I set out to change that looking first at shmem, but that wasn't working since shmem didn't work with fbdev deferred I/O. Then I did a vmalloc buffer attempt which worked with deferred I/O, but maybe wouldn't be of so much use as a library for other drivers to use. As my work to split out stuff from the CMA helper for shared use came to an end, I had a generic fbdev emulation that uses a shadow buffer for deferred I/O.
This means that I can now use shmem buffers after all.
Quoted 8 lines
Quoted 3 lines
I have looked at the other drivers that use
drm_gem_get_pages()and several supports different cache modes so I've done that even though tinydrm only uses the cached one.Out if interest, how can you use writecombine and uncached with shared memory?
as typically the linear kernel map of the affected pages also needs changing?
I think on x86 at least the core code takes care of that. On arm, I'm not sure this just works, since you can't change the mode of the linear map. Instead you need specially allocated memory which is _not_ in the linear map. I guess arm boxes with pcie slots aren't that common yet :-)
-Daniel
Quoted 9 lines
Thanks,
Thomas_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Den 14.09.2018 18.13, skrev Daniel Vetter:
Quoted 26 lines · Thomas Hellstrom
Quoted 18 lines
Hi, Noralf,
Quoted 15 lines · Noralf Trønnes
This patchset adds a library for shmem backed GEM objects and makes use of it in tinydrm.
When I made tinydrm I used the CMA helper because it was very easy to use. July last year I learned that this limits which drivers to PRIME import from, since CMA requires continuous memory. tinydrm drivers don't require that. So I set out to change that looking first at shmem, but that wasn't working since shmem didn't work with fbdev deferred I/O. Then I did a vmalloc buffer attempt which worked with deferred I/O, but maybe wouldn't be of so much use as a library for other drivers to use. As my work to split out stuff from the CMA helper for shared use came to an end, I had a generic fbdev emulation that uses a shadow buffer for deferred I/O.
This means that I can now use shmem buffers after all.Quoted 7 lines
Quoted 3 lines
I have looked at the other drivers that use
drm_gem_get_pages()and several supports different cache modes so I've done that even though tinydrm only uses the cached one.Out if interest, how can you use writecombine and uncached with shared memory?
as typically the linear kernel map of the affected pages also needs changing?
Quoted 5 lines
I think on x86 at least the core code takes care of that. On arm, I'm not sure this just works, since you can't change the mode of the linear map. Instead you need specially allocated memory which is _not_ in the linear map. I guess arm boxes with pcie slots aren't that common yet :-)
I was hoping to get some feedback on these cache mode flags.
These drivers use them:
udl/udl_gem.c
omapdrm/omap_gem.c
msm/msm_gem.c
etnaviv/etnaviv_gem.c
I don't know if they make sense or not, so any help is appreciated.
Noralf.
Quoted 12 lines
-Daniel
Quoted 8 lines
Thanks,
Thomas_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 36 lines · Noralf Trønnes
Den 14.09.2018 18.13, skrev Daniel Vetter:
Quoted 26 lines · Thomas Hellstrom
Quoted 18 lines
Hi, Noralf,
Quoted 15 lines · Noralf Trønnes
This patchset adds a library for shmem backed GEM objects and makes use of it in tinydrm.
When I made tinydrm I used the CMA helper because it was very easy to use. July last year I learned that this limits which drivers to PRIME import from, since CMA requires continuous memory. tinydrm drivers don't require that. So I set out to change that looking first at shmem, but that wasn't working since shmem didn't work with fbdev deferred I/O. Then I did a vmalloc buffer attempt which worked with deferred I/O, but maybe wouldn't be of so much use as a library for other drivers to use. As my work to split out stuff from the CMA helper for shared use came to an end, I had a generic fbdev emulation that uses a shadow buffer for deferred I/O.
This means that I can now use shmem buffers after all.Quoted 7 lines
Quoted 3 lines
I have looked at the other drivers that use
drm_gem_get_pages()and several supports different cache modes so I've done that even though tinydrm only uses the cached one.Out if interest, how can you use writecombine and uncached with shared memory?
as typically the linear kernel map of the affected pages also needs changing?Quoted 5 lines
I think on x86 at least the core code takes care of that. On arm, I'm not sure this just works, since you can't change the mode of the linear map. Instead you need specially allocated memory which is _not_ in the linear map. I guess arm boxes with pcie slots aren't that common yet :-)
I was hoping to get some feedback on these cache mode flags.
Quoted 7 lines
These drivers use them:
udl/udl_gem.c
omapdrm/omap_gem.c
msm/msm_gem.c
etnaviv/etnaviv_gem.cI don't know if they make sense or not, so any help is appreciated.
It's possible, as Daniel says, that the X86 PAT system now automatically tracks all pte inserts and changes the linear kernel map accordingly. It certainly didn't use to do that, so for example TTM does that explicitly. And it's a very slow operation since it involves a global cache- and TLB flush across all cores. So if PAT is doing that on a per-page basis, it's probably bound to be very slow.
The concern with shmem (last time I looked which was a couple of years ago, i admit) was that shmem needs the linear kernel map to copy data in and out when swapping and on hibernate. If the above drivers that you mention don't use shmem, that's all fine, but the combination of shmem and special memory that is NOT mapped in the kernel memory does look a bit odd to me.
/Thomas
Quoted 15 lines
Noralf.
Quoted 12 lines
-Daniel
Quoted 8 lines
Thanks,
Thomas_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Den 14.09.2018 19.11, skrev Thomas Hellstrom:
Quoted 43 lines · Noralf Trønnes
Quoted 42 lines
Den 14.09.2018 18.13, skrev Daniel Vetter:
Quoted 26 lines · Thomas Hellstrom
Quoted 18 lines
Hi, Noralf,
Quoted 15 lines · Noralf Trønnes
This patchset adds a library for shmem backed GEM objects and makes use of it in tinydrm.
When I made tinydrm I used the CMA helper because it was very easy to use. July last year I learned that this limits which drivers to PRIME import from, since CMA requires continuous memory. tinydrm drivers don't require that. So I set out to change that looking first at shmem, but that wasn't working since shmem didn't work with fbdev deferred I/O. Then I did a vmalloc buffer attempt which worked with deferred I/O, but maybe wouldn't be of so much use as a library for other drivers to use. As my work to split out stuff from the CMA helper for shared use came to an end, I had a generic fbdev emulation that uses a shadow buffer for deferred I/O.
This means that I can now use shmem buffers after all.Quoted 7 lines
Quoted 3 lines
I have looked at the other drivers that use
drm_gem_get_pages()and several supports different cache modes so I've done that even though tinydrm only uses the cached one.Out if interest, how can you use writecombine and uncached with shared memory?
as typically the linear kernel map of the affected pages also needs changing?Quoted 5 lines
I think on x86 at least the core code takes care of that. On arm, I'm not sure this just works, since you can't change the mode of the linear map. Instead you need specially allocated memory which is _not_ in the linear map. I guess arm boxes with pcie slots aren't that common yet :-)
I was hoping to get some feedback on these cache mode flags.
These drivers use them:
udl/udl_gem.c
omapdrm/omap_gem.c
msm/msm_gem.c
etnaviv/etnaviv_gem.c
Quoted 6 lines
Quoted 1 line
I don't know if they make sense or not, so any help is appreciated.
It's possible, as Daniel says, that the X86 PAT system now automatically tracks all pte inserts and changes the linear kernel map accordingly. It certainly didn't use to do that, so for example TTM does that explicitly. And it's a very slow operation since it involves a global cache- and TLB flush across all cores. So if PAT is doing that on a per-page basis, it's probably bound to be very slow.
The concern with shmem (last time I looked which was a couple of years ago, i admit) was that shmem needs the linear kernel map to copy data in and out when swapping and on hibernate. If the above drivers that you mention don't use shmem, that's all fine, but the combination of shmem and special memory that is NOT mapped in the kernel memory does look a bit odd to me.
When I started writing this helper I first looked at udl which has different cache modes, but only uses shmem. It does hardcode cache mode to cached though. Based on what you say I'm starting to think that maybe the udl GEM code was just copied from some other driver and not cleaned up properly afterwards.
In addition to shmem, msm and etnaviv use vram and omap uses dma_alloc_wc(). So the cache modes are for distinguishing the memory types I suppose.
They all have this type of code in their *_mmap_obj() function (with the same comment):
if (msm_obj->flags & MSM_BO_WC) {
vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); } else if (msm_obj->flags & MSM_BO_UNCACHED) {
vma->vm_page_prot = pgprot_noncached(vm_get_page_prot(vma->vm_flags)); } else {
/*
* Shunt off cached objs to shmem file so they have their own
* address_space (so unmap_mapping_range does what we want,
* in particular in the case of mmap'd dmabufs)
*/
fput(vma->vm_file);
get_file(obj->filp);
vma->vm_pgoff = 0;
vma->vm_file = obj->filp;
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); }
So now it's starting to make more sense to me. It seems that shmem is the cached mode and that WC and uncached is used for the other memory types.
If I've understood this correctly, it means that I can just drop the cache modes.
Thanks,
Noralf.
Quoted 19 lines
/Thomas
Quoted 15 lines
Noralf.
Quoted 12 lines
-Daniel
Quoted 8 lines
Thanks,
Thomas_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi
Quoted 80 lines · Noralf Trønnes
Den 14.09.2018 19.11, skrev Thomas Hellstrom:
Quoted 43 lines · Noralf Trønnes
Quoted 42 lines
Den 14.09.2018 18.13, skrev Daniel Vetter:
Quoted 26 lines · Thomas Hellstrom
Quoted 18 lines
Hi, Noralf,
Quoted 15 lines · Noralf Trønnes
This patchset adds a library for shmem backed GEM objects and makes use of it in tinydrm.
When I made tinydrm I used the CMA helper because it was very easy to use. July last year I learned that this limits which drivers to PRIME import from, since CMA requires continuous memory. tinydrm drivers don't require that. So I set out to change that looking first at shmem, but that wasn't working since shmem didn't work with fbdev deferred I/O. Then I did a vmalloc buffer attempt which worked with deferred I/O, but maybe wouldn't be of so much use as a library for other drivers to use. As my work to split out stuff from the CMA helper for shared use came to an end, I had a generic fbdev emulation that uses a shadow buffer for deferred I/O.
This means that I can now use shmem buffers after all.Quoted 7 lines
Quoted 3 lines
I have looked at the other drivers that use
drm_gem_get_pages()and several supports different cache modes so I've done that even though tinydrm only uses the cached one.Out if interest, how can you use writecombine and uncached with shared memory?
as typically the linear kernel map of the affected pages also needs changing?Quoted 5 lines
I think on x86 at least the core code takes care of that. On arm, I'm not sure this just works, since you can't change the mode of the linear map. Instead you need specially allocated memory which is _not_ in the linear map. I guess arm boxes with pcie slots aren't that common yet :-)
I was hoping to get some feedback on these cache mode flags.
These drivers use them:
udl/udl_gem.c
omapdrm/omap_gem.c
msm/msm_gem.c
etnaviv/etnaviv_gem.cQuoted 6 lines
Quoted 1 line
I don't know if they make sense or not, so any help is appreciated.
It's possible, as Daniel says, that the X86 PAT system now automatically tracks all pte inserts and changes the linear kernel map accordingly. It certainly didn't use to do that, so for example TTM does that explicitly. And it's a very slow operation since it involves a global cache- and TLB flush across all cores. So if PAT is doing that on a per-page basis, it's probably bound to be very slow.
The concern with shmem (last time I looked which was a couple of years ago, i admit) was that shmem needs the linear kernel map to copy data in and out when swapping and on hibernate. If the above drivers that you mention don't use shmem, that's all fine, but the combination of shmem and special memory that is NOT mapped in the kernel memory does look a bit odd to me.
When I started writing this helper I first looked at udl which has different cache modes, but only uses shmem. It does hardcode cache mode to cached though. Based on what you say I'm starting to think that maybe the udl GEM code was just copied from some other driver and not cleaned up properly afterwards.
In addition to shmem, msm and etnaviv use vram and omap uses
dma_alloc_wc(). So the cache modes are for distinguishing the memory types I suppose.They all have this type of code in their
*_mmap_obj()function (with the same comment):if (
msm_obj->flags&MSM_BO_WC) {
vma->vm_page_prot= pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); } else if (msm_obj->flags&MSM_BO_UNCACHED) {
vma->vm_page_prot= pgprot_noncached(vm_get_page_prot(vma->vm_flags)); } else {
/*
* Shunt off cached objs to shmem file so they have their own
*address_space(sounmap_mapping_rangedoes what we want,
* in particular in the case of mmap'd dmabufs)
*/
fput(vma->vm_file);
get_file(obj->filp);
vma->vm_pgoff= 0;
vma->vm_file =obj->filp;
Quoted 9 lines
vma->vm_page_prot=vm_get_page_prot(vma->vm_flags); }So now it's starting to make more sense to me. It seems that shmem is the cached mode and that WC and uncached is used for the other memory types.
If I've understood this correctly, it means that I can just drop the cache modes.
Yes, I think that might be a good idea, at least until there is a clear understanding how and if the linear kernel map is handled, and it's probably different on each architecture. Best would of course be if we were allowed to set up different mappings to a page with conflicting cache modes...
/Thomas
Quoted 22 lines
Thanks,
Noralf.Quoted 19 lines
/Thomas
Quoted 15 lines
Noralf.
Quoted 12 lines
-Daniel
Quoted 8 lines
Thanks,
Thomas_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel