1 | /** @file
|
---|
2 |
|
---|
3 | Private definitions of the VirtioRng RNG driver
|
---|
4 |
|
---|
5 | Copyright (C) 2016, Linaro Ltd.
|
---|
6 |
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 |
|
---|
11 | #ifndef _VIRTIO_SERIAL_DXE_H_
|
---|
12 | #define _VIRTIO_SERIAL_DXE_H_
|
---|
13 |
|
---|
14 | #include <Protocol/ComponentName.h>
|
---|
15 | #include <Protocol/DriverBinding.h>
|
---|
16 | #include <Protocol/SerialIo.h>
|
---|
17 |
|
---|
18 | #include <IndustryStandard/Virtio.h>
|
---|
19 | #include <IndustryStandard/VirtioSerial.h>
|
---|
20 |
|
---|
21 | #define VIRTIO_SERIAL_SIG SIGNATURE_32 ('V', 'S', 'I', 'O')
|
---|
22 |
|
---|
23 | #define MAX_PORTS 8
|
---|
24 | #define MAX_RINGS (MAX_PORTS * 2 + 2)
|
---|
25 |
|
---|
26 | #define CTRL_RX_BUFSIZE 128
|
---|
27 | #define CTRL_TX_BUFSIZE sizeof(VIRTIO_SERIAL_CONTROL)
|
---|
28 | #define PORT_RX_BUFSIZE 128
|
---|
29 | #define PORT_TX_BUFSIZE 128
|
---|
30 |
|
---|
31 | //
|
---|
32 | // Data structures
|
---|
33 | //
|
---|
34 |
|
---|
35 | typedef struct _VIRTIO_SERIAL_DEV VIRTIO_SERIAL_DEV;
|
---|
36 | typedef struct _VIRTIO_SERIAL_RING VIRTIO_SERIAL_RING;
|
---|
37 | typedef struct _VIRTIO_SERIAL_PORT VIRTIO_SERIAL_PORT;
|
---|
38 | typedef struct _VIRTIO_SERIAL_IO_PROTOCOL VIRTIO_SERIAL_IO_PROTOCOL;
|
---|
39 |
|
---|
40 | struct _VIRTIO_SERIAL_RING {
|
---|
41 | VRING Ring;
|
---|
42 | VOID *RingMap;
|
---|
43 | DESC_INDICES Indices; /* Avail Ring */
|
---|
44 | UINT16 LastUsedIdx; /* Used Ring */
|
---|
45 |
|
---|
46 | UINT32 BufferSize;
|
---|
47 | UINT32 BufferCount;
|
---|
48 | UINT32 BufferPages;
|
---|
49 | UINT8 *Buffers;
|
---|
50 | VOID *BufferMap;
|
---|
51 | EFI_PHYSICAL_ADDRESS DeviceAddress;
|
---|
52 |
|
---|
53 | BOOLEAN Ready;
|
---|
54 | };
|
---|
55 |
|
---|
56 | struct _VIRTIO_SERIAL_PORT {
|
---|
57 | BOOLEAN Ready;
|
---|
58 | BOOLEAN Console;
|
---|
59 | BOOLEAN DeviceOpen;
|
---|
60 |
|
---|
61 | CHAR16 Name[32];
|
---|
62 |
|
---|
63 | VIRTIO_SERIAL_IO_PROTOCOL *SerialIo;
|
---|
64 | };
|
---|
65 |
|
---|
66 | struct _VIRTIO_SERIAL_DEV {
|
---|
67 | UINT32 Signature;
|
---|
68 | LIST_ENTRY Link;
|
---|
69 |
|
---|
70 | EFI_HANDLE DriverBindingHandle;
|
---|
71 | EFI_HANDLE DeviceHandle;
|
---|
72 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
---|
73 |
|
---|
74 | VIRTIO_DEVICE_PROTOCOL *VirtIo;
|
---|
75 | EFI_EVENT ExitBoot;
|
---|
76 | VIRTIO_SERIAL_CONFIG Config;
|
---|
77 | VIRTIO_SERIAL_PORT Ports[MAX_PORTS];
|
---|
78 | VIRTIO_SERIAL_RING Rings[MAX_RINGS];
|
---|
79 | EFI_EVENT Timer;
|
---|
80 |
|
---|
81 | UINT32 NumPorts;
|
---|
82 | UINT32 NumConsoles;
|
---|
83 | UINT32 NumNamedPorts;
|
---|
84 | };
|
---|
85 |
|
---|
86 | struct _VIRTIO_SERIAL_IO_PROTOCOL {
|
---|
87 | EFI_SERIAL_IO_PROTOCOL SerialIo;
|
---|
88 | EFI_SERIAL_IO_MODE SerialIoMode;
|
---|
89 |
|
---|
90 | EFI_HANDLE DeviceHandle;
|
---|
91 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
---|
92 |
|
---|
93 | VIRTIO_SERIAL_DEV *Dev;
|
---|
94 | UINT32 PortId;
|
---|
95 |
|
---|
96 | UINT8 ReadBuffer[PORT_RX_BUFSIZE];
|
---|
97 | UINT32 ReadOffset;
|
---|
98 | UINT32 ReadSize;
|
---|
99 |
|
---|
100 | UINT8 WriteBuffer[PORT_TX_BUFSIZE];
|
---|
101 | UINT32 WriteOffset;
|
---|
102 | };
|
---|
103 |
|
---|
104 | //
|
---|
105 | // VirtioSerial.c
|
---|
106 | //
|
---|
107 |
|
---|
108 | VOID
|
---|
109 | EFIAPI
|
---|
110 | LogDevicePath (
|
---|
111 | UINT32 Level,
|
---|
112 | const CHAR8 *Func,
|
---|
113 | CHAR16 *Note,
|
---|
114 | EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
---|
115 | );
|
---|
116 |
|
---|
117 | EFI_STATUS
|
---|
118 | EFIAPI
|
---|
119 | VirtioSerialTxControl (
|
---|
120 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
121 | IN UINT32 Id,
|
---|
122 | IN UINT16 Event,
|
---|
123 | IN UINT16 Value
|
---|
124 | );
|
---|
125 |
|
---|
126 | //
|
---|
127 | // VirtioSerialRing.c
|
---|
128 | //
|
---|
129 |
|
---|
130 | EFI_STATUS
|
---|
131 | EFIAPI
|
---|
132 | VirtioSerialInitRing (
|
---|
133 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
134 | IN UINT16 Index,
|
---|
135 | IN UINT32 BufferSize
|
---|
136 | );
|
---|
137 |
|
---|
138 | VOID
|
---|
139 | EFIAPI
|
---|
140 | VirtioSerialUninitRing (
|
---|
141 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
142 | IN UINT16 Index
|
---|
143 | );
|
---|
144 |
|
---|
145 | VOID
|
---|
146 | EFIAPI
|
---|
147 | VirtioSerialRingFillRx (
|
---|
148 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
149 | IN UINT16 Index
|
---|
150 | );
|
---|
151 |
|
---|
152 | VOID
|
---|
153 | EFIAPI
|
---|
154 | VirtioSerialRingClearTx (
|
---|
155 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
156 | IN UINT16 Index
|
---|
157 | );
|
---|
158 |
|
---|
159 | EFI_STATUS
|
---|
160 | EFIAPI
|
---|
161 | VirtioSerialRingSendBuffer (
|
---|
162 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
163 | IN UINT16 Index,
|
---|
164 | IN VOID *Data,
|
---|
165 | IN UINT32 DataSize,
|
---|
166 | IN BOOLEAN Notify
|
---|
167 | );
|
---|
168 |
|
---|
169 | BOOLEAN
|
---|
170 | EFIAPI
|
---|
171 | VirtioSerialRingHasBuffer (
|
---|
172 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
173 | IN UINT16 Index
|
---|
174 | );
|
---|
175 |
|
---|
176 | BOOLEAN
|
---|
177 | EFIAPI
|
---|
178 | VirtioSerialRingGetBuffer (
|
---|
179 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
180 | IN UINT16 Index,
|
---|
181 | OUT VOID *Data,
|
---|
182 | OUT UINT32 *DataSize
|
---|
183 | );
|
---|
184 |
|
---|
185 | //
|
---|
186 | // VirtioSerialPort.c
|
---|
187 | //
|
---|
188 |
|
---|
189 | EFI_STATUS
|
---|
190 | EFIAPI
|
---|
191 | VirtioSerialPortAdd (
|
---|
192 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
193 | IN UINT32 PortId
|
---|
194 | );
|
---|
195 |
|
---|
196 | VOID
|
---|
197 | EFIAPI
|
---|
198 | VirtioSerialPortSetConsole (
|
---|
199 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
200 | IN UINT32 PortId
|
---|
201 | );
|
---|
202 |
|
---|
203 | VOID
|
---|
204 | EFIAPI
|
---|
205 | VirtioSerialPortSetName (
|
---|
206 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
207 | IN UINT32 PortId,
|
---|
208 | IN UINT8 *Name
|
---|
209 | );
|
---|
210 |
|
---|
211 | VOID
|
---|
212 | EFIAPI
|
---|
213 | VirtioSerialPortSetDeviceOpen (
|
---|
214 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
215 | IN UINT32 PortId,
|
---|
216 | IN UINT16 Value
|
---|
217 | );
|
---|
218 |
|
---|
219 | VOID
|
---|
220 | EFIAPI
|
---|
221 | VirtioSerialPortRemove (
|
---|
222 | IN OUT VIRTIO_SERIAL_DEV *Dev,
|
---|
223 | IN UINT32 PortId
|
---|
224 | );
|
---|
225 |
|
---|
226 | #endif
|
---|