2 Internal macro definitions, type definitions, and function declarations for
3 the Virtio Filesystem device driver.
5 Copyright (C) 2020, Red Hat, Inc.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef VIRTIO_FS_DXE_H_
11 #define VIRTIO_FS_DXE_H_
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
20 #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S')
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.
27 typedef CHAR16 VIRTIO_FS_LABEL
[VIRTIO_FS_TAG_BYTES
+ 1];
30 // Main context structure, expressing an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
31 // interface on top of the Virtio Filesystem device.
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
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
52 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \
53 CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG);
56 // Structure for describing a contiguous buffer, potentially mapped for Virtio
61 // The following fields originate from the owner of the buffer.
66 // All of the fields below, until the end of the structure, are
67 // zero-initialized when the structure is initially validated.
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.
74 EFI_PHYSICAL_ADDRESS MappedAddress
;
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().
83 } VIRTIO_FS_IO_VECTOR
;
86 // Structure for describing a list of IO Vectors.
90 // The following fields originate from the owner of the buffers.
92 VIRTIO_FS_IO_VECTOR
*IoVec
;
95 // TotalSize is calculated when the scatter-gather list is initially
99 } VIRTIO_FS_SCATTER_GATHER_LIST
;
102 // Initialization and helper routines for the Virtio Filesystem device.
107 IN OUT VIRTIO_FS
*VirtioFs
112 IN OUT VIRTIO_FS
*VirtioFs
118 IN EFI_EVENT ExitBootEvent
,
119 IN VOID
*VirtioFsAsVoid
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
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
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
,
146 VirtioFsFuseCheckResponse (
147 IN VIRTIO_FS_SCATTER_GATHER_LIST
*ResponseSgList
,
149 OUT UINTN
*TailBufferFill
153 VirtioFsErrnoToEfiStatus (
158 // Wrapper functions for FUSE commands (primitives).
162 VirtioFsFuseInitSession (
163 IN OUT VIRTIO_FS
*VirtioFs
167 // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesystem
174 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*This
,
175 OUT EFI_FILE_PROTOCOL
**Root
178 #endif // VIRTIO_FS_DXE_H_