forked from kjliew/qemu-3dfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmglvarry.c
94 lines (82 loc) · 2.59 KB
/
mglvarry.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* QEMU MESA GL Pass-Through
*
* Copyright (c) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library;
* if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu/osdep.h"
#include "mglfuncs.h"
#include "mglvarry.h"
typedef struct _vertArry {
uint32_t tagLo;
uint32_t tagHi;
uint8_t *ptr;
struct _vertArry *next;
} VERTARRY, * PVERTARRY;
static PVERTARRY vertexArry = NULL;
static void *LookupVertArry(PVERTARRY *pArry, uint32_t handle, uint32_t size)
{
PVERTARRY p = *pArry;
if (handle == 0)
return NULL;
while (p) {
if (((handle >= p->tagLo) && (handle < p->tagHi)) &&
((p->tagHi - handle) >= (size >> 1)))
break;
if (p->next == NULL)
break;
p = p->next;
}
if (p == NULL) {
p = g_new(VERTARRY, 1);
p->tagLo = (handle > size)? (handle - size):PAGE_SIZE;
p->tagHi = p->tagLo + (size << 1);
p->ptr = g_malloc(size << 1);
p->next = NULL;
fprintf(stderr, " alloc vaddr %08x-%08x from hndl %08x\n", p->tagLo, p->tagHi, handle);
*pArry = p;
}
else {
if (((handle >= p->tagLo) && (handle < p->tagHi)) &&
((p->tagHi - handle) >= (size >> 1))) { }
else {
p->next = g_new(VERTARRY, 1);
p = p->next;
p->tagLo = (handle > size)? (handle - size):PAGE_SIZE;
p->tagHi = p->tagLo + (size << 1);
p->ptr = g_malloc(size << 1);
fprintf(stderr, " alloc vaddr %08x-%08x from hndl %08x\n", p->tagLo, p->tagHi, handle);
p->next = NULL;
}
}
return p->ptr + (handle - p->tagLo);
}
static int FreeVertArry(PVERTARRY *pArry)
{
PVERTARRY p = *pArry;
int cnt = 0;
while (p) {
PVERTARRY next = p->next;
g_free(p->ptr);
g_free(p);
p = next;
cnt++;
}
*pArry = p;
return cnt;
}
void *LookupVertex(uint32_t handle, uint32_t size) { return LookupVertArry(&vertexArry, handle, size); }
int FreeVertex(void) { return FreeVertArry(&vertexArry); }