|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 3/4] Determine emulated device type from HardwareIDs or CompatibleIDs
These names are a little less arbitrary than the DeviceID and this change
also allows matching on class code for PCI devices, rather than a specific
vendor/device combo.
Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
src/xenbus.inf | 4 +-
src/xenfilt/driver.c | 167 +++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 137 insertions(+), 34 deletions(-)
diff --git a/src/xenbus.inf b/src/xenbus.inf
index 356e40b..bf3f0a1 100644
--- a/src/xenbus.inf
+++ b/src/xenbus.inf
@@ -117,8 +117,8 @@ AddReg = XenFilt_Parameters
[XenFilt_Parameters]
HKR,"Parameters",,0x00000010
-HKR,"Parameters","ACPI\PNP0A03",0x00000000,"PCI"
-HKR,"Parameters","PCIIDE\IDEChannel",0x00000000,"IDE"
+HKR,"Parameters","*PNP0A03",0x00000000,"PCI"
+HKR,"Parameters","Internal_IDE_Channel",0x00000000,"IDE"
[Monitor_Service]
DisplayName=%MonitorName%
diff --git a/src/xenfilt/driver.c b/src/xenfilt/driver.c
index 18ffeaa..0167c21 100644
--- a/src/xenfilt/driver.c
+++ b/src/xenfilt/driver.c
@@ -480,18 +480,33 @@ DriverQueryId(
KEVENT Event;
PIO_STACK_LOCATION StackLocation;
PWCHAR Buffer;
- ULONG Length;
NTSTATUS status;
ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
+ switch (Type) {
+ case BusQueryDeviceID:
+ case BusQueryInstanceID:
+ case BusQueryHardwareIDs:
+ case BusQueryCompatibleIDs:
+ status = STATUS_SUCCESS;
+ break;
+
+ default:
+ status = STATUS_NOT_SUPPORTED;
+ break;
+ }
+
+ if (!NT_SUCCESS(status))
+ goto fail1;
+
ObReferenceObject(DeviceObject);
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
status = STATUS_INSUFFICIENT_RESOURCES;
if (Irp == NULL)
- goto fail1;
+ goto fail2;
StackLocation = IoGetNextIrpStackLocation(Irp);
@@ -527,19 +542,78 @@ DriverQueryId(
}
if (!NT_SUCCESS(status))
- goto fail2;
+ goto fail3;
Buffer = (PWCHAR)Irp->IoStatus.Information;
- Length = (ULONG)(wcslen(Buffer) + 1) * sizeof (CHAR);
- *Id = __AllocatePoolWithTag(PagedPool, Length, 'TLIF');
+ switch (Type) {
+ case BusQueryDeviceID:
+ case BusQueryInstanceID: {
+ ULONG Length;
+ ULONG Size;
+
+ Length = (ULONG)(wcslen(Buffer));
+ Size = (Length + 1) * sizeof (CHAR);
+
+ *Id = __AllocatePoolWithTag(PagedPool, Size, 'TLIF');
+ if (*Id == NULL)
+ break;
+
+ status = RtlStringCbPrintfA(*Id, Size, "%ws", Buffer);
+ ASSERT(NT_SUCCESS(status));
+
+ break;
+ }
+ case BusQueryHardwareIDs:
+ case BusQueryCompatibleIDs: {
+ ULONG Index;
+ ULONG Size;
+
+ Index = 0;
+ for (;;) {
+ ULONG Length;
+
+ Length = (ULONG)wcslen(&Buffer[Index]);
+ if (Length == 0)
+ break;
+
+ Index += Length + 1;
+ }
+ ASSERT(Index > 0);
+
+ Size = (Index + 1) * sizeof (CHAR);
+
+ *Id = __AllocatePoolWithTag(PagedPool, Size, 'TLIF');
+ if (*Id == NULL)
+ break;
+
+ Index = 0;
+ for (;;) {
+ ULONG Length;
+
+ Length = (ULONG)wcslen(&Buffer[Index]);
+ if (Length == 0)
+ break;
+
+ status = RtlStringCbPrintfA(*Id + Index, Size, "%ws",
+ &Buffer[Index]);
+ ASSERT(NT_SUCCESS(status));
+
+ Index += Length + 1;
+ Size -= Length + 1;
+ }
+
+ break;
+ }
+ default:
+ ASSERT(FALSE);
+ *Id = NULL;
+ break;
+ }
status = STATUS_NO_MEMORY;
if (*Id == NULL)
- goto fail3;
-
- status = RtlStringCbPrintfA(*Id, Length, "%ws", Buffer);
- ASSERT(NT_SUCCESS(status));
+ goto fail4;
ExFreePool(Buffer);
IoFreeIrp(Irp);
@@ -547,15 +621,16 @@ DriverQueryId(
return STATUS_SUCCESS;
-fail3:
+fail4:
ExFreePool(Buffer);
-fail2:
+fail3:
IoFreeIrp(Irp);
-fail1:
+fail2:
ObDereferenceObject(DeviceObject);
+fail1:
return status;
}
@@ -651,29 +726,46 @@ fail1:
static XENFILT_EMULATED_OBJECT_TYPE
DriverGetEmulatedType(
- IN PCHAR DeviceID
+ IN PCHAR Id
)
{
HANDLE ParametersKey;
XENFILT_EMULATED_OBJECT_TYPE Type;
- PANSI_STRING Ansi;
- NTSTATUS status;
+ ULONG Index;
ParametersKey = __DriverGetParametersKey();
Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
+ Index = 0;
- status = RegistryQuerySzValue(ParametersKey,
- DeviceID,
- NULL,
- &Ansi);
- if (NT_SUCCESS(status)) {
- if (_strnicmp(Ansi->Buffer, "PCI", Ansi->Length) == 0)
- Type = XENFILT_EMULATED_OBJECT_TYPE_PCI;
- else if (_strnicmp(Ansi->Buffer, "IDE", Ansi->Length) == 0)
- Type = XENFILT_EMULATED_OBJECT_TYPE_IDE;
+ for (;;) {
+ ULONG Length;
+ PANSI_STRING Ansi;
+ NTSTATUS status;
+
+ Length = (ULONG)strlen(&Id[Index]);
+ if (Length == 0)
+ break;
+
+ status = RegistryQuerySzValue(ParametersKey,
+ &Id[Index],
+ NULL,
+ &Ansi);
+ if (NT_SUCCESS(status)) {
+ Info("MATCH: %s -> %Z\n", &Id[Index], Ansi);
+
+ if (_strnicmp(Ansi->Buffer, "PCI", Ansi->Length) == 0)
+ Type = XENFILT_EMULATED_OBJECT_TYPE_PCI;
+ else if (_strnicmp(Ansi->Buffer, "IDE", Ansi->Length) == 0)
+ Type = XENFILT_EMULATED_OBJECT_TYPE_IDE;
+
+ RegistryFreeSzValue(Ansi);
+ break;
+ } else {
+ Trace("NO MATCH: %s\n", &Id[Index]);
+ }
- RegistryFreeSzValue(Ansi);
+ Index += Length + 1;
}
return Type;
@@ -688,20 +780,31 @@ DriverAddDevice(
IN PDEVICE_OBJECT PhysicalDeviceObject
)
{
- PCHAR DeviceID;
+ PCHAR Id;
XENFILT_EMULATED_OBJECT_TYPE Type;
NTSTATUS status;
ASSERT3P(DriverObject, ==, __DriverGetDriverObject());
+ Type = XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN;
+
status = DriverQueryId(PhysicalDeviceObject,
- BusQueryDeviceID,
- &DeviceID);
- if (!NT_SUCCESS(status))
- goto done;
+ BusQueryHardwareIDs,
+ &Id);
+ if (NT_SUCCESS(status)) {
+ Type = DriverGetEmulatedType(Id);
+ ExFreePool(Id);
+ }
- Type = DriverGetEmulatedType(DeviceID);
- ExFreePool(DeviceID);
+ if (Type == XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN) {
+ status = DriverQueryId(PhysicalDeviceObject,
+ BusQueryCompatibleIDs,
+ &Id);
+ if (NT_SUCCESS(status)) {
+ Type = DriverGetEmulatedType(Id);
+ ExFreePool(Id);
+ }
+ }
status = STATUS_SUCCESS;
if (Type == XENFILT_EMULATED_OBJECT_TYPE_UNKNOWN)
--
2.5.3
_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/win-pv-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |