summaryrefslogtreecommitdiff
path: root/CRB/CRBTse.c
blob: db21975d6d3212590db9ee497e1d8e76137e011e (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
//*************************************************************************
//*************************************************************************
//**                                                                     **
//**        (C)Copyright 1985-2014, American Megatrends, Inc.            **
//**                                                                     **
//**                       All Rights Reserved.                          **
//**                                                                     **
//**      5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093           **
//**                                                                     **
//**                       Phone: (770)-246-8600                         **
//**                                                                     **
//*************************************************************************
//*************************************************************************
//*************************************************************************
// $Header: /Alaska/Projects/Intel/Haswell/LynxPoint_SharkBay-DT_Crb_1AQQW/CRB/CRBTse.c 1     3/17/14 2:36a Chaseliu $Revision:
//
// $Date: 3/17/14 2:36a $Log:
// 
//*************************************************************************
#include "Efi.h"
#include "token.h"
#include <AmiLib.h>
#include <AmiDxeLib.h>
#include "Protocol\PciIo.h"
#include "Protocol\DevicePath.h"
#include "protocol\DriverBinding.h"
#include "protocol\BlockIo.h"
#include "Protocol\PDiskInfo.h"
#include "Protocol\PIDEController.h"
#include "Protocol\PIDEBus.h"
#include "Protocol\PAhciBus.h"
#include "Protocol\PIDEBus.h"
#include <Setup.h>


#define     SecurityEnabledMask         0x0002


EFI_RUNTIME_SERVICES  *gRT;
EFI_BOOT_SERVICES     *gBS;

UINT8   Satamode=0;
UINT8   GetVariableError=0;

// Produced Protocols

// Consumed Protocols

//---------------------------------------------------------------------------
// Constant, Macro and Type Definition(s)
//---------------------------------------------------------------------------
// Constant Definition(s)

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   GetSetupSataMode
//
// Description: Gets the sata mode before entering Setup and Store in Satamode.
//              Global Variable.
//
// Input:       VOID
//
// Output:      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
GetSetupSataMode( )
{

    UINT32      SetupDataAttributes = 0;
    UINTN       SetupDataSize = sizeof(SETUP_DATA);
    SETUP_DATA  SetupData;
    EFI_GUID    gSetupGuid = SETUP_GUID;
    EFI_STATUS  Status;

    Status = gRT->GetVariable(L"Setup", &gSetupGuid, &SetupDataAttributes,
                                &SetupDataSize, &SetupData);

    if(EFI_ERROR(Status)){
        GetVariableError = 1;
        return;
    }
    //
    // Store the SataMode before going to setup.
    //    
    Satamode = SetupData.SataInterfaceMode;

    return;

}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   IssueColdReset
//
// Description: Issues cold reset.
//
// Input:       VOID
//
// Output:      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
IssueColdReset( )
{
    IoWrite8(0xcf9, 0xE);
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   CheckForChangeinSataMode
//
// Description: Gets the sata mode when exiting and resetting from
//              setup and checks whether sata mode is changed. If changed it
//              issues cold reset. Satamode(Value got before entering setup) is 
//              Stored in Satamode_Before_Setup.
//
// Input:       VOID
//
// Output:      VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
CheckForChangeinSataMode( )
{

    UINT32      SetupDataAttributes = 0;
    UINTN       SetupDataSize = sizeof(SETUP_DATA);
    EFI_GUID    gSetupGuid = SETUP_GUID;
    UINTN       Count;
    EFI_HANDLE  *HandleBuffer = NULL;
    UINT16      SecurityStatus = 0;
    EFI_STATUS  Status;
    UINT8       i;
    IDE_SECURITY_PROTOCOL *Security = NULL;
    EFI_GUID    gIDESecurityProtocolGuid    = IDE_SECURITY_INTERFACE_GUID;
    UINT8       Satamode_Before_Setup = Satamode;

    
    if(GetVariableError) {
        return;
    }

    //
    // Get the Setupdata.
    //
    GetSetupSataMode();
    
    //
    // Check for change in the satamode selection in  setup.if yes, issue cold reset.
    //
    if( Satamode_Before_Setup != Satamode) {
        //
        // Check all HDD, if Password is installed in anyone of the HDD, issue cold reset.
        //
        Status = gBS->LocateHandleBuffer(ByProtocol,
                                         &gIDESecurityProtocolGuid,
                                         NULL,
                                         &Count,
                                         &HandleBuffer);

        if(EFI_ERROR(Status)) {
            return;
        }

        for(i = 0; i < Count; i++) {

            Status = gBS->HandleProtocol(HandleBuffer[i], &gIDESecurityProtocolGuid, &Security);
            if(EFI_ERROR(Status)) {
                return;
            }

            //
            // Get the security status of the device, to check whether password is installed.
            //
            Status = Security->ReturnSecurityStatus( Security, &SecurityStatus );
            if(EFI_ERROR(Status)) {
                return;
            }

            if( SecurityStatus & SecurityEnabledMask ) {
                //
                // Issue Cold Reset.
                //
                IssueColdReset();
            }
        }

        gBS->FreePool(HandleBuffer);
    }

    return;
}

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