ReactOS  0.4.15-dev-1636-gf634010
ParaNdis-VirtIO.c File Reference
#include "ndis56common.h"
Include dependency graph for ParaNdis-VirtIO.c:

Go to the source code of this file.

Macros

#define PORT_MASK   0xFFFF
 

Functions

static u32 ReadVirtIODeviceRegister (ULONG_PTR ulRegister)
 
static void WriteVirtIODeviceRegister (ULONG_PTR ulRegister, u32 ulValue)
 
static u8 ReadVirtIODeviceByte (ULONG_PTR ulRegister)
 
static void WriteVirtIODeviceByte (ULONG_PTR ulRegister, u8 bValue)
 
static u16 ReadVirtIODeviceWord (ULONG_PTR ulRegister)
 
static void WriteVirtIODeviceWord (ULONG_PTR ulRegister, u16 wValue)
 
static voidmem_alloc_contiguous_pages (void *context, size_t size)
 
static void mem_free_contiguous_pages (void *context, void *virt)
 
static ULONGLONG mem_get_physical_address (void *context, void *virt)
 
static voidmem_alloc_nonpaged_block (void *context, size_t size)
 
static void mem_free_nonpaged_block (void *context, void *addr)
 
static int PCIReadConfig (PPARANDIS_ADAPTER pContext, int where, void *buffer, size_t length)
 
static int pci_read_config_byte (void *context, int where, u8 *bVal)
 
static int pci_read_config_word (void *context, int where, u16 *wVal)
 
static int pci_read_config_dword (void *context, int where, u32 *dwVal)
 
static size_t pci_get_resource_len (void *context, int bar)
 
static voidpci_map_address_range (void *context, int bar, size_t offset, size_t maxlen)
 
static u16 vdev_get_msix_vector (void *context, int queue)
 
static void vdev_sleep (void *context, unsigned int msecs)
 

Variables

VirtIOSystemOps ParaNdisSystemOps
 

Macro Definition Documentation

◆ PORT_MASK

#define PORT_MASK   0xFFFF

Definition at line 41 of file ParaNdis-VirtIO.c.

Function Documentation

◆ mem_alloc_contiguous_pages()

static void* mem_alloc_contiguous_pages ( void context,
size_t  size 
)
static

Definition at line 135 of file ParaNdis-VirtIO.c.

136 {
138  PVOID retVal = NULL;
139  ULONG i;
140 
141  /* find the first unused memory range of the requested size */
142  for (i = 0; i < MAX_NUM_OF_QUEUES; i++) {
143  if (pContext->SharedMemoryRanges[i].pBase != NULL &&
144  pContext->SharedMemoryRanges[i].bUsed == FALSE &&
145  pContext->SharedMemoryRanges[i].uLength == (ULONG)size) {
146  retVal = pContext->SharedMemoryRanges[i].pBase;
147  pContext->SharedMemoryRanges[i].bUsed = TRUE;
148  break;
149  }
150  }
151 
152  if (!retVal) {
153  /* find the first null memory range descriptor and allocate */
154  for (i = 0; i < MAX_NUM_OF_QUEUES; i++) {
155  if (pContext->SharedMemoryRanges[i].pBase == NULL) {
156  break;
157  }
158  }
159  if (i < MAX_NUM_OF_QUEUES) {
161  pContext->MiniportHandle,
162  (ULONG)size,
163  TRUE /* Cached */,
164  &pContext->SharedMemoryRanges[i].pBase,
165  &pContext->SharedMemoryRanges[i].BasePA);
166  retVal = pContext->SharedMemoryRanges[i].pBase;
167  if (retVal) {
168  NdisZeroMemory(retVal, size);
169  pContext->SharedMemoryRanges[i].uLength = (ULONG)size;
170  pContext->SharedMemoryRanges[i].bUsed = TRUE;
171  }
172  }
173  }
174 
175  if (retVal) {
176  DPrintf(6, ("[%s] returning %p, size %x\n", __FUNCTION__, retVal, (ULONG)size));
177  } else {
178  DPrintf(0, ("[%s] failed to allocate size %x\n", __FUNCTION__, (ULONG)size));
179  }
180  return retVal;
181 }
VOID EXPORT NdisMAllocateSharedMemory(IN NDIS_HANDLE MiniportAdapterHandle, IN ULONG Length, IN BOOLEAN Cached, OUT PVOID *VirtualAddress, OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress)
Definition: memory.c:148
Definition: http.c:7251
#define TRUE
Definition: types.h:120
tBusResource SharedMemoryRanges[MAX_NUM_OF_QUEUES]
Definition: ndis56common.h:352
NDIS_PHYSICAL_ADDRESS BasePA
Definition: ndis56common.h:161
#define FALSE
Definition: types.h:117
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
GLsizeiptr size
Definition: glext.h:5919
NDIS_HANDLE MiniportHandle
Definition: ndis56common.h:349
#define MAX_NUM_OF_QUEUES
Definition: ndis56common.h:93
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
#define NULL
Definition: types.h:112
#define NdisZeroMemory(Destination, Length)
Definition: ndis.h:3926
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: types.h:112

◆ mem_alloc_nonpaged_block()

static void* mem_alloc_nonpaged_block ( void context,
size_t  size 
)
static

Definition at line 222 of file ParaNdis-VirtIO.c.

223 {
224  PVOID retVal;
225 
227  &retVal,
228  (UINT)size,
230  retVal = NULL;
231  }
232 
233  if (retVal) {
234  NdisZeroMemory(retVal, size);
235  DPrintf(6, ("[%s] returning %p, len %x\n", __FUNCTION__, retVal, (ULONG)size));
236  } else {
237  DPrintf(0, ("[%s] failed to allocate size %x\n", __FUNCTION__, (ULONG)size));
238  }
239  return retVal;
240 }
NDIS_STATUS EXPORT NdisAllocateMemoryWithTag(OUT PVOID *VirtualAddress, IN UINT Length, IN ULONG Tag)
Definition: memory.c:21
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
GLsizeiptr size
Definition: glext.h:5919
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define NdisZeroMemory(Destination, Length)
Definition: ndis.h:3926
unsigned int ULONG
Definition: retypes.h:1
#define PARANDIS_MEMORY_TAG
Definition: ndis56common.h:120
#define __FUNCTION__
Definition: types.h:112

◆ mem_free_contiguous_pages()

static void mem_free_contiguous_pages ( void context,
void virt 
)
static

Definition at line 183 of file ParaNdis-VirtIO.c.

184 {
186  ULONG i;
187 
188  for (i = 0; i < MAX_NUM_OF_QUEUES; i++) {
189  if (pContext->SharedMemoryRanges[i].pBase == virt) {
190  pContext->SharedMemoryRanges[i].bUsed = FALSE;
191  break;
192  }
193  }
194 
195  if (i < MAX_NUM_OF_QUEUES) {
196  DPrintf(6, ("[%s] freed %p at index %d\n", __FUNCTION__, virt, i));
197  } else {
198  DPrintf(0, ("[%s] failed to free %p\n", __FUNCTION__, virt));
199  }
200 }
Definition: http.c:7251
tBusResource SharedMemoryRanges[MAX_NUM_OF_QUEUES]
Definition: ndis56common.h:352
#define FALSE
Definition: types.h:117
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
#define MAX_NUM_OF_QUEUES
Definition: ndis56common.h:93
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
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: types.h:112

◆ mem_free_nonpaged_block()

static void mem_free_nonpaged_block ( void context,
void addr 
)
static

Definition at line 242 of file ParaNdis-VirtIO.c.

243 {
245 
246  NdisFreeMemory(addr, 0, 0);
247  DPrintf(6, ("[%s] freed %p\n", __FUNCTION__, addr));
248 }
Definition: http.c:7251
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
GLenum const GLvoid * addr
Definition: glext.h:9621
#define __FUNCTION__
Definition: types.h:112
VOID EXPORT NdisFreeMemory(IN PVOID VirtualAddress, IN UINT Length, IN UINT MemoryFlags)
Definition: memory.c:110

◆ mem_get_physical_address()

static ULONGLONG mem_get_physical_address ( void context,
void virt 
)
static

Definition at line 202 of file ParaNdis-VirtIO.c.

203 {
205  ULONG_PTR uAddr = (ULONG_PTR)virt;
206  ULONG i;
207 
208  for (i = 0; i < MAX_NUM_OF_QUEUES; i++) {
209  ULONG_PTR uBase = (ULONG_PTR)pContext->SharedMemoryRanges[i].pBase;
210  if (uAddr >= uBase && uAddr < (uBase + pContext->SharedMemoryRanges[i].uLength)) {
211  ULONGLONG retVal = pContext->SharedMemoryRanges[i].BasePA.QuadPart + (uAddr - uBase);
212 
213  DPrintf(6, ("[%s] translated %p to %I64X\n", __FUNCTION__, virt, retVal));
214  return retVal;
215  }
216  }
217 
218  DPrintf(0, ("[%s] failed to translate %p\n", __FUNCTION__, virt));
219  return 0;
220 }
Definition: http.c:7251
tBusResource SharedMemoryRanges[MAX_NUM_OF_QUEUES]
Definition: ndis56common.h:352
NDIS_PHYSICAL_ADDRESS BasePA
Definition: ndis56common.h:161
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
if(!(yy_init))
Definition: macro.lex.yy.c:714
uint64_t ULONGLONG
Definition: typedefs.h:67
#define MAX_NUM_OF_QUEUES
Definition: ndis56common.h:93
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
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define __FUNCTION__
Definition: types.h:112
LONGLONG QuadPart
Definition: typedefs.h:114

◆ pci_get_resource_len()

static size_t pci_get_resource_len ( void context,
int  bar 
)
static

Definition at line 288 of file ParaNdis-VirtIO.c.

289 {
291 
292  if (bar < PCI_TYPE0_ADDRESSES) {
293  return pContext->AdapterResources.PciBars[bar].uLength;
294  }
295 
296  DPrintf(0, ("[%s] queried invalid BAR %d\n", __FUNCTION__, bar));
297  return 0;
298 }
#define PCI_TYPE0_ADDRESSES
Definition: iotypes.h:3496
tAdapterResources AdapterResources
Definition: ndis56common.h:351
Definition: http.c:7251
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
void bar()
Definition: ehthrow.cxx:142
#define __FUNCTION__
Definition: types.h:112
tBusResource PciBars[PCI_TYPE0_ADDRESSES]
Definition: ndis56common.h:170

◆ pci_map_address_range()

static void* pci_map_address_range ( void context,
int  bar,
size_t  offset,
size_t  maxlen 
)
static

Definition at line 300 of file ParaNdis-VirtIO.c.

301 {
303 
304  if (bar < PCI_TYPE0_ADDRESSES) {
305  tBusResource *pRes = &pContext->AdapterResources.PciBars[bar];
306  if (pRes->pBase == NULL) {
307  /* BAR not mapped yet */
308  if (pRes->bPortSpace) {
310  &pRes->pBase,
311  pContext->MiniportHandle,
312  pRes->BasePA.LowPart,
313  pRes->uLength)) {
314  DPrintf(6, ("[%s] mapped port BAR at %x\n", __FUNCTION__, pRes->BasePA.LowPart));
315  } else {
316  pRes->pBase = NULL;
317  DPrintf(0, ("[%s] failed to map port BAR at %x\n", __FUNCTION__, pRes->BasePA.LowPart));
318  }
319  } else {
321  &pRes->pBase,
322  pContext->MiniportHandle,
323  pRes->BasePA,
324  pRes->uLength)) {
325  DPrintf(6, ("[%s] mapped memory BAR at %I64x\n", __FUNCTION__, pRes->BasePA.QuadPart));
326  } else {
327  pRes->pBase = NULL;
328  DPrintf(0, ("[%s] failed to map memory BAR at %I64x\n", __FUNCTION__, pRes->BasePA.QuadPart));
329  }
330  }
331  }
332  if (pRes->pBase != NULL && offset < pRes->uLength) {
333  if (pRes->bPortSpace) {
334  /* use physical address for port I/O */
335  return (PUCHAR)(ULONG_PTR)pRes->BasePA.LowPart + offset;
336  } else {
337  /* use virtual address for memory I/O */
338  return (PUCHAR)pRes->pBase + offset;
339  }
340  } else {
341  DPrintf(0, ("[%s] failed to get map BAR %d, offset %x\n", __FUNCTION__, bar, offset));
342  }
343  } else {
344  DPrintf(0, ("[%s] queried invalid BAR %d\n", __FUNCTION__, bar));
345  }
346 
347  return NULL;
348 }
#define PCI_TYPE0_ADDRESSES
Definition: iotypes.h:3496
tAdapterResources AdapterResources
Definition: ndis56common.h:351
Definition: http.c:7251
NDIS_STATUS EXPORT NdisMRegisterIoPortRange(OUT PVOID *PortOffset, IN NDIS_HANDLE MiniportAdapterHandle, IN UINT InitialPort, IN UINT NumberOfPorts)
Definition: io.c:1018
unsigned char * PUCHAR
Definition: retypes.h:3
NDIS_PHYSICAL_ADDRESS BasePA
Definition: ndis56common.h:161
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
BOOLEAN bPortSpace
Definition: ndis56common.h:164
void bar()
Definition: ehthrow.cxx:142
GLintptr offset
Definition: glext.h:5920
NDIS_HANDLE MiniportHandle
Definition: ndis56common.h:349
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
ULONG LowPart
Definition: typedefs.h:106
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
NDIS_STATUS EXPORT NdisMMapIoSpace(OUT PVOID *VirtualAddress, IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_PHYSICAL_ADDRESS PhysicalAddress, IN UINT Length)
Definition: io.c:774
#define __FUNCTION__
Definition: types.h:112
LONGLONG QuadPart
Definition: typedefs.h:114
tBusResource PciBars[PCI_TYPE0_ADDRESSES]
Definition: ndis56common.h:170

◆ pci_read_config_byte()

static int pci_read_config_byte ( void context,
int  where,
u8 bVal 
)
static

Definition at line 273 of file ParaNdis-VirtIO.c.

274 {
275  return PCIReadConfig((PPARANDIS_ADAPTER)context, where, bVal, sizeof(*bVal));
276 }
Definition: http.c:7251
static int PCIReadConfig(PPARANDIS_ADAPTER pContext, int where, void *buffer, size_t length)

◆ pci_read_config_dword()

static int pci_read_config_dword ( void context,
int  where,
u32 dwVal 
)
static

Definition at line 283 of file ParaNdis-VirtIO.c.

284 {
285  return PCIReadConfig((PPARANDIS_ADAPTER)context, where, dwVal, sizeof(*dwVal));
286 }
Definition: http.c:7251
static int PCIReadConfig(PPARANDIS_ADAPTER pContext, int where, void *buffer, size_t length)

◆ pci_read_config_word()

static int pci_read_config_word ( void context,
int  where,
u16 wVal 
)
static

Definition at line 278 of file ParaNdis-VirtIO.c.

279 {
280  return PCIReadConfig((PPARANDIS_ADAPTER)context, where, wVal, sizeof(*wVal));
281 }
Definition: http.c:7251
static int PCIReadConfig(PPARANDIS_ADAPTER pContext, int where, void *buffer, size_t length)

◆ PCIReadConfig()

static int PCIReadConfig ( PPARANDIS_ADAPTER  pContext,
int  where,
void buffer,
size_t  length 
)
static

Definition at line 250 of file ParaNdis-VirtIO.c.

254 {
255  ULONG read;
256 
258  pContext->MiniportHandle,
259  0 /* SlotNumber */,
260  where,
261  buffer,
262  (ULONG)length);
263 
264  if (read == length) {
265  DPrintf(6, ("[%s] read %d bytes at %d\n", __FUNCTION__, read, where));
266  return 0;
267  } else {
268  DPrintf(0, ("[%s] failed to read %d bytes at %d\n", __FUNCTION__, read, where));
269  return -1;
270  }
271 }
GLuint buffer
Definition: glext.h:5915
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
NDIS_HANDLE MiniportHandle
Definition: ndis56common.h:349
ULONG EXPORT NdisReadPciSlotInformation(IN NDIS_HANDLE NdisAdapterHandle, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length)
Definition: hardware.c:180
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: types.h:112
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by pci_read_config_byte(), pci_read_config_dword(), and pci_read_config_word().

◆ ReadVirtIODeviceByte()

static u8 ReadVirtIODeviceByte ( ULONG_PTR  ulRegister)
static

Definition at line 68 of file ParaNdis-VirtIO.c.

69 {
70  u8 bValue;
71 
72  if (ulRegister & ~PORT_MASK) {
73  NdisReadRegisterUchar(ulRegister, &bValue);
74  } else {
75  NdisRawReadPortUchar(ulRegister, &bValue);
76  }
77 
78  DPrintf(6, ("[%s]R[%x]=%x", __FUNCTION__, (ULONG)ulRegister, bValue));
79  return bValue;
80 }
#define NdisReadRegisterUchar(Register, Data)
Definition: ndis.h:4258
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
UCHAR u8
Definition: btrfs.h:12
unsigned int ULONG
Definition: retypes.h:1
#define NdisRawReadPortUchar(Port, Data)
Definition: ndis.h:4173
#define __FUNCTION__
Definition: types.h:112
#define PORT_MASK

◆ ReadVirtIODeviceRegister()

static u32 ReadVirtIODeviceRegister ( ULONG_PTR  ulRegister)
static

Definition at line 43 of file ParaNdis-VirtIO.c.

44 {
45  ULONG ulValue;
46 
47  if (ulRegister & ~PORT_MASK) {
48  NdisReadRegisterUlong(ulRegister, &ulValue);
49  } else {
50  NdisRawReadPortUlong(ulRegister, &ulValue);
51  }
52 
53  DPrintf(6, ("[%s]R[%x]=%x", __FUNCTION__, (ULONG)ulRegister, ulValue));
54  return ulValue;
55 }
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
#define NdisRawReadPortUlong(Port, Data)
Definition: ndis.h:4182
#define NdisReadRegisterUlong(Register, Data)
Definition: ndis.h:4267
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: types.h:112
#define PORT_MASK

◆ ReadVirtIODeviceWord()

static u16 ReadVirtIODeviceWord ( ULONG_PTR  ulRegister)
static

Definition at line 93 of file ParaNdis-VirtIO.c.

94 {
95  u16 wValue;
96 
97  if (ulRegister & ~PORT_MASK) {
98  NdisReadRegisterUshort(ulRegister, &wValue);
99  } else {
100  NdisRawReadPortUshort(ulRegister, &wValue);
101  }
102 
103  DPrintf(6, ("[%s]R[%x]=%x\n", __FUNCTION__, (ULONG)ulRegister, wValue));
104  return wValue;
105 }
#define NdisRawReadPortUshort(Port, Data)
Definition: ndis.h:4191
#define NdisReadRegisterUshort(Register, Data)
Definition: ndis.h:4276
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
unsigned int ULONG
Definition: retypes.h:1
USHORT u16
Definition: btrfs.h:13
#define __FUNCTION__
Definition: types.h:112
#define PORT_MASK

◆ vdev_get_msix_vector()

static u16 vdev_get_msix_vector ( void context,
int  queue 
)
static

Definition at line 350 of file ParaNdis-VirtIO.c.

351 {
354 
355  /* we don't run on MSI support so this will never be true */
356  if (pContext->bUsingMSIX && queue >= 0) {
357  vector = (u16)pContext->AdapterResources.Vector;
358  }
359 
360  return vector;
361 }
tAdapterResources AdapterResources
Definition: ndis56common.h:351
Definition: http.c:7251
Definition: _queue.h:59
#define u16
Definition: types.h:8
#define VIRTIO_MSI_NO_VECTOR
Definition: virtio_pci.h:98
USHORT u16
Definition: btrfs.h:13

◆ vdev_sleep()

static void vdev_sleep ( void context,
unsigned int  msecs 
)
static

Definition at line 363 of file ParaNdis-VirtIO.c.

364 {
366 
367  NdisMSleep(1000 * msecs);
368 }
Definition: http.c:7251
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
VOID EXPORT NdisMSleep(IN ULONG MicrosecondsToSleep)
Definition: miniport.c:2928

◆ WriteVirtIODeviceByte()

static void WriteVirtIODeviceByte ( ULONG_PTR  ulRegister,
u8  bValue 
)
static

Definition at line 82 of file ParaNdis-VirtIO.c.

83 {
84  DPrintf(6, ("[%s]R[%x]=%x", __FUNCTION__, (ULONG)ulRegister, bValue));
85 
86  if (ulRegister & ~PORT_MASK) {
87  NdisWriteRegisterUchar((PUCHAR)ulRegister, bValue);
88  } else {
89  NdisRawWritePortUchar(ulRegister, bValue);
90  }
91 }
#define NdisRawWritePortUchar(Port, Data)
Definition: ndis.h:4230
unsigned char * PUCHAR
Definition: retypes.h:3
#define NdisWriteRegisterUchar(Register, Data)
Definition: ndis.h:4285
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: types.h:112
#define PORT_MASK

Referenced by CheckRunningDpc(), and ParaNdis_CallOnBugCheck().

◆ WriteVirtIODeviceRegister()

static void WriteVirtIODeviceRegister ( ULONG_PTR  ulRegister,
u32  ulValue 
)
static

Definition at line 57 of file ParaNdis-VirtIO.c.

58 {
59  DPrintf(6, ("[%s]R[%x]=%x", __FUNCTION__, (ULONG)ulRegister, ulValue));
60 
61  if (ulRegister & ~PORT_MASK) {
62  NdisWriteRegisterUlong((PULONG)ulRegister, ulValue);
63  } else {
64  NdisRawWritePortUlong(ulRegister, ulValue);
65  }
66 }
#define NdisWriteRegisterUlong(Register, Data)
Definition: ndis.h:4294
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: types.h:112
#define PORT_MASK
#define NdisRawWritePortUlong(Port, Data)
Definition: ndis.h:4239

◆ WriteVirtIODeviceWord()

static void WriteVirtIODeviceWord ( ULONG_PTR  ulRegister,
u16  wValue 
)
static

Definition at line 107 of file ParaNdis-VirtIO.c.

108 {
109 #if 1
110  if (ulRegister & ~PORT_MASK) {
111  NdisWriteRegisterUshort((PUSHORT)ulRegister, wValue);
112  } else {
113  NdisRawWritePortUshort(ulRegister, wValue);
114  }
115 #else
116  // test only to cause long TX waiting queue of NDIS packets
117  // to recognize it and request for reset via Hang handler
118  static int nCounterToFail = 0;
119  static const int StartFail = 200, StopFail = 600;
120  BOOLEAN bFail = FALSE;
121  DPrintf(6, ("%s> R[%x] = %x\n", __FUNCTION__, (ULONG)ulRegister, wValue));
122  if ((ulRegister & 0x1F) == 0x10)
123  {
124  nCounterToFail++;
125  bFail = nCounterToFail >= StartFail && nCounterToFail < StopFail;
126  }
127  if (!bFail) NdisRawWritePortUshort(ulRegister, wValue);
128  else
129  {
130  DPrintf(0, ("%s> FAILING R[%x] = %x\n", __FUNCTION__, (ULONG)ulRegister, wValue));
131  }
132 #endif
133 }
#define NdisWriteRegisterUshort(Register, Data)
Definition: ndis.h:4303
#define FALSE
Definition: types.h:117
#define NdisRawWritePortUshort(Port, Data)
Definition: ndis.h:4248
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
unsigned char BOOLEAN
unsigned int ULONG
Definition: retypes.h:1
#define __FUNCTION__
Definition: types.h:112
unsigned short * PUSHORT
Definition: retypes.h:2
#define PORT_MASK

Variable Documentation

◆ ParaNdisSystemOps

VirtIOSystemOps ParaNdisSystemOps
Initial value:
= {
}
static void WriteVirtIODeviceWord(ULONG_PTR ulRegister, u16 wValue)
static u16 ReadVirtIODeviceWord(ULONG_PTR ulRegister)
static int pci_read_config_dword(void *context, int where, u32 *dwVal)
static u32 ReadVirtIODeviceRegister(ULONG_PTR ulRegister)
static void vdev_sleep(void *context, unsigned int msecs)
static int pci_read_config_byte(void *context, int where, u8 *bVal)
static void * mem_alloc_nonpaged_block(void *context, size_t size)
static void * mem_alloc_contiguous_pages(void *context, size_t size)
static void mem_free_nonpaged_block(void *context, void *addr)
static ULONGLONG mem_get_physical_address(void *context, void *virt)
static size_t pci_get_resource_len(void *context, int bar)
static void mem_free_contiguous_pages(void *context, void *virt)
static void * pci_map_address_range(void *context, int bar, size_t offset, size_t maxlen)
static u16 vdev_get_msix_vector(void *context, int queue)
static void WriteVirtIODeviceByte(ULONG_PTR ulRegister, u8 bValue)
static u8 ReadVirtIODeviceByte(ULONG_PTR ulRegister)
static void WriteVirtIODeviceRegister(ULONG_PTR ulRegister, u32 ulValue)
static int pci_read_config_word(void *context, int where, u16 *wVal)

Definition at line 370 of file ParaNdis-VirtIO.c.

Referenced by ParaNdis_InitializeContext().