summaryrefslogtreecommitdiff
path: root/ReferenceCode/ME/Library/MeKernel/Pei/HeciMsgLibPei.c
blob: 905020b2db56c09a97c506161ab1d5352beda099 (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
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
/** @file
  Implementation file for Heci Message functionality

@copyright
  Copyright (c) 2010 - 2012 Intel Corporation. All rights
  reserved This software and associated documentation (if any)
  is furnished under a license and may only be used or copied in
  accordance with the terms of the license. Except as permitted
  by such license, no part of this software or documentation may
  be reproduced, stored in a retrieval system, or transmitted in
  any form or by any means without the express written consent
  of Intel Corporation.

  This file contains an 'Intel Peripheral Driver' and uniquely
  identified as "Intel Reference Module" and is
  licensed for Intel CPUs and chipsets under the terms of your
  license agreement with Intel or your vendor.  This file may
  be modified by the user, subject to additional terms of the
  license agreement
**/

//
// External include files do NOT need to be explicitly specified in real EDKII
// environment
//
#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000)
#include "EdkIIGluePeim.h"
#include "CoreBiosMsg.h"
#include "HeciMsgLibPei.h"
#include EFI_PPI_CONSUMER (Wdt)

#endif

/**
  Start Watch Dog Timer HECI message

  @param[in] PeiServices          General purpose services available to every PEIM.
  @param[in] HeciPpi              The pointer to HECI PPI
  @param[in] HeciMemBar           HECI Memory BAR
  @param[in] WaitTimerBios        The value of waiting limit

  @exception EFI_UNSUPPORTED      Current ME mode doesn't support this function
  @retval EFI_SUCCESS             Command succeeded
  @retval EFI_DEVICE_ERROR        HECI Device error, command aborts abnormally
  @retval EFI_TIMEOUT             HECI does not return the buffer before timeout
**/
EFI_STATUS
PeiHeciAsfStartWatchDog (
  IN  EFI_PEI_SERVICES            **PeiServices,
  IN  PEI_HECI_PPI                *HeciPpi,
  IN  UINT32                      HeciMemBar,
  IN  UINT16                      WaitTimerBios
  )
{
  EFI_STATUS    Status;
  ASF_START_WDT AsfStartWdt;
  UINT32        HeciLength;
  UINT32        MeMode;

  Status = HeciPpi->GetMeMode (PeiServices, &MeMode);
  if (EFI_ERROR (Status) || (MeMode != ME_MODE_NORMAL)) {
    return EFI_UNSUPPORTED;
  }
  ///
  /// Clear Start Watch Dog Timer HECI message
  ///
  ZeroMem ((VOID *) &AsfStartWdt, sizeof (ASF_START_WDT));

  AsfStartWdt.Command         = ASF_MANAGEMENT_CONTROL;
  AsfStartWdt.ByteCount       = START_WDT_BYTE_COUNT;
  AsfStartWdt.SubCommand      = ASF_SUB_COMMAND_START_WDT;
  AsfStartWdt.VersionNumber   = START_WDT_VERSION_NUMBER;
  AsfStartWdt.TimeoutLow      = (UINT8) WaitTimerBios;
  AsfStartWdt.TimeoutHigh     = (UINT8) (WaitTimerBios >> 8);
  AsfStartWdt.EventSensorType = START_WDT_EVENT_SENSOR_TYPE;
  AsfStartWdt.EventType       = START_WDT_EVENT_TYPE;
  AsfStartWdt.EventOffset     = START_WDT_EVENT_OFFSET;
  AsfStartWdt.EventSourceType = START_WDT_EVENT_SOURCE_TYPE_BIOS;
  AsfStartWdt.EventSeverity   = START_WDT_EVENT_SEVERITY;
  AsfStartWdt.SensorDevice    = START_WDT_SENSOR_DEVICE;
  AsfStartWdt.SensorNumber    = START_WDT_SENSOR_NUMBER;
  AsfStartWdt.Entity          = START_WDT_ENTITY;
  AsfStartWdt.EntityInstance  = START_WDT_ENTITY_INSTANCE;
  AsfStartWdt.EventData[0]    = START_WDT_EVENT_DATA_BYTE_0;
  AsfStartWdt.EventData[1]    = START_WDT_EVENT_DATA_BYTE_1_BIOS_TIMEOUT;

  HeciLength                  = ASF_START_WDT_LENGTH;

  Status = HeciPpi->SendMsg (
                      PeiServices,
                      HeciPpi,
                      (UINT32 *) &AsfStartWdt,
                      HeciMemBar,
                      HeciLength,
                      BIOS_FIXED_HOST_ADDR,
                      HECI_ASF_MESSAGE_ADDR
                      );

  return Status;
}

/**
  Send Core BIOS Reset Request Message through HECI to reset the system.

  @param[in] PeiServices          General purpose services available to every PEIM.
  @param[in] ResetOrigin          Reset source
  @param[in] ResetType            Global or Host reset

  @retval EFI_SUCCESS             Command succeeded
  @retval EFI_DEVICE_ERROR        HECI Device error, command aborts abnormally
  @retval EFI_TIMEOUT             HECI does not return the buffer before timeout
**/
EFI_STATUS
PeiHeciSendCbmResetRequest (
  IN  EFI_PEI_SERVICES            **PeiServices,
  IN  UINT8                       ResetOrigin,
  IN  UINT8                       ResetType
  )
{
  EFI_STATUS            Status;
  PEI_HECI_PPI          *HeciPpi;
  CBM_RESET_REQ         CbmResetRequest;
  UINT32                HeciLength;
  UINT32                HeciMemBar;
  PLATFORM_ME_HOOK_PPI  *PlatformMeHookPpi;
  EFI_GUID              WdtPpiGuid = WDT_PPI_GUID;
  WDT_PPI               *WdtPpi;

  Status = PeiServicesLocatePpi (
            &gPlatformMeHookPpiGuid,      // GUID
            0,                            // INSTANCE
            NULL,                         // EFI_PEI_PPI_DESCRIPTOR
            (VOID **) &PlatformMeHookPpi  // PPI
            );
  if (EFI_ERROR (Status)) {
    DEBUG ((EFI_D_ERROR, "Unable to Locate PlatformMeHook Protocol for Global Reset Hook, so skip instead.", Status));
  } else {
    PlatformMeHookPpi->PreGlobalReset (PeiServices, PlatformMeHookPpi);
  }

  Status = PeiServicesLocatePpi (
            &gPeiHeciPpiGuid,         // GUID
            0,                        // INSTANCE
            NULL,                     // EFI_PEI_PPI_DESCRIPTOR
            (VOID **) &HeciPpi        // PPI
            );
  ASSERT_EFI_ERROR (Status);

  Status = HeciPpi->InitializeHeci (PeiServices, HeciPpi, &HeciMemBar);
  if (EFI_ERROR (Status)) {
    return Status;
  }

  CbmResetRequest.MKHIHeader.Data               = 0;
  CbmResetRequest.MKHIHeader.Fields.Command     = CBM_RESET_REQ_CMD;
  CbmResetRequest.MKHIHeader.Fields.IsResponse  = 0;
  CbmResetRequest.MKHIHeader.Fields.GroupId     = MKHI_CBM_GROUP_ID;
  CbmResetRequest.MKHIHeader.Fields.Reserved    = 0;
  CbmResetRequest.MKHIHeader.Fields.Result      = 0;
  CbmResetRequest.Data.RequestOrigin            = CBM_RR_REQ_ORIGIN_BIOS_MEMORY_INIT;
  CbmResetRequest.Data.ResetType                = CBM_HRR_GLOBAL_RESET;

  HeciLength = sizeof (CBM_RESET_REQ);

  Status = PeiServicesLocatePpi (
            &WdtPpiGuid,              // GUID
            0,                        // INSTANCE
            NULL,                     // EFI_PEI_PPI_DESCRIPTOR
            (VOID **) &WdtPpi         // PPI
            );
  ASSERT_EFI_ERROR (Status);
  WdtPpi->AllowKnownReset ();

  Status = HeciPpi->SendMsg (
                      PeiServices,
                      HeciPpi,
                      (UINT32 *) &CbmResetRequest,
                      HeciMemBar,
                      HeciLength,
                      BIOS_FIXED_HOST_ADDR,
                      HECI_CORE_MESSAGE_ADDR
                      );

  return Status;
}