/** @file
DiskIo driver that lays on every BlockIo protocol in the system.
DiskIo converts a block oriented device to a byte oriented device.
Disk access may have to handle unaligned request about sector boundaries.
There are three cases:
UnderRun - The first byte is not on a sector boundary or the read request is
less than a sector in length.
Aligned - A read of N contiguous sectors.
OverRun - The last byte is not on a sector boundary.
Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "DiskIo.h"
//
// Driver binding protocol implementation for DiskIo driver.
//
0xa,
NULL,
};
//
// Template for DiskIo private data structure.
// The pointer to BlockIo protocol interface is assigned dynamically.
//
{
},
};
/**
Test to see if this driver supports ControllerHandle.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to test
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver supports this device
@retval EFI_ALREADY_STARTED This driver is already running on this device
@retval other This driver does not support this device
**/
)
{
//
// Open the IO Abstraction(s) needed to perform the supported test.
//
);
return Status;
}
//
// Close the I/O Abstraction(s) used to perform the supported test.
//
gBS->CloseProtocol (
);
return EFI_SUCCESS;
}
/**
Start this driver on ControllerHandle by opening a Block IO protocol and
installing a Disk IO protocol on ControllerHandle.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to bind driver to
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS This driver is added to ControllerHandle
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
@retval other This driver does not support this device
**/
)
{
//
// Connect to the Block IO interface on ControllerHandle.
//
);
goto ErrorExit1;
}
//
// Initialize the Disk IO device instance.
//
goto ErrorExit;
}
//
// Install protocol interfaces for the Disk IO device.
//
);
}
gBS->CloseProtocol (
);
}
return Status;
}
/**
Stop this driver on ControllerHandle by removing Disk IO protocol and closing
the Block IO protocol on ControllerHandle.
@param This Protocol instance pointer.
@param ControllerHandle Handle of device to stop driver on
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
children is zero stop the entire bus driver.
@param ChildHandleBuffer List of Child Handles to Stop.
@retval EFI_SUCCESS This driver is removed ControllerHandle
@retval other This driver was not removed from this device
**/
)
{
//
// Get our context back.
//
);
return EFI_UNSUPPORTED;
}
);
);
}
}
return Status;
}
/**
Read BufferSize bytes from Offset into Buffer.
Reads may support reads that are not aligned on
sector boundaries. There are three cases:
UnderRun - The first byte is not on a sector boundary or the read request is
less than a sector in length.
Aligned - A read of N contiguous sectors.
OverRun - The last byte is not on a sector boundary.
@param This Protocol instance pointer.
@param MediaId Id of the media, changes every time the media is replaced.
@param Offset The starting byte offset to read from
@param BufferSize Size of Buffer
@param Buffer Buffer containing read data
@retval EFI_SUCCESS The data was read correctly from the device.
@retval EFI_DEVICE_ERROR The device reported an error while performing the read.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
@retval EFI_INVALID_PARAMETER The read request contains device addresses that are not
valid for the device.
**/
)
{
return EFI_MEDIA_CHANGED;
}
//
// Allocate a temporary buffer for operation
//
} else {
}
return EFI_OUT_OF_RESOURCES;
}
if (UnderRun != 0) {
//
// Offset starts in the middle of an Lba, so read the entire block.
//
Lba,
);
goto Done;
}
if (Length > BufferSize) {
Length = BufferSize;
}
WorkingBuffer += Length;
if (WorkingBufferSize == 0) {
goto Done;
}
Lba += 1;
}
//
// If the DiskIo maps directly to a BlockIo device do the read.
//
if (OverRun != 0) {
}
//
// Check buffer alignment
//
//
// Alignment is satisfied, so read them together
//
Lba,
);
goto Done;
}
} else {
//
// Use the allocated buffer instead of the original buffer
// to avoid alignment issue.
// Here, the allocated buffer (8-byte align) can satisfy the alignment
//
do {
if (WorkingBufferSize <= DataBufferSize) {
//
// It is the last calling to readblocks in this loop
//
}
Lba,
);
goto Done;
}
} while (!LastRead);
}
}
if (!TransactionComplete && OverRun != 0) {
//
// Last read is not a complete block.
//
);
goto Done;
}
}
Done:
}
return Status;
}
/**
Writes BufferSize bytes from Buffer into Offset.
Writes may require a read modify write to support writes that are not
aligned on sector boundaries. There are three cases:
UnderRun - The first byte is not on a sector boundary or the write request
is less than a sector in length. Read modify write is required.
Aligned - A write of N contiguous sectors.
OverRun - The last byte is not on a sector boundary. Read modified write
required.
@param This Protocol instance pointer.
@param MediaId Id of the media, changes every time the media is replaced.
@param Offset The starting byte offset to read from
@param BufferSize Size of Buffer
@param Buffer Buffer containing read data
@retval EFI_SUCCESS The data was written correctly to the device.
@retval EFI_WRITE_PROTECTED The device can not be written to.
@retval EFI_DEVICE_ERROR The device reported an error while performing the write.
@retval EFI_NO_MEDIA There is no media in the device.
@retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
@retval EFI_INVALID_PARAMETER The write request contains device addresses that are not
valid for the device.
**/
)
{
return EFI_WRITE_PROTECTED;
}
return EFI_MEDIA_CHANGED;
}
} else {
}
return EFI_OUT_OF_RESOURCES;
}
if (UnderRun != 0) {
//
// Offset starts in the middle of an Lba, so do read modify write.
//
Lba,
);
goto Done;
}
if (Length > BufferSize) {
Length = BufferSize;
}
Lba,
);
goto Done;
}
WorkingBuffer += Length;
if (WorkingBufferSize == 0) {
goto Done;
}
Lba += 1;
}
//
// If the DiskIo maps directly to a BlockIo device do the write.
//
if (OverRun != 0) {
}
//
// Check buffer alignment
//
//
// Alignment is satisfied, so write them together
//
Lba,
);
goto Done;
}
} else {
//
// The buffer parameter is not aligned with the request
// So use the allocated instead.
// It can fit almost all the cases.
//
do {
if (WorkingBufferSize <= DataBufferSize) {
//
// It is the last calling to writeblocks in this loop
//
}
Lba,
);
goto Done;
}
} while (!LastWrite);
}
}
if (!TransactionComplete && OverRun != 0) {
//
// Last bit is not a complete block, so do a read modify write.
//
);
goto Done;
}
);
goto Done;
}
}
Done:
}
return Status;
}
/**
The user Entry Point for module DiskIo. The user code starts with this function.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval other Some error occurs when executing this entry point.
**/
)
{
//
// Install driver model protocol(s).
//
);
return Status;
}