Fix file properties

svn path=/trunk/; revision=14495
This commit is contained in:
Hervé Poussineau 2005-04-04 23:17:28 +00:00
parent 04bbda156c
commit e26cc4962b
2 changed files with 291 additions and 291 deletions

View file

@ -1,97 +1,97 @@
/* $Id: /* $Id:
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: drivers/dd/serial/circularbuffer.c * FILE: drivers/dd/serial/circularbuffer.c
* PURPOSE: Operations on a circular buffer * PURPOSE: Operations on a circular buffer
* *
* PROGRAMMERS: Hervé Poussineau (poussine@freesurf.fr) * PROGRAMMERS: Hervé Poussineau (poussine@freesurf.fr)
*/ */
#define NDEBUG #define NDEBUG
#include "serial.h" #include "serial.h"
NTSTATUS NTSTATUS
InitializeCircularBuffer( InitializeCircularBuffer(
IN PCIRCULAR_BUFFER pBuffer, IN PCIRCULAR_BUFFER pBuffer,
IN ULONG BufferSize) IN ULONG BufferSize)
{ {
DPRINT("Serial: InitializeCircularBuffer(pBuffer %p, BufferSize %lu)\n", pBuffer, BufferSize); DPRINT("Serial: InitializeCircularBuffer(pBuffer %p, BufferSize %lu)\n", pBuffer, BufferSize);
pBuffer->Buffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, BufferSize * sizeof(UCHAR), SERIAL_TAG); pBuffer->Buffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, BufferSize * sizeof(UCHAR), SERIAL_TAG);
if (!pBuffer->Buffer) if (!pBuffer->Buffer)
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
pBuffer->Length = BufferSize; pBuffer->Length = BufferSize;
pBuffer->ReadPosition = pBuffer->WritePosition = 0; pBuffer->ReadPosition = pBuffer->WritePosition = 0;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
NTSTATUS NTSTATUS
FreeCircularBuffer( FreeCircularBuffer(
IN PCIRCULAR_BUFFER pBuffer) IN PCIRCULAR_BUFFER pBuffer)
{ {
DPRINT("Serial: FreeCircularBuffer(pBuffer %p)\n", pBuffer); DPRINT("Serial: FreeCircularBuffer(pBuffer %p)\n", pBuffer);
ExFreePoolWithTag(pBuffer->Buffer, SERIAL_TAG); ExFreePoolWithTag(pBuffer->Buffer, SERIAL_TAG);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
BOOLEAN BOOLEAN
IsCircularBufferEmpty( IsCircularBufferEmpty(
IN PCIRCULAR_BUFFER pBuffer) IN PCIRCULAR_BUFFER pBuffer)
{ {
DPRINT("Serial: IsCircularBufferEmpty(pBuffer %p)\n", pBuffer); DPRINT("Serial: IsCircularBufferEmpty(pBuffer %p)\n", pBuffer);
return (pBuffer->ReadPosition == pBuffer->WritePosition); return (pBuffer->ReadPosition == pBuffer->WritePosition);
} }
NTSTATUS NTSTATUS
PushCircularBufferEntry( PushCircularBufferEntry(
IN PCIRCULAR_BUFFER pBuffer, IN PCIRCULAR_BUFFER pBuffer,
IN UCHAR Entry) IN UCHAR Entry)
{ {
ULONG NextPosition; ULONG NextPosition;
DPRINT("Serial: PushCircularBufferEntry(pBuffer %p, Entry 0x%x)\n", pBuffer, Entry); DPRINT("Serial: PushCircularBufferEntry(pBuffer %p, Entry 0x%x)\n", pBuffer, Entry);
ASSERT(pBuffer->Length); ASSERT(pBuffer->Length);
NextPosition = (pBuffer->WritePosition + 1) % pBuffer->Length; NextPosition = (pBuffer->WritePosition + 1) % pBuffer->Length;
if (NextPosition == pBuffer->ReadPosition) if (NextPosition == pBuffer->ReadPosition)
return STATUS_BUFFER_TOO_SMALL; return STATUS_BUFFER_TOO_SMALL;
pBuffer->Buffer[pBuffer->WritePosition] = Entry; pBuffer->Buffer[pBuffer->WritePosition] = Entry;
pBuffer->WritePosition = NextPosition; pBuffer->WritePosition = NextPosition;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
NTSTATUS NTSTATUS
PopCircularBufferEntry( PopCircularBufferEntry(
IN PCIRCULAR_BUFFER pBuffer, IN PCIRCULAR_BUFFER pBuffer,
OUT PUCHAR Entry) OUT PUCHAR Entry)
{ {
DPRINT("Serial: PopCircularBufferEntry(pBuffer %p)\n", pBuffer); DPRINT("Serial: PopCircularBufferEntry(pBuffer %p)\n", pBuffer);
ASSERT(pBuffer->Length); ASSERT(pBuffer->Length);
if (IsCircularBufferEmpty(pBuffer)) if (IsCircularBufferEmpty(pBuffer))
return STATUS_ARRAY_BOUNDS_EXCEEDED; return STATUS_ARRAY_BOUNDS_EXCEEDED;
*Entry = pBuffer->Buffer[pBuffer->ReadPosition]; *Entry = pBuffer->Buffer[pBuffer->ReadPosition];
pBuffer->ReadPosition = (pBuffer->ReadPosition + 1) % pBuffer->Length; pBuffer->ReadPosition = (pBuffer->ReadPosition + 1) % pBuffer->Length;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
NTSTATUS NTSTATUS
IncreaseCircularBufferSize( IncreaseCircularBufferSize(
IN PCIRCULAR_BUFFER pBuffer, IN PCIRCULAR_BUFFER pBuffer,
IN ULONG NewBufferSize) IN ULONG NewBufferSize)
{ {
PUCHAR NewBuffer; PUCHAR NewBuffer;
DPRINT("Serial: IncreaseCircularBufferSize(pBuffer %p, NewBufferSize %lu)\n", pBuffer, NewBufferSize); DPRINT("Serial: IncreaseCircularBufferSize(pBuffer %p, NewBufferSize %lu)\n", pBuffer, NewBufferSize);
ASSERT(pBuffer->Length); ASSERT(pBuffer->Length);
if (pBuffer->Length > NewBufferSize) if (pBuffer->Length > NewBufferSize)
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
else if (pBuffer->Length == NewBufferSize) else if (pBuffer->Length == NewBufferSize)
return STATUS_SUCCESS; return STATUS_SUCCESS;
NewBuffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, NewBufferSize * sizeof(UCHAR), SERIAL_TAG); NewBuffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, NewBufferSize * sizeof(UCHAR), SERIAL_TAG);
if (!NewBuffer) if (!NewBuffer)
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
RtlCopyMemory(NewBuffer, pBuffer->Buffer, pBuffer->Length * sizeof(UCHAR)); RtlCopyMemory(NewBuffer, pBuffer->Buffer, pBuffer->Length * sizeof(UCHAR));
ExFreePoolWithTag(pBuffer->Buffer, SERIAL_TAG); ExFreePoolWithTag(pBuffer->Buffer, SERIAL_TAG);
pBuffer->Buffer = NewBuffer; pBuffer->Buffer = NewBuffer;
pBuffer->Length = NewBufferSize; pBuffer->Length = NewBufferSize;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }

View file

@ -1,194 +1,194 @@
/* $Id: /* $Id:
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: drivers/bus/serial/legacy.c * FILE: drivers/bus/serial/legacy.c
* PURPOSE: Legacy serial port enumeration * PURPOSE: Legacy serial port enumeration
* *
* PROGRAMMERS: Hervé Poussineau (poussine@freesurf.fr) * PROGRAMMERS: Hervé Poussineau (poussine@freesurf.fr)
* Mark Junker (mjscod@gmx.de) * Mark Junker (mjscod@gmx.de)
*/ */
#define NDEBUG #define NDEBUG
#include "serial.h" #include "serial.h"
UART_TYPE UART_TYPE
SerialDetectUartType( SerialDetectUartType(
IN PUCHAR BaseAddress) IN PUCHAR BaseAddress)
{ {
UCHAR Lcr, TestLcr; UCHAR Lcr, TestLcr;
UCHAR OldScr, Scr5A, ScrA5; UCHAR OldScr, Scr5A, ScrA5;
BOOLEAN FifoEnabled; BOOLEAN FifoEnabled;
UCHAR NewFifoStatus; UCHAR NewFifoStatus;
Lcr = READ_PORT_UCHAR(SER_LCR(BaseAddress)); Lcr = READ_PORT_UCHAR(SER_LCR(BaseAddress));
WRITE_PORT_UCHAR(SER_LCR(BaseAddress), Lcr ^ 0xFF); WRITE_PORT_UCHAR(SER_LCR(BaseAddress), Lcr ^ 0xFF);
TestLcr = READ_PORT_UCHAR(SER_LCR(BaseAddress)) ^ 0xFF; TestLcr = READ_PORT_UCHAR(SER_LCR(BaseAddress)) ^ 0xFF;
WRITE_PORT_UCHAR(SER_LCR(BaseAddress), Lcr); WRITE_PORT_UCHAR(SER_LCR(BaseAddress), Lcr);
/* Accessing the LCR must work for a usable serial port */ /* Accessing the LCR must work for a usable serial port */
if (TestLcr != Lcr) if (TestLcr != Lcr)
return UartUnknown; return UartUnknown;
/* Ensure that all following accesses are done as required */ /* Ensure that all following accesses are done as required */
READ_PORT_UCHAR(SER_RBR(BaseAddress)); READ_PORT_UCHAR(SER_RBR(BaseAddress));
READ_PORT_UCHAR(SER_IER(BaseAddress)); READ_PORT_UCHAR(SER_IER(BaseAddress));
READ_PORT_UCHAR(SER_IIR(BaseAddress)); READ_PORT_UCHAR(SER_IIR(BaseAddress));
READ_PORT_UCHAR(SER_LCR(BaseAddress)); READ_PORT_UCHAR(SER_LCR(BaseAddress));
READ_PORT_UCHAR(SER_MCR(BaseAddress)); READ_PORT_UCHAR(SER_MCR(BaseAddress));
READ_PORT_UCHAR(SER_LSR(BaseAddress)); READ_PORT_UCHAR(SER_LSR(BaseAddress));
READ_PORT_UCHAR(SER_MSR(BaseAddress)); READ_PORT_UCHAR(SER_MSR(BaseAddress));
READ_PORT_UCHAR(SER_SCR(BaseAddress)); READ_PORT_UCHAR(SER_SCR(BaseAddress));
/* Test scratch pad */ /* Test scratch pad */
OldScr = READ_PORT_UCHAR(SER_SCR(BaseAddress)); OldScr = READ_PORT_UCHAR(SER_SCR(BaseAddress));
WRITE_PORT_UCHAR(SER_SCR(BaseAddress), 0x5A); WRITE_PORT_UCHAR(SER_SCR(BaseAddress), 0x5A);
Scr5A = READ_PORT_UCHAR(SER_SCR(BaseAddress)); Scr5A = READ_PORT_UCHAR(SER_SCR(BaseAddress));
WRITE_PORT_UCHAR(SER_SCR(BaseAddress), 0xA5); WRITE_PORT_UCHAR(SER_SCR(BaseAddress), 0xA5);
ScrA5 = READ_PORT_UCHAR(SER_SCR(BaseAddress)); ScrA5 = READ_PORT_UCHAR(SER_SCR(BaseAddress));
WRITE_PORT_UCHAR(SER_SCR(BaseAddress), OldScr); WRITE_PORT_UCHAR(SER_SCR(BaseAddress), OldScr);
/* When non-functional, we have a 8250 */ /* When non-functional, we have a 8250 */
if (Scr5A != 0x5A || ScrA5 != 0xA5) if (Scr5A != 0x5A || ScrA5 != 0xA5)
return Uart8250; return Uart8250;
/* Test FIFO type */ /* Test FIFO type */
FifoEnabled = (READ_PORT_UCHAR(SER_IIR(BaseAddress)) & 0x80) != 0; FifoEnabled = (READ_PORT_UCHAR(SER_IIR(BaseAddress)) & 0x80) != 0;
WRITE_PORT_UCHAR(SER_FCR(BaseAddress), SR_FCR_ENABLE_FIFO); WRITE_PORT_UCHAR(SER_FCR(BaseAddress), SR_FCR_ENABLE_FIFO);
NewFifoStatus = READ_PORT_UCHAR(SER_IIR(BaseAddress)) & 0xC0; NewFifoStatus = READ_PORT_UCHAR(SER_IIR(BaseAddress)) & 0xC0;
if (!FifoEnabled) if (!FifoEnabled)
WRITE_PORT_UCHAR(SER_FCR(BaseAddress), 0); WRITE_PORT_UCHAR(SER_FCR(BaseAddress), 0);
switch (NewFifoStatus) switch (NewFifoStatus)
{ {
case 0x00: case 0x00:
return Uart16450; return Uart16450;
case 0x40: case 0x40:
case 0x80: case 0x80:
/* Not sure about this but the documentation says that 0x40 /* Not sure about this but the documentation says that 0x40
* indicates an unusable FIFO but my tests only worked * indicates an unusable FIFO but my tests only worked
* with 0x80 */ * with 0x80 */
return Uart16550; return Uart16550;
} }
/* FIFO is only functional for 16550A+ */ /* FIFO is only functional for 16550A+ */
return Uart16550A; return Uart16550A;
} }
static NTSTATUS static NTSTATUS
DetectLegacyDevice( DetectLegacyDevice(
IN PDRIVER_OBJECT DriverObject, IN PDRIVER_OBJECT DriverObject,
IN ULONG ComPortBase, IN ULONG ComPortBase,
IN ULONG Irq, IN ULONG Irq,
IN PULONG pComPortNumber OPTIONAL) IN PULONG pComPortNumber OPTIONAL)
{ {
ULONG ResourceListSize; ULONG ResourceListSize;
PCM_RESOURCE_LIST ResourceList; PCM_RESOURCE_LIST ResourceList;
PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor; PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor;
BOOLEAN ConflictDetected; BOOLEAN ConflictDetected;
UART_TYPE UartType; UART_TYPE UartType;
PDEVICE_OBJECT Pdo = NULL; PDEVICE_OBJECT Pdo = NULL;
PDEVICE_OBJECT Fdo; PDEVICE_OBJECT Fdo;
KIRQL Dirql; KIRQL Dirql;
NTSTATUS Status; NTSTATUS Status;
/* Create resource list */ /* Create resource list */
ResourceListSize = sizeof(CM_RESOURCE_LIST) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); ResourceListSize = sizeof(CM_RESOURCE_LIST) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
ResourceList = (PCM_RESOURCE_LIST)ExAllocatePoolWithTag(PagedPool, ResourceListSize, SERIAL_TAG); ResourceList = (PCM_RESOURCE_LIST)ExAllocatePoolWithTag(PagedPool, ResourceListSize, SERIAL_TAG);
if (!ResourceList) if (!ResourceList)
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
ResourceList->Count = 1; ResourceList->Count = 1;
ResourceList->List[0].InterfaceType = InterfaceTypeUndefined; ResourceList->List[0].InterfaceType = InterfaceTypeUndefined;
ResourceList->List[0].BusNumber = -1; /* unknown */ ResourceList->List[0].BusNumber = -1; /* unknown */
ResourceList->List[0].PartialResourceList.Version = 1; ResourceList->List[0].PartialResourceList.Version = 1;
ResourceList->List[0].PartialResourceList.Revision = 1; ResourceList->List[0].PartialResourceList.Revision = 1;
ResourceList->List[0].PartialResourceList.Count = 2; ResourceList->List[0].PartialResourceList.Count = 2;
ResourceDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[0]; ResourceDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[0];
ResourceDescriptor->Type = CmResourceTypePort; ResourceDescriptor->Type = CmResourceTypePort;
ResourceDescriptor->ShareDisposition = CmResourceShareDriverExclusive; ResourceDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
ResourceDescriptor->Flags = CM_RESOURCE_PORT_IO; ResourceDescriptor->Flags = CM_RESOURCE_PORT_IO;
ResourceDescriptor->u.Port.Start.u.HighPart = 0; ResourceDescriptor->u.Port.Start.u.HighPart = 0;
ResourceDescriptor->u.Port.Start.u.LowPart = ComPortBase; ResourceDescriptor->u.Port.Start.u.LowPart = ComPortBase;
ResourceDescriptor->u.Port.Length = 8; ResourceDescriptor->u.Port.Length = 8;
ResourceDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[1]; ResourceDescriptor = &ResourceList->List[0].PartialResourceList.PartialDescriptors[1];
ResourceDescriptor->Type = CmResourceTypeInterrupt; ResourceDescriptor->Type = CmResourceTypeInterrupt;
ResourceDescriptor->ShareDisposition = CmResourceShareShared; ResourceDescriptor->ShareDisposition = CmResourceShareShared;
ResourceDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED; ResourceDescriptor->Flags = CM_RESOURCE_INTERRUPT_LATCHED;
ResourceDescriptor->u.Interrupt.Vector = HalGetInterruptVector( ResourceDescriptor->u.Interrupt.Vector = HalGetInterruptVector(
Internal, 0, 0, Irq, Internal, 0, 0, Irq,
&Dirql, &Dirql,
&ResourceDescriptor->u.Interrupt.Affinity); &ResourceDescriptor->u.Interrupt.Affinity);
ResourceDescriptor->u.Interrupt.Level = (ULONG)Dirql; ResourceDescriptor->u.Interrupt.Level = (ULONG)Dirql;
/* Report resource list */ /* Report resource list */
Status = IoReportResourceForDetection( Status = IoReportResourceForDetection(
DriverObject, ResourceList, ResourceListSize, DriverObject, ResourceList, ResourceListSize,
NULL, NULL, 0, NULL, NULL, 0,
&ConflictDetected); &ConflictDetected);
if (Status == STATUS_CONFLICTING_ADDRESSES) if (Status == STATUS_CONFLICTING_ADDRESSES)
{ {
DPRINT("Serial: conflict detected for serial port at 0x%lx (Irq %lu)\n", ComPortBase, Irq); DPRINT("Serial: conflict detected for serial port at 0x%lx (Irq %lu)\n", ComPortBase, Irq);
ExFreePoolWithTag(ResourceList, SERIAL_TAG); ExFreePoolWithTag(ResourceList, SERIAL_TAG);
return STATUS_DEVICE_NOT_CONNECTED; return STATUS_DEVICE_NOT_CONNECTED;
} }
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ExFreePoolWithTag(ResourceList, SERIAL_TAG); ExFreePoolWithTag(ResourceList, SERIAL_TAG);
return Status; return Status;
} }
/* Test if port exists */ /* Test if port exists */
UartType = SerialDetectUartType((PUCHAR)ComPortBase); UartType = SerialDetectUartType((PUCHAR)ComPortBase);
/* Report device if detected... */ /* Report device if detected... */
if (UartType != UartUnknown) if (UartType != UartUnknown)
{ {
Status = IoReportDetectedDevice( Status = IoReportDetectedDevice(
DriverObject, DriverObject,
ResourceList->List[0].InterfaceType, ResourceList->List[0].BusNumber, -1 /* unknown */, ResourceList->List[0].InterfaceType, ResourceList->List[0].BusNumber, -1 /* unknown */,
ResourceList, NULL, ResourceList, NULL,
TRUE, TRUE,
&Pdo); &Pdo);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
Status = SerialAddDeviceInternal(DriverObject, Pdo, UartType, pComPortNumber, &Fdo); Status = SerialAddDeviceInternal(DriverObject, Pdo, UartType, pComPortNumber, &Fdo);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
Status = SerialPnpStartDevice(Fdo, ResourceList); Status = SerialPnpStartDevice(Fdo, ResourceList);
} }
} }
} }
else else
{ {
/* Release resources */ /* Release resources */
Status = IoReportResourceForDetection( Status = IoReportResourceForDetection(
DriverObject, NULL, 0, DriverObject, NULL, 0,
NULL, NULL, 0, NULL, NULL, 0,
&ConflictDetected); &ConflictDetected);
Status = STATUS_DEVICE_NOT_CONNECTED; Status = STATUS_DEVICE_NOT_CONNECTED;
} }
ExFreePoolWithTag(ResourceList, SERIAL_TAG); ExFreePoolWithTag(ResourceList, SERIAL_TAG);
return Status; return Status;
} }
NTSTATUS NTSTATUS
DetectLegacyDevices( DetectLegacyDevices(
IN PDRIVER_OBJECT DriverObject) IN PDRIVER_OBJECT DriverObject)
{ {
ULONG ComPortBase[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; ULONG ComPortBase[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
ULONG Irq[] = { 4, 3, 4, 3 }; ULONG Irq[] = { 4, 3, 4, 3 };
ULONG ComPortNumber[] = { 1, 2, 3, 4 }; ULONG ComPortNumber[] = { 1, 2, 3, 4 };
ULONG i; ULONG i;
NTSTATUS Status; NTSTATUS Status;
NTSTATUS ReturnedStatus = STATUS_SUCCESS; NTSTATUS ReturnedStatus = STATUS_SUCCESS;
for (i = 0; i < sizeof(ComPortBase)/sizeof(ComPortBase[0]); i++) for (i = 0; i < sizeof(ComPortBase)/sizeof(ComPortBase[0]); i++)
{ {
Status = DetectLegacyDevice(DriverObject, ComPortBase[i], Irq[i], &ComPortNumber[i]); Status = DetectLegacyDevice(DriverObject, ComPortBase[i], Irq[i], &ComPortNumber[i]);
if (!NT_SUCCESS(Status) && Status != STATUS_DEVICE_NOT_CONNECTED) if (!NT_SUCCESS(Status) && Status != STATUS_DEVICE_NOT_CONNECTED)
ReturnedStatus = Status; ReturnedStatus = Status;
DPRINT("Serial: Legacy device at 0x%x (IRQ %lu): status = 0x%08lx\n", ComPortBase[i], Irq[i], Status); DPRINT("Serial: Legacy device at 0x%x (IRQ %lu): status = 0x%08lx\n", ComPortBase[i], Irq[i], Status);
} }
return ReturnedStatus; return ReturnedStatus;
} }