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

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI IntVideoPortGetLegacyResources (IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension, IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension, OUT PVIDEO_ACCESS_RANGE *AccessRanges, OUT PULONG AccessRangeCount)
 
NTSTATUS NTAPI IntVideoPortFilterResourceRequirements (IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IrpStack, IN PIRP Irp)
 
VOID IntVideoPortReleaseResources (_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI IntVideoPortMapPhysicalMemory (IN HANDLE Process, IN PHYSICAL_ADDRESS PhysicalAddress, IN ULONG SizeInBytes, IN ULONG Protect, IN OUT PVOID *VirtualAddress OPTIONAL)
 
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)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 24 of file resource.c.

Function Documentation

◆ IntVideoPortFilterResourceRequirements()

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

Definition at line 77 of file resource.c.

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

35{
36 PCI_COMMON_CONFIG PciConfig;
38
39 if (!DriverExtension->InitializationData.HwGetLegacyResources &&
40 !DriverExtension->InitializationData.HwLegacyResourceCount)
41 {
42 /* No legacy resources to report */
43 *AccessRangeCount = 0;
44 return STATUS_SUCCESS;
45 }
46
47 if (DriverExtension->InitializationData.HwGetLegacyResources)
48 {
50 DeviceExtension->SystemIoBusNumber,
51 DeviceExtension->SystemIoSlotNumber,
52 &PciConfig,
53 sizeof(PciConfig));
54 if (ReadLength != sizeof(PciConfig))
55 {
56 /* This device doesn't exist */
58 }
59
60 DriverExtension->InitializationData.HwGetLegacyResources(PciConfig.VendorID,
61 PciConfig.DeviceID,
62 AccessRanges,
63 AccessRangeCount);
64 }
65 else
66 {
67 *AccessRanges = DriverExtension->InitializationData.HwLegacyResourceList;
68 *AccessRangeCount = DriverExtension->InitializationData.HwLegacyResourceCount;
69 }
70
71 INFO_(VIDEOPRT, "Got %d legacy access ranges\n", *AccessRangeCount);
72
73 return STATUS_SUCCESS;
74}
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 270 of file resource.c.

277{
279 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
281 PVOID MappedAddress;
283
284 INFO_(VIDEOPRT, "- IoAddress: %lx\n", IoAddress.u.LowPart);
285 INFO_(VIDEOPRT, "- NumberOfUchars: %lx\n", NumberOfUchars);
286 INFO_(VIDEOPRT, "- InIoSpace: %x\n", InIoSpace);
287
288 InIoSpace &= ~VIDEO_MEMORY_SPACE_DENSE;
289 if ((InIoSpace & VIDEO_MEMORY_SPACE_P6CACHE) != 0)
290 {
291 INFO_(VIDEOPRT, "VIDEO_MEMORY_SPACE_P6CACHE not supported, turning off\n");
292 InIoSpace &= ~VIDEO_MEMORY_SPACE_P6CACHE;
293 }
294
295 if (ProcessHandle != NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
296 {
297 INFO_(VIDEOPRT, "ProcessHandle is not NULL (0x%x) but InIoSpace does not have "
298 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting "
299 "VIDEO_MEMORY_SPACE_USER_MODE.\n",
301 InIoSpace |= VIDEO_MEMORY_SPACE_USER_MODE;
302 }
303 else if (ProcessHandle == NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
304 {
305 INFO_(VIDEOPRT, "ProcessHandle is NULL (0x%x) but InIoSpace does have "
306 "VIDEO_MEMORY_SPACE_USER_MODE set! Setting ProcessHandle "
307 "to NtCurrentProcess()\n",
310 }
311
312 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0 &&
313 !IsListEmpty(&DeviceExtension->AddressMappingListHead))
314 {
315 Entry = DeviceExtension->AddressMappingListHead.Flink;
316 while (Entry != &DeviceExtension->AddressMappingListHead)
317 {
318 AddressMapping = CONTAINING_RECORD(
319 Entry,
321 List);
322 if (IoAddress.QuadPart == AddressMapping->IoAddress.QuadPart &&
323 NumberOfUchars <= AddressMapping->NumberOfUchars)
324 {
325 {
326 AddressMapping->MappingCount++;
327 if (Status)
328 *Status = NO_ERROR;
329 return AddressMapping->MappedAddress;
330 }
331 }
332 Entry = Entry->Flink;
333 }
334 }
335
336 AddressSpace = (ULONG)InIoSpace;
337 AddressSpace &= ~VIDEO_MEMORY_SPACE_USER_MODE;
339 DeviceExtension->AdapterInterfaceType,
340 DeviceExtension->SystemIoBusNumber,
341 IoAddress,
344 {
345 if (Status)
347
348 return NULL;
349 }
350
351 /* I/O space */
352 if (AddressSpace != 0)
353 {
354 ASSERT(0 == TranslatedAddress.u.HighPart);
355 if (Status)
356 *Status = NO_ERROR;
357
358 return (PVOID)(ULONG_PTR)TranslatedAddress.u.LowPart;
359 }
360
361 /* user space */
362 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
363 {
364 NTSTATUS NtStatus;
365 MappedAddress = NULL;
368 NumberOfUchars,
369 PAGE_READWRITE/* | PAGE_WRITECOMBINE*/,
370 &MappedAddress);
371 if (!NT_SUCCESS(NtStatus))
372 {
373 WARN_(VIDEOPRT, "IntVideoPortMapPhysicalMemory() failed! (0x%x)\n", NtStatus);
374 if (Status)
375 *Status = NO_ERROR;
376 return NULL;
377 }
378 INFO_(VIDEOPRT, "Mapped user address = 0x%08x\n", MappedAddress);
379 }
380 else /* kernel space */
381 {
382 MappedAddress = MmMapIoSpace(
384 NumberOfUchars,
386 }
387
388 if (MappedAddress != NULL)
389 {
390 if (Status)
391 {
392 *Status = NO_ERROR;
393 }
394 if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
395 {
396 AddressMapping = ExAllocatePoolWithTag(
397 PagedPool,
400
401 if (AddressMapping == NULL)
402 return MappedAddress;
403
404 RtlZeroMemory(AddressMapping, sizeof(VIDEO_PORT_ADDRESS_MAPPING));
405 AddressMapping->NumberOfUchars = NumberOfUchars;
406 AddressMapping->IoAddress = IoAddress;
407 AddressMapping->SystemIoBusNumber = DeviceExtension->SystemIoBusNumber;
408 AddressMapping->MappedAddress = MappedAddress;
409 AddressMapping->MappingCount = 1;
411 &DeviceExtension->AddressMappingListHead,
412 &AddressMapping->List);
413 }
414
415 return MappedAddress;
416 }
417
418 if (Status)
419 *Status = NO_ERROR;
420
421 return NULL;
422}
#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::@2299 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:219
_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 219 of file resource.c.

225{
226 OBJECT_ATTRIBUTES ObjAttribs;
228 HANDLE hMemObj;
230 SIZE_T Size;
231
232 /* Initialize object attribs */
233 RtlInitUnicodeString(&UnicodeString, L"\\Device\\PhysicalMemory");
234 InitializeObjectAttributes(&ObjAttribs,
237 NULL, NULL);
238
239 /* Open physical memory section */
240 Status = ZwOpenSection(&hMemObj, SECTION_ALL_ACCESS, &ObjAttribs);
241 if (!NT_SUCCESS(Status))
242 {
243 WARN_(VIDEOPRT, "ZwOpenSection() failed! (0x%x)\n", Status);
244 return Status;
245 }
246
247 /* Map view of section */
248 Size = SizeInBytes;
249 Status = ZwMapViewOfSection(hMemObj,
250 Process,
252 0,
253 Size,
255 &Size,
256 ViewUnmap,
257 0,
258 Protect);
259 ZwClose(hMemObj);
260 if (!NT_SUCCESS(Status))
261 {
262 WARN_(VIDEOPRT, "ZwMapViewOfSection() failed! (0x%x)\n", Status);
263 }
264
265 return Status;
266}
_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
#define L(x)
Definition: ntvdm.h:50
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 194 of file resource.c.

196{
198 BOOLEAN ConflictDetected;
199 // An empty CM_RESOURCE_LIST
200 UCHAR EmptyResourceList[FIELD_OFFSET(CM_RESOURCE_LIST, List)] = {0};
201
203 DeviceExtension->DriverObject,
204 NULL, 0, /* Driver List */
205 DeviceExtension->PhysicalDeviceObject,
206 (PCM_RESOURCE_LIST)EmptyResourceList,
207 sizeof(EmptyResourceList),
208 &ConflictDetected);
209
210 if (!NT_SUCCESS(Status))
211 {
212 DPRINT1("VideoPortReleaseResources IoReportResource failed with 0x%08lx ; ConflictDetected: %s\n",
213 Status, ConflictDetected ? "TRUE" : "FALSE");
214 }
215 /* Ignore the returned status however... */
216}
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 425 of file resource.c.

428{
429 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
432
433 Entry = DeviceExtension->AddressMappingListHead.Flink;
434 while (Entry != &DeviceExtension->AddressMappingListHead)
435 {
436 AddressMapping = CONTAINING_RECORD(
437 Entry,
439 List);
440 if (AddressMapping->MappedAddress == MappedAddress)
441 {
442 ASSERT(AddressMapping->MappingCount > 0);
443 AddressMapping->MappingCount--;
444 if (AddressMapping->MappingCount == 0)
445 {
447 AddressMapping->MappedAddress,
448 AddressMapping->NumberOfUchars);
450 ExFreePool(AddressMapping);
451 }
452 return;
453 }
454
455 Entry = Entry->Flink;
456 }
457
458 /* If there was no kernelmode mapping for the given address found we assume
459 * that the given address is a usermode mapping and try to unmap it.
460 *
461 * FIXME: Is it ok to use NtCurrentProcess?
462 */
463 Status = ZwUnmapViewOfSection(NtCurrentProcess(), MappedAddress);
464 if (!NT_SUCCESS(Status))
465 {
466 WARN_(VIDEOPRT, "Warning: Mapping for address 0x%p not found!\n", MappedAddress);
467 }
468}
#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 1051 of file resource.c.

1055{
1056 TRACE_(VIDEOPRT, "VideoPortAllocateBuffer\n");
1059}
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 1024 of file resource.c.

1029{
1030 TRACE_(VIDEOPRT, "VideoPortAllocatePool\n");
1032}
_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 498 of file resource.c.

501{
502 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
504 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
505 MappedAddress);
506}
#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:425

Referenced by InitializeModeTable().

◆ VideoPortFreePool()

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

Definition at line 1039 of file resource.c.

1042{
1043 ExFreePool(Ptr);
1044}
_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 626 of file resource.c.

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

1182{
1183 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
1184
1185 TRACE_(VIDEOPRT, "VideoPortGetBusData\n");
1186
1187 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
1188
1189 if (BusDataType != Cmos)
1190 {
1191 /* Legacy vs. PnP behaviour */
1192 if (DeviceExtension->PhysicalDeviceObject != NULL)
1193 SlotNumber = DeviceExtension->SystemIoSlotNumber;
1194 }
1195
1196 return HalGetBusDataByOffset(
1197 BusDataType,
1198 DeviceExtension->SystemIoBusNumber,
1199 SlotNumber,
1200 Buffer,
1201 Offset,
1202 Length);
1203}
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 477 of file resource.c.

482{
483 TRACE_(VIDEOPRT, "VideoPortGetDeviceBase\n");
485 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
486 IoAddress,
487 NumberOfUchars,
488 InIoSpace,
489 NULL,
490 NULL);
491}
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:270

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

1013{
1014 TRACE_(VIDEOPRT, "VideoPortGetDeviceData\n");
1017}
#define UNIMPLEMENTED
Definition: debug.h:118
#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 1079 of file resource.c.

1084{
1085 PMDL Mdl;
1086
1088 if (!Mdl)
1089 {
1090 return NULL;
1091 }
1092 /* FIXME use seh */
1094 return Mdl;
1095}
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:34
_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 1103 of file resource.c.

1109{
1110 PVOID Buffer;
1111
1112 /* clear output buffer */
1113 pVrp->OutputBuffer = NULL;
1114
1115 if (DmaFlags != VideoPortDmaInitOnly)
1116 {
1117 /* VideoPortKeepPagesLocked / VideoPortUnlockAfterDma is no-op */
1118 return FALSE;
1119 }
1120
1121 /* lock the buffer */
1122 Buffer = VideoPortLockBuffer(HwDeviceExtension, pVrp->InputBuffer, pVrp->InputBufferLength, IoModifyAccess);
1123
1124 if (Buffer)
1125 {
1126 /* store result buffer & length */
1127 pVrp->OutputBuffer = Buffer;
1128 pVrp->OutputBufferLength = pVrp->InputBufferLength;
1129
1130 /* operation succeeded */
1131 return TRUE;
1132 }
1133
1134 /* operation failed */
1135 return FALSE;
1136}
@ 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:1079
@ 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 513 of file resource.c.

523{
524 TRACE_(VIDEOPRT, "VideoPortMapBankedMemory\n");
527}

◆ VideoPortMapMemory()

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

Definition at line 535 of file resource.c.

541{
542 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
544
545 TRACE_(VIDEOPRT, "VideoPortMapMemory\n");
546 INFO_(VIDEOPRT, "- *VirtualAddress: 0x%x\n", *VirtualAddress);
547
548 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
550 DeviceExtension,
552 *Length,
553 *InIoSpace,
555 &Status);
556
557 return Status;
558}

◆ VideoPortReleaseBuffer()

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

Definition at line 1066 of file resource.c.

1069{
1070 TRACE_(VIDEOPRT, "VideoPortReleaseBuffer\n");
1071 ExFreePool(Ptr);
1072}

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

1217{
1218 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
1219
1220 TRACE_(VIDEOPRT, "VideoPortSetBusData\n");
1221
1222 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
1223
1224 if (BusDataType != Cmos)
1225 {
1226 /* Legacy vs. PnP behaviour */
1227 if (DeviceExtension->PhysicalDeviceObject != NULL)
1228 SlotNumber = DeviceExtension->SystemIoSlotNumber;
1229 }
1230
1231 return HalSetBusDataByOffset(
1232 BusDataType,
1233 DeviceExtension->SystemIoBusNumber,
1234 SlotNumber,
1235 Buffer,
1236 Offset,
1237 Length);
1238}
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 1160 of file resource.c.

1164{
1166 /* Should store the ranges in the device extension for use by ntvdm. */
1167 return NO_ERROR;
1168}

◆ VideoPortUnlockBuffer()

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

Definition at line 1144 of file resource.c.

1147{
1148 if (Mdl)
1149 {
1151 IoFreeMdl(Mdl);
1152 }
1153}
#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 565 of file resource.c.

569{
570 TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
571
573 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
575
576 return NO_ERROR;
577}

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

920{
921 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
922 BOOLEAN ConflictDetected;
923 ULONG ResourceListSize;
925 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
926 ULONG i;
928
929 TRACE_(VIDEOPRT, "VideoPortVerifyAccessRanges\n");
930
931 /* Verify parameters */
932 if (NumAccessRanges && !AccessRanges)
934
935 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
936
937 if (NumAccessRanges == 0)
938 {
939 /* Release the resources and do nothing more for now... */
940 IntVideoPortReleaseResources(DeviceExtension);
941 return NO_ERROR;
942 }
943
944 /* Create the resource list */
945 ResourceListSize = sizeof(CM_RESOURCE_LIST)
946 + (NumAccessRanges - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
948 if (!ResourceList)
949 {
950 WARN_(VIDEOPRT, "ExAllocatePool() failed\n");
952 }
953
954 /* Fill resource list */
955 ResourceList->Count = 1;
956 ResourceList->List[0].InterfaceType = DeviceExtension->AdapterInterfaceType;
957 ResourceList->List[0].BusNumber = DeviceExtension->SystemIoBusNumber;
958 ResourceList->List[0].PartialResourceList.Version = 1;
959 ResourceList->List[0].PartialResourceList.Revision = 1;
960 ResourceList->List[0].PartialResourceList.Count = NumAccessRanges;
961 for (i = 0; i < NumAccessRanges; i++, AccessRanges++)
962 {
963 PartialDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
964 if (AccessRanges->RangeInIoSpace)
965 {
966 PartialDescriptor->Type = CmResourceTypePort;
967 PartialDescriptor->u.Port.Start = AccessRanges->RangeStart;
968 PartialDescriptor->u.Port.Length = AccessRanges->RangeLength;
969 }
970 else
971 {
972 PartialDescriptor->Type = CmResourceTypeMemory;
973 PartialDescriptor->u.Memory.Start = AccessRanges->RangeStart;
974 PartialDescriptor->u.Memory.Length = AccessRanges->RangeLength;
975 }
976 if (AccessRanges->RangeShareable)
977 PartialDescriptor->ShareDisposition = CmResourceShareShared;
978 else
980 PartialDescriptor->Flags = 0;
981 if (AccessRanges->RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
982 PartialDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
983 if (AccessRanges->RangePassive & VIDEO_RANGE_10_BIT_DECODE)
984 PartialDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
985 }
986
987 /* Try to acquire all resource ranges */
989 DeviceExtension->DriverObject,
990 NULL, 0, /* Driver List */
991 DeviceExtension->PhysicalDeviceObject,
992 ResourceList, ResourceListSize,
993 &ConflictDetected);
994
996
997 if (!NT_SUCCESS(Status) || ConflictDetected)
999 else
1000 return NO_ERROR;
1001}
struct _CM_RESOURCE_LIST CM_RESOURCE_LIST
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391::@393 Port
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391::@396 Memory
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@391 u
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
VOID IntVideoPortReleaseResources(_In_ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
Definition: resource.c:194

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