2 Module produces Device I/O on top of PCI Root Bridge I/O for Segment 0 only.
3 This is a valid assumption because many of the EFI 1.02/EFI 1.10 systems that may have provided
4 Device I/O were single segment platforms. The goal of the ECP is to provide compatibility with the
5 drivers/apps that may have used Device I/O.
7 Device I/O is on list of deprecated protocols for UEFI 2.0 and later.
8 This module module layers Device I/O on top of PCI Root Bridge I/O (Segment 0)
10 There are no R8.x modules present that produces Device I/O
11 EFI drivers included that consume Device I/O
12 Platform required to support EFI drivers that consume Device I/O
13 Platform required to support EFI applications that consume Device I/O
15 Copyright (c) 2008 Intel Corporation. <BR>
16 All rights reserved. This program and the accompanying materials
17 are licensed and made available under the terms and conditions of the BSD License
18 which accompanies this distribution. The full text of the license may be found at
19 http://opensource.org/licenses/bsd-license.php
21 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
27 #include <IndustryStandard/Pci22.h>
28 #include <Protocol/DeviceIo.h>
29 #include <Protocol/PciRootBridgeIo.h>
30 #include <Library/BaseLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/UefiLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/DevicePathLib.h>
41 Perform reading memory mapped I/O space of device.
43 @param This A pointer to EFI_DEVICE_IO protocol instance.
44 @param Width Width of I/O operations.
45 @param Address The base address of I/O operations.
46 @param Count The number of I/O operations to perform. Bytes
47 moves is Width size * Count, starting at Address.
48 @param Buffer The destination buffer to store results.
50 @retval EFI_SUCCESS The data was read from the device.
51 @retval EFI_INVALID_PARAMETER Width is invalid.
52 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
59 IN EFI_DEVICE_IO_PROTOCOL
*This
,
60 IN EFI_IO_WIDTH Width
,
68 Perform writing memory mapped I/O space of device.
70 @param This A pointer to EFI_DEVICE_IO protocol instance.
71 @param Width Width of I/O operations.
72 @param Address The base address of I/O operations.
73 @param Count The number of I/O operations to perform. Bytes
74 moves is Width size * Count, starting at Address.
75 @param Buffer The source buffer of data to be written.
77 @retval EFI_SUCCESS The data was written to the device.
78 @retval EFI_INVALID_PARAMETER Width is invalid.
79 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
86 IN EFI_DEVICE_IO_PROTOCOL
*This
,
87 IN EFI_IO_WIDTH Width
,
94 Perform reading I/O space of device.
96 @param This A pointer to EFI_DEVICE_IO protocol instance.
97 @param Width Width of I/O operations.
98 @param Address The base address of I/O operations.
99 @param Count The number of I/O operations to perform. Bytes
100 moves is Width size * Count, starting at Address.
101 @param Buffer The destination buffer to store results.
103 @retval EFI_SUCCESS The data was read from the device.
104 @retval EFI_INVALID_PARAMETER Width is invalid.
105 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
112 IN EFI_DEVICE_IO_PROTOCOL
*This
,
113 IN EFI_IO_WIDTH Width
,
120 Perform writing I/O space of device.
122 @param This A pointer to EFI_DEVICE_IO protocol instance.
123 @param Width Width of I/O operations.
124 @param Address The base address of I/O operations.
125 @param Count The number of I/O operations to perform. Bytes
126 moves is Width size * Count, starting at Address.
127 @param Buffer The source buffer of data to be written.
129 @retval EFI_SUCCESS The data was written to the device.
130 @retval EFI_INVALID_PARAMETER Width is invalid.
131 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
138 IN EFI_DEVICE_IO_PROTOCOL
*This
,
139 IN EFI_IO_WIDTH Width
,
146 Perform reading PCI configuration space of device
148 @param This A pointer to EFI_DEVICE_IO protocol instance.
149 @param Width Width of I/O operations.
150 @param Address The base address of I/O operations.
151 @param Count The number of I/O operations to perform. Bytes
152 moves is Width size * Count, starting at Address.
153 @param Buffer The destination buffer to store results.
155 @retval EFI_SUCCESS The data was read from the device.
156 @retval EFI_INVALID_PARAMETER Width is invalid.
157 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
164 IN EFI_DEVICE_IO_PROTOCOL
*This
,
165 IN EFI_IO_WIDTH Width
,
172 Perform writing PCI configuration space of device.
174 @param This A pointer to EFI_DEVICE_IO protocol instance.
175 @param Width Width of I/O operations.
176 @param Address The base address of I/O operations.
177 @param Count The number of I/O operations to perform. Bytes
178 moves is Width size * Count, starting at Address.
179 @param Buffer The source buffer of data to be written.
181 @retval EFI_SUCCESS The data was written to the device.
182 @retval EFI_INVALID_PARAMETER Width is invalid.
183 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
190 IN EFI_DEVICE_IO_PROTOCOL
*This
,
191 IN EFI_IO_WIDTH Width
,
198 Provides an EFI Device Path for a PCI device with the given PCI configuration space address.
200 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
201 @param Address The PCI configuration space address of the device
202 whose Device Path is going to be returned.
203 @param PciDevicePath A pointer to the pointer for the EFI Device Path
204 for PciAddress. Memory for the Device Path is
205 allocated from the pool.
207 @retval EFI_SUCCESS The PciDevicePath returns a pointer to a valid EFI
209 @retval EFI_UNSUPPORTED The PciAddress does not map to a valid EFI Device
211 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
217 DeviceIoPciDevicePath (
218 IN EFI_DEVICE_IO_PROTOCOL
*This
,
220 IN OUT EFI_DEVICE_PATH_PROTOCOL
**PciDevicePath
224 Provides the device-specific addresses needed to access system memory.
226 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
227 @param Operation Indicates if the bus master is going to read or
228 write to system memory.
229 @param HostAddress The system memory address to map to the device.
230 @param NumberOfBytes On input the number of bytes to map. On output the
231 number of bytes that were mapped.
232 @param DeviceAddress The resulting map address for the bus master
233 device to use to access the hosts HostAddress.
234 @param Mapping A resulting value to pass to Unmap().
236 @retval EFI_SUCCESS The range was mapped for the returned
238 @retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.
239 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common
241 @retval EFI_DEVICE_ERROR The system hardware could not map the requested
243 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
250 IN EFI_DEVICE_IO_PROTOCOL
*This
,
251 IN EFI_IO_OPERATION_TYPE Operation
,
252 IN EFI_PHYSICAL_ADDRESS
*HostAddress
,
253 IN OUT UINTN
*NumberOfBytes
,
254 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
259 Completes the Map() operation and releases any corresponding resources.
261 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
262 @param Mapping The mapping value returned from Map().
264 @retval EFI_SUCCESS The range was unmapped.
265 @retval EFI_DEVICE_ERROR The data was not committed to the target system
272 IN EFI_DEVICE_IO_PROTOCOL
*This
,
277 Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping.
279 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
280 @param Type The type allocation to perform.
281 @param MemoryType The type of memory to allocate,
282 EfiBootServicesData or EfiRuntimeServicesData.
283 @param Pages The number of pages to allocate.
284 @param PhysicalAddress A pointer to store the base address of the
287 @retval EFI_SUCCESS The requested memory pages were allocated.
288 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
289 @retval EFI_INVALID_PARAMETER The requested memory type is invalid.
290 @retval EFI_UNSUPPORTED The requested PhysicalAddress is not supported on
296 DeviceIoAllocateBuffer (
297 IN EFI_DEVICE_IO_PROTOCOL
*This
,
298 IN EFI_ALLOCATE_TYPE Type
,
299 IN EFI_MEMORY_TYPE MemoryType
,
301 IN OUT EFI_PHYSICAL_ADDRESS
*PhysicalAddress
305 Flushes any posted write data to the device.
307 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
309 @retval EFI_SUCCESS The buffers were flushed.
310 @retval EFI_DEVICE_ERROR The buffers were not flushed due to a hardware
317 IN EFI_DEVICE_IO_PROTOCOL
*This
321 Frees pages that were allocated with AllocateBuffer().
323 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
324 @param Pages The number of pages to free.
325 @param HostAddress The base address of the range to free.
327 @retval EFI_SUCCESS The requested memory pages were freed.
328 @retval EFI_NOT_FOUND The requested memory pages were not allocated with
330 @retval EFI_INVALID_PARAMETER HostAddress is not page aligned or Pages is
337 IN EFI_DEVICE_IO_PROTOCOL
*This
,
339 IN EFI_PHYSICAL_ADDRESS HostAddress
343 #define DEVICE_IO_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('D', 'e', 'I', 'O')
347 EFI_DEVICE_IO_PROTOCOL DeviceIo
;
348 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
349 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
351 UINT16 SubordinateBus
;
352 } DEVICE_IO_PRIVATE_DATA
;
354 #define DEVICE_IO_PRIVATE_DATA_FROM_THIS(a) CR (a, DEVICE_IO_PRIVATE_DATA, DeviceIo, DEVICE_IO_PRIVATE_DATA_SIGNATURE)
356 #define MAX_COMMON_BUFFER 0x00000000FFFFFFFF
359 EFI_EVENT mPciRootBridgeIoRegistration
;
362 // Device Io Volume Protocol template
364 DEVICE_IO_PRIVATE_DATA gDeviceIoPrivateDataTemplate
= {
365 DEVICE_IO_PRIVATE_DATA_SIGNATURE
,
380 DeviceIoPciDevicePath
,
382 DeviceIoAllocateBuffer
,
386 NULL
, // PciRootBridgeIo
389 255 // SubordinateBus
394 PciRootBridgeIoNotificationEvent (
402 DEVICE_IO_PRIVATE_DATA
*Private
;
403 EFI_DEVICE_IO_PROTOCOL
*DeviceIo
;
404 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
407 BufferSize
= sizeof (Handle
);
408 Status
= gBS
->LocateHandle (
410 &gEfiPciRootBridgeIoProtocolGuid
,
411 mPciRootBridgeIoRegistration
,
415 if (EFI_ERROR (Status
)) {
417 // Exit Path of While Loop....
423 // Skip this handle if the Device Io Protocol is already installed
425 Status
= gBS
->HandleProtocol (
427 &gEfiDeviceIoProtocolGuid
,
430 if (!EFI_ERROR (Status
)) {
435 // Retrieve the Pci Root Bridge IO Protocol
437 Status
= gBS
->HandleProtocol (
439 &gEfiPciRootBridgeIoProtocolGuid
,
440 (VOID
**)&PciRootBridgeIo
442 ASSERT_EFI_ERROR (Status
);
445 // We only install Device IO for PCI bus in Segment 0.
446 // See the file description at @file for details.
448 if (PciRootBridgeIo
->SegmentNumber
!= 0) {
453 // Allocate private data structure
455 Private
= AllocateCopyPool (sizeof (DEVICE_IO_PRIVATE_DATA
), &gDeviceIoPrivateDataTemplate
);
456 if (Private
== NULL
) {
460 Status
= gBS
->HandleProtocol (
462 &gEfiDevicePathProtocolGuid
,
463 (VOID
**) &Private
->DevicePath
467 // Install Device Io onto same handle
469 Status
= gBS
->InstallMultipleProtocolInterfaces (
471 &gEfiDeviceIoProtocolGuid
,
475 ASSERT_EFI_ERROR (Status
);
480 The user Entry Point for DXE driver. The user code starts with this function
481 as the real entry point for the image goes into a library that calls this
484 @param[in] ImageHandle The firmware allocated handle for the EFI image.
485 @param[in] SystemTable A pointer to the EFI System Table.
487 @retval EFI_SUCCESS The entry point is executed successfully.
488 @retval other Some error occurs when executing this entry point.
494 IN EFI_HANDLE ImageHandle
,
495 IN EFI_SYSTEM_TABLE
*SystemTable
498 EfiCreateProtocolNotifyEvent (
499 &gEfiPciRootBridgeIoProtocolGuid
,
501 PciRootBridgeIoNotificationEvent
,
503 &mPciRootBridgeIoRegistration
510 Perform reading memory mapped I/O space of device.
512 @param This A pointer to EFI_DEVICE_IO protocol instance.
513 @param Width Width of I/O operations.
514 @param Address The base address of I/O operations.
515 @param Count The number of I/O operations to perform. Bytes
516 moves is Width size * Count, starting at Address.
517 @param Buffer The destination buffer to store results.
519 @retval EFI_SUCCESS The data was read from the device.
520 @retval EFI_INVALID_PARAMETER Width is invalid.
521 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
528 IN EFI_DEVICE_IO_PROTOCOL
*This
,
529 IN EFI_IO_WIDTH Width
,
536 DEVICE_IO_PRIVATE_DATA
*Private
;
538 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
540 if (Width
> MMIO_COPY_UINT64
) {
541 return EFI_INVALID_PARAMETER
;
543 if (Width
>= MMIO_COPY_UINT8
) {
544 Width
= Width
- MMIO_COPY_UINT8
;
545 Status
= Private
->PciRootBridgeIo
->CopyMem (
546 Private
->PciRootBridgeIo
,
547 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
548 (UINT64
) (UINTN
) Buffer
,
553 Status
= Private
->PciRootBridgeIo
->Mem
.Read (
554 Private
->PciRootBridgeIo
,
555 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
569 Perform writing memory mapped I/O space of device.
571 @param This A pointer to EFI_DEVICE_IO protocol instance.
572 @param Width Width of I/O operations.
573 @param Address The base address of I/O operations.
574 @param Count The number of I/O operations to perform. Bytes
575 moves is Width size * Count, starting at Address.
576 @param Buffer The source buffer of data to be written.
578 @retval EFI_SUCCESS The data was written to the device.
579 @retval EFI_INVALID_PARAMETER Width is invalid.
580 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
587 IN EFI_DEVICE_IO_PROTOCOL
*This
,
588 IN EFI_IO_WIDTH Width
,
595 DEVICE_IO_PRIVATE_DATA
*Private
;
597 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
599 if (Width
> MMIO_COPY_UINT64
) {
600 return EFI_INVALID_PARAMETER
;
602 if (Width
>= MMIO_COPY_UINT8
) {
603 Width
= Width
- MMIO_COPY_UINT8
;
604 Status
= Private
->PciRootBridgeIo
->CopyMem (
605 Private
->PciRootBridgeIo
,
606 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
608 (UINT64
) (UINTN
) Buffer
,
612 Status
= Private
->PciRootBridgeIo
->Mem
.Write (
613 Private
->PciRootBridgeIo
,
614 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
626 Perform reading I/O space of device.
628 @param This A pointer to EFI_DEVICE_IO protocol instance.
629 @param Width Width of I/O operations.
630 @param Address The base address of I/O operations.
631 @param Count The number of I/O operations to perform. Bytes
632 moves is Width size * Count, starting at Address.
633 @param Buffer The destination buffer to store results.
635 @retval EFI_SUCCESS The data was read from the device.
636 @retval EFI_INVALID_PARAMETER Width is invalid.
637 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
644 IN EFI_DEVICE_IO_PROTOCOL
*This
,
645 IN EFI_IO_WIDTH Width
,
652 DEVICE_IO_PRIVATE_DATA
*Private
;
654 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
656 if (Width
>= MMIO_COPY_UINT8
) {
657 return EFI_INVALID_PARAMETER
;
660 Status
= Private
->PciRootBridgeIo
->Io
.Read (
661 Private
->PciRootBridgeIo
,
662 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
673 Perform writing I/O space of device.
675 @param This A pointer to EFI_DEVICE_IO protocol instance.
676 @param Width Width of I/O operations.
677 @param Address The base address of I/O operations.
678 @param Count The number of I/O operations to perform. Bytes
679 moves is Width size * Count, starting at Address.
680 @param Buffer The source buffer of data to be written.
682 @retval EFI_SUCCESS The data was written to the device.
683 @retval EFI_INVALID_PARAMETER Width is invalid.
684 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
691 IN EFI_DEVICE_IO_PROTOCOL
*This
,
692 IN EFI_IO_WIDTH Width
,
699 DEVICE_IO_PRIVATE_DATA
*Private
;
701 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
703 if (Width
>= MMIO_COPY_UINT8
) {
704 return EFI_INVALID_PARAMETER
;
707 Status
= Private
->PciRootBridgeIo
->Io
.Write (
708 Private
->PciRootBridgeIo
,
709 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
720 Perform reading PCI configuration space of device
722 @param This A pointer to EFI_DEVICE_IO protocol instance.
723 @param Width Width of I/O operations.
724 @param Address The base address of I/O operations.
725 @param Count The number of I/O operations to perform. Bytes
726 moves is Width size * Count, starting at Address.
727 @param Buffer The destination buffer to store results.
729 @retval EFI_SUCCESS The data was read from the device.
730 @retval EFI_INVALID_PARAMETER Width is invalid.
731 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
738 IN EFI_DEVICE_IO_PROTOCOL
*This
,
739 IN EFI_IO_WIDTH Width
,
746 DEVICE_IO_PRIVATE_DATA
*Private
;
748 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
750 if (Width
< 0 || Width
>= MMIO_COPY_UINT8
) {
751 return EFI_INVALID_PARAMETER
;
754 Status
= Private
->PciRootBridgeIo
->Pci
.Read (
755 Private
->PciRootBridgeIo
,
756 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
767 Perform writing PCI configuration space of device.
769 @param This A pointer to EFI_DEVICE_IO protocol instance.
770 @param Width Width of I/O operations.
771 @param Address The base address of I/O operations.
772 @param Count The number of I/O operations to perform. Bytes
773 moves is Width size * Count, starting at Address.
774 @param Buffer The source buffer of data to be written.
776 @retval EFI_SUCCESS The data was written to the device.
777 @retval EFI_INVALID_PARAMETER Width is invalid.
778 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
785 IN EFI_DEVICE_IO_PROTOCOL
*This
,
786 IN EFI_IO_WIDTH Width
,
793 DEVICE_IO_PRIVATE_DATA
*Private
;
795 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
797 if (Width
< 0 || Width
>= MMIO_COPY_UINT8
) {
798 return EFI_INVALID_PARAMETER
;
801 Status
= Private
->PciRootBridgeIo
->Pci
.Write (
802 Private
->PciRootBridgeIo
,
803 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) Width
,
814 Append a PCI device path node to another device path.
816 @param Private A pointer to DEVICE_IO_PRIVATE_DATA instance.
817 @param Bus PCI bus number of the device.
818 @param Device PCI device number of the device.
819 @param Function PCI function number of the device.
820 @param DevicePath Original device path which will be appended a PCI
822 @param BridgePrimaryBus Primary bus number of the bridge.
823 @param BridgeSubordinateBus Subordinate bus number of the bridge.
825 @return Pointer to the appended PCI device path.
828 EFI_DEVICE_PATH_PROTOCOL
*
829 AppendPciDevicePath (
830 IN DEVICE_IO_PRIVATE_DATA
*Private
,
834 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
835 IN OUT UINT16
*BridgePrimaryBus
,
836 IN OUT UINT16
*BridgeSubordinateBus
843 PCI_TYPE01 PciBridge
;
845 EFI_DEVICE_PATH_PROTOCOL
*ReturnDevicePath
;
846 PCI_DEVICE_PATH PciNode
;
849 for (ThisBus
= *BridgePrimaryBus
; ThisBus
<= *BridgeSubordinateBus
; ThisBus
++) {
850 for (ThisDevice
= 0; ThisDevice
<= PCI_MAX_DEVICE
; ThisDevice
++) {
851 for (ThisFunc
= 0; ThisFunc
<= PCI_MAX_FUNC
; ThisFunc
++) {
852 Address
= EFI_PCI_ADDRESS (ThisBus
, ThisDevice
, ThisFunc
, 0);
853 ZeroMem (PciPtr
, sizeof (PCI_TYPE01
));
854 Private
->DeviceIo
.Pci
.Read (
859 &(PciPtr
->Hdr
.VendorId
)
861 if ((PciPtr
->Hdr
.VendorId
== 0xffff) && (ThisFunc
== 0)) {
864 if (PciPtr
->Hdr
.VendorId
== 0xffff) {
867 Private
->DeviceIo
.Pci
.Read (
871 sizeof (PCI_TYPE01
) / sizeof (UINT32
),
874 if (IS_PCI_BRIDGE (PciPtr
)) {
875 if (Bus
>= PciPtr
->Bridge
.SecondaryBus
&& Bus
<= PciPtr
->Bridge
.SubordinateBus
) {
877 PciNode
.Header
.Type
= HARDWARE_DEVICE_PATH
;
878 PciNode
.Header
.SubType
= HW_PCI_DP
;
879 SetDevicePathNodeLength (&PciNode
.Header
, sizeof (PciNode
));
881 PciNode
.Device
= ThisDevice
;
882 PciNode
.Function
= ThisFunc
;
883 ReturnDevicePath
= AppendDevicePathNode (DevicePath
, &PciNode
.Header
);
885 *BridgePrimaryBus
= PciPtr
->Bridge
.SecondaryBus
;
886 *BridgeSubordinateBus
= PciPtr
->Bridge
.SubordinateBus
;
887 return ReturnDevicePath
;
890 if (ThisFunc
== 0 && !(PciPtr
->Hdr
.HeaderType
& HEADER_TYPE_MULTI_FUNCTION
)) {
892 // Skip sub functions, this is not a multi function device
901 ZeroMem (&PciNode
, sizeof (PciNode
));
902 PciNode
.Header
.Type
= HARDWARE_DEVICE_PATH
;
903 PciNode
.Header
.SubType
= HW_PCI_DP
;
904 SetDevicePathNodeLength (&PciNode
.Header
, sizeof (PciNode
));
905 PciNode
.Device
= Device
;
906 PciNode
.Function
= Function
;
908 ReturnDevicePath
= AppendDevicePathNode (DevicePath
, &PciNode
.Header
);
910 *BridgePrimaryBus
= 0xffff;
911 *BridgeSubordinateBus
= 0xffff;
912 return ReturnDevicePath
;
917 Provides an EFI Device Path for a PCI device with the given PCI configuration space address.
919 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
920 @param Address The PCI configuration space address of the device
921 whose Device Path is going to be returned.
922 @param PciDevicePath A pointer to the pointer for the EFI Device Path
923 for PciAddress. Memory for the Device Path is
924 allocated from the pool.
926 @retval EFI_SUCCESS The PciDevicePath returns a pointer to a valid EFI
928 @retval EFI_UNSUPPORTED The PciAddress does not map to a valid EFI Device
930 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
936 DeviceIoPciDevicePath (
937 IN EFI_DEVICE_IO_PROTOCOL
*This
,
939 IN OUT EFI_DEVICE_PATH_PROTOCOL
**PciDevicePath
942 DEVICE_IO_PRIVATE_DATA
*Private
;
944 UINT16 SubordinateBus
;
949 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
951 Bus
= (UINT8
) (((UINT32
) Address
>> 24) & 0xff);
952 Device
= (UINT8
) (((UINT32
) Address
>> 16) & 0xff);
953 Func
= (UINT8
) (((UINT32
) Address
>> 8) & 0xff);
955 if (Bus
< Private
->PrimaryBus
|| Bus
> Private
->SubordinateBus
) {
956 return EFI_UNSUPPORTED
;
959 *PciDevicePath
= Private
->DevicePath
;
960 PrimaryBus
= Private
->PrimaryBus
;
961 SubordinateBus
= Private
->SubordinateBus
;
963 *PciDevicePath
= AppendPciDevicePath (
972 if (*PciDevicePath
== NULL
) {
973 return EFI_OUT_OF_RESOURCES
;
975 } while (PrimaryBus
!= 0xffff);
982 Provides the device-specific addresses needed to access system memory.
984 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
985 @param Operation Indicates if the bus master is going to read or
986 write to system memory.
987 @param HostAddress The system memory address to map to the device.
988 @param NumberOfBytes On input the number of bytes to map. On output the
989 number of bytes that were mapped.
990 @param DeviceAddress The resulting map address for the bus master
991 device to use to access the hosts HostAddress.
992 @param Mapping A resulting value to pass to Unmap().
994 @retval EFI_SUCCESS The range was mapped for the returned
996 @retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.
997 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common
999 @retval EFI_DEVICE_ERROR The system hardware could not map the requested
1001 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
1008 IN EFI_DEVICE_IO_PROTOCOL
*This
,
1009 IN EFI_IO_OPERATION_TYPE Operation
,
1010 IN EFI_PHYSICAL_ADDRESS
*HostAddress
,
1011 IN OUT UINTN
*NumberOfBytes
,
1012 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
,
1017 DEVICE_IO_PRIVATE_DATA
*Private
;
1019 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
1021 if (Operation
< 0 || Operation
> EfiBusMasterCommonBuffer
) {
1022 return EFI_INVALID_PARAMETER
;
1025 if (((UINTN
) (*HostAddress
) != (*HostAddress
)) && Operation
== EfiBusMasterCommonBuffer
) {
1026 return EFI_UNSUPPORTED
;
1029 Status
= Private
->PciRootBridgeIo
->Map (
1030 Private
->PciRootBridgeIo
,
1031 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION
) Operation
,
1032 (VOID
*) (UINTN
) (*HostAddress
),
1043 Completes the Map() operation and releases any corresponding resources.
1045 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
1046 @param Mapping The mapping value returned from Map().
1048 @retval EFI_SUCCESS The range was unmapped.
1049 @retval EFI_DEVICE_ERROR The data was not committed to the target system
1056 IN EFI_DEVICE_IO_PROTOCOL
*This
,
1061 DEVICE_IO_PRIVATE_DATA
*Private
;
1063 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
1065 Status
= Private
->PciRootBridgeIo
->Unmap (
1066 Private
->PciRootBridgeIo
,
1075 Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping.
1077 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
1078 @param Type The type allocation to perform.
1079 @param MemoryType The type of memory to allocate,
1080 EfiBootServicesData or EfiRuntimeServicesData.
1081 @param Pages The number of pages to allocate.
1082 @param PhysicalAddress A pointer to store the base address of the
1085 @retval EFI_SUCCESS The requested memory pages were allocated.
1086 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
1087 @retval EFI_INVALID_PARAMETER The requested memory type is invalid.
1088 @retval EFI_UNSUPPORTED The requested PhysicalAddress is not supported on
1094 DeviceIoAllocateBuffer (
1095 IN EFI_DEVICE_IO_PROTOCOL
*This
,
1096 IN EFI_ALLOCATE_TYPE Type
,
1097 IN EFI_MEMORY_TYPE MemoryType
,
1099 IN OUT EFI_PHYSICAL_ADDRESS
*PhysicalAddress
1103 EFI_PHYSICAL_ADDRESS HostAddress
;
1104 DEVICE_IO_PRIVATE_DATA
*Private
;
1107 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
1109 HostAddress
= *PhysicalAddress
;
1111 if ((MemoryType
!= EfiBootServicesData
) && (MemoryType
!= EfiRuntimeServicesData
)) {
1112 return EFI_INVALID_PARAMETER
;
1115 if ((Type
>= MaxAllocateType
) || (Type
< AllocateAnyPages
)) {
1116 return EFI_INVALID_PARAMETER
;
1119 if ((Type
== AllocateAddress
) && (HostAddress
+ EFI_PAGES_TO_SIZE (Pages
) - 1 > MAX_COMMON_BUFFER
)) {
1120 return EFI_UNSUPPORTED
;
1123 if ((AllocateAnyPages
== Type
) || (AllocateMaxAddress
== Type
&& HostAddress
> MAX_COMMON_BUFFER
)) {
1124 Type
= AllocateMaxAddress
;
1125 HostAddress
= MAX_COMMON_BUFFER
;
1128 HostAddress2
= (VOID
*) (UINTN
) (HostAddress
);
1129 Status
= Private
->PciRootBridgeIo
->AllocateBuffer (
1130 Private
->PciRootBridgeIo
,
1135 EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE
|
1136 EFI_PCI_ATTRIBUTE_MEMORY_CACHED
1139 if (EFI_ERROR (Status
)) {
1144 *PhysicalAddress
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) HostAddress2
;
1151 Flushes any posted write data to the device.
1153 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
1155 @retval EFI_SUCCESS The buffers were flushed.
1156 @retval EFI_DEVICE_ERROR The buffers were not flushed due to a hardware
1163 IN EFI_DEVICE_IO_PROTOCOL
*This
1167 DEVICE_IO_PRIVATE_DATA
*Private
;
1169 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
1171 Status
= Private
->PciRootBridgeIo
->Flush (Private
->PciRootBridgeIo
);
1178 Frees pages that were allocated with AllocateBuffer().
1180 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
1181 @param Pages The number of pages to free.
1182 @param HostAddress The base address of the range to free.
1184 @retval EFI_SUCCESS The requested memory pages were freed.
1185 @retval EFI_NOT_FOUND The requested memory pages were not allocated with
1187 @retval EFI_INVALID_PARAMETER HostAddress is not page aligned or Pages is
1193 DeviceIoFreeBuffer (
1194 IN EFI_DEVICE_IO_PROTOCOL
*This
,
1196 IN EFI_PHYSICAL_ADDRESS HostAddress
1199 DEVICE_IO_PRIVATE_DATA
*Private
;
1201 Private
= DEVICE_IO_PRIVATE_DATA_FROM_THIS (This
);
1203 if (((HostAddress
& EFI_PAGE_MASK
) != 0) || (Pages
<= 0)) {
1204 return EFI_INVALID_PARAMETER
;
1207 return Private
->PciRootBridgeIo
->FreeBuffer (
1208 Private
->PciRootBridgeIo
,
1210 (VOID
*) (UINTN
) HostAddress