Hi Pranav,

Please find my comments inline marked [SAMI].

Some comments in previous patches apply here as well and are not mentioned.

With those addressed.

Reviewed-by: Sami Mujawar <sami.muja...@arm.com>

Regards,

Sami Mujawar

On 16/05/2021 10:29 AM, Pranav Madhu wrote:
Add the SMBIOS type 17 table (Memory Device) that includes the
specification of each installed memory device such as size of each
device, bank locator, memory device type, and other related information.

Signed-off-by: Pranav Madhu <pranav.ma...@arm.com>
---
  Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf |   1 +
  Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h   |  14 +
  Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c   |   1 +
  Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/Type17MemoryDevice.c  | 288 
++++++++++++++++++++
  4 files changed, 304 insertions(+)

diff --git 
a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf 
b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
index ebd19c1882bb..9061c491d461 100644
--- a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
@@ -21,6 +21,7 @@
    Type4ProcessorInformation.c
    Type7CacheInformation.c
    Type16PhysicalMemoryArray.c
+  Type17MemoryDevice.c
[Packages]
    ArmPkg/ArmPkg.dec
diff --git a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h 
b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h
index e195fdea35af..5413982e233b 100644
--- a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h
@@ -47,6 +47,12 @@ InstallPhysicalMemoryArray (
    IN     EFI_SMBIOS_PROTOCOL    *Smbios
    );
+EFI_STATUS
+EFIAPI
+InstallMemoryDevice (
+  IN     EFI_SMBIOS_PROTOCOL    *Smbios
+  );
+
  enum SMBIOS_REFRENCE_HANDLES {
    SMBIOS_HANDLE_ENCLOSURE = 0x1000,
    SMBIOS_HANDLE_CLUSTER1,
@@ -56,6 +62,14 @@ enum SMBIOS_REFRENCE_HANDLES {
    SMBIOS_HANDLE_L3_CACHE,
    SMBIOS_HANDLE_L4_CACHE,
    SMBIOS_HANDLE_PHYSICAL_MEMORY,
+  SMBIOS_HANDLE_MEMORY_DEVICE0000,  // Chip 0 Bank 0
+  SMBIOS_HANDLE_MEMORY_DEVICE0001,  // Chip 0 Bank 1
+  SMBIOS_HANDLE_MEMORY_DEVICE0100,  // Chip 1 Bank 0
+  SMBIOS_HANDLE_MEMORY_DEVICE0101,  // Chip 1 Bank 1
+  SMBIOS_HANDLE_MEMORY_DEVICE0200,  // Chip 2 Bank 0
+  SMBIOS_HANDLE_MEMORY_DEVICE0201,  // Chip 2 Bank 1
+  SMBIOS_HANDLE_MEMORY_DEVICE0300,  // Chip 3 Bank 0
+  SMBIOS_HANDLE_MEMORY_DEVICE0301,  // Chip 3 Bank 1
  };
#endif // SMBIOS_PLATFORM_DXE_H_
diff --git a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c 
b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
index 48073ad0ad27..223bf1d114e4 100644
--- a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -32,6 +32,7 @@ ARM_RD_SMBIOS_TABLE_INSTALL_FPTR mSmbiosTableList[] = {
    &InstallProcessorInformation,
    &InstallCacheInformation,
    &InstallPhysicalMemoryArray,
+  &InstallMemoryDevice,
  };
/**
diff --git a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/Type17MemoryDevice.c 
b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/Type17MemoryDevice.c
new file mode 100644
index 000000000000..fc7422f432a6
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/Type17MemoryDevice.c
@@ -0,0 +1,288 @@
+/** @file
+  SMBIOS Type 17 (Memory Device) table for ARM RD platforms.
+
+  This file installs SMBIOS Type 17 (Memory Device) table for Arm's Reference
+  Design platforms. It includes the specification of each installed memory
+  device such as size of each device, bank locator, memory device type, and
+  other related information.
+
+  Copyright (c) 2021, ARM Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Specification Reference:
+    - SMBIOS Reference Specification 3.4.0, Chapter 7.18
+**/
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Protocol/Smbios.h>
+
+#include "SmbiosPlatformDxe.h"
+
+#define MAX_CHIP_COUNT  4
+#define BANK0_BASE      1
+#define BANK1_BASE      (BANK0_BASE + MAX_CHIP_COUNT)
+#define TYPE17_STRINGS                                  \
+  "Chip 0 Bank 0\0"                                     \
+  "Chip 1 Bank 0\0"                                     \
+  "Chip 2 Bank 0\0"                                     \
+  "Chip 3 Bank 0\0"                                     \
+  "Chip 0 Bank 1\0"                                     \
+  "Chip 1 Bank 1\0"                                     \
+  "Chip 2 Bank 1\0"                                     \
+  "Chip 3 Bank 1\0"
+
+/* SMBIOS Type17 structure */
+#pragma pack(1)
+struct ArmRdSmbiosType17 {
+  SMBIOS_TABLE_TYPE17 Base;
+  UINT8               Strings[sizeof (TYPE17_STRINGS)];
+};
+#pragma pack()
+
+/* Memory Device */
+static struct ArmRdSmbiosType17 mArmRdSmbiosType17[] = {
+  {
+    {
+      {
+        // SMBIOS header
+        EFI_SMBIOS_TYPE_MEMORY_DEVICE,  // Type 17
+        sizeof (SMBIOS_TABLE_TYPE17),   // Length
+        SMBIOS_HANDLE_MEMORY_DEVICE0000
+      },
+      SMBIOS_HANDLE_PHYSICAL_MEMORY,    // Physical memory array handle
+      0xFFFE,                           // Memory error info handle
+      0xFFFF,                           // Total width unknown
+      0xFFFF,                           // Data width unknown
+      0,                                // Size, Update dynamically
+      MemoryFormFactorOther,            // Form Factor
+      0,                                // Device set, not part of a set
+      0,                                // Device locator
+      BANK0_BASE,                       // Chip 0 Bank 0
+      MemoryTypeDram,                   // Memory type
+      {0, 1},                           // Type details others
+    },
+    // Text strings (unformatted area)
+    TYPE17_STRINGS
+  },
+  {
+    {
+      {
+        // SMBIOS header
+        EFI_SMBIOS_TYPE_MEMORY_DEVICE,  // Type 17
+        sizeof (SMBIOS_TABLE_TYPE17),   // Length
+        SMBIOS_HANDLE_MEMORY_DEVICE0001
+      },
+      SMBIOS_HANDLE_PHYSICAL_MEMORY,    // Physical memory array handle
+      0xFFFE,                           // Memory error info handle
+      0xFFFF,                           // Total width unknown
+      0xFFFF,                           // Data width unknown
+      0,                                // Size, Update dynamically
+      MemoryFormFactorOther,            // Form Factor
+      0,                                // Device set, not part of a set
+      0,                                // Device locator
+      BANK1_BASE,                       // Chip 0 Bank 1
+      MemoryTypeDram,                   // Memory type
+      {0, 1},                           // Type details others
+    },
+    // Text strings (unformatted area)
+    TYPE17_STRINGS
+  },
+  {
+    {
+      {
+        // SMBIOS header
+        EFI_SMBIOS_TYPE_MEMORY_DEVICE,  // Type 17
+        sizeof (SMBIOS_TABLE_TYPE17),   // Length
+        SMBIOS_HANDLE_MEMORY_DEVICE0100
+      },
+      SMBIOS_HANDLE_PHYSICAL_MEMORY,    // Physical memory array handle
+      0xFFFE,                           // Memory error info handle
+      0xFFFF,                           // Total width unknown
+      0xFFFF,                           // Data width unknown
+      0,                                // Size, Update dynamically
+      MemoryFormFactorOther,            // Form Factor
+      0,                                // Device set, not part of a set
+      0,                                // Device locator
+      BANK0_BASE + 1,                   // Chip 1 Bank 0
+      MemoryTypeDram,                   // Memory type
+      {0, 1},                           // Type details others
+    },
+    // Text strings (unformatted area)
+    TYPE17_STRINGS
+  },
+  {
+    {
+      {
+        // SMBIOS header
+        EFI_SMBIOS_TYPE_MEMORY_DEVICE,  // Type 17
+        sizeof (SMBIOS_TABLE_TYPE17),   // Length
+        SMBIOS_HANDLE_MEMORY_DEVICE0101
+      },
+      SMBIOS_HANDLE_PHYSICAL_MEMORY,    // Physical memory array handle
+      0xFFFE,                           // Memory error info handle
+      0xFFFF,                           // Total width unknown
+      0xFFFF,                           // Data width unknown
+      0,                                // Size, Update dynamically
+      MemoryFormFactorOther,            // Form Factor
+      0,                                // Device set, not part of a set
+      0,                                // Device locator
+      BANK1_BASE + 1,                   // Chip 1 Bank 1
+      MemoryTypeDram,                   // Memory type
+      {0, 1},                           // Type details others
+    },
+    // Text strings (unformatted area)
+    TYPE17_STRINGS
+  },
+  {
+    {
+      {
+        // SMBIOS header
+        EFI_SMBIOS_TYPE_MEMORY_DEVICE,  // Type 17
+        sizeof (SMBIOS_TABLE_TYPE17),   // Length
+        SMBIOS_HANDLE_MEMORY_DEVICE0200
+      },
+      SMBIOS_HANDLE_PHYSICAL_MEMORY,    // Physical memory array handle
+      0xFFFE,                           // Memory error info handle
+      0xFFFF,                           // Total width unknown
+      0xFFFF,                           // Data width unknown
+      0,                                // Size, Update dynamically
+      MemoryFormFactorOther,            // Form Factor
+      0,                                // Device set, not part of a set
+      0,                                // Device locator
+      BANK0_BASE + 2,                   // Chip 2 Bank 0
+      MemoryTypeDram,                   // Memory type
+      {0, 1},                           // Type details others
+    },
+    // Text strings (unformatted area)
+    TYPE17_STRINGS
+  },
+  {
+    {
+      {
+        // SMBIOS header
+        EFI_SMBIOS_TYPE_MEMORY_DEVICE,  // Type 17
+        sizeof (SMBIOS_TABLE_TYPE17),   // Length
+        SMBIOS_HANDLE_MEMORY_DEVICE0201
+      },
+      SMBIOS_HANDLE_PHYSICAL_MEMORY,    // Physical memory array handle
+      0xFFFE,                           // Memory error info handle
+      0xFFFF,                           // Total width unknown
+      0xFFFF,                           // Data width unknown
+      0,                                // Size, Update dynamically
+      MemoryFormFactorOther,            // Form Factor
+      0,                                // Device set, not part of a set
+      0,                                // Device locator
+      BANK1_BASE + 2,                   // Chip 2 Bank 1
+      MemoryTypeDram,                   // Memory type
+      {0, 1},                           // Type details others
+    },
+    // Text strings (unformatted area)
+    TYPE17_STRINGS
+  },
+  {
+    {
+      {
+        // SMBIOS header
+        EFI_SMBIOS_TYPE_MEMORY_DEVICE,  // Type 17
+        sizeof (SMBIOS_TABLE_TYPE17),   // Length
+        SMBIOS_HANDLE_MEMORY_DEVICE0300
+      },
+      SMBIOS_HANDLE_PHYSICAL_MEMORY,    // Physical memory array handle
+      0xFFFE,                           // Memory error info handle
+      0xFFFF,                           // Total width unknown
+      0xFFFF,                           // Data width unknown
+      0,                                // Size, Update dynamically
+      MemoryFormFactorOther,            // Form Factor
+      0,                                // Device set, not part of a set
+      0,                                // Device locator
+      BANK0_BASE + 3,                   // Chip 3 Bank 0
+      MemoryTypeDram,                   // Memory type
+      {0, 1},                           // Type details others
+    },
+    // Text strings (unformatted area)
+    TYPE17_STRINGS
+  },
+  {
+    {
+      {
+        // SMBIOS header
+        EFI_SMBIOS_TYPE_MEMORY_DEVICE,  // Type 17
+        sizeof (SMBIOS_TABLE_TYPE17),   // Length
+        SMBIOS_HANDLE_MEMORY_DEVICE0301
+      },
+      SMBIOS_HANDLE_PHYSICAL_MEMORY,    // Physical memory array handle
+      0xFFFE,                           // Memory error info handle
+      0xFFFF,                           // Total width unknown
+      0xFFFF,                           // Data width unknown
+      0,                                // Size, Update dynamically
+      MemoryFormFactorOther,            // Form Factor
+      0,                                // Device set, not part of a set
+      0,                                // Device locator
+      BANK1_BASE + 3,                   // Chip 3 Bank 1
+      MemoryTypeDram,                   // Memory type
+      {0, 1},                           // Type details others
+    },
+    // Text strings (unformatted area)
+    TYPE17_STRINGS
+  },
+};
+
+/**
+  Install SMBIOS memory device Table.
+
+  Install the SMBIOS memory device (type 17) table for RD platforms.
+
+  @param[in] Smbios   SMBIOS protocol.
+
+  @retval EFI_SUCCESS           Record was added.
+  @retval EFI_OUT_OF_RESOURCES  Record was not added.
+  @retval EFI_ALREADY_STARTED   The SmbiosHandle passed in is already in use.
+**/
+EFI_STATUS
+InstallMemoryDevice (
+  IN     EFI_SMBIOS_PROTOCOL    *Smbios
+  )
+{
+  EFI_STATUS Status;
+  EFI_SMBIOS_HANDLE SmbiosHandle;
+  UINT8  Idx;
+
+  /* Get system memory information */
+  for (Idx = 0; Idx < (FixedPcdGet32 (PcdChipCount) * 2); Idx += 2) {
+    mArmRdSmbiosType17[Idx].Base.Size =
+      (PcdGet64 (PcdSystemMemorySize) + SIZE_16MB) / SIZE_1MB;
[SAMI] Can you check if this field is encoded correctly, please?
The specification states the following:
'Size of the memory device
If the value is 0, no memory device is installed in the
socket; if the size is unknown, the field value is
FFFFh. If the size is 32 GB-1 MB or greater, the
field value is 7FFFh and the actual size is stored in
the Extended Size field.
The granularity in which the value is specified
depends on the setting of the most-significant bit (bit
15). If the bit is 0, the value is specified in megabyte
units; if the bit is 1, the value is specified in kilobyte
units. For example, the value 8100h identifies a
256 KB memory device and 0100h identifies a
256 MB memory device.'

For SgiPlatforms maybe you will never hit this situation. However, the code in its current state will silently produce incorrect result, which I think would be misleading should somone use this as reference.
[/SAMI]
+    mArmRdSmbiosType17[Idx].Base.MemoryTechnology = MemoryTechnologyDram;
+    
mArmRdSmbiosType17[Idx].Base.MemoryOperatingModeCapability.Bits.VolatileMemory 
= 1;
+
+    if (PcdGet64 (PcdDramBlock2Size) != 0) {
+      mArmRdSmbiosType17[Idx + 1].Base.Size =
+        PcdGet64 (PcdDramBlock2Size) / SIZE_1MB;
+      mArmRdSmbiosType17[Idx + 1].Base.MemoryTechnology = MemoryTechnologyDram;
+      mArmRdSmbiosType17[Idx + 
1].Base.MemoryOperatingModeCapability.Bits.VolatileMemory = 1;
+    }
+  }
+
+  /* Install valid entries */
+  for (Idx = 0; Idx < ARRAY_SIZE (mArmRdSmbiosType17); Idx++) {
+    if (mArmRdSmbiosType17[Idx].Base.Size != 0) {
+      SmbiosHandle =
+        ((EFI_SMBIOS_TABLE_HEADER *)&mArmRdSmbiosType17[Idx])->Handle;
+      Status = Smbios->Add (
+                         Smbios,
+                         NULL,
+                         &SmbiosHandle,
+                         (EFI_SMBIOS_TABLE_HEADER *)&mArmRdSmbiosType17[Idx]
+                         );
+      if (Status != EFI_SUCCESS) {
+        DEBUG ((
+          DEBUG_ERROR,
+          "SMBIOS: Failed to install Type17 SMBIOS table.\n"
+          ));
+        break;
+      }
+    }
+  }
+
+  return Status;
+}



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#75219): https://edk2.groups.io/g/devel/message/75219
Mute This Topic: https://groups.io/mt/82861606/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to