]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
1. PI SMBIOS Checkin. Major change include:
[mirror_edk2.git] / Nt32Pkg / MiscSubClassPlatformDxe / MiscSubclassDriverEntryPoint.c
index 515ccbbc5b0db28cf3b729880d9260c45418d17c..208178eff0424c720ea7e979a62016cee4010298 100644 (file)
@@ -1,6 +1,6 @@
 /**@file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
+Copyright (c) 2006 - 2009, 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
@@ -22,98 +22,78 @@ Abstract:
 \r
 #include "MiscSubclassDriver.h"\r
 \r
+EFI_HII_HANDLE  mHiiHandle;\r
 \r
-extern UINT8  MiscSubclassStrings[];\r
+/**\r
+  This is the standard EFI driver point that detects whether there is a\r
+  MemoryConfigurationData Variable and, if so, reports memory configuration info\r
+  to the DataHub.\r
 \r
+  @param  ImageHandle  Handle for the image of this driver\r
+  @param  SystemTable  Pointer to the EFI System Table\r
 \r
-//\r
-//\r
-//\r
+  @return EFI_SUCCESS if the data is successfully reported\r
+  @return EFI_NOT_FOUND if the HOB list could not be located.\r
+\r
+**/\r
 EFI_STATUS\r
-LogRecordDataToDataHub (\r
-  EFI_DATA_HUB_PROTOCOL *DataHub,\r
-  UINT32                RecordType,\r
-  UINT32                RecordLen,\r
-  VOID                  *RecordData\r
+LogMemorySmbiosRecord (\r
+  VOID\r
   )\r
-/*++\r
-Description:\r
-\r
-Parameters:\r
-\r
-  DataHub\r
-    %%TBD\r
-\r
-  RecordType\r
-    %%TBD\r
-\r
-  RecordLen\r
-    %%TBD\r
-\r
-  RecordData\r
-    %%TBD\r
-\r
-Returns:\r
-\r
-  EFI_INVALID_PARAMETER\r
-\r
-  EFI_SUCCESS\r
-\r
-  Other Data Hub errors\r
-\r
---*/\r
 {\r
-  EFI_MISC_SUBCLASS_DRIVER_DATA MiscSubclass;\r
-  EFI_STATUS                    Status;\r
+  EFI_STATUS                      Status;\r
+  UINT64                          TotalMemorySize;\r
+  UINT8                           NumSlots;\r
+  SMBIOS_TABLE_TYPE19             *Type19Record;\r
+  EFI_SMBIOS_HANDLE               MemArrayMappedAddrSmbiosHandle;\r
+  EFI_SMBIOS_PROTOCOL             *Smbios;\r
+  CHAR16                          *Nt32MemString;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  NumSlots        = 1;\r
 \r
   //\r
-  // Do nothing if data parameters are not valid.\r
+  // Process Memory String in form size!size ...\r
+  // So 64!64 is 128 MB\r
   //\r
-  if (RecordLen == 0 || RecordData == NULL) {\r
-    DEBUG (\r
-      (EFI_D_ERROR,\r
-      "RecordLen == %d  RecordData == %xh\n",\r
-      RecordLen,\r
-      RecordData)\r
-      );\r
-\r
-    return EFI_INVALID_PARAMETER;\r
+  Nt32MemString   = PcdGetPtr (PcdWinNtMemorySize);\r
+  for (TotalMemorySize = 0; *Nt32MemString != '\0';) {\r
+    TotalMemorySize += StrDecimalToUint64 (Nt32MemString);\r
+    while (*Nt32MemString != '\0') {\r
+      if (*Nt32MemString == '!') {\r
+        Nt32MemString++;       \r
+        break;\r
+      }\r
+      Nt32MemString++;\r
+    }\r
   }\r
+\r
+  //\r
+  // Convert Total Memory Size to based on KiloByte\r
   //\r
-  // Assemble Data Hub record.\r
+  TotalMemorySize = LShiftU64 (TotalMemorySize, 20);\r
   //\r
-  MiscSubclass.Header.Version     = EFI_MISC_SUBCLASS_VERSION;\r
-  MiscSubclass.Header.HeaderSize  = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r
-  MiscSubclass.Header.Instance    = 1;\r
-  MiscSubclass.Header.SubInstance = 1;\r
-  MiscSubclass.Header.RecordType  = RecordType;\r
-\r
-  CopyMem (\r
-    &MiscSubclass.Record,\r
-    RecordData,\r
-    RecordLen\r
-    );\r
+  // Generate Memory Array Mapped Address info\r
+  //\r
+  Type19Record = AllocatePool(sizeof (SMBIOS_TABLE_TYPE19));\r
+  ZeroMem(Type19Record, sizeof(SMBIOS_TABLE_TYPE19));\r
+  Type19Record->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS;\r
+  Type19Record->Hdr.Length = sizeof(SMBIOS_TABLE_TYPE19);\r
+  Type19Record->Hdr.Handle = 0;\r
+  Type19Record->StartingAddress = 0;\r
+  Type19Record->EndingAddress =  (UINT32)RShiftU64(TotalMemorySize, 10) - 1;\r
+  Type19Record->MemoryArrayHandle = 0;\r
+  Type19Record->PartitionWidth = (UINT8)(NumSlots); \r
 \r
   //\r
-  // Log Data Hub record.\r
+  // Generate Memory Array Mapped Address info (TYPE 19)\r
   //\r
-  Status = DataHub->LogData (\r
-                        DataHub,\r
-                        &gEfiMiscSubClassGuid,\r
-                        &gEfiMiscSubClassGuid,\r
-                        EFI_DATA_RECORD_CLASS_DATA,\r
-                        &MiscSubclass,\r
-                        sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen\r
-                        );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG (\r
-      (EFI_D_ERROR,\r
-      "LogData(%d bytes) == %r\n",\r
-      sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen,\r
-      Status)\r
-      );\r
-  }\r
+  MemArrayMappedAddrSmbiosHandle = 0;\r
+  Status = Smbios->Add (Smbios, NULL, &MemArrayMappedAddrSmbiosHandle, (EFI_SMBIOS_TABLE_HEADER*) Type19Record);\r
+  FreePool(Type19Record);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   return Status;\r
 }\r
@@ -146,193 +126,45 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_MISC_SUBCLASS_DRIVER_DATA     RecordData;\r
-  EFI_DATA_HUB_PROTOCOL             *DataHub;\r
-  EFI_HII_HANDLE                    HiiHandle;\r
-  EFI_STATUS                        Status;\r
-  UINTN                             Index;\r
-  BOOLEAN                           LogRecordData;\r
-  EFI_MEMORY_SUBCLASS_DRIVER_DATA   MemorySubClassData; \r
-  UINT64                            TotalMemorySize;\r
-  CHAR16                            *Nt32MemString;\r
+  UINTN                Index;\r
+  EFI_STATUS           EfiStatus;\r
+  EFI_SMBIOS_PROTOCOL  *Smbios;  \r
 \r
+  EfiStatus = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
 \r
-  //\r
-  // Initialize constant portion of subclass header.\r
-  //\r
-  RecordData.Header.Version     = EFI_MISC_SUBCLASS_VERSION;\r
-  RecordData.Header.HeaderSize  = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r
-  RecordData.Header.Instance    = 1;\r
-  RecordData.Header.SubInstance = 1;\r
-\r
-  //\r
-  // Locate data hub protocol.\r
-  //\r
-  Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**)&DataHub);\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "Could not locate DataHub protocol.  %r\n", Status));\r
-    return Status;\r
-  } else if (DataHub == NULL) {\r
-    DEBUG ((EFI_D_ERROR, "LocateProtocol(DataHub) returned NULL pointer!\n"));\r
-    return EFI_DEVICE_ERROR;\r
+  if (EFI_ERROR(EfiStatus)) {\r
+    DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol.  %r\n", EfiStatus));\r
+    return EfiStatus;\r
   }\r
-  //\r
-  // Add our default strings to the HII database. They will be modified later.\r
-  //\r
-  HiiHandle = HiiAddPackages (\r
-                &gEfiMiscSubClassGuid,\r
-                NULL,\r
-                MiscSubclassStrings,\r
-                NULL\r
-                );\r
-  if (HiiHandle == NULL) {\r
-    DEBUG ((EFI_D_ERROR, "Could not log default strings to Hii.  %r\n", Status));\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  //\r
-  //\r
-  //\r
-  for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {\r
-    //\r
-    // Stupidity check!  Do nothing if RecordLen is zero.\r
-    // %%TBD - Should this be an error or a mechanism for ignoring\r
-    // records in the Data Table?\r
-    //\r
-    if (mMiscSubclassDataTable[Index].RecordLen == 0) {\r
-      DEBUG (\r
-        (EFI_D_ERROR,\r
-        "mMiscSubclassDataTable[%d].RecordLen == 0\n",\r
-        Index)\r
-        );\r
 \r
-      continue;\r
-    }\r
+  mHiiHandle = HiiAddPackages (\r
+                 &gEfiCallerIdGuid,\r
+                 NULL,\r
+                 MiscSubclassStrings,\r
+                 NULL\r
+                 );\r
+  ASSERT (mHiiHandle != NULL);\r
+\r
+  for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {\r
     //\r
-    // Initialize per-record portion of subclass header and\r
-    // copy static data into data portion of subclass record.\r
+    // If the entry have a function pointer, just log the data.\r
     //\r
-    RecordData.Header.RecordType = mMiscSubclassDataTable[Index].RecordType;\r
-\r
-    if (mMiscSubclassDataTable[Index].RecordData == NULL) {\r
-      ZeroMem (\r
-        &RecordData.Record,\r
-        mMiscSubclassDataTable[Index].RecordLen\r
-        );\r
-    } else {\r
-      CopyMem (\r
-        &RecordData.Record,\r
+    if (mMiscSubclassDataTable[Index].Function != NULL) {\r
+      EfiStatus = (*mMiscSubclassDataTable[Index].Function)(\r
         mMiscSubclassDataTable[Index].RecordData,\r
-        mMiscSubclassDataTable[Index].RecordLen\r
+        Smbios\r
         );\r
-    }\r
-    //\r
-    // If the entry does not have a function pointer, just log the data.\r
-    //\r
-    if (mMiscSubclassDataTable[Index].Function == NULL) {\r
-      //\r
-      // Log RecordData to Data Hub.\r
-      //\r
-      Status = DataHub->LogData (\r
-                            DataHub,\r
-                            &gEfiMiscSubClassGuid,\r
-                            &gEfiMiscSubClassGuid,\r
-                            EFI_DATA_RECORD_CLASS_DATA,\r
-                            &RecordData,\r
-                            sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen\r
-                            );\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        DEBUG (\r
-          (EFI_D_ERROR,\r
-          "LogData(%d bytes) == %r\n",\r
-          sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r
-          Status)\r
-          );\r
-      }\r
-\r
-      continue;\r
-    }\r
-    //\r
-    // The entry has a valid function pointer.\r
-    // Keep calling the function and logging data until there\r
-    // is no more data to log.\r
-    //\r
-    for (;;) {\r
-      Status = (*mMiscSubclassDataTable[Index].Function)(mMiscSubclassDataTable[Index].RecordType, &mMiscSubclassDataTable[Index].RecordLen, &RecordData.Record, &LogRecordData);\r
-      if (EFI_ERROR (Status)) {\r
-        break;\r
-      }\r
-\r
-      if (!LogRecordData) {\r
-        break;\r
-      }\r
-\r
-      Status = DataHub->LogData (\r
-                            DataHub,\r
-                            &gEfiMiscSubClassGuid,\r
-                            &gEfiMiscSubClassGuid,\r
-                            EFI_DATA_RECORD_CLASS_DATA,\r
-                            &RecordData,\r
-                            sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen\r
-                            );\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        DEBUG (\r
-          (EFI_D_ERROR,\r
-          "LogData(%d bytes) == %r\n",\r
-          sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r
-          Status)\r
-          );\r
-      }\r
-    }\r
-  }\r
-\r
-  \r
-  //\r
-  // Log Memory Size info based on PCD setting.\r
-  //\r
-  MemorySubClassData.Header.Instance    = 1;\r
-  MemorySubClassData.Header.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;\r
-  MemorySubClassData.Header.RecordType  = EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER;\r
 \r
-  //\r
-  // Process Memory String in form size!size ...\r
-  // So 64!64 is 128 MB\r
-  //\r
-  Nt32MemString   = PcdGetPtr (PcdWinNtMemorySize);\r
-  for (TotalMemorySize = 0; *Nt32MemString != '\0';) {\r
-    TotalMemorySize += StrDecimalToUint64 (Nt32MemString);\r
-    while (*Nt32MemString != '\0') {\r
-      if (*Nt32MemString == '!') {\r
-        Nt32MemString++;       \r
-        break;\r
+      if (EFI_ERROR(EfiStatus)) {\r
+        DEBUG((EFI_D_ERROR, "Misc smbios store error.  Index=%d, ReturnStatus=%r\n", Index, EfiStatus));\r
+        return EfiStatus;\r
       }\r
-      Nt32MemString++;\r
     }\r
   }\r
 \r
-  MemorySubClassData.Record.ArrayStartAddress.MemoryArrayStartAddress               = 0;\r
-  MemorySubClassData.Record.ArrayStartAddress.MemoryArrayEndAddress                 = LShiftU64 (TotalMemorySize, 20) - 1;\r
-  MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.ProducerName  = gEfiCallerIdGuid;\r
-  MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.Instance      = 1;\r
-  MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.SubInstance   = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;\r
-  MemorySubClassData.Record.ArrayStartAddress.MemoryArrayPartitionWidth             = 0;\r
-\r
   //\r
-  // Store memory size data record to data hub.\r
+  // Log Memory SMBIOS Record\r
   //\r
-  Status = DataHub->LogData (\r
-                      DataHub,\r
-                      &gEfiMemorySubClassGuid,\r
-                      &gEfiCallerIdGuid,\r
-                      EFI_DATA_RECORD_CLASS_DATA,\r
-                      &MemorySubClassData,\r
-                      sizeof (EFI_SUBCLASS_TYPE1_HEADER) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA)\r
-                      );\r
-\r
-\r
-  return EFI_SUCCESS;\r
+  EfiStatus = LogMemorySmbiosRecord();\r
+  return EfiStatus;\r
 }\r
-\r
-\r