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