]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/Opal/OpalPassword/OpalPasswordPei.h
SecurityPkg OpalPassword: Add solution without SMM device code
[mirror_edk2.git] / SecurityPkg / Tcg / Opal / OpalPassword / OpalPasswordPei.h
1 /** @file
2 Opal Password PEI driver which is used to unlock Opal Password for S3.
3
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _OPAL_PASSWORD_PEI_H_
16 #define _OPAL_PASSWORD_PEI_H_
17
18 #include <PiPei.h>
19 #include <IndustryStandard/Atapi.h>
20 #include <IndustryStandard/Pci.h>
21
22 #include <Library/DebugLib.h>
23 #include <Library/IoLib.h>
24 #include <Library/PciLib.h>
25 #include <Library/BaseLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/PeimEntryPoint.h>
29 #include <Library/PeiServicesLib.h>
30 #include <Library/HobLib.h>
31 #include <Library/TimerLib.h>
32 #include <Library/LockBoxLib.h>
33 #include <Library/TcgStorageOpalLib.h>
34 #include <Library/Tcg2PhysicalPresenceLib.h>
35
36 #include <Protocol/StorageSecurityCommand.h>
37
38 #include <Ppi/IoMmu.h>
39
40 #include "OpalPasswordCommon.h"
41 #include "OpalAhciMode.h"
42 #include "OpalNvmeMode.h"
43
44 //
45 // Time out Value for ATA pass through protocol
46 //
47 #define ATA_TIMEOUT 30000000
48
49 //
50 // The payload Length of HDD related ATA commands
51 //
52 #define HDD_PAYLOAD 512
53 //
54 // According to ATA spec, the max Length of hdd password is 32 bytes
55 //
56 #define OPAL_PASSWORD_MAX_LENGTH 32
57
58 #pragma pack(1)
59
60 /**
61 * Opal I/O Type utilized by the Trusted IO callback
62 *
63 * The type indicates if the I/O is a send or receive
64 */
65 typedef enum {
66 //
67 // I/O is a TCG Trusted Send command
68 //
69 OpalSend,
70
71 //
72 // I/O is a TCG Trusted Receive command
73 //
74 OpalRecv
75 } OPAL_IO_TYPE;
76
77 #define OPAL_PEI_DEVICE_SIGNATURE SIGNATURE_32 ('o', 'p', 'd', 's')
78
79 typedef struct {
80 UINTN Signature;
81 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL Sscp;
82 UINT8 DeviceType;
83 OPAL_DEVICE_COMMON *Device;
84 VOID *Context;
85 } OPAL_PEI_DEVICE;
86
87 #define OPAL_PEI_DEVICE_FROM_THIS(a) CR (a, OPAL_PEI_DEVICE, Sscp, OPAL_PEI_DEVICE_SIGNATURE)
88
89 #pragma pack()
90
91 /**
92 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
93 OperationBusMasterCommonBuffer64 mapping.
94
95 @param Pages The number of pages to allocate.
96 @param HostAddress A pointer to store the base system memory address of the
97 allocated range.
98 @param DeviceAddress The resulting map address for the bus master PCI controller to use to
99 access the hosts HostAddress.
100 @param Mapping A resulting value to pass to Unmap().
101
102 @retval EFI_SUCCESS The requested memory pages were allocated.
103 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
104 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
105 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
106 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
107
108 **/
109 EFI_STATUS
110 IoMmuAllocateBuffer (
111 IN UINTN Pages,
112 OUT VOID **HostAddress,
113 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
114 OUT VOID **Mapping
115 );
116
117 /**
118 Frees memory that was allocated with AllocateBuffer().
119
120 @param Pages The number of pages to free.
121 @param HostAddress The base system memory address of the allocated range.
122 @param Mapping The mapping value returned from Map().
123
124 **/
125 VOID
126 IoMmuFreeBuffer (
127 IN UINTN Pages,
128 IN VOID *HostAddress,
129 IN VOID *Mapping
130 );
131
132 #endif // _OPAL_PASSWORD_PEI_H_
133