summaryrefslogtreecommitdiff
path: root/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckEsrt.c
blob: 371b162ab81885201f44f12ec6e3ce78d22acc4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/** @file

Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include <Uefi.h>
#include <PiDxe.h>
#include <Library/TestPointCheckLib.h>
#include <Library/TestPointLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h>
#include <Library/PrintLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Guid/SystemResourceTable.h>

CHAR8 *mFwTypeString[] = {
  "  Unknown ",
  "  System  ",
  "  Device  ",
  "  Driver  ",
};

CHAR8 *mLastAttemptStatusString[] = {
  "Success",
  "Error: Unsuccessful",
  "Error: Insufficient Resources",
  "Error: Incorrect Version",
  "Error: Invalid Format",
  "Error: Auth Error",
  "Error: Power Event AC",
  "Error: Power Event Battery",
};

CHAR8 mUnknownStr[11];

CHAR8 *
FwTypeToString(
  IN UINT32 FwType
  )
{
  if (FwType < sizeof(mFwTypeString) / sizeof(mFwTypeString[0])) {
    return mFwTypeString[FwType];
  } else {
    AsciiSPrint(mUnknownStr, sizeof(mUnknownStr), "[%08x]", FwType);
    return mUnknownStr;
  }
}

CHAR8 *
LastAttemptStatusToString(
  IN UINT32 LastAttemptStatus
  )
{
  if (LastAttemptStatus < sizeof(mLastAttemptStatusString) / sizeof(mLastAttemptStatusString[0])) {
    return mLastAttemptStatusString[LastAttemptStatus];
  } else {
    return "Error: Unknown";
  }
}

VOID
DumpEsrt (
  IN EFI_SYSTEM_RESOURCE_TABLE  *Esrt
  )
{
  UINTN                      Index;
  EFI_SYSTEM_RESOURCE_ENTRY  *EsrtEntry;

  DEBUG ((DEBUG_INFO, "ESRT Table:"));
  DEBUG ((DEBUG_INFO, " Count=0x%x", Esrt->FwResourceCount));
  DEBUG ((DEBUG_INFO, " CountMax=0x%x", Esrt->FwResourceCountMax));
  DEBUG ((DEBUG_INFO, " Version=0x%lx\n", Esrt->FwResourceVersion));

  DEBUG ((DEBUG_INFO, "               FwClass                   FwType    Version   LowestVer    Flags    AttemptVer Attempt\n"));
//DEBUG ((DEBUG_INFO, "  00000000-0000-0000-0000-000000000000 [00000000] 0x00000000 0x00000000 0x00000000 0x00000000 Success\n"));
  EsrtEntry = (VOID *)(Esrt + 1);
  for (Index = 0; Index < Esrt->FwResourceCount; Index++) {
    DEBUG ((DEBUG_INFO, "  %g ", &EsrtEntry->FwClass));
    DEBUG ((DEBUG_INFO, FwTypeToString(EsrtEntry->FwType)));
    DEBUG ((DEBUG_INFO, " 0x%08x", EsrtEntry->FwVersion));
    DEBUG ((DEBUG_INFO, " 0x%08x", EsrtEntry->LowestSupportedFwVersion));
    DEBUG ((DEBUG_INFO, " 0x%08x", EsrtEntry->CapsuleFlags));
    DEBUG ((DEBUG_INFO, " 0x%08x ", EsrtEntry->LastAttemptVersion));
    DEBUG ((DEBUG_INFO, LastAttemptStatusToString(EsrtEntry->LastAttemptStatus)));
    DEBUG ((DEBUG_INFO, "\n"));
    EsrtEntry++;
  }
}

EFI_STATUS
TestPointCheckEsrt (
  VOID
  )
{
  EFI_STATUS                 Status;
  EFI_SYSTEM_RESOURCE_TABLE  *Esrt;
  
  DEBUG ((DEBUG_INFO, "==== TestPointCheckEsrt - Enter\n"));
  Status = EfiGetSystemConfigurationTable (&gEfiSystemResourceTableGuid, (VOID **)&Esrt);
  if (!EFI_ERROR(Status)) {
    DumpEsrt(Esrt);
  } else {
    TestPointLibAppendErrorString (
      PLATFORM_TEST_POINT_ROLE_PLATFORM_IBV,
      NULL,
      TEST_POINT_BYTE8_READY_TO_BOOT_ESRT_TABLE_FUNCTIONAL_ERROR_CODE \
        TEST_POINT_READY_TO_BOOT \
        TEST_POINT_BYTE8_READY_TO_BOOT_ESRT_TABLE_FUNCTIONAL_ERROR_STRING
      );
  }
  DEBUG ((DEBUG_INFO, "==== TestPointCheckEsrt - Exit\n"));

  return Status;
}