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