1 /*
2 * Copyright (c) 2011, 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 /* This is a dummy implementation of "ti.sdo.fc.ires.tiledmemory"
34 * that just allocates from the heap:
35 */
37 #include <xdc/std.h>
38 #include <xdc/runtime/System.h>
39 #include <xdc/runtime/Memory.h>
40 #include <xdc/runtime/Assert.h>
42 #include <ti/xdais/ires.h>
44 #include <ti/sdo/fc/ires/iresman.h>
45 #include <ti/sdo/fc/ires/tiledmemory/ires_tiledmemory.h>
47 #include <ti/framework/dce/dce_priv.h>
48 #include <ti/utils/osal/trace.h>
50 #define MIN_ALIGNMENT 0x4
51 static IRESMAN_PersistentAllocFxn *allocFxn; /* Memory alloc function */
52 static IRESMAN_PersistentFreeFxn *freeFxn; /* Memory free function */
54 static void *allocRes(int size, int alignment)
55 {
56 if( alignment < MIN_ALIGNMENT ) {
57 alignment = MIN_ALIGNMENT;
58 }
59 IALG_MemRec rec =
60 {
61 .size = size,
62 .alignment = alignment,
63 .space = IALG_EXTERNAL,
64 .attrs = IALG_PERSIST,
65 };
66 if( !allocFxn(&rec, 1)) {
67 return (NULL);
68 }
69 return (rec.base);
70 }
72 static void freeRes(void *base, int size)
73 {
74 IALG_MemRec rec =
75 {
76 .base = base,
77 .size = size,
78 .alignment = 0x4,
79 .space = IALG_EXTERNAL,
80 .attrs = IALG_PERSIST,
81 };
83 freeFxn(&rec, 1);
84 }
86 static String getProtocolName()
87 {
88 return ("ti.sdo.fc.ires.tiledmemory");
89 }
91 static IRES_ProtocolRevision *getProtocolRevision()
92 {
93 static IRES_ProtocolRevision revision = { 1, 0, 0 };
95 return (&revision);
96 }
98 static IRES_Status myinit(IRESMAN_Params *initArgs)
99 {
100 allocFxn = initArgs->allocFxn;
101 freeFxn = initArgs->freeFxn;
102 return (IRES_OK);
103 }
105 static IRES_Status myexit()
106 {
107 return (IRES_OK);
108 }
110 static void getStaticProperties(IRES_Handle resourceHandle,
111 IRES_Properties *resourceProperties)
112 {
113 /* unused */
114 }
116 static IRES_Handle getHandles(IALG_Handle algHandle,
117 IRES_ResourceDescriptor *resDesc, Int scratchGroupId,
118 IRES_Status *status)
119 {
120 IRES_TILEDMEMORY_ProtocolArgs *args =
121 (IRES_TILEDMEMORY_ProtocolArgs *)resDesc->protocolArgs;
122 IRES_TILEDMEMORY_Handle handle = NULL;
123 Void *ptr = NULL;
124 int size, alignment;
126 Assert_isTrue(args, NULL);
127 Assert_isTrue(algHandle, NULL);
129 alignment = args->alignment;
130 size = args->sizeDim0;
131 if( args->sizeDim1 ) {
132 size *= args->sizeDim1;
133 }
135 DEBUG("alloc: %dx%d (%d)(%d)", args->sizeDim0, args->sizeDim1, size, alignment);
137 ptr = allocRes(size, alignment);
138 if( !ptr ) {
139 ERROR("could not allocate buffer: %dx%d (%d)",
140 args->sizeDim0, args->sizeDim1, size);
141 goto fail;
142 }
144 handle = allocRes(sizeof(*handle), MIN_ALIGNMENT);
145 if( !handle ) {
146 ERROR("could not allocate handle");
147 goto fail;
148 }
150 handle->ires.getStaticProperties = getStaticProperties;
151 handle->ires.persistent = IRES_PERSISTENT;
152 handle->memoryBaseAddress = ptr; /* MMU set up for 0x0 offset */
153 handle->systemSpaceBaseAddress = ptr;
154 handle->isTiledMemory = FALSE;
155 handle->accessUnit = IRES_TILEDMEMORY_RAW;
156 handle->tilerBaseAddress = NULL;
158 DEBUG("allocation succeeded: %dx%d", args->sizeDim0, args->sizeDim1);
160 return ((IRES_Handle)handle);
162 fail:
163 if( ptr ) {
164 freeRes(ptr, size);
165 }
166 if( handle ) {
167 freeRes(handle, sizeof(*handle));
168 }
169 *status = IRES_ENOMEM;
170 return (NULL);
171 }
173 static IRES_Status freeHandles(IALG_Handle algHandle,
174 IRES_Handle algResourceHandle,
175 IRES_ResourceDescriptor *resDesc,
176 Int scratchGroupId)
177 {
178 IRES_TILEDMEMORY_ProtocolArgs *args =
179 (IRES_TILEDMEMORY_ProtocolArgs *)resDesc->protocolArgs;
180 IRES_TILEDMEMORY_Handle handle =
181 (IRES_TILEDMEMORY_Handle)algResourceHandle;
182 int size;
184 Assert_isTrue(args, NULL);
185 Assert_isTrue(handle, NULL);
187 size = args->sizeDim0;
188 if( args->sizeDim1 ) {
189 size *= args->sizeDim1;
190 }
192 DEBUG("free: %dx%d (%d)", args->sizeDim0, args->sizeDim1, size);
194 freeRes(handle->memoryBaseAddress, size);
195 freeRes(handle, sizeof(*handle));
197 return (IRES_OK);
198 }
200 IRESMAN_Fxns IRESMAN_TILEDMEMORY =
201 {
202 getProtocolName,
203 getProtocolRevision,
204 myinit,
205 myexit,
206 getHandles,
207 freeHandles,
208 };