X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FNonDiscoverablePciDeviceDxe%2FNonDiscoverablePciDeviceIo.c;h=c3e83003a01c5e79c7b04e82d84722a2bd885ad1;hb=3b9cd714542a8744252d973e1f163222a9f21b9e;hp=ce73a770c18b907630a50e2fc854ce3212b94a33;hpb=16296a126c99174ad27a6d78229df70e62049310;p=mirror_edk2.git diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c index ce73a770c1..c3e83003a0 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c @@ -3,13 +3,7 @@ Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
Copyright (c) 2016, Linaro, Ltd. 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. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -28,9 +22,14 @@ typedef struct { UINTN NumberOfBytes; } NON_DISCOVERABLE_PCI_DEVICE_MAP_INFO; -// -// Get the resource associated with BAR number 'BarIndex'. -// +/** + Get the resource associated with BAR number 'BarIndex'. + + @param Dev Point to the NON_DISCOVERABLE_PCI_DEVICE instance. + @param BarIndex The BAR index of the standard PCI Configuration header to use as the + base address for the memory operation to perform. + @param Descriptor Points to the address space descriptor +**/ STATIC EFI_STATUS GetBarResource ( @@ -47,6 +46,10 @@ GetBarResource ( BarIndex -= (UINT8)Dev->BarOffset; + if (BarIndex >= Dev->BarCount) { + return EFI_UNSUPPORTED; + } + for (Desc = Dev->Device->Resources; Desc->Desc != ACPI_END_TAG_DESCRIPTOR; Desc = (VOID *)((UINT8 *)Desc + Desc->Len + 3)) { @@ -61,6 +64,21 @@ GetBarResource ( return EFI_NOT_FOUND; } +/** + Reads from the memory space of a PCI controller. Returns either when the polling exit criteria is + satisfied or after a defined duration. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Width Signifies the width of the memory or I/O operations. + @param BarIndex The BAR index of the standard PCI Configuration header to use as the + base address for the memory operation to perform. + @param Offset The offset within the selected BAR to start the memory operation. + @param Mask Mask used for the polling criteria. + @param Value The comparison value used for the polling exit criteria. + @param Delay The number of 100 ns units to poll. + @param Result Pointer to the last value read from the memory location. + +**/ STATIC EFI_STATUS EFIAPI @@ -75,10 +93,50 @@ PciIoPollMem ( OUT UINT64 *Result ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + UINTN Count; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (Result == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Count = 1; + + Status = GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } +/** + Reads from the memory space of a PCI controller. Returns either when the polling exit criteria is + satisfied or after a defined duration. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Width Signifies the width of the memory or I/O operations. + @param BarIndex The BAR index of the standard PCI Configuration header to use as the + base address for the memory operation to perform. + @param Offset The offset within the selected BAR to start the memory operation. + @param Mask Mask used for the polling criteria. + @param Value The comparison value used for the polling exit criteria. + @param Delay The number of 100 ns units to poll. + @param Result Pointer to the last value read from the memory location. + +**/ STATIC EFI_STATUS EFIAPI @@ -93,10 +151,51 @@ PciIoPollIo ( OUT UINT64 *Result ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + UINTN Count; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + if (Result == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Count = 1; + + Status = GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } +/** + Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space. + + @param Width Signifies the width of the memory or I/O operations. + @param Count The number of memory or I/O operations to perform. + @param DstStride The stride of the destination buffer. + @param Dst For read operations, the destination buffer to store the results. For write + operations, the destination buffer to write data to. + @param SrcStride The stride of the source buffer. + @param Src For read operations, the source buffer to read data from. For write + operations, the source buffer to write data from. + + @retval EFI_SUCCESS The data was read from or written to the PCI controller. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + +**/ STATIC EFI_STATUS EFIAPI @@ -148,6 +247,26 @@ PciIoMemRW ( return EFI_SUCCESS; } +/** + Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Width Signifies the width of the memory or I/O operations. + @param BarIndex The BAR index of the standard PCI Configuration header to use as the + base address for the memory or I/O operation to perform. + @param Offset The offset within the selected BAR to start the memory or I/O operation. + @param Count The number of memory or I/O operations to perform. + @param Buffer For read operations, the destination buffer to store the results. For write + operations, the source buffer to write data from. + + @retval EFI_SUCCESS The data was read from or written to the PCI controller. + @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller. + @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not + valid for the PCI BAR specified by BarIndex. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + +**/ STATIC EFI_STATUS EFIAPI @@ -215,6 +334,26 @@ PciIoMemRead ( return EFI_INVALID_PARAMETER; } +/** + Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Width Signifies the width of the memory or I/O operations. + @param BarIndex The BAR index of the standard PCI Configuration header to use as the + base address for the memory or I/O operation to perform. + @param Offset The offset within the selected BAR to start the memory or I/O operation. + @param Count The number of memory or I/O operations to perform. + @param Buffer For read operations, the destination buffer to store the results. For write + operations, the source buffer to write data from. + + @retval EFI_SUCCESS The data was read from or written to the PCI controller. + @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller. + @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not + valid for the PCI BAR specified by BarIndex. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + +**/ STATIC EFI_STATUS EFIAPI @@ -282,6 +421,19 @@ PciIoMemWrite ( return EFI_INVALID_PARAMETER; } +/** + Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Width Signifies the width of the memory or I/O operations. + @param BarIndex The BAR index of the standard PCI Configuration header to use as the + base address for the memory or I/O operation to perform. + @param Offset The offset within the selected BAR to start the memory or I/O operation. + @param Count The number of memory or I/O operations to perform. + @param Buffer For read operations, the destination buffer to store the results. For write + operations, the source buffer to write data from. + +**/ STATIC EFI_STATUS EFIAPI @@ -294,10 +446,46 @@ PciIoIoRead ( IN OUT VOID *Buffer ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_STATUS Status; + + if ((UINT32)Width >= EfiPciIoWidthMaximum) { + return EFI_INVALID_PARAMETER; + } + + if (Buffer == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status = GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } +/** + Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Width Signifies the width of the memory or I/O operations. + @param BarIndex The BAR index of the standard PCI Configuration header to use as the + base address for the memory or I/O operation to perform. + @param Offset The offset within the selected BAR to start the memory or I/O operation. + @param Count The number of memory or I/O operations to perform. + @param Buffer For read operations, the destination buffer to store the results. For write + operations, the source buffer to write data from. + +**/ STATIC EFI_STATUS EFIAPI @@ -310,10 +498,44 @@ PciIoIoWrite ( IN OUT VOID *Buffer ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_STATUS Status; + + if ((UINT32)Width >= EfiPciIoWidthMaximum) { + return EFI_INVALID_PARAMETER; + } + + if (Buffer == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status = GetBarResource (Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } +/** + Enable a PCI driver to access PCI config space. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Width Signifies the width of the memory or I/O operations. + @param Offset The offset within the selected BAR to start the memory or I/O operation. + @param Count The number of memory or I/O operations to perform. + @param Buffer For read operations, the destination buffer to store the results. For write + operations, the source buffer to write data from. + +**/ STATIC EFI_STATUS EFIAPI @@ -337,6 +559,11 @@ PciIoPciRead ( Address = (UINT8 *)&Dev->ConfigSpace + Offset; Length = Count << ((UINTN)Width & 0x3); + if (Offset >= sizeof (Dev->ConfigSpace)) { + ZeroMem (Buffer, Length); + return EFI_SUCCESS; + } + if (Offset + Length > sizeof (Dev->ConfigSpace)) { // // Read all zeroes for config space accesses beyond the first @@ -350,6 +577,22 @@ PciIoPciRead ( return PciIoMemRW (Width, Count, 1, Buffer, 1, Address); } +/** + Enable a PCI driver to access PCI config space. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Width Signifies the width of the memory or I/O operations. + @param Offset The offset within the selected BAR to start the memory or I/O operation. + @param Count The number of memory or I/O operations to perform. + @param Buffer For read operations, the destination buffer to store the results. For write + operations, the source buffer to write data from + + @retval EFI_SUCCESS The data was read from or written to the PCI controller. + @retval EFI_UNSUPPORTED The address range specified by Offset, Width, and Count is not + valid for the PCI BAR specified by BarIndex. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + +**/ STATIC EFI_STATUS EFIAPI @@ -378,6 +621,24 @@ PciIoPciWrite ( return PciIoMemRW (Width, Count, 1, Address, 1, Buffer); } +/** + Enables a PCI driver to copy one region of PCI memory space to another region of PCI + memory space. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Width Signifies the width of the memory operations. + @param DestBarIndex The BAR index in the standard PCI Configuration header to use as the + base address for the memory operation to perform. + @param DestOffset The destination offset within the BAR specified by DestBarIndex to + start the memory writes for the copy operation. + @param SrcBarIndex The BAR index in the standard PCI Configuration header to use as the + base address for the memory operation to perform. + @param SrcOffset The source offset within the BAR specified by SrcBarIndex to start + the memory reads for the copy operation. + @param Count The number of memory operations to perform. Bytes moved is Width + size * Count, starting at DestOffset and SrcOffset. + +**/ STATIC EFI_STATUS EFIAPI @@ -391,10 +652,58 @@ PciIoCopyMem ( IN UINTN Count ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *DestDesc; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *SrcDesc; + EFI_STATUS Status; + + if ((UINT32)Width > EfiPciIoWidthUint64) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + Status = GetBarResource (Dev, DestBarIndex, &DestDesc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (DestOffset + (Count << (Width & 0x3)) > DestDesc->AddrLen) { + return EFI_UNSUPPORTED; + } + + Status = GetBarResource (Dev, SrcBarIndex, &SrcDesc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (SrcOffset + (Count << (Width & 0x3)) > SrcDesc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } +/** + Provides the PCI controller-specific addresses needed to access system memory. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Operation Indicates if the bus master is going to read or write to system memory. + @param HostAddress The system memory address to map to the PCI controller. + @param NumberOfBytes On input the number of bytes to map. On output the number of bytes + that were mapped. + @param DeviceAddress The resulting map address for the bus master PCI controller to use to + access the hosts HostAddress. + @param Mapping A resulting value to pass to Unmap(). + + @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes. + @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. + @retval EFI_DEVICE_ERROR The system hardware could not map the requested address. + +**/ STATIC EFI_STATUS EFIAPI @@ -411,13 +720,26 @@ CoherentPciIoMap ( EFI_STATUS Status; NON_DISCOVERABLE_PCI_DEVICE_MAP_INFO *MapInfo; + if (Operation != EfiPciIoOperationBusMasterRead && + Operation != EfiPciIoOperationBusMasterWrite && + Operation != EfiPciIoOperationBusMasterCommonBuffer) { + return EFI_INVALID_PARAMETER; + } + + if (HostAddress == NULL || + NumberOfBytes == NULL || + DeviceAddress == NULL || + Mapping == NULL) { + return EFI_INVALID_PARAMETER; + } + // // If HostAddress exceeds 4 GB, and this device does not support 64-bit DMA // addressing, we need to allocate a bounce buffer and copy over the data. // Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); if ((Dev->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) == 0 && - (UINTN)HostAddress + *NumberOfBytes > SIZE_4GB) { + (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress + *NumberOfBytes > SIZE_4GB) { // // Bounce buffering is not possible for consistent mappings @@ -461,6 +783,15 @@ CoherentPciIoMap ( return EFI_SUCCESS; } +/** + Completes the Map() operation and releases any corresponding resources. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Mapping The mapping value returned from Map(). + + @retval EFI_SUCCESS The range was unmapped. + +**/ STATIC EFI_STATUS EFIAPI @@ -484,6 +815,25 @@ CoherentPciIoUnmap ( return EFI_SUCCESS; } +/** + Allocates pages. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Type This parameter is not used and must be ignored. + @param MemoryType The type of memory to allocate, EfiBootServicesData or + EfiRuntimeServicesData. + @param Pages The number of pages to allocate. + @param HostAddress A pointer to store the base system memory address of the + allocated range. + @param Attributes The requested bit mask of attributes for the allocated range. + + @retval EFI_SUCCESS The requested memory pages were allocated. + @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are + MEMORY_WRITE_COMBINE and MEMORY_CACHED. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + +**/ STATIC EFI_STATUS EFIAPI @@ -506,6 +856,11 @@ CoherentPciIoAllocateBuffer ( return EFI_UNSUPPORTED; } + if ((MemoryType != EfiBootServicesData) && + (MemoryType != EfiRuntimeServicesData)) { + return EFI_INVALID_PARAMETER; + } + // // Allocate below 4 GB if the dual address cycle attribute has not // been set. If the system has no memory available below 4 GB, there @@ -526,6 +881,16 @@ CoherentPciIoAllocateBuffer ( return Status; } +/** + Frees memory that was allocated in function CoherentPciIoAllocateBuffer (). + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Pages The number of pages to free. + @param HostAddress The base system memory address of the allocated range. + + @retval EFI_SUCCESS The requested memory pages were freed. + +**/ STATIC EFI_STATUS EFIAPI @@ -539,6 +904,17 @@ CoherentPciIoFreeBuffer ( return EFI_SUCCESS; } +/** + Frees memory that was allocated in function NonCoherentPciIoAllocateBuffer (). + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Pages The number of pages to free. + @param HostAddress The base system memory address of the allocated range. + + @retval EFI_SUCCESS The requested memory pages were freed. + @retval others The operation contain some errors. + +**/ STATIC EFI_STATUS EFIAPI @@ -557,6 +933,7 @@ NonCoherentPciIoFreeBuffer ( Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); Found = FALSE; + Alloc = NULL; // // Find the uncached allocation list entry associated @@ -603,6 +980,25 @@ FreeAlloc: return Status; } +/** + Allocates pages. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Type This parameter is not used and must be ignored. + @param MemoryType The type of memory to allocate, EfiBootServicesData or + EfiRuntimeServicesData. + @param Pages The number of pages to allocate. + @param HostAddress A pointer to store the base system memory address of the + allocated range. + @param Attributes The requested bit mask of attributes for the allocated range. + + @retval EFI_SUCCESS The requested memory pages were allocated. + @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are + MEMORY_WRITE_COMBINE and MEMORY_CACHED. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + +**/ STATIC EFI_STATUS EFIAPI @@ -622,6 +1018,10 @@ NonCoherentPciIoAllocateBuffer ( NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION *Alloc; VOID *AllocAddress; + if (HostAddress == NULL) { + return EFI_INVALID_PARAMETER; + } + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); Status = CoherentPciIoAllocateBuffer (This, Type, MemoryType, Pages, @@ -701,6 +1101,25 @@ FreeBuffer: return Status; } +/** + Provides the PCI controller-specific addresses needed to access system memory. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Operation Indicates if the bus master is going to read or write to system memory. + @param HostAddress The system memory address to map to the PCI controller. + @param NumberOfBytes On input the number of bytes to map. On output the number of bytes + that were mapped. + @param DeviceAddress The resulting map address for the bus master PCI controller to use to + access the hosts HostAddress. + @param Mapping A resulting value to pass to Unmap(). + + @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes. + @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. + @retval EFI_DEVICE_ERROR The system hardware could not map the requested address. + +**/ STATIC EFI_STATUS EFIAPI @@ -721,6 +1140,19 @@ NonCoherentPciIoMap ( EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; BOOLEAN Bounce; + if (HostAddress == NULL || + NumberOfBytes == NULL || + DeviceAddress == NULL || + Mapping == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (Operation != EfiPciIoOperationBusMasterRead && + Operation != EfiPciIoOperationBusMasterWrite && + Operation != EfiPciIoOperationBusMasterCommonBuffer) { + return EFI_INVALID_PARAMETER; + } + MapInfo = AllocatePool (sizeof *MapInfo); if (MapInfo == NULL) { return EFI_OUT_OF_RESOURCES; @@ -737,7 +1169,7 @@ NonCoherentPciIoMap ( // a bounce buffer and copy over the data in case HostAddress >= 4 GB. // Bounce = ((Dev->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) == 0 && - (UINTN)HostAddress + *NumberOfBytes > SIZE_4GB); + (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress + *NumberOfBytes > SIZE_4GB); if (!Bounce) { switch (Operation) { @@ -815,6 +1247,15 @@ FreeMapInfo: return Status; } +/** + Completes the Map() operation and releases any corresponding resources. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Mapping The mapping value returned from Map(). + + @retval EFI_SUCCESS The range was unmapped. + +**/ STATIC EFI_STATUS EFIAPI @@ -858,6 +1299,12 @@ NonCoherentPciIoUnmap ( return EFI_SUCCESS; } +/** + Flushes all PCI posted write transactions from a PCI host bridge to system memory. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + +**/ STATIC EFI_STATUS EFIAPI @@ -868,6 +1315,19 @@ PciIoFlush ( return EFI_SUCCESS; } +/** + Retrieves this PCI controller's current PCI bus number, device number, and function number. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param SegmentNumber The PCI controller's current PCI segment number. + @param BusNumber The PCI controller's current PCI bus number. + @param DeviceNumber The PCI controller's current PCI device number. + @param FunctionNumber The PCI controller's current PCI function number. + + @retval EFI_SUCCESS The PCI controller location was returned. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + +**/ STATIC EFI_STATUS EFIAPI @@ -879,6 +1339,8 @@ PciIoGetLocation ( OUT UINTN *FunctionNumber ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + if (SegmentNumber == NULL || BusNumber == NULL || DeviceNumber == NULL || @@ -886,14 +1348,35 @@ PciIoGetLocation ( return EFI_INVALID_PARAMETER; } - *SegmentNumber = 0; - *BusNumber = 0xff; - *DeviceNumber = 0; + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + *SegmentNumber = 0xff; + *BusNumber = Dev->UniqueId >> 5; + *DeviceNumber = Dev->UniqueId & 0x1f; *FunctionNumber = 0; return EFI_SUCCESS; } +/** + Performs an operation on the attributes that this PCI controller supports. The operations include + getting the set of supported attributes, retrieving the current attributes, setting the current + attributes, enabling attributes, and disabling attributes. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Operation The operation to perform on the attributes for this PCI controller. + @param Attributes The mask of attributes that are used for Set, Enable, and Disable + operations. + @param Result A pointer to the result mask of attributes that are returned for the Get + and Supported operations. + + @retval EFI_SUCCESS The operation on the PCI controller's attributes was completed. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_UNSUPPORTED one or more of the bits set in + Attributes are not supported by this PCI controller or one of + its parent bridges when Operation is Set, Enable or Disable. + +**/ STATIC EFI_STATUS EFIAPI @@ -909,6 +1392,10 @@ PciIoAttributes ( Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + if ((Attributes & (~(DEV_SUPPORTED_ATTRIBUTES))) != 0) { + return EFI_UNSUPPORTED; + } + Enable = FALSE; switch (Operation) { case EfiPciIoAttributeOperationGet: @@ -922,7 +1409,7 @@ PciIoAttributes ( if (Result == NULL) { return EFI_INVALID_PARAMETER; } - *Result = EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE; + *Result = DEV_SUPPORTED_ATTRIBUTES; break; case EfiPciIoAttributeOperationEnable: @@ -951,6 +1438,28 @@ PciIoAttributes ( return EFI_SUCCESS; } +/** + Gets the attributes that this PCI controller supports setting on a BAR using + SetBarAttributes(), and retrieves the list of resource descriptors for a BAR. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param BarIndex The BAR index of the standard PCI Configuration header to use as the + base address for resource range. The legal range for this field is 0..5. + @param Supports A pointer to the mask of attributes that this PCI controller supports + setting for this BAR with SetBarAttributes(). + @param Resources A pointer to the ACPI 2.0 resource descriptors that describe the current + configuration of this BAR of the PCI controller. + + @retval EFI_SUCCESS If Supports is not NULL, then the attributes that the PCI + controller supports are returned in Supports. If Resources + is not NULL, then the ACPI 2.0 resource descriptors that the PCI + controller is currently using are returned in Resources. + @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL. + @retval EFI_UNSUPPORTED BarIndex not valid for this PCI controller. + @retval EFI_OUT_OF_RESOURCES There are not enough resources available to allocate + Resources. + +**/ STATIC EFI_STATUS EFIAPI @@ -962,7 +1471,8 @@ PciIoGetBarAttributes ( ) { NON_DISCOVERABLE_PCI_DEVICE *Dev; - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor, *BarDesc; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc; EFI_ACPI_END_TAG_DESCRIPTOR *End; EFI_STATUS Status; @@ -1002,6 +1512,19 @@ PciIoGetBarAttributes ( return EFI_SUCCESS; } +/** + Sets the attributes for a range of a BAR on a PCI controller. + + @param This A pointer to the EFI_PCI_IO_PROTOCOL instance. + @param Attributes The mask of attributes to set for the resource range specified by + BarIndex, Offset, and Length. + @param BarIndex The BAR index of the standard PCI Configuration header to use as the + base address for resource range. The legal range for this field is 0..5. + @param Offset A pointer to the BAR relative base address of the resource range to be + modified by the attributes specified by Attributes. + @param Length A pointer to the length of the resource range to be modified by the + attributes specified by Attributes. +**/ STATIC EFI_STATUS EFIAPI @@ -1013,6 +1536,33 @@ PciIoSetBarAttributes ( IN OUT UINT64 *Length ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; + EFI_PCI_IO_PROTOCOL_WIDTH Width; + UINTN Count; + EFI_STATUS Status; + + if ((Attributes & (~DEV_SUPPORTED_ATTRIBUTES)) != 0) { + return EFI_UNSUPPORTED; + } + + if (Offset == NULL || Length == NULL) { + return EFI_INVALID_PARAMETER; + } + + Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + Width = EfiPciIoWidthUint8; + Count = (UINT32) *Length; + + Status = GetBarResource(Dev, BarIndex, &Desc); + if (EFI_ERROR (Status)) { + return Status; + } + + if (*Offset + (Count << (Width & 0x3)) > Desc->AddrLen) { + return EFI_UNSUPPORTED; + } + ASSERT (FALSE); return EFI_UNSUPPORTED; } @@ -1038,6 +1588,12 @@ STATIC CONST EFI_PCI_IO_PROTOCOL PciIoTemplate = 0 }; +/** + Initialize PciIo Protocol. + + @param Dev Point to NON_DISCOVERABLE_PCI_DEVICE instance. + +**/ VOID InitializePciIoProtocol ( NON_DISCOVERABLE_PCI_DEVICE *Dev