From d8f25b3cb81ac15bfd52932c6832d7e5d6b949a3 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Wed, 13 Jun 2001 22:17:01 +0000 Subject: [PATCH] Implemented access to PCI configuration space svn path=/trunk/; revision=1967 --- reactos/ntoskrnl/hal/x86/bus.c | 865 ++++++++------------ reactos/ntoskrnl/hal/x86/isa.c | 51 +- reactos/ntoskrnl/hal/x86/pci.c | 674 +++++++++------ reactos/ntoskrnl/hal/x86/sysbus.c | 74 +- reactos/ntoskrnl/include/internal/hal/bus.h | 104 +++ 5 files changed, 942 insertions(+), 826 deletions(-) create mode 100644 reactos/ntoskrnl/include/internal/hal/bus.h diff --git a/reactos/ntoskrnl/hal/x86/bus.c b/reactos/ntoskrnl/hal/x86/bus.c index 3578f076146..c3eb4d0e182 100644 --- a/reactos/ntoskrnl/hal/x86/bus.c +++ b/reactos/ntoskrnl/hal/x86/bus.c @@ -1,4 +1,4 @@ -/* $Id: bus.c,v 1.7 2001/03/16 18:11:21 dwelch Exp $ +/* $Id: bus.c,v 1.8 2001/06/13 22:17:01 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -17,6 +17,7 @@ #include #include +#include #define NDEBUG #include @@ -25,656 +26,490 @@ #define TAG_BUS TAG('B', 'U', 'S', 'H') -/* TYPE DEFINITIONS *********************************************************/ - - -struct _BUS_HANDLER; - -typedef NTSTATUS (STDCALL *pAdjustResourceList) ( - IN struct _BUS_HANDLER *BusHandler, - IN ULONG BusNumber, - IN OUT PCM_RESOURCE_LIST Resources - ); - -typedef NTSTATUS (STDCALL *pAssignSlotResources) ( - IN struct _BUS_HANDLER *BusHandler, - IN ULONG BusNumber, - IN PUNICODE_STRING RegistryPath, - IN PUNICODE_STRING DriverClassName, - IN PDRIVER_OBJECT DriverObject, - IN PDEVICE_OBJECT DeviceObject, - IN ULONG SlotNumber, - IN OUT PCM_RESOURCE_LIST *AllocatedResources - ); - -typedef ULONG (STDCALL *pGetSetBusData) ( - IN struct _BUS_HANDLER *BusHandler, - IN ULONG BusNumber, - IN ULONG SlotNumber, - OUT PVOID Buffer, - IN ULONG Offset, - IN ULONG Length - ); - -typedef ULONG (STDCALL *pGetInterruptVector) ( - IN struct _BUS_HANDLER *BusHandler, - IN ULONG BusNumber, - IN ULONG BusInterruptLevel, - IN ULONG BusInterruptVector, - OUT PKIRQL Irql, - OUT PKAFFINITY Affinity - ); - -typedef ULONG (STDCALL *pTranslateBusAddress) ( - IN struct _BUS_HANDLER *BusHandler, - IN ULONG BusNumber, - IN PHYSICAL_ADDRESS BusAddress, - IN OUT PULONG AddressSpace, - OUT PPHYSICAL_ADDRESS TranslatedAddress - ); - -typedef struct _BUS_HANDLER -{ - LIST_ENTRY Entry; - INTERFACE_TYPE InterfaceType; - BUS_DATA_TYPE BusDataType; - ULONG BusNumber; - ULONG RefCount; - - pGetSetBusData GetBusData; - pGetSetBusData SetBusData; - pAdjustResourceList AdjustResourceList; - pAssignSlotResources AssignSlotResources; - pGetInterruptVector GetInterruptVector; - pTranslateBusAddress TranslateBusAddress; - -} BUS_HANDLER, *PBUS_HANDLER; - - -/* sysbus.h */ -ULONG -STDCALL -HalpGetSystemInterruptVector ( - PVOID BusHandler, - ULONG BusNumber, - ULONG BusInterruptLevel, - ULONG BusInterruptVector, - PKIRQL Irql, - PKAFFINITY Affinity - ); - -BOOLEAN -STDCALL -HalpTranslateSystemBusAddress ( - PBUS_HANDLER BusHandler, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress - ); - -/* isa.c */ -BOOLEAN -STDCALL -HalpTranslateIsaBusAddress ( - PBUS_HANDLER BusHandler, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress - ); - - -/* GLOBAL VARIABLES **********************************************************/ - KSPIN_LOCK HalpBusHandlerSpinLock = {0,}; LIST_ENTRY HalpBusHandlerList; /* FUNCTIONS *****************************************************************/ -static -NTSTATUS -STDCALL -HalpNoAdjustResourceList ( - PBUS_HANDLER BusHandler, - ULONG BusNumber, - PCM_RESOURCE_LIST Resources - ) +static NTSTATUS STDCALL +HalpNoAdjustResourceList(PBUS_HANDLER BusHandler, + ULONG BusNumber, + PCM_RESOURCE_LIST Resources) { - return STATUS_UNSUCCESSFUL; + return STATUS_UNSUCCESSFUL; } -static -NTSTATUS -STDCALL -HalpNoAssignSlotResources ( - PBUS_HANDLER BusHandler, - ULONG BusNumber, - PUNICODE_STRING RegistryPath, - PUNICODE_STRING DriverClassName, - PDRIVER_OBJECT DriverObject, - PDEVICE_OBJECT DeviceObject, - ULONG SlotNumber, - PCM_RESOURCE_LIST *AllocatedResources - ) +static NTSTATUS STDCALL +HalpNoAssignSlotResources(PBUS_HANDLER BusHandler, + ULONG BusNumber, + PUNICODE_STRING RegistryPath, + PUNICODE_STRING DriverClassName, + PDRIVER_OBJECT DriverObject, + PDEVICE_OBJECT DeviceObject, + ULONG SlotNumber, + PCM_RESOURCE_LIST *AllocatedResources) { - return STATUS_NOT_SUPPORTED; + return STATUS_NOT_SUPPORTED; } -static -ULONG -STDCALL -HalpNoBusData ( - PBUS_HANDLER BusHandler, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length - ) +static ULONG STDCALL +HalpNoBusData(PBUS_HANDLER BusHandler, + ULONG BusNumber, + ULONG SlotNumber, + PVOID Buffer, + ULONG Offset, + ULONG Length) { - return 0; + return 0; } -static -ULONG -STDCALL -HalpNoGetInterruptVector ( - PBUS_HANDLER BusHandler, - ULONG BusNumber, - ULONG BusInterruptLevel, - ULONG BusInterruptVector, - PKIRQL Irql, - PKAFFINITY Affinity - ) +static ULONG STDCALL +HalpNoGetInterruptVector(PBUS_HANDLER BusHandler, + ULONG BusNumber, + ULONG BusInterruptLevel, + ULONG BusInterruptVector, + PKIRQL Irql, + PKAFFINITY Affinity) { - return 0; + return 0; } -static -ULONG -STDCALL -HalpNoTranslateBusAddress ( - PBUS_HANDLER BusHandler, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress - ) +static ULONG STDCALL +HalpNoTranslateBusAddress(PBUS_HANDLER BusHandler, + ULONG BusNumber, + PHYSICAL_ADDRESS BusAddress, + PULONG AddressSpace, + PPHYSICAL_ADDRESS TranslatedAddress) { - return 0; + return 0; } PBUS_HANDLER -HalpAllocateBusHandler ( - INTERFACE_TYPE InterfaceType, - BUS_DATA_TYPE BusDataType, - ULONG BusNumber - ) +HalpAllocateBusHandler(INTERFACE_TYPE InterfaceType, + BUS_DATA_TYPE BusDataType, + ULONG BusNumber) { - PBUS_HANDLER BusHandler = NULL; + PBUS_HANDLER BusHandler = NULL; - DPRINT("HalpAllocateBusHandler()\n"); + DPRINT("HalpAllocateBusHandler()\n"); - BusHandler = - ExAllocatePoolWithTag(NonPagedPool, sizeof(BUS_HANDLER), TAG_BUS); - if (BusHandler == NULL) - return NULL; + BusHandler = ExAllocatePoolWithTag(NonPagedPool, + sizeof(BUS_HANDLER), + TAG_BUS); + if (BusHandler == NULL) + return NULL; - RtlZeroMemory (BusHandler, sizeof(BUS_HANDLER)); + RtlZeroMemory(BusHandler, + sizeof(BUS_HANDLER)); - InsertTailList (&HalpBusHandlerList, - &BusHandler->Entry); + InsertTailList(&HalpBusHandlerList, + &BusHandler->Entry); - BusHandler->InterfaceType = InterfaceType; - BusHandler->BusDataType = BusDataType; - BusHandler->BusNumber = BusNumber; + BusHandler->InterfaceType = InterfaceType; + BusHandler->BusDataType = BusDataType; + BusHandler->BusNumber = BusNumber; - /* initialize default bus handler functions */ - BusHandler->GetBusData = HalpNoBusData; - BusHandler->SetBusData = HalpNoBusData; - BusHandler->AdjustResourceList = HalpNoAdjustResourceList; - BusHandler->AssignSlotResources = HalpNoAssignSlotResources; - BusHandler->GetInterruptVector = HalpNoGetInterruptVector; - BusHandler->TranslateBusAddress = HalpNoTranslateBusAddress; + /* initialize default bus handler functions */ + BusHandler->GetBusData = HalpNoBusData; + BusHandler->SetBusData = HalpNoBusData; + BusHandler->AdjustResourceList = HalpNoAdjustResourceList; + BusHandler->AssignSlotResources = HalpNoAssignSlotResources; + BusHandler->GetInterruptVector = HalpNoGetInterruptVector; + BusHandler->TranslateBusAddress = HalpNoTranslateBusAddress; - /* any more ?? */ + /* any more ?? */ - DPRINT("HalpAllocateBusHandler() done\n"); + DPRINT("HalpAllocateBusHandler() done\n"); - return BusHandler; + return BusHandler; } VOID -HalpInitBusHandlers (VOID) +HalpInitBusHandlers(VOID) { - PBUS_HANDLER BusHandler; + PBUS_HANDLER BusHandler; - /* general preparations */ - KeInitializeSpinLock (&HalpBusHandlerSpinLock); - InitializeListHead (&HalpBusHandlerList); + /* general preparations */ + KeInitializeSpinLock(&HalpBusHandlerSpinLock); + InitializeListHead(&HalpBusHandlerList); - /* initialize hal dispatch tables */ + /* initialize hal dispatch tables */ #if 0 - HalDispatchTable->HalQueryBusSlots = HaliQueryBusSlots; + HalDispatchTable->HalQueryBusSlots = HaliQueryBusSlots; #endif - /* - * add bus handlers - */ + /* add system bus handler */ + BusHandler = HalpAllocateBusHandler(Internal, + ConfigurationSpaceUndefined, + 0); + if (BusHandler == NULL) + return; + BusHandler->GetInterruptVector = + (pGetInterruptVector)HalpGetSystemInterruptVector; + BusHandler->TranslateBusAddress = + (pTranslateBusAddress)HalpTranslateSystemBusAddress; - /* system bus handler */ - BusHandler = HalpAllocateBusHandler (Internal, - ConfigurationSpaceUndefined, - 0); - BusHandler->GetInterruptVector = - (pGetInterruptVector)HalpGetSystemInterruptVector; - BusHandler->TranslateBusAddress = - (pTranslateBusAddress)HalpTranslateSystemBusAddress; + /* add cmos bus handler */ + BusHandler = HalpAllocateBusHandler(InterfaceTypeUndefined, + Cmos, + 0); + if (BusHandler == NULL) + return; +// BusHandler->GetBusData = (pGetSetBusData)HalpGetCmosData; +// BusHandler->SetBusData = (pGetSetBusData)HalpSetCmosData; - /* cmos bus handler */ - BusHandler = HalpAllocateBusHandler (InterfaceTypeUndefined, - Cmos, - 0); -// BusHandler->GetBusData = -// (pGetSetBusData)HalpGetCmosData; -// BusHandler->SetBusData = -// (pGetSetBusData)HalpSetCmosData; + /* add isa bus handler */ + BusHandler = HalpAllocateBusHandler(Isa, + ConfigurationSpaceUndefined, + 0); + if (BusHandler == NULL) + return; - /* isa bus handler */ - BusHandler = HalpAllocateBusHandler (Isa, - ConfigurationSpaceUndefined, - 0); - BusHandler->TranslateBusAddress = - (pTranslateBusAddress)HalpTranslateIsaBusAddress; - -#if 0 - /* pci bus handler */ - BusHandler = HalpAllocateBusHandler (PCIBus, - PCIConfiguration, - 0); -// BusHandler->GetBusData = -// (pGetSetBusData)HalpGetPciData; -// BusHandler->SetBusData = -// (pGetSetBusData)HalpSetPciData; -// BusHandler->GetInterruptVector = -// (pGetInterruptVector)HalpGetPciInterruptVector; -// BusHandler->AdjustResourceList = -// (pGetSetBusData)HalpAdjustPciResourceList; -// BusHandler->AssignSlotResources = -// (pGetSetBusData)HalpAssignPciSlotResources; -#endif + BusHandler->TranslateBusAddress = + (pTranslateBusAddress)HalpTranslateIsaBusAddress; } -PBUS_HANDLER -FASTCALL -HaliHandlerForBus ( - INTERFACE_TYPE InterfaceType, - ULONG BusNumber - ) +PBUS_HANDLER FASTCALL +HaliHandlerForBus(INTERFACE_TYPE InterfaceType, + ULONG BusNumber) { - PBUS_HANDLER BusHandler; - PLIST_ENTRY CurrentEntry; - KIRQL OldIrql; + PBUS_HANDLER BusHandler; + PLIST_ENTRY CurrentEntry; + KIRQL OldIrql; - KeAcquireSpinLock (&HalpBusHandlerSpinLock, &OldIrql); + KeAcquireSpinLock(&HalpBusHandlerSpinLock, + &OldIrql); - CurrentEntry = HalpBusHandlerList.Flink; - while (CurrentEntry != &HalpBusHandlerList) - { - BusHandler = (PBUS_HANDLER)CurrentEntry; - if (BusHandler->InterfaceType == InterfaceType && - BusHandler->BusNumber == BusNumber) - { - KeReleaseSpinLock (&HalpBusHandlerSpinLock, OldIrql); - return BusHandler; - } - CurrentEntry = CurrentEntry->Flink; - } - KeReleaseSpinLock (&HalpBusHandlerSpinLock, OldIrql); + CurrentEntry = HalpBusHandlerList.Flink; + while (CurrentEntry != &HalpBusHandlerList) + { + BusHandler = (PBUS_HANDLER)CurrentEntry; + if (BusHandler->InterfaceType == InterfaceType && + BusHandler->BusNumber == BusNumber) + { + KeReleaseSpinLock(&HalpBusHandlerSpinLock, + OldIrql); + return BusHandler; + } + CurrentEntry = CurrentEntry->Flink; + } + KeReleaseSpinLock(&HalpBusHandlerSpinLock, + OldIrql); - return NULL; + return NULL; } -PBUS_HANDLER -FASTCALL -HaliHandlerForConfigSpace ( - BUS_DATA_TYPE BusDataType, - ULONG BusNumber - ) +PBUS_HANDLER FASTCALL +HaliHandlerForConfigSpace(BUS_DATA_TYPE BusDataType, + ULONG BusNumber) { - PBUS_HANDLER BusHandler; - PLIST_ENTRY CurrentEntry; - KIRQL OldIrql; + PBUS_HANDLER BusHandler; + PLIST_ENTRY CurrentEntry; + KIRQL OldIrql; - KeAcquireSpinLock (&HalpBusHandlerSpinLock, &OldIrql); + KeAcquireSpinLock(&HalpBusHandlerSpinLock, + &OldIrql); - CurrentEntry = HalpBusHandlerList.Flink; - while (CurrentEntry != &HalpBusHandlerList) - { - BusHandler = (PBUS_HANDLER)CurrentEntry; - if (BusHandler->BusDataType == BusDataType && - BusHandler->BusNumber == BusNumber) - { - KeReleaseSpinLock (&HalpBusHandlerSpinLock, OldIrql); - return BusHandler; - } - CurrentEntry = CurrentEntry->Flink; - } - KeReleaseSpinLock (&HalpBusHandlerSpinLock, OldIrql); + CurrentEntry = HalpBusHandlerList.Flink; + while (CurrentEntry != &HalpBusHandlerList) + { + BusHandler = (PBUS_HANDLER)CurrentEntry; + if (BusHandler->BusDataType == BusDataType && + BusHandler->BusNumber == BusNumber) + { + KeReleaseSpinLock(&HalpBusHandlerSpinLock, + OldIrql); + return BusHandler; + } + CurrentEntry = CurrentEntry->Flink; + } + KeReleaseSpinLock(&HalpBusHandlerSpinLock, + OldIrql); - return NULL; + return NULL; } -PBUS_HANDLER -FASTCALL -HaliReferenceHandlerForBus ( - INTERFACE_TYPE InterfaceType, - ULONG BusNumber - ) +PBUS_HANDLER FASTCALL +HaliReferenceHandlerForBus(INTERFACE_TYPE InterfaceType, + ULONG BusNumber) { - PBUS_HANDLER BusHandler; - PLIST_ENTRY CurrentEntry; - KIRQL OldIrql; + PBUS_HANDLER BusHandler; + PLIST_ENTRY CurrentEntry; + KIRQL OldIrql; - KeAcquireSpinLock (&HalpBusHandlerSpinLock, &OldIrql); + KeAcquireSpinLock(&HalpBusHandlerSpinLock, + &OldIrql); - CurrentEntry = HalpBusHandlerList.Flink; - while (CurrentEntry != &HalpBusHandlerList) - { - BusHandler = (PBUS_HANDLER)CurrentEntry; - if (BusHandler->InterfaceType == InterfaceType && - BusHandler->BusNumber == BusNumber) - { - BusHandler->RefCount++; - KeReleaseSpinLock (&HalpBusHandlerSpinLock, OldIrql); - return BusHandler; - } - CurrentEntry = CurrentEntry->Flink; - } - KeReleaseSpinLock (&HalpBusHandlerSpinLock, OldIrql); + CurrentEntry = HalpBusHandlerList.Flink; + while (CurrentEntry != &HalpBusHandlerList) + { + BusHandler = (PBUS_HANDLER)CurrentEntry; + if (BusHandler->InterfaceType == InterfaceType && + BusHandler->BusNumber == BusNumber) + { + BusHandler->RefCount++; + KeReleaseSpinLock(&HalpBusHandlerSpinLock, + OldIrql); + return BusHandler; + } + CurrentEntry = CurrentEntry->Flink; + } + KeReleaseSpinLock(&HalpBusHandlerSpinLock, + OldIrql); - return NULL; + return NULL; } -PBUS_HANDLER -FASTCALL -HaliReferenceHandlerForConfigSpace ( - BUS_DATA_TYPE BusDataType, - ULONG BusNumber - ) +PBUS_HANDLER FASTCALL +HaliReferenceHandlerForConfigSpace(BUS_DATA_TYPE BusDataType, + ULONG BusNumber) { - PBUS_HANDLER BusHandler; - PLIST_ENTRY CurrentEntry; - KIRQL OldIrql; + PBUS_HANDLER BusHandler; + PLIST_ENTRY CurrentEntry; + KIRQL OldIrql; - KeAcquireSpinLock (&HalpBusHandlerSpinLock, &OldIrql); + KeAcquireSpinLock(&HalpBusHandlerSpinLock, + &OldIrql); - CurrentEntry = HalpBusHandlerList.Flink; - while (CurrentEntry != &HalpBusHandlerList) - { - BusHandler = (PBUS_HANDLER)CurrentEntry; - if (BusHandler->BusDataType == BusDataType && - BusHandler->BusNumber == BusNumber) - { - BusHandler->RefCount++; - KeReleaseSpinLock (&HalpBusHandlerSpinLock, OldIrql); - return BusHandler; - } - CurrentEntry = CurrentEntry->Flink; - } - KeReleaseSpinLock (&HalpBusHandlerSpinLock, OldIrql); + CurrentEntry = HalpBusHandlerList.Flink; + while (CurrentEntry != &HalpBusHandlerList) + { + BusHandler = (PBUS_HANDLER)CurrentEntry; + if (BusHandler->BusDataType == BusDataType && + BusHandler->BusNumber == BusNumber) + { + BusHandler->RefCount++; + KeReleaseSpinLock(&HalpBusHandlerSpinLock, + OldIrql); + return BusHandler; + } + CurrentEntry = CurrentEntry->Flink; + } + KeReleaseSpinLock(&HalpBusHandlerSpinLock, + OldIrql); - return NULL; + return NULL; } -VOID -FASTCALL -HaliDereferenceBusHandler ( - PBUS_HANDLER BusHandler - ) +VOID FASTCALL +HaliDereferenceBusHandler(PBUS_HANDLER BusHandler) { - KIRQL OldIrql; + KIRQL OldIrql; - KeAcquireSpinLock (&HalpBusHandlerSpinLock, &OldIrql); - - BusHandler->RefCount--; - - KeReleaseSpinLock (&HalpBusHandlerSpinLock, OldIrql); + KeAcquireSpinLock(&HalpBusHandlerSpinLock, + &OldIrql); + BusHandler->RefCount--; + KeReleaseSpinLock(&HalpBusHandlerSpinLock, + OldIrql); } -NTSTATUS -STDCALL -HalAdjustResourceList ( - PCM_RESOURCE_LIST Resources - ) +NTSTATUS STDCALL +HalAdjustResourceList(PCM_RESOURCE_LIST Resources) { - PBUS_HANDLER BusHandler; - NTSTATUS Status; + PBUS_HANDLER BusHandler; + NTSTATUS Status; - BusHandler = HaliReferenceHandlerForBus (Resources->List[0].InterfaceType, - Resources->List[0].BusNumber); - if (BusHandler == NULL) - return STATUS_SUCCESS; + BusHandler = HaliReferenceHandlerForBus(Resources->List[0].InterfaceType, + Resources->List[0].BusNumber); + if (BusHandler == NULL) + return STATUS_SUCCESS; - Status = BusHandler->AdjustResourceList (BusHandler, - Resources->List[0].BusNumber, - Resources); + Status = BusHandler->AdjustResourceList(BusHandler, + Resources->List[0].BusNumber, + Resources); + HaliDereferenceBusHandler (BusHandler); - HaliDereferenceBusHandler (BusHandler); - - return Status; + return Status; } -NTSTATUS -STDCALL -HalAssignSlotResources ( - PUNICODE_STRING RegistryPath, - PUNICODE_STRING DriverClassName, - PDRIVER_OBJECT DriverObject, - PDEVICE_OBJECT DeviceObject, - INTERFACE_TYPE BusType, - ULONG BusNumber, - ULONG SlotNumber, - PCM_RESOURCE_LIST *AllocatedResources - ) +NTSTATUS STDCALL +HalAssignSlotResources(PUNICODE_STRING RegistryPath, + PUNICODE_STRING DriverClassName, + PDRIVER_OBJECT DriverObject, + PDEVICE_OBJECT DeviceObject, + INTERFACE_TYPE BusType, + ULONG BusNumber, + ULONG SlotNumber, + PCM_RESOURCE_LIST *AllocatedResources) { - PBUS_HANDLER BusHandler; - NTSTATUS Status; + PBUS_HANDLER BusHandler; + NTSTATUS Status; - BusHandler = HaliReferenceHandlerForBus (BusType, - BusNumber); - if (BusHandler == NULL) - return STATUS_NOT_FOUND; + BusHandler = HaliReferenceHandlerForBus(BusType, + BusNumber); + if (BusHandler == NULL) + return STATUS_NOT_FOUND; - Status = BusHandler->AssignSlotResources (BusHandler, - BusNumber, - RegistryPath, - DriverClassName, - DriverObject, - DeviceObject, - SlotNumber, - AllocatedResources); + Status = BusHandler->AssignSlotResources(BusHandler, + BusNumber, + RegistryPath, + DriverClassName, + DriverObject, + DeviceObject, + SlotNumber, + AllocatedResources); - HaliDereferenceBusHandler (BusHandler); + HaliDereferenceBusHandler(BusHandler); - return Status; + return Status; } -ULONG -STDCALL -HalGetBusData ( - BUS_DATA_TYPE BusDataType, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Length - ) +ULONG STDCALL +HalGetBusData(BUS_DATA_TYPE BusDataType, + ULONG BusNumber, + ULONG SlotNumber, + PVOID Buffer, + ULONG Length) { - return (HalGetBusDataByOffset (BusDataType, - BusNumber, - SlotNumber, - Buffer, - 0, - Length)); + return (HalGetBusDataByOffset(BusDataType, + BusNumber, + SlotNumber, + Buffer, + 0, + Length)); } -ULONG -STDCALL -HalGetBusDataByOffset ( - BUS_DATA_TYPE BusDataType, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length - ) +ULONG STDCALL +HalGetBusDataByOffset(BUS_DATA_TYPE BusDataType, + ULONG BusNumber, + ULONG SlotNumber, + PVOID Buffer, + ULONG Offset, + ULONG Length) { - PBUS_HANDLER BusHandler; - ULONG Result; + PBUS_HANDLER BusHandler; + ULONG Result; - BusHandler = HaliReferenceHandlerForConfigSpace (BusDataType, - BusNumber); - if (BusHandler == NULL) - return 0; + BusHandler = HaliReferenceHandlerForConfigSpace(BusDataType, + BusNumber); + if (BusHandler == NULL) + return 0; - Result = BusHandler->GetBusData (BusHandler, - BusNumber, - SlotNumber, - Buffer, - Offset, - Length); + Result = BusHandler->GetBusData(BusHandler, + BusNumber, + SlotNumber, + Buffer, + Offset, + Length); - HaliDereferenceBusHandler (BusHandler); + HaliDereferenceBusHandler (BusHandler); - return Result; + return Result; } -ULONG -STDCALL -HalGetInterruptVector ( - INTERFACE_TYPE InterfaceType, - ULONG BusNumber, - ULONG BusInterruptLevel, - ULONG BusInterruptVector, - PKIRQL Irql, - PKAFFINITY Affinity - ) +ULONG STDCALL +HalGetInterruptVector(INTERFACE_TYPE InterfaceType, + ULONG BusNumber, + ULONG BusInterruptLevel, + ULONG BusInterruptVector, + PKIRQL Irql, + PKAFFINITY Affinity) { - PBUS_HANDLER BusHandler; - ULONG Result; + PBUS_HANDLER BusHandler; + ULONG Result; - BusHandler = HaliReferenceHandlerForBus (InterfaceType, - BusNumber); - if (BusHandler == NULL) - return 0; + BusHandler = HaliReferenceHandlerForBus(InterfaceType, + BusNumber); + if (BusHandler == NULL) + return 0; - Result = BusHandler->GetInterruptVector (BusHandler, - BusNumber, - BusInterruptLevel, - BusInterruptVector, - Irql, - Affinity); + Result = BusHandler->GetInterruptVector(BusHandler, + BusNumber, + BusInterruptLevel, + BusInterruptVector, + Irql, + Affinity); - HaliDereferenceBusHandler (BusHandler); + HaliDereferenceBusHandler(BusHandler); - return Result; + return Result; } -ULONG -STDCALL -HalSetBusData ( - BUS_DATA_TYPE BusDataType, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Length - ) +ULONG STDCALL +HalSetBusData(BUS_DATA_TYPE BusDataType, + ULONG BusNumber, + ULONG SlotNumber, + PVOID Buffer, + ULONG Length) { - return (HalSetBusDataByOffset (BusDataType, - BusNumber, - SlotNumber, - Buffer, - 0, - Length)); + return (HalSetBusDataByOffset(BusDataType, + BusNumber, + SlotNumber, + Buffer, + 0, + Length)); } -ULONG -STDCALL -HalSetBusDataByOffset ( - BUS_DATA_TYPE BusDataType, - ULONG BusNumber, - ULONG SlotNumber, - PVOID Buffer, - ULONG Offset, - ULONG Length - ) +ULONG STDCALL +HalSetBusDataByOffset(BUS_DATA_TYPE BusDataType, + ULONG BusNumber, + ULONG SlotNumber, + PVOID Buffer, + ULONG Offset, + ULONG Length) { - PBUS_HANDLER BusHandler; - ULONG Result; + PBUS_HANDLER BusHandler; + ULONG Result; - BusHandler = HaliReferenceHandlerForConfigSpace (BusDataType, - BusNumber); - if (BusHandler == NULL) - return 0; + BusHandler = HaliReferenceHandlerForConfigSpace(BusDataType, + BusNumber); + if (BusHandler == NULL) + return 0; - Result = BusHandler->SetBusData (BusHandler, - BusNumber, - SlotNumber, - Buffer, - Offset, - Length); + Result = BusHandler->SetBusData(BusHandler, + BusNumber, + SlotNumber, + Buffer, + Offset, + Length); - HaliDereferenceBusHandler (BusHandler); + HaliDereferenceBusHandler(BusHandler); - return Result; + return Result; } -BOOLEAN -STDCALL -HalTranslateBusAddress ( - INTERFACE_TYPE InterfaceType, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress - ) +BOOLEAN STDCALL +HalTranslateBusAddress(INTERFACE_TYPE InterfaceType, + ULONG BusNumber, + PHYSICAL_ADDRESS BusAddress, + PULONG AddressSpace, + PPHYSICAL_ADDRESS TranslatedAddress) { - PBUS_HANDLER BusHandler; - BOOLEAN Result; + PBUS_HANDLER BusHandler; + BOOLEAN Result; - BusHandler = HaliReferenceHandlerForBus (InterfaceType, - BusNumber); - if (BusHandler == NULL) - return FALSE; + BusHandler = HaliReferenceHandlerForBus(InterfaceType, + BusNumber); + if (BusHandler == NULL) + return FALSE; - Result = BusHandler->TranslateBusAddress (BusHandler, - BusNumber, - BusAddress, - AddressSpace, - TranslatedAddress); + Result = BusHandler->TranslateBusAddress(BusHandler, + BusNumber, + BusAddress, + AddressSpace, + TranslatedAddress); - HaliDereferenceBusHandler (BusHandler); + HaliDereferenceBusHandler(BusHandler); - return Result; + return Result; } /* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/isa.c b/reactos/ntoskrnl/hal/x86/isa.c index bdba17544af..eb731b22b60 100644 --- a/reactos/ntoskrnl/hal/x86/isa.c +++ b/reactos/ntoskrnl/hal/x86/isa.c @@ -1,4 +1,4 @@ -/* $Id: isa.c,v 1.6 2000/04/09 15:58:13 ekohl Exp $ +/* $Id: isa.c,v 1.7 2001/06/13 22:17:01 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -12,9 +12,7 @@ /* INCLUDES ***************************************************************/ #include - - -typedef struct _BUS_HANDLER *PBUS_HANDLER; +#include /* FUNCTIONS *****************************************************************/ @@ -36,34 +34,29 @@ BOOL HalIsaProbe(VOID) } -BOOLEAN -STDCALL -HalpTranslateIsaBusAddress ( - PBUS_HANDLER BusHandler, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress - ) +BOOLEAN STDCALL +HalpTranslateIsaBusAddress(PBUS_HANDLER BusHandler, + ULONG BusNumber, + PHYSICAL_ADDRESS BusAddress, + PULONG AddressSpace, + PPHYSICAL_ADDRESS TranslatedAddress) { - BOOLEAN Result; + BOOLEAN Result; - Result = HalTranslateBusAddress (PCIBus, - BusNumber, - BusAddress, - AddressSpace, - TranslatedAddress); + Result = HalTranslateBusAddress(PCIBus, + BusNumber, + BusAddress, + AddressSpace, + TranslatedAddress); + if (Result != FALSE) + return Result; - if (Result != FALSE) - return Result; - - Result = HalTranslateBusAddress (Internal, - BusNumber, - BusAddress, - AddressSpace, - TranslatedAddress); - - return Result; + Result = HalTranslateBusAddress(Internal, + BusNumber, + BusAddress, + AddressSpace, + TranslatedAddress); + return Result; } /* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/pci.c b/reactos/ntoskrnl/hal/x86/pci.c index e05ceddafb6..3918d77e618 100644 --- a/reactos/ntoskrnl/hal/x86/pci.c +++ b/reactos/ntoskrnl/hal/x86/pci.c @@ -1,4 +1,4 @@ -/* $Id: pci.c,v 1.6 2001/03/16 18:11:21 dwelch Exp $ +/* $Id: pci.c,v 1.7 2001/06/13 22:17:01 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -9,294 +9,486 @@ * UPDATE HISTORY: * 05/06/1998: Created * 17/08/2000: Added preliminary pci bus scanner + * 13/06/2001: Implemented access to pci configuration space */ /* * NOTES: Sections copied from the Linux pci support */ -/* INCLUDES ***************************************************************/ +/* INCLUDES *****************************************************************/ #include +#include #define NDEBUG #include -/* MACROS *****************************************************************/ +/* MACROS ******************************************************************/ /* access type 1 macros */ -#define PCI_FUNC(devfn) ((devfn) & 0x07) -#define CONFIG_CMD(bus, device_fn, where) \ +#define PCI_FUNC(devfn) \ + ((devfn) & 0x07) +#define CONFIG_CMD(bus, device_fn, where) \ (0x80000000 | (bus << 16) | (device_fn << 8) | (where & ~3)) +/* access type 2 macros */ +#define IOADDR(devfn, where) \ + ((0xC000 | ((devfn & 0x78) << 5)) + where) +#define FUNC(devfn) \ + (((devfn & 7) << 1) | 0xf0) + + #define PCIBIOS_SUCCESSFUL 0x00 #define PCIBIOS_DEVICE_NOT_FOUND 0x86 #define PCIBIOS_BAD_REGISTER_NUMBER 0x87 -// access type 2 macros -#define IOADDR(devfn, where) ((0xC000 | ((devfn & 0x78) << 5)) + where) -#define FUNC(devfn) (((devfn & 7) << 1) | 0xf0) + +/* GLOBALS ******************************************************************/ + +static ULONG BusConfigType = 0; /* undetermined config type */ -/* FUNCTIONS **************************************************************/ - -/* - * Bus access type 1 (recommended) - */ -static int -ReadPciConfigUcharType1(UCHAR Bus, - UCHAR device_fn, - UCHAR where, - PUCHAR Value) -{ - WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus,device_fn,where)); - *Value = READ_PORT_UCHAR((PUCHAR)0xCFC + (where&3)); - return PCIBIOS_SUCCESSFUL; -} - -#if 0 -static int -ReadPciConfigUshortType1(UCHAR Bus, - UCHAR device_fn, - UCHAR where, - PUSHORT Value) -{ - if ((where & 1) != 0) - { - return PCIBIOS_BAD_REGISTER_NUMBER; - } - - WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus,device_fn,where)); - *value = READ_PORT_USHORT((PUSHORT)0xCFC + (where&1)); - return PCIBIOS_SUCCESSFUL; -} -#endif - -static int -ReadPciConfigUlongType1(UCHAR Bus, - UCHAR device_fn, - UCHAR where, - PULONG Value) -{ - if ((where & 3) != 0) - { - return PCIBIOS_BAD_REGISTER_NUMBER; - } - - WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus,device_fn,where)); - *Value = READ_PORT_ULONG((PULONG)0xCFC); - return PCIBIOS_SUCCESSFUL; -} - -static void -ScanPciBusType1(ULONG Bus) -{ - USHORT dev_fn; - UCHAR hdr_type; - ULONG foo; - - for (dev_fn = 0; dev_fn < 256; dev_fn++) - { - if (PCI_FUNC(dev_fn) == 0) - { - /* 0E=PCI_HEADER_TYPE */ - ReadPciConfigUcharType1(Bus, dev_fn, 0x0E, &hdr_type); - } - else if ((hdr_type & 0x80) == 0) - { - /* not a multi-function device */ - continue; - } - - /* 00=PCI_VENDOR_ID */ - ReadPciConfigUlongType1(Bus, dev_fn, 0x00, &foo); - /* some broken boards return 0 if a slot is empty: */ - if (foo == 0xFFFFFFFF || foo == 0) - { - hdr_type = 0; - continue; - } - - DbgPrint("dev_fn=%3u, Vendor 0x%04lX, Device 0x%04lX\n", - dev_fn, foo & 0xFFFF, (foo >> 16) & 0xFFFF); - } -} +/* FUNCTIONS ****************************************************************/ static NTSTATUS -ScanPciBussesType1(VOID) +ReadPciConfigUchar(UCHAR Bus, + UCHAR Slot, + UCHAR Offset, + PUCHAR Value) { - ULONG i; - ULONG temp; + switch (BusConfigType) + { + case 1: + WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); + *Value = READ_PORT_UCHAR((PUCHAR)0xCFC + (Offset & 3)); + return STATUS_SUCCESS; - DPRINT("ScanPciBussesType1()\n"); + case 2: + WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); + WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); + *Value = READ_PORT_UCHAR((PUCHAR)(IOADDR(Slot, Offset))); + WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); + return STATUS_SUCCESS; + } + return STATUS_UNSUCCESSFUL; +} - DPRINT("Checking if configuration type 1 works\n"); + +static NTSTATUS +ReadPciConfigUshort(UCHAR Bus, + UCHAR Slot, + UCHAR Offset, + PUSHORT Value) +{ + if ((Offset & 1) != 0) + { + return PCIBIOS_BAD_REGISTER_NUMBER; + } + + switch (BusConfigType) + { + case 1: + WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); + *Value = READ_PORT_USHORT((PUSHORT)0xCFC + (Offset & 1)); + return STATUS_SUCCESS; + + case 2: + WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); + WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); + *Value = READ_PORT_USHORT((PUSHORT)(IOADDR(Slot, Offset))); + WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); + return STATUS_SUCCESS; + } + return STATUS_UNSUCCESSFUL; +} + + +static NTSTATUS +ReadPciConfigUlong(UCHAR Bus, + UCHAR Slot, + UCHAR Offset, + PULONG Value) +{ + if ((Offset & 3) != 0) + { + return PCIBIOS_BAD_REGISTER_NUMBER; + } + + switch (BusConfigType) + { + case 1: + WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); + *Value = READ_PORT_ULONG((PULONG)0xCFC); + return STATUS_SUCCESS; + + case 2: + WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); + WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); + *Value = READ_PORT_ULONG((PULONG)(IOADDR(Slot, Offset))); + WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); + return STATUS_SUCCESS; + } + return STATUS_UNSUCCESSFUL; +} + + +static NTSTATUS +WritePciConfigUchar(UCHAR Bus, + UCHAR Slot, + UCHAR Offset, + UCHAR Value) +{ + switch (BusConfigType) + { + case 1: + WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); + WRITE_PORT_UCHAR((PUCHAR)0xCFC + (Offset&3), Value); + return STATUS_SUCCESS; + + case 2: + WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); + WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); + WRITE_PORT_UCHAR((PUCHAR)(IOADDR(Slot,Offset)), Value); + WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); + return STATUS_SUCCESS; + } + return STATUS_UNSUCCESSFUL; +} + + +static NTSTATUS +WritePciConfigUshort(UCHAR Bus, + UCHAR Slot, + UCHAR Offset, + USHORT Value) +{ + if ((Offset & 1) != 0) + { + return PCIBIOS_BAD_REGISTER_NUMBER; + } + + switch (BusConfigType) + { + case 1: + WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); + WRITE_PORT_USHORT((PUSHORT)0xCFC + (Offset & 1), Value); + return STATUS_SUCCESS; + + case 2: + WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); + WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); + WRITE_PORT_USHORT((PUSHORT)(IOADDR(Slot, Offset)), Value); + WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); + return STATUS_SUCCESS; + } + return STATUS_UNSUCCESSFUL; +} + + +static NTSTATUS +WritePciConfigUlong(UCHAR Bus, + UCHAR Slot, + UCHAR Offset, + ULONG Value) +{ + if ((Offset & 3) != 0) + { + return PCIBIOS_BAD_REGISTER_NUMBER; + } + + switch (BusConfigType) + { + case 1: + WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus, Slot, Offset)); + WRITE_PORT_ULONG((PULONG)0xCFC, Value); + return STATUS_SUCCESS; + + case 2: + WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(Slot)); + WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); + WRITE_PORT_ULONG((PULONG)(IOADDR(Slot, Offset)), Value); + WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); + return STATUS_SUCCESS; + } + return STATUS_UNSUCCESSFUL; +} + + +static ULONG STDCALL +HalpGetPciData(PBUS_HANDLER BusHandler, + ULONG BusNumber, + ULONG SlotNumber, + PVOID Buffer, + ULONG Offset, + ULONG Length) +{ + PVOID Ptr = Buffer; + ULONG Address = Offset; + ULONG Len = Length; + ULONG Vendor; + UCHAR HeaderType; + + DPRINT("HalpGetPciData() called.\n"); + DPRINT(" BusNumber %lu\n", BusNumber); + DPRINT(" SlotNumber %lu\n", SlotNumber); + DPRINT(" Offset 0x%lx\n", Offset); + DPRINT(" Length 0x%lx\n", Length); + + if ((Length == 0) || (BusConfigType == 0)) + return 0; + + /* 0E=PCI_HEADER_TYPE */ + ReadPciConfigUchar(BusNumber, + SlotNumber & 0xF8, + 0x0E, + &HeaderType); + if (((HeaderType & 0x80) == 0) && ((SlotNumber & 0x07) != 0)) + return 0; + + ReadPciConfigUlong(BusNumber, + SlotNumber, + 0x00, + &Vendor); + /* some broken boards return 0 if a slot is empty: */ + if (Vendor == 0xFFFFFFFF || Vendor == 0) + return 0; + + if ((Address & 1) && (Len >= 1)) + { + ReadPciConfigUchar(BusNumber, + SlotNumber, + Address, + Ptr); + Ptr = Ptr + 1; + Address++; + Len--; + } + + if ((Address & 2) && (Len >= 2)) + { + ReadPciConfigUshort(BusNumber, + SlotNumber, + Address, + Ptr); + Ptr = Ptr + 2; + Address += 2; + Len -= 2; + } + + while (Len >= 4) + { + ReadPciConfigUlong(BusNumber, + SlotNumber, + Address, + Ptr); + Ptr = Ptr + 4; + Address += 4; + Len -= 4; + } + + if (Len >= 2) + { + ReadPciConfigUshort(BusNumber, + SlotNumber, + Address, + Ptr); + Ptr = Ptr + 2; + Address += 2; + Len -= 2; + } + + if (Len >= 1) + { + ReadPciConfigUchar(BusNumber, + SlotNumber, + Address, + Ptr); + Ptr = Ptr + 1; + Address++; + Len--; + } + + return Length - Len; +} + + +static ULONG STDCALL +HalpSetPciData(PBUS_HANDLER BusHandler, + ULONG BusNumber, + ULONG SlotNumber, + PVOID Buffer, + ULONG Offset, + ULONG Length) +{ + PVOID Ptr = Buffer; + ULONG Address = Offset; + ULONG Len = Length; + ULONG Vendor; + UCHAR HeaderType; + + DPRINT("HalpSetPciData() called.\n"); + DPRINT(" BusNumber %lu\n", BusNumber); + DPRINT(" SlotNumber %lu\n", SlotNumber); + DPRINT(" Offset 0x%lx\n", Offset); + DPRINT(" Length 0x%lx\n", Length); + + if ((Length == 0) || (BusConfigType == 0)) + return 0; + + /* 0E=PCI_HEADER_TYPE */ + ReadPciConfigUchar(BusNumber, + SlotNumber & 0xF8, + 0x0E, + &HeaderType); + if (((HeaderType & 0x80) == 0) && ((SlotNumber & 0x07) != 0)) + return 0; + + ReadPciConfigUlong(BusNumber, + SlotNumber, + 0x00, + &Vendor); + /* some broken boards return 0 if a slot is empty: */ + if (Vendor == 0xFFFFFFFF || Vendor == 0) + return 0; + + if ((Address & 1) && (Len >= 1)) + { + WritePciConfigUchar(BusNumber, + SlotNumber, + Address, + *(PUCHAR)Ptr); + Ptr = Ptr + 1; + Address++; + Len--; + } + + if ((Address & 2) && (Len >= 2)) + { + WritePciConfigUshort(BusNumber, + SlotNumber, + Address, + *(PUSHORT)Ptr); + Ptr = Ptr + 2; + Address += 2; + Len -= 2; + } + + while (Len >= 4) + { + WritePciConfigUlong(BusNumber, + SlotNumber, + Address, + *(PULONG)Ptr); + Ptr = Ptr + 4; + Address += 4; + Len -= 4; + } + + if (Len >= 2) + { + WritePciConfigUshort(BusNumber, + SlotNumber, + Address, + *(PUSHORT)Ptr); + Ptr = Ptr + 2; + Address += 2; + Len -= 2; + } + + if (Len >= 1) + { + WritePciConfigUchar(BusNumber, + SlotNumber, + Address, + *(PUCHAR)Ptr); + Ptr = Ptr + 1; + Address++; + Len--; + } + + return Length - Len; +} + + +static ULONG +GetBusConfigType(VOID) +{ + ULONG Value; + + DPRINT("GetBusConfigType() called\n"); + + DPRINT("Checking configuration type 1:"); WRITE_PORT_UCHAR((PUCHAR)0xCFB, 0x01); - temp = READ_PORT_ULONG((PULONG)0xCF8); + Value = READ_PORT_ULONG((PULONG)0xCF8); WRITE_PORT_ULONG((PULONG)0xCF8, 0x80000000); - if (READ_PORT_ULONG((PULONG)0xCF8) != 0x80000000) + if (READ_PORT_ULONG((PULONG)0xCF8) == 0x80000000) { - WRITE_PORT_ULONG((PULONG)0xCF8, temp); - DPRINT("No pci configuration type 1\n"); - return STATUS_UNSUCCESSFUL; + WRITE_PORT_ULONG((PULONG)0xCF8, Value); + DPRINT(" Success!\n"); + return 1; } + WRITE_PORT_ULONG((PULONG)0xCF8, Value); + DPRINT(" Unsuccessful!\n"); - DPRINT("Using configuration type 1\n"); - WRITE_PORT_ULONG((PULONG)0xCF8, temp); - for (i = 0; i < 8; i++) - { - DPRINT("Scanning PCI bus %u...\n", i); - ScanPciBusType1(i); - } - WRITE_PORT_ULONG((PULONG)0xCF8, temp); - - return STATUS_SUCCESS; -} - - -/* - * Bus access type 2 (should not be used any longer) - */ -static int -ReadPciConfigUcharType2 (UCHAR Bus, - UCHAR device_fn, - UCHAR where, - PUCHAR Value) -{ - if ((device_fn & 0x80) != 0) - { - return PCIBIOS_DEVICE_NOT_FOUND; - } - - WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(device_fn)); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); - *Value = READ_PORT_UCHAR((PUCHAR)(IOADDR(device_fn,where))); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); - - return PCIBIOS_SUCCESSFUL; -} - -#if 0 -static int -ReadPciConfigUshortType2(UCHAR Bus, - UCHAR device_fn, - UCHAR where, - PUSHORT Value) -{ - if ((device_fn & 0x80) != 0) - { - return PCIBIOS_DEVICE_NOT_FOUND; - } - - WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(device_fn)); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); - *Value = READ_PORT_USHORT((PUSHORT)(IOADDR(device_fn,where))); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); - - return PCIBIOS_SUCCESSFUL; -} -#endif - -static int -ReadPciConfigUlongType2(UCHAR Bus, - UCHAR device_fn, - UCHAR where, - PULONG Value) -{ - if ((device_fn & 0x80) != 0) - { - return PCIBIOS_DEVICE_NOT_FOUND; - } - - WRITE_PORT_UCHAR((PUCHAR)0xCF8, FUNC(device_fn)); - WRITE_PORT_UCHAR((PUCHAR)0xCFA, Bus); - *Value = READ_PORT_ULONG((PULONG)(IOADDR(device_fn,where))); - WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0); - - return PCIBIOS_SUCCESSFUL; -} - -static void -ScanPciBusType2(ULONG Bus) -{ - USHORT dev_fn; - UCHAR hdr_type; - ULONG foo; - - for (dev_fn = 0; dev_fn < 256; dev_fn++) - { - if (PCI_FUNC(dev_fn) == 0) - { - /* 0E=PCI_HEADER_TYPE */ - ReadPciConfigUcharType2(Bus, dev_fn, 0x0E, &hdr_type); - } - else if ((hdr_type & 0x80) == 0) - { - /* not a multi-function device */ - continue; - } - - /* 00=PCI_VENDOR_ID */ - ReadPciConfigUlongType2(Bus, dev_fn, 0x00, &foo); - /* some broken boards return 0 if a slot is empty: */ - if (foo == 0xFFFFFFFF || foo == 0) - { - hdr_type = 0; - continue; - } - - DbgPrint("dev_fn=%3u, Vendor 0x%04lX, Device 0x%04lX\n", - dev_fn, foo & 0xFFFF, (foo >> 16) & 0xFFFF); - } -} - -static NTSTATUS -ScanPciBussesType2(VOID) -{ - ULONG i; - - DPRINT("Checking if configuration type 2 works\n"); + DPRINT("Checking configuration type 2:"); WRITE_PORT_UCHAR((PUCHAR)0xCFB, 0x00); WRITE_PORT_UCHAR((PUCHAR)0xCF8, 0x00); WRITE_PORT_UCHAR((PUCHAR)0xCFA, 0x00); - if (READ_PORT_UCHAR((PUCHAR)0xCF8) != 0x00 || - READ_PORT_UCHAR((PUCHAR)0xCFB) != 0x00) + if (READ_PORT_UCHAR((PUCHAR)0xCF8) == 0x00 && + READ_PORT_UCHAR((PUCHAR)0xCFB) == 0x00) { - DPRINT("No pci configuration type 2\n"); - return STATUS_UNSUCCESSFUL; + DPRINT(" Success!\n"); + return 2; } + DPRINT(" Unsuccessful!\n"); - DPRINT("Using configuration type 2\n"); - for (i = 0; i < 8; i++) - { - DPRINT("Scanning PCI bus %u...\n", i); - ScanPciBusType2(i); - } - - return STATUS_UNSUCCESSFUL; + DPRINT("No pci bus found!\n"); + return 0; } VOID HalpInitPciBus (VOID) { - NTSTATUS Status; + PBUS_HANDLER BusHandler; - DPRINT("HalpInitPciBus()\n"); + DPRINT("HalpInitPciBus() called.\n"); - Status = ScanPciBussesType1(); - if (NT_SUCCESS(Status)) - { - return; - } + BusConfigType = GetBusConfigType(); + if (BusConfigType == 0) + return; - Status = ScanPciBussesType2(); - if (NT_SUCCESS(Status)) - { - return; - } + DPRINT("Bus configuration %lu used\n", BusConfigType); - DbgPrint("No pci bus found\n"); + /* pci bus (bus 0) handler */ + BusHandler = HalpAllocateBusHandler(PCIBus, + PCIConfiguration, + 0); + BusHandler->GetBusData = (pGetSetBusData)HalpGetPciData; + BusHandler->SetBusData = (pGetSetBusData)HalpSetPciData; +// BusHandler->GetInterruptVector = +// (pGetInterruptVector)HalpGetPciInterruptVector; +// BusHandler->AdjustResourceList = +// (pGetSetBusData)HalpAdjustPciResourceList; +// BusHandler->AssignSlotResources = +// (pGetSetBusData)HalpAssignPciSlotResources; + + + /* agp bus (bus 1) handler */ + BusHandler = HalpAllocateBusHandler(PCIBus, + PCIConfiguration, + 1); + BusHandler->GetBusData = (pGetSetBusData)HalpGetPciData; + BusHandler->SetBusData = (pGetSetBusData)HalpSetPciData; +// BusHandler->GetInterruptVector = +// (pGetInterruptVector)HalpGetPciInterruptVector; +// BusHandler->AdjustResourceList = +// (pGetSetBusData)HalpAdjustPciResourceList; +// BusHandler->AssignSlotResources = +// (pGetSetBusData)HalpAssignPciSlotResources; + + DPRINT("HalpInitPciBus() finished.\n"); } /* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/sysbus.c b/reactos/ntoskrnl/hal/x86/sysbus.c index c4f191b1fd4..e955c72d72f 100644 --- a/reactos/ntoskrnl/hal/x86/sysbus.c +++ b/reactos/ntoskrnl/hal/x86/sysbus.c @@ -1,4 +1,4 @@ -/* $Id: sysbus.c,v 1.2 2001/02/25 12:54:37 chorns Exp $ +/* $Id: sysbus.c,v 1.3 2001/06/13 22:17:01 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -12,61 +12,53 @@ /* INCLUDES *****************************************************************/ #include - - -typedef struct _BUS_HANDLER *PBUS_HANDLER; +#include /* FUNCTIONS ****************************************************************/ -ULONG -STDCALL -HalpGetSystemInterruptVector ( - PVOID BusHandler, - ULONG BusNumber, - ULONG BusInterruptLevel, - ULONG BusInterruptVector, - PKIRQL Irql, - PKAFFINITY Affinity - ) +ULONG STDCALL +HalpGetSystemInterruptVector(PVOID BusHandler, + ULONG BusNumber, + ULONG BusInterruptLevel, + ULONG BusInterruptVector, + PKIRQL Irql, + PKAFFINITY Affinity) { - *Irql = HIGH_LEVEL - BusInterruptVector; + *Irql = HIGH_LEVEL - BusInterruptVector; *Affinity = 0xFFFFFFFF; - return BusInterruptVector; + return BusInterruptVector; } -BOOLEAN -STDCALL -HalpTranslateSystemBusAddress ( - PBUS_HANDLER BusHandler, - ULONG BusNumber, - PHYSICAL_ADDRESS BusAddress, - PULONG AddressSpace, - PPHYSICAL_ADDRESS TranslatedAddress - ) +BOOLEAN STDCALL +HalpTranslateSystemBusAddress(PBUS_HANDLER BusHandler, + ULONG BusNumber, + PHYSICAL_ADDRESS BusAddress, + PULONG AddressSpace, + PPHYSICAL_ADDRESS TranslatedAddress) { - ULONG BaseAddress = 0; + ULONG BaseAddress = 0; - if (*AddressSpace == 0) - { - /* memory space */ + if (*AddressSpace == 0) + { + /* memory space */ - } - else if (*AddressSpace == 1) - { - /* io space */ + } + else if (*AddressSpace == 1) + { + /* io space */ - } - else - { - /* other */ - return FALSE; - } + } + else + { + /* other */ + return FALSE; + } - TranslatedAddress->QuadPart = BusAddress.QuadPart + BaseAddress; + TranslatedAddress->QuadPart = BusAddress.QuadPart + BaseAddress; - return TRUE; + return TRUE; } /* EOF */ diff --git a/reactos/ntoskrnl/include/internal/hal/bus.h b/reactos/ntoskrnl/include/internal/hal/bus.h new file mode 100644 index 00000000000..7417923dbb2 --- /dev/null +++ b/reactos/ntoskrnl/include/internal/hal/bus.h @@ -0,0 +1,104 @@ +/* + + */ + +#ifndef __INTERNAL_HAL_BUS_H +#define __INTERNAL_HAL_BUS_H + +struct _BUS_HANDLER; + +typedef NTSTATUS (STDCALL *pAdjustResourceList) ( + IN struct _BUS_HANDLER *BusHandler, + IN ULONG BusNumber, + IN OUT PCM_RESOURCE_LIST Resources + ); + +typedef NTSTATUS (STDCALL *pAssignSlotResources) ( + IN struct _BUS_HANDLER *BusHandler, + IN ULONG BusNumber, + IN PUNICODE_STRING RegistryPath, + IN PUNICODE_STRING DriverClassName, + IN PDRIVER_OBJECT DriverObject, + IN PDEVICE_OBJECT DeviceObject, + IN ULONG SlotNumber, + IN OUT PCM_RESOURCE_LIST *AllocatedResources + ); + +typedef ULONG (STDCALL *pGetSetBusData) ( + IN struct _BUS_HANDLER *BusHandler, + IN ULONG BusNumber, + IN ULONG SlotNumber, + OUT PVOID Buffer, + IN ULONG Offset, + IN ULONG Length + ); + +typedef ULONG (STDCALL *pGetInterruptVector) ( + IN struct _BUS_HANDLER *BusHandler, + IN ULONG BusNumber, + IN ULONG BusInterruptLevel, + IN ULONG BusInterruptVector, + OUT PKIRQL Irql, + OUT PKAFFINITY Affinity + ); + +typedef ULONG (STDCALL *pTranslateBusAddress) ( + IN struct _BUS_HANDLER *BusHandler, + IN ULONG BusNumber, + IN PHYSICAL_ADDRESS BusAddress, + IN OUT PULONG AddressSpace, + OUT PPHYSICAL_ADDRESS TranslatedAddress + ); + +typedef struct _BUS_HANDLER +{ + LIST_ENTRY Entry; + INTERFACE_TYPE InterfaceType; + BUS_DATA_TYPE BusDataType; + ULONG BusNumber; + ULONG RefCount; + + pGetSetBusData GetBusData; + pGetSetBusData SetBusData; + pAdjustResourceList AdjustResourceList; + pAssignSlotResources AssignSlotResources; + pGetInterruptVector GetInterruptVector; + pTranslateBusAddress TranslateBusAddress; +} BUS_HANDLER, *PBUS_HANDLER; + + +/* FUNCTIONS *****************************************************************/ + +/* bus.c */ +PBUS_HANDLER +HalpAllocateBusHandler(INTERFACE_TYPE InterfaceType, + BUS_DATA_TYPE BusDataType, + ULONG BusNumber); + +/* sysbus.h */ +ULONG STDCALL +HalpGetSystemInterruptVector(PVOID BusHandler, + ULONG BusNumber, + ULONG BusInterruptLevel, + ULONG BusInterruptVector, + PKIRQL Irql, + PKAFFINITY Affinity); + +BOOLEAN STDCALL +HalpTranslateSystemBusAddress(PBUS_HANDLER BusHandler, + ULONG BusNumber, + PHYSICAL_ADDRESS BusAddress, + PULONG AddressSpace, + PPHYSICAL_ADDRESS TranslatedAddress); + +/* isa.c */ +BOOLEAN STDCALL +HalpTranslateIsaBusAddress(PBUS_HANDLER BusHandler, + ULONG BusNumber, + PHYSICAL_ADDRESS BusAddress, + PULONG AddressSpace, + PPHYSICAL_ADDRESS TranslatedAddress); + +#endif /* __INTERNAL_HAL_BUS_H */ + +/* EOF */ \ No newline at end of file