wip.
[AROS.git] / arch / arm-native / soc / broadcom / 2708 / hidd / videocoregfx / videocoregfx_memory.c
blob9bf01dc2d15d8eec9cb892979c227fe138bae91c
1 /*
2 Copyright © 2013-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 1
7 #include <aros/debug.h>
9 #define __OOP_NOATTRBASES__
11 #include <proto/exec.h>
12 #include <proto/oop.h>
13 #include <proto/mbox.h>
14 #include <proto/kernel.h>
15 #include <proto/utility.h>
17 #include <exec/types.h>
18 #include <exec/lists.h>
19 #include <exec/memory.h>
20 #include <hidd/graphics.h>
21 #include <hidd/pci.h>
22 #include <oop/oop.h>
23 #include <utility/utility.h>
24 #include <aros/symbolsets.h>
26 #include "videocoregfx_class.h"
27 #include "videocoregfx_hardware.h"
29 #include LC_LIBDEFS_FILE
31 #ifdef MBoxBase
32 #undef MBoxBase
33 #endif
35 #define MBoxBase xsd->vcsd_MBoxBase
37 void *mh_Alloc(struct MemHeaderExt *mhe, IPTR size, ULONG *flags)
39 D(bug("[VideoCoreGfx] %s(%d bytes, 0x%08x)\n", __PRETTY_FUNCTION__, size, flags));
41 return NULL;
45 returns a handle on a block of gpu memory. you cannot directly access this
46 memory unless it is locked, since it may be moved around by the gpu.
48 void *FNAME_SUPPORT(Alloc)(struct MemHeaderExt *mhe, IPTR size, ULONG *flags)
50 struct VideoCoreGfx_staticdata *xsd = (APTR)mhe->mhe_UserData;
51 ULONG gpumemflags = VCMEM_NORMAL, gpumemalign = 0;
53 D(bug("[VideoCoreGfx] %s(%d bytes, 0x%08x)\n", __PRETTY_FUNCTION__, size, flags));
55 if (!(*flags & MEMF_PUBLIC))
56 gpumemflags = VCMEM_L1NONALLOCATING | VCMEM_NOINIT | VCMEM_LAZYLOCK;
57 if (*flags & MEMF_CLEAR)
58 gpumemflags |= VCMEM_ZERO;
59 if (*flags & MEMF_HWALIGNED)
60 gpumemalign = 4096;
62 xsd->vcsd_MBoxMessage[0] = 9 * 4;
63 xsd->vcsd_MBoxMessage[1] = VCTAG_REQ;
64 xsd->vcsd_MBoxMessage[2] = VCTAG_ALLOCMEM;
65 xsd->vcsd_MBoxMessage[3] = 4 * 3;
66 xsd->vcsd_MBoxMessage[4] = size;
67 xsd->vcsd_MBoxMessage[5] = gpumemalign;
68 xsd->vcsd_MBoxMessage[6] = gpumemflags;
70 xsd->vcsd_MBoxMessage[7] = 0;
72 xsd->vcsd_MBoxMessage[8] = 0; // terminate tag
74 MBoxWrite(VCMB_BASE, VCMB_PROPCHAN, xsd->vcsd_MBoxMessage);
75 if (MBoxRead(VCMB_BASE, VCMB_PROPCHAN) == xsd->vcsd_MBoxMessage)
77 D(bug("[VideoCoreGfx] %s: Allocated %d bytes, memhandle @ 0x%p\n", __PRETTY_FUNCTION__, xsd->vcsd_MBoxMessage[4], xsd->vcsd_MBoxMessage[7]));
79 mhe->mhe_MemHeader.mh_Free -= size;
81 return xsd->vcsd_MBoxMessage[7];
83 return NULL;
87 Lock the gpu memory represented by the memhandle,
88 and return a physical pointer to it..
90 void *FNAME_SUPPORT(LockMem)(struct MemHeaderExt *mhe, void *memhandle)
92 struct VideoCoreGfx_staticdata *xsd = (APTR)mhe->mhe_UserData;
94 D(bug("[VideoCoreGfx] %s(memhandle @ 0x%p)\n", __PRETTY_FUNCTION__, memhandle));
96 xsd->vcsd_MBoxMessage[0] = 7 * 4;
97 xsd->vcsd_MBoxMessage[1] = VCTAG_REQ;
98 xsd->vcsd_MBoxMessage[2] = VCTAG_LOCKMEM;
99 xsd->vcsd_MBoxMessage[3] = 4;
100 xsd->vcsd_MBoxMessage[4] = memhandle;
102 xsd->vcsd_MBoxMessage[5] = 0;
104 xsd->vcsd_MBoxMessage[6] = 0; // terminate tag
106 MBoxWrite(VCMB_BASE, VCMB_PROPCHAN, xsd->vcsd_MBoxMessage);
107 if (MBoxRead(VCMB_BASE, VCMB_PROPCHAN) == xsd->vcsd_MBoxMessage)
109 D(bug("[VideoCoreGfx] %s: Memory locked @ 0x%p\n", __PRETTY_FUNCTION__, xsd->vcsd_MBoxMessage[5]));
110 return xsd->vcsd_MBoxMessage[5];
112 return NULL;
116 Unlock the gpu memory represented by the memhandle.
118 void *FNAME_SUPPORT(UnLockMem)(struct MemHeaderExt *mhe, void *memhandle)
120 struct VideoCoreGfx_staticdata *xsd = (APTR)mhe->mhe_UserData;
122 D(bug("[VideoCoreGfx] %s(memhandle @ 0x%p)\n", __PRETTY_FUNCTION__, memhandle));
124 xsd->vcsd_MBoxMessage[0] = 7 * 4;
125 xsd->vcsd_MBoxMessage[1] = VCTAG_REQ;
126 xsd->vcsd_MBoxMessage[2] = VCTAG_UNLOCKMEM;
127 xsd->vcsd_MBoxMessage[3] = 4;
128 xsd->vcsd_MBoxMessage[4] = memhandle;
130 xsd->vcsd_MBoxMessage[5] = 0;
132 xsd->vcsd_MBoxMessage[6] = 0; // terminate tag
134 MBoxWrite(VCMB_BASE, VCMB_PROPCHAN, xsd->vcsd_MBoxMessage);
135 if (MBoxRead(VCMB_BASE, VCMB_PROPCHAN) == xsd->vcsd_MBoxMessage)
137 D(bug("[VideoCoreGfx] %s: Memory unlocked [status %08x]\n", __PRETTY_FUNCTION__, xsd->vcsd_MBoxMessage[5]));
138 return xsd->vcsd_MBoxMessage[5];
140 return NULL;
143 void mh_Free(struct MemHeaderExt *mhe, APTR mem, IPTR size)
145 D(bug("[VideoCoreGfx] %s(0x%p)\n", __PRETTY_FUNCTION__, mem));
149 Frees the gpu memory associated with the handle.
151 void FNAME_SUPPORT(Free)(struct MemHeaderExt *mhe, APTR memhandle, IPTR size)
153 struct VideoCoreGfx_staticdata *xsd = (APTR)mhe->mhe_UserData;
155 D(bug("[VideoCoreGfx] %s(memhandle @ 0x%p)\n", __PRETTY_FUNCTION__, memhandle));
157 xsd->vcsd_MBoxMessage[0] = 7 * 4;
158 xsd->vcsd_MBoxMessage[1] = VCTAG_REQ;
159 xsd->vcsd_MBoxMessage[2] = VCTAG_FREEMEM;
160 xsd->vcsd_MBoxMessage[3] = 4;
161 xsd->vcsd_MBoxMessage[4] = memhandle;
163 xsd->vcsd_MBoxMessage[5] = 0;
165 xsd->vcsd_MBoxMessage[6] = 0; // terminate tag
167 MBoxWrite(VCMB_BASE, VCMB_PROPCHAN, xsd->vcsd_MBoxMessage);
168 if (MBoxRead(VCMB_BASE, VCMB_PROPCHAN) == xsd->vcsd_MBoxMessage)
170 mhe->mhe_MemHeader.mh_Free += size;
172 D(bug("[VideoCoreGfx] %s: Memory freed [status %08x]\n", __PRETTY_FUNCTION__, xsd->vcsd_MBoxMessage[5]));
176 void *mh_AllocAbs(struct MemHeaderExt *mhe, IPTR size, APTR mem)
178 D(bug("[VideoCoreGfx] %s(0x%p, %d bytes)\n", __PRETTY_FUNCTION__, mem, size));
180 return NULL;
183 void *mh_ReAlloc(struct MemHeaderExt *mhe, APTR old, IPTR size)
185 D(bug("[VideoCoreGfx] %s(0x%p, %d bytes)\n", __PRETTY_FUNCTION__, old, size));
187 return NULL;
190 ULONG mh_Avail(struct MemHeaderExt *mhe, ULONG flags)
192 struct VideoCoreGfx_staticdata *xsd = (APTR)mhe->mhe_UserData;
194 D(bug("[VideoCoreGfx] %s(0x%08x)\n", __PRETTY_FUNCTION__, flags));
196 return mhe->mhe_MemHeader.mh_Free;
199 int FNAME_SUPPORT(InitMem)(void *memstart, int memlength, struct VideoCoreGfxBase *VideoCoreGfxBase)
201 struct VideoCoreGfx_staticdata *xsd = &LIBBASE->vsd;
202 // struct MemChunk *mc = memstart;
204 InitSemaphore(&xsd->vcsd_GPUMemLock);
206 bug("[VideoCoreGfx] VideoCore GPU Memory @ 0x%p [%dKB]\n", memstart, memlength >> 10);
208 xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Node.ln_Type = NT_MEMORY;
209 xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Node.ln_Name = "VideoCore GPU Memory";
210 xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Node.ln_Pri = -128;
211 xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Attributes = MEMF_CHIP | MEMF_MANAGED | MEMF_PUBLIC;
212 // xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_First = mc;
213 xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_First = NULL;
214 xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Lower = (APTR)memstart;
215 xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Free = memlength;
216 xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Upper = (APTR)(xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Free + (IPTR)memstart);
218 xsd->vcsd_GPUMemManage.mhe_UserData = xsd;
220 xsd->vcsd_GPUMemManage.mhe_Alloc = mh_Alloc;
221 xsd->vcsd_GPUMemManage.mhe_Free = mh_Free;
222 xsd->vcsd_GPUMemManage.mhe_AllocAbs = mh_AllocAbs;
223 xsd->vcsd_GPUMemManage.mhe_ReAlloc = mh_ReAlloc;
224 xsd->vcsd_GPUMemManage.mhe_Avail = mh_Avail;
226 // mc->mc_Next = NULL;
227 // mc->mc_Bytes = xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Free;
229 Disable();
230 AddTail(&SysBase->MemList, (struct Node *)&xsd->vcsd_GPUMemManage);
231 Enable();
233 bug("[VideoCoreGfx] Memory Manager Initialised\n");
235 return TRUE;