]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/libdce2.git/blob - libdce_linux.c
Merge remote-tracking branch 'other/master'
[glsdk/libdce2.git] / libdce_linux.c
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>
37 #include <xf86drm.h>
38 #include <omap_drm.h>
39 #include <omap_drmif.h>
41 #include <MmRpc.h>
42 #include "dce_priv.h"
43 #include "libdce.h"
44 #include "memplugin.h"
46 #define INVALID_DRM_FD (-1)
48 int                    OmapDrm_FD  = INVALID_DRM_FD;
49 struct omap_device    *OmapDev     = NULL;
50 extern MmRpc_Handle    MmRpcHandle;
52 void *dce_init(void)
53 {
54     dce_error_status    eError = DCE_EOK;
56     printf(" >> dce_init\n");
58     /* Open omapdrm device */
59     if( !OmapDrm_FD && OmapDrm_FD == INVALID_DRM_FD ) {
60         printf("Open omapdrm device \n");
61         OmapDrm_FD = drmOpen("omapdrm", "platform:omapdrm:00");
62         _ASSERT(OmapDrm_FD > 0, DCE_EOMAPDRM_FAIL);
63     }
64     OmapDev = omap_device_new(OmapDrm_FD);
65     _ASSERT(OmapDev != NULL, DCE_EOMAPDRM_FAIL);
67 EXIT:
68     return ((void *)OmapDev);
69 }
71 void dce_deinit(void *dev)
72 {
73     omap_device_del(dev);
74     dev = NULL;
75     close(OmapDrm_FD);
76     OmapDrm_FD = INVALID_DRM_FD;
78     return;
79 }
81 int dce_buf_lock(int num, size_t *handle)
82 {
83     int                 i;
84     MmRpc_BufDesc      *desc = NULL;
85     dce_error_status    eError = DCE_EOK;
87     _ASSERT(num > 0, DCE_EINVALID_INPUT);
89     desc = memplugin_alloc(num * sizeof(MmRpc_BufDesc), 0, TILER_1D_BUFFER);
90     _ASSERT(desc != NULL, DCE_EOUT_OF_MEMORY);
92     for( i = 0; i < num; i++ ) {
93         desc[i].handle = handle[i];
94     }
96     eError = MmRpc_use(MmRpcHandle, MmRpc_BufType_Handle, num, desc);
98     _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
99 EXIT:
100     return (eError);
103 int dce_buf_unlock(int num, size_t *handle)
105     int                 i;
106     MmRpc_BufDesc      *desc = NULL;
107     dce_error_status    eError = DCE_EOK;
109     _ASSERT(num > 0, DCE_EINVALID_INPUT);
111     desc = memplugin_alloc(num * sizeof(MmRpc_BufDesc), 0, TILER_1D_BUFFER);
112     _ASSERT(desc != NULL, DCE_EOUT_OF_MEMORY);
114     for( i = 0; i < num; i++ ) {
115         desc[i].handle = handle[i];
116     }
118     eError = MmRpc_release(MmRpcHandle, MmRpc_BufType_Handle, num, desc);
120     _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
121 EXIT:
122     return (eError);
125 /* Incase of X11 or Wayland the fd can be shared to libdce using this call */
126 void dce_set_fd(int dce_fd)
128     OmapDrm_FD = dce_fd;
131 int dce_get_fd(void)
133     return (OmapDrm_FD);