]>
Commit | Line | Data |
---|---|---|
b55d6622 LE |
1 | /** @file\r |
2 | Internal macro definitions, type definitions, and function declarations for\r | |
3 | the Virtio Filesystem device driver.\r | |
4 | \r | |
5 | Copyright (C) 2020, Red Hat, Inc.\r | |
6 | \r | |
7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
8 | **/\r | |
9 | \r | |
10 | #ifndef VIRTIO_FS_DXE_H_\r | |
11 | #define VIRTIO_FS_DXE_H_\r | |
12 | \r | |
13 | #include <Base.h> // SIGNATURE_64()\r | |
eaa7115d | 14 | #include <IndustryStandard/VirtioFs.h> // VIRTIO_FS_TAG_BYTES\r |
b55d6622 LE |
15 | #include <Library/DebugLib.h> // CR()\r |
16 | #include <Protocol/SimpleFileSystem.h> // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL\r | |
17 | #include <Protocol/VirtioDevice.h> // VIRTIO_DEVICE_PROTOCOL\r | |
eaa7115d | 18 | #include <Uefi/UefiBaseType.h> // EFI_EVENT\r |
b55d6622 LE |
19 | \r |
20 | #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S')\r | |
21 | \r | |
334c13e1 LE |
22 | #define VIRTIO_FS_FILE_SIG \\r |
23 | SIGNATURE_64 ('V', 'I', 'O', 'F', 'S', 'F', 'I', 'L')\r | |
24 | \r | |
eaa7115d LE |
25 | //\r |
26 | // Filesystem label encoded in UCS-2, transformed from the UTF-8 representation\r | |
27 | // in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII code\r | |
28 | // points (U+0020 through U+007E) are supported.\r | |
29 | //\r | |
30 | typedef CHAR16 VIRTIO_FS_LABEL[VIRTIO_FS_TAG_BYTES + 1];\r | |
31 | \r | |
b55d6622 LE |
32 | //\r |
33 | // Main context structure, expressing an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL\r | |
34 | // interface on top of the Virtio Filesystem device.\r | |
35 | //\r | |
36 | typedef struct {\r | |
37 | //\r | |
38 | // Parts of this structure are initialized / torn down in various functions\r | |
39 | // at various call depths. The table to the right should make it easier to\r | |
40 | // track them.\r | |
41 | //\r | |
42 | // field init function init depth\r | |
43 | // ----------- ------------------ ----------\r | |
44 | UINT64 Signature; // DriverBindingStart 0\r | |
45 | VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0\r | |
eaa7115d LE |
46 | VIRTIO_FS_LABEL Label; // VirtioFsInit 1\r |
47 | UINT16 QueueSize; // VirtioFsInit 1\r | |
48 | VRING Ring; // VirtioRingInit 2\r | |
49 | VOID *RingMap; // VirtioRingMap 2\r | |
fa97e372 | 50 | UINT64 RequestId; // FuseInitSession 1\r |
eaa7115d | 51 | EFI_EVENT ExitBoot; // DriverBindingStart 0\r |
334c13e1 | 52 | LIST_ENTRY OpenFiles; // DriverBindingStart 0\r |
b55d6622 LE |
53 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0\r |
54 | } VIRTIO_FS;\r | |
55 | \r | |
56 | #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \\r | |
57 | CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);\r | |
58 | \r | |
6578cacb LE |
59 | //\r |
60 | // Structure for describing a contiguous buffer, potentially mapped for Virtio\r | |
61 | // transfer.\r | |
62 | //\r | |
63 | typedef struct {\r | |
64 | //\r | |
65 | // The following fields originate from the owner of the buffer.\r | |
66 | //\r | |
67 | VOID *Buffer;\r | |
68 | UINTN Size;\r | |
69 | //\r | |
70 | // All of the fields below, until the end of the structure, are\r | |
71 | // zero-initialized when the structure is initially validated.\r | |
72 | //\r | |
73 | // Mapped, MappedAddress and Mapping are updated when the buffer is mapped\r | |
74 | // for VirtioOperationBusMasterRead or VirtioOperationBusMasterWrite. They\r | |
75 | // are again updated when the buffer is unmapped.\r | |
76 | //\r | |
77 | BOOLEAN Mapped;\r | |
78 | EFI_PHYSICAL_ADDRESS MappedAddress;\r | |
79 | VOID *Mapping;\r | |
80 | //\r | |
81 | // Transferred is updated after VirtioFlush() returns successfully:\r | |
82 | // - for VirtioOperationBusMasterRead, Transferred is set to Size;\r | |
83 | // - for VirtioOperationBusMasterWrite, Transferred is calculated from the\r | |
84 | // UsedLen output parameter of VirtioFlush().\r | |
85 | //\r | |
86 | UINTN Transferred;\r | |
87 | } VIRTIO_FS_IO_VECTOR;\r | |
88 | \r | |
89 | //\r | |
90 | // Structure for describing a list of IO Vectors.\r | |
91 | //\r | |
92 | typedef struct {\r | |
93 | //\r | |
94 | // The following fields originate from the owner of the buffers.\r | |
95 | //\r | |
96 | VIRTIO_FS_IO_VECTOR *IoVec;\r | |
97 | UINTN NumVec;\r | |
98 | //\r | |
99 | // TotalSize is calculated when the scatter-gather list is initially\r | |
100 | // validated.\r | |
101 | //\r | |
102 | UINT32 TotalSize;\r | |
103 | } VIRTIO_FS_SCATTER_GATHER_LIST;\r | |
104 | \r | |
334c13e1 LE |
105 | //\r |
106 | // Private context structure that exposes EFI_FILE_PROTOCOL on top of an open\r | |
107 | // FUSE file reference.\r | |
108 | //\r | |
109 | typedef struct {\r | |
110 | UINT64 Signature;\r | |
111 | EFI_FILE_PROTOCOL SimpleFile;\r | |
112 | BOOLEAN IsDirectory;\r | |
113 | VIRTIO_FS *OwnerFs;\r | |
114 | LIST_ENTRY OpenFilesEntry;\r | |
115 | //\r | |
116 | // In the FUSE wire protocol, every request except FUSE_INIT refers to a\r | |
117 | // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, by the\r | |
118 | // inode number of the file. However, some of the FUSE requests that we need\r | |
119 | // for some of the EFI_FILE_PROTOCOL member functions require an open file\r | |
120 | // handle *in addition* to the inode number. For simplicity, whenever a\r | |
121 | // VIRTIO_FS_FILE object is created, primarily defined by its NodeId field,\r | |
122 | // we also *open* the referenced file at once, and save the returned file\r | |
123 | // handle in the FuseHandle field. This way, when an EFI_FILE_PROTOCOL member\r | |
124 | // function must send a FUSE request that needs the file handle *in addition*\r | |
125 | // to the inode number, FuseHandle will be at our disposal at once.\r | |
126 | //\r | |
127 | UINT64 NodeId;\r | |
128 | UINT64 FuseHandle;\r | |
129 | } VIRTIO_FS_FILE;\r | |
130 | \r | |
131 | #define VIRTIO_FS_FILE_FROM_SIMPLE_FILE(SimpleFileReference) \\r | |
132 | CR (SimpleFileReference, VIRTIO_FS_FILE, SimpleFile, VIRTIO_FS_FILE_SIG);\r | |
133 | \r | |
134 | #define VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY(OpenFilesEntryReference) \\r | |
135 | CR (OpenFilesEntryReference, VIRTIO_FS_FILE, OpenFilesEntry, \\r | |
136 | VIRTIO_FS_FILE_SIG);\r | |
137 | \r | |
eaa7115d LE |
138 | //\r |
139 | // Initialization and helper routines for the Virtio Filesystem device.\r | |
140 | //\r | |
141 | \r | |
142 | EFI_STATUS\r | |
143 | VirtioFsInit (\r | |
144 | IN OUT VIRTIO_FS *VirtioFs\r | |
145 | );\r | |
146 | \r | |
147 | VOID\r | |
148 | VirtioFsUninit (\r | |
149 | IN OUT VIRTIO_FS *VirtioFs\r | |
150 | );\r | |
151 | \r | |
152 | VOID\r | |
153 | EFIAPI\r | |
154 | VirtioFsExitBoot (\r | |
155 | IN EFI_EVENT ExitBootEvent,\r | |
156 | IN VOID *VirtioFsAsVoid\r | |
157 | );\r | |
158 | \r | |
6578cacb LE |
159 | EFI_STATUS\r |
160 | VirtioFsSgListsValidate (\r | |
161 | IN VIRTIO_FS *VirtioFs,\r | |
162 | IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList,\r | |
163 | IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL\r | |
164 | );\r | |
165 | \r | |
166 | EFI_STATUS\r | |
167 | VirtioFsSgListsSubmit (\r | |
168 | IN OUT VIRTIO_FS *VirtioFs,\r | |
169 | IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList,\r | |
170 | IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL\r | |
171 | );\r | |
172 | \r | |
6a2dc768 LE |
173 | EFI_STATUS\r |
174 | VirtioFsFuseNewRequest (\r | |
175 | IN OUT VIRTIO_FS *VirtioFs,\r | |
176 | OUT VIRTIO_FS_FUSE_REQUEST *Request,\r | |
177 | IN UINT32 RequestSize,\r | |
fa97e372 | 178 | IN VIRTIO_FS_FUSE_OPCODE Opcode,\r |
6a2dc768 LE |
179 | IN UINT64 NodeId\r |
180 | );\r | |
181 | \r | |
182 | EFI_STATUS\r | |
183 | VirtioFsFuseCheckResponse (\r | |
184 | IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList,\r | |
185 | IN UINT64 RequestId,\r | |
186 | OUT UINTN *TailBufferFill\r | |
187 | );\r | |
188 | \r | |
e8a74c9a LE |
189 | EFI_STATUS\r |
190 | VirtioFsErrnoToEfiStatus (\r | |
191 | IN INT32 Errno\r | |
192 | );\r | |
193 | \r | |
fa97e372 LE |
194 | //\r |
195 | // Wrapper functions for FUSE commands (primitives).\r | |
196 | //\r | |
197 | \r | |
92a4d30e LE |
198 | EFI_STATUS\r |
199 | VirtioFsFuseForget (\r | |
200 | IN OUT VIRTIO_FS *VirtioFs,\r | |
201 | IN UINT64 NodeId\r | |
202 | );\r | |
203 | \r | |
72d4f133 LE |
204 | EFI_STATUS\r |
205 | VirtioFsFuseReleaseFileOrDir (\r | |
206 | IN OUT VIRTIO_FS *VirtioFs,\r | |
207 | IN UINT64 NodeId,\r | |
208 | IN UINT64 FuseHandle,\r | |
209 | IN BOOLEAN IsDir\r | |
210 | );\r | |
211 | \r | |
2e151d26 LE |
212 | EFI_STATUS\r |
213 | VirtioFsFuseFsyncFileOrDir (\r | |
214 | IN OUT VIRTIO_FS *VirtioFs,\r | |
215 | IN UINT64 NodeId,\r | |
216 | IN UINT64 FuseHandle,\r | |
217 | IN BOOLEAN IsDir\r | |
218 | );\r | |
219 | \r | |
fa97e372 LE |
220 | EFI_STATUS\r |
221 | VirtioFsFuseInitSession (\r | |
222 | IN OUT VIRTIO_FS *VirtioFs\r | |
223 | );\r | |
224 | \r | |
b62a0c56 LE |
225 | EFI_STATUS\r |
226 | VirtioFsFuseOpenDir (\r | |
227 | IN OUT VIRTIO_FS *VirtioFs,\r | |
228 | IN UINT64 NodeId,\r | |
229 | OUT UINT64 *FuseHandle\r | |
230 | );\r | |
231 | \r | |
b55d6622 LE |
232 | //\r |
233 | // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem\r | |
234 | // driver.\r | |
235 | //\r | |
236 | \r | |
237 | EFI_STATUS\r | |
238 | EFIAPI\r | |
239 | VirtioFsOpenVolume (\r | |
240 | IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r | |
241 | OUT EFI_FILE_PROTOCOL **Root\r | |
242 | );\r | |
243 | \r | |
334c13e1 LE |
244 | //\r |
245 | // EFI_FILE_PROTOCOL member functions for the Virtio Filesystem driver.\r | |
246 | //\r | |
247 | \r | |
248 | EFI_STATUS\r | |
249 | EFIAPI\r | |
250 | VirtioFsSimpleFileClose (\r | |
251 | IN EFI_FILE_PROTOCOL *This\r | |
252 | );\r | |
253 | \r | |
254 | EFI_STATUS\r | |
255 | EFIAPI\r | |
256 | VirtioFsSimpleFileDelete (\r | |
257 | IN EFI_FILE_PROTOCOL *This\r | |
258 | );\r | |
259 | \r | |
260 | EFI_STATUS\r | |
261 | EFIAPI\r | |
262 | VirtioFsSimpleFileFlush (\r | |
263 | IN EFI_FILE_PROTOCOL *This\r | |
264 | );\r | |
265 | \r | |
266 | EFI_STATUS\r | |
267 | EFIAPI\r | |
268 | VirtioFsSimpleFileGetInfo (\r | |
269 | IN EFI_FILE_PROTOCOL *This,\r | |
270 | IN EFI_GUID *InformationType,\r | |
271 | IN OUT UINTN *BufferSize,\r | |
272 | OUT VOID *Buffer\r | |
273 | );\r | |
274 | \r | |
275 | EFI_STATUS\r | |
276 | EFIAPI\r | |
277 | VirtioFsSimpleFileGetPosition (\r | |
278 | IN EFI_FILE_PROTOCOL *This,\r | |
279 | OUT UINT64 *Position\r | |
280 | );\r | |
281 | \r | |
282 | EFI_STATUS\r | |
283 | EFIAPI\r | |
284 | VirtioFsSimpleFileOpen (\r | |
285 | IN EFI_FILE_PROTOCOL *This,\r | |
286 | OUT EFI_FILE_PROTOCOL **NewHandle,\r | |
287 | IN CHAR16 *FileName,\r | |
288 | IN UINT64 OpenMode,\r | |
289 | IN UINT64 Attributes\r | |
290 | );\r | |
291 | \r | |
292 | EFI_STATUS\r | |
293 | EFIAPI\r | |
294 | VirtioFsSimpleFileRead (\r | |
295 | IN EFI_FILE_PROTOCOL *This,\r | |
296 | IN OUT UINTN *BufferSize,\r | |
297 | OUT VOID *Buffer\r | |
298 | );\r | |
299 | \r | |
300 | EFI_STATUS\r | |
301 | EFIAPI\r | |
302 | VirtioFsSimpleFileSetInfo (\r | |
303 | IN EFI_FILE_PROTOCOL *This,\r | |
304 | IN EFI_GUID *InformationType,\r | |
305 | IN UINTN BufferSize,\r | |
306 | IN VOID *Buffer\r | |
307 | );\r | |
308 | \r | |
309 | EFI_STATUS\r | |
310 | EFIAPI\r | |
311 | VirtioFsSimpleFileSetPosition (\r | |
312 | IN EFI_FILE_PROTOCOL *This,\r | |
313 | IN UINT64 Position\r | |
314 | );\r | |
315 | \r | |
316 | EFI_STATUS\r | |
317 | EFIAPI\r | |
318 | VirtioFsSimpleFileWrite (\r | |
319 | IN EFI_FILE_PROTOCOL *This,\r | |
320 | IN OUT UINTN *BufferSize,\r | |
321 | IN VOID *Buffer\r | |
322 | );\r | |
323 | \r | |
b55d6622 | 324 | #endif // VIRTIO_FS_DXE_H_\r |