OSDN Git Service

b314f8d0d5bd885149e131c0bd6d366b70fa4270
[android-x86/device-generic-goldfish-opengl.git] / system / OpenglSystemCommon / goldfish_dma.h
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     int fd;
46     void* mapped;
47     uint64_t sz; // size of reservation
48 };
49
50 int goldfish_dma_lock(struct goldfish_dma_context* cxt);
51 int goldfish_dma_unlock(struct goldfish_dma_context* cxt);
52 int goldfish_dma_create_region(uint32_t sz, struct goldfish_dma_context* res);
53
54 void* goldfish_dma_map(struct goldfish_dma_context* cxt);
55 int goldfish_dma_unmap(struct goldfish_dma_context* cxt);
56
57 void goldfish_dma_write(struct goldfish_dma_context* cxt,
58                         void* to_write,
59                         uint32_t sz);
60
61 void goldfish_dma_free(goldfish_dma_context* cxt);
62 uint64_t goldfish_dma_guest_paddr(struct goldfish_dma_context* cxt);
63
64 #endif