xref: /openbmc/linux/drivers/platform/goldfish/goldfish_pipe_qemu.h (revision 2e6ae11dd0d1c37f44cec51a58fb2092e55ed0f5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2018 Google, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15 
16 /*
17  * IMPORTANT: The following constants must match the ones used and defined in
18  * external/qemu/include/hw/misc/goldfish_pipe.h
19  */
20 
21 #ifndef GOLDFISH_PIPE_QEMU_H
22 #define GOLDFISH_PIPE_QEMU_H
23 
24 /* List of bitflags returned in status of CMD_POLL command */
25 enum PipePollFlags {
26 	PIPE_POLL_IN	= 1 << 0,
27 	PIPE_POLL_OUT	= 1 << 1,
28 	PIPE_POLL_HUP	= 1 << 2
29 };
30 
31 /* Possible status values used to signal errors */
32 enum PipeErrors {
33 	PIPE_ERROR_INVAL	= -1,
34 	PIPE_ERROR_AGAIN	= -2,
35 	PIPE_ERROR_NOMEM	= -3,
36 	PIPE_ERROR_IO		= -4
37 };
38 
39 /* Bit-flags used to signal events from the emulator */
40 enum PipeWakeFlags {
41 	/* emulator closed pipe */
42 	PIPE_WAKE_CLOSED		= 1 << 0,
43 
44 	/* pipe can now be read from */
45 	PIPE_WAKE_READ			= 1 << 1,
46 
47 	/* pipe can now be written to */
48 	PIPE_WAKE_WRITE			= 1 << 2,
49 
50 	/* unlock this pipe's DMA buffer */
51 	PIPE_WAKE_UNLOCK_DMA		= 1 << 3,
52 
53 	/* unlock DMA buffer of the pipe shared to this pipe */
54 	PIPE_WAKE_UNLOCK_DMA_SHARED	= 1 << 4,
55 };
56 
57 /* Possible pipe closing reasons */
58 enum PipeCloseReason {
59 	/* guest sent a close command */
60 	PIPE_CLOSE_GRACEFUL		= 0,
61 
62 	/* guest rebooted, we're closing the pipes */
63 	PIPE_CLOSE_REBOOT		= 1,
64 
65 	/* close old pipes on snapshot load */
66 	PIPE_CLOSE_LOAD_SNAPSHOT	= 2,
67 
68 	/* some unrecoverable error on the pipe */
69 	PIPE_CLOSE_ERROR		= 3,
70 };
71 
72 /* Bit flags for the 'flags' field */
73 enum PipeFlagsBits {
74 	BIT_CLOSED_ON_HOST = 0,  /* pipe closed by host */
75 	BIT_WAKE_ON_WRITE  = 1,  /* want to be woken on writes */
76 	BIT_WAKE_ON_READ   = 2,  /* want to be woken on reads */
77 };
78 
79 enum PipeRegs {
80 	PIPE_REG_CMD = 0,
81 
82 	PIPE_REG_SIGNAL_BUFFER_HIGH = 4,
83 	PIPE_REG_SIGNAL_BUFFER = 8,
84 	PIPE_REG_SIGNAL_BUFFER_COUNT = 12,
85 
86 	PIPE_REG_OPEN_BUFFER_HIGH = 20,
87 	PIPE_REG_OPEN_BUFFER = 24,
88 
89 	PIPE_REG_VERSION = 36,
90 
91 	PIPE_REG_GET_SIGNALLED = 48,
92 };
93 
94 enum PipeCmdCode {
95 	/* to be used by the pipe device itself */
96 	PIPE_CMD_OPEN		= 1,
97 
98 	PIPE_CMD_CLOSE,
99 	PIPE_CMD_POLL,
100 	PIPE_CMD_WRITE,
101 	PIPE_CMD_WAKE_ON_WRITE,
102 	PIPE_CMD_READ,
103 	PIPE_CMD_WAKE_ON_READ,
104 
105 	/*
106 	 * TODO(zyy): implement a deferred read/write execution to allow
107 	 * parallel processing of pipe operations on the host.
108 	 */
109 	PIPE_CMD_WAKE_ON_DONE_IO,
110 };
111 
112 #endif /* GOLDFISH_PIPE_QEMU_H */
113