forked from xCuri0/ReBarUEFI
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathS3ResumeScript.c
79 lines (65 loc) · 1.92 KB
/
S3ResumeScript.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdbool.h>
#include <stdint.h>
#include <Uefi.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Guid/EventGroup.h>
#include <Protocol/S3SaveState.h>
#include "ReBar.h"
#include "PciConfig.h"
#include "StatusVar.h"
#include "S3ResumeScript.h"
EFI_S3_SAVE_STATE_PROTOCOL *S3SaveState = NULL;
static void LoadS3SaveStateProtocol()
{
EFI_STATUS status = gBS->LocateProtocol(&gEfiS3SaveStateProtocolGuid, NULL, (void **)&S3SaveState);
if (EFI_ERROR(status))
SetEFIError(EFIError_LocateS3SaveStateProtocol, status);
}
void S3ResumeScript_Init(bool enabled)
{
if (enabled && !NvStrapsConfig_SkipS3Resume(config))
LoadS3SaveStateProtocol();
}
// EFI_STATUS S3ResumeScript_MemWrite_DWORD(uintptr_t address, uint_least32_t data);
EFI_STATUS S3ResumeScript_MemReadWrite_DWORD(uintptr_t address, uint_least32_t data, uint_least32_t dataMask)
{
if (S3SaveState)
return S3SaveState->Write
(
S3SaveState,
(UINT16)EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE,
(EFI_BOOT_SCRIPT_WIDTH)EfiBootScriptWidthUint32,
(UINT64)address,
(void *)&data,
(void *)&dataMask
);
return EFI_SUCCESS;
}
EFI_STATUS S3ResumeScript_PciConfigWrite_DWORD(UINTN pciAddress, uint_least16_t offset, uint_least32_t data)
{
if (S3SaveState)
return S3SaveState->Write
(
S3SaveState,
(UINT16)EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE,
(EFI_BOOT_SCRIPT_WIDTH)EfiBootScriptWidthUint32,
(UINT64)pciAddrOffset(pciAddress, offset),
(UINTN)1u,
(void *)&data
);
return EFI_SUCCESS;
}
EFI_STATUS S3ResumeScript_PciConfigReadWrite_DWORD(UINTN pciAddress, uint_least16_t offset, uint_least32_t data, uint_least32_t dataMask)
{
if (S3SaveState)
return S3SaveState->Write
(
S3SaveState,
(UINT16)EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE,
(EFI_BOOT_SCRIPT_WIDTH)EfiBootScriptWidthUint32,
(UINT64)pciAddrOffset(pciAddress, offset),
(void *)&data,
(void *)&dataMask
);
return EFI_SUCCESS;
}