e6279159f8ba989bc2a43a3a98751662f06a6b9c
[mirror_edk2.git] / OvmfPkg / Library / VirtioMmioDeviceLib / VirtioMmioDevice.h
1 /** @file
2
3 Internal definitions for the VirtIo MMIO Device driver
4
5 Copyright (C) 2013, ARM Ltd
6 Copyright (C) 2017, AMD Inc. All rights reserved.<BR>
7
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #ifndef _VIRTIO_MMIO_DEVICE_INTERNAL_H_
19 #define _VIRTIO_MMIO_DEVICE_INTERNAL_H_
20
21 #include <Protocol/VirtioDevice.h>
22
23 #include <IndustryStandard/Virtio.h>
24
25 #include <Library/DebugLib.h>
26 #include <Library/IoLib.h>
27 #include <Library/UefiLib.h>
28 #include <Library/VirtioMmioDeviceLib.h>
29 #include <Library/MemoryAllocationLib.h>
30
31 #define VIRTIO_MMIO_DEVICE_SIGNATURE SIGNATURE_32 ('V', 'M', 'I', 'O')
32
33 typedef struct {
34 UINT32 Signature;
35 VIRTIO_DEVICE_PROTOCOL VirtioDevice;
36 PHYSICAL_ADDRESS BaseAddress;
37 } VIRTIO_MMIO_DEVICE;
38
39 #define VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE(Device) \
40 CR (Device, VIRTIO_MMIO_DEVICE, VirtioDevice, VIRTIO_MMIO_DEVICE_SIGNATURE)
41
42 #define VIRTIO_CFG_WRITE(Device, Offset, Val) \
43 (MmioWrite32 (Device->BaseAddress + (Offset), Val))
44 #define VIRTIO_CFG_READ(Device, Offset) \
45 (MmioRead32 (Device->BaseAddress + (Offset)))
46
47 EFI_STATUS
48 EFIAPI
49 VirtioMmioDeviceRead (
50 IN VIRTIO_DEVICE_PROTOCOL *This,
51 IN UINTN FieldOFfset,
52 IN UINTN FieldSize,
53 IN UINTN BufferSize,
54 OUT VOID* Buffer
55 );
56
57 EFI_STATUS
58 EFIAPI
59 VirtioMmioDeviceWrite (
60 IN VIRTIO_DEVICE_PROTOCOL *This,
61 IN UINTN FieldOffset,
62 IN UINTN FieldSize,
63 IN UINT64 Value
64 );
65
66 EFI_STATUS
67 EFIAPI
68 VirtioMmioGetDeviceFeatures (
69 IN VIRTIO_DEVICE_PROTOCOL *This,
70 OUT UINT64 *DeviceFeatures
71 );
72
73 EFI_STATUS
74 EFIAPI
75 VirtioMmioGetQueueSize (
76 IN VIRTIO_DEVICE_PROTOCOL *This,
77 OUT UINT16 *QueueNumMax
78 );
79
80 EFI_STATUS
81 EFIAPI
82 VirtioMmioGetDeviceStatus (
83 IN VIRTIO_DEVICE_PROTOCOL *This,
84 OUT UINT8 *DeviceStatus
85 );
86
87 EFI_STATUS
88 EFIAPI
89 VirtioMmioSetQueueSize (
90 IN VIRTIO_DEVICE_PROTOCOL *This,
91 IN UINT16 QueueSize
92 );
93
94 EFI_STATUS
95 EFIAPI
96 VirtioMmioSetDeviceStatus (
97 IN VIRTIO_DEVICE_PROTOCOL *This,
98 IN UINT8 DeviceStatus
99 );
100
101 EFI_STATUS
102 EFIAPI
103 VirtioMmioSetQueueNotify (
104 IN VIRTIO_DEVICE_PROTOCOL *This,
105 IN UINT16 QueueNotify
106 );
107
108 EFI_STATUS
109 EFIAPI
110 VirtioMmioSetQueueSel (
111 IN VIRTIO_DEVICE_PROTOCOL *This,
112 IN UINT16 Sel
113 );
114
115 EFI_STATUS
116 VirtioMmioSetQueueAddress (
117 IN VIRTIO_DEVICE_PROTOCOL *This,
118 IN VRING *Ring,
119 IN UINT64 RingBaseShift
120 );
121
122 EFI_STATUS
123 EFIAPI
124 VirtioMmioSetQueueAlignment (
125 IN VIRTIO_DEVICE_PROTOCOL *This,
126 IN UINT32 Alignment
127 );
128
129 EFI_STATUS
130 EFIAPI
131 VirtioMmioSetPageSize (
132 IN VIRTIO_DEVICE_PROTOCOL *This,
133 IN UINT32 PageSize
134 );
135
136 EFI_STATUS
137 EFIAPI
138 VirtioMmioSetGuestFeatures (
139 IN VIRTIO_DEVICE_PROTOCOL *This,
140 IN UINT64 Features
141 );
142
143 EFI_STATUS
144 EFIAPI
145 VirtioMmioAllocateSharedPages (
146 IN VIRTIO_DEVICE_PROTOCOL *This,
147 IN UINTN NumPages,
148 OUT VOID **HostAddress
149 );
150
151 VOID
152 EFIAPI
153 VirtioMmioFreeSharedPages (
154 IN VIRTIO_DEVICE_PROTOCOL *This,
155 IN UINTN NumPages,
156 IN VOID *HostAddress
157 );
158
159 EFI_STATUS
160 EFIAPI
161 VirtioMmioMapSharedBuffer (
162 IN VIRTIO_DEVICE_PROTOCOL *This,
163 IN VIRTIO_MAP_OPERATION Operation,
164 IN VOID *HostAddress,
165 IN OUT UINTN *NumberOfBytes,
166 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
167 OUT VOID **Mapping
168 );
169
170 EFI_STATUS
171 EFIAPI
172 VirtioMmioUnmapSharedBuffer (
173 IN VIRTIO_DEVICE_PROTOCOL *This,
174 IN VOID *Mapping
175 );
176
177 #endif // _VIRTIO_MMIO_DEVICE_INTERNAL_H_