pciio.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 1,980 行 · 第 1/4 页
C
1,980 行
/*++
Copyright (c) 2004 - 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:
PciIo.c
Abstract:
PCI I/O Abstraction Driver
Revision History
--*/
#include "Pcibus.h"
//
// Internal use only
//
STATIC
EFI_STATUS
ReportErrorStatusCode (
IN PCI_IO_DEVICE *PciIoDevice,
IN EFI_STATUS_CODE_VALUE Code
);
//
// PCI I/O Support Function Prototypes
//
//
//
// Pci Io Protocol Interface
//
static EFI_PCI_IO_PROTOCOL PciIoInterface = {
PciIoPollMem,
PciIoPollIo,
{
PciIoMemRead,
PciIoMemWrite
},
{
PciIoIoRead,
PciIoIoWrite
},
{
PciIoConfigRead,
PciIoConfigWrite
},
PciIoCopyMem,
PciIoMap,
PciIoUnmap,
PciIoAllocateBuffer,
PciIoFreeBuffer,
PciIoFlush,
PciIoGetLocation,
PciIoAttributes,
PciIoGetBarAttributes,
PciIoSetBarAttributes,
0,
NULL
};
STATIC
EFI_STATUS
ReportErrorStatusCode (
IN PCI_IO_DEVICE *PciIoDevice,
IN EFI_STATUS_CODE_VALUE Code
)
/*++
Routine Description:
report a error Status code of PCI bus driver controller
Arguments:
Returns:
None
--*/
// TODO: PciIoDevice - add argument and description to function comment
// TODO: Code - add argument and description to function comment
{
return ReportStatusCodeWithDevicePath (
EFI_ERROR_CODE | EFI_ERROR_MINOR,
Code,
0,
&gEfiCallerIdGuid,
PciIoDevice->DevicePath
);
}
EFI_STATUS
InitializePciIoInstance (
PCI_IO_DEVICE *PciIoDevice
)
/*++
Routine Description:
Initializes a PCI I/O Instance
Arguments:
Returns:
None
--*/
// TODO: PciIoDevice - add argument and description to function comment
// TODO: EFI_SUCCESS - add return value to function comment
{
EfiCopyMem (&PciIoDevice->PciIo, &PciIoInterface, sizeof (EFI_PCI_IO_PROTOCOL));
return EFI_SUCCESS;
}
EFI_STATUS
PciIoVerifyBarAccess (
PCI_IO_DEVICE *PciIoDevice,
UINT8 BarIndex,
PCI_BAR_TYPE Type,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINTN Count,
UINT64 *Offset
)
/*++
Routine Description:
Verifies access to a PCI Base Address Register (BAR)
Arguments:
Returns:
None
--*/
// TODO: PciIoDevice - add argument and description to function comment
// TODO: BarIndex - add argument and description to function comment
// TODO: Type - add argument and description to function comment
// TODO: Width - add argument and description to function comment
// TODO: Count - add argument and description to function comment
// TODO: Offset - add argument and description to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
// TODO: EFI_SUCCESS - add return value to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
// TODO: EFI_SUCCESS - add return value to function comment
{
if (Width < 0 || Width >= EfiPciIoWidthMaximum) {
return EFI_INVALID_PARAMETER;
}
if (BarIndex == EFI_PCI_IO_PASS_THROUGH_BAR) {
return EFI_SUCCESS;
}
//
// BarIndex 0-5 is legal
//
if (BarIndex >= PCI_MAX_BAR) {
return EFI_INVALID_PARAMETER;
}
if (!CheckBarType (PciIoDevice, BarIndex, Type)) {
return EFI_INVALID_PARAMETER;
}
//
// If Width is EfiPciIoWidthFifoUintX then convert to EfiPciIoWidthUintX
// If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
//
if (Width >= EfiPciWidthFifoUint8 && Width <= EfiPciWidthFifoUint64) {
Count = 1;
}
Width &= 0x03;
if ((*Offset + Count * (1 << Width)) - 1 >= PciIoDevice->PciBar[BarIndex].Length) {
return EFI_INVALID_PARAMETER;
}
*Offset = *Offset + PciIoDevice->PciBar[BarIndex].BaseAddress;
return EFI_SUCCESS;
}
EFI_STATUS
PciIoVerifyConfigAccess (
PCI_IO_DEVICE *PciIoDevice,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINTN Count,
IN UINT64 *Offset
)
/*++
Routine Description:
Verifies access to a PCI Config Header
Arguments:
Returns:
None
--*/
// TODO: PciIoDevice - add argument and description to function comment
// TODO: Width - add argument and description to function comment
// TODO: Count - add argument and description to function comment
// TODO: Offset - add argument and description to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
// TODO: EFI_UNSUPPORTED - add return value to function comment
// TODO: EFI_UNSUPPORTED - add return value to function comment
// TODO: EFI_SUCCESS - add return value to function comment
{
UINT64 ExtendOffset;
if (Width < 0 || Width >= EfiPciIoWidthMaximum) {
return EFI_INVALID_PARAMETER;
}
//
// If Width is EfiPciIoWidthFillUintX then convert to EfiPciIoWidthUintX
//
Width &= 0x03;
if (PciIoDevice->IsPciExp) {
if ((*Offset + Count * (1 << Width)) - 1 >= PCI_EXP_MAX_CONFIG_OFFSET) {
return EFI_UNSUPPORTED;
}
ExtendOffset = LShiftU64 (*Offset, 32);
*Offset = EFI_PCI_ADDRESS (PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber, 0);
*Offset = (*Offset) | ExtendOffset;
} else {
if ((*Offset + Count * (1 << Width)) - 1 >= PCI_MAX_CONFIG_OFFSET) {
return EFI_UNSUPPORTED;
}
*Offset = EFI_PCI_ADDRESS (PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber, *Offset);
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
PciIoPollMem (
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINT8 BarIndex,
IN UINT64 Offset,
IN UINT64 Mask,
IN UINT64 Value,
IN UINT64 Delay,
OUT UINT64 *Result
)
/*++
Routine Description:
Poll PCI Memmory
Arguments:
Returns:
None
--*/
// TODO: This - add argument and description to function comment
// TODO: Width - add argument and description to function comment
// TODO: BarIndex - add argument and description to function comment
// TODO: Offset - add argument and description to function comment
// TODO: Mask - add argument and description to function comment
// TODO: Value - add argument and description to function comment
// TODO: Delay - add argument and description to function comment
// TODO: Result - add argument and description to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
// TODO: EFI_UNSUPPORTED - add return value to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
{
EFI_STATUS Status;
PCI_IO_DEVICE *PciIoDevice;
PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);
if (Width < 0 || Width >= EfiPciIoWidthMaximum) {
return EFI_INVALID_PARAMETER;
}
Status = PciIoVerifyBarAccess (PciIoDevice, BarIndex, PciBarTypeMem, Width, 1, &Offset);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
if (Width > EfiPciIoWidthUint64) {
return EFI_INVALID_PARAMETER;
}
Status = PciIoDevice->PciRootBridgeIo->PollMem (
PciIoDevice->PciRootBridgeIo,
(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
Offset,
Mask,
Value,
Delay,
Result
);
if (EFI_ERROR (Status)) {
ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);
}
return Status;
}
EFI_STATUS
EFIAPI
PciIoPollIo (
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINT8 BarIndex,
IN UINT64 Offset,
IN UINT64 Mask,
IN UINT64 Value,
IN UINT64 Delay,
OUT UINT64 *Result
)
/*++
Routine Description:
Poll PCI IO
Arguments:
Returns:
None
--*/
// TODO: This - add argument and description to function comment
// TODO: Width - add argument and description to function comment
// TODO: BarIndex - add argument and description to function comment
// TODO: Offset - add argument and description to function comment
// TODO: Mask - add argument and description to function comment
// TODO: Value - add argument and description to function comment
// TODO: Delay - add argument and description to function comment
// TODO: Result - add argument and description to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
// TODO: EFI_UNSUPPORTED - add return value to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
{
EFI_STATUS Status;
PCI_IO_DEVICE *PciIoDevice;
PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);
if (Width < 0 || Width > EfiPciIoWidthUint64) {
return EFI_INVALID_PARAMETER;
}
Status = PciIoVerifyBarAccess (PciIoDevice, BarIndex, PciBarTypeIo, Width, 1, &Offset);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Status = PciIoDevice->PciRootBridgeIo->PollIo (
PciIoDevice->PciRootBridgeIo,
(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
Offset,
Mask,
Value,
Delay,
Result
);
if (EFI_ERROR (Status)) {
ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_CONTROLLER_ERROR);
}
return Status;
}
EFI_STATUS
EFIAPI
PciIoMemRead (
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINT8 BarIndex,
IN UINT64 Offset,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Performs a PCI Memory Read Cycle
Arguments:
Returns:
None
--*/
// TODO: This - add argument and description to function comment
// TODO: Width - add argument and description to function comment
// TODO: BarIndex - add argument and description to function comment
// TODO: Offset - add argument and description to function comment
// TODO: Count - add argument and description to function comment
// TODO: Buffer - add argument and description to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
// TODO: EFI_UNSUPPORTED - add return value to function comment
{
EFI_STATUS Status;
PCI_IO_DEVICE *PciIoDevice;
PciIoDevice = PCI_IO_DEVICE_FROM_PCI_IO_THIS (This);
if (Width < 0 || Width >= EfiPciIoWidthMaximum) {
return EFI_INVALID_PARAMETER;
}
Status = PciIoVerifyBarAccess (PciIoDevice, BarIndex, PciBarTypeMem, Width, Count, &Offset);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Status = PciIoDevice->PciRootBridgeIo->Mem.Read (
PciIoDevice->PciRootBridgeIo,
(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
Offset,
Count,
Buffer
);
if (EFI_ERROR (Status)) {
ReportErrorStatusCode (PciIoDevice, EFI_IO_BUS_PCI | EFI_IOB_EC_READ_ERROR);
}
return Status;
}
EFI_STATUS
EFIAPI
PciIoMemWrite (
IN EFI_PCI_IO_PROTOCOL *This,
IN EFI_PCI_IO_PROTOCOL_WIDTH Width,
IN UINT8 BarIndex,
IN UINT64 Offset,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Performs a PCI Memory Write Cycle
Arguments:
Returns:
None
--*/
// TODO: This - add argument and description to function comment
// TODO: Width - add argument and description to function comment
// TODO: BarIndex - add argument and description to function comment
// TODO: Offset - add argument and description to function comment
// TODO: Count - add argument and description to function comment
// TODO: Buffer - add argument and description to function comment
// TODO: EFI_INVALID_PARAMETER - add return value to function comment
// TODO: EFI_UNSUPPORTED - add return value to function comment
{
EFI_STATUS Status;
PCI_IO_DEVICE *PciIoDevice;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?