[PCI]: Add PCI IRQ Routing Table structure to Shared, Internal PCI Header (based...
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / hwpci.c
index ebe3e50..20960cf 100644 (file)
@@ -13,9 +13,9 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <freeldr.h>
 #define NDEBUG
 #include <debug.h>
 
-typedef struct _ROUTING_SLOT
-{
-  UCHAR  BusNumber;
-  UCHAR  DeviceNumber;
-  UCHAR  LinkA;
-  USHORT BitmapA;
-  UCHAR  LinkB;
-  USHORT BitmapB;
-  UCHAR  LinkC;
-  USHORT BitmapC;
-  UCHAR  LinkD;
-  USHORT BitmapD;
-  UCHAR  SlotNumber;
-  UCHAR  Reserved;
-} __attribute__((packed)) ROUTING_SLOT, *PROUTING_SLOT;
-
-typedef struct _PCI_IRQ_ROUTING_TABLE
-{
-  ULONG Signature;
-  USHORT Version;
-  USHORT Size;
-  UCHAR  RouterBus;
-  UCHAR  RouterSlot;
-  USHORT ExclusiveIRQs;
-  ULONG CompatibleRouter;
-  ULONG MiniportData;
-  UCHAR  Reserved[11];
-  UCHAR  Checksum;
-  ROUTING_SLOT Slot[1];
-} __attribute__((packed)) PCI_IRQ_ROUTING_TABLE, *PPCI_IRQ_ROUTING_TABLE;
-
-typedef struct _PCI_REGISTRY_INFO
-{
-    UCHAR MajorRevision;
-    UCHAR MinorRevision;
-    UCHAR NoBuses;
-    UCHAR HardwareMechanism;
-} PCI_REGISTRY_INFO, *PPCI_REGISTRY_INFO;
-
 static PPCI_IRQ_ROUTING_TABLE
 GetPciIrqRoutingTable(VOID)
 {
@@ -73,14 +34,14 @@ GetPciIrqRoutingTable(VOID)
   Table = (PPCI_IRQ_ROUTING_TABLE)0xF0000;
   while ((ULONG_PTR)Table < 0x100000)
     {
-      if (Table->Signature == 0x52495024)
+      if (Table->Signature == 'RIP$')
        {
          DPRINTM(DPRINT_HWDETECT,
                    "Found signature\n");
 
          Ptr = (PUCHAR)Table;
          Sum = 0;
-         for (i = 0; i < Table->Size; i++)
+         for (i = 0; i < Table->TableSize; i++)
            {
              Sum += Ptr[i];
            }
@@ -128,7 +89,7 @@ FindPciBios(PPCI_REGISTRY_INFO BusData)
       BusData->NoBuses = RegsOut.b.cl + 1;
       BusData->MajorRevision = RegsOut.b.bh;
       BusData->MinorRevision = RegsOut.b.bl;
-      BusData->HardwareMechanism = RegsOut.b.cl;
+      BusData->HardwareMechanism = RegsOut.b.al;
 
       return TRUE;
     }
@@ -152,20 +113,11 @@ DetectPciIrqRoutingTable(PCONFIGURATION_COMPONENT_DATA BusKey)
   Table = GetPciIrqRoutingTable();
   if (Table != NULL)
     {
-      DPRINTM(DPRINT_HWDETECT, "Table size: %u\n", Table->Size);
-
-      FldrCreateComponentKey(BusKey,
-                             PeripheralClass,
-                             RealModeIrqRoutingTable,
-                             0x0,
-                             0x0,
-                             0xFFFFFFFF,
-                             "PCI Real-mode IRQ Routing Table",
-                             &TableKey);
+      DPRINTM(DPRINT_HWDETECT, "Table size: %u\n", Table->TableSize);
 
       /* Set 'Configuration Data' value */
       Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
-         2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + Table->Size;
+         2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) + Table->TableSize;
       PartialResourceList = MmHeapAlloc(Size);
       if (PartialResourceList == NULL)
       {
@@ -189,13 +141,22 @@ DetectPciIrqRoutingTable(PCONFIGURATION_COMPONENT_DATA BusKey)
       PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
       PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
       PartialDescriptor->ShareDisposition = CmResourceShareUndetermined;
-      PartialDescriptor->u.DeviceSpecificData.DataSize = Table->Size;
+      PartialDescriptor->u.DeviceSpecificData.DataSize = Table->TableSize;
 
       memcpy(&PartialResourceList->PartialDescriptors[2],
-          Table, Table->Size);
+          Table, Table->TableSize);
+
+      FldrCreateComponentKey(BusKey,
+                             PeripheralClass,
+                             RealModeIrqRoutingTable,
+                             0x0,
+                             0x0,
+                             0xFFFFFFFF,
+                             "PCI Real-mode IRQ Routing Table",
+                             PartialResourceList,
+                             Size,
+                             &TableKey);
 
-      /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(TableKey, PartialResourceList, Size);
       MmHeapFree(PartialResourceList);
     }
 }
@@ -215,19 +176,6 @@ DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
   /* Report the PCI BIOS */
   if (FindPciBios(&BusData))
     {
-      /* Create new bus key */
-      FldrCreateComponentKey(SystemKey,
-                             AdapterClass,
-                             MultiFunctionAdapter,
-                             0x0,
-                             0x0,
-                             0xFFFFFFFF,
-                             "PCI BIOS",
-                             &BiosKey);
-
-      /* Increment bus number */
-      (*BusNumber)++;
-
       /* Set 'Configuration Data' value */
       Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST,
                           PartialDescriptors);
@@ -242,8 +190,21 @@ DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
       /* Initialize resource descriptor */
       memset(PartialResourceList, 0, Size);
 
-      /* Set 'Configuration Data' value */
-      FldrSetConfigurationData(BiosKey, PartialResourceList, Size);
+      /* Create new bus key */
+      FldrCreateComponentKey(SystemKey,
+                             AdapterClass,
+                             MultiFunctionAdapter,
+                             0x0,
+                             0x0,
+                             0xFFFFFFFF,
+                             "PCI BIOS",
+                             PartialResourceList,
+                             Size,
+                             &BiosKey);
+
+      /* Increment bus number */
+      (*BusNumber)++;
+
       MmHeapFree(PartialResourceList);
 
       DetectPciIrqRoutingTable(BiosKey);
@@ -251,16 +212,6 @@ DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
       /* Report PCI buses */
       for (i = 0; i < (ULONG)BusData.NoBuses; i++)
       {
-          /* Create the bus key */
-          FldrCreateComponentKey(SystemKey,
-                                 AdapterClass,
-                                 MultiFunctionAdapter,
-                                 0x0,
-                                 0x0,
-                                 0xFFFFFFFF,
-                                 "PCI",
-                                 &BusKey);
-
           /* Check if this is the first bus */
           if (i == 0)
           {
@@ -289,10 +240,6 @@ DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
               memcpy(&PartialResourceList->PartialDescriptors[1],
                      &BusData,
                      sizeof(PCI_REGISTRY_INFO));
-
-              /* Set 'Configuration Data' value */
-              FldrSetConfigurationData(BusKey, PartialResourceList, Size);
-              MmHeapFree(PartialResourceList);
           }
           else
           {
@@ -309,12 +256,22 @@ DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 
               /* Initialize resource descriptor */
               memset(PartialResourceList, 0, Size);
-
-              /* Set 'Configuration Data' value */
-              FldrSetConfigurationData(BusKey, PartialResourceList, Size);
-              MmHeapFree(PartialResourceList);
           }
 
+          /* Create the bus key */
+          FldrCreateComponentKey(SystemKey,
+                                 AdapterClass,
+                                 MultiFunctionAdapter,
+                                 0x0,
+                                 0x0,
+                                 0xFFFFFFFF,
+                                 "PCI",
+                                 PartialResourceList,
+                                 Size,
+                                 &BusKey);
+
+          MmHeapFree(PartialResourceList);
+
           /* Increment bus number */
           (*BusNumber)++;
       }