1. Use the PciIo->GetBarAttributes to find the logical bar index of the memory mapped bar and IO mapped bar.

2. Remove unused code for undi 3.0.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu, Siyuan <siyuan.fu@intel.com>
Reviewed-By: Ye, Ting (ting.ye@intel.com)
Reviewed-By: Ni, Ruiyu <ruiyu.ni@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16104 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Fu, Siyuan
2014-09-15 03:37:58 +00:00
committed by sfu5
parent 6c22c0a35d
commit c4a7d20890
3 changed files with 74 additions and 630 deletions

View File

@@ -1,9 +1,9 @@
/** @file
This file contains two sets of callback routines for undi3.0 and undi3.1.
This file contains the callback routines for undi3.1.
the callback routines for Undi3.1 have an extra parameter UniqueId which
stores the interface context for the NIC that snp is trying to talk.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, 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
@@ -16,218 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "Snp.h"
//
// Global variables
// these 2 global variables are used only for 3.0 undi. we could not place
// them in the snp structure because we will not know which snp structure
// in the callback context!
//
BOOLEAN mInitializeLock = TRUE;
EFI_LOCK mLock;
//
// End Global variables
//
extern EFI_PCI_IO_PROTOCOL *mPciIo;
/**
Convert a virtual or CPU address provided by SNP to a physical or device
address.
This is a callback routine supplied to UNDI at undi_start time. Since EFI uses
the identical mapping, this routine returns the physical address same as the
virtual address for most of the addresses. an address above 4GB cannot
generally be used as a device address, it needs to be mapped to a lower
physical address. This routine does not call the map routine itself, but it
assumes that the mapping was done at the time of providing the address to
UNDI. This routine just looks up the address in a map table (which is the v2p
structure chain).
@param CpuAddr Virtual address.
@param DeviceAddrPtr Pointer to the physical address, or 0 in case of any
error.
**/
VOID
EFIAPI
SnpUndi32CallbackV2p30 (
IN UINT64 CpuAddr,
IN OUT UINT64 DeviceAddrPtr
)
{
V2P *V2p;
//
// Do nothing if virtual address is zero or physical pointer is NULL.
// No need to map if the virtual address is within 4GB limit since
// EFI uses identical mapping
//
if ((CpuAddr == 0) || (DeviceAddrPtr == 0)) {
DEBUG ((EFI_D_NET, "\nv2p: Null virtual address or physical pointer.\n"));
return ;
}
if (CpuAddr < FOUR_GIGABYTES) {
*(UINT64 *) (UINTN) DeviceAddrPtr = CpuAddr;
return ;
}
//
// SNP creates a vaddr tp paddr mapping at the time of calling undi with any
// big address, this callback routine just looks up in the v2p list and
// returns the physical address for any given virtual address.
//
if (FindV2p (&V2p, (VOID *) (UINTN) CpuAddr) != EFI_SUCCESS) {
*(UINT64 *) (UINTN) DeviceAddrPtr = CpuAddr;
} else {
*(UINT64 *) (UINTN) DeviceAddrPtr = V2p->PhysicalAddress;
}
}
/**
Acquire or release a lock of an exclusive access to a critical section of the
code/data.
This is a callback routine supplied to UNDI at undi_start time.
@param Enable Non-zero indicates acquire; Zero indicates release.
**/
VOID
EFIAPI
SnpUndi32CallbackBlock30 (
IN UINT32 Enable
)
{
//
// tcpip was calling snp at tpl_notify and if we acquire a lock that was
// created at a lower level (TPL_CALLBACK) it gives an assert!
//
if (mInitializeLock) {
EfiInitializeLock (&mLock, TPL_NOTIFY);
mInitializeLock = FALSE;
}
if (Enable != 0) {
EfiAcquireLock (&mLock);
} else {
EfiReleaseLock (&mLock);
}
}
/**
Delay MicroSeconds of micro seconds.
This is a callback routine supplied to UNDI at undi_start time.
@param MicroSeconds Number of micro seconds to pause, ususlly multiple of 10.
**/
VOID
EFIAPI
SnpUndi32CallbackDelay30 (
IN UINT64 MicroSeconds
)
{
if (MicroSeconds != 0) {
gBS->Stall ((UINTN) MicroSeconds);
}
}
/**
IO routine for UNDI.
This is a callback routine supplied to UNDI at undi_start time. This is not
currently being used by UNDI3.0 because Undi3.0 uses io/mem offsets relative
to the beginning of the device io/mem address and so it needs to use the
PCI_IO_FUNCTION that abstracts the start of the device's io/mem addresses.
Since SNP cannot retrive the context of the undi3.0 interface it cannot use
the PCI_IO_FUNCTION that specific for that NIC and uses one global IO
functions structure, this does not work. This however works fine for EFI1.0
Undis because they use absolute addresses for io/mem access.
@param ReadOrWrite Indicates read or write, IO or Memory.
@param NumBytes Number of bytes to read or write.
@param Address IO or memory address to read from or write to.
@param BufferAddr Memory location to read into or that contains the bytes to
write.
**/
VOID
EFIAPI
SnpUndi32CallbackMemio30 (
IN UINT8 ReadOrWrite,
IN UINT8 NumBytes,
IN UINT64 Address,
IN OUT UINT64 BufferAddr
)
{
EFI_PCI_IO_PROTOCOL_WIDTH Width;
switch (NumBytes) {
case 2:
Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 1;
break;
case 4:
Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 2;
break;
case 8:
Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 3;
break;
default:
Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 0;
}
switch (ReadOrWrite) {
case PXE_IO_READ:
mPciIo->Io.Read (
mPciIo,
Width,
1, // BAR 1, IO base address
Address,
1, // count
(VOID *) (UINTN) BufferAddr
);
break;
case PXE_IO_WRITE:
mPciIo->Io.Write (
mPciIo,
Width,
1, // BAR 1, IO base address
Address,
1, // count
(VOID *) (UINTN) BufferAddr
);
break;
case PXE_MEM_READ:
mPciIo->Mem.Read (
mPciIo,
Width,
0, // BAR 0, Memory base address
Address,
1, // count
(VOID *) (UINTN) BufferAddr
);
break;
case PXE_MEM_WRITE:
mPciIo->Mem.Write (
mPciIo,
Width,
0, // BAR 0, Memory base address
Address,
1, // count
(VOID *) (UINTN) BufferAddr
);
break;
}
return ;
}
/**
Acquire or release a lock of the exclusive access to a critical section of the
code/data.