From eddf35ba2a6f32f0abb35583927a4defd98c135d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Tue, 31 May 2005 10:35:22 +0000 Subject: [PATCH] Don't try to detect serial ports at known I/O addresses. They have to be written in registry and enumerated by Root bus enumerator. Get interrupt informations from AllocatedResourcesTranslated in IRP_MN_START_DEVICE svn path=/trunk/; revision=15695 --- reactos/drivers/dd/serial/legacy.c | 154 ----------------------------- reactos/drivers/dd/serial/pnp.c | 13 ++- reactos/drivers/dd/serial/serial.c | 2 +- reactos/drivers/dd/serial/serial.h | 4 - 4 files changed, 7 insertions(+), 166 deletions(-) diff --git a/reactos/drivers/dd/serial/legacy.c b/reactos/drivers/dd/serial/legacy.c index efb76e46155..01e737f3181 100644 --- a/reactos/drivers/dd/serial/legacy.c +++ b/reactos/drivers/dd/serial/legacy.c @@ -73,157 +73,3 @@ SerialDetectUartType( /* FIFO is only functional for 16550A+ */ return Uart16550A; } - -static NTSTATUS -DetectLegacyDevice( - IN PDRIVER_OBJECT DriverObject, - IN ULONG ComPortBase, - IN ULONG Irq, - IN PULONG pComPortNumber OPTIONAL) -{ - ULONG ResourceListSize; - PCM_RESOURCE_LIST ResourceList; - PCM_RESOURCE_LIST ResourceListTranslated; - PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor; - PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptorTranslated; - BOOLEAN ConflictDetected; - UART_TYPE UartType; - PDEVICE_OBJECT Pdo = NULL; - PDEVICE_OBJECT Fdo; - NTSTATUS Status; - - /* Create resource list */ - ResourceListSize = sizeof(CM_RESOURCE_LIST) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - ResourceList = (PCM_RESOURCE_LIST)ExAllocatePoolWithTag(PagedPool, ResourceListSize, SERIAL_TAG); - if (!ResourceList) - return STATUS_INSUFFICIENT_RESOURCES; - ResourceListTranslated = (PCM_RESOURCE_LIST)ExAllocatePoolWithTag(PagedPool, ResourceListSize, SERIAL_TAG); - if (!ResourceListTranslated) - { - ExFreePoolWithTag(ResourceList, SERIAL_TAG); - return STATUS_INSUFFICIENT_RESOURCES; - } - - /* Resource header */ - ResourceList->Count = ResourceListTranslated->Count - = 1; - ResourceList->List[0].InterfaceType = ResourceListTranslated->List[0].InterfaceType - = InterfaceTypeUndefined; - ResourceList->List[0].BusNumber = ResourceListTranslated->List[0].BusNumber - = -1; /* unknown */ - ResourceList->List[0].PartialResourceList.Version = ResourceListTranslated->List[0].PartialResourceList.Version - = 1; - ResourceList->List[0].PartialResourceList.Revision = ResourceListTranslated->List[0].PartialResourceList.Revision - = 1; - ResourceList->List[0].PartialResourceList.Count = ResourceListTranslated->List[0].PartialResourceList.Count - = 2; - - /* I/O port */ - ResourceDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[0]; - ResourceDescriptorTranslated = &ResourceListTranslated->List[0].PartialResourceList.PartialDescriptors[0]; - ResourceDescriptor->Type = ResourceDescriptorTranslated->Type - = CmResourceTypePort; - ResourceDescriptor->ShareDisposition = ResourceDescriptorTranslated->ShareDisposition - = CmResourceShareDriverExclusive; - ResourceDescriptor->Flags = ResourceDescriptorTranslated->Flags - = CM_RESOURCE_PORT_IO; - ResourceDescriptor->u.Port.Start.u.HighPart = ResourceDescriptorTranslated->u.Port.Start.u.HighPart - = 0; - ResourceDescriptor->u.Port.Start.u.LowPart = ResourceDescriptorTranslated->u.Port.Start.u.LowPart - = ComPortBase; - ResourceDescriptor->u.Port.Length = ResourceDescriptorTranslated->u.Port.Length - = 8; - - ResourceDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[1]; - ResourceDescriptorTranslated = &ResourceListTranslated->List[0].PartialResourceList.PartialDescriptors[1]; - ResourceDescriptor->Type = ResourceDescriptorTranslated->Type - = CmResourceTypeInterrupt; - ResourceDescriptor->ShareDisposition = ResourceDescriptorTranslated->ShareDisposition - = CmResourceShareShared; - ResourceDescriptor->Flags = ResourceDescriptorTranslated->Flags - = CM_RESOURCE_INTERRUPT_LATCHED; - ResourceDescriptor->u.Interrupt.Level = Irq; - ResourceDescriptorTranslated->u.Interrupt.Vector = HalGetInterruptVector( - ResourceList->List[0].InterfaceType, - ResourceList->List[0].BusNumber, - ResourceDescriptor->u.Interrupt.Level, - ResourceDescriptor->u.Interrupt.Vector, - (PKIRQL)&ResourceDescriptorTranslated->u.Interrupt.Level, - &ResourceDescriptor->u.Interrupt.Affinity); - ResourceDescriptorTranslated->u.Interrupt.Affinity = ResourceDescriptor->u.Interrupt.Affinity; - - /* Report resource list */ - Status = IoReportResourceForDetection( - DriverObject, ResourceList, ResourceListSize, - NULL, NULL, 0, - &ConflictDetected); - if (Status == STATUS_CONFLICTING_ADDRESSES) - { - DPRINT("Serial: conflict detected for serial port at 0x%lx (Irq %lu)\n", ComPortBase, Irq); - ExFreePoolWithTag(ResourceList, SERIAL_TAG); - ExFreePoolWithTag(ResourceListTranslated, SERIAL_TAG); - return STATUS_DEVICE_NOT_CONNECTED; - } - if (!NT_SUCCESS(Status)) - { - ExFreePoolWithTag(ResourceList, SERIAL_TAG); - ExFreePoolWithTag(ResourceListTranslated, SERIAL_TAG); - return Status; - } - - /* Test if port exists */ - UartType = SerialDetectUartType((PUCHAR)ComPortBase); - - /* Report device if detected... */ - if (UartType != UartUnknown) - { - Status = IoReportDetectedDevice( - DriverObject, - ResourceList->List[0].InterfaceType, ResourceList->List[0].BusNumber, -1 /* unknown */, - ResourceList, NULL, - TRUE, - &Pdo); - if (NT_SUCCESS(Status)) - { - Status = SerialAddDeviceInternal(DriverObject, Pdo, UartType, pComPortNumber, &Fdo); - if (NT_SUCCESS(Status)) - { - Status = SerialPnpStartDevice(Fdo, ResourceList, ResourceListTranslated); - } - } - } - else - { - /* Release resources */ - Status = IoReportResourceForDetection( - DriverObject, NULL, 0, - NULL, NULL, 0, - &ConflictDetected); - Status = STATUS_DEVICE_NOT_CONNECTED; - } - ExFreePoolWithTag(ResourceList, SERIAL_TAG); - ExFreePoolWithTag(ResourceListTranslated, SERIAL_TAG); - return Status; -} - -NTSTATUS -DetectLegacyDevices( - IN PDRIVER_OBJECT DriverObject) -{ - ULONG ComPortBase[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; - ULONG Irq[] = { 4, 3, 4, 3 }; - ULONG ComPortNumber[] = { 1, 2, 3, 4 }; - ULONG i; - NTSTATUS Status; - NTSTATUS ReturnedStatus = STATUS_SUCCESS; - - for (i = 0; i < sizeof(ComPortBase)/sizeof(ComPortBase[0]); i++) - { - Status = DetectLegacyDevice(DriverObject, ComPortBase[i], Irq[i], &ComPortNumber[i]); - if (!NT_SUCCESS(Status) && Status != STATUS_DEVICE_NOT_CONNECTED) - ReturnedStatus = Status; - DPRINT("Serial: Legacy device at 0x%x (IRQ %lu): status = 0x%08lx\n", ComPortBase[i], Irq[i], Status); - } - - return ReturnedStatus; -} diff --git a/reactos/drivers/dd/serial/pnp.c b/reactos/drivers/dd/serial/pnp.c index 0826cb18f58..e7ee5e8c87a 100644 --- a/reactos/drivers/dd/serial/pnp.c +++ b/reactos/drivers/dd/serial/pnp.c @@ -163,6 +163,7 @@ SerialPnpStartDevice( for (j = 0; j < ResourceList->List[i].PartialResourceList.Count; j++) { PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor = &ResourceList->List[i].PartialResourceList.PartialDescriptors[j]; + PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptorTranslated = &ResourceListTranslated->List[i].PartialResourceList.PartialDescriptors[j]; switch (PartialDescriptor->Type) { case CmResourceTypePort: @@ -173,16 +174,14 @@ SerialPnpStartDevice( DeviceExtension->BaseAddress = PartialDescriptor->u.Port.Start.u.LowPart; break; case CmResourceTypeInterrupt: - if (Dirql != 0) - return STATUS_UNSUCCESSFUL; - Dirql = (KIRQL)ResourceListTranslated->List[i].PartialResourceList.PartialDescriptors[j].u.Interrupt.Level; - Vector = ResourceListTranslated->List[i].PartialResourceList.PartialDescriptors[j].u.Interrupt.Vector; - Affinity = PartialDescriptor->u.Interrupt.Affinity; - if (PartialDescriptor->Flags & CM_RESOURCE_INTERRUPT_LATCHED) + Dirql = (KIRQL)PartialDescriptorTranslated->u.Interrupt.Level; + Vector = PartialDescriptorTranslated->u.Interrupt.Vector; + Affinity = PartialDescriptorTranslated->u.Interrupt.Affinity; + if (PartialDescriptorTranslated->Flags & CM_RESOURCE_INTERRUPT_LATCHED) InterruptMode = Latched; else InterruptMode = LevelSensitive; - ShareInterrupt = (PartialDescriptor->ShareDisposition == CmResourceShareShared); + ShareInterrupt = (PartialDescriptorTranslated->ShareDisposition == CmResourceShareShared); break; } } diff --git a/reactos/drivers/dd/serial/serial.c b/reactos/drivers/dd/serial/serial.c index 346cd6b2298..a7539af1717 100644 --- a/reactos/drivers/dd/serial/serial.c +++ b/reactos/drivers/dd/serial/serial.c @@ -42,5 +42,5 @@ DriverEntry( DriverObject->MajorFunction[IRP_MJ_PNP] = SerialPnp; DriverObject->MajorFunction[IRP_MJ_POWER] = SerialPower; - return DetectLegacyDevices(DriverObject); + return STATUS_SUCCESS; } diff --git a/reactos/drivers/dd/serial/serial.h b/reactos/drivers/dd/serial/serial.h index eb4794fb00d..8ac8fa1397d 100644 --- a/reactos/drivers/dd/serial/serial.h +++ b/reactos/drivers/dd/serial/serial.h @@ -274,10 +274,6 @@ UART_TYPE SerialDetectUartType( IN PUCHAR ComPortBase); -NTSTATUS -DetectLegacyDevices( - IN PDRIVER_OBJECT DriverObject); - /************************************ misc.c */ NTSTATUS