/** @file
EFI glue for BIOS INT 13h block devices.
This file is coded to EDD 3.0 as defined by T13 D1386 Revision 4
Availible on http://www.t13.org/#Project drafts
Copyright (c) 1999 - 2011, 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 "BiosBlkIo.h"
//
// Global data declaration
//
//
// EFI Driver Binding Protocol Instance
//
0x3,
NULL,
};
//
// Semaphore to control access to global variables mActiveInstances and mBufferUnder1Mb
//
//
// the shared buffer. You must acquire the semaphore to modify.
//
//
// Pointer to the beginning of the buffer used for real mode thunk
// You must acquire the semaphore to modify.
//
//
// Address packet is a buffer under 1 MB for all version EDD calls
//
//
// This is a buffer for INT 13h func 48 information
//
//
// Buffer of 0xFE00 bytes for EDD 1.1 transfer must be under 1 MB
// 0xFE00 bytes is the max transfer size supported.
//
/**
Driver entry point.
@param ImageHandle Handle of driver image.
@param SystemTable Pointer to system table.
@retval EFI_SUCCESS Entrypoint successfully executed.
@retval Others Fail to execute entrypoint.
**/
)
{
//
// Install protocols
//
);
return Status;
}
//
// Install Legacy BIOS GUID to mark this driver as a BIOS Thunk Driver
//
return gBS->InstallMultipleProtocolInterfaces (
NULL,
);
}
/**
Check whether the driver supports this device.
@param This The Udriver binding protocol.
@param Controller The controller handle to check.
@param RemainingDevicePath The remaining device path.
@retval EFI_SUCCESS The driver supports this controller.
@retval other This device isn't supported.
**/
)
{
//
// See if the Legacy BIOS Protocol is available
//
return Status;
}
(VOID **) &DevicePath,
);
return Status;
}
gBS->CloseProtocol (
);
//
// Open the IO Abstraction(s) needed to perform the supported test
//
);
return Status;
}
//
// See if this is a PCI VGA Controller by looking at the Command register and
// Class Code Register
//
goto Done;
}
(Pci.Hdr.ClassCode[2] == PCI_BASE_CLASS_INTELLIGENT && Pci.Hdr.ClassCode[1] == PCI_SUB_CLASS_INTELLIGENT)
) {
}
Done:
gBS->CloseProtocol (
);
return Status;
}
/**
Starts the device with this driver.
@param This The driver binding instance.
@param Controller Handle of device to bind driver to.
@param RemainingDevicePath Optional parameter use to pick a specific child
device to start.
@retval EFI_SUCCESS The controller is controlled by the driver.
@retval Other This controller cannot be started.
**/
)
{
//
// Initialize variables
//
PciDevPath = NULL;
//
// See if the Legacy BIOS Protocol is available
//
goto Error;
}
//
// Open the IO Abstraction(s) needed
//
);
goto Error;
}
(VOID **) &PciDevPath,
);
goto Error;
}
//
// Enable the device and make sure VGA cycles are being forwarded to this VGA device
//
);
goto Error;
}
DeviceEnable = TRUE;
//
// Check to see if there is a legacy option ROM image associated with this PCI device
//
NULL,
NULL,
);
goto Error;
}
//
// Post the legacy option ROM if it is available.
//
NULL,
&Flags,
&DiskEnd,
NULL,
);
goto Error;
}
//
// All instances share a buffer under 1MB to put real mode thunk code in
// If it has not been allocated, then we allocate it.
//
if (mBufferUnder1Mb == 0) {
//
// Should only be here if there are no active instances
//
ASSERT (mActiveInstances == 0);
//
// Acquire the lock
//
//
// Allocate below 1MB
//
mBufferUnder1Mb = 0x00000000000FFFFF;
Status = gBS->AllocatePages (AllocateMaxAddress, EfiBootServicesData, BLOCK_IO_BUFFER_PAGE_SIZE, &mBufferUnder1Mb);
//
// Release the lock
//
//
// Check memory allocation success
//
//
// In checked builds we want to assert if the allocate failed.
//
mBufferUnder1Mb = 0;
goto Error;
}
//
// Adjusting the value to be on proper boundary
//
//
// Adjusting the value to be on proper boundary
//
//
// Adjusting the value to be on proper boundary
//
}
//
// Allocate the private device structure for each disk
//
sizeof (BIOS_BLOCK_IO_DEV),
(VOID **) &BiosBlockIoPrivate
);
goto Error;
}
//
// Zero the private device structure
//
//
// Initialize the private device structure
//
if (BiosInitBlockIo (BiosBlockIoPrivate)) {
SetBiosInitBlockIoDevicePath (PciDevPath, &BiosBlockIoPrivate->Bios, &BiosBlockIoPrivate->DevicePath);
//
// Install the Block Io Protocol onto a new child handle
//
);
}
//
// Open For Child Device
//
);
} else {
}
}
if (DeviceEnable) {
PciIo->Attributes (
);
}
gBS->CloseProtocol (
);
if (PciDevPath != NULL) {
gBS->CloseProtocol (
);
}
if (mBufferUnder1Mb != 0 && mActiveInstances == 0) {
//
// Clear the buffer back to 0
//
mBufferUnder1Mb = 0;
}
}
} else {
//
// Successfully installed, so increment the number of active instances
//
}
return Status;
}
/**
Stop the device handled by this driver.
@param This The driver binding protocol.
@param Controller The controller to release.
@param NumberOfChildren The number of handles in ChildHandleBuffer.
@param ChildHandleBuffer The array of child handle.
@retval EFI_SUCCESS The device was stopped.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
@retval Others Fail to uninstall protocols attached on the device.
**/
)
{
//
// Decrement the number of active instances
//
if (mActiveInstances != 0) {
//
// Add a check since the stop function will be called 2 times for each handle
//
}
if ((mActiveInstances == 0) && (mBufferUnder1Mb != 0)) {
//
// Free our global buffer
//
mBufferUnder1Mb = 0;
}
);
return Status;
}
//
// Release PCI I/O and Block IO Protocols on the clild handle.
//
);
}
//
// Shutdown the hardware
//
);
gBS->CloseProtocol (
);
}
if (!AllChildrenStopped) {
return EFI_DEVICE_ERROR;
}
);
);
return EFI_SUCCESS;
}
/**
Build device path for device.
@param BaseDevicePath Base device path.
@param Drive Legacy drive.
@param DevicePath Device path for output.
**/
)
{
//
// BugBug: Check for memory leaks!
//
//
// EDD 3.0 case.
//
}
//
// EDD 1.1 device case or it is unrecognized EDD 3.0 device
//
}
}
/**
Build device path for EDD 3.0.
@param BaseDevicePath Base device path.
@param Drive Legacy drive.
@param DevicePath Device path for output.
@retval EFI_SUCCESS The device path is built successfully.
@retval EFI_UNSUPPORTED It is failed to built device path.
**/
)
{
//
// AVL UINT64 Address;
// AVL EFI_HANDLE Handle;
//
) {
//
// ATA or ATAPI drive found
//
} else {
//
//
if (Controller != 0) {
}
//
// SCSI drive
//
//
// Lun is miss aligned in both EDD and Device Path data structures.
// thus we do a byte copy, to prevent alignment traps on IA-64.
//
//
// USB drive
//
//
// 1394 drive
//
//
// Fibre drive
//
} else {
DEBUG (
(
DEBUG_BLKIO, "It is unrecognized EDD 3.0 device, Drive Number = %x, InterfaceType = %s\n",
)
);
}
}
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}