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 #ifdef EMULATOR_OPENGL_POST_O
22 #include <sys/ioctl.h>
23 #include <sys/unistd.h>
24 #endif
25 #include <fcntl.h>
26
27 // Make it conflict with ioctls that are not likely to be used
28 // in the emulator.
29 //
30 // '@' 00-0F linux/radeonfb.h conflict!
31 // '@' 00-0F drivers/video/aty/aty128fb.c conflict!
32 #define GOLDFISH_SYNC_IOC_MAGIC '@'
33
34 struct goldfish_sync_ioctl_info {
35 uint64_t host_glsync_handle_in;
36 uint64_t host_syncthread_handle_in;
37 int fence_fd_out;
38 };
39
40 #define GOLDFISH_SYNC_IOC_QUEUE_WORK _IOWR(GOLDFISH_SYNC_IOC_MAGIC, 0, struct goldfish_sync_ioctl_info)
41
goldfish_sync_open()42 static __inline__ int goldfish_sync_open() {
43 return open("/dev/goldfish_sync", O_RDWR);
44 }
45
goldfish_sync_close(int sync_fd)46 static __inline__ int goldfish_sync_close(int sync_fd) {
47 return close(sync_fd);
48 }
49
50 static unsigned int sQueueWorkIoctlCmd = GOLDFISH_SYNC_IOC_QUEUE_WORK;
51
52 // If we are running on a 64-bit kernel.
53 static unsigned int sQueueWorkIoctlCmd64Kernel = 0xc0184000;
54
goldfish_sync_queue_work(int goldfish_sync_fd,uint64_t host_glsync,uint64_t host_thread,int * fd_out)55 static __inline__ int goldfish_sync_queue_work(int goldfish_sync_fd,
56 uint64_t host_glsync,
57 uint64_t host_thread,
58 int* fd_out) {
59
60 struct goldfish_sync_ioctl_info info;
61 int err;
62
63 info.host_glsync_handle_in = host_glsync;
64 info.host_syncthread_handle_in = host_thread;
65 info.fence_fd_out = -1;
66
67 err = ioctl(goldfish_sync_fd, sQueueWorkIoctlCmd, &info);
68
69 if (err < 0 && errno == ENOTTY) {
70 sQueueWorkIoctlCmd = sQueueWorkIoctlCmd64Kernel;
71 err = ioctl(goldfish_sync_fd, sQueueWorkIoctlCmd, &info);
72 if (err < 0) {
73 sQueueWorkIoctlCmd = GOLDFISH_SYNC_IOC_QUEUE_WORK;
74 }
75 }
76
77 if (fd_out) *fd_out = info.fence_fd_out;
78
79 return err;
80 }
81
82 #endif
83