build static libs
[AROS.git] / rom / efi / efi_init.c
blobf3ae6341b5811bf4d912d72373714760ca73f4d7
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));
13 return FALSE;
16 /* TODO: Check CRC */
18 return TRUE;
21 AROS_INTH1(static ResetHandler, struct EFIBase *, EFIBase)
23 AROS_INTFUNC_INIT
25 UBYTE action = EFIBase->reset_handler.is_Node.ln_Type;
26 IPTR efiAction;
28 switch (action)
30 case SD_ACTION_COLDREBOOT:
31 efiAction = EFI_Reset_Cold;
32 break;
34 case SD_ACTION_POWEROFF:
35 efiAction = EFI_Reset_Shutdown;
36 break;
38 default:
39 /* Unknown action */
40 return FALSE;
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. */
47 return FALSE;
49 AROS_INTFUNC_EXIT
52 static int efi_Init(struct EFIBase *EFIBase)
54 APTR KernelBase;
55 struct TagItem *tag;
57 D(bug("[EFI] Entered efi_Init() at 0x%p\n", efi_Init));
59 KernelBase = OpenResource("kernel.resource");
60 if (!KernelBase)
62 return FALSE;
65 tag = LibFindTagItem(KRN_EFISystemTable, KrnGetBootInfo());
66 if (!tag)
68 D(bug("[EFI] No EFI system table from the bootstrap!\n"));
70 return FALSE;
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"));
79 return FALSE;
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);
94 return TRUE;
97 ADD2INITLIB(efi_Init, 0);