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_DMA_H
16 #define ANDROID_INCLUDE_HARDWARE_GOLDFISH_DMA_H
17 
18 #include <errno.h>
19 #include <linux/ioctl.h>
20 #include <linux/types.h>
21 #include <sys/cdefs.h>
22 #include <fcntl.h>
23 #include <stdlib.h>
24 
25 /* There is an ioctl associated with goldfish dma driver.
26  * Make it conflict with ioctls that are not likely to be used
27  * in the emulator.
28  * 'G'	00-3F	drivers/misc/sgi-gru/grulib.h	conflict!
29  * 'G'	00-0F	linux/gigaset_dev.h	conflict!
30  */
31 #define GOLDFISH_DMA_IOC_MAGIC	'G'
32 
33 #define GOLDFISH_DMA_IOC_LOCK			_IOWR(GOLDFISH_DMA_IOC_MAGIC, 0, struct goldfish_dma_ioctl_info)
34 #define GOLDFISH_DMA_IOC_UNLOCK			_IOWR(GOLDFISH_DMA_IOC_MAGIC, 1, struct goldfish_dma_ioctl_info)
35 #define GOLDFISH_DMA_IOC_GETOFF			_IOWR(GOLDFISH_DMA_IOC_MAGIC, 2, struct goldfish_dma_ioctl_info)
36 #define GOLDFISH_DMA_IOC_CREATE_REGION	_IOWR(GOLDFISH_DMA_IOC_MAGIC, 3, struct goldfish_dma_ioctl_info)
37 
38 struct goldfish_dma_ioctl_info {
39     uint64_t phys_begin;
40     uint64_t size;
41 };
42 
43 // userspace interface
44 struct goldfish_dma_context {
45     void* mapped;
46 #if !defined(__LP64__)
47     int mapped_padding;
48 #endif
49     uint64_t sz; // size of reservation
50     int fd;
51     int fd_padding;
52 };
53 
54 int goldfish_dma_lock(struct goldfish_dma_context* cxt);
55 int goldfish_dma_unlock(struct goldfish_dma_context* cxt);
56 int goldfish_dma_create_region(uint32_t sz, struct goldfish_dma_context* res);
57 
58 void* goldfish_dma_map(struct goldfish_dma_context* cxt);
59 int goldfish_dma_unmap(struct goldfish_dma_context* cxt);
60 
61 void goldfish_dma_write(struct goldfish_dma_context* cxt,
62                         void* to_write,
63                         uint32_t sz);
64 
65 void goldfish_dma_free(goldfish_dma_context* cxt);
66 uint64_t goldfish_dma_guest_paddr(struct goldfish_dma_context* cxt);
67 
68 #endif
69