memtest86plus/boot/efi.h
Chao Li 97922cc4cf
Add LoongArch support (#410)
* lib/assert: Add LoongArch assert support

Added LoongArch break 3 assert instruction.

Signed-off-by: Chao Li <lichao@loongson.cn>

* lib/barrier: Add barrier method for LoongArch

Added LoongArch barriers in barrier_spin_wait and barrier_halt_wait
functions.

Signed-off-by: Chao Li <lichao@loognson.cn>

* lib/spinlock: Add LoongArch CPU pause

Because the LoongArch haven't pause instruction, using eight nops to
replace the pause.

Signed-off-by: Chao Li <lichao@loongson.cn>

* lib/string: Make LoongArch use the string function in the file

Since LoongArch GCC doesn't have built-in string functions, use the
string function instance in the sting.c

Signed-off-by: Chao Li <lichao@loongson.cn>

* lib/unistd: Add LoongArch CPU pause

Because the LoongArch haven't pause instruction, using eight nops to
replace the pause.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/acpi: Reduce the way of search RSDP for non-x86 ARCHs

Searching RSDP from legacy BIOS EDBA and reserved areas is available
only on i386 and x64.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/cache: Add LoongArch64 cache operations support

Added cache operations support for LoongArch64.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/cpuid: Add the compile limit

Make the `cpuid` function action only on i386/x64.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/heap: Add heap support for LoongArch64

LoongArch64 uses the low 256MB as the low memory.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/memrw: Add 8-bit and 16-bit memory operations

Added 8-bit and 16-bit memory access operations, which 8-bit uses
`movb` and 16-bit is `movw`.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/memrw: Add LoongArch memory access operations

Added 8/16/32/64-bit memory access operations for LoongArch64.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system: Add Loongson PCI vendor ID and Loongson 7A chipset EHCI workaround

1. Added Loongson PCI vendor ID.
2. Added Loongson 7A chipset ECHI workaround.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/io: Add LoongArch64 IO port operations

Added IO port operations for LoongArch64.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/reloc64: Add LoongArch64 relocations support

Added R_LARCH_RELATIVE and R_LARCH_NONE relocations support for
LoongArch64.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/serial: Add Loongson CPU serial port support

Add the serial port address perfix of Loongson CPU and obtain serial
port clock method.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/smbus: Rename smbus.c to i2c_x86.c

Renamed the smbus.c to i2c_x86.c in i386 and x64 platforms.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/smp: Add LoongArch SMP support

Added LoongArch multi-core support and a way of map to node numbers if
the NUMA is enabled.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/timers: Add LoongArch supports

In LoongArch, there is a stable counter that is independent of other
clocks, it like the TSC in x64. Using it to count the ticks per
millisecond.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/tsc: Add LoongArch support

Usually the frequency of stable counter is not same to CPU frequency, so
using the performance counter for the delay operations.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/usbhcd: Add LoongArch MMIO perfix

Added LoongArch64 MMIO address perfix, use for address the PCI memory
space.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/usbhcd: Add Loongson 7A2000 chipset OHCI BAR offset fix

If the BAR address is not fixed for the Loongson 7A2000 OHCI controller,
some prots will not be usable, This change currently only affects the
LoongArch platform.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system: Add the way to IO access via MMIO

Usually, it is access the IO like PCI IO via MMIO on non-X86 ARCHs, so
a method to access IO via MMIO is added.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system: Add the way to access PCI memory space via MMIO

Some uniformly address ARCHs access the PCI memory depended the MMIO, so
the method to access PCI memory via MMIO is added.

Signed-off-by: Chao Li <lichao@loongson.cn>

* app: Add LoongArch version support

Reduced the version field by two characters to support ARCH name
abbreviations with more than three characters, and added "la64" ARCH
version display.

Singed-off-by: Chao Li <lichao@loongson.cn>

* test/block_move: Add block move test via ASM for LoongArch

Add block move test inline assembly instance for LoongArch.

Signed-off-by: Chao Li <lichao@loongson.cn>

* test/mov_inv_fixed: Add LoongArch ASM version word write operation

Add LoongArch ASM version word write cycle if it uses the HAND_OPTIMISED.

Signed-off-by: Chao Li <lichao@loongson.cn>

* boot: Adjust the AP stack size for LoongArch

LoongArch exception will store all of the GP, FP and CSR on stack, it
need more stack size, make LoongArch AP using 2KB stack size.

Signed-off-by: Chao Li <lichao@loongson.cn>

* boot/efisetup: Add LoongArch CPU halt instruction

Add "idle 0" for LoongArch

Signed-off-by: Chao Li <lichao@loongson.cn>

* boot/efi: Limiting the ms_abi using scope

Make the ms_abi only work on i386 and x64.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/imc/loongson: Add Loongson LoongArch IMC support

Added the Loongson LoongArch CPU IMC instance, support read out the IMC
sequence, currently only supports reading MC0.

Signed-off-by: Chao Li <lichao@loongson.cn>

* app/loongarch: Add intrrupt handler for LoongArch

Added the LoongArch IRQ handler support.

Signed-off-by: Chao Li <lichao@loongson.cn>

* system/loongarch: Add LoongArch ARCH specific files

Added LoongArch ARCH specific files: cpuid.c, cpuinfo.c, hwctrl.c,
memctrl.c, temperature.c, vmem.c, registers.h

They use the same pubilc API for i386 and x64 platforms.

Signed-off-by: Chao Li <lichao@loongson.cn>

* boot: Add LoongArch startup and header

Added the header.S and startup64.S for LoongArch, CPU works on:
1. Page mode.
2. Load and store is cacheable.
3. Instructions is cacheable.
4. DMWn 0 and 1 is used.
5. To access non-cacheable areas, use the perfix 0x8000000000000000.

Signed-off Chao Li <lichao@loongson.cn>

* build64/la64: Add LoongArch64 build files

Add infrastructure files to build memtest86 plus for LoongArch64
platform.

Signed-off-by: Chao Li <lichao@loongson.cn>

* workflows: Add LoongArch64 CI supports

Adjust workflow logci, remvoe 32 and 64 wordsize, replace with "i386,
x86_64 and la64", add LoongArch64 build CI check.

Signed-off-by: Chao Li <lichao@loongson.cn>

---------

Signed-off-by: Chao Li <lichao@loongson.cn>
Signed-off-by: Chao Li <lichao@loognson.cn>
2024-08-30 13:38:46 +02:00

310 lines
9.7 KiB
C

// SPDX-License-Identifier: GPL-2.0
#ifndef EFI_H
#define EFI_H
/**
* \file
*
* Provides definitions for accessing the UEFI boot services and configuration
* tables.
*
*//*
* Copyright (C) 2020-2022 Martin Whitaker.
*/
#include <stdint.h>
#if (ARCH_BITS == 64)
#define NATIVE_MSB UINT64_C(0x8000000000000000)
#else
#define NATIVE_MSB 0x80000000
#endif
/**
* EFI_STATUS values.
*/
#define EFI_SUCCESS 0
#define EFI_INVALID_PARAMETER (NATIVE_MSB | 2)
#define EFI_UNSUPPORTED (NATIVE_MSB | 3)
#define EFI_BUFFER_TOO_SMALL (NATIVE_MSB | 5)
#define EFI_NOT_READY (NATIVE_MSB | 6)
#define EFI_NOT_FOUND (NATIVE_MSB | 14)
#define EFI_ABORTED (NATIVE_MSB | 21)
/**
* EFI_LOCATE_SEARCH_TYPE values.
*/
#define EFI_LOCATE_BY_PROTOCOL 2
/**
* EFI_ALLOCATE_TYPE values.
*/
#define EFI_ALLOCATE_MAX_ADDRESS 1
#define EFI_ALLOCATE_ADDRESS 2
/**
* EFI_MEMORY_TYPE values.
*/
#define EFI_LOADER_CODE 1
#define EFI_LOADER_DATA 2
#define EFI_BOOT_SERVICES_CODE 3
#define EFI_BOOT_SERVICES_DATA 4
#define EFI_CONVENTIONAL_MEMORY 7
#define EFI_ACPI_RECLAIM_MEMORY 9
/**
* EFI_RESET_TYPE values.
*/
#define EFI_RESET_COLD 0
#define EFI_RESET_WARM 1
#define EFI_RESET_SHUTDOWN 2
/**
* EFI_GRAPHICS_PIXEL_FORMAT values.
*/
#define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
#define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
#define PIXEL_BIT_MASK 2
#define PIXEL_BLT_ONLY 3
#define EFI_SYSTEM_TABLE_SIGNATURE UINT64_C(0x5453595320494249)
#define EFI_RUNTIME_SERVICES_SIGNATURE UINT64_C(0x5652453544e5552)
#if defined(__x86_64__) || defined(__i386__)
#define efiapi __attribute__((ms_abi))
#else
#define efiapi
#endif
#if (ARCH_BITS == 64)
typedef uint64_t uintn_t;
#else
typedef uint32_t uintn_t;
#endif
typedef void * efi_handle_t;
typedef uintn_t efi_status_t;
typedef uint64_t efi_phys_addr_t;
typedef uint64_t efi_virt_addr_t;
typedef uint16_t efi_char16_t;
typedef struct {
uint32_t a;
uint16_t b;
uint16_t c;
uint8_t d[8];
} efi_guid_t;
typedef struct {
uint32_t type;
uint32_t pad;
efi_phys_addr_t phys_addr;
efi_virt_addr_t virt_addr;
uint64_t num_pages;
uint64_t attribute;
} efi_memory_desc_t;
typedef struct {
uint32_t red_mask;
uint32_t green_mask;
uint32_t blue_mask;
uint32_t rsvd_mask;
} efi_pixel_bitmask_t;
typedef struct {
uint32_t version;
uint32_t h_resolution;
uint32_t v_resolution;
int pixel_format;
efi_pixel_bitmask_t pixel_info;
uint32_t pixels_per_scan_line;
} efi_gop_mode_info_t;
typedef struct {
uint32_t max_mode;
uint32_t mode;
efi_gop_mode_info_t *info;
uintn_t info_size;
efi_phys_addr_t frame_buffer_base;
uintn_t frame_buffer_size;
} efi_gop_mode_t;
typedef struct efi_graphics_output_s {
efi_status_t (efiapi *query_mode)(struct efi_graphics_output_s *, uint32_t, uintn_t *, efi_gop_mode_info_t **);
efi_status_t (efiapi *set_mode)(struct efi_graphics_output_s *, uint32_t);
void *blt;
efi_gop_mode_t *mode;
} efi_graphics_output_t;
typedef struct {
uint64_t signature;
uint32_t revision;
uint32_t header_size;
uint32_t crc32;
uint32_t reserved;
} efi_table_header_t;
typedef struct {
uint16_t scan_code;
efi_char16_t ch;
} efi_input_key_t;
typedef struct efi_simple_text_in_s {
void *reset;
efi_status_t (efiapi *read_key_stroke)(struct efi_simple_text_in_s *, efi_input_key_t *);
void *test_string;
} efi_simple_text_in_t;
typedef struct efi_simple_text_out_s {
void *reset;
efi_status_t (efiapi *output_string)(struct efi_simple_text_out_s *, efi_char16_t *);
void *test_string;
} efi_simple_text_out_t;
typedef struct {
efi_table_header_t header;
void *raise_tpl;
void *restore_tpl;
efi_status_t (efiapi *allocate_pages)(int, int, uintn_t, efi_phys_addr_t *);
efi_status_t (efiapi *free_pages)(efi_phys_addr_t, uintn_t);
efi_status_t (efiapi *get_memory_map)(uintn_t *, void *, uintn_t *, uintn_t *, uint32_t *);
efi_status_t (efiapi *allocate_pool)(int, uintn_t, void **);
efi_status_t (efiapi *free_pool)(void *);
void *create_event;
void *set_timer;
void *wait_for_event;
void *signal_event;
void *close_event;
void *check_event;
void *install_protocol_interface;
void *reinstall_protocol_interface;
void *uninstall_protocol_interface;
efi_status_t (efiapi *handle_protocol)(efi_handle_t, efi_guid_t *, void **);
void *reserved;
void *register_protocol_notify;
efi_status_t (efiapi *locate_handle)(int, efi_guid_t *, void *, uintn_t *, efi_handle_t *);
void *locate_device_path;
efi_status_t (efiapi *install_configuration_table)(efi_guid_t *, void *);
void *load_image;
void *start_image;
void *exit;
void *unload_image;
efi_status_t (efiapi *exit_boot_services)(efi_handle_t, uintn_t);
void *get_next_monotonic_count;
void *stall;
void *set_watchdog_timer;
void *connect_controller;
efi_status_t (efiapi *disconnect_controller)(efi_handle_t, efi_handle_t, efi_handle_t);
void *open_protocol;
void *close_protocol;
void *open_protocol_information;
void *protocols_per_handle;
void *locate_handle_buffer;
efi_status_t (efiapi *locate_protocol)(efi_guid_t *, void *, void **);
void *install_multiple_protocol_interfaces;
void *uninstall_multiple_protocol_interfaces;
void *calculate_crc32;
void *copy_mem;
void *set_mem;
void *create_event_ex;
} efi_boot_services_t;
typedef struct {
efi_table_header_t header;
unsigned long get_time;
unsigned long set_time;
unsigned long get_wakeup_time;
unsigned long set_wakeup_time;
unsigned long set_virtual_address_map;
unsigned long convert_pointer;
unsigned long get_variable;
unsigned long get_next_variable;
unsigned long set_variable;
unsigned long get_next_high_mono_count;
efi_status_t (efiapi *reset_system)(int, int, int);
unsigned long update_capsule;
unsigned long query_capsule_caps;
unsigned long query_variable_info;
} efi_runtime_services_t;
typedef struct {
efi_guid_t guid;
uint32_t table;
} efi32_config_table_t;
typedef struct {
efi_guid_t guid;
uint64_t table;
} efi64_config_table_t;
typedef struct {
efi_guid_t guid;
void *table;
} efi_config_table_t;
typedef struct {
efi_table_header_t header;
uint32_t fw_vendor;
uint32_t fw_revision;
uint32_t con_in_handle;
uint32_t con_in;
uint32_t con_out_handle;
uint32_t con_out;
uint32_t std_err_handle;
uint32_t std_err;
uint32_t runtime_services;
uint32_t boot_services;
uint32_t num_config_tables;
uint32_t config_tables;
} efi32_system_table_t;
typedef struct {
efi_table_header_t header;
uint64_t fw_vendor;
uint32_t fw_revision;
uint32_t pad;
uint64_t con_in_handle;
uint64_t con_in;
uint64_t con_out_handle;
uint64_t con_out;
uint64_t std_err_handle;
uint64_t std_err;
uint64_t runtime_services;
uint64_t boot_services;
uint64_t num_config_tables;
uint64_t config_tables;
} efi64_system_table_t;
typedef struct {
efi_table_header_t header;
efi_char16_t *fw_vendor;
uint32_t fw_revision;
efi_handle_t con_in_handle;
efi_simple_text_in_t *con_in;
efi_handle_t con_out_handle;
efi_simple_text_out_t *con_out;
efi_handle_t std_err_handle;
efi_simple_text_out_t *std_err;
efi_runtime_services_t *runtime_services;
efi_boot_services_t *boot_services;
uintn_t num_config_tables;
efi_config_table_t *config_tables;
} efi_system_table_t;
typedef struct {
uint32_t revision;
efi_handle_t parent_handle;
efi_system_table_t *system_table;
efi_handle_t device_handle;
void *file_path;
void *reserved;
uint32_t load_options_size;
void *load_options;
void *image_base;
uint64_t image_size;
int image_code_type;
int image_data_type;
void *unload;
} efi_loaded_image_t;
#endif /* EFI_H */