]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c
Add missing status code in several modules.
[mirror_edk2.git] / MdeModulePkg / Bus / Ata / AtaBusDxe / AtaBus.c
1 /** @file
2 This file implements protocol interfaces for ATA bus driver.
3
4 This file implements protocol interfaces: Driver Binding protocol,
5 Block IO protocol and DiskInfo protocol.
6
7 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16
17 **/
18
19 #include "AtaBus.h"
20
21 UINT8 mMorControl;
22
23 //
24 // ATA Bus Driver Binding Protocol Instance
25 //
26 EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding = {
27 AtaBusDriverBindingSupported,
28 AtaBusDriverBindingStart,
29 AtaBusDriverBindingStop,
30 0x10,
31 NULL,
32 NULL
33 };
34
35 //
36 // Template for ATA Child Device.
37 //
38 ATA_DEVICE gAtaDeviceTemplate = {
39 ATA_DEVICE_SIGNATURE, // Signature
40 NULL, // Handle
41 { // BlockIo
42 EFI_BLOCK_IO_PROTOCOL_REVISION,
43 NULL,
44 AtaBlockIoReset,
45 AtaBlockIoReadBlocks,
46 AtaBlockIoWriteBlocks,
47 AtaBlockIoFlushBlocks
48 },
49 { // BlockIo2
50 NULL,
51 AtaBlockIoResetEx,
52 AtaBlockIoReadBlocksEx,
53 AtaBlockIoWriteBlocksEx,
54 AtaBlockIoFlushBlocksEx
55 },
56 { // BlockMedia
57 0, // MediaId
58 FALSE, // RemovableMedia
59 TRUE, // MediaPresent
60 FALSE, // LogicPartition
61 FALSE, // ReadOnly
62 FALSE, // WritingCache
63 0x200, // BlockSize
64 0, // IoAlign
65 0, // LastBlock
66 0, // LowestAlignedLba
67 1 // LogicalBlocksPerPhysicalBlock
68 },
69 { // DiskInfo
70 EFI_DISK_INFO_IDE_INTERFACE_GUID,
71 AtaDiskInfoInquiry,
72 AtaDiskInfoIdentify,
73 AtaDiskInfoSenseData,
74 AtaDiskInfoWhichIde
75 },
76 NULL, // DevicePath
77 {
78 AtaStorageSecurityReceiveData,
79 AtaStorageSecuritySendData
80 },
81 NULL, // AtaBusDriverData
82 0, // Port
83 0, // PortMultiplierPort
84 { 0, }, // Packet
85 {{ 0}, }, // Acb
86 NULL, // Asb
87 FALSE, // UdmaValid
88 FALSE, // Lba48Bit
89 NULL, // IdentifyData
90 NULL, // ControllerNameTable
91 {L'\0', }, // ModelName
92 {NULL, NULL}, // AtaTaskList
93 {NULL, NULL} // AtaSubTaskList
94 };
95
96 /**
97 Allocates an aligned buffer for ATA device.
98
99 This function allocates an aligned buffer for the ATA device to perform
100 ATA pass through operations. The alignment requirement is from ATA pass
101 through interface.
102
103 @param AtaDevice The ATA child device involved for the operation.
104 @param BufferSize The request buffer size.
105
106 @return A pointer to the aligned buffer or NULL if the allocation fails.
107
108 **/
109 VOID *
110 AllocateAlignedBuffer (
111 IN ATA_DEVICE *AtaDevice,
112 IN UINTN BufferSize
113 )
114 {
115 return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), AtaDevice->AtaBusDriverData->AtaPassThru->Mode->IoAlign);
116 }
117
118 /**
119 Frees an aligned buffer for ATA device.
120
121 This function frees an aligned buffer for the ATA device to perform
122 ATA pass through operations.
123
124 @param Buffer The aligned buffer to be freed.
125 @param BufferSize The request buffer size.
126
127 **/
128 VOID
129 FreeAlignedBuffer (
130 IN VOID *Buffer,
131 IN UINTN BufferSize
132 )
133 {
134 if (Buffer != NULL) {
135 FreeAlignedPages (Buffer, EFI_SIZE_TO_PAGES (BufferSize));
136 }
137 }
138
139
140 /**
141 Release all the resources allocated for the ATA device.
142
143 This function releases all the resources allocated for the ATA device.
144
145 @param AtaDevice The ATA child device involved for the operation.
146
147 **/
148 VOID
149 ReleaseAtaResources (
150 IN ATA_DEVICE *AtaDevice
151 )
152 {
153 ATA_BUS_ASYN_SUB_TASK *SubTask;
154 ATA_BUS_ASYN_TASK *AtaTask;
155 LIST_ENTRY *Entry;
156 LIST_ENTRY *DelEntry;
157 EFI_TPL OldTpl;
158
159 FreeUnicodeStringTable (AtaDevice->ControllerNameTable);
160 FreeAlignedBuffer (AtaDevice->Asb, sizeof (EFI_ATA_STATUS_BLOCK));
161 FreeAlignedBuffer (AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));
162 if (AtaDevice->DevicePath != NULL) {
163 FreePool (AtaDevice->DevicePath);
164 }
165 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
166 if (!IsListEmpty (&AtaDevice->AtaSubTaskList)) {
167 //
168 // Free the Subtask list.
169 //
170 for(Entry = AtaDevice->AtaSubTaskList.ForwardLink;
171 Entry != (&AtaDevice->AtaSubTaskList);
172 ) {
173 DelEntry = Entry;
174 Entry = Entry->ForwardLink;
175 SubTask = ATA_AYNS_SUB_TASK_FROM_ENTRY (DelEntry);
176
177 RemoveEntryList (DelEntry);
178 FreeAtaSubTask (SubTask);
179 }
180 }
181 if (!IsListEmpty (&AtaDevice->AtaTaskList)) {
182 //
183 // Free the Subtask list.
184 //
185 for(Entry = AtaDevice->AtaTaskList.ForwardLink;
186 Entry != (&AtaDevice->AtaTaskList);
187 ) {
188 DelEntry = Entry;
189 Entry = Entry->ForwardLink;
190 AtaTask = ATA_AYNS_TASK_FROM_ENTRY (DelEntry);
191
192 RemoveEntryList (DelEntry);
193 FreePool (AtaTask);
194 }
195 }
196 gBS->RestoreTPL (OldTpl);
197 FreePool (AtaDevice);
198 }
199
200
201 /**
202 Registers an ATA device.
203
204 This function allocates an ATA device structure for the ATA device specified by
205 Port and PortMultiplierPort if the ATA device is identified as a valid one.
206 Then it will create child handle and install Block IO and Disk Info protocol on
207 it.
208
209 @param AtaBusDriverData The parent ATA bus driver data structure.
210 @param Port The port number of the ATA device.
211 @param PortMultiplierPort The port multiplier port number of the ATA device.
212
213 @retval EFI_SUCCESS The ATA device is successfully registered.
214 @retval EFI_OUT_OF_RESOURCES There is not enough memory to allocate the ATA device
215 and related data structures.
216 @return Others Some error occurs when registering the ATA device.
217 **/
218 EFI_STATUS
219 RegisterAtaDevice (
220 IN OUT ATA_BUS_DRIVER_DATA *AtaBusDriverData,
221 IN UINT16 Port,
222 IN UINT16 PortMultiplierPort
223 )
224 {
225 EFI_STATUS Status;
226 ATA_DEVICE *AtaDevice;
227 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
228 EFI_DEVICE_PATH_PROTOCOL *NewDevicePathNode;
229 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
230 EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
231 EFI_HANDLE DeviceHandle;
232
233 AtaDevice = NULL;
234 NewDevicePathNode = NULL;
235 DevicePath = NULL;
236 RemainingDevicePath = NULL;
237
238 //
239 // Build device path
240 //
241 AtaPassThru = AtaBusDriverData->AtaPassThru;
242 Status = AtaPassThru->BuildDevicePath (AtaPassThru, Port, PortMultiplierPort, &NewDevicePathNode);
243 if (EFI_ERROR (Status)) {
244 goto Done;
245 }
246
247 DevicePath = AppendDevicePathNode (AtaBusDriverData->ParentDevicePath, NewDevicePathNode);
248 if (DevicePath == NULL) {
249 Status = EFI_OUT_OF_RESOURCES;
250 goto Done;
251 }
252
253 DeviceHandle = NULL;
254 RemainingDevicePath = DevicePath;
255 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &DeviceHandle);
256 if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd(RemainingDevicePath)) {
257 Status = EFI_ALREADY_STARTED;
258 FreePool (DevicePath);
259 goto Done;
260 }
261
262 //
263 // Allocate ATA device from the template.
264 //
265 AtaDevice = AllocateCopyPool (sizeof (ATA_DEVICE), &gAtaDeviceTemplate);
266 if (AtaDevice == NULL) {
267 Status = EFI_OUT_OF_RESOURCES;
268 goto Done;
269 }
270
271 //
272 // Initializes ATA device structures and allocates the required buffer.
273 //
274 AtaDevice->BlockIo.Media = &AtaDevice->BlockMedia;
275 AtaDevice->BlockIo2.Media = &AtaDevice->BlockMedia;
276 AtaDevice->AtaBusDriverData = AtaBusDriverData;
277 AtaDevice->DevicePath = DevicePath;
278 AtaDevice->Port = Port;
279 AtaDevice->PortMultiplierPort = PortMultiplierPort;
280 AtaDevice->Asb = AllocateAlignedBuffer (AtaDevice, sizeof (EFI_ATA_STATUS_BLOCK));
281 if (AtaDevice->Asb == NULL) {
282 Status = EFI_OUT_OF_RESOURCES;
283 goto Done;
284 }
285 AtaDevice->IdentifyData = AllocateAlignedBuffer (AtaDevice, sizeof (ATA_IDENTIFY_DATA));
286 if (AtaDevice->IdentifyData == NULL) {
287 Status = EFI_OUT_OF_RESOURCES;
288 goto Done;
289 }
290
291 //
292 // Initial Ata Task List
293 //
294 InitializeListHead (&AtaDevice->AtaTaskList);
295 InitializeListHead (&AtaDevice->AtaSubTaskList);
296
297 //
298 // Report Status Code to indicate the ATA device will be enabled
299 //
300 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
301 EFI_PROGRESS_CODE,
302 (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_ENABLE),
303 AtaBusDriverData->ParentDevicePath
304 );
305
306 //
307 // Try to identify the ATA device via the ATA pass through command.
308 //
309 Status = DiscoverAtaDevice (AtaDevice);
310 if (EFI_ERROR (Status)) {
311 goto Done;
312 }
313
314 //
315 // Build controller name for Component Name (2) protocol.
316 //
317 Status = AddUnicodeString2 (
318 "eng",
319 gAtaBusComponentName.SupportedLanguages,
320 &AtaDevice->ControllerNameTable,
321 AtaDevice->ModelName,
322 TRUE
323 );
324 if (EFI_ERROR (Status)) {
325 goto Done;
326 }
327
328 Status = AddUnicodeString2 (
329 "en",
330 gAtaBusComponentName2.SupportedLanguages,
331 &AtaDevice->ControllerNameTable,
332 AtaDevice->ModelName,
333 FALSE
334 );
335 if (EFI_ERROR (Status)) {
336 goto Done;
337 }
338
339 //
340 // Update to AHCI interface GUID based on device path node. The default one
341 // is IDE interface GUID copied from template.
342 //
343 if (NewDevicePathNode->SubType == MSG_SATA_DP) {
344 CopyGuid (&AtaDevice->DiskInfo.Interface, &gEfiDiskInfoAhciInterfaceGuid);
345 }
346
347 Status = gBS->InstallMultipleProtocolInterfaces (
348 &AtaDevice->Handle,
349 &gEfiDevicePathProtocolGuid,
350 AtaDevice->DevicePath,
351 &gEfiBlockIoProtocolGuid,
352 &AtaDevice->BlockIo,
353 &gEfiBlockIo2ProtocolGuid,
354 &AtaDevice->BlockIo2,
355 &gEfiDiskInfoProtocolGuid,
356 &AtaDevice->DiskInfo,
357 NULL
358 );
359 if (EFI_ERROR (Status)) {
360 goto Done;
361 }
362
363 //
364 // See if the ata device support trust computing feature or not.
365 // If yes, then install Storage Security Protocol at the ata device handle.
366 //
367 if ((AtaDevice->IdentifyData->trusted_computing_support & BIT0) != 0) {
368 DEBUG ((EFI_D_INFO, "Found TCG support in Port %x PortMultiplierPort %x\n", Port, PortMultiplierPort));
369 Status = gBS->InstallProtocolInterface (
370 &AtaDevice->Handle,
371 &gEfiStorageSecurityCommandProtocolGuid,
372 EFI_NATIVE_INTERFACE,
373 &AtaDevice->StorageSecurity
374 );
375 if (EFI_ERROR (Status)) {
376 goto Done;
377 }
378 DEBUG ((EFI_D_INFO, "Successfully Install Storage Security Protocol on the ATA device\n"));
379 }
380
381
382 if (((mMorControl & 0x01) == 0x01) && ((AtaDevice->IdentifyData->trusted_computing_support & BIT0) != 0)) {
383 DEBUG ((EFI_D_INFO,
384 "mMorControl = %x, AtaDevice->IdentifyData->trusted_computing_support & BIT0 = %x\n",
385 mMorControl,
386 (AtaDevice->IdentifyData->trusted_computing_support & BIT0)
387 ));
388 DEBUG ((EFI_D_INFO, "Try to lock device by sending TPer Reset command...\n"));
389 InitiateTPerReset(AtaDevice);
390 }
391
392 gBS->OpenProtocol (
393 AtaBusDriverData->Controller,
394 &gEfiAtaPassThruProtocolGuid,
395 (VOID **) &AtaPassThru,
396 AtaBusDriverData->DriverBindingHandle,
397 AtaDevice->Handle,
398 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
399 );
400
401 Done:
402 if (NewDevicePathNode != NULL) {
403 FreePool (NewDevicePathNode);
404 }
405
406 if (EFI_ERROR (Status) && (AtaDevice != NULL)) {
407 ReleaseAtaResources (AtaDevice);
408 DEBUG ((EFI_D_ERROR | EFI_D_INIT, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port, PortMultiplierPort, Status));
409 }
410 return Status;
411 }
412
413
414 /**
415 Unregisters an ATA device.
416
417 This function removes the protocols installed on the controller handle and
418 frees the resources allocated for the ATA device.
419
420 @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.
421 @param Controller The controller handle of the ATA device.
422 @param Handle The child handle.
423
424 @retval EFI_SUCCESS The ATA device is successfully unregistered.
425 @return Others Some error occurs when unregistering the ATA device.
426
427 **/
428 EFI_STATUS
429 UnregisterAtaDevice (
430 IN EFI_DRIVER_BINDING_PROTOCOL *This,
431 IN EFI_HANDLE Controller,
432 IN EFI_HANDLE Handle
433 )
434 {
435 EFI_STATUS Status;
436 EFI_BLOCK_IO_PROTOCOL *BlockIo;
437 EFI_BLOCK_IO2_PROTOCOL *BlockIo2;
438 ATA_DEVICE *AtaDevice;
439 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
440 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *StorageSecurity;
441
442 BlockIo2 = NULL;
443 BlockIo = NULL;
444
445 Status = gBS->OpenProtocol (
446 Handle,
447 &gEfiBlockIoProtocolGuid,
448 (VOID **) &BlockIo,
449 This->DriverBindingHandle,
450 Controller,
451 EFI_OPEN_PROTOCOL_GET_PROTOCOL
452 );
453 if (EFI_ERROR (Status)) {
454 //
455 // Locate BlockIo2 protocol
456 //
457 Status = gBS->OpenProtocol (
458 Handle,
459 &gEfiBlockIo2ProtocolGuid,
460 (VOID **) &BlockIo2,
461 This->DriverBindingHandle,
462 Controller,
463 EFI_OPEN_PROTOCOL_GET_PROTOCOL
464 );
465 if (EFI_ERROR (Status)) {
466 return Status;
467 }
468 }
469
470 //
471 // Get AtaDevice data.
472 //
473 if (BlockIo != NULL) {
474 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (BlockIo);
475 } else {
476 ASSERT (BlockIo2 != NULL);
477 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2);
478 }
479
480 //
481 // Close the child handle
482 //
483 gBS->CloseProtocol (
484 Controller,
485 &gEfiAtaPassThruProtocolGuid,
486 This->DriverBindingHandle,
487 Handle
488 );
489
490 //
491 // The Ata Bus driver installs the BlockIo and BlockIo2 in the DriverBindingStart().
492 // Here should uninstall both of them.
493 //
494 Status = gBS->UninstallMultipleProtocolInterfaces (
495 Handle,
496 &gEfiDevicePathProtocolGuid,
497 AtaDevice->DevicePath,
498 &gEfiBlockIoProtocolGuid,
499 &AtaDevice->BlockIo,
500 &gEfiBlockIo2ProtocolGuid,
501 &AtaDevice->BlockIo2,
502 &gEfiDiskInfoProtocolGuid,
503 &AtaDevice->DiskInfo,
504 NULL
505 );
506
507 if (EFI_ERROR (Status)) {
508 gBS->OpenProtocol (
509 Controller,
510 &gEfiAtaPassThruProtocolGuid,
511 (VOID **) &AtaPassThru,
512 This->DriverBindingHandle,
513 Handle,
514 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
515 );
516 return Status;
517 }
518
519 //
520 // If Storage Security Command Protocol is installed, then uninstall this protocol.
521 //
522 Status = gBS->OpenProtocol (
523 Handle,
524 &gEfiStorageSecurityCommandProtocolGuid,
525 (VOID **) &StorageSecurity,
526 This->DriverBindingHandle,
527 Controller,
528 EFI_OPEN_PROTOCOL_GET_PROTOCOL
529 );
530
531 if (!EFI_ERROR (Status)) {
532 Status = gBS->UninstallProtocolInterface (
533 Handle,
534 &gEfiStorageSecurityCommandProtocolGuid,
535 &AtaDevice->StorageSecurity
536 );
537 if (EFI_ERROR (Status)) {
538 gBS->OpenProtocol (
539 Controller,
540 &gEfiAtaPassThruProtocolGuid,
541 (VOID **) &AtaPassThru,
542 This->DriverBindingHandle,
543 Handle,
544 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
545 );
546 return Status;
547 }
548 }
549
550 ReleaseAtaResources (AtaDevice);
551 return EFI_SUCCESS;
552 }
553
554
555
556 /**
557 Tests to see if this driver supports a given controller. If a child device is provided,
558 it further tests to see if this driver supports creating a handle for the specified child device.
559
560 This function checks to see if the driver specified by This supports the device specified by
561 ControllerHandle. Drivers will typically use the device path attached to
562 ControllerHandle and/or the services from the bus I/O abstraction attached to
563 ControllerHandle to determine if the driver supports ControllerHandle. This function
564 may be called many times during platform initialization. In order to reduce boot times, the tests
565 performed by this function must be very small, and take as little time as possible to execute. This
566 function must not change the state of any hardware devices, and this function must be aware that the
567 device specified by ControllerHandle may already be managed by the same driver or a
568 different driver. This function must match its calls to AllocatePages() with FreePages(),
569 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
570 Since ControllerHandle may have been previously started by the same driver, if a protocol is
571 already in the opened state, then it must not be closed with CloseProtocol(). This is required
572 to guarantee the state of ControllerHandle is not modified by this function.
573
574 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
575 @param[in] ControllerHandle The handle of the controller to test. This handle
576 must support a protocol interface that supplies
577 an I/O abstraction to the driver.
578 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
579 parameter is ignored by device drivers, and is optional for bus
580 drivers. For bus drivers, if this parameter is not NULL, then
581 the bus driver must determine if the bus controller specified
582 by ControllerHandle and the child controller specified
583 by RemainingDevicePath are both supported by this
584 bus driver.
585
586 @retval EFI_SUCCESS The device specified by ControllerHandle and
587 RemainingDevicePath is supported by the driver specified by This.
588 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
589 RemainingDevicePath is already being managed by the driver
590 specified by This.
591 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
592 RemainingDevicePath is already being managed by a different
593 driver or an application that requires exclusive access.
594 Currently not implemented.
595 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
596 RemainingDevicePath is not supported by the driver specified by This.
597 **/
598 EFI_STATUS
599 EFIAPI
600 AtaBusDriverBindingSupported (
601 IN EFI_DRIVER_BINDING_PROTOCOL *This,
602 IN EFI_HANDLE Controller,
603 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
604 )
605 {
606 EFI_STATUS Status;
607 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
608 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
609 UINT16 Port;
610 UINT16 PortMultiplierPort;
611
612 //
613 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
614 //
615 Status = gBS->OpenProtocol (
616 Controller,
617 &gEfiAtaPassThruProtocolGuid,
618 (VOID **) &AtaPassThru,
619 This->DriverBindingHandle,
620 Controller,
621 EFI_OPEN_PROTOCOL_BY_DRIVER
622 );
623
624 if (Status == EFI_ALREADY_STARTED) {
625 return EFI_SUCCESS;
626 }
627
628 if (EFI_ERROR (Status)) {
629 return Status;
630 }
631
632 //
633 // Test RemainingDevicePath is valid or not.
634 //
635 if ((RemainingDevicePath != NULL) && !IsDevicePathEnd (RemainingDevicePath)) {
636 Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort);
637 if (EFI_ERROR (Status)) {
638 return Status;
639 }
640 }
641
642 //
643 // Close the I/O Abstraction(s) used to perform the supported test
644 //
645 gBS->CloseProtocol (
646 Controller,
647 &gEfiAtaPassThruProtocolGuid,
648 This->DriverBindingHandle,
649 Controller
650 );
651
652 //
653 // Open the EFI Device Path protocol needed to perform the supported test
654 //
655 Status = gBS->OpenProtocol (
656 Controller,
657 &gEfiDevicePathProtocolGuid,
658 (VOID **) &ParentDevicePath,
659 This->DriverBindingHandle,
660 Controller,
661 EFI_OPEN_PROTOCOL_GET_PROTOCOL
662 );
663 return Status;
664 }
665
666
667 /**
668 Starts a device controller or a bus controller.
669
670 The Start() function is designed to be invoked from the EFI boot service ConnectController().
671 As a result, much of the error checking on the parameters to Start() has been moved into this
672 common boot service. It is legal to call Start() from other locations,
673 but the following calling restrictions must be followed or the system behavior will not be deterministic.
674 1. ControllerHandle must be a valid EFI_HANDLE.
675 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
676 EFI_DEVICE_PATH_PROTOCOL.
677 3. Prior to calling Start(), the Supported() function for the driver specified by This must
678 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
679
680 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
681 @param[in] ControllerHandle The handle of the controller to start. This handle
682 must support a protocol interface that supplies
683 an I/O abstraction to the driver.
684 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
685 parameter is ignored by device drivers, and is optional for bus
686 drivers. For a bus driver, if this parameter is NULL, then handles
687 for all the children of Controller are created by this driver.
688 If this parameter is not NULL and the first Device Path Node is
689 not the End of Device Path Node, then only the handle for the
690 child device specified by the first Device Path Node of
691 RemainingDevicePath is created by this driver.
692 If the first Device Path Node of RemainingDevicePath is
693 the End of Device Path Node, no child handle is created by this
694 driver.
695
696 @retval EFI_SUCCESS The device was started.
697 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
698 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
699 @retval Others The driver failded to start the device.
700
701 **/
702 EFI_STATUS
703 EFIAPI
704 AtaBusDriverBindingStart (
705 IN EFI_DRIVER_BINDING_PROTOCOL *This,
706 IN EFI_HANDLE Controller,
707 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
708 )
709 {
710 EFI_STATUS Status;
711 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
712 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
713 ATA_BUS_DRIVER_DATA *AtaBusDriverData;
714 UINT16 Port;
715 UINT16 PortMultiplierPort;
716
717 AtaBusDriverData = NULL;
718
719 Status = gBS->OpenProtocol (
720 Controller,
721 &gEfiDevicePathProtocolGuid,
722 (VOID **) &ParentDevicePath,
723 This->DriverBindingHandle,
724 Controller,
725 EFI_OPEN_PROTOCOL_GET_PROTOCOL
726 );
727 if (EFI_ERROR (Status)) {
728 return Status;
729 }
730
731 //
732 // Report Status Code to indicate ATA bus starts
733 //
734 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
735 EFI_PROGRESS_CODE,
736 (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_INIT),
737 ParentDevicePath
738 );
739
740 Status = gBS->OpenProtocol (
741 Controller,
742 &gEfiAtaPassThruProtocolGuid,
743 (VOID **) &AtaPassThru,
744 This->DriverBindingHandle,
745 Controller,
746 EFI_OPEN_PROTOCOL_BY_DRIVER
747 );
748 if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {
749 goto ErrorExit;
750 }
751
752 //
753 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
754 //
755 if (Status != EFI_ALREADY_STARTED) {
756 AtaBusDriverData = AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA));
757 if (AtaBusDriverData == NULL) {
758 Status = EFI_OUT_OF_RESOURCES;
759 goto ErrorExit;
760 }
761
762 AtaBusDriverData->AtaPassThru = AtaPassThru;
763 AtaBusDriverData->Controller = Controller;
764 AtaBusDriverData->ParentDevicePath = ParentDevicePath;
765 AtaBusDriverData->DriverBindingHandle = This->DriverBindingHandle;
766
767 Status = gBS->InstallMultipleProtocolInterfaces (
768 &Controller,
769 &gEfiCallerIdGuid,
770 AtaBusDriverData,
771 NULL
772 );
773 if (EFI_ERROR (Status)) {
774 goto ErrorExit;
775 }
776
777 } else {
778 Status = gBS->OpenProtocol (
779 Controller,
780 &gEfiCallerIdGuid,
781 (VOID **) &AtaBusDriverData,
782 This->DriverBindingHandle,
783 Controller,
784 EFI_OPEN_PROTOCOL_GET_PROTOCOL
785 );
786 if (EFI_ERROR (Status)) {
787 AtaBusDriverData = NULL;
788 goto ErrorExit;
789 }
790 }
791
792 //
793 // Report Status Code to indicate detecting devices on bus
794 //
795 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
796 EFI_PROGRESS_CODE,
797 (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_DETECT),
798 ParentDevicePath
799 );
800
801 if (RemainingDevicePath == NULL) {
802 Port = 0xFFFF;
803 while (TRUE) {
804 Status = AtaPassThru->GetNextPort (AtaPassThru, &Port);
805 if (EFI_ERROR (Status)) {
806 //
807 // We cannot find more legal port then we are done.
808 //
809 break;
810 }
811
812 PortMultiplierPort = 0xFFFF;
813 while (TRUE) {
814 Status = AtaPassThru->GetNextDevice (AtaPassThru, Port, &PortMultiplierPort);
815 if (EFI_ERROR (Status)) {
816 //
817 // We cannot find more legal port multiplier port number for ATA device
818 // on the port, then we are done.
819 //
820 break;
821 }
822 RegisterAtaDevice (AtaBusDriverData, Port, PortMultiplierPort);
823 }
824 }
825 Status = EFI_SUCCESS;
826 } else if (!IsDevicePathEnd (RemainingDevicePath)) {
827 Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort);
828 if (!EFI_ERROR (Status)) {
829 Status = RegisterAtaDevice (AtaBusDriverData,Port, PortMultiplierPort);
830 }
831 }
832
833 return Status;
834
835 ErrorExit:
836
837 if (AtaBusDriverData != NULL) {
838 gBS->UninstallMultipleProtocolInterfaces (
839 Controller,
840 &gEfiCallerIdGuid,
841 AtaBusDriverData,
842 NULL
843 );
844 FreePool (AtaBusDriverData);
845 }
846
847 gBS->CloseProtocol (
848 Controller,
849 &gEfiAtaPassThruProtocolGuid,
850 This->DriverBindingHandle,
851 Controller
852 );
853
854 return Status;
855
856 }
857
858
859 /**
860 Stops a device controller or a bus controller.
861
862 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
863 As a result, much of the error checking on the parameters to Stop() has been moved
864 into this common boot service. It is legal to call Stop() from other locations,
865 but the following calling restrictions must be followed or the system behavior will not be deterministic.
866 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
867 same driver's Start() function.
868 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
869 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
870 Start() function, and the Start() function must have called OpenProtocol() on
871 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
872
873 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
874 @param[in] ControllerHandle A handle to the device being stopped. The handle must
875 support a bus specific I/O protocol for the driver
876 to use to stop the device.
877 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
878 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
879 if NumberOfChildren is 0.
880
881 @retval EFI_SUCCESS The device was stopped.
882 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
883
884 **/
885 EFI_STATUS
886 EFIAPI
887 AtaBusDriverBindingStop (
888 IN EFI_DRIVER_BINDING_PROTOCOL *This,
889 IN EFI_HANDLE Controller,
890 IN UINTN NumberOfChildren,
891 IN EFI_HANDLE *ChildHandleBuffer
892 )
893 {
894 EFI_STATUS Status;
895 BOOLEAN AllChildrenStopped;
896 UINTN Index;
897 ATA_BUS_DRIVER_DATA *AtaBusDriverData;
898
899 if (NumberOfChildren == 0) {
900 Status = gBS->OpenProtocol (
901 Controller,
902 &gEfiCallerIdGuid,
903 (VOID **) &AtaBusDriverData,
904 This->DriverBindingHandle,
905 Controller,
906 EFI_OPEN_PROTOCOL_GET_PROTOCOL
907 );
908 if (!EFI_ERROR (Status)) {
909 gBS->UninstallMultipleProtocolInterfaces (
910 Controller,
911 &gEfiCallerIdGuid,
912 AtaBusDriverData,
913 NULL
914 );
915 FreePool (AtaBusDriverData);
916 }
917
918 gBS->CloseProtocol (
919 Controller,
920 &gEfiAtaPassThruProtocolGuid,
921 This->DriverBindingHandle,
922 Controller
923 );
924
925 return EFI_SUCCESS;
926 }
927
928 AllChildrenStopped = TRUE;
929
930 for (Index = 0; Index < NumberOfChildren; Index++) {
931
932 Status = UnregisterAtaDevice (This, Controller, ChildHandleBuffer[Index]);
933 if (EFI_ERROR (Status)) {
934 AllChildrenStopped = FALSE;
935 }
936 }
937
938 if (!AllChildrenStopped) {
939 return EFI_DEVICE_ERROR;
940 }
941
942 return EFI_SUCCESS;
943 }
944
945
946 /**
947 Reset the Block Device.
948
949 @param This Indicates a pointer to the calling context.
950 @param ExtendedVerification Driver may perform diagnostics on reset.
951
952 @retval EFI_SUCCESS The device was reset.
953 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
954 not be reset.
955
956 **/
957 EFI_STATUS
958 EFIAPI
959 AtaBlockIoReset (
960 IN EFI_BLOCK_IO_PROTOCOL *This,
961 IN BOOLEAN ExtendedVerification
962 )
963 {
964 EFI_STATUS Status;
965 ATA_DEVICE *AtaDevice;
966 EFI_TPL OldTpl;
967
968 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
969
970 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);
971
972 Status = ResetAtaDevice (AtaDevice);
973
974 if (EFI_ERROR (Status)) {
975 Status = EFI_DEVICE_ERROR;
976 }
977
978 gBS->RestoreTPL (OldTpl);
979 return Status;
980 }
981
982
983 /**
984 Read/Write BufferSize bytes from Lba from/into Buffer.
985
986 @param[in] This Indicates a pointer to the calling context. Either be
987 block I/O or block I/O2.
988 @param[in] MediaId The media ID that the read/write request is for.
989 @param[in] Lba The starting logical block address to be read/written.
990 The caller is responsible for reading/writing to only
991 legitimate locations.
992 @param[in, out] Token A pointer to the token associated with the transaction.
993 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
994 @param[out] Buffer A pointer to the destination/source buffer for the data.
995 @param[in] IsBlockIo2 Indicate the calling is from BlockIO or BlockIO2. TURE is
996 from BlockIO2, FALSE is for BlockIO.
997 @param[in] IsWrite Indicates whether it is a write operation.
998
999 @retval EFI_SUCCESS The data was read/written correctly to the device.
1000 @retval EFI_WRITE_PROTECTED The device can not be read/written to.
1001 @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.
1002 @retval EFI_NO_MEDIA There is no media in the device.
1003 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1004 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1005 @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,
1006 or the buffer is not on proper alignment.
1007
1008 **/
1009 EFI_STATUS
1010 BlockIoReadWrite (
1011 IN VOID *This,
1012 IN UINT32 MediaId,
1013 IN EFI_LBA Lba,
1014 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
1015 IN UINTN BufferSize,
1016 OUT VOID *Buffer,
1017 IN BOOLEAN IsBlockIo2,
1018 IN BOOLEAN IsWrite
1019 )
1020 {
1021 ATA_DEVICE *AtaDevice;
1022 EFI_STATUS Status;
1023 EFI_TPL OldTpl;
1024 EFI_BLOCK_IO_MEDIA *Media;
1025 UINTN BlockSize;
1026 UINTN NumberOfBlocks;
1027 UINTN IoAlign;
1028
1029 if (IsBlockIo2) {
1030 Media = ((EFI_BLOCK_IO2_PROTOCOL *) This)->Media;
1031 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);
1032 } else {
1033 Media = ((EFI_BLOCK_IO_PROTOCOL *) This)->Media;
1034 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);
1035 }
1036
1037 if (MediaId != Media->MediaId) {
1038 return EFI_MEDIA_CHANGED;
1039 }
1040
1041 //
1042 // Check parameters.
1043 //
1044 if (Buffer == NULL) {
1045 return EFI_INVALID_PARAMETER;
1046 }
1047
1048 if (BufferSize == 0) {
1049 return EFI_SUCCESS;
1050 }
1051
1052 BlockSize = Media->BlockSize;
1053 if ((BufferSize % BlockSize) != 0) {
1054 return EFI_BAD_BUFFER_SIZE;
1055 }
1056
1057 NumberOfBlocks = BufferSize / BlockSize;
1058 if ((Lba + NumberOfBlocks - 1) > Media->LastBlock) {
1059 return EFI_INVALID_PARAMETER;
1060 }
1061
1062 IoAlign = Media->IoAlign;
1063 if (IoAlign > 0 && (((UINTN) Buffer & (IoAlign - 1)) != 0)) {
1064 return EFI_INVALID_PARAMETER;
1065 }
1066
1067 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1068
1069 //
1070 // Invoke low level AtaDevice Access Routine.
1071 //
1072 Status = AccessAtaDevice (AtaDevice, Buffer, Lba, NumberOfBlocks, IsWrite, Token);
1073
1074 gBS->RestoreTPL (OldTpl);
1075
1076 return Status;
1077 }
1078
1079
1080 /**
1081 Read BufferSize bytes from Lba into Buffer.
1082
1083 @param This Indicates a pointer to the calling context.
1084 @param MediaId Id of the media, changes every time the media is replaced.
1085 @param Lba The starting Logical Block Address to read from
1086 @param BufferSize Size of Buffer, must be a multiple of device block size.
1087 @param Buffer A pointer to the destination buffer for the data. The caller is
1088 responsible for either having implicit or explicit ownership of the buffer.
1089
1090 @retval EFI_SUCCESS The data was read correctly from the device.
1091 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
1092 @retval EFI_NO_MEDIA There is no media in the device.
1093 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
1094 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1095 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1096 or the buffer is not on proper alignment.
1097
1098 **/
1099 EFI_STATUS
1100 EFIAPI
1101 AtaBlockIoReadBlocks (
1102 IN EFI_BLOCK_IO_PROTOCOL *This,
1103 IN UINT32 MediaId,
1104 IN EFI_LBA Lba,
1105 IN UINTN BufferSize,
1106 OUT VOID *Buffer
1107 )
1108 {
1109 return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, FALSE);
1110 }
1111
1112
1113 /**
1114 Write BufferSize bytes from Lba into Buffer.
1115
1116 @param This Indicates a pointer to the calling context.
1117 @param MediaId The media ID that the write request is for.
1118 @param Lba The starting logical block address to be written. The caller is
1119 responsible for writing to only legitimate locations.
1120 @param BufferSize Size of Buffer, must be a multiple of device block size.
1121 @param Buffer A pointer to the source buffer for the data.
1122
1123 @retval EFI_SUCCESS The data was written correctly to the device.
1124 @retval EFI_WRITE_PROTECTED The device can not be written to.
1125 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1126 @retval EFI_NO_MEDIA There is no media in the device.
1127 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1128 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1129 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1130 or the buffer is not on proper alignment.
1131
1132 **/
1133 EFI_STATUS
1134 EFIAPI
1135 AtaBlockIoWriteBlocks (
1136 IN EFI_BLOCK_IO_PROTOCOL *This,
1137 IN UINT32 MediaId,
1138 IN EFI_LBA Lba,
1139 IN UINTN BufferSize,
1140 IN VOID *Buffer
1141 )
1142 {
1143 return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, TRUE);
1144 }
1145
1146
1147 /**
1148 Flush the Block Device.
1149
1150 @param This Indicates a pointer to the calling context.
1151
1152 @retval EFI_SUCCESS All outstanding data was written to the device
1153 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1154 @retval EFI_NO_MEDIA There is no media in the device.
1155
1156 **/
1157 EFI_STATUS
1158 EFIAPI
1159 AtaBlockIoFlushBlocks (
1160 IN EFI_BLOCK_IO_PROTOCOL *This
1161 )
1162 {
1163 //
1164 // return directly
1165 //
1166 return EFI_SUCCESS;
1167 }
1168
1169 /**
1170 Reset the Block Device.
1171
1172 @param[in] This Indicates a pointer to the calling context.
1173 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
1174
1175 @retval EFI_SUCCESS The device was reset.
1176 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
1177 not be reset.
1178
1179 **/
1180 EFI_STATUS
1181 EFIAPI
1182 AtaBlockIoResetEx (
1183 IN EFI_BLOCK_IO2_PROTOCOL *This,
1184 IN BOOLEAN ExtendedVerification
1185 )
1186 {
1187 EFI_STATUS Status;
1188 ATA_DEVICE *AtaDevice;
1189 EFI_TPL OldTpl;
1190
1191 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1192
1193 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);
1194
1195 Status = ResetAtaDevice (AtaDevice);
1196
1197 if (EFI_ERROR (Status)) {
1198 Status = EFI_DEVICE_ERROR;
1199 }
1200
1201 gBS->RestoreTPL (OldTpl);
1202 return Status;
1203 }
1204
1205 /**
1206 Read BufferSize bytes from Lba into Buffer.
1207
1208 @param[in] This Indicates a pointer to the calling context.
1209 @param[in] MediaId Id of the media, changes every time the media is replaced.
1210 @param[in] Lba The starting Logical Block Address to read from.
1211 @param[in, out] Token A pointer to the token associated with the transaction.
1212 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1213 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
1214 responsible for either having implicit or explicit ownership of the buffer.
1215
1216 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
1217 The data was read correctly from the device if
1218 the Event is NULL.
1219 @retval EFI_DEVICE_ERROR The device reported an error while performing
1220 the read.
1221 @retval EFI_NO_MEDIA There is no media in the device.
1222 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1223 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
1224 intrinsic block size of the device.
1225 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1226 or the buffer is not on proper alignment.
1227 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
1228 of resources.
1229
1230 **/
1231 EFI_STATUS
1232 EFIAPI
1233 AtaBlockIoReadBlocksEx (
1234 IN EFI_BLOCK_IO2_PROTOCOL *This,
1235 IN UINT32 MediaId,
1236 IN EFI_LBA Lba,
1237 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
1238 IN UINTN BufferSize,
1239 OUT VOID *Buffer
1240 )
1241 {
1242 return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, FALSE);
1243 }
1244
1245
1246 /**
1247 Write BufferSize bytes from Lba into Buffer.
1248
1249 @param[in] This Indicates a pointer to the calling context.
1250 @param[in] MediaId The media ID that the write request is for.
1251 @param[in] Lba The starting logical block address to be written. The
1252 caller is responsible for writing to only legitimate
1253 locations.
1254 @param[in, out] Token A pointer to the token associated with the transaction.
1255 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1256 @param[in] Buffer A pointer to the source buffer for the data.
1257
1258 @retval EFI_SUCCESS The data was written correctly to the device.
1259 @retval EFI_WRITE_PROTECTED The device can not be written to.
1260 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1261 @retval EFI_NO_MEDIA There is no media in the device.
1262 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1263 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1264 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1265 or the buffer is not on proper alignment.
1266
1267 **/
1268 EFI_STATUS
1269 EFIAPI
1270 AtaBlockIoWriteBlocksEx (
1271 IN EFI_BLOCK_IO2_PROTOCOL *This,
1272 IN UINT32 MediaId,
1273 IN EFI_LBA Lba,
1274 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
1275 IN UINTN BufferSize,
1276 IN VOID *Buffer
1277 )
1278 {
1279 return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, TRUE);
1280 }
1281
1282
1283 /**
1284 Flush the Block Device.
1285
1286 @param[in] This Indicates a pointer to the calling context.
1287 @param[in, out] Token A pointer to the token associated with the transaction.
1288
1289 @retval EFI_SUCCESS All outstanding data was written to the device
1290 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1291 @retval EFI_NO_MEDIA There is no media in the device.
1292
1293 **/
1294 EFI_STATUS
1295 EFIAPI
1296 AtaBlockIoFlushBlocksEx (
1297 IN EFI_BLOCK_IO2_PROTOCOL *This,
1298 IN OUT EFI_BLOCK_IO2_TOKEN *Token
1299 )
1300 {
1301 //
1302 // Signal event and return directly.
1303 //
1304 if (Token != NULL && Token->Event != NULL) {
1305 Token->TransactionStatus = EFI_SUCCESS;
1306 gBS->SignalEvent (Token->Event);
1307 }
1308 return EFI_SUCCESS;
1309 }
1310 /**
1311 Provides inquiry information for the controller type.
1312
1313 This function is used by the IDE bus driver to get inquiry data. Data format
1314 of Identify data is defined by the Interface GUID.
1315
1316 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1317 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
1318 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
1319
1320 @retval EFI_SUCCESS The command was accepted without any errors.
1321 @retval EFI_NOT_FOUND Device does not support this data class
1322 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
1323 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
1324
1325 **/
1326 EFI_STATUS
1327 EFIAPI
1328 AtaDiskInfoInquiry (
1329 IN EFI_DISK_INFO_PROTOCOL *This,
1330 IN OUT VOID *InquiryData,
1331 IN OUT UINT32 *InquiryDataSize
1332 )
1333 {
1334 return EFI_NOT_FOUND;
1335 }
1336
1337
1338 /**
1339 Provides identify information for the controller type.
1340
1341 This function is used by the IDE bus driver to get identify data. Data format
1342 of Identify data is defined by the Interface GUID.
1343
1344 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1345 instance.
1346 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1347 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1348 size.
1349
1350 @retval EFI_SUCCESS The command was accepted without any errors.
1351 @retval EFI_NOT_FOUND Device does not support this data class
1352 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1353 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1354
1355 **/
1356 EFI_STATUS
1357 EFIAPI
1358 AtaDiskInfoIdentify (
1359 IN EFI_DISK_INFO_PROTOCOL *This,
1360 IN OUT VOID *IdentifyData,
1361 IN OUT UINT32 *IdentifyDataSize
1362 )
1363 {
1364 EFI_STATUS Status;
1365 ATA_DEVICE *AtaDevice;
1366
1367 AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);
1368
1369 Status = EFI_BUFFER_TOO_SMALL;
1370 if (*IdentifyDataSize >= sizeof (ATA_IDENTIFY_DATA)) {
1371 Status = EFI_SUCCESS;
1372 CopyMem (IdentifyData, AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));
1373 }
1374 *IdentifyDataSize = sizeof (ATA_IDENTIFY_DATA);
1375
1376 return Status;
1377 }
1378
1379
1380 /**
1381 Provides sense data information for the controller type.
1382
1383 This function is used by the IDE bus driver to get sense data.
1384 Data format of Sense data is defined by the Interface GUID.
1385
1386 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1387 @param[in, out] SenseData Pointer to the SenseData.
1388 @param[in, out] SenseDataSize Size of SenseData in bytes.
1389 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1390
1391 @retval EFI_SUCCESS The command was accepted without any errors.
1392 @retval EFI_NOT_FOUND Device does not support this data class.
1393 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1394 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1395
1396 **/
1397 EFI_STATUS
1398 EFIAPI
1399 AtaDiskInfoSenseData (
1400 IN EFI_DISK_INFO_PROTOCOL *This,
1401 IN OUT VOID *SenseData,
1402 IN OUT UINT32 *SenseDataSize,
1403 OUT UINT8 *SenseDataNumber
1404 )
1405 {
1406 return EFI_NOT_FOUND;
1407 }
1408
1409
1410 /**
1411 This function is used by the IDE bus driver to get controller information.
1412
1413 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1414 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1415 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1416
1417 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1418 @retval EFI_UNSUPPORTED This is not an IDE device.
1419
1420 **/
1421 EFI_STATUS
1422 EFIAPI
1423 AtaDiskInfoWhichIde (
1424 IN EFI_DISK_INFO_PROTOCOL *This,
1425 OUT UINT32 *IdeChannel,
1426 OUT UINT32 *IdeDevice
1427 )
1428 {
1429 ATA_DEVICE *AtaDevice;
1430
1431 AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);
1432 *IdeChannel = AtaDevice->Port;
1433 *IdeDevice = AtaDevice->PortMultiplierPort;
1434
1435 return EFI_SUCCESS;
1436 }
1437
1438 /**
1439 Send a security protocol command to a device that receives data and/or the result
1440 of one or more commands sent by SendData.
1441
1442 The ReceiveData function sends a security protocol command to the given MediaId.
1443 The security protocol command sent is defined by SecurityProtocolId and contains
1444 the security protocol specific data SecurityProtocolSpecificData. The function
1445 returns the data from the security protocol command in PayloadBuffer.
1446
1447 For devices supporting the SCSI command set, the security protocol command is sent
1448 using the SECURITY PROTOCOL IN command defined in SPC-4.
1449
1450 For devices supporting the ATA command set, the security protocol command is sent
1451 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
1452 is non-zero.
1453
1454 If the PayloadBufferSize is zero, the security protocol command is sent using the
1455 Trusted Non-Data command defined in ATA8-ACS.
1456
1457 If PayloadBufferSize is too small to store the available data from the security
1458 protocol command, the function shall copy PayloadBufferSize bytes into the
1459 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
1460
1461 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
1462 the function shall return EFI_INVALID_PARAMETER.
1463
1464 If the given MediaId does not support security protocol commands, the function shall
1465 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
1466 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
1467 the function returns EFI_MEDIA_CHANGED.
1468
1469 If the security protocol fails to complete within the Timeout period, the function
1470 shall return EFI_TIMEOUT.
1471
1472 If the security protocol command completes without an error, the function shall
1473 return EFI_SUCCESS. If the security protocol command completes with an error, the
1474 function shall return EFI_DEVICE_ERROR.
1475
1476 @param This Indicates a pointer to the calling context.
1477 @param MediaId ID of the medium to receive data from.
1478 @param Timeout The timeout, in 100ns units, to use for the execution
1479 of the security protocol command. A Timeout value of 0
1480 means that this function will wait indefinitely for the
1481 security protocol command to execute. If Timeout is greater
1482 than zero, then this function will return EFI_TIMEOUT
1483 if the time required to execute the receive data command
1484 is greater than Timeout.
1485 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1486 the security protocol command to be sent.
1487 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1488 of the security protocol command to be sent.
1489 @param PayloadBufferSize Size in bytes of the payload data buffer.
1490 @param PayloadBuffer A pointer to a destination buffer to store the security
1491 protocol command specific payload data for the security
1492 protocol command. The caller is responsible for having
1493 either implicit or explicit ownership of the buffer.
1494 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
1495 data written to the payload data buffer.
1496
1497 @retval EFI_SUCCESS The security protocol command completed successfully.
1498 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
1499 data from the device. The PayloadBuffer contains the truncated data.
1500 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1501 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1502 @retval EFI_NO_MEDIA There is no media in the device.
1503 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1504 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
1505 PayloadBufferSize is non-zero.
1506 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1507 protocol command to execute.
1508
1509 **/
1510 EFI_STATUS
1511 EFIAPI
1512 AtaStorageSecurityReceiveData (
1513 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
1514 IN UINT32 MediaId,
1515 IN UINT64 Timeout,
1516 IN UINT8 SecurityProtocolId,
1517 IN UINT16 SecurityProtocolSpecificData,
1518 IN UINTN PayloadBufferSize,
1519 OUT VOID *PayloadBuffer,
1520 OUT UINTN *PayloadTransferSize
1521 )
1522 {
1523 EFI_STATUS Status;
1524 ATA_DEVICE *Private;
1525 EFI_TPL OldTpl;
1526
1527 DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Read"));
1528 if ((PayloadBuffer == NULL || PayloadTransferSize == NULL) && PayloadBufferSize != 0) {
1529 return EFI_INVALID_PARAMETER;
1530 }
1531
1532 Status = EFI_SUCCESS;
1533 Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);
1534
1535 if (MediaId != Private->BlockIo.Media->MediaId) {
1536 return EFI_MEDIA_CHANGED;
1537 }
1538
1539 if (!Private->BlockIo.Media->MediaPresent) {
1540 return EFI_NO_MEDIA;
1541 }
1542
1543 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1544
1545 Status = TrustTransferAtaDevice (
1546 Private,
1547 PayloadBuffer,
1548 SecurityProtocolId,
1549 SecurityProtocolSpecificData,
1550 PayloadBufferSize,
1551 FALSE,
1552 Timeout,
1553 PayloadTransferSize
1554 );
1555
1556 gBS->RestoreTPL (OldTpl);
1557 return Status;
1558 }
1559
1560 /**
1561 Send a security protocol command to a device.
1562
1563 The SendData function sends a security protocol command containing the payload
1564 PayloadBuffer to the given MediaId. The security protocol command sent is
1565 defined by SecurityProtocolId and contains the security protocol specific data
1566 SecurityProtocolSpecificData. If the underlying protocol command requires a
1567 specific padding for the command payload, the SendData function shall add padding
1568 bytes to the command payload to satisfy the padding requirements.
1569
1570 For devices supporting the SCSI command set, the security protocol command is sent
1571 using the SECURITY PROTOCOL OUT command defined in SPC-4.
1572
1573 For devices supporting the ATA command set, the security protocol command is sent
1574 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1575 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1576 sent using the Trusted Non-Data command defined in ATA8-ACS.
1577
1578 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1579 return EFI_INVALID_PARAMETER.
1580
1581 If the given MediaId does not support security protocol commands, the function
1582 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1583 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1584 device, the function returns EFI_MEDIA_CHANGED.
1585
1586 If the security protocol fails to complete within the Timeout period, the function
1587 shall return EFI_TIMEOUT.
1588
1589 If the security protocol command completes without an error, the function shall return
1590 EFI_SUCCESS. If the security protocol command completes with an error, the function
1591 shall return EFI_DEVICE_ERROR.
1592
1593 @param This Indicates a pointer to the calling context.
1594 @param MediaId ID of the medium to receive data from.
1595 @param Timeout The timeout, in 100ns units, to use for the execution
1596 of the security protocol command. A Timeout value of 0
1597 means that this function will wait indefinitely for the
1598 security protocol command to execute. If Timeout is greater
1599 than zero, then this function will return EFI_TIMEOUT
1600 if the time required to execute the receive data command
1601 is greater than Timeout.
1602 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1603 the security protocol command to be sent.
1604 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1605 of the security protocol command to be sent.
1606 @param PayloadBufferSize Size in bytes of the payload data buffer.
1607 @param PayloadBuffer A pointer to a destination buffer to store the security
1608 protocol command specific payload data for the security
1609 protocol command.
1610
1611 @retval EFI_SUCCESS The security protocol command completed successfully.
1612 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1613 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1614 @retval EFI_NO_MEDIA There is no media in the device.
1615 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1616 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1617 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1618 protocol command to execute.
1619
1620 **/
1621 EFI_STATUS
1622 EFIAPI
1623 AtaStorageSecuritySendData (
1624 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
1625 IN UINT32 MediaId,
1626 IN UINT64 Timeout,
1627 IN UINT8 SecurityProtocolId,
1628 IN UINT16 SecurityProtocolSpecificData,
1629 IN UINTN PayloadBufferSize,
1630 IN VOID *PayloadBuffer
1631 )
1632 {
1633 EFI_STATUS Status;
1634 ATA_DEVICE *Private;
1635 EFI_TPL OldTpl;
1636
1637 DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Send"));
1638 if ((PayloadBuffer == NULL) && (PayloadBufferSize != 0)) {
1639 return EFI_INVALID_PARAMETER;
1640 }
1641
1642 Status = EFI_SUCCESS;
1643 Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);
1644
1645 if (MediaId != Private->BlockIo.Media->MediaId) {
1646 return EFI_MEDIA_CHANGED;
1647 }
1648
1649 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1650 Status = TrustTransferAtaDevice (
1651 Private,
1652 PayloadBuffer,
1653 SecurityProtocolId,
1654 SecurityProtocolSpecificData,
1655 PayloadBufferSize,
1656 TRUE,
1657 Timeout,
1658 NULL
1659 );
1660
1661 gBS->RestoreTPL (OldTpl);
1662 return Status;
1663 }
1664
1665 /**
1666 The user Entry Point for module AtaBus. The user code starts with this function.
1667
1668 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1669 @param[in] SystemTable A pointer to the EFI System Table.
1670
1671 @retval EFI_SUCCESS The entry point is executed successfully.
1672 @retval other Some error occurs when executing this entry point.
1673
1674 **/
1675 EFI_STATUS
1676 EFIAPI
1677 InitializeAtaBus(
1678 IN EFI_HANDLE ImageHandle,
1679 IN EFI_SYSTEM_TABLE *SystemTable
1680 )
1681 {
1682 EFI_STATUS Status;
1683 UINTN DataSize;
1684
1685 //
1686 // Install driver model protocol(s).
1687 //
1688 Status = EfiLibInstallDriverBindingComponentName2 (
1689 ImageHandle,
1690 SystemTable,
1691 &gAtaBusDriverBinding,
1692 ImageHandle,
1693 &gAtaBusComponentName,
1694 &gAtaBusComponentName2
1695 );
1696 ASSERT_EFI_ERROR (Status);
1697
1698 //
1699 // Get the MorControl bit.
1700 //
1701 DataSize = sizeof (mMorControl);
1702 Status = gRT->GetVariable (
1703 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
1704 &gEfiMemoryOverwriteControlDataGuid,
1705 NULL,
1706 &DataSize,
1707 &mMorControl
1708 );
1709
1710 if (EFI_ERROR (Status)) {
1711 DEBUG ((EFI_D_INFO, "AtaBus:gEfiMemoryOverwriteControlDataGuid doesn't exist!!***\n"));
1712 mMorControl = 0;
1713 Status = EFI_SUCCESS;
1714 } else {
1715 DEBUG ((EFI_D_INFO, "AtaBus:Get the gEfiMemoryOverwriteControlDataGuid = %x!!***\n", mMorControl));
1716 }
1717
1718 return Status;
1719 }
1720
1721 /**
1722 Send TPer Reset command to reset eDrive to lock all protected bands.
1723 Typically, there are 2 mechanism for resetting eDrive. They are:
1724 1. TPer Reset through IEEE 1667 protocol.
1725 2. TPer Reset through native TCG protocol.
1726 This routine will detect what protocol the attached eDrive comform to, TCG or
1727 IEEE 1667 protocol. Then send out TPer Reset command separately.
1728
1729 @param[in] AtaDevice ATA_DEVICE pointer.
1730
1731 **/
1732 VOID
1733 InitiateTPerReset (
1734 IN ATA_DEVICE *AtaDevice
1735 )
1736 {
1737
1738 EFI_STATUS Status;
1739 UINT8 *Buffer;
1740 UINTN XferSize;
1741 UINTN Len;
1742 UINTN Index;
1743 BOOLEAN TcgFlag;
1744 BOOLEAN IeeeFlag;
1745 EFI_BLOCK_IO_PROTOCOL *BlockIo;
1746 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *Ssp;
1747 SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA *Data;
1748
1749 Buffer = NULL;
1750 TcgFlag = FALSE;
1751 IeeeFlag = FALSE;
1752 Ssp = &AtaDevice->StorageSecurity;
1753 BlockIo = &AtaDevice->BlockIo;
1754
1755 //
1756 // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.
1757 // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,
1758 // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.
1759 //
1760 Len = ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA));
1761 Buffer = AllocateZeroPool(Len);
1762
1763 if (Buffer == NULL) {
1764 return;
1765 }
1766
1767 //
1768 // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE
1769 // command, the device basic information data shall be returned.
1770 //
1771 Status = Ssp->ReceiveData (
1772 Ssp,
1773 BlockIo->Media->MediaId,
1774 100000000, // Timeout 10-sec
1775 0, // SecurityProtocol
1776 0, // SecurityProtocolSpecifcData
1777 Len, // PayloadBufferSize,
1778 Buffer, // PayloadBuffer
1779 &XferSize
1780 );
1781 if (EFI_ERROR (Status)) {
1782 goto Exit;
1783 }
1784
1785 //
1786 // In returned data, the ListLength field indicates the total length, in bytes,
1787 // of the supported security protocol list.
1788 //
1789 Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;
1790 Len = ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA) +
1791 (Data->SupportedSecurityListLength[0] << 8) +
1792 (Data->SupportedSecurityListLength[1])
1793 );
1794
1795 //
1796 // Free original buffer and allocate new buffer.
1797 //
1798 FreePool(Buffer);
1799 Buffer = AllocateZeroPool(Len);
1800 if (Buffer == NULL) {
1801 return;
1802 }
1803
1804 //
1805 // Read full supported security protocol list from device.
1806 //
1807 Status = Ssp->ReceiveData (
1808 Ssp,
1809 BlockIo->Media->MediaId,
1810 100000000, // Timeout 10-sec
1811 0, // SecurityProtocol
1812 0, // SecurityProtocolSpecifcData
1813 Len, // PayloadBufferSize,
1814 Buffer, // PayloadBuffer
1815 &XferSize
1816 );
1817
1818 if (EFI_ERROR (Status)) {
1819 goto Exit;
1820 }
1821
1822 Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;
1823 Len = (Data->SupportedSecurityListLength[0] << 8) + Data->SupportedSecurityListLength[1];
1824
1825 //
1826 // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol
1827 // is supported.
1828 //
1829 for (Index = 0; Index < Len; Index++) {
1830 if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_TCG) {
1831 //
1832 // Found a TCG device.
1833 //
1834 TcgFlag = TRUE;
1835 DEBUG ((EFI_D_INFO, "This device is a TCG protocol device\n"));
1836 break;
1837 }
1838
1839 if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_IEEE1667) {
1840 //
1841 // Found a IEEE 1667 device.
1842 //
1843 IeeeFlag = TRUE;
1844 DEBUG ((EFI_D_INFO, "This device is a IEEE 1667 protocol device\n"));
1845 break;
1846 }
1847 }
1848
1849 if (!TcgFlag && !IeeeFlag) {
1850 DEBUG ((EFI_D_INFO, "Neither a TCG nor IEEE 1667 protocol device is found\n"));
1851 goto Exit;
1852 }
1853
1854 if (TcgFlag) {
1855 //
1856 // As long as TCG protocol is supported, send out a TPer Reset
1857 // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.
1858 //
1859 Status = Ssp->SendData (
1860 Ssp,
1861 BlockIo->Media->MediaId,
1862 100000000, // Timeout 10-sec
1863 SECURITY_PROTOCOL_TCG, // SecurityProtocol
1864 0x0400, // SecurityProtocolSpecifcData
1865 512, // PayloadBufferSize,
1866 Buffer // PayloadBuffer
1867 );
1868
1869 if (!EFI_ERROR (Status)) {
1870 DEBUG ((EFI_D_INFO, "Send TPer Reset Command Successfully !\n"));
1871 } else {
1872 DEBUG ((EFI_D_INFO, "Send TPer Reset Command Fail !\n"));
1873 }
1874 }
1875
1876 if (IeeeFlag) {
1877 //
1878 // TBD : Perform a TPer Reset via IEEE 1667 Protocol
1879 //
1880 DEBUG ((EFI_D_INFO, "IEEE 1667 Protocol didn't support yet!\n"));
1881 }
1882
1883 Exit:
1884
1885 if (Buffer != NULL) {
1886 FreePool(Buffer);
1887 }
1888 }