2004-03-19 20:58:32 +00:00
|
|
|
/*
|
|
|
|
* VideoPort driver
|
|
|
|
*
|
2005-06-03 16:56:27 +00:00
|
|
|
* Copyright (C) 2002 - 2005 ReactOS Team
|
2004-03-19 20:58:32 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-10-27 10:34:16 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
2004-03-19 20:58:32 +00:00
|
|
|
* License as published by the Free Software Foundation; either
|
2009-10-27 10:34:16 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2004-03-19 20:58:32 +00:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2009-10-27 10:34:16 +00:00
|
|
|
* Lesser General Public License for more details.
|
2004-03-19 20:58:32 +00:00
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-03-19 20:58:32 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "videoprt.h"
|
|
|
|
|
2014-02-04 17:15:06 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2004-03-19 20:58:32 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
|
|
|
|
2011-10-23 02:45:09 +00:00
|
|
|
NTSTATUS NTAPI
|
|
|
|
IntVideoPortGetLegacyResources(
|
|
|
|
IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension,
|
|
|
|
IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension,
|
|
|
|
OUT PVIDEO_ACCESS_RANGE *AccessRanges,
|
|
|
|
OUT PULONG AccessRangeCount)
|
|
|
|
{
|
|
|
|
PCI_COMMON_CONFIG PciConfig;
|
|
|
|
ULONG ReadLength;
|
|
|
|
|
|
|
|
if (!DriverExtension->InitializationData.HwGetLegacyResources &&
|
|
|
|
!DriverExtension->InitializationData.HwLegacyResourceCount)
|
|
|
|
{
|
|
|
|
/* No legacy resources to report */
|
|
|
|
*AccessRangeCount = 0;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DriverExtension->InitializationData.HwGetLegacyResources)
|
|
|
|
{
|
|
|
|
ReadLength = HalGetBusData(PCIConfiguration,
|
|
|
|
DeviceExtension->SystemIoBusNumber,
|
|
|
|
DeviceExtension->SystemIoSlotNumber,
|
|
|
|
&PciConfig,
|
|
|
|
sizeof(PciConfig));
|
|
|
|
if (ReadLength != sizeof(PciConfig))
|
|
|
|
{
|
|
|
|
/* This device doesn't exist */
|
|
|
|
return STATUS_NO_SUCH_DEVICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DriverExtension->InitializationData.HwGetLegacyResources(PciConfig.VendorID,
|
|
|
|
PciConfig.DeviceID,
|
|
|
|
AccessRanges,
|
|
|
|
AccessRangeCount);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*AccessRanges = DriverExtension->InitializationData.HwLegacyResourceList;
|
|
|
|
*AccessRangeCount = DriverExtension->InitializationData.HwLegacyResourceCount;
|
|
|
|
}
|
2012-03-11 20:24:29 +00:00
|
|
|
|
|
|
|
INFO_(VIDEOPRT, "Got %d legacy access ranges\n", *AccessRangeCount);
|
|
|
|
|
2011-10-23 02:45:09 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS NTAPI
|
|
|
|
IntVideoPortFilterResourceRequirements(
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
|
|
|
|
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PVIDEO_ACCESS_RANGE AccessRanges;
|
|
|
|
ULONG AccessRangeCount, ListSize, i;
|
|
|
|
PIO_RESOURCE_REQUIREMENTS_LIST ResList, OldResList = (PVOID)Irp->IoStatus.Information;
|
|
|
|
PIO_RESOURCE_DESCRIPTOR CurrentDescriptor;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
DriverObject = DeviceObject->DriverObject;
|
|
|
|
DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
|
|
|
|
DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
Status = IntVideoPortGetLegacyResources(DriverExtension, DeviceExtension, &AccessRanges, &AccessRangeCount);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
if (!AccessRangeCount)
|
|
|
|
{
|
|
|
|
/* No legacy resources to report */
|
2021-07-06 09:32:23 +00:00
|
|
|
return Irp->IoStatus.Status;
|
2011-10-23 02:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, we've got the access ranges now. Let's set up the resource requirements list */
|
|
|
|
|
|
|
|
if (OldResList)
|
|
|
|
{
|
|
|
|
/* Already one there so let's add to it */
|
|
|
|
ListSize = OldResList->ListSize + sizeof(IO_RESOURCE_DESCRIPTOR) * AccessRangeCount;
|
|
|
|
ResList = ExAllocatePool(NonPagedPool,
|
|
|
|
ListSize);
|
|
|
|
if (!ResList) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
RtlCopyMemory(ResList, OldResList, OldResList->ListSize);
|
|
|
|
|
|
|
|
ASSERT(ResList->AlternativeLists == 1);
|
|
|
|
|
|
|
|
ResList->ListSize = ListSize;
|
|
|
|
ResList->List[0].Count += AccessRangeCount;
|
|
|
|
|
|
|
|
CurrentDescriptor = (PIO_RESOURCE_DESCRIPTOR)((PUCHAR)ResList + OldResList->ListSize);
|
|
|
|
|
|
|
|
ExFreePool(OldResList);
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We need to make a new one */
|
|
|
|
ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + sizeof(IO_RESOURCE_DESCRIPTOR) * (AccessRangeCount - 1);
|
|
|
|
ResList = ExAllocatePool(NonPagedPool,
|
|
|
|
ListSize);
|
|
|
|
if (!ResList) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
RtlZeroMemory(ResList, ListSize);
|
|
|
|
|
|
|
|
/* We need to initialize some fields */
|
|
|
|
ResList->ListSize = ListSize;
|
|
|
|
ResList->InterfaceType = DeviceExtension->AdapterInterfaceType;
|
|
|
|
ResList->BusNumber = DeviceExtension->SystemIoBusNumber;
|
|
|
|
ResList->SlotNumber = DeviceExtension->SystemIoSlotNumber;
|
|
|
|
ResList->AlternativeLists = 1;
|
|
|
|
ResList->List[0].Version = 1;
|
|
|
|
ResList->List[0].Revision = 1;
|
|
|
|
ResList->List[0].Count = AccessRangeCount;
|
|
|
|
|
|
|
|
CurrentDescriptor = ResList->List[0].Descriptors;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < AccessRangeCount; i++)
|
|
|
|
{
|
|
|
|
/* This is a required resource */
|
|
|
|
CurrentDescriptor->Option = 0;
|
|
|
|
|
|
|
|
if (AccessRanges[i].RangeInIoSpace)
|
|
|
|
CurrentDescriptor->Type = CmResourceTypePort;
|
|
|
|
else
|
|
|
|
CurrentDescriptor->Type = CmResourceTypeMemory;
|
|
|
|
|
|
|
|
CurrentDescriptor->ShareDisposition =
|
|
|
|
(AccessRanges[i].RangeShareable ? CmResourceShareShared : CmResourceShareDeviceExclusive);
|
|
|
|
|
|
|
|
CurrentDescriptor->Flags = 0;
|
|
|
|
|
|
|
|
if (CurrentDescriptor->Type == CmResourceTypePort)
|
|
|
|
{
|
|
|
|
CurrentDescriptor->u.Port.Length = AccessRanges[i].RangeLength;
|
|
|
|
CurrentDescriptor->u.Port.MinimumAddress =
|
|
|
|
CurrentDescriptor->u.Port.MaximumAddress = AccessRanges[i].RangeStart;
|
|
|
|
CurrentDescriptor->u.Port.Alignment = 1;
|
|
|
|
if (AccessRanges[i].RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
|
|
|
|
CurrentDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
|
|
|
|
if (AccessRanges[i].RangePassive & VIDEO_RANGE_10_BIT_DECODE)
|
|
|
|
CurrentDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentDescriptor->u.Memory.Length = AccessRanges[i].RangeLength;
|
|
|
|
CurrentDescriptor->u.Memory.MinimumAddress =
|
|
|
|
CurrentDescriptor->u.Memory.MaximumAddress = AccessRanges[i].RangeStart;
|
|
|
|
CurrentDescriptor->u.Memory.Alignment = 1;
|
|
|
|
CurrentDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentDescriptor++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)ResList;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
NTSTATUS NTAPI
|
2005-01-07 01:03:34 +00:00
|
|
|
IntVideoPortMapPhysicalMemory(
|
|
|
|
IN HANDLE Process,
|
|
|
|
IN PHYSICAL_ADDRESS PhysicalAddress,
|
|
|
|
IN ULONG SizeInBytes,
|
|
|
|
IN ULONG Protect,
|
|
|
|
IN OUT PVOID *VirtualAddress OPTIONAL)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjAttribs;
|
|
|
|
UNICODE_STRING UnicodeString;
|
|
|
|
HANDLE hMemObj;
|
|
|
|
NTSTATUS Status;
|
|
|
|
SIZE_T Size;
|
|
|
|
|
|
|
|
/* Initialize object attribs */
|
|
|
|
RtlInitUnicodeString(&UnicodeString, L"\\Device\\PhysicalMemory");
|
|
|
|
InitializeObjectAttributes(&ObjAttribs,
|
|
|
|
&UnicodeString,
|
2005-06-03 16:56:27 +00:00
|
|
|
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
2005-01-07 01:03:34 +00:00
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
/* Open physical memory section */
|
|
|
|
Status = ZwOpenSection(&hMemObj, SECTION_ALL_ACCESS, &ObjAttribs);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
WARN_(VIDEOPRT, "ZwOpenSection() failed! (0x%x)\n", Status);
|
2005-01-07 01:03:34 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Map view of section */
|
|
|
|
Size = SizeInBytes;
|
|
|
|
Status = ZwMapViewOfSection(hMemObj,
|
|
|
|
Process,
|
|
|
|
VirtualAddress,
|
|
|
|
0,
|
|
|
|
Size,
|
|
|
|
(PLARGE_INTEGER)(&PhysicalAddress),
|
|
|
|
&Size,
|
|
|
|
ViewUnmap,
|
|
|
|
0,
|
|
|
|
Protect);
|
|
|
|
ZwClose(hMemObj);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
WARN_(VIDEOPRT, "ZwMapViewOfSection() failed! (0x%x)\n", Status);
|
2005-01-07 01:03:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
PVOID NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
IntVideoPortMapMemory(
|
|
|
|
IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension,
|
|
|
|
IN PHYSICAL_ADDRESS IoAddress,
|
|
|
|
IN ULONG NumberOfUchars,
|
2011-06-25 14:10:19 +00:00
|
|
|
IN ULONG InIoSpace,
|
2005-02-05 00:09:56 +00:00
|
|
|
IN HANDLE ProcessHandle,
|
2004-03-19 20:58:32 +00:00
|
|
|
OUT VP_STATUS *Status)
|
|
|
|
{
|
|
|
|
PHYSICAL_ADDRESS TranslatedAddress;
|
2005-01-07 01:03:34 +00:00
|
|
|
PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
|
2004-03-19 20:58:32 +00:00
|
|
|
ULONG AddressSpace;
|
|
|
|
PVOID MappedAddress;
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
INFO_(VIDEOPRT, "- IoAddress: %lx\n", IoAddress.u.LowPart);
|
|
|
|
INFO_(VIDEOPRT, "- NumberOfUchars: %lx\n", NumberOfUchars);
|
|
|
|
INFO_(VIDEOPRT, "- InIoSpace: %x\n", InIoSpace);
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
InIoSpace &= ~VIDEO_MEMORY_SPACE_DENSE;
|
|
|
|
if ((InIoSpace & VIDEO_MEMORY_SPACE_P6CACHE) != 0)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
INFO_(VIDEOPRT, "VIDEO_MEMORY_SPACE_P6CACHE not supported, turning off\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
InIoSpace &= ~VIDEO_MEMORY_SPACE_P6CACHE;
|
|
|
|
}
|
|
|
|
|
2005-02-05 00:09:56 +00:00
|
|
|
if (ProcessHandle != NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
INFO_(VIDEOPRT, "ProcessHandle is not NULL (0x%x) but InIoSpace does not have "
|
2005-02-05 00:09:56 +00:00
|
|
|
"VIDEO_MEMORY_SPACE_USER_MODE set! Setting "
|
|
|
|
"VIDEO_MEMORY_SPACE_USER_MODE.\n",
|
|
|
|
ProcessHandle);
|
|
|
|
InIoSpace |= VIDEO_MEMORY_SPACE_USER_MODE;
|
|
|
|
}
|
|
|
|
else if (ProcessHandle == NULL && (InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
INFO_(VIDEOPRT, "ProcessHandle is NULL (0x%x) but InIoSpace does have "
|
2005-02-05 00:09:56 +00:00
|
|
|
"VIDEO_MEMORY_SPACE_USER_MODE set! Setting ProcessHandle "
|
|
|
|
"to NtCurrentProcess()\n",
|
|
|
|
ProcessHandle);
|
|
|
|
ProcessHandle = NtCurrentProcess();
|
|
|
|
}
|
|
|
|
|
2005-01-07 01:03:34 +00:00
|
|
|
if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0 &&
|
|
|
|
!IsListEmpty(&DeviceExtension->AddressMappingListHead))
|
2004-03-19 20:58:32 +00:00
|
|
|
{
|
|
|
|
Entry = DeviceExtension->AddressMappingListHead.Flink;
|
|
|
|
while (Entry != &DeviceExtension->AddressMappingListHead)
|
|
|
|
{
|
|
|
|
AddressMapping = CONTAINING_RECORD(
|
|
|
|
Entry,
|
|
|
|
VIDEO_PORT_ADDRESS_MAPPING,
|
|
|
|
List);
|
|
|
|
if (IoAddress.QuadPart == AddressMapping->IoAddress.QuadPart &&
|
|
|
|
NumberOfUchars <= AddressMapping->NumberOfUchars)
|
|
|
|
{
|
2004-12-18 22:14:39 +00:00
|
|
|
{
|
|
|
|
AddressMapping->MappingCount++;
|
|
|
|
if (Status)
|
|
|
|
*Status = NO_ERROR;
|
|
|
|
return AddressMapping->MappedAddress;
|
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressSpace = (ULONG)InIoSpace;
|
2004-12-18 22:14:39 +00:00
|
|
|
AddressSpace &= ~VIDEO_MEMORY_SPACE_USER_MODE;
|
2004-03-19 20:58:32 +00:00
|
|
|
if (HalTranslateBusAddress(
|
|
|
|
DeviceExtension->AdapterInterfaceType,
|
|
|
|
DeviceExtension->SystemIoBusNumber,
|
|
|
|
IoAddress,
|
|
|
|
&AddressSpace,
|
|
|
|
&TranslatedAddress) == FALSE)
|
|
|
|
{
|
|
|
|
if (Status)
|
|
|
|
*Status = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* I/O space */
|
|
|
|
if (AddressSpace != 0)
|
|
|
|
{
|
|
|
|
ASSERT(0 == TranslatedAddress.u.HighPart);
|
|
|
|
if (Status)
|
|
|
|
*Status = NO_ERROR;
|
|
|
|
|
2010-03-25 05:03:29 +00:00
|
|
|
return (PVOID)(ULONG_PTR)TranslatedAddress.u.LowPart;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
2004-12-18 22:14:39 +00:00
|
|
|
/* user space */
|
|
|
|
if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) != 0)
|
|
|
|
{
|
|
|
|
NTSTATUS NtStatus;
|
|
|
|
MappedAddress = NULL;
|
2005-02-05 00:09:56 +00:00
|
|
|
NtStatus = IntVideoPortMapPhysicalMemory(ProcessHandle,
|
2005-01-07 01:03:34 +00:00
|
|
|
TranslatedAddress,
|
|
|
|
NumberOfUchars,
|
|
|
|
PAGE_READWRITE/* | PAGE_WRITECOMBINE*/,
|
|
|
|
&MappedAddress);
|
2004-12-18 22:14:39 +00:00
|
|
|
if (!NT_SUCCESS(NtStatus))
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
WARN_(VIDEOPRT, "IntVideoPortMapPhysicalMemory() failed! (0x%x)\n", NtStatus);
|
2004-12-18 22:14:39 +00:00
|
|
|
if (Status)
|
|
|
|
*Status = NO_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-12-28 14:47:03 +00:00
|
|
|
INFO_(VIDEOPRT, "Mapped user address = 0x%08x\n", MappedAddress);
|
2004-12-18 22:14:39 +00:00
|
|
|
}
|
|
|
|
else /* kernel space */
|
2004-03-19 20:58:32 +00:00
|
|
|
{
|
2004-12-18 22:14:39 +00:00
|
|
|
MappedAddress = MmMapIoSpace(
|
|
|
|
TranslatedAddress,
|
|
|
|
NumberOfUchars,
|
|
|
|
MmNonCached);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MappedAddress != NULL)
|
|
|
|
{
|
2004-03-19 20:58:32 +00:00
|
|
|
if (Status)
|
|
|
|
{
|
|
|
|
*Status = NO_ERROR;
|
|
|
|
}
|
2005-01-07 01:03:34 +00:00
|
|
|
if ((InIoSpace & VIDEO_MEMORY_SPACE_USER_MODE) == 0)
|
2004-12-18 22:14:39 +00:00
|
|
|
{
|
|
|
|
AddressMapping = ExAllocatePoolWithTag(
|
|
|
|
PagedPool,
|
|
|
|
sizeof(VIDEO_PORT_ADDRESS_MAPPING),
|
|
|
|
TAG_VIDEO_PORT);
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2004-12-18 22:14:39 +00:00
|
|
|
if (AddressMapping == NULL)
|
|
|
|
return MappedAddress;
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2004-12-18 22:14:39 +00:00
|
|
|
RtlZeroMemory(AddressMapping, sizeof(VIDEO_PORT_ADDRESS_MAPPING));
|
|
|
|
AddressMapping->NumberOfUchars = NumberOfUchars;
|
|
|
|
AddressMapping->IoAddress = IoAddress;
|
|
|
|
AddressMapping->SystemIoBusNumber = DeviceExtension->SystemIoBusNumber;
|
|
|
|
AddressMapping->MappedAddress = MappedAddress;
|
|
|
|
AddressMapping->MappingCount = 1;
|
|
|
|
InsertHeadList(
|
|
|
|
&DeviceExtension->AddressMappingListHead,
|
|
|
|
&AddressMapping->List);
|
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
return MappedAddress;
|
|
|
|
}
|
|
|
|
|
2004-12-18 22:14:39 +00:00
|
|
|
if (Status)
|
|
|
|
*Status = NO_ERROR;
|
|
|
|
|
|
|
|
return NULL;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VOID NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
IntVideoPortUnmapMemory(
|
|
|
|
IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension,
|
|
|
|
IN PVOID MappedAddress)
|
|
|
|
{
|
|
|
|
PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
|
|
|
|
PLIST_ENTRY Entry;
|
2005-01-07 01:03:34 +00:00
|
|
|
NTSTATUS Status;
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
Entry = DeviceExtension->AddressMappingListHead.Flink;
|
|
|
|
while (Entry != &DeviceExtension->AddressMappingListHead)
|
|
|
|
{
|
|
|
|
AddressMapping = CONTAINING_RECORD(
|
|
|
|
Entry,
|
|
|
|
VIDEO_PORT_ADDRESS_MAPPING,
|
|
|
|
List);
|
2005-01-07 01:03:34 +00:00
|
|
|
if (AddressMapping->MappedAddress == MappedAddress)
|
2004-03-19 20:58:32 +00:00
|
|
|
{
|
2004-12-18 22:14:39 +00:00
|
|
|
ASSERT(AddressMapping->MappingCount > 0);
|
2004-03-19 20:58:32 +00:00
|
|
|
AddressMapping->MappingCount--;
|
|
|
|
if (AddressMapping->MappingCount == 0)
|
|
|
|
{
|
|
|
|
MmUnmapIoSpace(
|
|
|
|
AddressMapping->MappedAddress,
|
|
|
|
AddressMapping->NumberOfUchars);
|
2005-01-07 01:03:34 +00:00
|
|
|
RemoveEntryList(Entry);
|
|
|
|
ExFreePool(AddressMapping);
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
2004-12-18 22:14:39 +00:00
|
|
|
return;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
2005-01-07 01:03:34 +00:00
|
|
|
|
|
|
|
/* If there was no kernelmode mapping for the given address found we assume
|
|
|
|
* that the given address is a usermode mapping and try to unmap it.
|
2005-02-05 00:09:56 +00:00
|
|
|
*
|
|
|
|
* FIXME: Is it ok to use NtCurrentProcess?
|
2005-01-07 01:03:34 +00:00
|
|
|
*/
|
|
|
|
Status = ZwUnmapViewOfSection(NtCurrentProcess(), MappedAddress);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2010-03-25 05:03:29 +00:00
|
|
|
WARN_(VIDEOPRT, "Warning: Mapping for address 0x%p not found!\n", MappedAddress);
|
2005-01-07 01:03:34 +00:00
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
PVOID NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortGetDeviceBase(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN PHYSICAL_ADDRESS IoAddress,
|
|
|
|
IN ULONG NumberOfUchars,
|
|
|
|
IN UCHAR InIoSpace)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortGetDeviceBase\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
return IntVideoPortMapMemory(
|
|
|
|
VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
|
|
|
|
IoAddress,
|
|
|
|
NumberOfUchars,
|
|
|
|
InIoSpace,
|
2005-02-05 00:09:56 +00:00
|
|
|
NULL,
|
2004-03-19 20:58:32 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VOID NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortFreeDeviceBase(
|
2005-05-08 02:16:32 +00:00
|
|
|
IN PVOID HwDeviceExtension,
|
2004-03-19 20:58:32 +00:00
|
|
|
IN PVOID MappedAddress)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
IntVideoPortUnmapMemory(
|
|
|
|
VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
|
|
|
|
MappedAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
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)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortMapBankedMemory\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
UNIMPLEMENTED;
|
2008-11-27 20:05:12 +00:00
|
|
|
return ERROR_INVALID_FUNCTION;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortMapMemory(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN PHYSICAL_ADDRESS PhysicalAddress,
|
|
|
|
IN PULONG Length,
|
|
|
|
IN PULONG InIoSpace,
|
|
|
|
OUT PVOID *VirtualAddress)
|
|
|
|
{
|
|
|
|
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortMapMemory\n");
|
|
|
|
INFO_(VIDEOPRT, "- *VirtualAddress: 0x%x\n", *VirtualAddress);
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
|
|
|
|
*VirtualAddress = IntVideoPortMapMemory(
|
|
|
|
DeviceExtension,
|
|
|
|
PhysicalAddress,
|
|
|
|
*Length,
|
|
|
|
*InIoSpace,
|
2005-02-05 00:09:56 +00:00
|
|
|
(HANDLE)*VirtualAddress,
|
2004-03-19 20:58:32 +00:00
|
|
|
&Status);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortUnmapMemory(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN PVOID VirtualAddress,
|
|
|
|
IN HANDLE ProcessHandle)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortFreeDeviceBase\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
IntVideoPortUnmapMemory(
|
|
|
|
VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
|
|
|
|
VirtualAddress);
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortGetAccessRanges(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN ULONG NumRequestedResources,
|
|
|
|
IN PIO_RESOURCE_DESCRIPTOR RequestedResources OPTIONAL,
|
|
|
|
IN ULONG NumAccessRanges,
|
|
|
|
IN PVIDEO_ACCESS_RANGE AccessRanges,
|
|
|
|
IN PVOID VendorId,
|
|
|
|
IN PVOID DeviceId,
|
2011-10-22 23:32:51 +00:00
|
|
|
OUT PULONG Slot)
|
2004-03-19 20:58:32 +00:00
|
|
|
{
|
2011-10-23 03:55:35 +00:00
|
|
|
PCI_SLOT_NUMBER PciSlotNumber;
|
|
|
|
ULONG DeviceNumber;
|
|
|
|
ULONG FunctionNumber;
|
|
|
|
PCI_COMMON_CONFIG Config;
|
|
|
|
PCM_RESOURCE_LIST AllocatedResources;
|
|
|
|
NTSTATUS Status;
|
2012-03-12 01:38:21 +00:00
|
|
|
UINT AssignedCount = 0;
|
2011-10-23 03:55:35 +00:00
|
|
|
CM_FULL_RESOURCE_DESCRIPTOR *FullList;
|
|
|
|
CM_PARTIAL_RESOURCE_DESCRIPTOR *Descriptor;
|
|
|
|
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
|
|
|
|
USHORT VendorIdToFind;
|
|
|
|
USHORT DeviceIdToFind;
|
|
|
|
ULONG ReturnedLength;
|
|
|
|
PVIDEO_ACCESS_RANGE LegacyAccessRanges;
|
|
|
|
ULONG LegacyAccessRangeCount;
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
ULONG ListSize;
|
|
|
|
PIO_RESOURCE_REQUIREMENTS_LIST ResReqList;
|
|
|
|
BOOLEAN DeviceAndVendorFound = FALSE;
|
|
|
|
|
2012-03-11 20:24:29 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortGetAccessRanges(%d, %p, %d, %p)\n", NumRequestedResources, RequestedResources, NumAccessRanges, AccessRanges);
|
2011-10-23 03:55:35 +00:00
|
|
|
|
|
|
|
DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
|
|
|
|
DriverObject = DeviceExtension->DriverObject;
|
|
|
|
DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
|
2011-10-22 23:32:51 +00:00
|
|
|
|
2011-10-23 03:55:35 +00:00
|
|
|
if (NumRequestedResources == 0)
|
|
|
|
{
|
|
|
|
AllocatedResources = DeviceExtension->AllocatedResources;
|
|
|
|
if (AllocatedResources == NULL &&
|
|
|
|
DeviceExtension->AdapterInterfaceType == PCIBus)
|
|
|
|
{
|
|
|
|
if (DeviceExtension->PhysicalDeviceObject != NULL)
|
2011-10-22 23:32:51 +00:00
|
|
|
{
|
2011-10-23 03:55:35 +00:00
|
|
|
PciSlotNumber.u.AsULONG = DeviceExtension->SystemIoSlotNumber;
|
|
|
|
|
|
|
|
ReturnedLength = HalGetBusData(PCIConfiguration,
|
|
|
|
DeviceExtension->SystemIoBusNumber,
|
|
|
|
PciSlotNumber.u.AsULONG,
|
|
|
|
&Config,
|
|
|
|
sizeof(PCI_COMMON_CONFIG));
|
|
|
|
|
|
|
|
if (ReturnedLength != sizeof(PCI_COMMON_CONFIG))
|
|
|
|
{
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
2011-10-22 23:32:51 +00:00
|
|
|
}
|
2011-10-23 03:55:35 +00:00
|
|
|
else
|
2005-01-07 01:03:34 +00:00
|
|
|
{
|
2011-10-23 03:55:35 +00:00
|
|
|
VendorIdToFind = VendorId != NULL ? *(PUSHORT)VendorId : 0;
|
|
|
|
DeviceIdToFind = DeviceId != NULL ? *(PUSHORT)DeviceId : 0;
|
|
|
|
|
|
|
|
if (VendorIdToFind == 0 && DeviceIdToFind == 0)
|
|
|
|
{
|
|
|
|
/* We're screwed */
|
|
|
|
return ERROR_DEV_NOT_EXIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
INFO_(VIDEOPRT, "Looking for VendorId 0x%04x DeviceId 0x%04x\n",
|
|
|
|
VendorIdToFind, DeviceIdToFind);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search for the device id and vendor id on this bus.
|
|
|
|
*/
|
2019-08-30 20:18:06 +00:00
|
|
|
PciSlotNumber.u.bits.Reserved = 0;
|
2011-10-23 03:55:35 +00:00
|
|
|
for (DeviceNumber = 0; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
|
|
|
|
{
|
|
|
|
PciSlotNumber.u.bits.DeviceNumber = DeviceNumber;
|
|
|
|
for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
|
|
|
|
{
|
|
|
|
INFO_(VIDEOPRT, "- Function number: %d\n", FunctionNumber);
|
|
|
|
PciSlotNumber.u.bits.FunctionNumber = FunctionNumber;
|
|
|
|
ReturnedLength = HalGetBusData(PCIConfiguration,
|
|
|
|
DeviceExtension->SystemIoBusNumber,
|
|
|
|
PciSlotNumber.u.AsULONG,
|
|
|
|
&Config,
|
|
|
|
sizeof(PCI_COMMON_CONFIG));
|
|
|
|
INFO_(VIDEOPRT, "- Length of data: %x\n", ReturnedLength);
|
|
|
|
if (ReturnedLength == sizeof(PCI_COMMON_CONFIG))
|
|
|
|
{
|
|
|
|
INFO_(VIDEOPRT, "- Slot 0x%02x (Device %d Function %d) VendorId 0x%04x "
|
|
|
|
"DeviceId 0x%04x\n",
|
|
|
|
PciSlotNumber.u.AsULONG,
|
|
|
|
PciSlotNumber.u.bits.DeviceNumber,
|
|
|
|
PciSlotNumber.u.bits.FunctionNumber,
|
|
|
|
Config.VendorID,
|
|
|
|
Config.DeviceID);
|
|
|
|
|
|
|
|
if ((VendorIdToFind == 0 || Config.VendorID == VendorIdToFind) &&
|
|
|
|
(DeviceIdToFind == 0 || Config.DeviceID == DeviceIdToFind))
|
|
|
|
{
|
|
|
|
DeviceAndVendorFound = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (DeviceAndVendorFound) break;
|
|
|
|
}
|
|
|
|
if (FunctionNumber == PCI_MAX_FUNCTION)
|
|
|
|
{
|
|
|
|
WARN_(VIDEOPRT, "Didn't find device.\n");
|
|
|
|
return ERROR_DEV_NOT_EXIST;
|
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
2011-10-23 03:55:35 +00:00
|
|
|
|
|
|
|
Status = HalAssignSlotResources(&DeviceExtension->RegistryPath,
|
|
|
|
NULL,
|
|
|
|
DeviceExtension->DriverObject,
|
|
|
|
DeviceExtension->DriverObject->DeviceObject,
|
|
|
|
DeviceExtension->AdapterInterfaceType,
|
|
|
|
DeviceExtension->SystemIoBusNumber,
|
|
|
|
PciSlotNumber.u.AsULONG,
|
|
|
|
&AllocatedResources);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2005-01-07 01:03:34 +00:00
|
|
|
{
|
2011-10-23 03:55:35 +00:00
|
|
|
WARN_(VIDEOPRT, "HalAssignSlotResources failed with status %x.\n",Status);
|
|
|
|
return Status;
|
2005-01-07 01:03:34 +00:00
|
|
|
}
|
2011-10-23 03:55:35 +00:00
|
|
|
DeviceExtension->AllocatedResources = AllocatedResources;
|
2011-10-23 04:04:17 +00:00
|
|
|
DeviceExtension->SystemIoSlotNumber = PciSlotNumber.u.AsULONG;
|
2012-03-12 01:38:21 +00:00
|
|
|
|
|
|
|
/* Add legacy resources to the resources from HAL */
|
|
|
|
Status = IntVideoPortGetLegacyResources(DriverExtension, DeviceExtension,
|
|
|
|
&LegacyAccessRanges, &LegacyAccessRangeCount);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return ERROR_DEV_NOT_EXIST;
|
|
|
|
|
|
|
|
if (NumAccessRanges < LegacyAccessRangeCount)
|
|
|
|
{
|
|
|
|
ERR_(VIDEOPRT, "Too many legacy access ranges found\n");
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlCopyMemory(AccessRanges, LegacyAccessRanges, LegacyAccessRangeCount * sizeof(VIDEO_ACCESS_RANGE));
|
|
|
|
AssignedCount = LegacyAccessRangeCount;
|
2011-10-23 03:55:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + (NumRequestedResources - 1) * sizeof(IO_RESOURCE_DESCRIPTOR);
|
|
|
|
ResReqList = ExAllocatePool(NonPagedPool, ListSize);
|
|
|
|
if (!ResReqList) return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
ResReqList->ListSize = ListSize;
|
|
|
|
ResReqList->InterfaceType = DeviceExtension->AdapterInterfaceType;
|
|
|
|
ResReqList->BusNumber = DeviceExtension->SystemIoBusNumber;
|
|
|
|
ResReqList->SlotNumber = DeviceExtension->SystemIoSlotNumber;
|
|
|
|
ResReqList->AlternativeLists = 1;
|
|
|
|
ResReqList->List[0].Version = 1;
|
|
|
|
ResReqList->List[0].Revision = 1;
|
|
|
|
ResReqList->List[0].Count = NumRequestedResources;
|
|
|
|
|
|
|
|
/* Copy in the caller's resource list */
|
|
|
|
RtlCopyMemory(ResReqList->List[0].Descriptors,
|
|
|
|
RequestedResources,
|
|
|
|
NumRequestedResources * sizeof(IO_RESOURCE_DESCRIPTOR));
|
|
|
|
|
|
|
|
Status = IoAssignResources(&DeviceExtension->RegistryPath,
|
|
|
|
NULL,
|
|
|
|
DeviceExtension->DriverObject,
|
|
|
|
DeviceExtension->PhysicalDeviceObject ?
|
|
|
|
DeviceExtension->PhysicalDeviceObject :
|
|
|
|
DeviceExtension->DriverObject->DeviceObject,
|
|
|
|
ResReqList,
|
|
|
|
&AllocatedResources);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2005-01-07 01:03:34 +00:00
|
|
|
return Status;
|
2011-10-23 03:55:35 +00:00
|
|
|
|
|
|
|
if (!DeviceExtension->AllocatedResources)
|
|
|
|
DeviceExtension->AllocatedResources = AllocatedResources;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AllocatedResources == NULL)
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
/* Return the slot number if the caller wants it */
|
|
|
|
if (Slot != NULL) *Slot = DeviceExtension->SystemIoBusNumber;
|
2012-03-12 01:38:21 +00:00
|
|
|
|
2015-10-17 19:31:46 +00:00
|
|
|
FullList = AllocatedResources->List;
|
|
|
|
ASSERT(AllocatedResources->Count == 1);
|
|
|
|
INFO_(VIDEOPRT, "InterfaceType %u BusNumber List %u Device BusNumber %u Version %u Revision %u\n",
|
|
|
|
FullList->InterfaceType, FullList->BusNumber, DeviceExtension->SystemIoBusNumber, FullList->PartialResourceList.Version, FullList->PartialResourceList.Revision);
|
|
|
|
|
|
|
|
ASSERT(FullList->InterfaceType == PCIBus);
|
|
|
|
ASSERT(FullList->BusNumber == DeviceExtension->SystemIoBusNumber);
|
|
|
|
ASSERT(1 == FullList->PartialResourceList.Version);
|
|
|
|
ASSERT(1 == FullList->PartialResourceList.Revision);
|
|
|
|
for (Descriptor = FullList->PartialResourceList.PartialDescriptors;
|
|
|
|
Descriptor < FullList->PartialResourceList.PartialDescriptors + FullList->PartialResourceList.Count;
|
|
|
|
Descriptor++)
|
2011-10-23 03:55:35 +00:00
|
|
|
{
|
2015-10-17 19:31:46 +00:00
|
|
|
if ((Descriptor->Type == CmResourceTypeMemory ||
|
|
|
|
Descriptor->Type == CmResourceTypePort) &&
|
|
|
|
AssignedCount >= NumAccessRanges)
|
2011-10-23 03:55:35 +00:00
|
|
|
{
|
2015-10-17 19:31:46 +00:00
|
|
|
ERR_(VIDEOPRT, "Too many access ranges found\n");
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
2018-01-28 22:44:28 +00:00
|
|
|
else if (Descriptor->Type == CmResourceTypeMemory)
|
2015-10-17 19:31:46 +00:00
|
|
|
{
|
|
|
|
INFO_(VIDEOPRT, "Memory range starting at 0x%08x length 0x%08x\n",
|
|
|
|
Descriptor->u.Memory.Start.u.LowPart, Descriptor->u.Memory.Length);
|
|
|
|
AccessRanges[AssignedCount].RangeStart = Descriptor->u.Memory.Start;
|
|
|
|
AccessRanges[AssignedCount].RangeLength = Descriptor->u.Memory.Length;
|
|
|
|
AccessRanges[AssignedCount].RangeInIoSpace = 0;
|
|
|
|
AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
|
|
|
|
AccessRanges[AssignedCount].RangeShareable =
|
|
|
|
(Descriptor->ShareDisposition == CmResourceShareShared);
|
|
|
|
AccessRanges[AssignedCount].RangePassive = 0;
|
|
|
|
AssignedCount++;
|
|
|
|
}
|
|
|
|
else if (Descriptor->Type == CmResourceTypePort)
|
|
|
|
{
|
|
|
|
INFO_(VIDEOPRT, "Port range starting at 0x%04x length %d\n",
|
|
|
|
Descriptor->u.Port.Start.u.LowPart, Descriptor->u.Port.Length);
|
|
|
|
AccessRanges[AssignedCount].RangeStart = Descriptor->u.Port.Start;
|
|
|
|
AccessRanges[AssignedCount].RangeLength = Descriptor->u.Port.Length;
|
|
|
|
AccessRanges[AssignedCount].RangeInIoSpace = 1;
|
|
|
|
AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
|
|
|
|
AccessRanges[AssignedCount].RangeShareable =
|
|
|
|
(Descriptor->ShareDisposition == CmResourceShareShared);
|
|
|
|
AccessRanges[AssignedCount].RangePassive = 0;
|
|
|
|
if (Descriptor->Flags & CM_RESOURCE_PORT_10_BIT_DECODE)
|
|
|
|
AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_10_BIT_DECODE;
|
|
|
|
if (Descriptor->Flags & CM_RESOURCE_PORT_PASSIVE_DECODE)
|
|
|
|
AccessRanges[AssignedCount].RangePassive |= VIDEO_RANGE_PASSIVE_DECODE;
|
|
|
|
AssignedCount++;
|
|
|
|
}
|
|
|
|
else if (Descriptor->Type == CmResourceTypeInterrupt)
|
|
|
|
{
|
|
|
|
DeviceExtension->InterruptLevel = Descriptor->u.Interrupt.Level;
|
|
|
|
DeviceExtension->InterruptVector = Descriptor->u.Interrupt.Vector;
|
|
|
|
if (Descriptor->ShareDisposition == CmResourceShareShared)
|
|
|
|
DeviceExtension->InterruptShared = TRUE;
|
|
|
|
else
|
|
|
|
DeviceExtension->InterruptShared = FALSE;
|
2011-10-23 03:55:35 +00:00
|
|
|
}
|
2018-01-28 22:44:28 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
2011-10-23 03:55:35 +00:00
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
|
2015-10-17 19:31:46 +00:00
|
|
|
return NO_ERROR;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-08-03 14:46:12 +00:00
|
|
|
* @implemented
|
2004-03-19 20:58:32 +00:00
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortVerifyAccessRanges(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN ULONG NumAccessRanges,
|
|
|
|
IN PVIDEO_ACCESS_RANGE AccessRanges)
|
|
|
|
{
|
2005-08-03 14:46:12 +00:00
|
|
|
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
BOOLEAN ConflictDetected;
|
|
|
|
ULONG i;
|
|
|
|
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
|
|
|
|
PCM_RESOURCE_LIST ResourceList;
|
|
|
|
ULONG ResourceListSize;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortVerifyAccessRanges\n");
|
2005-08-03 14:46:12 +00:00
|
|
|
|
|
|
|
DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-08-03 14:46:12 +00:00
|
|
|
/* Create the resource list */
|
|
|
|
ResourceListSize = sizeof(CM_RESOURCE_LIST)
|
|
|
|
+ (NumAccessRanges - 1) * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
|
|
|
|
ResourceList = ExAllocatePool(PagedPool, ResourceListSize);
|
|
|
|
if (!ResourceList)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
WARN_(VIDEOPRT, "ExAllocatePool() failed\n");
|
2018-01-28 22:44:28 +00:00
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
2005-08-03 14:46:12 +00:00
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-08-03 14:46:12 +00:00
|
|
|
/* Fill resource list */
|
|
|
|
ResourceList->Count = 1;
|
|
|
|
ResourceList->List[0].InterfaceType = DeviceExtension->AdapterInterfaceType;
|
|
|
|
ResourceList->List[0].BusNumber = DeviceExtension->SystemIoBusNumber;
|
|
|
|
ResourceList->List[0].PartialResourceList.Version = 1;
|
|
|
|
ResourceList->List[0].PartialResourceList.Revision = 1;
|
|
|
|
ResourceList->List[0].PartialResourceList.Count = NumAccessRanges;
|
|
|
|
for (i = 0; i < NumAccessRanges; i++, AccessRanges++)
|
|
|
|
{
|
|
|
|
PartialDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[i];
|
|
|
|
if (AccessRanges->RangeInIoSpace)
|
|
|
|
{
|
|
|
|
PartialDescriptor->Type = CmResourceTypePort;
|
|
|
|
PartialDescriptor->u.Port.Start = AccessRanges->RangeStart;
|
|
|
|
PartialDescriptor->u.Port.Length = AccessRanges->RangeLength;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PartialDescriptor->Type = CmResourceTypeMemory;
|
|
|
|
PartialDescriptor->u.Memory.Start = AccessRanges->RangeStart;
|
|
|
|
PartialDescriptor->u.Memory.Length = AccessRanges->RangeLength;
|
|
|
|
}
|
|
|
|
if (AccessRanges->RangeShareable)
|
|
|
|
PartialDescriptor->ShareDisposition = CmResourceShareShared;
|
|
|
|
else
|
|
|
|
PartialDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
|
|
|
|
PartialDescriptor->Flags = 0;
|
|
|
|
if (AccessRanges->RangePassive & VIDEO_RANGE_PASSIVE_DECODE)
|
|
|
|
PartialDescriptor->Flags |= CM_RESOURCE_PORT_PASSIVE_DECODE;
|
|
|
|
if (AccessRanges->RangePassive & VIDEO_RANGE_10_BIT_DECODE)
|
|
|
|
PartialDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-08-03 14:46:12 +00:00
|
|
|
/* Try to acquire all resource ranges */
|
|
|
|
Status = IoReportResourceForDetection(
|
|
|
|
DeviceExtension->DriverObject,
|
|
|
|
NULL, 0, /* Driver List */
|
|
|
|
DeviceExtension->PhysicalDeviceObject,
|
|
|
|
ResourceList, ResourceListSize,
|
|
|
|
&ConflictDetected);
|
|
|
|
ExFreePool(ResourceList);
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-08-03 14:46:12 +00:00
|
|
|
if (!NT_SUCCESS(Status) || ConflictDetected)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
else
|
|
|
|
return NO_ERROR;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortGetDeviceData(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN VIDEO_DEVICE_DATA_TYPE DeviceDataType,
|
|
|
|
IN PMINIPORT_QUERY_DEVICE_ROUTINE CallbackRoutine,
|
|
|
|
IN PVOID Context)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortGetDeviceData\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
UNIMPLEMENTED;
|
2008-11-27 20:05:12 +00:00
|
|
|
return ERROR_INVALID_FUNCTION;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
PVOID NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortAllocatePool(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN VP_POOL_TYPE PoolType,
|
|
|
|
IN SIZE_T NumberOfBytes,
|
|
|
|
IN ULONG Tag)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortAllocatePool\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
return ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VOID NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortFreePool(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN PVOID Ptr)
|
|
|
|
{
|
|
|
|
ExFreePool(Ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortAllocateBuffer(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN ULONG Size,
|
|
|
|
OUT PVOID *Buffer)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortAllocateBuffer\n");
|
2007-12-27 18:30:36 +00:00
|
|
|
*Buffer = ExAllocatePoolWithTag ( PagedPool, Size, TAG_VIDEO_PORT_BUFFER ) ;
|
2004-03-19 20:58:32 +00:00
|
|
|
return *Buffer == NULL ? ERROR_NOT_ENOUGH_MEMORY : NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VOID NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortReleaseBuffer(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN PVOID Ptr)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortReleaseBuffer\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
ExFreePool(Ptr);
|
2005-05-08 02:16:32 +00:00
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
/*
|
2009-04-24 02:18:30 +00:00
|
|
|
* @implemented
|
2004-03-19 20:58:32 +00:00
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
PVOID NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortLockBuffer(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN PVOID BaseAddress,
|
|
|
|
IN ULONG Length,
|
|
|
|
IN VP_LOCK_OPERATION Operation)
|
|
|
|
{
|
2009-04-24 02:18:30 +00:00
|
|
|
PMDL Mdl;
|
|
|
|
|
|
|
|
Mdl = IoAllocateMdl(BaseAddress, Length, FALSE, FALSE, NULL);
|
|
|
|
if (!Mdl)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* FIXME use seh */
|
|
|
|
MmProbeAndLockPages(Mdl, KernelMode,Operation);
|
|
|
|
return Mdl;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-10-01 17:43:03 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
VideoPortLockPages(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN OUT PVIDEO_REQUEST_PACKET pVrp,
|
|
|
|
IN PEVENT pUEvent,
|
|
|
|
IN PEVENT pDisplayEvent,
|
|
|
|
IN DMA_FLAGS DmaFlags)
|
|
|
|
{
|
|
|
|
PVOID Buffer;
|
|
|
|
|
|
|
|
/* clear output buffer */
|
|
|
|
pVrp->OutputBuffer = NULL;
|
|
|
|
|
|
|
|
if (DmaFlags != VideoPortDmaInitOnly)
|
|
|
|
{
|
|
|
|
/* VideoPortKeepPagesLocked / VideoPortUnlockAfterDma is no-op */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lock the buffer */
|
|
|
|
Buffer = VideoPortLockBuffer(HwDeviceExtension, pVrp->InputBuffer, pVrp->InputBufferLength, IoModifyAccess);
|
|
|
|
|
|
|
|
if (Buffer)
|
|
|
|
{
|
|
|
|
/* store result buffer & length */
|
|
|
|
pVrp->OutputBuffer = Buffer;
|
|
|
|
pVrp->OutputBufferLength = pVrp->InputBufferLength;
|
|
|
|
|
|
|
|
/* operation succeeded */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* operation failed */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
2004-03-19 20:58:32 +00:00
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VOID NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortUnlockBuffer(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN PVOID Mdl)
|
|
|
|
{
|
2009-04-24 02:18:30 +00:00
|
|
|
if (Mdl)
|
|
|
|
{
|
|
|
|
MmUnlockPages((PMDL)Mdl);
|
|
|
|
IoFreeMdl(Mdl);
|
|
|
|
}
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
VP_STATUS NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortSetTrappedEmulatorPorts(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN ULONG NumAccessRanges,
|
|
|
|
IN PVIDEO_ACCESS_RANGE AccessRange)
|
|
|
|
{
|
2007-12-28 14:47:03 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
/* Should store the ranges in the device extension for use by ntvdm. */
|
|
|
|
return NO_ERROR;
|
2004-03-19 20:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
ULONG NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortGetBusData(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN BUS_DATA_TYPE BusDataType,
|
|
|
|
IN ULONG SlotNumber,
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
IN ULONG Offset,
|
|
|
|
IN ULONG Length)
|
|
|
|
{
|
|
|
|
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortGetBusData\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
|
|
|
|
|
|
|
|
if (BusDataType != Cmos)
|
|
|
|
{
|
|
|
|
/* Legacy vs. PnP behaviour */
|
|
|
|
if (DeviceExtension->PhysicalDeviceObject != NULL)
|
|
|
|
SlotNumber = DeviceExtension->SystemIoSlotNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HalGetBusDataByOffset(
|
2005-05-08 02:16:32 +00:00
|
|
|
BusDataType,
|
2004-03-19 20:58:32 +00:00
|
|
|
DeviceExtension->SystemIoBusNumber,
|
|
|
|
SlotNumber,
|
2005-05-08 02:16:32 +00:00
|
|
|
Buffer,
|
|
|
|
Offset,
|
2004-03-19 20:58:32 +00:00
|
|
|
Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
|
2005-08-24 21:29:24 +00:00
|
|
|
ULONG NTAPI
|
2004-03-19 20:58:32 +00:00
|
|
|
VideoPortSetBusData(
|
|
|
|
IN PVOID HwDeviceExtension,
|
|
|
|
IN BUS_DATA_TYPE BusDataType,
|
|
|
|
IN ULONG SlotNumber,
|
|
|
|
IN PVOID Buffer,
|
|
|
|
IN ULONG Offset,
|
|
|
|
IN ULONG Length)
|
|
|
|
{
|
|
|
|
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
|
2007-12-28 14:47:03 +00:00
|
|
|
TRACE_(VIDEOPRT, "VideoPortSetBusData\n");
|
2004-03-19 20:58:32 +00:00
|
|
|
|
|
|
|
DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2004-03-19 20:58:32 +00:00
|
|
|
if (BusDataType != Cmos)
|
|
|
|
{
|
|
|
|
/* Legacy vs. PnP behaviour */
|
|
|
|
if (DeviceExtension->PhysicalDeviceObject != NULL)
|
|
|
|
SlotNumber = DeviceExtension->SystemIoSlotNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HalSetBusDataByOffset(
|
|
|
|
BusDataType,
|
|
|
|
DeviceExtension->SystemIoBusNumber,
|
|
|
|
SlotNumber,
|
|
|
|
Buffer,
|
|
|
|
Offset,
|
|
|
|
Length);
|
|
|
|
}
|