ReactOS 0.4.16-dev-570-g1868985
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)
 
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
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 24 of file resource.c.

Function Documentation

◆ IntIsVgaSaveDriver()

static BOOLEAN IntIsVgaSaveDriver ( IN PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension)
static

Definition at line 32 of file resource.c.

34{
35 UNICODE_STRING VgaSave = RTL_CONSTANT_STRING(L"\\Driver\\VgaSave");
36 return RtlEqualUnicodeString(&VgaSave, &DeviceExtension->DriverObject->DriverName, TRUE);
37}
#define TRUE
Definition: types.h:120
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define L(x)
Definition: ntvdm.h:50
#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 87 of file resource.c.

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

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

287{
289 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
291 PVOID MappedAddress;
293
294 INFO_(VIDEOPRT, "- IoAddress: %lx\n", IoAddress.u.LowPart);
295 INFO_(VIDEOPRT, "- NumberOfUchars: %lx\n", NumberOfUchars);
296 INFO_(VIDEOPRT, "- InIoSpace: %x\n", InIoSpace);
297
298 InIoSpace &= ~VIDEO_MEMORY_SPACE_DENSE;
299 if ((InIoSpace & VIDEO_MEMORY_SPACE_P6CACHE) != 0)
300 {
301 INFO_(VIDEOPRT, "VIDEO_MEMORY_SPACE_P6CACHE not supported, turning off\n");
302 InIoSpace &= ~VIDEO_MEMORY_SPACE_P6CACHE;
303 }
304
305 if (ProcessHandle != NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
306 {
307 INFO_(VIDEOPRT, "ProcessHandle is not NULL (0x%x) but InIoSpace does not have "
308 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting "
309 "VIDEO_MEMORY_SPACE_USER_MODE.\n",
311 InIoSpace |= VIDEO_MEMORY_SPACE_USER_MODE;
312 }
313 else if (ProcessHandle == NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
314 {
315 INFO_(VIDEOPRT, "ProcessHandle is NULL (0x%x) but InIoSpace does have "
316 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting ProcessHandle "
317 "to NtCurrentProcess()\n",
320 }
321
322 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0 &&
323 !IsListEmpty(&DeviceExtension->AddressMappingListHead))
324 {
325 Entry = DeviceExtension->AddressMappingListHead.Flink;
326 while (Entry != &DeviceExtension->AddressMappingListHead)
327 {
328 AddressMapping = CONTAINING_RECORD(
329 Entry,
331 List);
332 if (IoAddress.QuadPart == AddressMapping->IoAddress.QuadPart &&
333 NumberOfUchars <= AddressMapping->NumberOfUchars)
334 {
335 {
336 AddressMapping->MappingCount++;
337 if (Status)
338 *Status = NO_ERROR;
339 return AddressMapping->MappedAddress;
340 }
341 }
342 Entry = Entry->Flink;
343 }
344 }
345
346 AddressSpace = (ULONG)InIoSpace;
347 AddressSpace &= ~VIDEO_MEMORY_SPACE_USER_MODE;
349 DeviceExtension->AdapterInterfaceType,
350 DeviceExtension->SystemIoBusNumber,
351 IoAddress,
354 {
355 if (Status)
357
358 return NULL;
359 }
360
361 /* I/O space */
362 if (AddressSpace != 0)
363 {
364 ASSERT(0 == TranslatedAddress.u.HighPart);
365 if (Status)
366 *Status = NO_ERROR;
367
368 return (PVOID)(ULONG_PTR)TranslatedAddress.u.LowPart;
369 }
370
371 /* user space */
372 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
373 {
374 NTSTATUS NtStatus;
375 MappedAddress = NULL;
378 NumberOfUchars,
379 PAGE_READWRITE/* | PAGE_WRITECOMBINE*/,
380 &MappedAddress);
381 if (!NT_SUCCESS(NtStatus))
382 {
383 WARN_(VIDEOPRT, "IntVideoPortMapPhysicalMemory() failed! (0x%x)\n", NtStatus);
384 if (Status)
385 *Status = NO_ERROR;
386 return NULL;
387 }
388 INFO_(VIDEOPRT, "Mapped user address = 0x%08x\n", MappedAddress);
389 }
390 else /* kernel space */
391 {
392 MappedAddress = MmMapIoSpace(
394 NumberOfUchars,
396 }
397
398 if (MappedAddress != NULL)
399 {
400 if (Status)
401 {
402 *Status = NO_ERROR;
403 }
404 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
405 {
406 AddressMapping = ExAllocatePoolWithTag(
407 PagedPool,
410
411 if (AddressMapping == NULL)
412 return MappedAddress;
413
414 RtlZeroMemory(AddressMapping, sizeof(VIDEO_PORT_ADDRESS_MAPPING));
415 AddressMapping->NumberOfUchars = NumberOfUchars;
416 AddressMapping->IoAddress = IoAddress;
417 AddressMapping->SystemIoBusNumber = DeviceExtension->SystemIoBusNumber;
418 AddressMapping->MappedAddress = MappedAddress;
419 AddressMapping->MappingCount = 1;
421 &DeviceExtension->AddressMappingListHead,
422 &AddressMapping->List);
423 }
424
425 return MappedAddress;
426 }
427
428 if (Status)
429 *Status = NO_ERROR;
430
431 return NULL;
432}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#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_READWRITE
Definition: nt_native.h:1304
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define VIDEO_MEMORY_SPACE_USER_MODE
Definition: video.h:134
#define VIDEO_MEMORY_SPACE_P6CACHE
Definition: video.h:136
#define WARN_(ch,...)
Definition: debug.h:157
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::@2306 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:229
_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

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

235{
236 OBJECT_ATTRIBUTES ObjAttribs;
238 HANDLE hMemObj;
240 SIZE_T Size;
241
242 /* Initialize object attribs */
243 RtlInitUnicodeString(&UnicodeString, L"\\Device\\PhysicalMemory");
244 InitializeObjectAttributes(&ObjAttribs,
247 NULL, NULL);
248
249 /* Open physical memory section */
250 Status = ZwOpenSection(&hMemObj, SECTION_ALL_ACCESS, &ObjAttribs);
251 if (!NT_SUCCESS(Status))
252 {
253 WARN_(VIDEOPRT, "ZwOpenSection() failed! (0x%x)\n", Status);
254 return Status;
255 }
256
257 /* Map view of section */
258 Size = SizeInBytes;
259 Status = ZwMapViewOfSection(hMemObj,
260 Process,
262 0,
263 Size,
265 &Size,
266 ViewUnmap,
267 0,
268 Protect);
269 ZwClose(hMemObj);
270 if (!NT_SUCCESS(Status))
271 {
272 WARN_(VIDEOPRT, "ZwMapViewOfSection() failed! (0x%x)\n", Status);
273 }
274
275 return Status;
276}
_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:1293
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
@ ViewUnmap
Definition: nt_native.h:1279
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:4533
_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
_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 IntAgpCommitVirtual(), and IntVideoPortMapMemory().

◆ IntVideoPortReleaseResources()

VOID IntVideoPortReleaseResources ( _In_ PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 204 of file resource.c.

206{
208 BOOLEAN ConflictDetected;
209 // An empty CM_RESOURCE_LIST
210 UCHAR EmptyResourceList[FIELD_OFFSET(CM_RESOURCE_LIST, List)] = {0};
211
213 DeviceExtension->DriverObject,
214 NULL, 0, /* Driver List */
215 DeviceExtension->PhysicalDeviceObject,
216 (PCM_RESOURCE_LIST)EmptyResourceList,
217 sizeof(EmptyResourceList),
218 &ConflictDetected);
219
220 if (!NT_SUCCESS(Status))
221 {
222 DPRINT1("VideoPortReleaseResources IoReportResource failed with 0x%08lx ; ConflictDetected: %s\n",
223 Status, ConflictDetected ? "TRUE" : "FALSE");
224 }
225 /* Ignore the returned status however... */
226}
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
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
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by VideoPortVerifyAccessRanges().

◆ IntVideoPortUnmapMemory()

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

Definition at line 435 of file resource.c.

438{
439 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
442
443 Entry = DeviceExtension->AddressMappingListHead.Flink;
444 while (Entry != &DeviceExtension->AddressMappingListHead)
445 {
446 AddressMapping = CONTAINING_RECORD(
447 Entry,
449 List);
450 if (AddressMapping->MappedAddress == MappedAddress)
451 {
452 ASSERT(AddressMapping->MappingCount > 0);
453 AddressMapping->MappingCount--;
454 if (AddressMapping->MappingCount == 0)
455 {
457 AddressMapping->MappedAddress,
458 AddressMapping->NumberOfUchars);
460 ExFreePool(AddressMapping);
461 }
462 return;
463 }
464
465 Entry = Entry->Flink;
466 }
467
468 /* If there was no kernelmode mapping for the given address found we assume
469 * that the given address is a usermode mapping and try to unmap it.
470 *
471 * FIXME: Is it ok to use NtCurrentProcess?
472 */
473 Status = ZwUnmapViewOfSection(NtCurrentProcess(), MappedAddress);
474 if (!NT_SUCCESS(Status))
475 {
476 WARN_(VIDEOPRT, "Warning: Mapping for address 0x%p not found!\n", MappedAddress);
477 }
478}
#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 1071 of file resource.c.

1075{
1076 TRACE_(VIDEOPRT, "VideoPortAllocateBuffer\n");
1079}
Definition: bufpool.h:45
#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 1044 of file resource.c.

1049{
1050 TRACE_(VIDEOPRT, "VideoPortAllocatePool\n");
1052}
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_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 508 of file resource.c.

511{
512 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
514 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
515 MappedAddress);
516}
#define VIDEO_PORT_GET_DEVICE_EXTENSION(MiniportExtension)
Definition: videoprt.h:140
VOID NTAPI IntVideoPortUnmapMemory(IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, IN PVOID MappedAddress)
Definition: resource.c:435

Referenced by InitializeModeTable().

◆ VideoPortFreePool()

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

Definition at line 1059 of file resource.c.

1062{
1063 ExFreePool(Ptr);
1064}
_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 636 of file resource.c.

646{
647 PCI_SLOT_NUMBER PciSlotNumber;
649 ULONG FunctionNumber;
653 UINT AssignedCount = 0;
656 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
658 USHORT VendorIdToFind;
659 USHORT DeviceIdToFind;
661 PVIDEO_ACCESS_RANGE LegacyAccessRanges;
662 ULONG LegacyAccessRangeCount;
664 ULONG ListSize;
666 BOOLEAN DeviceAndVendorFound = FALSE;
667
668 TRACE_(VIDEOPRT, "VideoPortGetAccessRanges(%d, %p, %d, %p)\n",
669 NumRequestedResources, RequestedResources, NumAccessRanges, AccessRanges);
670
671 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
672 DriverObject = DeviceExtension->DriverObject;
674
675 if (NumRequestedResources == 0)
676 {
677 AllocatedResources = DeviceExtension->AllocatedResources;
678 if (AllocatedResources == NULL &&
679 DeviceExtension->AdapterInterfaceType == PCIBus)
680 {
681 if (DeviceExtension->PhysicalDeviceObject != NULL)
682 {
683 PciSlotNumber.u.AsULONG = DeviceExtension->SystemIoSlotNumber;
684
686 DeviceExtension->SystemIoBusNumber,
687 PciSlotNumber.u.AsULONG,
688 &Config,
689 sizeof(Config));
690
691 if (ReturnedLength != sizeof(Config))
692 {
694 }
695 }
696 else
697 {
698 VendorIdToFind = VendorId != NULL ? *(PUSHORT)VendorId : 0;
699 DeviceIdToFind = DeviceId != NULL ? *(PUSHORT)DeviceId : 0;
700
701 if (VendorIdToFind == 0 && DeviceIdToFind == 0)
702 {
703 /* We're screwed */
704 return ERROR_DEV_NOT_EXIST;
705 }
706
707 INFO_(VIDEOPRT, "Looking for VendorId 0x%04x DeviceId 0x%04x\n",
708 VendorIdToFind, DeviceIdToFind);
709
710 /*
711 * Search for the device id and vendor id on this bus.
712 */
713 PciSlotNumber.u.bits.Reserved = 0;
715 {
716 PciSlotNumber.u.bits.DeviceNumber = DeviceNumber;
717 for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
718 {
719 INFO_(VIDEOPRT, "- Function number: %d\n", FunctionNumber);
720 PciSlotNumber.u.bits.FunctionNumber = FunctionNumber;
722 DeviceExtension->SystemIoBusNumber,
723 PciSlotNumber.u.AsULONG,
724 &Config,
725 sizeof(Config));
726
727 INFO_(VIDEOPRT, "- Length of data: %x\n", ReturnedLength);
728
729 if (ReturnedLength == sizeof(Config))
730 {
731 INFO_(VIDEOPRT, "- Slot 0x%02x (Device %d Function %d) VendorId 0x%04x "
732 "DeviceId 0x%04x\n",
733 PciSlotNumber.u.AsULONG,
734 PciSlotNumber.u.bits.DeviceNumber,
735 PciSlotNumber.u.bits.FunctionNumber,
736 Config.VendorID,
737 Config.DeviceID);
738
739 if ((VendorIdToFind == 0 || Config.VendorID == VendorIdToFind) &&
740 (DeviceIdToFind == 0 || Config.DeviceID == DeviceIdToFind))
741 {
742 DeviceAndVendorFound = TRUE;
743 break;
744 }
745 }
746 }
747 if (DeviceAndVendorFound)
748 break;
749 }
750 if (FunctionNumber == PCI_MAX_FUNCTION)
751 {
752 WARN_(VIDEOPRT, "Didn't find device.\n");
753 return ERROR_DEV_NOT_EXIST;
754 }
755 }
756
757 Status = HalAssignSlotResources(&DeviceExtension->RegistryPath,
758 NULL,
759 DeviceExtension->DriverObject,
760 DeviceExtension->DriverObject->DeviceObject,
761 DeviceExtension->AdapterInterfaceType,
762 DeviceExtension->SystemIoBusNumber,
763 PciSlotNumber.u.AsULONG,
765 if (!NT_SUCCESS(Status))
766 {
767 WARN_(VIDEOPRT, "HalAssignSlotResources failed with status %x.\n",Status);
768 return Status;
769 }
770 DeviceExtension->AllocatedResources = AllocatedResources;
771 DeviceExtension->SystemIoSlotNumber = PciSlotNumber.u.AsULONG;
772
773 /* Add legacy resources to the resources from HAL */
775 &LegacyAccessRanges, &LegacyAccessRangeCount);
776 if (!NT_SUCCESS(Status))
777 return ERROR_DEV_NOT_EXIST;
778
779 if (NumAccessRanges < LegacyAccessRangeCount)
780 {
781 ERR_(VIDEOPRT, "Too many legacy access ranges found\n");
782 return ERROR_NOT_ENOUGH_MEMORY; // ERROR_MORE_DATA;
783 }
784
785 RtlCopyMemory(AccessRanges, LegacyAccessRanges, LegacyAccessRangeCount * sizeof(VIDEO_ACCESS_RANGE));
786 AssignedCount = LegacyAccessRangeCount;
787 }
788 }
789 else
790 {
791 ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + (NumRequestedResources - 1) * sizeof(IO_RESOURCE_DESCRIPTOR);
792 ResReqList = ExAllocatePool(NonPagedPool, ListSize);
793 if (!ResReqList)
795
796 ResReqList->ListSize = ListSize;
797 ResReqList->InterfaceType = DeviceExtension->AdapterInterfaceType;
798 ResReqList->BusNumber = DeviceExtension->SystemIoBusNumber;
799 ResReqList->SlotNumber = DeviceExtension->SystemIoSlotNumber;
800 ResReqList->AlternativeLists = 1;
801 ResReqList->List[0].Version = 1;
802 ResReqList->List[0].Revision = 1;
803 ResReqList->List[0].Count = NumRequestedResources;
804
805 /* Copy in the caller's resource list */
806 RtlCopyMemory(ResReqList->List[0].Descriptors,
807 RequestedResources,
808 NumRequestedResources * sizeof(IO_RESOURCE_DESCRIPTOR));
809
810 Status = IoAssignResources(&DeviceExtension->RegistryPath,
811 NULL,
812 DeviceExtension->DriverObject,
813 DeviceExtension->PhysicalDeviceObject ?
814 DeviceExtension->PhysicalDeviceObject :
815 DeviceExtension->DriverObject->DeviceObject,
816 ResReqList,
818
819 if (!NT_SUCCESS(Status))
820 return Status;
821
822 if (!DeviceExtension->AllocatedResources)
823 DeviceExtension->AllocatedResources = AllocatedResources;
824 }
825
828
829 /* Return the slot number if the caller wants it */
830 if (Slot != NULL) *Slot = DeviceExtension->SystemIoBusNumber;
831
832 FullList = AllocatedResources->List;
833 ASSERT(AllocatedResources->Count == 1);
834 INFO_(VIDEOPRT, "InterfaceType %u BusNumber List %u Device BusNumber %u Version %u Revision %u\n",
835 FullList->InterfaceType, FullList->BusNumber, DeviceExtension->SystemIoBusNumber,
837
838 ASSERT(FullList->InterfaceType == PCIBus);
839 ASSERT(FullList->BusNumber == DeviceExtension->SystemIoBusNumber);
840 ASSERT(1 == FullList->PartialResourceList.Version);
841 ASSERT(1 == FullList->PartialResourceList.Revision);
842
844 Descriptor < FullList->PartialResourceList.PartialDescriptors + FullList->PartialResourceList.Count;
845 Descriptor++)
846 {
847 if ((Descriptor->Type == CmResourceTypeMemory ||
848 Descriptor->Type == CmResourceTypePort) &&
849 AssignedCount >= NumAccessRanges)
850 {
851 ERR_(VIDEOPRT, "Too many access ranges found\n");
852 return ERROR_MORE_DATA;
853 }
854 else if (Descriptor->Type == CmResourceTypeMemory)
855 {
856 INFO_(VIDEOPRT, "Memory range starting at 0x%08x length 0x%08x\n",
857 Descriptor->u.Memory.Start.u.LowPart, Descriptor->u.Memory.Length);
858 AccessRanges[AssignedCount].RangeStart = Descriptor->u.Memory.Start;
859 AccessRanges[AssignedCount].RangeLength = Descriptor->u.Memory.Length;
860 AccessRanges[AssignedCount].RangeInIoSpace = 0;
861 AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
862 AccessRanges[AssignedCount].RangeShareable =
863 (Descriptor->ShareDisposition == CmResourceShareShared);
864 AccessRanges[AssignedCount].RangePassive = 0;
865 AssignedCount++;
866 }
867 else if (Descriptor->Type == CmResourceTypePort)
868 {
869 INFO_(VIDEOPRT, "Port range starting at 0x%04x length %d\n",
870 Descriptor->u.Port.Start.u.LowPart, Descriptor->u.Port.Length);
871 AccessRanges[AssignedCount].RangeStart = Descriptor->u.Port.Start;
872 AccessRanges[AssignedCount].RangeLength = Descriptor->u.Port.Length;
873 AccessRanges[AssignedCount].RangeInIoSpace = 1;
874 AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
875 AccessRanges[AssignedCount].RangeShareable =
876 (Descriptor->ShareDisposition == CmResourceShareShared);
877 AccessRanges[AssignedCount].RangePassive = 0;
879 AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_10_BIT_DECODE;
881 AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_PASSIVE_DECODE;
882 AssignedCount++;
883 }
884 else if (Descriptor->Type == CmResourceTypeInterrupt)
885 {
886 DeviceExtension->InterruptLevel = Descriptor->u.Interrupt.Level;
887 DeviceExtension->InterruptVector = Descriptor->u.Interrupt.Vector;
888 if (Descriptor->ShareDisposition == CmResourceShareShared)
889 DeviceExtension->InterruptShared = TRUE;
890 else
891 DeviceExtension->InterruptShared = FALSE;
892 }
893 // else if (Descriptor->Type == CmResourceTypeDma) // TODO!
894 else
895 {
896 ASSERT(FALSE);
898 }
899 }
900
901 return NO_ERROR;
902}
_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
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
NTHALAPI NTSTATUS NTAPI HalAssignSlotResources(PUNICODE_STRING, PUNICODE_STRING, PDRIVER_OBJECT, PDEVICE_OBJECT, INTERFACE_TYPE, ULONG, ULONG, PCM_RESOURCE_LIST *)
@ PCIBus
Definition: hwresource.cpp:142
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
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
unsigned int UINT
Definition: ndis.h:50
_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
#define ERR_(ch,...)
Definition: debug.h:156
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2277
union _PCI_SLOT_NUMBER::@4059 u
struct _PCI_SLOT_NUMBER::@4059::@4060 bits
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:3599
#define PCI_MAX_DEVICES
Definition: iotypes.h:3598

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

1202{
1203 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
1204
1205 TRACE_(VIDEOPRT, "VideoPortGetBusData\n");
1206
1207 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
1208
1209 if (BusDataType != Cmos)
1210 {
1211 /* Legacy vs. PnP behaviour */
1212 if (DeviceExtension->PhysicalDeviceObject != NULL)
1213 SlotNumber = DeviceExtension->SystemIoSlotNumber;
1214 }
1215
1216 return HalGetBusDataByOffset(
1217 BusDataType,
1218 DeviceExtension->SystemIoBusNumber,
1219 SlotNumber,
1220 Buffer,
1221 Offset,
1222 Length);
1223}
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 487 of file resource.c.

492{
493 TRACE_(VIDEOPRT, "VideoPortGetDeviceBase\n");
495 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
496 IoAddress,
497 NumberOfUchars,
498 InIoSpace,
499 NULL,
500 NULL);
501}
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:280

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

1033{
1034 TRACE_(VIDEOPRT, "VideoPortGetDeviceData\n");
1037}
#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 1099 of file resource.c.

1104{
1105 PMDL Mdl;
1106
1108 if (!Mdl)
1109 {
1110 return NULL;
1111 }
1112 /* FIXME use seh */
1114 return Mdl;
1115}
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 1123 of file resource.c.

1129{
1130 PVOID Buffer;
1131
1132 /* clear output buffer */
1133 pVrp->OutputBuffer = NULL;
1134
1135 if (DmaFlags != VideoPortDmaInitOnly)
1136 {
1137 /* VideoPortKeepPagesLocked / VideoPortUnlockAfterDma is no-op */
1138 return FALSE;
1139 }
1140
1141 /* lock the buffer */
1142 Buffer = VideoPortLockBuffer(HwDeviceExtension, pVrp->InputBuffer, pVrp->InputBufferLength, IoModifyAccess);
1143
1144 if (Buffer)
1145 {
1146 /* store result buffer & length */
1147 pVrp->OutputBuffer = Buffer;
1148 pVrp->OutputBufferLength = pVrp->InputBufferLength;
1149
1150 /* operation succeeded */
1151 return TRUE;
1152 }
1153
1154 /* operation failed */
1155 return FALSE;
1156}
@ 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:1099
@ IoModifyAccess
Definition: ketypes.h:865

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

533{
534 TRACE_(VIDEOPRT, "VideoPortMapBankedMemory\n");
537}

◆ VideoPortMapMemory()

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

Definition at line 545 of file resource.c.

551{
552 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
554
555 TRACE_(VIDEOPRT, "VideoPortMapMemory\n");
556 INFO_(VIDEOPRT, "- *VirtualAddress: 0x%x\n", *VirtualAddress);
557
558 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
560 DeviceExtension,
562 *Length,
563 *InIoSpace,
565 &Status);
566
567 return Status;
568}

◆ VideoPortReleaseBuffer()

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

Definition at line 1086 of file resource.c.

1089{
1090 TRACE_(VIDEOPRT, "VideoPortReleaseBuffer\n");
1091 ExFreePool(Ptr);
1092}

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

1237{
1238 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
1239
1240 TRACE_(VIDEOPRT, "VideoPortSetBusData\n");
1241
1242 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
1243
1244 if (BusDataType != Cmos)
1245 {
1246 /* Legacy vs. PnP behaviour */
1247 if (DeviceExtension->PhysicalDeviceObject != NULL)
1248 SlotNumber = DeviceExtension->SystemIoSlotNumber;
1249 }
1250
1251 return HalSetBusDataByOffset(
1252 BusDataType,
1253 DeviceExtension->SystemIoBusNumber,
1254 SlotNumber,
1255 Buffer,
1256 Offset,
1257 Length);
1258}
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 1180 of file resource.c.

1184{
1186 /* Should store the ranges in the device extension for use by ntvdm. */
1187 return NO_ERROR;
1188}

◆ VideoPortUnlockBuffer()

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

Definition at line 1164 of file resource.c.

1167{
1168 if (Mdl)
1169 {
1171 IoFreeMdl(Mdl);
1172 }
1173}
#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 575 of file resource.c.

579{
580 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
581
583 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
585
586 return NO_ERROR;
587}

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

930{
931 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
932 BOOLEAN ConflictDetected;
933 ULONG ResourceListSize;
935 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
936 ULONG i;
938
939 TRACE_(VIDEOPRT, "VideoPortVerifyAccessRanges\n");
940
941 /* Verify parameters */
942 if (NumAccessRanges && !AccessRanges)
944
945 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
946
947 if (NumAccessRanges == 0)
948 {
949 /* Release the resources and do nothing more for now... */
950 IntVideoPortReleaseResources(DeviceExtension);
951 return NO_ERROR;
952 }
953
954 /* Create the resource list */
955 ResourceListSize = sizeof(CM_RESOURCE_LIST)
956 + (NumAccessRanges - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
958 if (!ResourceList)
959 {
960 WARN_(VIDEOPRT, "ExAllocatePool() failed\n");
962 }
963
964 /* Fill resource list */
965 ResourceList->Count = 1;
966 ResourceList->List[0].InterfaceType = DeviceExtension->AdapterInterfaceType;
967 ResourceList->List[0].BusNumber = DeviceExtension->SystemIoBusNumber;
968 ResourceList->List[0].PartialResourceList.Version = 1;
969 ResourceList->List[0].PartialResourceList.Revision = 1;
970 ResourceList->List[0].PartialResourceList.Count = NumAccessRanges;
971 for (i = 0; i < NumAccessRanges; i++, AccessRanges++)
972 {
973 PartialDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
974 if (AccessRanges->RangeInIoSpace)
975 {
976 PartialDescriptor->Type = CmResourceTypePort;
977 PartialDescriptor->u.Port.Start = AccessRanges->RangeStart;
978 PartialDescriptor->u.Port.Length = AccessRanges->RangeLength;
979 }
980 else
981 {
982 PartialDescriptor->Type = CmResourceTypeMemory;
983 PartialDescriptor->u.Memory.Start = AccessRanges->RangeStart;
984 PartialDescriptor->u.Memory.Length = AccessRanges->RangeLength;
985 }
986 if (AccessRanges->RangeShareable)
987 PartialDescriptor->ShareDisposition = CmResourceShareShared;
988 else
990 PartialDescriptor->Flags = 0;
991 if (AccessRanges->RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
992 PartialDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
993 if (AccessRanges->RangePassive & VIDEO_RANGE_10_BIT_DECODE)
994 PartialDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
995 }
996
997 /* Try to acquire all resource ranges */
999 DeviceExtension->DriverObject,
1000 NULL, 0, /* Driver List */
1001 DeviceExtension->PhysicalDeviceObject,
1002 ResourceList, ResourceListSize,
1003 &ConflictDetected);
1004
1006
1007 /* If VgaSave driver is conflicting and we don't explicitely want
1008 * to use it, ignore the problem (because win32k will try to use
1009 * this driver only if all other ones are failing). */
1011 IntIsVgaSaveDriver(DeviceExtension) &&
1012 !VpBaseVideo)
1013 {
1014 return NO_ERROR;
1015 }
1016
1017 if (!NT_SUCCESS(Status) || ConflictDetected)
1019 else
1020 return NO_ERROR;
1021}
struct _CM_RESOURCE_LIST CM_RESOURCE_LIST
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@392 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@392::@394 Port
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@392::@397 Memory
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
static BOOLEAN IntIsVgaSaveDriver(IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
Definition: resource.c:32
BOOLEAN VpBaseVideo
Definition: videoprt.c:36
VOID IntVideoPortReleaseResources(_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
Definition: resource.c:204

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

Variable Documentation

◆ VpBaseVideo

BOOLEAN VpBaseVideo
extern

Definition at line 36 of file videoprt.c.

Referenced by IntLoadRegistryParameters(), and VideoPortVerifyAccessRanges().