X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FUndiRuntimeDxe%2FInit.c;h=413ef32a7a8b5f76eb529da8b1636a9c7c6bc8da;hp=8315bc41d0fc620c5224d4f3c2722b19d6e97f18;hb=6a6d955c5f670141344c614c65dbea332f393b57;hpb=40834173c5ee2a2a1f7910dc9c68d3c3f3beb137 diff --git a/MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c b/MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c index 8315bc41d0..413ef32a7a 100644 --- a/MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c +++ b/MdeModulePkg/Bus/Pci/UndiRuntimeDxe/Init.c @@ -1,13 +1,13 @@ /*++ -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: @@ -22,15 +22,14 @@ Revision History --*/ #include "Undi32.h" - +#include // // Global Variables // -PXE_SW_UNDI *pxe = 0; // 3.0 entry point -PXE_SW_UNDI *pxe_31 = 0; // 3.1 entry -UNDI32_DEV *UNDI32DeviceList[MAX_NIC_INTERFACES]; -NII_TABLE *UnidiDataPointer=NULL; +PXE_SW_UNDI *pxe_31 = NULL; // 3.1 entry +UNDI32_DEV *UNDI32DeviceList[MAX_NIC_INTERFACES]; +NII_TABLE *UndiDataPointer = NULL; VOID EFIAPI @@ -103,7 +102,7 @@ UndiNotifyExitBs ( Routine Description: - When EFI is shuting down the boot services, we need to install a + When EFI is shuting down the boot services, we need to install a configuration table for UNDI to work at runtime! Arguments: @@ -152,15 +151,15 @@ Routine Description: Arguments: This - Protocol instance pointer. - + Controller - Handle of device to test. - + RemainingDevicePath - Not used. Returns: EFI_SUCCESS - This driver supports this device. - + other - This driver does not support this device. --*/ @@ -266,15 +265,15 @@ Routine Description: Arguments: This - Protocol instance pointer. - + Controller - Handle of device to work with. - + RemainingDevicePath - Not used, always produce all possible children. Returns: EFI_SUCCESS - This driver is added to Controller. - + other - This driver does not support this device. --*/ @@ -286,7 +285,9 @@ Returns: UINT16 NewCommand; UINT8 *TmpPxePointer; EFI_PCI_IO_PROTOCOL *PciIoFncs; - UINTN Len; + UINTN Len; + UINT64 Supports; + BOOLEAN PciAttributesSaved; Status = gBS->OpenProtocol ( Controller, @@ -321,6 +322,8 @@ Returns: return Status; } + PciAttributesSaved = FALSE; + Status = gBS->AllocatePool ( EfiRuntimeServicesData, sizeof (UNDI32_DEV), @@ -333,6 +336,21 @@ Returns: ZeroMem ((CHAR8 *) UNDI32Device, sizeof (UNDI32_DEV)); + // + // Get original PCI attributes + // + Status = PciIoFncs->Attributes ( + PciIoFncs, + EfiPciIoAttributeOperationGet, + 0, + &UNDI32Device->NicInfo.OriginalPciAttributes + ); + + if (EFI_ERROR (Status)) { + goto UndiErrorDeleteDevice; + } + PciAttributesSaved = TRUE; + // // allocate and initialize both (old and new) the !pxe structures here, // there should only be one copy of each of these structure for any number @@ -366,24 +384,27 @@ Returns: } else { pxe_31 = (PXE_SW_UNDI *) TmpPxePointer; } - // - // assuming that the sizeof pxe_31 is a 16 byte multiple - // - pxe = (PXE_SW_UNDI *) ((CHAR8 *) (pxe_31) + sizeof (PXE_SW_UNDI)); - PxeStructInit (pxe, 0x30); - PxeStructInit (pxe_31, 0x31); + PxeStructInit (pxe_31); } - UNDI32Device->NIIProtocol.ID = (UINT64) (UINTN) (pxe); UNDI32Device->NIIProtocol_31.ID = (UINT64) (UINTN) (pxe_31); Status = PciIoFncs->Attributes ( PciIoFncs, - EfiPciIoAttributeOperationEnable, - EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_MEMORY | EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, - NULL + EfiPciIoAttributeOperationSupported, + 0, + &Supports ); + if (!EFI_ERROR (Status)) { + Supports &= EFI_PCI_DEVICE_ENABLE; + Status = PciIoFncs->Attributes ( + PciIoFncs, + EfiPciIoAttributeOperationEnable, + Supports, + NULL + ); + } // // Read all the registers from device's PCI Configuration space // @@ -430,15 +451,13 @@ Returns: // the IfNum index for the current interface will be the total number // of interfaces initialized so far // - UNDI32Device->NIIProtocol.IfNum = pxe->IFcnt; UNDI32Device->NIIProtocol_31.IfNum = pxe_31->IFcnt; - PxeUpdate (&UNDI32Device->NicInfo, pxe); PxeUpdate (&UNDI32Device->NicInfo, pxe_31); - UNDI32Device->NicInfo.Io_Function = PciIoFncs; - UNDI32DeviceList[UNDI32Device->NIIProtocol.IfNum] = UNDI32Device; - UNDI32Device->Undi32BaseDevPath = UndiDevicePath; + UNDI32Device->NicInfo.Io_Function = PciIoFncs; + UNDI32DeviceList[UNDI32Device->NIIProtocol_31.IfNum] = UNDI32Device; + UNDI32Device->Undi32BaseDevPath = UndiDevicePath; Status = AppendMac2DevPath ( &UNDI32Device->Undi32DevPath, @@ -452,19 +471,6 @@ Returns: UNDI32Device->Signature = UNDI_DEV_SIGNATURE; - UNDI32Device->NIIProtocol.Revision = EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION; - UNDI32Device->NIIProtocol.Type = EfiNetworkInterfaceUndi; - UNDI32Device->NIIProtocol.MajorVer = PXE_ROMID_MAJORVER; - UNDI32Device->NIIProtocol.MinorVer = PXE_ROMID_MINORVER; - UNDI32Device->NIIProtocol.ImageSize = 0; - UNDI32Device->NIIProtocol.ImageAddr = 0; - UNDI32Device->NIIProtocol.Ipv6Supported = FALSE; - - UNDI32Device->NIIProtocol.StringId[0] = 'U'; - UNDI32Device->NIIProtocol.StringId[1] = 'N'; - UNDI32Device->NIIProtocol.StringId[2] = 'D'; - UNDI32Device->NIIProtocol.StringId[3] = 'I'; - UNDI32Device->NIIProtocol_31.Revision = EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION_31; UNDI32Device->NIIProtocol_31.Type = EfiNetworkInterfaceUndi; UNDI32Device->NIIProtocol_31.MajorVer = PXE_ROMID_MAJORVER; @@ -487,8 +493,6 @@ Returns: &UNDI32Device->DeviceHandle, &gEfiNetworkInterfaceIdentifierProtocolGuid_31, &UNDI32Device->NIIProtocol_31, - &gEfiNetworkInterfaceIdentifierProtocolGuid, - &UNDI32Device->NIIProtocol, &gEfiDevicePathProtocolGuid, UNDI32Device->Undi32DevPath, NULL @@ -499,22 +503,22 @@ Returns: } // - // if the table exists, free it and alloc again, or alloc it directly + // if the table exists, free it and alloc again, or alloc it directly // - if (UnidiDataPointer != NULL) { - Status = gBS->FreePool(UnidiDataPointer); + if (UndiDataPointer != NULL) { + Status = gBS->FreePool(UndiDataPointer); } if (EFI_ERROR (Status)) { goto UndiErrorDeleteDevicePath; } - Len = (pxe_31->IFcnt * sizeof (NII_ENTRY)) + sizeof (UnidiDataPointer); - Status = gBS->AllocatePool (EfiRuntimeServicesData, Len, (VOID **) &UnidiDataPointer); + Len = (pxe_31->IFcnt * sizeof (NII_ENTRY)) + sizeof (UndiDataPointer); + Status = gBS->AllocatePool (EfiRuntimeServicesData, Len, (VOID **) &UndiDataPointer); if (EFI_ERROR (Status)) { goto UndiErrorAllocDataPointer; } - + // // Open For Child Device // @@ -533,19 +537,16 @@ UndiErrorAllocDataPointer: &UNDI32Device->DeviceHandle, &gEfiNetworkInterfaceIdentifierProtocolGuid_31, &UNDI32Device->NIIProtocol_31, - &gEfiNetworkInterfaceIdentifierProtocolGuid, - &UNDI32Device->NIIProtocol, &gEfiDevicePathProtocolGuid, UNDI32Device->Undi32DevPath, NULL ); UndiErrorDeleteDevicePath: - UNDI32DeviceList[UNDI32Device->NIIProtocol.IfNum] = NULL; + UNDI32DeviceList[UNDI32Device->NIIProtocol_31.IfNum] = NULL; gBS->FreePool (UNDI32Device->Undi32DevPath); UndiErrorDeletePxe: - PxeUpdate (NULL, pxe); PxeUpdate (NULL, pxe_31); if (TmpPxePointer != NULL) { gBS->FreePool (TmpPxePointer); @@ -553,6 +554,18 @@ UndiErrorDeletePxe: } UndiErrorDeleteDevice: + if (PciAttributesSaved == TRUE) { + // + // Restore original PCI attributes + // + PciIoFncs->Attributes ( + PciIoFncs, + EfiPciIoAttributeOperationSet, + UNDI32Device->NicInfo.OriginalPciAttributes, + NULL + ); + } + gBS->FreePool (UNDI32Device); UndiError: @@ -639,7 +652,7 @@ Returns: Status = gBS->OpenProtocol ( ChildHandleBuffer[Index], - &gEfiNetworkInterfaceIdentifierProtocolGuid, + &gEfiNetworkInterfaceIdentifierProtocolGuid_31, (VOID **) &NIIProtocol, This->DriverBindingHandle, Controller, @@ -649,6 +662,17 @@ Returns: UNDI32Device = UNDI_DEV_FROM_THIS (NIIProtocol); + // + // Restore original PCI attributes + // + Status = UNDI32Device->NicInfo.Io_Function->Attributes ( + UNDI32Device->NicInfo.Io_Function, + EfiPciIoAttributeOperationSet, + UNDI32Device->NicInfo.OriginalPciAttributes, + NULL + ); + ASSERT_EFI_ERROR (Status); + Status = gBS->CloseProtocol ( Controller, &gEfiPciIoProtocolGuid, @@ -662,8 +686,6 @@ Returns: UNDI32Device->Undi32DevPath, &gEfiNetworkInterfaceIdentifierProtocolGuid_31, &UNDI32Device->NIIProtocol_31, - &gEfiNetworkInterfaceIdentifierProtocolGuid, - &UNDI32Device->NIIProtocol, NULL ); @@ -711,7 +733,7 @@ Routine Description: Arguments: UnqId - Runtime O/S routine might use this, this temp routine does not use it - + MicroSeconds - Determines the length of pause. Returns: @@ -741,13 +763,13 @@ Routine Description: Arguments: UnqId - Runtime O/S routine may use this field, this temp routine does not. - + ReadWrite - Determine if it is an I/O or Memory Read/Write Operation. - + Len - Determines the width of the data operation. - + Port - What port to Read/Write from. - + BuffAddr - Address to read to or write from. Returns: @@ -841,15 +863,15 @@ Routine Description: Arguments: DevPtr - Pointer which will point to the newly created device path with the MAC node attached. - + BaseDevPtr - Pointer to the device path which the UNDI device driver is latching on to. - + AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on.. Returns: EFI_SUCCESS - A MAC address was successfully appended to the Base Device Path. - + other - Not enough resources available to create new Device Path node. --*/ @@ -981,7 +1003,7 @@ Arguments: Returns: EFI_SUCCESS - Install a GUID/Pointer pair into the system's configuration table. - + other - Did not successfully install the GUID/Pointer pair into the configuration table. --*/ @@ -997,12 +1019,12 @@ Returns: return EFI_SUCCESS; } - if(UnidiDataPointer == NULL) { + if(UndiDataPointer == NULL) { return EFI_SUCCESS; } - - UndiData = (NII_TABLE *)UnidiDataPointer; - + + UndiData = (NII_TABLE *)UndiDataPointer; + UndiData->NumEntries = pxe_31->IFcnt; UndiData->NextLink = NULL; @@ -1057,12 +1079,12 @@ Returns: } /** - + Install driver binding protocol of UNDI. - - @param[in] ImageHandle The firmware allocated handle for the EFI image. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. - + @retval EFI_SUCCESS The entry point is executed successfully. @retval other Some error occurs when executing this entry point.