OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
LegacyRegionUnLock.c
Go to the documentation of this file.
1
15#include <Uefi.h>
16
17#include <IndustryStandard/Pci.h>
18
20
22#include <Protocol/LegacyRegion2.h>
23#include <Protocol/PciIo.h>
24
25#include <Library/BaseLib.h>
26#include <Library/BaseMemoryLib.h>
27#include <Library/DebugLib.h>
28#include <Library/MemoryAllocationLib.h>
29#include <Library/OcMiscLib.h>
30#include <Library/OcStringLib.h>
31#include <Library/UefiBootServicesTableLib.h>
32#include <Library/UefiLib.h>
33#include <Library/UefiRuntimeServicesTableLib.h>
34
42EFI_STATUS
44 IN UINT32 LegacyAddress,
45 IN UINT32 LegacyLength
46 )
47{
48 EFI_STATUS Status;
49
50 EFI_LEGACY_REGION_PROTOCOL *LegacyRegionProtocol;
51 EFI_LEGACY_REGION2_PROTOCOL *LegacyRegion2Protocol;
52 UINT32 Granularity;
53
54 //
55 // Locate v2 protocol and fallback to v1 if unavailable.
56 //
57 LegacyRegionProtocol = NULL;
58 LegacyRegion2Protocol = NULL;
59 Status = gBS->LocateProtocol (
61 NULL,
62 (VOID **)&LegacyRegion2Protocol
63 );
64
65 if (Status == EFI_NOT_FOUND) {
66 Status = gBS->LocateProtocol (
68 NULL,
69 (VOID **)&LegacyRegionProtocol
70 );
71 }
72
73 if (!EFI_ERROR (Status)) {
74 //
75 // Unlock region using LegacyRegionProtocol or LegacyRegion2Protocol.
76 //
77 Granularity = 0;
78 if (LegacyRegionProtocol != NULL) {
79 Status = LegacyRegionProtocol->UnLock (
80 LegacyRegionProtocol,
81 LegacyAddress,
82 LegacyLength,
83 &Granularity
84 );
85 } else {
86 Status = LegacyRegion2Protocol->UnLock (
87 LegacyRegion2Protocol,
88 LegacyAddress,
89 LegacyLength,
90 &Granularity
91 );
92 }
93
94 DEBUG ((
95 DEBUG_INFO,
96 "OCMM: Unlock LegacyRegion %0X-%0X - %r\n",
97 LegacyAddress,
98 (LegacyAddress + (LegacyLength - 1)),
99 Status
100 ));
101 }
102
103 return Status;
104}
EFI_GUID gEfiLegacyRegionProtocolGuid
EFI_STATUS LegacyRegionUnlock(IN UINT32 LegacyAddress, IN UINT32 LegacyLength)
EFI_BOOT_SERVICES * gBS
EFI_GUID gEfiLegacyRegion2ProtocolGuid
EFI_LEGACY_REGION_UNLOCK UnLock
Makes the specified OpROM region read-write or unlocked.