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
|
/** @file
PCH S3 Support Protocol SMM Driver Entry
@copyright
Copyright (c) 2015 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
**/
#include "S3SupportSmm.h"
//
// Global Variables
//
UINT16 mS3SupportIoTrapAddress;
EFI_SMM_SYSTEM_TABLE *mSmst;
EFI_SMM_BASE_PROTOCOL *mSmmBase;
EFI_SMM_IO_TRAP_DISPATCH_PROTOCOL *mPchIoTrap;
EFI_HANDLE mImageHandle;
EFI_PCH_S3_SUPPORT_SMM_PROTOCOL *mPchS3SupportSmmProtocol;
EFI_HANDLE mPchIoTrapHandle;
/**
An IO Trap SMI callback to copy the DispatchArray data to SMRAM and unregister the IO Trap.
@param[in] DispatchHandle - The handle of this callback, obtained when registering
@param[in] DispatchContext - Pointer to the EFI_SMM_IO_TRAP_DISPATCH_CALLBACK_CONTEXT
@retval None
**/
VOID
S3SupportSmmExitPmAuthCallback (
IN EFI_HANDLE DispatchHandle,
IN EFI_SMM_IO_TRAP_DISPATCH_CALLBACK_CONTEXT *CallbackContext
)
{
EFI_PHYSICAL_ADDRESS Address;
EFI_STATUS Status;
DEBUG ((EFI_D_INFO, "S3SupportSmmExitPmAuthCallback() Start\n"));
///
/// Allocate SMRAM memory for the PCH S3 Custom Dispatch Script
///
Status = mSmst->SmmAllocatePages (
AllocateAnyPages,
EfiRuntimeServicesData,
mPchS3SupportSmmProtocol->ProtocolSize,
&Address
);
DEBUG ((EFI_D_INFO, "SMRAM Memory Allocation Failed - S3SupportSmmExitPmAuthCallback()\n"));
ASSERT_EFI_ERROR (Status);
///
/// Copy S3 Support Data from Boot Services memory to SMRAM
///
CopyMem ((VOID *)Address, mPchS3SupportSmmProtocol->DispatchArray, mPchS3SupportSmmProtocol->ProtocolSize * EFI_PAGE_SIZE);
///
/// Unregister the IO Trap as the copy to SMRAM is only allowed once
///
Status = mPchIoTrap->UnRegister (
mPchIoTrap,
&mPchIoTrapHandle
);
DEBUG ((EFI_D_INFO, "IO Trap Unregister Failed - S3SupportSmmExitPmAuthCallback()\n"));
ASSERT_EFI_ERROR (Status);
///
/// Clear the NextDispatchItem in the Boot Services Memory so as to cause an error
/// if an entity tries to use the Protocol to add more data after the copy to SMRAM.
///
mPchS3SupportSmmProtocol->DispatchArray->NextDispatchItem = NULL;
DEBUG ((EFI_D_INFO, "S3SupportSmmExitPmAuthCallback() End\n"));
return;
}
/**
Initializes the PCH SMM handler for PCH save and restore
@param[in] ImageHandle - Handle for the image of this driver
@param[in] SystemTable - Pointer to the EFI System Table
@retval EFI_SUCCESS - PCH SMM handler was installed
**/
EFI_STATUS
S3SupportSmmEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_SMM_IO_TRAP_DISPATCH_REGISTER_CONTEXT PchIoTrapContext;
DEBUG ((EFI_D_INFO, "S3SupportSmmEntryPoint() Start\n"));
mImageHandle = NULL;
///
/// Locate SmmBase protocol
///
Status = gBS->LocateProtocol (&gEfiSmmBaseProtocolGuid, NULL, (VOID **)&mSmmBase);
ASSERT_EFI_ERROR (Status);
///
/// Initialize our module variables
///
Status = mSmmBase->GetSmstLocation (mSmmBase, &mSmst);
ASSERT_EFI_ERROR (Status);
///
/// Locate the PCH S3 SMM Support protocol
///
Status = gBS->LocateProtocol (&gEfiPchS3SupportSmmProtocolGuid, NULL, (void **)&mPchS3SupportSmmProtocol);
ASSERT_EFI_ERROR (Status);
///
/// Locate the PCH Trap dispatch protocol
///
Status = gBS->LocateProtocol (&gEfiSmmIoTrapDispatchProtocolGuid, NULL, &mPchIoTrap);
ASSERT_EFI_ERROR (Status);
PchIoTrapContext.Type = WriteTrap;
PchIoTrapContext.Length = 4;
PchIoTrapContext.Address = 0;
PchIoTrapContext.Context = NULL;
PchIoTrapContext.MergeDisable = FALSE;
Status = mPchIoTrap->Register (
mPchIoTrap,
S3SupportSmmExitPmAuthCallback,
&PchIoTrapContext,
&mPchIoTrapHandle
);
ASSERT_EFI_ERROR (Status);
mPchS3SupportSmmProtocol->PchS3SupportIoTrap = PchIoTrapContext.Address;
DEBUG ((EFI_D_INFO, "Pch S3 Support IO Trap Address = 0x%x\n", PchIoTrapContext.Address));
DEBUG ((EFI_D_INFO, "S3SupportSmmEntryPoint() End\n"));
return Status;
}
|