2 Copyright © 2013-2017, The AROS Development Team. All rights reserved.
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>
23 #include <utility/utility.h>
24 #include <aros/symbolsets.h>
26 #include "vc4gfx_hidd.h"
27 #include "vc4gfx_hardware.h"
29 #include LC_LIBDEFS_FILE
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
));
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
)
62 xsd
->vcsd_MBoxMessage
[0] = AROS_LE2LONG(9 * 4);
63 xsd
->vcsd_MBoxMessage
[1] = AROS_LE2LONG(VCTAG_REQ
);
64 xsd
->vcsd_MBoxMessage
[2] = AROS_LE2LONG(VCTAG_ALLOCMEM
);
65 xsd
->vcsd_MBoxMessage
[3] = AROS_LE2LONG(4 * 3);
66 xsd
->vcsd_MBoxMessage
[4] = AROS_LE2LONG(size
);
67 xsd
->vcsd_MBoxMessage
[5] = AROS_LE2LONG(gpumemalign
);
68 xsd
->vcsd_MBoxMessage
[6] = AROS_LE2LONG(gpumemflags
);
70 xsd
->vcsd_MBoxMessage
[7] = 0;
72 xsd
->vcsd_MBoxMessage
[8] = 0; // terminate tag
74 MBoxWrite((void*)VCMB_BASE
, VCMB_PROPCHAN
, xsd
->vcsd_MBoxMessage
);
75 if (MBoxRead((void*)VCMB_BASE
, VCMB_PROPCHAN
) == xsd
->vcsd_MBoxMessage
)
77 D(bug("[VideoCoreGfx] %s: Allocated %d bytes, memhandle @ 0x%p\n", __PRETTY_FUNCTION__
,
78 AROS_LE2LONG(xsd
->vcsd_MBoxMessage
[4]), AROS_LE2LONG(xsd
->vcsd_MBoxMessage
[7])));
80 mhe
->mhe_MemHeader
.mh_Free
-= size
;
82 return (void*)(AROS_LE2LONG(xsd
->vcsd_MBoxMessage
[7]) & 0x3fffffff);
88 Lock the gpu memory represented by the memhandle,
89 and return a physical pointer to it..
91 void *FNAME_SUPPORT(LockMem
)(struct MemHeaderExt
*mhe
, void *memhandle
)
93 struct VideoCoreGfx_staticdata
*xsd
= (APTR
)mhe
->mhe_UserData
;
95 D(bug("[VideoCoreGfx] %s(memhandle @ 0x%p)\n", __PRETTY_FUNCTION__
, memhandle
));
97 xsd
->vcsd_MBoxMessage
[0] = AROS_LE2LONG(7 * 4);
98 xsd
->vcsd_MBoxMessage
[1] = AROS_LE2LONG(VCTAG_REQ
);
99 xsd
->vcsd_MBoxMessage
[2] = AROS_LE2LONG(VCTAG_LOCKMEM
);
100 xsd
->vcsd_MBoxMessage
[3] = AROS_LE2LONG(4);
101 xsd
->vcsd_MBoxMessage
[4] = AROS_LE2LONG((ULONG
)memhandle
);
103 xsd
->vcsd_MBoxMessage
[5] = 0;
105 xsd
->vcsd_MBoxMessage
[6] = 0; // terminate tag
107 MBoxWrite((void*)VCMB_BASE
, VCMB_PROPCHAN
, xsd
->vcsd_MBoxMessage
);
108 if (MBoxRead((void*)VCMB_BASE
, VCMB_PROPCHAN
) == xsd
->vcsd_MBoxMessage
)
110 D(bug("[VideoCoreGfx] %s: Memory locked @ 0x%p\n", __PRETTY_FUNCTION__
, AROS_LE2LONG(xsd
->vcsd_MBoxMessage
[5])));
111 return (void*)(AROS_LE2LONG(xsd
->vcsd_MBoxMessage
[5]) & 0x3fffffff);
117 Unlock the gpu memory represented by the memhandle.
119 void *FNAME_SUPPORT(UnLockMem
)(struct MemHeaderExt
*mhe
, void *memhandle
)
121 struct VideoCoreGfx_staticdata
*xsd
= (APTR
)mhe
->mhe_UserData
;
123 D(bug("[VideoCoreGfx] %s(memhandle @ 0x%p)\n", __PRETTY_FUNCTION__
, memhandle
));
125 xsd
->vcsd_MBoxMessage
[0] = AROS_LE2LONG(7 * 4);
126 xsd
->vcsd_MBoxMessage
[1] = AROS_LE2LONG(VCTAG_REQ
);
127 xsd
->vcsd_MBoxMessage
[2] = AROS_LE2LONG(VCTAG_UNLOCKMEM
);
128 xsd
->vcsd_MBoxMessage
[3] = AROS_LE2LONG(4);
129 xsd
->vcsd_MBoxMessage
[4] = AROS_LE2LONG((ULONG
)memhandle
);
131 xsd
->vcsd_MBoxMessage
[5] = 0;
133 xsd
->vcsd_MBoxMessage
[6] = 0; // terminate tag
135 MBoxWrite((void*)VCMB_BASE
, VCMB_PROPCHAN
, xsd
->vcsd_MBoxMessage
);
136 if (MBoxRead((void*)VCMB_BASE
, VCMB_PROPCHAN
) == xsd
->vcsd_MBoxMessage
)
138 D(bug("[VideoCoreGfx] %s: Memory unlocked [status %08x]\n", __PRETTY_FUNCTION__
, AROS_LE2LONG(xsd
->vcsd_MBoxMessage
[5])));
139 return (void*)AROS_LE2LONG(xsd
->vcsd_MBoxMessage
[5]);
144 void mh_Free(struct MemHeaderExt
*mhe
, APTR mem
, IPTR size
)
146 D(bug("[VideoCoreGfx] %s(0x%p)\n", __PRETTY_FUNCTION__
, mem
));
150 Frees the gpu memory associated with the handle.
152 void FNAME_SUPPORT(Free
)(struct MemHeaderExt
*mhe
, APTR memhandle
, IPTR size
)
154 struct VideoCoreGfx_staticdata
*xsd
= (APTR
)mhe
->mhe_UserData
;
156 D(bug("[VideoCoreGfx] %s(memhandle @ 0x%p)\n", __PRETTY_FUNCTION__
, memhandle
));
158 xsd
->vcsd_MBoxMessage
[0] = AROS_LE2LONG(7 * 4);
159 xsd
->vcsd_MBoxMessage
[1] = AROS_LE2LONG(VCTAG_REQ
);
160 xsd
->vcsd_MBoxMessage
[2] = AROS_LE2LONG(VCTAG_FREEMEM
);
161 xsd
->vcsd_MBoxMessage
[3] = AROS_LE2LONG(4);
162 xsd
->vcsd_MBoxMessage
[4] = AROS_LE2LONG((ULONG
)memhandle
);
164 xsd
->vcsd_MBoxMessage
[5] = 0;
166 xsd
->vcsd_MBoxMessage
[6] = 0; // terminate tag
168 MBoxWrite((void*)VCMB_BASE
, VCMB_PROPCHAN
, xsd
->vcsd_MBoxMessage
);
169 if (MBoxRead((void*)VCMB_BASE
, VCMB_PROPCHAN
) == xsd
->vcsd_MBoxMessage
)
171 mhe
->mhe_MemHeader
.mh_Free
+= size
;
173 D(bug("[VideoCoreGfx] %s: Memory freed [status %08x]\n", __PRETTY_FUNCTION__
, AROS_LE2LONG(xsd
->vcsd_MBoxMessage
[5])));
177 void *mh_AllocAbs(struct MemHeaderExt
*mhe
, IPTR size
, APTR mem
)
179 D(bug("[VideoCoreGfx] %s(0x%p, %d bytes)\n", __PRETTY_FUNCTION__
, mem
, size
));
184 void *mh_ReAlloc(struct MemHeaderExt
*mhe
, APTR old
, IPTR size
)
186 D(bug("[VideoCoreGfx] %s(0x%p, %d bytes)\n", __PRETTY_FUNCTION__
, old
, size
));
191 IPTR
mh_Avail(struct MemHeaderExt
*mhe
, ULONG flags
)
193 //struct VideoCoreGfx_staticdata *xsd = (APTR)mhe->mhe_UserData;
195 D(bug("[VideoCoreGfx] %s(0x%08x)\n", __PRETTY_FUNCTION__
, flags
));
197 return mhe
->mhe_MemHeader
.mh_Free
;
200 int FNAME_SUPPORT(InitMem
)(void *memstart
, int memlength
, struct VideoCoreGfxBase
*VideoCoreGfxBase
)
202 struct VideoCoreGfx_staticdata
*xsd
= &LIBBASE
->vsd
;
203 // struct MemChunk *mc = memstart;
205 InitSemaphore(&xsd
->vcsd_GPUMemLock
);
207 bug("[VideoCoreGfx] VideoCore GPU Memory @ 0x%p [%dKB]\n", memstart
, memlength
>> 10);
209 xsd
->vcsd_GPUMemManage
.mhe_MemHeader
.mh_Node
.ln_Type
= NT_MEMORY
;
210 xsd
->vcsd_GPUMemManage
.mhe_MemHeader
.mh_Node
.ln_Name
= "VideoCore GPU Memory";
211 xsd
->vcsd_GPUMemManage
.mhe_MemHeader
.mh_Node
.ln_Pri
= -128;
212 xsd
->vcsd_GPUMemManage
.mhe_MemHeader
.mh_Attributes
= MEMF_CHIP
| MEMF_MANAGED
| MEMF_PUBLIC
;
213 // xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_First = mc;
214 xsd
->vcsd_GPUMemManage
.mhe_MemHeader
.mh_First
= NULL
;
215 xsd
->vcsd_GPUMemManage
.mhe_MemHeader
.mh_Lower
= (APTR
)memstart
;
216 xsd
->vcsd_GPUMemManage
.mhe_MemHeader
.mh_Free
= memlength
;
217 xsd
->vcsd_GPUMemManage
.mhe_MemHeader
.mh_Upper
= (APTR
)(xsd
->vcsd_GPUMemManage
.mhe_MemHeader
.mh_Free
+ (IPTR
)memstart
);
219 xsd
->vcsd_GPUMemManage
.mhe_UserData
= xsd
;
221 xsd
->vcsd_GPUMemManage
.mhe_Alloc
= mh_Alloc
;
222 xsd
->vcsd_GPUMemManage
.mhe_Free
= mh_Free
;
223 xsd
->vcsd_GPUMemManage
.mhe_AllocAbs
= mh_AllocAbs
;
224 xsd
->vcsd_GPUMemManage
.mhe_ReAlloc
= mh_ReAlloc
;
225 xsd
->vcsd_GPUMemManage
.mhe_Avail
= mh_Avail
;
227 // mc->mc_Next = NULL;
228 // mc->mc_Bytes = xsd->vcsd_GPUMemManage.mhe_MemHeader.mh_Free;
231 AddTail(&SysBase
->MemList
, (struct Node
*)&xsd
->vcsd_GPUMemManage
);
234 bug("[VideoCoreGfx] Memory Manager Initialised\n");