summaryrefslogtreecommitdiff
path: root/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckAcpiTpm.c
blob: 31aef8f4bf795707a794068ba7228d8aed9e194f (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/** @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/BaseMemoryLib.h>
#include <IndustryStandard/Acpi.h>
#include <IndustryStandard/TcpaAcpi.h>
#include <IndustryStandard/Tpm2Acpi.h>

VOID
DumpCharArray (
  IN CHAR8  *Ch,
  IN UINTN  Size
  );

VOID
DumpAcpiTableHeader (
  IN EFI_ACPI_DESCRIPTION_HEADER  *Table
  );

BOOLEAN
IsMmioExit (
  IN EFI_PHYSICAL_ADDRESS  BaseAddress,
  IN UINT64                Length,
  IN BOOLEAN               CheckAllocated
  );

VOID
DumpAcpiTpm2 (
  IN EFI_TPM2_ACPI_TABLE  *Tpm2
  )
{
  DumpAcpiTableHeader (&Tpm2->Header);
  DEBUG ((DEBUG_INFO, "         "));
  DEBUG ((DEBUG_INFO, " Flags=0x%08x ControlArea=0x%016lx StartMethod=0x%08x\n", Tpm2->Flags, Tpm2->AddressOfControlArea, Tpm2->StartMethod));
}

VOID
DumpAcpiTcpaClient (
  IN EFI_TCG_CLIENT_ACPI_TABLE  *TcpaClient
  )
{
  DumpAcpiTableHeader (&TcpaClient->Header);
  DEBUG ((DEBUG_INFO, "         "));
  DEBUG ((DEBUG_INFO, " PlatformClass=0x%04x Laml=0x%08x Lasa=0x%016lx\n",
    TcpaClient->PlatformClass, TcpaClient->Laml, TcpaClient->Lasa));
}

VOID
DumpAcpiTcpaServer (
  IN EFI_TCG_SERVER_ACPI_TABLE  *TcpaServer
  )
{
  DumpAcpiTableHeader (&TcpaServer->Header);
  DEBUG ((DEBUG_INFO, "         "));
  DEBUG ((DEBUG_INFO, " PlatformClass=0x%04x Laml=0x%016lx Lasa=0x%016lx\n",
    TcpaServer->PlatformClass, TcpaServer->Laml, TcpaServer->Lasa));
}

VOID
DumpAcpiTcpa (
  IN EFI_ACPI_DESCRIPTION_HEADER  *Tcpa
  )
{
  EFI_TCG_CLIENT_ACPI_TABLE  *TcpaClient;
  TcpaClient = (VOID *)Tcpa;
  switch (TcpaClient->PlatformClass) {
  case TCG_PLATFORM_TYPE_CLIENT:
    DumpAcpiTcpaClient((VOID *)Tcpa);
    break;
  case TCG_PLATFORM_TYPE_SERVER:
    DumpAcpiTcpaServer((VOID *)Tcpa);
    break;
  default:
    DumpAcpiTableHeader (Tcpa);
    DEBUG ((DEBUG_INFO, "         "));
    DEBUG ((DEBUG_INFO, " PlatformClass=0x%04x\n", TcpaClient->PlatformClass));
    break;
  }
}

EFI_STATUS
CheckAcpiTpm2 (
  IN EFI_TPM2_ACPI_TABLE  *Tpm2
  )
{
  switch (Tpm2->StartMethod) {
  case EFI_TPM2_ACPI_TABLE_START_METHOD_TIS:
    if (!IsMmioExit (0xFED40000, SIZE_4KB, TRUE)) {
      DEBUG ((DEBUG_ERROR, "TPM2 resource (0x%x) is not reported correctly.\n", 0xFED40000));
      return EFI_NOT_STARTED;
    }
    break;
  default:
    break;
  }
  return EFI_SUCCESS;
}

EFI_STATUS
CheckAcpiTcpaClient (
  IN EFI_TCG_CLIENT_ACPI_TABLE  *TcpaClient
  )
{
  if (!IsMmioExit (0xFED40000, SIZE_4KB, TRUE)) {
    DEBUG ((DEBUG_ERROR, "TCPA.client resource (0x%x) is not reported correctly.\n", 0xFED40000));
    return EFI_NOT_STARTED;
  }
  return EFI_SUCCESS;
}

EFI_STATUS
CheckAcpiTcpaServer (
  IN EFI_TCG_SERVER_ACPI_TABLE  *TcpaServer
  )
{
  if (!IsMmioExit (TcpaServer->BaseAddress.Address, SIZE_4KB, TRUE)) {
    DEBUG ((DEBUG_ERROR, "TCPA.server resource (0x%x) is not reported correctly.\n", 0xFED40000));
    return EFI_NOT_STARTED;
  }
  return EFI_SUCCESS;
}

EFI_STATUS
CheckAcpiTcpa (
  IN EFI_ACPI_DESCRIPTION_HEADER  *Tcpa
  )
{
  EFI_TCG_CLIENT_ACPI_TABLE  *TcpaClient;
  TcpaClient = (VOID *)Tcpa;
  switch (TcpaClient->PlatformClass) {
  case TCG_PLATFORM_TYPE_CLIENT:
    return CheckAcpiTcpaClient((VOID *)Tcpa);
    break;
  case TCG_PLATFORM_TYPE_SERVER:
    return CheckAcpiTcpaServer((VOID *)Tcpa);
    break;
  default:
    break;
  }
  return EFI_UNSUPPORTED;
}