Download UEFI Driver Writer`s Guide

Transcript
with most of the fields pre-initialized. This style produces UEFI Drivers that execute
faster and produce smaller executables than UEFI Drivers that initialize each field of
the private context data structure in the Start() function.
#include
#include
#include
#include
#include
<Uefi.h>
<Protocol/DriverBinding.h>
<Protocol/DevicePath.h>
<Protocol/DiskIo.h>
<Library/MemoryAllocationLib.h>
//
// Template for DiskIo private data structure.
// The pointer to BlockIo protocol interface is assigned dynamically.
//
DISK_IO_PRIVATE_DATA gDiskIoPrivateDataTemplate = {
DISK_IO_PRIVATE_DATA_SIGNATURE,
{
EFI_DISK_IO_PROTOCOL_REVISION,
DiskIoReadDisk,
DiskIoWriteDisk
},
NULL
};
EFI_STATUS
EFIAPI
DiskIoDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE
ControllerHandle,
IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
)
{
EFI_STATUS
Status;
DISK_IO_PRIVATE_DATA *Private;
//
// Initialize the Disk IO device instance.
//
Private = AllocateCopyPool (
sizeof (DISK_IO_PRIVATE_DATA),
&gDiskIoPrivateDataTemplate
);
if (Private == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
}
}
Example 117—Disk I/O allocation of private context data structure
248
3/8/2012
Version 1.01