]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
Update the copyright notice format
[mirror_edk2.git] / UnixPkg / MiscSubClassPlatformDxe / MiscSubclassDriverEntryPoint.c
index 8732677c95259e1bcbbe1a20b997a0b44e275fde..a2c14e7a7aa72bc3f215bf9817756ab242a52a45 100644 (file)
@@ -1,7 +1,7 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
 http://opensource.org/licenses/bsd-license.php\r
@@ -22,99 +22,80 @@ 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
-//\r
-//\r
-//\r
-EFI_STATUS\r
-LogRecordDataToDataHub (\r
-  EFI_DATA_HUB_PROTOCOL *DataHub,\r
-  UINT32                RecordType,\r
-  UINT32                RecordLen,\r
-  VOID                  *RecordData\r
-  )\r
-/*++\r
-Description:\r
-\r
-Parameters:\r
-\r
-  DataHub\r
-    %%TBD\r
+  @param  ImageHandle  Handle for the image of this driver\r
+  @param  SystemTable  Pointer to the EFI System Table\r
 \r
-  RecordType\r
-    %%TBD\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
-  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_STATUS\r
+LogMemorySmbiosRecord (\r
+  VOID\r
+  )\r
 {\r
-  EFI_MISC_SUBCLASS_DRIVER_DATA MiscSubclass;\r
-  EFI_STATUS                    EfiStatus;\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                          *UnixMemString;\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
+  UnixMemString   = PcdGetPtr (PcdUnixMemorySize);\r
+  for (TotalMemorySize = 0; *UnixMemString != '\0';) {\r
+    TotalMemorySize += StrDecimalToUint64 (UnixMemString);\r
+    while (*UnixMemString != '\0') {\r
+      if (*UnixMemString == '!') {\r
+        UnixMemString++;       \r
+        break;\r
+      }\r
+      UnixMemString++;\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
-  EfiStatus = 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 (EfiStatus)) {\r
-    DEBUG (\r
-      (EFI_D_ERROR,\r
-      "LogData(%d bytes) == %r\n",\r
-      sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen,\r
-      EfiStatus)\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 EfiStatus;\r
+  return Status;\r
 }\r
 \r
 \r
@@ -145,195 +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                        EfiStatus;\r
-  UINTN                             Index;\r
-  BOOLEAN                           LogRecordData;\r
-  EFI_MEMORY_SUBCLASS_DRIVER_DATA   MemorySubClassData; \r
-  UINT64                            TotalMemorySize;\r
-  CHAR16                            *UnixMemString;\r
-\r
-\r
+  UINTN                Index;\r
+  EFI_STATUS           EfiStatus;\r
+  EFI_SMBIOS_PROTOCOL  *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
+  EfiStatus = gBS->LocateProtocol(&gEfiSmbiosProtocolGuid, NULL, (VOID**)&Smbios);\r
 \r
-  //\r
-  // Locate data hub protocol.\r
-  //\r
-  EfiStatus = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**) &DataHub);\r
-\r
-  if (EFI_ERROR (EfiStatus)) {\r
-    DEBUG ((EFI_D_ERROR, "Could not locate DataHub protocol.  %r\n", EfiStatus));\r
+  if (EFI_ERROR(EfiStatus)) {\r
+    DEBUG((EFI_D_ERROR, "Could not locate SMBIOS protocol.  %r\n", EfiStatus));\r
     return EfiStatus;\r
-  } else if (DataHub == NULL) {\r
-    DEBUG ((EFI_D_ERROR, "LocateProtocol(DataHub) returned NULL pointer!\n"));\r
-    return EFI_DEVICE_ERROR;\r
   }\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", EfiStatus));\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
+  mHiiHandle = HiiAddPackages (\r
+                 &gEfiCallerIdGuid,\r
+                 NULL,\r
+                 MiscSubclassStrings,\r
+                 NULL\r
+                 );\r
+  ASSERT (mHiiHandle != NULL);\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
+    // If the entry have a function pointer, just log the data.\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
-    //\r
-    // Initialize per-record portion of subclass header and\r
-    // copy static data into data portion of subclass record.\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
-      EfiStatus = 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 (EfiStatus)) {\r
-        DEBUG (\r
-          (EFI_D_ERROR,\r
-          "LogData(%d bytes) == %r\n",\r
-          sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r
-          EfiStatus)\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
-      EfiStatus = (*mMiscSubclassDataTable[Index].Function)(mMiscSubclassDataTable[Index].RecordType, &mMiscSubclassDataTable[Index].RecordLen, &RecordData.Record, &LogRecordData);\r
-\r
-      if (EFI_ERROR (EfiStatus)) {\r
-        break;\r
-      }\r
-\r
-      if (!LogRecordData) {\r
-        break;\r
-      }\r
-      //\r
-      //\r
-      //\r
-      EfiStatus = 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 (EfiStatus)) {\r
-        DEBUG (\r
-          (EFI_D_ERROR,\r
-          "LogData(%d bytes) == %r\n",\r
-          sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r
-          EfiStatus)\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
-  UnixMemString   = PcdGetPtr (PcdUnixMemorySize);\r
-  for (TotalMemorySize = 0; *UnixMemString != '\0';) {\r
-    TotalMemorySize += StrDecimalToUint64 (UnixMemString);\r
-    while (*UnixMemString != '\0') {\r
-      if (*UnixMemString == '!') {\r
-        UnixMemString++;       \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
-      UnixMemString++;\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
-  EfiStatus = 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
-  return EFI_SUCCESS;\r
+  EfiStatus = LogMemorySmbiosRecord();\r
+  return EfiStatus;\r
 }\r