Tidy up code for performing reset via the EFI runtime sevices.
Make this entirely local to hwctrl.c.
This commit is contained in:
parent
a14a6b8e65
commit
e0c0cd55c6
|
@ -91,8 +91,6 @@ static int test_stage = 0;
|
||||||
// Public Variables
|
// Public Variables
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
efi_info_t saved_efi_info;
|
|
||||||
|
|
||||||
// These are exposed in test.h.
|
// These are exposed in test.h.
|
||||||
|
|
||||||
uint8_t chunk_index[MAX_CPUS];
|
uint8_t chunk_index[MAX_CPUS];
|
||||||
|
@ -199,6 +197,8 @@ static void global_init(void)
|
||||||
|
|
||||||
floppy_off();
|
floppy_off();
|
||||||
|
|
||||||
|
hwctrl_init();
|
||||||
|
|
||||||
cpuid_init();
|
cpuid_init();
|
||||||
|
|
||||||
screen_init();
|
screen_init();
|
||||||
|
@ -277,11 +277,6 @@ static void global_init(void)
|
||||||
reboot();
|
reboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_params_t *boot_params = (boot_params_t *)boot_params_addr;
|
|
||||||
if(boot_params->efi_info.loader_signature){
|
|
||||||
saved_efi_info = boot_params->efi_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
start_barrier = smp_alloc_barrier(1);
|
start_barrier = smp_alloc_barrier(1);
|
||||||
run_barrier = smp_alloc_barrier(1);
|
run_barrier = smp_alloc_barrier(1);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
// Copyright (C) 2020 Martin Whitaker.
|
// Copyright (C) 2020-2022 Martin Whitaker.
|
||||||
//
|
//
|
||||||
// Derived from an extract of memtest86+ lib.c:
|
// Derived from an extract of memtest86+ lib.c:
|
||||||
//
|
//
|
||||||
|
@ -14,39 +14,42 @@
|
||||||
#include "bootparams.h"
|
#include "bootparams.h"
|
||||||
#include "efi.h"
|
#include "efi.h"
|
||||||
|
|
||||||
#include "hwctrl.h"
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
#include "unistd.h"
|
#include "unistd.h"
|
||||||
|
|
||||||
|
#include "hwctrl.h"
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Private Variables
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static efi_runtime_services_t *efi_rs_table = NULL;
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Public Functions
|
// Public Functions
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
extern efi_info_t saved_efi_info;
|
void hwctrl_init(void)
|
||||||
|
|
||||||
static void efi_reset(uint8_t reset_type)
|
|
||||||
{
|
{
|
||||||
static efi_runtime_services_t *rs_table = NULL;
|
boot_params_t *boot_params = (boot_params_t *)boot_params_addr;
|
||||||
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
if (saved_efi_info.loader_signature == EFI64_LOADER_SIGNATURE) {
|
if (boot_params->efi_info.loader_signature == EFI64_LOADER_SIGNATURE) {
|
||||||
uintptr_t system_table_addr = ((uintptr_t)saved_efi_info.sys_tab_hi << 32) | saved_efi_info.sys_tab;
|
uintptr_t system_table_addr = (uintptr_t)boot_params->efi_info.sys_tab_hi << 32 | boot_params->efi_info.sys_tab;
|
||||||
if (system_table_addr != 0) {
|
if (system_table_addr != 0) {
|
||||||
efi64_system_table_t *sys_table = (efi64_system_table_t *)system_table_addr;
|
efi64_system_table_t *sys_table = (efi64_system_table_t *)system_table_addr;
|
||||||
rs_table = (efi_runtime_services_t *)sys_table->runtime_services;
|
efi_rs_table = (efi_runtime_services_t *)sys_table->runtime_services;
|
||||||
rs_table->reset_system(reset_type, 0, 0);
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (boot_params->efi_info.loader_signature == EFI32_LOADER_SIGNATURE) {
|
||||||
|
uintptr_t system_table_addr = boot_params->efi_info.sys_tab;
|
||||||
|
if (system_table_addr != 0) {
|
||||||
|
efi32_system_table_t *sys_table = (efi32_system_table_t *)system_table_addr;
|
||||||
|
efi_rs_table = (efi_runtime_services_t *)(uintptr_t)sys_table->runtime_services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (saved_efi_info.loader_signature == EFI32_LOADER_SIGNATURE) {
|
|
||||||
uintptr_t system_table_addr = saved_efi_info.sys_tab;
|
|
||||||
if (system_table_addr != 0) {
|
|
||||||
efi32_system_table_t *sys_table = (efi32_system_table_t *)system_table_addr;
|
|
||||||
rs_table = (efi_runtime_services_t *)(uintptr_t)sys_table->runtime_services;
|
|
||||||
rs_table->reset_system(reset_type, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void reboot(void)
|
void reboot(void)
|
||||||
|
@ -59,8 +62,8 @@ void reboot(void)
|
||||||
usleep(50);
|
usleep(50);
|
||||||
|
|
||||||
// If we have UEFI, try EFI reset service
|
// If we have UEFI, try EFI reset service
|
||||||
if(saved_efi_info.loader_signature) {
|
if (efi_rs_table != NULL) {
|
||||||
efi_reset(EFI_RESET_COLD);
|
efi_rs_table->reset_system(EFI_RESET_COLD, 0, 0);
|
||||||
usleep(1000000);
|
usleep(1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +71,7 @@ void reboot(void)
|
||||||
outb(0xfe, 0x64);
|
outb(0xfe, 0x64);
|
||||||
usleep(150000);
|
usleep(150000);
|
||||||
|
|
||||||
if(!saved_efi_info.loader_signature) {
|
if (efi_rs_table == NULL) {
|
||||||
// In last resort, (very) obsolete reboot method using BIOS
|
// In last resort, (very) obsolete reboot method using BIOS
|
||||||
*((uint16_t *)0x472) = 0x1234;
|
*((uint16_t *)0x472) = 0x1234;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
* Copyright (C) 2020-2022 Martin Whitaker.
|
* Copyright (C) 2020-2022 Martin Whitaker.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialises the hardware control interface.
|
||||||
|
*/
|
||||||
|
void hwctrl_init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reboots the machine.
|
* Reboots the machine.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue