forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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,11 @@
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
+ goto exit; \
66
+ } \
6367 \
6468 init_completion(&efi_rts_work.efi_rts_comp); \
6569 INIT_WORK(&efi_rts_work.work, efi_call_rts); \
....@@ -79,14 +83,29 @@
7983 else \
8084 pr_err("Failed to queue work to efi_rts_wq.\n"); \
8185 \
86
+exit: \
87
+ efi_rts_work.efi_rts_id = EFI_NONE; \
8288 efi_rts_work.status; \
8389 })
90
+
91
+#ifndef arch_efi_save_flags
92
+#define arch_efi_save_flags(state_flags) local_save_flags(state_flags)
93
+#define arch_efi_restore_flags(state_flags) local_irq_restore(state_flags)
94
+#endif
95
+
96
+unsigned long efi_call_virt_save_flags(void)
97
+{
98
+ unsigned long flags;
99
+
100
+ arch_efi_save_flags(flags);
101
+ return flags;
102
+}
84103
85104 void efi_call_virt_check_flags(unsigned long flags, const char *call)
86105 {
87106 unsigned long cur_flags, mismatch;
88107
89
- local_save_flags(cur_flags);
108
+ cur_flags = efi_call_virt_save_flags();
90109
91110 mismatch = flags ^ cur_flags;
92111 if (!WARN_ON_ONCE(mismatch & ARCH_EFI_IRQ_FLAGS_MASK))
....@@ -95,7 +114,7 @@
95114 add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_NOW_UNRELIABLE);
96115 pr_err_ratelimited(FW_BUG "IRQ flags corrupted (0x%08lx=>0x%08lx) by EFI %s\n",
97116 flags, cur_flags, call);
98
- local_irq_restore(flags);
117
+ arch_efi_restore_flags(flags);
99118 }
100119
101120 /*
....@@ -168,50 +187,50 @@
168187 arg5 = efi_rts_work.arg5;
169188
170189 switch (efi_rts_work.efi_rts_id) {
171
- case GET_TIME:
190
+ case EFI_GET_TIME:
172191 status = efi_call_virt(get_time, (efi_time_t *)arg1,
173192 (efi_time_cap_t *)arg2);
174193 break;
175
- case SET_TIME:
194
+ case EFI_SET_TIME:
176195 status = efi_call_virt(set_time, (efi_time_t *)arg1);
177196 break;
178
- case GET_WAKEUP_TIME:
197
+ case EFI_GET_WAKEUP_TIME:
179198 status = efi_call_virt(get_wakeup_time, (efi_bool_t *)arg1,
180199 (efi_bool_t *)arg2, (efi_time_t *)arg3);
181200 break;
182
- case SET_WAKEUP_TIME:
201
+ case EFI_SET_WAKEUP_TIME:
183202 status = efi_call_virt(set_wakeup_time, *(efi_bool_t *)arg1,
184203 (efi_time_t *)arg2);
185204 break;
186
- case GET_VARIABLE:
205
+ case EFI_GET_VARIABLE:
187206 status = efi_call_virt(get_variable, (efi_char16_t *)arg1,
188207 (efi_guid_t *)arg2, (u32 *)arg3,
189208 (unsigned long *)arg4, (void *)arg5);
190209 break;
191
- case GET_NEXT_VARIABLE:
210
+ case EFI_GET_NEXT_VARIABLE:
192211 status = efi_call_virt(get_next_variable, (unsigned long *)arg1,
193212 (efi_char16_t *)arg2,
194213 (efi_guid_t *)arg3);
195214 break;
196
- case SET_VARIABLE:
215
+ case EFI_SET_VARIABLE:
197216 status = efi_call_virt(set_variable, (efi_char16_t *)arg1,
198217 (efi_guid_t *)arg2, *(u32 *)arg3,
199218 *(unsigned long *)arg4, (void *)arg5);
200219 break;
201
- case QUERY_VARIABLE_INFO:
220
+ case EFI_QUERY_VARIABLE_INFO:
202221 status = efi_call_virt(query_variable_info, *(u32 *)arg1,
203222 (u64 *)arg2, (u64 *)arg3, (u64 *)arg4);
204223 break;
205
- case GET_NEXT_HIGH_MONO_COUNT:
224
+ case EFI_GET_NEXT_HIGH_MONO_COUNT:
206225 status = efi_call_virt(get_next_high_mono_count, (u32 *)arg1);
207226 break;
208
- case UPDATE_CAPSULE:
227
+ case EFI_UPDATE_CAPSULE:
209228 status = efi_call_virt(update_capsule,
210229 (efi_capsule_header_t **)arg1,
211230 *(unsigned long *)arg2,
212231 *(unsigned long *)arg3);
213232 break;
214
- case QUERY_CAPSULE_CAPS:
233
+ case EFI_QUERY_CAPSULE_CAPS:
215234 status = efi_call_virt(query_capsule_caps,
216235 (efi_capsule_header_t **)arg1,
217236 *(unsigned long *)arg2, (u64 *)arg3,
....@@ -235,7 +254,7 @@
235254
236255 if (down_interruptible(&efi_runtime_lock))
237256 return EFI_ABORTED;
238
- status = efi_queue_work(GET_TIME, tm, tc, NULL, NULL, NULL);
257
+ status = efi_queue_work(EFI_GET_TIME, tm, tc, NULL, NULL, NULL);
239258 up(&efi_runtime_lock);
240259 return status;
241260 }
....@@ -246,7 +265,7 @@
246265
247266 if (down_interruptible(&efi_runtime_lock))
248267 return EFI_ABORTED;
249
- status = efi_queue_work(SET_TIME, tm, NULL, NULL, NULL, NULL);
268
+ status = efi_queue_work(EFI_SET_TIME, tm, NULL, NULL, NULL, NULL);
250269 up(&efi_runtime_lock);
251270 return status;
252271 }
....@@ -259,7 +278,7 @@
259278
260279 if (down_interruptible(&efi_runtime_lock))
261280 return EFI_ABORTED;
262
- status = efi_queue_work(GET_WAKEUP_TIME, enabled, pending, tm, NULL,
281
+ status = efi_queue_work(EFI_GET_WAKEUP_TIME, enabled, pending, tm, NULL,
263282 NULL);
264283 up(&efi_runtime_lock);
265284 return status;
....@@ -271,7 +290,7 @@
271290
272291 if (down_interruptible(&efi_runtime_lock))
273292 return EFI_ABORTED;
274
- status = efi_queue_work(SET_WAKEUP_TIME, &enabled, tm, NULL, NULL,
293
+ status = efi_queue_work(EFI_SET_WAKEUP_TIME, &enabled, tm, NULL, NULL,
275294 NULL);
276295 up(&efi_runtime_lock);
277296 return status;
....@@ -287,7 +306,7 @@
287306
288307 if (down_interruptible(&efi_runtime_lock))
289308 return EFI_ABORTED;
290
- status = efi_queue_work(GET_VARIABLE, name, vendor, attr, data_size,
309
+ status = efi_queue_work(EFI_GET_VARIABLE, name, vendor, attr, data_size,
291310 data);
292311 up(&efi_runtime_lock);
293312 return status;
....@@ -301,7 +320,7 @@
301320
302321 if (down_interruptible(&efi_runtime_lock))
303322 return EFI_ABORTED;
304
- status = efi_queue_work(GET_NEXT_VARIABLE, name_size, name, vendor,
323
+ status = efi_queue_work(EFI_GET_NEXT_VARIABLE, name_size, name, vendor,
305324 NULL, NULL);
306325 up(&efi_runtime_lock);
307326 return status;
....@@ -317,7 +336,7 @@
317336
318337 if (down_interruptible(&efi_runtime_lock))
319338 return EFI_ABORTED;
320
- status = efi_queue_work(SET_VARIABLE, name, vendor, &attr, &data_size,
339
+ status = efi_queue_work(EFI_SET_VARIABLE, name, vendor, &attr, &data_size,
321340 data);
322341 up(&efi_runtime_lock);
323342 return status;
....@@ -352,7 +371,7 @@
352371
353372 if (down_interruptible(&efi_runtime_lock))
354373 return EFI_ABORTED;
355
- status = efi_queue_work(QUERY_VARIABLE_INFO, &attr, storage_space,
374
+ status = efi_queue_work(EFI_QUERY_VARIABLE_INFO, &attr, storage_space,
356375 remaining_space, max_variable_size, NULL);
357376 up(&efi_runtime_lock);
358377 return status;
....@@ -384,7 +403,7 @@
384403
385404 if (down_interruptible(&efi_runtime_lock))
386405 return EFI_ABORTED;
387
- status = efi_queue_work(GET_NEXT_HIGH_MONO_COUNT, count, NULL, NULL,
406
+ status = efi_queue_work(EFI_GET_NEXT_HIGH_MONO_COUNT, count, NULL, NULL,
388407 NULL, NULL);
389408 up(&efi_runtime_lock);
390409 return status;
....@@ -400,6 +419,7 @@
400419 "could not get exclusive access to the firmware\n");
401420 return;
402421 }
422
+ efi_rts_work.efi_rts_id = EFI_RESET_SYSTEM;
403423 __efi_call_virt(reset_system, reset_type, status, data_size, data);
404424 up(&efi_runtime_lock);
405425 }
....@@ -415,7 +435,7 @@
415435
416436 if (down_interruptible(&efi_runtime_lock))
417437 return EFI_ABORTED;
418
- status = efi_queue_work(UPDATE_CAPSULE, capsules, &count, &sg_list,
438
+ status = efi_queue_work(EFI_UPDATE_CAPSULE, capsules, &count, &sg_list,
419439 NULL, NULL);
420440 up(&efi_runtime_lock);
421441 return status;
....@@ -433,7 +453,7 @@
433453
434454 if (down_interruptible(&efi_runtime_lock))
435455 return EFI_ABORTED;
436
- status = efi_queue_work(QUERY_CAPSULE_CAPS, capsules, &count,
456
+ status = efi_queue_work(EFI_QUERY_CAPSULE_CAPS, capsules, &count,
437457 max_size, reset_type, NULL);
438458 up(&efi_runtime_lock);
439459 return status;