-
Notifications
You must be signed in to change notification settings - Fork 3
/
kgsl.c
100 lines (82 loc) · 2.17 KB
/
kgsl.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
94
95
96
97
98
99
100
/*
* Copyright © 2014 Rob Clark <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "kilroy.h"
int kgsl_map(int fd, int buf_fd, int len, uint32_t *gpuaddr)
{
struct kgsl_map_user_mem req = {
.fd = buf_fd,
.len = len,
.memtype = KGSL_USER_MEM_TYPE_ION,
};
void *p;
int ret;
ret = ioctl(fd, IOCTL_KGSL_MAP_USER_MEM, &req);
if (ret)
return ret;
*gpuaddr = req.gpuaddr;
return 0;
}
int kgsl_alloc(int fd, int size, uint32_t **ptr, uint32_t *gpuaddr)
{
struct kgsl_gpumem_alloc req = {
.size = size,
.flags = 0,
};
void *p;
int ret;
ret = ioctl(fd, IOCTL_KGSL_GPUMEM_ALLOC, &req);
if (ret)
return ret;
p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, req.gpuaddr);
if (p == MAP_FAILED)
return -1;
*gpuaddr = req.gpuaddr;
*ptr = p;
return 0;
}
int kgsl_ctx_create(int fd, uint32_t *ctx_id)
{
struct kgsl_drawctxt_create req = {
.flags = 0x001010d2,
};
int ret;
ret = ioctl(fd, IOCTL_KGSL_DRAWCTXT_CREATE, &req);
if (ret)
return ret;
*ctx_id = req.drawctxt_id;
return 0;
}
int kgsl_issueibcmds(int fd, uint32_t ctx_id, uint32_t *ibaddrs,
uint32_t *ibsizes, uint32_t ibaddrs_count)
{
struct kgsl_ibdesc ibdesc[MAX_IBS];
struct kgsl_ringbuffer_issueibcmds req = {
.drawctxt_id = ctx_id,
.ibdesc_addr = (unsigned long)&ibdesc,
.numibs = ibaddrs_count,
.flags = KGSL_CONTEXT_SUBMIT_IB_LIST,
.timestamp = 1,
};
uint32_t i;
for (i = 0; i < ibaddrs_count; i++) {
ibdesc[i].ctrl = 0;
ibdesc[i].hostptr = NULL;
ibdesc[i].gpuaddr = ibaddrs[i];
ibdesc[i].sizedwords = ibsizes[i];
}
return ioctl(fd, IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS, &req);
}