diff --git a/reactos/include/ddk/halddk.h b/reactos/include/ddk/halddk.h index ae210fd8bc5..8516399123e 100644 --- a/reactos/include/ddk/halddk.h +++ b/reactos/include/ddk/halddk.h @@ -1,4 +1,4 @@ -/* $Id: halddk.h,v 1.8 2001/01/14 15:35:56 ekohl Exp $ +/* $Id: halddk.h,v 1.9 2001/03/31 16:01:03 phreak Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -304,9 +304,10 @@ NTSTATUS STDCALL HalAllocateAdapterChannel ( IN PADAPTER_OBJECT AdapterObject, - ULONG Unknown2, + IN PDEVICE_OBJECT DeviceObject, IN ULONG NumberOfMapRegisters, - IN PDRIVER_CONTROL ExecutionRoutine + IN PDRIVER_CONTROL ExecutionRoutine, + IN PVOID Context ); PVOID diff --git a/reactos/include/ddk/iotypes.h b/reactos/include/ddk/iotypes.h index 2266c67fe43..cd0c4181406 100644 --- a/reactos/include/ddk/iotypes.h +++ b/reactos/include/ddk/iotypes.h @@ -1,4 +1,4 @@ -/* $Id: iotypes.h,v 1.23 2001/02/10 22:51:07 dwelch Exp $ +/* $Id: iotypes.h,v 1.24 2001/03/31 16:01:03 phreak Exp $ * */ @@ -84,9 +84,7 @@ typedef VOID (*PIO_APC_ROUTINE) (PVOID ApcContext, /* STRUCTURE TYPES ***********************************************************/ -typedef struct _ADAPTER_OBJECT -{ -} ADAPTER_OBJECT, *PADAPTER_OBJECT; +typedef struct _ADAPTER_OBJECT ADAPTER_OBJECT, *PADAPTER_OBJECT; /* * PURPOSE: Special timer associated with each device diff --git a/reactos/include/ddk/structs.h b/reactos/include/ddk/structs.h index bad9af706eb..113eff3ddba 100644 --- a/reactos/include/ddk/structs.h +++ b/reactos/include/ddk/structs.h @@ -8,6 +8,3 @@ #include #include -typedef struct _ADAPTER_OBJECT -{ -} ADAPTER_OBJECT, *PADAPTER_OBJECT; diff --git a/reactos/ntoskrnl/hal/x86/adapter.c b/reactos/ntoskrnl/hal/x86/adapter.c index 5472b76d16e..24b1ad2f4a7 100644 --- a/reactos/ntoskrnl/hal/x86/adapter.c +++ b/reactos/ntoskrnl/hal/x86/adapter.c @@ -1,4 +1,4 @@ -/* $Id: adapter.c,v 1.3 2000/12/30 01:41:29 ekohl Exp $ +/* $Id: adapter.c,v 1.4 2001/03/31 15:58:24 phreak Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -12,8 +12,9 @@ /* INCLUDES *****************************************************************/ #include - +#include #include +#include /* FUNCTIONS *****************************************************************/ @@ -21,11 +22,46 @@ NTSTATUS STDCALL HalAllocateAdapterChannel(PADAPTER_OBJECT AdapterObject, - ULONG Unknown2, + PDEVICE_OBJECT DeviceObject, ULONG NumberOfMapRegisters, - PDRIVER_CONTROL ExecutionRoutine) + PDRIVER_CONTROL ExecutionRoutine, + PVOID Context ) { - UNIMPLEMENTED; + KIRQL OldIrql; + PVOID Buffer; + int ret; + LARGE_INTEGER MaxAddress; + + MaxAddress.QuadPart = 0x1000000; + Buffer = MmAllocateContiguousAlignedMemory( NumberOfMapRegisters * PAGESIZE, + MaxAddress, + 0x10000 ); + if( !Buffer ) + return STATUS_INSUFFICIENT_RESOURCES; + KeAcquireSpinLock( &AdapterObject->SpinLock, &OldIrql ); + if( AdapterObject->Inuse ) + { + // someone is already using it, we need to wait + // create a wait block, and add it to the chain + UNIMPLEMENTED; + } + else { + AdapterObject->Inuse = TRUE; + KeReleaseSpinLock( &AdapterObject->SpinLock, OldIrql ); + ret = ExecutionRoutine( DeviceObject, + NULL, + Buffer, + Context ); + KeAcquireSpinLock( &AdapterObject->SpinLock, &OldIrql ); + if( ret == DeallocateObject ) + { + MmFreeContiguousMemory( Buffer ); + AdapterObject->Inuse = FALSE; + } + else AdapterObject->Buffer = Buffer; + } + KeReleaseSpinLock( &AdapterObject->SpinLock, OldIrql ); + return STATUS_SUCCESS; } @@ -37,14 +73,31 @@ IoFlushAdapterBuffers (PADAPTER_OBJECT AdapterObject, ULONG Length, BOOLEAN WriteToDevice) { - UNIMPLEMENTED; + // if this was a read from device, copy data back to caller buffer, otherwise, do nothing + if( !WriteToDevice ) + memcpy( MmGetSystemAddressForMdl( Mdl ), MapRegisterBase, Length ); + return TRUE; } VOID STDCALL IoFreeAdapterChannel (PADAPTER_OBJECT AdapterObject) { - UNIMPLEMENTED; + KIRQL OldIrql; + + KeAcquireSpinLock( &AdapterObject->SpinLock, &OldIrql ); + if( AdapterObject->Inuse == FALSE ) + { + DbgPrint( "Attempting to IoFreeAdapterChannel on a channel not in use\n" ); + KeBugCheck(0); + } + AdapterObject->Inuse = FALSE; + if( AdapterObject->Buffer ) + { + MmFreeContiguousMemory( AdapterObject->Buffer ); + AdapterObject->Buffer = 0; + } + KeReleaseSpinLock( &AdapterObject->SpinLock, OldIrql ); } @@ -65,8 +118,36 @@ IoMapTransfer (PADAPTER_OBJECT AdapterObject, PULONG Length, BOOLEAN WriteToDevice) { - UNIMPLEMENTED; + LARGE_INTEGER Address; + // program up the dma controller, and return + // if it is a write to the device, copy the caller buffer to the low buffer + if( WriteToDevice ) + memcpy( MapRegisterBase, + MmGetSystemAddressForMdl( Mdl ) + ( (DWORD)CurrentVa - (DWORD)MmGetMdlVirtualAddress( Mdl ) ), + *Length ); + // port 0xA is the dma mask register, or a 0x10 on to the channel number to mask it + WRITE_PORT_UCHAR( (PVOID)0x0A, AdapterObject->Channel | 0x10 ); + // write zero to the reset register + WRITE_PORT_UCHAR( (PVOID)0x0C, 0 ); + // mode register, or channel with 0x4 for write memory, 0x8 for read memory, 0x10 for non auto initialize + WRITE_PORT_UCHAR( (PVOID)0x0B, AdapterObject->Channel | ( WriteToDevice ? 0x8 : 0x4 ) ); + // set the 64k page register for the channel + WRITE_PORT_UCHAR( AdapterObject->PagePort, (UCHAR)(((ULONG)MapRegisterBase)>>16) ); + // low, then high address byte, which is always 0 for us, because we have a 64k alligned address + WRITE_PORT_UCHAR( AdapterObject->OffsetPort, 0 ); + WRITE_PORT_UCHAR( AdapterObject->OffsetPort, 0 ); + // count is 1 less than length, low then high + WRITE_PORT_UCHAR( AdapterObject->CountPort, (UCHAR)(*Length - 1) ); + WRITE_PORT_UCHAR( AdapterObject->CountPort, (UCHAR)((*Length - 1)>>8) ); + // unmask the channel to let it rip + WRITE_PORT_UCHAR( (PVOID)0x0A, AdapterObject->Channel ); + Address.QuadPart = (DWORD)MapRegisterBase; + return Address; } /* EOF */ + + + + diff --git a/reactos/ntoskrnl/hal/x86/dma.c b/reactos/ntoskrnl/hal/x86/dma.c index 50e0d83e440..fd7cbc78f3f 100644 --- a/reactos/ntoskrnl/hal/x86/dma.c +++ b/reactos/ntoskrnl/hal/x86/dma.c @@ -1,4 +1,4 @@ -/* $Id: dma.c,v 1.9 2000/12/30 01:41:29 ekohl Exp $ +/* $Id: dma.c,v 1.10 2001/03/31 15:58:24 phreak Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -14,6 +14,14 @@ #include #include +#include + +ADAPTER_OBJECT AdapterObjects[] = { + { 0, (PVOID)0x87, (PVOID)0x1, (PVOID)0x0, { 0 }, NULL }, + { 1, (PVOID)0x83, (PVOID)0x3, (PVOID)0x2, { 0 }, NULL }, + { 2, (PVOID)0x81, (PVOID)0x5, (PVOID)0x4, { 0 }, NULL }, + { 3, (PVOID)0x82, (PVOID)0x7, (PVOID)0x6, { 0 }, NULL } }; + /* FUNCTIONS *****************************************************************/ @@ -67,9 +75,9 @@ HalGetAdapter (PDEVICE_DESCRIPTION DeviceDescription, PULONG NumberOfMapRegisters) /* * FUNCTION: Returns a pointer to an adapter object for the DMA device - * defined the device description structure + * defined in the device description structure * ARGUMENTS: - * DeviceObject = Structure describing the attributes of the device + * DeviceDescription = Structure describing the attributes of the device * NumberOfMapRegisters (OUT) = Returns the maximum number of map * registers the device driver can * allocate for DMA transfer operations @@ -77,10 +85,27 @@ HalGetAdapter (PDEVICE_DESCRIPTION DeviceDescription, * NULL on failure */ { - UNIMPLEMENTED; + /* Validate parameters in device description, and return a pointer to + the adapter object for the requested dma channel */ + if( DeviceDescription->Version != DEVICE_DESCRIPTION_VERSION ) + return NULL; + if( DeviceDescription->Master ) + return NULL; + if( DeviceDescription->ScatterGather ) + return NULL; + if( DeviceDescription->AutoInitialize ) + return NULL; + if( DeviceDescription->Dma32BitAddress ) + return NULL; + if( DeviceDescription->InterfaceType != Isa ) + return NULL; + /* if( DeviceDescription->DmaWidth != Width8Bits ) + return NULL;*/ + *NumberOfMapRegisters = 0x10; + AdapterObjects[DeviceDescription->DmaChannel].Buffer = 0; + return &AdapterObjects[DeviceDescription->DmaChannel]; } - ULONG STDCALL HalReadDmaCounter (PADAPTER_OBJECT AdapterObject) { diff --git a/reactos/ntoskrnl/include/internal/i386/hal.h b/reactos/ntoskrnl/include/internal/i386/hal.h new file mode 100644 index 00000000000..960cab66fe7 --- /dev/null +++ b/reactos/ntoskrnl/include/internal/i386/hal.h @@ -0,0 +1,45 @@ +/* + * + */ + +#ifndef __INTERNAL_HAL_HAL_H +#define __INTERNAL_HAL_HAL_H + +#include +#include + +/* + * FUNCTION: Probes for a BIOS32 extension + */ +VOID Hal_bios32_probe(VOID); + +/* + * FUNCTION: Determines if a a bios32 service is present + */ +BOOLEAN Hal_bios32_is_service_present(ULONG service); + +VOID HalInitializeDisplay (PLOADER_PARAMETER_BLOCK LoaderBlock); +VOID HalResetDisplay (VOID); + +VOID HalpInitBusHandlers (VOID); + +/* irql.c */ +VOID HalpInitPICs(VOID); + +/* udelay.c */ +VOID HalpCalibrateStallExecution(VOID); + +/* pci.c */ +VOID HalpInitPciBus (VOID); + +struct _ADAPTER_OBJECT { + int Channel; + PVOID PagePort; + PVOID CountPort; + PVOID OffsetPort; + KSPIN_LOCK SpinLock; + PVOID Buffer; + BOOLEAN Inuse; +}; + +#endif /* __INTERNAL_HAL_HAL_H */ diff --git a/reactos/ntoskrnl/io/adapter.c b/reactos/ntoskrnl/io/adapter.c index be8f0771a40..ae3e6fc3b5b 100644 --- a/reactos/ntoskrnl/io/adapter.c +++ b/reactos/ntoskrnl/io/adapter.c @@ -1,4 +1,4 @@ -/* $Id: adapter.c,v 1.4 2000/07/19 14:18:18 dwelch Exp $ +/* $Id: adapter.c,v 1.5 2001/03/31 15:58:24 phreak Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -30,7 +30,11 @@ IoAllocateAdapterChannel (PADAPTER_OBJECT AdapterObject, PDRIVER_CONTROL ExecutionRoutine, PVOID Context) { - UNIMPLEMENTED; + return HalAllocateAdapterChannel( AdapterObject, + DeviceObject, + NumberOfMapRegisters, + ExecutionRoutine, + Context ); } diff --git a/reactos/ntoskrnl/ntoskrnl.def b/reactos/ntoskrnl/ntoskrnl.def index a1d18369902..d77bc1c3890 100644 --- a/reactos/ntoskrnl/ntoskrnl.def +++ b/reactos/ntoskrnl/ntoskrnl.def @@ -1,4 +1,4 @@ -; $Id: ntoskrnl.def,v 1.101 2001/03/25 02:34:27 dwelch Exp $ +; $Id: ntoskrnl.def,v 1.102 2001/03/31 15:58:23 phreak Exp $ ; ; reactos/ntoskrnl/ntoskrnl.def ; @@ -1014,7 +1014,7 @@ ExTryToAcquireFastMutex@4 HalAcquireDisplayOwnership@4 HalAdjustResourceList@4 HalAllProcessorsStarted@0 -HalAllocateAdapterChannel@16 +HalAllocateAdapterChannel@20 HalAllocateCommonBuffer@16 ;HalAllocateCrashDumpRegisters@8 HalAssignSlotResources@32 diff --git a/reactos/ntoskrnl/ntoskrnl.edf b/reactos/ntoskrnl/ntoskrnl.edf index e7f04f7a701..1f60dde9d6e 100644 --- a/reactos/ntoskrnl/ntoskrnl.edf +++ b/reactos/ntoskrnl/ntoskrnl.edf @@ -1,4 +1,4 @@ -; $Id: ntoskrnl.edf,v 1.88 2001/03/25 02:34:27 dwelch Exp $ +; $Id: ntoskrnl.edf,v 1.89 2001/03/31 15:58:24 phreak Exp $ ; ; reactos/ntoskrnl/ntoskrnl.def ; @@ -1012,7 +1012,7 @@ ExTryToAcquireFastMutex=ExTryToAcquireFastMutex@4 HalAcquireDisplayOwnership=HalAcquireDisplayOwnership@4 HalAdjustResourceList=HalAdjustResourceList@4 HalAllProcessorsStarted=HalAllProcessorsStarted@0 -HalAllocateAdapterChannel=HalAllocateAdapterChannel@16 +HalAllocateAdapterChannel=HalAllocateAdapterChannel@20 HalAllocateCommonBuffer=HalAllocateCommonBuffer@16 ;HalAllocateCrashDumpRegisters=HalAllocateCrashDumpRegisters@8 HalAssignSlotResource=HalAssignSlotResources@32