Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Menu-driven UEFI Variable maintenance |
| 4 | * |
| 5 | * Copyright (c) 2022 Masahisa Kojima, Linaro Limited |
| 6 | */ |
| 7 | |
| 8 | #ifndef _EFI_CONFIG_H |
| 9 | #define _EFI_CONFIG_H |
| 10 | |
| 11 | #include <efi_loader.h> |
Masahisa Kojima | fc811d1 | 2023-01-24 15:56:13 +0900 | [diff] [blame] | 12 | #include <menu.h> |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 13 | |
| 14 | #define EFICONFIG_ENTRY_NUM_MAX 99 |
Masahisa Kojima | bb052b9 | 2022-09-12 17:33:51 +0900 | [diff] [blame] | 15 | #define EFICONFIG_VOLUME_PATH_MAX 512 |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 16 | #define EFICONFIG_FILE_PATH_MAX 512 |
| 17 | #define EFICONFIG_FILE_PATH_BUF_SIZE (EFICONFIG_FILE_PATH_MAX * sizeof(u16)) |
| 18 | |
Masahisa Kojima | fc811d1 | 2023-01-24 15:56:13 +0900 | [diff] [blame] | 19 | extern const char *eficonfig_menu_desc; |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 20 | typedef efi_status_t (*eficonfig_entry_func)(void *data); |
| 21 | |
| 22 | /** |
| 23 | * struct eficonfig_entry - menu entry structure |
| 24 | * |
| 25 | * @num: menu entry index |
| 26 | * @title: title of entry |
| 27 | * @key: unique key |
| 28 | * @efi_menu: pointer to the menu structure |
| 29 | * @func: callback function to be called when this entry is selected |
| 30 | * @data: data to be passed to the callback function, caller must free() this pointer |
| 31 | * @list: list structure |
| 32 | */ |
| 33 | struct eficonfig_entry { |
| 34 | u32 num; |
| 35 | char *title; |
| 36 | char key[3]; |
| 37 | struct efimenu *efi_menu; |
| 38 | eficonfig_entry_func func; |
| 39 | void *data; |
| 40 | struct list_head list; |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * struct efimenu - efi menu structure |
| 45 | * |
| 46 | * @delay: delay for autoboot |
| 47 | * @active: active menu entry index |
| 48 | * @count: total count of menu entry |
| 49 | * @menu_header: menu header string |
Masahisa Kojima | fc811d1 | 2023-01-24 15:56:13 +0900 | [diff] [blame] | 50 | * @menu_desc: menu description string |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 51 | * @list: menu entry list structure |
Masahisa Kojima | a93282c | 2023-01-24 15:56:15 +0900 | [diff] [blame^] | 52 | * @start: top menu index to draw |
| 53 | * @end: bottom menu index to draw |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 54 | */ |
| 55 | struct efimenu { |
| 56 | int delay; |
| 57 | int active; |
| 58 | int count; |
| 59 | char *menu_header; |
Masahisa Kojima | fc811d1 | 2023-01-24 15:56:13 +0900 | [diff] [blame] | 60 | const char *menu_desc; |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 61 | struct list_head list; |
Masahisa Kojima | a93282c | 2023-01-24 15:56:15 +0900 | [diff] [blame^] | 62 | int start; |
| 63 | int end; |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * struct eficonfig_item - structure to construct eficonfig_entry |
| 68 | * |
| 69 | * @title: title of entry |
| 70 | * @func: callback function to be called when this entry is selected |
| 71 | * @data: data to be passed to the callback function |
| 72 | */ |
| 73 | struct eficonfig_item { |
| 74 | char *title; |
| 75 | eficonfig_entry_func func; |
| 76 | void *data; |
| 77 | }; |
| 78 | |
| 79 | /** |
| 80 | * struct eficonfig_select_file_info - structure to be used for file selection |
| 81 | * |
| 82 | * @current_volume: pointer to the efi_simple_file_system_protocol |
| 83 | * @dp_volume: pointer to device path of the selected device |
| 84 | * @current_path: pointer to the selected file path string |
| 85 | * @filepath_list: list_head structure for file path list |
| 86 | * @file_selectred: flag indicates file selecting status |
| 87 | */ |
| 88 | struct eficonfig_select_file_info { |
| 89 | struct efi_simple_file_system_protocol *current_volume; |
| 90 | struct efi_device_path *dp_volume; |
| 91 | u16 *current_path; |
| 92 | struct list_head filepath_list; |
| 93 | bool file_selected; |
| 94 | }; |
| 95 | |
| 96 | void eficonfig_print_msg(char *msg); |
Masahisa Kojima | fc811d1 | 2023-01-24 15:56:13 +0900 | [diff] [blame] | 97 | void eficonfig_print_entry(void *data); |
| 98 | void eficonfig_display_statusline(struct menu *m); |
| 99 | char *eficonfig_choice_entry(void *data); |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 100 | void eficonfig_destroy(struct efimenu *efi_menu); |
| 101 | efi_status_t eficonfig_process_quit(void *data); |
Masahisa Kojima | fc811d1 | 2023-01-24 15:56:13 +0900 | [diff] [blame] | 102 | efi_status_t eficonfig_process_common(struct efimenu *efi_menu, |
| 103 | char *menu_header, const char *menu_desc, |
| 104 | void (*display_statusline)(struct menu *), |
| 105 | void (*item_data_print)(void *), |
| 106 | char *(*item_choice)(void *)); |
Masahisa Kojima | 0be1b2a | 2022-11-20 09:21:13 +0900 | [diff] [blame] | 107 | efi_status_t eficonfig_process_select_file(void *data); |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 108 | efi_status_t eficonfig_get_unused_bootoption(u16 *buf, |
| 109 | efi_uintn_t buf_size, u32 *index); |
| 110 | efi_status_t eficonfig_append_bootorder(u16 index); |
Masahisa Kojima | 767a9e6 | 2022-09-12 17:33:54 +0900 | [diff] [blame] | 111 | efi_status_t eficonfig_generate_media_device_boot_option(void); |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 112 | |
Masahisa Kojima | 6be1d1f | 2022-11-20 09:21:14 +0900 | [diff] [blame] | 113 | efi_status_t eficonfig_append_menu_entry(struct efimenu *efi_menu, |
| 114 | char *title, eficonfig_entry_func func, |
| 115 | void *data); |
| 116 | efi_status_t eficonfig_append_quit_entry(struct efimenu *efi_menu); |
Masahisa Kojima | 3360183a | 2022-11-20 09:21:16 +0900 | [diff] [blame] | 117 | struct efi_device_path *eficonfig_create_device_path(struct efi_device_path *dp_volume, |
| 118 | u16 *current_path); |
Masahisa Kojima | cbdbcb4 | 2022-11-20 09:21:18 +0900 | [diff] [blame] | 119 | void *eficonfig_create_fixed_menu(const struct eficonfig_item *items, int count); |
| 120 | #ifdef CONFIG_EFI_SECURE_BOOT |
| 121 | efi_status_t eficonfig_process_secure_boot_config(void *data); |
| 122 | #endif |
Masahisa Kojima | 6be1d1f | 2022-11-20 09:21:14 +0900 | [diff] [blame] | 123 | |
Masahisa Kojima | c5ff0a0 | 2022-09-12 17:33:50 +0900 | [diff] [blame] | 124 | #endif |