| 1 |
/* init.c - initialize an ia64-based EFI system */ |
| 2 |
/* |
| 3 |
* GRUB -- GRand Unified Bootloader |
| 4 |
* Copyright (C) 2008 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/types.h> |
| 21 |
#include <grub/misc.h> |
| 22 |
#include <grub/mm.h> |
| 23 |
#include <grub/time.h> |
| 24 |
#include <grub/err.h> |
| 25 |
#include <grub/dl.h> |
| 26 |
#include <grub/kernel.h> |
| 27 |
#include <grub/efi/efi.h> |
| 28 |
#include <grub/loader.h> |
| 29 |
|
| 30 |
static grub_uint64_t divisor = 1; |
| 31 |
|
| 32 |
static grub_uint64_t |
| 33 |
get_itc (void) |
| 34 |
{ |
| 35 |
grub_uint64_t ret; |
| 36 |
asm volatile ("mov %0=ar.itc" : "=r" (ret)); |
| 37 |
return ret; |
| 38 |
} |
| 39 |
|
| 40 |
grub_uint64_t |
| 41 |
grub_rtc_get_time_ms (void) |
| 42 |
{ |
| 43 |
return get_itc () / divisor; |
| 44 |
} |
| 45 |
|
| 46 |
void |
| 47 |
grub_machine_init (void) |
| 48 |
{ |
| 49 |
grub_efi_event_t event; |
| 50 |
grub_uint64_t before, after; |
| 51 |
grub_efi_uintn_t idx; |
| 52 |
grub_efi_init (); |
| 53 |
|
| 54 |
grub_efi_system_table->boot_services->create_event (GRUB_EFI_EVT_TIMER, |
| 55 |
GRUB_EFI_TPL_CALLBACK, |
| 56 |
0, 0, &event); |
| 57 |
|
| 58 |
before = get_itc (); |
| 59 |
grub_efi_system_table->boot_services->set_timer (event, GRUB_EFI_TIMER_RELATIVE, |
| 60 |
200000); |
| 61 |
grub_efi_system_table->boot_services->wait_for_event (1, &event, &idx); |
| 62 |
after = get_itc (); |
| 63 |
grub_efi_system_table->boot_services->close_event (event); |
| 64 |
divisor = (after - before + 5) / 20; |
| 65 |
if (divisor == 0) |
| 66 |
divisor = 800000; |
| 67 |
grub_install_get_time_ms (grub_rtc_get_time_ms); |
| 68 |
} |
| 69 |
|
| 70 |
void |
| 71 |
grub_machine_fini (int flags) |
| 72 |
{ |
| 73 |
if (!(flags & GRUB_LOADER_FLAG_NORETURN)) |
| 74 |
return; |
| 75 |
|
| 76 |
grub_efi_fini (); |
| 77 |
|
| 78 |
if (!(flags & GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY)) |
| 79 |
grub_efi_memory_fini (); |
| 80 |
} |