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