-/* $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
#include <ddk/ntddk.h>
#include <internal/pool.h>
+#include <internal/hal/bus.h>
#define NDEBUG
#include <internal/debug.h>
#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
- */
-
- /* system bus handler */
- BusHandler = HalpAllocateBusHandler (Internal,
- ConfigurationSpaceUndefined,
- 0);
- BusHandler->GetInterruptVector =
- (pGetInterruptVector)HalpGetSystemInterruptVector;
- BusHandler->TranslateBusAddress =
- (pTranslateBusAddress)HalpTranslateSystemBusAddress;
-
- /* cmos bus handler */
- BusHandler = HalpAllocateBusHandler (InterfaceTypeUndefined,
- Cmos,
- 0);
-// BusHandler->GetBusData =
-// (pGetSetBusData)HalpGetCmosData;
-// BusHandler->SetBusData =
-// (pGetSetBusData)HalpSetCmosData;
-
- /* 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
+ /* add system bus handler */
+ BusHandler = HalpAllocateBusHandler(Internal,
+ ConfigurationSpaceUndefined,
+ 0);
+ if (BusHandler == NULL)
+ return;
+ 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;
+
+ /* add isa bus handler */
+ BusHandler = HalpAllocateBusHandler(Isa,
+ ConfigurationSpaceUndefined,
+ 0);
+ if (BusHandler == NULL)
+ return;
+
+ 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;
-
- 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);
-
- return NULL;
+ PBUS_HANDLER BusHandler;
+ PLIST_ENTRY CurrentEntry;
+ KIRQL 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);
+
+ 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;
-
- 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);
-
- return NULL;
+ PBUS_HANDLER BusHandler;
+ PLIST_ENTRY CurrentEntry;
+ KIRQL 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);
+
+ 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;
-
- 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);
-
- return NULL;
+ PBUS_HANDLER BusHandler;
+ PLIST_ENTRY CurrentEntry;
+ KIRQL 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);
+
+ 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;
-
- 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);
-
- return NULL;
+ PBUS_HANDLER BusHandler;
+ PLIST_ENTRY CurrentEntry;
+ KIRQL 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);
+
+ 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;
-
- BusHandler = HaliReferenceHandlerForBus (Resources->List[0].InterfaceType,
- Resources->List[0].BusNumber);
- if (BusHandler == NULL)
- return STATUS_SUCCESS;
+ PBUS_HANDLER BusHandler;
+ NTSTATUS Status;
- Status = BusHandler->AdjustResourceList (BusHandler,
- Resources->List[0].BusNumber,
- Resources);
+ BusHandler = HaliReferenceHandlerForBus(Resources->List[0].InterfaceType,
+ Resources->List[0].BusNumber);
+ if (BusHandler == NULL)
+ return STATUS_SUCCESS;
- HaliDereferenceBusHandler (BusHandler);
+ Status = BusHandler->AdjustResourceList(BusHandler,
+ Resources->List[0].BusNumber,
+ Resources);
+ 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;
-
- BusHandler = HaliReferenceHandlerForBus (BusType,
- BusNumber);
- if (BusHandler == NULL)
- return STATUS_NOT_FOUND;
-
- Status = BusHandler->AssignSlotResources (BusHandler,
- BusNumber,
- RegistryPath,
- DriverClassName,
- DriverObject,
- DeviceObject,
- SlotNumber,
- AllocatedResources);
-
- HaliDereferenceBusHandler (BusHandler);
-
- return Status;
+ PBUS_HANDLER BusHandler;
+ NTSTATUS Status;
+
+ BusHandler = HaliReferenceHandlerForBus(BusType,
+ BusNumber);
+ if (BusHandler == NULL)
+ return STATUS_NOT_FOUND;
+
+ Status = BusHandler->AssignSlotResources(BusHandler,
+ BusNumber,
+ RegistryPath,
+ DriverClassName,
+ DriverObject,
+ DeviceObject,
+ SlotNumber,
+ AllocatedResources);
+
+ HaliDereferenceBusHandler(BusHandler);
+
+ 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 */
-/* $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
* 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 <ddk/ntddk.h>
+#include <internal/hal/bus.h>
#define NDEBUG
#include <internal/debug.h>
-/* 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 ******************************************************************/
-/* FUNCTIONS **************************************************************/
+static ULONG BusConfigType = 0; /* undetermined config type */
-/*
- * Bus access type 1 (recommended)
- */
-static int
-ReadPciConfigUcharType1(UCHAR Bus,
- UCHAR device_fn,
- UCHAR where,
- PUCHAR Value)
+
+/* FUNCTIONS ****************************************************************/
+
+static NTSTATUS
+ReadPciConfigUchar(UCHAR Bus,
+ UCHAR Slot,
+ UCHAR Offset,
+ PUCHAR Value)
{
- WRITE_PORT_ULONG((PULONG)0xCF8, CONFIG_CMD(Bus,device_fn,where));
- *Value = READ_PORT_UCHAR((PUCHAR)0xCFC + (where&3));
- return PCIBIOS_SUCCESSFUL;
+ 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;
+
+ 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;
}
-#if 0
-static int
-ReadPciConfigUshortType1(UCHAR Bus,
- UCHAR device_fn,
- UCHAR where,
- PUSHORT Value)
+
+static NTSTATUS
+ReadPciConfigUshort(UCHAR Bus,
+ UCHAR Slot,
+ UCHAR Offset,
+ PUSHORT Value)
{
- if ((where & 1) != 0)
+ if ((Offset & 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;
+ 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;
}
-#endif
-static int
-ReadPciConfigUlongType1(UCHAR Bus,
- UCHAR device_fn,
- UCHAR where,
- PULONG Value)
+
+static NTSTATUS
+ReadPciConfigUlong(UCHAR Bus,
+ UCHAR Slot,
+ UCHAR Offset,
+ PULONG Value)
{
- if ((where & 3) != 0)
+ if ((Offset & 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;
+ 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 void
-ScanPciBusType1(ULONG Bus)
-{
- USHORT dev_fn;
- UCHAR hdr_type;
- ULONG foo;
- for (dev_fn = 0; dev_fn < 256; dev_fn++)
+static NTSTATUS
+WritePciConfigUchar(UCHAR Bus,
+ UCHAR Slot,
+ UCHAR Offset,
+ UCHAR Value)
+{
+ switch (BusConfigType)
{
- 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);
+ 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
-ScanPciBussesType1(VOID)
+WritePciConfigUshort(UCHAR Bus,
+ UCHAR Slot,
+ UCHAR Offset,
+ USHORT Value)
{
- ULONG i;
- ULONG temp;
-
- DPRINT("ScanPciBussesType1()\n");
-
- DPRINT("Checking if configuration type 1 works\n");
- WRITE_PORT_UCHAR((PUCHAR)0xCFB, 0x01);
- temp = READ_PORT_ULONG((PULONG)0xCF8);
- WRITE_PORT_ULONG((PULONG)0xCF8, 0x80000000);
- if (READ_PORT_ULONG((PULONG)0xCF8) != 0x80000000)
+ if ((Offset & 1) != 0)
{
- WRITE_PORT_ULONG((PULONG)0xCF8, temp);
- DPRINT("No pci configuration type 1\n");
- return STATUS_UNSUCCESSFUL;
+ return PCIBIOS_BAD_REGISTER_NUMBER;
}
- DPRINT("Using configuration type 1\n");
- WRITE_PORT_ULONG((PULONG)0xCF8, temp);
- for (i = 0; i < 8; i++)
+ switch (BusConfigType)
{
- DPRINT("Scanning PCI bus %u...\n", i);
- ScanPciBusType1(i);
+ 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;
}
- WRITE_PORT_ULONG((PULONG)0xCF8, temp);
-
- return STATUS_SUCCESS;
+ return STATUS_UNSUCCESSFUL;
}
-/*
- * Bus access type 2 (should not be used any longer)
- */
-static int
-ReadPciConfigUcharType2 (UCHAR Bus,
- UCHAR device_fn,
- UCHAR where,
- PUCHAR Value)
+static NTSTATUS
+WritePciConfigUlong(UCHAR Bus,
+ UCHAR Slot,
+ UCHAR Offset,
+ ULONG Value)
{
- if ((device_fn & 0x80) != 0)
+ if ((Offset & 3) != 0)
{
- return PCIBIOS_DEVICE_NOT_FOUND;
+ return PCIBIOS_BAD_REGISTER_NUMBER;
}
- 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;
+ 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;
}
-#if 0
-static int
-ReadPciConfigUshortType2(UCHAR Bus,
- UCHAR device_fn,
- UCHAR where,
- PUSHORT Value)
+
+static ULONG STDCALL
+HalpGetPciData(PBUS_HANDLER BusHandler,
+ ULONG BusNumber,
+ ULONG SlotNumber,
+ PVOID Buffer,
+ ULONG Offset,
+ ULONG Length)
{
- if ((device_fn & 0x80) != 0)
+ 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))
{
- return PCIBIOS_DEVICE_NOT_FOUND;
+ ReadPciConfigUchar(BusNumber,
+ SlotNumber,
+ Address,
+ Ptr);
+ Ptr = Ptr + 1;
+ Address++;
+ Len--;
}
- 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);
+ if ((Address & 2) && (Len >= 2))
+ {
+ ReadPciConfigUshort(BusNumber,
+ SlotNumber,
+ Address,
+ Ptr);
+ Ptr = Ptr + 2;
+ Address += 2;
+ Len -= 2;
+ }
- return PCIBIOS_SUCCESSFUL;
-}
-#endif
+ while (Len >= 4)
+ {
+ ReadPciConfigUlong(BusNumber,
+ SlotNumber,
+ Address,
+ Ptr);
+ Ptr = Ptr + 4;
+ Address += 4;
+ Len -= 4;
+ }
-static int
-ReadPciConfigUlongType2(UCHAR Bus,
- UCHAR device_fn,
- UCHAR where,
- PULONG Value)
-{
- if ((device_fn & 0x80) != 0)
+ if (Len >= 2)
{
- return PCIBIOS_DEVICE_NOT_FOUND;
+ ReadPciConfigUshort(BusNumber,
+ SlotNumber,
+ Address,
+ Ptr);
+ Ptr = Ptr + 2;
+ Address += 2;
+ Len -= 2;
}
- 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);
+ if (Len >= 1)
+ {
+ ReadPciConfigUchar(BusNumber,
+ SlotNumber,
+ Address,
+ Ptr);
+ Ptr = Ptr + 1;
+ Address++;
+ Len--;
+ }
- return PCIBIOS_SUCCESSFUL;
+ return Length - Len;
}
-static void
-ScanPciBusType2(ULONG Bus)
+
+static ULONG STDCALL
+HalpSetPciData(PBUS_HANDLER BusHandler,
+ ULONG BusNumber,
+ ULONG SlotNumber,
+ PVOID Buffer,
+ ULONG Offset,
+ ULONG Length)
{
- USHORT dev_fn;
- UCHAR hdr_type;
- ULONG foo;
+ 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--;
+ }
- for (dev_fn = 0; dev_fn < 256; dev_fn++)
+ if ((Address & 2) && (Len >= 2))
{
- 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);
- }
-}
+ WritePciConfigUshort(BusNumber,
+ SlotNumber,
+ Address,
+ *(PUSHORT)Ptr);
+ Ptr = Ptr + 2;
+ Address += 2;
+ Len -= 2;
+ }
-static NTSTATUS
-ScanPciBussesType2(VOID)
-{
- ULONG i;
+ while (Len >= 4)
+ {
+ WritePciConfigUlong(BusNumber,
+ SlotNumber,
+ Address,
+ *(PULONG)Ptr);
+ Ptr = Ptr + 4;
+ Address += 4;
+ Len -= 4;
+ }
- DPRINT("Checking if configuration type 2 works\n");
- 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 (Len >= 2)
{
- DPRINT("No pci configuration type 2\n");
- return STATUS_UNSUCCESSFUL;
+ WritePciConfigUshort(BusNumber,
+ SlotNumber,
+ Address,
+ *(PUSHORT)Ptr);
+ Ptr = Ptr + 2;
+ Address += 2;
+ Len -= 2;
}
- DPRINT("Using configuration type 2\n");
- for (i = 0; i < 8; i++)
+ if (Len >= 1)
{
- DPRINT("Scanning PCI bus %u...\n", i);
- ScanPciBusType2(i);
+ WritePciConfigUchar(BusNumber,
+ SlotNumber,
+ Address,
+ *(PUCHAR)Ptr);
+ Ptr = Ptr + 1;
+ Address++;
+ Len--;
}
- return STATUS_UNSUCCESSFUL;
+ return Length - Len;
}
-VOID HalpInitPciBus (VOID)
+static ULONG
+GetBusConfigType(VOID)
{
- NTSTATUS Status;
+ ULONG Value;
- DPRINT("HalpInitPciBus()\n");
+ DPRINT("GetBusConfigType() called\n");
- Status = ScanPciBussesType1();
- if (NT_SUCCESS(Status))
+ DPRINT("Checking configuration type 1:");
+ WRITE_PORT_UCHAR((PUCHAR)0xCFB, 0x01);
+ Value = READ_PORT_ULONG((PULONG)0xCF8);
+ WRITE_PORT_ULONG((PULONG)0xCF8, 0x80000000);
+ if (READ_PORT_ULONG((PULONG)0xCF8) == 0x80000000)
{
- return;
+ WRITE_PORT_ULONG((PULONG)0xCF8, Value);
+ DPRINT(" Success!\n");
+ return 1;
}
+ WRITE_PORT_ULONG((PULONG)0xCF8, Value);
+ DPRINT(" Unsuccessful!\n");
- Status = ScanPciBussesType2();
- if (NT_SUCCESS(Status))
+ 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)
{
- return;
+ DPRINT(" Success!\n");
+ return 2;
}
+ DPRINT(" Unsuccessful!\n");
- DbgPrint("No pci bus found\n");
+ DPRINT("No pci bus found!\n");
+ return 0;
+}
+
+
+VOID HalpInitPciBus (VOID)
+{
+ PBUS_HANDLER BusHandler;
+
+ DPRINT("HalpInitPciBus() called.\n");
+
+ BusConfigType = GetBusConfigType();
+ if (BusConfigType == 0)
+ return;
+
+ DPRINT("Bus configuration %lu used\n", BusConfigType);
+
+ /* 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 */