]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyPci.c
IntelFrameworkModulePkg/KeyboardDxe: Use macro to enable/disable page 0
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacyPci.c
index c4c77ec344a0399b957b559bc5d43035f6c1c052..b10a9dcef6aa34be854f4f3a22a9761bb95b0ae5 100644 (file)
@@ -41,7 +41,7 @@ BOOLEAN                             mIgnoreBbsUpdateFlag;
 BOOLEAN                             mVgaInstallationInProgress  = FALSE;\r
 UINT32                              mRomCount                   = 0x00;\r
 ROM_INSTANCE_ENTRY                  mRomEntry[ROM_MAX_ENTRIES];\r
-\r
+EDKII_IOMMU_PROTOCOL                *mIoMmu;\r
 \r
 /**\r
   Query shadowed legacy ROM parameters registered by RomShadow() previously.\r
@@ -2279,6 +2279,7 @@ LegacyBiosInstallRom (
   UINTN                 Function;\r
   EFI_IA32_REGISTER_SET Regs;\r
   UINT8                 VideoMode;\r
+  UINT8                 OldVideoMode;\r
   EFI_TIME              BootTime;\r
   UINT32                *BdaPtr;\r
   UINT32                LocalTime;\r
@@ -2299,6 +2300,7 @@ LegacyBiosInstallRom (
   Device          = 0;\r
   Function        = 0;\r
   VideoMode       = 0;\r
+  OldVideoMode    = 0;\r
   PhysicalAddress = 0;\r
   MaxRomAddr      = PcdGet32 (PcdEndOpromShadowAddress);\r
 \r
@@ -2401,31 +2403,34 @@ LegacyBiosInstallRom (
   // 2. BBS compliants drives will not change 40:75 until boot time.\r
   // 3. Onboard IDE controllers will change 40:75\r
   //\r
-  LocalDiskStart = (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80);\r
-  if ((Private->Disk4075 + 0x80) < LocalDiskStart) {\r
-    //\r
-    // Update table since onboard IDE drives found\r
-    //\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciSegment        = 0xff;\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciBus            = 0xff;\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciDevice         = 0xff;\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciFunction       = 0xff;\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].StartDriveNumber  = (UINT8) (Private->Disk4075 + 0x80);\r
-    Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].EndDriveNumber    = LocalDiskStart;\r
-    Private->LegacyEfiHddTableIndex ++;\r
-    Private->Disk4075 = (UINT8) (LocalDiskStart & 0x7f);\r
-    Private->DiskEnd  = LocalDiskStart;\r
-  }\r
+  ACCESS_PAGE0_CODE (\r
+    LocalDiskStart = (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80);\r
+    if ((Private->Disk4075 + 0x80) < LocalDiskStart) {\r
+      //\r
+      // Update table since onboard IDE drives found\r
+      //\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciSegment        = 0xff;\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciBus            = 0xff;\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciDevice         = 0xff;\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].PciFunction       = 0xff;\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].StartDriveNumber  = (UINT8) (Private->Disk4075 + 0x80);\r
+      Private->LegacyEfiHddTable[Private->LegacyEfiHddTableIndex].EndDriveNumber    = LocalDiskStart;\r
+      Private->LegacyEfiHddTableIndex ++;\r
+      Private->Disk4075 = (UINT8) (LocalDiskStart & 0x7f);\r
+      Private->DiskEnd  = LocalDiskStart;\r
+    }\r
 \r
-  if (PciHandle != mVgaHandle) {\r
+    if (PciHandle != mVgaHandle) {\r
 \r
-    EnablePs2Keyboard ();\r
+      EnablePs2Keyboard ();\r
+\r
+      //\r
+      // Store current mode settings since PrepareToScanRom may change mode.\r
+      //\r
+      VideoMode = *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE));\r
+    }\r
+  );\r
 \r
-    //\r
-    // Store current mode settings since PrepareToScanRom may change mode.\r
-    //\r
-    VideoMode = *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE));\r
-  }\r
   //\r
   // Notify the platform that we are about to scan the ROM\r
   //\r
@@ -2466,9 +2471,11 @@ LegacyBiosInstallRom (
   // Multiply result by 18.2 for number of ticks since midnight.\r
   // Use 182/10 to avoid floating point math.\r
   //\r
-  LocalTime = (LocalTime * 182) / 10;\r
-  BdaPtr    = (UINT32 *) ((UINTN) 0x46C);\r
-  *BdaPtr   = LocalTime;\r
+  ACCESS_PAGE0_CODE (\r
+    LocalTime = (LocalTime * 182) / 10;\r
+    BdaPtr    = (UINT32 *) ((UINTN) 0x46C);\r
+    *BdaPtr   = LocalTime;\r
+  );\r
   \r
   //\r
   // Pass in handoff data\r
@@ -2564,7 +2571,11 @@ LegacyBiosInstallRom (
     //\r
     // Set mode settings since PrepareToScanRom may change mode\r
     //\r
-    if (VideoMode != *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE))) {\r
+    ACCESS_PAGE0_CODE ({\r
+      OldVideoMode = *(UINT8 *) ((UINTN) (0x400 + BDA_VIDEO_MODE));\r
+    });\r
+\r
+    if (VideoMode != OldVideoMode) {\r
       //\r
       // The active video mode is changed, restore it to original mode.\r
       //\r
@@ -2604,7 +2615,9 @@ LegacyBiosInstallRom (
     }\r
   }\r
 \r
-  LocalDiskEnd = (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80);\r
+  ACCESS_PAGE0_CODE (\r
+    LocalDiskEnd = (UINT8) ((*(UINT8 *) ((UINTN) 0x475)) + 0x80);\r
+  );\r
   \r
   //\r
   // Allow platform to perform any required actions after the\r
@@ -2696,6 +2709,61 @@ Done:
   return Status;\r
 }\r
 \r
+/**\r
+  Let IOMMU grant DMA access for the PCI device.\r
+\r
+  @param  PciHandle             The EFI handle for the PCI device.\r
+  @param  HostAddress           The system memory address to map to the PCI controller.\r
+  @param  NumberOfBytes         The number of bytes to map.\r
+\r
+  @retval EFI_SUCCESS  The DMA access is granted.\r
+**/\r
+EFI_STATUS\r
+IoMmuGrantAccess (\r
+  IN  EFI_HANDLE                        PciHandle,\r
+  IN  EFI_PHYSICAL_ADDRESS              HostAddress,\r
+  IN  UINTN                             NumberOfBytes\r
+  )\r
+{\r
+  EFI_PHYSICAL_ADDRESS            DeviceAddress;\r
+  VOID                            *Mapping;\r
+  EFI_STATUS                      Status;\r
+\r
+  if (PciHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+  if (mIoMmu == NULL) {\r
+    gBS->LocateProtocol (&gEdkiiIoMmuProtocolGuid, NULL, (VOID **)&mIoMmu);\r
+  }\r
+  if (mIoMmu != NULL) {\r
+    Status = mIoMmu->Map (\r
+                       mIoMmu,\r
+                       EdkiiIoMmuOperationBusMasterCommonBuffer,\r
+                       (VOID *)(UINTN)HostAddress,\r
+                       &NumberOfBytes,\r
+                       &DeviceAddress,\r
+                       &Mapping\r
+                       );\r
+    if (EFI_ERROR(Status)) {\r
+      DEBUG ((DEBUG_ERROR, "LegacyPci - IoMmuMap - %r\n", Status));\r
+    } else {\r
+      ASSERT (DeviceAddress == HostAddress);\r
+      Status = mIoMmu->SetAttribute (\r
+                         mIoMmu,\r
+                         PciHandle,\r
+                         Mapping,\r
+                         EDKII_IOMMU_ACCESS_READ | EDKII_IOMMU_ACCESS_WRITE\r
+                         );\r
+      if (EFI_ERROR(Status)) {\r
+        DEBUG ((DEBUG_ERROR, "LegacyPci - IoMmuSetAttribute - %r\n", Status));\r
+      }\r
+    }\r
+  }\r
+  return Status;\r
+}\r
+\r
 /**\r
   Load a legacy PC-AT OPROM on the PciHandle device. Return information\r
   about how many disks were added by the OPROM and the shadow address and\r
@@ -2978,6 +3046,21 @@ LegacyBiosInstallPciRom (
       RuntimeImageLength = Pcir->MaxRuntimeImageLength * 512;\r
     }\r
   }\r
+\r
+  //\r
+  // Grant access for below 1M\r
+  // BDA/EBDA/LowPMM and scratch memory for OPROM.\r
+  //\r
+  IoMmuGrantAccess (PciHandle, 0, SIZE_1MB);\r
+  //\r
+  // Grant access for HiPmm\r
+  //\r
+  IoMmuGrantAccess (\r
+    PciHandle,\r
+    Private->IntThunk->EfiToLegacy16InitTable.HiPmmMemory,\r
+    Private->IntThunk->EfiToLegacy16InitTable.HiPmmMemorySizeInBytes\r
+    );\r
+\r
   //\r
   // Shadow and initialize the OpROM.\r
   //\r