blob: 18da6892e7964f1371f8a298aa9a58305e9ebfb4 [file] [log] [blame]
Tom Rinif739fcd2018-05-07 17:02:21 -04001// SPDX-License-Identifier: GPL-2.0+
Alexander Graf50149ea2016-03-04 01:10:01 +01002/*
3 * EFI application runtime services
4 *
5 * Copyright (c) 2016 Alexander Graf
Alexander Graf50149ea2016-03-04 01:10:01 +01006 */
7
Alexander Graf50149ea2016-03-04 01:10:01 +01008#include <command.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -07009#include <cpu_func.h>
Alexander Graf50149ea2016-03-04 01:10:01 +010010#include <dm.h>
Alexander Grafb34662d2018-06-18 17:23:11 +020011#include <elf.h>
Alexander Graf50149ea2016-03-04 01:10:01 +010012#include <efi_loader.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -070014#include <malloc.h>
Alexander Graf50149ea2016-03-04 01:10:01 +010015#include <rtc.h>
Simon Glass401d1c42020-10-30 21:38:53 -060016#include <asm/global_data.h>
Simon Glass3db71102019-11-14 12:57:16 -070017#include <u-boot/crc.h>
Alexander Graf50149ea2016-03-04 01:10:01 +010018
19/* For manual relocation support */
20DECLARE_GLOBAL_DATA_PTR;
21
Heinrich Schuchardt76be6872020-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 Graf80a48002016-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 */
Bin Meng6fc4fc32023-04-05 20:15:19 +080034static LIST_HEAD(efi_runtime_mmio);
Alexander Graf80a48002016-08-16 21:08:45 +020035
Alexander Graf3c63db92016-10-14 13:45:30 +020036static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void);
Alexander Graf50149ea2016-03-04 01:10:01 +010037
Simon Glass2d2b5b22018-06-11 23:26:40 -060038/*
Heinrich Schuchardt250b3252018-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 Glass2d2b5b22018-06-11 23:26:40 -060042 */
Alexander Grafbc028912018-06-18 17:23:08 +020043#if defined(__aarch64__)
Alexander Grafb34662d2018-06-18 17:23:11 +020044#define R_RELATIVE R_AARCH64_RELATIVE
Alexander Graf50149ea2016-03-04 01:10:01 +010045#define R_MASK 0xffffffffULL
46#define IS_RELA 1
Alexander Grafbc028912018-06-18 17:23:08 +020047#elif defined(__arm__)
Alexander Grafb34662d2018-06-18 17:23:11 +020048#define R_RELATIVE R_ARM_RELATIVE
Alexander Graf50149ea2016-03-04 01:10:01 +010049#define R_MASK 0xffULL
Heinrich Schuchardt3ce78292018-10-13 20:52:08 -070050#elif defined(__i386__)
Simon Glass65e4c0b2016-09-25 15:27:35 -060051#define R_RELATIVE R_386_RELATIVE
52#define R_MASK 0xffULL
Heinrich Schuchardt3ce78292018-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 Grafbc028912018-06-18 17:23:08 +020057#elif defined(__riscv)
Rick Chen6836adb2018-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 Grafbc028912018-06-18 17:23:08 +020068#if (__riscv_xlen == 32)
Rick Chen6836adb2018-05-28 19:06:37 +080069#define R_ABSOLUTE R_RISCV_32
70#define SYM_INDEX 8
Alexander Grafbc028912018-06-18 17:23:08 +020071#elif (__riscv_xlen == 64)
Rick Chen6836adb2018-05-28 19:06:37 +080072#define R_ABSOLUTE R_RISCV_64
73#define SYM_INDEX 32
Alexander Grafbc028912018-06-18 17:23:08 +020074#else
75#error unknown riscv target
Rick Chen6836adb2018-05-28 19:06:37 +080076#endif
Alexander Graf50149ea2016-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 Schuchardt7be56e82019-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 Graf50149ea2016-03-04 01:10:01 +010096/*
Heinrich Schuchardt250b3252018-09-03 19:29:41 +020097 * EFI runtime code lives in two stages. In the first stage, U-Boot and an EFI
Alexander Graf50149ea2016-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 Schuchardt76be6872020-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 Takahiroe771b4b2019-06-05 13:21:38 +0900110efi_status_t efi_init_runtime_supported(void)
111{
Heinrich Schuchardt76be6872020-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 Schuchardtb02a7072020-03-24 19:54:53 +0000124 EFI_RT_SUPPORTED_GET_VARIABLE |
125 EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME |
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200126 EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP |
127 EFI_RT_SUPPORTED_CONVERT_POINTER;
AKASHI Takahiroe771b4b2019-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 Schuchardt953661a2019-07-05 18:12:16 +0200133#ifdef CONFIG_EFI_HAVE_RUNTIME_RESET
Heinrich Schuchardt76be6872020-02-19 20:48:49 +0100134 rt_table->runtime_services_supported |= EFI_RT_SUPPORTED_RESET_SYSTEM;
AKASHI Takahiroe771b4b2019-06-05 13:21:38 +0900135#endif
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200136
Heinrich Schuchardt76be6872020-02-19 20:48:49 +0100137 ret = efi_install_configuration_table(&efi_rt_properties_table_guid,
138 rt_table);
139 return ret;
AKASHI Takahiroe771b4b2019-06-05 13:21:38 +0900140}
141
Heinrich Schuchardta39f39c2018-07-29 09:49:04 +0200142/**
Heinrich Schuchardtb0dd8cb2020-06-28 16:30:29 +0200143 * efi_memcpy_runtime() - copy memory area
144 *
145 * At runtime memcpy() is not available.
146 *
Heinrich Schuchardtebbad022020-07-22 07:56:14 +0200147 * Overlapping memory areas can be copied safely if src >= dest.
148 *
Heinrich Schuchardtb0dd8cb2020-06-28 16:30:29 +0200149 * @dest: destination buffer
150 * @src: source buffer
151 * @n: number of bytes to copy
152 * Return: pointer to destination buffer
153 */
154void __efi_runtime efi_memcpy_runtime(void *dest, const void *src, size_t n)
155{
156 u8 *d = dest;
157 const u8 *s = src;
158
159 for (; n; --n)
160 *d++ = *s++;
161}
162
163/**
Heinrich Schuchardta39f39c2018-07-29 09:49:04 +0200164 * efi_update_table_header_crc32() - Update crc32 in table header
165 *
166 * @table: EFI table
167 */
168void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table)
169{
170 table->crc32 = 0;
171 table->crc32 = crc32(0, (const unsigned char *)table,
172 table->headersize);
173}
174
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200175/**
Heinrich Schuchardt250b3252018-09-03 19:29:41 +0200176 * efi_reset_system_boottime() - reset system at boot time
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200177 *
178 * This function implements the ResetSystem() runtime service before
179 * SetVirtualAddressMap() is called.
180 *
181 * See the Unified Extensible Firmware Interface (UEFI) specification for
182 * details.
183 *
184 * @reset_type: type of reset to perform
185 * @reset_status: status code for the reset
186 * @data_size: size of reset_data
187 * @reset_data: information about the reset
188 */
Alexander Graf80a48002016-08-16 21:08:45 +0200189static void EFIAPI efi_reset_system_boottime(
190 enum efi_reset_type reset_type,
191 efi_status_t reset_status,
192 unsigned long data_size, void *reset_data)
Alexander Graf50149ea2016-03-04 01:10:01 +0100193{
Heinrich Schuchardtb095f3c2018-02-18 15:17:52 +0100194 struct efi_event *evt;
195
Alexander Graf50149ea2016-03-04 01:10:01 +0100196 EFI_ENTRY("%d %lx %lx %p", reset_type, reset_status, data_size,
197 reset_data);
198
Heinrich Schuchardtb095f3c2018-02-18 15:17:52 +0100199 /* Notify reset */
200 list_for_each_entry(evt, &efi_events, link) {
201 if (evt->group &&
202 !guidcmp(evt->group,
203 &efi_guid_event_group_reset_system)) {
Heinrich Schuchardt7eaa9002019-06-07 06:47:01 +0200204 efi_signal_event(evt);
Heinrich Schuchardtb095f3c2018-02-18 15:17:52 +0100205 break;
206 }
207 }
Alexander Graf50149ea2016-03-04 01:10:01 +0100208 switch (reset_type) {
209 case EFI_RESET_COLD:
210 case EFI_RESET_WARM:
Heinrich Schuchardt482fc902018-02-06 22:00:22 +0100211 case EFI_RESET_PLATFORM_SPECIFIC:
Alexander Graf50149ea2016-03-04 01:10:01 +0100212 do_reset(NULL, 0, 0, NULL);
213 break;
214 case EFI_RESET_SHUTDOWN:
Heinrich Schuchardte706ed72018-10-16 07:44:53 +0200215#ifdef CONFIG_CMD_POWEROFF
216 do_poweroff(NULL, 0, 0, NULL);
217#endif
Alexander Graf50149ea2016-03-04 01:10:01 +0100218 break;
219 }
220
Alexander Graf80a48002016-08-16 21:08:45 +0200221 while (1) { }
Alexander Graf50149ea2016-03-04 01:10:01 +0100222}
223
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200224/**
Heinrich Schuchardt250b3252018-09-03 19:29:41 +0200225 * efi_get_time_boottime() - get current time at boot time
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200226 *
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200227 * This function implements the GetTime runtime service before
228 * SetVirtualAddressMap() is called.
229 *
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200230 * See the Unified Extensible Firmware Interface (UEFI) specification
231 * for details.
232 *
233 * @time: pointer to structure to receive current time
234 * @capabilities: pointer to structure to receive RTC properties
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200235 * Returns: status code
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200236 */
Alexander Graf80a48002016-08-16 21:08:45 +0200237static efi_status_t EFIAPI efi_get_time_boottime(
238 struct efi_time *time,
239 struct efi_time_cap *capabilities)
Alexander Graf50149ea2016-03-04 01:10:01 +0100240{
Heinrich Schuchardt5ec48e32019-05-31 22:56:02 +0200241#ifdef CONFIG_EFI_GET_TIME
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200242 efi_status_t ret = EFI_SUCCESS;
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200243 struct rtc_time tm;
Alexander Graf50149ea2016-03-04 01:10:01 +0100244 struct udevice *dev;
245
246 EFI_ENTRY("%p %p", time, capabilities);
247
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200248 if (!time) {
249 ret = EFI_INVALID_PARAMETER;
250 goto out;
251 }
Heinrich Schuchardtbb2b13d2019-05-19 21:41:28 +0200252 if (uclass_get_device(UCLASS_RTC, 0, &dev) ||
253 dm_rtc_get(dev, &tm)) {
254 ret = EFI_UNSUPPORTED;
255 goto out;
256 }
257 if (dm_rtc_get(dev, &tm)) {
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200258 ret = EFI_DEVICE_ERROR;
259 goto out;
260 }
Alexander Graf50149ea2016-03-04 01:10:01 +0100261
262 memset(time, 0, sizeof(*time));
263 time->year = tm.tm_year;
264 time->month = tm.tm_mon;
265 time->day = tm.tm_mday;
266 time->hour = tm.tm_hour;
267 time->minute = tm.tm_min;
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200268 time->second = tm.tm_sec;
Heinrich Schuchardt0eae5522020-10-23 05:30:29 +0200269 if (tm.tm_isdst > 0)
Heinrich Schuchardt38b9a792019-05-31 22:08:45 +0200270 time->daylight =
271 EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT;
Heinrich Schuchardt0eae5522020-10-23 05:30:29 +0200272 else if (!tm.tm_isdst)
273 time->daylight = EFI_TIME_ADJUST_DAYLIGHT;
274 else
275 time->daylight = 0;
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200276 time->timezone = EFI_UNSPECIFIED_TIMEZONE;
Alexander Graf50149ea2016-03-04 01:10:01 +0100277
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200278 if (capabilities) {
279 /* Set reasonable dummy values */
280 capabilities->resolution = 1; /* 1 Hz */
281 capabilities->accuracy = 100000000; /* 100 ppm */
282 capabilities->sets_to_zero = false;
283 }
284out:
285 return EFI_EXIT(ret);
Alexander Graf50149ea2016-03-04 01:10:01 +0100286#else
Heinrich Schuchardt49de2452018-07-07 23:39:14 +0200287 EFI_ENTRY("%p %p", time, capabilities);
Heinrich Schuchardtbb2b13d2019-05-19 21:41:28 +0200288 return EFI_EXIT(EFI_UNSUPPORTED);
Alexander Graf50149ea2016-03-04 01:10:01 +0100289#endif
290}
291
Heinrich Schuchardt5ec48e32019-05-31 22:56:02 +0200292#ifdef CONFIG_EFI_SET_TIME
Heinrich Schuchardte6bcc352019-05-31 07:35:19 +0200293
294/**
295 * efi_validate_time() - checks if timestamp is valid
296 *
297 * @time: timestamp to validate
298 * Returns: 0 if timestamp is valid, 1 otherwise
299 */
300static int efi_validate_time(struct efi_time *time)
301{
302 return (!time ||
303 time->year < 1900 || time->year > 9999 ||
304 !time->month || time->month > 12 || !time->day ||
305 time->day > rtc_month_days(time->month - 1, time->year) ||
306 time->hour > 23 || time->minute > 59 || time->second > 59 ||
307 time->nanosecond > 999999999 ||
308 time->daylight &
309 ~(EFI_TIME_IN_DAYLIGHT | EFI_TIME_ADJUST_DAYLIGHT) ||
310 ((time->timezone < -1440 || time->timezone > 1440) &&
311 time->timezone != EFI_UNSPECIFIED_TIMEZONE));
312}
313
314#endif
315
Heinrich Schuchardt433bfe72019-05-19 20:07:39 +0200316/**
317 * efi_set_time_boottime() - set current time
318 *
319 * This function implements the SetTime() runtime service before
320 * SetVirtualAddressMap() is called.
321 *
322 * See the Unified Extensible Firmware Interface (UEFI) specification
323 * for details.
324 *
325 * @time: pointer to structure to with current time
326 * Returns: status code
327 */
328static efi_status_t EFIAPI efi_set_time_boottime(struct efi_time *time)
329{
Heinrich Schuchardt5ec48e32019-05-31 22:56:02 +0200330#ifdef CONFIG_EFI_SET_TIME
Heinrich Schuchardt433bfe72019-05-19 20:07:39 +0200331 efi_status_t ret = EFI_SUCCESS;
332 struct rtc_time tm;
333 struct udevice *dev;
Alexander Graf80a48002016-08-16 21:08:45 +0200334
Heinrich Schuchardt433bfe72019-05-19 20:07:39 +0200335 EFI_ENTRY("%p", time);
336
Heinrich Schuchardte6bcc352019-05-31 07:35:19 +0200337 if (efi_validate_time(time)) {
Heinrich Schuchardt433bfe72019-05-19 20:07:39 +0200338 ret = EFI_INVALID_PARAMETER;
339 goto out;
340 }
341
342 if (uclass_get_device(UCLASS_RTC, 0, &dev)) {
343 ret = EFI_UNSUPPORTED;
344 goto out;
345 }
346
347 memset(&tm, 0, sizeof(tm));
348 tm.tm_year = time->year;
349 tm.tm_mon = time->month;
350 tm.tm_mday = time->day;
351 tm.tm_hour = time->hour;
352 tm.tm_min = time->minute;
353 tm.tm_sec = time->second;
Heinrich Schuchardt0eae5522020-10-23 05:30:29 +0200354 switch (time->daylight) {
355 case EFI_TIME_ADJUST_DAYLIGHT:
356 tm.tm_isdst = 0;
357 break;
358 case EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT:
359 tm.tm_isdst = 1;
360 break;
361 default:
362 tm.tm_isdst = -1;
363 break;
364 }
Heinrich Schuchardt433bfe72019-05-19 20:07:39 +0200365 /* Calculate day of week */
366 rtc_calc_weekday(&tm);
367
368 if (dm_rtc_set(dev, &tm))
369 ret = EFI_DEVICE_ERROR;
370out:
371 return EFI_EXIT(ret);
372#else
373 EFI_ENTRY("%p", time);
374 return EFI_EXIT(EFI_UNSUPPORTED);
375#endif
376}
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200377/**
378 * efi_reset_system() - reset system
379 *
380 * This function implements the ResetSystem() runtime service after
Heinrich Schuchardtf03a8792020-08-22 08:29:53 +0200381 * SetVirtualAddressMap() is called. As this placeholder cannot reset the
382 * system it simply return to the caller.
383 *
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200384 * Boards may override the helpers below to implement reset functionality.
385 *
386 * See the Unified Extensible Firmware Interface (UEFI) specification for
387 * details.
388 *
389 * @reset_type: type of reset to perform
390 * @reset_status: status code for the reset
391 * @data_size: size of reset_data
392 * @reset_data: information about the reset
393 */
Alexander Graf3c63db92016-10-14 13:45:30 +0200394void __weak __efi_runtime EFIAPI efi_reset_system(
Alexander Graf80a48002016-08-16 21:08:45 +0200395 enum efi_reset_type reset_type,
396 efi_status_t reset_status,
397 unsigned long data_size, void *reset_data)
398{
Heinrich Schuchardtf03a8792020-08-22 08:29:53 +0200399 return;
Alexander Graf80a48002016-08-16 21:08:45 +0200400}
401
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200402/**
403 * efi_reset_system_init() - initialize the reset driver
404 *
405 * Boards may override this function to initialize the reset driver.
406 */
Heinrich Schuchardt22c793e2018-03-03 15:28:59 +0100407efi_status_t __weak efi_reset_system_init(void)
Alexander Graf80a48002016-08-16 21:08:45 +0200408{
Heinrich Schuchardt22c793e2018-03-03 15:28:59 +0100409 return EFI_SUCCESS;
Alexander Graf80a48002016-08-16 21:08:45 +0200410}
411
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200412/**
413 * efi_get_time() - get current time
414 *
415 * This function implements the GetTime runtime service after
416 * SetVirtualAddressMap() is called. As the U-Boot driver are not available
417 * anymore only an error code is returned.
418 *
419 * See the Unified Extensible Firmware Interface (UEFI) specification
420 * for details.
421 *
422 * @time: pointer to structure to receive current time
423 * @capabilities: pointer to structure to receive RTC properties
424 * Returns: status code
425 */
Alexander Graf3c63db92016-10-14 13:45:30 +0200426efi_status_t __weak __efi_runtime EFIAPI efi_get_time(
Alexander Graf80a48002016-08-16 21:08:45 +0200427 struct efi_time *time,
428 struct efi_time_cap *capabilities)
429{
Heinrich Schuchardtc5b63be2019-06-13 18:42:40 +0200430 return EFI_UNSUPPORTED;
Alexander Graf80a48002016-08-16 21:08:45 +0200431}
432
Heinrich Schuchardt433bfe72019-05-19 20:07:39 +0200433/**
434 * efi_set_time() - set current time
435 *
436 * This function implements the SetTime runtime service after
437 * SetVirtualAddressMap() is called. As the U-Boot driver are not available
438 * anymore only an error code is returned.
439 *
440 * See the Unified Extensible Firmware Interface (UEFI) specification
441 * for details.
442 *
443 * @time: pointer to structure to with current time
444 * Returns: status code
445 */
446efi_status_t __weak __efi_runtime EFIAPI efi_set_time(struct efi_time *time)
447{
448 return EFI_UNSUPPORTED;
449}
450
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000451/**
AKASHI Takahiro2bc27ca2020-11-17 09:27:55 +0900452 * efi_update_capsule_unsupported() - process information from operating system
453 *
454 * This function implements the UpdateCapsule() runtime service.
455 *
456 * See the Unified Extensible Firmware Interface (UEFI) specification for
457 * details.
458 *
459 * @capsule_header_array: pointer to array of virtual pointers
460 * @capsule_count: number of pointers in capsule_header_array
461 * @scatter_gather_list: pointer to array of physical pointers
462 * Returns: status code
463 */
Heinrich Schuchardt6c2377f2023-02-10 08:56:06 +0100464static efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported(
AKASHI Takahiro2bc27ca2020-11-17 09:27:55 +0900465 struct efi_capsule_header **capsule_header_array,
466 efi_uintn_t capsule_count,
467 u64 scatter_gather_list)
468{
469 return EFI_UNSUPPORTED;
470}
471
472/**
473 * efi_query_capsule_caps_unsupported() - check if capsule is supported
474 *
475 * This function implements the QueryCapsuleCapabilities() runtime service.
476 *
477 * See the Unified Extensible Firmware Interface (UEFI) specification for
478 * details.
479 *
480 * @capsule_header_array: pointer to array of virtual pointers
481 * @capsule_count: number of pointers in capsule_header_array
482 * @maximum_capsule_size: maximum capsule size
483 * @reset_type: type of reset needed for capsule update
484 * Returns: status code
485 */
Heinrich Schuchardt6c2377f2023-02-10 08:56:06 +0100486static efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps_unsupported(
AKASHI Takahiro2bc27ca2020-11-17 09:27:55 +0900487 struct efi_capsule_header **capsule_header_array,
488 efi_uintn_t capsule_count,
489 u64 *maximum_capsule_size,
490 u32 *reset_type)
491{
492 return EFI_UNSUPPORTED;
493}
494
495/**
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000496 * efi_is_runtime_service_pointer() - check if pointer points to runtime table
497 *
498 * @p: pointer to check
499 * Return: true if the pointer points to a service function pointer in the
500 * runtime table
501 */
502static bool efi_is_runtime_service_pointer(void *p)
Alexander Graf50149ea2016-03-04 01:10:01 +0100503{
Heinrich Schuchardt14b40482019-07-11 20:15:09 +0200504 return (p >= (void *)&efi_runtime_services.get_time &&
505 p <= (void *)&efi_runtime_services.query_variable_info) ||
506 p == (void *)&efi_events.prev ||
507 p == (void *)&efi_events.next;
Alexander Graf50149ea2016-03-04 01:10:01 +0100508}
509
Heinrich Schuchardtb23ffcb2019-07-05 18:12:21 +0200510/**
511 * efi_runtime_detach() - detach unimplemented runtime functions
512 */
Heinrich Schuchardt7f951042019-07-05 17:42:16 +0200513void efi_runtime_detach(void)
Alexander Graf50149ea2016-03-04 01:10:01 +0100514{
Heinrich Schuchardtb23ffcb2019-07-05 18:12:21 +0200515 efi_runtime_services.reset_system = efi_reset_system;
516 efi_runtime_services.get_time = efi_get_time;
517 efi_runtime_services.set_time = efi_set_time;
AKASHI Takahiro2bc27ca2020-11-17 09:27:55 +0900518 if (IS_ENABLED(CONFIG_EFI_RUNTIME_UPDATE_CAPSULE)) {
519 /* won't support at runtime */
520 efi_runtime_services.update_capsule =
521 efi_update_capsule_unsupported;
522 efi_runtime_services.query_capsule_caps =
523 efi_query_capsule_caps_unsupported;
524 }
Alexander Graf50149ea2016-03-04 01:10:01 +0100525
Heinrich Schuchardtb23ffcb2019-07-05 18:12:21 +0200526 /* Update CRC32 */
527 efi_update_table_header_crc32(&efi_runtime_services.hdr);
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000528}
529
Heinrich Schuchardtee8ebaa2019-06-29 03:32:52 +0200530/**
531 * efi_set_virtual_address_map_runtime() - change from physical to virtual
532 * mapping
533 *
534 * This function implements the SetVirtualAddressMap() runtime service after
535 * it is first called.
536 *
537 * See the Unified Extensible Firmware Interface (UEFI) specification for
538 * details.
539 *
540 * @memory_map_size: size of the virtual map
541 * @descriptor_size: size of an entry in the map
542 * @descriptor_version: version of the map entries
543 * @virtmap: virtual address mapping information
544 * Return: status code EFI_UNSUPPORTED
545 */
Heinrich Schuchardt96185602019-07-12 22:41:43 +0200546static __efi_runtime efi_status_t EFIAPI efi_set_virtual_address_map_runtime(
Heinrich Schuchardt24e67222019-07-27 20:28:47 +0200547 efi_uintn_t memory_map_size,
548 efi_uintn_t descriptor_size,
Heinrich Schuchardtee8ebaa2019-06-29 03:32:52 +0200549 uint32_t descriptor_version,
550 struct efi_mem_desc *virtmap)
551{
552 return EFI_UNSUPPORTED;
553}
554
555/**
556 * efi_convert_pointer_runtime() - convert from physical to virtual pointer
557 *
558 * This function implements the ConvertPointer() runtime service after
559 * the first call to SetVirtualAddressMap().
560 *
561 * See the Unified Extensible Firmware Interface (UEFI) specification for
562 * details.
563 *
564 * @debug_disposition: indicates if pointer may be converted to NULL
565 * @address: pointer to be converted
566 * Return: status code EFI_UNSUPPORTED
567 */
568static __efi_runtime efi_status_t EFIAPI efi_convert_pointer_runtime(
569 efi_uintn_t debug_disposition, void **address)
570{
571 return EFI_UNSUPPORTED;
572}
573
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200574/**
Heinrich Schuchardt7aeceff2020-03-22 08:28:15 +0100575 * efi_convert_pointer() - convert from physical to virtual pointer
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200576 *
577 * This function implements the ConvertPointer() runtime service until
578 * the first call to SetVirtualAddressMap().
579 *
580 * See the Unified Extensible Firmware Interface (UEFI) specification for
581 * details.
582 *
583 * @debug_disposition: indicates if pointer may be converted to NULL
584 * @address: pointer to be converted
Heinrich Schuchardt7aeceff2020-03-22 08:28:15 +0100585 * Return: status code
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200586 */
Heinrich Schuchardta44d2a22020-03-24 18:05:22 +0100587__efi_runtime efi_status_t EFIAPI
588efi_convert_pointer(efi_uintn_t debug_disposition, void **address)
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200589{
Heinrich Schuchardta27c78f2020-07-07 03:10:12 +0200590 efi_physical_addr_t addr;
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200591 efi_uintn_t i;
592 efi_status_t ret = EFI_NOT_FOUND;
593
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200594 if (!efi_virtmap) {
595 ret = EFI_UNSUPPORTED;
596 goto out;
597 }
598
599 if (!address) {
600 ret = EFI_INVALID_PARAMETER;
601 goto out;
602 }
Heinrich Schuchardt724d2812020-03-24 17:52:40 +0100603 if (!*address) {
604 if (debug_disposition & EFI_OPTIONAL_PTR)
605 return EFI_SUCCESS;
606 else
607 return EFI_INVALID_PARAMETER;
608 }
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200609
Heinrich Schuchardta27c78f2020-07-07 03:10:12 +0200610 addr = (uintptr_t)*address;
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200611 for (i = 0; i < efi_descriptor_count; i++) {
612 struct efi_mem_desc *map = (void *)efi_virtmap +
613 (efi_descriptor_size * i);
614
615 if (addr >= map->physical_start &&
616 (addr < map->physical_start
617 + (map->num_pages << EFI_PAGE_SHIFT))) {
618 *address = (void *)(uintptr_t)
619 (addr + map->virtual_start -
620 map->physical_start);
621
622 ret = EFI_SUCCESS;
623 break;
624 }
625 }
626
627out:
Heinrich Schuchardta44d2a22020-03-24 18:05:22 +0100628 return ret;
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200629}
630
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000631static __efi_runtime void efi_relocate_runtime_table(ulong offset)
632{
633 ulong patchoff;
634 void **pos;
635
636 /* Relocate the runtime services pointers */
637 patchoff = offset - gd->relocaddr;
638 for (pos = (void **)&efi_runtime_services.get_time;
639 pos <= (void **)&efi_runtime_services.query_variable_info; ++pos) {
Heinrich Schuchardtee8ebaa2019-06-29 03:32:52 +0200640 if (*pos)
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000641 *pos += patchoff;
Alexander Graf50149ea2016-03-04 01:10:01 +0100642 }
Heinrich Schuchardta39f39c2018-07-29 09:49:04 +0200643
Heinrich Schuchardtee8ebaa2019-06-29 03:32:52 +0200644 /*
645 * The entry for SetVirtualAddress() must point to a physical address.
646 * After the first execution the service must return EFI_UNSUPPORTED.
647 */
648 efi_runtime_services.set_virtual_address_map =
649 &efi_set_virtual_address_map_runtime;
650
651 /*
652 * The entry for ConvertPointer() must point to a physical address.
653 * The service is not usable after SetVirtualAddress().
654 */
655 efi_runtime_services.convert_pointer = &efi_convert_pointer_runtime;
656
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200657 /*
658 * TODO: Update UEFI variable RuntimeServicesSupported removing flags
659 * EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP and
660 * EFI_RT_SUPPORTED_CONVERT_POINTER as required by the UEFI spec 2.8.
661 */
662
Heinrich Schuchardt250b3252018-09-03 19:29:41 +0200663 /* Update CRC32 */
Heinrich Schuchardta39f39c2018-07-29 09:49:04 +0200664 efi_update_table_header_crc32(&efi_runtime_services.hdr);
Alexander Graf50149ea2016-03-04 01:10:01 +0100665}
666
667/* Relocate EFI runtime to uboot_reloc_base = offset */
668void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
669{
670#ifdef IS_RELA
671 struct elf_rela *rel = (void*)&__efi_runtime_rel_start;
672#else
673 struct elf_rel *rel = (void*)&__efi_runtime_rel_start;
Simon Glass98463902022-10-20 18:22:39 -0600674 static ulong lastoff = CONFIG_TEXT_BASE;
Alexander Graf50149ea2016-03-04 01:10:01 +0100675#endif
676
Alexander Grafedcef3b2016-06-02 11:38:27 +0200677 debug("%s: Relocating to offset=%lx\n", __func__, offset);
Alexander Graf50149ea2016-03-04 01:10:01 +0100678 for (; (ulong)rel < (ulong)&__efi_runtime_rel_stop; rel++) {
Simon Glass98463902022-10-20 18:22:39 -0600679 ulong base = CONFIG_TEXT_BASE;
Alexander Graf50149ea2016-03-04 01:10:01 +0100680 ulong *p;
681 ulong newaddr;
682
683 p = (void*)((ulong)rel->offset - base) + gd->relocaddr;
684
Heinrich Schuchardt9f8932d2019-08-14 06:49:09 +0200685 /*
686 * The runtime services table is updated in
687 * efi_relocate_runtime_table()
688 */
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000689 if (map && efi_is_runtime_service_pointer(p))
690 continue;
691
Heinrich Schuchardt3ce78292018-10-13 20:52:08 -0700692 debug("%s: rel->info=%#lx *p=%#lx rel->offset=%p\n", __func__,
693 rel->info, *p, rel->offset);
Alexander Graf50149ea2016-03-04 01:10:01 +0100694
Rick Chen6836adb2018-05-28 19:06:37 +0800695 switch (rel->info & R_MASK) {
696 case R_RELATIVE:
Alexander Graf50149ea2016-03-04 01:10:01 +0100697#ifdef IS_RELA
Simon Glass98463902022-10-20 18:22:39 -0600698 newaddr = rel->addend + offset - CONFIG_TEXT_BASE;
Alexander Graf50149ea2016-03-04 01:10:01 +0100699#else
700 newaddr = *p - lastoff + offset;
701#endif
Rick Chen6836adb2018-05-28 19:06:37 +0800702 break;
703#ifdef R_ABSOLUTE
704 case R_ABSOLUTE: {
705 ulong symidx = rel->info >> SYM_INDEX;
706 extern struct dyn_sym __dyn_sym_start[];
707 newaddr = __dyn_sym_start[symidx].addr + offset;
Alexander Grafafdc4fc2018-11-04 22:25:22 +0100708#ifdef IS_RELA
Simon Glass98463902022-10-20 18:22:39 -0600709 newaddr -= CONFIG_TEXT_BASE;
Alexander Grafafdc4fc2018-11-04 22:25:22 +0100710#endif
Rick Chen6836adb2018-05-28 19:06:37 +0800711 break;
712 }
713#endif
714 default:
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000715 printf("%s: Unknown relocation type %llx\n",
716 __func__, rel->info & R_MASK);
Rick Chen6836adb2018-05-28 19:06:37 +0800717 continue;
718 }
Alexander Graf50149ea2016-03-04 01:10:01 +0100719
720 /* Check if the relocation is inside bounds */
721 if (map && ((newaddr < map->virtual_start) ||
Heinrich Schuchardt591cf2e2017-09-18 22:11:34 +0200722 newaddr > (map->virtual_start +
723 (map->num_pages << EFI_PAGE_SHIFT)))) {
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000724 printf("%s: Relocation at %p is out of range (%lx)\n",
725 __func__, p, newaddr);
Alexander Graf50149ea2016-03-04 01:10:01 +0100726 continue;
727 }
728
Alexander Grafedcef3b2016-06-02 11:38:27 +0200729 debug("%s: Setting %p to %lx\n", __func__, p, newaddr);
Alexander Graf50149ea2016-03-04 01:10:01 +0100730 *p = newaddr;
Alexander Graf36c37a82016-04-11 23:20:39 +0200731 flush_dcache_range((ulong)p & ~(EFI_CACHELINE_SIZE - 1),
732 ALIGN((ulong)&p[1], EFI_CACHELINE_SIZE));
Alexander Graf50149ea2016-03-04 01:10:01 +0100733 }
734
735#ifndef IS_RELA
736 lastoff = offset;
737#endif
738
739 invalidate_icache_all();
740}
741
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200742/**
743 * efi_set_virtual_address_map() - change from physical to virtual mapping
744 *
745 * This function implements the SetVirtualAddressMap() runtime service.
746 *
747 * See the Unified Extensible Firmware Interface (UEFI) specification for
748 * details.
749 *
750 * @memory_map_size: size of the virtual map
751 * @descriptor_size: size of an entry in the map
752 * @descriptor_version: version of the map entries
753 * @virtmap: virtual address mapping information
754 * Return: status code
755 */
Alexander Graf50149ea2016-03-04 01:10:01 +0100756static efi_status_t EFIAPI efi_set_virtual_address_map(
Heinrich Schuchardt24e67222019-07-27 20:28:47 +0200757 efi_uintn_t memory_map_size,
758 efi_uintn_t descriptor_size,
Alexander Graf50149ea2016-03-04 01:10:01 +0100759 uint32_t descriptor_version,
760 struct efi_mem_desc *virtmap)
761{
Heinrich Schuchardt24e67222019-07-27 20:28:47 +0200762 efi_uintn_t n = memory_map_size / descriptor_size;
763 efi_uintn_t i;
Heinrich Schuchardt53e1d8f2019-08-14 05:19:37 +0200764 efi_status_t ret = EFI_INVALID_PARAMETER;
Alexander Graf5c38e052018-12-11 10:00:42 +0100765 int rt_code_sections = 0;
Heinrich Schuchardt14b40482019-07-11 20:15:09 +0200766 struct efi_event *event;
Alexander Graf50149ea2016-03-04 01:10:01 +0100767
Heinrich Schuchardt24e67222019-07-27 20:28:47 +0200768 EFI_ENTRY("%zx %zx %x %p", memory_map_size, descriptor_size,
Alexander Graf50149ea2016-03-04 01:10:01 +0100769 descriptor_version, virtmap);
770
Heinrich Schuchardt53e1d8f2019-08-14 05:19:37 +0200771 if (descriptor_version != EFI_MEMORY_DESCRIPTOR_VERSION ||
772 descriptor_size < sizeof(struct efi_mem_desc))
773 goto out;
774
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200775 efi_virtmap = virtmap;
776 efi_descriptor_size = descriptor_size;
777 efi_descriptor_count = n;
778
Alexander Graf5c38e052018-12-11 10:00:42 +0100779 /*
780 * TODO:
781 * Further down we are cheating. While really we should implement
782 * SetVirtualAddressMap() events and ConvertPointer() to allow
783 * dynamically loaded drivers to expose runtime services, we don't
784 * today.
785 *
786 * So let's ensure we see exactly one single runtime section, as
787 * that is the built-in one. If we see more (or less), someone must
788 * have tried adding or removing to that which we don't support yet.
789 * In that case, let's better fail rather than expose broken runtime
790 * services.
791 */
792 for (i = 0; i < n; i++) {
793 struct efi_mem_desc *map = (void*)virtmap +
794 (descriptor_size * i);
795
796 if (map->type == EFI_RUNTIME_SERVICES_CODE)
797 rt_code_sections++;
798 }
799
800 if (rt_code_sections != 1) {
801 /*
802 * We expose exactly one single runtime code section, so
803 * something is definitely going wrong.
804 */
Heinrich Schuchardt53e1d8f2019-08-14 05:19:37 +0200805 goto out;
Alexander Graf5c38e052018-12-11 10:00:42 +0100806 }
807
Heinrich Schuchardt14b40482019-07-11 20:15:09 +0200808 /* Notify EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE */
809 list_for_each_entry(event, &efi_events, link) {
810 if (event->notify_function)
811 EFI_CALL_VOID(event->notify_function(
812 event, event->notify_context));
813 }
814
Alexander Graf80a48002016-08-16 21:08:45 +0200815 /* Rebind mmio pointers */
816 for (i = 0; i < n; i++) {
817 struct efi_mem_desc *map = (void*)virtmap +
818 (descriptor_size * i);
819 struct list_head *lhandle;
820 efi_physical_addr_t map_start = map->physical_start;
821 efi_physical_addr_t map_len = map->num_pages << EFI_PAGE_SHIFT;
822 efi_physical_addr_t map_end = map_start + map_len;
Heinrich Schuchardt07240da2018-08-04 23:16:06 +0200823 u64 off = map->virtual_start - map_start;
Alexander Graf80a48002016-08-16 21:08:45 +0200824
825 /* Adjust all mmio pointers in this region */
826 list_for_each(lhandle, &efi_runtime_mmio) {
827 struct efi_runtime_mmio_list *lmmio;
828
829 lmmio = list_entry(lhandle,
830 struct efi_runtime_mmio_list,
831 link);
832 if ((map_start <= lmmio->paddr) &&
833 (map_end >= lmmio->paddr)) {
Alexander Graf80a48002016-08-16 21:08:45 +0200834 uintptr_t new_addr = lmmio->paddr + off;
835 *lmmio->ptr = (void *)new_addr;
836 }
837 }
Heinrich Schuchardt07240da2018-08-04 23:16:06 +0200838 if ((map_start <= (uintptr_t)systab.tables) &&
839 (map_end >= (uintptr_t)systab.tables)) {
840 char *ptr = (char *)systab.tables;
841
842 ptr += off;
843 systab.tables = (struct efi_configuration_table *)ptr;
844 }
Alexander Graf80a48002016-08-16 21:08:45 +0200845 }
846
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000847 /* Relocate the runtime. See TODO above */
Alexander Graf50149ea2016-03-04 01:10:01 +0100848 for (i = 0; i < n; i++) {
849 struct efi_mem_desc *map;
850
851 map = (void*)virtmap + (descriptor_size * i);
852 if (map->type == EFI_RUNTIME_SERVICES_CODE) {
Alexander Graf80a48002016-08-16 21:08:45 +0200853 ulong new_offset = map->virtual_start -
Alexander Graf5c38e052018-12-11 10:00:42 +0100854 map->physical_start + gd->relocaddr;
Alexander Graf50149ea2016-03-04 01:10:01 +0100855
Heinrich Schuchardt24a238f2019-06-20 22:00:02 +0000856 efi_relocate_runtime_table(new_offset);
Alexander Graf50149ea2016-03-04 01:10:01 +0100857 efi_runtime_relocate(new_offset, map);
Heinrich Schuchardt53e1d8f2019-08-14 05:19:37 +0200858 ret = EFI_SUCCESS;
859 goto out;
Alexander Graf50149ea2016-03-04 01:10:01 +0100860 }
861 }
862
Heinrich Schuchardt53e1d8f2019-08-14 05:19:37 +0200863out:
864 return EFI_EXIT(ret);
Alexander Graf50149ea2016-03-04 01:10:01 +0100865}
866
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200867/**
868 * efi_add_runtime_mmio() - add memory-mapped IO region
869 *
870 * This function adds a memory-mapped IO region to the memory map to make it
871 * available at runtime.
872 *
Heinrich Schuchardtfb34f292018-12-23 02:35:13 +0100873 * @mmio_ptr: pointer to a pointer to the start of the memory-mapped
874 * IO region
Heinrich Schuchardt250b3252018-09-03 19:29:41 +0200875 * @len: size of the memory-mapped IO region
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200876 * Returns: status code
877 */
Heinrich Schuchardt22c793e2018-03-03 15:28:59 +0100878efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len)
Alexander Graf80a48002016-08-16 21:08:45 +0200879{
880 struct efi_runtime_mmio_list *newmmio;
Alexander Graf813468c2018-03-15 15:08:16 +0100881 uint64_t addr = *(uintptr_t *)mmio_ptr;
Bryan O'Donoghueb225c922019-07-15 12:00:39 +0100882 efi_status_t ret;
Alexander Graf813468c2018-03-15 15:08:16 +0100883
Michael Walle714497e2020-05-17 12:29:19 +0200884 ret = efi_add_memory_map(addr, len, EFI_MMAP_IO);
Bryan O'Donoghueb225c922019-07-15 12:00:39 +0100885 if (ret != EFI_SUCCESS)
Alexander Graf813468c2018-03-15 15:08:16 +0100886 return EFI_OUT_OF_RESOURCES;
Alexander Graf80a48002016-08-16 21:08:45 +0200887
888 newmmio = calloc(1, sizeof(*newmmio));
Heinrich Schuchardt22c793e2018-03-03 15:28:59 +0100889 if (!newmmio)
890 return EFI_OUT_OF_RESOURCES;
Alexander Graf80a48002016-08-16 21:08:45 +0200891 newmmio->ptr = mmio_ptr;
892 newmmio->paddr = *(uintptr_t *)mmio_ptr;
893 newmmio->len = len;
894 list_add_tail(&newmmio->link, &efi_runtime_mmio);
Heinrich Schuchardt22c793e2018-03-03 15:28:59 +0100895
Alexander Graf813468c2018-03-15 15:08:16 +0100896 return EFI_SUCCESS;
Alexander Graf80a48002016-08-16 21:08:45 +0200897}
898
Alexander Graf50149ea2016-03-04 01:10:01 +0100899/*
900 * In the second stage, U-Boot has disappeared. To isolate our runtime code
901 * that at this point still exists from the rest, we put it into a special
902 * section.
903 *
904 * !!WARNING!!
905 *
906 * This means that we can not rely on any code outside of this file in any
907 * function or variable below this line.
908 *
909 * Please keep everything fully self-contained and annotated with
Alexander Graf3c63db92016-10-14 13:45:30 +0200910 * __efi_runtime and __efi_runtime_data markers.
Alexander Graf50149ea2016-03-04 01:10:01 +0100911 */
912
913/*
914 * Relocate the EFI runtime stub to a different place. We need to call this
915 * the first time we expose the runtime interface to a user and on set virtual
916 * address map calls.
917 */
918
Heinrich Schuchardtbcfb0e22018-07-29 15:10:11 +0200919/**
920 * efi_unimplemented() - replacement function, returns EFI_UNSUPPORTED
921 *
922 * This function is used after SetVirtualAddressMap() is called as replacement
923 * for services that are not available anymore due to constraints of the U-Boot
924 * implementation.
925 *
926 * Return: EFI_UNSUPPORTED
927 */
Alexander Graf3c63db92016-10-14 13:45:30 +0200928static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void)
Alexander Graf50149ea2016-03-04 01:10:01 +0100929{
930 return EFI_UNSUPPORTED;
931}
932
Alexander Graf3c63db92016-10-14 13:45:30 +0200933struct efi_runtime_services __efi_runtime_data efi_runtime_services = {
Alexander Graf50149ea2016-03-04 01:10:01 +0100934 .hdr = {
935 .signature = EFI_RUNTIME_SERVICES_SIGNATURE,
Heinrich Schuchardt112f2432018-06-28 12:45:27 +0200936 .revision = EFI_SPECIFICATION_VERSION,
Heinrich Schuchardt71c846a2018-06-28 12:45:29 +0200937 .headersize = sizeof(struct efi_runtime_services),
Alexander Graf50149ea2016-03-04 01:10:01 +0100938 },
Alexander Graf80a48002016-08-16 21:08:45 +0200939 .get_time = &efi_get_time_boottime,
Heinrich Schuchardt433bfe72019-05-19 20:07:39 +0200940 .set_time = &efi_set_time_boottime,
Alexander Graf50149ea2016-03-04 01:10:01 +0100941 .get_wakeup_time = (void *)&efi_unimplemented,
942 .set_wakeup_time = (void *)&efi_unimplemented,
943 .set_virtual_address_map = &efi_set_virtual_address_map,
Heinrich Schuchardt7be56e82019-07-27 20:35:24 +0200944 .convert_pointer = efi_convert_pointer,
Rob Clarkad644e72017-09-13 18:05:37 -0400945 .get_variable = efi_get_variable,
Heinrich Schuchardt45c66f92018-05-17 07:57:05 +0200946 .get_next_variable_name = efi_get_next_variable_name,
Rob Clarkad644e72017-09-13 18:05:37 -0400947 .set_variable = efi_set_variable,
Heinrich Schuchardtb94461c2019-06-20 15:40:49 +0200948 .get_next_high_mono_count = (void *)&efi_unimplemented,
Alexander Graf80a48002016-08-16 21:08:45 +0200949 .reset_system = &efi_reset_system_boottime,
AKASHI Takahiro2bc27ca2020-11-17 09:27:55 +0900950#ifdef CONFIG_EFI_RUNTIME_UPDATE_CAPSULE
Heinrich Schuchardt0c230742018-02-09 20:41:21 +0100951 .update_capsule = efi_update_capsule,
952 .query_capsule_caps = efi_query_capsule_caps,
AKASHI Takahiro2bc27ca2020-11-17 09:27:55 +0900953#else
954 .update_capsule = efi_update_capsule_unsupported,
955 .query_capsule_caps = efi_query_capsule_caps_unsupported,
956#endif
Heinrich Schuchardt0c230742018-02-09 20:41:21 +0100957 .query_variable_info = efi_query_variable_info,
Alexander Graf50149ea2016-03-04 01:10:01 +0100958};