X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EdkModulePkg%2FBus%2FUsb%2FUsbMassStorage%2FDxe%2FUsbMassStorage.c;h=daaf3f8fe41d72d2449e608cd43b53d685e84d2c;hp=b86c06a514d06469a2e0d73e07b73d7639ceb7a4;hb=93b0fbc8a1731a3c4ae789bebac4b1d8966719c3;hpb=1cc8ee7861a59532700a6fd1255689576eda0f52 diff --git a/EdkModulePkg/Bus/Usb/UsbMassStorage/Dxe/UsbMassStorage.c b/EdkModulePkg/Bus/Usb/UsbMassStorage/Dxe/UsbMassStorage.c index b86c06a514..daaf3f8fe4 100644 --- a/EdkModulePkg/Bus/Usb/UsbMassStorage/Dxe/UsbMassStorage.c +++ b/EdkModulePkg/Bus/Usb/UsbMassStorage/Dxe/UsbMassStorage.c @@ -1,18 +1,18 @@ /*++ -Copyright (c) 2006, Intel Corporation -All rights reserved. This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD License -which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2006 - 2007, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Module Name: UsbMassStorage.c - + Abstract: USB Mass Storage Driver @@ -24,44 +24,6 @@ Revision History #include "UsbMassStorage.h" #include "UsbMassStorageHelper.h" -extern EFI_COMPONENT_NAME_PROTOCOL gUsbMassStorageComponentName; - -// -// Prototypes -// Driver model protocol interface -// -EFI_STATUS -EFIAPI -USBMassStorageDriverBindingEntryPoint ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ); - -EFI_STATUS -EFIAPI -USBFloppyDriverBindingSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ); - -EFI_STATUS -EFIAPI -USBFloppyDriverBindingStart ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ); - -EFI_STATUS -EFIAPI -USBFloppyDriverBindingStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer - ); - // // Block I/O Protocol Interface // @@ -192,11 +154,11 @@ USBFloppyDriverBindingStart ( EFI_OUT_OF_RESOURCES- Can't allocate memory resources EFI_ALREADY_STARTED - Thios driver has been started --*/ -{ - EFI_STATUS Status; +{ + EFI_STATUS Status; EFI_USB_ATAPI_PROTOCOL *AtapiProtocol; USB_FLOPPY_DEV *UsbFloppyDevice; - + UsbFloppyDevice = NULL; // // Check whether Usb Atapi Protocol attached on the controller handle. @@ -311,7 +273,7 @@ USBFloppyDriverBindingStop ( EFI_DEVICE_ERROR others ---*/ +--*/ { EFI_STATUS Status; USB_FLOPPY_DEV *UsbFloppyDevice; @@ -373,21 +335,24 @@ USBFloppyReset ( Routine Description: Implements EFI_BLOCK_IO_PROTOCOL.Reset() function. - + Arguments: This The EFI_BLOCK_IO_PROTOCOL instance. ExtendedVerification Indicates that the driver may perform a more exhaustive verification operation of the device during reset. (This parameter is ingored in this driver.) - - Returns: + + Returns: EFI_SUCCESS - Success ---*/ +--*/ { USB_FLOPPY_DEV *UsbFloppyDevice; EFI_USB_ATAPI_PROTOCOL *UsbAtapiInterface; EFI_STATUS Status; + EFI_TPL OldTpl; + + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (This); @@ -396,7 +361,9 @@ USBFloppyReset ( // // directly calling EFI_USB_ATAPI_PROTOCOL.Reset() to implement reset. // - Status = UsbAtapiInterface->UsbAtapiReset (UsbAtapiInterface, TRUE); + Status = UsbAtapiInterface->UsbAtapiReset (UsbAtapiInterface, ExtendedVerification); + + gBS->RestoreTPL (OldTpl); return Status; } @@ -415,26 +382,26 @@ USBFloppyReadBlocks ( Routine Description: Implements EFI_BLOCK_IO_PROTOCOL.ReadBlocks() function. - + Arguments: This The EFI_BLOCK_IO_PROTOCOL instance. MediaId The media id that the read request is for. LBA The starting logical block address to read from on the device. BufferSize - The size of the Buffer in bytes. This must be a multiple of + The size of the Buffer in bytes. This must be a multiple of the intrinsic block size of the device. - Buffer A pointer to the destination buffer for the data. The caller + Buffer A pointer to the destination buffer for the data. The caller is responsible for either having implicit or explicit ownership - of the buffer. - - Returns: + of the buffer. + + Returns: EFI_INVALID_PARAMETER - Parameter is error - EFI_SUCCESS - Success + EFI_SUCCESS - Success EFI_DEVICE_ERROR - Hardware Error EFI_NO_MEDIA - No media EFI_MEDIA_CHANGED - Media Change EFI_BAD_BUFFER_SIZE - Buffer size is bad - --*/ + --*/ { USB_FLOPPY_DEV *UsbFloppyDevice; EFI_STATUS Status; @@ -444,25 +411,23 @@ USBFloppyReadBlocks ( BOOLEAN MediaChange; EFI_TPL OldTpl; - OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY); Status = EFI_SUCCESS; MediaChange = FALSE; - UsbFloppyDevice = USB_FLOPPY_DEV_FROM_THIS (This); // // Check parameters // - if (!Buffer) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (Buffer == NULL) { + return EFI_INVALID_PARAMETER; } if (BufferSize == 0) { - Status = EFI_SUCCESS; - goto Done; + return EFI_SUCCESS; } + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); + UsbFloppyTestUnitReady (UsbFloppyDevice); Status = UsbFloppyDetectMedia (UsbFloppyDevice, &MediaChange); @@ -473,14 +438,12 @@ USBFloppyReadBlocks ( } if (MediaChange) { - gBS->RestoreTPL (OldTpl); gBS->ReinstallProtocolInterface ( UsbFloppyDevice->Handle, &gEfiBlockIoProtocolGuid, &UsbFloppyDevice->BlkIo, &UsbFloppyDevice->BlkIo ); - gBS->RaiseTPL (EFI_TPL_NOTIFY); } Media = UsbFloppyDevice->BlkIo.Media; @@ -517,32 +480,32 @@ USBFloppyReadBlocks ( goto Done; } - if (!EFI_ERROR (Status)) { + while (NumberOfBlocks > 0) { + + if (NumberOfBlocks > BLOCK_UNIT) { + Status = USBFloppyRead10 (UsbFloppyDevice, Buffer, LBA, BLOCK_UNIT); + } else { + Status = USBFloppyRead10 (UsbFloppyDevice, Buffer, LBA, NumberOfBlocks); + } - Status = USBFloppyRead10 (UsbFloppyDevice, Buffer, LBA, 1); if (EFI_ERROR (Status)) { This->Reset (This, TRUE); Status = EFI_DEVICE_ERROR; goto Done; } - LBA += 1; - NumberOfBlocks -= 1; - Buffer = (UINT8 *) Buffer + This->Media->BlockSize; - - if (NumberOfBlocks == 0) { - Status = EFI_SUCCESS; - goto Done; + if (NumberOfBlocks > BLOCK_UNIT) { + NumberOfBlocks -= BLOCK_UNIT; + LBA += BLOCK_UNIT; + Buffer = (UINT8 *) Buffer + This->Media->BlockSize * BLOCK_UNIT; + } else { + NumberOfBlocks -= NumberOfBlocks; + LBA += NumberOfBlocks; + Buffer = (UINT8 *) Buffer + This->Media->BlockSize * NumberOfBlocks; } + } - Status = USBFloppyRead10 (UsbFloppyDevice, Buffer, LBA, NumberOfBlocks); - if (EFI_ERROR (Status)) { - This->Reset (This, TRUE); - Status = EFI_DEVICE_ERROR; - } - } - -Done: + Done: gBS->RestoreTPL (OldTpl); return Status; } @@ -561,29 +524,29 @@ USBFloppyWriteBlocks ( Routine Description: Implements EFI_BLOCK_IO_PROTOCOL.WriteBlocks() function. - + Arguments: This The EFI_BLOCK_IO_PROTOCOL instance. MediaId The media id that the write request is for. LBA The starting logical block address to be written. - The caller is responsible for writing to only + The caller is responsible for writing to only legitimate locations. BufferSize - The size of the Buffer in bytes. This must be a multiple of + The size of the Buffer in bytes. This must be a multiple of the intrinsic block size of the device. - Buffer A pointer to the source buffer for the data. The caller + Buffer A pointer to the source buffer for the data. The caller is responsible for either having implicit or explicit ownership - of the buffer. - - Returns: + of the buffer. + + Returns: EFI_INVALID_PARAMETER - Parameter is error - EFI_SUCCESS - Success + EFI_SUCCESS - Success EFI_DEVICE_ERROR - Hardware Error EFI_NO_MEDIA - No media EFI_MEDIA_CHANGED - Media Change EFI_BAD_BUFFER_SIZE - Buffer size is bad ---*/ +--*/ { USB_FLOPPY_DEV *UsbFloppyDevice; EFI_STATUS Status; @@ -593,7 +556,6 @@ USBFloppyWriteBlocks ( BOOLEAN MediaChange; EFI_TPL OldTpl; - OldTpl = gBS->RaiseTPL (EFI_TPL_NOTIFY); Status = EFI_SUCCESS; MediaChange = FALSE; @@ -602,16 +564,16 @@ USBFloppyWriteBlocks ( // // Check parameters // - if (!Buffer) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (Buffer == NULL) { + return EFI_INVALID_PARAMETER; } if (BufferSize == 0) { - Status = EFI_SUCCESS; - goto Done; + return EFI_SUCCESS; } + OldTpl = gBS->RaiseTPL (TPL_CALLBACK); + UsbFloppyTestUnitReady (UsbFloppyDevice); Status = UsbFloppyDetectMedia (UsbFloppyDevice, &MediaChange); @@ -622,14 +584,12 @@ USBFloppyWriteBlocks ( } if (MediaChange) { - gBS->RestoreTPL (OldTpl); gBS->ReinstallProtocolInterface ( UsbFloppyDevice->Handle, &gEfiBlockIoProtocolGuid, &UsbFloppyDevice->BlkIo, &UsbFloppyDevice->BlkIo ); - gBS->RaiseTPL (EFI_TPL_NOTIFY); } Media = UsbFloppyDevice->BlkIo.Media; @@ -671,29 +631,30 @@ USBFloppyWriteBlocks ( goto Done; } - if (!EFI_ERROR (Status)) { - Status = USBFloppyWrite10 (UsbFloppyDevice, Buffer, LBA, 1); - if (EFI_ERROR (Status)) { - This->Reset (This, TRUE); - Status = EFI_DEVICE_ERROR; - goto Done; - } - - LBA += 1; - NumberOfBlocks -= 1; - Buffer = (UINT8 *) Buffer + This->Media->BlockSize; + while (NumberOfBlocks > 0) { - if (NumberOfBlocks == 0) { - Status = EFI_SUCCESS; - goto Done; + if (NumberOfBlocks > BLOCK_UNIT) { + Status = USBFloppyWrite10 (UsbFloppyDevice, Buffer, LBA, BLOCK_UNIT); + } else { + Status = USBFloppyWrite10 (UsbFloppyDevice, Buffer, LBA, NumberOfBlocks); } - Status = USBFloppyWrite10 (UsbFloppyDevice, Buffer, LBA, NumberOfBlocks); if (EFI_ERROR (Status)) { This->Reset (This, TRUE); Status = EFI_DEVICE_ERROR; + goto Done; } - } + + if (NumberOfBlocks > BLOCK_UNIT) { + NumberOfBlocks -= BLOCK_UNIT; + LBA += BLOCK_UNIT; + Buffer = (UINT8 *) Buffer + This->Media->BlockSize * BLOCK_UNIT; + } else { + NumberOfBlocks -= NumberOfBlocks; + LBA += NumberOfBlocks; + Buffer = (UINT8 *) Buffer + This->Media->BlockSize * NumberOfBlocks; + } + } Done: gBS->RestoreTPL (OldTpl); @@ -711,13 +672,13 @@ USBFloppyFlushBlocks ( Routine Description: Implements EFI_BLOCK_IO_PROTOCOL.FlushBlocks() function. (In this driver, this function just returns EFI_SUCCESS.) - + Arguments: This The EFI_BLOCK_IO_PROTOCOL instance. - - Returns: + + Returns: EFI_SUCCESS - Success ---*/ +--*/ { return EFI_SUCCESS; }