OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcPciIoLib.c
Go to the documentation of this file.
1
9#include "OcPciIoU.h"
10#include <Library/OcPciIoLib.h>
11
12EFI_CPU_IO2_PROTOCOL *
14 IN BOOLEAN Reinstall
15 )
16{
17 EFI_TPL Tpl;
18 UINTN Index;
19 EFI_STATUS Status;
20 EFI_CPU_IO2_PROTOCOL *CpuIo;
21 UINTN HandleCount;
22 EFI_HANDLE *HandleBuffer;
23 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
24
25 CpuIo = InitializeCpuIo2 ();
26 if (CpuIo == NULL) {
27 return NULL;
28 }
29
30 if (!Reinstall) {
31 return CpuIo;
32 }
33
34 Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
35 Status = gBS->LocateHandleBuffer (
36 ByProtocol,
38 NULL,
39 &HandleCount,
40 &HandleBuffer
41 );
42
43 if (EFI_ERROR (Status)) {
44 gBS->RestoreTPL (Tpl);
45 return NULL;
46 }
47
48 DEBUG ((DEBUG_INFO, "OCPIO: Fixing CpuIo2\n"));
49 // Override with 64-bit MMIO compatible functions
50 CpuIo->Mem.Read = CpuMemoryServiceRead;
51 CpuIo->Mem.Write = CpuMemoryServiceWrite;
52
53 for (Index = 0; Index < HandleCount; ++Index) {
54 DEBUG ((DEBUG_INFO, "OCPIO: Fixing PciRootBridgeIo %d\n", Index));
55
56 Status = gBS->HandleProtocol (
57 HandleBuffer[Index],
59 (VOID **)&PciRootBridgeIo
60 );
61 if (EFI_ERROR (Status)) {
62 break;
63 }
64
65 // Override with 64-bit MMIO compatible functions
66 PciRootBridgeIo->Mem.Read = RootBridgeIoMemRead;
67 PciRootBridgeIo->Mem.Write = RootBridgeIoMemWrite;
68 }
69
70 gBS->RestoreTPL (Tpl);
71 FreePool (HandleBuffer);
72 return CpuIo;
73}
EFI_BOOT_SERVICES * gBS
EFI_CPU_IO2_PROTOCOL * OcPciIoInstallProtocol(IN BOOLEAN Reinstall)
Definition OcPciIoLib.c:13
EFI_STATUS EFIAPI RootBridgeIoMemRead(IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, IN UINT64 Address, IN UINTN Count, OUT VOID *Buffer)
Definition OcPciIoU.c:378
EFI_CPU_IO2_PROTOCOL * InitializeCpuIo2(VOID)
Definition OcPciIoU.c:48
EFI_STATUS EFIAPI CpuMemoryServiceWrite(IN EFI_CPU_IO2_PROTOCOL *This, IN EFI_CPU_IO_PROTOCOL_WIDTH Width, IN UINT64 Address, IN UINTN Count, IN VOID *Buffer)
Definition OcPciIoU.c:309
EFI_STATUS EFIAPI CpuMemoryServiceRead(IN EFI_CPU_IO2_PROTOCOL *This, IN EFI_CPU_IO_PROTOCOL_WIDTH Width, IN UINT64 Address, IN UINTN Count, OUT VOID *Buffer)
Definition OcPciIoU.c:228
EFI_STATUS EFIAPI RootBridgeIoMemWrite(IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This, IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width, IN UINT64 Address, IN UINTN Count, IN VOID *Buffer)
Definition OcPciIoU.c:433
EFI_GUID gEfiPciRootBridgeIoProtocolGuid