]>
Commit | Line | Data |
---|---|---|
87bc3f19 HW |
1 | /** @file\r |
2 | The AhciPei driver is used to manage ATA hard disk device working under AHCI\r | |
3 | mode at PEI phase.\r | |
4 | \r | |
5 | Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r | |
6 | \r | |
9d510e61 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
87bc3f19 HW |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #include "AhciPei.h"\r | |
12 | \r | |
13 | /**\r | |
14 | Traverse the attached ATA devices list to find out the device with given trust\r | |
15 | computing device index.\r | |
16 | \r | |
17 | @param[in] Private A pointer to the PEI_AHCI_CONTROLLER_PRIVATE_DATA\r | |
18 | instance.\r | |
19 | @param[in] TrustComputingDeviceIndex The trust computing device index.\r | |
20 | \r | |
21 | @retval The pointer to the PEI_AHCI_ATA_DEVICE_DATA structure of the device\r | |
22 | info to access.\r | |
23 | \r | |
24 | **/\r | |
25 | PEI_AHCI_ATA_DEVICE_DATA *\r | |
26 | SearchTrustComputingDeviceByIndex (\r | |
27 | IN PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private,\r | |
28 | IN UINTN TrustComputingDeviceIndex\r | |
29 | )\r | |
30 | {\r | |
31 | PEI_AHCI_ATA_DEVICE_DATA *DeviceData;\r | |
32 | LIST_ENTRY *Node;\r | |
33 | \r | |
34 | Node = GetFirstNode (&Private->DeviceList);\r | |
35 | while (!IsNull (&Private->DeviceList, Node)) {\r | |
36 | DeviceData = AHCI_PEI_ATA_DEVICE_INFO_FROM_THIS (Node);\r | |
37 | \r | |
38 | if (DeviceData->TrustComputingDeviceIndex == TrustComputingDeviceIndex) {\r | |
39 | return DeviceData;\r | |
40 | }\r | |
41 | \r | |
42 | Node = GetNextNode (&Private->DeviceList, Node);\r | |
43 | }\r | |
44 | \r | |
45 | return NULL;\r | |
46 | }\r | |
47 | \r | |
48 | /**\r | |
49 | Gets the count of storage security devices that one specific driver detects.\r | |
50 | \r | |
51 | @param[in] This The PPI instance pointer.\r | |
52 | @param[out] NumberofDevices The number of storage security devices discovered.\r | |
53 | \r | |
54 | @retval EFI_SUCCESS The operation performed successfully.\r | |
55 | @retval EFI_INVALID_PARAMETER The parameters are invalid.\r | |
56 | \r | |
57 | **/\r | |
58 | EFI_STATUS\r | |
59 | EFIAPI\r | |
60 | AhciStorageSecurityGetDeviceNo (\r | |
61 | IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This,\r | |
62 | OUT UINTN *NumberofDevices\r | |
63 | )\r | |
64 | {\r | |
65 | PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;\r | |
66 | \r | |
67 | if (This == NULL || NumberofDevices == NULL) {\r | |
68 | return EFI_INVALID_PARAMETER;\r | |
69 | }\r | |
70 | \r | |
71 | Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY (This);\r | |
72 | *NumberofDevices = Private->TrustComputingDevices;\r | |
73 | \r | |
74 | return EFI_SUCCESS;\r | |
75 | }\r | |
76 | \r | |
77 | /**\r | |
78 | Gets the device path of a specific storage security device.\r | |
79 | \r | |
80 | @param[in] This The PPI instance pointer.\r | |
81 | @param[in] DeviceIndex Specifies the storage security device to which\r | |
82 | the function wants to talk. Because the driver\r | |
83 | that implements Storage Security Command PPIs\r | |
84 | will manage multiple storage devices, the PPIs\r | |
85 | that want to talk to a single device must specify\r | |
86 | the device index that was assigned during the\r | |
87 | enumeration process. This index is a number from\r | |
88 | one to NumberofDevices.\r | |
89 | @param[out] DevicePathLength The length of the device path in bytes specified\r | |
90 | by DevicePath.\r | |
91 | @param[out] DevicePath The device path of storage security device.\r | |
92 | This field re-uses EFI Device Path Protocol as\r | |
93 | defined by Section 10.2 EFI Device Path Protocol\r | |
94 | of UEFI 2.7 Specification.\r | |
95 | \r | |
96 | @retval EFI_SUCCESS The operation succeeds.\r | |
97 | @retval EFI_INVALID_PARAMETER DevicePathLength or DevicePath is NULL.\r | |
98 | @retval EFI_NOT_FOUND The specified storage security device not found.\r | |
99 | @retval EFI_OUT_OF_RESOURCES The operation fails due to lack of resources.\r | |
100 | \r | |
101 | **/\r | |
102 | EFI_STATUS\r | |
103 | EFIAPI\r | |
104 | AhciStorageSecurityGetDevicePath (\r | |
105 | IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This,\r | |
106 | IN UINTN DeviceIndex,\r | |
107 | OUT UINTN *DevicePathLength,\r | |
108 | OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r | |
109 | )\r | |
110 | {\r | |
111 | PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;\r | |
112 | PEI_AHCI_ATA_DEVICE_DATA *DeviceData;\r | |
113 | EFI_STATUS Status;\r | |
114 | \r | |
115 | if (This == NULL || DevicePathLength == NULL || DevicePath == NULL) {\r | |
116 | return EFI_INVALID_PARAMETER;\r | |
117 | }\r | |
118 | \r | |
119 | Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY (This);\r | |
120 | if ((DeviceIndex == 0) || (DeviceIndex > Private->TrustComputingDevices)) {\r | |
121 | return EFI_INVALID_PARAMETER;\r | |
122 | }\r | |
123 | \r | |
124 | DeviceData = SearchTrustComputingDeviceByIndex (Private, DeviceIndex);\r | |
125 | if (DeviceData == NULL) {\r | |
126 | return EFI_NOT_FOUND;\r | |
127 | }\r | |
128 | \r | |
129 | Status = AhciBuildDevicePath (\r | |
130 | Private,\r | |
131 | DeviceData->Port,\r | |
132 | DeviceData->PortMultiplier,\r | |
133 | DevicePathLength,\r | |
134 | DevicePath\r | |
135 | );\r | |
136 | if (EFI_ERROR (Status)) {\r | |
137 | return Status;\r | |
138 | }\r | |
139 | \r | |
140 | return EFI_SUCCESS;\r | |
141 | }\r | |
142 | \r | |
143 | /**\r | |
144 | Send a security protocol command to a device that receives data and/or the result\r | |
145 | of one or more commands sent by SendData.\r | |
146 | \r | |
147 | The ReceiveData function sends a security protocol command to the given DeviceIndex.\r | |
148 | The security protocol command sent is defined by SecurityProtocolId and contains\r | |
149 | the security protocol specific data SecurityProtocolSpecificData. The function\r | |
150 | returns the data from the security protocol command in PayloadBuffer.\r | |
151 | \r | |
152 | For devices supporting the SCSI command set, the security protocol command is sent\r | |
153 | using the SECURITY PROTOCOL IN command defined in SPC-4.\r | |
154 | \r | |
155 | For devices supporting the ATA command set, the security protocol command is sent\r | |
156 | using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize\r | |
157 | is non-zero.\r | |
158 | \r | |
159 | If the PayloadBufferSize is zero, the security protocol command is sent using the\r | |
160 | Trusted Non-Data command defined in ATA8-ACS.\r | |
161 | \r | |
162 | If PayloadBufferSize is too small to store the available data from the security\r | |
163 | protocol command, the function shall copy PayloadBufferSize bytes into the\r | |
164 | PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.\r | |
165 | \r | |
166 | If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,\r | |
167 | the function shall return EFI_INVALID_PARAMETER.\r | |
168 | \r | |
169 | If the given DeviceIndex does not support security protocol commands, the function\r | |
170 | shall return EFI_UNSUPPORTED.\r | |
171 | \r | |
172 | If the security protocol fails to complete within the Timeout period, the function\r | |
173 | shall return EFI_TIMEOUT.\r | |
174 | \r | |
175 | If the security protocol command completes without an error, the function shall\r | |
176 | return EFI_SUCCESS. If the security protocol command completes with an error, the\r | |
177 | function shall return EFI_DEVICE_ERROR.\r | |
178 | \r | |
179 | @param[in] This The PPI instance pointer.\r | |
180 | @param[in] DeviceIndex Specifies the storage security device to which the\r | |
181 | function wants to talk. Because the driver that\r | |
182 | implements Storage Security Command PPIs will manage\r | |
183 | multiple storage devices, the PPIs that want to talk\r | |
184 | to a single device must specify the device index\r | |
185 | that was assigned during the enumeration process.\r | |
186 | This index is a number from one to NumberofDevices.\r | |
187 | @param[in] Timeout The timeout, in 100ns units, to use for the execution\r | |
188 | of the security protocol command. A Timeout value\r | |
189 | of 0 means that this function will wait indefinitely\r | |
190 | for the security protocol command to execute. If\r | |
191 | Timeout is greater than zero, then this function\r | |
192 | will return EFI_TIMEOUT if the time required to\r | |
193 | execute the receive data command is greater than\r | |
194 | Timeout.\r | |
195 | @param[in] SecurityProtocolId\r | |
196 | The value of the "Security Protocol" parameter of\r | |
197 | the security protocol command to be sent.\r | |
198 | @param[in] SecurityProtocolSpecificData\r | |
199 | The value of the "Security Protocol Specific"\r | |
200 | parameter of the security protocol command to be\r | |
201 | sent.\r | |
202 | @param[in] PayloadBufferSize\r | |
203 | Size in bytes of the payload data buffer.\r | |
204 | @param[out] PayloadBuffer A pointer to a destination buffer to store the\r | |
205 | security protocol command specific payload data\r | |
206 | for the security protocol command. The caller is\r | |
207 | responsible for having either implicit or explicit\r | |
208 | ownership of the buffer.\r | |
209 | @param[out] PayloadTransferSize\r | |
210 | A pointer to a buffer to store the size in bytes\r | |
211 | of the data written to the payload data buffer.\r | |
212 | \r | |
213 | @retval EFI_SUCCESS The security protocol command completed\r | |
214 | successfully.\r | |
215 | @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to\r | |
216 | store the available data from the device.\r | |
217 | The PayloadBuffer contains the truncated\r | |
218 | data.\r | |
219 | @retval EFI_UNSUPPORTED The given DeviceIndex does not support\r | |
220 | security protocol commands.\r | |
221 | @retval EFI_DEVICE_ERROR The security protocol command completed\r | |
222 | with an error.\r | |
223 | @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize\r | |
224 | is NULL and PayloadBufferSize is non-zero.\r | |
225 | @retval EFI_TIMEOUT A timeout occurred while waiting for the\r | |
226 | security protocol command to execute.\r | |
227 | \r | |
228 | **/\r | |
229 | EFI_STATUS\r | |
230 | EFIAPI\r | |
231 | AhciStorageSecurityReceiveData (\r | |
232 | IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This,\r | |
233 | IN UINTN DeviceIndex,\r | |
234 | IN UINT64 Timeout,\r | |
235 | IN UINT8 SecurityProtocolId,\r | |
236 | IN UINT16 SecurityProtocolSpecificData,\r | |
237 | IN UINTN PayloadBufferSize,\r | |
238 | OUT VOID *PayloadBuffer,\r | |
239 | OUT UINTN *PayloadTransferSize\r | |
240 | )\r | |
241 | {\r | |
242 | PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;\r | |
243 | PEI_AHCI_ATA_DEVICE_DATA *DeviceData;\r | |
244 | \r | |
245 | if ((PayloadBuffer == NULL) || (PayloadTransferSize == NULL) || (PayloadBufferSize == 0)) {\r | |
246 | return EFI_INVALID_PARAMETER;\r | |
247 | }\r | |
248 | \r | |
249 | Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY (This);\r | |
250 | if ((DeviceIndex == 0) || (DeviceIndex > Private->TrustComputingDevices)) {\r | |
251 | return EFI_INVALID_PARAMETER;\r | |
252 | }\r | |
253 | \r | |
254 | DeviceData = SearchTrustComputingDeviceByIndex (Private, DeviceIndex);\r | |
255 | if (DeviceData == NULL) {\r | |
256 | return EFI_NOT_FOUND;\r | |
257 | }\r | |
258 | \r | |
259 | ASSERT ((DeviceData->IdentifyData->trusted_computing_support & BIT0) != 0);\r | |
260 | if ((DeviceData->IdentifyData->trusted_computing_support & BIT0) == 0) {\r | |
261 | return EFI_UNSUPPORTED;\r | |
262 | }\r | |
263 | \r | |
264 | return TrustTransferAtaDevice (\r | |
265 | DeviceData,\r | |
266 | PayloadBuffer,\r | |
267 | SecurityProtocolId,\r | |
268 | SecurityProtocolSpecificData,\r | |
269 | PayloadBufferSize,\r | |
270 | FALSE,\r | |
271 | Timeout,\r | |
272 | PayloadTransferSize\r | |
273 | );\r | |
274 | }\r | |
275 | \r | |
276 | /**\r | |
277 | Send a security protocol command to a device.\r | |
278 | \r | |
279 | The SendData function sends a security protocol command containing the payload\r | |
280 | PayloadBuffer to the given DeviceIndex. The security protocol command sent is\r | |
281 | defined by SecurityProtocolId and contains the security protocol specific data\r | |
282 | SecurityProtocolSpecificData. If the underlying protocol command requires a\r | |
283 | specific padding for the command payload, the SendData function shall add padding\r | |
284 | bytes to the command payload to satisfy the padding requirements.\r | |
285 | \r | |
286 | For devices supporting the SCSI command set, the security protocol command is\r | |
287 | sent using the SECURITY PROTOCOL OUT command defined in SPC-4.\r | |
288 | \r | |
289 | For devices supporting the ATA command set, the security protocol command is\r | |
290 | sent using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize\r | |
291 | is non-zero. If the PayloadBufferSize is zero, the security protocol command\r | |
292 | is sent using the Trusted Non-Data command defined in ATA8-ACS.\r | |
293 | \r | |
294 | If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall\r | |
295 | return EFI_INVALID_PARAMETER.\r | |
296 | \r | |
297 | If the given DeviceIndex does not support security protocol commands, the function\r | |
298 | shall return EFI_UNSUPPORTED.\r | |
299 | \r | |
300 | If the security protocol fails to complete within the Timeout period, the function\r | |
301 | shall return EFI_TIMEOUT.\r | |
302 | \r | |
303 | If the security protocol command completes without an error, the function shall\r | |
304 | return EFI_SUCCESS. If the security protocol command completes with an error,\r | |
305 | the functio shall return EFI_DEVICE_ERROR.\r | |
306 | \r | |
307 | @param[in] This The PPI instance pointer.\r | |
308 | @param[in] DeviceIndex The ID of the device.\r | |
309 | @param[in] Timeout The timeout, in 100ns units, to use for the execution\r | |
310 | of the security protocol command. A Timeout value\r | |
311 | of 0 means that this function will wait indefinitely\r | |
312 | for the security protocol command to execute. If\r | |
313 | Timeout is greater than zero, then this function\r | |
314 | will return EFI_TIMEOUT if the time required to\r | |
315 | execute the receive data command is greater than\r | |
316 | Timeout.\r | |
317 | @param[in] SecurityProtocolId\r | |
318 | The value of the "Security Protocol" parameter of\r | |
319 | the security protocol command to be sent.\r | |
320 | @param[in] SecurityProtocolSpecificData\r | |
321 | The value of the "Security Protocol Specific"\r | |
322 | parameter of the security protocol command to be\r | |
323 | sent.\r | |
324 | @param[in] PayloadBufferSize Size in bytes of the payload data buffer.\r | |
325 | @param[in] PayloadBuffer A pointer to a destination buffer to store the\r | |
326 | security protocol command specific payload data\r | |
327 | for the security protocol command.\r | |
328 | \r | |
329 | @retval EFI_SUCCESS The security protocol command completed successfully.\r | |
330 | @retval EFI_UNSUPPORTED The given DeviceIndex does not support security\r | |
331 | protocol commands.\r | |
332 | @retval EFI_DEVICE_ERROR The security protocol command completed with\r | |
333 | an error.\r | |
334 | @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize\r | |
335 | is non-zero.\r | |
336 | @retval EFI_TIMEOUT A timeout occurred while waiting for the security\r | |
337 | protocol command to execute.\r | |
338 | \r | |
339 | **/\r | |
340 | EFI_STATUS\r | |
341 | EFIAPI\r | |
342 | AhciStorageSecuritySendData (\r | |
343 | IN EDKII_PEI_STORAGE_SECURITY_CMD_PPI *This,\r | |
344 | IN UINTN DeviceIndex,\r | |
345 | IN UINT64 Timeout,\r | |
346 | IN UINT8 SecurityProtocolId,\r | |
347 | IN UINT16 SecurityProtocolSpecificData,\r | |
348 | IN UINTN PayloadBufferSize,\r | |
349 | IN VOID *PayloadBuffer\r | |
350 | )\r | |
351 | {\r | |
352 | PEI_AHCI_CONTROLLER_PRIVATE_DATA *Private;\r | |
353 | PEI_AHCI_ATA_DEVICE_DATA *DeviceData;\r | |
354 | \r | |
355 | if ((PayloadBuffer == NULL) && (PayloadBufferSize != 0)) {\r | |
356 | return EFI_INVALID_PARAMETER;\r | |
357 | }\r | |
358 | \r | |
359 | Private = GET_AHCI_PEIM_HC_PRIVATE_DATA_FROM_THIS_STROAGE_SECURITY (This);\r | |
360 | if ((DeviceIndex == 0) || (DeviceIndex > Private->TrustComputingDevices)) {\r | |
361 | return EFI_INVALID_PARAMETER;\r | |
362 | }\r | |
363 | \r | |
364 | DeviceData = SearchTrustComputingDeviceByIndex (Private, DeviceIndex);\r | |
365 | if (DeviceData == NULL) {\r | |
366 | return EFI_NOT_FOUND;\r | |
367 | }\r | |
368 | \r | |
369 | ASSERT ((DeviceData->IdentifyData->trusted_computing_support & BIT0) != 0);\r | |
370 | if ((DeviceData->IdentifyData->trusted_computing_support & BIT0) == 0) {\r | |
371 | return EFI_UNSUPPORTED;\r | |
372 | }\r | |
373 | \r | |
374 | return TrustTransferAtaDevice (\r | |
375 | DeviceData,\r | |
376 | PayloadBuffer,\r | |
377 | SecurityProtocolId,\r | |
378 | SecurityProtocolSpecificData,\r | |
379 | PayloadBufferSize,\r | |
380 | TRUE,\r | |
381 | Timeout,\r | |
382 | NULL\r | |
383 | );\r | |
384 | }\r |