• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef GOLDFISH_PIPE_H
15 #define GOLDFISH_PIPE_H
16 
17 #include <linux/module.h>
18 #include <linux/interrupt.h>
19 #include <linux/kernel.h>
20 #include <linux/spinlock.h>
21 #include <linux/miscdevice.h>
22 #include <linux/platform_device.h>
23 #include <linux/poll.h>
24 #include <linux/sched.h>
25 #include <linux/bitops.h>
26 #include <linux/slab.h>
27 #include <linux/io.h>
28 #include <linux/mm.h>
29 #include <linux/acpi.h>
30 
31 
32 /* Initialize the legacy version of the pipe device driver */
33 int goldfish_pipe_device_init_v1(struct platform_device *pdev);
34 
35 /* Deinitialize the legacy version of the pipe device driver */
36 void goldfish_pipe_device_deinit_v1(struct platform_device *pdev);
37 
38 /* Forward declarations for the device struct */
39 struct goldfish_pipe;
40 struct goldfish_pipe_device_buffers;
41 
42 /* The global driver data. Holds a reference to the i/o page used to
43  * communicate with the emulator, and a wake queue for blocked tasks
44  * waiting to be awoken.
45  */
46 struct goldfish_pipe_dev {
47 	/*
48 	 * Global device spinlock. Protects the following members:
49 	 *  - pipes, pipes_capacity
50 	 *  - [*pipes, *pipes + pipes_capacity) - array data
51 	 *  - first_signalled_pipe,
52 	 *      goldfish_pipe::prev_signalled,
53 	 *      goldfish_pipe::next_signalled,
54 	 *      goldfish_pipe::signalled_flags - all singnalled-related fields,
55 	 *                                       in all allocated pipes
56 	 *  - open_command_params - PIPE_CMD_OPEN-related buffers
57 	 *
58 	 * It looks like a lot of different fields, but the trick is that the only
59 	 * operation that happens often is the signalled pipes array manipulation.
60 	 * That's why it's OK for now to keep the rest of the fields under the same
61 	 * lock. If we notice too much contention because of PIPE_CMD_OPEN,
62 	 * then we should add a separate lock there.
63 	 */
64 	spinlock_t lock;
65 
66 	/*
67 	 * Array of the pipes of |pipes_capacity| elements,
68 	 * indexed by goldfish_pipe::id
69 	 */
70 	struct goldfish_pipe **pipes;
71 	u32 pipes_capacity;
72 
73 	/* Pointers to the buffers host uses for interaction with this driver */
74 	struct goldfish_pipe_dev_buffers *buffers;
75 
76 	/* Head of a doubly linked list of signalled pipes */
77 	struct goldfish_pipe *first_signalled_pipe;
78 
79 	/* Some device-specific data */
80 	int irq;
81 	int version;
82 	unsigned char __iomem *base;
83 
84 	/* v1-specific access parameters */
85 	struct access_params *aps;
86 
87 	/* DMA info */
88 	u64 dma_alloc_total;
89 
90 	/* ptr to platform device's device struct */
91 	struct device *pdev_dev;
92 };
93 
94 extern struct goldfish_pipe_dev goldfish_pipe_dev[1];
95 
96 #endif /* GOLDFISH_PIPE_H */
97