2 Module produces Device I/O on top of PCI Root Bridge I/O for Segment 0 only.
\r
3 This is a valid assumption because many of the EFI 1.02/EFI 1.10 systems that may have provided
\r
4 Device I/O were single segment platforms. The goal of the ECP is to provide compatibility with the
\r
5 drivers/apps that may have used Device I/O.
\r
7 Device I/O is on list of deprecated protocols for UEFI 2.0 and later.
\r
8 This module module layers Device I/O on top of PCI Root Bridge I/O (Segment 0)
\r
10 There are no R8.x modules present that produces Device I/O
\r
11 EFI drivers included that consume Device I/O
\r
12 Platform required to support EFI drivers that consume Device I/O
\r
13 Platform required to support EFI applications that consume Device I/O
\r
15 Copyright (c) 2008 Intel Corporation. <BR>
\r
16 All rights reserved. This program and the accompanying materials
\r
17 are licensed and made available under the terms and conditions of the BSD License
\r
18 which accompanies this distribution. The full text of the license may be found at
\r
19 http://opensource.org/licenses/bsd-license.php
\r
21 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
27 #include <IndustryStandard/Pci22.h>
\r
28 #include <Protocol/DeviceIo.h>
\r
29 #include <Protocol/PciRootBridgeIo.h>
\r
30 #include <Library/BaseLib.h>
\r
31 #include <Library/BaseMemoryLib.h>
\r
32 #include <Library/DebugLib.h>
\r
33 #include <Library/UefiBootServicesTableLib.h>
\r
34 #include <Library/UefiDriverEntryPoint.h>
\r
35 #include <Library/UefiLib.h>
\r
36 #include <Library/MemoryAllocationLib.h>
\r
37 #include <Library/DevicePathLib.h>
\r
41 Perform reading memory mapped I/O space of device.
\r
43 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
44 @param Width Width of I/O operations.
\r
45 @param Address The base address of I/O operations.
\r
46 @param Count The number of I/O operations to perform. Bytes
\r
47 moves is Width size * Count, starting at Address.
\r
48 @param Buffer The destination buffer to store results.
\r
50 @retval EFI_SUCCESS The data was read from the device.
\r
51 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
52 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
59 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
60 IN EFI_IO_WIDTH Width,
\r
69 Perform writing memory mapped I/O space of device.
\r
71 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
72 @param Width Width of I/O operations.
\r
73 @param Address The base address of I/O operations.
\r
74 @param Count The number of I/O operations to perform. Bytes
\r
75 moves is Width size * Count, starting at Address.
\r
76 @param Buffer The source buffer of data to be written.
\r
78 @retval EFI_SUCCESS The data was written to the device.
\r
79 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
80 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
87 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
88 IN EFI_IO_WIDTH Width,
\r
96 Perform reading I/O space of device.
\r
98 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
99 @param Width Width of I/O operations.
\r
100 @param Address The base address of I/O operations.
\r
101 @param Count The number of I/O operations to perform. Bytes
\r
102 moves is Width size * Count, starting at Address.
\r
103 @param Buffer The destination buffer to store results.
\r
105 @retval EFI_SUCCESS The data was read from the device.
\r
106 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
107 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
114 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
115 IN EFI_IO_WIDTH Width,
\r
118 IN OUT VOID *Buffer
\r
123 Perform writing I/O space of device.
\r
125 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
126 @param Width Width of I/O operations.
\r
127 @param Address The base address of I/O operations.
\r
128 @param Count The number of I/O operations to perform. Bytes
\r
129 moves is Width size * Count, starting at Address.
\r
130 @param Buffer The source buffer of data to be written.
\r
132 @retval EFI_SUCCESS The data was written to the device.
\r
133 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
134 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
141 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
142 IN EFI_IO_WIDTH Width,
\r
145 IN OUT VOID *Buffer
\r
150 Perform reading PCI configuration space of device
\r
152 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
153 @param Width Width of I/O operations.
\r
154 @param Address The base address of I/O operations.
\r
155 @param Count The number of I/O operations to perform. Bytes
\r
156 moves is Width size * Count, starting at Address.
\r
157 @param Buffer The destination buffer to store results.
\r
159 @retval EFI_SUCCESS The data was read from the device.
\r
160 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
161 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
168 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
169 IN EFI_IO_WIDTH Width,
\r
172 IN OUT VOID *Buffer
\r
177 Perform writing PCI configuration space of device.
\r
179 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
180 @param Width Width of I/O operations.
\r
181 @param Address The base address of I/O operations.
\r
182 @param Count The number of I/O operations to perform. Bytes
\r
183 moves is Width size * Count, starting at Address.
\r
184 @param Buffer The source buffer of data to be written.
\r
186 @retval EFI_SUCCESS The data was written to the device.
\r
187 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
188 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
195 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
196 IN EFI_IO_WIDTH Width,
\r
199 IN OUT VOID *Buffer
\r
204 Provides an EFI Device Path for a PCI device with the given PCI configuration space address.
\r
206 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
207 @param Address The PCI configuration space address of the device
\r
208 whose Device Path is going to be returned.
\r
209 @param PciDevicePath A pointer to the pointer for the EFI Device Path
\r
210 for PciAddress. Memory for the Device Path is
\r
211 allocated from the pool.
\r
213 @retval EFI_SUCCESS The PciDevicePath returns a pointer to a valid EFI
\r
215 @retval EFI_UNSUPPORTED The PciAddress does not map to a valid EFI Device
\r
217 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
\r
223 DeviceIoPciDevicePath (
\r
224 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
226 IN OUT EFI_DEVICE_PATH_PROTOCOL **PciDevicePath
\r
231 Provides the device-specific addresses needed to access system memory.
\r
233 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
234 @param Operation Indicates if the bus master is going to read or
\r
235 write to system memory.
\r
236 @param HostAddress The system memory address to map to the device.
\r
237 @param NumberOfBytes On input the number of bytes to map. On output the
\r
238 number of bytes that were mapped.
\r
239 @param DeviceAddress The resulting map address for the bus master
\r
240 device to use to access the hosts HostAddress.
\r
241 @param Mapping A resulting value to pass to Unmap().
\r
243 @retval EFI_SUCCESS The range was mapped for the returned
\r
245 @retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.
\r
246 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common
\r
248 @retval EFI_DEVICE_ERROR The system hardware could not map the requested
\r
250 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
\r
257 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
258 IN EFI_IO_OPERATION_TYPE Operation,
\r
259 IN EFI_PHYSICAL_ADDRESS *HostAddress,
\r
260 IN OUT UINTN *NumberOfBytes,
\r
261 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
\r
267 Completes the Map() operation and releases any corresponding resources.
\r
269 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
270 @param Mapping The mapping value returned from Map().
\r
272 @retval EFI_SUCCESS The range was unmapped.
\r
273 @retval EFI_DEVICE_ERROR The data was not committed to the target system
\r
280 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
286 Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping.
\r
288 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
289 @param Type The type allocation to perform.
\r
290 @param MemoryType The type of memory to allocate,
\r
291 EfiBootServicesData or EfiRuntimeServicesData.
\r
292 @param Pages The number of pages to allocate.
\r
293 @param PhysicalAddress A pointer to store the base address of the
\r
296 @retval EFI_SUCCESS The requested memory pages were allocated.
\r
297 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
\r
298 @retval EFI_INVALID_PARAMETER The requested memory type is invalid.
\r
299 @retval EFI_UNSUPPORTED The requested PhysicalAddress is not supported on
\r
305 DeviceIoAllocateBuffer (
\r
306 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
307 IN EFI_ALLOCATE_TYPE Type,
\r
308 IN EFI_MEMORY_TYPE MemoryType,
\r
310 IN OUT EFI_PHYSICAL_ADDRESS *PhysicalAddress
\r
315 Flushes any posted write data to the device.
\r
317 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
319 @retval EFI_SUCCESS The buffers were flushed.
\r
320 @retval EFI_DEVICE_ERROR The buffers were not flushed due to a hardware
\r
327 IN EFI_DEVICE_IO_PROTOCOL *This
\r
332 Frees pages that were allocated with AllocateBuffer().
\r
334 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
335 @param Pages The number of pages to free.
\r
336 @param HostAddress The base address of the range to free.
\r
338 @retval EFI_SUCCESS The requested memory pages were freed.
\r
339 @retval EFI_NOT_FOUND The requested memory pages were not allocated with
\r
341 @retval EFI_INVALID_PARAMETER HostAddress is not page aligned or Pages is
\r
347 DeviceIoFreeBuffer (
\r
348 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
350 IN EFI_PHYSICAL_ADDRESS HostAddress
\r
355 #define DEVICE_IO_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('D', 'e', 'I', 'O')
\r
359 EFI_DEVICE_IO_PROTOCOL DeviceIo;
\r
360 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
\r
361 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
\r
363 UINT16 SubordinateBus;
\r
364 } DEVICE_IO_PRIVATE_DATA;
\r
366 #define DEVICE_IO_PRIVATE_DATA_FROM_THIS(a) CR (a, DEVICE_IO_PRIVATE_DATA, DeviceIo, DEVICE_IO_PRIVATE_DATA_SIGNATURE)
\r
368 #define MAX_COMMON_BUFFER 0x00000000FFFFFFFF
\r
371 EFI_EVENT mPciRootBridgeIoRegistration;
\r
374 // Device Io Volume Protocol template
\r
376 DEVICE_IO_PRIVATE_DATA gDeviceIoPrivateDataTemplate = {
\r
377 DEVICE_IO_PRIVATE_DATA_SIGNATURE,
\r
392 DeviceIoPciDevicePath,
\r
394 DeviceIoAllocateBuffer,
\r
398 NULL, // PciRootBridgeIo
\r
399 NULL, // DevicePath
\r
401 255 // SubordinateBus
\r
406 PciRootBridgeIoNotificationEvent (
\r
407 IN EFI_EVENT Event,
\r
414 DEVICE_IO_PRIVATE_DATA *Private;
\r
415 EFI_DEVICE_IO_PROTOCOL *DeviceIo;
\r
416 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
\r
419 BufferSize = sizeof (Handle);
\r
420 Status = gBS->LocateHandle (
\r
422 &gEfiPciRootBridgeIoProtocolGuid,
\r
423 mPciRootBridgeIoRegistration,
\r
427 if (EFI_ERROR (Status)) {
\r
429 // Exit Path of While Loop....
\r
435 // Skip this handle if the Device Io Protocol is already installed
\r
437 Status = gBS->HandleProtocol (
\r
439 &gEfiDeviceIoProtocolGuid,
\r
442 if (!EFI_ERROR (Status)) {
\r
447 // Retrieve the Pci Root Bridge IO Protocol
\r
449 Status = gBS->HandleProtocol (
\r
451 &gEfiPciRootBridgeIoProtocolGuid,
\r
452 (VOID **)&PciRootBridgeIo
\r
454 ASSERT_EFI_ERROR (Status);
\r
457 // We only install Device IO for PCI bus in Segment 0.
\r
458 // See the file description at @file for details.
\r
460 if (PciRootBridgeIo->SegmentNumber != 0) {
\r
465 // Allocate private data structure
\r
467 Private = AllocateCopyPool (sizeof (DEVICE_IO_PRIVATE_DATA), &gDeviceIoPrivateDataTemplate);
\r
468 if (Private == NULL) {
\r
472 Status = gBS->HandleProtocol (
\r
474 &gEfiDevicePathProtocolGuid,
\r
475 (VOID **) &Private->DevicePath
\r
479 // Install Device Io onto same handle
\r
481 Status = gBS->InstallMultipleProtocolInterfaces (
\r
483 &gEfiDeviceIoProtocolGuid,
\r
484 &Private->DeviceIo,
\r
487 ASSERT_EFI_ERROR (Status);
\r
492 The user Entry Point for DXE driver. The user code starts with this function
\r
493 as the real entry point for the image goes into a library that calls this
\r
496 @param[in] ImageHandle The firmware allocated handle for the EFI image.
\r
497 @param[in] SystemTable A pointer to the EFI System Table.
\r
499 @retval EFI_SUCCESS The entry point is executed successfully.
\r
500 @retval other Some error occurs when executing this entry point.
\r
505 InitializeDeviceIo (
\r
506 IN EFI_HANDLE ImageHandle,
\r
507 IN EFI_SYSTEM_TABLE *SystemTable
\r
510 EfiCreateProtocolNotifyEvent (
\r
511 &gEfiPciRootBridgeIoProtocolGuid,
\r
513 PciRootBridgeIoNotificationEvent,
\r
515 &mPciRootBridgeIoRegistration
\r
517 return EFI_SUCCESS;
\r
522 Perform reading memory mapped I/O space of device.
\r
524 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
525 @param Width Width of I/O operations.
\r
526 @param Address The base address of I/O operations.
\r
527 @param Count The number of I/O operations to perform. Bytes
\r
528 moves is Width size * Count, starting at Address.
\r
529 @param Buffer The destination buffer to store results.
\r
531 @retval EFI_SUCCESS The data was read from the device.
\r
532 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
533 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
540 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
541 IN EFI_IO_WIDTH Width,
\r
544 IN OUT VOID *Buffer
\r
548 DEVICE_IO_PRIVATE_DATA *Private;
\r
550 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
552 if (Width > MMIO_COPY_UINT64) {
\r
553 return EFI_INVALID_PARAMETER;
\r
555 if (Width >= MMIO_COPY_UINT8) {
\r
556 Width = Width - MMIO_COPY_UINT8;
\r
557 Status = Private->PciRootBridgeIo->CopyMem (
\r
558 Private->PciRootBridgeIo,
\r
559 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
\r
560 (UINT64) (UINTN) Buffer,
\r
565 Status = Private->PciRootBridgeIo->Mem.Read (
\r
566 Private->PciRootBridgeIo,
\r
567 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
\r
581 Perform writing memory mapped I/O space of device.
\r
583 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
584 @param Width Width of I/O operations.
\r
585 @param Address The base address of I/O operations.
\r
586 @param Count The number of I/O operations to perform. Bytes
\r
587 moves is Width size * Count, starting at Address.
\r
588 @param Buffer The source buffer of data to be written.
\r
590 @retval EFI_SUCCESS The data was written to the device.
\r
591 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
592 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
599 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
600 IN EFI_IO_WIDTH Width,
\r
603 IN OUT VOID *Buffer
\r
607 DEVICE_IO_PRIVATE_DATA *Private;
\r
609 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
611 if (Width > MMIO_COPY_UINT64) {
\r
612 return EFI_INVALID_PARAMETER;
\r
614 if (Width >= MMIO_COPY_UINT8) {
\r
615 Width = Width - MMIO_COPY_UINT8;
\r
616 Status = Private->PciRootBridgeIo->CopyMem (
\r
617 Private->PciRootBridgeIo,
\r
618 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
\r
620 (UINT64) (UINTN) Buffer,
\r
624 Status = Private->PciRootBridgeIo->Mem.Write (
\r
625 Private->PciRootBridgeIo,
\r
626 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
\r
638 Perform reading I/O space of device.
\r
640 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
641 @param Width Width of I/O operations.
\r
642 @param Address The base address of I/O operations.
\r
643 @param Count The number of I/O operations to perform. Bytes
\r
644 moves is Width size * Count, starting at Address.
\r
645 @param Buffer The destination buffer to store results.
\r
647 @retval EFI_SUCCESS The data was read from the device.
\r
648 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
649 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
656 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
657 IN EFI_IO_WIDTH Width,
\r
660 IN OUT VOID *Buffer
\r
664 DEVICE_IO_PRIVATE_DATA *Private;
\r
666 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
668 if (Width >= MMIO_COPY_UINT8) {
\r
669 return EFI_INVALID_PARAMETER;
\r
672 Status = Private->PciRootBridgeIo->Io.Read (
\r
673 Private->PciRootBridgeIo,
\r
674 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
\r
685 Perform writing I/O space of device.
\r
687 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
688 @param Width Width of I/O operations.
\r
689 @param Address The base address of I/O operations.
\r
690 @param Count The number of I/O operations to perform. Bytes
\r
691 moves is Width size * Count, starting at Address.
\r
692 @param Buffer The source buffer of data to be written.
\r
694 @retval EFI_SUCCESS The data was written to the device.
\r
695 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
696 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
703 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
704 IN EFI_IO_WIDTH Width,
\r
707 IN OUT VOID *Buffer
\r
711 DEVICE_IO_PRIVATE_DATA *Private;
\r
713 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
715 if (Width >= MMIO_COPY_UINT8) {
\r
716 return EFI_INVALID_PARAMETER;
\r
719 Status = Private->PciRootBridgeIo->Io.Write (
\r
720 Private->PciRootBridgeIo,
\r
721 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
\r
732 Perform reading PCI configuration space of device
\r
734 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
735 @param Width Width of I/O operations.
\r
736 @param Address The base address of I/O operations.
\r
737 @param Count The number of I/O operations to perform. Bytes
\r
738 moves is Width size * Count, starting at Address.
\r
739 @param Buffer The destination buffer to store results.
\r
741 @retval EFI_SUCCESS The data was read from the device.
\r
742 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
743 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
750 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
751 IN EFI_IO_WIDTH Width,
\r
754 IN OUT VOID *Buffer
\r
758 DEVICE_IO_PRIVATE_DATA *Private;
\r
760 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
762 if (Width < 0 || Width >= MMIO_COPY_UINT8) {
\r
763 return EFI_INVALID_PARAMETER;
\r
766 Status = Private->PciRootBridgeIo->Pci.Read (
\r
767 Private->PciRootBridgeIo,
\r
768 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
\r
779 Perform writing PCI configuration space of device.
\r
781 @param This A pointer to EFI_DEVICE_IO protocol instance.
\r
782 @param Width Width of I/O operations.
\r
783 @param Address The base address of I/O operations.
\r
784 @param Count The number of I/O operations to perform. Bytes
\r
785 moves is Width size * Count, starting at Address.
\r
786 @param Buffer The source buffer of data to be written.
\r
788 @retval EFI_SUCCESS The data was written to the device.
\r
789 @retval EFI_INVALID_PARAMETER Width is invalid.
\r
790 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of
\r
797 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
798 IN EFI_IO_WIDTH Width,
\r
801 IN OUT VOID *Buffer
\r
805 DEVICE_IO_PRIVATE_DATA *Private;
\r
807 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
809 if (Width < 0 || Width >= MMIO_COPY_UINT8) {
\r
810 return EFI_INVALID_PARAMETER;
\r
813 Status = Private->PciRootBridgeIo->Pci.Write (
\r
814 Private->PciRootBridgeIo,
\r
815 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) Width,
\r
826 Append a PCI device path node to another device path.
\r
828 @param Private A pointer to DEVICE_IO_PRIVATE_DATA instance.
\r
829 @param Bus PCI bus number of the device.
\r
830 @param Device PCI device number of the device.
\r
831 @param Function PCI function number of the device.
\r
832 @param DevicePath Original device path which will be appended a PCI
\r
834 @param BridgePrimaryBus Primary bus number of the bridge.
\r
835 @param BridgeSubordinateBus Subordinate bus number of the bridge.
\r
837 @return Pointer to the appended PCI device path.
\r
840 EFI_DEVICE_PATH_PROTOCOL *
\r
841 AppendPciDevicePath (
\r
842 IN DEVICE_IO_PRIVATE_DATA *Private,
\r
846 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
\r
847 IN OUT UINT16 *BridgePrimaryBus,
\r
848 IN OUT UINT16 *BridgeSubordinateBus
\r
855 PCI_TYPE01 PciBridge;
\r
856 PCI_TYPE01 *PciPtr;
\r
857 EFI_DEVICE_PATH_PROTOCOL *ReturnDevicePath;
\r
858 PCI_DEVICE_PATH PciNode;
\r
860 PciPtr = &PciBridge;
\r
861 for (ThisBus = *BridgePrimaryBus; ThisBus <= *BridgeSubordinateBus; ThisBus++) {
\r
862 for (ThisDevice = 0; ThisDevice <= PCI_MAX_DEVICE; ThisDevice++) {
\r
863 for (ThisFunc = 0; ThisFunc <= PCI_MAX_FUNC; ThisFunc++) {
\r
864 Address = EFI_PCI_ADDRESS (ThisBus, ThisDevice, ThisFunc, 0);
\r
865 ZeroMem (PciPtr, sizeof (PCI_TYPE01));
\r
866 Private->DeviceIo.Pci.Read (
\r
867 &Private->DeviceIo,
\r
871 &(PciPtr->Hdr.VendorId)
\r
873 if ((PciPtr->Hdr.VendorId == 0xffff) && (ThisFunc == 0)) {
\r
876 if (PciPtr->Hdr.VendorId == 0xffff) {
\r
879 Private->DeviceIo.Pci.Read (
\r
880 &Private->DeviceIo,
\r
883 sizeof (PCI_TYPE01) / sizeof (UINT32),
\r
886 if (IS_PCI_BRIDGE (PciPtr)) {
\r
887 if (Bus >= PciPtr->Bridge.SecondaryBus && Bus <= PciPtr->Bridge.SubordinateBus) {
\r
889 PciNode.Header.Type = HARDWARE_DEVICE_PATH;
\r
890 PciNode.Header.SubType = HW_PCI_DP;
\r
891 SetDevicePathNodeLength (&PciNode.Header, sizeof (PciNode));
\r
893 PciNode.Device = ThisDevice;
\r
894 PciNode.Function = ThisFunc;
\r
895 ReturnDevicePath = AppendDevicePathNode (DevicePath, &PciNode.Header);
\r
897 *BridgePrimaryBus = PciPtr->Bridge.SecondaryBus;
\r
898 *BridgeSubordinateBus = PciPtr->Bridge.SubordinateBus;
\r
899 return ReturnDevicePath;
\r
902 if (ThisFunc == 0 && !(PciPtr->Hdr.HeaderType & HEADER_TYPE_MULTI_FUNCTION)) {
\r
904 // Skip sub functions, this is not a multi function device
\r
913 ZeroMem (&PciNode, sizeof (PciNode));
\r
914 PciNode.Header.Type = HARDWARE_DEVICE_PATH;
\r
915 PciNode.Header.SubType = HW_PCI_DP;
\r
916 SetDevicePathNodeLength (&PciNode.Header, sizeof (PciNode));
\r
917 PciNode.Device = Device;
\r
918 PciNode.Function = Function;
\r
920 ReturnDevicePath = AppendDevicePathNode (DevicePath, &PciNode.Header);
\r
922 *BridgePrimaryBus = 0xffff;
\r
923 *BridgeSubordinateBus = 0xffff;
\r
924 return ReturnDevicePath;
\r
929 Provides an EFI Device Path for a PCI device with the given PCI configuration space address.
\r
931 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
932 @param Address The PCI configuration space address of the device
\r
933 whose Device Path is going to be returned.
\r
934 @param PciDevicePath A pointer to the pointer for the EFI Device Path
\r
935 for PciAddress. Memory for the Device Path is
\r
936 allocated from the pool.
\r
938 @retval EFI_SUCCESS The PciDevicePath returns a pointer to a valid EFI
\r
940 @retval EFI_UNSUPPORTED The PciAddress does not map to a valid EFI Device
\r
942 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
\r
948 DeviceIoPciDevicePath (
\r
949 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
951 IN OUT EFI_DEVICE_PATH_PROTOCOL **PciDevicePath
\r
954 DEVICE_IO_PRIVATE_DATA *Private;
\r
956 UINT16 SubordinateBus;
\r
961 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
963 Bus = (UINT8) (((UINT32) Address >> 24) & 0xff);
\r
964 Device = (UINT8) (((UINT32) Address >> 16) & 0xff);
\r
965 Func = (UINT8) (((UINT32) Address >> 8) & 0xff);
\r
967 if (Bus < Private->PrimaryBus || Bus > Private->SubordinateBus) {
\r
968 return EFI_UNSUPPORTED;
\r
971 *PciDevicePath = Private->DevicePath;
\r
972 PrimaryBus = Private->PrimaryBus;
\r
973 SubordinateBus = Private->SubordinateBus;
\r
975 *PciDevicePath = AppendPciDevicePath (
\r
984 if (*PciDevicePath == NULL) {
\r
985 return EFI_OUT_OF_RESOURCES;
\r
987 } while (PrimaryBus != 0xffff);
\r
989 return EFI_SUCCESS;
\r
994 Provides the device-specific addresses needed to access system memory.
\r
996 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
997 @param Operation Indicates if the bus master is going to read or
\r
998 write to system memory.
\r
999 @param HostAddress The system memory address to map to the device.
\r
1000 @param NumberOfBytes On input the number of bytes to map. On output the
\r
1001 number of bytes that were mapped.
\r
1002 @param DeviceAddress The resulting map address for the bus master
\r
1003 device to use to access the hosts HostAddress.
\r
1004 @param Mapping A resulting value to pass to Unmap().
\r
1006 @retval EFI_SUCCESS The range was mapped for the returned
\r
1008 @retval EFI_INVALID_PARAMETER The Operation or HostAddress is undefined.
\r
1009 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common
\r
1011 @retval EFI_DEVICE_ERROR The system hardware could not map the requested
\r
1013 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
\r
1020 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
1021 IN EFI_IO_OPERATION_TYPE Operation,
\r
1022 IN EFI_PHYSICAL_ADDRESS *HostAddress,
\r
1023 IN OUT UINTN *NumberOfBytes,
\r
1024 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
\r
1025 OUT VOID **Mapping
\r
1028 EFI_STATUS Status;
\r
1029 DEVICE_IO_PRIVATE_DATA *Private;
\r
1031 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
1033 if (Operation < 0 || Operation > EfiBusMasterCommonBuffer) {
\r
1034 return EFI_INVALID_PARAMETER;
\r
1037 if (((UINTN) (*HostAddress) != (*HostAddress)) && Operation == EfiBusMasterCommonBuffer) {
\r
1038 return EFI_UNSUPPORTED;
\r
1041 Status = Private->PciRootBridgeIo->Map (
\r
1042 Private->PciRootBridgeIo,
\r
1043 (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION) Operation,
\r
1044 (VOID *) (UINTN) (*HostAddress),
\r
1055 Completes the Map() operation and releases any corresponding resources.
\r
1057 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
1058 @param Mapping The mapping value returned from Map().
\r
1060 @retval EFI_SUCCESS The range was unmapped.
\r
1061 @retval EFI_DEVICE_ERROR The data was not committed to the target system
\r
1068 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
1072 EFI_STATUS Status;
\r
1073 DEVICE_IO_PRIVATE_DATA *Private;
\r
1075 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
1077 Status = Private->PciRootBridgeIo->Unmap (
\r
1078 Private->PciRootBridgeIo,
\r
1087 Allocates pages that are suitable for an EFIBusMasterCommonBuffer mapping.
\r
1089 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
1090 @param Type The type allocation to perform.
\r
1091 @param MemoryType The type of memory to allocate,
\r
1092 EfiBootServicesData or EfiRuntimeServicesData.
\r
1093 @param Pages The number of pages to allocate.
\r
1094 @param PhysicalAddress A pointer to store the base address of the
\r
1097 @retval EFI_SUCCESS The requested memory pages were allocated.
\r
1098 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
\r
1099 @retval EFI_INVALID_PARAMETER The requested memory type is invalid.
\r
1100 @retval EFI_UNSUPPORTED The requested PhysicalAddress is not supported on
\r
1106 DeviceIoAllocateBuffer (
\r
1107 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
1108 IN EFI_ALLOCATE_TYPE Type,
\r
1109 IN EFI_MEMORY_TYPE MemoryType,
\r
1111 IN OUT EFI_PHYSICAL_ADDRESS *PhysicalAddress
\r
1114 EFI_STATUS Status;
\r
1115 EFI_PHYSICAL_ADDRESS HostAddress;
\r
1116 DEVICE_IO_PRIVATE_DATA *Private;
\r
1117 VOID *HostAddress2;
\r
1119 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
1121 HostAddress = *PhysicalAddress;
\r
1123 if ((MemoryType != EfiBootServicesData) && (MemoryType != EfiRuntimeServicesData)) {
\r
1124 return EFI_INVALID_PARAMETER;
\r
1127 if ((Type >= MaxAllocateType) || (Type < AllocateAnyPages)) {
\r
1128 return EFI_INVALID_PARAMETER;
\r
1131 if ((Type == AllocateAddress) && (HostAddress + EFI_PAGES_TO_SIZE (Pages) - 1 > MAX_COMMON_BUFFER)) {
\r
1132 return EFI_UNSUPPORTED;
\r
1135 if ((AllocateAnyPages == Type) || (AllocateMaxAddress == Type && HostAddress > MAX_COMMON_BUFFER)) {
\r
1136 Type = AllocateMaxAddress;
\r
1137 HostAddress = MAX_COMMON_BUFFER;
\r
1140 HostAddress2 = (VOID *) (UINTN) (HostAddress);
\r
1141 Status = Private->PciRootBridgeIo->AllocateBuffer (
\r
1142 Private->PciRootBridgeIo,
\r
1147 EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE |
\r
1148 EFI_PCI_ATTRIBUTE_MEMORY_CACHED
\r
1151 if (EFI_ERROR (Status)) {
\r
1156 *PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress2;
\r
1158 return EFI_SUCCESS;
\r
1163 Flushes any posted write data to the device.
\r
1165 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
1167 @retval EFI_SUCCESS The buffers were flushed.
\r
1168 @retval EFI_DEVICE_ERROR The buffers were not flushed due to a hardware
\r
1175 IN EFI_DEVICE_IO_PROTOCOL *This
\r
1178 EFI_STATUS Status;
\r
1179 DEVICE_IO_PRIVATE_DATA *Private;
\r
1181 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
1183 Status = Private->PciRootBridgeIo->Flush (Private->PciRootBridgeIo);
\r
1190 Frees pages that were allocated with AllocateBuffer().
\r
1192 @param This A pointer to the EFI_DEVICE_IO_INTERFACE instance.
\r
1193 @param Pages The number of pages to free.
\r
1194 @param HostAddress The base address of the range to free.
\r
1196 @retval EFI_SUCCESS The requested memory pages were freed.
\r
1197 @retval EFI_NOT_FOUND The requested memory pages were not allocated with
\r
1199 @retval EFI_INVALID_PARAMETER HostAddress is not page aligned or Pages is
\r
1205 DeviceIoFreeBuffer (
\r
1206 IN EFI_DEVICE_IO_PROTOCOL *This,
\r
1208 IN EFI_PHYSICAL_ADDRESS HostAddress
\r
1211 DEVICE_IO_PRIVATE_DATA *Private;
\r
1213 Private = DEVICE_IO_PRIVATE_DATA_FROM_THIS (This);
\r
1215 if (((HostAddress & EFI_PAGE_MASK) != 0) || (Pages <= 0)) {
\r
1216 return EFI_INVALID_PARAMETER;
\r
1219 return Private->PciRootBridgeIo->FreeBuffer (
\r
1220 Private->PciRootBridgeIo,
\r
1222 (VOID *) (UINTN) HostAddress
\r