blob: 0b171c1ff7bfb7365bffe9fe7fdfab21adcf6b41 [file] [log] [blame]
Tom Rini70df9d62018-05-07 17:02:21 -04001// SPDX-License-Identifier: GPL-2.0+
Alexander Graf0bd425a2016-03-04 01:10:01 +01002/*
3 * EFI application runtime services
4 *
5 * Copyright (c) 2016 Alexander Graf
Alexander Graf0bd425a2016-03-04 01:10:01 +01006 */
7
8#include <common.h>
9#include <command.h>
Simon Glass63334482019-11-14 12:57:39 -070010#include <cpu_func.h>
Alexander Graf0bd425a2016-03-04 01:10:01 +010011#include <dm.h>
Alexander Graf46c15142018-06-18 17:23:11 +020012#include <elf.h>
Alexander Graf0bd425a2016-03-04 01:10:01 +010013#include <efi_loader.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070015#include <malloc.h>
Alexander Graf0bd425a2016-03-04 01:10:01 +010016#include <rtc.h>
Simon Glass48b6c6b2019-11-14 12:57:16 -070017#include <u-boot/crc.h>
Alexander Graf0bd425a2016-03-04 01:10:01 +010018
19/* For manual relocation support */
20DECLARE_GLOBAL_DATA_PTR;
21
Heinrich Schuchardt956eff32020-02-19 20:48:49 +010022/* GUID of the runtime properties table */
23static const efi_guid_t efi_rt_properties_table_guid =
24 EFI_RT_PROPERTIES_TABLE_GUID;
25
Alexander Graf77256092016-08-16 21:08:45 +020026struct efi_runtime_mmio_list {
27 struct list_head link;
28 void **ptr;
29 u64 paddr;
30 u64 len;
31};
32
33/* This list contains all runtime available mmio regions */
34LIST_HEAD(efi_runtime_mmio);
35
Alexander Graf393dd912016-10-14 13:45:30 +020036static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void);
Alexander Graf0bd425a2016-03-04 01:10:01 +010037
Simon Glassfff89d42018-06-11 23:26:40 -060038/*
Heinrich Schuchardt11121542018-09-03 19:29:41 +020039 * TODO(sjg@chromium.org): These defines and structures should come from the ELF
40 * header for each architecture (or a generic header) rather than being repeated
41 * here.
Simon Glassfff89d42018-06-11 23:26:40 -060042 */
Alexander Graf0fe51922018-06-18 17:23:08 +020043#if defined(__aarch64__)
Alexander Graf46c15142018-06-18 17:23:11 +020044#define R_RELATIVE R_AARCH64_RELATIVE
Alexander Graf0bd425a2016-03-04 01:10:01 +010045#define R_MASK 0xffffffffULL
46#define IS_RELA 1
Alexander Graf0fe51922018-06-18 17:23:08 +020047#elif defined(__arm__)
Alexander Graf46c15142018-06-18 17:23:11 +020048#define R_RELATIVE R_ARM_RELATIVE
Alexander Graf0bd425a2016-03-04 01:10:01 +010049#define R_MASK 0xffULL
Heinrich Schuchardt56e82be2018-10-13 20:52:08 -070050#elif defined(__i386__)
Simon Glasscdfe6962016-09-25 15:27:35 -060051#define R_RELATIVE R_386_RELATIVE
52#define R_MASK 0xffULL
Heinrich Schuchardt56e82be2018-10-13 20:52:08 -070053#elif defined(__x86_64__)
54#define R_RELATIVE R_X86_64_RELATIVE
55#define R_MASK 0xffffffffULL
56#define IS_RELA 1
Alexander Graf0fe51922018-06-18 17:23:08 +020057#elif defined(__riscv)
Rick Chen9677a372018-05-28 19:06:37 +080058#define R_RELATIVE R_RISCV_RELATIVE
59#define R_MASK 0xffULL
60#define IS_RELA 1
61
62struct dyn_sym {
63 ulong foo1;
64 ulong addr;
65 u32 foo2;
66 u32 foo3;
67};
Alexander Graf0fe51922018-06-18 17:23:08 +020068#if (__riscv_xlen == 32)
Rick Chen9677a372018-05-28 19:06:37 +080069#define R_ABSOLUTE R_RISCV_32
70#define SYM_INDEX 8
Alexander Graf0fe51922018-06-18 17:23:08 +020071#elif (__riscv_xlen == 64)
Rick Chen9677a372018-05-28 19:06:37 +080072#define R_ABSOLUTE R_RISCV_64
73#define SYM_INDEX 32
Alexander Graf0fe51922018-06-18 17:23:08 +020074#else
75#error unknown riscv target
Rick Chen9677a372018-05-28 19:06:37 +080076#endif
Alexander Graf0bd425a2016-03-04 01:10:01 +010077#else
78#error Need to add relocation awareness
79#endif
80
81struct elf_rel {
82 ulong *offset;
83 ulong info;
84};
85
86struct elf_rela {
87 ulong *offset;
88 ulong info;
89 long addend;
90};
91
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +020092static __efi_runtime_data struct efi_mem_desc *efi_virtmap;
93static __efi_runtime_data efi_uintn_t efi_descriptor_count;
94static __efi_runtime_data efi_uintn_t efi_descriptor_size;
95
Alexander Graf0bd425a2016-03-04 01:10:01 +010096/*
Heinrich Schuchardt11121542018-09-03 19:29:41 +020097 * EFI runtime code lives in two stages. In the first stage, U-Boot and an EFI
Alexander Graf0bd425a2016-03-04 01:10:01 +010098 * payload are running concurrently at the same time. In this mode, we can
99 * handle a good number of runtime callbacks
100 */
101
Heinrich Schuchardt956eff32020-02-19 20:48:49 +0100102/**
103 * efi_init_runtime_supported() - create runtime properties table
104 *
105 * Create a configuration table specifying which services are available at
106 * runtime.
107 *
108 * Return: status code
109 */
AKASHI Takahiro32401842019-06-05 13:21:38 +0900110efi_status_t efi_init_runtime_supported(void)
111{
Heinrich Schuchardt956eff32020-02-19 20:48:49 +0100112 efi_status_t ret;
113 struct efi_rt_properties_table *rt_table;
114
115 ret = efi_allocate_pool(EFI_RUNTIME_SERVICES_DATA,
116 sizeof(struct efi_rt_properties_table),
117 (void **)&rt_table);
118 if (ret != EFI_SUCCESS)
119 return ret;
120
121 rt_table->version = EFI_RT_PROPERTIES_TABLE_VERSION;
122 rt_table->length = sizeof(struct efi_rt_properties_table);
123 rt_table->runtime_services_supported =
Heinrich Schuchardt5be59712020-03-24 19:54:53 +0000124 EFI_RT_SUPPORTED_GET_VARIABLE |
125 EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME |
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200126 EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP |
127 EFI_RT_SUPPORTED_CONVERT_POINTER;
AKASHI Takahiro32401842019-06-05 13:21:38 +0900128
129 /*
130 * This value must be synced with efi_runtime_detach_list
131 * as well as efi_runtime_services.
132 */
Heinrich Schuchardt05874fb2019-07-05 18:12:16 +0200133#ifdef CONFIG_EFI_HAVE_RUNTIME_RESET
Heinrich Schuchardt956eff32020-02-19 20:48:49 +0100134 rt_table->runtime_services_supported |= EFI_RT_SUPPORTED_RESET_SYSTEM;
AKASHI Takahiro32401842019-06-05 13:21:38 +0900135#endif
AKASHI Takahiro473d9b32020-11-17 09:27:55 +0900136 if (IS_ENABLED(CONFIG_EFI_RUNTIME_UPDATE_CAPSULE))
137 rt_table->runtime_services_supported |=
138 (EFI_RT_SUPPORTED_UPDATE_CAPSULE |
139 EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES);
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200140
Heinrich Schuchardt956eff32020-02-19 20:48:49 +0100141 ret = efi_install_configuration_table(&efi_rt_properties_table_guid,
142 rt_table);
143 return ret;
AKASHI Takahiro32401842019-06-05 13:21:38 +0900144}
145
Heinrich Schuchardt69c15762018-07-29 09:49:04 +0200146/**
Heinrich Schuchardt8cd99752020-06-28 16:30:29 +0200147 * efi_memcpy_runtime() - copy memory area
148 *
149 * At runtime memcpy() is not available.
150 *
Heinrich Schuchardt447753e2020-07-22 07:56:14 +0200151 * Overlapping memory areas can be copied safely if src >= dest.
152 *
Heinrich Schuchardt8cd99752020-06-28 16:30:29 +0200153 * @dest: destination buffer
154 * @src: source buffer
155 * @n: number of bytes to copy
156 * Return: pointer to destination buffer
157 */
158void __efi_runtime efi_memcpy_runtime(void *dest, const void *src, size_t n)
159{
160 u8 *d = dest;
161 const u8 *s = src;
162
163 for (; n; --n)
164 *d++ = *s++;
165}
166
167/**
Heinrich Schuchardt69c15762018-07-29 09:49:04 +0200168 * efi_update_table_header_crc32() - Update crc32 in table header
169 *
170 * @table: EFI table
171 */
172void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table)
173{
174 table->crc32 = 0;
175 table->crc32 = crc32(0, (const unsigned char *)table,
176 table->headersize);
177}
178
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200179/**
Heinrich Schuchardt11121542018-09-03 19:29:41 +0200180 * efi_reset_system_boottime() - reset system at boot time
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200181 *
182 * This function implements the ResetSystem() runtime service before
183 * SetVirtualAddressMap() is called.
184 *
185 * See the Unified Extensible Firmware Interface (UEFI) specification for
186 * details.
187 *
188 * @reset_type: type of reset to perform
189 * @reset_status: status code for the reset
190 * @data_size: size of reset_data
191 * @reset_data: information about the reset
192 */
Alexander Graf77256092016-08-16 21:08:45 +0200193static void EFIAPI efi_reset_system_boottime(
194 enum efi_reset_type reset_type,
195 efi_status_t reset_status,
196 unsigned long data_size, void *reset_data)
Alexander Graf0bd425a2016-03-04 01:10:01 +0100197{
Heinrich Schuchardtbf7f1692018-02-18 15:17:52 +0100198 struct efi_event *evt;
199
Alexander Graf0bd425a2016-03-04 01:10:01 +0100200 EFI_ENTRY("%d %lx %lx %p", reset_type, reset_status, data_size,
201 reset_data);
202
Heinrich Schuchardtbf7f1692018-02-18 15:17:52 +0100203 /* Notify reset */
204 list_for_each_entry(evt, &efi_events, link) {
205 if (evt->group &&
206 !guidcmp(evt->group,
207 &efi_guid_event_group_reset_system)) {
Heinrich Schuchardt7b4b8d862019-06-07 06:47:01 +0200208 efi_signal_event(evt);
Heinrich Schuchardtbf7f1692018-02-18 15:17:52 +0100209 break;
210 }
211 }
Alexander Graf0bd425a2016-03-04 01:10:01 +0100212 switch (reset_type) {
213 case EFI_RESET_COLD:
214 case EFI_RESET_WARM:
Heinrich Schuchardt450d4c82018-02-06 22:00:22 +0100215 case EFI_RESET_PLATFORM_SPECIFIC:
Alexander Graf0bd425a2016-03-04 01:10:01 +0100216 do_reset(NULL, 0, 0, NULL);
217 break;
218 case EFI_RESET_SHUTDOWN:
Heinrich Schuchardt44489452018-10-16 07:44:53 +0200219#ifdef CONFIG_CMD_POWEROFF
220 do_poweroff(NULL, 0, 0, NULL);
221#endif
Alexander Graf0bd425a2016-03-04 01:10:01 +0100222 break;
223 }
224
Alexander Graf77256092016-08-16 21:08:45 +0200225 while (1) { }
Alexander Graf0bd425a2016-03-04 01:10:01 +0100226}
227
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200228/**
Heinrich Schuchardt11121542018-09-03 19:29:41 +0200229 * efi_get_time_boottime() - get current time at boot time
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200230 *
231 * This function implements the GetTime runtime service before
232 * SetVirtualAddressMap() is called.
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200233 *
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200234 * See the Unified Extensible Firmware Interface (UEFI) specification
235 * for details.
236 *
237 * @time: pointer to structure to receive current time
238 * @capabilities: pointer to structure to receive RTC properties
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200239 * Returns: status code
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200240 */
Alexander Graf77256092016-08-16 21:08:45 +0200241static efi_status_t EFIAPI efi_get_time_boottime(
242 struct efi_time *time,
243 struct efi_time_cap *capabilities)
Alexander Graf0bd425a2016-03-04 01:10:01 +0100244{
Heinrich Schuchardtf2856ad2019-05-31 22:56:02 +0200245#ifdef CONFIG_EFI_GET_TIME
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200246 efi_status_t ret = EFI_SUCCESS;
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200247 struct rtc_time tm;
Alexander Graf0bd425a2016-03-04 01:10:01 +0100248 struct udevice *dev;
249
250 EFI_ENTRY("%p %p", time, capabilities);
251
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200252 if (!time) {
253 ret = EFI_INVALID_PARAMETER;
254 goto out;
255 }
Heinrich Schuchardtb4bd3662019-05-19 21:41:28 +0200256 if (uclass_get_device(UCLASS_RTC, 0, &dev) ||
257 dm_rtc_get(dev, &tm)) {
258 ret = EFI_UNSUPPORTED;
259 goto out;
260 }
261 if (dm_rtc_get(dev, &tm)) {
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200262 ret = EFI_DEVICE_ERROR;
263 goto out;
264 }
Alexander Graf0bd425a2016-03-04 01:10:01 +0100265
266 memset(time, 0, sizeof(*time));
267 time->year = tm.tm_year;
268 time->month = tm.tm_mon;
269 time->day = tm.tm_mday;
270 time->hour = tm.tm_hour;
271 time->minute = tm.tm_min;
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200272 time->second = tm.tm_sec;
Heinrich Schuchardt6846c572020-10-23 05:30:29 +0200273 if (tm.tm_isdst > 0)
Heinrich Schuchardtba3e8282019-05-31 22:08:45 +0200274 time->daylight =
275 EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT;
Heinrich Schuchardt6846c572020-10-23 05:30:29 +0200276 else if (!tm.tm_isdst)
277 time->daylight = EFI_TIME_ADJUST_DAYLIGHT;
278 else
279 time->daylight = 0;
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200280 time->timezone = EFI_UNSPECIFIED_TIMEZONE;
Alexander Graf0bd425a2016-03-04 01:10:01 +0100281
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200282 if (capabilities) {
283 /* Set reasonable dummy values */
284 capabilities->resolution = 1; /* 1 Hz */
285 capabilities->accuracy = 100000000; /* 100 ppm */
286 capabilities->sets_to_zero = false;
287 }
288out:
289 return EFI_EXIT(ret);
Alexander Graf0bd425a2016-03-04 01:10:01 +0100290#else
Heinrich Schuchardt37035b12018-07-07 23:39:14 +0200291 EFI_ENTRY("%p %p", time, capabilities);
Heinrich Schuchardtb4bd3662019-05-19 21:41:28 +0200292 return EFI_EXIT(EFI_UNSUPPORTED);
Alexander Graf0bd425a2016-03-04 01:10:01 +0100293#endif
294}
295
Heinrich Schuchardtf2856ad2019-05-31 22:56:02 +0200296#ifdef CONFIG_EFI_SET_TIME
Heinrich Schuchardt33e5a0e2019-05-31 07:35:19 +0200297
298/**
299 * efi_validate_time() - checks if timestamp is valid
300 *
301 * @time: timestamp to validate
302 * Returns: 0 if timestamp is valid, 1 otherwise
303 */
304static int efi_validate_time(struct efi_time *time)
305{
306 return (!time ||
307 time->year < 1900 || time->year > 9999 ||
308 !time->month || time->month > 12 || !time->day ||
309 time->day > rtc_month_days(time->month - 1, time->year) ||
310 time->hour > 23 || time->minute > 59 || time->second > 59 ||
311 time->nanosecond > 999999999 ||
312 time->daylight &
313 ~(EFI_TIME_IN_DAYLIGHT | EFI_TIME_ADJUST_DAYLIGHT) ||
314 ((time->timezone < -1440 || time->timezone > 1440) &&
315 time->timezone != EFI_UNSPECIFIED_TIMEZONE));
316}
317
318#endif
319
Heinrich Schuchardt411b2d52019-05-19 20:07:39 +0200320/**
321 * efi_set_time_boottime() - set current time
322 *
323 * This function implements the SetTime() runtime service before
324 * SetVirtualAddressMap() is called.
325 *
326 * See the Unified Extensible Firmware Interface (UEFI) specification
327 * for details.
328 *
329 * @time: pointer to structure to with current time
330 * Returns: status code
331 */
332static efi_status_t EFIAPI efi_set_time_boottime(struct efi_time *time)
333{
Heinrich Schuchardtf2856ad2019-05-31 22:56:02 +0200334#ifdef CONFIG_EFI_SET_TIME
Heinrich Schuchardt411b2d52019-05-19 20:07:39 +0200335 efi_status_t ret = EFI_SUCCESS;
336 struct rtc_time tm;
337 struct udevice *dev;
Alexander Graf77256092016-08-16 21:08:45 +0200338
Heinrich Schuchardt411b2d52019-05-19 20:07:39 +0200339 EFI_ENTRY("%p", time);
340
Heinrich Schuchardt33e5a0e2019-05-31 07:35:19 +0200341 if (efi_validate_time(time)) {
Heinrich Schuchardt411b2d52019-05-19 20:07:39 +0200342 ret = EFI_INVALID_PARAMETER;
343 goto out;
344 }
345
346 if (uclass_get_device(UCLASS_RTC, 0, &dev)) {
347 ret = EFI_UNSUPPORTED;
348 goto out;
349 }
350
351 memset(&tm, 0, sizeof(tm));
352 tm.tm_year = time->year;
353 tm.tm_mon = time->month;
354 tm.tm_mday = time->day;
355 tm.tm_hour = time->hour;
356 tm.tm_min = time->minute;
357 tm.tm_sec = time->second;
Heinrich Schuchardt6846c572020-10-23 05:30:29 +0200358 switch (time->daylight) {
359 case EFI_TIME_ADJUST_DAYLIGHT:
360 tm.tm_isdst = 0;
361 break;
362 case EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT:
363 tm.tm_isdst = 1;
364 break;
365 default:
366 tm.tm_isdst = -1;
367 break;
368 }
Heinrich Schuchardt411b2d52019-05-19 20:07:39 +0200369 /* Calculate day of week */
370 rtc_calc_weekday(&tm);
371
372 if (dm_rtc_set(dev, &tm))
373 ret = EFI_DEVICE_ERROR;
374out:
375 return EFI_EXIT(ret);
376#else
377 EFI_ENTRY("%p", time);
378 return EFI_EXIT(EFI_UNSUPPORTED);
379#endif
380}
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200381/**
382 * efi_reset_system() - reset system
383 *
384 * This function implements the ResetSystem() runtime service after
Heinrich Schuchardt7b66fcc2020-08-22 08:29:53 +0200385 * SetVirtualAddressMap() is called. As this placeholder cannot reset the
386 * system it simply return to the caller.
387 *
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200388 * Boards may override the helpers below to implement reset functionality.
389 *
390 * See the Unified Extensible Firmware Interface (UEFI) specification for
391 * details.
392 *
393 * @reset_type: type of reset to perform
394 * @reset_status: status code for the reset
395 * @data_size: size of reset_data
396 * @reset_data: information about the reset
397 */
Alexander Graf393dd912016-10-14 13:45:30 +0200398void __weak __efi_runtime EFIAPI efi_reset_system(
Alexander Graf77256092016-08-16 21:08:45 +0200399 enum efi_reset_type reset_type,
400 efi_status_t reset_status,
401 unsigned long data_size, void *reset_data)
402{
Heinrich Schuchardt7b66fcc2020-08-22 08:29:53 +0200403 return;
Alexander Graf77256092016-08-16 21:08:45 +0200404}
405
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200406/**
407 * efi_reset_system_init() - initialize the reset driver
408 *
409 * Boards may override this function to initialize the reset driver.
410 */
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +0100411efi_status_t __weak efi_reset_system_init(void)
Alexander Graf77256092016-08-16 21:08:45 +0200412{
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +0100413 return EFI_SUCCESS;
Alexander Graf77256092016-08-16 21:08:45 +0200414}
415
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200416/**
417 * efi_get_time() - get current time
418 *
419 * This function implements the GetTime runtime service after
420 * SetVirtualAddressMap() is called. As the U-Boot driver are not available
421 * anymore only an error code is returned.
422 *
423 * See the Unified Extensible Firmware Interface (UEFI) specification
424 * for details.
425 *
426 * @time: pointer to structure to receive current time
427 * @capabilities: pointer to structure to receive RTC properties
428 * Returns: status code
429 */
Alexander Graf393dd912016-10-14 13:45:30 +0200430efi_status_t __weak __efi_runtime EFIAPI efi_get_time(
Alexander Graf77256092016-08-16 21:08:45 +0200431 struct efi_time *time,
432 struct efi_time_cap *capabilities)
433{
Heinrich Schuchardtb4ba5be2019-06-13 18:42:40 +0200434 return EFI_UNSUPPORTED;
Alexander Graf77256092016-08-16 21:08:45 +0200435}
436
Heinrich Schuchardt411b2d52019-05-19 20:07:39 +0200437/**
438 * efi_set_time() - set current time
439 *
440 * This function implements the SetTime runtime service after
441 * SetVirtualAddressMap() is called. As the U-Boot driver are not available
442 * anymore only an error code is returned.
443 *
444 * See the Unified Extensible Firmware Interface (UEFI) specification
445 * for details.
446 *
447 * @time: pointer to structure to with current time
448 * Returns: status code
449 */
450efi_status_t __weak __efi_runtime EFIAPI efi_set_time(struct efi_time *time)
451{
452 return EFI_UNSUPPORTED;
453}
454
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000455/**
AKASHI Takahiro473d9b32020-11-17 09:27:55 +0900456 * efi_update_capsule_unsupported() - process information from operating system
457 *
458 * This function implements the UpdateCapsule() runtime service.
459 *
460 * See the Unified Extensible Firmware Interface (UEFI) specification for
461 * details.
462 *
463 * @capsule_header_array: pointer to array of virtual pointers
464 * @capsule_count: number of pointers in capsule_header_array
465 * @scatter_gather_list: pointer to array of physical pointers
466 * Returns: status code
467 */
468efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported(
469 struct efi_capsule_header **capsule_header_array,
470 efi_uintn_t capsule_count,
471 u64 scatter_gather_list)
472{
473 return EFI_UNSUPPORTED;
474}
475
476/**
477 * efi_query_capsule_caps_unsupported() - check if capsule is supported
478 *
479 * This function implements the QueryCapsuleCapabilities() runtime service.
480 *
481 * See the Unified Extensible Firmware Interface (UEFI) specification for
482 * details.
483 *
484 * @capsule_header_array: pointer to array of virtual pointers
485 * @capsule_count: number of pointers in capsule_header_array
486 * @maximum_capsule_size: maximum capsule size
487 * @reset_type: type of reset needed for capsule update
488 * Returns: status code
489 */
490efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps_unsupported(
491 struct efi_capsule_header **capsule_header_array,
492 efi_uintn_t capsule_count,
493 u64 *maximum_capsule_size,
494 u32 *reset_type)
495{
496 return EFI_UNSUPPORTED;
497}
498
499/**
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000500 * efi_is_runtime_service_pointer() - check if pointer points to runtime table
501 *
502 * @p: pointer to check
503 * Return: true if the pointer points to a service function pointer in the
504 * runtime table
505 */
506static bool efi_is_runtime_service_pointer(void *p)
Alexander Graf0bd425a2016-03-04 01:10:01 +0100507{
Heinrich Schuchardt4429d872019-07-11 20:15:09 +0200508 return (p >= (void *)&efi_runtime_services.get_time &&
509 p <= (void *)&efi_runtime_services.query_variable_info) ||
510 p == (void *)&efi_events.prev ||
511 p == (void *)&efi_events.next;
Alexander Graf0bd425a2016-03-04 01:10:01 +0100512}
513
Heinrich Schuchardtc3f2a9f2019-07-05 18:12:21 +0200514/**
515 * efi_runtime_detach() - detach unimplemented runtime functions
516 */
Heinrich Schuchardt1943dbb2019-07-05 17:42:16 +0200517void efi_runtime_detach(void)
Alexander Graf0bd425a2016-03-04 01:10:01 +0100518{
Heinrich Schuchardtc3f2a9f2019-07-05 18:12:21 +0200519 efi_runtime_services.reset_system = efi_reset_system;
520 efi_runtime_services.get_time = efi_get_time;
521 efi_runtime_services.set_time = efi_set_time;
AKASHI Takahiro473d9b32020-11-17 09:27:55 +0900522 if (IS_ENABLED(CONFIG_EFI_RUNTIME_UPDATE_CAPSULE)) {
523 /* won't support at runtime */
524 efi_runtime_services.update_capsule =
525 efi_update_capsule_unsupported;
526 efi_runtime_services.query_capsule_caps =
527 efi_query_capsule_caps_unsupported;
528 }
Alexander Graf0bd425a2016-03-04 01:10:01 +0100529
Heinrich Schuchardtc3f2a9f2019-07-05 18:12:21 +0200530 /* Update CRC32 */
531 efi_update_table_header_crc32(&efi_runtime_services.hdr);
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000532}
533
Heinrich Schuchardt25728512019-06-29 03:32:52 +0200534/**
535 * efi_set_virtual_address_map_runtime() - change from physical to virtual
536 * mapping
537 *
538 * This function implements the SetVirtualAddressMap() runtime service after
539 * it is first called.
540 *
541 * See the Unified Extensible Firmware Interface (UEFI) specification for
542 * details.
543 *
544 * @memory_map_size: size of the virtual map
545 * @descriptor_size: size of an entry in the map
546 * @descriptor_version: version of the map entries
547 * @virtmap: virtual address mapping information
548 * Return: status code EFI_UNSUPPORTED
549 */
Heinrich Schuchardt2b6bd382019-07-12 22:41:43 +0200550static __efi_runtime efi_status_t EFIAPI efi_set_virtual_address_map_runtime(
Heinrich Schuchardtf8599dc2019-07-27 20:28:47 +0200551 efi_uintn_t memory_map_size,
552 efi_uintn_t descriptor_size,
Heinrich Schuchardt25728512019-06-29 03:32:52 +0200553 uint32_t descriptor_version,
554 struct efi_mem_desc *virtmap)
555{
556 return EFI_UNSUPPORTED;
557}
558
559/**
560 * efi_convert_pointer_runtime() - convert from physical to virtual pointer
561 *
562 * This function implements the ConvertPointer() runtime service after
563 * the first call to SetVirtualAddressMap().
564 *
565 * See the Unified Extensible Firmware Interface (UEFI) specification for
566 * details.
567 *
568 * @debug_disposition: indicates if pointer may be converted to NULL
569 * @address: pointer to be converted
570 * Return: status code EFI_UNSUPPORTED
571 */
572static __efi_runtime efi_status_t EFIAPI efi_convert_pointer_runtime(
573 efi_uintn_t debug_disposition, void **address)
574{
575 return EFI_UNSUPPORTED;
576}
577
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200578/**
Heinrich Schuchardt582f8572020-03-22 08:28:15 +0100579 * efi_convert_pointer() - convert from physical to virtual pointer
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200580 *
581 * This function implements the ConvertPointer() runtime service until
582 * the first call to SetVirtualAddressMap().
583 *
584 * See the Unified Extensible Firmware Interface (UEFI) specification for
585 * details.
586 *
587 * @debug_disposition: indicates if pointer may be converted to NULL
588 * @address: pointer to be converted
Heinrich Schuchardt582f8572020-03-22 08:28:15 +0100589 * Return: status code
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200590 */
Heinrich Schuchardt699b7c62020-03-24 18:05:22 +0100591__efi_runtime efi_status_t EFIAPI
592efi_convert_pointer(efi_uintn_t debug_disposition, void **address)
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200593{
Heinrich Schuchardtb0818b72020-07-07 03:10:12 +0200594 efi_physical_addr_t addr;
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200595 efi_uintn_t i;
596 efi_status_t ret = EFI_NOT_FOUND;
597
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200598 if (!efi_virtmap) {
599 ret = EFI_UNSUPPORTED;
600 goto out;
601 }
602
603 if (!address) {
604 ret = EFI_INVALID_PARAMETER;
605 goto out;
606 }
Heinrich Schuchardtdabe54a2020-03-24 17:52:40 +0100607 if (!*address) {
608 if (debug_disposition & EFI_OPTIONAL_PTR)
609 return EFI_SUCCESS;
610 else
611 return EFI_INVALID_PARAMETER;
612 }
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200613
Heinrich Schuchardtb0818b72020-07-07 03:10:12 +0200614 addr = (uintptr_t)*address;
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200615 for (i = 0; i < efi_descriptor_count; i++) {
616 struct efi_mem_desc *map = (void *)efi_virtmap +
617 (efi_descriptor_size * i);
618
619 if (addr >= map->physical_start &&
620 (addr < map->physical_start
621 + (map->num_pages << EFI_PAGE_SHIFT))) {
622 *address = (void *)(uintptr_t)
623 (addr + map->virtual_start -
624 map->physical_start);
625
626 ret = EFI_SUCCESS;
627 break;
628 }
629 }
630
631out:
Heinrich Schuchardt699b7c62020-03-24 18:05:22 +0100632 return ret;
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200633}
634
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000635static __efi_runtime void efi_relocate_runtime_table(ulong offset)
636{
637 ulong patchoff;
638 void **pos;
639
640 /* Relocate the runtime services pointers */
641 patchoff = offset - gd->relocaddr;
642 for (pos = (void **)&efi_runtime_services.get_time;
643 pos <= (void **)&efi_runtime_services.query_variable_info; ++pos) {
Heinrich Schuchardt25728512019-06-29 03:32:52 +0200644 if (*pos)
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000645 *pos += patchoff;
646 }
Heinrich Schuchardt69c15762018-07-29 09:49:04 +0200647
Heinrich Schuchardt25728512019-06-29 03:32:52 +0200648 /*
649 * The entry for SetVirtualAddress() must point to a physical address.
650 * After the first execution the service must return EFI_UNSUPPORTED.
651 */
652 efi_runtime_services.set_virtual_address_map =
653 &efi_set_virtual_address_map_runtime;
654
655 /*
656 * The entry for ConvertPointer() must point to a physical address.
657 * The service is not usable after SetVirtualAddress().
658 */
659 efi_runtime_services.convert_pointer = &efi_convert_pointer_runtime;
660
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200661 /*
662 * TODO: Update UEFI variable RuntimeServicesSupported removing flags
663 * EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP and
664 * EFI_RT_SUPPORTED_CONVERT_POINTER as required by the UEFI spec 2.8.
665 */
666
Heinrich Schuchardt11121542018-09-03 19:29:41 +0200667 /* Update CRC32 */
Heinrich Schuchardt69c15762018-07-29 09:49:04 +0200668 efi_update_table_header_crc32(&efi_runtime_services.hdr);
Alexander Graf0bd425a2016-03-04 01:10:01 +0100669}
670
671/* Relocate EFI runtime to uboot_reloc_base = offset */
672void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
673{
674#ifdef IS_RELA
675 struct elf_rela *rel = (void*)&__efi_runtime_rel_start;
676#else
677 struct elf_rel *rel = (void*)&__efi_runtime_rel_start;
678 static ulong lastoff = CONFIG_SYS_TEXT_BASE;
679#endif
680
Alexander Graf62a67482016-06-02 11:38:27 +0200681 debug("%s: Relocating to offset=%lx\n", __func__, offset);
Alexander Graf0bd425a2016-03-04 01:10:01 +0100682 for (; (ulong)rel < (ulong)&__efi_runtime_rel_stop; rel++) {
683 ulong base = CONFIG_SYS_TEXT_BASE;
684 ulong *p;
685 ulong newaddr;
686
687 p = (void*)((ulong)rel->offset - base) + gd->relocaddr;
688
Heinrich Schuchardt33691582019-08-14 06:49:09 +0200689 /*
690 * The runtime services table is updated in
691 * efi_relocate_runtime_table()
692 */
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000693 if (map && efi_is_runtime_service_pointer(p))
694 continue;
695
Heinrich Schuchardt56e82be2018-10-13 20:52:08 -0700696 debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__,
697 rel->info, *p, rel->offset);
Alexander Graf0bd425a2016-03-04 01:10:01 +0100698
Rick Chen9677a372018-05-28 19:06:37 +0800699 switch (rel->info & R_MASK) {
700 case R_RELATIVE:
Alexander Graf0bd425a2016-03-04 01:10:01 +0100701#ifdef IS_RELA
702 newaddr = rel->addend + offset - CONFIG_SYS_TEXT_BASE;
703#else
704 newaddr = *p - lastoff + offset;
705#endif
Rick Chen9677a372018-05-28 19:06:37 +0800706 break;
707#ifdef R_ABSOLUTE
708 case R_ABSOLUTE: {
709 ulong symidx = rel->info >> SYM_INDEX;
710 extern struct dyn_sym __dyn_sym_start[];
711 newaddr = __dyn_sym_start[symidx].addr + offset;
Alexander Grafdf0f6c72018-11-04 22:25:22 +0100712#ifdef IS_RELA
713 newaddr -= CONFIG_SYS_TEXT_BASE;
714#endif
Rick Chen9677a372018-05-28 19:06:37 +0800715 break;
716 }
717#endif
718 default:
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000719 printf("%s: Unknown relocation type %llx\n",
720 __func__, rel->info & R_MASK);
Rick Chen9677a372018-05-28 19:06:37 +0800721 continue;
722 }
Alexander Graf0bd425a2016-03-04 01:10:01 +0100723
724 /* Check if the relocation is inside bounds */
725 if (map && ((newaddr < map->virtual_start) ||
Heinrich Schuchardt9ebc47f2017-09-18 22:11:34 +0200726 newaddr > (map->virtual_start +
727 (map->num_pages << EFI_PAGE_SHIFT)))) {
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000728 printf("%s: Relocation at %p is out of range (%lx)\n",
729 __func__, p, newaddr);
Alexander Graf0bd425a2016-03-04 01:10:01 +0100730 continue;
731 }
732
Alexander Graf62a67482016-06-02 11:38:27 +0200733 debug("%s: Setting %p to %lx\n", __func__, p, newaddr);
Alexander Graf0bd425a2016-03-04 01:10:01 +0100734 *p = newaddr;
Alexander Grafe5702322016-04-11 23:20:39 +0200735 flush_dcache_range((ulong)p & ~(EFI_CACHELINE_SIZE - 1),
736 ALIGN((ulong)&p[1], EFI_CACHELINE_SIZE));
Alexander Graf0bd425a2016-03-04 01:10:01 +0100737 }
738
739#ifndef IS_RELA
740 lastoff = offset;
741#endif
742
743 invalidate_icache_all();
744}
745
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200746/**
747 * efi_set_virtual_address_map() - change from physical to virtual mapping
748 *
749 * This function implements the SetVirtualAddressMap() runtime service.
750 *
751 * See the Unified Extensible Firmware Interface (UEFI) specification for
752 * details.
753 *
754 * @memory_map_size: size of the virtual map
755 * @descriptor_size: size of an entry in the map
756 * @descriptor_version: version of the map entries
757 * @virtmap: virtual address mapping information
758 * Return: status code
759 */
Alexander Graf0bd425a2016-03-04 01:10:01 +0100760static efi_status_t EFIAPI efi_set_virtual_address_map(
Heinrich Schuchardtf8599dc2019-07-27 20:28:47 +0200761 efi_uintn_t memory_map_size,
762 efi_uintn_t descriptor_size,
Alexander Graf0bd425a2016-03-04 01:10:01 +0100763 uint32_t descriptor_version,
764 struct efi_mem_desc *virtmap)
765{
Heinrich Schuchardtf8599dc2019-07-27 20:28:47 +0200766 efi_uintn_t n = memory_map_size / descriptor_size;
767 efi_uintn_t i;
Heinrich Schuchardtc70a1612019-08-14 05:19:37 +0200768 efi_status_t ret = EFI_INVALID_PARAMETER;
Alexander Graf86e00212018-12-11 10:00:42 +0100769 int rt_code_sections = 0;
Heinrich Schuchardt4429d872019-07-11 20:15:09 +0200770 struct efi_event *event;
Alexander Graf0bd425a2016-03-04 01:10:01 +0100771
Heinrich Schuchardtf8599dc2019-07-27 20:28:47 +0200772 EFI_ENTRY("%zx %zx %x %p", memory_map_size, descriptor_size,
Alexander Graf0bd425a2016-03-04 01:10:01 +0100773 descriptor_version, virtmap);
774
Heinrich Schuchardtc70a1612019-08-14 05:19:37 +0200775 if (descriptor_version != EFI_MEMORY_DESCRIPTOR_VERSION ||
776 descriptor_size < sizeof(struct efi_mem_desc))
777 goto out;
778
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200779 efi_virtmap = virtmap;
780 efi_descriptor_size = descriptor_size;
781 efi_descriptor_count = n;
782
Alexander Graf86e00212018-12-11 10:00:42 +0100783 /*
784 * TODO:
785 * Further down we are cheating. While really we should implement
786 * SetVirtualAddressMap() events and ConvertPointer() to allow
787 * dynamically loaded drivers to expose runtime services, we don't
788 * today.
789 *
790 * So let's ensure we see exactly one single runtime section, as
791 * that is the built-in one. If we see more (or less), someone must
792 * have tried adding or removing to that which we don't support yet.
793 * In that case, let's better fail rather than expose broken runtime
794 * services.
795 */
796 for (i = 0; i < n; i++) {
797 struct efi_mem_desc *map = (void*)virtmap +
798 (descriptor_size * i);
799
800 if (map->type == EFI_RUNTIME_SERVICES_CODE)
801 rt_code_sections++;
802 }
803
804 if (rt_code_sections != 1) {
805 /*
806 * We expose exactly one single runtime code section, so
807 * something is definitely going wrong.
808 */
Heinrich Schuchardtc70a1612019-08-14 05:19:37 +0200809 goto out;
Alexander Graf86e00212018-12-11 10:00:42 +0100810 }
811
Heinrich Schuchardt4429d872019-07-11 20:15:09 +0200812 /* Notify EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE */
813 list_for_each_entry(event, &efi_events, link) {
814 if (event->notify_function)
815 EFI_CALL_VOID(event->notify_function(
816 event, event->notify_context));
817 }
818
Alexander Graf77256092016-08-16 21:08:45 +0200819 /* Rebind mmio pointers */
820 for (i = 0; i < n; i++) {
821 struct efi_mem_desc *map = (void*)virtmap +
822 (descriptor_size * i);
823 struct list_head *lhandle;
824 efi_physical_addr_t map_start = map->physical_start;
825 efi_physical_addr_t map_len = map->num_pages << EFI_PAGE_SHIFT;
826 efi_physical_addr_t map_end = map_start + map_len;
Heinrich Schuchardt39054562018-08-04 23:16:06 +0200827 u64 off = map->virtual_start - map_start;
Alexander Graf77256092016-08-16 21:08:45 +0200828
829 /* Adjust all mmio pointers in this region */
830 list_for_each(lhandle, &efi_runtime_mmio) {
831 struct efi_runtime_mmio_list *lmmio;
832
833 lmmio = list_entry(lhandle,
834 struct efi_runtime_mmio_list,
835 link);
836 if ((map_start <= lmmio->paddr) &&
837 (map_end >= lmmio->paddr)) {
Alexander Graf77256092016-08-16 21:08:45 +0200838 uintptr_t new_addr = lmmio->paddr + off;
839 *lmmio->ptr = (void *)new_addr;
840 }
841 }
Heinrich Schuchardt39054562018-08-04 23:16:06 +0200842 if ((map_start <= (uintptr_t)systab.tables) &&
843 (map_end >= (uintptr_t)systab.tables)) {
844 char *ptr = (char *)systab.tables;
845
846 ptr += off;
847 systab.tables = (struct efi_configuration_table *)ptr;
848 }
Alexander Graf77256092016-08-16 21:08:45 +0200849 }
850
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000851 /* Relocate the runtime. See TODO above */
Alexander Graf0bd425a2016-03-04 01:10:01 +0100852 for (i = 0; i < n; i++) {
853 struct efi_mem_desc *map;
854
855 map = (void*)virtmap + (descriptor_size * i);
856 if (map->type == EFI_RUNTIME_SERVICES_CODE) {
Alexander Graf77256092016-08-16 21:08:45 +0200857 ulong new_offset = map->virtual_start -
Alexander Graf86e00212018-12-11 10:00:42 +0100858 map->physical_start + gd->relocaddr;
Alexander Graf0bd425a2016-03-04 01:10:01 +0100859
Heinrich Schuchardt19cd80b2019-06-20 22:00:02 +0000860 efi_relocate_runtime_table(new_offset);
Alexander Graf0bd425a2016-03-04 01:10:01 +0100861 efi_runtime_relocate(new_offset, map);
Heinrich Schuchardtc70a1612019-08-14 05:19:37 +0200862 ret = EFI_SUCCESS;
863 goto out;
Alexander Graf0bd425a2016-03-04 01:10:01 +0100864 }
865 }
866
Heinrich Schuchardtc70a1612019-08-14 05:19:37 +0200867out:
868 return EFI_EXIT(ret);
Alexander Graf0bd425a2016-03-04 01:10:01 +0100869}
870
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200871/**
872 * efi_add_runtime_mmio() - add memory-mapped IO region
873 *
874 * This function adds a memory-mapped IO region to the memory map to make it
875 * available at runtime.
876 *
Heinrich Schuchardt7e307642018-12-23 02:35:13 +0100877 * @mmio_ptr: pointer to a pointer to the start of the memory-mapped
878 * IO region
Heinrich Schuchardt11121542018-09-03 19:29:41 +0200879 * @len: size of the memory-mapped IO region
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200880 * Returns: status code
881 */
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +0100882efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len)
Alexander Graf77256092016-08-16 21:08:45 +0200883{
884 struct efi_runtime_mmio_list *newmmio;
Alexander Graf33a83a32018-03-15 15:08:16 +0100885 uint64_t addr = *(uintptr_t *)mmio_ptr;
Bryan O'Donoghue89a22b42019-07-15 12:00:39 +0100886 efi_status_t ret;
Alexander Graf33a83a32018-03-15 15:08:16 +0100887
Michael Walle282d3862020-05-17 12:29:19 +0200888 ret = efi_add_memory_map(addr, len, EFI_MMAP_IO);
Bryan O'Donoghue89a22b42019-07-15 12:00:39 +0100889 if (ret != EFI_SUCCESS)
Alexander Graf33a83a32018-03-15 15:08:16 +0100890 return EFI_OUT_OF_RESOURCES;
Alexander Graf77256092016-08-16 21:08:45 +0200891
892 newmmio = calloc(1, sizeof(*newmmio));
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +0100893 if (!newmmio)
894 return EFI_OUT_OF_RESOURCES;
Alexander Graf77256092016-08-16 21:08:45 +0200895 newmmio->ptr = mmio_ptr;
896 newmmio->paddr = *(uintptr_t *)mmio_ptr;
897 newmmio->len = len;
898 list_add_tail(&newmmio->link, &efi_runtime_mmio);
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +0100899
Alexander Graf33a83a32018-03-15 15:08:16 +0100900 return EFI_SUCCESS;
Alexander Graf77256092016-08-16 21:08:45 +0200901}
902
Alexander Graf0bd425a2016-03-04 01:10:01 +0100903/*
904 * In the second stage, U-Boot has disappeared. To isolate our runtime code
905 * that at this point still exists from the rest, we put it into a special
906 * section.
907 *
908 * !!WARNING!!
909 *
910 * This means that we can not rely on any code outside of this file in any
911 * function or variable below this line.
912 *
913 * Please keep everything fully self-contained and annotated with
Alexander Graf393dd912016-10-14 13:45:30 +0200914 * __efi_runtime and __efi_runtime_data markers.
Alexander Graf0bd425a2016-03-04 01:10:01 +0100915 */
916
917/*
918 * Relocate the EFI runtime stub to a different place. We need to call this
919 * the first time we expose the runtime interface to a user and on set virtual
920 * address map calls.
921 */
922
Heinrich Schuchardt711853b2018-07-29 15:10:11 +0200923/**
924 * efi_unimplemented() - replacement function, returns EFI_UNSUPPORTED
925 *
926 * This function is used after SetVirtualAddressMap() is called as replacement
927 * for services that are not available anymore due to constraints of the U-Boot
928 * implementation.
929 *
930 * Return: EFI_UNSUPPORTED
931 */
Alexander Graf393dd912016-10-14 13:45:30 +0200932static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void)
Alexander Graf0bd425a2016-03-04 01:10:01 +0100933{
934 return EFI_UNSUPPORTED;
935}
936
Alexander Graf393dd912016-10-14 13:45:30 +0200937struct efi_runtime_services __efi_runtime_data efi_runtime_services = {
Alexander Graf0bd425a2016-03-04 01:10:01 +0100938 .hdr = {
939 .signature = EFI_RUNTIME_SERVICES_SIGNATURE,
Heinrich Schuchardte75b3cb2018-06-28 12:45:27 +0200940 .revision = EFI_SPECIFICATION_VERSION,
Heinrich Schuchardt10204252018-06-28 12:45:29 +0200941 .headersize = sizeof(struct efi_runtime_services),
Alexander Graf0bd425a2016-03-04 01:10:01 +0100942 },
Alexander Graf77256092016-08-16 21:08:45 +0200943 .get_time = &efi_get_time_boottime,
Heinrich Schuchardt411b2d52019-05-19 20:07:39 +0200944 .set_time = &efi_set_time_boottime,
Alexander Graf0bd425a2016-03-04 01:10:01 +0100945 .get_wakeup_time = (void *)&efi_unimplemented,
946 .set_wakeup_time = (void *)&efi_unimplemented,
947 .set_virtual_address_map = &efi_set_virtual_address_map,
Heinrich Schuchardtc680dc42019-07-27 20:35:24 +0200948 .convert_pointer = efi_convert_pointer,
Rob Clark15f3d742017-09-13 18:05:37 -0400949 .get_variable = efi_get_variable,
Heinrich Schuchardtd6a6baa2018-05-17 07:57:05 +0200950 .get_next_variable_name = efi_get_next_variable_name,
Rob Clark15f3d742017-09-13 18:05:37 -0400951 .set_variable = efi_set_variable,
Heinrich Schuchardt5337a6c2019-06-20 15:40:49 +0200952 .get_next_high_mono_count = (void *)&efi_unimplemented,
Alexander Graf77256092016-08-16 21:08:45 +0200953 .reset_system = &efi_reset_system_boottime,
AKASHI Takahiro473d9b32020-11-17 09:27:55 +0900954#ifdef CONFIG_EFI_RUNTIME_UPDATE_CAPSULE
Heinrich Schuchardt897c0722018-02-09 20:41:21 +0100955 .update_capsule = efi_update_capsule,
956 .query_capsule_caps = efi_query_capsule_caps,
AKASHI Takahiro473d9b32020-11-17 09:27:55 +0900957#else
958 .update_capsule = efi_update_capsule_unsupported,
959 .query_capsule_caps = efi_query_capsule_caps_unsupported,
960#endif
Heinrich Schuchardt897c0722018-02-09 20:41:21 +0100961 .query_variable_info = efi_query_variable_info,
Alexander Graf0bd425a2016-03-04 01:10:01 +0100962};