summaryrefslogtreecommitdiff
path: root/Core/EM/HddSecurity/Hddpassword/ForceHddPassword.c
blob: 90c9a4d068b9be7e25dce11b76028c7e63a19c56 (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
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**         5555 Oakbrook Pkwy, Suite 200, Norcross, GA 30093        **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************
//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/HddSecurity/HddPassword/ForceHddPassword.c 2     10/11/10 6:19p Krishnakumarg $
//
// $Revision: 2 $
//
// $Date: 10/11/10 6:19p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/HddSecurity/HddPassword/ForceHddPassword.c $
// 
// 2     10/11/10 6:19p Krishnakumarg
// [TAG] - EIP 45593
// [Category] - IMPROVEMENT
// [Severity] - Minor
// [Symptom]  - Build Errors in ForceHDDPassword.c on new core 4.6.4.1
// label
// [RootCause]- IDE_CONTROLLER_PROTOCOL structure defined header not
// included
// [Solution] - Include the respective header(PIDEController.h)
// [Files] - ForceHddPassword.c
// 
// 1     8/19/10 2:44a Rameshr
// Issue:Need do HDD PSW reset when warmboot
// EIP 40528
//
//
//**********************************************************************

//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:        ForceHddPassword.c
//
// Description: Send Disable Software Preservation command when the 
//              FORCE_HDD_PASSWORD_PROMPT token is set to 1
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#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"


EFI_RUNTIME_SERVICES  *gRT;
EFI_BOOT_SERVICES     *gBS;

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:   DisableSoftwarePreservation
//
// Description: Send the Disable software Preservation 
//
// Input:       None
//
// Output:      None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
DisableSoftwarePreservation ( )
{
#if FORCE_HDD_PASSWORD_PROMPT
    UINTN               HandleCount;
    EFI_HANDLE          *HandleBuffer;
    UINT8               i;
    AHCI_BUS_PROTOCOL   *AhciBusInterface;
    EFI_GUID gEfiAhciBusProtocolGuid = AHCI_BUS_INIT_PROTOCOL_GUID;
    SATA_DEVICE_INTERFACE   *SataDeviceInterface;
    DLINK                   *dlink;
    COMMAND_STRUCTURE       CommandStructure = {0};
    EFI_STATUS              Status;    


    Status = gBS->LocateHandleBuffer (
                                      ByProtocol,
                                      &gEfiAhciBusProtocolGuid,
                                      NULL,
                                      &HandleCount,
                                      &HandleBuffer
                                      );

    if(EFI_ERROR(Status) || HandleCount == 0 ) {
        return;
    }

    //
    // Issue Disable Software Preservation command all the Sata Devices connected.
    //
    for (i = 0; i < HandleCount; i++) {
        Status = gBS->HandleProtocol (HandleBuffer[i], &gEfiAhciBusProtocolGuid, &AhciBusInterface);
        if (!EFI_ERROR(Status)) {
            dlink = AhciBusInterface->SataDeviceList.pHead; 
            if (dlink){ 
                do {
                    SataDeviceInterface = OUTTER(dlink, SataDeviceLink, SATA_DEVICE_INTERFACE);
 
                    if ((SataDeviceInterface->IdentifyData.Reserved_76_79[0] != 0xFFFF )&&
                        (SataDeviceInterface->IdentifyData.Reserved_76_79[2] & 0x0040)&&           // Software Preservation support
                        (SataDeviceInterface->IdentifyData.Security_Status_128 & 0x0002)&&         // Security enabled
                        (!(SataDeviceInterface->IdentifyData.Security_Status_128 & 0x0004))) {     // Security not locked
 
                            //
                            // Send Disable Software Preservation command.
                            //
                            CommandStructure.Features = DISABLE_SATA2_SOFTPREV;
                            CommandStructure.SectorCount = 6;
                            CommandStructure.Command = SET_FEATURE_COMMAND;
                            Status = AhciBusInterface->ExecuteNonDataCommand(SataDeviceInterface, CommandStructure);
                    }
                    dlink = dlink-> pNext;
                }while (dlink);    
            }
         }
     }
#endif
    return;
}


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