]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/Callback.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Callback.c
index fc018265c792551f0d18d525634f8126c9701757..6387dbdb35ef2317550b5c68c20ea25de08a5a1d 100644 (file)
 /** @file\r
-  This file contains two sets of callback routines for undi3.0 and undi3.1.\r
+  This file contains the callback routines for undi3.1.\r
   the callback routines for Undi3.1 have an extra parameter UniqueId which\r
   stores the interface context for the NIC that snp is trying to talk.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "Snp.h"\r
 \r
-//\r
-// Global variables\r
-// these 2 global variables are used only for 3.0 undi. we could not place\r
-// them in the snp structure because we will not know which snp structure\r
-// in the callback context!\r
-//\r
-BOOLEAN              mInitializeLock = TRUE;\r
-EFI_LOCK             mLock;\r
-\r
-//\r
-// End Global variables\r
-//\r
-extern EFI_PCI_IO_PROTOCOL  *mPciIo;\r
-\r
-/** \r
-  Convert a virtual or CPU address provided by SNP to a physical or device \r
-  address. \r
-\r
-  This is a callback routine supplied to UNDI at undi_start time. Since EFI uses\r
-  the identical mapping, this routine returns the physical address same as the \r
-  virtual address for most of the addresses. an address above 4GB cannot \r
-  generally be used as a device address, it needs to be mapped to a lower \r
-  physical address. This routine does not call the map routine itself, but it \r
-  assumes that the mapping was done at the time of providing the address to \r
-  UNDI. This routine just looks up the address in a map table (which is the v2p \r
-  structure chain). \r
-  \r
-  @param  CpuAddr        Virtual address.\r
-  @param  DeviceAddrPtr  Pointer to the physical address, or 0 in case of any \r
-                         error.\r
-\r
-**/\r
-VOID\r
-SnpUndi32CallbackV2p30 (\r
-  IN UINT64     CpuAddr,\r
-  IN OUT UINT64 DeviceAddrPtr\r
-  )\r
-{\r
-  V2P  *V2p;\r
-  //\r
-  // Do nothing if virtual address is zero or physical pointer is NULL.\r
-  // No need to map if the virtual address is within 4GB limit since\r
-  // EFI uses identical mapping\r
-  //\r
-  if ((CpuAddr == 0) || (DeviceAddrPtr == 0)) {\r
-    DEBUG ((EFI_D_INFO | EFI_D_NET, "\nv2p: Null virtual address or physical pointer.\n"));\r
-    return ;\r
-  }\r
-\r
-  if (CpuAddr < FOUR_GIGABYTES) {\r
-    *(UINT64 *) (UINTN) DeviceAddrPtr = CpuAddr;\r
-    return ;\r
-  }\r
-  //\r
-  // SNP creates a vaddr tp paddr mapping at the time of calling undi with any\r
-  // big address, this callback routine just looks up in the v2p list and\r
-  // returns the physical address for any given virtual address.\r
-  //\r
-  if (FindV2p (&V2p, (VOID *) (UINTN) CpuAddr) != EFI_SUCCESS) {\r
-    *(UINT64 *) (UINTN) DeviceAddrPtr = CpuAddr;\r
-  } else {\r
-    *(UINT64 *) (UINTN) DeviceAddrPtr = V2p->PhysicalAddress;\r
-  }\r
-}\r
-\r
-/**\r
-  Acquire or release a lock of an exclusive access to a critical section of the\r
-  code/data. \r
-\r
-  This is a callback routine supplied to UNDI at undi_start time.\r
-\r
-  @param Enable   Non-zero indicates acquire; Zero indicates release.\r
-\r
-**/\r
-VOID\r
-SnpUndi32CallbackBlock30 (\r
-  IN UINT32 Enable\r
-  )\r
-{\r
-  //\r
-  // tcpip was calling snp at tpl_notify and if we acquire a lock that was\r
-  // created at a lower level (TPL_CALLBACK) it gives an assert!\r
-  //\r
-  if (mInitializeLock) {\r
-    EfiInitializeLock (&mLock, TPL_NOTIFY);\r
-    mInitializeLock = FALSE;\r
-  }\r
-\r
-  if (Enable != 0) {\r
-    EfiAcquireLock (&mLock);\r
-  } else {\r
-    EfiReleaseLock (&mLock);\r
-  }\r
-}\r
-\r
 /**\r
-  Delay MicroSeconds of micro seconds.\r
-   \r
-  This is a callback routine supplied to UNDI at undi_start time.\r
-\r
-  @param MicroSeconds  Number of micro seconds to pause, ususlly multiple of 10.\r
+  Acquire or release a lock of the exclusive access to a critical section of the\r
+  code/data.\r
 \r
-**/\r
-VOID\r
-SnpUndi32CallbackDelay30 (\r
-  IN UINT64 MicroSeconds\r
-  )\r
-{\r
-  if (MicroSeconds != 0) {\r
-    gBS->Stall ((UINTN) MicroSeconds);\r
-  }\r
-}\r
-\r
-/**\r
-  IO routine for UNDI. \r
-\r
-  This is a callback routine supplied to UNDI at undi_start time. This is not \r
-  currently being used by UNDI3.0 because Undi3.0 uses io/mem offsets relative \r
-  to the beginning of the device io/mem address and so it needs to use the \r
-  PCI_IO_FUNCTION that abstracts the start of the device's io/mem addresses. \r
-  Since SNP cannot retrive the context of the undi3.0 interface it cannot use \r
-  the PCI_IO_FUNCTION that specific for that NIC and uses one global IO \r
-  functions structure, this does not work. This however works fine for EFI1.0 \r
-  Undis because they use absolute addresses for io/mem access. \r
-\r
-  @param ReadOrWrite  Indicates read or write, IO or Memory.\r
-  @param NumBytes     Number of bytes to read or write.\r
-  @param Address      IO or memory address to read from or write to.\r
-  @param BufferAddr   Memory location to read into or that contains the bytes to\r
-                      write.\r
-\r
-**/\r
-VOID\r
-SnpUndi32CallbackMemio30 (\r
-  IN UINT8      ReadOrWrite,\r
-  IN UINT8      NumBytes,\r
-  IN UINT64     Address,\r
-  IN OUT UINT64 BufferAddr\r
-  )\r
-{\r
-  EFI_PCI_IO_PROTOCOL_WIDTH Width;\r
-\r
-  switch (NumBytes) {\r
-  case 2:\r
-    Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 1;\r
-    break;\r
-\r
-  case 4:\r
-    Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 2;\r
-    break;\r
-\r
-  case 8:\r
-    Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 3;\r
-    break;\r
-\r
-  default:\r
-    Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 0;\r
-  }\r
-\r
-  switch (ReadOrWrite) {\r
-  case PXE_IO_READ:\r
-    mPciIo->Io.Read (\r
-                 mPciIo,\r
-                 Width,\r
-                 1,    // BAR 1, IO base address\r
-                 Address,\r
-                 1,    // count\r
-                 (VOID *) (UINTN) BufferAddr\r
-                 );\r
-    break;\r
-\r
-  case PXE_IO_WRITE:\r
-    mPciIo->Io.Write (\r
-                 mPciIo,\r
-                 Width,\r
-                 1,    // BAR 1, IO base address\r
-                 Address,\r
-                 1,    // count\r
-                 (VOID *) (UINTN) BufferAddr\r
-                 );\r
-    break;\r
-\r
-  case PXE_MEM_READ:\r
-    mPciIo->Mem.Read (\r
-                  mPciIo,\r
-                  Width,\r
-                  0,  // BAR 0, Memory base address\r
-                  Address,\r
-                  1,  // count\r
-                  (VOID *) (UINTN) BufferAddr\r
-                  );\r
-    break;\r
-\r
-  case PXE_MEM_WRITE:\r
-    mPciIo->Mem.Write (\r
-                  mPciIo,\r
-                  Width,\r
-                  0,  // BAR 0, Memory base address\r
-                  Address,\r
-                  1,  // count\r
-                  (VOID *) (UINTN) BufferAddr\r
-                  );\r
-    break;\r
-  }\r
-\r
-  return ;\r
-}\r
-\r
-/**\r
-  Acquire or release a lock of the exclusive access to a critical section of the \r
-  code/data. \r
-   \r
   This is a callback routine supplied to UNDI3.1 at undi_start time.\r
   New callbacks for 3.1: there won't be a virtual2physical callback for UNDI 3.1\r
-  because undi3.1 uses the MemMap call to map the required address by itself! \r
+  because undi3.1 uses the MemMap call to map the required address by itself!\r
 \r
-  @param UniqueId  This was supplied to UNDI at Undi_Start, SNP uses this to \r
+  @param UniqueId  This was supplied to UNDI at Undi_Start, SNP uses this to\r
                       store Undi interface context (Undi does not read or write\r
                       this variable).\r
-  @param Enable    Non-zero indicates acquire; Zero indicates release. \r
+  @param Enable    Non-zero indicates acquire; Zero indicates release.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 SnpUndi32CallbackBlock (\r
   IN UINT64 UniqueId,\r
   IN UINT32 Enable\r
@@ -260,16 +47,17 @@ SnpUndi32CallbackBlock (
 \r
 /**\r
   Delay MicroSeconds of micro seconds.\r
-   \r
+\r
   This is a callback routine supplied to UNDI at undi_start time.\r
 \r
   @param UniqueId      This was supplied to UNDI at Undi_Start, SNP uses this to\r
                        store Undi interface context (Undi does not read or write\r
                        this variable).\r
-  @param MicroSeconds  Number of micro seconds to pause, ususlly multiple of 10.  \r
+  @param MicroSeconds  Number of micro seconds to pause, ususlly multiple of 10.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 SnpUndi32CallbackDelay (\r
   IN UINT64 UniqueId,\r
   IN UINT64 MicroSeconds\r
@@ -281,21 +69,22 @@ SnpUndi32CallbackDelay (
 }\r
 \r
 /**\r
-  IO routine for UNDI3.1. \r
-   \r
+  IO routine for UNDI3.1.\r
+\r
   This is a callback routine supplied to UNDI at undi_start time.\r
-   \r
-  @param UniqueId       This was supplied to UNDI at Undi_Start, SNP uses this \r
-                               to store Undi interface context (Undi does not read or\r
-                               write this variable).\r
+\r
+  @param UniqueId       This was supplied to UNDI at Undi_Start, SNP uses this\r
+                        to store Undi interface context (Undi does not read or\r
+                        write this variable).\r
   @param ReadOrWrite    Indicates read or write, IO or Memory.\r
   @param NumBytes       Number of bytes to read or write.\r
   @param MemOrPortAddr  IO or memory address to read from or write to.\r
   @param BufferPtr      Memory location to read into or that contains the bytes\r
-                               to write.\r
+                        to write.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 SnpUndi32CallbackMemio (\r
   IN UINT64     UniqueId,\r
   IN UINT8      ReadOrWrite,\r
@@ -374,7 +163,7 @@ SnpUndi32CallbackMemio (
 }\r
 \r
 /**\r
-  Map a CPU address to a device address. \r
+  Map a CPU address to a device address.\r
 \r
   This is a callback routine supplied to UNDI at undi_start time.\r
 \r
@@ -389,6 +178,7 @@ SnpUndi32CallbackMemio (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 SnpUndi32CallbackMap (\r
   IN UINT64     UniqueId,\r
   IN UINT64     CpuAddr,\r
@@ -467,21 +257,22 @@ SnpUndi32CallbackMap (
 }\r
 \r
 /**\r
-  Unmap an address that was previously mapped using map callback. \r
-   \r
+  Unmap an address that was previously mapped using map callback.\r
+\r
   This is a callback routine supplied to UNDI at undi_start time.\r
 \r
-  @param UniqueId    This was supplied to UNDI at Undi_Start, SNP uses this to \r
+  @param UniqueId    This was supplied to UNDI at Undi_Start, SNP uses this to\r
                      store. Undi interface context (Undi does not read or write\r
                      this variable).\r
   @param CpuAddr     Virtual address that was mapped.\r
   @param NumBytes    Size of memory mapped.\r
-  @param Direction   Direction of data flow for this memory's usage: \r
+  @param Direction   Direction of data flow for this memory's usage:\r
                      cpu->device, device->cpu or both ways.\r
   @param DeviceAddr  The mapped device address.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 SnpUndi32CallbackUnmap (\r
   IN UINT64 UniqueId,\r
   IN UINT64 CpuAddr,\r
@@ -512,19 +303,19 @@ SnpUndi32CallbackUnmap (
   return ;\r
 }\r
 \r
-/** \r
-  Synchronize the virtual buffer contents with the mapped buffer contents. \r
-   \r
+/**\r
+  Synchronize the virtual buffer contents with the mapped buffer contents.\r
+\r
   This is a callback routine supplied to UNDI at undi_start time. The virtual\r
-  and mapped buffers need not correspond to the same physical memory (especially \r
-  if the virtual address is > 4GB). Depending on the direction for which the \r
-  buffer is mapped, undi will need to synchronize their contents whenever it \r
-  writes to/reads from the buffer using either the cpu address or the device \r
-  address. \r
-  EFI does not provide a sync call since virt=physical, we should just do the \r
-  synchronization ourselves here. \r
-\r
-  @param UniqueId    This was supplied to UNDI at Undi_Start, SNP uses this to \r
+  and mapped buffers need not correspond to the same physical memory (especially\r
+  if the virtual address is > 4GB). Depending on the direction for which the\r
+  buffer is mapped, undi will need to synchronize their contents whenever it\r
+  writes to/reads from the buffer using either the cpu address or the device\r
+  address.\r
+  EFI does not provide a sync call since virt=physical, we should just do the\r
+  synchronization ourselves here.\r
+\r
+  @param UniqueId    This was supplied to UNDI at Undi_Start, SNP uses this to\r
                      store Undi interface context (Undi does not read or write\r
                      this variable).\r
   @param CpuAddr     Virtual address that was mapped.\r
@@ -535,6 +326,7 @@ SnpUndi32CallbackUnmap (
 \r
 **/\r
 VOID\r
+EFIAPI\r
 SnpUndi32CallbackSync (\r
   IN UINT64             UniqueId,\r
   IN UINT64             CpuAddr,\r