summaryrefslogtreecommitdiff
path: root/Chipset/SB/PowerButton.c
blob: d9256fffe33cc30b521e9bd3522cb82031a705e3 (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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/SMM/PowerButton/PowerButton.c 9     9/20/11 3:12p Markw $
//
// $Revision: 9 $
//
// $Date: 9/20/11 3:12p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/SMM/PowerButton/PowerButton.c $
// 
// 9     9/20/11 3:12p Markw
// [TAG]  		EIP67890
// [Category]  	Spec Update
// [Severity]  	Normal
// [Description]  	Support power button handler in PI 1.1
// 
// [Files]  		PowerButton.c, PowerButton.mak, PowerButton. dxs
//
// 8     7/08/09 7:56p Markw
// Update headers.
//
// 7     1/07/08 4:26p Robert
// Updated for coding standard
//
// 6     5/30/07 5:29p Markw
// Use library function to shutdown.
//
// 5     3/28/07 1:27p Markw
// Update headers.
//
// 4     2/26/07 11:44a Yakovlevs
// Added arming PwrButton Smi when registering SMI handler.
// In event handler added check for Sleep SMI enable and disabling it.
//
// 3     11/11/05 11:46a Markw
// Renamed IntallSmmHandler to InitSmmHandler because of build errors
// because another driver used InstallSmmHandler.
//
// 2     11/08/05 6:05p Markw
// Using InstallSmiHandler library function.
//
// 1     1/28/05 4:33p Sivagarn
// Power Button SMM Component - Initial check in
//
//
//**********************************************************************

//<AMI_FHDR_START>
//---------------------------------------------------------------------------
//
// Name:        PowerButton.C
//
// Description: Provide functions to register and handle Powerbutton
//              functionality.  This code is generic and as long as PM
//              base address SDL token is defined properly this should
//              work fine.
//
//---------------------------------------------------------------------------
//<AMI_FHDR_END>


#include <Token.h>
#include <AmiDxeLib.h>
#include <AMICSPLIBInc.h>
#if PI_SPECIFICATION_VERSION < 0x1000A
#include <Protocol\SmmPowerButtonDispatch.h>
#else
#include <Protocol\SmmPowerButtonDispatch2.h>
#endif

EFI_GUID gThisFileGuid =
    {0xe566b097,0x4378,0x485f,0x91,0xd0,0x1c,0x09,0x7c,0x19,0x0c,0xe2};
    //E566B097-4378-485f-91D0-1C097C190CE2

#if PI_SPECIFICATION_VERSION < 0x1000A
EFI_SMM_POWER_BUTTON_DISPATCH_CONTEXT	DispatchContext = {PowerButtonEntry};
#else
EFI_SMM_POWER_BUTTON_REGISTER_CONTEXT	DispatchContext = {EfiPowerButtonExit};
EFI_SMM_BASE2_PROTOCOL					*pSmmBase2;
EFI_SMM_SYSTEM_TABLE2					*pSmst2;
#endif

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:   PowerButtonActivated
//
// Description: If the power button is pressed, then this function is called.
//
// Input:
//  IN EFI_HANDLE                               DispatchHandle
//  IN EFI_SMM_POWER_BUTTON_DISPATCH_CONTEXT    *DispatchContext
//
// Output: VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
#if PI_SPECIFICATION_VERSION < 0x1000A
VOID PowerButtonActivated(
    IN EFI_HANDLE                               DispatchHandle,
    IN EFI_SMM_POWER_BUTTON_DISPATCH_CONTEXT    *DispatchContext
    )
#else
EFI_STATUS
EFIAPI
PowerButtonActivated(
	IN EFI_HANDLE	DispatchHandle,
	IN CONST VOID	*Context OPTIONAL,
	IN OUT VOID		*CommBuffer OPTIONAL,
	IN OUT UINTN	*CommBufferSize OPTIONAL)
#endif
{
    SBLib_Shutdown();

#if PI_SPECIFICATION_VERSION >= 0x1000A
	return EFI_SUCCESS;
#endif
}


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:   InSmmFunction
//
// Description: This function is called from SMM during SMM registration.
//
// Input:
//  IN EFI_HANDLE       ImageHandle
//  IN EFI_SYSTEM_TABLE *SystemTable
//
// Output: EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS InSmmFunction(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
#if PI_SPECIFICATION_VERSION >= 0x1000A
    EFI_SMM_POWER_BUTTON_DISPATCH2_PROTOCOL	*PowerButton;
#else
    EFI_SMM_POWER_BUTTON_DISPATCH_PROTOCOL  *PowerButton;
#endif
    EFI_HANDLE  hPowerButton;
    EFI_STATUS  Status;

#if PI_SPECIFICATION_VERSION >= 0x1000A
    Status = pSmmBase2->GetSmstLocation(pSmmBase2, &pSmst2);
    if (EFI_ERROR(Status)) return Status;

    Status = pSmst2->SmmLocateProtocol(
        &gEfiSmmPowerButtonDispatch2ProtocolGuid,
        NULL,
        &PowerButton
    );
#else
    Status = pBS->LocateProtocol(
        &gEfiSmmPowerButtonDispatchProtocolGuid,
        NULL,
        &PowerButton
    );
#endif
    if (EFI_ERROR(Status)) return Status;

    Status = PowerButton->Register(
        PowerButton,
        PowerButtonActivated,
        &DispatchContext,
        &hPowerButton
    );
    return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:   NotInSmmFunction
//
// Description: This function is called from outside of SMM during SMM registration.
//
// Input:
//  IN EFI_HANDLE       ImageHandle
//  IN EFI_SYSTEM_TABLE *SystemTable
//
// Output: EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS NotInSmmFunction(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
    UINT16  Value;
    //Clear All PM  Statuses
    Value = IoRead16(PM_BASE_ADDRESS);
    IoWrite16(PM_BASE_ADDRESS,Value);

    //Enable PowerButton and Global Enable
    IoWrite16(PM_BASE_ADDRESS + 0x02, BIT05 + BIT08);
    return EFI_SUCCESS;
}



//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure:   InitPowerButton
//
// Description: This is the entrypoint of the Power button driver.
//
// Input:
//  IN EFI_HANDLE       ImageHandle
//  IN EFI_SYSTEM_TABLE *SystemTable
//
// Output: EFI_STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS InitPowerButton(
    IN EFI_HANDLE       ImageHandle,
    IN EFI_SYSTEM_TABLE *SystemTable
    )
{
#if PI_SPECIFICATION_VERSION >= 0x0001000a
    EFI_STATUS    Status;
#endif

    InitAmiLib(ImageHandle, SystemTable);

#if PI_SPECIFICATION_VERSION >= 0x0001000a
    Status = pBS->LocateProtocol(&gEfiSmmBase2ProtocolGuid, NULL, &pSmmBase2);
    if (EFI_ERROR(Status)) return Status;

    return InitSmmHandler(ImageHandle, SystemTable, InSmmFunction, NULL);
#else
    return InitSmmHandler(ImageHandle, SystemTable, InSmmFunction, NotInSmmFunction);
#endif
}

//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************