diff options
author | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-02-13 09:08:24 +0000 |
---|---|---|
committer | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-02-13 09:08:24 +0000 |
commit | 1c61953576f35507eb24032fe2804eaf9a0e976c (patch) | |
tree | 360cede2dc10e488a9efd48a7f125a596db41f69 /MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c | |
parent | d1f076304d3be2f1423ba8d62062253cb0d59354 (diff) | |
download | edk2-platforms-1c61953576f35507eb24032fe2804eaf9a0e976c.tar.xz |
1. Added EFI_MEDIA_CHANGED and EFI_INVALID_PARAMETER returns in UsbMassReadBlocks().
2. Use DEBUG () to replace some native debug function in USB stack modules.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4689 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c')
-rw-r--r-- | MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c index f077e2aaad..71ccfa9d10 100644 --- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c +++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c @@ -40,10 +40,6 @@ USB_MASS_TRANSPORT *mUsbMassTransport[] = { NULL
};
-UINTN mUsbMscInfo = DEBUG_INFO;
-UINTN mUsbMscError = DEBUG_ERROR;
-
-
/**
Retrieve the media parameters such as disk gemotric for the
device's BLOCK IO protocol.
@@ -84,6 +80,7 @@ UsbMassInitMedia ( Media->ReadOnly = FALSE;
Media->WriteCaching = FALSE;
Media->IoAlign = 0;
+ Media->MediaId = 1;
//
// Some device may spend several seconds before it is ready.
@@ -102,7 +99,7 @@ UsbMassInitMedia ( Status = UsbBootIsUnitReady (UsbMass);
if (EFI_ERROR (Status)) {
- gBS->Stall (USB_BOOT_RETRY_UNIT_READY_STALL * (Index + 1));
+ gBS->Stall (USB_BOOT_RETRY_UNIT_READY_STALL * (Index + 1));
}
}
@@ -122,6 +119,7 @@ UsbMassInitMedia ( **/
EFI_STATUS
+EFIAPI
UsbMassReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
@@ -162,6 +160,7 @@ UsbMassReset ( **/
EFI_STATUS
+EFIAPI
UsbMassReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
@@ -175,7 +174,7 @@ UsbMassReadBlocks ( EFI_STATUS Status;
EFI_TPL OldTpl;
UINTN TotalBlock;
-
+
OldTpl = gBS->RaiseTPL (USB_MASS_TPL);
UsbMass = USB_MASS_DEVICE_FROM_BLOCKIO (This);
Media = &UsbMass->BlockIoMedia;
@@ -187,21 +186,21 @@ UsbMassReadBlocks ( Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
-
+
//
// If it is a removable media, such as CD-Rom or Usb-Floppy,
- // need to detect the media before each rw. While some of
+ // need to detect the media before each rw. While some of
// Usb-Flash is marked as removable media.
- //
- //
+ //
+ //
if (Media->RemovableMedia == TRUE) {
Status = UsbBootDetectMedia (UsbMass);
if (EFI_ERROR (Status)) {
- DEBUG ((mUsbMscError, "UsbMassReadBlocks: UsbBootDetectMedia (%r)\n", Status));
+ DEBUG ((EFI_D_ERROR, "UsbMassReadBlocks: UsbBootDetectMedia (%r)\n", Status));
goto ON_EXIT;
- }
+ }
}
-
+
//
// Make sure BlockSize and LBA is consistent with BufferSize
//
@@ -213,13 +212,23 @@ UsbMassReadBlocks ( TotalBlock = BufferSize / Media->BlockSize;
if (Lba + TotalBlock - 1 > Media->LastBlock) {
- Status = EFI_BAD_BUFFER_SIZE;
+ Status = EFI_INVALID_PARAMETER;
+ goto ON_EXIT;
+ }
+
+ if (!(Media->MediaPresent)) {
+ Status = EFI_NO_MEDIA;
+ goto ON_EXIT;
+ }
+
+ if (MediaId != Media->MediaId) {
+ Status = EFI_MEDIA_CHANGED;
goto ON_EXIT;
}
-
+
Status = UsbBootReadBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer);
if (EFI_ERROR (Status)) {
- DEBUG ((mUsbMscError, "UsbMassReadBlocks: UsbBootReadBlocks (%r) -> Reset\n", Status));
+ DEBUG ((EFI_D_ERROR, "UsbMassReadBlocks: UsbBootReadBlocks (%r) -> Reset\n", Status));
UsbMassReset (This, TRUE);
}
@@ -249,6 +258,7 @@ ON_EXIT: **/
EFI_STATUS
+EFIAPI
UsbMassWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
@@ -274,21 +284,21 @@ UsbMassWriteBlocks ( Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
-
+
//
// If it is a removable media, such as CD-Rom or Usb-Floppy,
- // need to detect the media before each rw. While some of
+ // need to detect the media before each rw. While some of
// Usb-Flash is marked as removable media.
- //
- //
+ //
+ //
if (Media->RemovableMedia == TRUE) {
Status = UsbBootDetectMedia (UsbMass);
if (EFI_ERROR (Status)) {
- DEBUG ((mUsbMscError, "UsbMassWriteBlocks: UsbBootDetectMedia (%r)\n", Status));
+ DEBUG ((EFI_D_ERROR, "UsbMassWriteBlocks: UsbBootDetectMedia (%r)\n", Status));
goto ON_EXIT;
- }
+ }
}
-
+
//
// Make sure BlockSize and LBA is consistent with BufferSize
//
@@ -300,20 +310,30 @@ UsbMassWriteBlocks ( TotalBlock = BufferSize / Media->BlockSize;
if (Lba + TotalBlock - 1 > Media->LastBlock) {
- Status = EFI_BAD_BUFFER_SIZE;
+ Status = EFI_INVALID_PARAMETER;
goto ON_EXIT;
}
-
+
+ if (!(Media->MediaPresent)) {
+ Status = EFI_NO_MEDIA;
+ goto ON_EXIT;
+ }
+
+ if (MediaId != Media->MediaId) {
+ Status = EFI_MEDIA_CHANGED;
+ goto ON_EXIT;
+ }
+
//
// Try to write the data even the device is marked as ReadOnly,
// and clear the status should the write succeed.
//
Status = UsbBootWriteBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer);
if (EFI_ERROR (Status)) {
- DEBUG ((mUsbMscError, "UsbMassWriteBlocks: UsbBootWriteBlocks (%r) -> Reset\n", Status));
+ DEBUG ((EFI_D_ERROR, "UsbMassWriteBlocks: UsbBootWriteBlocks (%r) -> Reset\n", Status));
UsbMassReset (This, TRUE);
}
-
+
ON_EXIT:
gBS->RestoreTPL (OldTpl);
return Status;
@@ -330,6 +350,7 @@ ON_EXIT: **/
EFI_STATUS
+EFIAPI
UsbMassFlushBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This
)
@@ -402,7 +423,7 @@ USBMassDriverBindingSupported ( }
}
- DEBUG ((mUsbMscInfo, "Found a USB mass store device %r\n", Status));
+ DEBUG ((EFI_D_INFO, "Found a USB mass store device %r\n", Status));
ON_EXIT:
gBS->CloseProtocol (
@@ -467,7 +488,7 @@ USBMassDriverBindingStart ( //
Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);
if (EFI_ERROR (Status)) {
- DEBUG ((mUsbMscError, "USBMassDriverBindingStart: UsbIo->UsbGetInterfaceDescriptor (%r)\n", Status));
+ DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbIo->UsbGetInterfaceDescriptor (%r)\n", Status));
goto ON_ERROR;
}
@@ -484,7 +505,7 @@ USBMassDriverBindingStart ( }
if (EFI_ERROR (Status)) {
- DEBUG ((mUsbMscError, "USBMassDriverBindingStart: Transport->Init (%r)\n", Status));
+ DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: Transport->Init (%r)\n", Status));
goto ON_ERROR;
}
@@ -508,11 +529,11 @@ USBMassDriverBindingStart ( (UsbMass->Pdt != USB_PDT_CDROM) &&
(UsbMass->Pdt != USB_PDT_OPTICAL) &&
(UsbMass->Pdt != USB_PDT_SIMPLE_DIRECT)) {
- DEBUG ((mUsbMscError, "USBMassDriverBindingStart: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));
+ DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: Found an unsupported peripheral type[%d]\n", UsbMass->Pdt));
goto ON_ERROR;
}
} else if (Status != EFI_NO_MEDIA){
- DEBUG ((mUsbMscError, "USBMassDriverBindingStart: UsbMassInitMedia (%r)\n", Status));
+ DEBUG ((EFI_D_ERROR, "USBMassDriverBindingStart: UsbMassInitMedia (%r)\n", Status));
goto ON_ERROR;
}
|