-
Notifications
You must be signed in to change notification settings - Fork 3
/
ion.c
62 lines (51 loc) · 1.38 KB
/
ion.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
/*
* 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 ion_alloc(int fd, int len, void **hdl)
{
struct ion_allocation_data req = {
.len = len,
#ifdef NEW_ION
.heap_mask = ION_HEAP(ION_CP_MM_HEAP_ID),
.flags = ION_SECURE | ION_FORCE_CONTIGUOUS,
#else
.flags = ION_SECURE | ION_FORCE_CONTIGUOUS | ION_HEAP(ION_CP_MM_HEAP_ID),
#endif
.align = len,
};
int ret;
ret = ioctl(fd, ION_IOC_ALLOC, &req);
if (ret)
return ret;
*hdl = req.handle;
return 0;
}
int ion_map(int fd, int len, void *hdl, uint32_t **ptr)
{
struct ion_fd_data req = {
.handle = hdl,
};
void *p;
int ret;
ret = ioctl(fd, ION_IOC_MAP, &req);
if (ret)
return ret;
p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, req.fd, 0);
if (p == MAP_FAILED)
return -1;
*ptr = p;
return req.fd;
}