2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
7 #include <resources/efi.h>
8 #include <proto/arossupport.h>
9 #include <proto/kernel.h>
11 #include "efi_intern.h"
13 static BOOL
CheckTable(struct EFI_TableHeader
*t
, UQUAD sig
)
15 if (t
->Signature
!= sig
)
17 D(bug("[EFI] Table 0x%p bad signature (has 0x%016llX, wanted 0x%016llX)\n", t
, t
->Signature
, sig
));
26 AROS_INTH1(static ResetHandler
, struct EFIBase
*, EFIBase
)
30 UBYTE action
= EFIBase
->reset_handler
.is_Node
.ln_Type
;
35 case SD_ACTION_COLDREBOOT
:
36 efiAction
= EFI_Reset_Cold
;
39 case SD_ACTION_POWEROFF
:
40 efiAction
= EFI_Reset_Shutdown
;
48 /* Use EFI runtime services to perform the action */
49 EFIBase
->Runtime
->ResetSystem(efiAction
, 0, 0, NULL
);
51 /* Shut up the compiler, we should never reach this. */
57 static int efi_Init(struct EFIBase
*EFIBase
)
62 D(bug("[EFI] Entered efi_Init() at 0x%p\n", efi_Init
));
64 KernelBase
= OpenResource("kernel.resource");
70 tag
= LibFindTagItem(KRN_EFISystemTable
, KrnGetBootInfo());
73 D(bug("[EFI] No EFI system table from the bootstrap!\n"));
78 EFIBase
->System
= (struct EFI_SystemTable
*)tag
->ti_Data
;
79 D(bug("Found EFI system table at 0x%p\n", EFIBase
->System
));
81 if (!CheckTable(&EFIBase
->System
->Hdr
, EFI_SYSTEM_TABLE_SIGNATURE
))
83 D(bug("[EFI] System table broken\n"));
87 if (CheckTable(&EFIBase
->System
->RuntimeServices
->Hdr
, EFI_RUNTIME_SERVICES_SIGNATURE
))
89 EFIBase
->Runtime
= EFIBase
->System
->RuntimeServices
;
90 D(bug("[EFI] Valid runtime services table at 0x%p\n", EFIBase
->Runtime
));
92 /* Install EFI reset/power-off mechanism */
93 EFIBase
->reset_handler
.is_Node
.ln_Pri
= -56;
94 EFIBase
->reset_handler
.is_Node
.ln_Name
= "EFI reset";
95 EFIBase
->reset_handler
.is_Code
= (VOID_FUNC
)ResetHandler
;
96 EFIBase
->reset_handler
.is_Data
= EFIBase
;
97 AddResetCallback(&EFIBase
->reset_handler
);
103 ADD2INITLIB(efi_Init
, 0);