Debian Codegraph @

grub-core/kern/loongarch64/efi/init.c

raw
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2023 Free Software Foundation, Inc.
4 *
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <grub/env.h>
20 #include <grub/kernel.h>
21 #include <grub/misc.h>
22 #include <grub/mm.h>
23 #include <grub/time.h>
24 #include <grub/efi/efi.h>
25 #include <grub/loader.h>
26
27 #define EFI_TIMER_PERIOD_MILLISECONDS(ms) ((grub_uint64_t)(ms * 10000))
28
29 static grub_uint64_t tmr;
30 static grub_efi_event_t tmr_evt;
31
32 static grub_uint64_t
33 grub_efi_get_time_ms (void)
34 {
35 return tmr;
36 }
37
38 static void
39 grub_loongson_increment_timer (grub_efi_event_t event __attribute__ ((unused)),
40 void *context __attribute__ ((unused)))
41 {
42 tmr += 10;
43 }
44
45 void
46 grub_machine_init (void)
47 {
48 grub_efi_boot_services_t *b;
49
50 grub_efi_init ();
51
52 b = grub_efi_system_table->boot_services;
53 b->create_event (GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
54 GRUB_EFI_TPL_CALLBACK, grub_loongson_increment_timer, NULL, &tmr_evt);
55 b->set_timer (tmr_evt, GRUB_EFI_TIMER_PERIODIC, EFI_TIMER_PERIOD_MILLISECONDS(10));
56
57 grub_install_get_time_ms (grub_efi_get_time_ms);
58 }
59
60 void
61 grub_machine_fini (int flags)
62 {
63 grub_efi_boot_services_t *b;
64
65 if (!(flags & GRUB_LOADER_FLAG_NORETURN))
66 return;
67
68 b = grub_efi_system_table->boot_services;
69
70 b->set_timer (tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
71 b->close_event (tmr_evt);
72
73 grub_efi_fini ();
74
75 if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY))
76 grub_efi_memory_fini ();
77 }