ReactOS 0.4.15-dev-8241-g63935f8
VirtIOPCILegacy.c File Reference
#include "osdep.h"
#include "virtio_pci.h"
#include "VirtIO.h"
#include "kdebugprint.h"
#include "virtio_ring.h"
#include "virtio_pci_common.h"
#include "windows/virtio_ring_allocation.h"
Include dependency graph for VirtIOPCILegacy.c:

Go to the source code of this file.

Functions

void vio_legacy_dump_registers (VirtIODevice *vdev)
 
static void vio_legacy_get_config (VirtIODevice *vdev, unsigned offset, void *buf, unsigned len)
 
static void vio_legacy_set_config (VirtIODevice *vdev, unsigned offset, const void *buf, unsigned len)
 
static u8 vio_legacy_get_status (VirtIODevice *vdev)
 
static void vio_legacy_set_status (VirtIODevice *vdev, u8 status)
 
static void vio_legacy_reset (VirtIODevice *vdev)
 
static u64 vio_legacy_get_features (VirtIODevice *vdev)
 
static NTSTATUS vio_legacy_set_features (VirtIODevice *vdev, u64 features)
 
static u16 vio_legacy_set_config_vector (VirtIODevice *vdev, u16 vector)
 
static u16 vio_legacy_set_queue_vector (struct virtqueue *vq, u16 vector)
 
static NTSTATUS vio_legacy_query_vq_alloc (VirtIODevice *vdev, unsigned index, unsigned short *pNumEntries, unsigned long *pRingSize, unsigned long *pHeapSize)
 
static NTSTATUS vio_legacy_setup_vq (struct virtqueue **queue, VirtIODevice *vdev, VirtIOQueueInfo *info, unsigned index, u16 msix_vec)
 
static void vio_legacy_del_vq (VirtIOQueueInfo *info)
 
NTSTATUS vio_legacy_initialize (VirtIODevice *vdev)
 

Variables

static const struct virtio_device_ops virtio_pci_device_ops
 

Function Documentation

◆ vio_legacy_del_vq()

static void vio_legacy_del_vq ( VirtIOQueueInfo info)
static

Definition at line 232 of file VirtIOPCILegacy.c.

233{
234 struct virtqueue *vq = info->vq;
235 VirtIODevice *vdev = vq->vdev;
236
238
239 if (vdev->msix_used) {
242 /* Flush the write out to device */
244 }
245
246 /* Select and deactivate the queue */
248
250}
USHORT u16
Definition: btrfs.h:13
ULONG_PTR addr
Definition: virtio_pci.h:239
unsigned int index
Definition: VirtIO.h:45
VirtIODevice * vdev
Definition: VirtIO.h:44
#define VIRTIO_PCI_ISR
Definition: virtio_pci.h:71
#define VIRTIO_MSI_QUEUE_VECTOR
Definition: virtio_pci.h:77
#define VIRTIO_MSI_NO_VECTOR
Definition: virtio_pci.h:98
#define VIRTIO_PCI_QUEUE_SEL
Definition: virtio_pci.h:60
#define VIRTIO_PCI_QUEUE_PFN
Definition: virtio_pci.h:54
#define mem_free_contiguous_pages(vdev, virt)
#define iowrite32(vdev, val, addr)
#define iowrite16(vdev, val, addr)
#define ioread8(vdev, addr)

◆ vio_legacy_dump_registers()

void vio_legacy_dump_registers ( VirtIODevice vdev)

Definition at line 50 of file VirtIOPCILegacy.c.

51{
52 DPrintf(5, "%s\n", __FUNCTION__);
53
54 DPrintf(0, "[VIRTIO_PCI_HOST_FEATURES] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_HOST_FEATURES));
55 DPrintf(0, "[VIRTIO_PCI_GUEST_FEATURES] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_GUEST_FEATURES));
56 DPrintf(0, "[VIRTIO_PCI_QUEUE_PFN] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_PFN));
57 DPrintf(0, "[VIRTIO_PCI_QUEUE_NUM] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_NUM));
58 DPrintf(0, "[VIRTIO_PCI_QUEUE_SEL] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_SEL));
59 DPrintf(0, "[VIRTIO_PCI_QUEUE_NOTIFY] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_NOTIFY));
60 DPrintf(0, "[VIRTIO_PCI_STATUS] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_STATUS));
61 DPrintf(0, "[VIRTIO_PCI_ISR] = %x\n", ioread32(vdev, vdev->addr + VIRTIO_PCI_ISR));
62}
#define __FUNCTION__
Definition: types.h:116
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
#define VIRTIO_PCI_QUEUE_NUM
Definition: virtio_pci.h:57
#define VIRTIO_PCI_HOST_FEATURES
Definition: virtio_pci.h:48
#define VIRTIO_PCI_STATUS
Definition: virtio_pci.h:66
#define VIRTIO_PCI_QUEUE_NOTIFY
Definition: virtio_pci.h:63
#define VIRTIO_PCI_GUEST_FEATURES
Definition: virtio_pci.h:51
#define ioread32(vdev, addr)

◆ vio_legacy_get_config()

static void vio_legacy_get_config ( VirtIODevice vdev,
unsigned  offset,
void buf,
unsigned  len 
)
static

Definition at line 64 of file VirtIOPCILegacy.c.

68{
69 ULONG_PTR ioaddr = vdev->addr + VIRTIO_PCI_CONFIG(vdev->msix_used) + offset;
70 u8 *ptr = buf;
71 unsigned i;
72
73 DPrintf(5, "%s\n", __FUNCTION__);
74
75 for (i = 0; i < len; i++) {
76 ptr[i] = ioread8(vdev, ioaddr + i);
77 }
78}
UCHAR u8
Definition: btrfs.h:12
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static PVOID ptr
Definition: dispmode.c:27
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define VIRTIO_PCI_CONFIG(msix_enabled)
Definition: virtio_pci.h:83

◆ vio_legacy_get_features()

static u64 vio_legacy_get_features ( VirtIODevice vdev)
static

Definition at line 114 of file VirtIOPCILegacy.c.

115{
116 return ioread32(vdev, vdev->addr + VIRTIO_PCI_HOST_FEATURES);
117}

◆ vio_legacy_get_status()

static u8 vio_legacy_get_status ( VirtIODevice vdev)
static

Definition at line 96 of file VirtIOPCILegacy.c.

97{
98 DPrintf(6, "%s\n", __FUNCTION__);
99 return ioread8(vdev, vdev->addr + VIRTIO_PCI_STATUS);
100}

◆ vio_legacy_initialize()

NTSTATUS vio_legacy_initialize ( VirtIODevice vdev)

Definition at line 269 of file VirtIOPCILegacy.c.

270{
271 size_t length = pci_get_resource_len(vdev, 0);
272 vdev->addr = (ULONG_PTR)pci_map_address_range(vdev, 0, 0, length);
273
274 if (!vdev->addr) {
276 }
277
278 vdev->isr = (u8 *)vdev->addr + VIRTIO_PCI_ISR;
279
281
282 return STATUS_SUCCESS;
283}
static const struct virtio_device_ops virtio_pci_device_ops
#define ULONG_PTR
Definition: config.h:101
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define STATUS_SUCCESS
Definition: shellext.h:65
volatile u8 * isr
Definition: virtio_pci.h:260
const struct virtio_device_ops * device
Definition: virtio_pci.h:251
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define pci_map_address_range(vdev, bar, offset, maxlen)
#define pci_get_resource_len(vdev, bar)

Referenced by virtio_device_initialize().

◆ vio_legacy_query_vq_alloc()

static NTSTATUS vio_legacy_query_vq_alloc ( VirtIODevice vdev,
unsigned  index,
unsigned short pNumEntries,
unsigned long pRingSize,
unsigned long pHeapSize 
)
static

Definition at line 149 of file VirtIOPCILegacy.c.

154{
155 unsigned long ring_size, data_size;
156 u16 num;
157
158 /* Select the queue we're interested in */
160
161 /* Check if queue is either not available or already active. */
162 num = ioread16(vdev, vdev->addr + VIRTIO_PCI_QUEUE_NUM);
163 if (!num || ioread32(vdev, vdev->addr + VIRTIO_PCI_QUEUE_PFN)) {
164 return STATUS_NOT_FOUND;
165 }
166
168 data_size = ROUND_TO_PAGES(vring_control_block_size(num, false));
169
170 *pNumEntries = num;
171 *pRingSize = ring_size + data_size;
172 *pHeapSize = 0;
173
174 return STATUS_SUCCESS;
175}
unsigned int vring_control_block_size(u16 qsize, bool packed)
Definition: VirtIORing.c:474
GLuint index
Definition: glext.h:6031
GLuint GLuint num
Definition: glext.h:9618
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define VIRTIO_PCI_VRING_ALIGN
Definition: virtio_pci.h:91
#define ioread16(vdev, addr)
unsigned long vring_size(unsigned int num, unsigned long align, bool packed)
Definition: VirtIORing.c:555
#define ROUND_TO_PAGES(Size)

Referenced by vio_legacy_setup_vq().

◆ vio_legacy_reset()

static void vio_legacy_reset ( VirtIODevice vdev)
static

Definition at line 108 of file VirtIOPCILegacy.c.

109{
110 /* 0 status means a reset. */
111 iowrite8(vdev, 0, vdev->addr + VIRTIO_PCI_STATUS);
112}
#define iowrite8(vdev, val, addr)

◆ vio_legacy_set_config()

static void vio_legacy_set_config ( VirtIODevice vdev,
unsigned  offset,
const void buf,
unsigned  len 
)
static

Definition at line 80 of file VirtIOPCILegacy.c.

84{
85 ULONG_PTR ioaddr = vdev->addr + VIRTIO_PCI_CONFIG(vdev->msix_used) + offset;
86 const u8 *ptr = buf;
87 unsigned i;
88
89 DPrintf(5, "%s\n", __FUNCTION__);
90
91 for (i = 0; i < len; i++) {
92 iowrite8(vdev, ptr[i], ioaddr + i);
93 }
94}

◆ vio_legacy_set_config_vector()

static u16 vio_legacy_set_config_vector ( VirtIODevice vdev,
u16  vector 
)
static

Definition at line 131 of file VirtIOPCILegacy.c.

132{
133 /* Setup the vector used for configuration events */
135 /* Verify we had enough resources to assign the vector */
136 /* Will also flush the write out to device */
137 return ioread16(vdev, vdev->addr + VIRTIO_MSI_CONFIG_VECTOR);
138}
#define VIRTIO_MSI_CONFIG_VECTOR
Definition: virtio_pci.h:75

◆ vio_legacy_set_features()

static NTSTATUS vio_legacy_set_features ( VirtIODevice vdev,
u64  features 
)
static

Definition at line 119 of file VirtIOPCILegacy.c.

120{
121 /* Give virtio_ring a chance to accept features. */
122 vring_transport_features(vdev, &features);
123
124 /* Make sure we don't have any features > 32 bits! */
125 ASSERT((u32)features == features);
126 iowrite32(vdev, (u32)features, vdev->addr + VIRTIO_PCI_GUEST_FEATURES);
127
128 return STATUS_SUCCESS;
129}
ULONG32 u32
Definition: btrfs.h:14
#define ASSERT(a)
Definition: mode.c:44
void vring_transport_features(VirtIODevice *vdev, u64 *features)
Definition: VirtIORing.c:534

◆ vio_legacy_set_queue_vector()

static u16 vio_legacy_set_queue_vector ( struct virtqueue vq,
u16  vector 
)
static

Definition at line 140 of file VirtIOPCILegacy.c.

141{
142 VirtIODevice *vdev = vq->vdev;
143
144 iowrite16(vdev, (u16)vq->index, vdev->addr + VIRTIO_PCI_QUEUE_SEL);
146 return ioread16(vdev, vdev->addr + VIRTIO_MSI_QUEUE_VECTOR);
147}

◆ vio_legacy_set_status()

static void vio_legacy_set_status ( VirtIODevice vdev,
u8  status 
)
static

Definition at line 102 of file VirtIOPCILegacy.c.

103{
104 DPrintf(6, "%s>>> %x\n", __FUNCTION__, status);
105 iowrite8(vdev, status, vdev->addr + VIRTIO_PCI_STATUS);
106}
Definition: ps.c:97

◆ vio_legacy_setup_vq()

static NTSTATUS vio_legacy_setup_vq ( struct virtqueue **  queue,
VirtIODevice vdev,
VirtIOQueueInfo info,
unsigned  index,
u16  msix_vec 
)
static

Definition at line 177 of file VirtIOPCILegacy.c.

182{
183 struct virtqueue *vq;
184 unsigned long ring_size, heap_size;
186
187 /* Select the queue and query allocation parameters */
188 status = vio_legacy_query_vq_alloc(vdev, index, &info->num, &ring_size, &heap_size);
189 if (!NT_SUCCESS(status)) {
190 return status;
191 }
192
193 info->queue = mem_alloc_contiguous_pages(vdev, ring_size);
194 if (info->queue == NULL) {
196 }
197
198 /* activate the queue */
201
202 /* create the vring */
205 info->queue, vp_notify,
206 (u8 *)info->queue + ROUND_TO_PAGES(vring_size(info->num, VIRTIO_PCI_VRING_ALIGN, false)));
207 if (!vq) {
209 goto err_activate_queue;
210 }
211
213
214 if (msix_vec != VIRTIO_MSI_NO_VECTOR) {
215 msix_vec = vdev->device->set_queue_vector(vq, msix_vec);
216 if (msix_vec == VIRTIO_MSI_NO_VECTOR) {
218 goto err_assign;
219 }
220 }
221
222 *queue = vq;
223 return STATUS_SUCCESS;
224
225err_assign:
226err_activate_queue:
229 return status;
230}
static NTSTATUS vio_legacy_query_vq_alloc(VirtIODevice *vdev, unsigned index, unsigned short *pNumEntries, unsigned long *pRingSize, unsigned long *pHeapSize)
struct virtqueue * vring_new_virtqueue_split(unsigned int index, unsigned int num, unsigned int vring_align, VirtIODevice *vdev, void *pages, void(*notify)(struct virtqueue *), void *control)
Definition: VirtIORing.c:486
LONG NTSTATUS
Definition: precomp.h:26
Definition: _queue.h:67
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
void * notification_addr
Definition: VirtIO.h:47
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
#define VIRTIO_PCI_QUEUE_ADDR_SHIFT
Definition: virtio_pci.h:87
#define mem_get_physical_address(vdev, virt)
#define mem_alloc_contiguous_pages(vdev, size)
void vp_notify(struct virtqueue *vq)

Variable Documentation

◆ virtio_pci_device_ops

const struct virtio_device_ops virtio_pci_device_ops
static
Initial value:
= {
}
static void vio_legacy_del_vq(VirtIOQueueInfo *info)
static void vio_legacy_set_status(VirtIODevice *vdev, u8 status)
static void vio_legacy_reset(VirtIODevice *vdev)
static void vio_legacy_get_config(VirtIODevice *vdev, unsigned offset, void *buf, unsigned len)
static u16 vio_legacy_set_queue_vector(struct virtqueue *vq, u16 vector)
static NTSTATUS vio_legacy_set_features(VirtIODevice *vdev, u64 features)
static u16 vio_legacy_set_config_vector(VirtIODevice *vdev, u16 vector)
static NTSTATUS vio_legacy_setup_vq(struct virtqueue **queue, VirtIODevice *vdev, VirtIOQueueInfo *info, unsigned index, u16 msix_vec)
static u8 vio_legacy_get_status(VirtIODevice *vdev)
static u64 vio_legacy_get_features(VirtIODevice *vdev)
static void vio_legacy_set_config(VirtIODevice *vdev, unsigned offset, const void *buf, unsigned len)

Definition at line 252 of file VirtIOPCILegacy.c.

Referenced by vio_legacy_initialize().