Skip to content

Commit face276

Browse files
committed
Add BatteryDxe for Windows mobilestartup
1 parent eadc0df commit face276

File tree

7 files changed

+327
-18
lines changed

7 files changed

+327
-18
lines changed

ArmVirtPkg/ArmVirtPkg.dec

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
gEarly16550UartBaseAddressGuid = { 0xea67ca3e, 0x1f54, 0x436b, { 0x97, 0x88, 0xd4, 0xeb, 0x29, 0xc3, 0x42, 0x67 } }
3535
gArmVirtSystemMemorySizeGuid = { 0x504eccb9, 0x1bf0, 0x4420, { 0x86, 0x5d, 0xdc, 0x66, 0x06, 0xd4, 0x13, 0xbf } }
3636

37+
[Protocols]
38+
gEfiBatteryChargingProtocolGuid = {0x840cb643, 0x8198, 0x428a, { 0xa8, 0xb3, 0xa0, 0x72, 0xce, 0x57, 0xcd, 0xb9}}
39+
gEfiDisplayPowerProtocolGuid = {0xf352021d, 0x9593, 0x4432, { 0xbf, 0x4, 0x67, 0xb9, 0xf3, 0xb7, 0x60, 0x8}}
40+
3741
[PcdsFeatureFlag]
3842
#
3943
# Feature Flag PCD that defines whether TPM2 support is enabled

ArmVirtPkg/ArmVirtQemu.dsc

+23-18
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
#
3030
DEFINE TTY_TERMINAL = FALSE
3131
DEFINE SECURE_BOOT_ENABLE = FALSE
32-
DEFINE TPM2_ENABLE = FALSE
33-
DEFINE TPM2_CONFIG_ENABLE = FALSE
34-
DEFINE CAVIUM_ERRATUM_27456 = FALSE
35-
DEFINE TF_A_SUPPORT = FALSE
36-
37-
#
38-
# Network definition
32+
DEFINE TPM2_ENABLE = FALSE
33+
DEFINE TPM2_CONFIG_ENABLE = FALSE
34+
DEFINE CAVIUM_ERRATUM_27456 = FALSE
35+
DEFINE TF_A_SUPPORT = FALSE
36+
37+
#
38+
# Network definition
3939
#
4040
DEFINE NETWORK_IP6_ENABLE = FALSE
4141
DEFINE NETWORK_HTTP_BOOT_ENABLE = FALSE
@@ -232,17 +232,17 @@
232232
gArmTokenSpaceGuid.PcdSystemMemorySize|0x8000000
233233

234234
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize | 0x40000
235-
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize | 0x40000
236-
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize | 0x40000
237-
238-
!if $(TF_A_SUPPORT) == TRUE
239-
gArmTokenSpaceGuid.PcdSecureFvBaseAddress|0x00000000
240-
gArmTokenSpaceGuid.PcdSecureFvSize|0x04000000
241-
!endif
242-
243-
[PcdsFixedAtBuild.AARCH64]
244-
# Clearing BIT0 in this PCD prevents installing a 32-bit SMBIOS entry point,
245-
# if the entry point version is >= 3.0. AARCH64 OSes cannot assume the
235+
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize | 0x40000
236+
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize | 0x40000
237+
238+
!if $(TF_A_SUPPORT) == TRUE
239+
gArmTokenSpaceGuid.PcdSecureFvBaseAddress|0x00000000
240+
gArmTokenSpaceGuid.PcdSecureFvSize|0x04000000
241+
!endif
242+
243+
[PcdsFixedAtBuild.AARCH64]
244+
# Clearing BIT0 in this PCD prevents installing a 32-bit SMBIOS entry point,
245+
# if the entry point version is >= 3.0. AARCH64 OSes cannot assume the
246246
# presence of the 32-bit entry point anyway (because many AARCH64 systems
247247
# don't have 32-bit addressable physical RAM), and the additional allocations
248248
# below 4 GB needlessly fragment the memory map. So expose the 64-bit entry
@@ -617,3 +617,8 @@
617617
<LibraryClasses>
618618
NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
619619
}
620+
621+
#
622+
# Battery
623+
#
624+
ArmVirtPkg/BatteryDxe/BatteryDxe.inf

ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc

+5
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,8 @@ READ_LOCK_STATUS = TRUE
212212
# Ramdisk support
213213
#
214214
INF MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
215+
216+
#
217+
# Battery
218+
#
219+
INF ArmVirtPkg/BatteryDxe/BatteryDxe.inf

ArmVirtPkg/BatteryDxe/BatteryDxe.c

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#include <Uefi.h>
2+
#include <Library/UefiBootServicesTableLib.h>
3+
#include <Library/DebugLib.h>
4+
#include <Library/UefiDriverEntryPoint.h>
5+
#include <Protocol/BatteryCharging.h>
6+
#include <Protocol/DisplayPower.h>
7+
8+
EFI_STATUS
9+
EFIAPI
10+
GetBatteryStatus (
11+
IN EFI_BATTERY_CHARGING_PROTOCOL *This,
12+
OUT UINT32 *StateOfCharge,
13+
OUT UINT32 *RatedCapacity,
14+
OUT INT32 *ChargeCurrent )
15+
{
16+
*StateOfCharge = 90;
17+
*RatedCapacity = 3000;
18+
*ChargeCurrent = -1;
19+
20+
return EFI_SUCCESS;
21+
}
22+
23+
EFI_STATUS
24+
EFIAPI
25+
ChargeBattery (
26+
IN EFI_BATTERY_CHARGING_PROTOCOL *This,
27+
IN UINT32 MaximumCurrent,
28+
IN UINT32 TargetStateOfCharge,
29+
IN EFI_BATTERY_CHARGING_COMPLETION_TOKEN *CompletionToken )
30+
{
31+
return EFI_SUCCESS;
32+
}
33+
34+
EFI_STATUS
35+
EFIAPI
36+
GetBatteryInformation (
37+
IN EFI_BATTERY_CHARGING_PROTOCOL *This,
38+
OUT UINT32 *StateOfCharge,
39+
OUT INT32 *CurrentIntoBattery,
40+
OUT UINT32 *BatteryTerminalVoltage,
41+
OUT INT32 *BatteryTemperature,
42+
OUT UINT32 *USBCableVoltage,
43+
OUT UINT32 *USBCableCurrent
44+
)
45+
{
46+
*StateOfCharge = 90;
47+
*CurrentIntoBattery = -1;
48+
*BatteryTerminalVoltage = 4500;
49+
*BatteryTemperature = 30;
50+
*USBCableVoltage = 0;
51+
*USBCableCurrent = 0;
52+
53+
return EFI_SUCCESS;
54+
}
55+
56+
EFI_STATUS
57+
EFIAPI
58+
SetDisplayPowerState (
59+
IN EFI_DISPLAY_POWER_PROTOCOL *This,
60+
IN EFI_DISPLAY_POWER_STATE PowerState )
61+
{
62+
return EFI_SUCCESS;
63+
}
64+
65+
EFI_STATUS
66+
EFIAPI
67+
GetDisplayPowerState (
68+
IN EFI_DISPLAY_POWER_PROTOCOL *This,
69+
OUT EFI_DISPLAY_POWER_STATE *PowerState )
70+
{
71+
*PowerState = EfiDisplayPowerStateMaximum;
72+
73+
return EFI_SUCCESS;
74+
}
75+
76+
// Protocol instances
77+
EFI_BATTERY_CHARGING_PROTOCOL gBatteryChargingProtocol = {
78+
GetBatteryStatus,
79+
ChargeBattery,
80+
0x00010002,
81+
GetBatteryInformation
82+
};
83+
84+
EFI_DISPLAY_POWER_PROTOCOL gDisplayPowerProtocol = {
85+
0x00010000,
86+
SetDisplayPowerState,
87+
GetDisplayPowerState
88+
};
89+
90+
EFI_STATUS
91+
EFIAPI
92+
BatteryDxeEntry (
93+
IN EFI_HANDLE ImageHandle,
94+
IN EFI_SYSTEM_TABLE *SystemTable )
95+
{
96+
EFI_STATUS Status;
97+
98+
// Install Battery Charging Protocol
99+
Status = gBS->InstallProtocolInterface(
100+
&ImageHandle,
101+
&gEfiBatteryChargingProtocolGuid,
102+
EFI_NATIVE_INTERFACE,
103+
&gBatteryChargingProtocol
104+
);
105+
if (EFI_ERROR(Status)) {
106+
DEBUG((DEBUG_ERROR, "Failed to install Battery Charging Protocol: %r\n", Status));
107+
return Status;
108+
}
109+
DEBUG((DEBUG_INFO, "Battery Charging Protocol installed successfully\n"));
110+
111+
// Install Display Power Protocol
112+
Status = gBS->InstallProtocolInterface(
113+
&ImageHandle,
114+
&gEfiDisplayPowerProtocolGuid,
115+
EFI_NATIVE_INTERFACE,
116+
&gDisplayPowerProtocol
117+
);
118+
if (EFI_ERROR(Status)) {
119+
DEBUG((DEBUG_ERROR, "Failed to install Display Power Protocol: %r\n", Status));
120+
return Status;
121+
}
122+
DEBUG((DEBUG_INFO, "Display Power Protocol installed successfully\n"));
123+
124+
return EFI_SUCCESS;
125+
}
126+
127+
// UEFI driver unload function
128+
EFI_STATUS
129+
EFIAPI
130+
BatteryDxeUnload (
131+
IN EFI_HANDLE ImageHandle )
132+
{
133+
EFI_STATUS Status;
134+
135+
// Uninstall Battery Charging Protocol
136+
Status = gBS->UninstallProtocolInterface(
137+
ImageHandle,
138+
&gEfiBatteryChargingProtocolGuid,
139+
&gBatteryChargingProtocol
140+
);
141+
if (EFI_ERROR(Status)) {
142+
DEBUG((DEBUG_ERROR, "Failed to uninstall Battery Charging Protocol: %r\n", Status));
143+
return Status;
144+
}
145+
DEBUG((DEBUG_INFO, "Battery Charging Protocol uninstalled successfully\n"));
146+
147+
// Uninstall Display Power Protocol
148+
Status = gBS->UninstallProtocolInterface(
149+
ImageHandle,
150+
&gEfiDisplayPowerProtocolGuid,
151+
&gDisplayPowerProtocol
152+
);
153+
if (EFI_ERROR(Status)) {
154+
DEBUG((DEBUG_ERROR, "Failed to uninstall Display Power Protocol: %r\n", Status));
155+
return Status;
156+
}
157+
DEBUG((DEBUG_INFO, "Display Power Protocol uninstalled successfully\n"));
158+
159+
return EFI_SUCCESS;
160+
}

ArmVirtPkg/BatteryDxe/BatteryDxe.inf

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[Defines]
2+
INF_VERSION = 0x00010006
3+
BASE_NAME = BatteryDxe
4+
FILE_GUID = 550e8400-e29b-41d4-a716-446655440000
5+
MODULE_TYPE = DXE_DRIVER
6+
VERSION_STRING = 1.0
7+
ENTRY_POINT = BatteryDxeEntry
8+
UNLOAD_IMAGE = BatteryDxeUnload
9+
10+
[Packages]
11+
ArmVirtPkg/ArmVirtPkg.dec
12+
MdePkg/MdePkg.dec
13+
14+
[LibraryClasses]
15+
UefiBootServicesTableLib
16+
UefiRuntimeServicesTableLib
17+
UefiLib
18+
DebugLib
19+
UefiDriverEntryPoint
20+
21+
[Protocols]
22+
gEfiBatteryChargingProtocolGuid
23+
gEfiDisplayPowerProtocolGuid
24+
25+
[Sources]
26+
BatteryDxe.c
27+
28+
[Depex]
29+
TRUE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifndef __BATTERY_CHARGING_H__
2+
#define __BATTERY_CHARGING_H__
3+
4+
#include <Uefi.h>
5+
6+
#define EFI_BATTERY_CHARGING_PROTOCOL_GUID { \
7+
0x840cb643, 0x8198, 0x428a, { \
8+
0xa8, 0xb3, 0xa0, 0x72, 0xce, 0x57, 0xcd, 0xb9 \
9+
} \
10+
}
11+
12+
extern EFI_GUID gEfiBatteryChargingProtocolGuid;
13+
14+
typedef struct _EFI_BATTERY_CHARGING_PROTOCOL EFI_BATTERY_CHARGING_PROTOCOL;
15+
16+
typedef enum _EFI_BATTERY_CHARGING_STATUS {
17+
EfiBatteryChargingStatusNone = 0,
18+
EfiBatteryChargingStatusSuccess,
19+
EfiBatteryChargingStatusOverheat,
20+
EfiBatteryChargingStatusVoltageOutOfRange,
21+
EfiBatteryChargingStatusCurrentOutOfRange,
22+
EfiBatteryChargingStatusTimeout,
23+
EfiBatteryChargingStatusAborted,
24+
EfiBatteryChargingStatusDeviceError,
25+
EfiBatteryChargingStatusExtremeCold,
26+
EfiBatteryChargingStatusBatteryChargingNotSupported,
27+
EfiBatteryChargingStatusBatteryNotDetected,
28+
EfiBatteryChargingSourceNotDetected,
29+
EfiBatteryChargingSourceVoltageInvalid,
30+
EfiBatteryChargingSourceCurrentInvalid,
31+
EfiBatteryChargingErrorRequestShutdown,
32+
EfiBatteryChargingErrorRequestReboot
33+
} EFI_BATTERY_CHARGING_STATUS;
34+
35+
typedef struct _EFI_BATTERY_CHARGING_COMPLETION_TOKEN {
36+
EFI_EVENT Event;
37+
EFI_BATTERY_CHARGING_STATUS Status;
38+
} EFI_BATTERY_CHARGING_COMPLETION_TOKEN;
39+
40+
typedef EFI_STATUS (EFIAPI * EFI_BATTERY_CHARGING_GET_BATTERY_STATUS) (
41+
IN EFI_BATTERY_CHARGING_PROTOCOL *This,
42+
OUT UINT32 *StateOfCharge,
43+
OUT UINT32 *RatedCapacity,
44+
OUT INT32 *ChargeCurrent );
45+
46+
typedef EFI_STATUS (EFIAPI * EFI_BATTERY_CHARGING_CHARGE_BATTERY) (
47+
IN EFI_BATTERY_CHARGING_PROTOCOL *This,
48+
IN UINT32 MaximumCurrent,
49+
IN UINT32 TargetStateOfCharge,
50+
IN EFI_BATTERY_CHARGING_COMPLETION_TOKEN *CompletionToken );
51+
52+
typedef EFI_STATUS (EFIAPI * EFI_BATTERY_CHARGING_GET_BATTERY_INFORMATION) (
53+
IN EFI_BATTERY_CHARGING_PROTOCOL *This,
54+
OUT UINT32 *StateOfCharge,
55+
OUT INT32 *CurrentIntoBattery,
56+
OUT UINT32 *BatteryTerminalVoltage,
57+
OUT INT32 *BatteryTemperature,
58+
OUT UINT32 *USBCableVoltage,
59+
OUT UINT32 *USBCableCurrent );
60+
61+
struct _EFI_BATTERY_CHARGING_PROTOCOL {
62+
EFI_BATTERY_CHARGING_GET_BATTERY_STATUS GetBatteryStatus;
63+
EFI_BATTERY_CHARGING_CHARGE_BATTERY ChargeBattery;
64+
UINT32 Revision;
65+
EFI_BATTERY_CHARGING_GET_BATTERY_INFORMATION GetBatteryInformation;
66+
};
67+
68+
#endif
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef __DISPLAY_POWER_H__
2+
#define __DISPLAY_POWER_H__
3+
4+
#include <Uefi.h>
5+
6+
#define EFI_DISPLAY_POWER_PROTOCOL_GUID { \
7+
0xf352021d, 0x9593, 0x4432, { \
8+
0xbf, 0x4, 0x67, 0xb9, 0xf3, 0xb7, 0x60, 0x8 \
9+
} \
10+
}
11+
12+
extern EFI_GUID gEfiDisplayPowerProtocolGuid;
13+
14+
typedef struct _EFI_DISPLAY_POWER_PROTOCOL EFI_DISPLAY_POWER_PROTOCOL;
15+
16+
typedef enum _EFI_DISPLAY_POWER_STATE {
17+
EfiDisplayPowerStateUnknown = 0,
18+
EfiDisplayPowerStateOff,
19+
EfiDisplayPowerStateMaximum,
20+
} EFI_DISPLAY_POWER_STATE;
21+
22+
typedef EFI_STATUS (EFIAPI * EFI_DISPLAY_POWER_SETDISPLAYPOWERSTATE) (
23+
IN EFI_DISPLAY_POWER_PROTOCOL *This,
24+
IN EFI_DISPLAY_POWER_STATE PowerState
25+
);
26+
27+
typedef EFI_STATUS (EFIAPI * EFI_DISPLAY_POWER_GETDISPLAYPOWERSTATE) (
28+
IN EFI_DISPLAY_POWER_PROTOCOL *This,
29+
OUT EFI_DISPLAY_POWER_STATE *PowerState
30+
);
31+
32+
struct _EFI_DISPLAY_POWER_PROTOCOL {
33+
UINT32 Revision;
34+
EFI_DISPLAY_POWER_SETDISPLAYPOWERSTATE SetDisplayPowerState;
35+
EFI_DISPLAY_POWER_GETDISPLAYPOWERSTATE GetDisplayPowerState;
36+
};
37+
38+
#endif

0 commit comments

Comments
 (0)