ReactOS 0.4.17-dev-1190-g4c812f4
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
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@494::@496 Port
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@494 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@494::@499 Memory
CM_FULL_RESOURCE_DESCRIPTOR List[1]
Definition: restypes.h:150

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
#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:24
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
_In_ PIRP Irp
Definition: kse.h:79
#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:1925
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::@2498::@2499 Port
union _IO_RESOURCE_DESCRIPTOR::@2498 u
struct _IO_RESOURCE_DESCRIPTOR::@2498::@2500 Memory
IO_RESOURCE_DESCRIPTOR Descriptors[1]
Definition: iotypes.h:2752
INTERFACE_TYPE InterfaceType
Definition: iotypes.h:2757
IO_RESOURCE_LIST List[1]
Definition: iotypes.h:2762
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:99
#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{
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)
_In_ ULONG _In_ PCI_SLOT_NUMBER _In_ PPCI_COMMON_HEADER PciConfig
Definition: pciidex.h:67
@ 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;
341
342 INFO_(VIDEOPRT, "- IoAddress: %lx\n", IoAddress.u.LowPart);
343 INFO_(VIDEOPRT, "- NumberOfUchars: %lx\n", NumberOfUchars);
344 INFO_(VIDEOPRT, "- InIoSpace: %x\n", InIoSpace);
345
346 InIoSpace &= ~VIDEO_MEMORY_SPACE_DENSE;
347
348 if (ProcessHandle != NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
349 {
350 INFO_(VIDEOPRT, "ProcessHandle is not NULL (0x%x) but InIoSpace does not have "
351 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting "
352 "VIDEO_MEMORY_SPACE_USER_MODE.\n",
354 InIoSpace |= VIDEO_MEMORY_SPACE_USER_MODE;
355 }
356 else if (ProcessHandle == NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
357 {
358 INFO_(VIDEOPRT, "ProcessHandle is NULL (0x%x) but InIoSpace does have "
359 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting ProcessHandle "
360 "to NtCurrentProcess()\n",
363 }
364
365 CacheType = (InIoSpace & VIDEO_MEMORY_SPACE_P6CACHE) ?
367
368 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0 &&
369 !IsListEmpty(&DeviceExtension->AddressMappingListHead))
370 {
371 Entry = DeviceExtension->AddressMappingListHead.Flink;
372 while (Entry != &DeviceExtension->AddressMappingListHead)
373 {
374 AddressMapping = CONTAINING_RECORD(
375 Entry,
377 List);
378 if (IoAddress.QuadPart == AddressMapping->IoAddress.QuadPart &&
379 NumberOfUchars <= AddressMapping->NumberOfUchars &&
380 CacheType == AddressMapping->CacheType)
381 {
382 {
383 AddressMapping->MappingCount++;
384 if (Status)
385 *Status = NO_ERROR;
386 return AddressMapping->MappedAddress;
387 }
388 }
389 Entry = Entry->Flink;
390 }
391 }
392
393 AddressSpace = (ULONG)InIoSpace;
396 DeviceExtension->AdapterInterfaceType,
397 DeviceExtension->SystemIoBusNumber,
398 IoAddress,
401 {
402 if (Status)
404
405 return NULL;
406 }
407
408 /* I/O space */
409 if (AddressSpace != 0)
410 {
411 ASSERT(0 == TranslatedAddress.u.HighPart);
412 if (Status)
413 *Status = NO_ERROR;
414
415 return (PVOID)(ULONG_PTR)TranslatedAddress.u.LowPart;
416 }
417
418 /* user space */
419 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
420 {
421 NTSTATUS NtStatus;
425 else
427 MappedAddress = NULL;
430 NumberOfUchars,
431 Protect,
432 &MappedAddress);
433 if (!NT_SUCCESS(NtStatus))
434 {
435 ERR_(VIDEOPRT, "IntVideoPortMapPhysicalMemory() failed! (0x%x)\n", NtStatus);
436 if (Status)
438 return NULL;
439 }
440 INFO_(VIDEOPRT, "Mapped user address = 0x%08x\n", MappedAddress);
441 }
442 else /* kernel space */
443 {
444 MappedAddress = MmMapIoSpace(
446 NumberOfUchars,
447 CacheType);
448 }
449
450 if (MappedAddress != NULL)
451 {
452 if (Status)
453 {
454 *Status = NO_ERROR;
455 }
456 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
457 {
458 AddressMapping = ExAllocatePoolWithTag(
459 PagedPool,
462
463 if (AddressMapping == NULL)
464 return MappedAddress;
465
466 RtlZeroMemory(AddressMapping, sizeof(VIDEO_PORT_ADDRESS_MAPPING));
467 AddressMapping->NumberOfUchars = NumberOfUchars;
468 AddressMapping->IoAddress = IoAddress;
469 AddressMapping->SystemIoBusNumber = DeviceExtension->SystemIoBusNumber;
470 AddressMapping->MappedAddress = MappedAddress;
471 AddressMapping->CacheType = CacheType;
472 AddressMapping->MappingCount = 1;
474 &DeviceExtension->AddressMappingListHead,
475 &AddressMapping->List);
476 }
477
478 return MappedAddress;
479 }
480
481 ERR_(VIDEOPRT,
482 "Couldn't map video memory. IoAddress: 0x%lx, NumberOfUchars: 0x%lx, InIoSpace: 0x%x\n",
483 IoAddress.u.LowPart, NumberOfUchars, InIoSpace);
484 if (Status)
486
487 return NULL;
488}
#define NO_ERROR
Definition: dderror.h:5
_In_ ULONG _In_ MEMORY_CACHING_TYPE CacheType
Definition: dispmprt.h:713
#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:407
#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
Entry
Definition: section.c:5216
Definition: typedefs.h:120
MEMORY_CACHING_TYPE CacheType
Definition: videoprt.h:51
PHYSICAL_ADDRESS IoAddress
Definition: videoprt.h:49
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
struct _LARGE_INTEGER::@2753 u
static int Protect(const char **args)
Definition: vfdcmd.c:2132
#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
enum _MEMORY_CACHING_TYPE MEMORY_CACHING_TYPE
@ MmNonCached
Definition: mmtypes.h:129
@ MmWriteCombined
Definition: mmtypes.h:131
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78

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}
_In_ ULONG _In_ MEMORY_CACHING_TYPE _Out_ PPHYSICAL_ADDRESS PhysicalAddress
Definition: dispmprt.h:714
_In_ ULONG _In_ MEMORY_CACHING_TYPE _Out_ PPHYSICAL_ADDRESS _Out_ PVOID * VirtualAddress
Definition: dispmprt.h:716
#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:115
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
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PCUNICODE_STRING UnicodeString
Definition: wdfstring.h:64

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
unsigned char UCHAR
Definition: typedefs.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
static UNICODE_STRING VideoClassName
Definition: resource.c:29

Referenced by IntVideoPortFindAdapter(), and VideoPortVerifyAccessRanges().

◆ IntVideoPortUnmapMemory()

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

Definition at line 491 of file resource.c.

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

Referenced by VideoPortFreeDeviceBase(), and VideoPortUnmapMemory().

◆ VideoPortAllocateBuffer()

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

Definition at line 1262 of file resource.c.

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

1240{
1241 TRACE_(VIDEOPRT, "VideoPortAllocatePool\n");
1243}
_Must_inspect_result_ _In_ UCXENDPOINT _In_ PVOID Tag
Definition: ucxendpoint.h:325
_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 564 of file resource.c.

567{
568 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
570 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
571 MappedAddress);
572}
#define VIDEO_PORT_GET_DEVICE_EXTENSION(MiniportExtension)
Definition: videoprt.h:146
VOID NTAPI IntVideoPortUnmapMemory(IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, IN PVOID MappedAddress)
Definition: resource.c:491

Referenced by InitializeModeTable().

◆ VideoPortFreePool()

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

Definition at line 1250 of file resource.c.

1253{
1254 ExFreePool(Ptr);
1255}
_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 692 of file resource.c.

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

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

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

548{
549 TRACE_(VIDEOPRT, "VideoPortGetDeviceBase\n");
551 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
552 IoAddress,
553 NumberOfUchars,
554 InIoSpace,
555 NULL,
556 NULL);
557}
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 1219 of file resource.c.

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

1295{
1296 PMDL Mdl;
1297
1299 if (!Mdl)
1300 {
1301 return NULL;
1302 }
1303 /* FIXME use seh */
1305 return Mdl;
1306}
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:928
#define KernelMode
Definition: asm.h:38
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize _Pre_valid_ PVOID * BaseAddress
Definition: mmfuncs.h:408
_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 1314 of file resource.c.

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

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

589{
590 TRACE_(VIDEOPRT, "VideoPortMapBankedMemory\n");
593}

◆ VideoPortMapMemory()

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

Definition at line 601 of file resource.c.

607{
608 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
610
611 TRACE_(VIDEOPRT, "VideoPortMapMemory\n");
612 INFO_(VIDEOPRT, "- *VirtualAddress: 0x%x\n", *VirtualAddress);
613
614 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
616 DeviceExtension,
618 *Length,
619 *InIoSpace,
621 &Status);
622
623 return Status;
624}

◆ VideoPortReleaseBuffer()

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

Definition at line 1277 of file resource.c.

1280{
1281 TRACE_(VIDEOPRT, "VideoPortReleaseBuffer\n");
1282 ExFreePool(Ptr);
1283}

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

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

1375{
1377 /* Should store the ranges in the device extension for use by ntvdm. */
1378 return NO_ERROR;
1379}

◆ VideoPortUnlockBuffer()

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

Definition at line 1355 of file resource.c.

1358{
1359 if (Mdl)
1360 {
1362 IoFreeMdl(Mdl);
1363 }
1364}
#define IoFreeMdl
Definition: fxmdl.h:89
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1432

◆ VideoPortUnmapMemory()

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

Definition at line 631 of file resource.c.

635{
636 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
637
639 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
641
642 return NO_ERROR;
643}

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

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