drm/omap: OMAP_BO flags
Subsystems (3)
v3 cover drm/omap: OMAP_BO flags
A first version of this work had been sent by Tomi Valkeinen in may 2017
(https://www.spinics.net/lists/dri-devel/msg140663.html).
This series adds a few new OMAP_BO flags to help the userspace manage situations where it needs to use lots of buffers, and would currently run out of TILER space. The TILER space is limited to mapping 128MB at any given time and some applications might need more.
This seres is also the opportunity to do some cleanup in the flags and improve the comments describing them.
The user-space patches for libdrm, although ready, haven't been posted yet. It will be be done when this series have been discussed and hopefully in the process of getting merged.
JJ
changes in v3:
- rebase on top of v5.4-rc2
- Document omap_gem_new() and the new flags using the kernel-doc format
changes in v2:
- fixed build error that crept in during rebase before sending (sorry about that)
- rework the refcount part a bit.
Jean-Jacques Hiblot (1):
drm/omap: use refcount API to track the number of users of dma_addr
Tomi Valkeinen (7):
drm/omap: add omap_gem_unpin_locked() drm/omap: accept NULL for dma_addr in omap_gem_pin drm/omap: cleanup OMAP_BO flags
drm/omap: remove OMAP_BO_TILED define drm/omap: cleanup OMAP_BO_SCANOUT use drm/omap: add omap_gem_validate_flags() drm/omap: add OMAP_BO flags to affect buffer allocation
drivers/gpu/drm/omapdrm/omap_dmm_tiler.h | 2 +- drivers/gpu/drm/omapdrm/omap_fb.c | 6 +- drivers/gpu/drm/omapdrm/omap_gem.c | 191 ++++++++++++++++------ drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c | 2 +- include/uapi/drm/omap_drm.h | 27 ++- 5 files changed, 164 insertions(+), 64 deletions(-)
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 1/8 drm/omap: use refcount API to track the number of users of dma_addr
This would give us a WARN_ON() if the pin/unpin calls are unbalanced.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 45 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 22 deletions(-)
drivers/gpu/drm/omapdrm/omap_gem.c +23 -22
@@ -67,7 +67,7 @@ struct omap_gem_object {/** * # of users of dma_addr */ -u32 dma_addr_cnt; +refcount_t dma_addr_cnt;/** * If the buffer has been imported from a dmabuf the OMAP_DB_DMABUF flag
@@ -773,13 +773,15 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)mutex_lock (&omap_obj->lock);if (!omap_gem_is_contiguous (omap_obj) && priv->has_dmm) { -if (omap_obj->dma_addr_cnt ==0 ) { +if (refcount_read (&omap_obj->dma_addr_cnt) ==0 ) {u32 npages = obj->size >>PAGE_SHIFT ;enum tiler_fmt fmt =gem2fmt (omap_obj->flags);struct tiler_block *block;BUG_ON (omap_obj->block); +refcount_set (&omap_obj->dma_addr_cnt,1 ); + ret =omap_gem_attach_pages (obj);if (ret) goto fail;
@@ -813,10 +815,10 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr) omap_obj->block = block;DBG ("got dma address: %pad" , &omap_obj->dma_addr); + }else { +refcount_inc (&omap_obj->dma_addr_cnt); } - omap_obj->dma_addr_cnt++; - *dma_addr = omap_obj->dma_addr; }else if (omap_gem_is_contiguous (omap_obj)) { *dma_addr = omap_obj->dma_addr;
@@ -846,23 +848,21 @@ void omap_gem_unpin(struct drm_gem_object *obj)mutex_lock (&omap_obj->lock); -if (omap_obj->dma_addr_cnt >0 ) { - omap_obj->dma_addr_cnt--; -if (omap_obj->dma_addr_cnt ==0 ) { - ret =tiler_unpin (omap_obj->block); -if (ret) { -dev_err (obj->dev->dev, -"could not unpin pages: %d\n" , ret); - } - ret =tiler_release (omap_obj->block); -if (ret) { -dev_err (obj->dev->dev, -"could not release unmap: %d\n" , ret); - } - omap_obj->dma_addr =0 ; - omap_obj->block =NULL ; +if (refcount_dec_and_test (&omap_obj->dma_addr_cnt)) { + ret =tiler_unpin (omap_obj->block); +if (ret) { +dev_err (obj->dev->dev, +"could not unpin pages: %d\n" , ret); } + ret =tiler_release (omap_obj->block); +if (ret) { +dev_err (obj->dev->dev, +"could not release unmap: %d\n" , ret); + } + omap_obj->dma_addr =0 ; + omap_obj->block =NULL ; } +}mutex_unlock (&omap_obj->lock); }
@@ -879,7 +879,7 @@ int omap_gem_rotated_dma_addr(struct drm_gem_object *obj, u32 orient,mutex_lock (&omap_obj->lock); -if ((omap_obj->dma_addr_cnt >0 ) && omap_obj->block && +if ((refcount_read (&omap_obj->dma_addr_cnt) >0 ) && omap_obj->block && (omap_obj->flags &OMAP_BO_TILED )) { *dma_addr =tiler_tsptr (omap_obj->block, orient, x, y); ret =0 ;
@@ -1030,7 +1030,8 @@ void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m)seq_printf (m,"%08x: %2d (%2d) %08llx %pad (%2d) %p %4d" , omap_obj->flags, obj->name,kref_read (&obj->refcount), - off, &omap_obj->dma_addr, omap_obj->dma_addr_cnt, + off, &omap_obj->dma_addr, +refcount_read (&omap_obj->dma_addr_cnt), omap_obj->vaddr, omap_obj->roll);if (omap_obj->flags &OMAP_BO_TILED ) {
@@ -1093,7 +1094,7 @@ void omap_gem_free_object(struct drm_gem_object *obj)mutex_lock (&omap_obj->lock);/* The object should not be pinned. */ -WARN_ON (omap_obj->dma_addr_cnt >0 ); +WARN_ON (refcount_read (&omap_obj->dma_addr_cnt) >0 );if (omap_obj->pages) {if (omap_obj->flags &OMAP_BO_MEM_DMABUF )
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 1/8] drm/omap: use refcount API to track the number of users of dma_addr
Hi JJ,
Quoted 6 lines · Jean-Jacques Hiblot
This would give us a
WARN_ON()if the pin/unpin calls are unbalanced.Proposed-by Laurent Pinchart <[email protected]>Signed-off-by Jean-Jacques Hiblot <[email protected]>Reviewed-by Tomi Valkeinen <[email protected]>---
This doesn't compile, but it gets fixed in some later patch in the series.
Can you fix this, and add your reviewed-bys, and resend one more time.
Tomi
Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 2/8 drm/omap: add omap_gem_unpin_locked()
In reply to Jean-Jacques HiblotFrom: Tomi Valkeinen <[email protected]>
Add omap_gem_unpin_locked() which is a version of omap_gem_unpin() that expects the caller to hold the omap_obj lock.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/gpu/drm/omapdrm/omap_gem.c +17 -7
@@ -834,20 +834,16 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr) }/** -* omap_gem_unpin() - Unpin a GEM object from memory +* omap_gem_unpin_locked() - Unpin a GEM object from memory * @obj: the GEM object * -* Unpin the given GEM object previously pinned with omap_gem_pin(). Pins are -* reference-counted, the actualy unpin will only be performed when the number -* of calls to this function matches the number of calls to omap_gem_pin(). +* omap_gem_unpin() without locking. */ -void omap_gem_unpin (struct drm_gem_object *obj) +static void omap_gem_unpin_locked (struct drm_gem_object *obj) {struct omap_gem_object *omap_obj =to_omap_bo (obj);int ret; -mutex_lock (&omap_obj->lock); -if (refcount_dec_and_test (&omap_obj->dma_addr_cnt)) { ret =tiler_unpin (omap_obj->block);if (ret) {
@@ -864,6 +860,20 @@ void omap_gem_unpin(struct drm_gem_object *obj) } } +/** +* omap_gem_unpin() - Unpin a GEM object from memory +* @obj: the GEM object +* +* Unpin the given GEM object previously pinned with omap_gem_pin(). Pins are +* reference-counted, the actual unpin will only be performed when the number +* of calls to this function matches the number of calls to omap_gem_pin(). +*/ +void omap_gem_unpin (struct drm_gem_object *obj) +{ +struct omap_gem_object *omap_obj =to_omap_bo (obj); + +mutex_lock (&omap_obj->lock); +omap_gem_unpin_locked (obj);mutex_unlock (&omap_obj->lock); }
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [v3,2/8] drm/omap: add omap_gem_unpin_locked()
Quoted 49 lines · Jean-Jacques Hiblot
From: Tomi Valkeinen <[email protected]>
Add
omap_gem_unpin_locked()which is a version ofomap_gem_unpin()that expects the caller to hold theomap_objlock.Signed-off-by Tomi Valkeinen <[email protected]>--- drivers/gpu/drm/omapdrm/omap_gem.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)drivers/gpu/drm/omapdrm/omap_gem.c +10
-7@@ -834,20 +834,16 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr) }/** -* omap_gem_unpin() - Unpin a GEM object from memory +* omap_gem_unpin_locked() - Unpin a GEM object from memory * @obj: the GEM object * -* Unpin the given GEM object previously pinned with omap_gem_pin(). Pins are -* reference-counted, the actualy unpin will only be performed when the number -* of calls to this function matches the number of calls to omap_gem_pin(). +* omap_gem_unpin() without locking. */ -void omap_gem_unpin (struct drm_gem_object *obj) +static void omap_gem_unpin_locked (struct drm_gem_object *obj) {struct omap_gem_object *omap_obj =to_omap_bo (obj);int ret; -mutex_lock (&omap_obj->lock); -if (refcount_dec_and_test (&omap_obj->dma_addr_cnt)) { ret =tiler_unpin (omap_obj->block);if (ret) {@@ -864,6 +860,20 @@ void omap_gem_unpin(struct drm_gem_object *obj) } } +/** +* omap_gem_unpin() - Unpin a GEM object from memory +* @obj: the GEM object +* +* Unpin the given GEM object previously pinned with omap_gem_pin(). Pins are +* reference-counted, the actual unpin will only be performed when the number +* of calls to this function matches the number of calls to omap_gem_pin().
drivers/gpu/drm/omapdrm/omap_gem.c void omap_gem_unpin(struct drm_gem_object *obj) · line 879
Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_gem.c +7
-0+*/ +void omap_gem_unpin (struct drm_gem_object *obj) +{ +struct omap_gem_object *omap_obj =to_omap_bo (obj); + +mutex_lock (&omap_obj->lock); +omap_gem_unpin_locked (obj);mutex_unlock (&omap_obj->lock); }
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 3/8 drm/omap: accept NULL for dma_addr in omap_gem_pin
In reply to Jean-Jacques HiblotFrom: Tomi Valkeinen <[email protected]>
Allow NULL to be passed in 'dma_addr' for omap_gem_pin(), in case the caller does not need the dma_addr.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/omapdrm/omap_gem.c +4 -2
@@ -819,9 +819,11 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)refcount_inc (&omap_obj->dma_addr_cnt); } - *dma_addr = omap_obj->dma_addr; +if (dma_addr) + *dma_addr = omap_obj->dma_addr; }else if (omap_gem_is_contiguous (omap_obj)) { - *dma_addr = omap_obj->dma_addr; +if (dma_addr) + *dma_addr = omap_obj->dma_addr; }else { ret = -EINVAL ; goto fail;
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [v3,3/8] drm/omap: accept NULL for dma_addr in omap_gem_pin
Quoted 18 lines · Jean-Jacques Hiblot
From: Tomi Valkeinen <[email protected]>
Allow NULL to be passed in '
dma_addr' foromap_gem_pin(), in case the caller does not need thedma_addr.Signed-off-by Tomi Valkeinen <[email protected]>--- drivers/gpu/drm/omapdrm/omap_gem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/omapdrm/omap_gem.c +0
-0@@ -819,9 +819,11 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)refcount_inc (&omap_obj->dma_addr_cnt); }
drivers/gpu/drm/omapdrm/omap_gem.c int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr) · line 829
Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_gem.c +4
-2- *dma_addr = omap_obj->dma_addr; +if (dma_addr) + *dma_addr = omap_obj->dma_addr; }else if (omap_gem_is_contiguous (omap_obj)) { - *dma_addr = omap_obj->dma_addr; +if (dma_addr) + *dma_addr = omap_obj->dma_addr; }else { ret = -EINVAL ; goto fail;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 4/8 drm/omap: cleanup OMAP_BO flags
In reply to Jean-Jacques HiblotFrom: Tomi Valkeinen <[email protected]>
Reorder OMAP_BO flags and improve the comments.
--- include/uapi/drm/omap_drm.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
include/uapi/drm/omap_drm.h +9 -8
@@ -38,19 +38,20 @@ struct drm_omap_param {__u64 value;/* in (set_param), out (get_param) */ }; -#define OMAP_BO_SCANOUT 0x00000001/* scanout capable (phys contiguous) */ -#define OMAP_BO_CACHE_MASK 0x00000006/* cache type mask, see cache modes */ -#define OMAP_BO_TILED_MASK 0x00000f00/* tiled mapping mask, see tiled modes */ +/* Scanout buffer, consumable by DSS */ +#define OMAP_BO_SCANOUT 0x00000001 -/* cache modes */ -#define OMAP_BO_CACHED 0x00000000/* default */ -#define OMAP_BO_WC 0x00000002/* write-combine */ -#define OMAP_BO_UNCACHED 0x00000004/* strongly-ordered (uncached) */ +/* Buffer CPU caching mode: cached, write-combining or uncached. */ +#define OMAP_BO_CACHED 0x00000000 +#define OMAP_BO_WC 0x00000002 +#define OMAP_BO_UNCACHED 0x00000004 +#define OMAP_BO_CACHE_MASK 0x00000006 -/* tiled modes */ +/* Use TILER for the buffer. The TILER container unit can be 8, 16 or 32 bits. */ #define OMAP_BO_TILED_8 0x00000100#define OMAP_BO_TILED_16 0x00000200#define OMAP_BO_TILED_32 0x00000300 +#define OMAP_BO_TILED_MASK 0x00000f00#define OMAP_BO_TILED (OMAP_BO_TILED_8 | OMAP_BO_TILED_16 | OMAP_BO_TILED_32)union omap_gem_size {
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [v3,4/8] drm/omap: cleanup OMAP_BO flags
Quoted 32 lines · Jean-Jacques Hiblot
From: Tomi Valkeinen <[email protected]>
Reorder
OMAP_BOflags and improve the comments.Signed-off-by Tomi Valkeinen <[email protected]>--- include/uapi/drm/omap_drm.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)include/uapi/drm/omap_drm.h +7
-7@@ -38,19 +38,20 @@ struct drm_omap_param {__u64 value;/* in (set_param), out (get_param) */ }; -#define OMAP_BO_SCANOUT 0x00000001/* scanout capable (phys contiguous) */ -#define OMAP_BO_CACHE_MASK 0x00000006/* cache type mask, see cache modes */ -#define OMAP_BO_TILED_MASK 0x00000f00/* tiled mapping mask, see tiled modes */ +/* Scanout buffer, consumable by DSS */ +#define OMAP_BO_SCANOUT 0x00000001 -/* cache modes */ -#define OMAP_BO_CACHED 0x00000000/* default */ -#define OMAP_BO_WC 0x00000002/* write-combine */ -#define OMAP_BO_UNCACHED 0x00000004/* strongly-ordered (uncached) */ +/* Buffer CPU caching mode: cached, write-combining or uncached. */ +#define OMAP_BO_CACHED 0x00000000 +#define OMAP_BO_WC 0x00000002 +#define OMAP_BO_UNCACHED 0x00000004 +#define OMAP_BO_CACHE_MASK 0x00000006
include/uapi/drm/omap_drm.h struct drm_omap_param { · line 57
Quoted 10 lines
include/uapi/drm/omap_drm.h +2
-1-/* tiled modes */ +/* Use TILER for the buffer. The TILER container unit can be 8, 16 or 32 bits. */ #define OMAP_BO_TILED_8 0x00000100#define OMAP_BO_TILED_16 0x00000200#define OMAP_BO_TILED_32 0x00000300 +#define OMAP_BO_TILED_MASK 0x00000f00#define OMAP_BO_TILED (OMAP_BO_TILED_8 | OMAP_BO_TILED_16 | OMAP_BO_TILED_32)union omap_gem_size {
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 5/8 drm/omap: remove OMAP_BO_TILED define
In reply to Jean-Jacques HiblotFrom: Tomi Valkeinen <[email protected]>
OMAP_BO_TILED does not make sense, as OMAP_BO_TILED_* values are not bitmasks but normal values. As we already have OMAP_BO_TILED_MASK for the mask, we can remove OMAP_BO_TILED and use OMAP_BO_TILED_MASK instead.
--- drivers/gpu/drm/omapdrm/omap_dmm_tiler.h | 2 +- drivers/gpu/drm/omapdrm/omap_fb.c | 6 +++--- drivers/gpu/drm/omapdrm/omap_gem.c | 18 +++++++++--------- drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c | 2 +- include/uapi/drm/omap_drm.h | 1 - 5 files changed, 14 insertions(+), 15 deletions(-)
drivers/gpu/drm/omapdrm/omap_dmm_tiler.h +1 -1
@@ -113,7 +113,7 @@ extern struct platform_driver omap_dmm_driver;/* GEM bo flags -> tiler fmt */ static inline enum tiler_fmt gem2fmt (u32 flags) { -switch (flags &OMAP_BO_TILED ) { +switch (flags &OMAP_BO_TILED_MASK ) {case OMAP_BO_TILED_8 :return TILFMT_8BIT ;case OMAP_BO_TILED_16 :
drivers/gpu/drm/omapdrm/omap_fb.c +3 -3
@@ -95,7 +95,7 @@ static u32 get_linear_addr(struct drm_framebuffer *fb,bool omap_framebuffer_supports_rotation (struct drm_framebuffer *fb) { -return omap_gem_flags (fb->obj[0 ]) &OMAP_BO_TILED ; +return omap_gem_flags (fb->obj[0 ]) &OMAP_BO_TILED_MASK ; }/* Note: DRM rotates counter-clockwise, TILER & DSS rotates clockwise */
@@ -154,7 +154,7 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, x = state->src_x >>16 ; y = state->src_y >>16 ; -if (omap_gem_flags (fb->obj[0 ]) &OMAP_BO_TILED ) { +if (omap_gem_flags (fb->obj[0 ]) &OMAP_BO_TILED_MASK ) {u32 w = state->src_w >>16 ;u32 h = state->src_h >>16 ;
@@ -212,7 +212,7 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, plane = &omap_fb->planes[1 ];if (info->rotation_type ==OMAP_DSS_ROT_TILER ) { -WARN_ON (!(omap_gem_flags (fb->obj[1 ]) &OMAP_BO_TILED )); +WARN_ON (!(omap_gem_flags (fb->obj[1 ]) &OMAP_BO_TILED_MASK ));omap_gem_rotated_dma_addr (fb->obj[1 ], orient, x/2 , y/2 , &info->p_uv_addr); }else {
drivers/gpu/drm/omapdrm/omap_gem.c +9 -9
@@ -196,7 +196,7 @@ static void omap_gem_evict(struct drm_gem_object *obj)struct omap_gem_object *omap_obj =to_omap_bo (obj);struct omap_drm_private *priv = obj->dev->dev_private; -if (omap_obj->flags &OMAP_BO_TILED ) { +if (omap_obj->flags &OMAP_BO_TILED_MASK ) {enum tiler_fmt fmt =gem2fmt (omap_obj->flags);int i;
@@ -324,7 +324,7 @@ size_t omap_gem_mmap_size(struct drm_gem_object *obj)struct omap_gem_object *omap_obj =to_omap_bo (obj);size_t size = obj->size; -if (omap_obj->flags &OMAP_BO_TILED ) { +if (omap_obj->flags &OMAP_BO_TILED_MASK ) {/* for tiled buffers, the virtual size has stride rounded up * to 4kb.. (to hide the fact that row n+1 might start 16kb or * 32kb later!). But we don't back the entire buffer with
@@ -513,7 +513,7 @@ vm_fault_t omap_gem_fault(struct vm_fault *vmf)* probably trigger put_pages()? */ -if (omap_obj->flags &OMAP_BO_TILED ) +if (omap_obj->flags &OMAP_BO_TILED_MASK ) ret =omap_gem_fault_2d (obj, vma, vmf);else ret =omap_gem_fault_1d (obj, vma, vmf);
@@ -786,7 +786,7 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)if (ret) goto fail; -if (omap_obj->flags &OMAP_BO_TILED ) { +if (omap_obj->flags &OMAP_BO_TILED_MASK ) { block =tiler_reserve_2d (fmt, omap_obj->width, omap_obj->height,0 );
@@ -892,7 +892,7 @@ int omap_gem_rotated_dma_addr(struct drm_gem_object *obj, u32 orient,mutex_lock (&omap_obj->lock);if ((refcount_read (&omap_obj->dma_addr_cnt) >0 ) && omap_obj->block && - (omap_obj->flags &OMAP_BO_TILED )) { + (omap_obj->flags &OMAP_BO_TILED_MASK )) { *dma_addr =tiler_tsptr (omap_obj->block, orient, x, y); ret =0 ; }
@@ -907,7 +907,7 @@ int omap_gem_tiled_stride(struct drm_gem_object *obj, u32 orient) {struct omap_gem_object *omap_obj =to_omap_bo (obj);int ret = -EINVAL ; -if (omap_obj->flags &OMAP_BO_TILED ) +if (omap_obj->flags &OMAP_BO_TILED_MASK ) ret =tiler_stride (gem2fmt (omap_obj->flags), orient);return ret; }
@@ -1046,7 +1046,7 @@ void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m)refcount_read (&omap_obj->dma_addr_cnt), omap_obj->vaddr, omap_obj->roll); -if (omap_obj->flags &OMAP_BO_TILED ) { +if (omap_obj->flags &OMAP_BO_TILED_MASK ) {seq_printf (m," %dx%d" , omap_obj->width, omap_obj->height);if (omap_obj->block) {struct tcm_area *area = &omap_obj->block->area;
@@ -1145,7 +1145,7 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,int ret;/* Validate the flags and compute the memory and cache flags. */ -if (flags &OMAP_BO_TILED ) { +if (flags &OMAP_BO_TILED_MASK ) {if (!priv->usergart) {dev_err (dev->dev,"Tiled buffers require DMM\n" );return NULL ;
@@ -1187,7 +1187,7 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev, omap_obj->flags = flags;mutex_init (&omap_obj->lock); -if (flags &OMAP_BO_TILED ) { +if (flags &OMAP_BO_TILED_MASK ) {/* * For tiled buffers align dimensions to slot boundaries and * calculate size based on aligned dimensions.
drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c +1 -1
@@ -67,7 +67,7 @@ static int omap_gem_dmabuf_begin_cpu_access(struct dma_buf *buffer, {struct drm_gem_object *obj = buffer->priv;struct page **pages; -if (omap_gem_flags (obj) &OMAP_BO_TILED ) { +if (omap_gem_flags (obj) &OMAP_BO_TILED_MASK ) {/* TODO we would need to pin at least part of the buffer to * get de-tiled view. For now just reject it. */
include/uapi/drm/omap_drm.h +0 -1
@@ -52,7 +52,6 @@ struct drm_omap_param {#define OMAP_BO_TILED_16 0x00000200#define OMAP_BO_TILED_32 0x00000300#define OMAP_BO_TILED_MASK 0x00000f00 -#define OMAP_BO_TILED (OMAP_BO_TILED_8 | OMAP_BO_TILED_16 | OMAP_BO_TILED_32)union omap_gem_size {__u32 bytes;/* (for non-tiled formats) */
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [v3,5/8] drm/omap: remove OMAP_BO_TILED define
Quoted 163 lines · Jean-Jacques Hiblot
From: Tomi Valkeinen <[email protected]>
OMAP_BO_TILEDdoes not make sense, as OMAP_BO_TILED_* values are not bitmasks but normal values. As we already haveOMAP_BO_TILED_MASKfor the mask, we can removeOMAP_BO_TILEDand useOMAP_BO_TILED_MASKinstead.Signed-off-by Tomi Valkeinen <[email protected]>--- drivers/gpu/drm/omapdrm/omap_dmm_tiler.h | 2 +- drivers/gpu/drm/omapdrm/omap_fb.c | 6 +++--- drivers/gpu/drm/omapdrm/omap_gem.c | 18 +++++++++--------- drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c | 2 +- include/uapi/drm/omap_drm.h | 1 - 5 files changed, 14 insertions(+), 15 deletions(-)drivers/gpu/drm/omapdrm/omap_dmm_tiler.h +1
-1@@ -113,7 +113,7 @@ extern struct platform_driver omap_dmm_driver;/* GEM bo flags -> tiler fmt */ static inline enum tiler_fmt gem2fmt (u32 flags) { -switch (flags &OMAP_BO_TILED ) { +switch (flags &OMAP_BO_TILED_MASK ) {case OMAP_BO_TILED_8 :return TILFMT_8BIT ;case OMAP_BO_TILED_16 :drivers/gpu/drm/omapdrm/omap_fb.c +3
-3@@ -95,7 +95,7 @@ static u32 get_linear_addr(struct drm_framebuffer *fb,bool omap_framebuffer_supports_rotation (struct drm_framebuffer *fb) { -return omap_gem_flags (fb->obj[0 ]) &OMAP_BO_TILED ; +return omap_gem_flags (fb->obj[0 ]) &OMAP_BO_TILED_MASK ; }/* Note: DRM rotates counter-clockwise, TILER & DSS rotates clockwise */ @@ -154,7 +154,7 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, x = state->src_x >>16 ; y = state->src_y >>16 ; -if (omap_gem_flags (fb->obj[0 ]) &OMAP_BO_TILED ) { +if (omap_gem_flags (fb->obj[0 ]) &OMAP_BO_TILED_MASK ) {u32 w = state->src_w >>16 ;u32 h = state->src_h >>16 ;@@ -212,7 +212,7 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, plane = &omap_fb->planes[1 ];if (info->rotation_type ==OMAP_DSS_ROT_TILER ) { -WARN_ON (!(omap_gem_flags (fb->obj[1 ]) &OMAP_BO_TILED )); +WARN_ON (!(omap_gem_flags (fb->obj[1 ]) &OMAP_BO_TILED_MASK ));omap_gem_rotated_dma_addr (fb->obj[1 ], orient, x/2 , y/2 , &info->p_uv_addr); }else {drivers/gpu/drm/omapdrm/omap_gem.c +9
-9@@ -196,7 +196,7 @@ static void omap_gem_evict(struct drm_gem_object *obj)struct omap_gem_object *omap_obj =to_omap_bo (obj);struct omap_drm_private *priv = obj->dev->dev_private; -if (omap_obj->flags &OMAP_BO_TILED ) { +if (omap_obj->flags &OMAP_BO_TILED_MASK ) {enum tiler_fmt fmt =gem2fmt (omap_obj->flags);int i;@@ -324,7 +324,7 @@ size_t omap_gem_mmap_size(struct drm_gem_object *obj)struct omap_gem_object *omap_obj =to_omap_bo (obj);size_t size = obj->size; -if (omap_obj->flags &OMAP_BO_TILED ) { +if (omap_obj->flags &OMAP_BO_TILED_MASK ) {/* for tiled buffers, the virtual size has stride rounded up * to 4kb.. (to hide the fact that row n+1 might start 16kb or * 32kb later!). But we don't back the entire buffer with @@ -513,7 +513,7 @@ vm_fault_t omap_gem_fault(struct vm_fault *vmf)* probably trigger put_pages()? */ -if (omap_obj->flags &OMAP_BO_TILED ) +if (omap_obj->flags &OMAP_BO_TILED_MASK ) ret =omap_gem_fault_2d (obj, vma, vmf);else ret =omap_gem_fault_1d (obj, vma, vmf);@@ -786,7 +786,7 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)if (ret) goto fail; -if (omap_obj->flags &OMAP_BO_TILED ) { +if (omap_obj->flags &OMAP_BO_TILED_MASK ) { block =tiler_reserve_2d (fmt, omap_obj->width, omap_obj->height,0 );@@ -892,7 +892,7 @@ int omap_gem_rotated_dma_addr(struct drm_gem_object *obj, u32 orient,mutex_lock (&omap_obj->lock);if ((refcount_read (&omap_obj->dma_addr_cnt) >0 ) && omap_obj->block && - (omap_obj->flags &OMAP_BO_TILED )) { + (omap_obj->flags &OMAP_BO_TILED_MASK )) { *dma_addr =tiler_tsptr (omap_obj->block, orient, x, y); ret =0 ; }@@ -907,7 +907,7 @@ int omap_gem_tiled_stride(struct drm_gem_object *obj, u32 orient) {struct omap_gem_object *omap_obj =to_omap_bo (obj);int ret = -EINVAL ; -if (omap_obj->flags &OMAP_BO_TILED ) +if (omap_obj->flags &OMAP_BO_TILED_MASK ) ret =tiler_stride (gem2fmt (omap_obj->flags), orient);return ret; }@@ -1046,7 +1046,7 @@ void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m)refcount_read (&omap_obj->dma_addr_cnt), omap_obj->vaddr, omap_obj->roll); -if (omap_obj->flags &OMAP_BO_TILED ) { +if (omap_obj->flags &OMAP_BO_TILED_MASK ) {seq_printf (m," %dx%d" , omap_obj->width, omap_obj->height);if (omap_obj->block) {struct tcm_area *area = &omap_obj->block->area;@@ -1145,7 +1145,7 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,int ret;/* Validate the flags and compute the memory and cache flags. */ -if (flags &OMAP_BO_TILED ) { +if (flags &OMAP_BO_TILED_MASK ) {if (!priv->usergart) {dev_err (dev->dev,"Tiled buffers require DMM\n" );return NULL ;@@ -1187,7 +1187,7 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev, omap_obj->flags = flags;mutex_init (&omap_obj->lock); -if (flags &OMAP_BO_TILED ) { +if (flags &OMAP_BO_TILED_MASK ) {/* * For tiled buffers align dimensions to slot boundaries and * calculate size based on aligned dimensions. drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c +1
-1@@ -67,7 +67,7 @@ static int omap_gem_dmabuf_begin_cpu_access(struct dma_buf *buffer, {struct drm_gem_object *obj = buffer->priv;struct page **pages; -if (omap_gem_flags (obj) &OMAP_BO_TILED ) { +if (omap_gem_flags (obj) &OMAP_BO_TILED_MASK ) {/* TODO we would need to pin at least part of the buffer to * get de-tiled view. For now just reject it. */ include/uapi/drm/omap_drm.h +0
-0
include/uapi/drm/omap_drm.h struct drm_omap_param { · line 57
Quoted 7 lines
include/uapi/drm/omap_drm.h +0
-1@@ -52,7 +52,6 @@ struct drm_omap_param {#define OMAP_BO_TILED_16 0x00000200#define OMAP_BO_TILED_32 0x00000300#define OMAP_BO_TILED_MASK 0x00000f00 -#define OMAP_BO_TILED (OMAP_BO_TILED_8 | OMAP_BO_TILED_16 | OMAP_BO_TILED_32)union omap_gem_size {__u32 bytes;/* (for non-tiled formats) */
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 6/8 drm/omap: cleanup OMAP_BO_SCANOUT use
In reply to Jean-Jacques HiblotFrom: Tomi Valkeinen <[email protected]>
omap_gem_new() has a comment about OMAP_BO_SCANOUT which does not make sense. Also, for the TILER case, we drop OMAP_BO_SCANOUT flag for some reason.
It's not clear what the original purpose of OMAP_BO_SCANOUT is, but presuming it means "scanout buffer, something that can be consumed by DSS", this patch cleans up the above issues.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/omapdrm/omap_gem.c +2 -4
@@ -1155,7 +1155,6 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,* Tiled buffers are always shmem paged backed. When they are * scanned out, they are remapped into DMM/TILER. */ - flags &= ~OMAP_BO_SCANOUT ; flags |=OMAP_BO_MEM_SHMEM ;/*
@@ -1166,9 +1165,8 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev, flags |=tiler_get_cpu_cache_flags (); }else if ((flags &OMAP_BO_SCANOUT ) && !priv->has_dmm) {/* -* OMAP_BO_SCANOUT hints that the buffer doesn't need to be -* tiled. However, to lower the pressure on memory allocation, -* use contiguous memory only if no TILER is available. +* If we don't have DMM, we must allocate scanout buffers +* from contiguous DMA memory. */ flags |=OMAP_BO_MEM_DMA_API ; }else if (!(flags &OMAP_BO_MEM_DMABUF )) {
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [v3,6/8] drm/omap: cleanup OMAP_BO_SCANOUT use
Quoted 29 lines · Jean-Jacques Hiblot
From: Tomi Valkeinen <[email protected]>
omap_gem_new()has a comment aboutOMAP_BO_SCANOUTwhich does not make sense. Also, for the TILER case, we dropOMAP_BO_SCANOUTflag for some reason.It's not clear what the original purpose of
OMAP_BO_SCANOUTis, but presuming it means "scanout buffer, something that can be consumed by DSS", this patch cleans up the above issues.Signed-off-by Tomi Valkeinen <[email protected]>--- drivers/gpu/drm/omapdrm/omap_gem.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/gpu/drm/omapdrm/omap_gem.c +0
-1@@ -1155,7 +1155,6 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,* Tiled buffers are always shmem paged backed. When they are * scanned out, they are remapped into DMM/TILER. */ - flags &= ~OMAP_BO_SCANOUT ; flags |=OMAP_BO_MEM_SHMEM ;/* @@ -1166,9 +1165,8 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev, flags |=tiler_get_cpu_cache_flags ();
drivers/gpu/drm/omapdrm/omap_gem.c struct drm_gem_object *omap_gem_new(struct drm_device *dev, · line 1172
Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_gem.c +2
-3}else if ((flags &OMAP_BO_SCANOUT ) && !priv->has_dmm) {/* -* OMAP_BO_SCANOUT hints that the buffer doesn't need to be -* tiled. However, to lower the pressure on memory allocation, -* use contiguous memory only if no TILER is available. +* If we don't have DMM, we must allocate scanout buffers +* from contiguous DMA memory. */ flags |=OMAP_BO_MEM_DMA_API ; }else if (!(flags &OMAP_BO_MEM_DMABUF )) {
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 7/8 drm/omap: add omap_gem_validate_flags()
In reply to Jean-Jacques HiblotFrom: Tomi Valkeinen <[email protected]>
Add a helper function omap_gem_validate_flags() which validates the omap_bo flags passed from the userspace.
Also drop the dev_err() message, as the userspace can cause that at will.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 40 ++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-)
drivers/gpu/drm/omapdrm/omap_gem.c +35 -5
@@ -1133,6 +1133,38 @@ void omap_gem_free_object(struct drm_gem_object *obj)kfree (omap_obj); } +static bool omap_gem_validate_flags (struct drm_device *dev,u32 flags) +{ +struct omap_drm_private *priv = dev->dev_private; + +switch (flags &OMAP_BO_CACHE_MASK ) { +case OMAP_BO_CACHED : +case OMAP_BO_WC : +case OMAP_BO_CACHE_MASK : +break ; + +default : +return false; + } + +if (flags &OMAP_BO_TILED_MASK ) { +if (!priv->usergart) +return false; + +switch (flags &OMAP_BO_TILED_MASK ) { +case OMAP_BO_TILED_8 : +case OMAP_BO_TILED_16 : +case OMAP_BO_TILED_32 : +break ; + +default : +return false; + } + } + +return true; +} +/* GEM buffer object constructor */ struct drm_gem_object *omap_gem_new (struct drm_device *dev,union omap_gem_size gsize,u32 flags)
@@ -1144,13 +1176,11 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,size_t size;int ret; +if (!omap_gem_validate_flags (dev, flags)) +return NULL ; +/* Validate the flags and compute the memory and cache flags. */ if (flags &OMAP_BO_TILED_MASK ) { -if (!priv->usergart) { -dev_err (dev->dev,"Tiled buffers require DMM\n" ); -return NULL ; - } -/* * Tiled buffers are always shmem paged backed. When they are * scanned out, they are remapped into DMM/TILER.
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [v3,7/8] drm/omap: add omap_gem_validate_flags()
Quoted 63 lines · Jean-Jacques Hiblot
From: Tomi Valkeinen <[email protected]>
Add a helper function
omap_gem_validate_flags()which validates theomap_boflags passed from the userspace.Also drop the
dev_err()message, as the userspace can cause that at will.Signed-off-by Tomi Valkeinen <[email protected]>--- drivers/gpu/drm/omapdrm/omap_gem.c | 40 ++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-)drivers/gpu/drm/omapdrm/omap_gem.c +35
-0@@ -1133,6 +1133,38 @@ void omap_gem_free_object(struct drm_gem_object *obj)kfree (omap_obj); } +static bool omap_gem_validate_flags (struct drm_device *dev,u32 flags) +{ +struct omap_drm_private *priv = dev->dev_private; + +switch (flags &OMAP_BO_CACHE_MASK ) { +case OMAP_BO_CACHED : +case OMAP_BO_WC : +case OMAP_BO_CACHE_MASK : +break ; + +default : +return false; + } + +if (flags &OMAP_BO_TILED_MASK ) { +if (!priv->usergart) +return false; + +switch (flags &OMAP_BO_TILED_MASK ) { +case OMAP_BO_TILED_8 : +case OMAP_BO_TILED_16 : +case OMAP_BO_TILED_32 : +break ; + +default : +return false; + } + } + +return true; +} +/* GEM buffer object constructor */ struct drm_gem_object *omap_gem_new (struct drm_device *dev,union omap_gem_size gsize,u32 flags)@@ -1144,13 +1176,11 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,size_t size;int ret; +if (!omap_gem_validate_flags (dev, flags)) +return NULL ; +
drivers/gpu/drm/omapdrm/omap_gem.c struct drm_gem_object *omap_gem_new(struct drm_device *dev, · line 1186
Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_gem.c +0
-5/* Validate the flags and compute the memory and cache flags. */ if (flags &OMAP_BO_TILED_MASK ) { -if (!priv->usergart) { -dev_err (dev->dev,"Tiled buffers require DMM\n" ); -return NULL ; - } -/* * Tiled buffers are always shmem paged backed. When they are * scanned out, they are remapped into DMM/TILER.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v3 8/8 drm/omap: add OMAP_BO flags to affect buffer allocation
In reply to Jean-Jacques HiblotFrom: Tomi Valkeinen <[email protected]>
On SoCs with DMM/TILER, we have two ways to allocate buffers: normal dma_alloc or via DMM (which basically functions as an IOMMU). DMM can map 128MB at a time, and we only map the DMM buffers when they are used (i.e. not at alloc time). If DMM is present, omapdrm always uses DMM.
There are use cases that require lots of big buffers that are being used at the same time by different IPs. At the moment the userspace has a hard maximum of 128MB.
This patch adds three new flags that can be used by the userspace to solve the situation:
OMAP_BO_MEM_CONTIG: The driver will use dma_alloc to get the memory. This can be used to avoid DMM if the userspace knows it needs more than 128M of memory at the same time.
OMAP_BO_MEM_DMM: The driver will use DMM to get the memory. There's not much use for this flag at the moment, as on platforms with DMM it is used by default, but it's here for completeness.
OMAP_BO_MEM_PIN: The driver will pin the memory at alloc time, and keep it pinned. This can be used to 1) get an error at alloc time if DMM space is full, and 2) get rid of the constant pin/unpin operations which may have some effect on performance.
If none of the flags are given, the behavior is the same as currently.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 54 ++++++++++++++++++++++++++++-- include/uapi/drm/omap_drm.h | 9 +++++ 2 files changed, 61 insertions(+), 2 deletions(-)
drivers/gpu/drm/omapdrm/omap_gem.c +52 -2
@@ -1097,6 +1097,9 @@ void omap_gem_free_object(struct drm_gem_object *obj)list_del (&omap_obj->mm_list);mutex_unlock (&priv->list_lock); +if (omap_obj->flags &OMAP_BO_MEM_PIN ) +omap_gem_unpin_locked (obj); +/* * We own the sole reference to the object at this point, but to keep * lockdep happy, we must still take the omap_obj_lock to call
@@ -1147,10 +1150,19 @@ static bool omap_gem_validate_flags(struct drm_device *dev, u32 flags)return false; } +if ((flags &OMAP_BO_MEM_CONTIG ) && (flags &OMAP_BO_MEM_DMM )) +return false; + +if ((flags &OMAP_BO_MEM_DMM ) && !priv->usergart) +return false; +if (flags &OMAP_BO_TILED_MASK ) {if (!priv->usergart)return false; +if (flags &OMAP_BO_MEM_CONTIG ) +return false; +switch (flags &OMAP_BO_TILED_MASK ) {case OMAP_BO_TILED_8 :case OMAP_BO_TILED_16 :
@@ -1165,7 +1177,34 @@ static bool omap_gem_validate_flags(struct drm_device *dev, u32 flags)return true; } -/* GEM buffer object constructor */ +/** +* omap_gem_new() - Create a new GEM buffer +* @dev: The DRM device +* @gsize: The requested size for the GEM buffer. If the buffer is tiled +* (2D buffer), the size is a pair of values: height and width +* expressed in pixels. If the buffers is not tiled, it is expressed +* in bytes. +* @flags: Flags give additionnal information about the allocation: +* OMAP_BO_TILED_x: use the TILER (2D buffers). The TILER container +* unit can be 8, 16 or 32 bits. Cache is always disabled for +* tiled buffers. +* OMAP_BO_SCANOUT: Scannout buffer, consummable by the DSS +* OMAP_BO_CACHED: Buffer CPU caching mode: cached +* OMAP_BO_WC: Buffer CPU caching mode: write-combined +* OMAP_BO_UNCACHED: Buffer CPU caching mode: uncached +* OMAP_BO_MEM_CONTIG: The driver will use dma_alloc to get the memory. +* This can be used to avoid DMM if the userspace knows it needs +* more than 128M of memory at the same time. +* OMAP_BO_MEM_DMM: The driver will use DMM to get the memory. There's +* not much use for this flag at the moment, as on platforms with +* DMM it is used by default, but it's here for completeness. +* OMAP_BO_MEM_PIN: The driver will pin the memory at alloc time, and +* keep it pinned. This can be used to 1) get an error at alloc +* time if DMM space is full, and 2) get rid of the constant +* pin/unpin operations which may have some effect on performance. +* +* Return: The GEM buffer or NULL if the allocation failed +*/ struct drm_gem_object *omap_gem_new (struct drm_device *dev,union omap_gem_size gsize,u32 flags) {
@@ -1193,7 +1232,8 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,*/ flags &= ~(OMAP_BO_CACHED |OMAP_BO_WC |OMAP_BO_UNCACHED ); flags |=tiler_get_cpu_cache_flags (); - }else if ((flags &OMAP_BO_SCANOUT ) && !priv->has_dmm) { + }else if ((flags &OMAP_BO_MEM_CONTIG ) || + ((flags &OMAP_BO_SCANOUT ) && !priv->has_dmm)) {/* * If we don't have DMM, we must allocate scanout buffers * from contiguous DMA memory.
@@ -1253,12 +1293,22 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev, goto err_release; } +if (flags &OMAP_BO_MEM_PIN ) { + ret =omap_gem_pin (obj,NULL ); +if (ret) + goto err_free_dma; + } +mutex_lock (&priv->list_lock);list_add (&omap_obj->mm_list, &priv->obj_list);mutex_unlock (&priv->list_lock);return obj; +err_free_dma: +if (flags &OMAP_BO_MEM_DMA_API ) +dma_free_wc (dev->dev, size, omap_obj->vaddr, + omap_obj->dma_addr); err_release:drm_gem_object_release (obj); err_free:
include/uapi/drm/omap_drm.h +9 -0
@@ -47,6 +47,15 @@ struct drm_omap_param {#define OMAP_BO_UNCACHED 0x00000004#define OMAP_BO_CACHE_MASK 0x00000006 +/* Force allocation from contiguous DMA memory */ +#define OMAP_BO_MEM_CONTIG 0x00000008 + +/* Force allocation via DMM */ +#define OMAP_BO_MEM_DMM 0x00000010 + +/* Pin the buffer when allocating and keep pinned */ +#define OMAP_BO_MEM_PIN 0x00000020 +/* Use TILER for the buffer. The TILER container unit can be 8, 16 or 32 bits. */ #define OMAP_BO_TILED_8 0x00000100#define OMAP_BO_TILED_16 0x00000200
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [v3,8/8] drm/omap: add OMAP_BO flags to affect buffer allocation
Quoted 148 lines · Jean-Jacques Hiblot
From: Tomi Valkeinen <[email protected]>
On SoCs with DMM/TILER, we have two ways to allocate buffers: normal
dma_allocor via DMM (which basically functions as an IOMMU). DMM can map 128MB at a time, and we only map the DMM buffers when they are used (i.e. not at alloc time). If DMM is present, omapdrm always uses DMM.There are use cases that require lots of big buffers that are being used at the same time by different IPs. At the moment the userspace has a hard maximum of 128MB.
This patch adds three new flags that can be used by the userspace to solve the situation:
OMAP_BO_MEM_CONTIG: The driver will usedma_allocto get the memory. This can be used to avoid DMM if the userspace knows it needs more than 128M of memory at the same time.
OMAP_BO_MEM_DMM: The driver will use DMM to get the memory. There's not much use for this flag at the moment, as on platforms with DMM it is used by default, but it's here for completeness.
OMAP_BO_MEM_PIN: The driver will pin the memory at alloc time, and keep it pinned. This can be used to 1) get an error at alloc time if DMM space is full, and 2) get rid of the constant pin/unpin operations which may have some effect on performance.If none of the flags are given, the behavior is the same as currently.
Signed-off-by Tomi Valkeinen <[email protected]>--- drivers/gpu/drm/omapdrm/omap_gem.c | 54 ++++++++++++++++++++++++++++-- include/uapi/drm/omap_drm.h | 9 +++++ 2 files changed, 61 insertions(+), 2 deletions(-)drivers/gpu/drm/omapdrm/omap_gem.c +52
-2@@ -1097,6 +1097,9 @@ void omap_gem_free_object(struct drm_gem_object *obj)list_del (&omap_obj->mm_list);mutex_unlock (&priv->list_lock); +if (omap_obj->flags &OMAP_BO_MEM_PIN ) +omap_gem_unpin_locked (obj); +/* * We own the sole reference to the object at this point, but to keep * lockdep happy, we must still take the omap_obj_lock to call @@ -1147,10 +1150,19 @@ static bool omap_gem_validate_flags(struct drm_device *dev, u32 flags)return false; } +if ((flags &OMAP_BO_MEM_CONTIG ) && (flags &OMAP_BO_MEM_DMM )) +return false; + +if ((flags &OMAP_BO_MEM_DMM ) && !priv->usergart) +return false; +if (flags &OMAP_BO_TILED_MASK ) {if (!priv->usergart)return false; +if (flags &OMAP_BO_MEM_CONTIG ) +return false; +switch (flags &OMAP_BO_TILED_MASK ) {case OMAP_BO_TILED_8 :case OMAP_BO_TILED_16 :@@ -1165,7 +1177,34 @@ static bool omap_gem_validate_flags(struct drm_device *dev, u32 flags)return true; } -/* GEM buffer object constructor */ +/** +* omap_gem_new() - Create a new GEM buffer +* @dev: The DRM device +* @gsize: The requested size for the GEM buffer. If the buffer is tiled +* (2D buffer), the size is a pair of values: height and width +* expressed in pixels. If the buffers is not tiled, it is expressed +* in bytes. +* @flags: Flags give additionnal information about the allocation: +* OMAP_BO_TILED_x: use the TILER (2D buffers). The TILER container +* unit can be 8, 16 or 32 bits. Cache is always disabled for +* tiled buffers. +* OMAP_BO_SCANOUT: Scannout buffer, consummable by the DSS +* OMAP_BO_CACHED: Buffer CPU caching mode: cached +* OMAP_BO_WC: Buffer CPU caching mode: write-combined +* OMAP_BO_UNCACHED: Buffer CPU caching mode: uncached +* OMAP_BO_MEM_CONTIG: The driver will use dma_alloc to get the memory. +* This can be used to avoid DMM if the userspace knows it needs +* more than 128M of memory at the same time. +* OMAP_BO_MEM_DMM: The driver will use DMM to get the memory. There's +* not much use for this flag at the moment, as on platforms with +* DMM it is used by default, but it's here for completeness. +* OMAP_BO_MEM_PIN: The driver will pin the memory at alloc time, and +* keep it pinned. This can be used to 1) get an error at alloc +* time if DMM space is full, and 2) get rid of the constant +* pin/unpin operations which may have some effect on performance. +* +* Return: The GEM buffer or NULL if the allocation failed +*/ struct drm_gem_object *omap_gem_new (struct drm_device *dev,union omap_gem_size gsize,u32 flags) {@@ -1193,7 +1232,8 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,*/ flags &= ~(OMAP_BO_CACHED |OMAP_BO_WC |OMAP_BO_UNCACHED ); flags |=tiler_get_cpu_cache_flags (); - }else if ((flags &OMAP_BO_SCANOUT ) && !priv->has_dmm) { + }else if ((flags &OMAP_BO_MEM_CONTIG ) || + ((flags &OMAP_BO_SCANOUT ) && !priv->has_dmm)) {/* * If we don't have DMM, we must allocate scanout buffers * from contiguous DMA memory. @@ -1253,12 +1293,22 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev, goto err_release; } +if (flags &OMAP_BO_MEM_PIN ) { + ret =omap_gem_pin (obj,NULL ); +if (ret) + goto err_free_dma; + } +mutex_lock (&priv->list_lock);list_add (&omap_obj->mm_list, &priv->obj_list);mutex_unlock (&priv->list_lock);return obj; +err_free_dma: +if (flags &OMAP_BO_MEM_DMA_API ) +dma_free_wc (dev->dev, size, omap_obj->vaddr, + omap_obj->dma_addr); err_release:drm_gem_object_release (obj); err_free:include/uapi/drm/omap_drm.h +2
-0@@ -47,6 +47,15 @@ struct drm_omap_param {#define OMAP_BO_UNCACHED 0x00000004#define OMAP_BO_CACHE_MASK 0x00000006 +/* Force allocation from contiguous DMA memory */ +#define OMAP_BO_MEM_CONTIG 0x00000008
include/uapi/drm/omap_drm.h struct drm_omap_param { · line 61
Quoted 10 lines
include/uapi/drm/omap_drm.h +7
-0+ +/* Force allocation via DMM */ +#define OMAP_BO_MEM_DMM 0x00000010 + +/* Pin the buffer when allocating and keep pinned */ +#define OMAP_BO_MEM_PIN 0x00000020 +/* Use TILER for the buffer. The TILER container unit can be 8, 16 or 32 bits. */ #define OMAP_BO_TILED_8 0x00000100#define OMAP_BO_TILED_16 0x00000200
I modified the patch to add comment following the kernel-doc style, so my Reviewed-by actually applies only to the code modifications, not the comment wording.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 38 lines · Jean-Jacques Hiblot
A first version of this work had been sent by Tomi Valkeinen in may 2017
(https://www.spinics.net/lists/dri-devel/msg140663.html).This series adds a few new
OMAP_BOflags to help the userspace manage situations where it needs to use lots of buffers, and would currently run out of TILER space. The TILER space is limited to mapping 128MB at any given time and some applications might need more.This seres is also the opportunity to do some cleanup in the flags and improve the comments describing them.
The user-space patches for libdrm, although ready, haven't been posted yet. It will be be done when this series have been discussed and hopefully in the process of getting merged.
JJ
changes in v3:
- rebase on top of v5.4-rc2
- Documentomap_gem_new()and the new flags using the kernel-doc formatchanges in v2:
- fixed build error that crept in during rebase before sending (sorry about that)
- rework the refcount part a bit.Jean-Jacques Hiblot (1):
drm/omap: use refcount API to track the number of users ofdma_addrTomi Valkeinen (7):
drm/omap: addomap_gem_unpin_locked()drm/omap: accept NULL fordma_addrinomap_gem_pindrm/omap: cleanupOMAP_BOflags
drm/omap: removeOMAP_BO_TILEDdefine drm/omap: cleanupOMAP_BO_SCANOUTuse drm/omap: addomap_gem_validate_flags()drm/omap: addOMAP_BOflags to affect buffer allocation
Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_dmm_tiler.h | 2 +- drivers/gpu/drm/omapdrm/omap_fb.c | 6 +- drivers/gpu/drm/omapdrm/omap_gem.c | 191 ++++++++++++++++------ drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c | 2 +- include/uapi/drm/omap_drm.h | 27 ++- 5 files changed, 164 insertions(+), 64 deletions(-)
Thanks! This looks good to me. One comment, though:
Some people may have different opinions on how to manage other people's patches, but here's mine:
If you have made changes to a patch from someone else (me, in this case), other than really trivial typo fixes or such, you should add your signed-off-by.
Also, if you change the patch in a way that might make it behave differently than the original, you should change the ownership to yourself, drop the original signed-off-by, and perhaps say in the desc that the original was written by xyz. I don't want "my" patch to cause kernel crashes, if it's really not my code =).
Actually, I see we now have "Co-developed-by" documented in Documentation/process/5.Posting.rst. That may be suitable here.
And for the patches that you didn't touch, I'm sure you've still gone through those, so you could add your reviewed-by.
Tomi
Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 46 lines · Tomi Valkeinen
Quoted 38 lines · Jean-Jacques Hiblot
A first version of this work had been sent by Tomi Valkeinen in may 2017
(https://www.spinics.net/lists/dri-devel/msg140663.html).This series adds a few new
OMAP_BOflags to help the userspace manage situations where it needs to use lots of buffers, and would currently run out of TILER space. The TILER space is limited to mapping 128MB at any given time and some applications might need more.This seres is also the opportunity to do some cleanup in the flags and improve the comments describing them.
The user-space patches for libdrm, although ready, haven't been posted yet. It will be be done when this series have been discussed and hopefully in the process of getting merged.
JJ
changes in v3:
- rebase on top of v5.4-rc2
- Documentomap_gem_new()and the new flags using the kernel-doc formatchanges in v2:
- fixed build error that crept in during rebase before sending (sorry about that)
- rework the refcount part a bit.Jean-Jacques Hiblot (1):
drm/omap: use refcount API to track the number of users ofdma_addrTomi Valkeinen (7):
drm/omap: addomap_gem_unpin_locked()drm/omap: accept NULL fordma_addrinomap_gem_pindrm/omap: cleanupOMAP_BOflags
drm/omap: removeOMAP_BO_TILEDdefine drm/omap: cleanupOMAP_BO_SCANOUTuse drm/omap: addomap_gem_validate_flags()drm/omap: addOMAP_BOflags to affect buffer allocationQuoted 6 lines
drivers/gpu/drm/omapdrm/omap_dmm_tiler.h | 2 +- drivers/gpu/drm/omapdrm/omap_fb.c | 6 +- drivers/gpu/drm/omapdrm/omap_gem.c | 191 ++++++++++++++++------
drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c| 2 +- include/uapi/drm/omap_drm.h | 27 ++-5 files changed, 164 insertions(+), 64 deletions(-)
Quoted 7 lines
Thanks! This looks good to me. One comment, though:
Some people may have different opinions on how to manage other people's patches, but here's mine:
If you have made changes to a patch from someone else (me, in this case), other than really trivial typo fixes or such, you should add your signed-off-by.
Also, if you change the patch in a way that might make it behave differently than the original, you should change the ownership to yourself, drop the original signed-off-by, and perhaps say in the desc that the original was written by xyz. I don't want "my" patch to cause kernel crashes, if it's really not my code =).
Actually I didn't touch those patches a lot. Apart from the first one (the atomic stuff) and the kernel-doc style comment in the last patch, it is pretty much the stuff that you authored and is now part of TI's tree.
Quoted 4 lines
Actually, I see we now have "Co-developed-by" documented in
Documentation/process/5.Posting.rst. That may be suitable here.And for the patches that you didn't touch, I'm sure you've still gone through those, so you could add your reviewed-by.
Done.
Thanks
JJ
Quoted 3 lines
Tomi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 54 lines · Jean-Jacques Hiblot
Quoted 52 lines · Tomi Valkeinen
Quoted 38 lines · Jean-Jacques Hiblot
A first version of this work had been sent by Tomi Valkeinen in may 2017
(https://www.spinics.net/lists/dri-devel/msg140663.html).This series adds a few new
OMAP_BOflags to help the userspace manage situations where it needs to use lots of buffers, and would currently run out of TILER space. The TILER space is limited to mapping 128MB at any given time and some applications might need more.This seres is also the opportunity to do some cleanup in the flags and improve the comments describing them.
The user-space patches for libdrm, although ready, haven't been posted yet. It will be be done when this series have been discussed and hopefully in the process of getting merged.
JJ
changes in v3:
- rebase on top of v5.4-rc2
- Documentomap_gem_new()and the new flags using the kernel-doc formatchanges in v2:
- fixed build error that crept in during rebase before sending (sorry about that)
- rework the refcount part a bit.Jean-Jacques Hiblot (1):
drm/omap: use refcount API to track the number of users ofdma_addrTomi Valkeinen (7):
drm/omap: addomap_gem_unpin_locked()drm/omap: accept NULL fordma_addrinomap_gem_pindrm/omap: cleanupOMAP_BOflags
drm/omap: removeOMAP_BO_TILEDdefine drm/omap: cleanupOMAP_BO_SCANOUTuse drm/omap: addomap_gem_validate_flags()drm/omap: addOMAP_BOflags to affect buffer allocationQuoted 6 lines
drivers/gpu/drm/omapdrm/omap_dmm_tiler.h | 2 +- drivers/gpu/drm/omapdrm/omap_fb.c | 6 +- drivers/gpu/drm/omapdrm/omap_gem.c | 191 ++++++++++++++++------
drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c| 2 +- include/uapi/drm/omap_drm.h | 27 ++-5 files changed, 164 insertions(+), 64 deletions(-)Thanks! This looks good to me. One comment, though:
Some people may have different opinions on how to manage other people's patches, but here's mine:
If you have made changes to a patch from someone else (me, in this case), other than really trivial typo fixes or such, you should add your signed-off-by.
Quoted 8 lines
Quoted 1 line
Also, if you change the patch in a way that might make it behave differently than the original, you should change the ownership to yourself, drop the original signed-off-by, and perhaps say in the desc that the original was written by xyz. I don't want "my" patch to cause kernel crashes, if it's really not my code =).
Actually I didn't touch those patches a lot. Apart from the first one (the atomic stuff) and the kernel-doc style comment in the last patch, it is pretty much the stuff that you authored and is now part of TI's tree.
Quoted 4 lines
Actually, I see we now have "Co-developed-by" documented in
Documentation/process/5.Posting.rst. That may be suitable here.And for the patches that you didn't touch, I'm sure you've still gone through those, so you could add your reviewed-by.
Done.
Thanks! I'll push these to drm-misc-next.
Tomi
Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel