• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef HOST_BUILD
22 
goldfish_sync_open()23 static __inline__ int goldfish_sync_open() {
24     return 0;
25 }
26 
goldfish_sync_close(int)27 static __inline__ int goldfish_sync_close(int) {
28     return 0;
29 }
30 
goldfish_sync_queue_work(int,uint64_t,uint64_t,int *)31 static __inline__ int goldfish_sync_queue_work(int,
32                                                uint64_t,
33                                                uint64_t,
34                                                int*) {
35     return 0;
36 }
37 
goldfish_sync_signal(int goldfish_sync_fd)38 static __inline__ int goldfish_sync_signal(int goldfish_sync_fd) {
39     return 0;
40 }
41 
42 #else
43 
44 #include <errno.h>
45 #include <linux/ioctl.h>
46 #include <linux/types.h>
47 #include <sys/cdefs.h>
48 #include <sys/ioctl.h>
49 #include <sys/unistd.h>
50 #include <fcntl.h>
51 
52 // Make it conflict with ioctls that are not likely to be used
53 // in the emulator.
54 //
55 // '@'	00-0F	linux/radeonfb.h	conflict!
56 // '@'	00-0F	drivers/video/aty/aty128fb.c	conflict!
57 #define GOLDFISH_SYNC_IOC_MAGIC	'@'
58 
59 struct goldfish_sync_ioctl_info {
60     uint64_t host_glsync_handle_in;
61     uint64_t host_syncthread_handle_in;
62     int fence_fd_out;
63 };
64 
65 #define GOLDFISH_SYNC_IOC_QUEUE_WORK	_IOWR(GOLDFISH_SYNC_IOC_MAGIC, 0, struct goldfish_sync_ioctl_info)
66 #define GOLDFISH_SYNC_IOC_SIGNAL	_IOWR(GOLDFISH_SYNC_IOC_MAGIC, 1, struct goldfish_sync_ioctl_info)
67 
goldfish_sync_open()68 static __inline__ int goldfish_sync_open() {
69     return open("/dev/goldfish_sync", O_RDWR);
70 }
71 
goldfish_sync_close(int sync_fd)72 static __inline__ int goldfish_sync_close(int sync_fd) {
73     return close(sync_fd);
74 }
75 
76 static unsigned int sQueueWorkIoctlCmd = GOLDFISH_SYNC_IOC_QUEUE_WORK;
77 
78 // If we are running on a 64-bit kernel.
79 static unsigned int sQueueWorkIoctlCmd64Kernel = 0xc0184000;
80 
goldfish_sync_queue_work(int goldfish_sync_fd,uint64_t host_glsync,uint64_t host_thread,int * fd_out)81 static __inline__ int goldfish_sync_queue_work(int goldfish_sync_fd,
82                                                 uint64_t host_glsync,
83                                                 uint64_t host_thread,
84                                                 int* fd_out) {
85 
86     struct goldfish_sync_ioctl_info info;
87     int err;
88 
89     info.host_glsync_handle_in = host_glsync;
90     info.host_syncthread_handle_in = host_thread;
91     info.fence_fd_out = -1;
92 
93     err = ioctl(goldfish_sync_fd, sQueueWorkIoctlCmd, &info);
94 
95     if (err < 0 && errno == ENOTTY) {
96         sQueueWorkIoctlCmd = sQueueWorkIoctlCmd64Kernel;
97         err = ioctl(goldfish_sync_fd, sQueueWorkIoctlCmd, &info);
98         if (err < 0) {
99             sQueueWorkIoctlCmd = GOLDFISH_SYNC_IOC_QUEUE_WORK;
100         }
101     }
102 
103     if (fd_out) *fd_out = info.fence_fd_out;
104 
105     return err;
106 }
107 
goldfish_sync_signal(int goldfish_sync_fd)108 static __inline__ int goldfish_sync_signal(int goldfish_sync_fd) {
109     return ioctl(goldfish_sync_fd, GOLDFISH_SYNC_IOC_SIGNAL, 0);
110 }
111 
112 #endif // !HOST_BUILD
113 
114 #endif
115