+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
-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
-\r
-Module Name:\r
-\r
- DeviceIo.c\r
- \r
-Abstract:\r
-\r
- EFI PC-AT PCI Device IO driver\r
-\r
---*/\r
-#include "PcatPciRootBridge.h"\r
-#include "DeviceIo.h"\r
-\r
-EFI_STATUS\r
-DeviceIoConstructor (\r
- IN EFI_HANDLE Handle,\r
- IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo,\r
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
- IN UINT16 PrimaryBus,\r
- IN UINT16 SubordinateBus\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Initialize and install a Device IO protocol on a empty device path handle.\r
-\r
-Arguments:\r
- \r
- Handle - Handle of PCI RootBridge IO instance\r
- PciRootBridgeIo - PCI RootBridge IO instance\r
- DevicePath - Device Path of PCI RootBridge IO instance\r
- PrimaryBus - Primary Bus\r
- SubordinateBus - Subordinate Bus\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - This driver is added to ControllerHandle. \r
- EFI_ALREADY_STARTED - This driver is already running on ControllerHandle. \r
- Others - This driver does not support this device.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- //\r
- // Initialize the Device IO device instance.\r
- //\r
- Private = AllocateZeroPool (sizeof (DEVICE_IO_PRIVATE_DATA));\r
- if (Private == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- Private->Signature = DEVICE_IO_PRIVATE_DATA_SIGNATURE;\r
- Private->Handle = Handle;\r
- Private->PciRootBridgeIo = PciRootBridgeIo;\r
- Private->DevicePath = DevicePath;\r
- Private->PrimaryBus = PrimaryBus;\r
- Private->SubordinateBus = SubordinateBus;\r
-\r
- Private->DeviceIo.Mem.Read = DeviceIoMemRead;\r
- Private->DeviceIo.Mem.Write = DeviceIoMemWrite;\r
- Private->DeviceIo.Io.Read = DeviceIoIoRead;\r
- Private->DeviceIo.Io.Write = DeviceIoIoWrite;\r
- Private->DeviceIo.Pci.Read = DeviceIoPciRead;\r
- Private->DeviceIo.Pci.Write = DeviceIoPciWrite;\r
- Private->DeviceIo.PciDevicePath = DeviceIoPciDevicePath;\r
- Private->DeviceIo.Map = DeviceIoMap;\r
- Private->DeviceIo.Unmap = DeviceIoUnmap;\r
- Private->DeviceIo.AllocateBuffer = DeviceIoAllocateBuffer;\r
- Private->DeviceIo.Flush = DeviceIoFlush;\r
- Private->DeviceIo.FreeBuffer = DeviceIoFreeBuffer;\r
-\r
- //\r
- // Install protocol interfaces for the Device IO device.\r
- //\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &Private->Handle,\r
- &gEfiDeviceIoProtocolGuid,\r
- &Private->DeviceIo,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoMemRead (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN EFI_IO_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Perform reading memory mapped I/O space of device.\r
-\r
-Arguments:\r
- \r
- This - A pointer to EFI_DEVICE_IO protocol instance. \r
- Width - Width of I/O operations.\r
- Address - The base address of I/O operations. \r
- Count - The number of I/O operations to perform. \r
- Bytes moves is Width size * Count, starting at Address. \r
- Buffer - The destination buffer to store results.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The data was read from the device. \r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- if (Width > MMIO_COPY_UINT64) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if (Width >= MMIO_COPY_UINT8) {\r
- Width = (EFI_IO_WIDTH) (Width - MMIO_COPY_UINT8);\r
- Status = Private->PciRootBridgeIo->CopyMem (\r
- Private->PciRootBridgeIo,\r
- (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
- (UINT64)(UINTN) Buffer,\r
- Address,\r
- Count\r
- );\r
- } else {\r
- Status = Private->PciRootBridgeIo->Mem.Read (\r
- Private->PciRootBridgeIo,\r
- (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
- Address,\r
- Count,\r
- Buffer\r
- );\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoMemWrite (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN EFI_IO_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Perform writing memory mapped I/O space of device.\r
-\r
-Arguments:\r
- \r
- This - A pointer to EFI_DEVICE_IO protocol instance. \r
- Width - Width of I/O operations. \r
- Address - The base address of I/O operations. \r
- Count - The number of I/O operations to perform. \r
- Bytes moves is Width size * Count, starting at Address. \r
- Buffer - The source buffer of data to be written.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The data was written to the device.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- if (Width > MMIO_COPY_UINT64) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if (Width >= MMIO_COPY_UINT8) {\r
- Width = (EFI_IO_WIDTH) (Width - MMIO_COPY_UINT8);\r
- Status = Private->PciRootBridgeIo->CopyMem (\r
- Private->PciRootBridgeIo,\r
- (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
- Address,\r
- (UINT64)(UINTN) Buffer,\r
- Count\r
- );\r
- } else {\r
- Status = Private->PciRootBridgeIo->Mem.Write (\r
- Private->PciRootBridgeIo,\r
- (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
- Address,\r
- Count,\r
- Buffer\r
- );\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoIoRead (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN EFI_IO_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Perform reading I/O space of device.\r
-\r
-Arguments:\r
- \r
- This - A pointer to EFI_DEVICE_IO protocol instance. \r
- Width - Width of I/O operations.\r
- Address - The base address of I/O operations. \r
- Count - The number of I/O operations to perform. \r
- Bytes moves is Width size * Count, starting at Address. \r
- Buffer - The destination buffer to store results.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The data was read from the device.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- if (Width >= MMIO_COPY_UINT8) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = Private->PciRootBridgeIo->Io.Read (\r
- Private->PciRootBridgeIo,\r
- (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
- Address,\r
- Count,\r
- Buffer\r
- );\r
-\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoIoWrite (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN EFI_IO_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Perform writing I/O space of device.\r
-\r
-Arguments:\r
- \r
- This - A pointer to EFI_DEVICE_IO protocol instance. \r
- Width - Width of I/O operations.\r
- Address - The base address of I/O operations.\r
- Count - The number of I/O operations to perform. \r
- Bytes moves is Width size * Count, starting at Address. \r
- Buffer - The source buffer of data to be written.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The data was written to the device.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- if (Width >= MMIO_COPY_UINT8) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = Private->PciRootBridgeIo->Io.Write (\r
- Private->PciRootBridgeIo,\r
- (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
- Address,\r
- Count,\r
- Buffer\r
- );\r
-\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoPciRead (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN EFI_IO_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Perform reading PCI configuration space of device\r
-\r
-Arguments:\r
- \r
- This - A pointer to EFI_DEVICE_IO protocol instance. \r
- Width - Width of I/O operations. \r
- Address - The base address of I/O operations. \r
- Count - The number of I/O operations to perform. \r
- Bytes moves is Width size * Count, starting at Address. \r
- Buffer - The destination buffer to store results.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The data was read from the device.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- if ((UINT32)Width >= MMIO_COPY_UINT8) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = Private->PciRootBridgeIo->Pci.Read (\r
- Private->PciRootBridgeIo,\r
- (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
- Address,\r
- Count,\r
- Buffer\r
- );\r
-\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoPciWrite (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN EFI_IO_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Perform writing PCI configuration space of device.\r
-\r
-Arguments:\r
- \r
- This - A pointer to EFI_DEVICE_IO protocol instance. \r
- Width - Width of I/O operations. \r
- Address - The base address of I/O operations. \r
- Count - The number of I/O operations to perform. \r
- Bytes moves is Width size * Count, starting at Address. \r
- Buffer - The source buffer of data to be written.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The data was written to the device.\r
- EFI_INVALID_PARAMETER - Width is invalid.\r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- if ((UINT32)Width >= MMIO_COPY_UINT8) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Status = Private->PciRootBridgeIo->Pci.Write (\r
- Private->PciRootBridgeIo,\r
- (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,\r
- Address,\r
- Count,\r
- Buffer\r
- );\r
-\r
- return Status;\r
-}\r
-\r
-EFI_DEVICE_PATH_PROTOCOL *\r
-AppendPciDevicePath (\r
- IN DEVICE_IO_PRIVATE_DATA *Private,\r
- IN UINT8 Bus,\r
- IN UINT8 Device,\r
- IN UINT8 Function,\r
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
- IN OUT UINT16 *BridgePrimaryBus,\r
- IN OUT UINT16 *BridgeSubordinateBus\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Append a PCI device path node to another device path.\r
-\r
-Arguments:\r
- \r
- Private - A pointer to DEVICE_IO_PRIVATE_DATA instance. \r
- Bus - PCI bus number of the device.\r
- Device - PCI device number of the device.\r
- Function - PCI function number of the device.\r
- DevicePath - Original device path which will be appended a PCI device path node.\r
- BridgePrimaryBus - Primary bus number of the bridge.\r
- BridgeSubordinateBus - Subordinate bus number of the bridge.\r
-\r
-Returns:\r
- \r
- Pointer to the appended PCI device path.\r
-\r
---*/\r
-{\r
- UINT16 ThisBus;\r
- UINT8 ThisDevice;\r
- UINT8 ThisFunc;\r
- UINT64 Address;\r
- PCI_TYPE01 PciBridge;\r
- PCI_TYPE01 *PciPtr;\r
- EFI_DEVICE_PATH_PROTOCOL *ReturnDevicePath;\r
- PCI_DEVICE_PATH PciNode;\r
-\r
- PciPtr = &PciBridge;\r
- for (ThisBus = *BridgePrimaryBus; ThisBus <= *BridgeSubordinateBus; ThisBus++) {\r
- for (ThisDevice = 0; ThisDevice <= PCI_MAX_DEVICE; ThisDevice++) {\r
- for (ThisFunc = 0; ThisFunc <= PCI_MAX_FUNC; ThisFunc++) {\r
- Address = EFI_PCI_ADDRESS (ThisBus, ThisDevice, ThisFunc, 0);\r
- ZeroMem (PciPtr, sizeof (PCI_TYPE01));\r
- Private->DeviceIo.Pci.Read (\r
- &Private->DeviceIo,\r
- IO_UINT32,\r
- Address,\r
- 1,\r
- &(PciPtr->Hdr.VendorId)\r
- );\r
- if ((PciPtr->Hdr.VendorId == 0xffff) && (ThisFunc == 0)) {\r
- break;\r
- }\r
- if (PciPtr->Hdr.VendorId == 0xffff) {\r
- continue;\r
- }\r
-\r
- Private->DeviceIo.Pci.Read (\r
- &Private->DeviceIo,\r
- IO_UINT32,\r
- Address,\r
- sizeof (PCI_TYPE01) / sizeof (UINT32),\r
- PciPtr\r
- );\r
- if (IS_PCI_BRIDGE (PciPtr)) {\r
- if (Bus >= PciPtr->Bridge.SecondaryBus && Bus <= PciPtr->Bridge.SubordinateBus) {\r
-\r
- PciNode.Header.Type = HARDWARE_DEVICE_PATH;\r
- PciNode.Header.SubType = HW_PCI_DP;\r
- SetDevicePathNodeLength (&PciNode.Header, sizeof (PciNode));\r
-\r
- PciNode.Device = ThisDevice;\r
- PciNode.Function = ThisFunc;\r
- ReturnDevicePath = AppendDevicePathNode (DevicePath, &PciNode.Header);\r
-\r
- *BridgePrimaryBus = PciPtr->Bridge.SecondaryBus;\r
- *BridgeSubordinateBus = PciPtr->Bridge.SubordinateBus;\r
- return ReturnDevicePath;\r
- }\r
- }\r
-\r
- if ((ThisFunc == 0) && ((PciPtr->Hdr.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x0)) {\r
- //\r
- // Skip sub functions, this is not a multi function device\r
- //\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-\r
- ZeroMem (&PciNode, sizeof (PciNode));\r
- PciNode.Header.Type = HARDWARE_DEVICE_PATH;\r
- PciNode.Header.SubType = HW_PCI_DP;\r
- SetDevicePathNodeLength (&PciNode.Header, sizeof (PciNode));\r
- PciNode.Device = Device;\r
- PciNode.Function = Function;\r
-\r
- ReturnDevicePath = AppendDevicePathNode (DevicePath, &PciNode.Header);\r
-\r
- *BridgePrimaryBus = 0xffff;\r
- *BridgeSubordinateBus = 0xffff;\r
- return ReturnDevicePath;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoPciDevicePath (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN UINT64 Address,\r
- IN OUT EFI_DEVICE_PATH_PROTOCOL **PciDevicePath\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Provides an EFI Device Path for a PCI device with the given PCI configuration space address.\r
-\r
-Arguments:\r
- \r
- This - A pointer to the EFI_DEVICE_IO_INTERFACE instance. \r
- Address - The PCI configuration space address of the device whose Device Path\r
- is going to be returned. \r
- PciDevicePath - A pointer to the pointer for the EFI Device Path for PciAddress.\r
- Memory for the Device Path is allocated from the pool.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The PciDevicePath returns a pointer to a valid EFI Device Path.\r
- EFI_UNSUPPORTED - The PciAddress does not map to a valid EFI Device Path. \r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
-\r
---*/\r
-{\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
- UINT16 PrimaryBus;\r
- UINT16 SubordinateBus;\r
- UINT8 Bus;\r
- UINT8 Device;\r
- UINT8 Func;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- Bus = (UINT8) (((UINT32) Address >> 24) & 0xff);\r
- Device = (UINT8) (((UINT32) Address >> 16) & 0xff);\r
- Func = (UINT8) (((UINT32) Address >> 8) & 0xff);\r
-\r
- if (Bus < Private->PrimaryBus || Bus > Private->SubordinateBus) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- *PciDevicePath = Private->DevicePath;\r
- PrimaryBus = Private->PrimaryBus;\r
- SubordinateBus = Private->SubordinateBus;\r
- do {\r
- *PciDevicePath = AppendPciDevicePath (\r
- Private,\r
- Bus,\r
- Device,\r
- Func,\r
- *PciDevicePath,\r
- &PrimaryBus,\r
- &SubordinateBus\r
- );\r
- if (*PciDevicePath == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- } while (PrimaryBus != 0xffff);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoMap (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN EFI_IO_OPERATION_TYPE Operation,\r
- IN EFI_PHYSICAL_ADDRESS *HostAddress,\r
- IN OUT UINTN *NumberOfBytes,\r
- OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
- OUT VOID **Mapping\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Provides the device-specific addresses needed to access system memory.\r
-\r
-Arguments:\r
- \r
- This - A pointer to the EFI_DEVICE_IO_INTERFACE instance. \r
- Operation - Indicates if the bus master is going to read or write to system memory. \r
- HostAddress - The system memory address to map to the device.\r
- NumberOfBytes - On input the number of bytes to map. On output the number of bytes\r
- that were mapped.\r
- DeviceAddress - The resulting map address for the bus master device to use to access the\r
- hosts HostAddress.\r
- Mapping - A resulting value to pass to Unmap().\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The range was mapped for the returned NumberOfBytes. \r
- EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined. \r
- EFI_UNSUPPORTED - The HostAddress cannot be mapped as a common buffer.\r
- EFI_DEVICE_ERROR - The system hardware could not map the requested address. \r
- EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- if ((UINT32)Operation > EfiBusMasterCommonBuffer) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (((UINTN) (*HostAddress) != (*HostAddress)) && Operation == EfiBusMasterCommonBuffer) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- Status = Private->PciRootBridgeIo->Map (\r
- Private->PciRootBridgeIo,\r
- (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION) Operation,\r
- (VOID *) (UINTN) (*HostAddress),\r
- NumberOfBytes,\r
- DeviceAddress,\r
- Mapping\r
- );\r
-\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoUnmap (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN VOID *Mapping\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Completes the Map() operation and releases any corresponding resources.\r
-\r
-Arguments:\r
- \r
- This - A pointer to the EFI_DEVICE_IO_INTERFACE instance.\r
- Mapping - The mapping value returned from Map().\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The range was unmapped.\r
- EFI_DEVICE_ERROR - The data was not committed to the target system memory.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- Status = Private->PciRootBridgeIo->Unmap (\r
- Private->PciRootBridgeIo,\r
- Mapping\r
- );\r
-\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoAllocateBuffer (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN EFI_ALLOCATE_TYPE Type,\r
- IN EFI_MEMORY_TYPE MemoryType,\r
- IN UINTN Pages,\r
- IN OUT EFI_PHYSICAL_ADDRESS *PhysicalAddress\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping.\r
-\r
-Arguments:\r
- \r
- This - A pointer to the EFI_DEVICE_IO_INTERFACE instance.\r
- Type - The type allocation to perform.\r
- MemoryType - The type of memory to allocate, EfiBootServicesData or\r
- EfiRuntimeServicesData.\r
- Pages - The number of pages to allocate.\r
- PhysicalAddress - A pointer to store the base address of the allocated range.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The requested memory pages were allocated.\r
- EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r
- EFI_INVALID_PARAMETER - The requested memory type is invalid.\r
- EFI_UNSUPPORTED - The requested PhysicalAddress is not supported on\r
- this platform.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- EFI_PHYSICAL_ADDRESS HostAddress;\r
-\r
- HostAddress = *PhysicalAddress;\r
-\r
- if ((MemoryType != EfiBootServicesData) && (MemoryType != EfiRuntimeServicesData)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if ((UINT32)Type >= MaxAllocateType) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if ((Type == AllocateAddress) && (HostAddress + EFI_PAGES_TO_SIZE (Pages) - 1 > MAX_COMMON_BUFFER)) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- if ((AllocateAnyPages == Type) || (AllocateMaxAddress == Type && HostAddress > MAX_COMMON_BUFFER)) {\r
- Type = AllocateMaxAddress;\r
- HostAddress = MAX_COMMON_BUFFER;\r
- }\r
-\r
- Status = gBS->AllocatePages (\r
- Type,\r
- MemoryType,\r
- Pages,\r
- &HostAddress\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
-\r
- *PhysicalAddress = HostAddress;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoFlush (\r
- IN EFI_DEVICE_IO_PROTOCOL *This\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Flushes any posted write data to the device.\r
-\r
-Arguments:\r
- \r
- This - A pointer to the EFI_DEVICE_IO_INTERFACE instance.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The buffers were flushed.\r
- EFI_DEVICE_ERROR - The buffers were not flushed due to a hardware error.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- DEVICE_IO_PRIVATE_DATA *Private;\r
-\r
- Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
- Status = Private->PciRootBridgeIo->Flush (Private->PciRootBridgeIo);\r
-\r
- return Status;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DeviceIoFreeBuffer (\r
- IN EFI_DEVICE_IO_PROTOCOL *This,\r
- IN UINTN Pages,\r
- IN EFI_PHYSICAL_ADDRESS HostAddress\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Frees pages that were allocated with AllocateBuffer().\r
-\r
-Arguments:\r
- \r
- This - A pointer to the EFI_DEVICE_IO_INTERFACE instance.\r
- Pages - The number of pages to free.\r
- HostAddress - The base address of the range to free.\r
-\r
-Returns:\r
- \r
- EFI_SUCCESS - The requested memory pages were freed.\r
- EFI_NOT_FOUND - The requested memory pages were not allocated with\r
- AllocateBuffer(). \r
- EFI_INVALID_PARAMETER - HostAddress is not page aligned or Pages is invalid.\r
-\r
---*/\r
-{\r
- if (((HostAddress & EFI_PAGE_MASK) != 0) || (Pages <= 0)) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return gBS->FreePages (HostAddress, Pages);\r
-}\r