2c31847bf6db77fab377c90e7ed36897439d6027
[grub.git] / grub-core / kern / efi / init.c
1 /* init.c - generic EFI initialization and finalization */
2 /*
3  *  GRUB  --  GRand Unified Bootloader
4  *  Copyright (C) 2006,2007  Free Software Foundation, Inc.
5  *
6  *  GRUB is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  GRUB is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include <grub/efi/efi.h>
21 #include <grub/efi/console.h>
22 #include <grub/efi/disk.h>
23 #include <grub/term.h>
24 #include <grub/misc.h>
25 #include <grub/env.h>
26 #include <grub/mm.h>
27 #include <grub/kernel.h>
28
29 grub_addr_t grub_modbase;
30
31 void
32 grub_efi_init (void)
33 {
34   grub_modbase = grub_efi_modules_addr ();
35   /* First of all, initialize the console so that GRUB can display
36      messages.  */
37   grub_console_init ();
38
39   /* Initialize the memory management system.  */
40   grub_efi_mm_init ();
41
42   efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
43               0, 0, 0, NULL);
44
45   grub_efidisk_init ();
46 }
47
48 void (*grub_efi_net_config) (grub_efi_handle_t hnd, 
49                              char **device,
50                              char **path);
51
52 void
53 grub_machine_get_bootlocation (char **device, char **path)
54 {
55   grub_efi_loaded_image_t *image = NULL;
56   char *p;
57
58   image = grub_efi_get_loaded_image (grub_efi_image_handle);
59   if (!image)
60     return;
61   *device = grub_efidisk_get_device_name (image->device_handle);
62   if (!*device && grub_efi_net_config)
63     {
64       grub_efi_net_config (image->device_handle, device, path);
65       return;
66     }
67
68   *path = grub_efi_get_filename (image->file_path);
69   if (*path)
70     {
71       /* Get the directory.  */
72       p = grub_strrchr (*path, '/');
73       if (p)
74         *p = '\0';
75     }
76 }
77
78 void
79 grub_efi_fini (void)
80 {
81   grub_efidisk_fini ();
82   grub_console_fini ();
83 }