| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * runtime-wrappers.c - Runtime Services function call wrappers |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 19 | 20 | * Copyright (C) 1999-2002 Hewlett-Packard Co. |
|---|
| 20 | 21 | * Copyright (C) 2005-2008 Intel Co. |
|---|
| 21 | 22 | * Copyright (C) 2013 SuSE Labs |
|---|
| 22 | | - * |
|---|
| 23 | | - * This file is released under the GPLv2. |
|---|
| 24 | 23 | */ |
|---|
| 25 | 24 | |
|---|
| 26 | 25 | #define pr_fmt(fmt) "efi: " fmt |
|---|
| .. | .. |
|---|
| 41 | 40 | * code doesn't get too cluttered: |
|---|
| 42 | 41 | */ |
|---|
| 43 | 42 | #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) |
|---|
| 45 | 44 | #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) |
|---|
| 47 | 46 | |
|---|
| 48 | 47 | struct efi_runtime_work efi_rts_work; |
|---|
| 49 | 48 | |
|---|
| .. | .. |
|---|
| 60 | 59 | #define efi_queue_work(_rts, _arg1, _arg2, _arg3, _arg4, _arg5) \ |
|---|
| 61 | 60 | ({ \ |
|---|
| 62 | 61 | 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 | + } \ |
|---|
| 63 | 67 | \ |
|---|
| 64 | 68 | init_completion(&efi_rts_work.efi_rts_comp); \ |
|---|
| 65 | 69 | INIT_WORK(&efi_rts_work.work, efi_call_rts); \ |
|---|
| .. | .. |
|---|
| 79 | 83 | else \ |
|---|
| 80 | 84 | pr_err("Failed to queue work to efi_rts_wq.\n"); \ |
|---|
| 81 | 85 | \ |
|---|
| 86 | +exit: \ |
|---|
| 87 | + efi_rts_work.efi_rts_id = EFI_NONE; \ |
|---|
| 82 | 88 | efi_rts_work.status; \ |
|---|
| 83 | 89 | }) |
|---|
| 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 | +} |
|---|
| 84 | 103 | |
|---|
| 85 | 104 | void efi_call_virt_check_flags(unsigned long flags, const char *call) |
|---|
| 86 | 105 | { |
|---|
| 87 | 106 | unsigned long cur_flags, mismatch; |
|---|
| 88 | 107 | |
|---|
| 89 | | - local_save_flags(cur_flags); |
|---|
| 108 | + cur_flags = efi_call_virt_save_flags(); |
|---|
| 90 | 109 | |
|---|
| 91 | 110 | mismatch = flags ^ cur_flags; |
|---|
| 92 | 111 | if (!WARN_ON_ONCE(mismatch & ARCH_EFI_IRQ_FLAGS_MASK)) |
|---|
| .. | .. |
|---|
| 95 | 114 | add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_NOW_UNRELIABLE); |
|---|
| 96 | 115 | pr_err_ratelimited(FW_BUG "IRQ flags corrupted (0x%08lx=>0x%08lx) by EFI %s\n", |
|---|
| 97 | 116 | flags, cur_flags, call); |
|---|
| 98 | | - local_irq_restore(flags); |
|---|
| 117 | + arch_efi_restore_flags(flags); |
|---|
| 99 | 118 | } |
|---|
| 100 | 119 | |
|---|
| 101 | 120 | /* |
|---|
| .. | .. |
|---|
| 168 | 187 | arg5 = efi_rts_work.arg5; |
|---|
| 169 | 188 | |
|---|
| 170 | 189 | switch (efi_rts_work.efi_rts_id) { |
|---|
| 171 | | - case GET_TIME: |
|---|
| 190 | + case EFI_GET_TIME: |
|---|
| 172 | 191 | status = efi_call_virt(get_time, (efi_time_t *)arg1, |
|---|
| 173 | 192 | (efi_time_cap_t *)arg2); |
|---|
| 174 | 193 | break; |
|---|
| 175 | | - case SET_TIME: |
|---|
| 194 | + case EFI_SET_TIME: |
|---|
| 176 | 195 | status = efi_call_virt(set_time, (efi_time_t *)arg1); |
|---|
| 177 | 196 | break; |
|---|
| 178 | | - case GET_WAKEUP_TIME: |
|---|
| 197 | + case EFI_GET_WAKEUP_TIME: |
|---|
| 179 | 198 | status = efi_call_virt(get_wakeup_time, (efi_bool_t *)arg1, |
|---|
| 180 | 199 | (efi_bool_t *)arg2, (efi_time_t *)arg3); |
|---|
| 181 | 200 | break; |
|---|
| 182 | | - case SET_WAKEUP_TIME: |
|---|
| 201 | + case EFI_SET_WAKEUP_TIME: |
|---|
| 183 | 202 | status = efi_call_virt(set_wakeup_time, *(efi_bool_t *)arg1, |
|---|
| 184 | 203 | (efi_time_t *)arg2); |
|---|
| 185 | 204 | break; |
|---|
| 186 | | - case GET_VARIABLE: |
|---|
| 205 | + case EFI_GET_VARIABLE: |
|---|
| 187 | 206 | status = efi_call_virt(get_variable, (efi_char16_t *)arg1, |
|---|
| 188 | 207 | (efi_guid_t *)arg2, (u32 *)arg3, |
|---|
| 189 | 208 | (unsigned long *)arg4, (void *)arg5); |
|---|
| 190 | 209 | break; |
|---|
| 191 | | - case GET_NEXT_VARIABLE: |
|---|
| 210 | + case EFI_GET_NEXT_VARIABLE: |
|---|
| 192 | 211 | status = efi_call_virt(get_next_variable, (unsigned long *)arg1, |
|---|
| 193 | 212 | (efi_char16_t *)arg2, |
|---|
| 194 | 213 | (efi_guid_t *)arg3); |
|---|
| 195 | 214 | break; |
|---|
| 196 | | - case SET_VARIABLE: |
|---|
| 215 | + case EFI_SET_VARIABLE: |
|---|
| 197 | 216 | status = efi_call_virt(set_variable, (efi_char16_t *)arg1, |
|---|
| 198 | 217 | (efi_guid_t *)arg2, *(u32 *)arg3, |
|---|
| 199 | 218 | *(unsigned long *)arg4, (void *)arg5); |
|---|
| 200 | 219 | break; |
|---|
| 201 | | - case QUERY_VARIABLE_INFO: |
|---|
| 220 | + case EFI_QUERY_VARIABLE_INFO: |
|---|
| 202 | 221 | status = efi_call_virt(query_variable_info, *(u32 *)arg1, |
|---|
| 203 | 222 | (u64 *)arg2, (u64 *)arg3, (u64 *)arg4); |
|---|
| 204 | 223 | break; |
|---|
| 205 | | - case GET_NEXT_HIGH_MONO_COUNT: |
|---|
| 224 | + case EFI_GET_NEXT_HIGH_MONO_COUNT: |
|---|
| 206 | 225 | status = efi_call_virt(get_next_high_mono_count, (u32 *)arg1); |
|---|
| 207 | 226 | break; |
|---|
| 208 | | - case UPDATE_CAPSULE: |
|---|
| 227 | + case EFI_UPDATE_CAPSULE: |
|---|
| 209 | 228 | status = efi_call_virt(update_capsule, |
|---|
| 210 | 229 | (efi_capsule_header_t **)arg1, |
|---|
| 211 | 230 | *(unsigned long *)arg2, |
|---|
| 212 | 231 | *(unsigned long *)arg3); |
|---|
| 213 | 232 | break; |
|---|
| 214 | | - case QUERY_CAPSULE_CAPS: |
|---|
| 233 | + case EFI_QUERY_CAPSULE_CAPS: |
|---|
| 215 | 234 | status = efi_call_virt(query_capsule_caps, |
|---|
| 216 | 235 | (efi_capsule_header_t **)arg1, |
|---|
| 217 | 236 | *(unsigned long *)arg2, (u64 *)arg3, |
|---|
| .. | .. |
|---|
| 235 | 254 | |
|---|
| 236 | 255 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 237 | 256 | 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); |
|---|
| 239 | 258 | up(&efi_runtime_lock); |
|---|
| 240 | 259 | return status; |
|---|
| 241 | 260 | } |
|---|
| .. | .. |
|---|
| 246 | 265 | |
|---|
| 247 | 266 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 248 | 267 | 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); |
|---|
| 250 | 269 | up(&efi_runtime_lock); |
|---|
| 251 | 270 | return status; |
|---|
| 252 | 271 | } |
|---|
| .. | .. |
|---|
| 259 | 278 | |
|---|
| 260 | 279 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 261 | 280 | 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, |
|---|
| 263 | 282 | NULL); |
|---|
| 264 | 283 | up(&efi_runtime_lock); |
|---|
| 265 | 284 | return status; |
|---|
| .. | .. |
|---|
| 271 | 290 | |
|---|
| 272 | 291 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 273 | 292 | 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, |
|---|
| 275 | 294 | NULL); |
|---|
| 276 | 295 | up(&efi_runtime_lock); |
|---|
| 277 | 296 | return status; |
|---|
| .. | .. |
|---|
| 287 | 306 | |
|---|
| 288 | 307 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 289 | 308 | 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, |
|---|
| 291 | 310 | data); |
|---|
| 292 | 311 | up(&efi_runtime_lock); |
|---|
| 293 | 312 | return status; |
|---|
| .. | .. |
|---|
| 301 | 320 | |
|---|
| 302 | 321 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 303 | 322 | 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, |
|---|
| 305 | 324 | NULL, NULL); |
|---|
| 306 | 325 | up(&efi_runtime_lock); |
|---|
| 307 | 326 | return status; |
|---|
| .. | .. |
|---|
| 317 | 336 | |
|---|
| 318 | 337 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 319 | 338 | 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, |
|---|
| 321 | 340 | data); |
|---|
| 322 | 341 | up(&efi_runtime_lock); |
|---|
| 323 | 342 | return status; |
|---|
| .. | .. |
|---|
| 352 | 371 | |
|---|
| 353 | 372 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 354 | 373 | 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, |
|---|
| 356 | 375 | remaining_space, max_variable_size, NULL); |
|---|
| 357 | 376 | up(&efi_runtime_lock); |
|---|
| 358 | 377 | return status; |
|---|
| .. | .. |
|---|
| 384 | 403 | |
|---|
| 385 | 404 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 386 | 405 | 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, |
|---|
| 388 | 407 | NULL, NULL); |
|---|
| 389 | 408 | up(&efi_runtime_lock); |
|---|
| 390 | 409 | return status; |
|---|
| .. | .. |
|---|
| 400 | 419 | "could not get exclusive access to the firmware\n"); |
|---|
| 401 | 420 | return; |
|---|
| 402 | 421 | } |
|---|
| 422 | + efi_rts_work.efi_rts_id = EFI_RESET_SYSTEM; |
|---|
| 403 | 423 | __efi_call_virt(reset_system, reset_type, status, data_size, data); |
|---|
| 404 | 424 | up(&efi_runtime_lock); |
|---|
| 405 | 425 | } |
|---|
| .. | .. |
|---|
| 415 | 435 | |
|---|
| 416 | 436 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 417 | 437 | 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, |
|---|
| 419 | 439 | NULL, NULL); |
|---|
| 420 | 440 | up(&efi_runtime_lock); |
|---|
| 421 | 441 | return status; |
|---|
| .. | .. |
|---|
| 433 | 453 | |
|---|
| 434 | 454 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 435 | 455 | return EFI_ABORTED; |
|---|
| 436 | | - status = efi_queue_work(QUERY_CAPSULE_CAPS, capsules, &count, |
|---|
| 456 | + status = efi_queue_work(EFI_QUERY_CAPSULE_CAPS, capsules, &count, |
|---|
| 437 | 457 | max_size, reset_type, NULL); |
|---|
| 438 | 458 | up(&efi_runtime_lock); |
|---|
| 439 | 459 | return status; |
|---|