1 #include <aros/debug.h>
2 #include <resources/efi.h>
3 #include <proto/arossupport.h>
4 #include <proto/kernel.h>
6 #include "efi_intern.h"
8 static BOOL
CheckTable(struct EFI_TableHeader
*t
, UQUAD sig
)
10 if (t
->Signature
!= sig
)
12 D(bug("[EFI] Table 0x%p bad signature (has 0x%016llX, wanted 0x%016llX)\n", t
, t
->Signature
, sig
));
21 AROS_INTH1(static ResetHandler
, struct EFIBase
*, EFIBase
)
25 UBYTE action
= EFIBase
->reset_handler
.is_Node
.ln_Type
;
30 case SD_ACTION_COLDREBOOT
:
31 efiAction
= EFI_Reset_Cold
;
34 case SD_ACTION_POWEROFF
:
35 efiAction
= EFI_Reset_Shutdown
;
43 /* Use EFI runtime services to perform the action */
44 EFIBase
->Runtime
->ResetSystem(efiAction
, 0, 0, NULL
);
46 /* Shut up the compiler, we should never reach this. */
52 static int efi_Init(struct EFIBase
*EFIBase
)
57 D(bug("[EFI] Entered efi_Init() at 0x%p\n", efi_Init
));
59 KernelBase
= OpenResource("kernel.resource");
65 tag
= LibFindTagItem(KRN_EFISystemTable
, KrnGetBootInfo());
68 D(bug("[EFI] No EFI system table from the bootstrap!\n"));
73 EFIBase
->System
= (struct EFI_SystemTable
*)tag
->ti_Data
;
74 D(bug("Found EFI system table at 0x%p\n", EFIBase
->System
));
76 if (!CheckTable(&EFIBase
->System
->Hdr
, EFI_SYSTEM_TABLE_SIGNATURE
))
78 D(bug("[EFI] System table broken\n"));
82 if (CheckTable(&EFIBase
->System
->RuntimeServices
->Hdr
, EFI_RUNTIME_SERVICES_SIGNATURE
))
84 EFIBase
->Runtime
= EFIBase
->System
->RuntimeServices
;
85 D(bug("[EFI] Valid runtime services table at 0x%p\n", EFIBase
->Runtime
));
87 /* Install EFI reset/power-off mechanism */
88 EFIBase
->reset_handler
.is_Node
.ln_Pri
= -56;
89 EFIBase
->reset_handler
.is_Code
= (VOID_FUNC
)ResetHandler
;
90 EFIBase
->reset_handler
.is_Data
= EFIBase
;
91 AddResetCallback(&EFIBase
->reset_handler
);
97 ADD2INITLIB(efi_Init
, 0);