ReactOS 0.4.16-dev-1946-g52006dd
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
#define L(x)
Definition: resources.c:13
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by VideoPortVerifyAccessRanges().

◆ IntVideoPortFilterResourceRequirements()

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

Definition at line 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 ASSERT(a)
Definition: mode.c:44
#define CM_RESOURCE_MEMORY_READ_WRITE
Definition: cmtypes.h:120
#define CM_RESOURCE_PORT_PASSIVE_DECODE
Definition: cmtypes.h:114
#define CM_RESOURCE_PORT_10_BIT_DECODE
Definition: cmtypes.h:110
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1916
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31
#define CmResourceTypeMemory
Definition: restypes.h:106
#define CmResourceTypePort
Definition: restypes.h:104
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::@2227 u
struct _IO_RESOURCE_DESCRIPTOR::@2227::@2229 Memory
struct _IO_RESOURCE_DESCRIPTOR::@2227::@2228 Port
IO_RESOURCE_DESCRIPTOR Descriptors[1]
Definition: iotypes.h:2739
INTERFACE_TYPE InterfaceType
Definition: iotypes.h:2744
IO_RESOURCE_LIST List[1]
Definition: iotypes.h:2749
ULONG RangeLength
Definition: video.h:216
UCHAR RangeShareable
Definition: video.h:219
PHYSICAL_ADDRESS RangeStart
Definition: video.h:215
INTERFACE_TYPE AdapterInterfaceType
Definition: videoprt.h:98
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
struct _VIDEO_PORT_DEVICE_EXTENSTION * PVIDEO_PORT_DEVICE_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
NTSTATUS NTAPI IntVideoPortGetLegacyResources(IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension, IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, OUT PVIDEO_ACCESS_RANGE *AccessRanges, OUT PULONG AccessRangeCount)
Definition: resource.c: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 281 of file resource.c.

288{
290 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
292 PVOID MappedAddress;
294
295 INFO_(VIDEOPRT, "- IoAddress: %lx\n", IoAddress.u.LowPart);
296 INFO_(VIDEOPRT, "- NumberOfUchars: %lx\n", NumberOfUchars);
297 INFO_(VIDEOPRT, "- InIoSpace: %x\n", InIoSpace);
298
299 InIoSpace &= ~VIDEO_MEMORY_SPACE_DENSE;
300
301 if (ProcessHandle != NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
302 {
303 INFO_(VIDEOPRT, "ProcessHandle is not NULL (0x%x) but InIoSpace does not have "
304 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting "
305 "VIDEO_MEMORY_SPACE_USER_MODE.\n",
307 InIoSpace |= VIDEO_MEMORY_SPACE_USER_MODE;
308 }
309 else if (ProcessHandle == NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
310 {
311 INFO_(VIDEOPRT, "ProcessHandle is NULL (0x%x) but InIoSpace does have "
312 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting ProcessHandle "
313 "to NtCurrentProcess()\n",
316 }
317
318 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0 &&
319 !IsListEmpty(&DeviceExtension->AddressMappingListHead))
320 {
321 Entry = DeviceExtension->AddressMappingListHead.Flink;
322 while (Entry != &DeviceExtension->AddressMappingListHead)
323 {
324 AddressMapping = CONTAINING_RECORD(
325 Entry,
327 List);
328 if (IoAddress.QuadPart == AddressMapping->IoAddress.QuadPart &&
329 NumberOfUchars <= AddressMapping->NumberOfUchars)
330 {
331 {
332 AddressMapping->MappingCount++;
333 if (Status)
334 *Status = NO_ERROR;
335 return AddressMapping->MappedAddress;
336 }
337 }
338 Entry = Entry->Flink;
339 }
340 }
341
342 AddressSpace = (ULONG)InIoSpace;
345 DeviceExtension->AdapterInterfaceType,
346 DeviceExtension->SystemIoBusNumber,
347 IoAddress,
350 {
351 if (Status)
353
354 return NULL;
355 }
356
357 /* I/O space */
358 if (AddressSpace != 0)
359 {
360 ASSERT(0 == TranslatedAddress.u.HighPart);
361 if (Status)
362 *Status = NO_ERROR;
363
364 return (PVOID)(ULONG_PTR)TranslatedAddress.u.LowPart;
365 }
366
367 /* user space */
368 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
369 {
370 NTSTATUS NtStatus;
372 if (InIoSpace & VIDEO_MEMORY_SPACE_P6CACHE)
374 else
376 MappedAddress = NULL;
379 NumberOfUchars,
380 Protect,
381 &MappedAddress);
382 if (!NT_SUCCESS(NtStatus))
383 {
384 ERR_(VIDEOPRT, "IntVideoPortMapPhysicalMemory() failed! (0x%x)\n", NtStatus);
385 if (Status)
387 return NULL;
388 }
389 INFO_(VIDEOPRT, "Mapped user address = 0x%08x\n", MappedAddress);
390 }
391 else /* kernel space */
392 {
393 MappedAddress = MmMapIoSpace(
395 NumberOfUchars,
397 }
398
399 if (MappedAddress != NULL)
400 {
401 if (Status)
402 {
403 *Status = NO_ERROR;
404 }
405 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
406 {
407 AddressMapping = ExAllocatePoolWithTag(
408 PagedPool,
411
412 if (AddressMapping == NULL)
413 return MappedAddress;
414
415 RtlZeroMemory(AddressMapping, sizeof(VIDEO_PORT_ADDRESS_MAPPING));
416 AddressMapping->NumberOfUchars = NumberOfUchars;
417 AddressMapping->IoAddress = IoAddress;
418 AddressMapping->SystemIoBusNumber = DeviceExtension->SystemIoBusNumber;
419 AddressMapping->MappedAddress = MappedAddress;
420 AddressMapping->MappingCount = 1;
422 &DeviceExtension->AddressMappingListHead,
423 &AddressMapping->List);
424 }
425
426 return MappedAddress;
427 }
428
429 ERR_(VIDEOPRT,
430 "Couldn't map video memory. IoAddress: 0x%lx, NumberOfUchars: 0x%lx, InIoSpace: 0x%x\n",
431 IoAddress.u.LowPart, NumberOfUchars, InIoSpace);
432 if (Status)
434
435 return NULL;
436}
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define InsertHeadList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define PagedPool
Definition: env_spec_w32.h:308
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
#define PAGE_NOCACHE
Definition: nt_native.h:1314
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define NtCurrentProcess()
Definition: nt_native.h:1660
#define VIDEO_MEMORY_SPACE_USER_MODE
Definition: video.h:134
#define VIDEO_MEMORY_SPACE_P6CACHE
Definition: video.h:136
#define ERR_(ch,...)
Definition: debug.h:156
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
PHYSICAL_ADDRESS IoAddress
Definition: videoprt.h:49
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
struct _LARGE_INTEGER::@2479 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:230
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2275
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274
@ MmNonCached
Definition: mmtypes.h:129
#define PAGE_WRITECOMBINE
Definition: mmtypes.h:78
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG _In_ ULONG Protect
Definition: zwfuncs.h:221

Referenced by VideoPortGetDeviceBase(), and VideoPortMapMemory().

◆ IntVideoPortMapPhysicalMemory()

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

Definition at line 230 of file resource.c.

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

Referenced by IntAgpCommitVirtual(), and IntVideoPortMapMemory().

◆ IntVideoPortReleaseResources()

VOID IntVideoPortReleaseResources ( _In_ PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 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 ERR_(VIDEOPRT,
223 "VideoPortReleaseResources IoReportResource failed with 0x%08lx ; ConflictDetected: %s\n",
224 Status, ConflictDetected ? "TRUE" : "FALSE");
225 }
226 /* Ignore the returned status however... */
227}
unsigned char BOOLEAN
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 439 of file resource.c.

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

1079{
1080 TRACE_(VIDEOPRT, "VideoPortAllocateBuffer\n");
1083}
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 1048 of file resource.c.

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

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

◆ VideoPortFreeDeviceBase()

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

Definition at line 512 of file resource.c.

515{
516 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
518 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
519 MappedAddress);
520}
#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:439

Referenced by InitializeModeTable().

◆ VideoPortFreePool()

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

Definition at line 1063 of file resource.c.

1066{
1067 ExFreePool(Ptr);
1068}
_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 640 of file resource.c.

650{
651 PCI_SLOT_NUMBER PciSlotNumber;
653 ULONG FunctionNumber;
657 UINT AssignedCount = 0;
660 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
662 USHORT VendorIdToFind;
663 USHORT DeviceIdToFind;
665 PVIDEO_ACCESS_RANGE LegacyAccessRanges;
666 ULONG LegacyAccessRangeCount;
668 ULONG ListSize;
670 BOOLEAN DeviceAndVendorFound = FALSE;
671
672 TRACE_(VIDEOPRT, "VideoPortGetAccessRanges(%d, %p, %d, %p)\n",
673 NumRequestedResources, RequestedResources, NumAccessRanges, AccessRanges);
674
675 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
676 DriverObject = DeviceExtension->DriverObject;
678
679 if (NumRequestedResources == 0)
680 {
681 AllocatedResources = DeviceExtension->AllocatedResources;
682 if (AllocatedResources == NULL &&
683 DeviceExtension->AdapterInterfaceType == PCIBus)
684 {
685 if (DeviceExtension->PhysicalDeviceObject != NULL)
686 {
687 PciSlotNumber.u.AsULONG = DeviceExtension->SystemIoSlotNumber;
688
690 DeviceExtension->SystemIoBusNumber,
691 PciSlotNumber.u.AsULONG,
692 &Config,
693 sizeof(Config));
694
695 if (ReturnedLength != sizeof(Config))
696 {
698 }
699 }
700 else
701 {
702 VendorIdToFind = VendorId != NULL ? *(PUSHORT)VendorId : 0;
703 DeviceIdToFind = DeviceId != NULL ? *(PUSHORT)DeviceId : 0;
704
705 if (VendorIdToFind == 0 && DeviceIdToFind == 0)
706 {
707 /* We're screwed */
708 return ERROR_DEV_NOT_EXIST;
709 }
710
711 INFO_(VIDEOPRT, "Looking for VendorId 0x%04x DeviceId 0x%04x\n",
712 VendorIdToFind, DeviceIdToFind);
713
714 /*
715 * Search for the device id and vendor id on this bus.
716 */
717 PciSlotNumber.u.bits.Reserved = 0;
719 {
720 PciSlotNumber.u.bits.DeviceNumber = DeviceNumber;
721 for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
722 {
723 INFO_(VIDEOPRT, "- Function number: %d\n", FunctionNumber);
724 PciSlotNumber.u.bits.FunctionNumber = FunctionNumber;
726 DeviceExtension->SystemIoBusNumber,
727 PciSlotNumber.u.AsULONG,
728 &Config,
729 sizeof(Config));
730
731 INFO_(VIDEOPRT, "- Length of data: %x\n", ReturnedLength);
732
733 if (ReturnedLength == sizeof(Config))
734 {
735 INFO_(VIDEOPRT, "- Slot 0x%02x (Device %d Function %d) VendorId 0x%04x "
736 "DeviceId 0x%04x\n",
737 PciSlotNumber.u.AsULONG,
738 PciSlotNumber.u.bits.DeviceNumber,
739 PciSlotNumber.u.bits.FunctionNumber,
740 Config.VendorID,
741 Config.DeviceID);
742
743 if ((VendorIdToFind == 0 || Config.VendorID == VendorIdToFind) &&
744 (DeviceIdToFind == 0 || Config.DeviceID == DeviceIdToFind))
745 {
746 DeviceAndVendorFound = TRUE;
747 break;
748 }
749 }
750 }
751 if (DeviceAndVendorFound)
752 break;
753 }
754 if (FunctionNumber == PCI_MAX_FUNCTION)
755 {
756 WARN_(VIDEOPRT, "Didn't find device.\n");
757 return ERROR_DEV_NOT_EXIST;
758 }
759 }
760
761 Status = HalAssignSlotResources(&DeviceExtension->RegistryPath,
762 NULL,
763 DeviceExtension->DriverObject,
764 DeviceExtension->DriverObject->DeviceObject,
765 DeviceExtension->AdapterInterfaceType,
766 DeviceExtension->SystemIoBusNumber,
767 PciSlotNumber.u.AsULONG,
769 if (!NT_SUCCESS(Status))
770 {
771 WARN_(VIDEOPRT, "HalAssignSlotResources failed with status %x.\n",Status);
772 return Status;
773 }
774 DeviceExtension->AllocatedResources = AllocatedResources;
775 DeviceExtension->SystemIoSlotNumber = PciSlotNumber.u.AsULONG;
776
777 /* Add legacy resources to the resources from HAL */
779 &LegacyAccessRanges, &LegacyAccessRangeCount);
780 if (!NT_SUCCESS(Status))
781 return ERROR_DEV_NOT_EXIST;
782
783 if (NumAccessRanges < LegacyAccessRangeCount)
784 {
785 ERR_(VIDEOPRT, "Too many legacy access ranges found\n");
786 return ERROR_NOT_ENOUGH_MEMORY; // ERROR_MORE_DATA;
787 }
788
789 RtlCopyMemory(AccessRanges, LegacyAccessRanges, LegacyAccessRangeCount * sizeof(VIDEO_ACCESS_RANGE));
790 AssignedCount = LegacyAccessRangeCount;
791 }
792 }
793 else
794 {
795 ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + (NumRequestedResources - 1) * sizeof(IO_RESOURCE_DESCRIPTOR);
796 ResReqList = ExAllocatePool(NonPagedPool, ListSize);
797 if (!ResReqList)
799
800 ResReqList->ListSize = ListSize;
801 ResReqList->InterfaceType = DeviceExtension->AdapterInterfaceType;
802 ResReqList->BusNumber = DeviceExtension->SystemIoBusNumber;
803 ResReqList->SlotNumber = DeviceExtension->SystemIoSlotNumber;
804 ResReqList->AlternativeLists = 1;
805 ResReqList->List[0].Version = 1;
806 ResReqList->List[0].Revision = 1;
807 ResReqList->List[0].Count = NumRequestedResources;
808
809 /* Copy in the caller's resource list */
810 RtlCopyMemory(ResReqList->List[0].Descriptors,
811 RequestedResources,
812 NumRequestedResources * sizeof(IO_RESOURCE_DESCRIPTOR));
813
814 Status = IoAssignResources(&DeviceExtension->RegistryPath,
815 NULL,
816 DeviceExtension->DriverObject,
817 DeviceExtension->PhysicalDeviceObject ?
818 DeviceExtension->PhysicalDeviceObject :
819 DeviceExtension->DriverObject->DeviceObject,
820 ResReqList,
822
823 if (!NT_SUCCESS(Status))
824 return Status;
825
826 if (!DeviceExtension->AllocatedResources)
827 DeviceExtension->AllocatedResources = AllocatedResources;
828 }
829
832
833 /* Return the slot number if the caller wants it */
834 if (Slot != NULL) *Slot = DeviceExtension->SystemIoBusNumber;
835
836 FullList = AllocatedResources->List;
837 ASSERT(AllocatedResources->Count == 1);
838 INFO_(VIDEOPRT, "InterfaceType %u BusNumber List %u Device BusNumber %u Version %u Revision %u\n",
839 FullList->InterfaceType, FullList->BusNumber, DeviceExtension->SystemIoBusNumber,
841
842 ASSERT(FullList->InterfaceType == PCIBus);
843 ASSERT(FullList->BusNumber == DeviceExtension->SystemIoBusNumber);
844 ASSERT(1 == FullList->PartialResourceList.Version);
845 ASSERT(1 == FullList->PartialResourceList.Revision);
846
848 Descriptor < FullList->PartialResourceList.PartialDescriptors + FullList->PartialResourceList.Count;
849 Descriptor++)
850 {
851 if ((Descriptor->Type == CmResourceTypeMemory ||
852 Descriptor->Type == CmResourceTypePort) &&
853 AssignedCount >= NumAccessRanges)
854 {
855 ERR_(VIDEOPRT, "Too many access ranges found\n");
856 return ERROR_MORE_DATA;
857 }
858 else if (Descriptor->Type == CmResourceTypeMemory)
859 {
860 INFO_(VIDEOPRT, "Memory range starting at 0x%08x length 0x%08x\n",
861 Descriptor->u.Memory.Start.u.LowPart, Descriptor->u.Memory.Length);
862 AccessRanges[AssignedCount].RangeStart = Descriptor->u.Memory.Start;
863 AccessRanges[AssignedCount].RangeLength = Descriptor->u.Memory.Length;
864 AccessRanges[AssignedCount].RangeInIoSpace = 0;
865 AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
866 AccessRanges[AssignedCount].RangeShareable =
867 (Descriptor->ShareDisposition == CmResourceShareShared);
868 AccessRanges[AssignedCount].RangePassive = 0;
869 AssignedCount++;
870 }
871 else if (Descriptor->Type == CmResourceTypePort)
872 {
873 INFO_(VIDEOPRT, "Port range starting at 0x%04x length %d\n",
874 Descriptor->u.Port.Start.u.LowPart, Descriptor->u.Port.Length);
875 AccessRanges[AssignedCount].RangeStart = Descriptor->u.Port.Start;
876 AccessRanges[AssignedCount].RangeLength = Descriptor->u.Port.Length;
877 AccessRanges[AssignedCount].RangeInIoSpace = 1;
878 AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
879 AccessRanges[AssignedCount].RangeShareable =
880 (Descriptor->ShareDisposition == CmResourceShareShared);
881 AccessRanges[AssignedCount].RangePassive = 0;
883 AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_10_BIT_DECODE;
885 AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_PASSIVE_DECODE;
886 AssignedCount++;
887 }
888 else if (Descriptor->Type == CmResourceTypeInterrupt)
889 {
890 DeviceExtension->InterruptLevel = Descriptor->u.Interrupt.Level;
891 DeviceExtension->InterruptVector = Descriptor->u.Interrupt.Vector;
892 if (Descriptor->ShareDisposition == CmResourceShareShared)
893 DeviceExtension->InterruptShared = TRUE;
894 else
895 DeviceExtension->InterruptShared = FALSE;
896 }
897 // else if (Descriptor->Type == CmResourceTypeDma) // TODO!
898 else
899 {
900 ASSERT(FALSE);
902 }
903 }
904
905 return NO_ERROR;
906}
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
#define ERROR_DEV_NOT_EXIST
Definition: dderror.h:8
#define ERROR_MORE_DATA
Definition: dderror.h:13
NTHALAPI NTSTATUS NTAPI HalAssignSlotResources(PUNICODE_STRING, PUNICODE_STRING, PDRIVER_OBJECT, PDEVICE_OBJECT, INTERFACE_TYPE, ULONG, ULONG, PCM_RESOURCE_LIST *)
NTSTATUS NTAPI IoAssignResources(_In_ PUNICODE_STRING RegistryPath, _In_opt_ PUNICODE_STRING DriverClassName, _In_ PDRIVER_OBJECT DriverObject, _In_opt_ PDEVICE_OBJECT DeviceObject, _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources, _Inout_ PCM_RESOURCE_LIST *AllocatedResources)
Definition: iorsrce.c:1134
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4643
unsigned int UINT
Definition: ndis.h:50
unsigned short USHORT
Definition: pedump.c:61
@ PCIBus
Definition: restypes.h:126
#define CmResourceTypeInterrupt
Definition: restypes.h:105
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: restypes.h:144
INTERFACE_TYPE InterfaceType
Definition: restypes.h:142
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2279
struct _PCI_SLOT_NUMBER::@4322::@4323 bits
union _PCI_SLOT_NUMBER::@4322 u
PDEVICE_OBJECT PhysicalDeviceObject
Definition: videoprt.h:87
PCM_RESOURCE_LIST AllocatedResources
Definition: videoprt.h:94
UNICODE_STRING RegistryPath
Definition: videoprt.h:90
PDRIVER_OBJECT DriverObject
Definition: videoprt.h:86
uint16_t * PUSHORT
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:476
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
#define PCI_MAX_FUNCTION
Definition: iotypes.h:3601
#define PCI_MAX_DEVICES
Definition: iotypes.h:3600

Referenced by BochsFindAdapter(), and XboxVmpFindAdapter().

◆ VideoPortGetBusData()

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

Definition at line 1199 of file resource.c.

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

496{
497 TRACE_(VIDEOPRT, "VideoPortGetDeviceBase\n");
499 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
500 IoAddress,
501 NumberOfUchars,
502 InIoSpace,
503 NULL,
504 NULL);
505}
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:281

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

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

1108{
1109 PMDL Mdl;
1110
1112 if (!Mdl)
1113 {
1114 return NULL;
1115 }
1116 /* FIXME use seh */
1118 return Mdl;
1119}
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 1127 of file resource.c.

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

◆ VideoPortMapBankedMemory()

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

Definition at line 527 of file resource.c.

537{
538 TRACE_(VIDEOPRT, "VideoPortMapBankedMemory\n");
541}

◆ VideoPortMapMemory()

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

Definition at line 549 of file resource.c.

555{
556 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
558
559 TRACE_(VIDEOPRT, "VideoPortMapMemory\n");
560 INFO_(VIDEOPRT, "- *VirtualAddress: 0x%x\n", *VirtualAddress);
561
562 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
564 DeviceExtension,
566 *Length,
567 *InIoSpace,
569 &Status);
570
571 return Status;
572}

◆ VideoPortReleaseBuffer()

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

Definition at line 1090 of file resource.c.

1093{
1094 TRACE_(VIDEOPRT, "VideoPortReleaseBuffer\n");
1095 ExFreePool(Ptr);
1096}

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

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

1188{
1190 /* Should store the ranges in the device extension for use by ntvdm. */
1191 return NO_ERROR;
1192}

◆ VideoPortUnlockBuffer()

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

Definition at line 1168 of file resource.c.

1171{
1172 if (Mdl)
1173 {
1175 IoFreeMdl(Mdl);
1176 }
1177}
#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 579 of file resource.c.

583{
584 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
585
587 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
589
590 return NO_ERROR;
591}

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

934{
935 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
936 BOOLEAN ConflictDetected;
937 ULONG ResourceListSize;
939 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
940 ULONG i;
942
943 TRACE_(VIDEOPRT, "VideoPortVerifyAccessRanges\n");
944
945 /* Verify parameters */
946 if (NumAccessRanges && !AccessRanges)
948
949 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
950
951 if (NumAccessRanges == 0)
952 {
953 /* Release the resources and do nothing more for now... */
954 IntVideoPortReleaseResources(DeviceExtension);
955 return NO_ERROR;
956 }
957
958 /* Create the resource list */
959 ResourceListSize = sizeof(CM_RESOURCE_LIST)
960 + (NumAccessRanges - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
962 if (!ResourceList)
963 {
964 WARN_(VIDEOPRT, "ExAllocatePool() failed\n");
966 }
967
968 /* Fill resource list */
969 ResourceList->Count = 1;
970 ResourceList->List[0].InterfaceType = DeviceExtension->AdapterInterfaceType;
971 ResourceList->List[0].BusNumber = DeviceExtension->SystemIoBusNumber;
972 ResourceList->List[0].PartialResourceList.Version = 1;
973 ResourceList->List[0].PartialResourceList.Revision = 1;
974 ResourceList->List[0].PartialResourceList.Count = NumAccessRanges;
975 for (i = 0; i < NumAccessRanges; i++, AccessRanges++)
976 {
977 PartialDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
978 if (AccessRanges->RangeInIoSpace)
979 {
980 PartialDescriptor->Type = CmResourceTypePort;
981 PartialDescriptor->u.Port.Start = AccessRanges->RangeStart;
982 PartialDescriptor->u.Port.Length = AccessRanges->RangeLength;
983 }
984 else
985 {
986 PartialDescriptor->Type = CmResourceTypeMemory;
987 PartialDescriptor->u.Memory.Start = AccessRanges->RangeStart;
988 PartialDescriptor->u.Memory.Length = AccessRanges->RangeLength;
989 }
990 if (AccessRanges->RangeShareable)
991 PartialDescriptor->ShareDisposition = CmResourceShareShared;
992 else
994 PartialDescriptor->Flags = 0;
995 if (AccessRanges->RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
996 PartialDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
997 if (AccessRanges->RangePassive & VIDEO_RANGE_10_BIT_DECODE)
998 PartialDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
999 }
1000
1001 /* Try to acquire all resource ranges */
1003 DeviceExtension->DriverObject,
1004 NULL, 0, /* Driver List */
1005 DeviceExtension->PhysicalDeviceObject,
1006 ResourceList, ResourceListSize,
1007 &ConflictDetected);
1008
1010
1011 /* If VgaSave driver is conflicting and we don't explicitely want
1012 * to use it, ignore the problem (because win32k will try to use
1013 * this driver only if all other ones are failing). */
1015 IntIsVgaSaveDriver(DeviceExtension) &&
1016 !VpBaseVideo)
1017 {
1018 return NO_ERROR;
1019 }
1020
1021 if (!NT_SUCCESS(Status) || ConflictDetected)
1023 else
1024 return NO_ERROR;
1025}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#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 _CM_PARTIAL_RESOURCE_DESCRIPTOR::@430::@435 Memory
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@430::@432 Port
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@430 u
_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().