]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioFsDxe/VirtioFsDxe.h
OvmfPkg/VirtioFsDxe: submit the FUSE_INIT request to the device
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / VirtioFsDxe.h
1 /** @file
2 Internal macro definitions, type definitions, and function declarations for
3 the Virtio Filesystem device driver.
4
5 Copyright (C) 2020, Red Hat, Inc.
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8 **/
9
10 #ifndef VIRTIO_FS_DXE_H_
11 #define VIRTIO_FS_DXE_H_
12
13 #include <Base.h> // SIGNATURE_64()
14 #include <IndustryStandard/VirtioFs.h> // VIRTIO_FS_TAG_BYTES
15 #include <Library/DebugLib.h> // CR()
16 #include <Protocol/SimpleFileSystem.h> // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
17 #include <Protocol/VirtioDevice.h> // VIRTIO_DEVICE_PROTOCOL
18 #include <Uefi/UefiBaseType.h> // EFI_EVENT
19
20 #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S')
21
22 //
23 // Filesystem label encoded in UCS-2, transformed from the UTF-8 representation
24 // in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII code
25 // points (U+0020 through U+007E) are supported.
26 //
27 typedef CHAR16 VIRTIO_FS_LABEL[VIRTIO_FS_TAG_BYTES + 1];
28
29 //
30 // Main context structure, expressing an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
31 // interface on top of the Virtio Filesystem device.
32 //
33 typedef struct {
34 //
35 // Parts of this structure are initialized / torn down in various functions
36 // at various call depths. The table to the right should make it easier to
37 // track them.
38 //
39 // field init function init depth
40 // ----------- ------------------ ----------
41 UINT64 Signature; // DriverBindingStart 0
42 VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0
43 VIRTIO_FS_LABEL Label; // VirtioFsInit 1
44 UINT16 QueueSize; // VirtioFsInit 1
45 VRING Ring; // VirtioRingInit 2
46 VOID *RingMap; // VirtioRingMap 2
47 UINT64 RequestId; // FuseInitSession 1
48 EFI_EVENT ExitBoot; // DriverBindingStart 0
49 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0
50 } VIRTIO_FS;
51
52 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \
53 CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);
54
55 //
56 // Structure for describing a contiguous buffer, potentially mapped for Virtio
57 // transfer.
58 //
59 typedef struct {
60 //
61 // The following fields originate from the owner of the buffer.
62 //
63 VOID *Buffer;
64 UINTN Size;
65 //
66 // All of the fields below, until the end of the structure, are
67 // zero-initialized when the structure is initially validated.
68 //
69 // Mapped, MappedAddress and Mapping are updated when the buffer is mapped
70 // for VirtioOperationBusMasterRead or VirtioOperationBusMasterWrite. They
71 // are again updated when the buffer is unmapped.
72 //
73 BOOLEAN Mapped;
74 EFI_PHYSICAL_ADDRESS MappedAddress;
75 VOID *Mapping;
76 //
77 // Transferred is updated after VirtioFlush() returns successfully:
78 // - for VirtioOperationBusMasterRead, Transferred is set to Size;
79 // - for VirtioOperationBusMasterWrite, Transferred is calculated from the
80 // UsedLen output parameter of VirtioFlush().
81 //
82 UINTN Transferred;
83 } VIRTIO_FS_IO_VECTOR;
84
85 //
86 // Structure for describing a list of IO Vectors.
87 //
88 typedef struct {
89 //
90 // The following fields originate from the owner of the buffers.
91 //
92 VIRTIO_FS_IO_VECTOR *IoVec;
93 UINTN NumVec;
94 //
95 // TotalSize is calculated when the scatter-gather list is initially
96 // validated.
97 //
98 UINT32 TotalSize;
99 } VIRTIO_FS_SCATTER_GATHER_LIST;
100
101 //
102 // Initialization and helper routines for the Virtio Filesystem device.
103 //
104
105 EFI_STATUS
106 VirtioFsInit (
107 IN OUT VIRTIO_FS *VirtioFs
108 );
109
110 VOID
111 VirtioFsUninit (
112 IN OUT VIRTIO_FS *VirtioFs
113 );
114
115 VOID
116 EFIAPI
117 VirtioFsExitBoot (
118 IN EFI_EVENT ExitBootEvent,
119 IN VOID *VirtioFsAsVoid
120 );
121
122 EFI_STATUS
123 VirtioFsSgListsValidate (
124 IN VIRTIO_FS *VirtioFs,
125 IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList,
126 IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL
127 );
128
129 EFI_STATUS
130 VirtioFsSgListsSubmit (
131 IN OUT VIRTIO_FS *VirtioFs,
132 IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList,
133 IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL
134 );
135
136 EFI_STATUS
137 VirtioFsFuseNewRequest (
138 IN OUT VIRTIO_FS *VirtioFs,
139 OUT VIRTIO_FS_FUSE_REQUEST *Request,
140 IN UINT32 RequestSize,
141 IN VIRTIO_FS_FUSE_OPCODE Opcode,
142 IN UINT64 NodeId
143 );
144
145 EFI_STATUS
146 VirtioFsFuseCheckResponse (
147 IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList,
148 IN UINT64 RequestId,
149 OUT UINTN *TailBufferFill
150 );
151
152 EFI_STATUS
153 VirtioFsErrnoToEfiStatus (
154 IN INT32 Errno
155 );
156
157 //
158 // Wrapper functions for FUSE commands (primitives).
159 //
160
161 EFI_STATUS
162 VirtioFsFuseInitSession (
163 IN OUT VIRTIO_FS *VirtioFs
164 );
165
166 //
167 // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem
168 // driver.
169 //
170
171 EFI_STATUS
172 EFIAPI
173 VirtioFsOpenVolume (
174 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
175 OUT EFI_FILE_PROTOCOL **Root
176 );
177
178 #endif // VIRTIO_FS_DXE_H_