forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 10ebd8556b7990499c896a550e3d416b444211e6
kernel/drivers/firmware/efi/runtime-wrappers.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * runtime-wrappers.c - Runtime Services function call wrappers
34 *
....@@ -19,8 +20,6 @@
1920 * Copyright (C) 1999-2002 Hewlett-Packard Co.
2021 * Copyright (C) 2005-2008 Intel Co.
2122 * Copyright (C) 2013 SuSE Labs
22
- *
23
- * This file is released under the GPLv2.
2423 */
2524
2625 #define pr_fmt(fmt) "efi: " fmt
....@@ -41,9 +40,9 @@
4140 * code doesn't get too cluttered:
4241 */
4342 #define efi_call_virt(f, args...) \
44
- efi_call_virt_pointer(efi.systab->runtime, f, args)
43
+ efi_call_virt_pointer(efi.runtime, f, args)
4544 #define __efi_call_virt(f, args...) \
46
- __efi_call_virt_pointer(efi.systab->runtime, f, args)
45
+ __efi_call_virt_pointer(efi.runtime, f, args)
4746
4847 struct efi_runtime_work efi_rts_work;
4948
....@@ -60,6 +59,12 @@
6059 #define efi_queue_work(_rts, _arg1, _arg2, _arg3, _arg4, _arg5) \
6160 ({ \
6261 efi_rts_work.status = EFI_ABORTED; \
62
+ \
63
+ if (!efi_enabled(EFI_RUNTIME_SERVICES)) { \
64
+ pr_warn_once("EFI Runtime Services are disabled!\n"); \
65
+ efi_rts_work.status = EFI_DEVICE_ERROR; \
66
+ goto exit; \
67
+ } \
6368 \
6469 init_completion(&efi_rts_work.efi_rts_comp); \
6570 INIT_WORK(&efi_rts_work.work, efi_call_rts); \
....@@ -79,14 +84,29 @@
7984 else \
8085 pr_err("Failed to queue work to efi_rts_wq.\n"); \
8186 \
87
+exit: \
88
+ efi_rts_work.efi_rts_id = EFI_NONE; \
8289 efi_rts_work.status; \
8390 })
91
+
92
+#ifndef arch_efi_save_flags
93
+#define arch_efi_save_flags(state_flags) local_save_flags(state_flags)
94
+#define arch_efi_restore_flags(state_flags) local_irq_restore(state_flags)
95
+#endif
96
+
97
+unsigned long efi_call_virt_save_flags(void)
98
+{
99
+ unsigned long flags;
100
+
101
+ arch_efi_save_flags(flags);
102
+ return flags;
103
+}
84104
85105 void efi_call_virt_check_flags(unsigned long flags, const char *call)
86106 {
87107 unsigned long cur_flags, mismatch;
88108
89
- local_save_flags(cur_flags);
109
+ cur_flags = efi_call_virt_save_flags();
90110
91111 mismatch = flags ^ cur_flags;
92112 if (!WARN_ON_ONCE(mismatch & ARCH_EFI_IRQ_FLAGS_MASK))
....@@ -95,7 +115,7 @@
95115 add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_NOW_UNRELIABLE);
96116 pr_err_ratelimited(FW_BUG "IRQ flags corrupted (0x%08lx=>0x%08lx) by EFI %s\n",
97117 flags, cur_flags, call);
98
- local_irq_restore(flags);
118
+ arch_efi_restore_flags(flags);
99119 }
100120
101121 /*
....@@ -168,50 +188,50 @@
168188 arg5 = efi_rts_work.arg5;
169189
170190 switch (efi_rts_work.efi_rts_id) {
171
- case GET_TIME:
191
+ case EFI_GET_TIME:
172192 status = efi_call_virt(get_time, (efi_time_t *)arg1,
173193 (efi_time_cap_t *)arg2);
174194 break;
175
- case SET_TIME:
195
+ case EFI_SET_TIME:
176196 status = efi_call_virt(set_time, (efi_time_t *)arg1);
177197 break;
178
- case GET_WAKEUP_TIME:
198
+ case EFI_GET_WAKEUP_TIME:
179199 status = efi_call_virt(get_wakeup_time, (efi_bool_t *)arg1,
180200 (efi_bool_t *)arg2, (efi_time_t *)arg3);
181201 break;
182
- case SET_WAKEUP_TIME:
202
+ case EFI_SET_WAKEUP_TIME:
183203 status = efi_call_virt(set_wakeup_time, *(efi_bool_t *)arg1,
184204 (efi_time_t *)arg2);
185205 break;
186
- case GET_VARIABLE:
206
+ case EFI_GET_VARIABLE:
187207 status = efi_call_virt(get_variable, (efi_char16_t *)arg1,
188208 (efi_guid_t *)arg2, (u32 *)arg3,
189209 (unsigned long *)arg4, (void *)arg5);
190210 break;
191
- case GET_NEXT_VARIABLE:
211
+ case EFI_GET_NEXT_VARIABLE:
192212 status = efi_call_virt(get_next_variable, (unsigned long *)arg1,
193213 (efi_char16_t *)arg2,
194214 (efi_guid_t *)arg3);
195215 break;
196
- case SET_VARIABLE:
216
+ case EFI_SET_VARIABLE:
197217 status = efi_call_virt(set_variable, (efi_char16_t *)arg1,
198218 (efi_guid_t *)arg2, *(u32 *)arg3,
199219 *(unsigned long *)arg4, (void *)arg5);
200220 break;
201
- case QUERY_VARIABLE_INFO:
221
+ case EFI_QUERY_VARIABLE_INFO:
202222 status = efi_call_virt(query_variable_info, *(u32 *)arg1,
203223 (u64 *)arg2, (u64 *)arg3, (u64 *)arg4);
204224 break;
205
- case GET_NEXT_HIGH_MONO_COUNT:
225
+ case EFI_GET_NEXT_HIGH_MONO_COUNT:
206226 status = efi_call_virt(get_next_high_mono_count, (u32 *)arg1);
207227 break;
208
- case UPDATE_CAPSULE:
228
+ case EFI_UPDATE_CAPSULE:
209229 status = efi_call_virt(update_capsule,
210230 (efi_capsule_header_t **)arg1,
211231 *(unsigned long *)arg2,
212232 *(unsigned long *)arg3);
213233 break;
214
- case QUERY_CAPSULE_CAPS:
234
+ case EFI_QUERY_CAPSULE_CAPS:
215235 status = efi_call_virt(query_capsule_caps,
216236 (efi_capsule_header_t **)arg1,
217237 *(unsigned long *)arg2, (u64 *)arg3,
....@@ -235,7 +255,7 @@
235255
236256 if (down_interruptible(&efi_runtime_lock))
237257 return EFI_ABORTED;
238
- status = efi_queue_work(GET_TIME, tm, tc, NULL, NULL, NULL);
258
+ status = efi_queue_work(EFI_GET_TIME, tm, tc, NULL, NULL, NULL);
239259 up(&efi_runtime_lock);
240260 return status;
241261 }
....@@ -246,7 +266,7 @@
246266
247267 if (down_interruptible(&efi_runtime_lock))
248268 return EFI_ABORTED;
249
- status = efi_queue_work(SET_TIME, tm, NULL, NULL, NULL, NULL);
269
+ status = efi_queue_work(EFI_SET_TIME, tm, NULL, NULL, NULL, NULL);
250270 up(&efi_runtime_lock);
251271 return status;
252272 }
....@@ -259,7 +279,7 @@
259279
260280 if (down_interruptible(&efi_runtime_lock))
261281 return EFI_ABORTED;
262
- status = efi_queue_work(GET_WAKEUP_TIME, enabled, pending, tm, NULL,
282
+ status = efi_queue_work(EFI_GET_WAKEUP_TIME, enabled, pending, tm, NULL,
263283 NULL);
264284 up(&efi_runtime_lock);
265285 return status;
....@@ -271,7 +291,7 @@
271291
272292 if (down_interruptible(&efi_runtime_lock))
273293 return EFI_ABORTED;
274
- status = efi_queue_work(SET_WAKEUP_TIME, &enabled, tm, NULL, NULL,
294
+ status = efi_queue_work(EFI_SET_WAKEUP_TIME, &enabled, tm, NULL, NULL,
275295 NULL);
276296 up(&efi_runtime_lock);
277297 return status;
....@@ -287,7 +307,7 @@
287307
288308 if (down_interruptible(&efi_runtime_lock))
289309 return EFI_ABORTED;
290
- status = efi_queue_work(GET_VARIABLE, name, vendor, attr, data_size,
310
+ status = efi_queue_work(EFI_GET_VARIABLE, name, vendor, attr, data_size,
291311 data);
292312 up(&efi_runtime_lock);
293313 return status;
....@@ -301,7 +321,7 @@
301321
302322 if (down_interruptible(&efi_runtime_lock))
303323 return EFI_ABORTED;
304
- status = efi_queue_work(GET_NEXT_VARIABLE, name_size, name, vendor,
324
+ status = efi_queue_work(EFI_GET_NEXT_VARIABLE, name_size, name, vendor,
305325 NULL, NULL);
306326 up(&efi_runtime_lock);
307327 return status;
....@@ -317,7 +337,7 @@
317337
318338 if (down_interruptible(&efi_runtime_lock))
319339 return EFI_ABORTED;
320
- status = efi_queue_work(SET_VARIABLE, name, vendor, &attr, &data_size,
340
+ status = efi_queue_work(EFI_SET_VARIABLE, name, vendor, &attr, &data_size,
321341 data);
322342 up(&efi_runtime_lock);
323343 return status;
....@@ -352,7 +372,7 @@
352372
353373 if (down_interruptible(&efi_runtime_lock))
354374 return EFI_ABORTED;
355
- status = efi_queue_work(QUERY_VARIABLE_INFO, &attr, storage_space,
375
+ status = efi_queue_work(EFI_QUERY_VARIABLE_INFO, &attr, storage_space,
356376 remaining_space, max_variable_size, NULL);
357377 up(&efi_runtime_lock);
358378 return status;
....@@ -384,7 +404,7 @@
384404
385405 if (down_interruptible(&efi_runtime_lock))
386406 return EFI_ABORTED;
387
- status = efi_queue_work(GET_NEXT_HIGH_MONO_COUNT, count, NULL, NULL,
407
+ status = efi_queue_work(EFI_GET_NEXT_HIGH_MONO_COUNT, count, NULL, NULL,
388408 NULL, NULL);
389409 up(&efi_runtime_lock);
390410 return status;
....@@ -400,6 +420,7 @@
400420 "could not get exclusive access to the firmware\n");
401421 return;
402422 }
423
+ efi_rts_work.efi_rts_id = EFI_RESET_SYSTEM;
403424 __efi_call_virt(reset_system, reset_type, status, data_size, data);
404425 up(&efi_runtime_lock);
405426 }
....@@ -415,7 +436,7 @@
415436
416437 if (down_interruptible(&efi_runtime_lock))
417438 return EFI_ABORTED;
418
- status = efi_queue_work(UPDATE_CAPSULE, capsules, &count, &sg_list,
439
+ status = efi_queue_work(EFI_UPDATE_CAPSULE, capsules, &count, &sg_list,
419440 NULL, NULL);
420441 up(&efi_runtime_lock);
421442 return status;
....@@ -433,7 +454,7 @@
433454
434455 if (down_interruptible(&efi_runtime_lock))
435456 return EFI_ABORTED;
436
- status = efi_queue_work(QUERY_CAPSULE_CAPS, capsules, &count,
457
+ status = efi_queue_work(EFI_QUERY_CAPSULE_CAPS, capsules, &count,
437458 max_size, reset_type, NULL);
438459 up(&efi_runtime_lock);
439460 return status;