/** @file

  Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>

  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>

#include "SmbiosPlatformDxe.h"

/**
  This function adds SMBIOS Table (Type 8) records.

  @param  RecordData                 Pointer to SMBIOS Table with default values.
  @param  Smbios                     SMBIOS protocol.

  @retval EFI_SUCCESS                The SMBIOS Table was successfully added.
  @retval Other                      Failed to update the SMBIOS Table.

**/
SMBIOS_PLATFORM_DXE_TABLE_FUNCTION (PlatformPortConnector) {
  EFI_STATUS         Status;
  STR_TOKEN_INFO     *InputStrToken;
  SMBIOS_TABLE_TYPE8 *InputData;
  SMBIOS_TABLE_TYPE8 *Type8Record;

  InputData = (SMBIOS_TABLE_TYPE8 *)RecordData;
  InputStrToken = (STR_TOKEN_INFO *)StrToken;

  while (InputData->Hdr.Type != NULL_TERMINATED_TYPE) {
    SmbiosPlatformDxeCreateTable (
      (VOID *)&Type8Record,
      (VOID *)&InputData,
      sizeof (SMBIOS_TABLE_TYPE8),
      InputStrToken
      );
    if (Type8Record == NULL) {
      return EFI_OUT_OF_RESOURCES;
    }

    Status = SmbiosPlatformDxeAddRecord ((UINT8 *)Type8Record, NULL);
    if (EFI_ERROR (Status)) {
      FreePool (Type8Record);
      return Status;
    }

    FreePool (Type8Record);
    InputData++;
    InputStrToken++;
  }

  return Status;
}
