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 */
33 #include <stdlib.h>
34 #include <string.h>
35 #include <stdio.h>
36 #include <xdc/std.h>
38 #include <xf86drm.h>
39 #include <omap_drm.h>
40 #include <omap_drmif.h>
42 #include <MmRpc.h>
43 #include "dce_priv.h"
45 #define INVALID_DRM_FD (-1)
47 int OmapDrm_FD = INVALID_DRM_FD;
49 void *dce_init(void)
50 {
51 struct omap_device *OmapDev = NULL;
52 dce_error_status eError = DCE_EOK;
54 printf(" >> dce_init\n");
56 /* Open omapdrm device */
57 if( !OmapDrm_FD && OmapDrm_FD == INVALID_DRM_FD ) {
58 printf("Open omapdrm device \n");
59 OmapDrm_FD = drmOpen("omapdrm", "platform:omapdrm:00");
60 _ASSERT(OmapDrm_FD > 0, DCE_EOMAPDRM_FAIL);
61 }
62 OmapDev = omap_device_new(OmapDrm_FD);
63 _ASSERT(OmapDev != NULL, DCE_EOMAPDRM_FAIL);
65 EXIT:
66 return ((void *)OmapDev);
67 }
69 void dce_deinit(void *dev)
70 {
71 omap_device_del(dev);
72 dev = NULL;
73 close(OmapDrm_FD);
74 OmapDrm_FD = INVALID_DRM_FD;
76 return;
77 }
79 int dce_buf_lock(int num, size_t *handle)
80 {
81 int i;
82 MmRpc_BufDesc *desc = NULL;
83 dce_error_status eError = DCE_EOK;
85 _ASSERT(num > 0, DCE_EINVALID_INPUT);
87 desc = memplugin_alloc(num * sizeof(MmRpc_BufDesc), 0, TILER_1D_BUFFER);
88 _ASSERT(desc != NULL, DCE_EOUT_OF_MEMORY);
90 for( i = 0; i < num; i++ ) {
91 desc[i].handle = handle[i];
92 }
94 eError = MmRpc_use(MmRpcHandle, MmRpc_BufType_Handle, num, desc);
96 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
97 EXIT:
98 return (eError);
99 }
101 int dce_buf_unlock(int num, size_t *handle)
102 {
103 int i;
104 MmRpc_BufDesc *desc = NULL;
105 dce_error_status eError = DCE_EOK;
107 _ASSERT(num > 0, DCE_EINVALID_INPUT);
109 desc = memplugin_alloc(num * sizeof(MmRpc_BufDesc), 0, TILER_1D_BUFFER);
110 _ASSERT(desc != NULL, DCE_EOUT_OF_MEMORY);
112 for( i = 0; i < num; i++ ) {
113 desc[i].handle = handle[i];
114 }
116 eError = MmRpc_release(MmRpcHandle, MmRpc_BufType_Handle, num, desc);
118 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
119 EXIT:
120 return (eError);
121 }
123 /* Incase of X11 or Wayland the fd can be shared to libdce using this call */
124 void dce_set_fd(int dce_fd)
125 {
126 OmapDrm_FD = dce_fd;
127 }
129 int dce_get_fd(void)
130 {
131 return (OmapDrm_FD);
132 }