Initial import.
[mirror_edk2.git] / EdkModulePkg / Bus / Usb / UsbMassStorage / Dxe / UsbMassStorage.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 UsbMassStorage.c\r
15 \r
16Abstract:\r
17\r
18 USB Mass Storage Driver\r
19\r
20Revision History\r
21\r
22--*/\r
23\r
24#include "UsbMassStorage.h"\r
25#include "UsbMassStorageHelper.h"\r
26\r
27extern EFI_COMPONENT_NAME_PROTOCOL gUsbMassStorageComponentName;\r
28\r
29//\r
30// Prototypes\r
31// Driver model protocol interface\r
32//\r
33EFI_STATUS\r
34EFIAPI\r
35USBMassStorageDriverBindingEntryPoint (\r
36 IN EFI_HANDLE ImageHandle,\r
37 IN EFI_SYSTEM_TABLE *SystemTable\r
38 );\r
39\r
40EFI_STATUS\r
41EFIAPI\r
42USBFloppyDriverBindingSupported (\r
43 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
44 IN EFI_HANDLE Controller,\r
45 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
46 );\r
47\r
48EFI_STATUS\r
49EFIAPI\r
50USBFloppyDriverBindingStart (\r
51 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
52 IN EFI_HANDLE Controller,\r
53 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
54 );\r
55\r
56EFI_STATUS\r
57EFIAPI\r
58USBFloppyDriverBindingStop (\r
59 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
60 IN EFI_HANDLE Controller,\r
61 IN UINTN NumberOfChildren,\r
62 IN EFI_HANDLE *ChildHandleBuffer\r
63 );\r
64\r
65//\r
66// Block I/O Protocol Interface\r
67//\r
68STATIC\r
69EFI_STATUS\r
70EFIAPI\r
71USBFloppyReset (\r
72 IN EFI_BLOCK_IO_PROTOCOL *This,\r
73 IN BOOLEAN ExtendedVerification\r
74 );\r
75\r
76STATIC\r
77EFI_STATUS\r
78EFIAPI\r
79USBFloppyReadBlocks (\r
80 IN EFI_BLOCK_IO_PROTOCOL *This,\r
81 IN UINT32 MediaId,\r
82 IN EFI_LBA LBA,\r
83 IN UINTN BufferSize,\r
84 OUT VOID *Buffer\r
85 );\r
86\r
87STATIC\r
88EFI_STATUS\r
89EFIAPI\r
90USBFloppyWriteBlocks (\r
91 IN EFI_BLOCK_IO_PROTOCOL *This,\r
92 IN UINT32 MediaId,\r
93 IN EFI_LBA LBA,\r
94 IN UINTN BufferSize,\r
95 IN VOID *Buffer\r
96 );\r
97\r
98STATIC\r
99EFI_STATUS\r
100EFIAPI\r
101USBFloppyFlushBlocks (\r
102 IN EFI_BLOCK_IO_PROTOCOL *This\r
103 );\r
104\r
105//\r
106// USB Floppy Driver Global Variables\r
107//\r
108EFI_DRIVER_BINDING_PROTOCOL gUSBFloppyDriverBinding = {\r
109 USBFloppyDriverBindingSupported,\r
110 USBFloppyDriverBindingStart,\r
111 USBFloppyDriverBindingStop,\r
112 0x10,\r
113 NULL,\r
114 NULL\r
115};\r
116\r
117EFI_STATUS\r
118EFIAPI\r
119USBFloppyDriverBindingSupported (\r
120 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
121 IN EFI_HANDLE Controller,\r
122 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
123 )\r
124/*++\r
125\r
126 Routine Description:\r
127 Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
128 that has UsbHcProtocol installed will be supported.\r
129\r
130 Arguments:\r
131 This - Protocol instance pointer.\r
132 Controller - Handle of device to test\r
133 RemainingDevicePath - Not used\r
134\r
135 Returns:\r
136 EFI_SUCCESS - This driver supports this device.\r
137 EFI_UNSUPPORTED - This driver does not support this device.\r
138\r
139--*/\r
140{\r
141 EFI_STATUS OpenStatus;\r
142 EFI_USB_ATAPI_PROTOCOL *AtapiProtocol;\r
143\r
144 //\r
145 // check whether EFI_USB_ATAPI_PROTOCOL exists, if it does,\r
146 // then the controller must be a USB Mass Storage Controller\r
147 //\r
148 OpenStatus = gBS->OpenProtocol (\r
149 Controller,\r
150 &gEfiUsbAtapiProtocolGuid,\r
151 (VOID **) &AtapiProtocol,\r
152 This->DriverBindingHandle,\r
153 Controller,\r
154 EFI_OPEN_PROTOCOL_BY_DRIVER\r
155 );\r
156 if (EFI_ERROR (OpenStatus)) {\r
157 return OpenStatus;\r
158 }\r
159\r
160 gBS->CloseProtocol (\r
161 Controller,\r
162 &gEfiUsbAtapiProtocolGuid,\r
163 This->DriverBindingHandle,\r
164 Controller\r
165 );\r
166\r
167 return EFI_SUCCESS;\r
168}\r
169\r
170EFI_STATUS\r
171EFIAPI\r
172USBFloppyDriverBindingStart (\r
173 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
174 IN EFI_HANDLE Controller,\r
175 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
176 )\r
177/*++\r
178\r
179 Routine Description:\r
180 Starting the Usb Bus Driver\r
181\r
182 Arguments:\r
183 This - Protocol instance pointer.\r
184 Controller - Handle of device to test\r
185 RemainingDevicePath - Not used\r
186\r
187 Returns:\r
188 EFI_SUCCESS - This driver supports this device.\r
189 EFI_UNSUPPORTED - This driver does not support this device.\r
190 EFI_DEVICE_ERROR - This driver cannot be started due to device\r
191 Error\r
192 EFI_OUT_OF_RESOURCES- Can't allocate memory resources\r
193 EFI_ALREADY_STARTED - Thios driver has been started\r
194--*/\r
195{ \r
196 EFI_STATUS Status; \r
197 EFI_USB_ATAPI_PROTOCOL *AtapiProtocol;\r
198 USB_FLOPPY_DEV *UsbFloppyDevice;\r
199 \r
200 UsbFloppyDevice = NULL;\r
201 //\r
202 // Check whether Usb Atapi Protocol attached on the controller handle.\r
203 //\r
204 Status = gBS->OpenProtocol (\r
205 Controller,\r
206 &gEfiUsbAtapiProtocolGuid,\r
207 (VOID **) &AtapiProtocol,\r
208 This->DriverBindingHandle,\r
209 Controller,\r
210 EFI_OPEN_PROTOCOL_BY_DRIVER\r
211 );\r
212 if (EFI_ERROR (Status)) {\r
213 return Status;\r
214 }\r
215\r
216 Status = gBS->AllocatePool (\r
217 EfiBootServicesData,\r
218 sizeof (USB_FLOPPY_DEV),\r
219 (VOID **) &UsbFloppyDevice\r
220 );\r
221 if (EFI_ERROR (Status)) {\r
222 gBS->CloseProtocol (\r
223 Controller,\r
224 &gEfiUsbAtapiProtocolGuid,\r
225 This->DriverBindingHandle,\r
226 Controller\r
227 );\r
228 return Status;\r
229 }\r
230\r
231 ZeroMem (UsbFloppyDevice, sizeof (USB_FLOPPY_DEV));\r
232\r
233 UsbFloppyDevice->Handle = Controller;\r
234 UsbFloppyDevice->BlkIo.Media = &UsbFloppyDevice->BlkMedia;\r
235 UsbFloppyDevice->Signature = USB_FLOPPY_DEV_SIGNATURE;\r
236 UsbFloppyDevice->BlkIo.Reset = USBFloppyReset;\r
237 UsbFloppyDevice->BlkIo.ReadBlocks = USBFloppyReadBlocks;\r
238 UsbFloppyDevice->BlkIo.WriteBlocks = USBFloppyWriteBlocks;\r
239 UsbFloppyDevice->BlkIo.FlushBlocks = USBFloppyFlushBlocks;\r
240 UsbFloppyDevice->AtapiProtocol = AtapiProtocol;\r
241\r
242 //\r
243 // Identify drive type and retrieve media information.\r
244 //\r
245 Status = USBFloppyIdentify (UsbFloppyDevice);\r
246 if (EFI_ERROR (Status)) {\r
247 if (UsbFloppyDevice->SenseData != NULL) {\r
248 gBS->FreePool (UsbFloppyDevice->SenseData);\r
249 }\r
250\r
251 gBS->FreePool (UsbFloppyDevice);\r
252 gBS->CloseProtocol (\r
253 Controller,\r
254 &gEfiUsbAtapiProtocolGuid,\r
255 This->DriverBindingHandle,\r
256 Controller\r
257 );\r
258 return Status;\r
259 }\r
260 //\r
261 // Install Block I/O protocol for the usb floppy device.\r
262 //\r
263 Status = gBS->InstallProtocolInterface (\r
264 &Controller,\r
265 &gEfiBlockIoProtocolGuid,\r
266 EFI_NATIVE_INTERFACE,\r
267 &UsbFloppyDevice->BlkIo\r
268 );\r
269 if (EFI_ERROR (Status)) {\r
270 if (UsbFloppyDevice->SenseData != NULL) {\r
271 gBS->FreePool (UsbFloppyDevice->SenseData);\r
272 }\r
273\r
274 gBS->FreePool (UsbFloppyDevice);\r
275 gBS->CloseProtocol (\r
276 Controller,\r
277 &gEfiUsbAtapiProtocolGuid,\r
278 This->DriverBindingHandle,\r
279 Controller\r
280 );\r
281 return Status;\r
282 }\r
283\r
284 return EFI_SUCCESS;\r
285\r
286}\r
287\r
288\r
289EFI_STATUS\r
290EFIAPI\r
291USBFloppyDriverBindingStop (\r
292 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
293 IN EFI_HANDLE Controller,\r
294 IN UINTN NumberOfChildren,\r
295 IN EFI_HANDLE *ChildHandleBuffer\r
296 )\r
297/*++\r
298\r
299 Routine Description:\r
300 Stop this driver on ControllerHandle. Support stoping any child handles\r
301 created by this driver.\r
302\r
303 Arguments:\r
304 This - Protocol instance pointer.\r
305 Controller - Handle of device to stop driver on\r
306 NumberOfChildren - Number of Children in the ChildHandleBuffer\r
307 ChildHandleBuffer - List of handles for the children we need to stop.\r
308\r
309 Returns:\r
310 EFI_SUCCESS\r
311 EFI_DEVICE_ERROR\r
312 others\r
313\r
314--*/ \r
315{\r
316 EFI_STATUS Status;\r
317 USB_FLOPPY_DEV *UsbFloppyDevice;\r
318 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
319\r
320 //\r
321 // First find USB_FLOPPY_DEV\r
322 //\r
323 gBS->OpenProtocol (\r
324 Controller,\r
325 &gEfiBlockIoProtocolGuid,\r
326 (VOID **) &BlkIo,\r
327 This->DriverBindingHandle,\r
328 Controller,\r
329 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
330 );\r
331\r
332 UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (BlkIo);\r
333\r
334 //\r
335 // Uninstall Block I/O protocol from the device handle\r
336 //\r
337 Status = gBS->UninstallProtocolInterface (\r
338 Controller,\r
339 &gEfiBlockIoProtocolGuid,\r
340 &UsbFloppyDevice->BlkIo\r
341 );\r
342 if (EFI_ERROR (Status)) {\r
343 return Status;\r
344 }\r
345 //\r
346 // Stop using EFI_USB_ATAPI_PROTOCOL\r
347 //\r
348 gBS->CloseProtocol (\r
349 Controller,\r
350 &gEfiUsbAtapiProtocolGuid,\r
351 This->DriverBindingHandle,\r
352 Controller\r
353 );\r
354\r
355 if (UsbFloppyDevice->SenseData != NULL) {\r
356 gBS->FreePool (UsbFloppyDevice->SenseData);\r
357 }\r
358\r
359 gBS->FreePool (UsbFloppyDevice);\r
360\r
361 return EFI_SUCCESS;\r
362}\r
363\r
364\r
365STATIC\r
366EFI_STATUS\r
367EFIAPI\r
368USBFloppyReset (\r
369 IN EFI_BLOCK_IO_PROTOCOL *This,\r
370 IN BOOLEAN ExtendedVerification\r
371 )\r
372/*++\r
373\r
374 Routine Description:\r
375 Implements EFI_BLOCK_IO_PROTOCOL.Reset() function.\r
376 \r
377 Arguments:\r
378 This The EFI_BLOCK_IO_PROTOCOL instance.\r
379 ExtendedVerification\r
380 Indicates that the driver may perform a more exhaustive\r
381 verification operation of the device during reset.\r
382 (This parameter is ingored in this driver.)\r
383 \r
384 Returns: \r
385 EFI_SUCCESS - Success\r
386--*/ \r
387{\r
388 USB_FLOPPY_DEV *UsbFloppyDevice;\r
389 EFI_USB_ATAPI_PROTOCOL *UsbAtapiInterface;\r
390 EFI_STATUS Status;\r
391\r
392 UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (This);\r
393\r
394 UsbAtapiInterface = UsbFloppyDevice->AtapiProtocol;\r
395\r
396 //\r
397 // directly calling EFI_USB_ATAPI_PROTOCOL.Reset() to implement reset.\r
398 //\r
399 Status = UsbAtapiInterface->UsbAtapiReset (UsbAtapiInterface, TRUE);\r
400\r
401 return Status;\r
402}\r
403\r
404STATIC\r
405EFI_STATUS\r
406EFIAPI\r
407USBFloppyReadBlocks (\r
408 IN EFI_BLOCK_IO_PROTOCOL *This,\r
409 IN UINT32 MediaId,\r
410 IN EFI_LBA LBA,\r
411 IN UINTN BufferSize,\r
412 OUT VOID *Buffer\r
413 )\r
414/*++\r
415\r
416 Routine Description:\r
417 Implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks() function.\r
418 \r
419 Arguments:\r
420 This The EFI_BLOCK_IO_PROTOCOL instance.\r
421 MediaId The media id that the read request is for.\r
422 LBA The starting logical block address to read from on the device.\r
423 BufferSize\r
424 The size of the Buffer in bytes. This must be a multiple of \r
425 the intrinsic block size of the device.\r
426 Buffer A pointer to the destination buffer for the data. The caller \r
427 is responsible for either having implicit or explicit ownership\r
428 of the buffer. \r
429 \r
430 Returns: \r
431 EFI_INVALID_PARAMETER - Parameter is error\r
432 EFI_SUCCESS - Success \r
433 EFI_DEVICE_ERROR - Hardware Error\r
434 EFI_NO_MEDIA - No media\r
435 EFI_MEDIA_CHANGED - Media Change\r
436 EFI_BAD_BUFFER_SIZE - Buffer size is bad\r
437 --*/ \r
438{\r
439 USB_FLOPPY_DEV *UsbFloppyDevice;\r
440 EFI_STATUS Status;\r
441 EFI_BLOCK_IO_MEDIA *Media;\r
442 UINTN BlockSize;\r
443 UINTN NumberOfBlocks;\r
444 BOOLEAN MediaChange;\r
445 EFI_TPL OldTpl;\r
446 UINT32 Retry;\r
447\r
448 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
449 Status = EFI_SUCCESS;\r
450 MediaChange = FALSE;\r
451 Retry = 0;\r
452\r
453 UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (This);\r
454\r
455 //\r
456 // Check parameters\r
457 //\r
458 if (!Buffer) {\r
459 Status = EFI_INVALID_PARAMETER;\r
460 goto Done;\r
461 }\r
462\r
463 if (BufferSize == 0) {\r
464 Status = EFI_SUCCESS;\r
465 goto Done;\r
466 }\r
467\r
468 UsbFloppyTestUnitReady (UsbFloppyDevice);\r
469\r
470 Status = UsbFloppyDetectMedia (UsbFloppyDevice, &MediaChange);\r
471 if (EFI_ERROR (Status)) {\r
472\r
473 Status = EFI_DEVICE_ERROR;\r
474 goto Done;\r
475 }\r
476\r
477 if (MediaChange) {\r
478 gBS->RestoreTPL (OldTpl);\r
479 gBS->ReinstallProtocolInterface (\r
480 UsbFloppyDevice->Handle,\r
481 &gEfiBlockIoProtocolGuid,\r
482 &UsbFloppyDevice->BlkIo,\r
483 &UsbFloppyDevice->BlkIo\r
484 );\r
485 gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
486 }\r
487\r
488 Media = UsbFloppyDevice->BlkIo.Media;\r
489 BlockSize = Media->BlockSize;\r
490 NumberOfBlocks = BufferSize / BlockSize;\r
491\r
492 if (!(Media->MediaPresent)) {\r
493 Status = EFI_NO_MEDIA;\r
494 goto Done;\r
495 }\r
496\r
497 if (MediaId != Media->MediaId) {\r
498 Status = EFI_MEDIA_CHANGED;\r
499 goto Done;\r
500 }\r
501\r
502 if (BufferSize % BlockSize != 0) {\r
503 Status = EFI_BAD_BUFFER_SIZE;\r
504 goto Done;\r
505 }\r
506\r
507 if (LBA > Media->LastBlock) {\r
508 Status = EFI_INVALID_PARAMETER;\r
509 goto Done;\r
510 }\r
511\r
512 if ((LBA + NumberOfBlocks - 1) > Media->LastBlock) {\r
513 Status = EFI_INVALID_PARAMETER;\r
514 goto Done;\r
515 }\r
516\r
517 if ((Media->IoAlign > 1) && (((UINTN) Buffer & (Media->IoAlign - 1)) != 0)) {\r
518 Status = EFI_INVALID_PARAMETER;\r
519 goto Done;\r
520 }\r
521\r
522 if (!EFI_ERROR (Status)) {\r
523\r
524 Status = USBFloppyRead10 (UsbFloppyDevice, Buffer, LBA, 1);\r
525 if (EFI_ERROR (Status)) {\r
526 This->Reset (This, TRUE);\r
527 Status = EFI_DEVICE_ERROR;\r
528 goto Done;\r
529 }\r
530\r
531 LBA += 1;\r
532 NumberOfBlocks -= 1;\r
533 Buffer = (UINT8 *) Buffer + This->Media->BlockSize;\r
534\r
535 if (NumberOfBlocks == 0) {\r
536 Status = EFI_SUCCESS;\r
537 goto Done;\r
538 }\r
539\r
540 Status = USBFloppyRead10 (UsbFloppyDevice, Buffer, LBA, NumberOfBlocks);\r
541 if (EFI_ERROR (Status)) {\r
542 This->Reset (This, TRUE);\r
543 Status = EFI_DEVICE_ERROR;\r
544 }\r
545 }\r
546\r
547Done:\r
548 gBS->RestoreTPL (OldTpl);\r
549 return Status;\r
550}\r
551\r
552STATIC\r
553EFI_STATUS\r
554EFIAPI\r
555USBFloppyWriteBlocks (\r
556 IN EFI_BLOCK_IO_PROTOCOL *This,\r
557 IN UINT32 MediaId,\r
558 IN EFI_LBA LBA,\r
559 IN UINTN BufferSize,\r
560 IN VOID *Buffer\r
561 )\r
562/*++\r
563\r
564 Routine Description:\r
565 Implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks() function.\r
566 \r
567 Arguments:\r
568 This The EFI_BLOCK_IO_PROTOCOL instance.\r
569 MediaId The media id that the write request is for.\r
570 LBA The starting logical block address to be written.\r
571 The caller is responsible for writing to only \r
572 legitimate locations.\r
573 BufferSize\r
574 The size of the Buffer in bytes. This must be a multiple of \r
575 the intrinsic block size of the device.\r
576 Buffer A pointer to the source buffer for the data. The caller \r
577 is responsible for either having implicit or explicit ownership\r
578 of the buffer. \r
579 \r
580 Returns: \r
581 EFI_INVALID_PARAMETER - Parameter is error\r
582 EFI_SUCCESS - Success \r
583 EFI_DEVICE_ERROR - Hardware Error\r
584 EFI_NO_MEDIA - No media\r
585 EFI_MEDIA_CHANGED - Media Change\r
586 EFI_BAD_BUFFER_SIZE - Buffer size is bad\r
587\r
588--*/ \r
589{\r
590 USB_FLOPPY_DEV *UsbFloppyDevice;\r
591 EFI_STATUS Status;\r
592 EFI_BLOCK_IO_MEDIA *Media;\r
593 UINTN BlockSize;\r
594 UINTN NumberOfBlocks;\r
595 BOOLEAN MediaChange;\r
596 EFI_TPL OldTpl;\r
597 UINT32 Retry;\r
598\r
599 OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
600 Status = EFI_SUCCESS;\r
601 MediaChange = FALSE;\r
602 Retry = 0;\r
603\r
604 UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (This);\r
605\r
606 //\r
607 // Check parameters\r
608 //\r
609 if (!Buffer) {\r
610 Status = EFI_INVALID_PARAMETER;\r
611 goto Done;\r
612 }\r
613\r
614 if (BufferSize == 0) {\r
615 Status = EFI_SUCCESS;\r
616 goto Done;\r
617 }\r
618\r
619 UsbFloppyTestUnitReady (UsbFloppyDevice);\r
620\r
621 Status = UsbFloppyDetectMedia (UsbFloppyDevice, &MediaChange);\r
622 if (EFI_ERROR (Status)) {\r
623\r
624 Status = EFI_DEVICE_ERROR;\r
625 goto Done;\r
626 }\r
627\r
628 if (MediaChange) {\r
629 gBS->RestoreTPL (OldTpl);\r
630 gBS->ReinstallProtocolInterface (\r
631 UsbFloppyDevice->Handle,\r
632 &gEfiBlockIoProtocolGuid,\r
633 &UsbFloppyDevice->BlkIo,\r
634 &UsbFloppyDevice->BlkIo\r
635 );\r
636 gBS->RaiseTPL (EFI_TPL_NOTIFY);\r
637 }\r
638\r
639 Media = UsbFloppyDevice->BlkIo.Media;\r
640 BlockSize = Media->BlockSize;\r
641 NumberOfBlocks = BufferSize / BlockSize;\r
642\r
643 if (!(Media->MediaPresent)) {\r
644 Status = EFI_NO_MEDIA;\r
645 goto Done;\r
646 }\r
647\r
648 if (MediaId != Media->MediaId) {\r
649 Status = EFI_MEDIA_CHANGED;\r
650 goto Done;\r
651 }\r
652\r
653 if (BufferSize % BlockSize != 0) {\r
654 Status = EFI_BAD_BUFFER_SIZE;\r
655 goto Done;\r
656 }\r
657\r
658 if (LBA > Media->LastBlock) {\r
659 Status = EFI_INVALID_PARAMETER;\r
660 goto Done;\r
661 }\r
662\r
663 if ((LBA + NumberOfBlocks - 1) > Media->LastBlock) {\r
664 Status = EFI_INVALID_PARAMETER;\r
665 goto Done;\r
666 }\r
667\r
668 if ((Media->IoAlign > 1) && (((UINTN) Buffer & (Media->IoAlign - 1)) != 0)) {\r
669 Status = EFI_INVALID_PARAMETER;\r
670 goto Done;\r
671 }\r
672\r
673 if (UsbFloppyDevice->BlkMedia.ReadOnly) {\r
674 Status = EFI_WRITE_PROTECTED;\r
675 goto Done;\r
676 }\r
677\r
678 if (!EFI_ERROR (Status)) {\r
679 Status = USBFloppyWrite10 (UsbFloppyDevice, Buffer, LBA, 1);\r
680 if (EFI_ERROR (Status)) {\r
681 This->Reset (This, TRUE);\r
682 Status = EFI_DEVICE_ERROR;\r
683 goto Done;\r
684 }\r
685\r
686 LBA += 1;\r
687 NumberOfBlocks -= 1;\r
688 Buffer = (UINT8 *) Buffer + This->Media->BlockSize;\r
689\r
690 if (NumberOfBlocks == 0) {\r
691 Status = EFI_SUCCESS;\r
692 goto Done;\r
693 }\r
694\r
695 Status = USBFloppyWrite10 (UsbFloppyDevice, Buffer, LBA, NumberOfBlocks);\r
696 if (EFI_ERROR (Status)) {\r
697 This->Reset (This, TRUE);\r
698 Status = EFI_DEVICE_ERROR;\r
699 }\r
700 }\r
701\r
702Done:\r
703 gBS->RestoreTPL (OldTpl);\r
704 return Status;\r
705}\r
706\r
707STATIC\r
708EFI_STATUS\r
709EFIAPI\r
710USBFloppyFlushBlocks (\r
711 IN EFI_BLOCK_IO_PROTOCOL *This\r
712 )\r
713/*++\r
714\r
715 Routine Description:\r
716 Implements EFI_BLOCK_IO_PROTOCOL.FlushBlocks() function.\r
717 (In this driver, this function just returns EFI_SUCCESS.)\r
718 \r
719 Arguments:\r
720 This The EFI_BLOCK_IO_PROTOCOL instance.\r
721 \r
722 Returns: \r
723 EFI_SUCCESS - Success\r
724--*/ \r
725{\r
726 return EFI_SUCCESS;\r
727}\r