1 /**************************************************************************
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
39 #include <sys/ioctl.h>
40 #include <sys/types.h>
47 #include <tbm_bufmgr.h>
48 #include <tbm_bufmgr_backend.h>
49 #include <drm/sprd_drm.h>
51 #include <tbm_surface.h>
55 //#define USE_CONTIG_ONLY
58 #define TBM_COLOR_FORMAT_COUNT 8
63 #define LOG_TAG "TBM_BACKEND"
71 static int initialized = 0;
72 static char app_name[128];
77 /* get the application name */
78 f = fopen("/proc/self/cmdline", "r");
85 memset(app_name, 0x00, sizeof(app_name));
87 if ( fgets(app_name, 100, f) == NULL )
95 if ( (slash=strrchr(app_name, '/')) != NULL )
97 memmove(app_name, slash+1, strlen(slash));
104 #define TBM_SPRD_LOG(fmt, args...) LOGE("\033[31m" "[%s]" fmt "\033[0m", target_name(), ##args)
105 #define DBG(fmt, args...) if(bDebug&01) LOGE("[%s]" fmt, target_name(), ##args)
107 #define TBM_SPRD_LOG(...)
111 #define SIZE_ALIGN( value, base ) (((value) + ((base) - 1)) & ~((base) - 1))
113 #define TBM_SURFACE_ALIGNMENT_PLANE (64)
114 #define TBM_SURFACE_ALIGNMENT_PITCH_RGB (64)
115 #define TBM_SURFACE_ALIGNMENT_PITCH_YUV (16)
118 /* check condition */
119 #define SPRD_RETURN_IF_FAIL(cond) {\
121 TBM_SPRD_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\
125 #define SPRD_RETURN_VAL_IF_FAIL(cond, val) {\
127 TBM_SPRD_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\
132 struct dma_buf_info {
134 unsigned int fence_supported;
135 unsigned int padding;
138 #define DMA_BUF_ACCESS_READ 0x1
139 #define DMA_BUF_ACCESS_WRITE 0x2
140 #define DMA_BUF_ACCESS_DMA 0x4
141 #define DMA_BUF_ACCESS_MAX 0x8
143 #define DMA_FENCE_LIST_MAX 5
145 struct dma_buf_fence {
150 #define DMABUF_IOCTL_BASE 'F'
151 #define DMABUF_IOWR(nr, type) _IOWR(DMABUF_IOCTL_BASE, nr, type)
153 #define DMABUF_IOCTL_GET_INFO DMABUF_IOWR(0x00, struct dma_buf_info)
154 #define DMABUF_IOCTL_GET_FENCE DMABUF_IOWR(0x01, struct dma_buf_fence)
155 #define DMABUF_IOCTL_PUT_FENCE DMABUF_IOWR(0x02, struct dma_buf_fence)
157 typedef struct _tbm_bufmgr_sprd *tbm_bufmgr_sprd;
158 typedef struct _tbm_bo_sprd *tbm_bo_sprd;
160 typedef struct _sprd_private
165 /* tbm buffor object for sprd */
170 unsigned int name; /* FLINK ID */
172 unsigned int gem; /* GEM Handle */
174 unsigned int dmabuf; /* fd for dmabuf */
176 void *pBase; /* virtual address */
180 unsigned int flags_sprd;
181 unsigned int flags_tbm;
185 pthread_mutex_t mutex;
186 struct dma_buf_fence dma_fence[DMA_FENCE_LIST_MAX];
191 /* tbm bufmgr private for sprd */
192 struct _tbm_bufmgr_sprd
218 uint32_t tbm_sprd_color_format_list[TBM_COLOR_FORMAT_COUNT] = { TBM_FORMAT_RGBA8888,
228 #ifndef USE_CONTIG_ONLY
230 _get_sprd_flag_from_tbm (unsigned int ftbm)
232 unsigned int flags = 0;
235 * TBM_BO_DEFAULT => ION_HEAP_ID_MASK_SYSTEM
236 * TBM_BO_SCANOUT => ION_HEAP_ID_MASK_MM
237 * TBM_BO_VENDOR => ION_HEAP_ID_MASK_OVERLAY
238 * To be updated appropriately once DRM-GEM supports different heap id masks.
241 if (ftbm & TBM_BO_SCANOUT)
243 flags = SPRD_BO_CONTIG;
247 flags = SPRD_BO_NONCONTIG | SPRD_BO_DEV_SYSTEM;
250 if (ftbm & TBM_BO_WC)
252 else if (ftbm & TBM_BO_NONCACHABLE)
253 flags |= SPRD_BO_NONCACHABLE;
259 _get_tbm_flag_from_sprd (unsigned int fsprd)
261 unsigned int flags = 0;
263 if (fsprd & SPRD_BO_NONCONTIG)
264 flags |= TBM_BO_DEFAULT;
266 flags |= TBM_BO_SCANOUT;
268 if (fsprd & SPRD_BO_WC)
270 else if (fsprd & SPRD_BO_CACHABLE)
271 flags |= TBM_BO_DEFAULT;
273 flags |= TBM_BO_NONCACHABLE;
280 _get_name (int fd, unsigned int gem)
282 struct drm_gem_flink arg = {0,};
285 if (drmIoctl (fd, DRM_IOCTL_GEM_FLINK, &arg))
287 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
288 "error %s:%d fail to get flink gem=%d\n",
289 getpid(), __FUNCTION__, __LINE__, gem);
293 return (unsigned int)arg.name;
297 _sprd_bo_handle (tbm_bo_sprd bo_sprd, int device)
299 tbm_bo_handle bo_handle;
300 memset (&bo_handle, 0x0, sizeof (uint64_t));
304 case TBM_DEVICE_DEFAULT:
306 bo_handle.u32 = (uint32_t)bo_sprd->gem;
311 struct drm_sprd_gem_mmap arg = {0,};
313 arg.handle = bo_sprd->gem;
314 arg.size = bo_sprd->size;
315 if (drmCommandWriteRead (bo_sprd->fd, DRM_SPRD_GEM_MMAP, &arg, sizeof(arg)))
317 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
318 "error %s:%d Cannot usrptr gem=%d\n",
319 getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
320 return (tbm_bo_handle) NULL;
322 bo_sprd->pBase = (void*)((uint32_t)arg.mapped);
325 bo_handle.ptr = (void *)bo_sprd->pBase;
329 if (!bo_sprd->dmabuf)
331 struct drm_prime_handle arg = {0, };
332 arg.handle = bo_sprd->gem;
333 if (drmIoctl (bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg))
335 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
336 "error %s:%d Cannot dmabuf=%d\n",
337 getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
338 return (tbm_bo_handle) NULL;
340 bo_sprd->dmabuf = arg.fd;
343 bo_handle.u32 = (uint32_t)bo_sprd->dmabuf;
350 //TODO : Add ioctl for GSP MAP once available.
351 DBG ("[libtbm-sprd:%d] %s In case TBM_DEVICE_MM: \n", getpid(),
355 if (!bo_sprd->dmabuf)
357 struct drm_prime_handle arg = {0, };
359 arg.handle = bo_sprd->gem;
360 if (drmIoctl (bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg))
362 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
363 "error %s:%d Cannot dmabuf=%d\n",
364 getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
365 return (tbm_bo_handle) NULL;
367 bo_sprd->dmabuf = arg.fd;
370 bo_handle.u32 = (uint32_t)bo_sprd->dmabuf;
374 bo_handle.ptr = (void *) NULL;
383 _sprd_cache_flush (int fd, tbm_bo_sprd bo_sprd, int flags)
385 struct drm_sprd_gem_cache_op cache_op = {0, };
388 /* if bo_sprd is null, do cache_flush_all */
392 cache_op.usr_addr = (uint64_t)((uint32_t)bo_sprd->pBase);
393 cache_op.size = bo_sprd->size;
397 flags = TBM_CACHE_FLUSH_ALL;
399 cache_op.usr_addr = 0;
403 if (flags & TBM_CACHE_INV)
405 if(flags & TBM_CACHE_ALL)
406 cache_op.flags |= SPRD_DRM_CACHE_INV_ALL;
408 cache_op.flags |= SPRD_DRM_CACHE_INV_RANGE;
411 if (flags & TBM_CACHE_CLN)
413 if(flags & TBM_CACHE_ALL)
414 cache_op.flags |= SPRD_DRM_CACHE_CLN_ALL;
416 cache_op.flags |= SPRD_DRM_CACHE_CLN_RANGE;
419 if(flags & TBM_CACHE_ALL)
420 cache_op.flags |= SPRD_DRM_ALL_CACHES_CORES;
422 ret = drmCommandWriteRead (fd, DRM_SPRD_GEM_CACHE_OP, &cache_op, sizeof(cache_op));
425 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
426 "error %s:%d fail to flush the cache.\n",
427 getpid(), __FUNCTION__, __LINE__);
436 tbm_sprd_bo_size (tbm_bo bo)
438 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
442 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
444 return bo_sprd->size;
448 tbm_sprd_bo_alloc (tbm_bo bo, int size, int flags)
450 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
453 tbm_bufmgr_sprd bufmgr_sprd;
454 unsigned int sprd_flags;
456 bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
457 SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd!=NULL, 0);
459 bo_sprd = calloc (1, sizeof(struct _tbm_bo_sprd));
462 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
463 "error %s:%d fail to allocate the bo private\n",
464 getpid(), __FUNCTION__, __LINE__);
468 #ifdef USE_CONTIG_ONLY
469 flags = TBM_BO_SCANOUT;
470 sprd_flags = SPRD_BO_CONTIG;
472 sprd_flags = _get_sprd_flag_from_tbm (flags);
473 if((flags & TBM_BO_SCANOUT) &&
476 sprd_flags |= SPRD_BO_NONCONTIG;
478 #endif // USE_CONTIG_ONLY
479 struct drm_sprd_gem_create arg = {0, };
481 arg.flags = sprd_flags;
482 if (drmCommandWriteRead(bufmgr_sprd->fd, DRM_SPRD_GEM_CREATE, &arg, sizeof(arg)))
484 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
485 "error %s:%d Cannot create bo(flag:%x, size:%d)\n",
486 getpid(), __FUNCTION__, __LINE__, arg.flags, (unsigned int)arg.size);
491 bo_sprd->fd = bufmgr_sprd->fd;
492 bo_sprd->gem = arg.handle;
493 bo_sprd->size = size;
494 bo_sprd->flags_tbm = flags;
495 bo_sprd->flags_sprd = sprd_flags;
496 bo_sprd->name = _get_name (bo_sprd->fd, bo_sprd->gem);
498 pthread_mutex_init(&bo_sprd->mutex, NULL);
500 if (bufmgr_sprd->use_dma_fence
503 struct drm_prime_handle arg = {0, };
505 arg.handle = bo_sprd->gem;
506 if (drmIoctl (bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg))
508 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
509 "error %s:%d Cannot dmabuf=%d\n",
510 getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
514 bo_sprd->dmabuf = arg.fd;
518 PrivGem* privGem = calloc (1, sizeof(PrivGem));
519 privGem->ref_count = 1;
520 if (drmHashInsert(bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0)
522 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
523 "error %s:%d Cannot insert bo to Hash(%d)\n",
524 getpid(), __FUNCTION__, __LINE__, bo_sprd->name);
527 DBG ("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(),
528 __FUNCTION__, bo_sprd->size,
529 bo_sprd->gem, bo_sprd->name,
532 return (void *)bo_sprd;
536 tbm_sprd_bo_free(tbm_bo bo)
539 tbm_bufmgr_sprd bufmgr_sprd;
544 bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
545 SPRD_RETURN_IF_FAIL (bufmgr_sprd!=NULL);
547 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
548 SPRD_RETURN_IF_FAIL (bo_sprd!=NULL);
550 DBG ("[libtbm-sprd:%d] %s size:%d, gem:%d(%d)\n",
551 getpid(), __FUNCTION__, bo_sprd->size, bo_sprd->gem, bo_sprd->name);
555 if (munmap(bo_sprd->pBase, bo_sprd->size) == -1)
557 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
559 getpid(), __FUNCTION__, __LINE__);
566 close (bo_sprd->dmabuf);
570 /* delete bo from hash */
571 PrivGem *privGem = NULL;
574 ret = drmHashLookup (bufmgr_sprd->hashBos, bo_sprd->name, (void**)&privGem);
577 privGem->ref_count--;
578 if (privGem->ref_count == 0)
580 drmHashDelete (bufmgr_sprd->hashBos, bo_sprd->name);
587 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
588 "warning %s:%d Cannot find bo to Hash(%d), ret=%d\n",
589 getpid(), __FUNCTION__, __LINE__, bo_sprd->name, ret);
592 /* Free gem handle */
593 struct drm_gem_close arg = {0, };
594 memset (&arg, 0, sizeof(arg));
595 arg.handle = bo_sprd->gem;
596 if (drmIoctl (bo_sprd->fd, DRM_IOCTL_GEM_CLOSE, &arg))
598 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
600 getpid(), __FUNCTION__, __LINE__);
608 tbm_sprd_bo_import (tbm_bo bo, unsigned int key)
610 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
612 tbm_bufmgr_sprd bufmgr_sprd;
615 bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
616 SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd!=NULL, 0);
618 struct drm_gem_open arg = {0, };
619 struct drm_sprd_gem_info info = {0, };
622 if (drmIoctl(bufmgr_sprd->fd, DRM_IOCTL_GEM_OPEN, &arg))
624 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
625 "error %s:%d Cannot open gem name=%d\n",
626 getpid(), __FUNCTION__, __LINE__, key);
630 info.handle = arg.handle;
631 if (drmCommandWriteRead(bufmgr_sprd->fd,
634 sizeof(struct drm_sprd_gem_info)))
636 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
637 "error %s:%d Cannot get gem info=%d\n",
638 getpid(), __FUNCTION__, __LINE__, key);
642 bo_sprd = calloc (1, sizeof(struct _tbm_bo_sprd));
645 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
646 "error %s:%d fail to allocate the bo private\n",
647 getpid(), __FUNCTION__, __LINE__);
651 bo_sprd->fd = bufmgr_sprd->fd;
652 bo_sprd->gem = arg.handle;
653 bo_sprd->size = arg.size;
654 bo_sprd->flags_sprd = info.flags;
656 #ifdef USE_CONTIG_ONLY
657 bo_sprd->flags_sprd = SPRD_BO_CONTIG;
658 bo_sprd->flags_tbm |= TBM_BO_SCANOUT;
660 bo_sprd->flags_tbm = _get_tbm_flag_from_sprd (bo_sprd->flags_sprd);
664 if (!bo_sprd->dmabuf)
666 struct drm_prime_handle arg = {0, };
668 arg.handle = bo_sprd->gem;
669 if (drmIoctl (bo_sprd->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg))
671 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
672 "error %s:%d Cannot dmabuf=%d\n",
673 getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
677 bo_sprd->dmabuf = arg.fd;
681 PrivGem *privGem = NULL;
684 ret = drmHashLookup (bufmgr_sprd->hashBos, bo_sprd->name, (void**)&privGem);
687 privGem->ref_count++;
691 privGem = calloc (1, sizeof(PrivGem));
692 privGem->ref_count = 1;
693 if (drmHashInsert (bufmgr_sprd->hashBos, bo_sprd->name, (void *)privGem) < 0)
695 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
696 "error %s:%d Cannot insert bo to Hash(%d)\n",
697 getpid(), __FUNCTION__, __LINE__, bo_sprd->name);
702 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
703 "error %s:%d Cannot insert bo to Hash(%d)\n",
704 getpid(), __FUNCTION__, __LINE__, bo_sprd->name);
707 DBG ("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(),
708 __FUNCTION__, bo_sprd->size,
709 bo_sprd->gem, bo_sprd->name,
710 bo_sprd->flags_tbm, bo_sprd->flags_sprd);
712 return (void *)bo_sprd;
716 tbm_sprd_bo_export (tbm_bo bo)
718 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
722 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
723 SPRD_RETURN_VAL_IF_FAIL (bo_sprd!=NULL, 0);
727 bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem);
730 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
731 "error %s:%d Cannot get name\n",
732 getpid(), __FUNCTION__, __LINE__);
737 DBG ("[libtbm-sprd:%d] %s size:%d, gem:%d(%d), flags:%d(%d)\n", getpid(),
738 __FUNCTION__, bo_sprd->size,
739 bo_sprd->gem, bo_sprd->name,
740 bo_sprd->flags_tbm, bo_sprd->flags_sprd);
742 return (unsigned int)bo_sprd->name;
746 tbm_sprd_bo_get_handle (tbm_bo bo, int device)
748 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, (tbm_bo_handle) NULL);
750 tbm_bo_handle bo_handle;
753 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
754 SPRD_RETURN_VAL_IF_FAIL (bo_sprd!=NULL, (tbm_bo_handle) NULL);
758 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
759 "error %s:%d Cannot map gem=%d\n",
760 getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
761 return (tbm_bo_handle) NULL;
764 DBG ("[libtbm-sprd:%d] %s gem:%d(%d), %s\n", getpid(),
765 __FUNCTION__, bo_sprd->gem, bo_sprd->name, STR_DEVICE[device]);
767 /*Get mapped bo_handle*/
768 bo_handle = _sprd_bo_handle (bo_sprd, device);
769 if (bo_handle.ptr == NULL)
771 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
772 "error %s:%d Cannot get handle: gem:%d, device:%d\n",
773 getpid(), __FUNCTION__, __LINE__, bo_sprd->gem, device);
774 return (tbm_bo_handle) NULL;
781 tbm_sprd_bo_map (tbm_bo bo, int device, int opt)
783 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, (tbm_bo_handle) NULL);
785 tbm_bo_handle bo_handle;
788 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
789 SPRD_RETURN_VAL_IF_FAIL (bo_sprd!=NULL, (tbm_bo_handle) NULL);
793 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
794 "error %s:%d Cannot map gem=%d\n",
795 getpid(), __FUNCTION__, __LINE__, bo_sprd->gem);
796 return (tbm_bo_handle) NULL;
799 DBG ("[libtbm-sprd:%d] %s gem:%d(%d), %s, %s\n", getpid(),
800 __FUNCTION__, bo_sprd->gem, bo_sprd->name, STR_DEVICE[device], STR_OPT[opt]);
802 /*Get mapped bo_handle*/
803 bo_handle = _sprd_bo_handle (bo_sprd, device);
804 if (bo_handle.ptr == NULL)
806 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
807 "error %s:%d Cannot get handle: gem:%d, device:%d, opt:%d\n",
808 getpid(), __FUNCTION__, __LINE__, bo_sprd->gem, device, opt);
809 return (tbm_bo_handle) NULL;
816 tbm_sprd_bo_unmap (tbm_bo bo)
818 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
822 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
823 SPRD_RETURN_VAL_IF_FAIL (bo_sprd!=NULL, 0);
828 DBG ("[libtbm-sprd:%d] %s gem:%d(%d) \n", getpid(),
829 __FUNCTION__, bo_sprd->gem, bo_sprd->name);
835 tbm_sprd_bo_cache_flush (tbm_bo bo, int flags)
837 tbm_bufmgr_sprd bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
838 SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd!=NULL, 0);
840 /* cache flush is managed by kernel side when using dma-fence. */
841 if (bufmgr_sprd->use_dma_fence)
844 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
848 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
849 SPRD_RETURN_VAL_IF_FAIL (bo_sprd!=NULL, 0);
852 if (!_sprd_cache_flush(bo_sprd->fd, bo_sprd, flags))
860 tbm_sprd_bo_get_global_key (tbm_bo bo)
862 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
866 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
867 SPRD_RETURN_VAL_IF_FAIL (bo_sprd!=NULL, 0);
874 bo_sprd->name = _get_name(bo_sprd->fd, bo_sprd->gem);
877 return bo_sprd->name;
881 tbm_sprd_bo_lock(tbm_bo bo, int device, int opt)
883 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
886 tbm_bufmgr_sprd bufmgr_sprd;
888 struct dma_buf_fence fence;
891 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
892 SPRD_RETURN_VAL_IF_FAIL (bo_sprd!=NULL, 0);
894 bufmgr_sprd = (tbm_bufmgr_sprd)tbm_backend_get_bufmgr_priv(bo);
895 SPRD_RETURN_VAL_IF_FAIL (bufmgr_sprd!=NULL, 0);
897 memset(&fence, 0, sizeof(struct dma_buf_fence));
899 /* Check if the given type is valid or not. */
900 if (opt & TBM_OPTION_WRITE)
902 if (device == TBM_DEVICE_CPU)
903 fence.type = DMA_BUF_ACCESS_WRITE;
904 else if (device == TBM_DEVICE_3D)
905 fence.type = DMA_BUF_ACCESS_WRITE | DMA_BUF_ACCESS_DMA;
908 DBG ("[libtbm-sprd:%d] %s GET_FENCE is ignored(device type is not 3D/CPU),\n", getpid(), __FUNCTION__);
912 else if (opt & TBM_OPTION_READ)
914 if (device == TBM_DEVICE_CPU)
915 fence.type = DMA_BUF_ACCESS_READ;
916 else if (device == TBM_DEVICE_3D)
917 fence.type = DMA_BUF_ACCESS_READ | DMA_BUF_ACCESS_DMA;
920 DBG ("[libtbm-sprd:%d] %s GET_FENCE is ignored(device type is not 3D/CPU),\n", getpid(), __FUNCTION__);
926 TBM_SPRD_LOG ("[libtbm-sprd:%d] error %s:%d Invalid argument\n", getpid(), __FUNCTION__, __LINE__);
930 /* Check if the tbm manager supports dma fence or not. */
931 if (!bufmgr_sprd->use_dma_fence)
933 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
934 "error %s:%d Not support DMA FENCE(%s)\n",
935 getpid(), __FUNCTION__, __LINE__, strerror(errno) );
940 ret = ioctl(bo_sprd->dmabuf, DMABUF_IOCTL_GET_FENCE, &fence);
943 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
944 "error %s:%d Can not set GET FENCE(%s)\n",
945 getpid(), __FUNCTION__, __LINE__, strerror(errno) );
949 pthread_mutex_lock(&bo_sprd->mutex);
951 for (i = 0; i < DMA_FENCE_LIST_MAX; i++)
953 if (bo_sprd->dma_fence[i].ctx == 0)
955 bo_sprd->dma_fence[i].type = fence.type;
956 bo_sprd->dma_fence[i].ctx = fence.ctx;
960 if (i == DMA_FENCE_LIST_MAX)
962 //TODO: if dma_fence list is full, it needs realloc. I will fix this. by minseok3.kim
963 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
964 "error %s:%d fence list is full\n",
965 getpid(), __FUNCTION__, __LINE__);
967 pthread_mutex_unlock(&bo_sprd->mutex);
969 DBG ("[libtbm-sprd:%d] %s DMABUF_IOCTL_GET_FENCE! flink_id=%d dmabuf=%d\n", getpid(),
970 __FUNCTION__, bo_sprd->name, bo_sprd->dmabuf);
977 tbm_sprd_bo_unlock(tbm_bo bo)
979 SPRD_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
983 struct dma_buf_fence fence;
986 bo_sprd = (tbm_bo_sprd)tbm_backend_get_bo_priv(bo);
987 SPRD_RETURN_VAL_IF_FAIL (bo_sprd!=NULL, 0);
989 if (!bo_sprd->dma_fence[0].ctx)
991 DBG ("[libtbm-sprd:%d] %s FENCE not support or ignored,\n", getpid(), __FUNCTION__);
995 if (!bo_sprd->dma_fence[0].type)
997 DBG ("[libtbm-sprd:%d] %s device type is not 3D/CPU,\n", getpid(), __FUNCTION__);
1001 pthread_mutex_lock(&bo_sprd->mutex);
1002 fence.type = bo_sprd->dma_fence[0].type;
1003 fence.ctx = bo_sprd->dma_fence[0].ctx;
1005 for (i = 1; i < DMA_FENCE_LIST_MAX; i++)
1007 bo_sprd->dma_fence[i-1].type = bo_sprd->dma_fence[i].type;
1008 bo_sprd->dma_fence[i-1].ctx = bo_sprd->dma_fence[i].ctx;
1010 bo_sprd->dma_fence[DMA_FENCE_LIST_MAX-1].type = 0;
1011 bo_sprd->dma_fence[DMA_FENCE_LIST_MAX-1].ctx = 0;
1012 pthread_mutex_unlock(&bo_sprd->mutex);
1014 ret = ioctl(bo_sprd->dmabuf, DMABUF_IOCTL_PUT_FENCE, &fence);
1017 TBM_SPRD_LOG ("[libtbm-sprd:%d] "
1018 "error %s:%d Can not set PUT FENCE(%s)\n",
1019 getpid(), __FUNCTION__, __LINE__, strerror(errno) );
1023 DBG ("[libtbm-sprd:%d] %s DMABUF_IOCTL_PUT_FENCE! flink_id=%d dmabuf=%d\n", getpid(),
1024 __FUNCTION__, bo_sprd->name, bo_sprd->dmabuf);
1031 tbm_sprd_bufmgr_deinit (void *priv)
1033 SPRD_RETURN_IF_FAIL (priv!=NULL);
1035 tbm_bufmgr_sprd bufmgr_sprd;
1037 bufmgr_sprd = (tbm_bufmgr_sprd)priv;
1039 if (bufmgr_sprd->hashBos)
1044 while (drmHashFirst(bufmgr_sprd->hashBos, &key, &value) > 0)
1047 drmHashDelete (bufmgr_sprd->hashBos, key);
1050 drmHashDestroy (bufmgr_sprd->hashBos);
1051 bufmgr_sprd->hashBos = NULL;
1058 tbm_sprd_surface_supported_format(uint32_t **formats, uint32_t *num)
1060 uint32_t* color_formats=NULL;
1062 color_formats = (uint32_t*)calloc (1,sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT);
1064 if( color_formats == NULL )
1068 memcpy( color_formats, tbm_sprd_color_format_list , sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT );
1071 *formats = color_formats;
1072 *num = TBM_COLOR_FORMAT_COUNT;
1080 * @brief get the plane data of the surface.
1081 * @param[in] surface : the surface
1082 * @param[in] width : the width of the surface
1083 * @param[in] height : the height of the surface
1084 * @param[in] format : the format of the surface
1085 * @param[in] plane_idx : the format of the surface
1086 * @param[out] size : the size of the plane
1087 * @param[out] offset : the offset of the plane
1088 * @param[out] pitch : the pitch of the plane
1089 * @param[out] padding : the padding of the plane
1090 * @return 1 if this function succeeds, otherwise 0.
1093 tbm_sprd_surface_get_plane_data(tbm_surface_h surface, int width, int height, tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx)
1105 case TBM_FORMAT_XRGB4444:
1106 case TBM_FORMAT_XBGR4444:
1107 case TBM_FORMAT_RGBX4444:
1108 case TBM_FORMAT_BGRX4444:
1109 case TBM_FORMAT_ARGB4444:
1110 case TBM_FORMAT_ABGR4444:
1111 case TBM_FORMAT_RGBA4444:
1112 case TBM_FORMAT_BGRA4444:
1113 case TBM_FORMAT_XRGB1555:
1114 case TBM_FORMAT_XBGR1555:
1115 case TBM_FORMAT_RGBX5551:
1116 case TBM_FORMAT_BGRX5551:
1117 case TBM_FORMAT_ARGB1555:
1118 case TBM_FORMAT_ABGR1555:
1119 case TBM_FORMAT_RGBA5551:
1120 case TBM_FORMAT_BGRA5551:
1121 case TBM_FORMAT_RGB565:
1124 _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
1125 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1129 case TBM_FORMAT_RGB888:
1130 case TBM_FORMAT_BGR888:
1133 _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
1134 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1138 case TBM_FORMAT_XRGB8888:
1139 case TBM_FORMAT_XBGR8888:
1140 case TBM_FORMAT_RGBX8888:
1141 case TBM_FORMAT_BGRX8888:
1142 case TBM_FORMAT_ARGB8888:
1143 case TBM_FORMAT_ABGR8888:
1144 case TBM_FORMAT_RGBA8888:
1145 case TBM_FORMAT_BGRA8888:
1148 _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
1149 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1154 case TBM_FORMAT_YUYV:
1155 case TBM_FORMAT_YVYU:
1156 case TBM_FORMAT_UYVY:
1157 case TBM_FORMAT_VYUY:
1158 case TBM_FORMAT_AYUV:
1161 _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1162 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1168 * index 0 = Y plane, [7:0] Y
1169 * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
1171 * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
1173 case TBM_FORMAT_NV12:
1174 case TBM_FORMAT_NV21:
1179 _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1180 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1183 else if( plane_idx ==1 )
1185 _offset = width*height;
1186 _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1187 _size = SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
1192 case TBM_FORMAT_NV16:
1193 case TBM_FORMAT_NV61:
1195 //if(plane_idx == 0)
1198 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1199 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1204 //else if( plane_idx ==1 )
1207 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1208 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1215 * index 0: Y plane, [7:0] Y
1216 * index 1: Cb plane, [7:0] Cb
1217 * index 2: Cr plane, [7:0] Cr
1219 * index 1: Cr plane, [7:0] Cr
1220 * index 2: Cb plane, [7:0] Cb
1223 NATIVE_BUFFER_FORMAT_YV12
1224 NATIVE_BUFFER_FORMAT_I420
1226 case TBM_FORMAT_YUV410:
1227 case TBM_FORMAT_YVU410:
1230 case TBM_FORMAT_YUV411:
1231 case TBM_FORMAT_YVU411:
1232 case TBM_FORMAT_YUV420:
1233 case TBM_FORMAT_YVU420:
1235 //if(plane_idx == 0)
1238 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1239 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1244 //else if( plane_idx == 1 )
1247 _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1248 _size = SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
1253 //else if (plane_idx == 2 )
1256 _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1257 _size = SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
1261 case TBM_FORMAT_YUV422:
1262 case TBM_FORMAT_YVU422:
1264 //if(plane_idx == 0)
1267 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1268 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1273 //else if( plane_idx == 1 )
1276 _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1277 _size = SIZE_ALIGN(_pitch*(height),TBM_SURFACE_ALIGNMENT_PLANE);
1282 //else if (plane_idx == 2 )
1285 _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1286 _size = SIZE_ALIGN(_pitch*(height),TBM_SURFACE_ALIGNMENT_PLANE);
1290 case TBM_FORMAT_YUV444:
1291 case TBM_FORMAT_YVU444:
1293 //if(plane_idx == 0)
1296 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1297 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1302 //else if( plane_idx == 1 )
1305 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1306 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1311 //else if (plane_idx == 2 )
1314 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1315 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1332 * @brief get the size of the surface with a format.
1333 * @param[in] surface : the surface
1334 * @param[in] width : the width of the surface
1335 * @param[in] height : the height of the surface
1336 * @param[in] format : the format of the surface
1337 * @return size of the surface if this function succeeds, otherwise 0.
1341 tbm_sprd_surface_get_size(tbm_surface_h surface, int width, int height, tbm_format format)
1347 int align =TBM_SURFACE_ALIGNMENT_PLANE;
1353 case TBM_FORMAT_XRGB4444:
1354 case TBM_FORMAT_XBGR4444:
1355 case TBM_FORMAT_RGBX4444:
1356 case TBM_FORMAT_BGRX4444:
1357 case TBM_FORMAT_ARGB4444:
1358 case TBM_FORMAT_ABGR4444:
1359 case TBM_FORMAT_RGBA4444:
1360 case TBM_FORMAT_BGRA4444:
1361 case TBM_FORMAT_XRGB1555:
1362 case TBM_FORMAT_XBGR1555:
1363 case TBM_FORMAT_RGBX5551:
1364 case TBM_FORMAT_BGRX5551:
1365 case TBM_FORMAT_ARGB1555:
1366 case TBM_FORMAT_ABGR1555:
1367 case TBM_FORMAT_RGBA5551:
1368 case TBM_FORMAT_BGRA5551:
1369 case TBM_FORMAT_RGB565:
1371 _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
1372 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1375 case TBM_FORMAT_RGB888:
1376 case TBM_FORMAT_BGR888:
1378 _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
1379 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1382 case TBM_FORMAT_XRGB8888:
1383 case TBM_FORMAT_XBGR8888:
1384 case TBM_FORMAT_RGBX8888:
1385 case TBM_FORMAT_BGRX8888:
1386 case TBM_FORMAT_ARGB8888:
1387 case TBM_FORMAT_ABGR8888:
1388 case TBM_FORMAT_RGBA8888:
1389 case TBM_FORMAT_BGRA8888:
1391 _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
1392 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1395 case TBM_FORMAT_YUYV:
1396 case TBM_FORMAT_YVYU:
1397 case TBM_FORMAT_UYVY:
1398 case TBM_FORMAT_VYUY:
1399 case TBM_FORMAT_AYUV:
1401 _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1402 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1406 * index 0 = Y plane, [7:0] Y
1407 * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
1409 * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
1411 case TBM_FORMAT_NV12:
1412 case TBM_FORMAT_NV21:
1416 _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1417 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1421 _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1422 _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
1425 case TBM_FORMAT_NV16:
1426 case TBM_FORMAT_NV61:
1430 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1431 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1435 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1436 _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1442 * index 0: Y plane, [7:0] Y
1443 * index 1: Cb plane, [7:0] Cb
1444 * index 2: Cr plane, [7:0] Cr
1446 * index 1: Cr plane, [7:0] Cr
1447 * index 2: Cb plane, [7:0] Cb
1449 case TBM_FORMAT_YUV410:
1450 case TBM_FORMAT_YVU410:
1452 align = TBM_SURFACE_ALIGNMENT_PITCH_YUV;
1454 case TBM_FORMAT_YUV411:
1455 case TBM_FORMAT_YVU411:
1456 case TBM_FORMAT_YUV420:
1457 case TBM_FORMAT_YVU420:
1461 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1462 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1466 _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1467 _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
1471 _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1472 _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
1476 case TBM_FORMAT_YUV422:
1477 case TBM_FORMAT_YVU422:
1481 _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
1482 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1486 _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1487 _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1491 _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
1492 _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
1495 case TBM_FORMAT_YUV444:
1496 case TBM_FORMAT_YVU444:
1498 align = TBM_SURFACE_ALIGNMENT_PITCH_YUV;
1509 ret = SIZE_ALIGN( (width * height * bpp) >> 3, align);
1516 tbm_sprd_surface_get_num_bos(tbm_format format)
1523 case TBM_FORMAT_XRGB4444:
1524 case TBM_FORMAT_XBGR4444:
1525 case TBM_FORMAT_RGBX4444:
1526 case TBM_FORMAT_BGRX4444:
1527 case TBM_FORMAT_ARGB4444:
1528 case TBM_FORMAT_ABGR4444:
1529 case TBM_FORMAT_RGBA4444:
1530 case TBM_FORMAT_BGRA4444:
1531 case TBM_FORMAT_XRGB1555:
1532 case TBM_FORMAT_XBGR1555:
1533 case TBM_FORMAT_RGBX5551:
1534 case TBM_FORMAT_BGRX5551:
1535 case TBM_FORMAT_ARGB1555:
1536 case TBM_FORMAT_ABGR1555:
1537 case TBM_FORMAT_RGBA5551:
1538 case TBM_FORMAT_BGRA5551:
1539 case TBM_FORMAT_RGB565:
1541 case TBM_FORMAT_RGB888:
1542 case TBM_FORMAT_BGR888:
1544 case TBM_FORMAT_XRGB8888:
1545 case TBM_FORMAT_XBGR8888:
1546 case TBM_FORMAT_RGBX8888:
1547 case TBM_FORMAT_BGRX8888:
1548 case TBM_FORMAT_ARGB8888:
1549 case TBM_FORMAT_ABGR8888:
1550 case TBM_FORMAT_RGBA8888:
1551 case TBM_FORMAT_BGRA8888:
1553 case TBM_FORMAT_YUYV:
1554 case TBM_FORMAT_YVYU:
1555 case TBM_FORMAT_UYVY:
1556 case TBM_FORMAT_VYUY:
1557 case TBM_FORMAT_AYUV:
1560 * index 0 = Y plane, [7:0] Y
1561 * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
1563 * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
1565 case TBM_FORMAT_NV12:
1566 case TBM_FORMAT_NV21:
1567 case TBM_FORMAT_NV16:
1568 case TBM_FORMAT_NV61:
1571 * index 0: Y plane, [7:0] Y
1572 * index 1: Cb plane, [7:0] Cb
1573 * index 2: Cr plane, [7:0] Cr
1575 * index 1: Cr plane, [7:0] Cr
1576 * index 2: Cb plane, [7:0] Cb
1578 case TBM_FORMAT_YUV410:
1579 case TBM_FORMAT_YVU410:
1580 case TBM_FORMAT_YUV411:
1581 case TBM_FORMAT_YVU411:
1582 case TBM_FORMAT_YUV420:
1583 case TBM_FORMAT_YVU420:
1584 case TBM_FORMAT_YUV422:
1585 case TBM_FORMAT_YVU422:
1586 case TBM_FORMAT_YUV444:
1587 case TBM_FORMAT_YVU444:
1599 MODULEINITPPROTO (init_tbm_bufmgr_priv);
1601 static TBMModuleVersionInfo SprdVersRec =
1608 TBMModuleData tbmModuleData = { &SprdVersRec, init_tbm_bufmgr_priv};
1611 init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd)
1613 tbm_bufmgr_sprd bufmgr_sprd;
1614 tbm_bufmgr_backend bufmgr_backend;
1619 bufmgr_sprd = calloc (1, sizeof(struct _tbm_bufmgr_sprd));
1622 TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to alloc bufmgr_sprd!\n", getpid());
1626 bufmgr_sprd->fd = fd;
1627 if (bufmgr_sprd->fd < 0)
1629 TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid());
1635 bufmgr_sprd->hashBos = drmHashCreate ();
1637 //Check if the tbm manager supports dma fence or not.
1638 int fp = open("/sys/module/dmabuf_sync/parameters/enabled", O_RDONLY);
1643 length = read(fp, buf, 1);
1645 if (length == 1 && buf[0] == '1')
1646 bufmgr_sprd->use_dma_fence = 1;
1651 bufmgr_backend = tbm_backend_alloc();
1652 if (!bufmgr_backend)
1654 TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to create drm!\n", getpid());
1659 bufmgr_backend->priv = (void *)bufmgr_sprd;
1660 bufmgr_backend->bufmgr_deinit = tbm_sprd_bufmgr_deinit,
1661 bufmgr_backend->bo_size = tbm_sprd_bo_size,
1662 bufmgr_backend->bo_alloc = tbm_sprd_bo_alloc,
1663 bufmgr_backend->bo_free = tbm_sprd_bo_free,
1664 bufmgr_backend->bo_import = tbm_sprd_bo_import,
1665 bufmgr_backend->bo_export = tbm_sprd_bo_export,
1666 bufmgr_backend->bo_get_handle = tbm_sprd_bo_get_handle,
1667 bufmgr_backend->bo_map = tbm_sprd_bo_map,
1668 bufmgr_backend->bo_unmap = tbm_sprd_bo_unmap,
1669 bufmgr_backend->bo_cache_flush = tbm_sprd_bo_cache_flush,
1670 bufmgr_backend->bo_get_global_key = tbm_sprd_bo_get_global_key;
1671 bufmgr_backend->surface_get_plane_data = tbm_sprd_surface_get_plane_data;
1672 bufmgr_backend->surface_get_size = tbm_sprd_surface_get_size;
1673 bufmgr_backend->surface_supported_format = tbm_sprd_surface_supported_format;
1674 bufmgr_backend->surface_get_num_bos = tbm_sprd_surface_get_num_bos;
1676 if (bufmgr_sprd->use_dma_fence)
1678 bufmgr_backend->flags = (TBM_LOCK_CTRL_BACKEND | TBM_CACHE_CTRL_BACKEND);
1679 bufmgr_backend->bo_lock = NULL;
1680 bufmgr_backend->bo_lock2 = tbm_sprd_bo_lock;
1681 bufmgr_backend->bo_unlock = tbm_sprd_bo_unlock;
1685 bufmgr_backend->flags = 0;
1686 bufmgr_backend->bo_lock = NULL;
1687 bufmgr_backend->bo_unlock = NULL;
1690 if (!tbm_backend_init (bufmgr, bufmgr_backend))
1692 TBM_SPRD_LOG ("[libtbm-sprd:%d] error: Fail to init backend!\n", getpid());
1693 tbm_backend_free (bufmgr_backend);
1701 env = getenv ("TBM_SPRD_DEBUG");
1704 bDebug = atoi (env);
1705 TBM_SPRD_LOG ("TBM_SPRD_DEBUG=%s\n", env);
1714 DBG ("[libtbm-sprd:%d] %s DMABUF FENCE is %s\n", getpid(),
1715 __FUNCTION__, bufmgr_sprd->use_dma_fence ? "supported!" : "NOT supported!");
1717 DBG ("[libtbm-sprd:%d] %s fd:%d\n", getpid(),
1718 __FUNCTION__, bufmgr_sprd->fd);