[HAL] Add Xbox Hardware Abstraction Layer
[reactos.git] / hal / halx86 / legacy / bus / pcibus.c
index 0045763..93ed9cb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * PROJECT:         ReactOS HAL
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            hal/halx86/generic/bus/pcibus.c
+ * FILE:            hal/halx86/legacy/bus/pcibus.c
  * PURPOSE:         PCI Bus Support (Configuration Space, Resource Allocation)
  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
  */
 #define NDEBUG
 #include <debug.h>
 
+#if defined(ALLOC_PRAGMA) && !defined(_MINIHAL_)
+#pragma alloc_text(INIT, HalpInitializePciStubs)
+#pragma alloc_text(INIT, HalpQueryPciRegistryInfo)
+#pragma alloc_text(INIT, HalpRegisterPciDebuggingDeviceInfo)
+#pragma alloc_text(INIT, HalpReleasePciDeviceForDebugging)
+#pragma alloc_text(INIT, HalpSetupPciDeviceForDebugging)
+#endif
+
 /* GLOBALS *******************************************************************/
 
 extern BOOLEAN HalpPciLockSettings;
@@ -343,27 +351,29 @@ ULONG
 NTAPI
 HalpGetPCIData(IN PBUS_HANDLER BusHandler,
                IN PBUS_HANDLER RootHandler,
-               IN PCI_SLOT_NUMBER Slot,
+               IN ULONG SlotNumber,
                IN PVOID Buffer,
                IN ULONG Offset,
                IN ULONG Length)
 {
+    PCI_SLOT_NUMBER Slot;
     UCHAR PciBuffer[PCI_COMMON_HDR_LENGTH];
     PPCI_COMMON_CONFIG PciConfig = (PPCI_COMMON_CONFIG)PciBuffer;
     ULONG Len = 0;
 
+    Slot.u.AsULONG = SlotNumber;
 #ifdef SARCH_XBOX
     /* Trying to get PCI config data from devices 0:0:1 and 0:0:2 will completely
      * hang the Xbox. Also, the device number doesn't seem to be decoded for the
      * video card, so it appears to be present on 1:0:0 - 1:31:0.
      * We hack around these problems by indicating "device not present" for devices
      * 0:0:1, 0:0:2, 1:1:0, 1:2:0, 1:3:0, ...., 1:31:0 */
-    if ((0 == BusHandler->BusNumber && 0 == Slot.u.bits.DeviceNumber &&
-         (1 == Slot.u.bits.FunctionNumber || 2 == Slot.u.bits.FunctionNumber)) ||
-        (1 == BusHandler->BusNumber && 0 != Slot.u.bits.DeviceNumber))
+    if ((BusHandler->BusNumber == 0 && Slot.u.bits.DeviceNumber == 0 &&
+        (Slot.u.bits.FunctionNumber == 1 || Slot.u.bits.FunctionNumber == 2)) ||
+        (BusHandler->BusNumber == 1 && Slot.u.bits.DeviceNumber != 0))
     {
-        DPRINT("Blacklisted PCI slot\n");
-        if (0 == Offset && sizeof(USHORT) <= Length)
+        DPRINT("Blacklisted PCI slot (%d:%d:%d)\n", BusHandler->BusNumber, Slot.u.bits.DeviceNumber, Slot.u.bits.FunctionNumber);
+        if (Offset == 0 && Length >= sizeof(USHORT))
         {
             *(PUSHORT)Buffer = PCI_INVALID_VENDORID;
             return sizeof(USHORT);
@@ -433,26 +443,28 @@ ULONG
 NTAPI
 HalpSetPCIData(IN PBUS_HANDLER BusHandler,
                IN PBUS_HANDLER RootHandler,
-               IN PCI_SLOT_NUMBER Slot,
+               IN ULONG SlotNumber,
                IN PVOID Buffer,
                IN ULONG Offset,
                IN ULONG Length)
 {
+    PCI_SLOT_NUMBER Slot;
     UCHAR PciBuffer[PCI_COMMON_HDR_LENGTH];
     PPCI_COMMON_CONFIG PciConfig = (PPCI_COMMON_CONFIG)PciBuffer;
     ULONG Len = 0;
 
+    Slot.u.AsULONG = SlotNumber;
 #ifdef SARCH_XBOX
     /* Trying to get PCI config data from devices 0:0:1 and 0:0:2 will completely
      * hang the Xbox. Also, the device number doesn't seem to be decoded for the
      * video card, so it appears to be present on 1:0:0 - 1:31:0.
      * We hack around these problems by indicating "device not present" for devices
      * 0:0:1, 0:0:2, 1:1:0, 1:2:0, 1:3:0, ...., 1:31:0 */
-    if ((0 == BusHandler->BusNumber && 0 == Slot.u.bits.DeviceNumber &&
-         (1 == Slot.u.bits.FunctionNumber || 2 == Slot.u.bits.FunctionNumber)) ||
-        (1 == BusHandler->BusNumber && 0 != Slot.u.bits.DeviceNumber))
+    if ((BusHandler->BusNumber == 0 && Slot.u.bits.DeviceNumber == 0 &&
+        (Slot.u.bits.FunctionNumber == 1 || Slot.u.bits.FunctionNumber == 2)) ||
+        (BusHandler->BusNumber == 1 && Slot.u.bits.DeviceNumber != 0))
     {
-        DPRINT1("Trying to set data on blacklisted PCI slot\n");
+        DPRINT1("Trying to set data on blacklisted PCI slot (%d:%d:%d)\n", BusHandler->BusNumber, Slot.u.bits.DeviceNumber, Slot.u.bits.FunctionNumber);
         return 0;
     }
 #endif
@@ -536,10 +548,9 @@ HalpPCIPin2ISALine(IN PBUS_HANDLER BusHandler,
                    IN PCI_SLOT_NUMBER SlotNumber,
                    IN PPCI_COMMON_CONFIG PciData)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
 }
-        
+
 VOID
 NTAPI
 HalpPCIISALine2Pin(IN PBUS_HANDLER BusHandler,
@@ -548,8 +559,7 @@ HalpPCIISALine2Pin(IN PBUS_HANDLER BusHandler,
                    IN PPCI_COMMON_CONFIG PciNewData,
                    IN PPCI_COMMON_CONFIG PciOldData)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
 }
 
 NTSTATUS
@@ -560,30 +570,30 @@ HalpGetISAFixedPCIIrq(IN PBUS_HANDLER BusHandler,
                       OUT PSUPPORTED_RANGE *Range)
 {
     PCI_COMMON_HEADER PciData;
-    
+
     /* Read PCI configuration data */
     HalGetBusData(PCIConfiguration,
                   BusHandler->BusNumber,
                   PciSlot.u.AsULONG,
                   &PciData,
                   PCI_COMMON_HDR_LENGTH);
-                
+
     /* Make sure it's a real device */
     if (PciData.VendorID == PCI_INVALID_VENDORID) return STATUS_UNSUCCESSFUL;
-    
+
     /* Allocate the supported range structure */
     *Range = ExAllocatePoolWithTag(PagedPool, sizeof(SUPPORTED_RANGE), TAG_HAL);
     if (!*Range) return STATUS_INSUFFICIENT_RESOURCES;
-    
+
     /* Set it up */
     RtlZeroMemory(*Range, sizeof(SUPPORTED_RANGE));
     (*Range)->Base = 1;
-    
+
     /* If the PCI device has no IRQ, nothing to do */
     if (!PciData.u.type0.InterruptPin) return STATUS_SUCCESS;
-    
+
     /* FIXME: The PCI IRQ Routing Miniport should be called */
-    
+
     /* Also if the INT# seems bogus, nothing to do either */
     if ((PciData.u.type0.InterruptLine == 0) ||
         (PciData.u.type0.InterruptLine == 255))
@@ -591,16 +601,16 @@ HalpGetISAFixedPCIIrq(IN PBUS_HANDLER BusHandler,
         /* Fake success */
         return STATUS_SUCCESS;
     }
-    
+
     /* Otherwise, the INT# should be valid, return it to the caller */
     (*Range)->Base = PciData.u.type0.InterruptLine;
     (*Range)->Limit = PciData.u.type0.InterruptLine;
     return STATUS_SUCCESS;
 }
 
+INIT_FUNCTION
 NTSTATUS
 NTAPI
-INIT_FUNCTION
 HalpSetupPciDeviceForDebugging(IN PVOID LoaderBlock,
                                IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice)
 {
@@ -608,18 +618,18 @@ HalpSetupPciDeviceForDebugging(IN PVOID LoaderBlock,
     return STATUS_NOT_IMPLEMENTED;
 }
 
+INIT_FUNCTION
 NTSTATUS
 NTAPI
-INIT_FUNCTION
 HalpReleasePciDeviceForDebugging(IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice)
 {
     DPRINT1("Unimplemented!\n");
     return STATUS_NOT_IMPLEMENTED;
 }
 
+INIT_FUNCTION
 VOID
 NTAPI
-INIT_FUNCTION
 HalpRegisterPciDebuggingDeviceInfo(VOID)
 {
     BOOLEAN Found = FALSE;
@@ -639,11 +649,10 @@ HalpRegisterPciDebuggingDeviceInfo(VOID)
 
     /* Bail out if there aren't any */
     if (!Found) return;
-    
+
     /* FIXME: TODO */
-    DPRINT1("You have implemented the KD routines for searching PCI debugger"
-            "devices, but you have forgotten to implement this routine\n");
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK("You have implemented the KD routines for searching PCI debugger"
+                           "devices, but you have forgotten to implement this routine\n");
 }
 
 static ULONG NTAPI
@@ -664,11 +673,11 @@ HalpAdjustPCIResourceList(IN PBUS_HANDLER BusHandler,
     PCI_SLOT_NUMBER SlotNumber;
     PSUPPORTED_RANGE Interrupt;
     NTSTATUS Status;
-    
+
     /* Get PCI bus data */
     BusData = BusHandler->BusData;
     SlotNumber.u.AsULONG = (*pResourceList)->SlotNumber;
-    
+
     /* Get the IRQ supported range */
     Status = BusData->GetIrqRange(BusHandler, RootHandler, SlotNumber, &Interrupt);
     if (!NT_SUCCESS(Status)) return Status;
@@ -677,8 +686,7 @@ HalpAdjustPCIResourceList(IN PBUS_HANDLER BusHandler,
     if (HalpPciLockSettings)
     {
         /* /PCILOCK is not yet supported */
-        UNIMPLEMENTED;
-        while (TRUE);
+        UNIMPLEMENTED_DBGBREAK("/PCILOCK boot switch is not yet supported.");
     }
 #endif
     /* Now create the correct resource list based on the supported bus ranges */
@@ -709,7 +717,7 @@ HalpAssignPCISlotResources(IN PBUS_HANDLER BusHandler,
 {
     PCI_COMMON_CONFIG PciConfig;
     SIZE_T Address;
-    SIZE_T ResourceCount;
+    ULONG ResourceCount;
     ULONG Size[PCI_TYPE0_ADDRESSES];
     NTSTATUS Status = STATUS_SUCCESS;
     UCHAR Offset;
@@ -854,9 +862,9 @@ HaliPciInterfaceReadConfig(IN PBUS_HANDLER RootBusHandler,
     return Length;
 }
 
+INIT_FUNCTION
 PPCI_REGISTRY_INFO_INTERNAL
 NTAPI
-INIT_FUNCTION
 HalpQueryPciRegistryInfo(VOID)
 {
 #ifndef _MINIHAL_
@@ -1087,9 +1095,9 @@ HalpQueryPciRegistryInfo(VOID)
 #endif
 }
 
+INIT_FUNCTION
 VOID
 NTAPI
-INIT_FUNCTION
 HalpInitializePciStubs(VOID)
 {
     PPCI_REGISTRY_INFO_INTERNAL PciRegistryInfo;