X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EdkModulePkg%2FUniversal%2FNetwork%2FSnp32_64%2FDxe%2Fsnp.c;h=a32812a01a6b0c5a318a5e3aa4c192241a5f5c8c;hp=c193730ffa03be3e51bdf5d2156831ce3c75ddf5;hb=26aa0c2ff5254864bb117f172dce4ed3fe2be6be;hpb=4cbd855edf89ee4d98642e5e3682581868c786c3 diff --git a/EdkModulePkg/Universal/Network/Snp32_64/Dxe/snp.c b/EdkModulePkg/Universal/Network/Snp32_64/Dxe/snp.c index c193730ffa..a32812a01a 100644 --- a/EdkModulePkg/Universal/Network/Snp32_64/Dxe/snp.c +++ b/EdkModulePkg/Universal/Network/Snp32_64/Dxe/snp.c @@ -1,12 +1,12 @@ /*++ -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. +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. Module name: snp.c @@ -18,72 +18,6 @@ Abstract: #include "Snp.h" -EFI_STATUS -pxe_start ( - SNP_DRIVER *snp - ); -EFI_STATUS -pxe_stop ( - SNP_DRIVER *snp - ); -EFI_STATUS -pxe_init ( - SNP_DRIVER *snp, - UINT16 OpFlags - ); -EFI_STATUS -pxe_shutdown ( - SNP_DRIVER *snp - ); -EFI_STATUS -pxe_get_stn_addr ( - SNP_DRIVER *snp - ); - -EFI_STATUS -EFIAPI -InitializeSnpNiiDriver ( - IN EFI_HANDLE image_handle, - IN EFI_SYSTEM_TABLE *system_table - ); - -EFI_STATUS -EFIAPI -SimpleNetworkDriverSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ); - -EFI_STATUS -EFIAPI -SimpleNetworkDriverStart ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ); - -EFI_STATUS -EFIAPI -SimpleNetworkDriverStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer - ); - -// -// Simple Network Protocol Driver Global Variables -// -EFI_DRIVER_BINDING_PROTOCOL mSimpleNetworkDriverBinding = { - SimpleNetworkDriverSupported, - SimpleNetworkDriverStart, - SimpleNetworkDriverStop, - 0x10, - NULL, - NULL -}; - // // Module global variables needed to support undi 3.0 interface // @@ -91,202 +25,6 @@ EFI_PCI_IO_PROTOCOL *mPciIoFncs; struct s_v2p *_v2p = NULL; // undi3.0 map_list head // End Global variables // -EFI_STATUS -add_v2p ( - IN OUT struct s_v2p **v2p, - EFI_PCI_IO_PROTOCOL_OPERATION type, - VOID *vaddr, - UINTN bsize - ) -/*++ - -Routine Description: - This routine maps the given CPU address to a Device address. It creates a - an entry in the map list with the virtual and physical addresses and the - un map cookie. - -Arguments: - v2p - pointer to return a map list node pointer. - type - the direction in which the data flows from the given virtual address - device->cpu or cpu->device or both ways. - vaddr - virtual address (or CPU address) to be mapped - bsize - size of the buffer to be mapped. - -Returns: - - EFI_SUCEESS - routine has completed the mapping - other - error as indicated. - ---*/ -{ - EFI_STATUS Status; - - if ((v2p == NULL) || (vaddr == NULL) || (bsize == 0)) { - return EFI_INVALID_PARAMETER; - } - - Status = gBS->AllocatePool ( - EfiBootServicesData, - sizeof (struct s_v2p), - (VOID **) v2p - ); - - if (Status != EFI_SUCCESS) { - return Status; - } - - Status = mPciIoFncs->Map ( - mPciIoFncs, - type, - vaddr, - &bsize, - &(*v2p)->paddr, - &(*v2p)->unmap - ); - if (Status != EFI_SUCCESS) { - gBS->FreePool (*v2p); - return Status; - } - (*v2p)->vaddr = vaddr; - (*v2p)->bsize = bsize; - (*v2p)->next = _v2p; - _v2p = *v2p; - - return EFI_SUCCESS; -} - -EFI_STATUS -find_v2p ( - struct s_v2p **v2p, - VOID *vaddr - ) -/*++ - -Routine Description: - This routine searches the linked list of mapped address nodes (for undi3.0 - interface) to find the node that corresponds to the given virtual address and - returns a pointer to that node. - -Arguments: - v2p - pointer to return a map list node pointer. - vaddr - virtual address (or CPU address) to be searched in the map list - -Returns: - - EFI_SUCEESS - if a match found! - Other - match not found - ---*/ -{ - struct s_v2p *v; - - if (v2p == NULL || vaddr == NULL) { - return EFI_INVALID_PARAMETER; - } - - for (v = _v2p; v != NULL; v = v->next) { - if (v->vaddr == vaddr) { - *v2p = v; - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - -EFI_STATUS -del_v2p ( - VOID *vaddr - ) -/*++ - -Routine Description: - This routine unmaps the given virtual address and frees the memory allocated - for the map list node corresponding to that address. - -Arguments: - vaddr - virtual address (or CPU address) to be unmapped - -Returns: - EFI_SUCEESS - if successfully unmapped - Other - as indicated by the error - - ---*/ -{ - struct s_v2p *v; - struct s_v2p *t; - EFI_STATUS Status; - - if (vaddr == NULL) { - return EFI_INVALID_PARAMETER; - } - - if (_v2p == NULL) { - return EFI_NOT_FOUND; - } - // - // Is our node at the head of the list?? - // - if ((v = _v2p)->vaddr == vaddr) { - _v2p = _v2p->next; - - Status = mPciIoFncs->Unmap (mPciIoFncs, v->unmap); - - gBS->FreePool (v); - -#if SNP_DEBUG - if (Status) { - Print (L"Unmap failed with status = %x\n", Status); - } -#endif - return Status; - } - - for (; v->next != NULL; v = t) { - if ((t = v->next)->vaddr == vaddr) { - v->next = t->next; - Status = mPciIoFncs->Unmap (mPciIoFncs, t->unmap); - gBS->FreePool (t); -#if SNP_DEBUG - if (Status) { - Print (L"Unmap failed with status = %x\n", Status); - } -#endif - return Status; - } - } - - return EFI_NOT_FOUND; -} - -#if SNP_DEBUG -VOID -snp_wait_for_key ( - VOID - ) -/*++ - -Routine Description: - Wait for a key stroke, used for debugging purposes - -Arguments: - none - -Returns: - none - ---*/ -{ - EFI_INPUT_KEY key; - - Aprint ("\nPress any key to continue\n"); - - while (gST->ConIn->ReadKeyStroke (gST->ConIn, &key) == EFI_NOT_READY) { - ; - } -} -#endif STATIC EFI_STATUS @@ -303,10 +41,8 @@ Returns: --*/ { -#if SNP_DEBUG - Aprint ("\nissue_hwundi_command() - This should not be called!"); - snp_wait_for_key (); -#endif + DEBUG ((EFI_D_ERROR, "\nissue_hwundi_command() - This should not be called!")); + if (cdb == 0) { return EFI_INVALID_PARAMETER; @@ -327,7 +63,7 @@ calc_8bit_cksum ( Routine Description: Compute 8-bit checksum of a buffer. - + Arguments: ptr - Pointer to buffer. len - Length of buffer in bytes. @@ -355,6 +91,7 @@ Returns: return cksum; } +STATIC EFI_STATUS EFIAPI SimpleNetworkDriverSupported ( @@ -408,19 +145,13 @@ SimpleNetworkDriverSupported ( ); if (Status == EFI_ALREADY_STARTED) { -#if SNP_DEBUG - Aprint ("Support(): Already Started. on handle %x\n", Controller); -#endif + DEBUG ((EFI_D_INFO, "Support(): Already Started. on handle %x\n", Controller)); return EFI_ALREADY_STARTED; } if (!EFI_ERROR (Status)) { - -#if SNP_DEBUG - Aprint ("Support(): UNDI3.1 found on handle %x\n", Controller); - snp_wait_for_key (); -#endif + DEBUG ((EFI_D_INFO, "Support(): UNDI3.1 found on handle %x\n", Controller)); IsUndi31 = TRUE; } else { // @@ -438,10 +169,7 @@ SimpleNetworkDriverSupported ( return Status; } -#if SNP_DEBUG - Aprint ("Support(): UNDI3.0 found on handle %x\n", Controller); - snp_wait_for_key (); -#endif + DEBUG ((EFI_D_INFO, "Support(): UNDI3.0 found on handle %x\n", Controller)); } // // check the version, we don't want to connect to the undi16 @@ -505,10 +233,7 @@ SimpleNetworkDriverSupported ( } Status = EFI_SUCCESS; -#if SNP_DEBUG - Aprint ("Support(): supported on %x\n", Controller); - snp_wait_for_key (); -#endif + DEBUG ((EFI_D_INFO, "Support(): supported on %x\n", Controller)); Done: if (IsUndi31) { @@ -531,6 +256,7 @@ Done: return Status; } +STATIC EFI_STATUS EFIAPI SimpleNetworkDriverStart ( @@ -634,10 +360,8 @@ Arguments: // probably not a 3.1 UNDI // UndiNew = TRUE; -#if SNP_DEBUG - Aprint ("Start(): UNDI3.1 found\n"); - snp_wait_for_key (); -#endif + DEBUG ((EFI_D_INFO, "Start(): UNDI3.1 found\n")); + } else { UndiNew = FALSE; Status = gBS->OpenProtocol ( @@ -659,10 +383,7 @@ Arguments: return Status; } -#if SNP_DEBUG - Aprint ("Start(): UNDI3.0 found\n"); - snp_wait_for_key (); -#endif + DEBUG ((EFI_D_INFO, "Start(): UNDI3.0 found\n")); } pxe = (PXE_UNDI *) (UINTN) (Nii->ID); @@ -1190,6 +911,7 @@ NiiError: return Status; } +STATIC EFI_STATUS EFIAPI SimpleNetworkDriverStop ( @@ -1255,7 +977,7 @@ Returns: Controller ); } - + Status = gBS->CloseProtocol ( Controller, &gEfiDevicePathProtocolGuid, @@ -1313,3 +1035,175 @@ Returns: return Status; } +// +// Simple Network Protocol Driver Global Variables +// +EFI_DRIVER_BINDING_PROTOCOL mSimpleNetworkDriverBinding = { + SimpleNetworkDriverSupported, + SimpleNetworkDriverStart, + SimpleNetworkDriverStop, + 0xa, + NULL, + NULL +}; + +EFI_STATUS +add_v2p ( + IN OUT struct s_v2p **v2p, + EFI_PCI_IO_PROTOCOL_OPERATION type, + VOID *vaddr, + UINTN bsize + ) +/*++ + +Routine Description: + This routine maps the given CPU address to a Device address. It creates a + an entry in the map list with the virtual and physical addresses and the + un map cookie. + +Arguments: + v2p - pointer to return a map list node pointer. + type - the direction in which the data flows from the given virtual address + device->cpu or cpu->device or both ways. + vaddr - virtual address (or CPU address) to be mapped + bsize - size of the buffer to be mapped. + +Returns: + + EFI_SUCEESS - routine has completed the mapping + other - error as indicated. + +--*/ +{ + EFI_STATUS Status; + + if ((v2p == NULL) || (vaddr == NULL) || (bsize == 0)) { + return EFI_INVALID_PARAMETER; + } + + *v2p = AllocatePool (sizeof (struct s_v2p)); + if (*v2p != NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = mPciIoFncs->Map ( + mPciIoFncs, + type, + vaddr, + &bsize, + &(*v2p)->paddr, + &(*v2p)->unmap + ); + if (Status != EFI_SUCCESS) { + FreePool (*v2p); + return Status; + } + (*v2p)->vaddr = vaddr; + (*v2p)->bsize = bsize; + (*v2p)->next = _v2p; + _v2p = *v2p; + + return EFI_SUCCESS; +} + +EFI_STATUS +find_v2p ( + struct s_v2p **v2p, + VOID *vaddr + ) +/*++ + +Routine Description: + This routine searches the linked list of mapped address nodes (for undi3.0 + interface) to find the node that corresponds to the given virtual address and + returns a pointer to that node. + +Arguments: + v2p - pointer to return a map list node pointer. + vaddr - virtual address (or CPU address) to be searched in the map list + +Returns: + + EFI_SUCEESS - if a match found! + Other - match not found + +--*/ +{ + struct s_v2p *v; + + if (v2p == NULL || vaddr == NULL) { + return EFI_INVALID_PARAMETER; + } + + for (v = _v2p; v != NULL; v = v->next) { + if (v->vaddr == vaddr) { + *v2p = v; + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +EFI_STATUS +del_v2p ( + VOID *vaddr + ) +/*++ + +Routine Description: + This routine unmaps the given virtual address and frees the memory allocated + for the map list node corresponding to that address. + +Arguments: + vaddr - virtual address (or CPU address) to be unmapped + +Returns: + EFI_SUCEESS - if successfully unmapped + Other - as indicated by the error + + +--*/ +{ + struct s_v2p *v; + struct s_v2p *t; + EFI_STATUS Status; + + if (vaddr == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (_v2p == NULL) { + return EFI_NOT_FOUND; + } + // + // Is our node at the head of the list?? + // + if ((v = _v2p)->vaddr == vaddr) { + _v2p = _v2p->next; + + Status = mPciIoFncs->Unmap (mPciIoFncs, v->unmap); + + FreePool (v); + + if (Status) { + DEBUG ((EFI_D_ERROR, "Unmap failed with status = %x\n", Status)); + } + return Status; + } + + for (; v->next != NULL; v = t) { + if ((t = v->next)->vaddr == vaddr) { + v->next = t->next; + Status = mPciIoFncs->Unmap (mPciIoFncs, t->unmap); + FreePool (t); + + if (Status) { + DEBUG ((EFI_D_ERROR, "Unmap failed with status = %x\n", Status)); + } + return Status; + } + } + + return EFI_NOT_FOUND; +}