blob: 6cd1b63be8c907a4d2279a6e8f7ce63a4f1de98f [file] [log] [blame]
Yurii Zubrytskyif9101242016-07-29 10:51:46 -07001/*
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/goldfish.h>
29#include <linux/dma-mapping.h>
30#include <linux/mm.h>
31#include <linux/acpi.h>
32
33
34/* Initialize the legacy version of the pipe device driver */
35int goldfish_pipe_device_init_v1(struct platform_device *pdev);
36
37/* Deinitialize the legacy version of the pipe device driver */
38void goldfish_pipe_device_deinit_v1(struct platform_device *pdev);
39
40/* Forward declarations for the device struct */
41struct goldfish_pipe;
42struct goldfish_pipe_device_buffers;
43
44/* The global driver data. Holds a reference to the i/o page used to
45 * communicate with the emulator, and a wake queue for blocked tasks
46 * waiting to be awoken.
47 */
48struct goldfish_pipe_dev {
49 /*
50 * Global device spinlock. Protects the following members:
51 * - pipes, pipes_capacity
52 * - [*pipes, *pipes + pipes_capacity) - array data
53 * - first_signalled_pipe,
54 * goldfish_pipe::prev_signalled,
55 * goldfish_pipe::next_signalled,
56 * goldfish_pipe::signalled_flags - all singnalled-related fields,
57 * in all allocated pipes
58 * - open_command_params - PIPE_CMD_OPEN-related buffers
59 *
60 * It looks like a lot of different fields, but the trick is that the only
61 * operation that happens often is the signalled pipes array manipulation.
62 * That's why it's OK for now to keep the rest of the fields under the same
63 * lock. If we notice too much contention because of PIPE_CMD_OPEN,
64 * then we should add a separate lock there.
65 */
66 spinlock_t lock;
67
68 /*
69 * Array of the pipes of |pipes_capacity| elements,
70 * indexed by goldfish_pipe::id
71 */
72 struct goldfish_pipe **pipes;
73 u32 pipes_capacity;
74
75 /* Pointers to the buffers host uses for interaction with this driver */
76 struct goldfish_pipe_dev_buffers *buffers;
77
78 /* Head of a doubly linked list of signalled pipes */
79 struct goldfish_pipe *first_signalled_pipe;
80
81 /* Some device-specific data */
82 int irq;
83 int version;
84 unsigned char __iomem *base;
85
86 /* v1-specific access parameters */
87 struct access_params *aps;
88};
89
90extern struct goldfish_pipe_dev pipe_dev[1];
91
92#endif /* GOLDFISH_PIPE_H */