- Added an implemention of VideoPortGetProcAddress

- ati2mtag calls VideoPortGetAccessRanges with *DeviceId == 0 so treat
that as matching an device id.
- Return STATUS_SUCCESS from VideoPortSetTrappedEmulatorPorts even though
the data is ignored.

svn path=/trunk/; revision=8560
This commit is contained in:
David Welch 2004-03-07 04:43:55 +00:00
parent ff81e5e1b0
commit 75860969fe
4 changed files with 141 additions and 31 deletions

View file

@ -18,7 +18,7 @@
* If not, write to the Free Software Foundation, * If not, write to the Free Software Foundation,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Id: videoprt.c,v 1.8 2004/03/06 22:25:22 dwelch Exp $ * $Id: videoprt.c,v 1.9 2004/03/07 04:43:55 dwelch Exp $
*/ */
#include "videoprt.h" #include "videoprt.h"
@ -35,6 +35,9 @@ VideoPortDeferredRoutine(
IN PVOID SystemArgument1, IN PVOID SystemArgument1,
IN PVOID SystemArgument2 IN PVOID SystemArgument2
); );
PVOID STDCALL
VideoPortGetProcAddress(IN PVOID HwDeviceExtension,
IN PUCHAR FunctionName);
// ------------------------------------------------------- Public Interface // ------------------------------------------------------- Public Interface
@ -199,7 +202,6 @@ VideoPortGetAccessRanges(IN PVOID HwDeviceExtension,
IN PULONG Slot) IN PULONG Slot)
{ {
PCI_SLOT_NUMBER PciSlotNumber; PCI_SLOT_NUMBER PciSlotNumber;
BOOLEAN FoundDevice;
ULONG FunctionNumber; ULONG FunctionNumber;
PCI_COMMON_CONFIG Config; PCI_COMMON_CONFIG Config;
PCM_RESOURCE_LIST AllocatedResources; PCM_RESOURCE_LIST AllocatedResources;
@ -208,49 +210,82 @@ VideoPortGetAccessRanges(IN PVOID HwDeviceExtension,
CM_FULL_RESOURCE_DESCRIPTOR *FullList; CM_FULL_RESOURCE_DESCRIPTOR *FullList;
CM_PARTIAL_RESOURCE_DESCRIPTOR *Descriptor; CM_PARTIAL_RESOURCE_DESCRIPTOR *Descriptor;
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension; PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
USHORT VendorIdToFind;
USHORT DeviceIdToFind;
DPRINT("VideoPortGetAccessRanges\n"); DPRINT("VideoPortGetAccessRanges\n");
if (VendorId != NULL)
{
VendorIdToFind = *(PUSHORT)VendorId;
}
else
{
VendorIdToFind = 0;
}
if (DeviceId != NULL)
{
DeviceIdToFind = *(PUSHORT)DeviceId;
}
else
{
DeviceIdToFind = 0;
}
DeviceExtension = CONTAINING_RECORD(HwDeviceExtension, DeviceExtension = CONTAINING_RECORD(HwDeviceExtension,
VIDEO_PORT_DEVICE_EXTENSION, VIDEO_PORT_DEVICE_EXTENSION,
MiniPortDeviceExtension); MiniPortDeviceExtension);
if (0 == NumRequestedResources && PCIBus == DeviceExtension->AdapterInterfaceType) if (0 == NumRequestedResources &&
PCIBus == DeviceExtension->AdapterInterfaceType)
{ {
if (DeviceId != NULL && VendorId != NULL) DPRINT("Looking for VendorId 0x%04x DeviceId 0x%04x\n",
{ VendorIdToFind, DeviceIdToFind);
DPRINT("Looking for VendorId 0x%04x DeviceId 0x%04x\n", (int)*((USHORT *) VendorId),
(int)*((USHORT *) DeviceId));
}
FoundDevice = FALSE;
PciSlotNumber.u.AsULONG = *Slot; PciSlotNumber.u.AsULONG = *Slot;
for (FunctionNumber = 0; ! FoundDevice && FunctionNumber < 8; FunctionNumber++)
/*
Search for the device id and vendor id on this bus.
*/
for (FunctionNumber = 0; FunctionNumber < 8; FunctionNumber++)
{ {
ULONG ReturnedLength;
PciSlotNumber.u.bits.FunctionNumber = FunctionNumber; PciSlotNumber.u.bits.FunctionNumber = FunctionNumber;
if (sizeof(PCI_COMMON_CONFIG) == ReturnedLength = HalGetBusData(PCIConfiguration,
HalGetBusDataByOffset(PCIConfiguration, DeviceExtension->SystemIoBusNumber, DeviceExtension->SystemIoBusNumber,
PciSlotNumber.u.AsULONG,&Config, 0, PciSlotNumber.u.AsULONG,
sizeof(PCI_COMMON_CONFIG))) &Config,
sizeof(PCI_COMMON_CONFIG));
if (sizeof(PCI_COMMON_CONFIG) == ReturnedLength)
{ {
if (DeviceId != NULL && VendorId != NULL) if (DeviceId != NULL && VendorId != NULL)
{ {
DPRINT("Slot 0x%02x (Device %d Function %d) VendorId 0x%04x DeviceId 0x%04x\n", DPRINT("Slot 0x%02x (Device %d Function %d) VendorId 0x%04x "
PciSlotNumber.u.AsULONG, PciSlotNumber.u.bits.DeviceNumber, "DeviceId 0x%04x\n",
PciSlotNumber.u.bits.FunctionNumber, Config.VendorID, Config.DeviceID); PciSlotNumber.u.AsULONG,
PciSlotNumber.u.bits.DeviceNumber,
PciSlotNumber.u.bits.FunctionNumber, Config.VendorID,
Config.DeviceID);
} }
FoundDevice = (VendorId == NULL || Config.VendorID == *((USHORT *) VendorId)) && if ((VendorIdToFind == 0 || Config.VendorID == VendorIdToFind) &&
(DeviceId == NULL || Config.DeviceID == *((USHORT *) DeviceId)); (DeviceIdToFind == 0 || Config.DeviceID == DeviceIdToFind))
}
}
if (! FoundDevice)
{ {
break;
}
}
}
if (FunctionNumber == 8)
{
DPRINT("Didn't find device.\n");
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
Status = HalAssignSlotResources(NULL, NULL, NULL, NULL, Status = HalAssignSlotResources(NULL, NULL, NULL, NULL,
DeviceExtension->AdapterInterfaceType, DeviceExtension->AdapterInterfaceType,
DeviceExtension->SystemIoBusNumber, DeviceExtension->SystemIoBusNumber,
PciSlotNumber.u.AsULONG, &AllocatedResources); PciSlotNumber.u.AsULONG,
&AllocatedResources);
if (! NT_SUCCESS(Status)) if (! NT_SUCCESS(Status))
{ {
return Status; return Status;
@ -596,11 +631,11 @@ VideoPortInitialize(IN PVOID Context1,
ConfigInfo.InterruptMode = (PCIBus == DeviceExtension->AdapterInterfaceType) ? ConfigInfo.InterruptMode = (PCIBus == DeviceExtension->AdapterInterfaceType) ?
LevelSensitive : Latched; LevelSensitive : Latched;
ConfigInfo.DriverRegistryPath = RegistryPath->Buffer; ConfigInfo.DriverRegistryPath = RegistryPath->Buffer;
ConfigInfo.VideoPortGetProcAddress = VideoPortGetProcAddress;
/* Call HwFindAdapter entry point */ /* Call HwFindAdapter entry point */
/* FIXME: Need to figure out what string to pass as param 3 */ /* FIXME: Need to figure out what string to pass as param 3 */
DPRINT("HwFindAdapter %X Context2 %X\n", DPRINT("FindAdapter %X\n", HwInitializationData->HwFindAdapter);
HwInitializationData->HwFindAdapter, Context2);
Status = HwInitializationData->HwFindAdapter(&DeviceExtension->MiniPortDeviceExtension, Status = HwInitializationData->HwFindAdapter(&DeviceExtension->MiniPortDeviceExtension,
Context2, Context2,
NULL, NULL,
@ -608,7 +643,7 @@ VideoPortInitialize(IN PVOID Context1,
&Again); &Again);
if (NO_ERROR != Status) if (NO_ERROR != Status)
{ {
DPRINT("HwFindAdapter call failed with error %d\n", Status); DPRINT("HwFindAdapter call failed with error %X\n", Status);
DeviceExtension->SystemIoBusNumber++; DeviceExtension->SystemIoBusNumber++;
} }
} }
@ -875,8 +910,8 @@ VideoPortSetTrappedEmulatorPorts(IN PVOID HwDeviceExtension,
IN PVIDEO_ACCESS_RANGE AccessRange) IN PVIDEO_ACCESS_RANGE AccessRange)
{ {
DPRINT("VideoPortSetTrappedEmulatorPorts\n"); DPRINT("VideoPortSetTrappedEmulatorPorts\n");
UNIMPLEMENTED; /* Should store the ranges in the device extension for use by ntvdm. */
return STATUS_NOT_IMPLEMENTED; return STATUS_SUCCESS;
} }
@ -1672,3 +1707,76 @@ VideoPortRegisterBugcheckCallback ( IN PVOID HwDeviceExtension,
DPRINT1("VideoPortRegisterBugcheckCallback(): Unimplemented.\n"); DPRINT1("VideoPortRegisterBugcheckCallback(): Unimplemented.\n");
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
PVOID
STDCALL
VideoPortImageDirectoryEntryToData ( PVOID BaseAddress,
ULONG Directory )
{
PIMAGE_NT_HEADERS NtHeader;
ULONG Va;
NtHeader = RtlImageNtHeader (BaseAddress);
if (NtHeader == NULL)
return NULL;
if (Directory >= NtHeader->OptionalHeader.NumberOfRvaAndSizes)
return NULL;
Va = NtHeader->OptionalHeader.DataDirectory[Directory].VirtualAddress;
if (Va == 0)
return NULL;
return (PVOID)(BaseAddress + Va);
}
PVOID STDCALL
VideoPortGetProcAddress(IN PVOID HwDeviceExtension,
IN PUCHAR FunctionName)
{
SYSTEM_LOAD_IMAGE GdiDriverInfo;
PVOID BaseAddress;
PIMAGE_EXPORT_DIRECTORY ExportDir;
PUSHORT OrdinalPtr;
PULONG NamePtr;
PULONG AddressPtr;
ULONG i = 0;
NTSTATUS Status;
DPRINT("VideoPortGetProcAddress(%s)\n", FunctionName);
RtlInitUnicodeString(&GdiDriverInfo.ModuleName, L"videoprt");
Status = ZwSetSystemInformation(SystemLoadImage, &GdiDriverInfo,
sizeof(SYSTEM_LOAD_IMAGE));
if (!NT_SUCCESS(Status))
{
DPRINT("Couldn't get our own module handle?\n");
return NULL;
}
BaseAddress = GdiDriverInfo.ModuleBase;
/* Get the pointer to the export directory */
ExportDir = (PIMAGE_EXPORT_DIRECTORY)
VideoPortImageDirectoryEntryToData (BaseAddress,
IMAGE_DIRECTORY_ENTRY_EXPORT);
/* search by name */
AddressPtr = (PULONG)
((ULONG_PTR)BaseAddress + (ULONG_PTR)ExportDir->AddressOfFunctions);
OrdinalPtr = (PUSHORT)
((ULONG_PTR)BaseAddress + (ULONG_PTR)ExportDir->AddressOfNameOrdinals);
NamePtr = (PULONG)
((ULONG_PTR)BaseAddress + (ULONG_PTR)ExportDir->AddressOfNames);
for (i = 0; i < ExportDir->NumberOfNames; i++, NamePtr++, OrdinalPtr++)
{
if (!_strnicmp(FunctionName, (char*)(BaseAddress + *NamePtr),
strlen(FunctionName)))
{
return (PVOID)((ULONG_PTR)BaseAddress +
(ULONG_PTR)AddressPtr[*OrdinalPtr]);
}
}
DPRINT("VideoPortGetProcAddress: Can't resolve symbol %s\n", FunctionName);
return(NULL);
}

View file

@ -1,4 +1,4 @@
; $Id: videoprt.def,v 1.5 2004/03/06 22:25:22 dwelch Exp $ ; $Id: videoprt.def,v 1.6 2004/03/07 04:43:55 dwelch Exp $
; ;
; vidport.def - export definition file for ReactOS ; vidport.def - export definition file for ReactOS
; ;
@ -6,6 +6,7 @@ EXPORTS
ReturnCsrssAddress ReturnCsrssAddress
VideoPortAllocateBuffer@12 VideoPortAllocateBuffer@12
VideoPortAllocateCommonBuffer@24 VideoPortAllocateCommonBuffer@24
VideoPortCheckForDeviceExistence@28
VideoPortClearEvent@8 VideoPortClearEvent@8
VideoPortCompareMemory@12 VideoPortCompareMemory@12
VideoPortCreateEvent@16 VideoPortCreateEvent@16

View file

@ -1,4 +1,4 @@
; $Id: videoprt.edf,v 1.5 2004/03/06 22:25:22 dwelch Exp $ ; $Id: videoprt.edf,v 1.6 2004/03/07 04:43:55 dwelch Exp $
; ;
; vidport.def - export definition file for ReactOS ; vidport.def - export definition file for ReactOS
; ;
@ -6,6 +6,7 @@ EXPORTS
VideoPortAllocateBuffer=VideoPortAllocateBuffer@12 VideoPortAllocateBuffer=VideoPortAllocateBuffer@12
VideoPortAllocateCommonBuffer=VideoPortAllocateCommonBuffer@24 VideoPortAllocateCommonBuffer=VideoPortAllocateCommonBuffer@24
VideoPortAllocatePool=VideoPortAllocatePool@16 VideoPortAllocatePool=VideoPortAllocatePool@16
VideoPortCheckForDeviceExistence=VideoPortCheckForDeviceExistence@28
VideoPortCompareMemory=NTOSKRNL.RtlCompareMemory VideoPortCompareMemory=NTOSKRNL.RtlCompareMemory
VideoPortClearEvent=VideoPortClearEvent@8 VideoPortClearEvent=VideoPortClearEvent@8
VideoPortCreateEvent=VideoPortCreateEvent@16 VideoPortCreateEvent=VideoPortCreateEvent@16

View file

@ -18,7 +18,7 @@
* If not, write to the Free Software Foundation, * If not, write to the Free Software Foundation,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Id: videoprt.h,v 1.3 2004/03/06 22:25:22 dwelch Exp $ * $Id: videoprt.h,v 1.4 2004/03/07 04:43:55 dwelch Exp $
*/ */
#ifndef VIDEOPRT_H #ifndef VIDEOPRT_H
@ -28,7 +28,7 @@
#include <ddk/video.h> #include <ddk/video.h>
#include <ddk/ntddvdeo.h> #include <ddk/ntddvdeo.h>
#include "internal/ps.h" #include "internal/ps.h"
/*#define NDEBUG*/ #define NDEBUG
#include <debug.h> #include <debug.h>
/* /*