| .. | .. |
|---|
| 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 | + efi_rts_work.status = EFI_DEVICE_ERROR; \ |
|---|
| 66 | + goto exit; \ |
|---|
| 67 | + } \ |
|---|
| 63 | 68 | \ |
|---|
| 64 | 69 | init_completion(&efi_rts_work.efi_rts_comp); \ |
|---|
| 65 | 70 | INIT_WORK(&efi_rts_work.work, efi_call_rts); \ |
|---|
| .. | .. |
|---|
| 79 | 84 | else \ |
|---|
| 80 | 85 | pr_err("Failed to queue work to efi_rts_wq.\n"); \ |
|---|
| 81 | 86 | \ |
|---|
| 87 | +exit: \ |
|---|
| 88 | + efi_rts_work.efi_rts_id = EFI_NONE; \ |
|---|
| 82 | 89 | efi_rts_work.status; \ |
|---|
| 83 | 90 | }) |
|---|
| 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 | +} |
|---|
| 84 | 104 | |
|---|
| 85 | 105 | void efi_call_virt_check_flags(unsigned long flags, const char *call) |
|---|
| 86 | 106 | { |
|---|
| 87 | 107 | unsigned long cur_flags, mismatch; |
|---|
| 88 | 108 | |
|---|
| 89 | | - local_save_flags(cur_flags); |
|---|
| 109 | + cur_flags = efi_call_virt_save_flags(); |
|---|
| 90 | 110 | |
|---|
| 91 | 111 | mismatch = flags ^ cur_flags; |
|---|
| 92 | 112 | if (!WARN_ON_ONCE(mismatch & ARCH_EFI_IRQ_FLAGS_MASK)) |
|---|
| .. | .. |
|---|
| 95 | 115 | add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_NOW_UNRELIABLE); |
|---|
| 96 | 116 | pr_err_ratelimited(FW_BUG "IRQ flags corrupted (0x%08lx=>0x%08lx) by EFI %s\n", |
|---|
| 97 | 117 | flags, cur_flags, call); |
|---|
| 98 | | - local_irq_restore(flags); |
|---|
| 118 | + arch_efi_restore_flags(flags); |
|---|
| 99 | 119 | } |
|---|
| 100 | 120 | |
|---|
| 101 | 121 | /* |
|---|
| .. | .. |
|---|
| 168 | 188 | arg5 = efi_rts_work.arg5; |
|---|
| 169 | 189 | |
|---|
| 170 | 190 | switch (efi_rts_work.efi_rts_id) { |
|---|
| 171 | | - case GET_TIME: |
|---|
| 191 | + case EFI_GET_TIME: |
|---|
| 172 | 192 | status = efi_call_virt(get_time, (efi_time_t *)arg1, |
|---|
| 173 | 193 | (efi_time_cap_t *)arg2); |
|---|
| 174 | 194 | break; |
|---|
| 175 | | - case SET_TIME: |
|---|
| 195 | + case EFI_SET_TIME: |
|---|
| 176 | 196 | status = efi_call_virt(set_time, (efi_time_t *)arg1); |
|---|
| 177 | 197 | break; |
|---|
| 178 | | - case GET_WAKEUP_TIME: |
|---|
| 198 | + case EFI_GET_WAKEUP_TIME: |
|---|
| 179 | 199 | status = efi_call_virt(get_wakeup_time, (efi_bool_t *)arg1, |
|---|
| 180 | 200 | (efi_bool_t *)arg2, (efi_time_t *)arg3); |
|---|
| 181 | 201 | break; |
|---|
| 182 | | - case SET_WAKEUP_TIME: |
|---|
| 202 | + case EFI_SET_WAKEUP_TIME: |
|---|
| 183 | 203 | status = efi_call_virt(set_wakeup_time, *(efi_bool_t *)arg1, |
|---|
| 184 | 204 | (efi_time_t *)arg2); |
|---|
| 185 | 205 | break; |
|---|
| 186 | | - case GET_VARIABLE: |
|---|
| 206 | + case EFI_GET_VARIABLE: |
|---|
| 187 | 207 | status = efi_call_virt(get_variable, (efi_char16_t *)arg1, |
|---|
| 188 | 208 | (efi_guid_t *)arg2, (u32 *)arg3, |
|---|
| 189 | 209 | (unsigned long *)arg4, (void *)arg5); |
|---|
| 190 | 210 | break; |
|---|
| 191 | | - case GET_NEXT_VARIABLE: |
|---|
| 211 | + case EFI_GET_NEXT_VARIABLE: |
|---|
| 192 | 212 | status = efi_call_virt(get_next_variable, (unsigned long *)arg1, |
|---|
| 193 | 213 | (efi_char16_t *)arg2, |
|---|
| 194 | 214 | (efi_guid_t *)arg3); |
|---|
| 195 | 215 | break; |
|---|
| 196 | | - case SET_VARIABLE: |
|---|
| 216 | + case EFI_SET_VARIABLE: |
|---|
| 197 | 217 | status = efi_call_virt(set_variable, (efi_char16_t *)arg1, |
|---|
| 198 | 218 | (efi_guid_t *)arg2, *(u32 *)arg3, |
|---|
| 199 | 219 | *(unsigned long *)arg4, (void *)arg5); |
|---|
| 200 | 220 | break; |
|---|
| 201 | | - case QUERY_VARIABLE_INFO: |
|---|
| 221 | + case EFI_QUERY_VARIABLE_INFO: |
|---|
| 202 | 222 | status = efi_call_virt(query_variable_info, *(u32 *)arg1, |
|---|
| 203 | 223 | (u64 *)arg2, (u64 *)arg3, (u64 *)arg4); |
|---|
| 204 | 224 | break; |
|---|
| 205 | | - case GET_NEXT_HIGH_MONO_COUNT: |
|---|
| 225 | + case EFI_GET_NEXT_HIGH_MONO_COUNT: |
|---|
| 206 | 226 | status = efi_call_virt(get_next_high_mono_count, (u32 *)arg1); |
|---|
| 207 | 227 | break; |
|---|
| 208 | | - case UPDATE_CAPSULE: |
|---|
| 228 | + case EFI_UPDATE_CAPSULE: |
|---|
| 209 | 229 | status = efi_call_virt(update_capsule, |
|---|
| 210 | 230 | (efi_capsule_header_t **)arg1, |
|---|
| 211 | 231 | *(unsigned long *)arg2, |
|---|
| 212 | 232 | *(unsigned long *)arg3); |
|---|
| 213 | 233 | break; |
|---|
| 214 | | - case QUERY_CAPSULE_CAPS: |
|---|
| 234 | + case EFI_QUERY_CAPSULE_CAPS: |
|---|
| 215 | 235 | status = efi_call_virt(query_capsule_caps, |
|---|
| 216 | 236 | (efi_capsule_header_t **)arg1, |
|---|
| 217 | 237 | *(unsigned long *)arg2, (u64 *)arg3, |
|---|
| .. | .. |
|---|
| 235 | 255 | |
|---|
| 236 | 256 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 237 | 257 | 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); |
|---|
| 239 | 259 | up(&efi_runtime_lock); |
|---|
| 240 | 260 | return status; |
|---|
| 241 | 261 | } |
|---|
| .. | .. |
|---|
| 246 | 266 | |
|---|
| 247 | 267 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 248 | 268 | 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); |
|---|
| 250 | 270 | up(&efi_runtime_lock); |
|---|
| 251 | 271 | return status; |
|---|
| 252 | 272 | } |
|---|
| .. | .. |
|---|
| 259 | 279 | |
|---|
| 260 | 280 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 261 | 281 | 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, |
|---|
| 263 | 283 | NULL); |
|---|
| 264 | 284 | up(&efi_runtime_lock); |
|---|
| 265 | 285 | return status; |
|---|
| .. | .. |
|---|
| 271 | 291 | |
|---|
| 272 | 292 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 273 | 293 | 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, |
|---|
| 275 | 295 | NULL); |
|---|
| 276 | 296 | up(&efi_runtime_lock); |
|---|
| 277 | 297 | return status; |
|---|
| .. | .. |
|---|
| 287 | 307 | |
|---|
| 288 | 308 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 289 | 309 | 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, |
|---|
| 291 | 311 | data); |
|---|
| 292 | 312 | up(&efi_runtime_lock); |
|---|
| 293 | 313 | return status; |
|---|
| .. | .. |
|---|
| 301 | 321 | |
|---|
| 302 | 322 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 303 | 323 | 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, |
|---|
| 305 | 325 | NULL, NULL); |
|---|
| 306 | 326 | up(&efi_runtime_lock); |
|---|
| 307 | 327 | return status; |
|---|
| .. | .. |
|---|
| 317 | 337 | |
|---|
| 318 | 338 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 319 | 339 | 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, |
|---|
| 321 | 341 | data); |
|---|
| 322 | 342 | up(&efi_runtime_lock); |
|---|
| 323 | 343 | return status; |
|---|
| .. | .. |
|---|
| 352 | 372 | |
|---|
| 353 | 373 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 354 | 374 | 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, |
|---|
| 356 | 376 | remaining_space, max_variable_size, NULL); |
|---|
| 357 | 377 | up(&efi_runtime_lock); |
|---|
| 358 | 378 | return status; |
|---|
| .. | .. |
|---|
| 384 | 404 | |
|---|
| 385 | 405 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 386 | 406 | 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, |
|---|
| 388 | 408 | NULL, NULL); |
|---|
| 389 | 409 | up(&efi_runtime_lock); |
|---|
| 390 | 410 | return status; |
|---|
| .. | .. |
|---|
| 400 | 420 | "could not get exclusive access to the firmware\n"); |
|---|
| 401 | 421 | return; |
|---|
| 402 | 422 | } |
|---|
| 423 | + efi_rts_work.efi_rts_id = EFI_RESET_SYSTEM; |
|---|
| 403 | 424 | __efi_call_virt(reset_system, reset_type, status, data_size, data); |
|---|
| 404 | 425 | up(&efi_runtime_lock); |
|---|
| 405 | 426 | } |
|---|
| .. | .. |
|---|
| 415 | 436 | |
|---|
| 416 | 437 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 417 | 438 | 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, |
|---|
| 419 | 440 | NULL, NULL); |
|---|
| 420 | 441 | up(&efi_runtime_lock); |
|---|
| 421 | 442 | return status; |
|---|
| .. | .. |
|---|
| 433 | 454 | |
|---|
| 434 | 455 | if (down_interruptible(&efi_runtime_lock)) |
|---|
| 435 | 456 | return EFI_ABORTED; |
|---|
| 436 | | - status = efi_queue_work(QUERY_CAPSULE_CAPS, capsules, &count, |
|---|
| 457 | + status = efi_queue_work(EFI_QUERY_CAPSULE_CAPS, capsules, &count, |
|---|
| 437 | 458 | max_size, reset_type, NULL); |
|---|
| 438 | 459 | up(&efi_runtime_lock); |
|---|
| 439 | 460 | return status; |
|---|