summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChangyeon Lee <cyeon.lee@samsung.com>2022-06-22 16:23:27 +0900
committerChangyeon Lee <cyeon.lee@samsung.com>2022-06-27 15:29:38 +0900
commit04a221d9b35aa91c57aa61cb9000ccc2935a7166 (patch)
treea428075dca64c1c6c2010a2dbff27e60b539a63f
parentce8262f1b690587ab17745c8f71dda63b52eb0cd (diff)
downloadlibtbm-msm-04a221d9b35aa91c57aa61cb9000ccc2935a7166.tar.gz
libtbm-msm-04a221d9b35aa91c57aa61cb9000ccc2935a7166.tar.bz2
libtbm-msm-04a221d9b35aa91c57aa61cb9000ccc2935a7166.zip
remove legacy libtbm backendtizen
Change-Id: I871ee0046f80676b0326d08de18f22157e351c0c
-rw-r--r--configure.ac24
-rw-r--r--packaging/hal-backend-tbm-msm.manifest (renamed from packaging/libhal-backend-tbm-msm.manifest)0
-rw-r--r--packaging/hal-backend-tbm-msm.spec (renamed from packaging/libtbm-msm.spec)38
-rw-r--r--packaging/libtbm-msm.manifest5
-rw-r--r--src/Makefile.am13
-rw-r--r--src/libhal-backend-tbm-msm/Makefile.am12
-rw-r--r--src/libtbm-msm/Makefile.am12
-rw-r--r--src/libtbm-msm/tbm_bufmgr_msm.c1514
-rw-r--r--src/tbm_backend_log.c (renamed from src/libhal-backend-tbm-msm/tbm_backend_log.c)0
-rw-r--r--src/tbm_backend_log.h (renamed from src/libhal-backend-tbm-msm/tbm_backend_log.h)0
-rw-r--r--src/tbm_backend_msm.c (renamed from src/libhal-backend-tbm-msm/tbm_backend_msm.c)0
11 files changed, 21 insertions, 1597 deletions
diff --git a/configure.ac b/configure.ac
index 2ba3491..5dc9ee8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AC_PREREQ(2.60)
-AC_INIT(libtbm-msm, 1.0.0)
+AC_INIT(hal-backend-tbm-msm, 1.0.0)
AC_USE_SYSTEM_EXTENSIONS
AC_CONFIG_SRCDIR([Makefile.am])
AM_INIT_AUTOMAKE([dist-bzip2])
@@ -37,7 +37,6 @@ AC_FUNC_ALLOCA
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
PKG_CHECK_MODULES(LIBDRM, libdrm)
-PKG_CHECK_MODULES(LIBTBM, libtbm)
PKG_CHECK_MODULES(GBM, gbm)
PKG_CHECK_MODULES(HAL_API_COMMON, hal-api-common)
PKG_CHECK_MODULES(HAL_API_TBM, hal-api-tbm)
@@ -51,18 +50,9 @@ AC_ARG_WITH(hal-libdir, AS_HELP_STRING([--with-hal-libdir=PATH], [hal backend li
AC_DEFINE_UNQUOTED(HAL_LIBDIR, "${HAL_LIBDIR}", [Directory for hal backend library path])
AC_SUBST(HAL_LIBDIR)
-# for libtbm-msm
-LIBTBM_MSM_CFLAGS="$LIBDRM_CFLAGS $LIBTBM_CFLAGS $LIBUDEV_CFLAGS $GBM_CFLAGS"
-LIBTBM_MSM_LIBS="$LIBDRM_LIBS $LIBTBM_LIBS $LIBUDEV_LIBS $GBM_LIBS"
-AC_SUBST(LIBTBM_MSM_CFLAGS)
-AC_SUBST(LIBTBM_MSM_LIBS)
-
-bufmgr_dir=${libdir#*/}
-AC_SUBST(bufmgr_dir)
-
-# for libhal-backend-tbm-msm
LIBHAL_BACKEND_TBM_MSM_CFLAGS="$HAL_API_COMMON_CFLAGS $HAL_API_TBM_CFLAGS $LIBDRM_CFLAGS $GBM_CFLAGS $LIBUDEV_CFLAGS"
LIBHAL_BACKEND_TBM_MSM_LIBS="$HAL_API_COMMON_LIBS $HAL_API_TBM_LIBS $LIBDRM_LIBS $GBM_LIBS $LIBUDEV_LIBS"
+
AC_SUBST(LIBHAL_BACKEND_TBM_MSM_CFLAGS)
AC_SUBST(LIBHAL_BACKEND_TBM_MSM_LIBS)
@@ -77,26 +67,18 @@ if test "x${use_dlog}" = "xyes"; then
PKG_CHECK_MODULES(DLOG, dlog)
- LIBTBM_MSM_CFLAGS="$LIBTBM_MSM_CFLAGS $DLOG_CFLAGS "
- LIBTBM_MSM_LIBS="$LIBTBM_MSM_LIBS $DLOG_LIBS "
-
LIBHAL_BACKEND_TBM_MSM_CFLAGS="$LIBHAL_BACKEND_TBM_MSM_CFLAGS $DLOG_CFLAGS "
LIBHAL_BACKEND_TBM_MSM_LIBS="$LIBHAL_BACKEND_TBM_MSM_LIBS $DLOG_LIBS "
fi
AC_OUTPUT([
Makefile
- src/libtbm-msm/Makefile
- src/libhal-backend-tbm-msm/Makefile
src/Makefile])
echo ""
echo "CFLAGS : $CFLAGS"
echo "LDFLAGS : $LDFLAGS"
-echo "LIBTBM_MSM_CFLAGS : $LIBTBM_MSM_CFLAGS"
-echo "LIBTBM_MSM_LIBS : $LIBTBM_MSM_LIBS"
-echo "bufmgr_dir : $bufmgr_dir"
echo "LIBHAL_BACKEND_TBM_MSM_CFLAGS : $LIBHAL_BACKEND_TBM_MSM_CFLAGS"
echo "LIBHAL_BACKEND_TBM_MSM_LIBS : $LIBHAL_BACKEND_TBM_MSM_LIBS"
-echo "hal-libdir : $HAL_LIBDIR"
+echo "HAL_LIBDIR : $HAL_LIBDIR"
echo ""
diff --git a/packaging/libhal-backend-tbm-msm.manifest b/packaging/hal-backend-tbm-msm.manifest
index 75b0fa5..75b0fa5 100644
--- a/packaging/libhal-backend-tbm-msm.manifest
+++ b/packaging/hal-backend-tbm-msm.manifest
diff --git a/packaging/libtbm-msm.spec b/packaging/hal-backend-tbm-msm.spec
index 83cda8d..8ea64b6 100644
--- a/packaging/libtbm-msm.spec
+++ b/packaging/hal-backend-tbm-msm.spec
@@ -1,15 +1,13 @@
-Name: libtbm-msm
+Name: hal-backend-tbm-msm
Version: 1.0.2
Release: 1
License: MIT
-Summary: Tizen Buffer Manager - drm msm backend
+Summary: hal-backend-tbm module for msm
Group: System/Libraries
Source0: %{name}-%{version}.tar.gz
-Source1001: %{name}.manifest
-Source1002: libhal-backend-tbm-msm.manifest
+Source1001: %{name}.manifest
BuildRequires: pkgconfig(libdrm)
-BuildRequires: pkgconfig(libtbm)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(libudev)
BuildRequires: pkgconfig(gbm)
@@ -18,25 +16,15 @@ BuildRequires: pkgconfig(hal-api-tbm)
ExclusiveArch: %{arm} aarch64
%description
-descriptionion: Tizen Buffer manager backend module uses drm msm
-
-%package -n hal-backend-tbm-msm
-Summary: hal-backend-tbm module for msm
-Group: System/Libraries
-Requires: hal-api-tbm
-Requires: hal-api-common
-
-%description -n hal-backend-tbm-msm
-descriptionion: hal tbm backend module for msm
+description: hal tbm backend module for msm
%prep
%setup -q
cp %{SOURCE1001} .
-cp %{SOURCE1002} .
%build
-%reconfigure --prefix=%{_prefix} --libdir=%{_libdir}/bufmgr \
+%reconfigure --prefix=%{_prefix} --libdir=%{_libdir} \
--with-hal-libdir=%{_hal_libdir} \
--with-default-dlog=yes \
--disable-align-eight \
@@ -50,29 +38,15 @@ rm -rf %{buildroot}
%make_install
-
%post
-if [ -f %{_libdir}/bufmgr/libtbm_default.so ]; then
- rm -rf %{_libdir}/bufmgr/libtbm_default.so
-fi
-ln -s libtbm-msm.so %{_libdir}/bufmgr/libtbm_default.so
-
-%postun -p /sbin/ldconfig
-
-%post -n hal-backend-tbm-msm
if [ -f %{_hal_libdir}/libhal-backend-tbm.so ]; then
rm -rf %{_hal_libdir}/libhal-backend-tbm.so
fi
ln -s libhal-backend-tbm-msm.so %{_hal_libdir}/libhal-backend-tbm.so
-%postun -n hal-backend-tbm-msm -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
%files
%manifest %{name}.manifest
%license COPYING
-%{_libdir}/bufmgr/libtbm-*.so*
-
-%files -n hal-backend-tbm-msm
-%manifest libhal-backend-tbm-msm.manifest
-%license COPYING
%{_hal_libdir}/libhal-backend-*.so*
diff --git a/packaging/libtbm-msm.manifest b/packaging/libtbm-msm.manifest
deleted file mode 100644
index 97e8c31..0000000
--- a/packaging/libtbm-msm.manifest
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
- <request>
- <domain name="_"/>
- </request>
-</manifest>
diff --git a/src/Makefile.am b/src/Makefile.am
index d9eba17..1f24c2d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1 +1,12 @@
-SUBDIRS = libtbm-msm libhal-backend-tbm-msm
+AM_CFLAGS = \
+ @LIBHAL_BACKEND_TBM_MSM_CFLAGS@ \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src
+
+libhal_backend_tbm_msm_la_LTLIBRARIES = libhal-backend-tbm-msm.la
+libhal_backend_tbm_msm_ladir = @HAL_LIBDIR@
+libhal_backend_tbm_msm_la_LIBADD = @LIBHAL_BACKEND_TBM_MSM_LIBS@
+
+libhal_backend_tbm_msm_la_SOURCES = \
+ tbm_backend_log.c \
+ tbm_backend_msm.c
diff --git a/src/libhal-backend-tbm-msm/Makefile.am b/src/libhal-backend-tbm-msm/Makefile.am
deleted file mode 100644
index f79415e..0000000
--- a/src/libhal-backend-tbm-msm/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-AM_CFLAGS = \
- @LIBHAL_BACKEND_TBM_MSM_CFLAGS@ \
- -I$(top_srcdir) \
- -I$(top_srcdir)/src/libhal-backend-tbm-msm
-
-libhal_backend_tbm_msm_la_LTLIBRARIES = libhal-backend-tbm-msm.la
-libhal_backend_tbm_msm_ladir = @HAL_LIBDIR@
-libhal_backend_tbm_msm_la_LIBADD = @LIBHAL_BACKEND_TBM_MSM_LIBS@
-
-libhal_backend_tbm_msm_la_SOURCES = \
- tbm_backend_log.c \
- tbm_backend_msm.c
diff --git a/src/libtbm-msm/Makefile.am b/src/libtbm-msm/Makefile.am
deleted file mode 100644
index 8df2bbb..0000000
--- a/src/libtbm-msm/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-AM_CFLAGS = \
- @LIBTBM_MSM_CFLAGS@ \
- -I$(top_srcdir) \
- -I$(top_srcdir)/src \
- -I$(includedir)/drm
-
-libtbm_msm_la_LTLIBRARIES = libtbm-msm.la
-libtbm_msm_ladir = /${bufmgr_dir}
-libtbm_msm_la_LIBADD = @LIBTBM_MSM_LIBS@
-
-libtbm_msm_la_SOURCES = \
- tbm_bufmgr_msm.c
diff --git a/src/libtbm-msm/tbm_bufmgr_msm.c b/src/libtbm-msm/tbm_bufmgr_msm.c
deleted file mode 100644
index 15e3b5d..0000000
--- a/src/libtbm-msm/tbm_bufmgr_msm.c
+++ /dev/null
@@ -1,1514 +0,0 @@
-/**************************************************************************
-
-libtbm_msm
-
-Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>,
- Junkyeong Kim <jk0430.kim@samsung.com>,
- Changyeon Lee <cyeon.lee@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <libudev.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <xf86drm.h>
-#include <pthread.h>
-#include <tbm_backend.h>
-#include <tbm_drm_helper.h>
-#include <tbm_log.h>
-#include <gbm.h>
-
-#define TBM_COLOR_FORMAT_COUNT 4
-
-#define SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1))
-
-#define TBM_SURFACE_ALIGNMENT_PLANE (64)
-#define TBM_SURFACE_ALIGNMENT_PITCH_RGB (128)
-#define TBM_SURFACE_ALIGNMENT_PITCH_YUV (16)
-#define TBM_SURFACE_ALIGNMENT_PITCH_NV (512)
-
-typedef struct _tbm_bufmgr_msm *tbm_bufmgr_msm;
-typedef struct _tbm_bo_msm *tbm_bo_msm;
-
-/* tbm buffor object for msm */
-struct _tbm_bo_msm {
- int device_fd;
-
- struct gbm_bo *gbo;
-
- unsigned int handle; /* GEM Handle */
- unsigned int name; /* FLINK ID */
- int buf_fd; /* fd for dmabuf */
- void *pBase; /* virtual address */
-
- unsigned int size;
-
- unsigned int flags_msm;
- unsigned int flags_tbm;
-
- pthread_mutex_t mutex;
- int device;
- int opt;
-
- tbm_bufmgr_msm bufmgr_msm;
-};
-
-/* tbm bufmgr private for msm */
-struct _tbm_bufmgr_msm {
- int fd;
- struct gbm_device *gdevice;
-
- void *hash_bos;
-
- char *device_name;
- void *bind_display;
-
- tbm_backend_bufmgr_func *bufmgr_func;
- tbm_backend_bo_func *bo_func;
-
- tbm_bufmgr bufmgr;
-};
-
-char *STR_DEVICE[] = {
- "DEF",
- "CPU",
- "2D",
- "3D",
- "MM"
-};
-
-char *STR_OPT[] = {
- "NONE",
- "RD",
- "WR",
- "RDWR"
-};
-
-uint32_t tbm_msm_color_format_list[TBM_COLOR_FORMAT_COUNT] = {
- TBM_FORMAT_ARGB8888,
- TBM_FORMAT_XRGB8888,
- TBM_FORMAT_NV12,
- TBM_FORMAT_YUV420
- };
-
-static int
-_tbm_msm_open_drm()
-{
- struct udev *udev = NULL;
- struct udev_enumerate *e = NULL;
- struct udev_list_entry *entry = NULL;
- struct udev_device *device = NULL, *drm_device = NULL, *pci = NULL;
- const char *filepath, *id;
- struct stat s;
- int fd = -1;
- int ret;
-
- udev = udev_new();
- if (!udev) {
- TBM_ERR("udev_new() failed.\n");
- return -1;
- }
-
- e = udev_enumerate_new(udev);
- udev_enumerate_add_match_subsystem(e, "drm");
- udev_enumerate_add_match_sysname(e, "card[0-9]*");
- udev_enumerate_scan_devices(e);
-
- drm_device = NULL;
- udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
- filepath = udev_list_entry_get_name(entry);
- device = udev_device_new_from_syspath(udev, filepath);
- if (!device)
- continue;
-
- pci = udev_device_get_parent_with_subsystem_devtype(device, "pci", NULL);
- if (pci) {
- id = udev_device_get_sysattr_value(pci, "boot_vga");
- if (id && !strcmp(id, "1")) {
- if (drm_device)
- udev_device_unref(drm_device);
- drm_device = device;
- break;
- }
- }
-
- if (!drm_device)
- drm_device = device;
- else
- udev_device_unref(device);
- }
-
- udev_enumerate_unref(e);
-
- /* Get device file path. */
- filepath = udev_device_get_devnode(drm_device);
- if (!filepath) {
- TBM_ERR("udev_device_get_devnode() failed.\n");
- udev_device_unref(drm_device);
- udev_unref(udev);
- return -1;
- }
-
- /* Open DRM device file and check validity. */
- fd = open(filepath, O_RDWR | O_CLOEXEC);
- if (fd < 0) {
- TBM_ERR("open(%s, O_RDWR | O_CLOEXEC) failed.\n");
- udev_device_unref(drm_device);
- udev_unref(udev);
- return -1;
- }
-
- ret = fstat(fd, &s);
- if (ret) {
- TBM_ERR("fstat() failed %s.\n");
- close(fd);
- udev_device_unref(drm_device);
- udev_unref(udev);
- return -1;
- }
-
- udev_device_unref(drm_device);
- udev_unref(udev);
-
- return fd;
-}
-
-static unsigned int
-_get_msm_flag_from_tbm(unsigned int ftbm)
-{
- unsigned int flags = 0;
-
- flags |= GBM_BO_USE_RENDERING;
-
- if (ftbm & TBM_BO_SCANOUT)
- flags |= GBM_BO_USE_SCANOUT;
-
- return flags;
-}
-
-#if 0
-static unsigned int
-_get_tbm_flag_from_msm(unsigned int fmsm)
-{
- unsigned int flags = 0;
-
- if (fmsm & GBM_BO_USE_SCANOUT)
- flags |= TBM_BO_SCANOUT;
-
- return flags;
-}
-#endif
-
-static unsigned int
-_get_name(int fd, unsigned int handle)
-{
- struct drm_gem_flink arg = {0,};
-
- arg.handle = handle;
- if (drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &arg)) {
- TBM_ERR("fail to DRM_IOCTL_GEM_FLINK handle:%d", handle);
- return 0;
- }
-
- return (unsigned int)arg.name;
-}
-
-static tbm_bo_handle
-_msm_bo_handle(tbm_bo_msm bo_msm, int device)
-{
- tbm_bo_handle bo_handle;
-
- memset(&bo_handle, 0x0, sizeof(uint64_t));
-
- switch (device) {
- case TBM_DEVICE_DEFAULT:
- case TBM_DEVICE_2D:
- bo_handle.u32 = (uint32_t)bo_msm->handle;
- break;
- case TBM_DEVICE_CPU:
- if (!bo_msm->pBase) {
- void *map = NULL;
-
- map = mmap(0, bo_msm->size, PROT_READ | PROT_WRITE, MAP_SHARED, bo_msm->buf_fd, 0);
- if(map == MAP_FAILED) {
- TBM_ERR("Cannot usrptr fd=%d(%m)", bo_msm->buf_fd);
- return (tbm_bo_handle) NULL;
- }
-
- bo_msm->pBase = map;
- }
- bo_handle.ptr = (void *)bo_msm->pBase;
- break;
- case TBM_DEVICE_3D:
- bo_handle.u32 = (uint32_t)bo_msm->buf_fd;
- break;
- case TBM_DEVICE_MM:
- bo_handle.u32 = (uint32_t)bo_msm->buf_fd;
- break;
- default:
- TBM_ERR("Not supported device:%d", device);
- bo_handle.ptr = (void *) NULL;
- break;
- }
-
- return bo_handle;
-}
-
-static tbm_bufmgr_capability
-tbm_msm_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error)
-{
- tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE;
-
- capabilities = TBM_BUFMGR_CAPABILITY_SHARE_FD | TBM_BUFMGR_CAPABILITY_SHARE_KEY;
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return capabilities;
-}
-
-static tbm_error_e
-tbm_msm_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display)
-{
- tbm_bufmgr_msm bufmgr_msm = (tbm_bufmgr_msm)bufmgr_data;
- TBM_RETURN_VAL_IF_FAIL(bufmgr_msm != NULL, TBM_ERROR_INVALID_PARAMETER);
-
- if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_msm->fd,
- bufmgr_msm->device_name, 0)) {
- TBM_ERR("fail to tbm_drm_helper_wl_server_init");
- return TBM_ERROR_INVALID_OPERATION;
- }
-
- bufmgr_msm->bind_display = native_display;
-
- return TBM_ERROR_NONE;
-}
-
-static tbm_error_e
-tbm_msm_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data,
- uint32_t **formats, uint32_t *num)
-{
- tbm_bufmgr_msm bufmgr_msm = (tbm_bufmgr_msm)bufmgr_data;
- uint32_t *color_formats;
-
- TBM_RETURN_VAL_IF_FAIL(bufmgr_msm != NULL, TBM_ERROR_INVALID_PARAMETER);
-
- color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT);
- if (color_formats == NULL)
- return TBM_ERROR_OUT_OF_MEMORY;
-
- memcpy(color_formats, tbm_msm_color_format_list, sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT);
-
- *formats = color_formats;
- *num = TBM_COLOR_FORMAT_COUNT;
-
- TBM_DBG("supported format count = %d", *num);
-
- return TBM_ERROR_NONE;
-}
-
-static tbm_error_e
-tbm_msm_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data,
- tbm_format format, int plane_idx, int width,
- int height, uint32_t *size, uint32_t *offset,
- uint32_t *pitch, int *bo_idx)
-{
- tbm_bufmgr_msm bufmgr_msm = (tbm_bufmgr_msm)bufmgr_data;
- int bpp;
- int _offset = 0;
- int _pitch = 0;
- int _size = 0;
- int _bo_idx = 0;
- int _aligned_height = 0;
-
- TBM_RETURN_VAL_IF_FAIL(bufmgr_msm != NULL, TBM_ERROR_INVALID_PARAMETER);
-
- switch (format) {
- /* 16 bpp RGB */
- case TBM_FORMAT_XRGB4444:
- case TBM_FORMAT_XBGR4444:
- case TBM_FORMAT_RGBX4444:
- case TBM_FORMAT_BGRX4444:
- case TBM_FORMAT_ARGB4444:
- case TBM_FORMAT_ABGR4444:
- case TBM_FORMAT_RGBA4444:
- case TBM_FORMAT_BGRA4444:
- case TBM_FORMAT_XRGB1555:
- case TBM_FORMAT_XBGR1555:
- case TBM_FORMAT_RGBX5551:
- case TBM_FORMAT_BGRX5551:
- case TBM_FORMAT_ARGB1555:
- case TBM_FORMAT_ABGR1555:
- case TBM_FORMAT_RGBA5551:
- case TBM_FORMAT_BGRA5551:
- case TBM_FORMAT_RGB565:
- bpp = 16;
- _offset = 0;
- _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_RGB);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- break;
- /* 24 bpp RGB */
- case TBM_FORMAT_RGB888:
- case TBM_FORMAT_BGR888:
- bpp = 24;
- _offset = 0;
- _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_RGB);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- break;
- /* 32 bpp RGB */
- case TBM_FORMAT_XRGB8888:
- case TBM_FORMAT_XBGR8888:
- case TBM_FORMAT_RGBX8888:
- case TBM_FORMAT_BGRX8888:
- case TBM_FORMAT_ARGB8888:
- case TBM_FORMAT_ABGR8888:
- case TBM_FORMAT_RGBA8888:
- case TBM_FORMAT_BGRA8888:
- bpp = 32;
- _offset = 0;
- _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_RGB);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- break;
-
- /* packed YCbCr */
- case TBM_FORMAT_YUYV:
- case TBM_FORMAT_YVYU:
- case TBM_FORMAT_UYVY:
- case TBM_FORMAT_VYUY:
- case TBM_FORMAT_AYUV:
- bpp = 32;
- _offset = 0;
- _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- break;
-
- /*
- * 2 plane YCbCr
- * index 0 = Y plane, [7:0] Y
- * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
- * or
- * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
- */
- case TBM_FORMAT_NV12:
- case TBM_FORMAT_NV21:
- bpp = 12;
- //if (plane_idx == 0)
- {
- _offset = 0;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_NV);
- _aligned_height = SIZE_ALIGN(height, TBM_SURFACE_ALIGNMENT_PITCH_NV);
- _size = _pitch * _aligned_height;
- _bo_idx = 0;
- if (plane_idx == 0)
- break;
- }
- //else if (plane_idx == 1)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_NV);
- _aligned_height = SIZE_ALIGN(height / 2, TBM_SURFACE_ALIGNMENT_PITCH_NV / 2);
- _size = _pitch * _aligned_height;
- _bo_idx = 0;
- }
- break;
- case TBM_FORMAT_NV16:
- case TBM_FORMAT_NV61:
- bpp = 16;
- //if (plane_idx == 0)
- {
- _offset = 0;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 0)
- break;
- }
- //else if (plane_idx == 1)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- }
- break;
-
- /*
- * 3 plane YCbCr
- * index 0: Y plane, [7:0] Y
- * index 1: Cb plane, [7:0] Cb
- * index 2: Cr plane, [7:0] Cr
- * or
- * index 1: Cr plane, [7:0] Cr
- * index 2: Cb plane, [7:0] Cb
- */
- /*
- NATIVE_BUFFER_FORMAT_YV12
- NATIVE_BUFFER_FORMAT_I420
- */
- case TBM_FORMAT_YUV410:
- case TBM_FORMAT_YVU410:
- bpp = 9;
- break;
- case TBM_FORMAT_YUV411:
- case TBM_FORMAT_YVU411:
- case TBM_FORMAT_YUV420:
- case TBM_FORMAT_YVU420:
- bpp = 12;
- //if (plane_idx == 0)
- {
- _offset = 0;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 0)
- break;
- }
- //else if (plane_idx == 1)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 1)
- break;
- }
- //else if (plane_idx == 2)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- }
- break;
- case TBM_FORMAT_YUV422:
- case TBM_FORMAT_YVU422:
- bpp = 16;
- //if (plane_idx == 0)
- {
- _offset = 0;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 0)
- break;
- }
- //else if (plane_idx == 1)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 1)
- break;
- }
- //else if (plane_idx == 2)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- }
- break;
- case TBM_FORMAT_YUV444:
- case TBM_FORMAT_YVU444:
- bpp = 24;
- //if (plane_idx == 0)
- {
- _offset = 0;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 0)
- break;
- }
- //else if (plane_idx == 1)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 1)
- break;
- }
- //else if (plane_idx == 2)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- }
- break;
- default:
- bpp = 0;
- break;
- }
-
- *size = _size;
- *offset = _offset;
- *pitch = _pitch;
- *bo_idx = _bo_idx;
-
- return TBM_ERROR_NONE;
-}
-
-static tbm_backend_bo_data *
-tbm_msm_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size,
- tbm_bo_memory_type flags, tbm_error_e *error)
-{
- tbm_bufmgr_msm bufmgr_msm = (tbm_bufmgr_msm)bufmgr_data;
- tbm_bo_msm bo_msm;
- struct gbm_bo *gbo;
- unsigned int msm_flags;
- uint32_t width = 2048, height;
-
- if (bufmgr_msm == NULL) {
- TBM_ERR("bufmgr_data is null\n");
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- bo_msm = calloc(1, sizeof(struct _tbm_bo_msm));
- if (!bo_msm) {
- TBM_ERR("fail to allocate the bo_msm private\n");
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- bo_msm->bufmgr_msm = bufmgr_msm;
-
- msm_flags = _get_msm_flag_from_tbm(flags);
-
- height = ((uint32_t) size + (width * 4) - 1) / (width * 4);
-
- gbo = gbm_bo_create(bufmgr_msm->gdevice, width, height, GBM_FORMAT_ARGB8888, msm_flags);
- if (!gbo) {
- TBM_ERR("Cannot create gbm bo(size:%d mem_types:%d) (%m)", size, flags);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- bo_msm->gbo = gbo;
- bo_msm->device_fd = bufmgr_msm->fd;
- bo_msm->flags_tbm = flags;
- bo_msm->flags_msm = msm_flags;
-
- bo_msm->handle = gbm_bo_get_handle(gbo).u32;
- if (!bo_msm->handle) {
- TBM_ERR("Cannot get handle:(%m)");
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- bo_msm->name = _get_name(bo_msm->device_fd, bo_msm->handle);
- if (!bo_msm->name) {
- TBM_ERR("Cannot get name from handle:%d(%m)", bo_msm->handle);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- bo_msm->buf_fd = gbm_bo_get_fd(gbo);
- if (bo_msm->buf_fd < 0) {
- TBM_ERR("Cannot get fd bo_msm:%p", bo_msm);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- bo_msm->size = lseek(bo_msm->buf_fd, 0, SEEK_END);
- if (!bo_msm->size) {
- TBM_ERR("Cannot get size bo_msm:%p (%m)", bo_msm);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- if (drmHashInsert(bufmgr_msm->hash_bos, bo_msm->name, (void *)bo_msm) < 0) {
- TBM_ERR("Cannot insert bo_msm to Hash(%d)", bo_msm->name);
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- goto fail;
- }
-
- pthread_mutex_init(&bo_msm->mutex, NULL);
-
- TBM_DBG(" bo_msm:%p, handle:%d, flags:%d(%d), size:%d",
- bo_msm,
- bo_msm->handle,
- bo_msm->flags_tbm,
- bo_msm->size);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return (tbm_backend_bo_data *)bo_msm;
-
-fail:
- if (gbo) gbm_bo_destroy(gbo);
- if (bo_msm) free(bo_msm);
-
- return NULL;
-}
-
-static tbm_backend_bo_data *
-tbm_msm_bufmgr_alloc_bo_with_format(tbm_backend_bufmgr_data *bufmgr_data,
- int format, int bo_idx, int width,
- int height, tbm_bo_memory_type mem_types,
- tbm_error_e *error)
-{
- tbm_bufmgr_msm bufmgr_msm = (tbm_bufmgr_msm)bufmgr_data;
- tbm_bo_msm bo_msm;
- struct gbm_bo *gbo;
- unsigned int msm_flags;
-
- if (bufmgr_msm == NULL) {
- TBM_ERR("bufmgr_data is null\n");
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- bo_msm = calloc(1, sizeof(struct _tbm_bo_msm));
- if (!bo_msm) {
- TBM_ERR("fail to allocate the bo_msm private\n");
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- bo_msm->bufmgr_msm = bufmgr_msm;
-
- msm_flags = _get_msm_flag_from_tbm(mem_types);
-
- gbo = gbm_bo_create(bufmgr_msm->gdevice, width, height, format, msm_flags);
- if (!gbo) {
- TBM_ERR("Cannot create gbm bo(format:%d bo_idx:%d width:%d height:%d mem_types:%d) (%m)",
- format, bo_idx, width, height, mem_types);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- bo_msm->gbo = gbo;
- bo_msm->device_fd = bufmgr_msm->fd;
- bo_msm->flags_tbm = mem_types;
- bo_msm->flags_msm = msm_flags;
-
- bo_msm->handle = gbm_bo_get_handle(gbo).u32;
- if (!bo_msm->handle) {
- TBM_ERR("Cannot get handle:(%m)");
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- bo_msm->name = _get_name(bo_msm->device_fd, bo_msm->handle);
- if (!bo_msm->name) {
- TBM_ERR("Cannot get name from handle:%d(%m)", bo_msm->handle);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- bo_msm->buf_fd = gbm_bo_get_fd(gbo);
- if (bo_msm->buf_fd < 0) {
- TBM_ERR("Cannot get fd bo_msm:%p", bo_msm);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- bo_msm->size = lseek(bo_msm->buf_fd, 0, SEEK_END);
- if (!bo_msm->size) {
- TBM_ERR("Cannot get size bo_msm:%p (%m)", bo_msm);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- if (drmHashInsert(bufmgr_msm->hash_bos, bo_msm->name, (void *)bo_msm) < 0) {
- TBM_ERR("Cannot insert bo_msm to Hash(%d)", bo_msm->name);
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- goto fail;
- }
-
- pthread_mutex_init(&bo_msm->mutex, NULL);
-
- TBM_DBG(" bo_msm:%p, handle:%d, flags:%d(%d), size:%d",
- bo_msm,
- bo_msm->handle,
- bo_msm->flags_tbm,
- bo_msm->size);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return (tbm_backend_bo_data *)bo_msm;
-
-fail:
- if (gbo) gbm_bo_destroy(gbo);
- if (bo_msm) free(bo_msm);
-
- return NULL;
-}
-
-static tbm_backend_bo_data *
-tbm_msm_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error)
-{
- tbm_bufmgr_msm bufmgr_msm = (tbm_bufmgr_msm)bufmgr_data;
- tbm_bo_msm bo_msm = NULL;
- struct gbm_bo *gbo = NULL;
- struct gbm_import_fd_data fd_data;
- union gbm_bo_handle handle;
- unsigned int name;
- struct drm_prime_handle prime_arg = {0, };
- int ret;
-
- if (bufmgr_msm == NULL) {
- TBM_ERR("bufmgr_data is null\n");
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- prime_arg.fd = key;
- prime_arg.flags = 0;
- if (drmIoctl(bufmgr_msm->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &prime_arg)) {
- TBM_ERR("Cannot get gem handle from fd:%d (%m)", prime_arg.fd);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- name = _get_name(bufmgr_msm->fd, prime_arg.handle);
- if (!name) {
- TBM_ERR("Cannot get name from handle:%d, fd:%d (%m)", prime_arg.handle, key);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- ret = drmHashLookup(bufmgr_msm->hash_bos, name, (void **)&bo_msm);
- if (ret == 0) {
- if (prime_arg.handle == bo_msm->handle) {
- if (error)
- *error = TBM_ERROR_NONE;
- return bo_msm;
- }
- }
-
- /* we don't know format in backend */
- fd_data.format = GBM_FORMAT_ABGR8888;
- fd_data.fd = dup(key);
-
- gbo = gbm_bo_import(bufmgr_msm->gdevice, GBM_BO_IMPORT_FD, &fd_data, GBM_BO_USE_RENDERING);
- if (!gbo) {
- TBM_ERR("Cannot import gbm bo(fd:%d) (%m)", key);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- handle = gbm_bo_get_handle(gbo);
- if (!handle.ptr) {
- TBM_ERR("Cannot get handle gbm bo(fd:%d) (%m)", key);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- bo_msm = calloc(1, sizeof(struct _tbm_bo_msm));
- if (!bo_msm) {
- TBM_ERR("bo_msm:%p fail to allocate the bo_msm", bo_msm);
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- bo_msm->bufmgr_msm = bufmgr_msm;
- bo_msm->gbo = gbo;
- bo_msm->device_fd = bufmgr_msm->fd;
-
- bo_msm->handle = gbm_bo_get_handle(gbo).u32;
- if (!bo_msm->handle) {
- TBM_ERR("Cannot get handle (%m)");
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- bo_msm->name = _get_name(bo_msm->device_fd, bo_msm->handle);
- if (!bo_msm->name) {
- TBM_ERR("Cannot get name from handle:%d (%m)", bo_msm->handle);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- bo_msm->buf_fd = gbm_bo_get_fd(gbo);
- if (bo_msm->buf_fd < 0) {
- TBM_ERR("Cannot get fd bo_msm:%p (%m)", bo_msm);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- bo_msm->size = lseek(bo_msm->buf_fd, 0, SEEK_END);
- if (!bo_msm->size) {
- TBM_ERR("Cannot get size bo_msm:%p (%m)", bo_msm);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail;
- }
-
- if (drmHashInsert(bufmgr_msm->hash_bos, bo_msm->name, (void *)bo_msm) < 0) {
- TBM_ERR("Cannot insert bo_msm to Hash(%d)", bo_msm->name);
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- goto fail;
- }
-
- pthread_mutex_init(&bo_msm->mutex, NULL);
-
- TBM_DBG(" bo_msm:%p, handle:%d(%d), fd:%d, key_fd:%d, flags:%d, size:%d",
- bo_msm,
- bo_msm->handle,
- bo_msm->buf_fd,
- key,
- bo_msm->flags_tbm,
- bo_msm->size);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return (tbm_backend_bo_data *)bo_msm;
-
-fail:
- if (fd_data.fd >= 0)
- close(fd_data.fd);
- if (gbo) gbm_bo_destroy(gbo);
- if (bo_msm) free(bo_msm);
-
- return NULL;
-}
-
-static tbm_backend_bo_data *
-tbm_msm_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error)
-{
- tbm_bufmgr_msm bufmgr_msm = (tbm_bufmgr_msm)bufmgr_data;
- tbm_bo_msm bo_msm = NULL;
- struct drm_gem_open open_arg = {0, };
- struct drm_gem_close close_arg = {0, };
- struct drm_prime_handle prime_arg = {0, };
- int ret;
-
- if (bufmgr_msm == NULL) {
- TBM_ERR("bufmgr_data is null\n");
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- ret = drmHashLookup(bufmgr_msm->hash_bos, key, (void **)&bo_msm);
- if (ret == 0) {
- if (error)
- *error = TBM_ERROR_NONE;
- return (tbm_backend_bo_data *)bo_msm;
- }
-
- open_arg.name = key;
- if (drmIoctl(bufmgr_msm->fd, DRM_IOCTL_GEM_OPEN, &open_arg)) {
- TBM_ERR("Cannot open gem name:%d (%m)", key);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- prime_arg.handle = open_arg.handle;
- if (drmIoctl(bufmgr_msm->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &prime_arg)) {
- TBM_ERR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD handle:%d (%m)", prime_arg.handle);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
-
- goto fail;
- }
-
- close_arg.handle = open_arg.handle;
- if (drmIoctl(bufmgr_msm->fd, DRM_IOCTL_GEM_CLOSE, &close_arg))
- TBM_ERR("Cannot close gem_handle:%d (%m)", close_arg.handle);
-
- open_arg.handle = 0;
-
- bo_msm = tbm_msm_bufmgr_import_fd(bufmgr_data, prime_arg.fd, error);
- if (!bo_msm) {
- TBM_ERR("fail to import fd:%d", prime_arg.fd);
-
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
-
- goto fail;
- }
-
- close(prime_arg.fd);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- TBM_DBG(" bo_msm:%p, handle:%d(%d), fd:%d, key_fd:%d, flags:%d, size:%d",
- bo_msm,
- bo_msm->handle,
- bo_msm->buf_fd,
- key,
- bo_msm->flags_tbm,
- bo_msm->size);
-
- return (tbm_backend_bo_data *)bo_msm;
-
-fail:
- if (open_arg.handle) {
- close_arg.handle = open_arg.handle;
- drmIoctl(bufmgr_msm->fd, DRM_IOCTL_GEM_CLOSE, &close_arg);
- }
- if (prime_arg.fd >= 0) close(prime_arg.fd);
-
- return NULL;
-}
-
-static void
-tbm_msm_bo_free(tbm_backend_bo_data *bo_data)
-{
- tbm_bo_msm bo_msm = (tbm_bo_msm)bo_data;
- tbm_bufmgr_msm bufmgr_msm;
- tbm_bo_msm temp;
- int ret;
-
- if (!bo_data)
- return;
-
- bufmgr_msm = bo_msm->bufmgr_msm;
- if (!bufmgr_msm)
- return;
-
- TBM_DBG(" bo_msm:%p, handle:%d(%d), fd:%d, size:%d",
- bo_msm,
- bo_msm->handle,
- bo_msm->buf_fd,
- bo_msm->size);
-
- if (bo_msm->pBase) {
- if (munmap(bo_msm->pBase, bo_msm->size) == -1)
- TBM_ERR("bo_msm:%p fail to munmap(%m)");
- }
-
- ret = drmHashLookup(bufmgr_msm->hash_bos, bo_msm->name, (void **)&temp);
- if (ret == 0)
- drmHashDelete(bufmgr_msm->hash_bos, bo_msm->name);
- else
- TBM_ERR("Cannot find bo_msm to Hash(%d), ret:%d", bo_msm->name, ret);
-
- if (temp != bo_msm)
- TBM_ERR("hash_bos probably has several BOs with same name!!!\n");
-
- gbm_bo_destroy(bo_msm->gbo);
-
- free(bo_msm);
-}
-
-static int
-tbm_msm_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error)
-{
- tbm_bo_msm bo_msm = (tbm_bo_msm)bo_data;
-
- if (!bo_msm) {
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return 0;
- }
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return bo_msm->size;
-}
-
-static tbm_bo_memory_type
-tbm_msm_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error)
-{
- tbm_bo_msm bo_msm = (tbm_bo_msm)bo_data;
-
- if (!bo_msm) {
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return TBM_BO_DEFAULT;
- }
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return bo_msm->flags_tbm;
-}
-
-static tbm_bo_handle
-tbm_msm_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error)
-{
- tbm_bo_msm bo_msm = (tbm_bo_msm)bo_data;
- tbm_bo_handle bo_handle;
-
- if (!bo_msm) {
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return (tbm_bo_handle) NULL;
- }
-
- if (!bo_msm->handle) {
- TBM_ERR("Cannot map handle:%d", bo_msm->handle);
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return (tbm_bo_handle) NULL;
- }
-
- /*Get mapped bo_handle*/
- bo_handle = _msm_bo_handle(bo_msm, device);
- if (bo_handle.ptr == NULL) {
- TBM_ERR("Cannot get handle: handle:%d, device:%d\n",
- bo_msm->handle, device);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return (tbm_bo_handle) NULL;
- }
-
- TBM_DBG("bo_msm:%p, handle:%d(%d), fd:%d, flags:%d, size:%d, %s",
- bo_msm,
- bo_msm->handle,
- bo_msm->buf_fd,
- bo_msm->flags_tbm,
- bo_msm->size,
- STR_DEVICE[device]);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return bo_handle;
-}
-
-static tbm_bo_handle
-tbm_msm_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device,
- tbm_bo_access_option opt, tbm_error_e *error)
-{
- tbm_bo_msm bo_msm = (tbm_bo_msm)bo_data;
- tbm_bo_handle bo_handle;
- tbm_bufmgr_msm bufmgr_msm;
-
- if (!bo_msm) {
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return (tbm_bo_handle) NULL;
- }
-
- bufmgr_msm = bo_msm->bufmgr_msm;
- if (!bufmgr_msm) {
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return (tbm_bo_handle) NULL;
- }
-
- if (!bo_msm->handle) {
- TBM_ERR("Cannot map handle:%d", bo_msm->handle);
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return (tbm_bo_handle) NULL;
- }
-
- /*Get mapped bo_handle*/
- bo_handle = _msm_bo_handle(bo_msm, device);
- if (bo_handle.ptr == NULL) {
- TBM_ERR("Cannot get handle: handle:%d, device:%d, opt:%d",
- bo_msm->handle, device, opt);
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return (tbm_bo_handle) NULL;
- }
-
- TBM_DBG(" bo_msm:%p, handle:%d(%d), fd:%d, %s, %s",
- bo_msm,
- bo_msm->handle,
- bo_msm->buf_fd,
- STR_DEVICE[device],
- STR_OPT[opt]);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return bo_handle;
-}
-
-static tbm_error_e
-tbm_msm_bo_unmap(tbm_backend_bo_data *bo_data)
-{
- tbm_bo_msm bo_msm = (tbm_bo_msm)bo_data;
- tbm_bufmgr_msm bufmgr_msm;
-
- if (!bo_msm)
- return TBM_ERROR_INVALID_PARAMETER;
-
- bufmgr_msm = bo_msm->bufmgr_msm;
- if (!bufmgr_msm)
- return TBM_ERROR_INVALID_PARAMETER;
-
- if (!bo_msm->handle)
- return TBM_ERROR_INVALID_PARAMETER;
-
- TBM_DBG(" bo_msm:%p, handle:%d(%d), fd:%d",
- bo_msm,
- bo_msm->handle,
- bo_msm->buf_fd);
-
- return TBM_ERROR_NONE;
-}
-
-tbm_fd
-tbm_msm_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error)
-{
- tbm_bo_msm bo_msm = (tbm_bo_msm)bo_data;
- int fd = -1;
-
- if (!bo_msm) {
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return -1;
- }
-
- fd = gbm_bo_get_fd(bo_msm->gbo);
- if (fd < 0) {
- TBM_ERR("bo_msm:%p Cannot handle=%d",
- bo_msm, bo_msm->handle);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return (tbm_fd)-1;
- }
-
- TBM_DBG(" bo_msm:%p, handle:%d(%d), fd:%d, key_fd:%d, flags:%d, size:%d",
- bo_msm,
- bo_msm->handle,
- bo_msm->buf_fd,
- fd,
- bo_msm->flags_tbm,
- bo_msm->size);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return (tbm_fd)dup(fd);
-}
-
-tbm_key
-tbm_msm_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error)
-{
- tbm_bo_msm bo_msm = (tbm_bo_msm)bo_data;
-
- if (!bo_msm) {
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return 0;
- }
-
- if (!bo_msm->name) {
- bo_msm->name = _get_name(bo_msm->device_fd, bo_msm->handle);
- if (!bo_msm->name) {
- TBM_ERR("error Cannot get name");
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return 0;
- }
- }
-
- TBM_DBG(" bo_msm:%p, handle:%d(%d), fd:%d, flags:%d, size:%d\n",
- bo_msm,
- bo_msm->handle, bo_msm->name,
- bo_msm->buf_fd,
- bo_msm->flags_tbm,
- bo_msm->size);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return (tbm_key)bo_msm->name;
-}
-
-static void
-tbm_msm_deinit(tbm_backend_bufmgr_data *bufmgr_data)
-{
- tbm_bufmgr_msm bufmgr_msm = (tbm_bufmgr_msm)bufmgr_data;
- tbm_bufmgr bufmgr;
- tbm_error_e error;
- void *value;
- unsigned long key;
-
- TBM_RETURN_IF_FAIL(bufmgr_msm != NULL);
-
- bufmgr = bufmgr_msm->bufmgr;
-
- tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_msm->bufmgr_func);
- tbm_backend_bufmgr_free_bo_func(bufmgr, bufmgr_msm->bo_func);
-
- if (bufmgr_msm->hash_bos) {
- while (drmHashFirst(bufmgr_msm->hash_bos, &key, &value) > 0) {
- free(value);
- drmHashDelete(bufmgr_msm->hash_bos, key);
- }
-
- drmHashDestroy(bufmgr_msm->hash_bos);
- bufmgr_msm->hash_bos = NULL;
- }
-
- if (bufmgr_msm->bind_display)
- tbm_drm_helper_wl_auth_server_deinit();
-
- if (bufmgr_msm->device_name)
- free(bufmgr_msm->device_name);
-
- if (tbm_backend_bufmgr_query_display_server(bufmgr, &error))
- tbm_drm_helper_unset_tbm_master_fd();
- else
- tbm_drm_helper_unset_fd();
-
- if (bufmgr_msm->gdevice)
- gbm_device_destroy(bufmgr_msm->gdevice);
-
- close(bufmgr_msm->fd);
-
- free(bufmgr_msm);
-}
-
-static tbm_backend_bufmgr_data *
-tbm_msm_init(tbm_bufmgr bufmgr, tbm_error_e *error)
-{
- tbm_bufmgr_msm bufmgr_msm = NULL;
- tbm_backend_bufmgr_func *bufmgr_func = NULL;
- tbm_backend_bo_func *bo_func = NULL;
- int set_master = 0;
- tbm_error_e err;
-
- if (!bufmgr) {
- TBM_ERR("bufmgr is null.");
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- bufmgr_msm = calloc(1, sizeof(struct _tbm_bufmgr_msm));
- if (!bufmgr_msm) {
- TBM_ERR("fail to alloc bufmgr_msm!");
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- bufmgr_msm->hash_bos = drmHashCreate();
- if (!bufmgr_msm->hash_bos) {
- TBM_ERR("fail to create hash bos");
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- goto fail_hash_bos;
- }
-
- /* check the master_fd which already had opened */
- bufmgr_msm->fd = tbm_drm_helper_get_master_fd();
- if (bufmgr_msm->fd < 0) {
- bufmgr_msm->fd = _tbm_msm_open_drm();
- if (bufmgr_msm->fd < 0) {
- TBM_ERR("fail to open drm!\n");
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail_open_drm;
- }
-
- if (drmIsMaster(bufmgr_msm->fd)) {
- tbm_drm_helper_set_tbm_master_fd(bufmgr_msm->fd);
- set_master = 1;
-
- bufmgr_msm->device_name = drmGetDeviceNameFromFd(bufmgr_msm->fd);
- if (!bufmgr_msm->device_name) {
- TBM_ERR("fail to get device name!");
- tbm_drm_helper_unset_tbm_master_fd();
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail_get_device_name;
- }
- TBM_ERR("This is Master FD(%d) from open_drm.", bufmgr_msm->fd);
- } else {
- /* close the fd and get the authenticated fd from the master fd */
- close(bufmgr_msm->fd);
- bufmgr_msm->fd = -1;
-
- /* get the authenticated drm fd from the master fd */
- if (!tbm_drm_helper_get_auth_info(&(bufmgr_msm->fd), &(bufmgr_msm->device_name), NULL)) {
- TBM_ERR("fail to get auth drm info!");
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail_get_auth_info;
- }
- TBM_ERR("This is Authenticated FD(%d)", bufmgr_msm->fd);
- }
- } else {
- bufmgr_msm->device_name = drmGetDeviceNameFromFd(bufmgr_msm->fd);
- if (!bufmgr_msm->device_name) {
- TBM_ERR("fail to get device name!");
- tbm_drm_helper_unset_tbm_master_fd();
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail_get_device_name;
- }
- TBM_ERR("This is Master FD from tbm_drm_helper_get_master_fd(%d)", bufmgr_msm->fd);
- }
- tbm_drm_helper_set_fd(bufmgr_msm->fd);
-
- bufmgr_msm->gdevice = gbm_create_device(bufmgr_msm->fd);
- if (!bufmgr_msm->gdevice) {
- TBM_ERR("fail to create gbm_device:%m");
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail_create_gbm_device;
- }
-
- /* alloc and register bufmgr_funcs */
- bufmgr_func = tbm_backend_bufmgr_alloc_bufmgr_func(bufmgr, &err);
- if (!bufmgr_func) {
- TBM_ERR("fail to alloc bufmgr_func! err(%d)", err);
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- goto fail_alloc_bufmgr_func;
- }
-
- bufmgr_func->bufmgr_get_capabilities = tbm_msm_bufmgr_get_capabilities;
- bufmgr_func->bufmgr_bind_native_display = tbm_msm_bufmgr_bind_native_display;
- bufmgr_func->bufmgr_get_supported_formats = tbm_msm_bufmgr_get_supported_formats;
- bufmgr_func->bufmgr_get_plane_data = tbm_msm_bufmgr_get_plane_data;
- bufmgr_func->bufmgr_alloc_bo = tbm_msm_bufmgr_alloc_bo;
- bufmgr_func->bufmgr_alloc_bo_with_format = tbm_msm_bufmgr_alloc_bo_with_format;
- bufmgr_func->bufmgr_import_fd = tbm_msm_bufmgr_import_fd;
- bufmgr_func->bufmgr_import_key = tbm_msm_bufmgr_import_key;
-
- err = tbm_backend_bufmgr_register_bufmgr_func(bufmgr, bufmgr_func);
- if (err != TBM_ERROR_NONE) {
- TBM_ERR("fail to register bufmgr_func! err(%d)\n", err);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail_register_bufmgr_func;
- }
- bufmgr_msm->bufmgr_func = bufmgr_func;
-
- /* alloc and register bo_funcs */
- bo_func = tbm_backend_bufmgr_alloc_bo_func(bufmgr, &err);
- if (!bo_func) {
- TBM_ERR("fail to alloc bo_func! err(%d)", err);
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- goto fail_alloc_bo_func;
- }
-
- bo_func->bo_free = tbm_msm_bo_free;
- bo_func->bo_get_size = tbm_msm_bo_get_size;
- bo_func->bo_get_memory_types = tbm_msm_bo_get_memory_type;
- bo_func->bo_get_handle = tbm_msm_bo_get_handle;
- bo_func->bo_map = tbm_msm_bo_map;
- bo_func->bo_unmap = tbm_msm_bo_unmap;
- bo_func->bo_export_fd = tbm_msm_bo_export_fd;
- bo_func->bo_export_key = tbm_msm_bo_export_key;
-
- err = tbm_backend_bufmgr_register_bo_func(bufmgr, bo_func);
- if (err != TBM_ERROR_NONE) {
- TBM_ERR("fail to register bo_func! err(%d)", err);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- goto fail_register_bo_func;
- }
- bufmgr_msm->bo_func = bo_func;
-
- TBM_DBG("fd:%d", bufmgr_msm->fd);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- bufmgr_msm->bufmgr = bufmgr;
-
- return (tbm_backend_bufmgr_data *)bufmgr_msm;
-
-fail_register_bo_func:
- tbm_backend_bufmgr_free_bo_func(bufmgr, bo_func);
-fail_alloc_bo_func:
-fail_register_bufmgr_func:
- tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_func);
-fail_alloc_bufmgr_func:
- if (bufmgr_msm->gdevice)
- gbm_device_destroy(bufmgr_msm->gdevice);
-fail_create_gbm_device:
- if (bufmgr_msm->device_name)
- free(bufmgr_msm->device_name);
-fail_get_device_name:
- if (set_master)
- tbm_drm_helper_unset_tbm_master_fd();
- tbm_drm_helper_unset_fd();
- if (bufmgr_msm->fd >= 0)
- close(bufmgr_msm->fd);
-fail_get_auth_info:
-fail_open_drm:
- if (bufmgr_msm->hash_bos)
- drmHashDestroy(bufmgr_msm->hash_bos);
-fail_hash_bos:
- free(bufmgr_msm);
- return NULL;
-}
-
-tbm_backend_module tbm_backend_module_data = {
- "msm",
- "Samsung",
- TBM_BACKEND_ABI_VERSION_3_0,
- tbm_msm_init,
- tbm_msm_deinit
-};
diff --git a/src/libhal-backend-tbm-msm/tbm_backend_log.c b/src/tbm_backend_log.c
index 51d447a..51d447a 100644
--- a/src/libhal-backend-tbm-msm/tbm_backend_log.c
+++ b/src/tbm_backend_log.c
diff --git a/src/libhal-backend-tbm-msm/tbm_backend_log.h b/src/tbm_backend_log.h
index 50903ae..50903ae 100644
--- a/src/libhal-backend-tbm-msm/tbm_backend_log.h
+++ b/src/tbm_backend_log.h
diff --git a/src/libhal-backend-tbm-msm/tbm_backend_msm.c b/src/tbm_backend_msm.c
index f23cdb3..f23cdb3 100644
--- a/src/libhal-backend-tbm-msm/tbm_backend_msm.c
+++ b/src/tbm_backend_msm.c