]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c
MdeModulePkg/UsbBusDxe: Add UsbControlTransfer() error check
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMassImpl.c
CommitLineData
e237e7ae 1/** @file\r
d80ed2a7 2 USB Mass Storage Driver that manages USB Mass Storage Device and produces Block I/O Protocol.\r
cc5166ff 3\r
3cf6450e 4Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 5This program and the accompanying materials\r
e237e7ae 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
e237e7ae 13**/\r
14\r
39840c50 15#include "UsbMass.h"\r
e237e7ae 16\r
db0bd81c 17#define USB_MASS_TRANSPORT_COUNT 3\r
d80ed2a7 18//\r
19// Array of USB transport interfaces. \r
20//\r
db0bd81c 21USB_MASS_TRANSPORT *mUsbMassTransport[USB_MASS_TRANSPORT_COUNT] = {\r
e237e7ae 22 &mUsbCbi0Transport,\r
23 &mUsbCbi1Transport,\r
24 &mUsbBotTransport,\r
e237e7ae 25};\r
26\r
d80ed2a7 27EFI_DRIVER_BINDING_PROTOCOL gUSBMassDriverBinding = {\r
28 USBMassDriverBindingSupported,\r
29 USBMassDriverBindingStart,\r
30 USBMassDriverBindingStop,\r
31 0x11,\r
32 NULL,\r
33 NULL\r
34};\r
35\r
e237e7ae 36/**\r
d80ed2a7 37 Reset the block device.\r
38\r
39 This function implements EFI_BLOCK_IO_PROTOCOL.Reset(). \r
40 It resets the block device hardware.\r
41 ExtendedVerification is ignored in this implementation.\r
e237e7ae 42\r
d80ed2a7 43 @param This Indicates a pointer to the calling context.\r
44 @param ExtendedVerification Indicates that the driver may perform a more exhaustive\r
45 verification operation of the device during reset.\r
e237e7ae 46\r
d80ed2a7 47 @retval EFI_SUCCESS The block device was reset.\r
48 @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be reset.\r
e237e7ae 49\r
50**/\r
51EFI_STATUS\r
1c619535 52EFIAPI\r
e237e7ae 53UsbMassReset (\r
54 IN EFI_BLOCK_IO_PROTOCOL *This,\r
55 IN BOOLEAN ExtendedVerification\r
56 )\r
57{\r
58 USB_MASS_DEVICE *UsbMass;\r
41e8ff27 59 EFI_TPL OldTpl;\r
60 EFI_STATUS Status;\r
61\r
d80ed2a7 62 //\r
63 // Raise TPL to TPL_NOTIFY to serialize all its operations\r
64 // to protect shared data structures.\r
65 //\r
3cf6450e 66 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
e237e7ae 67\r
d80ed2a7 68 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (This);\r
41e8ff27 69 Status = UsbMass->Transport->Reset (UsbMass->Context, ExtendedVerification);\r
70\r
71 gBS->RestoreTPL (OldTpl);\r
72\r
73 return Status;\r
e237e7ae 74}\r
75\r
e237e7ae 76/**\r
d80ed2a7 77 Reads the requested number of blocks from the device.\r
78\r
79 This function implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks(). \r
80 It reads the requested number of blocks from the device.\r
81 All the blocks are read, or an error is returned.\r
82\r
83 @param This Indicates a pointer to the calling context.\r
84 @param MediaId The media ID that the read request is for.\r
85 @param Lba The starting logical block address to read from on the device.\r
86 @param BufferSize The size of the Buffer in bytes.\r
87 This must be a multiple of the intrinsic block size of the device.\r
88 @param Buffer A pointer to the destination buffer for the data. The caller is\r
89 responsible for either having implicit or explicit ownership of the buffer.\r
90\r
91 @retval EFI_SUCCESS The data was read correctly from the device.\r
92 @retval EFI_DEVICE_ERROR The device reported an error while attempting to perform the read operation.\r
93 @retval EFI_NO_MEDIA There is no media in the device.\r
94 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r
95 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the intrinsic block size of the device.\r
96 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
97 or the buffer is not on proper alignment.\r
e237e7ae 98\r
99**/\r
100EFI_STATUS\r
1c619535 101EFIAPI\r
e237e7ae 102UsbMassReadBlocks (\r
103 IN EFI_BLOCK_IO_PROTOCOL *This,\r
104 IN UINT32 MediaId,\r
105 IN EFI_LBA Lba,\r
106 IN UINTN BufferSize,\r
107 OUT VOID *Buffer\r
108 )\r
109{\r
110 USB_MASS_DEVICE *UsbMass;\r
111 EFI_BLOCK_IO_MEDIA *Media;\r
112 EFI_STATUS Status;\r
41e8ff27 113 EFI_TPL OldTpl;\r
e237e7ae 114 UINTN TotalBlock;\r
1c619535 115\r
d80ed2a7 116 //\r
117 // Raise TPL to TPL_NOTIFY to serialize all its operations\r
118 // to protect shared data structures.\r
119 //\r
3cf6450e 120 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
d80ed2a7 121 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (This);\r
122 Media = &UsbMass->BlockIoMedia;\r
123\r
e237e7ae 124 //\r
41e8ff27 125 // If it is a removable media, such as CD-Rom or Usb-Floppy,\r
d80ed2a7 126 // need to detect the media before each read/write. While some of\r
41e8ff27 127 // Usb-Flash is marked as removable media.\r
1c619535 128 //\r
d80ed2a7 129 if (Media->RemovableMedia) {\r
41e8ff27 130 Status = UsbBootDetectMedia (UsbMass);\r
131 if (EFI_ERROR (Status)) {\r
41e8ff27 132 goto ON_EXIT;\r
1c619535 133 }\r
e237e7ae 134 }\r
1c619535 135\r
fcf5e49d
RN
136 if (!(Media->MediaPresent)) {\r
137 Status = EFI_NO_MEDIA;\r
138 goto ON_EXIT;\r
139 }\r
140\r
141 if (MediaId != Media->MediaId) {\r
142 Status = EFI_MEDIA_CHANGED;\r
143 goto ON_EXIT;\r
144 }\r
145\r
146 if (BufferSize == 0) {\r
147 Status = EFI_SUCCESS;\r
148 goto ON_EXIT;\r
149 }\r
150\r
151 if (Buffer == NULL) {\r
152 Status = EFI_INVALID_PARAMETER;\r
153 goto ON_EXIT;\r
154 }\r
155\r
e237e7ae 156 //\r
d80ed2a7 157 // BufferSize must be a multiple of the intrinsic block size of the device.\r
e237e7ae 158 //\r
159 if ((BufferSize % Media->BlockSize) != 0) {\r
41e8ff27 160 Status = EFI_BAD_BUFFER_SIZE;\r
161 goto ON_EXIT;\r
e237e7ae 162 }\r
163\r
164 TotalBlock = BufferSize / Media->BlockSize;\r
165\r
d80ed2a7 166 //\r
167 // Make sure the range to read is valid.\r
168 //\r
e237e7ae 169 if (Lba + TotalBlock - 1 > Media->LastBlock) {\r
1c619535 170 Status = EFI_INVALID_PARAMETER;\r
171 goto ON_EXIT;\r
172 }\r
173\r
99c1725e 174 if (UsbMass->Cdb16Byte) {\r
175 Status = UsbBootReadBlocks16 (UsbMass, Lba, TotalBlock, Buffer);\r
176 } else {\r
177 Status = UsbBootReadBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer);\r
178 }\r
179\r
e237e7ae 180 if (EFI_ERROR (Status)) {\r
1c619535 181 DEBUG ((EFI_D_ERROR, "UsbMassReadBlocks: UsbBootReadBlocks (%r) -> Reset\n", Status));\r
e237e7ae 182 UsbMassReset (This, TRUE);\r
183 }\r
184\r
41e8ff27 185ON_EXIT:\r
186 gBS->RestoreTPL (OldTpl);\r
e237e7ae 187 return Status;\r
188}\r
189\r
190\r
191/**\r
d80ed2a7 192 Writes a specified number of blocks to the device.\r
193\r
194 This function implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks(). \r
195 It writes a specified number of blocks to the device.\r
196 All blocks are written, or an error is returned.\r
197\r
198 @param This Indicates a pointer to the calling context.\r
199 @param MediaId The media ID that the write request is for.\r
200 @param Lba The starting logical block address to be written.\r
201 @param BufferSize The size of the Buffer in bytes.\r
202 This must be a multiple of the intrinsic block size of the device.\r
203 @param Buffer Pointer to the source buffer for the data.\r
204\r
205 @retval EFI_SUCCESS The data were written correctly to the device.\r
206 @retval EFI_WRITE_PROTECTED The device cannot be written to.\r
207 @retval EFI_NO_MEDIA There is no media in the device.\r
208 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r
209 @retval EFI_DEVICE_ERROR The device reported an error while attempting to perform the write operation.\r
210 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the intrinsic\r
211 block size of the device.\r
212 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
213 or the buffer is not on proper alignment.\r
e237e7ae 214\r
215**/\r
216EFI_STATUS\r
1c619535 217EFIAPI\r
e237e7ae 218UsbMassWriteBlocks (\r
219 IN EFI_BLOCK_IO_PROTOCOL *This,\r
220 IN UINT32 MediaId,\r
221 IN EFI_LBA Lba,\r
222 IN UINTN BufferSize,\r
223 IN VOID *Buffer\r
224 )\r
225{\r
226 USB_MASS_DEVICE *UsbMass;\r
227 EFI_BLOCK_IO_MEDIA *Media;\r
228 EFI_STATUS Status;\r
41e8ff27 229 EFI_TPL OldTpl;\r
e237e7ae 230 UINTN TotalBlock;\r
231\r
e237e7ae 232 //\r
d80ed2a7 233 // Raise TPL to TPL_NOTIFY to serialize all its operations\r
234 // to protect shared data structures.\r
1c619535 235 //\r
3cf6450e 236 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
d80ed2a7 237 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (This);\r
238 Media = &UsbMass->BlockIoMedia;\r
239\r
240 //\r
241 // If it is a removable media, such as CD-Rom or Usb-Floppy,\r
242 // need to detect the media before each read/write. Some of\r
243 // USB Flash is marked as removable media.\r
1c619535 244 //\r
d80ed2a7 245 if (Media->RemovableMedia) {\r
41e8ff27 246 Status = UsbBootDetectMedia (UsbMass);\r
247 if (EFI_ERROR (Status)) {\r
41e8ff27 248 goto ON_EXIT;\r
1c619535 249 }\r
e237e7ae 250 }\r
1c619535 251\r
fcf5e49d
RN
252 if (!(Media->MediaPresent)) {\r
253 Status = EFI_NO_MEDIA;\r
254 goto ON_EXIT;\r
255 }\r
256\r
257 if (MediaId != Media->MediaId) {\r
258 Status = EFI_MEDIA_CHANGED;\r
259 goto ON_EXIT;\r
260 }\r
261\r
262 if (BufferSize == 0) {\r
263 Status = EFI_SUCCESS;\r
264 goto ON_EXIT;\r
265 }\r
266\r
267 if (Buffer == NULL) {\r
268 Status = EFI_INVALID_PARAMETER;\r
269 goto ON_EXIT;\r
270 }\r
271\r
e237e7ae 272 //\r
d80ed2a7 273 // BufferSize must be a multiple of the intrinsic block size of the device.\r
e237e7ae 274 //\r
275 if ((BufferSize % Media->BlockSize) != 0) {\r
41e8ff27 276 Status = EFI_BAD_BUFFER_SIZE;\r
277 goto ON_EXIT;\r
e237e7ae 278 }\r
279\r
280 TotalBlock = BufferSize / Media->BlockSize;\r
281\r
d80ed2a7 282 //\r
283 // Make sure the range to write is valid.\r
284 //\r
e237e7ae 285 if (Lba + TotalBlock - 1 > Media->LastBlock) {\r
1c619535 286 Status = EFI_INVALID_PARAMETER;\r
41e8ff27 287 goto ON_EXIT;\r
e237e7ae 288 }\r
1c619535 289\r
e237e7ae 290 //\r
291 // Try to write the data even the device is marked as ReadOnly,\r
292 // and clear the status should the write succeed.\r
293 //\r
99c1725e 294 if (UsbMass->Cdb16Byte) {\r
295 Status = UsbBootWriteBlocks16 (UsbMass, Lba, TotalBlock, Buffer);\r
296 } else {\r
297 Status = UsbBootWriteBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer);\r
298 } \r
299\r
e237e7ae 300 if (EFI_ERROR (Status)) {\r
1c619535 301 DEBUG ((EFI_D_ERROR, "UsbMassWriteBlocks: UsbBootWriteBlocks (%r) -> Reset\n", Status));\r
e237e7ae 302 UsbMassReset (This, TRUE);\r
303 }\r
1c619535 304\r
41e8ff27 305ON_EXIT:\r
306 gBS->RestoreTPL (OldTpl);\r
e237e7ae 307 return Status;\r
308}\r
309\r
e237e7ae 310/**\r
d80ed2a7 311 Flushes all modified data to a physical block device.\r
312\r
313 This function implements EFI_BLOCK_IO_PROTOCOL.FlushBlocks().\r
314 USB mass storage device doesn't support write cache,\r
315 so return EFI_SUCCESS directly.\r
e237e7ae 316\r
d80ed2a7 317 @param This Indicates a pointer to the calling context.\r
e237e7ae 318\r
d80ed2a7 319 @retval EFI_SUCCESS All outstanding data were written correctly to the device.\r
320 @retval EFI_DEVICE_ERROR The device reported an error while attempting to write data.\r
321 @retval EFI_NO_MEDIA There is no media in the device.\r
e237e7ae 322\r
323**/\r
324EFI_STATUS\r
1c619535 325EFIAPI\r
e237e7ae 326UsbMassFlushBlocks (\r
327 IN EFI_BLOCK_IO_PROTOCOL *This\r
328 )\r
329{\r
330 return EFI_SUCCESS;\r
331}\r
332\r
c7e39923 333/**\r
d80ed2a7 334 Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.\r
c7e39923 335\r
336 @param UsbMass The USB mass storage device\r
337\r
d80ed2a7 338 @retval EFI_SUCCESS The media parameters are updated successfully.\r
c7e39923 339 @retval Others Failed to get the media parameters.\r
340\r
341**/\r
342EFI_STATUS\r
343UsbMassInitMedia (\r
344 IN USB_MASS_DEVICE *UsbMass\r
345 )\r
346{\r
347 EFI_BLOCK_IO_MEDIA *Media;\r
348 EFI_STATUS Status;\r
c7e39923 349\r
350 Media = &UsbMass->BlockIoMedia;\r
351\r
352 //\r
d80ed2a7 353 // Fields of EFI_BLOCK_IO_MEDIA are defined in UEFI 2.0 spec,\r
354 // section for Block I/O Protocol.\r
c7e39923 355 //\r
356 Media->MediaPresent = FALSE;\r
357 Media->LogicalPartition = FALSE;\r
358 Media->ReadOnly = FALSE;\r
359 Media->WriteCaching = FALSE;\r
360 Media->IoAlign = 0;\r
361 Media->MediaId = 1;\r
362\r
19bc8527 363 Status = UsbBootGetParams (UsbMass);\r
c7e39923 364 return Status;\r
365}\r
366\r
cc5166ff 367/**\r
d80ed2a7 368 Initilize the USB Mass Storage transport.\r
369\r
370 This function tries to find the matching USB Mass Storage transport\r
371 protocol for USB device. If found, initializes the matching transport.\r
cc5166ff 372\r
373 @param This The USB mass driver's driver binding.\r
374 @param Controller The device to test.\r
375 @param Transport The pointer to pointer to USB_MASS_TRANSPORT.\r
3e03cb4d 376 @param Context The parameter for USB_MASS_DEVICE.Context.\r
cc5166ff 377 @param MaxLun Get the MaxLun if is BOT dev.\r
378\r
d7db0902 379 @retval EFI_SUCCESS The initialization is successful.\r
d80ed2a7 380 @retval EFI_UNSUPPORTED No matching transport protocol is found.\r
d7db0902 381 @retval Others Failed to initialize dev.\r
cc5166ff 382\r
383**/\r
c7e39923 384EFI_STATUS\r
385UsbMassInitTransport (\r
386 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
387 IN EFI_HANDLE Controller,\r
388 OUT USB_MASS_TRANSPORT **Transport,\r
389 OUT VOID **Context,\r
390 OUT UINT8 *MaxLun\r
391 )\r
392{\r
393 EFI_USB_IO_PROTOCOL *UsbIo;\r
394 EFI_USB_INTERFACE_DESCRIPTOR Interface;\r
395 UINT8 Index;\r
396 EFI_STATUS Status;\r
397 \r
398 Status = gBS->OpenProtocol (\r
399 Controller,\r
400 &gEfiUsbIoProtocolGuid,\r
b16b8bf9 401 (VOID **) &UsbIo,\r
c7e39923 402 This->DriverBindingHandle,\r
403 Controller,\r
404 EFI_OPEN_PROTOCOL_BY_DRIVER\r
405 );\r
406\r
407 if (EFI_ERROR (Status)) {\r
c7e39923 408 return Status;\r
409 }\r
410 \r
411 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);\r
412 if (EFI_ERROR (Status)) {\r
c7e39923 413 goto ON_EXIT;\r
414 }\r
415 \r
416 Status = EFI_UNSUPPORTED;\r
417\r
d80ed2a7 418 //\r
419 // Traverse the USB_MASS_TRANSPORT arrary and try to find the\r
420 // matching transport protocol.\r
421 // If not found, return EFI_UNSUPPORTED.\r
422 // If found, execute USB_MASS_TRANSPORT.Init() to initialize the transport context.\r
423 //\r
db0bd81c 424 for (Index = 0; Index < USB_MASS_TRANSPORT_COUNT; Index++) {\r
c7e39923 425 *Transport = mUsbMassTransport[Index];\r
426\r
427 if (Interface.InterfaceProtocol == (*Transport)->Protocol) {\r
428 Status = (*Transport)->Init (UsbIo, Context);\r
429 break;\r
430 }\r
431 }\r
432\r
433 if (EFI_ERROR (Status)) {\r
c7e39923 434 goto ON_EXIT;\r
435 }\r
436\r
437 //\r
d80ed2a7 438 // For BOT device, try to get its max LUN. \r
439 // If max LUN is 0, then it is a non-lun device.\r
440 // Otherwise, it is a multi-lun device.\r
c7e39923 441 //\r
442 if ((*Transport)->Protocol == USB_MASS_STORE_BOT) {\r
443 (*Transport)->GetMaxLun (*Context, MaxLun);\r
c7e39923 444 }\r
445\r
446ON_EXIT:\r
447 gBS->CloseProtocol (\r
448 Controller,\r
449 &gEfiUsbIoProtocolGuid,\r
450 This->DriverBindingHandle,\r
451 Controller\r
452 );\r
453 return Status; \r
454}\r
455\r
cc5166ff 456/**\r
3e03cb4d 457 Initialize data for device that supports multiple LUNSs.\r
cc5166ff 458\r
3e03cb4d 459 @param This The Driver Binding Protocol instance.\r
460 @param Controller The device to initialize.\r
461 @param Transport Pointer to USB_MASS_TRANSPORT.\r
462 @param Context Parameter for USB_MASS_DEVICE.Context.\r
463 @param DevicePath The remaining device path.\r
464 @param MaxLun The max LUN number.\r
cc5166ff 465\r
3e03cb4d 466 @retval EFI_SUCCESS At least one LUN is initialized successfully.\r
66a5771e 467 @retval EFI_NOT_FOUND Fail to initialize any of multiple LUNs.\r
cc5166ff 468\r
469**/\r
c7e39923 470EFI_STATUS\r
471UsbMassInitMultiLun (\r
3e03cb4d 472 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
c7e39923 473 IN EFI_HANDLE Controller,\r
474 IN USB_MASS_TRANSPORT *Transport,\r
475 IN VOID *Context,\r
476 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
477 IN UINT8 MaxLun\r
478 )\r
479{\r
480 USB_MASS_DEVICE *UsbMass;\r
481 EFI_USB_IO_PROTOCOL *UsbIo;\r
482 DEVICE_LOGICAL_UNIT_DEVICE_PATH LunNode;\r
483 UINT8 Index;\r
484 EFI_STATUS Status;\r
66a5771e 485 EFI_STATUS ReturnStatus;\r
c7e39923 486\r
487 ASSERT (MaxLun > 0);\r
66a5771e 488 ReturnStatus = EFI_NOT_FOUND;\r
c7e39923 489\r
490 for (Index = 0; Index <= MaxLun; Index++) { \r
491\r
492 DEBUG ((EFI_D_INFO, "UsbMassInitMultiLun: Start to initialize No.%d logic unit\n", Index));\r
493 \r
494 UsbIo = NULL;\r
495 UsbMass = AllocateZeroPool (sizeof (USB_MASS_DEVICE));\r
3e03cb4d 496 ASSERT (UsbMass != NULL);\r
c7e39923 497 \r
498 UsbMass->Signature = USB_MASS_SIGNATURE;\r
499 UsbMass->UsbIo = UsbIo;\r
500 UsbMass->BlockIo.Media = &UsbMass->BlockIoMedia;\r
501 UsbMass->BlockIo.Reset = UsbMassReset;\r
502 UsbMass->BlockIo.ReadBlocks = UsbMassReadBlocks;\r
503 UsbMass->BlockIo.WriteBlocks = UsbMassWriteBlocks;\r
504 UsbMass->BlockIo.FlushBlocks = UsbMassFlushBlocks;\r
505 UsbMass->OpticalStorage = FALSE;\r
506 UsbMass->Transport = Transport;\r
507 UsbMass->Context = Context;\r
508 UsbMass->Lun = Index;\r
509 \r
510 //\r
3e03cb4d 511 // Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.\r
c7e39923 512 //\r
513 Status = UsbMassInitMedia (UsbMass);\r
66a5771e 514 if ((EFI_ERROR (Status)) && (Status != EFI_NO_MEDIA)) {\r
c7e39923 515 DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: UsbMassInitMedia (%r)\n", Status));\r
66a5771e
TF
516 FreePool (UsbMass);\r
517 continue;\r
c7e39923 518 }\r
519\r
520 //\r
3e03cb4d 521 // Create a device path node for device logic unit, and append it.\r
c7e39923 522 //\r
523 LunNode.Header.Type = MESSAGING_DEVICE_PATH;\r
524 LunNode.Header.SubType = MSG_DEVICE_LOGICAL_UNIT_DP;\r
525 LunNode.Lun = UsbMass->Lun;\r
526 \r
527 SetDevicePathNodeLength (&LunNode.Header, sizeof (LunNode));\r
528 \r
529 UsbMass->DevicePath = AppendDevicePathNode (DevicePath, &LunNode.Header);\r
530 \r
531 if (UsbMass->DevicePath == NULL) {\r
532 DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: failed to create device logic unit device path\n"));\r
c7e39923 533 Status = EFI_OUT_OF_RESOURCES;\r
66a5771e
TF
534 FreePool (UsbMass);\r
535 continue;\r
c7e39923 536 }\r
537\r
39840c50 538 InitializeDiskInfo (UsbMass);\r
539\r
c7e39923 540 //\r
3e03cb4d 541 // Create a new handle for each LUN, and install Block I/O Protocol and Device Path Protocol.\r
c7e39923 542 //\r
543 Status = gBS->InstallMultipleProtocolInterfaces (\r
544 &UsbMass->Controller,\r
545 &gEfiDevicePathProtocolGuid,\r
546 UsbMass->DevicePath,\r
547 &gEfiBlockIoProtocolGuid,\r
548 &UsbMass->BlockIo,\r
39840c50 549 &gEfiDiskInfoProtocolGuid,\r
550 &UsbMass->DiskInfo,\r
c7e39923 551 NULL\r
552 );\r
553 \r
554 if (EFI_ERROR (Status)) {\r
555 DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: InstallMultipleProtocolInterfaces (%r)\n", Status));\r
66a5771e
TF
556 FreePool (UsbMass->DevicePath);\r
557 FreePool (UsbMass);\r
558 continue;\r
c7e39923 559 }\r
560\r
561 //\r
3e03cb4d 562 // Open USB I/O Protocol by child to setup a parent-child relationship.\r
c7e39923 563 //\r
564 Status = gBS->OpenProtocol (\r
565 Controller,\r
566 &gEfiUsbIoProtocolGuid,\r
b16b8bf9 567 (VOID **) &UsbIo,\r
c7e39923 568 This->DriverBindingHandle,\r
569 UsbMass->Controller,\r
570 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
571 );\r
572\r
573 if (EFI_ERROR (Status)) {\r
574 DEBUG ((EFI_D_ERROR, "UsbMassInitMultiLun: OpenUsbIoProtocol By Child (%r)\n", Status));\r
575 gBS->UninstallMultipleProtocolInterfaces (\r
576 &UsbMass->Controller,\r
577 &gEfiDevicePathProtocolGuid,\r
578 UsbMass->DevicePath,\r
579 &gEfiBlockIoProtocolGuid,\r
580 &UsbMass->BlockIo,\r
39840c50 581 &gEfiDiskInfoProtocolGuid,\r
582 &UsbMass->DiskInfo,\r
c7e39923 583 NULL\r
584 );\r
66a5771e
TF
585 FreePool (UsbMass->DevicePath);\r
586 FreePool (UsbMass);\r
587 continue;\r
c7e39923 588 }\r
66a5771e 589 ReturnStatus = EFI_SUCCESS;\r
c7e39923 590 DEBUG ((EFI_D_INFO, "UsbMassInitMultiLun: Success to initialize No.%d logic unit\n", Index));\r
591 }\r
592 \r
66a5771e 593 return ReturnStatus;\r
c7e39923 594}\r
595\r
cc5166ff 596/**\r
3e03cb4d 597 Initialize data for device that does not support multiple LUNSs.\r
cc5166ff 598\r
3e03cb4d 599 @param This The Driver Binding Protocol instance.\r
600 @param Controller The device to initialize.\r
601 @param Transport Pointer to USB_MASS_TRANSPORT.\r
602 @param Context Parameter for USB_MASS_DEVICE.Context.\r
cc5166ff 603\r
3e03cb4d 604 @retval EFI_SUCCESS Initialization succeeds.\r
cc5166ff 605 @retval Other Initialization fails.\r
606\r
607**/\r
c7e39923 608EFI_STATUS\r
609UsbMassInitNonLun (\r
610 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
611 IN EFI_HANDLE Controller,\r
612 IN USB_MASS_TRANSPORT *Transport,\r
613 IN VOID *Context\r
614 )\r
615{\r
616 USB_MASS_DEVICE *UsbMass;\r
617 EFI_USB_IO_PROTOCOL *UsbIo;\r
618 EFI_STATUS Status;\r
619\r
620 UsbIo = NULL;\r
621 UsbMass = AllocateZeroPool (sizeof (USB_MASS_DEVICE));\r
3e03cb4d 622 ASSERT (UsbMass != NULL);\r
623\r
c7e39923 624 Status = gBS->OpenProtocol (\r
625 Controller,\r
626 &gEfiUsbIoProtocolGuid,\r
b16b8bf9 627 (VOID **) &UsbIo,\r
c7e39923 628 This->DriverBindingHandle,\r
629 Controller,\r
630 EFI_OPEN_PROTOCOL_BY_DRIVER\r
631 );\r
632\r
633 if (EFI_ERROR (Status)) {\r
634 DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: OpenUsbIoProtocol By Driver (%r)\n", Status));\r
635 goto ON_ERROR;\r
636 }\r
637 \r
638 UsbMass->Signature = USB_MASS_SIGNATURE;\r
639 UsbMass->Controller = Controller;\r
640 UsbMass->UsbIo = UsbIo;\r
641 UsbMass->BlockIo.Media = &UsbMass->BlockIoMedia;\r
642 UsbMass->BlockIo.Reset = UsbMassReset;\r
643 UsbMass->BlockIo.ReadBlocks = UsbMassReadBlocks;\r
644 UsbMass->BlockIo.WriteBlocks = UsbMassWriteBlocks;\r
645 UsbMass->BlockIo.FlushBlocks = UsbMassFlushBlocks;\r
646 UsbMass->OpticalStorage = FALSE;\r
647 UsbMass->Transport = Transport;\r
648 UsbMass->Context = Context;\r
649 \r
650 //\r
3e03cb4d 651 // Initialize the media parameter data for EFI_BLOCK_IO_MEDIA of Block I/O Protocol.\r
c7e39923 652 //\r
653 Status = UsbMassInitMedia (UsbMass);\r
66a5771e 654 if ((EFI_ERROR (Status)) && (Status != EFI_NO_MEDIA)) {\r
c7e39923 655 DEBUG ((EFI_D_ERROR, "UsbMassInitNonLun: UsbMassInitMedia (%r)\n", Status));\r
656 goto ON_ERROR;\r
657 }\r
658 \r
39840c50 659 InitializeDiskInfo (UsbMass);\r
660\r
661 Status = gBS->InstallMultipleProtocolInterfaces (\r
c7e39923 662 &Controller,\r
663 &gEfiBlockIoProtocolGuid,\r
39840c50 664 &UsbMass->BlockIo,\r
665 &gEfiDiskInfoProtocolGuid,\r
666 &UsbMass->DiskInfo,\r
667 NULL\r
c7e39923 668 );\r
669 if (EFI_ERROR (Status)) {\r
670 goto ON_ERROR;\r
671 }\r
672\r
673 return EFI_SUCCESS;\r
674\r
675ON_ERROR:\r
676 if (UsbMass != NULL) {\r
3e03cb4d 677 FreePool (UsbMass);\r
c7e39923 678 }\r
73f8ef8c 679 if (UsbIo != NULL) {\r
680 gBS->CloseProtocol (\r
681 Controller,\r
682 &gEfiUsbIoProtocolGuid,\r
683 This->DriverBindingHandle,\r
684 Controller\r
685 );\r
686 }\r
c7e39923 687 return Status; \r
688}\r
689\r
e237e7ae 690\r
691/**\r
692 Check whether the controller is a supported USB mass storage.\r
693\r
d80ed2a7 694 @param This The USB mass storage driver binding protocol.\r
695 @param Controller The controller handle to check.\r
696 @param RemainingDevicePath The remaining device path.\r
e237e7ae 697\r
d80ed2a7 698 @retval EFI_SUCCESS The driver supports this controller.\r
699 @retval other This device isn't supported.\r
e237e7ae 700\r
701**/\r
702EFI_STATUS\r
703EFIAPI\r
704USBMassDriverBindingSupported (\r
705 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
706 IN EFI_HANDLE Controller,\r
707 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
708 )\r
709{\r
710 EFI_USB_IO_PROTOCOL *UsbIo;\r
711 EFI_USB_INTERFACE_DESCRIPTOR Interface;\r
712 USB_MASS_TRANSPORT *Transport;\r
713 EFI_STATUS Status;\r
d80ed2a7 714 UINTN Index;\r
e237e7ae 715\r
e237e7ae 716 Status = gBS->OpenProtocol (\r
717 Controller,\r
718 &gEfiUsbIoProtocolGuid,\r
c52fa98c 719 (VOID **) &UsbIo,\r
e237e7ae 720 This->DriverBindingHandle,\r
721 Controller,\r
722 EFI_OPEN_PROTOCOL_BY_DRIVER\r
723 );\r
724 if (EFI_ERROR (Status)) {\r
725 return Status;\r
726 }\r
727\r
728 //\r
d80ed2a7 729 // Get the interface descriptor to check the USB class and find a transport\r
e237e7ae 730 // protocol handler.\r
731 //\r
732 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);\r
733 if (EFI_ERROR (Status)) {\r
734 goto ON_EXIT;\r
735 }\r
736\r
737 Status = EFI_UNSUPPORTED;\r
738\r
739 if (Interface.InterfaceClass != USB_MASS_STORE_CLASS) {\r
740 goto ON_EXIT;\r
741 }\r
742\r
d80ed2a7 743 //\r
744 // Traverse the USB_MASS_TRANSPORT arrary and try to find the\r
745 // matching transport method.\r
746 // If not found, return EFI_UNSUPPORTED.\r
747 // If found, execute USB_MASS_TRANSPORT.Init() to initialize the transport context.\r
748 //\r
db0bd81c 749 for (Index = 0; Index < USB_MASS_TRANSPORT_COUNT; Index++) {\r
e237e7ae 750 Transport = mUsbMassTransport[Index];\r
751 if (Interface.InterfaceProtocol == Transport->Protocol) {\r
c7e39923 752 Status = Transport->Init (UsbIo, NULL);\r
e237e7ae 753 break;\r
754 }\r
755 }\r
756\r
e237e7ae 757ON_EXIT:\r
758 gBS->CloseProtocol (\r
d80ed2a7 759 Controller,\r
760 &gEfiUsbIoProtocolGuid,\r
761 This->DriverBindingHandle,\r
762 Controller\r
763 );\r
e237e7ae 764\r
765 return Status;\r
766}\r
767\r
e237e7ae 768/**\r
d80ed2a7 769 Starts the USB mass storage device with this driver.\r
e237e7ae 770\r
d80ed2a7 771 This function consumes USB I/O Portocol, intializes USB mass storage device,\r
772 installs Block I/O Protocol, and submits Asynchronous Interrupt\r
773 Transfer to manage the USB mass storage device.\r
774\r
3e03cb4d 775 @param This The USB mass storage driver binding protocol.\r
776 @param Controller The USB mass storage device to start on\r
777 @param RemainingDevicePath The remaining device path.\r
e237e7ae 778\r
d80ed2a7 779 @retval EFI_SUCCESS This driver supports this device.\r
780 @retval EFI_UNSUPPORTED This driver does not support this device.\r
781 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.\r
782 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.\r
783 @retval EFI_ALREADY_STARTED This driver has been started.\r
e237e7ae 784\r
785**/\r
786EFI_STATUS\r
787EFIAPI\r
788USBMassDriverBindingStart (\r
789 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
790 IN EFI_HANDLE Controller,\r
791 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
792 )\r
793{\r
e237e7ae 794 USB_MASS_TRANSPORT *Transport;\r
c7e39923 795 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
796 VOID *Context;\r
797 UINT8 MaxLun;\r
e237e7ae 798 EFI_STATUS Status;\r
73f8ef8c 799 EFI_USB_IO_PROTOCOL *UsbIo; \r
15cc67e6 800 EFI_TPL OldTpl;\r
801\r
802 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
803\r
c7e39923 804 Transport = NULL;\r
805 Context = NULL;\r
806 MaxLun = 0;\r
e237e7ae 807\r
c7e39923 808 Status = UsbMassInitTransport (This, Controller, &Transport, &Context, &MaxLun);\r
e237e7ae 809\r
810 if (EFI_ERROR (Status)) {\r
c7e39923 811 DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitTransport (%r)\n", Status));\r
15cc67e6 812 goto Exit;\r
e237e7ae 813 }\r
c7e39923 814 if (MaxLun == 0) {\r
815 //\r
3e03cb4d 816 // Initialize data for device that does not support multiple LUNSs.\r
c7e39923 817 //\r
3e03cb4d 818 Status = UsbMassInitNonLun (This, Controller, Transport, Context);\r
c7e39923 819 if (EFI_ERROR (Status)) { \r
820 DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitNonLun (%r)\n", Status));\r
821 }\r
822 } else {\r
823 //\r
3e03cb4d 824 // Open device path to prepare for appending Device Logic Unit node.\r
c7e39923 825 //\r
826 Status = gBS->OpenProtocol (\r
827 Controller,\r
828 &gEfiDevicePathProtocolGuid,\r
829 (VOID **) &DevicePath,\r
830 This->DriverBindingHandle,\r
831 Controller,\r
832 EFI_OPEN_PROTOCOL_BY_DRIVER\r
833 );\r
834 \r
835 if (EFI_ERROR (Status)) {\r
836 DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: OpenDevicePathProtocol By Driver (%r)\n", Status));\r
15cc67e6 837 goto Exit;\r
e237e7ae 838 }\r
e237e7ae 839\r
73f8ef8c 840 Status = gBS->OpenProtocol (\r
841 Controller,\r
842 &gEfiUsbIoProtocolGuid,\r
843 (VOID **) &UsbIo,\r
844 This->DriverBindingHandle,\r
845 Controller,\r
846 EFI_OPEN_PROTOCOL_BY_DRIVER\r
847 );\r
848 \r
849 if (EFI_ERROR (Status)) {\r
850 DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: OpenUsbIoProtocol By Driver (%r)\n", Status));\r
851 gBS->CloseProtocol (\r
852 Controller,\r
853 &gEfiDevicePathProtocolGuid,\r
854 This->DriverBindingHandle,\r
855 Controller\r
856 );\r
15cc67e6 857 goto Exit;\r
73f8ef8c 858 }\r
859\r
c7e39923 860 //\r
66a5771e 861 // Initialize data for device that supports multiple LUNs.\r
3e03cb4d 862 // EFI_SUCCESS is returned if at least 1 LUN is initialized successfully.\r
c7e39923 863 //\r
d80ed2a7 864 Status = UsbMassInitMultiLun (This, Controller, Transport, Context, DevicePath, MaxLun);\r
c7e39923 865 if (EFI_ERROR (Status)) {\r
73f8ef8c 866 gBS->CloseProtocol (\r
867 Controller,\r
868 &gEfiDevicePathProtocolGuid,\r
869 This->DriverBindingHandle,\r
870 Controller\r
871 );\r
872 gBS->CloseProtocol (\r
873 Controller,\r
874 &gEfiUsbIoProtocolGuid,\r
875 This->DriverBindingHandle,\r
876 Controller\r
877 );\r
c7e39923 878 DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitMultiLun (%r) with Maxlun=%d\n", Status, MaxLun));\r
879 }\r
e237e7ae 880 }\r
15cc67e6 881Exit:\r
882 gBS->RestoreTPL (OldTpl);\r
e237e7ae 883 return Status;\r
884}\r
885\r
886\r
887/**\r
888 Stop controlling the device.\r
889\r
890 @param This The USB mass storage driver binding\r
891 @param Controller The device controller controlled by the driver.\r
892 @param NumberOfChildren The number of children of this device\r
893 @param ChildHandleBuffer The buffer of children handle.\r
894\r
895 @retval EFI_SUCCESS The driver stopped from controlling the device.\r
3e03cb4d 896 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
897 @retval EFI_UNSUPPORTED Block I/O Protocol is not installed on Controller.\r
e237e7ae 898 @retval Others Failed to stop the driver\r
899\r
900**/\r
901EFI_STATUS\r
902EFIAPI\r
903USBMassDriverBindingStop (\r
904 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
905 IN EFI_HANDLE Controller,\r
906 IN UINTN NumberOfChildren,\r
907 IN EFI_HANDLE *ChildHandleBuffer\r
908 )\r
909{\r
910 EFI_STATUS Status;\r
911 USB_MASS_DEVICE *UsbMass;\r
3e03cb4d 912 EFI_USB_IO_PROTOCOL *UsbIo;\r
e237e7ae 913 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
3e03cb4d 914 UINTN Index;\r
915 BOOLEAN AllChildrenStopped;\r
c7e39923 916\r
917 //\r
3e03cb4d 918 // This is a bus driver stop function since multi-lun is supported.\r
919 // There are three kinds of device handles that might be passed:\r
73f8ef8c 920 // 1st is a handle with USB I/O & Block I/O installed (non-multi-lun)\r
3e03cb4d 921 // 2nd is a handle with Device Path & USB I/O installed (multi-lun root)\r
73f8ef8c 922 // 3rd is a handle with Device Path & USB I/O & Block I/O installed (multi-lun).\r
c7e39923 923 //\r
924 if (NumberOfChildren == 0) {\r
925 //\r
926 // A handle without any children, might be 1st and 2nd type.\r
927 //\r
928 Status = gBS->OpenProtocol (\r
929 Controller,\r
930 &gEfiBlockIoProtocolGuid,\r
b16b8bf9 931 (VOID **) &BlockIo,\r
c7e39923 932 This->DriverBindingHandle,\r
933 Controller,\r
934 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
935 );\r
936 \r
937 if (EFI_ERROR(Status)) {\r
938 //\r
73f8ef8c 939 // This is a 2nd type handle(multi-lun root), it needs to close devicepath\r
940 // and usbio protocol.\r
c7e39923 941 //\r
942 gBS->CloseProtocol (\r
943 Controller,\r
944 &gEfiDevicePathProtocolGuid,\r
945 This->DriverBindingHandle,\r
946 Controller\r
947 );\r
73f8ef8c 948 gBS->CloseProtocol (\r
949 Controller,\r
950 &gEfiUsbIoProtocolGuid,\r
951 This->DriverBindingHandle,\r
952 Controller\r
953 );\r
c7e39923 954 DEBUG ((EFI_D_INFO, "Success to stop multi-lun root handle\n"));\r
955 return EFI_SUCCESS;\r
956 }\r
957 \r
958 //\r
3e03cb4d 959 // This is a 1st type handle(non-multi-lun), which only needs to uninstall\r
960 // Block I/O Protocol, close USB I/O Protocol and free mass device.\r
c7e39923 961 //\r
d80ed2a7 962 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlockIo);\r
c7e39923 963 \r
964 //\r
965 // Uninstall Block I/O protocol from the device handle,\r
966 // then call the transport protocol to stop itself.\r
967 //\r
39840c50 968 Status = gBS->UninstallMultipleProtocolInterfaces (\r
c7e39923 969 Controller,\r
970 &gEfiBlockIoProtocolGuid,\r
39840c50 971 &UsbMass->BlockIo,\r
972 &gEfiDiskInfoProtocolGuid,\r
973 &UsbMass->DiskInfo,\r
974 NULL\r
c7e39923 975 );\r
976 if (EFI_ERROR (Status)) {\r
977 return Status;\r
978 }\r
979 \r
980 gBS->CloseProtocol (\r
981 Controller,\r
982 &gEfiUsbIoProtocolGuid,\r
983 This->DriverBindingHandle,\r
984 Controller\r
985 );\r
986 \r
d80ed2a7 987 UsbMass->Transport->CleanUp (UsbMass->Context);\r
3e03cb4d 988 FreePool (UsbMass);\r
c7e39923 989 \r
990 DEBUG ((EFI_D_INFO, "Success to stop non-multi-lun root handle\n"));\r
991 return EFI_SUCCESS;\r
992 } \r
993\r
994 //\r
995 // This is a 3rd type handle(multi-lun), which needs uninstall\r
3e03cb4d 996 // Block I/O Protocol and Device Path Protocol, close USB I/O Protocol and \r
997 // free mass device for all children.\r
c7e39923 998 //\r
999 AllChildrenStopped = TRUE;\r
1000\r
1001 for (Index = 0; Index < NumberOfChildren; Index++) {\r
1002\r
1003 Status = gBS->OpenProtocol (\r
1004 ChildHandleBuffer[Index],\r
1005 &gEfiBlockIoProtocolGuid,\r
1006 (VOID **) &BlockIo,\r
1007 This->DriverBindingHandle,\r
1008 Controller,\r
1009 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1010 );\r
1011 if (EFI_ERROR (Status)) {\r
1012 AllChildrenStopped = FALSE;\r
7df7393f 1013 DEBUG ((EFI_D_ERROR, "Fail to stop No.%d multi-lun child handle when opening blockio\n", (UINT32)Index));\r
c7e39923 1014 continue;\r
1015 }\r
e237e7ae 1016\r
d80ed2a7 1017 UsbMass = USB_MASS_DEVICE_FROM_BLOCK_IO (BlockIo);\r
c7e39923 1018\r
1019 gBS->CloseProtocol (\r
3e03cb4d 1020 Controller,\r
1021 &gEfiUsbIoProtocolGuid,\r
1022 This->DriverBindingHandle,\r
1023 ChildHandleBuffer[Index]\r
1024 );\r
c7e39923 1025 \r
1026 Status = gBS->UninstallMultipleProtocolInterfaces (\r
1027 ChildHandleBuffer[Index],\r
1028 &gEfiDevicePathProtocolGuid,\r
1029 UsbMass->DevicePath,\r
1030 &gEfiBlockIoProtocolGuid,\r
1031 &UsbMass->BlockIo,\r
39840c50 1032 &gEfiDiskInfoProtocolGuid,\r
1033 &UsbMass->DiskInfo,\r
c7e39923 1034 NULL\r
1035 );\r
1036 \r
1037 if (EFI_ERROR (Status)) {\r
1038 //\r
3e03cb4d 1039 // Fail to uninstall Block I/O Protocol and Device Path Protocol, so re-open USB I/O Protocol by child.\r
c7e39923 1040 //\r
1041 AllChildrenStopped = FALSE;\r
7df7393f 1042 DEBUG ((EFI_D_ERROR, "Fail to stop No.%d multi-lun child handle when uninstalling blockio and devicepath\n", (UINT32)Index));\r
c7e39923 1043 \r
1044 gBS->OpenProtocol (\r
1045 Controller,\r
1046 &gEfiUsbIoProtocolGuid,\r
b16b8bf9 1047 (VOID **) &UsbIo,\r
c7e39923 1048 This->DriverBindingHandle,\r
1049 ChildHandleBuffer[Index],\r
1050 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
1051 );\r
1052 } else {\r
1053 //\r
3e03cb4d 1054 // Succeed to stop this multi-lun handle, so go on with next child.\r
c7e39923 1055 //\r
1056 if (((Index + 1) == NumberOfChildren) && AllChildrenStopped) {\r
d80ed2a7 1057 UsbMass->Transport->CleanUp (UsbMass->Context);\r
c7e39923 1058 }\r
3e03cb4d 1059 FreePool (UsbMass);\r
c7e39923 1060 }\r
e237e7ae 1061 }\r
1062\r
c7e39923 1063 if (!AllChildrenStopped) {\r
1064 return EFI_DEVICE_ERROR;\r
e237e7ae 1065 }\r
c7e39923 1066 \r
3e03cb4d 1067 DEBUG ((EFI_D_INFO, "Success to stop all %d multi-lun children handles\n", (UINT32) NumberOfChildren));\r
e237e7ae 1068 return EFI_SUCCESS;\r
1069}\r
1070\r
cc5166ff 1071/**\r
3e03cb4d 1072 Entrypoint of USB Mass Storage Driver.\r
1073\r
1074 This function is the entrypoint of USB Mass Storage Driver. It installs Driver Binding\r
1075 Protocol together with Component Name Protocols.\r
cc5166ff 1076\r
3e03cb4d 1077 @param ImageHandle The firmware allocated handle for the EFI image.\r
1078 @param SystemTable A pointer to the EFI System Table.\r
cc5166ff 1079\r
3e03cb4d 1080 @retval EFI_SUCCESS The entry point is executed successfully.\r
cc5166ff 1081\r
1082**/\r
e237e7ae 1083EFI_STATUS\r
1084EFIAPI\r
1085USBMassStorageEntryPoint (\r
1086 IN EFI_HANDLE ImageHandle,\r
1087 IN EFI_SYSTEM_TABLE *SystemTable\r
1088 )\r
e237e7ae 1089{\r
1090 EFI_STATUS Status;\r
1091\r
1092 //\r
1093 // Install driver binding protocol\r
1094 //\r
62b9bb55 1095 Status = EfiLibInstallDriverBindingComponentName2 (\r
e237e7ae 1096 ImageHandle,\r
1097 SystemTable,\r
1098 &gUSBMassDriverBinding,\r
1099 ImageHandle,\r
1100 &gUsbMassStorageComponentName,\r
62b9bb55 1101 &gUsbMassStorageComponentName2\r
e237e7ae 1102 );\r
d80ed2a7 1103 ASSERT_EFI_ERROR (Status);\r
e237e7ae 1104\r
d80ed2a7 1105 return EFI_SUCCESS;\r
e237e7ae 1106}\r