[HAL]: Use Bus Handler support for HalFindBusAddressTranslation. Implement HalpContex...
authorSir Richard <sir_richard@svn.reactos.org>
Mon, 7 Jun 2010 21:36:31 +0000 (21:36 +0000)
committerSir Richard <sir_richard@svn.reactos.org>
Mon, 7 Jun 2010 21:36:31 +0000 (21:36 +0000)
       All the HAL's bus functions now use Bus Handlers on Legacy systems. There are still big issues with PCI cards.
       eVb: PCI-x should work now.
       More PCI-related HAL patches may follow later.

svn path=/trunk/; revision=47684

reactos/hal/halx86/generic/legacy/bus/bushndlr.c
reactos/hal/halx86/generic/legacy/bussupp.c
reactos/hal/halx86/include/bus.h

index 0e5774b..2ab551c 100644 (file)
@@ -201,6 +201,41 @@ HaliReferenceHandlerForConfigSpace(IN BUS_DATA_TYPE ConfigType,
     return HalpLookupHandler(HalpConfigTable, ConfigType, BusNumber, TRUE);
 }
 
     return HalpLookupHandler(HalpConfigTable, ConfigType, BusNumber, TRUE);
 }
 
+PBUS_HANDLER
+NTAPI
+HalpContextToBusHandler(IN ULONG_PTR ContextValue)
+{
+    PLIST_ENTRY NextEntry;
+    PHAL_BUS_HANDLER BusHandler, ThisHandler;
+    
+    /* Start lookup */
+    NextEntry = HalpAllBusHandlers.Flink;
+    ThisHandler = CONTAINING_RECORD(NextEntry, HAL_BUS_HANDLER, AllHandlers);
+    if (ContextValue)
+    {
+        /* If the list is empty, quit */
+        if (IsListEmpty(&HalpAllBusHandlers)) return NULL;
+
+        /* Otherwise, scan the list */
+        BusHandler = CONTAINING_RECORD(ContextValue, HAL_BUS_HANDLER, Handler);
+        do
+        {
+            /* Check if we've reached the right one */
+            ThisHandler = CONTAINING_RECORD(NextEntry, HAL_BUS_HANDLER, AllHandlers);
+            if (ThisHandler == BusHandler) break;
+            
+            /* Try the next one */
+            NextEntry = NextEntry->Flink;
+        } while (NextEntry != &HalpAllBusHandlers);
+    }
+    
+    /* If we looped back to the end, we didn't find anything */
+    if (NextEntry == &HalpAllBusHandlers) return NULL;
+    
+    /* Otherwise return the handler */
+    return &ThisHandler->Handler;
+}
+
 #ifndef _MINIHAL_
 NTSTATUS
 NTAPI
 #ifndef _MINIHAL_
 NTSTATUS
 NTAPI
@@ -408,13 +443,7 @@ HalpInitBusHandler(VOID)
 #endif
     HalPciAssignSlotResources = HalpAssignSlotResources;
     HalPciTranslateBusAddress = HaliTranslateBusAddress; /* PCI Driver can override */
 #endif
     HalPciAssignSlotResources = HalpAssignSlotResources;
     HalPciTranslateBusAddress = HaliTranslateBusAddress; /* PCI Driver can override */
-    /* FIXME: Fix later */
-#if 0
     if (!HalFindBusAddressTranslation) HalFindBusAddressTranslation = HaliFindBusAddressTranslation;
     if (!HalFindBusAddressTranslation) HalFindBusAddressTranslation = HaliFindBusAddressTranslation;
-#else
-    /* These should be written by the PCI driver later, but we give defaults */
-    HalFindBusAddressTranslation = HalpFindBusAddressTranslation;
-#endif
 }
 
 /* EOF */
 }
 
 /* EOF */
index a697860..6faa60f 100644 (file)
@@ -1152,50 +1152,75 @@ HalpAssignSlotResources(IN PUNICODE_STRING RegistryPath,
 
 BOOLEAN
 NTAPI
 
 BOOLEAN
 NTAPI
-HalpTranslateBusAddress(IN INTERFACE_TYPE InterfaceType,
-                        IN ULONG BusNumber,
-                        IN PHYSICAL_ADDRESS BusAddress,
-                        IN OUT PULONG AddressSpace,
-                        OUT PPHYSICAL_ADDRESS TranslatedAddress)
-{
-    /* Translation is easy */
-    TranslatedAddress->QuadPart = BusAddress.QuadPart;
-    return TRUE;
-}
-
-ULONG
-NTAPI
-HalpGetSystemInterruptVector_Acpi(IN ULONG BusNumber,
-                                  IN ULONG BusInterruptLevel,
-                                  IN ULONG BusInterruptVector,
-                                  OUT PKIRQL Irql,
-                                  OUT PKAFFINITY Affinity)
-{
-    ULONG Vector = IRQ2VECTOR(BusInterruptLevel);
-    *Irql = (KIRQL)VECTOR2IRQL(Vector);
-    *Affinity = 0xFFFFFFFF;
-    return Vector;
-}
-
-BOOLEAN
-NTAPI
-HalpFindBusAddressTranslation(IN PHYSICAL_ADDRESS BusAddress,
+HaliFindBusAddressTranslation(IN PHYSICAL_ADDRESS BusAddress,
                               IN OUT PULONG AddressSpace,
                               OUT PPHYSICAL_ADDRESS TranslatedAddress,
                               IN OUT PULONG_PTR Context,
                               IN BOOLEAN NextBus)
 {
                               IN OUT PULONG AddressSpace,
                               OUT PPHYSICAL_ADDRESS TranslatedAddress,
                               IN OUT PULONG_PTR Context,
                               IN BOOLEAN NextBus)
 {
+    PHAL_BUS_HANDLER BusHandler;
+    PBUS_HANDLER Handler;
+    PLIST_ENTRY NextEntry;
+    ULONG ContextValue;
+
     /* Make sure we have a context */
     if (!Context) return FALSE;
     /* Make sure we have a context */
     if (!Context) return FALSE;
-
-    /* If we have data in the context, then this shouldn't be a new lookup */
-    if ((*Context) && (NextBus == TRUE)) return FALSE;
-
-    /* Return bus data */
-    TranslatedAddress->QuadPart = BusAddress.QuadPart;
-
-    /* Set context value and return success */
-    *Context = 1;
+    ASSERT((*Context) || (NextBus == TRUE));
+    
+    /* Read the context */
+    ContextValue = *Context;
+    
+    /* Find the bus handler */
+    Handler = HalpContextToBusHandler(ContextValue);
+    if (!Handler) return FALSE;
+    
+    /* Check if this is an ongoing lookup */
+    if (NextBus)
+    {
+        /* Get the HAL bus handler */
+        BusHandler = CONTAINING_RECORD(Handler, HAL_BUS_HANDLER, Handler);
+        NextEntry = &BusHandler->AllHandlers;
+        
+        /* Get the next one if we were already with one */
+        if (ContextValue) NextEntry = NextEntry->Flink;
+        
+        /* Start scanning */
+        while (TRUE)
+        {
+            /* Check if this is the last one */
+            if (NextEntry == &HalpAllBusHandlers)
+            {
+                /* Quit */
+                *Context = 1;
+                return FALSE;
+            }
+            
+            /* Call this translator */
+            BusHandler = CONTAINING_RECORD(NextEntry, HAL_BUS_HANDLER, AllHandlers);
+            if (HalTranslateBusAddress(BusHandler->Handler.InterfaceType,
+                                       BusHandler->Handler.BusNumber,
+                                       BusAddress,
+                                       AddressSpace,
+                                       TranslatedAddress)) break;
+            
+            /* Try the next one */
+            NextEntry = NextEntry->Flink;
+        }
+        
+        /* If we made it, we're done */
+        *Context = (ULONG_PTR)Handler;
+        return TRUE;
+    }
+    
+    /* Try the first one through */
+    if (!HalTranslateBusAddress(Handler->InterfaceType,
+                                Handler->BusNumber,
+                                BusAddress,
+                                AddressSpace,
+                                TranslatedAddress)) return FALSE;
+    
+    /* Remember for next time */
+    *Context = (ULONG_PTR)Handler;
     return TRUE;
 }
 
     return TRUE;
 }
 
index 5af43db..3f6e1d6 100644 (file)
@@ -376,16 +376,6 @@ HalpTranslateBusAddress(
     OUT PPHYSICAL_ADDRESS TranslatedAddress
 );
 
     OUT PPHYSICAL_ADDRESS TranslatedAddress
 );
 
-BOOLEAN
-NTAPI
-HaliTranslateBusAddress(
-    IN INTERFACE_TYPE InterfaceType,
-    IN ULONG BusNumber,
-    IN PHYSICAL_ADDRESS BusAddress,
-    IN OUT PULONG AddressSpace,
-    OUT PPHYSICAL_ADDRESS TranslatedAddress
-);
-
 NTSTATUS
 NTAPI
 HalpAssignSlotResources(
 NTSTATUS
 NTAPI
 HalpAssignSlotResources(
@@ -417,6 +407,26 @@ HalpRegisterPciDebuggingDeviceInfo(
 
 /* LEGACY */
 
 
 /* LEGACY */
 
+BOOLEAN
+NTAPI
+HaliTranslateBusAddress(
+    IN INTERFACE_TYPE InterfaceType,
+    IN ULONG BusNumber,
+    IN PHYSICAL_ADDRESS BusAddress,
+    IN OUT PULONG AddressSpace,
+    OUT PPHYSICAL_ADDRESS TranslatedAddress
+);
+
+BOOLEAN
+NTAPI
+HaliFindBusAddressTranslation(
+    IN PHYSICAL_ADDRESS BusAddress,
+    IN OUT PULONG AddressSpace,
+    OUT PPHYSICAL_ADDRESS TranslatedAddress,
+    IN OUT PULONG_PTR Context,
+    IN BOOLEAN NextBus
+);
+
 NTSTATUS
 NTAPI
 HalpAdjustPCIResourceList(IN PBUS_HANDLER BusHandler,
 NTSTATUS
 NTAPI
 HalpAdjustPCIResourceList(IN PBUS_HANDLER BusHandler,
@@ -459,6 +469,12 @@ HalpInitBusHandler(
     VOID
 );
 
     VOID
 );
 
+PBUS_HANDLER
+NTAPI
+HalpContextToBusHandler(
+    IN ULONG_PTR ContextValue
+);
+
 PBUS_HANDLER
 FASTCALL
 HaliReferenceHandlerForConfigSpace(
 PBUS_HANDLER
 FASTCALL
 HaliReferenceHandlerForConfigSpace(
@@ -534,5 +550,6 @@ extern ULONG HalpBusType;
 extern BOOLEAN HalpPCIConfigInitialized;
 extern BUS_HANDLER HalpFakePciBusHandler;
 extern ULONG HalpMinPciBus, HalpMaxPciBus;
 extern BOOLEAN HalpPCIConfigInitialized;
 extern BUS_HANDLER HalpFakePciBusHandler;
 extern ULONG HalpMinPciBus, HalpMaxPciBus;
+extern LIST_ENTRY HalpAllBusHandlers;
 
 /* EOF */
 
 /* EOF */