ReactOS 0.4.16-dev-2354-g16de117
resource.c File Reference
#include "videoprt.h"
#include <debug.h>
Include dependency graph for resource.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI IntVideoPortGetLegacyResources (IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension, IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, OUT PVIDEO_ACCESS_RANGE *AccessRanges, OUT PULONG AccessRangeCount)
 
NTSTATUS NTAPI IntVideoPortFilterResourceRequirements (IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IrpStack, IN PIRP Irp)
 
VOID IntVideoPortReleaseResources (_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI IntVideoPortMapPhysicalMemory (IN HANDLE Process, IN PHYSICAL_ADDRESS PhysicalAddress, IN ULONG SizeInBytes, IN ULONG Protect, IN OUT PVOID *VirtualAddress OPTIONAL)
 
static BOOLEAN IntAccessRangeIsInAllocatedResources (_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, _In_ PVIDEO_ACCESS_RANGE Range)
 
PVOID NTAPI IntVideoPortMapMemory (IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, IN PHYSICAL_ADDRESS IoAddress, IN ULONG NumberOfUchars, IN ULONG InIoSpace, IN HANDLE ProcessHandle, OUT VP_STATUS *Status)
 
VOID NTAPI IntVideoPortUnmapMemory (IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, IN PVOID MappedAddress)
 
PVOID NTAPI VideoPortGetDeviceBase (IN PVOID HwDeviceExtension, IN PHYSICAL_ADDRESS IoAddress, IN ULONG NumberOfUchars, IN UCHAR InIoSpace)
 
VOID NTAPI VideoPortFreeDeviceBase (IN PVOID HwDeviceExtension, IN PVOID MappedAddress)
 
VP_STATUS NTAPI VideoPortMapBankedMemory (IN PVOID HwDeviceExtension, IN PHYSICAL_ADDRESS PhysicalAddress, IN PULONG Length, IN PULONG InIoSpace, OUT PVOID *VirtualAddress, IN ULONG BankLength, IN UCHAR ReadWriteBank, IN PBANKED_SECTION_ROUTINE BankRoutine, IN PVOID Context)
 
VP_STATUS NTAPI VideoPortMapMemory (IN PVOID HwDeviceExtension, IN PHYSICAL_ADDRESS PhysicalAddress, IN PULONG Length, IN PULONG InIoSpace, OUT PVOID *VirtualAddress)
 
VP_STATUS NTAPI VideoPortUnmapMemory (IN PVOID HwDeviceExtension, IN PVOID VirtualAddress, IN HANDLE ProcessHandle)
 
VP_STATUS NTAPI VideoPortGetAccessRanges (_In_ PVOID HwDeviceExtension, _In_opt_ ULONG NumRequestedResources, _In_reads_opt_(NumRequestedResources) PIO_RESOURCE_DESCRIPTOR RequestedResources, _In_ ULONG NumAccessRanges, _Out_writes_(NumAccessRanges) PVIDEO_ACCESS_RANGE AccessRanges, _In_ PVOID VendorId, _In_ PVOID DeviceId, _Out_ PULONG Slot)
 Retrieves bus-relative (mainly PCI) hardware resources access ranges and, if possible, claims these resources for the caller.
 
VP_STATUS NTAPI VideoPortVerifyAccessRanges (_In_ PVOID HwDeviceExtension, _In_opt_ ULONG NumAccessRanges, _In_reads_opt_(NumAccessRanges) PVIDEO_ACCESS_RANGE AccessRanges)
 Claims or releases a range of hardware resources and checks for conflicts.
 
VP_STATUS NTAPI VideoPortGetDeviceData (IN PVOID HwDeviceExtension, IN VIDEO_DEVICE_DATA_TYPE DeviceDataType, IN PMINIPORT_QUERY_DEVICE_ROUTINE CallbackRoutine, IN PVOID Context)
 
PVOID NTAPI VideoPortAllocatePool (IN PVOID HwDeviceExtension, IN VP_POOL_TYPE PoolType, IN SIZE_T NumberOfBytes, IN ULONG Tag)
 
VOID NTAPI VideoPortFreePool (IN PVOID HwDeviceExtension, IN PVOID Ptr)
 
VP_STATUS NTAPI VideoPortAllocateBuffer (IN PVOID HwDeviceExtension, IN ULONG Size, OUT PVOID *Buffer)
 
VOID NTAPI VideoPortReleaseBuffer (IN PVOID HwDeviceExtension, IN PVOID Ptr)
 
PVOID NTAPI VideoPortLockBuffer (IN PVOID HwDeviceExtension, IN PVOID BaseAddress, IN ULONG Length, IN VP_LOCK_OPERATION Operation)
 
BOOLEAN NTAPI VideoPortLockPages (IN PVOID HwDeviceExtension, IN OUT PVIDEO_REQUEST_PACKET pVrp, IN PEVENT pUEvent, IN PEVENT pDisplayEvent, IN DMA_FLAGS DmaFlags)
 
VOID NTAPI VideoPortUnlockBuffer (IN PVOID HwDeviceExtension, IN PVOID Mdl)
 
VP_STATUS NTAPI VideoPortSetTrappedEmulatorPorts (IN PVOID HwDeviceExtension, IN ULONG NumAccessRanges, IN PVIDEO_ACCESS_RANGE AccessRange)
 
ULONG NTAPI VideoPortGetBusData (IN PVOID HwDeviceExtension, IN BUS_DATA_TYPE BusDataType, IN ULONG SlotNumber, OUT PVOID Buffer, IN ULONG Offset, IN ULONG Length)
 
ULONG NTAPI VideoPortSetBusData (IN PVOID HwDeviceExtension, IN BUS_DATA_TYPE BusDataType, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
 

Variables

BOOLEAN VpBaseVideo
 
static UNICODE_STRING VideoClassName = RTL_CONSTANT_STRING(L"VIDEO")
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 24 of file resource.c.

Function Documentation

◆ IntAccessRangeIsInAllocatedResources()

static BOOLEAN IntAccessRangeIsInAllocatedResources ( _In_ PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension,
_In_ PVIDEO_ACCESS_RANGE  Range 
)
static

Definition at line 294 of file resource.c.

297{
298 CM_RESOURCE_LIST *Res = DeviceExtension->AllocatedResources;
301
302 if (!Res || Res->Count == 0)
303 return FALSE;
304 Full = &Res->List[0];
305 for (Desc = Full->PartialResourceList.PartialDescriptors;
306 Desc < Full->PartialResourceList.PartialDescriptors + Full->PartialResourceList.Count;
307 ++Desc)
308 {
309 if (Range->RangeInIoSpace && Desc->Type == CmResourceTypePort)
310 {
311 if (Desc->u.Port.Start.QuadPart == Range->RangeStart.QuadPart &&
312 Desc->u.Port.Length == Range->RangeLength)
313 return TRUE;
314 }
315 else if (!Range->RangeInIoSpace && Desc->Type == CmResourceTypeMemory)
316 {
317 if (Desc->u.Memory.Start.QuadPart == Range->RangeStart.QuadPart &&
318 Desc->u.Memory.Length == Range->RangeLength)
319 return TRUE;
320 }
321 }
322 return FALSE;
323}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static BOOL Full
Definition: pageheap.c:12
#define CmResourceTypeMemory
Definition: restypes.h:106
#define CmResourceTypePort
Definition: restypes.h:104
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384::@386 Port
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384::@389 Memory
CM_FULL_RESOURCE_DESCRIPTOR List[1]
Definition: restypes.h:149

Referenced by VideoPortVerifyAccessRanges().

◆ IntVideoPortFilterResourceRequirements()

NTSTATUS NTAPI IntVideoPortFilterResourceRequirements ( IN PDEVICE_OBJECT  DeviceObject,
IN PIO_STACK_LOCATION  IrpStack,
IN PIRP  Irp 
)

Definition at line 81 of file resource.c.

85{
88 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
89 PVIDEO_ACCESS_RANGE AccessRanges;
90 ULONG AccessRangeCount, ListSize, i;
92 PIO_RESOURCE_REQUIREMENTS_LIST OldResList = IrpStack->Parameters.FilterResourceRequirements.IoResourceRequirementList;
93 PIO_RESOURCE_DESCRIPTOR CurrentDescriptor;
95
96 DriverObject = DeviceObject->DriverObject;
98 DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
99
100 Status = IntVideoPortGetLegacyResources(DriverExtension, DeviceExtension, &AccessRanges, &AccessRangeCount);
101 if (!NT_SUCCESS(Status))
102 return Status;
103 if (!AccessRangeCount)
104 {
105 /* No legacy resources to report */
106 return Irp->IoStatus.Status;
107 }
108
109 /* OK, we've got the access ranges now. Let's set up the resource requirements list */
110
111 if (OldResList)
112 {
113 /* Already one there so let's add to it */
114 ListSize = OldResList->ListSize + sizeof(IO_RESOURCE_DESCRIPTOR) * AccessRangeCount;
116 ListSize);
117 if (!ResList) return STATUS_NO_MEMORY;
118
119 RtlCopyMemory(ResList, OldResList, OldResList->ListSize);
120
121 ASSERT(ResList->AlternativeLists == 1);
122
123 ResList->ListSize = ListSize;
124 ResList->List[0].Count += AccessRangeCount;
125
126 CurrentDescriptor = (PIO_RESOURCE_DESCRIPTOR)((PUCHAR)ResList + OldResList->ListSize);
127
128 ExFreePool(OldResList);
129 Irp->IoStatus.Information = 0;
130 }
131 else
132 {
133 /* We need to make a new one */
134 ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + sizeof(IO_RESOURCE_DESCRIPTOR) * (AccessRangeCount - 1);
136 ListSize);
137 if (!ResList) return STATUS_NO_MEMORY;
138
139 RtlZeroMemory(ResList, ListSize);
140
141 /* We need to initialize some fields */
142 ResList->ListSize = ListSize;
143 ResList->InterfaceType = DeviceExtension->AdapterInterfaceType;
144 ResList->BusNumber = DeviceExtension->SystemIoBusNumber;
145 ResList->SlotNumber = DeviceExtension->SystemIoSlotNumber;
146 ResList->AlternativeLists = 1;
147 ResList->List[0].Version = 1;
148 ResList->List[0].Revision = 1;
149 ResList->List[0].Count = AccessRangeCount;
150
151 CurrentDescriptor = ResList->List[0].Descriptors;
152 }
153
154 for (i = 0; i < AccessRangeCount; i++)
155 {
156 /* This is a required resource */
157 CurrentDescriptor->Option = 0;
158
159 if (AccessRanges[i].RangeInIoSpace)
160 CurrentDescriptor->Type = CmResourceTypePort;
161 else
162 CurrentDescriptor->Type = CmResourceTypeMemory;
163
164 CurrentDescriptor->ShareDisposition =
166
167 CurrentDescriptor->Flags = 0;
168
169 if (CurrentDescriptor->Type == CmResourceTypePort)
170 {
171 CurrentDescriptor->u.Port.Length = AccessRanges[i].RangeLength;
172 CurrentDescriptor->u.Port.MinimumAddress = AccessRanges[i].RangeStart;
173 CurrentDescriptor->u.Port.MaximumAddress.QuadPart = AccessRanges[i].RangeStart.QuadPart + AccessRanges[i].RangeLength - 1;
174 CurrentDescriptor->u.Port.Alignment = 1;
175 if (AccessRanges[i].RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
176 CurrentDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
177 if (AccessRanges[i].RangePassive & VIDEO_RANGE_10_BIT_DECODE)
178 CurrentDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
179 }
180 else
181 {
182 CurrentDescriptor->u.Memory.Length = AccessRanges[i].RangeLength;
183 CurrentDescriptor->u.Memory.MinimumAddress = AccessRanges[i].RangeStart;
184 CurrentDescriptor->u.Memory.MaximumAddress.QuadPart = AccessRanges[i].RangeStart.QuadPart + AccessRanges[i].RangeLength - 1;
185 CurrentDescriptor->u.Memory.Alignment = 1;
186 CurrentDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
187 }
188
189 CurrentDescriptor++;
190 }
191
192 Irp->IoStatus.Information = (ULONG_PTR)ResList;
193
194 return STATUS_SUCCESS;
195}
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ULONG_PTR
Definition: config.h:101
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:25
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 ASSERT(a)
Definition: mode.c:44
#define CM_RESOURCE_MEMORY_READ_WRITE
Definition: cmtypes.h:121
#define CM_RESOURCE_PORT_PASSIVE_DECODE
Definition: cmtypes.h:114
#define CM_RESOURCE_PORT_10_BIT_DECODE
Definition: cmtypes.h:110
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1916
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31
struct _IO_RESOURCE_DESCRIPTOR * PIO_RESOURCE_DESCRIPTOR
struct _IO_RESOURCE_DESCRIPTOR IO_RESOURCE_DESCRIPTOR
#define VIDEO_RANGE_10_BIT_DECODE
Definition: video.h:99
#define VIDEO_RANGE_PASSIVE_DECODE
Definition: video.h:98
#define STATUS_SUCCESS
Definition: shellext.h:65
union _IO_RESOURCE_DESCRIPTOR::@2212 u
struct _IO_RESOURCE_DESCRIPTOR::@2212::@2214 Memory
struct _IO_RESOURCE_DESCRIPTOR::@2212::@2213 Port
IO_RESOURCE_DESCRIPTOR Descriptors[1]
Definition: iotypes.h:2739
INTERFACE_TYPE InterfaceType
Definition: iotypes.h:2744
IO_RESOURCE_LIST List[1]
Definition: iotypes.h:2749
ULONG RangeLength
Definition: video.h:216
UCHAR RangeShareable
Definition: video.h:219
PHYSICAL_ADDRESS RangeStart
Definition: video.h:215
INTERFACE_TYPE AdapterInterfaceType
Definition: videoprt.h:98
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
struct _VIDEO_PORT_DEVICE_EXTENSTION * PVIDEO_PORT_DEVICE_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
NTSTATUS NTAPI IntVideoPortGetLegacyResources(IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension, IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, OUT PVIDEO_ACCESS_RANGE *AccessRanges, OUT PULONG AccessRangeCount)
Definition: resource.c:34
@ CmResourceShareDeviceExclusive
Definition: cmtypes.h:241
@ CmResourceShareShared
Definition: cmtypes.h:243
struct _IO_RESOURCE_REQUIREMENTS_LIST IO_RESOURCE_REQUIREMENTS_LIST

Referenced by IntVideoPortDispatchFdoPnp().

◆ IntVideoPortGetLegacyResources()

NTSTATUS NTAPI IntVideoPortGetLegacyResources ( IN PVIDEO_PORT_DRIVER_EXTENSION  DriverExtension,
IN PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension,
OUT PVIDEO_ACCESS_RANGE AccessRanges,
OUT PULONG  AccessRangeCount 
)

Definition at line 34 of file resource.c.

39{
40 PCI_COMMON_CONFIG PciConfig;
42
43 if (!DriverExtension->InitializationData.HwGetLegacyResources &&
44 !DriverExtension->InitializationData.HwLegacyResourceCount)
45 {
46 /* No legacy resources to report */
47 *AccessRangeCount = 0;
48 return STATUS_SUCCESS;
49 }
50
51 if (DriverExtension->InitializationData.HwGetLegacyResources)
52 {
54 DeviceExtension->SystemIoBusNumber,
55 DeviceExtension->SystemIoSlotNumber,
56 &PciConfig,
57 sizeof(PciConfig));
58 if (ReadLength != sizeof(PciConfig))
59 {
60 /* This device doesn't exist */
62 }
63
64 DriverExtension->InitializationData.HwGetLegacyResources(PciConfig.VendorID,
65 PciConfig.DeviceID,
66 AccessRanges,
67 AccessRangeCount);
68 }
69 else
70 {
71 *AccessRanges = DriverExtension->InitializationData.HwLegacyResourceList;
72 *AccessRangeCount = DriverExtension->InitializationData.HwLegacyResourceCount;
73 }
74
75 INFO_(VIDEOPRT, "Got %d legacy access ranges\n", *AccessRangeCount);
76
77 return STATUS_SUCCESS;
78}
ULONG ReadLength
NTHALAPI ULONG NTAPI HalGetBusData(BUS_DATA_TYPE, ULONG, ULONG, PVOID, ULONG)
@ PCIConfiguration
Definition: miniport.h:93
#define INFO_(ch,...)
Definition: debug.h:159
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136

Referenced by IntVideoPortFilterResourceRequirements(), and VideoPortGetAccessRanges().

◆ IntVideoPortMapMemory()

PVOID NTAPI IntVideoPortMapMemory ( IN PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension,
IN PHYSICAL_ADDRESS  IoAddress,
IN ULONG  NumberOfUchars,
IN ULONG  InIoSpace,
IN HANDLE  ProcessHandle,
OUT VP_STATUS Status 
)

Definition at line 327 of file resource.c.

334{
336 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
338 PVOID MappedAddress;
340
341 INFO_(VIDEOPRT, "- IoAddress: %lx\n", IoAddress.u.LowPart);
342 INFO_(VIDEOPRT, "- NumberOfUchars: %lx\n", NumberOfUchars);
343 INFO_(VIDEOPRT, "- InIoSpace: %x\n", InIoSpace);
344
345 InIoSpace &= ~VIDEO_MEMORY_SPACE_DENSE;
346
347 if (ProcessHandle != NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
348 {
349 INFO_(VIDEOPRT, "ProcessHandle is not NULL (0x%x) but InIoSpace does not have "
350 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting "
351 "VIDEO_MEMORY_SPACE_USER_MODE.\n",
353 InIoSpace |= VIDEO_MEMORY_SPACE_USER_MODE;
354 }
355 else if (ProcessHandle == NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
356 {
357 INFO_(VIDEOPRT, "ProcessHandle is NULL (0x%x) but InIoSpace does have "
358 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting ProcessHandle "
359 "to NtCurrentProcess()\n",
362 }
363
364 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0 &&
365 !IsListEmpty(&DeviceExtension->AddressMappingListHead))
366 {
367 Entry = DeviceExtension->AddressMappingListHead.Flink;
368 while (Entry != &DeviceExtension->AddressMappingListHead)
369 {
370 AddressMapping = CONTAINING_RECORD(
371 Entry,
373 List);
374 if (IoAddress.QuadPart == AddressMapping->IoAddress.QuadPart &&
375 NumberOfUchars <= AddressMapping->NumberOfUchars)
376 {
377 {
378 AddressMapping->MappingCount++;
379 if (Status)
380 *Status = NO_ERROR;
381 return AddressMapping->MappedAddress;
382 }
383 }
384 Entry = Entry->Flink;
385 }
386 }
387
388 AddressSpace = (ULONG)InIoSpace;
391 DeviceExtension->AdapterInterfaceType,
392 DeviceExtension->SystemIoBusNumber,
393 IoAddress,
396 {
397 if (Status)
399
400 return NULL;
401 }
402
403 /* I/O space */
404 if (AddressSpace != 0)
405 {
406 ASSERT(0 == TranslatedAddress.u.HighPart);
407 if (Status)
408 *Status = NO_ERROR;
409
410 return (PVOID)(ULONG_PTR)TranslatedAddress.u.LowPart;
411 }
412
413 /* user space */
414 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
415 {
416 NTSTATUS NtStatus;
418 if (InIoSpace & VIDEO_MEMORY_SPACE_P6CACHE)
420 else
422 MappedAddress = NULL;
425 NumberOfUchars,
426 Protect,
427 &MappedAddress);
428 if (!NT_SUCCESS(NtStatus))
429 {
430 ERR_(VIDEOPRT, "IntVideoPortMapPhysicalMemory() failed! (0x%x)\n", NtStatus);
431 if (Status)
433 return NULL;
434 }
435 INFO_(VIDEOPRT, "Mapped user address = 0x%08x\n", MappedAddress);
436 }
437 else /* kernel space */
438 {
439 MappedAddress = MmMapIoSpace(
441 NumberOfUchars,
443 }
444
445 if (MappedAddress != NULL)
446 {
447 if (Status)
448 {
449 *Status = NO_ERROR;
450 }
451 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
452 {
453 AddressMapping = ExAllocatePoolWithTag(
454 PagedPool,
457
458 if (AddressMapping == NULL)
459 return MappedAddress;
460
461 RtlZeroMemory(AddressMapping, sizeof(VIDEO_PORT_ADDRESS_MAPPING));
462 AddressMapping->NumberOfUchars = NumberOfUchars;
463 AddressMapping->IoAddress = IoAddress;
464 AddressMapping->SystemIoBusNumber = DeviceExtension->SystemIoBusNumber;
465 AddressMapping->MappedAddress = MappedAddress;
466 AddressMapping->MappingCount = 1;
468 &DeviceExtension->AddressMappingListHead,
469 &AddressMapping->List);
470 }
471
472 return MappedAddress;
473 }
474
475 ERR_(VIDEOPRT,
476 "Couldn't map video memory. IoAddress: 0x%lx, NumberOfUchars: 0x%lx, InIoSpace: 0x%x\n",
477 IoAddress.u.LowPart, NumberOfUchars, InIoSpace);
478 if (Status)
480
481 return NULL;
482}
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define InsertHeadList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define PagedPool
Definition: env_spec_w32.h:308
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
#define PAGE_NOCACHE
Definition: nt_native.h:1314
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define NtCurrentProcess()
Definition: nt_native.h:1660
#define VIDEO_MEMORY_SPACE_USER_MODE
Definition: video.h:134
#define VIDEO_MEMORY_SPACE_P6CACHE
Definition: video.h:136
#define ERR_(ch,...)
Definition: debug.h:156
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
PHYSICAL_ADDRESS IoAddress
Definition: videoprt.h:49
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
struct _LARGE_INTEGER::@2464 u
#define TAG_VIDEO_PORT
Definition: videoprt.h:38
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
NTSTATUS NTAPI IntVideoPortMapPhysicalMemory(IN HANDLE Process, IN PHYSICAL_ADDRESS PhysicalAddress, IN ULONG SizeInBytes, IN ULONG Protect, IN OUT PVOID *VirtualAddress OPTIONAL)
Definition: resource.c:244
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2275
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274
@ MmNonCached
Definition: mmtypes.h:129
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG _In_ ULONG Protect
Definition: zwfuncs.h:221

Referenced by VideoPortGetDeviceBase(), and VideoPortMapMemory().

◆ IntVideoPortMapPhysicalMemory()

NTSTATUS NTAPI IntVideoPortMapPhysicalMemory ( IN HANDLE  Process,
IN PHYSICAL_ADDRESS  PhysicalAddress,
IN ULONG  SizeInBytes,
IN ULONG  Protect,
IN OUT PVOID *VirtualAddress  OPTIONAL 
)

Definition at line 244 of file resource.c.

250{
251 OBJECT_ATTRIBUTES ObjAttribs;
253 HANDLE hMemObj;
255 SIZE_T Size;
256
257 /* Initialize object attribs */
258 RtlInitUnicodeString(&UnicodeString, L"\\Device\\PhysicalMemory");
259 InitializeObjectAttributes(&ObjAttribs,
262 NULL, NULL);
263
264 /* Open physical memory section */
265 Status = ZwOpenSection(&hMemObj, SECTION_ALL_ACCESS, &ObjAttribs);
266 if (!NT_SUCCESS(Status))
267 {
268 WARN_(VIDEOPRT, "ZwOpenSection() failed! (0x%x)\n", Status);
269 return Status;
270 }
271
272 /* Map view of section */
273 Size = SizeInBytes;
274 Status = ZwMapViewOfSection(hMemObj,
275 Process,
277 0,
278 Size,
280 &Size,
281 ViewUnmap,
282 0,
283 Protect);
284 ZwClose(hMemObj);
285 if (!NT_SUCCESS(Status))
286 {
287 WARN_(VIDEOPRT, "ZwMapViewOfSection() failed! (0x%x)\n", Status);
288 }
289
290 return Status;
291}
#define L(x)
Definition: resources.c:13
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwOpenSection(_Out_ PHANDLE SectionHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1296
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
@ ViewUnmap
Definition: nt_native.h:1282
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define WARN_(ch,...)
Definition: debug.h:157
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098

Referenced by IntAgpCommitVirtual(), and IntVideoPortMapMemory().

◆ IntVideoPortReleaseResources()

VOID IntVideoPortReleaseResources ( _In_ PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 198 of file resource.c.

200{
202 BOOLEAN ConflictDetected;
203 // An empty CM_RESOURCE_LIST
204 UCHAR EmptyResourceList[FIELD_OFFSET(CM_RESOURCE_LIST, List)] = {0};
205
206 if (DeviceExtension->IsLegacyDevice || DeviceExtension->IsLegacyDetect || DeviceExtension->IsVgaDetect)
207 {
209 DeviceExtension->DriverObject,
210 NULL, 0, /* Driver List */
211 DeviceExtension->PhysicalDeviceObject,
212 (PCM_RESOURCE_LIST)EmptyResourceList,
213 sizeof(EmptyResourceList),
214 &ConflictDetected);
215
216 if (!NT_SUCCESS(Status))
217 {
218 ERR_(VIDEOPRT,
219 "VideoPortReleaseResources (Detect) failed with 0x%08lx ; ConflictDetected: %s\n",
220 Status, ConflictDetected ? "TRUE" : "FALSE");
221 }
222 }
223 else
224 {
226 DeviceExtension->DriverObject,
227 NULL,
228 0,
229 DeviceExtension->PhysicalDeviceObject,
230 (PCM_RESOURCE_LIST)EmptyResourceList,
231 sizeof(EmptyResourceList),
232 FALSE,
233 &ConflictDetected);
234 if (!NT_SUCCESS(Status))
235 {
236 ERR_(VIDEOPRT,
237 "VideoPortReleaseResources (Usage) failed with 0x%08lx ; ConflictDetected: %s\n",
238 Status, ConflictDetected ? "TRUE" : "FALSE");
239 }
240 }
241}
unsigned char BOOLEAN
Definition: actypes.h:127
NTSTATUS NTAPI IoReportResourceUsage(_In_opt_ PUNICODE_STRING DriverClassName, _In_ PDRIVER_OBJECT DriverObject, _In_reads_bytes_opt_(DriverListSize) PCM_RESOURCE_LIST DriverList, _In_opt_ ULONG DriverListSize, _In_opt_ PDEVICE_OBJECT DeviceObject, _In_reads_bytes_opt_(DeviceListSize) PCM_RESOURCE_LIST DeviceList, _In_opt_ ULONG DeviceListSize, _In_ BOOLEAN OverrideConflict, _Out_ PBOOLEAN ConflictDetected)
Reports hardware resources in the \Registry\Machine\Hardware\ResourceMap tree, so that a subsequently...
Definition: iorsrce.c:1041
NTSTATUS NTAPI IoReportResourceForDetection(IN PDRIVER_OBJECT DriverObject, IN PCM_RESOURCE_LIST DriverList OPTIONAL, IN ULONG DriverListSize OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PCM_RESOURCE_LIST DeviceList OPTIONAL, IN ULONG DeviceListSize OPTIONAL, OUT PBOOLEAN ConflictDetected)
Definition: pnpreport.c:394
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
static UNICODE_STRING VideoClassName
Definition: resource.c:29
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by IntVideoPortFindAdapter(), and VideoPortVerifyAccessRanges().

◆ IntVideoPortUnmapMemory()

VOID NTAPI IntVideoPortUnmapMemory ( IN PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension,
IN PVOID  MappedAddress 
)

Definition at line 485 of file resource.c.

488{
489 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
492
493 Entry = DeviceExtension->AddressMappingListHead.Flink;
494 while (Entry != &DeviceExtension->AddressMappingListHead)
495 {
496 AddressMapping = CONTAINING_RECORD(
497 Entry,
499 List);
500 if (AddressMapping->MappedAddress == MappedAddress)
501 {
502 ASSERT(AddressMapping->MappingCount > 0);
503 AddressMapping->MappingCount--;
504 if (AddressMapping->MappingCount == 0)
505 {
507 AddressMapping->MappedAddress,
508 AddressMapping->NumberOfUchars);
510 ExFreePool(AddressMapping);
511 }
512 return;
513 }
514
515 Entry = Entry->Flink;
516 }
517
518 /* If there was no kernelmode mapping for the given address found we assume
519 * that the given address is a usermode mapping and try to unmap it.
520 *
521 * FIXME: Is it ok to use NtCurrentProcess?
522 */
523 Status = ZwUnmapViewOfSection(NtCurrentProcess(), MappedAddress);
524 if (!NT_SUCCESS(Status))
525 {
526 WARN_(VIDEOPRT, "Warning: Mapping for address 0x%p not found!\n", MappedAddress);
527 }
528}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193

Referenced by VideoPortFreeDeviceBase(), and VideoPortUnmapMemory().

◆ VideoPortAllocateBuffer()

VP_STATUS NTAPI VideoPortAllocateBuffer ( IN PVOID  HwDeviceExtension,
IN ULONG  Size,
OUT PVOID Buffer 
)

Definition at line 1256 of file resource.c.

1260{
1261 TRACE_(VIDEOPRT, "VideoPortAllocateBuffer\n");
1264}
Definition: bufpool.h:45
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define TRACE_(x)
Definition: compat.h:76
#define TAG_VIDEO_PORT_BUFFER
Definition: videoprt.h:39

◆ VideoPortAllocatePool()

PVOID NTAPI VideoPortAllocatePool ( IN PVOID  HwDeviceExtension,
IN VP_POOL_TYPE  PoolType,
IN SIZE_T  NumberOfBytes,
IN ULONG  Tag 
)

Definition at line 1229 of file resource.c.

1234{
1235 TRACE_(VIDEOPRT, "VideoPortAllocatePool\n");
1237}
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4071
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3821
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1036

Referenced by BochsInitialize(), InitializeModeTable(), VbeGetVideoMemoryBaseAddress(), VBEInitialize(), and VbeSetColorLookup().

◆ VideoPortFreeDeviceBase()

VOID NTAPI VideoPortFreeDeviceBase ( IN PVOID  HwDeviceExtension,
IN PVOID  MappedAddress 
)

Definition at line 558 of file resource.c.

561{
562 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
564 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
565 MappedAddress);
566}
#define VIDEO_PORT_GET_DEVICE_EXTENSION(MiniportExtension)
Definition: videoprt.h:145
VOID NTAPI IntVideoPortUnmapMemory(IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, IN PVOID MappedAddress)
Definition: resource.c:485

Referenced by InitializeModeTable().

◆ VideoPortFreePool()

VOID NTAPI VideoPortFreePool ( IN PVOID  HwDeviceExtension,
IN PVOID  Ptr 
)

Definition at line 1244 of file resource.c.

1247{
1248 ExFreePool(Ptr);
1249}
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898

Referenced by BochsFreeResources(), InitializeModeTable(), VbeGetVideoMemoryBaseAddress(), and VbeSetColorLookup().

◆ VideoPortGetAccessRanges()

VP_STATUS NTAPI VideoPortGetAccessRanges ( _In_ PVOID  HwDeviceExtension,
_In_opt_ ULONG  NumRequestedResources,
_In_reads_opt_(NumRequestedResources) PIO_RESOURCE_DESCRIPTOR  RequestedResources,
_In_ ULONG  NumAccessRanges,
_Out_writes_(NumAccessRanges) PVIDEO_ACCESS_RANGE  AccessRanges,
_In_ PVOID  VendorId,
_In_ PVOID  DeviceId,
_Out_ PULONG  Slot 
)

Retrieves bus-relative (mainly PCI) hardware resources access ranges and, if possible, claims these resources for the caller.

Parameters
[in]HwDeviceExtensionThe miniport device extension.
[in]NumRequestedResourcesThe number of hardware resources in the RequestedResources array.
[in]RequestedResourcesAn optional array of IO_RESOURCE_DESCRIPTOR elements describing hardware resources the miniport requires.
[in]NumAccessRangesThe number of ranges in the AccessRanges array the miniport expects to retrieve.
[out]AccessRangesA pointer to an array of hardware resource ranges VideoPortGetAccessRanges fills with bus-relative device memory ACCESS_RANGE's for the adapter.
[in]VendorIdFor a PCI device, points to a USHORT-type value that identifies the PCI manufacturer of the adapter. Otherwise, should be NULL.
[in]DeviceIdFor a PCI device, points to a USHORT-type value that identifies a particular PCI adapter model, assigned by the manufacturer. Otherwise, should be NULL.
[out]SlotPoints to a ULONG value that receives the logical slot / location of the adapter (bus-dependent). For a PCI adapter, Slot points to a PCI_SLOT_NUMBER structure that locates the adapter on the PCI bus.
Returns
  • NO_ERROR if the resources have been successfully claimed or released.
  • ERROR_INVALID_PARAMETER if an error or a conflict occurred.
  • ERROR_DEV_NOT_EXIST if the device is not found.
  • ERROR_MORE_DATA if there exist more device access ranges available than what is specified by NumAccessRanges.
  • ERROR_NOT_ENOUGH_MEMORY if there is not enough memory available.

Definition at line 686 of file resource.c.

696{
697 PCI_SLOT_NUMBER PciSlotNumber;
699 ULONG FunctionNumber;
703 UINT AssignedCount = 0;
706 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
708 USHORT VendorIdToFind;
709 USHORT DeviceIdToFind;
711 PVIDEO_ACCESS_RANGE LegacyAccessRanges;
712 ULONG LegacyAccessRangeCount;
714 ULONG ListSize;
716 BOOLEAN DeviceAndVendorFound = FALSE;
717
718 TRACE_(VIDEOPRT, "VideoPortGetAccessRanges(%d, %p, %d, %p)\n",
719 NumRequestedResources, RequestedResources, NumAccessRanges, AccessRanges);
720
721 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
722 DriverObject = DeviceExtension->DriverObject;
724
725 if (NumRequestedResources == 0)
726 {
727 AllocatedResources = DeviceExtension->AllocatedResources;
728 if (AllocatedResources == NULL &&
729 DeviceExtension->AdapterInterfaceType == PCIBus)
730 {
731 if (DeviceExtension->PhysicalDeviceObject != NULL)
732 {
733 PciSlotNumber.u.AsULONG = DeviceExtension->SystemIoSlotNumber;
734
736 DeviceExtension->SystemIoBusNumber,
737 PciSlotNumber.u.AsULONG,
738 &Config,
739 sizeof(Config));
740
741 if (ReturnedLength != sizeof(Config))
742 {
744 }
745 }
746 else
747 {
748 VendorIdToFind = VendorId != NULL ? *(PUSHORT)VendorId : 0;
749 DeviceIdToFind = DeviceId != NULL ? *(PUSHORT)DeviceId : 0;
750
751 if (VendorIdToFind == 0 && DeviceIdToFind == 0)
752 {
753 /* We're screwed */
754 return ERROR_DEV_NOT_EXIST;
755 }
756
757 INFO_(VIDEOPRT, "Looking for VendorId 0x%04x DeviceId 0x%04x\n",
758 VendorIdToFind, DeviceIdToFind);
759
760 /*
761 * Search for the device id and vendor id on this bus.
762 */
763 PciSlotNumber.u.bits.Reserved = 0;
765 {
766 PciSlotNumber.u.bits.DeviceNumber = DeviceNumber;
767 for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
768 {
769 INFO_(VIDEOPRT, "- Function number: %d\n", FunctionNumber);
770 PciSlotNumber.u.bits.FunctionNumber = FunctionNumber;
772 DeviceExtension->SystemIoBusNumber,
773 PciSlotNumber.u.AsULONG,
774 &Config,
775 sizeof(Config));
776
777 INFO_(VIDEOPRT, "- Length of data: %x\n", ReturnedLength);
778
779 if (ReturnedLength == sizeof(Config))
780 {
781 INFO_(VIDEOPRT, "- Slot 0x%02x (Device %d Function %d) VendorId 0x%04x "
782 "DeviceId 0x%04x\n",
783 PciSlotNumber.u.AsULONG,
784 PciSlotNumber.u.bits.DeviceNumber,
785 PciSlotNumber.u.bits.FunctionNumber,
786 Config.VendorID,
787 Config.DeviceID);
788
789 if ((VendorIdToFind == 0 || Config.VendorID == VendorIdToFind) &&
790 (DeviceIdToFind == 0 || Config.DeviceID == DeviceIdToFind))
791 {
792 DeviceAndVendorFound = TRUE;
793 break;
794 }
795 }
796 }
797 if (DeviceAndVendorFound)
798 break;
799 }
800 if (FunctionNumber == PCI_MAX_FUNCTION)
801 {
802 WARN_(VIDEOPRT, "Didn't find device.\n");
803 return ERROR_DEV_NOT_EXIST;
804 }
805 }
806
807 Status = HalAssignSlotResources(&DeviceExtension->RegistryPath,
808 NULL,
809 DeviceExtension->DriverObject,
810 DeviceExtension->DriverObject->DeviceObject,
811 DeviceExtension->AdapterInterfaceType,
812 DeviceExtension->SystemIoBusNumber,
813 PciSlotNumber.u.AsULONG,
815 if (!NT_SUCCESS(Status))
816 {
817 WARN_(VIDEOPRT, "HalAssignSlotResources failed with status %x.\n",Status);
818 return Status;
819 }
820 DeviceExtension->AllocatedResources = AllocatedResources;
821 DeviceExtension->SystemIoSlotNumber = PciSlotNumber.u.AsULONG;
822
823 /* Add legacy resources to the resources from HAL */
825 &LegacyAccessRanges, &LegacyAccessRangeCount);
826 if (!NT_SUCCESS(Status))
827 return ERROR_DEV_NOT_EXIST;
828
829 if (NumAccessRanges < LegacyAccessRangeCount)
830 {
831 ERR_(VIDEOPRT, "Too many legacy access ranges found\n");
832 return ERROR_NOT_ENOUGH_MEMORY; // ERROR_MORE_DATA;
833 }
834
835 RtlCopyMemory(AccessRanges, LegacyAccessRanges, LegacyAccessRangeCount * sizeof(VIDEO_ACCESS_RANGE));
836 AssignedCount = LegacyAccessRangeCount;
837 }
838 }
839 else
840 {
841 ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + (NumRequestedResources - 1) * sizeof(IO_RESOURCE_DESCRIPTOR);
842 ResReqList = ExAllocatePool(NonPagedPool, ListSize);
843 if (!ResReqList)
845
846 ResReqList->ListSize = ListSize;
847 ResReqList->InterfaceType = DeviceExtension->AdapterInterfaceType;
848 ResReqList->BusNumber = DeviceExtension->SystemIoBusNumber;
849 ResReqList->SlotNumber = DeviceExtension->SystemIoSlotNumber;
850 ResReqList->AlternativeLists = 1;
851 ResReqList->List[0].Version = 1;
852 ResReqList->List[0].Revision = 1;
853 ResReqList->List[0].Count = NumRequestedResources;
854
855 /* Copy in the caller's resource list */
856 RtlCopyMemory(ResReqList->List[0].Descriptors,
857 RequestedResources,
858 NumRequestedResources * sizeof(IO_RESOURCE_DESCRIPTOR));
859
860 Status = IoAssignResources(&DeviceExtension->RegistryPath,
861 NULL,
862 DeviceExtension->DriverObject,
863 DeviceExtension->PhysicalDeviceObject ?
864 DeviceExtension->PhysicalDeviceObject :
865 DeviceExtension->DriverObject->DeviceObject,
866 ResReqList,
868
869 if (!NT_SUCCESS(Status))
870 return Status;
871
872 if (!DeviceExtension->AllocatedResources)
873 DeviceExtension->AllocatedResources = AllocatedResources;
874 }
875
878
879 /* Return the slot number if the caller wants it */
880 if (Slot != NULL) *Slot = DeviceExtension->SystemIoSlotNumber;
881
882 FullList = AllocatedResources->List;
883 ASSERT(AllocatedResources->Count == 1);
884 INFO_(VIDEOPRT, "InterfaceType %u BusNumber List %u Device BusNumber %u Version %u Revision %u\n",
885 FullList->InterfaceType, FullList->BusNumber, DeviceExtension->SystemIoBusNumber,
887
888 ASSERT(FullList->InterfaceType == PCIBus);
889 ASSERT(FullList->BusNumber == DeviceExtension->SystemIoBusNumber);
890 ASSERT(1 == FullList->PartialResourceList.Version);
891 ASSERT(1 == FullList->PartialResourceList.Revision);
892
894 Descriptor < FullList->PartialResourceList.PartialDescriptors + FullList->PartialResourceList.Count;
895 Descriptor++)
896 {
897 if ((Descriptor->Type == CmResourceTypeMemory ||
898 Descriptor->Type == CmResourceTypePort) &&
899 AssignedCount >= NumAccessRanges)
900 {
901 ERR_(VIDEOPRT, "Too many access ranges found\n");
902 return ERROR_MORE_DATA;
903 }
904 else if (Descriptor->Type == CmResourceTypeMemory)
905 {
906 INFO_(VIDEOPRT, "Memory range starting at 0x%08x length 0x%08x\n",
907 Descriptor->u.Memory.Start.u.LowPart, Descriptor->u.Memory.Length);
908 AccessRanges[AssignedCount].RangeStart = Descriptor->u.Memory.Start;
909 AccessRanges[AssignedCount].RangeLength = Descriptor->u.Memory.Length;
910 AccessRanges[AssignedCount].RangeInIoSpace = 0;
911 AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
912 AccessRanges[AssignedCount].RangeShareable =
913 (Descriptor->ShareDisposition == CmResourceShareShared);
914 AccessRanges[AssignedCount].RangePassive = 0;
915 AssignedCount++;
916 }
917 else if (Descriptor->Type == CmResourceTypePort)
918 {
919 INFO_(VIDEOPRT, "Port range starting at 0x%04x length %d\n",
920 Descriptor->u.Port.Start.u.LowPart, Descriptor->u.Port.Length);
921 AccessRanges[AssignedCount].RangeStart = Descriptor->u.Port.Start;
922 AccessRanges[AssignedCount].RangeLength = Descriptor->u.Port.Length;
923 AccessRanges[AssignedCount].RangeInIoSpace = 1;
924 AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
925 AccessRanges[AssignedCount].RangeShareable =
926 (Descriptor->ShareDisposition == CmResourceShareShared);
927 AccessRanges[AssignedCount].RangePassive = 0;
929 AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_10_BIT_DECODE;
931 AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_PASSIVE_DECODE;
932 AssignedCount++;
933 }
934 else if (Descriptor->Type == CmResourceTypeInterrupt)
935 {
936 DeviceExtension->InterruptLevel = Descriptor->u.Interrupt.Level;
937 DeviceExtension->InterruptVector = Descriptor->u.Interrupt.Vector;
938 if (Descriptor->ShareDisposition == CmResourceShareShared)
939 DeviceExtension->InterruptShared = TRUE;
940 else
941 DeviceExtension->InterruptShared = FALSE;
942 }
943 // else if (Descriptor->Type == CmResourceTypeDma) // TODO!
944 else
945 {
946 ASSERT(FALSE);
948 }
949 }
950
951 return NO_ERROR;
952}
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
#define ERROR_DEV_NOT_EXIST
Definition: dderror.h:8
#define ERROR_MORE_DATA
Definition: dderror.h:13
NTHALAPI NTSTATUS NTAPI HalAssignSlotResources(PUNICODE_STRING, PUNICODE_STRING, PDRIVER_OBJECT, PDEVICE_OBJECT, INTERFACE_TYPE, ULONG, ULONG, PCM_RESOURCE_LIST *)
NTSTATUS NTAPI IoAssignResources(_In_ PUNICODE_STRING RegistryPath, _In_opt_ PUNICODE_STRING DriverClassName, _In_ PDRIVER_OBJECT DriverObject, _In_opt_ PDEVICE_OBJECT DeviceObject, _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources, _Inout_ PCM_RESOURCE_LIST *AllocatedResources)
Definition: iorsrce.c:1134
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4643
unsigned int UINT
Definition: ndis.h:50
unsigned short USHORT
Definition: pedump.c:61
@ PCIBus
Definition: restypes.h:126
#define CmResourceTypeInterrupt
Definition: restypes.h:105
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: restypes.h:144
INTERFACE_TYPE InterfaceType
Definition: restypes.h:142
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2279
struct _PCI_SLOT_NUMBER::@4346::@4347 bits
union _PCI_SLOT_NUMBER::@4346 u
PDEVICE_OBJECT PhysicalDeviceObject
Definition: videoprt.h:87
PCM_RESOURCE_LIST AllocatedResources
Definition: videoprt.h:94
UNICODE_STRING RegistryPath
Definition: videoprt.h:90
PDRIVER_OBJECT DriverObject
Definition: videoprt.h:86
uint16_t * PUSHORT
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:476
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
#define PCI_MAX_FUNCTION
Definition: iotypes.h:3601
#define PCI_MAX_DEVICES
Definition: iotypes.h:3600

Referenced by BochsFindAdapter(), and XboxVmpFindAdapter().

◆ VideoPortGetBusData()

ULONG NTAPI VideoPortGetBusData ( IN PVOID  HwDeviceExtension,
IN BUS_DATA_TYPE  BusDataType,
IN ULONG  SlotNumber,
OUT PVOID  Buffer,
IN ULONG  Offset,
IN ULONG  Length 
)

Definition at line 1380 of file resource.c.

1387{
1388 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
1389
1390 TRACE_(VIDEOPRT, "VideoPortGetBusData\n");
1391
1392 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
1393
1394 if (BusDataType != Cmos)
1395 {
1396 /* Legacy vs. PnP behaviour */
1397 if (DeviceExtension->PhysicalDeviceObject != NULL)
1398 SlotNumber = DeviceExtension->SystemIoSlotNumber;
1399 }
1400
1401 return HalGetBusDataByOffset(
1402 BusDataType,
1403 DeviceExtension->SystemIoBusNumber,
1404 SlotNumber,
1405 Buffer,
1406 Offset,
1407 Length);
1408}
ULONG NTAPI HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:73
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ Cmos
Definition: miniport.h:89
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:68

◆ VideoPortGetDeviceBase()

PVOID NTAPI VideoPortGetDeviceBase ( IN PVOID  HwDeviceExtension,
IN PHYSICAL_ADDRESS  IoAddress,
IN ULONG  NumberOfUchars,
IN UCHAR  InIoSpace 
)

Definition at line 537 of file resource.c.

542{
543 TRACE_(VIDEOPRT, "VideoPortGetDeviceBase\n");
545 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
546 IoAddress,
547 NumberOfUchars,
548 InIoSpace,
549 NULL,
550 NULL);
551}
PVOID NTAPI IntVideoPortMapMemory(IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, IN PHYSICAL_ADDRESS IoAddress, IN ULONG NumberOfUchars, IN ULONG InIoSpace, IN HANDLE ProcessHandle, OUT VP_STATUS *Status)
Definition: resource.c:327

Referenced by BochsFindAdapter(), InitializeModeTable(), and VgaFindAdapter().

◆ VideoPortGetDeviceData()

VP_STATUS NTAPI VideoPortGetDeviceData ( IN PVOID  HwDeviceExtension,
IN VIDEO_DEVICE_DATA_TYPE  DeviceDataType,
IN PMINIPORT_QUERY_DEVICE_ROUTINE  CallbackRoutine,
IN PVOID  Context 
)

Definition at line 1213 of file resource.c.

1218{
1219 TRACE_(VIDEOPRT, "VideoPortGetDeviceData\n");
1222}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6

Referenced by VgaFindAdapter().

◆ VideoPortLockBuffer()

PVOID NTAPI VideoPortLockBuffer ( IN PVOID  HwDeviceExtension,
IN PVOID  BaseAddress,
IN ULONG  Length,
IN VP_LOCK_OPERATION  Operation 
)

Definition at line 1284 of file resource.c.

1289{
1290 PMDL Mdl;
1291
1293 if (!Mdl)
1294 {
1295 return NULL;
1296 }
1297 /* FIXME use seh */
1299 return Mdl;
1300}
FP_OP Operation
Definition: fpcontrol.c:150
#define IoAllocateMdl
Definition: fxmdl.h:88
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:931
#define KernelMode
Definition: asm.h:38
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl

Referenced by VideoPortLockPages().

◆ VideoPortLockPages()

BOOLEAN NTAPI VideoPortLockPages ( IN PVOID  HwDeviceExtension,
IN OUT PVIDEO_REQUEST_PACKET  pVrp,
IN PEVENT  pUEvent,
IN PEVENT  pDisplayEvent,
IN DMA_FLAGS  DmaFlags 
)

Definition at line 1308 of file resource.c.

1314{
1315 PVOID Buffer;
1316
1317 /* clear output buffer */
1318 pVrp->OutputBuffer = NULL;
1319
1320 if (DmaFlags != VideoPortDmaInitOnly)
1321 {
1322 /* VideoPortKeepPagesLocked / VideoPortUnlockAfterDma is no-op */
1323 return FALSE;
1324 }
1325
1326 /* lock the buffer */
1327 Buffer = VideoPortLockBuffer(HwDeviceExtension, pVrp->InputBuffer, pVrp->InputBufferLength, IoModifyAccess);
1328
1329 if (Buffer)
1330 {
1331 /* store result buffer & length */
1332 pVrp->OutputBuffer = Buffer;
1333 pVrp->OutputBufferLength = pVrp->InputBufferLength;
1334
1335 /* operation succeeded */
1336 return TRUE;
1337 }
1338
1339 /* operation failed */
1340 return FALSE;
1341}
@ VideoPortDmaInitOnly
Definition: video.h:551
PVOID NTAPI VideoPortLockBuffer(IN PVOID HwDeviceExtension, IN PVOID BaseAddress, IN ULONG Length, IN VP_LOCK_OPERATION Operation)
Definition: resource.c:1284
@ IoModifyAccess
Definition: ketypes.h:917

◆ VideoPortMapBankedMemory()

VP_STATUS NTAPI VideoPortMapBankedMemory ( IN PVOID  HwDeviceExtension,
IN PHYSICAL_ADDRESS  PhysicalAddress,
IN PULONG  Length,
IN PULONG  InIoSpace,
OUT PVOID VirtualAddress,
IN ULONG  BankLength,
IN UCHAR  ReadWriteBank,
IN PBANKED_SECTION_ROUTINE  BankRoutine,
IN PVOID  Context 
)

Definition at line 573 of file resource.c.

583{
584 TRACE_(VIDEOPRT, "VideoPortMapBankedMemory\n");
587}

◆ VideoPortMapMemory()

VP_STATUS NTAPI VideoPortMapMemory ( IN PVOID  HwDeviceExtension,
IN PHYSICAL_ADDRESS  PhysicalAddress,
IN PULONG  Length,
IN PULONG  InIoSpace,
OUT PVOID VirtualAddress 
)

Definition at line 595 of file resource.c.

601{
602 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
604
605 TRACE_(VIDEOPRT, "VideoPortMapMemory\n");
606 INFO_(VIDEOPRT, "- *VirtualAddress: 0x%x\n", *VirtualAddress);
607
608 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
610 DeviceExtension,
612 *Length,
613 *InIoSpace,
615 &Status);
616
617 return Status;
618}

◆ VideoPortReleaseBuffer()

VOID NTAPI VideoPortReleaseBuffer ( IN PVOID  HwDeviceExtension,
IN PVOID  Ptr 
)

Definition at line 1271 of file resource.c.

1274{
1275 TRACE_(VIDEOPRT, "VideoPortReleaseBuffer\n");
1276 ExFreePool(Ptr);
1277}

◆ VideoPortSetBusData()

ULONG NTAPI VideoPortSetBusData ( IN PVOID  HwDeviceExtension,
IN BUS_DATA_TYPE  BusDataType,
IN ULONG  SlotNumber,
IN PVOID  Buffer,
IN ULONG  Offset,
IN ULONG  Length 
)

Definition at line 1415 of file resource.c.

1422{
1423 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
1424
1425 TRACE_(VIDEOPRT, "VideoPortSetBusData\n");
1426
1427 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
1428
1429 if (BusDataType != Cmos)
1430 {
1431 /* Legacy vs. PnP behaviour */
1432 if (DeviceExtension->PhysicalDeviceObject != NULL)
1433 SlotNumber = DeviceExtension->SystemIoSlotNumber;
1434 }
1435
1436 return HalSetBusDataByOffset(
1437 BusDataType,
1438 DeviceExtension->SystemIoBusNumber,
1439 SlotNumber,
1440 Buffer,
1441 Offset,
1442 Length);
1443}
ULONG NTAPI HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:123

◆ VideoPortSetTrappedEmulatorPorts()

VP_STATUS NTAPI VideoPortSetTrappedEmulatorPorts ( IN PVOID  HwDeviceExtension,
IN ULONG  NumAccessRanges,
IN PVIDEO_ACCESS_RANGE  AccessRange 
)

Definition at line 1365 of file resource.c.

1369{
1371 /* Should store the ranges in the device extension for use by ntvdm. */
1372 return NO_ERROR;
1373}

◆ VideoPortUnlockBuffer()

VOID NTAPI VideoPortUnlockBuffer ( IN PVOID  HwDeviceExtension,
IN PVOID  Mdl 
)

Definition at line 1349 of file resource.c.

1352{
1353 if (Mdl)
1354 {
1356 IoFreeMdl(Mdl);
1357 }
1358}
#define IoFreeMdl
Definition: fxmdl.h:89
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1435

◆ VideoPortUnmapMemory()

VP_STATUS NTAPI VideoPortUnmapMemory ( IN PVOID  HwDeviceExtension,
IN PVOID  VirtualAddress,
IN HANDLE  ProcessHandle 
)

Definition at line 625 of file resource.c.

629{
630 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
631
633 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
635
636 return NO_ERROR;
637}

◆ VideoPortVerifyAccessRanges()

VP_STATUS NTAPI VideoPortVerifyAccessRanges ( _In_ PVOID  HwDeviceExtension,
_In_opt_ ULONG  NumAccessRanges,
_In_reads_opt_(NumAccessRanges) PVIDEO_ACCESS_RANGE  AccessRanges 
)

Claims or releases a range of hardware resources and checks for conflicts.

Parameters
[in]HwDeviceExtensionThe miniport device extension.
[in]NumAccessRangesThe number of hardware resource ranges in the AccessRanges array. Specify zero to release the hardware resources held by the miniport.
[in]AccessRangesThe array of hardware resource ranges to claim ownership. Specify NULL to release the hardware resources held by the miniport.
Returns
  • NO_ERROR if the resources have been successfully claimed or released.
  • ERROR_INVALID_PARAMETER if an error or a conflict occurred.
  • ERROR_NOT_ENOUGH_MEMORY if there is not enough memory available.

Definition at line 976 of file resource.c.

980{
981 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
982 BOOLEAN ConflictDetected;
983 ULONG ResourceListSize;
985 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
986 ULONG i;
988
989 TRACE_(VIDEOPRT, "VideoPortVerifyAccessRanges\n");
990
991 /* Verify parameters */
992 if (NumAccessRanges && !AccessRanges)
994
995 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
996
997 if (NumAccessRanges == 0)
998 {
999 /* Release the resources and do nothing more for now... */
1000 IntVideoPortReleaseResources(DeviceExtension);
1001 /* If releasing VGA device resources, clear tracked ranges */
1002 if (DeviceExtension->IsVgaDriver)
1003 {
1005 if (VgaRanges)
1006 {
1008 VgaRanges = NULL;
1009 }
1010 NumOfVgaRanges = 0;
1013 }
1014 return NO_ERROR;
1015 }
1016
1017 /*
1018 * For non-legacy PCI devices, validate that the relevant I/O or memory
1019 * decoding bits are enabled in the PCI command register before claiming
1020 */
1021 if (!DeviceExtension->IsLegacyDevice && DeviceExtension->AdapterInterfaceType == PCIBus)
1022 {
1023 USHORT PciCommand;
1025
1027 DeviceExtension->SystemIoBusNumber,
1028 DeviceExtension->SystemIoSlotNumber,
1029 &PciCommand,
1031 sizeof(PciCommand));
1032 if (BytesRead == sizeof(PciCommand))
1033 {
1034 for (i = 0; i < NumAccessRanges; i++)
1035 {
1036 if (AccessRanges[i].RangeInIoSpace)
1037 {
1038 if ((PciCommand & PCI_ENABLE_IO_SPACE) == 0)
1039 {
1040 WARN_(VIDEOPRT, "PCI I/O space disabled; refusing access range claim\n");
1042 }
1043 }
1044 else
1045 {
1046 if ((PciCommand & PCI_ENABLE_MEMORY_SPACE) == 0)
1047 {
1048 WARN_(VIDEOPRT, "PCI memory space disabled; refusing access range claim\n");
1050 }
1051 }
1052 }
1053 }
1054 }
1055
1056 /* Determine which ranges need to be claimed (exclude PnP-assigned ones) */
1057 ULONG Needed = 0;
1058 for (i = 0; i < NumAccessRanges; ++i)
1059 {
1060 if (DeviceExtension->PhysicalDeviceObject && !DeviceExtension->IsLegacyDevice)
1061 {
1062 if (IntAccessRangeIsInAllocatedResources(DeviceExtension, &AccessRanges[i]))
1063 continue;
1064 }
1065 ++Needed;
1066 }
1067
1068 if (Needed == 0)
1069 {
1070 /* Nothing to report/claim */
1071 return NO_ERROR;
1072 }
1073
1074 /* Create the resource list for the non-PnP-assigned ranges */
1075 ResourceListSize = sizeof(CM_RESOURCE_LIST)
1076 + (Needed - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
1078 if (!ResourceList)
1079 {
1080 WARN_(VIDEOPRT, "ExAllocatePool() failed\n");
1082 }
1083
1084 /* Fill resource list */
1085 ResourceList->Count = 1;
1086 ResourceList->List[0].InterfaceType = DeviceExtension->AdapterInterfaceType;
1087 ResourceList->List[0].BusNumber = DeviceExtension->SystemIoBusNumber;
1088 ResourceList->List[0].PartialResourceList.Version = 1;
1089 ResourceList->List[0].PartialResourceList.Revision = 1;
1090 ResourceList->List[0].PartialResourceList.Count = Needed;
1091
1092 ULONG j = 0;
1093 for (i = 0; i < NumAccessRanges; ++i)
1094 {
1095 if (DeviceExtension->PhysicalDeviceObject && !DeviceExtension->IsLegacyDevice)
1096 {
1097 if (IntAccessRangeIsInAllocatedResources(DeviceExtension, &AccessRanges[i]))
1098 continue;
1099 }
1100
1101 PartialDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[j++];
1102 if (AccessRanges[i].RangeInIoSpace)
1103 {
1104 PartialDescriptor->Type = CmResourceTypePort;
1105 PartialDescriptor->u.Port.Start = AccessRanges[i].RangeStart;
1106 PartialDescriptor->u.Port.Length = AccessRanges[i].RangeLength;
1107 }
1108 else
1109 {
1110 PartialDescriptor->Type = CmResourceTypeMemory;
1111 PartialDescriptor->u.Memory.Start = AccessRanges[i].RangeStart;
1112 PartialDescriptor->u.Memory.Length = AccessRanges[i].RangeLength;
1113 }
1114 PartialDescriptor->ShareDisposition = AccessRanges[i].RangeShareable ?
1116 PartialDescriptor->Flags = 0;
1117 if (AccessRanges[i].RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
1118 PartialDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
1119 if (AccessRanges[i].RangePassive & VIDEO_RANGE_10_BIT_DECODE)
1120 PartialDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
1121 }
1122
1123 if (DeviceExtension->IsLegacyDevice || DeviceExtension->IsLegacyDetect || DeviceExtension->IsVgaDetect)
1124 {
1126 DeviceExtension->DriverObject,
1127 NULL, 0, /* Driver List */
1128 DeviceExtension->PhysicalDeviceObject,
1129 ResourceList, ResourceListSize,
1130 &ConflictDetected);
1131
1132 /* IntIsVgaSaveDriver() will later ignore STATUS_CONFLICTING_ADDRESSES, but we still claim it */
1133 if (!NT_SUCCESS(Status) && DeviceExtension->IsVgaDriver)
1134 {
1135 NTSTATUS fbStatus;
1136 BOOLEAN fbConflict = FALSE;
1138 DeviceExtension->DriverObject,
1139 NULL,
1140 0,
1141 DeviceExtension->PhysicalDeviceObject,
1143 ResourceListSize,
1144 FALSE,
1145 &fbConflict);
1146 INFO_(VIDEOPRT, "VGA detect->usage fallback: Status=0x%lx Conflict=%d fbStatus=0x%lx fbConflict=%d\n",
1147 Status, ConflictDetected, fbStatus, fbConflict);
1148 Status = fbStatus;
1149 ConflictDetected = fbConflict;
1150 }
1151 }
1152 else
1153 {
1155 DeviceExtension->DriverObject,
1156 NULL,
1157 0,
1158 DeviceExtension->PhysicalDeviceObject,
1160 ResourceListSize,
1161 FALSE,
1162 &ConflictDetected);
1163 }
1165
1166 /* If VgaSave driver is conflicting and we don't explicitly want
1167 * to use it, ignore the problem (because win32k will try to use
1168 * this driver only if all other ones are failing). */
1169 if ((Status == STATUS_CONFLICTING_ADDRESSES || ConflictDetected) &&
1170 DeviceExtension->IsVgaDriver && !VpBaseVideo)
1171 {
1172 return NO_ERROR;
1173 }
1174
1175 if (!NT_SUCCESS(Status) || ConflictDetected)
1177 else
1178 {
1179 /* Track VGA access ranges on success for fallback handling */
1180 if (DeviceExtension->IsVgaDriver && AccessRanges != VgaRanges)
1181 {
1183 if (VgaRanges)
1184 {
1186 VgaRanges = NULL;
1187 NumOfVgaRanges = 0;
1188 }
1189 if (NumAccessRanges)
1190 {
1191 SIZE_T sz = NumAccessRanges * sizeof(VIDEO_ACCESS_RANGE);
1193 if (VgaRanges)
1194 {
1195 RtlCopyMemory(VgaRanges, AccessRanges, sz);
1196 NumOfVgaRanges = NumAccessRanges;
1197 VgaDeviceExtension = DeviceExtension;
1198 }
1199 }
1201 }
1202 /* Leave VGA detect phase after first successful claim */
1203 DeviceExtension->IsVgaDetect = FALSE;
1204 return NO_ERROR;
1205 }
1206}
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 GLint GLint j
Definition: glfuncs.h:250
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
LONG NTAPI KeReleaseMutex(IN PKMUTEX Mutex, IN BOOLEAN Wait)
Definition: mutex.c:189
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:354
struct _CM_RESOURCE_LIST CM_RESOURCE_LIST
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
struct _VIDEO_ACCESS_RANGE VIDEO_ACCESS_RANGE
Definition: shell.h:41
ULONG NumOfVgaRanges
Definition: videoprt.c:48
PVIDEO_PORT_DEVICE_EXTENSION VgaDeviceExtension
Definition: videoprt.c:46
KMUTEX VgaSyncLock
Definition: videoprt.c:45
PVIDEO_ACCESS_RANGE VgaRanges
Definition: videoprt.c:47
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
static BOOLEAN IntAccessRangeIsInAllocatedResources(_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, _In_ PVIDEO_ACCESS_RANGE Range)
Definition: resource.c:294
BOOLEAN VpBaseVideo
Definition: videoprt.c:36
VOID IntVideoPortReleaseResources(_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
Definition: resource.c:198
#define PCI_ENABLE_IO_SPACE
Definition: iotypes.h:3618
#define PCI_ENABLE_MEMORY_SPACE
Definition: iotypes.h:3619
#define KeWaitForMutexObject
Definition: kefuncs.h:543
@ Executive
Definition: ketypes.h:467

Referenced by BochsFindAdapter(), IntVideoPortFindAdapter(), Pc98VidFindAdapter(), VgaAcquireResources(), and VGAFindAdapter().

Variable Documentation

◆ VideoClassName

UNICODE_STRING VideoClassName = RTL_CONSTANT_STRING(L"VIDEO")
static

Definition at line 29 of file resource.c.

Referenced by IntVideoPortReleaseResources(), and VideoPortVerifyAccessRanges().

◆ VpBaseVideo

BOOLEAN VpBaseVideo
extern

Definition at line 36 of file videoprt.c.

Referenced by IntLoadRegistryParameters(), and VideoPortVerifyAccessRanges().