]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/Library/DuetBdsLib/BdsPlatform.c
remove the self-implementation on checksum() in this module by using BaseLib.
[mirror_edk2.git] / DuetPkg / Library / DuetBdsLib / BdsPlatform.c
index 71e9b5db507fb88eb8bc01f7f52dc16e044a640d..da0613017fb88f46c0b9008c7d3b2e60a818d62a 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
+Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -27,6 +27,11 @@ Abstract:
 CHAR16  mFirmwareVendor[] = L"TianoCore.org";\r
 extern BOOLEAN  gConnectAllHappened;\r
 extern USB_CLASS_FORMAT_DEVICE_PATH gUsbClassKeyboardDevicePath;\r
+\r
+EFI_GUID                    *gTableGuidArray[] = {\r
+    &gEfiAcpi20TableGuid, &gEfiAcpiTableGuid, &gEfiSmbiosTableGuid, &gEfiMpsTableGuid\r
+  };\r
+\r
 //\r
 // BDS Platform Functions\r
 //\r
@@ -48,39 +53,30 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_STATUS                  Status;\r
-  EFI_HOB_HANDOFF_INFO_TABLE  *HobList;\r
-  EFI_HOB_HANDOFF_INFO_TABLE  *HobStart;\r
+  EFI_PEI_HOB_POINTERS        GuidHob;\r
+  EFI_PEI_HOB_POINTERS        HobStart;\r
   EFI_PHYSICAL_ADDRESS        *Table;\r
   UINTN                       Index;\r
-  EFI_GUID                    *TableGuidArray[] = {\r
-    &gEfiAcpi20TableGuid, &gEfiAcpiTableGuid, &gEfiSmbiosTableGuid, &gEfiMpsTableGuid\r
-  };\r
 \r
   //\r
   // Get Hob List\r
   //\r
-  Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, (VOID *) &HobList);\r
-  if (EFI_ERROR (Status)) {\r
-    return;\r
-  }\r
-\r
+  HobStart.Raw = GetHobList ();\r
   //\r
   // Iteratively add ACPI Table, SMBIOS Table, MPS Table to EFI System Table\r
   //\r
-  for (Index = 0; Index < sizeof (TableGuidArray) / sizeof (*TableGuidArray); ++Index) {\r
-    HobStart = HobList;\r
-    Table = NULL;\r
-    Table = GetNextGuidHob (TableGuidArray[Index], &HobStart);\r
-    if (!EFI_ERROR (Status)) {\r
+  for (Index = 0; Index < sizeof (gTableGuidArray) / sizeof (*gTableGuidArray); ++Index) {\r
+    GuidHob.Raw = GetNextGuidHob (gTableGuidArray[Index], HobStart.Raw);\r
+    if (GuidHob.Raw != NULL) {\r
+      Table = GET_GUID_HOB_DATA (GuidHob.Guid);\r
       if (Table != NULL) {\r
         //\r
         // Check if Mps Table/Smbios Table/Acpi Table exists in E/F seg,\r
         // According to UEFI Spec, we should make sure Smbios table, \r
         // ACPI table and Mps tables kept in memory of specified type\r
         //\r
-        ConvertSystemTable(TableGuidArray[Index], &Table);\r
-        gBS->InstallConfigurationTable (TableGuidArray[Index], (VOID *)Table);\r
+        ConvertSystemTable(gTableGuidArray[Index], (VOID**)&Table);\r
+        gBS->InstallConfigurationTable (gTableGuidArray[Index], (VOID *)Table);\r
       }\r
     }\r
   }\r
@@ -89,7 +85,7 @@ Returns:
 }\r
 \r
 #define EFI_LDR_MEMORY_DESCRIPTOR_GUID \\r
-  { 0x7701d7e5, 0x7d1d, 0x4432, 0xa4, 0x68, 0x67, 0x3d, 0xab, 0x8a, 0xde, 0x60 }\r
+  { 0x7701d7e5, 0x7d1d, 0x4432, {0xa4, 0x68, 0x67, 0x3d, 0xab, 0x8a, 0xde, 0x60 }}\r
 \r
 EFI_GUID gEfiLdrMemoryDescriptorGuid = EFI_LDR_MEMORY_DESCRIPTOR_GUID;\r
 \r
@@ -152,7 +148,7 @@ UpdateMemoryMap (
   )\r
 {\r
   EFI_STATUS                  Status;\r
-  EFI_HOB_HANDOFF_INFO_TABLE  *HobList;\r
+  EFI_PEI_HOB_POINTERS        GuidHob;\r
   VOID                        *Table;\r
   MEMORY_DESC_HOB             MemoryDescHob;\r
   UINTN                       Index;\r
@@ -161,12 +157,18 @@ UpdateMemoryMap (
   //\r
   // Get Hob List\r
   //\r
-  Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, (VOID *) &HobList);\r
-  if (EFI_ERROR (Status)) {\r
+  GuidHob.Raw = GetHobList();\r
+  \r
+  GuidHob.Raw = GetNextGuidHob (&gEfiLdrMemoryDescriptorGuid, GuidHob.Raw);\r
+  if (GuidHob.Raw == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "Fail to get gEfiLdrMemoryDescriptorGuid from GUID HOB LIST!\n"));\r
+    return;\r
+  }\r
+  Table = GET_GUID_HOB_DATA (GuidHob.Guid);\r
+  if (Table == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "Fail to get gEfiLdrMemoryDescriptorGuid from GUID HOB LIST!\n"));\r
     return;\r
   }\r
-\r
-  Table = GetNextGuidHob (&gEfiLdrMemoryDescriptorGuid, &HobList);\r
   MemoryDescHob.MemDescCount = *(UINTN *)Table;\r
   MemoryDescHob.MemDesc      = *(EFI_MEMORY_DESCRIPTOR **)((UINTN)Table + sizeof(UINTN));\r
 \r
@@ -177,7 +179,7 @@ UpdateMemoryMap (
     if (MemoryDescHob.MemDesc[Index].PhysicalStart < 0x100000) {\r
       continue;\r
     }\r
-    if (MemoryDescHob.MemDesc[Index].PhysicalStart >= 0x100000000) {\r
+    if (MemoryDescHob.MemDesc[Index].PhysicalStart >= 0x100000000ULL) {\r
       continue;\r
     }\r
     if ((MemoryDescHob.MemDesc[Index].Type == EfiReservedMemoryType) ||\r
@@ -217,7 +219,7 @@ UpdateMemoryMap (
       Memory = MemoryDescHob.MemDesc[Index].PhysicalStart;\r
       Status = gBS->AllocatePages (\r
                       AllocateAddress,\r
-                      MemoryDescHob.MemDesc[Index].Type,\r
+                      (EFI_MEMORY_TYPE)MemoryDescHob.MemDesc[Index].Type,\r
                       (UINTN)MemoryDescHob.MemDesc[Index].NumberOfPages,\r
                       &Memory\r
                       );\r
@@ -347,8 +349,9 @@ Returns:
 \r
 \r
 VOID\r
+EFIAPI\r
 PlatformBdsInit (\r
-  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData\r
+  VOID\r
   )\r
 /*++\r
 \r
@@ -359,8 +362,6 @@ Routine Description:
 \r
 Arguments:\r
 \r
-  PrivateData  - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
-\r
 Returns:\r
 \r
   None.\r
@@ -382,6 +383,19 @@ Returns:
   // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
   //\r
   gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
+\r
+  GetSystemTablesFromHob ();\r
+\r
+  UpdateMemoryMap ();\r
+  \r
+  //\r
+  // Append Usb Keyboard short form DevicePath into "ConInDev" \r
+  //\r
+  BdsLibUpdateConsoleVariable (\r
+    VarConsoleInpDev,\r
+    (EFI_DEVICE_PATH_PROTOCOL *) &gUsbClassKeyboardDevicePath,\r
+    NULL\r
+    );\r
 }\r
 \r
 UINT64\r
@@ -407,23 +421,20 @@ Returns:
   UINTN                                    BufferSize;\r
   UINT32                                   Index;\r
   UINT32                                   Number;\r
-  VOID                                     *HobList;\r
-  EFI_STATUS                               Status;\r
-\r
-  BufferSize = 0;\r
-  //\r
-  // Get Hob List from configuration table\r
-  //\r
-  Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &HobList);\r
-  if (EFI_ERROR (Status)) {\r
-    return 0;\r
-  }\r
+  EFI_PEI_HOB_POINTERS                     GuidHob;\r
 \r
   //\r
   // Get PciExpressAddressInfo Hob\r
   //\r
   PciExpressBaseAddressInfo = NULL;\r
-  PciExpressBaseAddressInfo = GetNextGuidHob (&gEfiPciExpressBaseAddressGuid, &HobList);\r
+  BufferSize                = 0;\r
+  GuidHob.Raw = GetFirstGuidHob (&gEfiPciExpressBaseAddressGuid);\r
+  if (GuidHob.Raw != NULL) {\r
+    PciExpressBaseAddressInfo = GET_GUID_HOB_DATA (GuidHob.Guid);\r
+    BufferSize                = GET_GUID_HOB_DATA_SIZE (GuidHob.Guid);\r
+  } else {\r
+    return 0;\r
+  }\r
 \r
   //\r
   // Search the PciExpress Base Address in the Hob for current RootBridge\r
@@ -439,7 +450,7 @@ Returns:
   //\r
   // Do not find the PciExpress Base Address in the Hob\r
   //\r
-  return 0;\r
+  return 0;  \r
 }\r
 \r
 VOID\r
@@ -452,7 +463,9 @@ PatchPciRootBridgeDevicePath (
   UINT64  PciExpressBase;\r
 \r
   PciExpressBase = GetPciExpressBaseAddressForRootBridge (HostBridgeNumber, RootBridgeNumber);\r
-\r
+  \r
+  DEBUG ((EFI_D_INFO, "Get PciExpress Address from Hob: 0x%X\n", PciExpressBase));\r
+  \r
   if (PciExpressBase != 0) {\r
     RootBridge->PciRootBridge.HID = EISA_PNP_ID(0x0A08);\r
   }\r
@@ -497,6 +510,8 @@ Returns:
                   &gPlatformRootBridges[0], \r
                   &RootHandle\r
                   );\r
+  DEBUG ((EFI_D_INFO, "Pci Root bridge handle is 0x%X\n", RootHandle));\r
+  \r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -540,7 +555,7 @@ Returns:
   Status = gBS->HandleProtocol (\r
                   DeviceHandle,\r
                   &gEfiDevicePathProtocolGuid,\r
-                  &DevicePath\r
+                  (VOID*)&DevicePath\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -585,7 +600,6 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
 EFI_STATUS\r
 GetGopDevicePath (\r
    IN  EFI_DEVICE_PATH_PROTOCOL *PciDevicePath,\r
@@ -639,7 +653,7 @@ GetGopDevicePath (
     // Add all the child handles as possible Console Device\r
     //\r
     for (Index = 0; Index < GopHandleCount; Index++) {\r
-      Status = gBS->HandleProtocol (GopHandleBuffer[Index], &gEfiDevicePathProtocolGuid, &TempDevicePath);\r
+      Status = gBS->HandleProtocol (GopHandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID*)&TempDevicePath);\r
       if (EFI_ERROR (Status)) {\r
         continue;\r
       }\r
@@ -670,7 +684,6 @@ GetGopDevicePath (
 \r
   return EFI_SUCCESS;\r
 }\r
-#endif\r
 \r
 EFI_STATUS\r
 PreparePciVgaDevicePath (\r
@@ -696,24 +709,20 @@ Returns:
 {\r
   EFI_STATUS                Status;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
   EFI_DEVICE_PATH_PROTOCOL  *GopDevicePath;\r
-#endif  \r
 \r
   DevicePath = NULL;\r
   Status = gBS->HandleProtocol (\r
                   DeviceHandle,\r
                   &gEfiDevicePathProtocolGuid,\r
-                  &DevicePath\r
+                  (VOID*)&DevicePath\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
   \r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
   GetGopDevicePath (DevicePath, &GopDevicePath);\r
   DevicePath = GopDevicePath;\r
-#endif\r
 \r
   BdsLibUpdateConsoleVariable (VarConsoleOut, DevicePath, NULL);\r
   \r
@@ -744,12 +753,12 @@ Returns:
 {\r
   EFI_STATUS                Status;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-\r
+  \r
   DevicePath = NULL;\r
   Status = gBS->HandleProtocol (\r
                   DeviceHandle,\r
                   &gEfiDevicePathProtocolGuid,\r
-                  &DevicePath\r
+                  (VOID*)&DevicePath\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -810,7 +819,7 @@ Returns:
   }\r
 \r
   for (Index = 0; Index < HandleCount; Index++) {\r
-    Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtocolGuid, &PciIo);\r
+    Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiPciIoProtocolGuid, (VOID*)&PciIo);\r
     if (EFI_ERROR (Status)) {\r
       continue;\r
     }\r
@@ -839,6 +848,7 @@ Returns:
         // Add IsaKeyboard to ConIn,\r
         // add IsaSerial to ConOut, ConIn, ErrOut\r
         //\r
+        DEBUG ((EFI_D_INFO, "Find the LPC Bridge device\n"));\r
         PrepareLpcBridgeDevicePath (HandleBuffer[Index]);\r
         continue;\r
       }\r
@@ -849,6 +859,7 @@ Returns:
         //\r
         // Add them to ConOut, ConIn, ErrOut.\r
         //\r
+        DEBUG ((EFI_D_INFO, "Find the 16550 SERIAL device\n"));\r
         PreparePciSerialDevicePath (HandleBuffer[Index]);\r
         continue;\r
       }\r
@@ -861,6 +872,7 @@ Returns:
       //\r
       // Add them to ConOut.\r
       //\r
+      DEBUG ((EFI_D_INFO, "Find the VGA device\n"));\r
       PreparePciVgaDevicePath (HandleBuffer[Index]);\r
       continue;\r
     }\r
@@ -918,6 +930,7 @@ Returns:
                &gEfiGlobalVariableGuid,\r
                &DevicePathSize\r
                );\r
+  \r
   if (VarConout == NULL || VarConin == NULL) {\r
     //\r
     // Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut\r
@@ -1080,7 +1093,7 @@ Returns:
   // from the graphic lib\r
   //\r
   if (QuietBoot) {\r
-    Status = EnableQuietBootEx (&gEfiDefaultBmpLogoGuid, mBdsImageHandle);\r
+    Status = EnableQuietBoot (&gEfiDefaultBmpLogoGuid);\r
     if (EFI_ERROR (Status)) {\r
       DisableQuietBoot ();\r
       return;\r
@@ -1103,8 +1116,8 @@ Returns:
 }\r
 \r
 VOID\r
+EFIAPI\r
 PlatformBdsPolicyBehavior (\r
-  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData,\r
   IN OUT LIST_ENTRY              *DriverOptionList,\r
   IN OUT LIST_ENTRY              *BootOptionList\r
   )\r
@@ -1118,8 +1131,6 @@ Routine Description:
   \r
 Arguments:\r
 \r
-  PrivateData      - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
-  \r
   DriverOptionList - The header of the driver option link list\r
   \r
   BootOptionList   - The header of the boot option link list\r
@@ -1138,11 +1149,12 @@ Returns:
   UINTN                              Index;\r
   EFI_INPUT_KEY                      Key;\r
   EFI_TPL                            OldTpl;\r
+  EFI_BOOT_MODE                      BootMode;\r
 \r
   //\r
   // Init the time out value\r
   //\r
-  Timeout = BdsLibGetTimeout ();\r
+  Timeout = PcdGet16 (PcdPlatformBootTimeOut);\r
 \r
   //\r
   // Load the driver option as the driver option list\r
@@ -1152,14 +1164,14 @@ Returns:
   //\r
   // Get current Boot Mode\r
   //\r
-  Status = BdsLibGetBootMode (&PrivateData->BootMode);\r
-  DEBUG ((EFI_D_ERROR, "Boot Mode:%x\n", PrivateData->BootMode));\r
+  Status = BdsLibGetBootMode (&BootMode);\r
+  DEBUG ((EFI_D_ERROR, "Boot Mode:%x\n", BootMode));\r
 \r
   //\r
   // Go the different platform policy with different boot mode\r
   // Notes: this part code can be change with the table policy\r
   //\r
-  ASSERT (PrivateData->BootMode == BOOT_WITH_FULL_CONFIGURATION);\r
+  ASSERT (BootMode == BOOT_WITH_FULL_CONFIGURATION);\r
   //\r
   // Connect platform console\r
   //\r
@@ -1174,7 +1186,7 @@ Returns:
   // Create a 300ms duration event to ensure user has enough input time to enter Setup\r
   //\r
   Status = gBS->CreateEvent (\r
-                  EFI_EVENT_TIMER,\r
+                  EVT_TIMER,\r
                   0,\r
                   NULL,\r
                   NULL,\r
@@ -1197,6 +1209,8 @@ Returns:
   // Give one chance to enter the setup if we\r
   // have the time out\r
   //\r
+  // BUGBUG: hard code timeout to 5 second to show logo in graphic mode.\r
+  Timeout = 5;  \r
   if (Timeout != 0) {\r
     PlatformBdsEnterFrontPage (Timeout, FALSE);\r
   }\r
@@ -1271,6 +1285,7 @@ Returns:
 }\r
 \r
 VOID\r
+EFIAPI\r
 PlatformBdsBootSuccess (\r
   IN  BDS_COMMON_OPTION *Option\r
   )\r
@@ -1307,6 +1322,7 @@ Returns:
 }\r
 \r
 VOID\r
+EFIAPI\r
 PlatformBdsBootFail (\r
   IN  BDS_COMMON_OPTION  *Option,\r
   IN  EFI_STATUS         Status,\r
@@ -1446,38 +1462,6 @@ Returns:
   return EFI_UNSUPPORTED;\r
 }  \r
 \r
-UINT8\r
-GetBufferCheckSum (\r
-  IN VOID *      Buffer,\r
-  IN UINTN       Length\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Caculate buffer checksum (8-bit)\r
-\r
-Arguments:\r
-  Buffer - Pointer to Buffer that to be caculated\r
-  Length - How many bytes are to be caculated  \r
-\r
-Returns:\r
-  Checksum of the buffer\r
-\r
---*/\r
-{\r
-  UINT8   CheckSum;\r
-  UINT8   *Ptr8;\r
-  \r
-  CheckSum = 0;\r
-  Ptr8 = (UINT8 *) Buffer;\r
-  \r
-  while (Length > 0) {\r
-    CheckSum = (UINT8) (CheckSum + *Ptr8++);\r
-    Length--;\r
-  }\r
-  \r
-  return ((0xFF - CheckSum) + 1);\r
-}  \r
 \r
 EFI_STATUS\r
 ConvertAcpiTable (\r
@@ -1612,7 +1596,7 @@ Returns:
   SmbiosTableNew->TableAddress = (UINT32)BufferPtr;\r
   SmbiosTableNew->IntermediateChecksum = 0;\r
   SmbiosTableNew->IntermediateChecksum = \r
-          GetBufferCheckSum ((UINT8*)SmbiosTableNew + 0x10, SmbiosEntryLen -0x10);\r
+          CalculateCheckSum8 ((UINT8*)SmbiosTableNew + 0x10, SmbiosEntryLen -0x10);\r
   //\r
   // Change the SMBIOS pointer\r
   //\r
@@ -1711,10 +1695,10 @@ Returns:
         MpsTableNew->OemTablePointer = (UINT32)(UINTN)OemTableNew;\r
     }\r
     MpsTableNew->Checksum = 0;\r
-    MpsTableNew->Checksum = GetBufferCheckSum (MpsTableNew, MpsTableOri->BaseTableLength);\r
+    MpsTableNew->Checksum = CalculateCheckSum8 (MpsTableNew, MpsTableOri->BaseTableLength);\r
     MpsFloatingPointerNew->PhysicalAddress = (UINT32)(UINTN)MpsTableNew;\r
     MpsFloatingPointerNew->Checksum = 0;\r
-    MpsFloatingPointerNew->Checksum = GetBufferCheckSum (MpsFloatingPointerNew, FPLength);\r
+    MpsFloatingPointerNew->Checksum = CalculateCheckSum8 (MpsFloatingPointerNew, FPLength);\r
   }\r
   //\r
   // Change the pointer\r