EFI_STATUS EFIAPI RootBridgeIoCopyMem ( IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, IN UINT64 DestAddress, IN UINT64 SrcAddress, IN UINTN Count ) /*++ Routine Description: Copy one region of PCI root bridge memory space to be copied to another region of PCI root bridge memory space. Arguments: This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance. Width - Signifies the width of the memory operation. DestAddress - Destination address of the memory operation. SrcAddress - Source address of the memory operation. Count - Number of memory operations to perform. Returns: EFI_SUCCESS - The data was copied successfully. EFI_INVALID_PARAMETER - Invalid parameters found. EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources. --*/ { EFI_STATUS Status; BOOLEAN Direction; UINTN Stride; UINTN Index; UINT64 Result; if (Width < 0 || Width > EfiPciWidthUint64) { return EFI_INVALID_PARAMETER; } if (DestAddress == SrcAddress) { return EFI_SUCCESS; } Stride = (UINTN)1 << Width; Direction = TRUE; if ((DestAddress > SrcAddress) && (DestAddress < (SrcAddress + Count * Stride))) { Direction = FALSE; SrcAddress = SrcAddress + (Count - 1) * Stride; DestAddress = DestAddress + (Count - 1) * Stride; } for (Index = 0; Index < Count; Index++) { Status = RootBridgeIoMemRead ( This, Width, SrcAddress, 1, &Result ); if (EFI_ERROR (Status)) { return Status; } Status = RootBridgeIoMemWrite ( This, Width, DestAddress, 1, &Result ); if (EFI_ERROR (Status)) { return Status; } if (Direction) { SrcAddress += Stride; DestAddress += Stride; } else { SrcAddress -= Stride; DestAddress -= Stride; } } return EFI_SUCCESS; }
EFI_STATUS EFIAPI RootBridgeIoCopyMem ( IN struct _EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, IN UINT64 DestAddress, IN UINT64 SrcAddress, IN UINTN Count ) /*++ Routine Description: Memory copy Arguments: Returns: --*/ { EFI_STATUS Status; BOOLEAN Direction; UINTN Stride; UINTN Index; UINT64 Result; if (Width < 0 || Width > EfiPciWidthUint64) { return EFI_INVALID_PARAMETER; } if (DestAddress == SrcAddress) { return EFI_SUCCESS; } Stride = (UINTN)(1 << Width); Direction = TRUE; if ((DestAddress > SrcAddress) && (DestAddress < (SrcAddress + Count * Stride))) { Direction = FALSE; SrcAddress = SrcAddress + (Count-1) * Stride; DestAddress = DestAddress + (Count-1) * Stride; } for (Index = 0;Index < Count;Index++) { Status = RootBridgeIoMemRead ( This, Width, SrcAddress, 1, &Result ); if (EFI_ERROR (Status)) { return Status; } Status = RootBridgeIoMemWrite ( This, Width, DestAddress, 1, &Result ); if (EFI_ERROR (Status)) { return Status; } if (Direction) { SrcAddress += Stride; DestAddress += Stride; } else { SrcAddress -= Stride; DestAddress -= Stride; } } return EFI_SUCCESS; }