2008-04-10 10:49:28 +02:00
|
|
|
/** @file
|
|
|
|
This file contains two sets of callback routines for undi3.0 and 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.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Copyright (c) 2006 - 2008, Intel Corporation. <BR>
|
2008-02-20 03:20:05 +01:00
|
|
|
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.
|
|
|
|
|
2008-04-10 10:49:28 +02:00
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
|
|
|
|
#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!
|
|
|
|
//
|
2008-10-30 07:05:06 +01:00
|
|
|
BOOLEAN mInitializeLock = TRUE;
|
|
|
|
EFI_LOCK mLock;
|
2008-02-20 03:20:05 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// End Global variables
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
extern EFI_PCI_IO_PROTOCOL *mPciIo;
|
2008-02-20 03:20:05 +01:00
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
/**
|
|
|
|
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).
|
2008-11-13 04:42:21 +01:00
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@param CpuAddr Virtual address.
|
|
|
|
@param DeviceAddrPtr Pointer to the physical address, or 0 in case of any
|
|
|
|
error.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackV2p30 (
|
2008-02-20 03:20:05 +01:00
|
|
|
IN UINT64 CpuAddr,
|
|
|
|
IN OUT UINT64 DeviceAddrPtr
|
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
V2P *V2p;
|
2008-02-20 03:20:05 +01:00
|
|
|
//
|
|
|
|
// 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)) {
|
2008-12-29 02:16:13 +01:00
|
|
|
DEBUG ((EFI_D_INFO | EFI_D_NET, "\nv2p: Null virtual address or physical pointer.\n"));
|
2008-02-20 03:20:05 +01:00
|
|
|
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.
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
if (FindV2p (&V2p, (VOID *) (UINTN) CpuAddr) != EFI_SUCCESS) {
|
2008-02-20 03:20:05 +01:00
|
|
|
*(UINT64 *) (UINTN) DeviceAddrPtr = CpuAddr;
|
|
|
|
} else {
|
2008-11-13 04:42:21 +01:00
|
|
|
*(UINT64 *) (UINTN) DeviceAddrPtr = V2p->PhysicalAddress;
|
2008-02-20 03:20:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
Acquire or release a lock of an exclusive access to a critical section of the
|
|
|
|
code/data.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
This is a callback routine supplied to UNDI at undi_start time.
|
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@param Enable Non-zero indicates acquire; Zero indicates release.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackBlock30 (
|
2008-02-20 03:20:05 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
Delay MicroSeconds of micro seconds.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
This is a callback routine supplied to UNDI at undi_start time.
|
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@param MicroSeconds Number of micro seconds to pause, ususlly multiple of 10.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackDelay30 (
|
2008-02-20 03:20:05 +01:00
|
|
|
IN UINT64 MicroSeconds
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (MicroSeconds != 0) {
|
|
|
|
gBS->Stall ((UINTN) MicroSeconds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
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.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackMemio30 (
|
2008-02-20 03:20:05 +01:00
|
|
|
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:
|
2008-11-13 04:42:21 +01:00
|
|
|
mPciIo->Io.Read (
|
|
|
|
mPciIo,
|
|
|
|
Width,
|
|
|
|
1, // BAR 1, IO base address
|
|
|
|
Address,
|
|
|
|
1, // count
|
|
|
|
(VOID *) (UINTN) BufferAddr
|
|
|
|
);
|
2008-02-20 03:20:05 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PXE_IO_WRITE:
|
2008-11-13 04:42:21 +01:00
|
|
|
mPciIo->Io.Write (
|
|
|
|
mPciIo,
|
|
|
|
Width,
|
|
|
|
1, // BAR 1, IO base address
|
|
|
|
Address,
|
|
|
|
1, // count
|
|
|
|
(VOID *) (UINTN) BufferAddr
|
|
|
|
);
|
2008-02-20 03:20:05 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PXE_MEM_READ:
|
2008-11-13 04:42:21 +01:00
|
|
|
mPciIo->Mem.Read (
|
|
|
|
mPciIo,
|
|
|
|
Width,
|
|
|
|
0, // BAR 0, Memory base address
|
|
|
|
Address,
|
|
|
|
1, // count
|
|
|
|
(VOID *) (UINTN) BufferAddr
|
|
|
|
);
|
2008-02-20 03:20:05 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PXE_MEM_WRITE:
|
2008-11-13 04:42:21 +01:00
|
|
|
mPciIo->Mem.Write (
|
|
|
|
mPciIo,
|
|
|
|
Width,
|
|
|
|
0, // BAR 0, Memory base address
|
|
|
|
Address,
|
|
|
|
1, // count
|
|
|
|
(VOID *) (UINTN) BufferAddr
|
|
|
|
);
|
2008-02-20 03:20:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ;
|
|
|
|
}
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
Acquire or release a lock of the exclusive access to a critical section of the
|
|
|
|
code/data.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
This is a callback routine supplied to UNDI3.1 at undi_start time.
|
2008-12-29 02:16:13 +01:00
|
|
|
New callbacks for 3.1: there won't be a virtual2physical callback for UNDI 3.1
|
|
|
|
because undi3.1 uses the MemMap call to map the required address by itself!
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
@param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
|
2008-12-29 02:16:13 +01:00
|
|
|
store Undi interface context (Undi does not read or write
|
|
|
|
this variable).
|
|
|
|
@param Enable Non-zero indicates acquire; Zero indicates release.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackBlock (
|
2008-02-20 03:20:05 +01:00
|
|
|
IN UINT64 UniqueId,
|
|
|
|
IN UINT32 Enable
|
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
SNP_DRIVER *Snp;
|
2008-02-20 03:20:05 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp = (SNP_DRIVER *) (UINTN) UniqueId;
|
2008-02-20 03:20:05 +01:00
|
|
|
//
|
|
|
|
// tcpip was calling snp at tpl_notify and when we acquire a lock that was
|
|
|
|
// created at a lower level (TPL_CALLBACK) it gives an assert!
|
|
|
|
//
|
|
|
|
if (Enable != 0) {
|
2008-11-13 04:42:21 +01:00
|
|
|
EfiAcquireLock (&Snp->Lock);
|
2008-02-20 03:20:05 +01:00
|
|
|
} else {
|
2008-11-13 04:42:21 +01:00
|
|
|
EfiReleaseLock (&Snp->Lock);
|
2008-02-20 03:20:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
Delay MicroSeconds of micro seconds.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
This is a callback routine supplied to UNDI at undi_start time.
|
|
|
|
|
|
|
|
@param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
|
2008-12-29 02:16:13 +01:00
|
|
|
store Undi interface context (Undi does not read or write
|
|
|
|
this variable).
|
|
|
|
@param MicroSeconds Number of micro seconds to pause, ususlly multiple of 10.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackDelay (
|
2008-02-20 03:20:05 +01:00
|
|
|
IN UINT64 UniqueId,
|
|
|
|
IN UINT64 MicroSeconds
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (MicroSeconds != 0) {
|
|
|
|
gBS->Stall ((UINTN) MicroSeconds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
IO routine for UNDI3.1.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
This is a callback routine supplied to UNDI at undi_start time.
|
2008-12-29 02:16:13 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
@param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this
|
2008-12-29 02:16:13 +01:00
|
|
|
to store Undi interface context (Undi does not read or
|
|
|
|
write this variable).
|
|
|
|
@param ReadOrWrite Indicates read or write, IO or Memory.
|
|
|
|
@param NumBytes Number of bytes to read or write.
|
2008-11-13 04:42:21 +01:00
|
|
|
@param MemOrPortAddr IO or memory address to read from or write to.
|
2008-12-29 02:16:13 +01:00
|
|
|
@param BufferPtr Memory location to read into or that contains the bytes
|
|
|
|
to write.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackMemio (
|
|
|
|
IN UINT64 UniqueId,
|
|
|
|
IN UINT8 ReadOrWrite,
|
|
|
|
IN UINT8 NumBytes,
|
|
|
|
IN UINT64 MemOrPortAddr,
|
|
|
|
IN OUT UINT64 BufferPtr
|
2008-02-20 03:20:05 +01:00
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
SNP_DRIVER *Snp;
|
2008-02-20 03:20:05 +01:00
|
|
|
EFI_PCI_IO_PROTOCOL_WIDTH Width;
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp = (SNP_DRIVER *) (UINTN) UniqueId;
|
2008-02-20 03:20:05 +01:00
|
|
|
|
|
|
|
Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 0;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ReadOrWrite) {
|
|
|
|
case PXE_IO_READ:
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->PciIo->Io.Read (
|
|
|
|
Snp->PciIo,
|
|
|
|
Width,
|
|
|
|
Snp->IoBarIndex, // BAR 1 (for 32bit regs), IO base address
|
|
|
|
MemOrPortAddr,
|
|
|
|
1, // count
|
|
|
|
(VOID *) (UINTN) BufferPtr
|
|
|
|
);
|
2008-02-20 03:20:05 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PXE_IO_WRITE:
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->PciIo->Io.Write (
|
|
|
|
Snp->PciIo,
|
|
|
|
Width,
|
|
|
|
Snp->IoBarIndex, // BAR 1 (for 32bit regs), IO base address
|
|
|
|
MemOrPortAddr,
|
|
|
|
1, // count
|
|
|
|
(VOID *) (UINTN) BufferPtr
|
|
|
|
);
|
2008-02-20 03:20:05 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PXE_MEM_READ:
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->PciIo->Mem.Read (
|
|
|
|
Snp->PciIo,
|
2008-02-20 03:20:05 +01:00
|
|
|
Width,
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->MemoryBarIndex, // BAR 0, Memory base address
|
|
|
|
MemOrPortAddr,
|
2008-02-20 03:20:05 +01:00
|
|
|
1, // count
|
2008-11-13 04:42:21 +01:00
|
|
|
(VOID *) (UINTN) BufferPtr
|
2008-02-20 03:20:05 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PXE_MEM_WRITE:
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->PciIo->Mem.Write (
|
|
|
|
Snp->PciIo,
|
2008-02-20 03:20:05 +01:00
|
|
|
Width,
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->MemoryBarIndex, // BAR 0, Memory base address
|
|
|
|
MemOrPortAddr,
|
2008-02-20 03:20:05 +01:00
|
|
|
1, // count
|
2008-11-13 04:42:21 +01:00
|
|
|
(VOID *) (UINTN) BufferPtr
|
2008-02-20 03:20:05 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
Map a CPU address to a device address.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
This is a callback routine supplied to UNDI at undi_start time.
|
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
|
|
|
|
store Undi interface context (Undi does not read or write
|
|
|
|
this variable).
|
|
|
|
@param CpuAddr Virtual address to be mapped.
|
|
|
|
@param NumBytes Size of memory to be mapped.
|
|
|
|
@param Direction Direction of data flow for this memory's usage:
|
|
|
|
cpu->device, device->cpu or both ways.
|
|
|
|
@param DeviceAddrPtr Pointer to return the mapped device address.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackMap (
|
2008-02-20 03:20:05 +01:00
|
|
|
IN UINT64 UniqueId,
|
|
|
|
IN UINT64 CpuAddr,
|
|
|
|
IN UINT32 NumBytes,
|
|
|
|
IN UINT32 Direction,
|
|
|
|
IN OUT UINT64 DeviceAddrPtr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_PHYSICAL_ADDRESS *DevAddrPtr;
|
|
|
|
EFI_PCI_IO_PROTOCOL_OPERATION DirectionFlag;
|
|
|
|
UINTN BuffSize;
|
2008-11-13 04:42:21 +01:00
|
|
|
SNP_DRIVER *Snp;
|
2008-02-20 03:20:05 +01:00
|
|
|
UINTN Index;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
BuffSize = (UINTN) NumBytes;
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp = (SNP_DRIVER *) (UINTN) UniqueId;
|
2008-02-20 03:20:05 +01:00
|
|
|
DevAddrPtr = (EFI_PHYSICAL_ADDRESS *) (UINTN) DeviceAddrPtr;
|
|
|
|
|
|
|
|
if (CpuAddr == 0) {
|
|
|
|
*DevAddrPtr = 0;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Direction) {
|
|
|
|
case TO_AND_FROM_DEVICE:
|
|
|
|
DirectionFlag = EfiPciIoOperationBusMasterCommonBuffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FROM_DEVICE:
|
|
|
|
DirectionFlag = EfiPciIoOperationBusMasterWrite;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TO_DEVICE:
|
|
|
|
DirectionFlag = EfiPciIoOperationBusMasterRead;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*DevAddrPtr = 0;
|
|
|
|
//
|
|
|
|
// any non zero indicates error!
|
|
|
|
//
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// find an unused map_list entry
|
|
|
|
//
|
|
|
|
for (Index = 0; Index < MAX_MAP_LENGTH; Index++) {
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Snp->MapList[Index].VirtualAddress == 0) {
|
2008-02-20 03:20:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Index >= MAX_MAP_LENGTH) {
|
|
|
|
DEBUG ((EFI_D_INFO, "SNP maplist is FULL\n"));
|
|
|
|
*DevAddrPtr = 0;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->MapList[Index].VirtualAddress = (EFI_PHYSICAL_ADDRESS) CpuAddr;
|
2008-02-20 03:20:05 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = Snp->PciIo->Map (
|
|
|
|
Snp->PciIo,
|
|
|
|
DirectionFlag,
|
|
|
|
(VOID *) (UINTN) CpuAddr,
|
|
|
|
&BuffSize,
|
|
|
|
DevAddrPtr,
|
|
|
|
&(Snp->MapList[Index].MapCookie)
|
|
|
|
);
|
2008-02-20 03:20:05 +01:00
|
|
|
if (Status != EFI_SUCCESS) {
|
2008-11-13 04:42:21 +01:00
|
|
|
*DevAddrPtr = 0;
|
|
|
|
Snp->MapList[Index].VirtualAddress = 0;
|
2008-02-20 03:20:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
Unmap an address that was previously mapped using map callback.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
This is a callback routine supplied to UNDI at undi_start time.
|
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
|
|
|
|
store. Undi interface context (Undi does not read or write
|
|
|
|
this variable).
|
|
|
|
@param CpuAddr Virtual address that was mapped.
|
|
|
|
@param NumBytes Size of memory mapped.
|
|
|
|
@param Direction Direction of data flow for this memory's usage:
|
|
|
|
cpu->device, device->cpu or both ways.
|
|
|
|
@param DeviceAddr The mapped device address.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackUnmap (
|
2008-02-20 03:20:05 +01:00
|
|
|
IN UINT64 UniqueId,
|
|
|
|
IN UINT64 CpuAddr,
|
|
|
|
IN UINT32 NumBytes,
|
|
|
|
IN UINT32 Direction,
|
|
|
|
IN UINT64 DeviceAddr
|
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
SNP_DRIVER *Snp;
|
2008-02-20 03:20:05 +01:00
|
|
|
UINT16 Index;
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp = (SNP_DRIVER *) (UINTN) UniqueId;
|
2008-02-20 03:20:05 +01:00
|
|
|
|
|
|
|
for (Index = 0; Index < MAX_MAP_LENGTH; Index++) {
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Snp->MapList[Index].VirtualAddress == CpuAddr) {
|
2008-02-20 03:20:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
if (Index >= MAX_MAP_LENGTH) {
|
2008-02-20 03:20:05 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "SNP could not find a mapping, failed to unmap.\n"));
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->PciIo->Unmap (Snp->PciIo, Snp->MapList[Index].MapCookie);
|
|
|
|
Snp->MapList[Index].VirtualAddress = 0;
|
|
|
|
Snp->MapList[Index].MapCookie = NULL;
|
2008-02-20 03:20:05 +01:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
/**
|
|
|
|
Synchronize the virtual buffer contents with the mapped buffer contents.
|
|
|
|
|
|
|
|
This is a callback routine supplied to UNDI at undi_start time. The virtual
|
|
|
|
and mapped buffers need not correspond to the same physical memory (especially
|
|
|
|
if the virtual address is > 4GB). Depending on the direction for which the
|
|
|
|
buffer is mapped, undi will need to synchronize their contents whenever it
|
|
|
|
writes to/reads from the buffer using either the cpu address or the device
|
|
|
|
address.
|
|
|
|
EFI does not provide a sync call since virt=physical, we should just do the
|
|
|
|
synchronization ourselves here.
|
|
|
|
|
|
|
|
@param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
|
|
|
|
store Undi interface context (Undi does not read or write
|
|
|
|
this variable).
|
|
|
|
@param CpuAddr Virtual address that was mapped.
|
|
|
|
@param NumBytes Size of memory mapped.
|
|
|
|
@param Direction Direction of data flow for this memory's usage:
|
2008-11-13 04:42:21 +01:00
|
|
|
cpu->device, device->cpu or both ways.
|
2008-12-29 02:16:13 +01:00
|
|
|
@param DeviceAddr The mapped device address.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
**/
|
2008-02-20 03:20:05 +01:00
|
|
|
VOID
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32CallbackSync (
|
|
|
|
IN UINT64 UniqueId,
|
|
|
|
IN UINT64 CpuAddr,
|
|
|
|
IN UINT32 NumBytes,
|
|
|
|
IN UINT32 Direction,
|
|
|
|
IN UINT64 DeviceAddr
|
2008-02-20 03:20:05 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if ((CpuAddr == 0) || (DeviceAddr == 0) || (NumBytes == 0)) {
|
|
|
|
return ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Direction) {
|
|
|
|
case FROM_DEVICE:
|
|
|
|
CopyMem ((UINT8 *) (UINTN) CpuAddr, (UINT8 *) (UINTN) DeviceAddr, NumBytes);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TO_DEVICE:
|
|
|
|
CopyMem ((UINT8 *) (UINTN) DeviceAddr, (UINT8 *) (UINTN) CpuAddr, NumBytes);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ;
|
|
|
|
}
|