1 /*
2 * Copyright (C) 2016 Google, Inc.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15 #ifndef ANDROID_INCLUDE_HARDWARE_GOLDFISH_SYNC_H
16 #define ANDROID_INCLUDE_HARDWARE_GOLDFISH_SYNC_H
17
18 #include <linux/ioctl.h>
19 #include <linux/types.h>
20 #include <sys/cdefs.h>
21 #include <fcntl.h>
22
23 // Make it conflict with ioctls that are not likely to be used
24 // in the emulator.
25 //
26 // '@' 00-0F linux/radeonfb.h conflict!
27 // '@' 00-0F drivers/video/aty/aty128fb.c conflict!
28 #define GOLDFISH_SYNC_IOC_MAGIC '@'
29
30 struct goldfish_sync_ioctl_info {
31 uint64_t host_glsync_handle_in;
32 uint64_t host_syncthread_handle_in;
33 int fence_fd_out;
34 };
35
36 #define GOLDFISH_SYNC_IOC_QUEUE_WORK _IOWR(GOLDFISH_SYNC_IOC_MAGIC, 0, struct goldfish_sync_ioctl_info)
37
goldfish_sync_open()38 static __inline__ int goldfish_sync_open() {
39 return open("/dev/goldfish_sync", O_RDWR);
40 }
41
goldfish_sync_close(int sync_fd)42 static __inline__ int goldfish_sync_close(int sync_fd) {
43 return close(sync_fd);
44 }
45
goldfish_sync_queue_work(int goldfish_sync_fd,uint64_t host_glsync,uint64_t host_thread,int * fd_out)46 static __inline__ int goldfish_sync_queue_work(int goldfish_sync_fd,
47 uint64_t host_glsync,
48 uint64_t host_thread,
49 int* fd_out) {
50
51 struct goldfish_sync_ioctl_info info;
52 int err;
53
54 info.host_glsync_handle_in = host_glsync;
55 info.host_syncthread_handle_in = host_thread;
56 info.fence_fd_out = -1;
57
58 err = ioctl(goldfish_sync_fd, GOLDFISH_SYNC_IOC_QUEUE_WORK, &info);
59
60 if (fd_out) *fd_out = info.fence_fd_out;
61
62 return err;
63 }
64
65 #endif
66