aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSathishkumar2013-07-30 00:50:14 -0500
committerSaurabh Bipin Chandra2013-08-27 16:12:42 -0500
commitf71e00630af23f1dd7d2a0df87d9b5b524c823a8 (patch)
tree956d57896e212423862da2031aabaa50ba2d7f01
parent17668bcb5a1f7f9db2ba225b1825bc55365c3e66 (diff)
downloadrepo-libdce-f71e00630af23f1dd7d2a0df87d9b5b524c823a8.tar.gz
repo-libdce-f71e00630af23f1dd7d2a0df87d9b5b524c823a8.tar.xz
repo-libdce-f71e00630af23f1dd7d2a0df87d9b5b524c823a8.zip
[GLP] Libdce linux implementation
make install & libdce.c issue fix 1. make install has been fixed. libdce.h will be installed in /usr/include, libdce.so files in /usr/lib and libdce.pc in /usr/lib/pkgconfig on using --prefix=/usr. By default the prefix is /usr/local. 2. init and deinit calls are removed from libdce.h 3. dce_set_fd and dce_get_fd calls are implemented in libdce.c 4. configure.ac checks for libmmrpc and makefile.am modified to link with libmmrpc. configure.ac and makefile.am modified 1. Codec_engine,xdctolls,framework_components,ipc,xdctools and xdaias paths needs to be exported. Configure.ac checks for the exported paths. 2. Makefile.am is modified to have the exported paths in the include directories list for the compiler. Modifications done after review 1. Comments added in memplugin_linux.c. White spaces removed manually and cleaned up libdce.c, memplugin.h. dce_priv.h is modified to have File and line number in the logs. linux/dce.h file is removed. Libdce modifications for linux Linux Specific libdce functionality added. 1. memplugin calls specific to linux are added in memplugin_linux.c 2. Error and debug logs implementation for linux in dce_priv.h 3. xll and wayland specific files are moved to linux folder Change-Id: Ib41e6a52d902376cdabbb939dee7585944720d92 Signed-off-by: Saurabh Bipin Chandra <a0131926@ti.com> Signed-off-by: Sathishkumar <x0203598@ti.com>
-rw-r--r--Makefile.am34
-rwxr-xr-xautogen.sh31
-rw-r--r--configure.ac148
-rw-r--r--dce_priv.h12
-rw-r--r--libdce.c90
-rw-r--r--libdce.h7
-rw-r--r--libdce.pc.in11
-rw-r--r--linux/libdce-x11.c131
-rw-r--r--linux/wayland-drm-client-protocol.h209
-rw-r--r--linux/wayland-drm-protocol.c71
-rw-r--r--memplugin.h17
-rw-r--r--memplugin_linux.c87
12 files changed, 820 insertions, 28 deletions
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..93d14d4
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,34 @@
1## Process this file with automake to produce Makefile.in
2
3
4lib_LTLIBRARIES = libdce.la
5
6
7CE_CFLAGS = \
8 -I$(CODEC_ENGINE)/ \
9 -I$(FRAMEWORK_COMPONENTS) \
10 -I$(IVAHD_CODECS) \
11 -I$(XDAIAS) \
12 -I$(XDCTOOLS)/ \
13 -I$(IPC)/packages/ti/ipc/mm \
14 -DBUILDOS_LINUX=1 \
15 -Wno-pointer-to-int-cast
16
17
18libdce_la_SOURCES = libdce.c memplugin_linux.c
19libdce_la_CFLAGS = $(WARN_CFLAGS) $(CE_CFLAGS) $(DRM_CFLAGS) $(X11_CFLAGS) $(WAYLAND_CFLAGS)
20libdce_la_LDFLAGS = -no-undefined -version-info 1:0:0
21libdce_la_LIBADD = $(DRM_LIBS) $(X11_LIBS) $(WAYLAND_LIBS) $(MMRPC_LIBS)
22
23if ENABLE_X11
24libdce_la_SOURCES += linux/libdce-x11.c
25endif
26if ENABLE_WAYLAND
27libdce_la_SOURCES += linux/libdce-wayland.c linux/wayland-drm-protocol.c
28endif
29
30libdce_la_includedir = $(includedir)
31libdce_la_include_HEADERS = libdce.h
32
33pkgconfig_DATA = libdce.pc
34pkgconfigdir = $(libdir)/pkgconfig
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..0cf21bc
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,31 @@
1#! /bin/sh
2
3cd `dirname $0`
4
5# on some platforms, you have "g" versions of some of these tools instead,
6# ie glibtoolize instead of libtoolize..
7find_tool() {
8 which $1 2> /dev/null || which g$1 2> /dev/null
9}
10
11aclocal=`find_tool aclocal`
12libtoolize=`find_tool libtoolize`
13automake=`find_tool automake`
14autoconf=`find_tool autoconf`
15
16mkdir -p config && $aclocal && $libtoolize --copy --force && $automake --copy --add-missing --foreign && $autoconf
17
18test -n "$NOCONFIGURE" && {
19 echo "skipping configure stage as requested."
20 echo "autogen.sh done."
21 exit 0
22}
23
24CONFIGURE_DEF_OPT="--enable-maintainer-mode"
25echo ./configure $CONFIGURE_DEF_OPT $*
26./configure $CONFIGURE_DEF_OPT $* || {
27 echo " configure failed"
28 exit 1
29}
30
31echo "Now type 'make' to compile"
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..72430cb
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,148 @@
1AC_PREREQ(2.52)
2
3dnl initialize autoconf
4AC_INIT([libdce], [1.0.0], [http://www.ti.com])
5
6dnl define PACKAGE_VERSION_* variables
7dnl AS_VERSION
8
9dnl can autoconf find the source ?
10AC_CONFIG_SRCDIR([libdce.c])
11
12dnl set the autotools aux directory
13AC_CONFIG_AUX_DIR([config])
14
15dnl AM_MAINTAINER_MODE only provides the option to configure to enable it
16AM_MAINTAINER_MODE
17
18dnl sets host_*, target_ variables
19AC_CANONICAL_SYSTEM
20
21dnl initialize automake
22AM_INIT_AUTOMAKE([foreign])
23
24dnl use pretty build output with automake >= 1.11
25m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])],
26 [AM_DEFAULT_VERBOSITY=1
27 AC_SUBST(AM_DEFAULT_VERBOSITY)])
28
29dnl find a compiler
30AC_PROG_CC
31AM_PROG_AS
32AM_PROG_LIBTOOL
33
34dnl *** autotools stuff ***
35dnl allow for different autotools
36dnl AS_AUTOTOOLS_ALTERNATE
37
38dnl *** checks for platform ***
39AC_DEFINE_UNQUOTED(CPU_`echo $target_cpu | tr a-z- A-Z_`,[1])
40AC_DEFINE_UNQUOTED(OS_` echo $target_os | tr a-z- A-Z_`,[1])
41
42dnl *** checks for programs ***
43AC_PROG_INSTALL
44
45dnl Check for pkgconfig first
46AC_CHECK_PROG([HAVE_PKGCONFIG], [pkg-config], [yes], [no])
47
48dnl *** checks for libraries ***
49dnl Check for libdrm
50PKG_CHECK_MODULES(DRM, libdrm libdrm_omap)
51
52dnl *** checks for libraries ***
53dnl Check for libmmrpc
54PKG_CHECK_MODULES(MMRPC, libmmrpc)
55
56dnl Check for X11/libdri2
57PKG_CHECK_MODULES(X11, x11 dri2, [HAVE_X11=yes], [HAVE_X11=no])
58if test "x$HAVE_X11" = "xyes"; then
59 AC_DEFINE(HAVE_X11, 1, [Have X11 support])
60else
61 AC_MSG_WARN([Building without X11 support])
62fi
63AM_CONDITIONAL(ENABLE_X11, [test "x$HAVE_X11" = xyes])
64
65dnl Check for wayland
66PKG_CHECK_MODULES(WAYLAND, wayland-client >= 0.95.0, [HAVE_WAYLAND=yes], [HAVE_WAYLAND=no])
67if test "x$HAVE_WAYLAND" = "xyes"; then
68 AC_DEFINE(HAVE_WAYLAND, 1, [Have Wayland support])
69else
70 AC_MSG_WARN([Building without Wayland support])
71fi
72AM_CONDITIONAL(ENABLE_WAYLAND, [test "x$HAVE_WAYLAND" = xyes])
73
74dnl *** checks for header files ***
75dnl check if we have ANSI C header files
76AC_HEADER_STDC
77
78dnl *** checks for types/defines ***
79
80dnl *** checks for structures ***
81
82dnl *** checks for compiler characteristics ***
83
84dnl *** checks for library functions ***
85
86dnl *** checks for dependancy libraries ***
87
88dnl *** set variables based on configure arguments ***
89
90
91if test "$CODEC_ENGINE" != "" ; then
92 AC_MSG_NOTICE([Checking component : CODEC_ENGINE])
93 AC_CHECK_FILES(["$CODEC_ENGINE"],,[AC_MSG_ERROR(["$CODEC_ENGINE" not found Set path variable CODEC_ENGINE])])
94 AC_SUBST(CODEC_ENGINE)
95else
96 AC_MSG_ERROR([Set path variable CODEC_ENGINE])
97fi
98
99if test "$FRAMEWORK_COMPONENTS" != "" ; then
100 AC_MSG_NOTICE([Checking component : FRAMEWORK_COMPONENTS])
101 AC_CHECK_FILES(["$FRAMEWORK_COMPONENTS"],,[AC_MSG_ERROR(["$FRAMEWORK_COMPONENTS" not found Set path variable FRAMEWORK_COMPONENTS])])
102 AC_SUBST(FRAMEWORK_COMPONENTS)
103else
104 AC_MSG_ERROR([Set path variable FRAMEWORK_COMPONENTS])
105fi
106
107if test "$IVAHD_CODECS" != "" ; then
108 AC_MSG_NOTICE([Checking component : IVAHD_CODECS])
109 AC_CHECK_FILES(["$IVAHD_CODECS"],,[AC_MSG_ERROR(["$IVAHD_CODECS" not fou nd Set path variable IVAHD_CODECS])])
110 AC_SUBST(IVAHD_CODECS)
111else
112 AC_MSG_ERROR([Set path variable IVAHD_CODECS])
113fi
114
115if test "$XDAIAS" != "" ; then
116 AC_MSG_NOTICE([Checking component : XDAIAS])
117 AC_CHECK_FILES(["$XDAIAS"],,[AC_MSG_ERROR(["$XDAIAS" not found Set path variable XDAIAS])])
118 AC_SUBST(XDAIAS)
119else
120 AC_MSG_ERROR([Set path variable XDAIAS])
121fi
122
123if test "$XDCTOOLS" != "" ; then
124 AC_MSG_NOTICE([Checking component : XDCTOOLS])
125 AC_CHECK_FILES(["$XDCTOOLS"],,[AC_MSG_ERROR(["$XDCTOOLS" not found Set path variable XDCTOOLS])])
126 AC_SUBST(XDCTOOLS)
127else
128 AC_MSG_ERROR([Set path variable XDCTOOLS])
129fi
130
131if test "$IPC" != "" ; then
132 AC_MSG_NOTICE([Checking component : IPC])
133 AC_CHECK_FILES(["$IPC"],,[AC_MSG_ERROR(["$IPC" not found Set path variable IPC])])
134 AC_SUBST(IPC)
135else
136 AC_MSG_ERROR([Set path variable IPC])
137fi
138
139
140
141
142
143
144AC_CONFIG_FILES([
145libdce.pc
146Makefile
147])
148AC_OUTPUT
diff --git a/dce_priv.h b/dce_priv.h
index dea43d4..7f2624f 100644
--- a/dce_priv.h
+++ b/dce_priv.h
@@ -33,8 +33,11 @@
33#ifndef __DCE_PRIV_H__ 33#ifndef __DCE_PRIV_H__
34#define __DCE_PRIV_H__ 34#define __DCE_PRIV_H__
35 35
36
37#ifdef BUILDOS_QNX
36#include <sys/slog.h> 38#include <sys/slog.h>
37 39
40
38/********************* MACROS ************************/ 41/********************* MACROS ************************/
39/***************** TRACE MACROS *********************/ 42/***************** TRACE MACROS *********************/
40/* Need to make it OS specific and support different trace levels */ 43/* Need to make it OS specific and support different trace levels */
@@ -44,7 +47,16 @@
44#define DEBUG(FMT, ...) do { \ 47#define DEBUG(FMT, ...) do { \
45 slogf(42, _SLOG_DEBUG2, "%s:%d:\t%s\tdebug: " FMT, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \ 48 slogf(42, _SLOG_DEBUG2, "%s:%d:\t%s\tdebug: " FMT, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
46} while( 0 ) 49} while( 0 )
50#endif
47 51
52#ifdef BUILDOS_LINUX
53#define ERROR(FMT, ...) do { \
54 printf("%s:%d:\t%s\t Error: "FMT,__FILE__, __LINE__,__FUNCTION__ ,##__VA_ARGS__); \
55}while( 0 )
56#define DEBUG(FMT, ...) do { \
57 printf("%s:%d:\t%s\t Debug: "FMT,__FILE__, __LINE__,__FUNCTION__ ,##__VA_ARGS__); \
58}while( 0 )
59#endif
48 60
49/***************** ASSERT MACROS *********************/ 61/***************** ASSERT MACROS *********************/
50#define _ASSERT_AND_EXECUTE(_COND_, _ERRORCODE_, _EXPR_) do { \ 62#define _ASSERT_AND_EXECUTE(_COND_, _ERRORCODE_, _EXPR_) do { \
diff --git a/libdce.c b/libdce.c
index ed02fcf..fc507c6 100644
--- a/libdce.c
+++ b/libdce.c
@@ -71,12 +71,11 @@
71 71
72#include <xdc/std.h> 72#include <xdc/std.h>
73 73
74#if defined(BUILDOS_GLP) 74#if defined(BUILDOS_LINUX)
75#include <xf86drm.h> 75#include <xf86drm.h>
76#include <omap_drm.h> 76#include <omap_drm.h>
77#include <omap_dce.h>
78#include <omap_drmif.h> 77#include <omap_drmif.h>
79#endif /* BUILDOS_GLP */ 78#endif /* BUILDOS_LINUX */
80 79
81/* IPC Headers */ 80/* IPC Headers */
82#include <MmRpc.h> 81#include <MmRpc.h>
@@ -88,21 +87,19 @@
88#include "memplugin.h" 87#include "memplugin.h"
89 88
90 89
91#if defined(BUILDOS_GLP) 90#if defined(BUILDOS_LINUX)
92#ifdef GLP_X11 91#ifdef HAVE_X11
93int dce_auth_x11(int *fd); 92// Defined from configure.ac
94#endif /* GLP_X11 */ 93extern int dce_auth_x11(int *fd);
95#ifdef GLP_WAYLAND 94#endif /* HAVE_X11 */
96int dce_auth_wayland(int *fd); 95#ifdef HAVE_WAYLAND // Defined from configure.ac
97#endif /* GLP_WAYLAND */ 96extern int dce_auth_wayland(int *fd);
97#endif /* HAVE_WAYLAND */
98 98
99static int fd = -1; 99int fd = -1;
100static struct omap_device *dev; 100struct omap_device *dev = 0;
101static int ioctl_base; 101uint32_t dce_debug = 3;
102#define CMD(name) (ioctl_base + DRM_OMAP_DCE_##name) 102#endif /* BUILDOS_LINUX */
103
104uint32_t dce_debug = 3;
105#endif /* BUILDOS_GLP */
106 103
107 104
108/********************* GLOBALS ***********************/ 105/********************* GLOBALS ***********************/
@@ -181,6 +178,42 @@ static int dce_init(void)
181 _ASSERT_AND_EXECUTE(eError == DCE_EOK, DCE_EIPC_CREATE_FAIL, count--); 178 _ASSERT_AND_EXECUTE(eError == DCE_EOK, DCE_EIPC_CREATE_FAIL, count--);
182 179
183 printf("open(/dev/" DCE_DEVICE_NAME ") -> 0x%x\n", (int)MmRpcHandle); 180 printf("open(/dev/" DCE_DEVICE_NAME ") -> 0x%x\n", (int)MmRpcHandle);
181
182#if defined(BUILDOS_LINUX)
183 /* Open omapdrm device */
184 int authenticated = 0;
185
186#ifdef HAVE_X11
187 /*If X11 server is running*/
188 if( !authenticated ) {
189 int ret = dce_auth_x11(&fd);
190 if( !ret ) {
191 authenticated = 1;
192 }
193 }
194#endif
195#ifdef HAVE_WAYLAND
196 /*If Wayland windowing is supported*/
197 if( !authenticated ) {
198 int ret = dce_auth_wayland(&fd);
199 if( !ret ) {
200 authenticated = 1;
201 }
202 }
203#endif
204 if((fd == -1) && !authenticated ) {
205 printf("no X11/wayland, fallback to opening DRM device directly\n");
206 fd = drmOpen("omapdrm", "platform:omapdrm:00");
207 }
208 if( fd >= 0 ) {
209 dev = omap_device_new(fd);
210 } else {
211 printf("Error opening omapdrm : drmOpen failed");
212 goto EXIT;
213 }
214#endif /* BUILDOS_LINUX */
215
216
184EXIT: 217EXIT:
185 pthread_mutex_unlock(&mutex); 218 pthread_mutex_unlock(&mutex);
186 return (eError); 219 return (eError);
@@ -199,11 +232,34 @@ static void dce_deinit(void)
199 MmRpc_delete(&MmRpcHandle); 232 MmRpc_delete(&MmRpcHandle);
200 } 233 }
201 MmRpcHandle = NULL; 234 MmRpcHandle = NULL;
235
236#if defined(BUILDOS_LINUX)
237 omap_device_del(dev);
238 dev = NULL;
239 close(fd);
240 fd = -1;
241#endif /* BUILDOS_LINUX */
242
243
202EXIT: 244EXIT:
203 pthread_mutex_unlock(&mutex); 245 pthread_mutex_unlock(&mutex);
204 return; 246 return;
205} 247}
206 248
249/* Incase of X11 or Wayland the fd can be shared to libdce using this call */
250#if defined(BUILDOS_LINUX)
251void dce_set_fd(int dce_fd)
252{
253 fd = dce_fd;
254}
255
256int dce_get_fd(void)
257{
258 return (fd);
259}
260
261#endif /* BUILDOS_LINUX */
262
207/*===============================================================*/ 263/*===============================================================*/
208/** Engine_open : Open Codec Engine. 264/** Engine_open : Open Codec Engine.
209 * 265 *
diff --git a/libdce.h b/libdce.h
index c64456a..9f7dcd7 100644
--- a/libdce.h
+++ b/libdce.h
@@ -60,7 +60,7 @@ void *dce_alloc(int sz);
60void dce_free(void *ptr); 60void dce_free(void *ptr);
61 61
62 62
63#if defined(BUILDOS_GLP) 63#if defined(BUILDOS_LINUX)
64void dce_set_fd(int fd); 64void dce_set_fd(int fd);
65int dce_get_fd(); 65int dce_get_fd();
66 66
@@ -68,12 +68,9 @@ int dce_get_fd();
68#define xdc__ARGTOPTR 68#define xdc__ARGTOPTR
69#define xdc__ARGTOFXN 69#define xdc__ARGTOFXN
70 70
71struct omap_device *dce_init(void);
72void dce_deinit(struct omap_device *dev);
73
74#define XDM_MEMTYPE_BO 10 71#define XDM_MEMTYPE_BO 10
75#define XDM_MEMTYPE_BO_OFFSET 11 72#define XDM_MEMTYPE_BO_OFFSET 11
76#endif /* BUILDOS_GLP */ 73#endif /* BUILDOS_LINUX */
77 74
78#endif /* __LIBDCE_H__ */ 75#endif /* __LIBDCE_H__ */
79 76
diff --git a/libdce.pc.in b/libdce.pc.in
new file mode 100644
index 0000000..5f71a29
--- /dev/null
+++ b/libdce.pc.in
@@ -0,0 +1,11 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@
5
6Name: libdce
7Description: distributed codec-engine
8Version: @VERSION@
9Requires: libdrm libdrm_omap
10Libs: -L${libdir} -ldce
11Cflags: -I${includedir}/
diff --git a/linux/libdce-x11.c b/linux/libdce-x11.c
new file mode 100644
index 0000000..442a761
--- /dev/null
+++ b/linux/libdce-x11.c
@@ -0,0 +1,131 @@
1/*
2 * Copyright (c) 2012, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <stdlib.h>
34#include <string.h>
35#include <stdio.h>
36#include <unistd.h>
37#include <stdint.h>
38#include <sys/types.h>
39#include <sys/stat.h>
40#include <fcntl.h>
41#include <pthread.h>
42#include <xf86drm.h>
43#include <xf86drm.h>
44#include <omap_drm.h>
45#include <omap_drmif.h>
46
47#include <X11/Xlib.h>
48#include <X11/Xmd.h>
49#include <X11/extensions/dri2proto.h>
50#include <X11/extensions/dri2.h>
51
52#include <dce_priv.h>
53
54int dce_auth_x11(int *pfd)
55{
56 Display *dpy;
57 Window root;
58 drm_magic_t magic;
59 int eventBase, errorBase, major, minor;
60 char *driver, *device;
61 int ret = -1;
62 int fd = *pfd;
63
64 DEBUG("attempting to open X11 connection");
65 dpy = XOpenDisplay(NULL);
66 if (!dpy) {
67 ERROR("Could not open display");
68 goto no_x11;
69 }
70
71 if (!DRI2InitDisplay(dpy, NULL)) {
72 ERROR("DRI2InitDisplay failed");
73 goto no_x11;
74 }
75
76 if (!DRI2QueryExtension(dpy, &eventBase, &errorBase)) {
77 ERROR("DRI2QueryExtension failed");
78 goto no_x11;
79 }
80
81 DEBUG("DRI2QueryExtension: eventBase=%d, errorBase=%d", eventBase, errorBase);
82
83 if (!DRI2QueryVersion(dpy, &major, &minor)) {
84 ERROR("DRI2QueryVersion failed");
85 goto no_x11;
86 }
87
88 DEBUG("DRI2QueryVersion: major=%d, minor=%d", major, minor);
89
90 root = RootWindow(dpy, DefaultScreen(dpy));
91
92 if (!DRI2Connect(dpy, root, DRI2DriverDRI, &driver, &device)) {
93 DEBUG("DRI2Connect failed");
94 goto no_x11;
95 }
96
97 DEBUG("DRI2Connect: driver=%s, device=%s", driver, device);
98
99 /* only open the device if we don't already have an fd.. see
100 * dce_set_fd(). Need to sort out a better way to handle this
101 * but GEM buffer handles are only valid within the context of
102 * a given file-open. Switching to dmabuf or flink handles
103 * would solve this.
104 */
105 if (fd == -1) {
106 fd = open(device, O_RDWR);
107 if (fd < 0) {
108 ERROR("open failed");
109 goto no_x11_free;
110 }
111 }
112
113 if (drmGetMagic(fd, &magic)) {
114 ERROR("drmGetMagic failed");
115 goto no_x11_free;
116 }
117
118 if (!DRI2Authenticate(dpy, root, magic)) {
119 ERROR("DRI2Authenticate failed");
120 goto no_x11_free;
121 }
122
123 ret = 0;
124 *pfd = fd;
125
126no_x11_free:
127 XFree(driver);
128 XFree(device);
129no_x11:
130 return ret;
131}
diff --git a/linux/wayland-drm-client-protocol.h b/linux/wayland-drm-client-protocol.h
new file mode 100644
index 0000000..dfcaa8b
--- /dev/null
+++ b/linux/wayland-drm-client-protocol.h
@@ -0,0 +1,209 @@
1/*
2 * Copyright © 2008-2011 Kristian Høgsberg
3 * Copyright © 2010-2011 Intel Corporation
4 *
5 * Permission to use, copy, modify, distribute, and sell this
6 * software and its documentation for any purpose is hereby granted
7 * without fee, provided that\n the above copyright notice appear in
8 * all copies and that both that copyright notice and this permission
9 * notice appear in supporting documentation, and that the name of
10 * the copyright holders not be used in advertising or publicity
11 * pertaining to distribution of the software without specific,
12 * written prior permission. The copyright holders make no
13 * representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied
15 * warranty.
16 *
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
22 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
24 * THIS SOFTWARE.
25 */
26
27#ifndef DRM_CLIENT_PROTOCOL_H
28#define DRM_CLIENT_PROTOCOL_H
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <stdint.h>
35#include <stddef.h>
36#include "wayland-util.h"
37
38struct wl_client;
39struct wl_resource;
40struct wl_drm;
41extern const struct wl_interface wl_drm_interface;
42
43#ifndef WL_DRM_ERROR_ENUM
44#define WL_DRM_ERROR_ENUM
45enum wl_drm_error {
46 WL_DRM_ERROR_AUTHENTICATE_FAIL = 0,
47 WL_DRM_ERROR_INVALID_FORMAT = 1,
48 WL_DRM_ERROR_INVALID_NAME = 2,
49};
50#endif /* WL_DRM_ERROR_ENUM */
51
52#ifndef WL_DRM_FORMAT_ENUM
53#define WL_DRM_FORMAT_ENUM
54enum wl_drm_format {
55 WL_DRM_FORMAT_C8 = 0x20203843,
56 WL_DRM_FORMAT_RGB332 = 0x38424752,
57 WL_DRM_FORMAT_BGR233 = 0x38524742,
58 WL_DRM_FORMAT_XRGB4444 = 0x32315258,
59 WL_DRM_FORMAT_XBGR4444 = 0x32314258,
60 WL_DRM_FORMAT_RGBX4444 = 0x32315852,
61 WL_DRM_FORMAT_BGRX4444 = 0x32315842,
62 WL_DRM_FORMAT_ARGB4444 = 0x32315241,
63 WL_DRM_FORMAT_ABGR4444 = 0x32314241,
64 WL_DRM_FORMAT_RGBA4444 = 0x32314152,
65 WL_DRM_FORMAT_BGRA4444 = 0x32314142,
66 WL_DRM_FORMAT_XRGB1555 = 0x35315258,
67 WL_DRM_FORMAT_XBGR1555 = 0x35314258,
68 WL_DRM_FORMAT_RGBX5551 = 0x35315852,
69 WL_DRM_FORMAT_BGRX5551 = 0x35315842,
70 WL_DRM_FORMAT_ARGB1555 = 0x35315241,
71 WL_DRM_FORMAT_ABGR1555 = 0x35314241,
72 WL_DRM_FORMAT_RGBA5551 = 0x35314152,
73 WL_DRM_FORMAT_BGRA5551 = 0x35314142,
74 WL_DRM_FORMAT_RGB565 = 0x36314752,
75 WL_DRM_FORMAT_BGR565 = 0x36314742,
76 WL_DRM_FORMAT_RGB888 = 0x34324752,
77 WL_DRM_FORMAT_BGR888 = 0x34324742,
78 WL_DRM_FORMAT_XRGB8888 = 0x34325258,
79 WL_DRM_FORMAT_XBGR8888 = 0x34324258,
80 WL_DRM_FORMAT_RGBX8888 = 0x34325852,
81 WL_DRM_FORMAT_BGRX8888 = 0x34325842,
82 WL_DRM_FORMAT_ARGB8888 = 0x34325241,
83 WL_DRM_FORMAT_ABGR8888 = 0x34324241,
84 WL_DRM_FORMAT_RGBA8888 = 0x34324152,
85 WL_DRM_FORMAT_BGRA8888 = 0x34324142,
86 WL_DRM_FORMAT_XRGB2101010 = 0x30335258,
87 WL_DRM_FORMAT_XBGR2101010 = 0x30334258,
88 WL_DRM_FORMAT_RGBX1010102 = 0x30335852,
89 WL_DRM_FORMAT_BGRX1010102 = 0x30335842,
90 WL_DRM_FORMAT_ARGB2101010 = 0x30335241,
91 WL_DRM_FORMAT_ABGR2101010 = 0x30334241,
92 WL_DRM_FORMAT_RGBA1010102 = 0x30334152,
93 WL_DRM_FORMAT_BGRA1010102 = 0x30334142,
94 WL_DRM_FORMAT_YUYV = 0x56595559,
95 WL_DRM_FORMAT_YVYU = 0x55595659,
96 WL_DRM_FORMAT_UYVY = 0x59565955,
97 WL_DRM_FORMAT_VYUY = 0x59555956,
98 WL_DRM_FORMAT_AYUV = 0x56555941,
99 WL_DRM_FORMAT_NV12 = 0x3231564e,
100 WL_DRM_FORMAT_NV21 = 0x3132564e,
101 WL_DRM_FORMAT_NV16 = 0x3631564e,
102 WL_DRM_FORMAT_NV61 = 0x3136564e,
103 WL_DRM_FORMAT_YUV410 = 0x39565559,
104 WL_DRM_FORMAT_YVU410 = 0x39555659,
105 WL_DRM_FORMAT_YUV411 = 0x31315559,
106 WL_DRM_FORMAT_YVU411 = 0x31315659,
107 WL_DRM_FORMAT_YUV420 = 0x32315559,
108 WL_DRM_FORMAT_YVU420 = 0x32315659,
109 WL_DRM_FORMAT_YUV422 = 0x36315559,
110 WL_DRM_FORMAT_YVU422 = 0x36315659,
111 WL_DRM_FORMAT_YUV444 = 0x34325559,
112 WL_DRM_FORMAT_YVU444 = 0x34325659,
113};
114#endif /* WL_DRM_FORMAT_ENUM */
115
116struct wl_drm_listener {
117 /**
118 * device - (none)
119 * @name: (none)
120 */
121 void (*device)(void *data,
122 struct wl_drm *wl_drm,
123 const char *name);
124 /**
125 * format - (none)
126 * @format: (none)
127 */
128 void (*format)(void *data,
129 struct wl_drm *wl_drm,
130 uint32_t format);
131 /**
132 * authenticated - (none)
133 */
134 void (*authenticated)(void *data,
135 struct wl_drm *wl_drm);
136};
137
138static inline int
139wl_drm_add_listener(struct wl_drm *wl_drm,
140 const struct wl_drm_listener *listener, void *data)
141{
142 return wl_proxy_add_listener((struct wl_proxy *) wl_drm,
143 (void (**)(void)) listener, data);
144}
145
146#define WL_DRM_AUTHENTICATE 0
147#define WL_DRM_CREATE_BUFFER 1
148#define WL_DRM_CREATE_PLANAR_BUFFER 2
149
150static inline void
151wl_drm_set_user_data(struct wl_drm *wl_drm, void *user_data)
152{
153 wl_proxy_set_user_data((struct wl_proxy *) wl_drm, user_data);
154}
155
156static inline void *
157wl_drm_get_user_data(struct wl_drm *wl_drm)
158{
159 return wl_proxy_get_user_data((struct wl_proxy *) wl_drm);
160}
161
162static inline void
163wl_drm_destroy(struct wl_drm *wl_drm)
164{
165 wl_proxy_destroy((struct wl_proxy *) wl_drm);
166}
167
168static inline void
169wl_drm_authenticate(struct wl_drm *wl_drm, uint32_t id)
170{
171 wl_proxy_marshal((struct wl_proxy *) wl_drm,
172 WL_DRM_AUTHENTICATE, id);
173}
174
175static inline struct wl_buffer *
176wl_drm_create_buffer(struct wl_drm *wl_drm, uint32_t name, int32_t width, int32_t height, uint32_t stride, uint32_t format)
177{
178 struct wl_proxy *id;
179 id = wl_proxy_create((struct wl_proxy *) wl_drm,
180 &wl_buffer_interface);
181 if (!id)
182 return NULL;
183
184 wl_proxy_marshal((struct wl_proxy *) wl_drm,
185 WL_DRM_CREATE_BUFFER, id, name, width, height, stride, format);
186
187 return (struct wl_buffer *) id;
188}
189
190static inline struct wl_buffer *
191wl_drm_create_planar_buffer(struct wl_drm *wl_drm, uint32_t name, int32_t width, int32_t height, uint32_t format, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2)
192{
193 struct wl_proxy *id;
194 id = wl_proxy_create((struct wl_proxy *) wl_drm,
195 &wl_buffer_interface);
196 if (!id)
197 return NULL;
198
199 wl_proxy_marshal((struct wl_proxy *) wl_drm,
200 WL_DRM_CREATE_PLANAR_BUFFER, id, name, width, height, format, offset0, stride0, offset1, stride1, offset2, stride2);
201
202 return (struct wl_buffer *) id;
203}
204
205#ifdef __cplusplus
206}
207#endif
208
209#endif
diff --git a/linux/wayland-drm-protocol.c b/linux/wayland-drm-protocol.c
new file mode 100644
index 0000000..aa6d4e0
--- /dev/null
+++ b/linux/wayland-drm-protocol.c
@@ -0,0 +1,71 @@
1/*
2 * Copyright © 2008-2011 Kristian Høgsberg
3 * Copyright © 2010-2011 Intel Corporation
4 *
5 * Permission to use, copy, modify, distribute, and sell this
6 * software and its documentation for any purpose is hereby granted
7 * without fee, provided that\n the above copyright notice appear in
8 * all copies and that both that copyright notice and this permission
9 * notice appear in supporting documentation, and that the name of
10 * the copyright holders not be used in advertising or publicity
11 * pertaining to distribution of the software without specific,
12 * written prior permission. The copyright holders make no
13 * representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied
15 * warranty.
16 *
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
22 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
24 * THIS SOFTWARE.
25 */
26
27#include <stdlib.h>
28#include <stdint.h>
29#include "wayland-util.h"
30
31extern const struct wl_interface wl_buffer_interface;
32extern const struct wl_interface wl_buffer_interface;
33
34static const struct wl_interface *types[] = {
35 NULL,
36 &wl_buffer_interface,
37 NULL,
38 NULL,
39 NULL,
40 NULL,
41 NULL,
42 &wl_buffer_interface,
43 NULL,
44 NULL,
45 NULL,
46 NULL,
47 NULL,
48 NULL,
49 NULL,
50 NULL,
51 NULL,
52 NULL,
53};
54
55static const struct wl_message wl_drm_requests[] = {
56 { "authenticate", "u", types + 0 },
57 { "create_buffer", "nuiiuu", types + 1 },
58 { "create_planar_buffer", "nuiiuiiiiii", types + 7 },
59};
60
61static const struct wl_message wl_drm_events[] = {
62 { "device", "s", types + 0 },
63 { "format", "u", types + 0 },
64 { "authenticated", "", types + 0 },
65};
66
67WL_EXPORT const struct wl_interface wl_drm_interface = {
68 "wl_drm", 1,
69 ARRAY_LENGTH(wl_drm_requests), wl_drm_requests,
70 ARRAY_LENGTH(wl_drm_events), wl_drm_events,
71};
diff --git a/memplugin.h b/memplugin.h
index 816829b..49e0500 100644
--- a/memplugin.h
+++ b/memplugin.h
@@ -37,22 +37,26 @@
37#include <string.h> 37#include <string.h>
38#include <stdio.h> 38#include <stdio.h>
39 39
40#if defined(BUILDOS_QNX)
41#include <memmgr.h>
42#endif /* BUILDOS_QNX */
43 40
44#if defined(BUILDOS_GLP) 41#if defined(BUILDOS_LINUX)
45#include <xf86drm.h> 42#include <xf86drm.h>
46#endif /* BUILDOS_GLP */ 43#include <omap_drm.h>
44#include <omap_drmif.h>
45#endif /* BUILDOS_LINUX */
47 46
47
48#if defined(BUILDOS_QNX)
48/* IPC Headers */ 49/* IPC Headers */
49#include <tilermem.h> 50#include <tilermem.h>
50#include <SharedMemoryAllocatorUsr.h> 51#include <SharedMemoryAllocatorUsr.h>
52#include <memmgr.h>
53#endif /* BUILDOS_QNX */
51 54
52 55
53#define P2H(p) (&(((MemHeader *)(p))[-1])) 56#define P2H(p) (&(((MemHeader *)(p))[-1]))
54#define H2P(h) ((void *)&(h)[1]) 57#define H2P(h) ((void *)&(h)[1])
55 58
59
56/* MemHeader is important because it is necessary to know the */ 60/* MemHeader is important because it is necessary to know the */
57/* size of the parameter buffers on IPU for Cache operations */ 61/* size of the parameter buffers on IPU for Cache operations */
58/* The size can't be assumed as codec supports different inputs */ 62/* The size can't be assumed as codec supports different inputs */
@@ -63,6 +67,7 @@ typedef struct MemHeader {
63 void *ptr; 67 void *ptr;
64} MemHeader; 68} MemHeader;
65 69
70
66typedef enum mem_type { 71typedef enum mem_type {
67 TILER_1D_BUFFER, 72 TILER_1D_BUFFER,
68 TILER8_2D_BUFFER, 73 TILER8_2D_BUFFER,
@@ -85,7 +90,7 @@ void *memplugin_alloc(int sz, int height, mem_type memory_type);
85 90
86void memplugin_free(void *ptr, mem_type memory_type); 91void memplugin_free(void *ptr, mem_type memory_type);
87 92
88void *memplugin_share(void *ptr, mem_type memory_type); 93int memplugin_share(void *ptr);
89 94
90#endif /* __MEMPLUGIN_H__ */ 95#endif /* __MEMPLUGIN_H__ */
91 96
diff --git a/memplugin_linux.c b/memplugin_linux.c
new file mode 100644
index 0000000..bb99d26
--- /dev/null
+++ b/memplugin_linux.c
@@ -0,0 +1,87 @@
1/*
2 * Copyright (c) 2013, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include "memplugin.h"
34#include "dce_priv.h"
35
36extern struct omap_device *dev;
37
38
39/* memplugin_alloc - allocates omap_bo buffer with a header above it.
40 * @sz: Size of the buffer requsted
41 * @height: this parameter is currently not used
42 * @memory_type : Currently dce_alloc is used on for parameter buffer
43 * Returns a virtual address pointer to omap_bo buffer or the param buffer
44 */
45void *memplugin_alloc(int sz, int height, mem_type memory_type)
46{
47 MemHeader *h;
48 struct omap_bo *bo = omap_bo_new(dev, sz + sizeof(MemHeader), OMAP_BO_WC);
49
50 if( !bo ) {
51 return (NULL);
52 }
53
54 h = omap_bo_map(bo);
55 memset(H2P(h), 0, sz);
56 h->size = sz;
57 h->ptr = (void *)bo;
58
59 return (H2P(h));
60
61}
62
63/*
64 * @ptr: pointer to omap_bo buffer, to be freed
65 * @memory_type: Currently dce_free is called on parameter buffers only
66 */
67void memplugin_free(void *ptr, mem_type memory_type)
68{
69 if( ptr ) {
70 MemHeader *h = P2H(ptr);
71 omap_bo_del((struct omap_bo *)h->ptr);
72 }
73}
74
75/* memplugin_share - converts the omap_bo buffer into dmabuf
76 * @ptr : pointer of omap_bo buffer, to be converted to fd
77 * Returns a file discriptor for the omap_bo buffer
78 */
79int memplugin_share(void *ptr)
80{
81 if( ptr ) {
82 MemHeader *h = P2H(ptr);
83 return (omap_bo_dmabuf((struct omap_bo *)h->ptr));
84 }
85 return (-1);
86}
87