]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/libdce2.git/blob - memplugin_qnx.c
610a4f9aea7b16b88ce6e4bba965a466ce26f5a2
[glsdk/libdce2.git] / memplugin_qnx.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 "memplugin.h"
34 #include "dce_priv.h"
37 /* For TILER 2D Buffers : sz       = width                              */
38 /*                                : height = nonzero                           */
39 /* For other memory_types : height = 0                               */
40 void *memplugin_alloc(int sz, int height, mem_type memory_type)
41 {
42     MemHeader          *h;
43     shm_buf            *handle;
44     MemAllocBlock       block;
45     int                 num_block;
46     mem_error_status    eError = MEM_EOK;
48     _ASSERT(sz != 0, MEM_EINVALID_INPUT);
49     _ASSERT((memory_type < MEM_MAX) && (memory_type >= TILER_1D_BUFFER), MEM_EINVALID_INPUT);
51     /* Tiler buffer Allocations : Only Tiler 1D used for Parameter Buffers and RPC Message buffers */
52     if( memory_type == TILER_1D_BUFFER || memory_type == TILER8_2D_BUFFER || memory_type == TILER16_2D_BUFFER ) {
53         num_block = 1;
55         if( memory_type == TILER_1D_BUFFER ) {
56             /* Allocate in tiler paged mode (1d) container */
57             block.pixelFormat = PIXEL_FMT_PAGE;
58             block.dim.len = sz + sizeof(MemHeader);
59 #if 0 /* Data Tiler Buffers not to be allocated by DCE */
60         } else if( memory_type == TILER8_2D_BUFFER ) {
61             /* Allocate in tiler 8 bit mode (2d) container */
62             _ASSERT(height != 0, MEM_EINVALID_INPUT);
63             block.pixelFormat = PIXEL_FMT_8BIT;
64             block.dim.area.width  = sz;
65             block.dim.area.height = height;
66         } else {
67             /* Allocate in tiler 16 bit mode (2d) container */
68             _ASSERT(height != 0, MEM_EINVALID_INPUT);
69             block.pixelFormat = PIXEL_FMT_16BIT;
70             block.dim.area.width  = sz;
71             block.dim.area.height = height;
72 #endif
73         }
74         block.stride = 0;
76         h = MemMgr_Alloc(&block, num_block);
78         _ASSERT(h != NULL, MEM_EOUT_OF_TILER_MEMORY);
80         h->size = sz;
81         memset(H2P(h), 0, sz);
82         return (H2P(h));
83     } else {
85         handle = malloc(sizeof(shm_buf));
86         _ASSERT(handle != NULL, MEM_EOUT_OF_SYSTEM_MEMORY);
88         /* Parameter Buffers : Allocate from Shared Memory considering MemHeader*/
89         SHM_alloc(sz + sizeof(MemHeader), handle);
91         h = (MemHeader *)handle->vir_addr;
92         _ASSERT_AND_EXECUTE(h != NULL, MEM_EOUT_OF_SHMEMORY, free(handle));
94         h->size = sz;
95         h->ptr = handle;
96         memset(H2P(h), 0, sz);
97         return (H2P(h));
98     }
99 EXIT:
100     return (NULL);
103 /* memory_type is not added if MemHeader is used for Tiler Buffers */
104 void memplugin_free(void *ptr, mem_type memory_type)
106     shm_buf            *handle;
107     mem_error_status    eError = MEM_EOK;
109     _ASSERT(ptr != NULL, MEM_EINVALID_INPUT);
110     _ASSERT((memory_type < MEM_MAX) && (memory_type >= TILER_1D_BUFFER), MEM_EINVALID_INPUT);
112     if( memory_type == TILER_1D_BUFFER ) {
113         MemMgr_Free(P2H(ptr));
114     } else if( memory_type == SHARED_MEMORY_BUFFER ) {
115         handle = (P2H(ptr))->ptr;
116         SHM_release(handle);
117         free(handle);
118     } else {
119         ERROR("Tiler 2D Allocation/Free not implemented");
120     }
121 EXIT:;
124 void *memplugin_share(void *ptr, mem_type memory_type)
126     /* No Userspace Virtual pointers to DMA BUF Handles conversion required*/
127     /* Do nothing */
128     return (ptr);