]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/Opal/OpalPasswordSmm/OpalIdeMode.h
SecurityPkg OpalPassword: Add solution without SMM device code
[mirror_edk2.git] / SecurityPkg / Tcg / Opal / OpalPasswordSmm / OpalIdeMode.h
1 /** @file
2 Header file for IDE mode of ATA host controller.
3
4 Copyright (c) 2016, 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
16
17 #ifndef __OPAL_PASSWORD_IDE_MODE_H__
18 #define __OPAL_PASSWORD_IDE_MODE_H__
19
20 typedef enum {
21 EfiIdePrimary = 0,
22 EfiIdeSecondary = 1,
23 EfiIdeMaxChannel = 2
24 } EFI_IDE_CHANNEL;
25
26 typedef enum {
27 EfiIdeMaster = 0,
28 EfiIdeSlave = 1,
29 EfiIdeMaxDevice = 2
30 } EFI_IDE_DEVICE;
31
32 //
33 // IDE registers set
34 //
35 typedef struct {
36 UINT16 Data;
37 UINT16 ErrOrFeature;
38 UINT16 SectorCount;
39 UINT16 SectorNumber;
40 UINT16 CylinderLsb;
41 UINT16 CylinderMsb;
42 UINT16 Head;
43 UINT16 CmdOrStatus;
44 UINT16 AltOrDev;
45 } EFI_IDE_REGISTERS;
46
47 //
48 // Bit definitions in Programming Interface byte of the Class Code field
49 // in PCI IDE controller's Configuration Space
50 //
51 #define IDE_PRIMARY_OPERATING_MODE BIT0
52 #define IDE_PRIMARY_PROGRAMMABLE_INDICATOR BIT1
53 #define IDE_SECONDARY_OPERATING_MODE BIT2
54 #define IDE_SECONDARY_PROGRAMMABLE_INDICATOR BIT3
55
56 /**
57 Get IDE i/o port registers' base addresses by mode.
58
59 In 'Compatibility' mode, use fixed addresses.
60 In Native-PCI mode, get base addresses from BARs in the PCI IDE controller's
61 Configuration Space.
62
63 The steps to get IDE i/o port registers' base addresses for each channel
64 as follows:
65
66 1. Examine the Programming Interface byte of the Class Code fields in PCI IDE
67 controller's Configuration Space to determine the operating mode.
68
69 2. a) In 'Compatibility' mode, use fixed addresses shown in the Table 1 below.
70 ___________________________________________
71 | | Command Block | Control Block |
72 | Channel | Registers | Registers |
73 |___________|_______________|_______________|
74 | Primary | 1F0h - 1F7h | 3F6h - 3F7h |
75 |___________|_______________|_______________|
76 | Secondary | 170h - 177h | 376h - 377h |
77 |___________|_______________|_______________|
78
79 Table 1. Compatibility resource mappings
80
81 b) In Native-PCI mode, IDE registers are mapped into IO space using the BARs
82 in IDE controller's PCI Configuration Space, shown in the Table 2 below.
83 ___________________________________________________
84 | | Command Block | Control Block |
85 | Channel | Registers | Registers |
86 |___________|___________________|___________________|
87 | Primary | BAR at offset 0x10| BAR at offset 0x14|
88 |___________|___________________|___________________|
89 | Secondary | BAR at offset 0x18| BAR at offset 0x1C|
90 |___________|___________________|___________________|
91
92 Table 2. BARs for Register Mapping
93
94 @param[in] Bus The bus number of ata host controller.
95 @param[in] Device The device number of ata host controller.
96 @param[in] Function The function number of ata host controller.
97 @param[in, out] IdeRegisters Pointer to EFI_IDE_REGISTERS which is used to
98 store the IDE i/o port registers' base addresses
99
100 @retval EFI_UNSUPPORTED Return this Value when the BARs is not IO type
101 @retval EFI_SUCCESS Get the Base address successfully
102 @retval Other Read the pci configureation Data error
103
104 **/
105 EFI_STATUS
106 EFIAPI
107 GetIdeRegisterIoAddr (
108 IN UINTN Bus,
109 IN UINTN Device,
110 IN UINTN Function,
111 IN OUT EFI_IDE_REGISTERS *IdeRegisters
112 );
113
114 /**
115 Sends out an ATA Identify Command to the specified device.
116
117 This function sends out the ATA Identify Command to the
118 specified device. Only ATA device responses to this command. If
119 the command succeeds, it returns the Identify Data structure which
120 contains information about the device. This function extracts the
121 information it needs to fill the IDE_BLK_IO_DEV Data structure,
122 including device type, media block Size, media capacity, and etc.
123
124 @param IdeRegisters A pointer to EFI_IDE_REGISTERS Data structure.
125 @param Channel The channel number of device.
126 @param Device The device number of device.
127 @param Buffer A pointer to Data Buffer which is used to contain IDENTIFY Data.
128
129 @retval EFI_SUCCESS Identify ATA device successfully.
130 @retval EFI_DEVICE_ERROR ATA Identify Device Command failed or device is not ATA device.
131 @retval EFI_OUT_OF_RESOURCES Allocate memory failed.
132 **/
133 EFI_STATUS
134 EFIAPI
135 AtaIdentify (
136 IN EFI_IDE_REGISTERS *IdeRegisters,
137 IN UINT8 Channel,
138 IN UINT8 Device,
139 IN OUT ATA_IDENTIFY_DATA *Buffer
140 );
141
142 /**
143 This function is used to send out ATA commands conforms to the PIO Data In Protocol.
144
145 @param IdeRegisters A pointer to EFI_IDE_REGISTERS Data structure.
146 @param Buffer A pointer to the source Buffer for the Data.
147 @param ByteCount The Length of the Data.
148 @param Read Flag used to determine the Data transfer direction.
149 Read equals 1, means Data transferred from device to host;
150 Read equals 0, means Data transferred from host to device.
151 @param AtaCommandBlock A pointer to EFI_ATA_COMMAND_BLOCK Data structure.
152 @param AtaStatusBlock A pointer to EFI_ATA_STATUS_BLOCK Data structure.
153 @param Timeout The time to complete the command.
154
155 @retval EFI_SUCCESS send out the ATA command and device send required Data successfully.
156 @retval EFI_DEVICE_ERROR command sent failed.
157
158 **/
159 EFI_STATUS
160 EFIAPI
161 AtaPioDataInOut (
162 IN EFI_IDE_REGISTERS *IdeRegisters,
163 IN OUT VOID *Buffer,
164 IN UINT64 ByteCount,
165 IN BOOLEAN Read,
166 IN EFI_ATA_COMMAND_BLOCK *AtaCommandBlock,
167 IN OUT EFI_ATA_STATUS_BLOCK *AtaStatusBlock,
168 IN UINT64 Timeout
169 );
170
171
172 #endif
173