1 // Copyright 2016 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef ANDROID_INCLUDE_HARDWARE_GOLDFISH_SYNC_H
16 #define ANDROID_INCLUDE_HARDWARE_GOLDFISH_SYNC_H
17
18 #define GOLDFISH_SYNC_VULKAN_SEMAPHORE_SYNC 0x00000001
19 #define GOLDFISH_SYNC_VULKAN_QSRI 0x00000002
20
21 #include <errno.h>
22 #include <linux/ioctl.h>
23 #include <linux/types.h>
24 #include <sys/cdefs.h>
25 #include <sys/ioctl.h>
26 #include <sys/unistd.h>
27 #include <fcntl.h>
28
29 // Make it conflict with ioctls that are not likely to be used
30 // in the emulator.
31 //
32 // '@' 00-0F linux/radeonfb.h conflict!
33 // '@' 00-0F drivers/video/aty/aty128fb.c conflict!
34 #define GOLDFISH_SYNC_IOC_MAGIC '@'
35
36 struct goldfish_sync_ioctl_info {
37 uint64_t host_glsync_handle_in;
38 uint64_t host_syncthread_handle_in;
39 int fence_fd_out;
40 };
41
42 #define GOLDFISH_SYNC_IOC_QUEUE_WORK _IOWR(GOLDFISH_SYNC_IOC_MAGIC, 0, struct goldfish_sync_ioctl_info)
43 #define GOLDFISH_SYNC_IOC_SIGNAL _IOWR(GOLDFISH_SYNC_IOC_MAGIC, 1, struct goldfish_sync_ioctl_info)
44
goldfish_sync_open()45 static __inline__ int goldfish_sync_open() {
46 return open("/dev/goldfish_sync", O_RDWR);
47 }
48
goldfish_sync_close(int sync_fd)49 static __inline__ int goldfish_sync_close(int sync_fd) {
50 return close(sync_fd);
51 }
52
53 static unsigned int sQueueWorkIoctlCmd = GOLDFISH_SYNC_IOC_QUEUE_WORK;
54
55 // If we are running on a 64-bit kernel.
56 static unsigned int sQueueWorkIoctlCmd64Kernel = 0xc0184000;
57
goldfish_sync_queue_work(int goldfish_sync_fd,uint64_t host_glsync,uint64_t host_thread,int * fd_out)58 static __inline__ int goldfish_sync_queue_work(int goldfish_sync_fd,
59 uint64_t host_glsync,
60 uint64_t host_thread,
61 int* fd_out) {
62
63 struct goldfish_sync_ioctl_info info;
64 int err;
65
66 info.host_glsync_handle_in = host_glsync;
67 info.host_syncthread_handle_in = host_thread;
68 info.fence_fd_out = -1;
69
70 err = ioctl(goldfish_sync_fd, sQueueWorkIoctlCmd, &info);
71
72 if (err < 0 && errno == ENOTTY) {
73 sQueueWorkIoctlCmd = sQueueWorkIoctlCmd64Kernel;
74 err = ioctl(goldfish_sync_fd, sQueueWorkIoctlCmd, &info);
75 if (err < 0) {
76 sQueueWorkIoctlCmd = GOLDFISH_SYNC_IOC_QUEUE_WORK;
77 }
78 }
79
80 if (fd_out) *fd_out = info.fence_fd_out;
81
82 return err;
83 }
84
goldfish_sync_signal(int goldfish_sync_fd)85 static __inline__ int goldfish_sync_signal(int goldfish_sync_fd) {
86 return ioctl(goldfish_sync_fd, GOLDFISH_SYNC_IOC_SIGNAL, 0);
87 }
88
89 #endif
90