]>
Commit | Line | Data |
---|---|---|
263559b8 | 1 | /** @file\r |
2 | \r | |
3 | Declarations of utility functions used by virtio device drivers.\r | |
4 | \r | |
5 | Copyright (C) 2012, Red Hat, Inc.\r | |
6 | \r | |
7 | This program and the accompanying materials are licensed and made available\r | |
8 | under the terms and conditions of the BSD License which accompanies this\r | |
9 | distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r | |
13 | WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #ifndef _VIRTIO_LIB_H_\r | |
18 | #define _VIRTIO_LIB_H_\r | |
19 | \r | |
56f65ed8 OM |
20 | #include <Protocol/VirtioDevice.h>\r |
21 | \r | |
263559b8 | 22 | #include <IndustryStandard/Virtio.h>\r |
23 | \r | |
263559b8 | 24 | \r |
25 | /**\r | |
26 | \r | |
27 | Configure a virtio ring.\r | |
28 | \r | |
29 | This function sets up internal storage (the guest-host communication area)\r | |
30 | and lays out several "navigation" (ie. no-ownership) pointers to parts of\r | |
31 | that storage.\r | |
32 | \r | |
33 | Relevant sections from the virtio-0.9.5 spec:\r | |
34 | - 1.1 Virtqueues,\r | |
35 | - 2.3 Virtqueue Configuration.\r | |
36 | \r | |
37 | @param[in] The number of descriptors to allocate for the\r | |
38 | virtio ring, as requested by the host.\r | |
39 | \r | |
40 | @param[out] Ring The virtio ring to set up.\r | |
41 | \r | |
42 | @retval EFI_OUT_OF_RESOURCES AllocatePages() failed to allocate contiguous\r | |
43 | pages for the requested QueueSize. Fields of\r | |
44 | Ring have indeterminate value.\r | |
45 | \r | |
46 | @retval EFI_SUCCESS Allocation and setup successful. Ring->Base\r | |
47 | (and nothing else) is responsible for\r | |
48 | deallocation.\r | |
49 | \r | |
50 | **/\r | |
51 | EFI_STATUS\r | |
52 | EFIAPI\r | |
53 | VirtioRingInit (\r | |
54 | IN UINT16 QueueSize,\r | |
55 | OUT VRING *Ring\r | |
56 | );\r | |
57 | \r | |
58 | \r | |
59 | /**\r | |
60 | \r | |
61 | Tear down the internal resources of a configured virtio ring.\r | |
62 | \r | |
63 | The caller is responsible to stop the host from using this ring before\r | |
64 | invoking this function: the VSTAT_DRIVER_OK bit must be clear in\r | |
65 | VhdrDeviceStatus.\r | |
66 | \r | |
67 | @param[out] Ring The virtio ring to clean up.\r | |
68 | \r | |
69 | **/\r | |
70 | VOID\r | |
71 | EFIAPI\r | |
72 | VirtioRingUninit (\r | |
73 | IN OUT VRING *Ring\r | |
74 | );\r | |
75 | \r | |
76 | \r | |
e371e7e5 | 77 | //\r |
78 | // Internal use structure for tracking the submission of a multi-descriptor\r | |
79 | // request.\r | |
80 | //\r | |
81 | typedef struct {\r | |
635a3ca2 | 82 | UINT16 HeadDescIdx;\r |
83 | UINT16 NextDescIdx;\r | |
e371e7e5 | 84 | } DESC_INDICES;\r |
85 | \r | |
86 | \r | |
87 | /**\r | |
88 | \r | |
89 | Turn off interrupt notifications from the host, and prepare for appending\r | |
90 | multiple descriptors to the virtio ring.\r | |
91 | \r | |
92 | The calling driver must be in VSTAT_DRIVER_OK state.\r | |
93 | \r | |
f2965f4e | 94 | @param[in,out] Ring The virtio ring we intend to append descriptors to.\r |
e371e7e5 | 95 | \r |
96 | @param[out] Indices The DESC_INDICES structure to initialize.\r | |
97 | \r | |
98 | **/\r | |
99 | VOID\r | |
100 | EFIAPI\r | |
101 | VirtioPrepare (\r | |
102 | IN OUT VRING *Ring,\r | |
103 | OUT DESC_INDICES *Indices\r | |
104 | );\r | |
105 | \r | |
106 | \r | |
263559b8 | 107 | /**\r |
108 | \r | |
109 | Append a contiguous buffer for transmission / reception via the virtio ring.\r | |
110 | \r | |
635a3ca2 | 111 | This function implements the following section from virtio-0.9.5:\r |
263559b8 | 112 | - 2.4.1.1 Placing Buffers into the Descriptor Table\r |
263559b8 | 113 | \r |
114 | Free space is taken as granted, since the individual drivers support only\r | |
115 | synchronous requests and host side status is processed in lock-step with\r | |
116 | request submission. It is the calling driver's responsibility to verify the\r | |
117 | ring size in advance.\r | |
118 | \r | |
e371e7e5 | 119 | The caller is responsible for initializing *Indices with VirtioPrepare()\r |
120 | first.\r | |
121 | \r | |
11a5fdf4 | 122 | @param[in,out] Ring The virtio ring to append the buffer to, as a\r |
123 | descriptor.\r | |
124 | \r | |
125 | @param[in] BufferPhysAddr (Guest pseudo-physical) start address of the\r | |
126 | transmit / receive buffer.\r | |
127 | \r | |
128 | @param[in] BufferSize Number of bytes to transmit or receive.\r | |
129 | \r | |
130 | @param[in] Flags A bitmask of VRING_DESC_F_* flags. The caller\r | |
131 | computes this mask dependent on further buffers to\r | |
132 | append and transfer direction.\r | |
133 | VRING_DESC_F_INDIRECT is unsupported. The\r | |
134 | VRING_DESC.Next field is always set, but the host\r | |
135 | only interprets it dependent on VRING_DESC_F_NEXT.\r | |
136 | \r | |
137 | @param[in,out] Indices Indices->HeadDescIdx is not accessed.\r | |
138 | On input, Indices->NextDescIdx identifies the next\r | |
139 | descriptor to carry the buffer. On output,\r | |
140 | Indices->NextDescIdx is incremented by one, modulo\r | |
141 | 2^16.\r | |
263559b8 | 142 | \r |
143 | **/\r | |
144 | VOID\r | |
145 | EFIAPI\r | |
7fcacd6c | 146 | VirtioAppendDesc (\r |
e371e7e5 | 147 | IN OUT VRING *Ring,\r |
148 | IN UINTN BufferPhysAddr,\r | |
149 | IN UINT32 BufferSize,\r | |
150 | IN UINT16 Flags,\r | |
151 | IN OUT DESC_INDICES *Indices\r | |
152 | );\r | |
153 | \r | |
154 | \r | |
155 | /**\r | |
156 | \r | |
635a3ca2 | 157 | Notify the host about the descriptor chain just built, and wait until the\r |
158 | host processes it.\r | |
e371e7e5 | 159 | \r |
56f65ed8 | 160 | @param[in] VirtIo The target virtio device to notify.\r |
e371e7e5 | 161 | \r |
162 | @param[in] VirtQueueId Identifies the queue for the target device.\r | |
163 | \r | |
a7615fa8 | 164 | @param[in,out] Ring The virtio ring with descriptors to submit.\r |
e371e7e5 | 165 | \r |
a7615fa8 | 166 | @param[in] Indices Indices->NextDescIdx is not accessed.\r |
167 | Indices->HeadDescIdx identifies the head descriptor\r | |
168 | of the descriptor chain.\r | |
e371e7e5 | 169 | \r |
170 | \r | |
56f65ed8 | 171 | @return Error code from VirtIo->SetQueueNotify() if it fails.\r |
e371e7e5 | 172 | \r |
173 | @retval EFI_SUCCESS Otherwise, the host processed all descriptors.\r | |
174 | \r | |
175 | **/\r | |
176 | EFI_STATUS\r | |
177 | EFIAPI\r | |
178 | VirtioFlush (\r | |
56f65ed8 OM |
179 | IN VIRTIO_DEVICE_PROTOCOL *VirtIo,\r |
180 | IN UINT16 VirtQueueId,\r | |
181 | IN OUT VRING *Ring,\r | |
182 | IN DESC_INDICES *Indices\r | |
263559b8 | 183 | );\r |
184 | \r | |
185 | #endif // _VIRTIO_LIB_H_\r |