ReactOS  0.4.15-dev-1070-ge1a01de
virtio_pci_common.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ioread8(vdev, addr)   vdev->system->vdev_read_byte((ULONG_PTR)(addr))
 
#define ioread16(vdev, addr)   vdev->system->vdev_read_word((ULONG_PTR)(addr))
 
#define ioread32(vdev, addr)   vdev->system->vdev_read_dword((ULONG_PTR)(addr))
 
#define iowrite8(vdev, val, addr)   vdev->system->vdev_write_byte((ULONG_PTR)(addr), val)
 
#define iowrite16(vdev, val, addr)   vdev->system->vdev_write_word((ULONG_PTR)(addr), val)
 
#define iowrite32(vdev, val, addr)   vdev->system->vdev_write_dword((ULONG_PTR)(addr), val)
 
#define iowrite64_twopart(vdev, val, lo_addr, hi_addr)
 
#define mem_alloc_contiguous_pages(vdev, size)   vdev->system->mem_alloc_contiguous_pages(vdev->DeviceContext, size)
 
#define mem_free_contiguous_pages(vdev, virt)   vdev->system->mem_free_contiguous_pages(vdev->DeviceContext, virt)
 
#define mem_get_physical_address(vdev, virt)   vdev->system->mem_get_physical_address(vdev->DeviceContext, virt)
 
#define mem_alloc_nonpaged_block(vdev, size)   vdev->system->mem_alloc_nonpaged_block(vdev->DeviceContext, size)
 
#define mem_free_nonpaged_block(vdev, addr)   vdev->system->mem_free_nonpaged_block(vdev->DeviceContext, addr)
 
#define pci_read_config_byte(vdev, where, bVal)   vdev->system->pci_read_config_byte(vdev->DeviceContext, where, bVal)
 
#define pci_read_config_word(vdev, where, wVal)   vdev->system->pci_read_config_word(vdev->DeviceContext, where, wVal)
 
#define pci_read_config_dword(vdev, where, dwVal)   vdev->system->pci_read_config_dword(vdev->DeviceContext, where, dwVal)
 
#define pci_get_resource_len(vdev, bar)   vdev->system->pci_get_resource_len(vdev->DeviceContext, bar)
 
#define pci_map_address_range(vdev, bar, offset, maxlen)   vdev->system->pci_map_address_range(vdev->DeviceContext, bar, offset, maxlen)
 
#define vdev_get_msix_vector(vdev, queue)   vdev->system->vdev_get_msix_vector(vdev->DeviceContext, queue)
 
#define vdev_sleep(vdev, msecs)   vdev->system->vdev_sleep(vdev->DeviceContext, msecs)
 

Functions

void vp_notify (struct virtqueue *vq)
 
NTSTATUS vio_legacy_initialize (VirtIODevice *vdev)
 
NTSTATUS vio_modern_initialize (VirtIODevice *vdev)
 

Macro Definition Documentation

◆ ioread16

#define ioread16 (   vdev,
  addr 
)    vdev->system->vdev_read_word((ULONG_PTR)(addr))

Definition at line 40 of file virtio_pci_common.h.

◆ ioread32

#define ioread32 (   vdev,
  addr 
)    vdev->system->vdev_read_dword((ULONG_PTR)(addr))

Definition at line 42 of file virtio_pci_common.h.

◆ ioread8

#define ioread8 (   vdev,
  addr 
)    vdev->system->vdev_read_byte((ULONG_PTR)(addr))

Definition at line 38 of file virtio_pci_common.h.

◆ iowrite16

#define iowrite16 (   vdev,
  val,
  addr 
)    vdev->system->vdev_write_word((ULONG_PTR)(addr), val)

Definition at line 46 of file virtio_pci_common.h.

◆ iowrite32

#define iowrite32 (   vdev,
  val,
  addr 
)    vdev->system->vdev_write_dword((ULONG_PTR)(addr), val)

Definition at line 48 of file virtio_pci_common.h.

◆ iowrite64_twopart

#define iowrite64_twopart (   vdev,
  val,
  lo_addr,
  hi_addr 
)
Value:
vdev->system->vdev_write_dword((ULONG_PTR)(lo_addr), (u32)(val)); \
vdev->system->vdev_write_dword((ULONG_PTR)(hi_addr), (val) >> 32)
ULONG32 u32
Definition: btrfs.h:14
uint32_t ULONG_PTR
Definition: typedefs.h:65
GLuint GLfloat * val
Definition: glext.h:7180

Definition at line 50 of file virtio_pci_common.h.

◆ iowrite8

#define iowrite8 (   vdev,
  val,
  addr 
)    vdev->system->vdev_write_byte((ULONG_PTR)(addr), val)

Definition at line 44 of file virtio_pci_common.h.

◆ mem_alloc_contiguous_pages

#define mem_alloc_contiguous_pages (   vdev,
  size 
)    vdev->system->mem_alloc_contiguous_pages(vdev->DeviceContext, size)

Definition at line 54 of file virtio_pci_common.h.

◆ mem_alloc_nonpaged_block

#define mem_alloc_nonpaged_block (   vdev,
  size 
)    vdev->system->mem_alloc_nonpaged_block(vdev->DeviceContext, size)

Definition at line 60 of file virtio_pci_common.h.

◆ mem_free_contiguous_pages

#define mem_free_contiguous_pages (   vdev,
  virt 
)    vdev->system->mem_free_contiguous_pages(vdev->DeviceContext, virt)

Definition at line 56 of file virtio_pci_common.h.

◆ mem_free_nonpaged_block

#define mem_free_nonpaged_block (   vdev,
  addr 
)    vdev->system->mem_free_nonpaged_block(vdev->DeviceContext, addr)

Definition at line 62 of file virtio_pci_common.h.

◆ mem_get_physical_address

#define mem_get_physical_address (   vdev,
  virt 
)    vdev->system->mem_get_physical_address(vdev->DeviceContext, virt)

Definition at line 58 of file virtio_pci_common.h.

◆ pci_get_resource_len

#define pci_get_resource_len (   vdev,
  bar 
)    vdev->system->pci_get_resource_len(vdev->DeviceContext, bar)

Definition at line 72 of file virtio_pci_common.h.

◆ pci_map_address_range

#define pci_map_address_range (   vdev,
  bar,
  offset,
  maxlen 
)    vdev->system->pci_map_address_range(vdev->DeviceContext, bar, offset, maxlen)

Definition at line 74 of file virtio_pci_common.h.

◆ pci_read_config_byte

#define pci_read_config_byte (   vdev,
  where,
  bVal 
)    vdev->system->pci_read_config_byte(vdev->DeviceContext, where, bVal)

Definition at line 65 of file virtio_pci_common.h.

◆ pci_read_config_dword

#define pci_read_config_dword (   vdev,
  where,
  dwVal 
)    vdev->system->pci_read_config_dword(vdev->DeviceContext, where, dwVal)

Definition at line 69 of file virtio_pci_common.h.

◆ pci_read_config_word

#define pci_read_config_word (   vdev,
  where,
  wVal 
)    vdev->system->pci_read_config_word(vdev->DeviceContext, where, wVal)

Definition at line 67 of file virtio_pci_common.h.

◆ vdev_get_msix_vector

#define vdev_get_msix_vector (   vdev,
  queue 
)    vdev->system->vdev_get_msix_vector(vdev->DeviceContext, queue)

Definition at line 77 of file virtio_pci_common.h.

◆ vdev_sleep

#define vdev_sleep (   vdev,
  msecs 
)    vdev->system->vdev_sleep(vdev->DeviceContext, msecs)

Definition at line 79 of file virtio_pci_common.h.

Function Documentation

◆ 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 
280  vdev->device = &virtio_pci_device_ops;
281 
282  return STATUS_SUCCESS;
283 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define pci_map_address_range(vdev, bar, offset, maxlen)
volatile u8 * isr
Definition: virtio_pci.h:260
#define pci_get_resource_len(vdev, bar)
#define VIRTIO_PCI_ISR
Definition: virtio_pci.h:71
const struct virtio_device_ops * device
Definition: virtio_pci.h:251
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UCHAR u8
Definition: btrfs.h:12
static const struct virtio_device_ops virtio_pci_device_ops
#define ULONG_PTR
Definition: config.h:101
return STATUS_SUCCESS
Definition: btrfs.c:3014
ULONG_PTR addr
Definition: virtio_pci.h:239

Referenced by virtio_device_initialize().

◆ vio_modern_initialize()

NTSTATUS vio_modern_initialize ( VirtIODevice vdev)

Definition at line 511 of file VirtIOPCIModern.c.

512 {
513  int capabilities[VIRTIO_PCI_CAP_PCI_CFG];
514 
515  u32 notify_length;
516  u32 notify_offset;
517 
518  RtlZeroMemory(capabilities, sizeof(capabilities));
520 
521  /* Check for a common config, if not found use legacy mode */
522  if (!capabilities[VIRTIO_PCI_CAP_COMMON_CFG]) {
523  DPrintf(0, "%s(%p): device not found\n", __FUNCTION__, vdev);
525  }
526 
527  /* Check isr and notify caps, if not found fail */
528  if (!capabilities[VIRTIO_PCI_CAP_ISR_CFG] || !capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG]) {
529  DPrintf(0, "%s(%p): missing capabilities %i/%i/%i\n",
530  __FUNCTION__, vdev,
531  capabilities[VIRTIO_PCI_CAP_COMMON_CFG],
532  capabilities[VIRTIO_PCI_CAP_ISR_CFG],
533  capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG]);
535  }
536 
537  /* Map bars according to the capabilities */
539  capabilities[VIRTIO_PCI_CAP_COMMON_CFG],
540  sizeof(struct virtio_pci_common_cfg), 4);
541  if (!vdev->common) {
543  }
544 
546  capabilities[VIRTIO_PCI_CAP_ISR_CFG],
547  sizeof(u8), 1);
548  if (!vdev->isr) {
550  }
551 
552  /* Read notify_off_multiplier from config space. */
555  notify_off_multiplier),
556  &vdev->notify_offset_multiplier);
557 
558  /* Read notify length and offset from config space. */
561  cap.length),
562  &notify_length);
565  cap.offset),
566  &notify_offset);
567 
568  /* Map the notify capability if it's small enough.
569  * Otherwise, map each VQ individually later.
570  */
571  if (notify_length + (notify_offset % PAGE_SIZE) <= PAGE_SIZE) {
573  capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG], 2, 2,
574  0, notify_length,
575  &vdev->notify_len);
576  if (!vdev->notify_base) {
578  }
579  } else {
580  vdev->notify_map_cap = capabilities[VIRTIO_PCI_CAP_NOTIFY_CFG];
581  }
582 
583  /* Map the device config capability, the PAGE_SIZE size is a guess */
584  if (capabilities[VIRTIO_PCI_CAP_DEVICE_CFG]) {
585  vdev->config = vio_modern_map_capability(vdev,
586  capabilities[VIRTIO_PCI_CAP_DEVICE_CFG], 0, 4,
587  0, PAGE_SIZE,
588  &vdev->config_len);
589  if (!vdev->config) {
591  }
592  }
593 
594  vdev->device = &virtio_pci_device_ops;
595 
596  return STATUS_SUCCESS;
597 }
#define pci_read_config_dword(vdev, where, dwVal)
#define VIRTIO_PCI_CAP_NOTIFY_CFG
Definition: virtio_pci.h:105
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define VIRTIO_PCI_CAP_COMMON_CFG
Definition: virtio_pci.h:103
volatile u8 * isr
Definition: virtio_pci.h:260
ULONG32 u32
Definition: btrfs.h:14
int notify_map_cap
Definition: virtio_pci.h:266
u32 notify_offset_multiplier
Definition: virtio_pci.h:267
GLenum cap
Definition: glext.h:9639
volatile unsigned char * config
Definition: virtio_pci.h:264
const struct virtio_device_ops * device
Definition: virtio_pci.h:251
volatile unsigned char * notify_base
Definition: virtio_pci.h:265
size_t notify_len
Definition: virtio_pci.h:270
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
#define offsetof(TYPE, MEMBER)
static void * vio_modern_map_capability(VirtIODevice *vdev, int cap_offset, size_t minlen, u32 alignment, u32 start, u32 size, size_t *len)
#define VIRTIO_PCI_CAP_DEVICE_CFG
Definition: virtio_pci.h:109
static void * vio_modern_map_simple_capability(VirtIODevice *vdev, int cap_offset, size_t length, u32 alignment)
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
volatile struct virtio_pci_common_cfg * common
Definition: virtio_pci.h:263
UCHAR u8
Definition: btrfs.h:12
#define VIRTIO_PCI_CAP_PCI_CFG
Definition: virtio_pci.h:111
#define PAGE_SIZE
Definition: env_spec_w32.h:49
static const struct virtio_device_ops virtio_pci_device_ops
static void find_pci_vendor_capabilities(VirtIODevice *vdev, int *Offsets, size_t nOffsets)
size_t config_len
Definition: virtio_pci.h:269
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define __FUNCTION__
Definition: types.h:112
#define VIRTIO_PCI_CAP_ISR_CFG
Definition: virtio_pci.h:107

Referenced by virtio_device_initialize().

◆ vp_notify()

void vp_notify ( struct virtqueue vq)

Definition at line 393 of file VirtIOPCICommon.c.

394 {
395  /* we write the queue's selector into the notification register to
396  * signal the other end */
397  iowrite16(vq->vdev, (unsigned short)vq->index, vq->notification_addr);
398  DPrintf(6, "virtio: vp_notify vq->index = %x\n", vq->index);
399 }
void * notification_addr
Definition: VirtIO.h:47
unsigned int index
Definition: VirtIO.h:45
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
VirtIODevice * vdev
Definition: VirtIO.h:44
#define iowrite16(vdev, val, addr)

Referenced by vio_legacy_setup_vq(), and vio_modern_setup_vq().