ReactOS 0.4.15-dev-7934-g1dc8d80
agp.c File Reference
#include "videoprt.h"
#include <debug.h>
Include dependency graph for agp.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS IopInitiatePnpIrp (PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK IoStatusBlock, UCHAR MinorFunction, PIO_STACK_LOCATION Stack OPTIONAL)
 
BOOLEAN NTAPI IntAgpCommitPhysical (IN PVOID HwDeviceExtension, IN PVOID PhysicalContext, IN ULONG Pages, IN ULONG Offset)
 
VOID NTAPI IntAgpFreePhysical (IN PVOID HwDeviceExtension, IN PVOID PhysicalContext, IN ULONG Pages, IN ULONG Offset)
 
VOID NTAPI IntAgpReleasePhysical (IN PVOID HwDeviceExtension, IN PVOID PhysicalContext)
 
PHYSICAL_ADDRESS NTAPI IntAgpReservePhysical (IN PVOID HwDeviceExtension, IN ULONG Pages, IN VIDEO_PORT_CACHE_TYPE Caching, OUT PVOID *PhysicalContext)
 
PVOID NTAPI IntAgpCommitVirtual (IN PVOID HwDeviceExtension, IN PVOID VirtualContext, IN ULONG Pages, IN ULONG Offset)
 
VOID NTAPI IntAgpFreeVirtual (IN PVOID HwDeviceExtension, IN PVOID VirtualContext, IN ULONG Pages, IN ULONG Offset)
 
VOID NTAPI IntAgpReleaseVirtual (IN PVOID HwDeviceExtension, IN PVOID VirtualContext)
 
PVOID NTAPI IntAgpReserveVirtual (IN PVOID HwDeviceExtension, IN HANDLE ProcessHandle, IN PVOID PhysicalContext, OUT PVOID *VirtualContext)
 
BOOLEAN NTAPI IntAgpSetRate (IN PVOID HwDeviceExtension, IN ULONG Rate)
 
NTSTATUS NTAPI IntAgpGetInterface (IN PVOID HwDeviceExtension, IN OUT PINTERFACE Interface)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 24 of file agp.c.

Function Documentation

◆ IntAgpCommitPhysical()

BOOLEAN NTAPI IntAgpCommitPhysical ( IN PVOID  HwDeviceExtension,
IN PVOID  PhysicalContext,
IN ULONG  Pages,
IN ULONG  Offset 
)

Definition at line 94 of file agp.c.

99{
100 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
101 PAGP_BUS_INTERFACE_STANDARD AgpBusInterface;
102 PHYSICAL_ADDRESS MappingAddr = {{0, 0}};
103 PVIDEO_PORT_AGP_MAPPING AgpMapping;
105
106 TRACE_(VIDEOPRT, "AgpCommitPhysical - PhysicalContext: 0x%x Pages: %d, Offset: 0x%x\n",
107 PhysicalContext, Pages, Offset);
108
109 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
110 AgpBusInterface = &DeviceExtension->AgpInterface;
111 AgpMapping = (PVIDEO_PORT_AGP_MAPPING)PhysicalContext;
112
113 Status = AgpBusInterface->CommitMemory(AgpBusInterface->AgpContext,
114 AgpMapping->MapHandle, Pages, Offset,
115 NULL, &MappingAddr);
116
117 if (!NT_SUCCESS(Status))
118 {
119 WARN_(VIDEOPRT, "Warning: AgpBusInterface->CommitMemory failed (Status = 0x%x)\n",
120 Status);
121 }
122 return NT_SUCCESS(Status);
123}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TRACE_(x)
Definition: compat.h:76
Status
Definition: gdiplustypes.h:25
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define WARN_(ch,...)
Definition: debug.h:157
PAGP_BUS_COMMIT_MEMORY CommitMemory
Definition: ntagp.h:188
AGP_BUS_INTERFACE_STANDARD AgpInterface
Definition: videoprt.h:105
struct _VIDEO_PORT_AGP_MAPPING * PVIDEO_PORT_AGP_MAPPING
#define VIDEO_PORT_GET_DEVICE_EXTENSION(MiniportExtension)
Definition: videoprt.h:140

Referenced by IntAgpGetInterface().

◆ IntAgpCommitVirtual()

PVOID NTAPI IntAgpCommitVirtual ( IN PVOID  HwDeviceExtension,
IN PVOID  VirtualContext,
IN ULONG  Pages,
IN ULONG  Offset 
)

Definition at line 248 of file agp.c.

253{
254 PVIDEO_PORT_AGP_VIRTUAL_MAPPING VirtualMapping;
258
259 TRACE_(VIDEOPRT, "AgpCommitVirtual - VirtualContext: 0x%x Pages: %d, Offset: 0x%x\n",
260 VirtualContext, Pages, Offset);
261
262 VirtualMapping = (PVIDEO_PORT_AGP_VIRTUAL_MAPPING)VirtualContext;
263
264 /* I think the NT API provides no way of reserving a part of the address space
265 * and setting it up to map into a specified range of physical memory later.
266 * This means that we will have to release some of the reserved virtual memory
267 * and map the physical memory into it using MapViewOfSection.
268 *
269 * - blight (2004-12-21)
270 */
271
272 if (VirtualMapping->ProcessHandle == NULL)
273 {
274 /* FIXME: not implemented */
275 }
276 else /* ProcessHandle != NULL */
277 {
278 /* Release some virtual memory */
279 SIZE_T Size = Pages * PAGE_SIZE;
280 ULONG OffsetInBytes = Offset * PAGE_SIZE;
281 BaseAddress = (PVOID)((ULONG_PTR)VirtualMapping->MappedAddress +
282 OffsetInBytes);
283 PhysicalAddress = VirtualMapping->AgpMapping->PhysicalAddress;
284 PhysicalAddress.QuadPart += OffsetInBytes;
285
286 Status = ZwFreeVirtualMemory(VirtualMapping->ProcessHandle,
288 &Size, MEM_RELEASE);
289 if (!NT_SUCCESS(Status))
290 {
291 WARN_(VIDEOPRT, "Warning: ZwFreeVirtualMemory() failed: Status = 0x%x\n", Status);
292 return NULL;
293 }
294 ASSERT(Size == Pages * PAGE_SIZE);
295 ASSERT(BaseAddress == (PVOID)((ULONG_PTR)VirtualMapping->MappedAddress +
296 OffsetInBytes));
297
298 /* Map the physical memory into the released virtual memory area */
301 Size,
303 &BaseAddress);
304 if (!NT_SUCCESS(Status))
305 {
306 WARN_(VIDEOPRT, "Warning: IntVideoPortMapPhysicalMemory() failed: Status = 0x%x\n", Status);
307 /* Reserve the released virtual memory area again */
308 Status = ZwAllocateVirtualMemory(VirtualMapping->ProcessHandle,
311 if (!NT_SUCCESS(Status))
312 {
313 WARN_(VIDEOPRT, "Warning: ZwAllocateVirtualMemory() failed: Status = 0x%x\n", Status);
314 /* FIXME: What to do now?? */
315 ASSERT(0);
316 return NULL;
317 }
318 ASSERT(Size == Pages * PAGE_SIZE);
319 ASSERT(BaseAddress == (PVOID)((ULONG_PTR)VirtualMapping->MappedAddress +
320 OffsetInBytes));
321 return NULL;
322 }
323 ASSERT(BaseAddress == (PVOID)((ULONG_PTR)VirtualMapping->MappedAddress +
324 OffsetInBytes));
325 }
326
327 return BaseAddress;
328}
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ASSERT(a)
Definition: mode.c:44
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define MEM_RESERVE
Definition: nt_native.h:1314
#define MEM_RELEASE
Definition: nt_native.h:1316
#define PAGE_NOACCESS
Definition: nt_native.h:1302
PHYSICAL_ADDRESS PhysicalAddress
Definition: videoprt.h:60
PVIDEO_PORT_AGP_MAPPING AgpMapping
Definition: videoprt.h:65
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
struct _VIDEO_PORT_AGP_VIRTUAL_MAPPING * PVIDEO_PORT_AGP_VIRTUAL_MAPPING
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
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
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098

Referenced by IntAgpGetInterface().

◆ IntAgpFreePhysical()

VOID NTAPI IntAgpFreePhysical ( IN PVOID  HwDeviceExtension,
IN PVOID  PhysicalContext,
IN ULONG  Pages,
IN ULONG  Offset 
)

Definition at line 126 of file agp.c.

131{
132 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
133 PAGP_BUS_INTERFACE_STANDARD AgpBusInterface;
134 PVIDEO_PORT_AGP_MAPPING AgpMapping;
136
137 TRACE_(VIDEOPRT, "AgpFreePhysical - PhysicalContext: 0x%x Pages: %d, Offset: 0x%x\n",
138 PhysicalContext, Pages, Offset);
139
140 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
141 AgpBusInterface = &DeviceExtension->AgpInterface;
142 AgpMapping = (PVIDEO_PORT_AGP_MAPPING)PhysicalContext;
143
144 Status = AgpBusInterface->FreeMemory(AgpBusInterface->AgpContext,
145 AgpMapping->MapHandle, Pages, Offset);
146 if (!NT_SUCCESS(Status))
147 {
148 WARN_(VIDEOPRT, "Warning: AgpBusInterface->FreeMemory failed (Status = 0x%x)\n",
149 Status);
150 }
151}
PAGP_BUS_FREE_MEMORY FreeMemory
Definition: ntagp.h:189

Referenced by IntAgpGetInterface().

◆ IntAgpFreeVirtual()

VOID NTAPI IntAgpFreeVirtual ( IN PVOID  HwDeviceExtension,
IN PVOID  VirtualContext,
IN ULONG  Pages,
IN ULONG  Offset 
)

Definition at line 331 of file agp.c.

336{
337 PVIDEO_PORT_AGP_VIRTUAL_MAPPING VirtualMapping;
340
341 TRACE_(VIDEOPRT, "AgpFreeVirtual - VirtualContext: 0x%x Pages: %d, Offset: 0x%x\n",
342 VirtualContext, Pages, Offset);
343
344 VirtualMapping = (PVIDEO_PORT_AGP_VIRTUAL_MAPPING)VirtualContext;
345
346 if (VirtualMapping->ProcessHandle == NULL)
347 {
348 /* FIXME: not implemented */
349 }
350 else /* ProcessHandle != NULL */
351 {
352 /* Unmap the section view */
353 SIZE_T Size = Pages * PAGE_SIZE;
354 ULONG OffsetInBytes = Offset * PAGE_SIZE;
355 BaseAddress = (PVOID)((ULONG_PTR)VirtualMapping->MappedAddress +
356 OffsetInBytes);
357
358 Status = ZwUnmapViewOfSection(VirtualMapping->ProcessHandle, BaseAddress);
359 if (!NT_SUCCESS(Status))
360 {
361 WARN_(VIDEOPRT, "Warning: ZwUnmapViewOfSection() failed: Status = 0x%x\n", Status);
362 /* FIXME: What to do now?? */
363 ASSERT(0);
364 return;
365 }
366
367 /* And reserve the virtual memory area again */
368 Status = ZwAllocateVirtualMemory(VirtualMapping->ProcessHandle,
371 if (!NT_SUCCESS(Status))
372 {
373 WARN_(VIDEOPRT, "Warning: ZwAllocateVirtualMemory() failed: Status = 0x%x\n", Status);
374 /* FIXME: What to do now?? */
375 ASSERT(0);
376 return;
377 }
378 ASSERT(Size == Pages * PAGE_SIZE);
379 ASSERT(BaseAddress == (PVOID)((ULONG_PTR)VirtualMapping->MappedAddress +
380 OffsetInBytes));
381 }
382}

Referenced by IntAgpGetInterface().

◆ IntAgpGetInterface()

NTSTATUS NTAPI IntAgpGetInterface ( IN PVOID  HwDeviceExtension,
IN OUT PINTERFACE  Interface 
)

Definition at line 496 of file agp.c.

499{
501 IO_STACK_LOCATION IoStack;
503 PVIDEO_PORT_AGP_INTERFACE_2 AgpInterface;
504 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
505 PAGP_BUS_INTERFACE_STANDARD AgpBusInterface;
506
507 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
508 AgpBusInterface = &DeviceExtension->AgpInterface;
510
514 {
516 }
518 {
519 ASSERT(Interface->Size >= sizeof(VIDEO_PORT_AGP_INTERFACE));
520 }
521
522 if (DeviceExtension->NextDeviceObject == NULL)
523 {
524 WARN_(VIDEOPRT, "DeviceExtension->NextDeviceObject is NULL!\n");
525 return STATUS_UNSUCCESSFUL;
526 }
527
528 /* Query the interface from the AGP bus driver */
529 if (DeviceExtension->AgpInterface.Size == 0)
530 {
531 AgpBusInterface->Size = sizeof(AGP_BUS_INTERFACE_STANDARD);
533 AgpBusInterface->Version = AGP_BUS_INTERFACE_V1;
534 else /* if (InterfaceVersion == VIDEO_PORT_AGP_INTERFACE_VERSION_2) */
535 AgpBusInterface->Version = AGP_BUS_INTERFACE_V2;
536 IoStack.Parameters.QueryInterface.Size = AgpBusInterface->Size;
537 IoStack.Parameters.QueryInterface.Version = AgpBusInterface->Version;
538 IoStack.Parameters.QueryInterface.Interface = (PINTERFACE)AgpBusInterface;
539 IoStack.Parameters.QueryInterface.InterfaceType =
540 &GUID_AGP_TARGET_BUS_INTERFACE_STANDARD;
541 Status = IopInitiatePnpIrp(DeviceExtension->NextDeviceObject,
543 if (!NT_SUCCESS(Status))
544 {
545 WARN_(VIDEOPRT, "IopInitiatePnpIrp() failed! (Status 0x%x)\n", Status);
546 return Status;
547 }
548 INFO_(VIDEOPRT, "Got AGP driver interface!\n");
549 }
550
551 /* FIXME: Not sure if we should wrap the reference/dereference functions */
552 AgpInterface->Context = AgpBusInterface->AgpContext;
553 AgpInterface->InterfaceReference = AgpBusInterface->InterfaceReference;
554 AgpInterface->InterfaceDereference = AgpBusInterface->InterfaceDereference;
558 AgpInterface->AgpFreePhysical = IntAgpFreePhysical;
562 AgpInterface->AgpFreeVirtual = IntAgpFreeVirtual;
563 AgpInterface->AgpAllocationLimit = 0x1000000; /* FIXME: using 16 MB for now */
564
565 if (AgpInterface->Version >= VIDEO_PORT_AGP_INTERFACE_VERSION_2)
566 {
567 AgpInterface->AgpSetRate = IntAgpSetRate;
568 }
569
570 return STATUS_SUCCESS;
571}
VOID NTAPI IntAgpFreeVirtual(IN PVOID HwDeviceExtension, IN PVOID VirtualContext, IN ULONG Pages, IN ULONG Offset)
Definition: agp.c:331
PVOID NTAPI IntAgpReserveVirtual(IN PVOID HwDeviceExtension, IN HANDLE ProcessHandle, IN PVOID PhysicalContext, OUT PVOID *VirtualContext)
Definition: agp.c:419
BOOLEAN NTAPI IntAgpSetRate(IN PVOID HwDeviceExtension, IN ULONG Rate)
Definition: agp.c:479
BOOLEAN NTAPI IntAgpCommitPhysical(IN PVOID HwDeviceExtension, IN PVOID PhysicalContext, IN ULONG Pages, IN ULONG Offset)
Definition: agp.c:94
NTSTATUS IopInitiatePnpIrp(PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK IoStatusBlock, UCHAR MinorFunction, PIO_STACK_LOCATION Stack OPTIONAL)
Definition: agp.c:30
VOID NTAPI IntAgpFreePhysical(IN PVOID HwDeviceExtension, IN PVOID PhysicalContext, IN ULONG Pages, IN ULONG Offset)
Definition: agp.c:126
VOID NTAPI IntAgpReleasePhysical(IN PVOID HwDeviceExtension, IN PVOID PhysicalContext)
Definition: agp.c:154
PVOID NTAPI IntAgpCommitVirtual(IN PVOID HwDeviceExtension, IN PVOID VirtualContext, IN ULONG Pages, IN ULONG Offset)
Definition: agp.c:248
PHYSICAL_ADDRESS NTAPI IntAgpReservePhysical(IN PVOID HwDeviceExtension, IN ULONG Pages, IN VIDEO_PORT_CACHE_TYPE Caching, OUT PVOID *PhysicalContext)
Definition: agp.c:183
VOID NTAPI IntAgpReleaseVirtual(IN PVOID HwDeviceExtension, IN PVOID VirtualContext)
Definition: agp.c:385
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
struct _AGP_BUS_INTERFACE_STANDARD AGP_BUS_INTERFACE_STANDARD
#define AGP_BUS_INTERFACE_V2
Definition: ntagp.h:32
#define AGP_BUS_INTERFACE_V1
Definition: ntagp.h:31
struct _INTERFACE * PINTERFACE
#define VIDEO_PORT_AGP_INTERFACE_VERSION_1
Definition: video.h:123
#define VIDEO_PORT_AGP_INTERFACE_VERSION_2
Definition: video.h:124
struct _VIDEO_PORT_AGP_INTERFACE_2 * PVIDEO_PORT_AGP_INTERFACE_2
#define INFO_(ch,...)
Definition: debug.h:159
#define STATUS_SUCCESS
Definition: shellext.h:65
PINTERFACE_REFERENCE InterfaceReference
Definition: ntagp.h:183
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: ntagp.h:184
union _IO_STACK_LOCATION::@1564 Parameters
struct _IO_STACK_LOCATION::@3978::@4004 QueryInterface
OUT PAGP_COMMIT_VIRTUAL AgpCommitVirtual
Definition: video.h:750
OUT PAGP_COMMIT_PHYSICAL AgpCommitPhysical
Definition: video.h:746
OUT PAGP_RESERVE_VIRTUAL AgpReserveVirtual
Definition: video.h:748
OUT PINTERFACE_DEREFERENCE InterfaceDereference
Definition: video.h:743
OUT PAGP_RESERVE_PHYSICAL AgpReservePhysical
Definition: video.h:744
OUT PAGP_FREE_VIRTUAL AgpFreeVirtual
Definition: video.h:751
OUT PAGP_SET_RATE AgpSetRate
Definition: video.h:753
OUT ULONGLONG AgpAllocationLimit
Definition: video.h:752
OUT PAGP_RELEASE_VIRTUAL AgpReleaseVirtual
Definition: video.h:749
OUT PINTERFACE_REFERENCE InterfaceReference
Definition: video.h:742
OUT PAGP_FREE_PHYSICAL AgpFreePhysical
Definition: video.h:747
OUT PAGP_RELEASE_PHYSICAL AgpReleasePhysical
Definition: video.h:745
PDEVICE_OBJECT NextDeviceObject
Definition: videoprt.h:89
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
#define IRP_MN_QUERY_INTERFACE

Referenced by VideoPortQueryServices().

◆ IntAgpReleasePhysical()

VOID NTAPI IntAgpReleasePhysical ( IN PVOID  HwDeviceExtension,
IN PVOID  PhysicalContext 
)

Definition at line 154 of file agp.c.

157{
158 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
159 PAGP_BUS_INTERFACE_STANDARD AgpBusInterface;
160 PVIDEO_PORT_AGP_MAPPING AgpMapping;
162
163 TRACE_(VIDEOPRT, "AgpReleasePhysical - PhysicalContext: 0x%x\n", PhysicalContext);
164
165 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
166 AgpBusInterface = &DeviceExtension->AgpInterface;
167 AgpMapping = (PVIDEO_PORT_AGP_MAPPING)PhysicalContext;
168
169 /* Release memory */
170 Status = AgpBusInterface->ReleaseMemory(AgpBusInterface->AgpContext,
171 AgpMapping->MapHandle);
172 if (!NT_SUCCESS(Status))
173 {
174 WARN_(VIDEOPRT, "Warning: AgpBusInterface->ReleaseMemory failed (Status = 0x%x)\n",
175 Status);
176 }
177
178 /* Free resources */
180}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
PAGP_BUS_RELEASE_MEMORY ReleaseMemory
Definition: ntagp.h:187
#define TAG_VIDEO_PORT
Definition: videoprt.h:38

Referenced by IntAgpGetInterface().

◆ IntAgpReleaseVirtual()

VOID NTAPI IntAgpReleaseVirtual ( IN PVOID  HwDeviceExtension,
IN PVOID  VirtualContext 
)

Definition at line 385 of file agp.c.

388{
389 PVIDEO_PORT_AGP_VIRTUAL_MAPPING VirtualMapping;
391
392 TRACE_(VIDEOPRT, "AgpReleaseVirtual - VirtualContext: 0x%x\n", VirtualContext);
393
394 VirtualMapping = (PVIDEO_PORT_AGP_VIRTUAL_MAPPING)VirtualContext;
395
396 /* Release the virtual memory */
397 if (VirtualMapping->ProcessHandle == NULL)
398 {
399 /* FIXME: not implemented */
400 }
401 else /* ProcessHandle != NULL */
402 {
403 /* Release the allocated virtual memory */
404 SIZE_T Size = VirtualMapping->AgpMapping->NumberOfPages * PAGE_SIZE;
405 Status = ZwFreeVirtualMemory(VirtualMapping->ProcessHandle,
406 &VirtualMapping->MappedAddress,
407 &Size, MEM_RELEASE);
408 if (!NT_SUCCESS(Status))
409 {
410 WARN_(VIDEOPRT, "Warning: ZwFreeVirtualMemory() failed: Status = 0x%x\n", Status);
411 }
412 }
413
414 /* Free resources */
415 ExFreePoolWithTag(VirtualMapping, TAG_VIDEO_PORT);
416}

Referenced by IntAgpGetInterface().

◆ IntAgpReservePhysical()

PHYSICAL_ADDRESS NTAPI IntAgpReservePhysical ( IN PVOID  HwDeviceExtension,
IN ULONG  Pages,
IN VIDEO_PORT_CACHE_TYPE  Caching,
OUT PVOID PhysicalContext 
)

Definition at line 183 of file agp.c.

188{
189 PHYSICAL_ADDRESS ZeroAddress = {{0, 0}};
190 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
191 PAGP_BUS_INTERFACE_STANDARD AgpBusInterface;
192 MEMORY_CACHING_TYPE MemCachingType;
193 PVIDEO_PORT_AGP_MAPPING AgpMapping;
195
196 TRACE_(VIDEOPRT, "AgpReservePhysical - Pages: %d, Caching: 0x%x\n", Pages, Caching);
197
198 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
199 AgpBusInterface = &DeviceExtension->AgpInterface;
200
201 /* Translate memory caching type */
202 if (Caching == VpNonCached)
203 MemCachingType = MmNonCached;
204 else if (Caching == VpCached)
205 MemCachingType = MmCached;
206 else if (Caching == VpWriteCombined)
207 MemCachingType = MmWriteCombined;
208 else
209 {
210 WARN_(VIDEOPRT, "Invalid caching type %d!\n", Caching);
211 return ZeroAddress;
212 }
213
214 /* Allocate an AGP mapping structure */
215 AgpMapping = ExAllocatePoolWithTag(PagedPool,
218 if (AgpMapping == NULL)
219 {
220 WARN_(VIDEOPRT, "Out of memory! Couldn't allocate AGP mapping structure!\n");
221 return ZeroAddress;
222 }
223 RtlZeroMemory(AgpMapping, sizeof(VIDEO_PORT_AGP_MAPPING));
224
225 /* Reserve memory for the AGP bus */
226 Status = AgpBusInterface->ReserveMemory(AgpBusInterface->AgpContext,
227 Pages,
228 MemCachingType,
229 &AgpMapping->MapHandle,
230 &AgpMapping->PhysicalAddress);
231 if (!NT_SUCCESS(Status) || AgpMapping->MapHandle == NULL)
232 {
234 WARN_(VIDEOPRT, "Warning: AgpBusInterface->ReserveMemory failed (Status = 0x%x)\n",
235 Status);
236 return ZeroAddress;
237 }
238
239 /* Fill the rest of the AGP mapping */
240 AgpMapping->NumberOfPages = Pages;
241
242 *PhysicalContext = (PVOID)AgpMapping;
243 return AgpMapping->PhysicalAddress;
244}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
PAGP_BUS_RESERVE_MEMORY ReserveMemory
Definition: ntagp.h:186
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
@ VpNonCached
Definition: videoagp.h:37
@ VpWriteCombined
Definition: videoagp.h:38
@ VpCached
Definition: videoagp.h:39
enum _MEMORY_CACHING_TYPE MEMORY_CACHING_TYPE
@ MmCached
Definition: mmtypes.h:130
@ MmNonCached
Definition: mmtypes.h:129
@ MmWriteCombined
Definition: mmtypes.h:131

Referenced by IntAgpGetInterface().

◆ IntAgpReserveVirtual()

PVOID NTAPI IntAgpReserveVirtual ( IN PVOID  HwDeviceExtension,
IN HANDLE  ProcessHandle,
IN PVOID  PhysicalContext,
OUT PVOID VirtualContext 
)

Definition at line 419 of file agp.c.

424{
425 PVIDEO_PORT_AGP_MAPPING AgpMapping;
426 PVIDEO_PORT_AGP_VIRTUAL_MAPPING VirtualMapping;
427 PVOID MappedAddress;
429
430 TRACE_(VIDEOPRT, "AgpReserveVirtual - ProcessHandle: 0x%x PhysicalContext: 0x%x\n",
431 ProcessHandle, PhysicalContext);
432
433 AgpMapping = (PVIDEO_PORT_AGP_MAPPING)PhysicalContext;
434
435 /* Allocate an AGP virtual mapping structure */
436 VirtualMapping = ExAllocatePoolWithTag(PagedPool,
439 if (VirtualMapping == NULL)
440 {
441 WARN_(VIDEOPRT, "Out of memory! Couldn't allocate AGP virtual mapping structure!\n");
442 return NULL;
443 }
444 RtlZeroMemory(VirtualMapping, sizeof(VIDEO_PORT_AGP_VIRTUAL_MAPPING));
445
446 /* Reserve a virtual memory area for the physical pages. */
447 if (ProcessHandle == NULL)
448 {
449 /* FIXME: What to do in this case? */
450 ExFreePoolWithTag(VirtualMapping, TAG_VIDEO_PORT);
451 return NULL;
452 }
453 else /* ProcessHandle != NULL */
454 {
455 /* Reserve memory for usermode */
456 SIZE_T Size = AgpMapping->NumberOfPages * PAGE_SIZE;
457 MappedAddress = NULL;
458 Status = ZwAllocateVirtualMemory(ProcessHandle, &MappedAddress, 0, &Size,
460 if (!NT_SUCCESS(Status))
461 {
462 ExFreePoolWithTag(VirtualMapping, TAG_VIDEO_PORT);
463 WARN_(VIDEOPRT, "ZwAllocateVirtualMemory() failed: Status = 0x%x\n", Status);
464 return NULL;
465 }
466 }
467
468 /* Fill the AGP virtual mapping */
469 VirtualMapping->AgpMapping = AgpMapping;
470 VirtualMapping->ProcessHandle = ProcessHandle;
471 VirtualMapping->MappedAddress = MappedAddress;
472
473 *VirtualContext = (PVOID)VirtualMapping;
474 return MappedAddress;
475}
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403

Referenced by IntAgpGetInterface().

◆ IntAgpSetRate()

BOOLEAN NTAPI IntAgpSetRate ( IN PVOID  HwDeviceExtension,
IN ULONG  Rate 
)

Definition at line 479 of file agp.c.

482{
483 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
484 PAGP_BUS_INTERFACE_STANDARD AgpBusInterface;
485
486 TRACE_(VIDEOPRT, "AgpSetRate - Rate: %d\n", Rate);
487
488 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
489 AgpBusInterface = &DeviceExtension->AgpInterface;
490
491 return NT_SUCCESS(AgpBusInterface->SetRate(AgpBusInterface->AgpContext, Rate));
492}
PAGP_BUS_SET_RATE SetRate
Definition: ntagp.h:191

Referenced by IntAgpGetInterface().

◆ IopInitiatePnpIrp()

NTSTATUS IopInitiatePnpIrp ( PDEVICE_OBJECT  DeviceObject,
PIO_STATUS_BLOCK  IoStatusBlock,
UCHAR  MinorFunction,
PIO_STACK_LOCATION Stack  OPTIONAL 
)

Definition at line 30 of file agp.c.

35{
36 PDEVICE_OBJECT TopDeviceObject;
40 PIRP Irp;
41
42 /* Always call the top of the device stack */
44
46 &Event,
48 FALSE);
49
52 TopDeviceObject,
53 NULL,
54 0,
55 NULL,
56 &Event,
58
59 /* PNP IRPs are always initialized with a status code of
60 STATUS_NOT_SUPPORTED */
61 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
62 Irp->IoStatus.Information = 0;
63
66
67 if (Stack)
68 {
72 sizeof(Stack->Parameters));
73 }
74
75 Status = IoCallDriver(TopDeviceObject, Irp);
77 {
79 &Event,
82 FALSE,
83 NULL);
85 }
86
87 ObDereferenceObject(TopDeviceObject);
88
89 return Status;
90}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ PIRP Irp
Definition: csq.h:116
#define FALSE
Definition: types.h:117
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
@ Executive
Definition: ketypes.h:415
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by IntAgpGetInterface().