ReactOS 0.4.16-dev-2207-geb15453
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

static BOOLEAN IntIsVgaSaveDriver (IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
 
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 302 of file resource.c.

305{
306 CM_RESOURCE_LIST *Res = DeviceExtension->AllocatedResources;
309
310 if (!Res || Res->Count == 0)
311 return FALSE;
312 Full = &Res->List[0];
313 for (Desc = Full->PartialResourceList.PartialDescriptors;
314 Desc < Full->PartialResourceList.PartialDescriptors + Full->PartialResourceList.Count;
315 ++Desc)
316 {
317 if (Range->RangeInIoSpace && Desc->Type == CmResourceTypePort)
318 {
319 if (Desc->u.Port.Start.QuadPart == Range->RangeStart.QuadPart &&
320 Desc->u.Port.Length == Range->RangeLength)
321 return TRUE;
322 }
323 else if (!Range->RangeInIoSpace && Desc->Type == CmResourceTypeMemory)
324 {
325 if (Desc->u.Memory.Start.QuadPart == Range->RangeStart.QuadPart &&
326 Desc->u.Memory.Length == Range->RangeLength)
327 return TRUE;
328 }
329 }
330 return FALSE;
331}
#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
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@432::@437 Memory
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@432::@434 Port
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@432 u
CM_FULL_RESOURCE_DESCRIPTOR List[1]
Definition: restypes.h:149

Referenced by VideoPortVerifyAccessRanges().

◆ IntIsVgaSaveDriver()

static BOOLEAN IntIsVgaSaveDriver ( IN PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension)
static

Definition at line 34 of file resource.c.

36{
37 UNICODE_STRING VgaSave = RTL_CONSTANT_STRING(L"\\Driver\\VgaSave");
38 return RtlEqualUnicodeString(&VgaSave, &DeviceExtension->DriverObject->DriverName, TRUE);
39}
#define L(x)
Definition: resources.c:13
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by VideoPortVerifyAccessRanges().

◆ IntVideoPortFilterResourceRequirements()

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

Definition at line 89 of file resource.c.

93{
96 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
97 PVIDEO_ACCESS_RANGE AccessRanges;
98 ULONG AccessRangeCount, ListSize, i;
100 PIO_RESOURCE_REQUIREMENTS_LIST OldResList = IrpStack->Parameters.FilterResourceRequirements.IoResourceRequirementList;
101 PIO_RESOURCE_DESCRIPTOR CurrentDescriptor;
103
104 DriverObject = DeviceObject->DriverObject;
106 DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
107
108 Status = IntVideoPortGetLegacyResources(DriverExtension, DeviceExtension, &AccessRanges, &AccessRangeCount);
109 if (!NT_SUCCESS(Status))
110 return Status;
111 if (!AccessRangeCount)
112 {
113 /* No legacy resources to report */
114 return Irp->IoStatus.Status;
115 }
116
117 /* OK, we've got the access ranges now. Let's set up the resource requirements list */
118
119 if (OldResList)
120 {
121 /* Already one there so let's add to it */
122 ListSize = OldResList->ListSize + sizeof(IO_RESOURCE_DESCRIPTOR) * AccessRangeCount;
124 ListSize);
125 if (!ResList) return STATUS_NO_MEMORY;
126
127 RtlCopyMemory(ResList, OldResList, OldResList->ListSize);
128
129 ASSERT(ResList->AlternativeLists == 1);
130
131 ResList->ListSize = ListSize;
132 ResList->List[0].Count += AccessRangeCount;
133
134 CurrentDescriptor = (PIO_RESOURCE_DESCRIPTOR)((PUCHAR)ResList + OldResList->ListSize);
135
136 ExFreePool(OldResList);
137 Irp->IoStatus.Information = 0;
138 }
139 else
140 {
141 /* We need to make a new one */
142 ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + sizeof(IO_RESOURCE_DESCRIPTOR) * (AccessRangeCount - 1);
144 ListSize);
145 if (!ResList) return STATUS_NO_MEMORY;
146
147 RtlZeroMemory(ResList, ListSize);
148
149 /* We need to initialize some fields */
150 ResList->ListSize = ListSize;
151 ResList->InterfaceType = DeviceExtension->AdapterInterfaceType;
152 ResList->BusNumber = DeviceExtension->SystemIoBusNumber;
153 ResList->SlotNumber = DeviceExtension->SystemIoSlotNumber;
154 ResList->AlternativeLists = 1;
155 ResList->List[0].Version = 1;
156 ResList->List[0].Revision = 1;
157 ResList->List[0].Count = AccessRangeCount;
158
159 CurrentDescriptor = ResList->List[0].Descriptors;
160 }
161
162 for (i = 0; i < AccessRangeCount; i++)
163 {
164 /* This is a required resource */
165 CurrentDescriptor->Option = 0;
166
167 if (AccessRanges[i].RangeInIoSpace)
168 CurrentDescriptor->Type = CmResourceTypePort;
169 else
170 CurrentDescriptor->Type = CmResourceTypeMemory;
171
172 CurrentDescriptor->ShareDisposition =
174
175 CurrentDescriptor->Flags = 0;
176
177 if (CurrentDescriptor->Type == CmResourceTypePort)
178 {
179 CurrentDescriptor->u.Port.Length = AccessRanges[i].RangeLength;
180 CurrentDescriptor->u.Port.MinimumAddress = AccessRanges[i].RangeStart;
181 CurrentDescriptor->u.Port.MaximumAddress.QuadPart = AccessRanges[i].RangeStart.QuadPart + AccessRanges[i].RangeLength - 1;
182 CurrentDescriptor->u.Port.Alignment = 1;
183 if (AccessRanges[i].RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
184 CurrentDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
185 if (AccessRanges[i].RangePassive & VIDEO_RANGE_10_BIT_DECODE)
186 CurrentDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
187 }
188 else
189 {
190 CurrentDescriptor->u.Memory.Length = AccessRanges[i].RangeLength;
191 CurrentDescriptor->u.Memory.MinimumAddress = AccessRanges[i].RangeStart;
192 CurrentDescriptor->u.Memory.MaximumAddress.QuadPart = AccessRanges[i].RangeStart.QuadPart + AccessRanges[i].RangeLength - 1;
193 CurrentDescriptor->u.Memory.Alignment = 1;
194 CurrentDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
195 }
196
197 CurrentDescriptor++;
198 }
199
200 Irp->IoStatus.Information = (ULONG_PTR)ResList;
201
202 return STATUS_SUCCESS;
203}
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:120
#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
struct _IO_RESOURCE_DESCRIPTOR::@2250::@2251 Port
struct _IO_RESOURCE_DESCRIPTOR::@2250::@2252 Memory
union _IO_RESOURCE_DESCRIPTOR::@2250 u
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:42
@ 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 42 of file resource.c.

47{
48 PCI_COMMON_CONFIG PciConfig;
50
51 if (!DriverExtension->InitializationData.HwGetLegacyResources &&
52 !DriverExtension->InitializationData.HwLegacyResourceCount)
53 {
54 /* No legacy resources to report */
55 *AccessRangeCount = 0;
56 return STATUS_SUCCESS;
57 }
58
59 if (DriverExtension->InitializationData.HwGetLegacyResources)
60 {
62 DeviceExtension->SystemIoBusNumber,
63 DeviceExtension->SystemIoSlotNumber,
64 &PciConfig,
65 sizeof(PciConfig));
66 if (ReadLength != sizeof(PciConfig))
67 {
68 /* This device doesn't exist */
70 }
71
72 DriverExtension->InitializationData.HwGetLegacyResources(PciConfig.VendorID,
73 PciConfig.DeviceID,
74 AccessRanges,
75 AccessRangeCount);
76 }
77 else
78 {
79 *AccessRanges = DriverExtension->InitializationData.HwLegacyResourceList;
80 *AccessRangeCount = DriverExtension->InitializationData.HwLegacyResourceCount;
81 }
82
83 INFO_(VIDEOPRT, "Got %d legacy access ranges\n", *AccessRangeCount);
84
85 return STATUS_SUCCESS;
86}
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 335 of file resource.c.

342{
344 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
346 PVOID MappedAddress;
348
349 INFO_(VIDEOPRT, "- IoAddress: %lx\n", IoAddress.u.LowPart);
350 INFO_(VIDEOPRT, "- NumberOfUchars: %lx\n", NumberOfUchars);
351 INFO_(VIDEOPRT, "- InIoSpace: %x\n", InIoSpace);
352
353 InIoSpace &= ~VIDEO_MEMORY_SPACE_DENSE;
354
355 if (ProcessHandle != NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
356 {
357 INFO_(VIDEOPRT, "ProcessHandle is not NULL (0x%x) but InIoSpace does not have "
358 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting "
359 "VIDEO_MEMORY_SPACE_USER_MODE.\n",
361 InIoSpace |= VIDEO_MEMORY_SPACE_USER_MODE;
362 }
363 else if (ProcessHandle == NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
364 {
365 INFO_(VIDEOPRT, "ProcessHandle is NULL (0x%x) but InIoSpace does have "
366 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting ProcessHandle "
367 "to NtCurrentProcess()\n",
370 }
371
372 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0 &&
373 !IsListEmpty(&DeviceExtension->AddressMappingListHead))
374 {
375 Entry = DeviceExtension->AddressMappingListHead.Flink;
376 while (Entry != &DeviceExtension->AddressMappingListHead)
377 {
378 AddressMapping = CONTAINING_RECORD(
379 Entry,
381 List);
382 if (IoAddress.QuadPart == AddressMapping->IoAddress.QuadPart &&
383 NumberOfUchars <= AddressMapping->NumberOfUchars)
384 {
385 {
386 AddressMapping->MappingCount++;
387 if (Status)
388 *Status = NO_ERROR;
389 return AddressMapping->MappedAddress;
390 }
391 }
392 Entry = Entry->Flink;
393 }
394 }
395
396 AddressSpace = (ULONG)InIoSpace;
399 DeviceExtension->AdapterInterfaceType,
400 DeviceExtension->SystemIoBusNumber,
401 IoAddress,
404 {
405 if (Status)
407
408 return NULL;
409 }
410
411 /* I/O space */
412 if (AddressSpace != 0)
413 {
414 ASSERT(0 == TranslatedAddress.u.HighPart);
415 if (Status)
416 *Status = NO_ERROR;
417
418 return (PVOID)(ULONG_PTR)TranslatedAddress.u.LowPart;
419 }
420
421 /* user space */
422 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
423 {
424 NTSTATUS NtStatus;
426 if (InIoSpace & VIDEO_MEMORY_SPACE_P6CACHE)
428 else
430 MappedAddress = NULL;
433 NumberOfUchars,
434 Protect,
435 &MappedAddress);
436 if (!NT_SUCCESS(NtStatus))
437 {
438 ERR_(VIDEOPRT, "IntVideoPortMapPhysicalMemory() failed! (0x%x)\n", NtStatus);
439 if (Status)
441 return NULL;
442 }
443 INFO_(VIDEOPRT, "Mapped user address = 0x%08x\n", MappedAddress);
444 }
445 else /* kernel space */
446 {
447 MappedAddress = MmMapIoSpace(
449 NumberOfUchars,
451 }
452
453 if (MappedAddress != NULL)
454 {
455 if (Status)
456 {
457 *Status = NO_ERROR;
458 }
459 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
460 {
461 AddressMapping = ExAllocatePoolWithTag(
462 PagedPool,
465
466 if (AddressMapping == NULL)
467 return MappedAddress;
468
469 RtlZeroMemory(AddressMapping, sizeof(VIDEO_PORT_ADDRESS_MAPPING));
470 AddressMapping->NumberOfUchars = NumberOfUchars;
471 AddressMapping->IoAddress = IoAddress;
472 AddressMapping->SystemIoBusNumber = DeviceExtension->SystemIoBusNumber;
473 AddressMapping->MappedAddress = MappedAddress;
474 AddressMapping->MappingCount = 1;
476 &DeviceExtension->AddressMappingListHead,
477 &AddressMapping->List);
478 }
479
480 return MappedAddress;
481 }
482
483 ERR_(VIDEOPRT,
484 "Couldn't map video memory. IoAddress: 0x%lx, NumberOfUchars: 0x%lx, InIoSpace: 0x%x\n",
485 IoAddress.u.LowPart, NumberOfUchars, InIoSpace);
486 if (Status)
488
489 return NULL;
490}
#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::@2502 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:252
_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 252 of file resource.c.

258{
259 OBJECT_ATTRIBUTES ObjAttribs;
261 HANDLE hMemObj;
263 SIZE_T Size;
264
265 /* Initialize object attribs */
266 RtlInitUnicodeString(&UnicodeString, L"\\Device\\PhysicalMemory");
267 InitializeObjectAttributes(&ObjAttribs,
270 NULL, NULL);
271
272 /* Open physical memory section */
273 Status = ZwOpenSection(&hMemObj, SECTION_ALL_ACCESS, &ObjAttribs);
274 if (!NT_SUCCESS(Status))
275 {
276 WARN_(VIDEOPRT, "ZwOpenSection() failed! (0x%x)\n", Status);
277 return Status;
278 }
279
280 /* Map view of section */
281 Size = SizeInBytes;
282 Status = ZwMapViewOfSection(hMemObj,
283 Process,
285 0,
286 Size,
288 &Size,
289 ViewUnmap,
290 0,
291 Protect);
292 ZwClose(hMemObj);
293 if (!NT_SUCCESS(Status))
294 {
295 WARN_(VIDEOPRT, "ZwMapViewOfSection() failed! (0x%x)\n", Status);
296 }
297
298 return Status;
299}
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#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 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 206 of file resource.c.

208{
210 BOOLEAN ConflictDetected;
211 // An empty CM_RESOURCE_LIST
212 UCHAR EmptyResourceList[FIELD_OFFSET(CM_RESOURCE_LIST, List)] = {0};
213
214 if (DeviceExtension->IsLegacyDevice || DeviceExtension->IsLegacyDetect || DeviceExtension->IsVgaDetect)
215 {
217 DeviceExtension->DriverObject,
218 NULL, 0, /* Driver List */
219 DeviceExtension->PhysicalDeviceObject,
220 (PCM_RESOURCE_LIST)EmptyResourceList,
221 sizeof(EmptyResourceList),
222 &ConflictDetected);
223
224 if (!NT_SUCCESS(Status))
225 {
226 ERR_(VIDEOPRT,
227 "VideoPortReleaseResources (Detect) failed with 0x%08lx ; ConflictDetected: %s\n",
228 Status, ConflictDetected ? "TRUE" : "FALSE");
229 }
230 }
231 else
232 {
234 DeviceExtension->DriverObject,
235 NULL,
236 0,
237 DeviceExtension->PhysicalDeviceObject,
238 (PCM_RESOURCE_LIST)EmptyResourceList,
239 sizeof(EmptyResourceList),
240 FALSE,
241 &ConflictDetected);
242 if (!NT_SUCCESS(Status))
243 {
244 ERR_(VIDEOPRT,
245 "VideoPortReleaseResources (Usage) failed with 0x%08lx ; ConflictDetected: %s\n",
246 Status, ConflictDetected ? "TRUE" : "FALSE");
247 }
248 }
249}
unsigned char BOOLEAN
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 493 of file resource.c.

496{
497 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
500
501 Entry = DeviceExtension->AddressMappingListHead.Flink;
502 while (Entry != &DeviceExtension->AddressMappingListHead)
503 {
504 AddressMapping = CONTAINING_RECORD(
505 Entry,
507 List);
508 if (AddressMapping->MappedAddress == MappedAddress)
509 {
510 ASSERT(AddressMapping->MappingCount > 0);
511 AddressMapping->MappingCount--;
512 if (AddressMapping->MappingCount == 0)
513 {
515 AddressMapping->MappedAddress,
516 AddressMapping->NumberOfUchars);
518 ExFreePool(AddressMapping);
519 }
520 return;
521 }
522
523 Entry = Entry->Flink;
524 }
525
526 /* If there was no kernelmode mapping for the given address found we assume
527 * that the given address is a usermode mapping and try to unmap it.
528 *
529 * FIXME: Is it ok to use NtCurrentProcess?
530 */
531 Status = ZwUnmapViewOfSection(NtCurrentProcess(), MappedAddress);
532 if (!NT_SUCCESS(Status))
533 {
534 WARN_(VIDEOPRT, "Warning: Mapping for address 0x%p not found!\n", MappedAddress);
535 }
536}
#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 1265 of file resource.c.

1269{
1270 TRACE_(VIDEOPRT, "VideoPortAllocateBuffer\n");
1273}
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 1238 of file resource.c.

1243{
1244 TRACE_(VIDEOPRT, "VideoPortAllocatePool\n");
1246}
_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 566 of file resource.c.

569{
570 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
572 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
573 MappedAddress);
574}
#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:493

Referenced by InitializeModeTable().

◆ VideoPortFreePool()

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

Definition at line 1253 of file resource.c.

1256{
1257 ExFreePool(Ptr);
1258}
_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 694 of file resource.c.

704{
705 PCI_SLOT_NUMBER PciSlotNumber;
707 ULONG FunctionNumber;
711 UINT AssignedCount = 0;
714 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
716 USHORT VendorIdToFind;
717 USHORT DeviceIdToFind;
719 PVIDEO_ACCESS_RANGE LegacyAccessRanges;
720 ULONG LegacyAccessRangeCount;
722 ULONG ListSize;
724 BOOLEAN DeviceAndVendorFound = FALSE;
725
726 TRACE_(VIDEOPRT, "VideoPortGetAccessRanges(%d, %p, %d, %p)\n",
727 NumRequestedResources, RequestedResources, NumAccessRanges, AccessRanges);
728
729 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
730 DriverObject = DeviceExtension->DriverObject;
732
733 if (NumRequestedResources == 0)
734 {
735 AllocatedResources = DeviceExtension->AllocatedResources;
736 if (AllocatedResources == NULL &&
737 DeviceExtension->AdapterInterfaceType == PCIBus)
738 {
739 if (DeviceExtension->PhysicalDeviceObject != NULL)
740 {
741 PciSlotNumber.u.AsULONG = DeviceExtension->SystemIoSlotNumber;
742
744 DeviceExtension->SystemIoBusNumber,
745 PciSlotNumber.u.AsULONG,
746 &Config,
747 sizeof(Config));
748
749 if (ReturnedLength != sizeof(Config))
750 {
752 }
753 }
754 else
755 {
756 VendorIdToFind = VendorId != NULL ? *(PUSHORT)VendorId : 0;
757 DeviceIdToFind = DeviceId != NULL ? *(PUSHORT)DeviceId : 0;
758
759 if (VendorIdToFind == 0 && DeviceIdToFind == 0)
760 {
761 /* We're screwed */
762 return ERROR_DEV_NOT_EXIST;
763 }
764
765 INFO_(VIDEOPRT, "Looking for VendorId 0x%04x DeviceId 0x%04x\n",
766 VendorIdToFind, DeviceIdToFind);
767
768 /*
769 * Search for the device id and vendor id on this bus.
770 */
771 PciSlotNumber.u.bits.Reserved = 0;
773 {
774 PciSlotNumber.u.bits.DeviceNumber = DeviceNumber;
775 for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
776 {
777 INFO_(VIDEOPRT, "- Function number: %d\n", FunctionNumber);
778 PciSlotNumber.u.bits.FunctionNumber = FunctionNumber;
780 DeviceExtension->SystemIoBusNumber,
781 PciSlotNumber.u.AsULONG,
782 &Config,
783 sizeof(Config));
784
785 INFO_(VIDEOPRT, "- Length of data: %x\n", ReturnedLength);
786
787 if (ReturnedLength == sizeof(Config))
788 {
789 INFO_(VIDEOPRT, "- Slot 0x%02x (Device %d Function %d) VendorId 0x%04x "
790 "DeviceId 0x%04x\n",
791 PciSlotNumber.u.AsULONG,
792 PciSlotNumber.u.bits.DeviceNumber,
793 PciSlotNumber.u.bits.FunctionNumber,
794 Config.VendorID,
795 Config.DeviceID);
796
797 if ((VendorIdToFind == 0 || Config.VendorID == VendorIdToFind) &&
798 (DeviceIdToFind == 0 || Config.DeviceID == DeviceIdToFind))
799 {
800 DeviceAndVendorFound = TRUE;
801 break;
802 }
803 }
804 }
805 if (DeviceAndVendorFound)
806 break;
807 }
808 if (FunctionNumber == PCI_MAX_FUNCTION)
809 {
810 WARN_(VIDEOPRT, "Didn't find device.\n");
811 return ERROR_DEV_NOT_EXIST;
812 }
813 }
814
815 Status = HalAssignSlotResources(&DeviceExtension->RegistryPath,
816 NULL,
817 DeviceExtension->DriverObject,
818 DeviceExtension->DriverObject->DeviceObject,
819 DeviceExtension->AdapterInterfaceType,
820 DeviceExtension->SystemIoBusNumber,
821 PciSlotNumber.u.AsULONG,
823 if (!NT_SUCCESS(Status))
824 {
825 WARN_(VIDEOPRT, "HalAssignSlotResources failed with status %x.\n",Status);
826 return Status;
827 }
828 DeviceExtension->AllocatedResources = AllocatedResources;
829 DeviceExtension->SystemIoSlotNumber = PciSlotNumber.u.AsULONG;
830
831 /* Add legacy resources to the resources from HAL */
833 &LegacyAccessRanges, &LegacyAccessRangeCount);
834 if (!NT_SUCCESS(Status))
835 return ERROR_DEV_NOT_EXIST;
836
837 if (NumAccessRanges < LegacyAccessRangeCount)
838 {
839 ERR_(VIDEOPRT, "Too many legacy access ranges found\n");
840 return ERROR_NOT_ENOUGH_MEMORY; // ERROR_MORE_DATA;
841 }
842
843 RtlCopyMemory(AccessRanges, LegacyAccessRanges, LegacyAccessRangeCount * sizeof(VIDEO_ACCESS_RANGE));
844 AssignedCount = LegacyAccessRangeCount;
845 }
846 }
847 else
848 {
849 ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + (NumRequestedResources - 1) * sizeof(IO_RESOURCE_DESCRIPTOR);
850 ResReqList = ExAllocatePool(NonPagedPool, ListSize);
851 if (!ResReqList)
853
854 ResReqList->ListSize = ListSize;
855 ResReqList->InterfaceType = DeviceExtension->AdapterInterfaceType;
856 ResReqList->BusNumber = DeviceExtension->SystemIoBusNumber;
857 ResReqList->SlotNumber = DeviceExtension->SystemIoSlotNumber;
858 ResReqList->AlternativeLists = 1;
859 ResReqList->List[0].Version = 1;
860 ResReqList->List[0].Revision = 1;
861 ResReqList->List[0].Count = NumRequestedResources;
862
863 /* Copy in the caller's resource list */
864 RtlCopyMemory(ResReqList->List[0].Descriptors,
865 RequestedResources,
866 NumRequestedResources * sizeof(IO_RESOURCE_DESCRIPTOR));
867
868 Status = IoAssignResources(&DeviceExtension->RegistryPath,
869 NULL,
870 DeviceExtension->DriverObject,
871 DeviceExtension->PhysicalDeviceObject ?
872 DeviceExtension->PhysicalDeviceObject :
873 DeviceExtension->DriverObject->DeviceObject,
874 ResReqList,
876
877 if (!NT_SUCCESS(Status))
878 return Status;
879
880 if (!DeviceExtension->AllocatedResources)
881 DeviceExtension->AllocatedResources = AllocatedResources;
882 }
883
886
887 /* Return the slot number if the caller wants it */
888 if (Slot != NULL) *Slot = DeviceExtension->SystemIoBusNumber;
889
890 FullList = AllocatedResources->List;
891 ASSERT(AllocatedResources->Count == 1);
892 INFO_(VIDEOPRT, "InterfaceType %u BusNumber List %u Device BusNumber %u Version %u Revision %u\n",
893 FullList->InterfaceType, FullList->BusNumber, DeviceExtension->SystemIoBusNumber,
895
896 ASSERT(FullList->InterfaceType == PCIBus);
897 ASSERT(FullList->BusNumber == DeviceExtension->SystemIoBusNumber);
898 ASSERT(1 == FullList->PartialResourceList.Version);
899 ASSERT(1 == FullList->PartialResourceList.Revision);
900
902 Descriptor < FullList->PartialResourceList.PartialDescriptors + FullList->PartialResourceList.Count;
903 Descriptor++)
904 {
905 if ((Descriptor->Type == CmResourceTypeMemory ||
906 Descriptor->Type == CmResourceTypePort) &&
907 AssignedCount >= NumAccessRanges)
908 {
909 ERR_(VIDEOPRT, "Too many access ranges found\n");
910 return ERROR_MORE_DATA;
911 }
912 else if (Descriptor->Type == CmResourceTypeMemory)
913 {
914 INFO_(VIDEOPRT, "Memory range starting at 0x%08x length 0x%08x\n",
915 Descriptor->u.Memory.Start.u.LowPart, Descriptor->u.Memory.Length);
916 AccessRanges[AssignedCount].RangeStart = Descriptor->u.Memory.Start;
917 AccessRanges[AssignedCount].RangeLength = Descriptor->u.Memory.Length;
918 AccessRanges[AssignedCount].RangeInIoSpace = 0;
919 AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
920 AccessRanges[AssignedCount].RangeShareable =
921 (Descriptor->ShareDisposition == CmResourceShareShared);
922 AccessRanges[AssignedCount].RangePassive = 0;
923 AssignedCount++;
924 }
925 else if (Descriptor->Type == CmResourceTypePort)
926 {
927 INFO_(VIDEOPRT, "Port range starting at 0x%04x length %d\n",
928 Descriptor->u.Port.Start.u.LowPart, Descriptor->u.Port.Length);
929 AccessRanges[AssignedCount].RangeStart = Descriptor->u.Port.Start;
930 AccessRanges[AssignedCount].RangeLength = Descriptor->u.Port.Length;
931 AccessRanges[AssignedCount].RangeInIoSpace = 1;
932 AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
933 AccessRanges[AssignedCount].RangeShareable =
934 (Descriptor->ShareDisposition == CmResourceShareShared);
935 AccessRanges[AssignedCount].RangePassive = 0;
937 AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_10_BIT_DECODE;
939 AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_PASSIVE_DECODE;
940 AssignedCount++;
941 }
942 else if (Descriptor->Type == CmResourceTypeInterrupt)
943 {
944 DeviceExtension->InterruptLevel = Descriptor->u.Interrupt.Level;
945 DeviceExtension->InterruptVector = Descriptor->u.Interrupt.Vector;
946 if (Descriptor->ShareDisposition == CmResourceShareShared)
947 DeviceExtension->InterruptShared = TRUE;
948 else
949 DeviceExtension->InterruptShared = FALSE;
950 }
951 // else if (Descriptor->Type == CmResourceTypeDma) // TODO!
952 else
953 {
954 ASSERT(FALSE);
956 }
957 }
958
959 return NO_ERROR;
960}
_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::@4345::@4346 bits
union _PCI_SLOT_NUMBER::@4345 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 1389 of file resource.c.

1396{
1397 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
1398
1399 TRACE_(VIDEOPRT, "VideoPortGetBusData\n");
1400
1401 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
1402
1403 if (BusDataType != Cmos)
1404 {
1405 /* Legacy vs. PnP behaviour */
1406 if (DeviceExtension->PhysicalDeviceObject != NULL)
1407 SlotNumber = DeviceExtension->SystemIoSlotNumber;
1408 }
1409
1410 return HalGetBusDataByOffset(
1411 BusDataType,
1412 DeviceExtension->SystemIoBusNumber,
1413 SlotNumber,
1414 Buffer,
1415 Offset,
1416 Length);
1417}
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 545 of file resource.c.

550{
551 TRACE_(VIDEOPRT, "VideoPortGetDeviceBase\n");
553 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
554 IoAddress,
555 NumberOfUchars,
556 InIoSpace,
557 NULL,
558 NULL);
559}
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:335

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 1222 of file resource.c.

1227{
1228 TRACE_(VIDEOPRT, "VideoPortGetDeviceData\n");
1231}
#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 1293 of file resource.c.

1298{
1299 PMDL Mdl;
1300
1302 if (!Mdl)
1303 {
1304 return NULL;
1305 }
1306 /* FIXME use seh */
1308 return Mdl;
1309}
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 1317 of file resource.c.

1323{
1324 PVOID Buffer;
1325
1326 /* clear output buffer */
1327 pVrp->OutputBuffer = NULL;
1328
1329 if (DmaFlags != VideoPortDmaInitOnly)
1330 {
1331 /* VideoPortKeepPagesLocked / VideoPortUnlockAfterDma is no-op */
1332 return FALSE;
1333 }
1334
1335 /* lock the buffer */
1336 Buffer = VideoPortLockBuffer(HwDeviceExtension, pVrp->InputBuffer, pVrp->InputBufferLength, IoModifyAccess);
1337
1338 if (Buffer)
1339 {
1340 /* store result buffer & length */
1341 pVrp->OutputBuffer = Buffer;
1342 pVrp->OutputBufferLength = pVrp->InputBufferLength;
1343
1344 /* operation succeeded */
1345 return TRUE;
1346 }
1347
1348 /* operation failed */
1349 return FALSE;
1350}
@ 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:1293
@ 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 581 of file resource.c.

591{
592 TRACE_(VIDEOPRT, "VideoPortMapBankedMemory\n");
595}

◆ VideoPortMapMemory()

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

Definition at line 603 of file resource.c.

609{
610 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
612
613 TRACE_(VIDEOPRT, "VideoPortMapMemory\n");
614 INFO_(VIDEOPRT, "- *VirtualAddress: 0x%x\n", *VirtualAddress);
615
616 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
618 DeviceExtension,
620 *Length,
621 *InIoSpace,
623 &Status);
624
625 return Status;
626}

◆ VideoPortReleaseBuffer()

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

Definition at line 1280 of file resource.c.

1283{
1284 TRACE_(VIDEOPRT, "VideoPortReleaseBuffer\n");
1285 ExFreePool(Ptr);
1286}

◆ 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 1424 of file resource.c.

1431{
1432 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
1433
1434 TRACE_(VIDEOPRT, "VideoPortSetBusData\n");
1435
1436 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
1437
1438 if (BusDataType != Cmos)
1439 {
1440 /* Legacy vs. PnP behaviour */
1441 if (DeviceExtension->PhysicalDeviceObject != NULL)
1442 SlotNumber = DeviceExtension->SystemIoSlotNumber;
1443 }
1444
1445 return HalSetBusDataByOffset(
1446 BusDataType,
1447 DeviceExtension->SystemIoBusNumber,
1448 SlotNumber,
1449 Buffer,
1450 Offset,
1451 Length);
1452}
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 1374 of file resource.c.

1378{
1380 /* Should store the ranges in the device extension for use by ntvdm. */
1381 return NO_ERROR;
1382}

◆ VideoPortUnlockBuffer()

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

Definition at line 1358 of file resource.c.

1361{
1362 if (Mdl)
1363 {
1365 IoFreeMdl(Mdl);
1366 }
1367}
#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 633 of file resource.c.

637{
638 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
639
641 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
643
644 return NO_ERROR;
645}

◆ 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 984 of file resource.c.

988{
989 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
990 BOOLEAN ConflictDetected;
991 ULONG ResourceListSize;
993 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
994 ULONG i;
996
997 TRACE_(VIDEOPRT, "VideoPortVerifyAccessRanges\n");
998
999 /* Verify parameters */
1000 if (NumAccessRanges && !AccessRanges)
1002
1003 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
1004
1005 if (NumAccessRanges == 0)
1006 {
1007 /* Release the resources and do nothing more for now... */
1008 IntVideoPortReleaseResources(DeviceExtension);
1009 /* If releasing VGA device resources, clear tracked ranges */
1010 if (DeviceExtension->IsVgaDriver)
1011 {
1013 if (VgaRanges)
1014 {
1016 VgaRanges = NULL;
1017 }
1018 NumOfVgaRanges = 0;
1021 }
1022 return NO_ERROR;
1023 }
1024
1025 /*
1026 * For non-legacy PCI devices, validate that the relevant I/O or memory
1027 * decoding bits are enabled in the PCI command register before claiming
1028 */
1029 if (!DeviceExtension->IsLegacyDevice && DeviceExtension->AdapterInterfaceType == PCIBus)
1030 {
1031 USHORT PciCommand;
1033
1035 DeviceExtension->SystemIoBusNumber,
1036 DeviceExtension->SystemIoSlotNumber,
1037 &PciCommand,
1039 sizeof(PciCommand));
1040 if (BytesRead == sizeof(PciCommand))
1041 {
1042 for (i = 0; i < NumAccessRanges; i++)
1043 {
1044 if (AccessRanges[i].RangeInIoSpace)
1045 {
1046 if ((PciCommand & PCI_ENABLE_IO_SPACE) == 0)
1047 {
1048 WARN_(VIDEOPRT, "PCI I/O space disabled; refusing access range claim\n");
1050 }
1051 }
1052 else
1053 {
1054 if ((PciCommand & PCI_ENABLE_MEMORY_SPACE) == 0)
1055 {
1056 WARN_(VIDEOPRT, "PCI memory space disabled; refusing access range claim\n");
1058 }
1059 }
1060 }
1061 }
1062 }
1063
1064 /* Determine which ranges need to be claimed (exclude PnP-assigned ones) */
1065 ULONG Needed = 0;
1066 for (i = 0; i < NumAccessRanges; ++i)
1067 {
1068 if (DeviceExtension->PhysicalDeviceObject && !DeviceExtension->IsLegacyDevice)
1069 {
1070 if (IntAccessRangeIsInAllocatedResources(DeviceExtension, &AccessRanges[i]))
1071 continue;
1072 }
1073 ++Needed;
1074 }
1075
1076 if (Needed == 0)
1077 {
1078 /* Nothing to report/claim */
1079 return NO_ERROR;
1080 }
1081
1082 /* Create the resource list for the non-PnP-assigned ranges */
1083 ResourceListSize = sizeof(CM_RESOURCE_LIST)
1084 + (Needed - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
1086 if (!ResourceList)
1087 {
1088 WARN_(VIDEOPRT, "ExAllocatePool() failed\n");
1090 }
1091
1092 /* Fill resource list */
1093 ResourceList->Count = 1;
1094 ResourceList->List[0].InterfaceType = DeviceExtension->AdapterInterfaceType;
1095 ResourceList->List[0].BusNumber = DeviceExtension->SystemIoBusNumber;
1096 ResourceList->List[0].PartialResourceList.Version = 1;
1097 ResourceList->List[0].PartialResourceList.Revision = 1;
1098 ResourceList->List[0].PartialResourceList.Count = Needed;
1099
1100 ULONG j = 0;
1101 for (i = 0; i < NumAccessRanges; ++i)
1102 {
1103 if (DeviceExtension->PhysicalDeviceObject && !DeviceExtension->IsLegacyDevice)
1104 {
1105 if (IntAccessRangeIsInAllocatedResources(DeviceExtension, &AccessRanges[i]))
1106 continue;
1107 }
1108
1109 PartialDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[j++];
1110 if (AccessRanges[i].RangeInIoSpace)
1111 {
1112 PartialDescriptor->Type = CmResourceTypePort;
1113 PartialDescriptor->u.Port.Start = AccessRanges[i].RangeStart;
1114 PartialDescriptor->u.Port.Length = AccessRanges[i].RangeLength;
1115 }
1116 else
1117 {
1118 PartialDescriptor->Type = CmResourceTypeMemory;
1119 PartialDescriptor->u.Memory.Start = AccessRanges[i].RangeStart;
1120 PartialDescriptor->u.Memory.Length = AccessRanges[i].RangeLength;
1121 }
1122 PartialDescriptor->ShareDisposition = AccessRanges[i].RangeShareable ?
1124 PartialDescriptor->Flags = 0;
1125 if (AccessRanges[i].RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
1126 PartialDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
1127 if (AccessRanges[i].RangePassive & VIDEO_RANGE_10_BIT_DECODE)
1128 PartialDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
1129 }
1130
1131 if (DeviceExtension->IsLegacyDevice || DeviceExtension->IsLegacyDetect || DeviceExtension->IsVgaDetect)
1132 {
1134 DeviceExtension->DriverObject,
1135 NULL, 0, /* Driver List */
1136 DeviceExtension->PhysicalDeviceObject,
1137 ResourceList, ResourceListSize,
1138 &ConflictDetected);
1139
1140 /* IntIsVgaSaveDriver() will later ignore STATUS_CONFLICTING_ADDRESSES, but we still claim it */
1141 if (!NT_SUCCESS(Status) && IntIsVgaSaveDriver(DeviceExtension))
1142 {
1143 NTSTATUS fbStatus;
1144 BOOLEAN fbConflict = FALSE;
1146 DeviceExtension->DriverObject,
1147 NULL,
1148 0,
1149 DeviceExtension->PhysicalDeviceObject,
1151 ResourceListSize,
1152 FALSE,
1153 &fbConflict);
1154 INFO_(VIDEOPRT, "VGA detect->usage fallback: Status=0x%lx Conflict=%d fbStatus=0x%lx fbConflict=%d\n",
1155 Status, ConflictDetected, fbStatus, fbConflict);
1156 Status = fbStatus;
1157 ConflictDetected = fbConflict;
1158 }
1159 }
1160 else
1161 {
1163 DeviceExtension->DriverObject,
1164 NULL,
1165 0,
1166 DeviceExtension->PhysicalDeviceObject,
1168 ResourceListSize,
1169 FALSE,
1170 &ConflictDetected);
1171 }
1173
1174 /* If VgaSave driver is conflicting and we don't explicitely want
1175 * to use it, ignore the problem (because win32k will try to use
1176 * this driver only if all other ones are failing). */
1177 if ((Status == STATUS_CONFLICTING_ADDRESSES || ConflictDetected) &&
1178 IntIsVgaSaveDriver(DeviceExtension) &&
1179 !VpBaseVideo)
1180 {
1181 return NO_ERROR;
1182 }
1183
1184 if (!NT_SUCCESS(Status) || ConflictDetected)
1186 else
1187 {
1188 /* Track VGA access ranges on success for fallback handling */
1189 if (DeviceExtension->IsVgaDriver)
1190 {
1192 if (VgaRanges)
1193 {
1195 VgaRanges = NULL;
1196 NumOfVgaRanges = 0;
1197 }
1198 if (NumAccessRanges)
1199 {
1200 SIZE_T sz = NumAccessRanges * sizeof(VIDEO_ACCESS_RANGE);
1202 if (VgaRanges)
1203 {
1204 RtlCopyMemory(VgaRanges, AccessRanges, sz);
1205 NumOfVgaRanges = NumAccessRanges;
1206 VgaDeviceExtension = DeviceExtension;
1207 }
1208 }
1210 }
1211 /* Leave VGA detect phase after first successful claim */
1212 DeviceExtension->IsVgaDetect = FALSE;
1213 return NO_ERROR;
1214 }
1215}
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:302
static BOOLEAN IntIsVgaSaveDriver(IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
Definition: resource.c:34
BOOLEAN VpBaseVideo
Definition: videoprt.c:36
VOID IntVideoPortReleaseResources(_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
Definition: resource.c:206
#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().