Tom Rini | 70df9d6 | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 2 | /* |
| 3 | * EFI application runtime services |
| 4 | * |
| 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <dm.h> |
Alexander Graf | 46c1514 | 2018-06-18 17:23:11 +0200 | [diff] [blame] | 11 | #include <elf.h> |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 12 | #include <efi_loader.h> |
| 13 | #include <rtc.h> |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 14 | |
| 15 | /* For manual relocation support */ |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 18 | struct efi_runtime_mmio_list { |
| 19 | struct list_head link; |
| 20 | void **ptr; |
| 21 | u64 paddr; |
| 22 | u64 len; |
| 23 | }; |
| 24 | |
| 25 | /* This list contains all runtime available mmio regions */ |
| 26 | LIST_HEAD(efi_runtime_mmio); |
| 27 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 28 | static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 29 | |
Simon Glass | fff89d4 | 2018-06-11 23:26:40 -0600 | [diff] [blame] | 30 | /* |
Heinrich Schuchardt | 1112154 | 2018-09-03 19:29:41 +0200 | [diff] [blame] | 31 | * TODO(sjg@chromium.org): These defines and structures should come from the ELF |
| 32 | * header for each architecture (or a generic header) rather than being repeated |
| 33 | * here. |
Simon Glass | fff89d4 | 2018-06-11 23:26:40 -0600 | [diff] [blame] | 34 | */ |
Alexander Graf | 0fe5192 | 2018-06-18 17:23:08 +0200 | [diff] [blame] | 35 | #if defined(__aarch64__) |
Alexander Graf | 46c1514 | 2018-06-18 17:23:11 +0200 | [diff] [blame] | 36 | #define R_RELATIVE R_AARCH64_RELATIVE |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 37 | #define R_MASK 0xffffffffULL |
| 38 | #define IS_RELA 1 |
Alexander Graf | 0fe5192 | 2018-06-18 17:23:08 +0200 | [diff] [blame] | 39 | #elif defined(__arm__) |
Alexander Graf | 46c1514 | 2018-06-18 17:23:11 +0200 | [diff] [blame] | 40 | #define R_RELATIVE R_ARM_RELATIVE |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 41 | #define R_MASK 0xffULL |
Heinrich Schuchardt | 56e82be | 2018-10-13 20:52:08 -0700 | [diff] [blame] | 42 | #elif defined(__i386__) |
Simon Glass | cdfe696 | 2016-09-25 15:27:35 -0600 | [diff] [blame] | 43 | #define R_RELATIVE R_386_RELATIVE |
| 44 | #define R_MASK 0xffULL |
Heinrich Schuchardt | 56e82be | 2018-10-13 20:52:08 -0700 | [diff] [blame] | 45 | #elif defined(__x86_64__) |
| 46 | #define R_RELATIVE R_X86_64_RELATIVE |
| 47 | #define R_MASK 0xffffffffULL |
| 48 | #define IS_RELA 1 |
Alexander Graf | 0fe5192 | 2018-06-18 17:23:08 +0200 | [diff] [blame] | 49 | #elif defined(__riscv) |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 50 | #define R_RELATIVE R_RISCV_RELATIVE |
| 51 | #define R_MASK 0xffULL |
| 52 | #define IS_RELA 1 |
| 53 | |
| 54 | struct dyn_sym { |
| 55 | ulong foo1; |
| 56 | ulong addr; |
| 57 | u32 foo2; |
| 58 | u32 foo3; |
| 59 | }; |
Alexander Graf | 0fe5192 | 2018-06-18 17:23:08 +0200 | [diff] [blame] | 60 | #if (__riscv_xlen == 32) |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 61 | #define R_ABSOLUTE R_RISCV_32 |
| 62 | #define SYM_INDEX 8 |
Alexander Graf | 0fe5192 | 2018-06-18 17:23:08 +0200 | [diff] [blame] | 63 | #elif (__riscv_xlen == 64) |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 64 | #define R_ABSOLUTE R_RISCV_64 |
| 65 | #define SYM_INDEX 32 |
Alexander Graf | 0fe5192 | 2018-06-18 17:23:08 +0200 | [diff] [blame] | 66 | #else |
| 67 | #error unknown riscv target |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 68 | #endif |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 69 | #else |
| 70 | #error Need to add relocation awareness |
| 71 | #endif |
| 72 | |
| 73 | struct elf_rel { |
| 74 | ulong *offset; |
| 75 | ulong info; |
| 76 | }; |
| 77 | |
| 78 | struct elf_rela { |
| 79 | ulong *offset; |
| 80 | ulong info; |
| 81 | long addend; |
| 82 | }; |
| 83 | |
| 84 | /* |
Heinrich Schuchardt | 1112154 | 2018-09-03 19:29:41 +0200 | [diff] [blame] | 85 | * EFI runtime code lives in two stages. In the first stage, U-Boot and an EFI |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 86 | * payload are running concurrently at the same time. In this mode, we can |
| 87 | * handle a good number of runtime callbacks |
| 88 | */ |
| 89 | |
AKASHI Takahiro | 3240184 | 2019-06-05 13:21:38 +0900 | [diff] [blame] | 90 | efi_status_t efi_init_runtime_supported(void) |
| 91 | { |
| 92 | u16 efi_runtime_services_supported = 0; |
| 93 | |
| 94 | /* |
| 95 | * This value must be synced with efi_runtime_detach_list |
| 96 | * as well as efi_runtime_services. |
| 97 | */ |
Heinrich Schuchardt | 05874fb | 2019-07-05 18:12:16 +0200 | [diff] [blame] | 98 | #ifdef CONFIG_EFI_HAVE_RUNTIME_RESET |
AKASHI Takahiro | 3240184 | 2019-06-05 13:21:38 +0900 | [diff] [blame] | 99 | efi_runtime_services_supported |= EFI_RT_SUPPORTED_RESET_SYSTEM; |
| 100 | #endif |
| 101 | efi_runtime_services_supported |= |
| 102 | EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP; |
| 103 | return EFI_CALL(efi_set_variable(L"RuntimeServicesSupported", |
| 104 | &efi_global_variable_guid, |
| 105 | EFI_VARIABLE_BOOTSERVICE_ACCESS | |
| 106 | EFI_VARIABLE_RUNTIME_ACCESS, |
| 107 | sizeof(efi_runtime_services_supported), |
| 108 | &efi_runtime_services_supported)); |
| 109 | } |
| 110 | |
Heinrich Schuchardt | 69c1576 | 2018-07-29 09:49:04 +0200 | [diff] [blame] | 111 | /** |
| 112 | * efi_update_table_header_crc32() - Update crc32 in table header |
| 113 | * |
| 114 | * @table: EFI table |
| 115 | */ |
| 116 | void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table) |
| 117 | { |
| 118 | table->crc32 = 0; |
| 119 | table->crc32 = crc32(0, (const unsigned char *)table, |
| 120 | table->headersize); |
| 121 | } |
| 122 | |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 123 | /** |
Heinrich Schuchardt | 1112154 | 2018-09-03 19:29:41 +0200 | [diff] [blame] | 124 | * efi_reset_system_boottime() - reset system at boot time |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 125 | * |
| 126 | * This function implements the ResetSystem() runtime service before |
| 127 | * SetVirtualAddressMap() is called. |
| 128 | * |
| 129 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 130 | * details. |
| 131 | * |
| 132 | * @reset_type: type of reset to perform |
| 133 | * @reset_status: status code for the reset |
| 134 | * @data_size: size of reset_data |
| 135 | * @reset_data: information about the reset |
| 136 | */ |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 137 | static void EFIAPI efi_reset_system_boottime( |
| 138 | enum efi_reset_type reset_type, |
| 139 | efi_status_t reset_status, |
| 140 | unsigned long data_size, void *reset_data) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 141 | { |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 142 | struct efi_event *evt; |
| 143 | |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 144 | EFI_ENTRY("%d %lx %lx %p", reset_type, reset_status, data_size, |
| 145 | reset_data); |
| 146 | |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 147 | /* Notify reset */ |
| 148 | list_for_each_entry(evt, &efi_events, link) { |
| 149 | if (evt->group && |
| 150 | !guidcmp(evt->group, |
| 151 | &efi_guid_event_group_reset_system)) { |
Heinrich Schuchardt | 7b4b8d86 | 2019-06-07 06:47:01 +0200 | [diff] [blame] | 152 | efi_signal_event(evt); |
Heinrich Schuchardt | bf7f169 | 2018-02-18 15:17:52 +0100 | [diff] [blame] | 153 | break; |
| 154 | } |
| 155 | } |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 156 | switch (reset_type) { |
| 157 | case EFI_RESET_COLD: |
| 158 | case EFI_RESET_WARM: |
Heinrich Schuchardt | 450d4c8 | 2018-02-06 22:00:22 +0100 | [diff] [blame] | 159 | case EFI_RESET_PLATFORM_SPECIFIC: |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 160 | do_reset(NULL, 0, 0, NULL); |
| 161 | break; |
| 162 | case EFI_RESET_SHUTDOWN: |
Heinrich Schuchardt | 4448945 | 2018-10-16 07:44:53 +0200 | [diff] [blame] | 163 | #ifdef CONFIG_CMD_POWEROFF |
| 164 | do_poweroff(NULL, 0, 0, NULL); |
| 165 | #endif |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 166 | break; |
| 167 | } |
| 168 | |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 169 | while (1) { } |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 172 | /** |
Heinrich Schuchardt | 1112154 | 2018-09-03 19:29:41 +0200 | [diff] [blame] | 173 | * efi_get_time_boottime() - get current time at boot time |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 174 | * |
| 175 | * This function implements the GetTime runtime service before |
| 176 | * SetVirtualAddressMap() is called. |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 177 | * |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 178 | * See the Unified Extensible Firmware Interface (UEFI) specification |
| 179 | * for details. |
| 180 | * |
| 181 | * @time: pointer to structure to receive current time |
| 182 | * @capabilities: pointer to structure to receive RTC properties |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 183 | * Returns: status code |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 184 | */ |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 185 | static efi_status_t EFIAPI efi_get_time_boottime( |
| 186 | struct efi_time *time, |
| 187 | struct efi_time_cap *capabilities) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 188 | { |
Heinrich Schuchardt | f2856ad | 2019-05-31 22:56:02 +0200 | [diff] [blame] | 189 | #ifdef CONFIG_EFI_GET_TIME |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 190 | efi_status_t ret = EFI_SUCCESS; |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 191 | struct rtc_time tm; |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 192 | struct udevice *dev; |
| 193 | |
| 194 | EFI_ENTRY("%p %p", time, capabilities); |
| 195 | |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 196 | if (!time) { |
| 197 | ret = EFI_INVALID_PARAMETER; |
| 198 | goto out; |
| 199 | } |
Heinrich Schuchardt | b4bd366 | 2019-05-19 21:41:28 +0200 | [diff] [blame] | 200 | if (uclass_get_device(UCLASS_RTC, 0, &dev) || |
| 201 | dm_rtc_get(dev, &tm)) { |
| 202 | ret = EFI_UNSUPPORTED; |
| 203 | goto out; |
| 204 | } |
| 205 | if (dm_rtc_get(dev, &tm)) { |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 206 | ret = EFI_DEVICE_ERROR; |
| 207 | goto out; |
| 208 | } |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 209 | |
| 210 | memset(time, 0, sizeof(*time)); |
| 211 | time->year = tm.tm_year; |
| 212 | time->month = tm.tm_mon; |
| 213 | time->day = tm.tm_mday; |
| 214 | time->hour = tm.tm_hour; |
| 215 | time->minute = tm.tm_min; |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 216 | time->second = tm.tm_sec; |
Heinrich Schuchardt | ba3e828 | 2019-05-31 22:08:45 +0200 | [diff] [blame] | 217 | if (tm.tm_isdst) |
| 218 | time->daylight = |
| 219 | EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT; |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 220 | time->timezone = EFI_UNSPECIFIED_TIMEZONE; |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 221 | |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 222 | if (capabilities) { |
| 223 | /* Set reasonable dummy values */ |
| 224 | capabilities->resolution = 1; /* 1 Hz */ |
| 225 | capabilities->accuracy = 100000000; /* 100 ppm */ |
| 226 | capabilities->sets_to_zero = false; |
| 227 | } |
| 228 | out: |
| 229 | return EFI_EXIT(ret); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 230 | #else |
Heinrich Schuchardt | 37035b1 | 2018-07-07 23:39:14 +0200 | [diff] [blame] | 231 | EFI_ENTRY("%p %p", time, capabilities); |
Heinrich Schuchardt | b4bd366 | 2019-05-19 21:41:28 +0200 | [diff] [blame] | 232 | return EFI_EXIT(EFI_UNSUPPORTED); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 233 | #endif |
| 234 | } |
| 235 | |
Heinrich Schuchardt | f2856ad | 2019-05-31 22:56:02 +0200 | [diff] [blame] | 236 | #ifdef CONFIG_EFI_SET_TIME |
Heinrich Schuchardt | 33e5a0e | 2019-05-31 07:35:19 +0200 | [diff] [blame] | 237 | |
| 238 | /** |
| 239 | * efi_validate_time() - checks if timestamp is valid |
| 240 | * |
| 241 | * @time: timestamp to validate |
| 242 | * Returns: 0 if timestamp is valid, 1 otherwise |
| 243 | */ |
| 244 | static int efi_validate_time(struct efi_time *time) |
| 245 | { |
| 246 | return (!time || |
| 247 | time->year < 1900 || time->year > 9999 || |
| 248 | !time->month || time->month > 12 || !time->day || |
| 249 | time->day > rtc_month_days(time->month - 1, time->year) || |
| 250 | time->hour > 23 || time->minute > 59 || time->second > 59 || |
| 251 | time->nanosecond > 999999999 || |
| 252 | time->daylight & |
| 253 | ~(EFI_TIME_IN_DAYLIGHT | EFI_TIME_ADJUST_DAYLIGHT) || |
| 254 | ((time->timezone < -1440 || time->timezone > 1440) && |
| 255 | time->timezone != EFI_UNSPECIFIED_TIMEZONE)); |
| 256 | } |
| 257 | |
| 258 | #endif |
| 259 | |
Heinrich Schuchardt | 411b2d5 | 2019-05-19 20:07:39 +0200 | [diff] [blame] | 260 | /** |
| 261 | * efi_set_time_boottime() - set current time |
| 262 | * |
| 263 | * This function implements the SetTime() runtime service before |
| 264 | * SetVirtualAddressMap() is called. |
| 265 | * |
| 266 | * See the Unified Extensible Firmware Interface (UEFI) specification |
| 267 | * for details. |
| 268 | * |
| 269 | * @time: pointer to structure to with current time |
| 270 | * Returns: status code |
| 271 | */ |
| 272 | static efi_status_t EFIAPI efi_set_time_boottime(struct efi_time *time) |
| 273 | { |
Heinrich Schuchardt | f2856ad | 2019-05-31 22:56:02 +0200 | [diff] [blame] | 274 | #ifdef CONFIG_EFI_SET_TIME |
Heinrich Schuchardt | 411b2d5 | 2019-05-19 20:07:39 +0200 | [diff] [blame] | 275 | efi_status_t ret = EFI_SUCCESS; |
| 276 | struct rtc_time tm; |
| 277 | struct udevice *dev; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 278 | |
Heinrich Schuchardt | 411b2d5 | 2019-05-19 20:07:39 +0200 | [diff] [blame] | 279 | EFI_ENTRY("%p", time); |
| 280 | |
Heinrich Schuchardt | 33e5a0e | 2019-05-31 07:35:19 +0200 | [diff] [blame] | 281 | if (efi_validate_time(time)) { |
Heinrich Schuchardt | 411b2d5 | 2019-05-19 20:07:39 +0200 | [diff] [blame] | 282 | ret = EFI_INVALID_PARAMETER; |
| 283 | goto out; |
| 284 | } |
| 285 | |
| 286 | if (uclass_get_device(UCLASS_RTC, 0, &dev)) { |
| 287 | ret = EFI_UNSUPPORTED; |
| 288 | goto out; |
| 289 | } |
| 290 | |
| 291 | memset(&tm, 0, sizeof(tm)); |
| 292 | tm.tm_year = time->year; |
| 293 | tm.tm_mon = time->month; |
| 294 | tm.tm_mday = time->day; |
| 295 | tm.tm_hour = time->hour; |
| 296 | tm.tm_min = time->minute; |
| 297 | tm.tm_sec = time->second; |
Heinrich Schuchardt | ba3e828 | 2019-05-31 22:08:45 +0200 | [diff] [blame] | 298 | tm.tm_isdst = time->daylight == |
| 299 | (EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT); |
Heinrich Schuchardt | 411b2d5 | 2019-05-19 20:07:39 +0200 | [diff] [blame] | 300 | /* Calculate day of week */ |
| 301 | rtc_calc_weekday(&tm); |
| 302 | |
| 303 | if (dm_rtc_set(dev, &tm)) |
| 304 | ret = EFI_DEVICE_ERROR; |
| 305 | out: |
| 306 | return EFI_EXIT(ret); |
| 307 | #else |
| 308 | EFI_ENTRY("%p", time); |
| 309 | return EFI_EXIT(EFI_UNSUPPORTED); |
| 310 | #endif |
| 311 | } |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 312 | /** |
| 313 | * efi_reset_system() - reset system |
| 314 | * |
| 315 | * This function implements the ResetSystem() runtime service after |
| 316 | * SetVirtualAddressMap() is called. It only executes an endless loop. |
| 317 | * Boards may override the helpers below to implement reset functionality. |
| 318 | * |
| 319 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 320 | * details. |
| 321 | * |
| 322 | * @reset_type: type of reset to perform |
| 323 | * @reset_status: status code for the reset |
| 324 | * @data_size: size of reset_data |
| 325 | * @reset_data: information about the reset |
| 326 | */ |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 327 | void __weak __efi_runtime EFIAPI efi_reset_system( |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 328 | enum efi_reset_type reset_type, |
| 329 | efi_status_t reset_status, |
| 330 | unsigned long data_size, void *reset_data) |
| 331 | { |
| 332 | /* Nothing we can do */ |
| 333 | while (1) { } |
| 334 | } |
| 335 | |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 336 | /** |
| 337 | * efi_reset_system_init() - initialize the reset driver |
| 338 | * |
| 339 | * Boards may override this function to initialize the reset driver. |
| 340 | */ |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 341 | efi_status_t __weak efi_reset_system_init(void) |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 342 | { |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 343 | return EFI_SUCCESS; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 344 | } |
| 345 | |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 346 | /** |
| 347 | * efi_get_time() - get current time |
| 348 | * |
| 349 | * This function implements the GetTime runtime service after |
| 350 | * SetVirtualAddressMap() is called. As the U-Boot driver are not available |
| 351 | * anymore only an error code is returned. |
| 352 | * |
| 353 | * See the Unified Extensible Firmware Interface (UEFI) specification |
| 354 | * for details. |
| 355 | * |
| 356 | * @time: pointer to structure to receive current time |
| 357 | * @capabilities: pointer to structure to receive RTC properties |
| 358 | * Returns: status code |
| 359 | */ |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 360 | efi_status_t __weak __efi_runtime EFIAPI efi_get_time( |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 361 | struct efi_time *time, |
| 362 | struct efi_time_cap *capabilities) |
| 363 | { |
Heinrich Schuchardt | b4ba5be | 2019-06-13 18:42:40 +0200 | [diff] [blame] | 364 | return EFI_UNSUPPORTED; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Heinrich Schuchardt | 411b2d5 | 2019-05-19 20:07:39 +0200 | [diff] [blame] | 367 | /** |
| 368 | * efi_set_time() - set current time |
| 369 | * |
| 370 | * This function implements the SetTime runtime service after |
| 371 | * SetVirtualAddressMap() is called. As the U-Boot driver are not available |
| 372 | * anymore only an error code is returned. |
| 373 | * |
| 374 | * See the Unified Extensible Firmware Interface (UEFI) specification |
| 375 | * for details. |
| 376 | * |
| 377 | * @time: pointer to structure to with current time |
| 378 | * Returns: status code |
| 379 | */ |
| 380 | efi_status_t __weak __efi_runtime EFIAPI efi_set_time(struct efi_time *time) |
| 381 | { |
| 382 | return EFI_UNSUPPORTED; |
| 383 | } |
| 384 | |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 385 | /** |
| 386 | * efi_is_runtime_service_pointer() - check if pointer points to runtime table |
| 387 | * |
| 388 | * @p: pointer to check |
| 389 | * Return: true if the pointer points to a service function pointer in the |
| 390 | * runtime table |
| 391 | */ |
| 392 | static bool efi_is_runtime_service_pointer(void *p) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 393 | { |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 394 | return p >= (void *)&efi_runtime_services.get_time && |
| 395 | p <= (void *)&efi_runtime_services.query_variable_info; |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 396 | } |
| 397 | |
Heinrich Schuchardt | c3f2a9f | 2019-07-05 18:12:21 +0200 | [diff] [blame] | 398 | /** |
| 399 | * efi_runtime_detach() - detach unimplemented runtime functions |
| 400 | */ |
Heinrich Schuchardt | 1943dbb | 2019-07-05 17:42:16 +0200 | [diff] [blame^] | 401 | void efi_runtime_detach(void) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 402 | { |
Heinrich Schuchardt | c3f2a9f | 2019-07-05 18:12:21 +0200 | [diff] [blame] | 403 | efi_runtime_services.reset_system = efi_reset_system; |
| 404 | efi_runtime_services.get_time = efi_get_time; |
| 405 | efi_runtime_services.set_time = efi_set_time; |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 406 | |
Heinrich Schuchardt | c3f2a9f | 2019-07-05 18:12:21 +0200 | [diff] [blame] | 407 | /* Update CRC32 */ |
| 408 | efi_update_table_header_crc32(&efi_runtime_services.hdr); |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Heinrich Schuchardt | 2572851 | 2019-06-29 03:32:52 +0200 | [diff] [blame] | 411 | /** |
| 412 | * efi_set_virtual_address_map_runtime() - change from physical to virtual |
| 413 | * mapping |
| 414 | * |
| 415 | * This function implements the SetVirtualAddressMap() runtime service after |
| 416 | * it is first called. |
| 417 | * |
| 418 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 419 | * details. |
| 420 | * |
| 421 | * @memory_map_size: size of the virtual map |
| 422 | * @descriptor_size: size of an entry in the map |
| 423 | * @descriptor_version: version of the map entries |
| 424 | * @virtmap: virtual address mapping information |
| 425 | * Return: status code EFI_UNSUPPORTED |
| 426 | */ |
| 427 | static efi_status_t EFIAPI efi_set_virtual_address_map_runtime( |
| 428 | unsigned long memory_map_size, |
| 429 | unsigned long descriptor_size, |
| 430 | uint32_t descriptor_version, |
| 431 | struct efi_mem_desc *virtmap) |
| 432 | { |
| 433 | return EFI_UNSUPPORTED; |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * efi_convert_pointer_runtime() - convert from physical to virtual pointer |
| 438 | * |
| 439 | * This function implements the ConvertPointer() runtime service after |
| 440 | * the first call to SetVirtualAddressMap(). |
| 441 | * |
| 442 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 443 | * details. |
| 444 | * |
| 445 | * @debug_disposition: indicates if pointer may be converted to NULL |
| 446 | * @address: pointer to be converted |
| 447 | * Return: status code EFI_UNSUPPORTED |
| 448 | */ |
| 449 | static __efi_runtime efi_status_t EFIAPI efi_convert_pointer_runtime( |
| 450 | efi_uintn_t debug_disposition, void **address) |
| 451 | { |
| 452 | return EFI_UNSUPPORTED; |
| 453 | } |
| 454 | |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 455 | static __efi_runtime void efi_relocate_runtime_table(ulong offset) |
| 456 | { |
| 457 | ulong patchoff; |
| 458 | void **pos; |
| 459 | |
| 460 | /* Relocate the runtime services pointers */ |
| 461 | patchoff = offset - gd->relocaddr; |
| 462 | for (pos = (void **)&efi_runtime_services.get_time; |
| 463 | pos <= (void **)&efi_runtime_services.query_variable_info; ++pos) { |
Heinrich Schuchardt | 2572851 | 2019-06-29 03:32:52 +0200 | [diff] [blame] | 464 | if (*pos) |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 465 | *pos += patchoff; |
| 466 | } |
Heinrich Schuchardt | 69c1576 | 2018-07-29 09:49:04 +0200 | [diff] [blame] | 467 | |
Heinrich Schuchardt | 2572851 | 2019-06-29 03:32:52 +0200 | [diff] [blame] | 468 | /* |
| 469 | * The entry for SetVirtualAddress() must point to a physical address. |
| 470 | * After the first execution the service must return EFI_UNSUPPORTED. |
| 471 | */ |
| 472 | efi_runtime_services.set_virtual_address_map = |
| 473 | &efi_set_virtual_address_map_runtime; |
| 474 | |
| 475 | /* |
| 476 | * The entry for ConvertPointer() must point to a physical address. |
| 477 | * The service is not usable after SetVirtualAddress(). |
| 478 | */ |
| 479 | efi_runtime_services.convert_pointer = &efi_convert_pointer_runtime; |
| 480 | |
Heinrich Schuchardt | 1112154 | 2018-09-03 19:29:41 +0200 | [diff] [blame] | 481 | /* Update CRC32 */ |
Heinrich Schuchardt | 69c1576 | 2018-07-29 09:49:04 +0200 | [diff] [blame] | 482 | efi_update_table_header_crc32(&efi_runtime_services.hdr); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /* Relocate EFI runtime to uboot_reloc_base = offset */ |
| 486 | void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map) |
| 487 | { |
| 488 | #ifdef IS_RELA |
| 489 | struct elf_rela *rel = (void*)&__efi_runtime_rel_start; |
| 490 | #else |
| 491 | struct elf_rel *rel = (void*)&__efi_runtime_rel_start; |
| 492 | static ulong lastoff = CONFIG_SYS_TEXT_BASE; |
| 493 | #endif |
| 494 | |
Alexander Graf | 62a6748 | 2016-06-02 11:38:27 +0200 | [diff] [blame] | 495 | debug("%s: Relocating to offset=%lx\n", __func__, offset); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 496 | for (; (ulong)rel < (ulong)&__efi_runtime_rel_stop; rel++) { |
| 497 | ulong base = CONFIG_SYS_TEXT_BASE; |
| 498 | ulong *p; |
| 499 | ulong newaddr; |
| 500 | |
| 501 | p = (void*)((ulong)rel->offset - base) + gd->relocaddr; |
| 502 | |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 503 | /* The runtime services are updated in efi_runtime_detach() */ |
| 504 | if (map && efi_is_runtime_service_pointer(p)) |
| 505 | continue; |
| 506 | |
Heinrich Schuchardt | 56e82be | 2018-10-13 20:52:08 -0700 | [diff] [blame] | 507 | debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__, |
| 508 | rel->info, *p, rel->offset); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 509 | |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 510 | switch (rel->info & R_MASK) { |
| 511 | case R_RELATIVE: |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 512 | #ifdef IS_RELA |
| 513 | newaddr = rel->addend + offset - CONFIG_SYS_TEXT_BASE; |
| 514 | #else |
| 515 | newaddr = *p - lastoff + offset; |
| 516 | #endif |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 517 | break; |
| 518 | #ifdef R_ABSOLUTE |
| 519 | case R_ABSOLUTE: { |
| 520 | ulong symidx = rel->info >> SYM_INDEX; |
| 521 | extern struct dyn_sym __dyn_sym_start[]; |
| 522 | newaddr = __dyn_sym_start[symidx].addr + offset; |
Alexander Graf | df0f6c7 | 2018-11-04 22:25:22 +0100 | [diff] [blame] | 523 | #ifdef IS_RELA |
| 524 | newaddr -= CONFIG_SYS_TEXT_BASE; |
| 525 | #endif |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 526 | break; |
| 527 | } |
| 528 | #endif |
| 529 | default: |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 530 | printf("%s: Unknown relocation type %llx\n", |
| 531 | __func__, rel->info & R_MASK); |
Rick Chen | 9677a37 | 2018-05-28 19:06:37 +0800 | [diff] [blame] | 532 | continue; |
| 533 | } |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 534 | |
| 535 | /* Check if the relocation is inside bounds */ |
| 536 | if (map && ((newaddr < map->virtual_start) || |
Heinrich Schuchardt | 9ebc47f | 2017-09-18 22:11:34 +0200 | [diff] [blame] | 537 | newaddr > (map->virtual_start + |
| 538 | (map->num_pages << EFI_PAGE_SHIFT)))) { |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 539 | printf("%s: Relocation at %p is out of range (%lx)\n", |
| 540 | __func__, p, newaddr); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 541 | continue; |
| 542 | } |
| 543 | |
Alexander Graf | 62a6748 | 2016-06-02 11:38:27 +0200 | [diff] [blame] | 544 | debug("%s: Setting %p to %lx\n", __func__, p, newaddr); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 545 | *p = newaddr; |
Alexander Graf | e570232 | 2016-04-11 23:20:39 +0200 | [diff] [blame] | 546 | flush_dcache_range((ulong)p & ~(EFI_CACHELINE_SIZE - 1), |
| 547 | ALIGN((ulong)&p[1], EFI_CACHELINE_SIZE)); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | #ifndef IS_RELA |
| 551 | lastoff = offset; |
| 552 | #endif |
| 553 | |
| 554 | invalidate_icache_all(); |
| 555 | } |
| 556 | |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 557 | /** |
| 558 | * efi_set_virtual_address_map() - change from physical to virtual mapping |
| 559 | * |
| 560 | * This function implements the SetVirtualAddressMap() runtime service. |
| 561 | * |
| 562 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 563 | * details. |
| 564 | * |
| 565 | * @memory_map_size: size of the virtual map |
| 566 | * @descriptor_size: size of an entry in the map |
| 567 | * @descriptor_version: version of the map entries |
| 568 | * @virtmap: virtual address mapping information |
| 569 | * Return: status code |
| 570 | */ |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 571 | static efi_status_t EFIAPI efi_set_virtual_address_map( |
| 572 | unsigned long memory_map_size, |
| 573 | unsigned long descriptor_size, |
| 574 | uint32_t descriptor_version, |
| 575 | struct efi_mem_desc *virtmap) |
| 576 | { |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 577 | int n = memory_map_size / descriptor_size; |
| 578 | int i; |
Alexander Graf | 86e0021 | 2018-12-11 10:00:42 +0100 | [diff] [blame] | 579 | int rt_code_sections = 0; |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 580 | |
| 581 | EFI_ENTRY("%lx %lx %x %p", memory_map_size, descriptor_size, |
| 582 | descriptor_version, virtmap); |
| 583 | |
Alexander Graf | 86e0021 | 2018-12-11 10:00:42 +0100 | [diff] [blame] | 584 | /* |
| 585 | * TODO: |
| 586 | * Further down we are cheating. While really we should implement |
| 587 | * SetVirtualAddressMap() events and ConvertPointer() to allow |
| 588 | * dynamically loaded drivers to expose runtime services, we don't |
| 589 | * today. |
| 590 | * |
| 591 | * So let's ensure we see exactly one single runtime section, as |
| 592 | * that is the built-in one. If we see more (or less), someone must |
| 593 | * have tried adding or removing to that which we don't support yet. |
| 594 | * In that case, let's better fail rather than expose broken runtime |
| 595 | * services. |
| 596 | */ |
| 597 | for (i = 0; i < n; i++) { |
| 598 | struct efi_mem_desc *map = (void*)virtmap + |
| 599 | (descriptor_size * i); |
| 600 | |
| 601 | if (map->type == EFI_RUNTIME_SERVICES_CODE) |
| 602 | rt_code_sections++; |
| 603 | } |
| 604 | |
| 605 | if (rt_code_sections != 1) { |
| 606 | /* |
| 607 | * We expose exactly one single runtime code section, so |
| 608 | * something is definitely going wrong. |
| 609 | */ |
| 610 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 611 | } |
| 612 | |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 613 | /* Rebind mmio pointers */ |
| 614 | for (i = 0; i < n; i++) { |
| 615 | struct efi_mem_desc *map = (void*)virtmap + |
| 616 | (descriptor_size * i); |
| 617 | struct list_head *lhandle; |
| 618 | efi_physical_addr_t map_start = map->physical_start; |
| 619 | efi_physical_addr_t map_len = map->num_pages << EFI_PAGE_SHIFT; |
| 620 | efi_physical_addr_t map_end = map_start + map_len; |
Heinrich Schuchardt | 3905456 | 2018-08-04 23:16:06 +0200 | [diff] [blame] | 621 | u64 off = map->virtual_start - map_start; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 622 | |
| 623 | /* Adjust all mmio pointers in this region */ |
| 624 | list_for_each(lhandle, &efi_runtime_mmio) { |
| 625 | struct efi_runtime_mmio_list *lmmio; |
| 626 | |
| 627 | lmmio = list_entry(lhandle, |
| 628 | struct efi_runtime_mmio_list, |
| 629 | link); |
| 630 | if ((map_start <= lmmio->paddr) && |
| 631 | (map_end >= lmmio->paddr)) { |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 632 | uintptr_t new_addr = lmmio->paddr + off; |
| 633 | *lmmio->ptr = (void *)new_addr; |
| 634 | } |
| 635 | } |
Heinrich Schuchardt | 3905456 | 2018-08-04 23:16:06 +0200 | [diff] [blame] | 636 | if ((map_start <= (uintptr_t)systab.tables) && |
| 637 | (map_end >= (uintptr_t)systab.tables)) { |
| 638 | char *ptr = (char *)systab.tables; |
| 639 | |
| 640 | ptr += off; |
| 641 | systab.tables = (struct efi_configuration_table *)ptr; |
| 642 | } |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 643 | } |
| 644 | |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 645 | /* |
| 646 | * Some runtime services are implemented in a way that we can only offer |
| 647 | * them at boottime. Replace those function pointers. |
| 648 | * |
| 649 | * TODO: move this call to ExitBootServices(). |
| 650 | */ |
| 651 | efi_runtime_detach(); |
| 652 | |
| 653 | /* Relocate the runtime. See TODO above */ |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 654 | for (i = 0; i < n; i++) { |
| 655 | struct efi_mem_desc *map; |
| 656 | |
| 657 | map = (void*)virtmap + (descriptor_size * i); |
| 658 | if (map->type == EFI_RUNTIME_SERVICES_CODE) { |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 659 | ulong new_offset = map->virtual_start - |
Alexander Graf | 86e0021 | 2018-12-11 10:00:42 +0100 | [diff] [blame] | 660 | map->physical_start + gd->relocaddr; |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 661 | |
Heinrich Schuchardt | 19cd80b | 2019-06-20 22:00:02 +0000 | [diff] [blame] | 662 | efi_relocate_runtime_table(new_offset); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 663 | efi_runtime_relocate(new_offset, map); |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 664 | return EFI_EXIT(EFI_SUCCESS); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
| 669 | } |
| 670 | |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 671 | /** |
| 672 | * efi_add_runtime_mmio() - add memory-mapped IO region |
| 673 | * |
| 674 | * This function adds a memory-mapped IO region to the memory map to make it |
| 675 | * available at runtime. |
| 676 | * |
Heinrich Schuchardt | 7e30764 | 2018-12-23 02:35:13 +0100 | [diff] [blame] | 677 | * @mmio_ptr: pointer to a pointer to the start of the memory-mapped |
| 678 | * IO region |
Heinrich Schuchardt | 1112154 | 2018-09-03 19:29:41 +0200 | [diff] [blame] | 679 | * @len: size of the memory-mapped IO region |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 680 | * Returns: status code |
| 681 | */ |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 682 | efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len) |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 683 | { |
| 684 | struct efi_runtime_mmio_list *newmmio; |
xypron.glpk@gmx.de | 93fcc7f | 2017-08-11 21:19:37 +0200 | [diff] [blame] | 685 | u64 pages = (len + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; |
Alexander Graf | 33a83a3 | 2018-03-15 15:08:16 +0100 | [diff] [blame] | 686 | uint64_t addr = *(uintptr_t *)mmio_ptr; |
| 687 | uint64_t retaddr; |
| 688 | |
| 689 | retaddr = efi_add_memory_map(addr, pages, EFI_MMAP_IO, false); |
| 690 | if (retaddr != addr) |
| 691 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 692 | |
| 693 | newmmio = calloc(1, sizeof(*newmmio)); |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 694 | if (!newmmio) |
| 695 | return EFI_OUT_OF_RESOURCES; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 696 | newmmio->ptr = mmio_ptr; |
| 697 | newmmio->paddr = *(uintptr_t *)mmio_ptr; |
| 698 | newmmio->len = len; |
| 699 | list_add_tail(&newmmio->link, &efi_runtime_mmio); |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 700 | |
Alexander Graf | 33a83a3 | 2018-03-15 15:08:16 +0100 | [diff] [blame] | 701 | return EFI_SUCCESS; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 702 | } |
| 703 | |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 704 | /* |
| 705 | * In the second stage, U-Boot has disappeared. To isolate our runtime code |
| 706 | * that at this point still exists from the rest, we put it into a special |
| 707 | * section. |
| 708 | * |
| 709 | * !!WARNING!! |
| 710 | * |
| 711 | * This means that we can not rely on any code outside of this file in any |
| 712 | * function or variable below this line. |
| 713 | * |
| 714 | * Please keep everything fully self-contained and annotated with |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 715 | * __efi_runtime and __efi_runtime_data markers. |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 716 | */ |
| 717 | |
| 718 | /* |
| 719 | * Relocate the EFI runtime stub to a different place. We need to call this |
| 720 | * the first time we expose the runtime interface to a user and on set virtual |
| 721 | * address map calls. |
| 722 | */ |
| 723 | |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 724 | /** |
| 725 | * efi_unimplemented() - replacement function, returns EFI_UNSUPPORTED |
| 726 | * |
| 727 | * This function is used after SetVirtualAddressMap() is called as replacement |
| 728 | * for services that are not available anymore due to constraints of the U-Boot |
| 729 | * implementation. |
| 730 | * |
| 731 | * Return: EFI_UNSUPPORTED |
| 732 | */ |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 733 | static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void) |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 734 | { |
| 735 | return EFI_UNSUPPORTED; |
| 736 | } |
| 737 | |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 738 | /** |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 739 | * efi_update_capsule() - process information from operating system |
| 740 | * |
| 741 | * This function implements the UpdateCapsule() runtime service. |
| 742 | * |
| 743 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 744 | * details. |
| 745 | * |
| 746 | * @capsule_header_array: pointer to array of virtual pointers |
| 747 | * @capsule_count: number of pointers in capsule_header_array |
| 748 | * @scatter_gather_list: pointer to arry of physical pointers |
| 749 | * Returns: status code |
| 750 | */ |
Heinrich Schuchardt | 897c072 | 2018-02-09 20:41:21 +0100 | [diff] [blame] | 751 | efi_status_t __efi_runtime EFIAPI efi_update_capsule( |
| 752 | struct efi_capsule_header **capsule_header_array, |
| 753 | efi_uintn_t capsule_count, |
| 754 | u64 scatter_gather_list) |
| 755 | { |
| 756 | return EFI_UNSUPPORTED; |
| 757 | } |
| 758 | |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 759 | /** |
| 760 | * efi_query_capsule_caps() - check if capsule is supported |
| 761 | * |
| 762 | * This function implements the QueryCapsuleCapabilities() runtime service. |
| 763 | * |
| 764 | * See the Unified Extensible Firmware Interface (UEFI) specification for |
| 765 | * details. |
| 766 | * |
| 767 | * @capsule_header_array: pointer to array of virtual pointers |
| 768 | * @capsule_count: number of pointers in capsule_header_array |
Heinrich Schuchardt | 1d1be36 | 2018-09-03 20:59:25 +0200 | [diff] [blame] | 769 | * @maximum_capsule_size: maximum capsule size |
Heinrich Schuchardt | 711853b | 2018-07-29 15:10:11 +0200 | [diff] [blame] | 770 | * @reset_type: type of reset needed for capsule update |
| 771 | * Returns: status code |
| 772 | */ |
Heinrich Schuchardt | 897c072 | 2018-02-09 20:41:21 +0100 | [diff] [blame] | 773 | efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps( |
| 774 | struct efi_capsule_header **capsule_header_array, |
| 775 | efi_uintn_t capsule_count, |
AKASHI Takahiro | d840b67 | 2018-11-14 16:18:53 +0900 | [diff] [blame] | 776 | u64 *maximum_capsule_size, |
| 777 | u32 *reset_type) |
Heinrich Schuchardt | 897c072 | 2018-02-09 20:41:21 +0100 | [diff] [blame] | 778 | { |
| 779 | return EFI_UNSUPPORTED; |
| 780 | } |
| 781 | |
Alexander Graf | 393dd91 | 2016-10-14 13:45:30 +0200 | [diff] [blame] | 782 | struct efi_runtime_services __efi_runtime_data efi_runtime_services = { |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 783 | .hdr = { |
| 784 | .signature = EFI_RUNTIME_SERVICES_SIGNATURE, |
Heinrich Schuchardt | e75b3cb | 2018-06-28 12:45:27 +0200 | [diff] [blame] | 785 | .revision = EFI_SPECIFICATION_VERSION, |
Heinrich Schuchardt | 1020425 | 2018-06-28 12:45:29 +0200 | [diff] [blame] | 786 | .headersize = sizeof(struct efi_runtime_services), |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 787 | }, |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 788 | .get_time = &efi_get_time_boottime, |
Heinrich Schuchardt | 411b2d5 | 2019-05-19 20:07:39 +0200 | [diff] [blame] | 789 | .set_time = &efi_set_time_boottime, |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 790 | .get_wakeup_time = (void *)&efi_unimplemented, |
| 791 | .set_wakeup_time = (void *)&efi_unimplemented, |
| 792 | .set_virtual_address_map = &efi_set_virtual_address_map, |
Heinrich Schuchardt | 5337a6c | 2019-06-20 15:40:49 +0200 | [diff] [blame] | 793 | .convert_pointer = (void *)&efi_unimplemented, |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 794 | .get_variable = efi_get_variable, |
Heinrich Schuchardt | d6a6baa | 2018-05-17 07:57:05 +0200 | [diff] [blame] | 795 | .get_next_variable_name = efi_get_next_variable_name, |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 796 | .set_variable = efi_set_variable, |
Heinrich Schuchardt | 5337a6c | 2019-06-20 15:40:49 +0200 | [diff] [blame] | 797 | .get_next_high_mono_count = (void *)&efi_unimplemented, |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 798 | .reset_system = &efi_reset_system_boottime, |
Heinrich Schuchardt | 897c072 | 2018-02-09 20:41:21 +0100 | [diff] [blame] | 799 | .update_capsule = efi_update_capsule, |
| 800 | .query_capsule_caps = efi_query_capsule_caps, |
| 801 | .query_variable_info = efi_query_variable_info, |
Alexander Graf | 0bd425a | 2016-03-04 01:10:01 +0100 | [diff] [blame] | 802 | }; |