hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/** @file
 
  Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>
                                                                                   
  SPDX-License-Identifier: BSD-2-Clause-Patent
 
                                                                                   
 
Module Name:
 
 
  IchTcoReset.c
 
Abstract:
  Implements the programming of events in TCO Reset
 
 
--*/
 
#include "PlatformDxe.h"
#include <Protocol/TcoReset.h>
#include <Protocol/HwWatchdogTimer.h>
 
 
EFI_STATUS
EFIAPI
EnableTcoReset (
  IN      UINT32            *RcrbGcsSaveValue
  );
  
EFI_STATUS
EFIAPI
DisableTcoReset (
  OUT     UINT32    RcrbGcsRestoreValue
  );
 
EFI_TCO_RESET_PROTOCOL  mTcoResetProtocol = {
  EnableTcoReset,
  DisableTcoReset
};
 
/**
 
  Enables the TCO timer to reset the system in case of a system hang.  This is
  used when writing the clock registers.
 
  @param RcrbGcsSaveValue   This is the value of the RCRB GCS register before it is
                            changed by this procedure.  This will be used to restore
                            the settings of this register in PpiDisableTcoReset.
 
  @retval  EFI_STATUS
 
**/
EFI_STATUS
EFIAPI
EnableTcoReset (
  IN      UINT32            *RcrbGcsSaveValue
  )
{
  UINT16          TmpWord;
  UINT16          AcpiBase;
  EFI_WATCHDOG_TIMER_DRIVER_PROTOCOL  *WatchdogTimerProtocol;
  EFI_STATUS          Status;
  UINTN           PbtnDisableInterval = 4;  //Default value
 
  //
  // Get Watchdog Timer protocol.
  //
  Status = gBS->LocateProtocol (
                  &gEfiWatchdogTimerDriverProtocolGuid,
                  NULL,
                  (VOID **)&WatchdogTimerProtocol
                  );
 
  //
  // If the protocol is present, shut off the Timer as we enter BDS
  //
  if (!EFI_ERROR(Status)) {
    WatchdogTimerProtocol->RestartWatchdogTimer();
    WatchdogTimerProtocol->AllowKnownReset(TRUE);
  }
 
  if (*RcrbGcsSaveValue == 0) {
    PbtnDisableInterval = PcdGet32(PcdPBTNDisableInterval);
  } else {
    PbtnDisableInterval = *RcrbGcsSaveValue * 10 / 6;
  }
 
  //
  // Read ACPI Base Address
  //
  AcpiBase = PchLpcPciCfg16(R_PCH_LPC_ACPI_BASE) & B_PCH_LPC_ACPI_BASE_BAR;
 
  //
  // Stop TCO if not already stopped
  //
  TmpWord = IoRead16(AcpiBase + R_PCH_TCO_CNT);
  TmpWord |= B_PCH_TCO_CNT_TMR_HLT;
  IoWrite16(AcpiBase + R_PCH_TCO_CNT, TmpWord);
 
  //
  // Clear second TCO status
  //
  IoWrite32(AcpiBase + R_PCH_TCO_STS, B_PCH_TCO_STS_SECOND_TO);
 
  //
  // Enable reboot on TCO timeout
  //
  *RcrbGcsSaveValue = MmioRead32 (PMC_BASE_ADDRESS + R_PCH_PMC_PM_CFG);
  MmioAnd8 (PMC_BASE_ADDRESS + R_PCH_PMC_PM_CFG, (UINT8) ~B_PCH_PMC_PM_CFG_NO_REBOOT);
 
  //
  // Set TCO reload value (interval *.6s)
  //
  IoWrite32(AcpiBase + R_PCH_TCO_TMR, (UINT32)(PbtnDisableInterval<<16));
 
  //
  // Force TCO to load new value
  //
  IoWrite8(AcpiBase + R_PCH_TCO_RLD, 4);
 
  //
  // Clear second TCO status
  //
  IoWrite32(AcpiBase + R_PCH_TCO_STS, B_PCH_TCO_STS_SECOND_TO);
 
  //
  // Start TCO timer running
  //
  TmpWord = IoRead16(AcpiBase + R_PCH_TCO_CNT);
  TmpWord &= ~(B_PCH_TCO_CNT_TMR_HLT);
  IoWrite16(AcpiBase + R_PCH_TCO_CNT, TmpWord);
 
  return EFI_SUCCESS;
}
 
/**
  Disables the TCO timer.  This is used after writing the clock registers.
 
  @param RcrbGcsRestoreValue   Value saved in PpiEnableTcoReset so that it can
                               restored.
 
  @retval EFI_STATUS
 
**/
EFI_STATUS
EFIAPI
DisableTcoReset (
  OUT     UINT32    RcrbGcsRestoreValue
  )
{
  UINT16          TmpWord;
  UINT16          AcpiBase;
  EFI_WATCHDOG_TIMER_DRIVER_PROTOCOL  *WatchdogTimerProtocol;
  EFI_STATUS          Status;
 
  //
  // Read ACPI Base Address
  //
  AcpiBase = PchLpcPciCfg16(R_PCH_LPC_ACPI_BASE) & B_PCH_LPC_ACPI_BASE_BAR;
 
  //
  // Stop the TCO timer
  //
  TmpWord = IoRead16(AcpiBase + R_PCH_TCO_CNT);
  TmpWord |= B_PCH_TCO_CNT_TMR_HLT;
  IoWrite16(AcpiBase + R_PCH_TCO_CNT, TmpWord);
 
  //
  // Get Watchdog Timer protocol.
  //
  Status = gBS->LocateProtocol (
                  &gEfiWatchdogTimerDriverProtocolGuid,
                  NULL,
                  (VOID **)&WatchdogTimerProtocol
                  );
 
  //
  // If the protocol is present, shut off the Timer as we enter BDS
  //
  if (!EFI_ERROR(Status)) {
    WatchdogTimerProtocol->AllowKnownReset(FALSE);
  }
 
  return EFI_SUCCESS;
}
 
/**
 
  Updates the feature policies according to the setup variable.
 
  @retval Returns   VOID
 
**/
VOID
InitTcoReset (
  )
{
  EFI_HANDLE                        Handle;
  EFI_STATUS                        Status;
 
  Handle = NULL;
  Status = gBS->InstallProtocolInterface (
                  &Handle,
                  &gEfiTcoResetProtocolGuid,
                  EFI_NATIVE_INTERFACE,
                  &mTcoResetProtocol
                  );
  ASSERT_EFI_ERROR(Status);
 
}