public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Pranav Madhu" <pranav.madhu@arm.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>,
	Leif Lindholm <leif@nuviainc.com>
Subject: [edk2-platforms][PATCH V1 09/11] Platform/ARM/SgiPkg: Add SMBIOS Type17 Table
Date: Fri, 15 Jan 2021 23:56:46 +0530	[thread overview]
Message-ID: <20210115182648.20938-10-pranav.madhu@arm.com> (raw)
In-Reply-To: <20210115182648.20938-1-pranav.madhu@arm.com>

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.madhu@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  | 273 ++++++++++++++++++++
 4 files changed, 289 insertions(+)

diff --git a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
index 83bcb40531fe..7f16aef64c8e 100644
--- a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
@@ -31,6 +31,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 e7ecb5d56704..c56429541504 100644
--- a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h
@@ -45,6 +45,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,
@@ -54,6 +60,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 accc9fe2e560..464fb62d06fa 100644
--- a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -27,6 +27,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..283ff6eaa236
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/Type17MemoryDevice.c
@@ -0,0 +1,273 @@
+/** @file
+  SMBIOS Type 17 (Memory Device) table for ARM RD platforms.
+
+  Copyright (c) 2020-2021, ARM Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#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 (SMBIOS 3.4 spec, section 7.18) */
+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 Bios information Table
+
+  @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;
+
+  for (Idx = 0; Idx < (FixedPcdGet32 (PcdChipCount) * 2); Idx += 2) {
+    mArmRdSmbiosType17[Idx].Base.Size =
+      (PcdGet64 (PcdSystemMemorySize) + SIZE_16MB) / SIZE_1MB;
+    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 (EFI_ERROR (Status)) {
+        break;
+      }
+    }
+  }
+
+  return Status;
+}
-- 
2.17.1


  parent reply	other threads:[~2021-01-15 18:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 18:26 [edk2-platforms][PATCH V1 00/11] Add SMBIOS tables for SGI/RD platforms Pranav Madhu
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 01/11] Platform/ARM/SgiPkg: Define RD-N2 platform id values Pranav Madhu
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 02/11] Platform/ARM/SgiPkg: Add GetProductId API for SGI/RD Platforms Pranav Madhu
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 03/11] Platform/ARM/SgiPkg: Add Initial SMBIOS support Pranav Madhu
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 04/11] Platform/ARM/SgiPkg: Add SMBIOS Type1 Table Pranav Madhu
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 05/11] Platform/ARM/SgiPkg: Add SMBIOS Type3 Table Pranav Madhu
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 06/11] Platform/ARM/SgiPkg: Add SMBIOS Type4 Table Pranav Madhu
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 07/11] Platform/ARM/SgiPkg: Add SMBIOS Type7 Table Pranav Madhu
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 08/11] Platform/ARM/SgiPkg: Add SMBIOS Type16 Table Pranav Madhu
2021-01-15 18:26 ` Pranav Madhu [this message]
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 10/11] Platform/ARM/SgiPkg: Add SMBIOS Type19 Table Pranav Madhu
2021-01-15 18:26 ` [edk2-platforms][PATCH V1 11/11] Platform/ARM/SgiPkg: Add SMBIOS Type32 Table Pranav Madhu
2021-01-26 14:33 ` [edk2-devel] [edk2-platforms][PATCH V1 00/11] Add SMBIOS tables for SGI/RD platforms Thomas Abraham
2021-01-29  6:29   ` Pranav Madhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210115182648.20938-10-pranav.madhu@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox