add modules DiskIo, Partition and SecurityStub.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2732 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
46
MdeModulePkg/Universal/Disk/DiskIo/Dxe/CommonHeader.h
Normal file
46
MdeModulePkg/Universal/Disk/DiskIo/Dxe/CommonHeader.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/**@file
|
||||
Common header file shared by all source files.
|
||||
|
||||
This file includes package header files, library classes and protocol, PPI & GUID definitions.
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
#ifndef __COMMON_HEADER_H_
|
||||
#define __COMMON_HEADER_H_
|
||||
|
||||
|
||||
//
|
||||
// The package level header files this module uses
|
||||
//
|
||||
#include <Uefi.h>
|
||||
//
|
||||
// The protocols, PPI and GUID defintions for this module
|
||||
//
|
||||
#include <Protocol/BlockIo.h>
|
||||
#include <Protocol/ComponentName.h>
|
||||
#include <Protocol/DriverBinding.h>
|
||||
#include <Protocol/DiskIo.h>
|
||||
//
|
||||
// The Library classes this module consumes
|
||||
//
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/UefiDriverEntryPoint.h>
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
//
|
||||
// Driver Binding Externs
|
||||
//
|
||||
extern EFI_DRIVER_BINDING_PROTOCOL gDiskIoDriverBinding;
|
||||
extern EFI_COMPONENT_NAME_PROTOCOL gDiskIoComponentName;
|
||||
|
||||
#endif
|
144
MdeModulePkg/Universal/Disk/DiskIo/Dxe/ComponentName.c
Normal file
144
MdeModulePkg/Universal/Disk/DiskIo/Dxe/ComponentName.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/*++
|
||||
|
||||
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.
|
||||
|
||||
Module Name:
|
||||
|
||||
ComponentName.c
|
||||
|
||||
Abstract:
|
||||
|
||||
--*/
|
||||
|
||||
//
|
||||
// Include common header file for this module.
|
||||
//
|
||||
#include "CommonHeader.h"
|
||||
|
||||
#include "DiskIo.h"
|
||||
|
||||
//
|
||||
// EFI Component Name Protocol
|
||||
//
|
||||
EFI_COMPONENT_NAME_PROTOCOL gDiskIoComponentName = {
|
||||
DiskIoComponentNameGetDriverName,
|
||||
DiskIoComponentNameGetControllerName,
|
||||
"eng"
|
||||
};
|
||||
|
||||
static EFI_UNICODE_STRING_TABLE mDiskIoDriverNameTable[] = {
|
||||
{
|
||||
"eng",
|
||||
(CHAR16 *)L"Generic Disk I/O Driver"
|
||||
},
|
||||
{
|
||||
NULL,
|
||||
NULL
|
||||
}
|
||||
};
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoComponentNameGetDriverName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **DriverName
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Retrieves a Unicode string that is the user readable name of the EFI Driver.
|
||||
|
||||
Arguments:
|
||||
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
|
||||
Language - A pointer to a three character ISO 639-2 language identifier.
|
||||
This is the language of the driver name that that the caller
|
||||
is requesting, and it must match one of the languages specified
|
||||
in SupportedLanguages. The number of languages supported by a
|
||||
driver is up to the driver writer.
|
||||
DriverName - A pointer to the Unicode string to return. This Unicode string
|
||||
is the name of the driver specified by This in the language
|
||||
specified by Language.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS - The Unicode string for the Driver specified by This
|
||||
and the language specified by Language was returned
|
||||
in DriverName.
|
||||
EFI_INVALID_PARAMETER - Language is NULL.
|
||||
EFI_INVALID_PARAMETER - DriverName is NULL.
|
||||
EFI_UNSUPPORTED - The driver specified by This does not support the
|
||||
language specified by Language.
|
||||
|
||||
--*/
|
||||
{
|
||||
return LookupUnicodeString (
|
||||
Language,
|
||||
gDiskIoComponentName.SupportedLanguages,
|
||||
mDiskIoDriverNameTable,
|
||||
DriverName
|
||||
);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoComponentNameGetControllerName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_HANDLE ChildHandle OPTIONAL,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **ControllerName
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Retrieves a Unicode string that is the user readable name of the controller
|
||||
that is being managed by an EFI Driver.
|
||||
|
||||
Arguments:
|
||||
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
|
||||
ControllerHandle - The handle of a controller that the driver specified by
|
||||
This is managing. This handle specifies the controller
|
||||
whose name is to be returned.
|
||||
ChildHandle - The handle of the child controller to retrieve the name
|
||||
of. This is an optional parameter that may be NULL. It
|
||||
will be NULL for device drivers. It will also be NULL
|
||||
for a bus drivers that wish to retrieve the name of the
|
||||
bus controller. It will not be NULL for a bus driver
|
||||
that wishes to retrieve the name of a child controller.
|
||||
Language - A pointer to a three character ISO 639-2 language
|
||||
identifier. This is the language of the controller name
|
||||
that that the caller is requesting, and it must match one
|
||||
of the languages specified in SupportedLanguages. The
|
||||
number of languages supported by a driver is up to the
|
||||
driver writer.
|
||||
ControllerName - A pointer to the Unicode string to return. This Unicode
|
||||
string is the name of the controller specified by
|
||||
ControllerHandle and ChildHandle in the language specified
|
||||
by Language from the point of view of the driver specified
|
||||
by This.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS - The Unicode string for the user readable name in the
|
||||
language specified by Language for the driver
|
||||
specified by This was returned in DriverName.
|
||||
EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
|
||||
EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
|
||||
EFI_INVALID_PARAMETER - Language is NULL.
|
||||
EFI_INVALID_PARAMETER - ControllerName is NULL.
|
||||
EFI_UNSUPPORTED - The driver specified by This is not currently managing
|
||||
the controller specified by ControllerHandle and
|
||||
ChildHandle.
|
||||
EFI_UNSUPPORTED - The driver specified by This does not support the
|
||||
language specified by Language.
|
||||
|
||||
--*/
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
122
MdeModulePkg/Universal/Disk/DiskIo/Dxe/DiskIo.h
Normal file
122
MdeModulePkg/Universal/Disk/DiskIo/Dxe/DiskIo.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/*++
|
||||
|
||||
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.
|
||||
|
||||
Module Name:
|
||||
|
||||
DiskIo.h
|
||||
|
||||
Abstract:
|
||||
Private Data definition for Disk IO driver
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef _DISK_IO_H
|
||||
#define _DISK_IO_H
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Include common header file for this module.
|
||||
//
|
||||
#include "CommonHeader.h"
|
||||
|
||||
#define DISK_IO_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('d', 's', 'k', 'I')
|
||||
|
||||
#define DATA_BUFFER_BLOCK_NUM (64)
|
||||
|
||||
typedef struct {
|
||||
UINTN Signature;
|
||||
EFI_DISK_IO_PROTOCOL DiskIo;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlockIo;
|
||||
} DISK_IO_PRIVATE_DATA;
|
||||
|
||||
#define DISK_IO_PRIVATE_DATA_FROM_THIS(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo, DISK_IO_PRIVATE_DATA_SIGNATURE)
|
||||
|
||||
//
|
||||
// Global Variables
|
||||
//
|
||||
extern EFI_DRIVER_BINDING_PROTOCOL gDiskIoDriverBinding;
|
||||
extern EFI_COMPONENT_NAME_PROTOCOL gDiskIoComponentName;
|
||||
|
||||
//
|
||||
// Prototypes
|
||||
// Driver model protocol interface
|
||||
//
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoDriverBindingSupported (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoDriverBindingStart (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoDriverBindingStop (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN UINTN NumberOfChildren,
|
||||
IN EFI_HANDLE *ChildHandleBuffer
|
||||
);
|
||||
|
||||
//
|
||||
// Disk I/O Protocol Interface
|
||||
//
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoReadDisk (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoWriteDisk (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
//
|
||||
// EFI Component Name Functions
|
||||
//
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoComponentNameGetDriverName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **DriverName
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoComponentNameGetControllerName (
|
||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_HANDLE ChildHandle OPTIONAL,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **ControllerName
|
||||
);
|
||||
|
||||
#endif
|
105
MdeModulePkg/Universal/Disk/DiskIo/Dxe/DiskIo.inf
Normal file
105
MdeModulePkg/Universal/Disk/DiskIo/Dxe/DiskIo.inf
Normal file
@@ -0,0 +1,105 @@
|
||||
#/** @file
|
||||
# Component description file for DiskIo module.
|
||||
#
|
||||
# DiskIo driver that layers it's self on every Block IO protocol in the system.
|
||||
# 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.
|
||||
#
|
||||
#
|
||||
#**/
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Defines Section - statements that will be processed to create a Makefile.
|
||||
#
|
||||
################################################################################
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = DiskIo
|
||||
FILE_GUID = 6B38F7B4-AD98-40e9-9093-ACA2B5A253C4
|
||||
MODULE_TYPE = UEFI_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
EDK_RELEASE_VERSION = 0x00020000
|
||||
EFI_SPECIFICATION_VERSION = 0x00020000
|
||||
|
||||
ENTRY_POINT = InitializeDiskIo
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
# DRIVER_BINDING = gDiskIoDriverBinding
|
||||
# COMPONENT_NAME = gDiskIoComponentName
|
||||
#
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Sources Section - list of files that are required for the build to succeed.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
[Sources.common]
|
||||
ComponentName.c
|
||||
DiskIo.h
|
||||
diskio.c
|
||||
CommonHeader.h
|
||||
EntryPoint.c
|
||||
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Includes Section - list of Include locations that are required for
|
||||
# this module.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
[Includes]
|
||||
$(WORKSPACE)/MdePkg\Include/Library
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Package Dependency Section - list of Package files that are required for
|
||||
# this module.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
[Packages]
|
||||
$(WORKSPACE)\MdeModulePkg/MdeModulePkg.dec
|
||||
$(WORKSPACE)\MdePkg/MdePkg.dec
|
||||
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Library Class Section - list of Library Classes that are required for
|
||||
# this module.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
[LibraryClasses]
|
||||
UefiBootServicesTableLib
|
||||
MemoryAllocationLib
|
||||
BaseMemoryLib
|
||||
BaseLib
|
||||
UefiLib
|
||||
UefiDriverEntryPoint
|
||||
DebugLib
|
||||
|
||||
|
||||
################################################################################
|
||||
#
|
||||
# Protocol C Name Section - list of Protocol and Protocol Notify C Names
|
||||
# that this module uses or produces.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
[Protocols]
|
||||
gEfiDiskIoProtocolGuid # PROTOCOL BY_START
|
||||
gEfiBlockIoProtocolGuid # PROTOCOL TO_START
|
||||
|
75
MdeModulePkg/Universal/Disk/DiskIo/Dxe/DiskIo.msa
Normal file
75
MdeModulePkg/Universal/Disk/DiskIo/Dxe/DiskIo.msa
Normal file
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
|
||||
<MsaHeader>
|
||||
<ModuleName>DiskIo</ModuleName>
|
||||
<ModuleType>UEFI_DRIVER</ModuleType>
|
||||
<GuidValue>6B38F7B4-AD98-40e9-9093-ACA2B5A253C4</GuidValue>
|
||||
<Version>1.0</Version>
|
||||
<Abstract>Component description file for DiskIo module.</Abstract>
|
||||
<Description>DiskIo driver that layers it's self on every Block IO protocol in the system.</Description>
|
||||
<Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>
|
||||
<License>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.</License>
|
||||
<Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
|
||||
</MsaHeader>
|
||||
<ModuleDefinitions>
|
||||
<SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
|
||||
<BinaryModule>false</BinaryModule>
|
||||
<OutputFileBasename>DiskIo</OutputFileBasename>
|
||||
</ModuleDefinitions>
|
||||
<LibraryClassDefinitions>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED" RecommendedInstanceGuid="bda39d3a-451b-4350-8266-81ab10fa0523">
|
||||
<Keyword>DebugLib</Keyword>
|
||||
<HelpText>Recommended libary Instance is PeiDxeDebugLibReportStatusCode instance in MdePkg.</HelpText>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>UefiDriverModelLib</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>UefiDriverEntryPoint</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>UefiLib</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>BaseLib</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>BaseMemoryLib</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>MemoryAllocationLib</Keyword>
|
||||
</LibraryClass>
|
||||
<LibraryClass Usage="ALWAYS_CONSUMED">
|
||||
<Keyword>UefiBootServicesTableLib</Keyword>
|
||||
</LibraryClass>
|
||||
</LibraryClassDefinitions>
|
||||
<SourceFiles>
|
||||
<Filename>diskio.c</Filename>
|
||||
<Filename>DiskIo.h</Filename>
|
||||
<Filename>ComponentName.c</Filename>
|
||||
</SourceFiles>
|
||||
<PackageDependencies>
|
||||
<Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
|
||||
</PackageDependencies>
|
||||
<Protocols>
|
||||
<Protocol Usage="TO_START">
|
||||
<ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>
|
||||
</Protocol>
|
||||
<Protocol Usage="BY_START">
|
||||
<ProtocolCName>gEfiDiskIoProtocolGuid</ProtocolCName>
|
||||
</Protocol>
|
||||
</Protocols>
|
||||
<Externs>
|
||||
<Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
|
||||
<Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
|
||||
<Extern>
|
||||
<DriverBinding>gDiskIoDriverBinding</DriverBinding>
|
||||
<ComponentName>gDiskIoComponentName</ComponentName>
|
||||
</Extern>
|
||||
</Externs>
|
||||
</ModuleSurfaceArea>
|
56
MdeModulePkg/Universal/Disk/DiskIo/Dxe/EntryPoint.c
Normal file
56
MdeModulePkg/Universal/Disk/DiskIo/Dxe/EntryPoint.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/**@file
|
||||
Entry Point Source file.
|
||||
|
||||
This file contains the user entry point
|
||||
|
||||
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.
|
||||
**/
|
||||
|
||||
|
||||
//
|
||||
// Include common header file for this module.
|
||||
//
|
||||
#include "CommonHeader.h"
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeDiskIo(
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Install driver model protocol(s).
|
||||
//
|
||||
Status = EfiLibInstallAllDriverProtocols (
|
||||
ImageHandle,
|
||||
SystemTable,
|
||||
&gDiskIoDriverBinding,
|
||||
ImageHandle,
|
||||
&gDiskIoComponentName,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
|
||||
return Status;
|
||||
}
|
734
MdeModulePkg/Universal/Disk/DiskIo/Dxe/diskio.c
Normal file
734
MdeModulePkg/Universal/Disk/DiskIo/Dxe/diskio.c
Normal file
@@ -0,0 +1,734 @@
|
||||
/*++
|
||||
|
||||
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.
|
||||
|
||||
Module Name:
|
||||
|
||||
DiskIo.c
|
||||
|
||||
Abstract:
|
||||
|
||||
DiskIo driver that layers it's self on every Block IO protocol in the system.
|
||||
DiskIo converts a block oriented device to a byte oriented device.
|
||||
|
||||
ReadDisk may have to do 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.
|
||||
|
||||
--*/
|
||||
|
||||
//
|
||||
// Include common header file for this module.
|
||||
//
|
||||
#include "CommonHeader.h"
|
||||
|
||||
#include "DiskIo.h"
|
||||
|
||||
EFI_DRIVER_BINDING_PROTOCOL gDiskIoDriverBinding = {
|
||||
DiskIoDriverBindingSupported,
|
||||
DiskIoDriverBindingStart,
|
||||
DiskIoDriverBindingStop,
|
||||
0xa,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
DISK_IO_PRIVATE_DATA gDiskIoPrivateDataTemplate = {
|
||||
DISK_IO_PRIVATE_DATA_SIGNATURE,
|
||||
{
|
||||
EFI_DISK_IO_PROTOCOL_REVISION,
|
||||
DiskIoReadDisk,
|
||||
DiskIoWriteDisk
|
||||
},
|
||||
NULL
|
||||
};
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoDriverBindingSupported (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Test to see if this driver supports ControllerHandle. Any ControllerHandle
|
||||
than contains a BlockIo protocol can be supported.
|
||||
|
||||
Arguments:
|
||||
This - Protocol instance pointer.
|
||||
ControllerHandle - Handle of device to test.
|
||||
RemainingDevicePath - Not used.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS - This driver supports this device.
|
||||
EFI_ALREADY_STARTED - This driver is already running on this device.
|
||||
other - This driver does not support this device.
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlockIo;
|
||||
|
||||
//
|
||||
// Open the IO Abstraction(s) needed to perform the supported test.
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
ControllerHandle,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
(VOID **) &BlockIo,
|
||||
This->DriverBindingHandle,
|
||||
ControllerHandle,
|
||||
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
//
|
||||
// Close the I/O Abstraction(s) used to perform the supported test.
|
||||
//
|
||||
gBS->CloseProtocol (
|
||||
ControllerHandle,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
This->DriverBindingHandle,
|
||||
ControllerHandle
|
||||
);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoDriverBindingStart (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Start this driver on ControllerHandle by opening a Block IO protocol and
|
||||
installing a Disk IO protocol on ControllerHandle.
|
||||
|
||||
Arguments:
|
||||
This - Protocol instance pointer.
|
||||
ControllerHandle - Handle of device to bind driver to.
|
||||
RemainingDevicePath - Not used, always produce all possible children.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS - This driver is added to ControllerHandle.
|
||||
EFI_ALREADY_STARTED - This driver is already running on ControllerHandle.
|
||||
other - This driver does not support this device.
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
DISK_IO_PRIVATE_DATA *Private;
|
||||
|
||||
Private = NULL;
|
||||
|
||||
//
|
||||
// Connect to the Block IO interface on ControllerHandle.
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
ControllerHandle,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
(VOID **) &gDiskIoPrivateDataTemplate.BlockIo,
|
||||
This->DriverBindingHandle,
|
||||
ControllerHandle,
|
||||
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
//
|
||||
// Initialize the Disk IO device instance.
|
||||
//
|
||||
Private = AllocateCopyPool (sizeof (DISK_IO_PRIVATE_DATA), &gDiskIoPrivateDataTemplate);
|
||||
if (Private == NULL) {
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto ErrorExit;
|
||||
}
|
||||
//
|
||||
// Install protocol interfaces for the Disk IO device.
|
||||
//
|
||||
Status = gBS->InstallProtocolInterface (
|
||||
&ControllerHandle,
|
||||
&gEfiDiskIoProtocolGuid,
|
||||
EFI_NATIVE_INTERFACE,
|
||||
&Private->DiskIo
|
||||
);
|
||||
|
||||
ErrorExit:
|
||||
if (EFI_ERROR (Status)) {
|
||||
|
||||
if (Private != NULL) {
|
||||
FreePool (Private);
|
||||
}
|
||||
|
||||
gBS->CloseProtocol (
|
||||
ControllerHandle,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
This->DriverBindingHandle,
|
||||
ControllerHandle
|
||||
);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoDriverBindingStop (
|
||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN UINTN NumberOfChildren,
|
||||
IN EFI_HANDLE *ChildHandleBuffer
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Stop this driver on ControllerHandle by removing Disk IO protocol and closing
|
||||
the Block IO protocol on ControllerHandle.
|
||||
|
||||
Arguments:
|
||||
This - Protocol instance pointer.
|
||||
ControllerHandle - Handle of device to stop driver on.
|
||||
NumberOfChildren - Not used.
|
||||
ChildHandleBuffer - Not used.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS - This driver is removed ControllerHandle.
|
||||
other - This driver was not removed from this device.
|
||||
EFI_UNSUPPORTED
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_DISK_IO_PROTOCOL *DiskIo;
|
||||
DISK_IO_PRIVATE_DATA *Private;
|
||||
|
||||
//
|
||||
// Get our context back.
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
ControllerHandle,
|
||||
&gEfiDiskIoProtocolGuid,
|
||||
(VOID **) &DiskIo,
|
||||
This->DriverBindingHandle,
|
||||
ControllerHandle,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Private = DISK_IO_PRIVATE_DATA_FROM_THIS (DiskIo);
|
||||
|
||||
Status = gBS->UninstallProtocolInterface (
|
||||
ControllerHandle,
|
||||
&gEfiDiskIoProtocolGuid,
|
||||
&Private->DiskIo
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
|
||||
Status = gBS->CloseProtocol (
|
||||
ControllerHandle,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
This->DriverBindingHandle,
|
||||
ControllerHandle
|
||||
);
|
||||
}
|
||||
|
||||
if (!EFI_ERROR (Status)) {
|
||||
FreePool (Private);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoReadDisk (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
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.
|
||||
|
||||
|
||||
Arguments:
|
||||
This - Protocol instance pointer.
|
||||
MediaId - Id of the media, changes every time the media is replaced.
|
||||
Offset - The starting byte offset to read from.
|
||||
BufferSize - Size of Buffer.
|
||||
Buffer - Buffer containing read data.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS - The data was read correctly from the device.
|
||||
EFI_DEVICE_ERROR - The device reported an error while performing the read.
|
||||
EFI_NO_MEDIA - There is no media in the device.
|
||||
EFI_MEDIA_CHNAGED - The MediaId does not matched the current device.
|
||||
EFI_INVALID_PARAMETER - The read request contains device addresses that are not
|
||||
valid for the device.
|
||||
EFI_OUT_OF_RESOURCES
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
DISK_IO_PRIVATE_DATA *Private;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlockIo;
|
||||
EFI_BLOCK_IO_MEDIA *Media;
|
||||
UINT32 BlockSize;
|
||||
UINT64 Lba;
|
||||
UINT64 OverRunLba;
|
||||
UINT32 UnderRun;
|
||||
UINT32 OverRun;
|
||||
BOOLEAN TransactionComplete;
|
||||
UINTN WorkingBufferSize;
|
||||
UINT8 *WorkingBuffer;
|
||||
UINTN Length;
|
||||
UINT8 *Data;
|
||||
UINT8 *PreData;
|
||||
UINTN IsBufferAligned;
|
||||
UINTN DataBufferSize;
|
||||
BOOLEAN LastRead;
|
||||
|
||||
Private = DISK_IO_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
BlockIo = Private->BlockIo;
|
||||
Media = BlockIo->Media;
|
||||
BlockSize = Media->BlockSize;
|
||||
|
||||
if (Media->MediaId != MediaId) {
|
||||
return EFI_MEDIA_CHANGED;
|
||||
}
|
||||
|
||||
WorkingBuffer = Buffer;
|
||||
WorkingBufferSize = BufferSize;
|
||||
|
||||
//
|
||||
// Allocate a temporary buffer for operation
|
||||
//
|
||||
DataBufferSize = BlockSize * DATA_BUFFER_BLOCK_NUM;
|
||||
|
||||
if (Media->IoAlign > 1) {
|
||||
PreData = AllocatePool (DataBufferSize + Media->IoAlign);
|
||||
Data = PreData - ((UINTN) PreData & (Media->IoAlign - 1)) + Media->IoAlign;
|
||||
} else {
|
||||
PreData = AllocatePool (DataBufferSize);
|
||||
Data = PreData;
|
||||
}
|
||||
|
||||
if (PreData == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
Lba = DivU64x32Remainder (Offset, BlockSize, &UnderRun);
|
||||
|
||||
Length = BlockSize - UnderRun;
|
||||
TransactionComplete = FALSE;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
if (UnderRun != 0) {
|
||||
//
|
||||
// Offset starts in the middle of an Lba, so read the entire block.
|
||||
//
|
||||
Status = BlockIo->ReadBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
Lba,
|
||||
BlockSize,
|
||||
Data
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
if (Length > BufferSize) {
|
||||
Length = BufferSize;
|
||||
TransactionComplete = TRUE;
|
||||
}
|
||||
|
||||
CopyMem (WorkingBuffer, Data + UnderRun, Length);
|
||||
|
||||
WorkingBuffer += Length;
|
||||
|
||||
WorkingBufferSize -= Length;
|
||||
if (WorkingBufferSize == 0) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
Lba += 1;
|
||||
}
|
||||
|
||||
OverRunLba = Lba + DivU64x32Remainder (WorkingBufferSize, BlockSize, &OverRun);
|
||||
|
||||
if (!TransactionComplete && WorkingBufferSize >= BlockSize) {
|
||||
//
|
||||
// If the DiskIo maps directly to a BlockIo device do the read.
|
||||
//
|
||||
if (OverRun != 0) {
|
||||
WorkingBufferSize -= OverRun;
|
||||
}
|
||||
//
|
||||
// Check buffer alignment
|
||||
//
|
||||
IsBufferAligned = (UINTN) WorkingBuffer & (UINTN) (Media->IoAlign - 1);
|
||||
|
||||
if (Media->IoAlign <= 1 || IsBufferAligned == 0) {
|
||||
//
|
||||
// Alignment is satisfied, so read them together
|
||||
//
|
||||
Status = BlockIo->ReadBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
Lba,
|
||||
WorkingBufferSize,
|
||||
WorkingBuffer
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
WorkingBuffer += WorkingBufferSize;
|
||||
|
||||
} 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
|
||||
//
|
||||
LastRead = FALSE;
|
||||
do {
|
||||
if (WorkingBufferSize <= DataBufferSize) {
|
||||
//
|
||||
// It is the last calling to readblocks in this loop
|
||||
//
|
||||
DataBufferSize = WorkingBufferSize;
|
||||
LastRead = TRUE;
|
||||
}
|
||||
|
||||
Status = BlockIo->ReadBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
Lba,
|
||||
DataBufferSize,
|
||||
Data
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
CopyMem (WorkingBuffer, Data, DataBufferSize);
|
||||
WorkingBufferSize -= DataBufferSize;
|
||||
WorkingBuffer += DataBufferSize;
|
||||
Lba += DATA_BUFFER_BLOCK_NUM;
|
||||
} while (!LastRead);
|
||||
}
|
||||
}
|
||||
|
||||
if (!TransactionComplete && OverRun != 0) {
|
||||
//
|
||||
// Last read is not a complete block.
|
||||
//
|
||||
Status = BlockIo->ReadBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
OverRunLba,
|
||||
BlockSize,
|
||||
Data
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
CopyMem (WorkingBuffer, Data, OverRun);
|
||||
}
|
||||
|
||||
Done:
|
||||
if (PreData != NULL) {
|
||||
FreePool (PreData);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DiskIoWriteDisk (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Read BufferSize bytes from Offset into Buffer.
|
||||
|
||||
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.
|
||||
|
||||
Arguments:
|
||||
This - Protocol instance pointer.
|
||||
MediaId - Id of the media, changes every time the media is replaced.
|
||||
Offset - The starting byte offset to read from.
|
||||
BufferSize - Size of Buffer.
|
||||
Buffer - Buffer containing read data.
|
||||
|
||||
Returns:
|
||||
EFI_SUCCESS - The data was written correctly to the device.
|
||||
EFI_WRITE_PROTECTED - The device can not be written to.
|
||||
EFI_DEVICE_ERROR - The device reported an error while performing the write.
|
||||
EFI_NO_MEDIA - There is no media in the device.
|
||||
EFI_MEDIA_CHNAGED - The MediaId does not matched the current device.
|
||||
EFI_INVALID_PARAMETER - The write request contains device addresses that are not
|
||||
valid for the device.
|
||||
EFI_OUT_OF_RESOURCES
|
||||
|
||||
--*/
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
DISK_IO_PRIVATE_DATA *Private;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlockIo;
|
||||
EFI_BLOCK_IO_MEDIA *Media;
|
||||
UINT32 BlockSize;
|
||||
UINT64 Lba;
|
||||
UINT64 OverRunLba;
|
||||
UINT32 UnderRun;
|
||||
UINT32 OverRun;
|
||||
BOOLEAN TransactionComplete;
|
||||
UINTN WorkingBufferSize;
|
||||
UINT8 *WorkingBuffer;
|
||||
UINTN Length;
|
||||
UINT8 *Data;
|
||||
UINT8 *PreData;
|
||||
UINTN IsBufferAligned;
|
||||
UINTN DataBufferSize;
|
||||
BOOLEAN LastWrite;
|
||||
|
||||
Private = DISK_IO_PRIVATE_DATA_FROM_THIS (This);
|
||||
|
||||
BlockIo = Private->BlockIo;
|
||||
Media = BlockIo->Media;
|
||||
BlockSize = Media->BlockSize;
|
||||
|
||||
if (Media->ReadOnly) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
if (Media->MediaId != MediaId) {
|
||||
return EFI_MEDIA_CHANGED;
|
||||
}
|
||||
|
||||
DataBufferSize = BlockSize * DATA_BUFFER_BLOCK_NUM;
|
||||
|
||||
if (Media->IoAlign > 1) {
|
||||
PreData = AllocatePool (DataBufferSize + Media->IoAlign);
|
||||
Data = PreData - ((UINTN) PreData & (Media->IoAlign - 1)) + Media->IoAlign;
|
||||
} else {
|
||||
PreData = AllocatePool (DataBufferSize);
|
||||
Data = PreData;
|
||||
}
|
||||
|
||||
if (PreData == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
WorkingBuffer = Buffer;
|
||||
WorkingBufferSize = BufferSize;
|
||||
|
||||
Lba = DivU64x32Remainder (Offset, BlockSize, &UnderRun);
|
||||
|
||||
Length = BlockSize - UnderRun;
|
||||
TransactionComplete = FALSE;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
if (UnderRun != 0) {
|
||||
//
|
||||
// Offset starts in the middle of an Lba, so do read modify write.
|
||||
//
|
||||
Status = BlockIo->ReadBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
Lba,
|
||||
BlockSize,
|
||||
Data
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
if (Length > BufferSize) {
|
||||
Length = BufferSize;
|
||||
TransactionComplete = TRUE;
|
||||
}
|
||||
|
||||
CopyMem (Data + UnderRun, WorkingBuffer, Length);
|
||||
|
||||
Status = BlockIo->WriteBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
Lba,
|
||||
BlockSize,
|
||||
Data
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
WorkingBuffer += Length;
|
||||
WorkingBufferSize -= Length;
|
||||
if (WorkingBufferSize == 0) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
Lba += 1;
|
||||
}
|
||||
|
||||
OverRunLba = Lba + DivU64x32Remainder (WorkingBufferSize, BlockSize, &OverRun);
|
||||
|
||||
if (!TransactionComplete && WorkingBufferSize >= BlockSize) {
|
||||
//
|
||||
// If the DiskIo maps directly to a BlockIo device do the write.
|
||||
//
|
||||
if (OverRun != 0) {
|
||||
WorkingBufferSize -= OverRun;
|
||||
}
|
||||
//
|
||||
// Check buffer alignment
|
||||
//
|
||||
IsBufferAligned = (UINTN) WorkingBuffer & (UINTN) (Media->IoAlign - 1);
|
||||
|
||||
if (Media->IoAlign <= 1 || IsBufferAligned == 0) {
|
||||
//
|
||||
// Alignment is satisfied, so write them together
|
||||
//
|
||||
Status = BlockIo->WriteBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
Lba,
|
||||
WorkingBufferSize,
|
||||
WorkingBuffer
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
WorkingBuffer += WorkingBufferSize;
|
||||
|
||||
} else {
|
||||
//
|
||||
// The buffer parameter is not aligned with the request
|
||||
// So use the allocated instead.
|
||||
// It can fit almost all the cases.
|
||||
//
|
||||
LastWrite = FALSE;
|
||||
do {
|
||||
if (WorkingBufferSize <= DataBufferSize) {
|
||||
//
|
||||
// It is the last calling to writeblocks in this loop
|
||||
//
|
||||
DataBufferSize = WorkingBufferSize;
|
||||
LastWrite = TRUE;
|
||||
}
|
||||
|
||||
CopyMem (Data, WorkingBuffer, DataBufferSize);
|
||||
Status = BlockIo->WriteBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
Lba,
|
||||
DataBufferSize,
|
||||
Data
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
WorkingBufferSize -= DataBufferSize;
|
||||
WorkingBuffer += DataBufferSize;
|
||||
Lba += DATA_BUFFER_BLOCK_NUM;
|
||||
} while (!LastWrite);
|
||||
}
|
||||
}
|
||||
|
||||
if (!TransactionComplete && OverRun != 0) {
|
||||
//
|
||||
// Last bit is not a complete block, so do a read modify write.
|
||||
//
|
||||
Status = BlockIo->ReadBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
OverRunLba,
|
||||
BlockSize,
|
||||
Data
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
CopyMem (Data, WorkingBuffer, OverRun);
|
||||
|
||||
Status = BlockIo->WriteBlocks (
|
||||
BlockIo,
|
||||
MediaId,
|
||||
OverRunLba,
|
||||
BlockSize,
|
||||
Data
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
}
|
||||
|
||||
Done:
|
||||
if (PreData != NULL) {
|
||||
FreePool (PreData);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
Reference in New Issue
Block a user