]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyPci.c
IntelFrameworkModulePkg/LegacyBios: Get SIO data from SIO interface
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacyPci.c
index 1d09bb879d41f3e51fa711c3091eb97ddc369f5f..9d84ab00000ce8303cb6aa9289065eb2fef10c57 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
@@ -1198,7 +1198,7 @@ PciProgramAllInterruptLineRegisters (
                       &Supports\r
                       );\r
     if (!EFI_ERROR (Status)) {\r
-      Supports &= EFI_PCI_DEVICE_ENABLE;\r
+      Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;\r
       Status = PciIo->Attributes (\r
                         PciIo,\r
                         EfiPciIoAttributeOperationEnable,\r
@@ -1500,54 +1500,52 @@ UpdateBevBcvTable (
     }\r
   }\r
 \r
-  if (PciPtr >= (EFI_LEGACY_EXPANSION_ROM_HEADER *) ((UINTN) 0xc8000)) {\r
-    while (TRUE) {\r
-      Status    = FindNextPnpExpansionHeader (Private, Instance, &PnpPtr);\r
-      Instance  = NOT_FIRST_INSTANCE;\r
-      if (EFI_ERROR (Status)) {\r
-        break;\r
-      }\r
-      //\r
-      // There can be additional $PnP headers within the OPROM.\r
-      // Example: SCSI can have one per drive.\r
-      //\r
-      BbsTable[BbsIndex].BootPriority             = BBS_UNPRIORITIZED_ENTRY;\r
-      BbsTable[BbsIndex].DeviceType               = DeviceType;\r
-      BbsTable[BbsIndex].Bus                      = (UINT32) Bus;\r
-      BbsTable[BbsIndex].Device                   = (UINT32) Device;\r
-      BbsTable[BbsIndex].Function                 = (UINT32) Function;\r
-      BbsTable[BbsIndex].StatusFlags.OldPosition  = 0;\r
-      BbsTable[BbsIndex].StatusFlags.Reserved1    = 0;\r
-      BbsTable[BbsIndex].StatusFlags.Enabled      = 0;\r
-      BbsTable[BbsIndex].StatusFlags.Failed       = 0;\r
-      BbsTable[BbsIndex].StatusFlags.MediaPresent = 0;\r
-      BbsTable[BbsIndex].StatusFlags.Reserved2    = 0;\r
-      BbsTable[BbsIndex].Class                    = PnpPtr->Class;\r
-      BbsTable[BbsIndex].SubClass                 = PnpPtr->SubClass;\r
-      BbsTable[BbsIndex].DescStringOffset         = PnpPtr->ProductNamePointer;\r
-      BbsTable[BbsIndex].DescStringSegment        = mBbsRomSegment;\r
-      BbsTable[BbsIndex].MfgStringOffset          = PnpPtr->MfgPointer;\r
-      BbsTable[BbsIndex].MfgStringSegment         = mBbsRomSegment;\r
-      BbsTable[BbsIndex].BootHandlerSegment       = mBbsRomSegment;\r
-\r
-      //\r
-      // Have seen case where PXE base code have PnP expansion ROM\r
-      // header but no Bcv or Bev vectors.\r
-      //\r
-      if (PnpPtr->Bcv != 0) {\r
-        BbsTable[BbsIndex].BootHandlerOffset = PnpPtr->Bcv;\r
-        ++BbsIndex;\r
-      }\r
+  while (TRUE) {\r
+    Status    = FindNextPnpExpansionHeader (Private, Instance, &PnpPtr);\r
+    Instance  = NOT_FIRST_INSTANCE;\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+    //\r
+    // There can be additional $PnP headers within the OPROM.\r
+    // Example: SCSI can have one per drive.\r
+    //\r
+    BbsTable[BbsIndex].BootPriority             = BBS_UNPRIORITIZED_ENTRY;\r
+    BbsTable[BbsIndex].DeviceType               = DeviceType;\r
+    BbsTable[BbsIndex].Bus                      = (UINT32) Bus;\r
+    BbsTable[BbsIndex].Device                   = (UINT32) Device;\r
+    BbsTable[BbsIndex].Function                 = (UINT32) Function;\r
+    BbsTable[BbsIndex].StatusFlags.OldPosition  = 0;\r
+    BbsTable[BbsIndex].StatusFlags.Reserved1    = 0;\r
+    BbsTable[BbsIndex].StatusFlags.Enabled      = 0;\r
+    BbsTable[BbsIndex].StatusFlags.Failed       = 0;\r
+    BbsTable[BbsIndex].StatusFlags.MediaPresent = 0;\r
+    BbsTable[BbsIndex].StatusFlags.Reserved2    = 0;\r
+    BbsTable[BbsIndex].Class                    = PnpPtr->Class;\r
+    BbsTable[BbsIndex].SubClass                 = PnpPtr->SubClass;\r
+    BbsTable[BbsIndex].DescStringOffset         = PnpPtr->ProductNamePointer;\r
+    BbsTable[BbsIndex].DescStringSegment        = mBbsRomSegment;\r
+    BbsTable[BbsIndex].MfgStringOffset          = PnpPtr->MfgPointer;\r
+    BbsTable[BbsIndex].MfgStringSegment         = mBbsRomSegment;\r
+    BbsTable[BbsIndex].BootHandlerSegment       = mBbsRomSegment;\r
+\r
+    //\r
+    // Have seen case where PXE base code have PnP expansion ROM\r
+    // header but no Bcv or Bev vectors.\r
+    //\r
+    if (PnpPtr->Bcv != 0) {\r
+      BbsTable[BbsIndex].BootHandlerOffset = PnpPtr->Bcv;\r
+      ++BbsIndex;\r
+    }\r
 \r
-      if (PnpPtr->Bev != 0) {\r
-        BbsTable[BbsIndex].BootHandlerOffset  = PnpPtr->Bev;\r
-        BbsTable[BbsIndex].DeviceType         = BBS_BEV_DEVICE;\r
-        ++BbsIndex;\r
-      }\r
+    if (PnpPtr->Bev != 0) {\r
+      BbsTable[BbsIndex].BootHandlerOffset  = PnpPtr->Bev;\r
+      BbsTable[BbsIndex].DeviceType         = BBS_BEV_DEVICE;\r
+      ++BbsIndex;\r
+    }\r
 \r
-      if ((PnpPtr == (LEGACY_PNP_EXPANSION_HEADER *) PciPtr) || (PnpPtr > (LEGACY_PNP_EXPANSION_HEADER *) RomEnd)) {\r
-        break;\r
-      }\r
+    if ((PnpPtr == (LEGACY_PNP_EXPANSION_HEADER *) PciPtr) || (PnpPtr > (LEGACY_PNP_EXPANSION_HEADER *) RomEnd)) {\r
+      break;\r
     }\r
   }\r
 \r
@@ -1717,6 +1715,20 @@ PciShadowRoms (
     if (!EFI_ERROR (Status)) {\r
       continue;\r
     }\r
+    \r
+    //\r
+    // If legacy VBIOS Oprom has not been dispatched before, install legacy VBIOS here.\r
+    //\r
+    if (IS_PCI_DISPLAY (&Pci) && Index == 0) {    \r
+      Status = LegacyBiosInstallVgaRom (Private);\r
+      //\r
+      // A return status of EFI_NOT_FOUND is considered valid (No EFI\r
+      // driver is controlling video).\r
+      //\r
+      ASSERT ((Status == EFI_SUCCESS) || (Status == EFI_NOT_FOUND));\r
+      continue;\r
+    }\r
+\r
     //\r
     // Install legacy ROM\r
     //\r
@@ -1760,7 +1772,7 @@ PciShadowRoms (
                           &Supports\r
                           );\r
         if (!EFI_ERROR (Status)) {\r
-          Supports &= EFI_PCI_DEVICE_ENABLE;\r
+          Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;\r
           Status = PciIo->Attributes (\r
                             PciIo,\r
                             EfiPciIoAttributeOperationEnable,\r
@@ -1867,6 +1879,7 @@ LegacyBiosCheckPciRomEx (
   PCI_TYPE00                      PciConfigHeader;\r
   VOID                            *LocalConfigUtilityCodeHeader;\r
 \r
+  LocalConfigUtilityCodeHeader = NULL;\r
   *Flags = NO_ROM;\r
   Status = gBS->HandleProtocol (\r
                   PciHandle,\r
@@ -1882,7 +1895,7 @@ LegacyBiosCheckPciRomEx (
   //\r
   Status = IsLegacyRom (PciHandle);\r
   if (!EFI_ERROR (Status)) {\r
-    *Flags |= (ROM_FOUND | VALID_LEGACY_ROM);\r
+    *Flags |= (UINTN)(ROM_FOUND | VALID_LEGACY_ROM);\r
     return EFI_SUCCESS;\r
   }\r
   //\r
@@ -2174,8 +2187,8 @@ LegacyBiosInstallVgaRom (
                     &Supports\r
                     );\r
   if (!EFI_ERROR (Status)) {\r
-    Supports &= EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | \\r
-                EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16;\r
+    Supports &= (UINT64)(EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | \\r
+                         EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16);\r
     Status = PciIo->Attributes (\r
                       PciIo,\r
                       EfiPciIoAttributeOperationEnable,\r
@@ -2271,6 +2284,7 @@ LegacyBiosInstallRom (
   UINT32                LocalTime;\r
   UINT32                StartBbsIndex;\r
   UINT32                EndBbsIndex;\r
+  UINT32                MaxRomAddr;\r
   UINTN                 TempData;\r
   UINTN                 InitAddress;\r
   UINTN                 RuntimeAddress;\r
@@ -2286,6 +2300,15 @@ LegacyBiosInstallRom (
   Function        = 0;\r
   VideoMode       = 0;\r
   PhysicalAddress = 0;\r
+  MaxRomAddr      = PcdGet32 (PcdEndOpromShadowAddress);\r
+\r
+  if ((Private->Legacy16Table->TableLength >= OFFSET_OF(EFI_COMPATIBILITY16_TABLE, HiPermanentMemoryAddress)) &&\r
+      (Private->Legacy16Table->UmaAddress != 0) && \r
+      (Private->Legacy16Table->UmaSize != 0) &&\r
+      (MaxRomAddr > (Private->Legacy16Table->UmaAddress))) {\r
+    MaxRomAddr = Private->Legacy16Table->UmaAddress;\r
+  }\r
+\r
 \r
   PciProgramAllInterruptLineRegisters (Private);\r
 \r
@@ -2304,6 +2327,13 @@ LegacyBiosInstallRom (
         \r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((EFI_D_ERROR, "return LegacyBiosInstallRom(%d): EFI_OUT_OF_RESOURCES (no more space for OpROM)\n", __LINE__));\r
+      //\r
+      // Report Status Code to indicate that there is no enough space for OpROM\r
+      //\r
+      REPORT_STATUS_CODE (\r
+        EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+        (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_LEGACY_OPROM_NO_SPACE)\r
+        );\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     InitAddress = (UINTN) PhysicalAddress;\r
@@ -2311,9 +2341,16 @@ LegacyBiosInstallRom (
     //   then test if there is enough space for its RT code\r
     //\r
     RuntimeAddress = Private->OptionRom;\r
-    if (RuntimeAddress + *RuntimeImageLength > PcdGet32 (PcdEndOpromShadowAddress)) {\r
+    if (RuntimeAddress + *RuntimeImageLength > MaxRomAddr) {\r
       DEBUG ((EFI_D_ERROR, "return LegacyBiosInstallRom(%d): EFI_OUT_OF_RESOURCES (no more space for OpROM)\n", __LINE__));\r
       gBS->FreePages (PhysicalAddress, EFI_SIZE_TO_PAGES (ImageSize));\r
+      //\r
+      // Report Status Code to indicate that there is no enough space for OpROM\r
+      //\r
+      REPORT_STATUS_CODE (\r
+        EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+        (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_LEGACY_OPROM_NO_SPACE)\r
+        );\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
   } else {\r
@@ -2322,8 +2359,15 @@ LegacyBiosInstallRom (
     //   test if there is enough space for its INIT code\r
     //\r
     InitAddress    = PCI_START_ADDRESS (Private->OptionRom);\r
-    if (InitAddress + ImageSize > PcdGet32 (PcdEndOpromShadowAddress)) {\r
+    if (InitAddress + ImageSize > MaxRomAddr) {\r
       DEBUG ((EFI_D_ERROR, "return LegacyBiosInstallRom(%d): EFI_OUT_OF_RESOURCES (no more space for OpROM)\n", __LINE__));\r
+      //\r
+      // Report Status Code to indicate that there is no enough space for OpROM\r
+      //\r
+      REPORT_STATUS_CODE (\r
+        EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+        (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_LEGACY_OPROM_NO_SPACE)\r
+        );\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
@@ -2536,7 +2580,16 @@ LegacyBiosInstallRom (
   //\r
   // The ROM could have updated it's size so we need to read again.\r
   //\r
-  *RuntimeImageLength = ((EFI_LEGACY_EXPANSION_ROM_HEADER *) (RuntimeAddress))->Size512 * 512;\r
+  if (((EFI_LEGACY_EXPANSION_ROM_HEADER *) RuntimeAddress)->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {\r
+    //\r
+    // Now we check the signature (0xaa55) to judge whether the run-time code is truly generated by INIT function.\r
+    // If signature is not valid, that means the INIT function didn't copy the run-time code to RuntimeAddress.\r
+    //\r
+    *RuntimeImageLength = 0;\r
+  } else {\r
+    *RuntimeImageLength = ((EFI_LEGACY_EXPANSION_ROM_HEADER *) RuntimeAddress)->Size512 * 512;\r
+  }\r
+\r
   DEBUG ((EFI_D_INFO, " fsize = %x\n", *RuntimeImageLength));\r
 \r
   //\r
@@ -2872,7 +2925,15 @@ LegacyBiosInstallPciRom (
       return EFI_UNSUPPORTED;\r
     }\r
 \r
-    if (!Private->VgaInstalled) {\r
+    Status = Private->LegacyBiosPlatform->GetPlatformHandle (\r
+                                            Private->LegacyBiosPlatform,\r
+                                            EfiGetPlatformVgaHandle,\r
+                                            0,\r
+                                            &HandleBuffer,\r
+                                            &HandleCount,\r
+                                            NULL\r
+                                            );\r
+    if ((!EFI_ERROR (Status)) && (!Private->VgaInstalled)) {\r
       //\r
       // A return status of EFI_NOT_FOUND is considered valid (No EFI\r
       // driver is controlling video.\r
@@ -2900,7 +2961,7 @@ LegacyBiosInstallPciRom (
     Pcir = (PCI_3_0_DATA_STRUCTURE *)\r
            ((UINT8 *) LocalRomImage + ((PCI_EXPANSION_ROM_HEADER *) LocalRomImage)->PcirOffset);\r
 \r
-    if (Pcir->Signature != PCI_DATA_STRUCTURE_SIGNATURE) {\r
+    if ((Pcir->Signature != PCI_DATA_STRUCTURE_SIGNATURE) || (Pcir->CodeType != PCI_CODE_TYPE_PCAT_IMAGE)) {\r
       mVgaInstallationInProgress = FALSE;\r
       return EFI_UNSUPPORTED;\r
     }\r