• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 UAPI_GOLDFISH_DMA_H
16 #define UAPI_GOLDFISH_DMA_H
17 
18 #include <linux/types.h>
19 
20 /* GOLDFISH DMA
21  *
22  * Goldfish DMA is an extension to the pipe device
23  * and is designed to facilitate high-speed RAM->RAM
24  * transfers from guest to host.
25  *
26  * Interface (guest side):
27  *
28  * The guest user calls goldfish_dma_alloc (ioctls)
29  * and then mmap() on a goldfish pipe fd,
30  * which means that it wants high-speed access to
31  * host-visible memory.
32  *
33  * The guest can then write into the pointer
34  * returned by mmap(), and these writes
35  * become immediately visible on the host without BQL
36  * or otherweise context switching.
37  *
38  * dma_alloc_coherent() is used to obtain contiguous
39  * physical memory regions, and we allocate and interact
40  * with this region on both guest and host through
41  * the following ioctls:
42  *
43  * - LOCK: lock the region for data access.
44  * - UNLOCK: unlock the region. This may also be done from the host
45  *   through the WAKE_ON_UNLOCK_DMA procedure.
46  * - CREATE_REGION: initialize size info for a dma region.
47  * - GETOFF: send physical address to guest drivers.
48  * - (UN)MAPHOST: uses goldfish_pipe_cmd to tell the host to
49  * (un)map to the guest physical address associated
50  * with the current dma context. This makes the physically
51  * contiguous memory (in)visible to the host.
52  *
53  * Guest userspace obtains a pointer to the DMA memory
54  * through mmap(), which also lazily allocates the memory
55  * with dma_alloc_coherent. (On last pipe close(), the region is freed).
56  * The mmaped() region can handle very high bandwidth
57  * transfers, and pipe operations can be used at the same
58  * time to handle synchronization and command communication.
59  */
60 
61 #define GOLDFISH_DMA_BUFFER_SIZE (32 * 1024 * 1024)
62 
63 struct goldfish_dma_ioctl_info {
64 	__u64 phys_begin;
65 	__u64 size;
66 };
67 
68 /* There is an ioctl associated with goldfish dma driver.
69  * Make it conflict with ioctls that are not likely to be used
70  * in the emulator.
71  * 'G'	00-3F	drivers/misc/sgi-gru/grulib.h	conflict!
72  * 'G'	00-0F	linux/gigaset_dev.h	conflict!
73  */
74 #define GOLDFISH_DMA_IOC_MAGIC	'G'
75 #define GOLDFISH_DMA_IOC_OP(OP)	_IOWR(GOLDFISH_DMA_IOC_MAGIC, OP, \
76 				struct goldfish_dma_ioctl_info)
77 
78 #define GOLDFISH_DMA_IOC_LOCK		GOLDFISH_DMA_IOC_OP(0)
79 #define GOLDFISH_DMA_IOC_UNLOCK		GOLDFISH_DMA_IOC_OP(1)
80 #define GOLDFISH_DMA_IOC_GETOFF		GOLDFISH_DMA_IOC_OP(2)
81 #define GOLDFISH_DMA_IOC_CREATE_REGION	GOLDFISH_DMA_IOC_OP(3)
82 
83 #endif /* UAPI_GOLDFISH_DMA_H */
84