summaryrefslogtreecommitdiff
path: root/Board/EM/RapidStartWrapper/Smm/RapidStartWrapperSmm.c
blob: 2d21006e1c8c49bad9d521da8b1b7d120495c74a (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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2012, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartWrapperSmm.c 3     5/13/14 4:56a Joshchou $
//
// $Revision: 3 $
//
// $Date: 5/13/14 4:56a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/Intel Fast Flash Standby/iRST_SharkBay/RapidStartWrapper/RapidStartWrapperSmm.c $
// 
// 3     5/13/14 4:56a Joshchou
// [TAG]  		EIP167032
// [Category]  	Improvement
// [Description]  	Review the variable's attribute, we shouldn't use
// runtime attribute with setup variable.
// [Files]  		RapidStartWrapperSmm.c
// RapidStartWrapperSmm.h
// RapidStartWrapperSmm.cif
// 
// 2     4/15/13 2:36a Bensonlai
// [TAG]  		None
// [Category]  	Bug Fix
// [Severity]  	Important
// [Symptom]  	If users change any item from driver then restore to boot
// setting, our SMI can't distinguish between user's and driver's event.
// [RootCause]  	It's an Intel driver issue.
// [Solution]  	1. Removing the sync up with Rapid Start driver and BIOS
// variable as default.
// 2. Remove our BIOS workaround.
// [Files]  		RapidStartWrapperSmm.sdl, RapidStartWrapperSmm.h,
// RapidStartWrapperSmm.sdl, RapidStartWrapperAcpiTables.sdl,
// RapidStartWrapper.sdl
// 
// 1     12/27/12 2:23a Bensonlai
// [TAG]  		EIP110680
// [Category]  	New Feature
// [Description]  	When iRST application is run under OS, and change
// timer.
// BIOS should update the changed to Setup option as well.
// [Files]  		Board\EM\RapidStartWrapper\Smm\RapidStartWrapperSmm.c
// Board\EM\RapidStartWrapper\Smm\RapidStartWrapperSmm.h
// Board\EM\RapidStartWrapper\Smm\RapidStartWrapperSmm.mak
// Board\EM\RapidStartWrapper\Smm\RapidStartWrapperSmm.dxs
// Board\EM\RapidStartWrapper\Smm\RapidStartWrapperSmm.sdl
// Board\EM\RapidStartWrapper\Smm\RapidStartWrapperSmm.cif
// Board\EM\RapidStartWrapper\AcpiTables\RapidStartWrapperAcpiTables.cif
// Board\EM\RapidStartWrapper\AcpiTables\RapidStartWrapperAcpiTables.sdl
// Board\EM\RapidStartWrapper\AcpiTables\Ssdt\RapidStartWrapper.asl
// Board\EM\RapidStartWrapper\RapidStartSetup\RapidStartSetup.sd
// 
//**********************************************************************
//<AMI_FHDR_START>
//
// Name: RapidStartWrapperSmm.c
//
// Description: Sw SMI for RapidStart Wrapper
//
//<AMI_FHDR_END>
//**********************************************************************

#include "RapidStartWrapperSmm.h"

VOID* InternalGetSmstConfigurationTable(IN EFI_GUID *TableGuid) {
    EFI_CONFIGURATION_TABLE	    *Table;
    UINTN                        i;
    EFI_STATUS                   Status;

    if (mSmmBase == NULL) {
        Status = gBS->LocateProtocol (&gEfiSmmBaseProtocolGuid, NULL, &mSmmBase);
        if (EFI_ERROR(Status) || mSmmBase == NULL)return NULL;
    }

    if (mSmst == NULL ) {
        if (mSmmBase!=NULL) {
            Status = mSmmBase->GetSmstLocation (mSmmBase, &mSmst);
            if (EFI_ERROR(Status) || mSmst == NULL)return NULL;
        }
    }

    if (mSmst != NULL) {
        Table = mSmst->SmmConfigurationTable;
        i = mSmst->NumberOfTableEntries;

        for (; i; --i,++Table)
        {
            if (CompareGuid(&Table->VendorGuid,TableGuid))
                return Table->VendorTable;
        }
    }
    return NULL;
}

VOID
RapidStartSyncVariable (
    VOID
)
{
    EFI_STATUS       Status;
    RAPID_START_WRAPPER_SMM_DATA  RapidStartWrapperSmmData;
    RapidStartWrapperSmmData.S3WakeTimerMin = mRapidStartGlobalNvs->WakeTimerMin;

    if ( (mRapidStartGlobalNvs->EventsEnabled & RAPID_START_ACPI_RTC_WAKE) != 0) {
        RapidStartWrapperSmmData.EntryOnS3RtcWake = 1;
    } else {
        RapidStartWrapperSmmData.EntryOnS3RtcWake = 0;
    }

    if ( (mRapidStartGlobalNvs->EventsEnabled & RAPID_START_ACPI_BATT_WAKE) != 0) {
        RapidStartWrapperSmmData.EntryOnS3CritBattWake = 1;
    } else {
        RapidStartWrapperSmmData.EntryOnS3CritBattWake = 0;
    }

    Status = mySMMgRT->SetVariable( L"RstWrapVar", \
                                    &RapidStartWrapperSmmDataGuid, \
                                    EFI_VARIABLE_NON_VOLATILE | \
                                    EFI_VARIABLE_BOOTSERVICE_ACCESS | \
                                    EFI_VARIABLE_RUNTIME_ACCESS, \
                                    sizeof (RAPID_START_WRAPPER_SMM_DATA), \
                                    &RapidStartWrapperSmmData
                                  );

    if ( EFI_ERROR(Status) ) {
        return;
    }

    return;
}

VOID
RapidStartWrapperSwSmiCallback (
    IN  EFI_HANDLE                    DispatchHandle,
    IN  EFI_SMM_SW_DISPATCH_CONTEXT   *DispatchContext
)
{
    UINT8            WrapperFunctionIndex;

    WrapperFunctionIndex = IoRead8(SW_SMI_IO_DATA_ADDRESS);     // Get Wrapper Function Index
    IoWrite8(SW_SMI_IO_DATA_ADDRESS, 0x00);                     // Clear data

    switch ( WrapperFunctionIndex ) {
    case AMI_RAPID_START_SYNC_VARIABLE_FUNCTION:
        RapidStartSyncVariable();
        break;

    default :
        break;
    }

    return;
}

EFI_STATUS
RapidStartWrapperSmmEntryPoint (
    IN EFI_HANDLE        ImageHandle,
    IN EFI_SYSTEM_TABLE  *SystemTable
)
{
    RAPID_START_GLOBAL_NVS_AREA_PROTOCOL  *RapidStartGlobalNvsAreaProtocol;
    EFI_SMM_SW_DISPATCH_PROTOCOL          *SwDispatch;
    EFI_SMM_SW_DISPATCH_CONTEXT           SwContext;
    EFI_HANDLE                            DispatchHandle;
    EFI_STATUS                            Status;
    VOID                                  *ptrRs;

    ptrRs = InternalGetSmstConfigurationTable(&SmmRtServTableGuid);
    if (ptrRs!=NULL) mySMMgRT = ptrRs;

    DEBUG ((EFI_D_INFO, "RapidStartWrapperSmmEntryPoint()\n"));

    Status = gBS->LocateProtocol (
                 &gRapidStartGlobalNvsAreaProtocolGuid,
                 NULL,
                 (VOID **) &RapidStartGlobalNvsAreaProtocol
             );

    if ( EFI_ERROR (Status) ) {
        DEBUG ((EFI_D_INFO, "No RapidStart info protocol available\n"));
        return Status;
    }

    mRapidStartGlobalNvs      = RapidStartGlobalNvsAreaProtocol->Area;
    DEBUG ((EFI_D_INFO, "RapidStartGlobalNvs:      %x\n", mRapidStartGlobalNvs));

    ///
    /// Locate the SMM SW dispatch protocol
    ///
    Status = gBS->LocateProtocol (&gEfiSmmSwDispatchProtocolGuid, NULL, &SwDispatch);
    if ( EFI_ERROR (Status) ) {
        return Status;
    }

    ///
    /// Register SWSMI handler
    ///
    DEBUG ((EFI_D_INFO, "Register SW_SMI_RAPID_START_WRAPPER: %x\n", SW_SMI_RAPID_START_WRAPPER));
    SwContext.SwSmiInputValue = SW_SMI_RAPID_START_WRAPPER;
    Status = SwDispatch->Register (
                 SwDispatch,
                 RapidStartWrapperSwSmiCallback,
                 &SwContext,
                 &DispatchHandle
             );
    if ( EFI_ERROR (Status) ) {
        return Status;
    }

    return EFI_SUCCESS;
}

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