Lines Matching +full:used +full:- +full:by +full:- +full:rtas

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Procedures for interfacing to the RTAS on CHRP machines.
30 #include <asm/rtas.h>
47 /* This is here deliberately so it's only used in this file */
54 srr_regs_clobbered(); /* rtas uses SRRs, invalidate */ in do_enter_rtas()
57 struct rtas_t rtas = { variable
60 EXPORT_SYMBOL(rtas);
71 * If non-NULL, this gets called when the kernel terminates.
77 /* RTAS use home made raw locking instead of spin_lock_irqsave
88 arch_spin_lock(&rtas.lock); in lock_rtas()
94 arch_spin_unlock(&rtas.lock); in unlock_rtas()
101 * are designed only for very early low-level debugging, which
102 * is why the token is hard-coded to 10.
108 if (!rtas.base) in call_rtas_display_status()
112 rtas_call_unlocked(&rtas.args, 10, 1, 1, NULL, c); in call_rtas_display_status()
122 while (width-- > 0) in call_rtas_display_status_delay()
133 if (width--) { in call_rtas_display_status_delay()
149 * hardcode rtas.base/entry etc.
158 if (!rtas.base) in udbg_rtascon_putc()
177 if (!rtas.base) in udbg_rtascon_getc_poll()
178 return -1; in udbg_rtascon_getc_poll()
181 return -1; in udbg_rtascon_getc_poll()
190 while ((c = udbg_rtascon_getc_poll()) == -1) in udbg_rtascon_getc()
218 if (!rtas.base) in rtas_progress()
223 if ((root = of_find_node_by_path("/rtas"))) { in rtas_progress()
225 "ibm,display-line-length", NULL))) in rtas_progress()
228 "ibm,form-feed", NULL))) in rtas_progress()
231 "ibm,display-number-of-lines", NULL))) in rtas_progress()
234 "ibm,display-truncation-length", NULL); in rtas_progress()
237 display_character = rtas_token("display-character"); in rtas_progress()
238 set_indicator = rtas_token("set-indicator"); in rtas_progress()
286 if (current_line > display_lines-1) in rtas_progress()
287 current_line = display_lines-1; in rtas_progress()
292 /* RTAS wants CR-LF, not just LF */ in rtas_progress()
298 /* CR might be used to re-draw a line, so we'll in rtas_progress()
309 width--; in rtas_progress()
323 EXPORT_SYMBOL(rtas_progress); /* needed by rtas_flash module */
328 if (rtas.dev == NULL) in rtas_token()
330 tokp = of_get_property(rtas.dev, service, NULL); in rtas_token()
343 * Return the firmware-specified size of the error log buffer
344 * for all rtas calls that require an error buffer argument.
345 * This includes 'check-exception' and 'rtas-last-error'.
353 rtas_error_log_max = rtas_token ("rtas-error-log-max"); in rtas_get_error_log_max()
356 printk (KERN_WARNING "RTAS: bad log buffer size %d\n", in rtas_get_error_log_max()
369 * most recent failed call to rtas. Because the error text
370 * might go stale if there are any other intervening rtas calls,
372 * the error (i.e. with rtas.lock still held from the previous call).
380 if (rtas_last_error_token == -1) in __fetch_rtas_last_error()
392 save_args = rtas.args; in __fetch_rtas_last_error()
393 rtas.args = err_args; in __fetch_rtas_last_error()
395 do_enter_rtas(__pa(&rtas.args)); in __fetch_rtas_last_error()
397 err_args = rtas.args; in __fetch_rtas_last_error()
398 rtas.args = save_args; in __fetch_rtas_last_error()
430 args->token = cpu_to_be32(token); in va_rtas_call_unlocked()
431 args->nargs = cpu_to_be32(nargs); in va_rtas_call_unlocked()
432 args->nret = cpu_to_be32(nret); in va_rtas_call_unlocked()
433 args->rets = &(args->args[nargs]); in va_rtas_call_unlocked()
436 args->args[i] = cpu_to_be32(va_arg(list, __u32)); in va_rtas_call_unlocked()
439 args->rets[i] = 0; in va_rtas_call_unlocked()
462 if (!rtas.entry || token == RTAS_UNKNOWN_SERVICE) in rtas_call()
463 return -1; in rtas_call()
467 /* We use the global rtas args buffer */ in rtas_call()
468 rtas_args = &rtas.args; in rtas_call()
474 /* A -1 return code indicates that the last command couldn't in rtas_call()
476 if (be32_to_cpu(rtas_args->rets[0]) == -1) in rtas_call()
480 for (i = 0; i < nret-1; ++i) in rtas_call()
481 outputs[i] = be32_to_cpu(rtas_args->rets[i+1]); in rtas_call()
482 ret = (nret > 0)? be32_to_cpu(rtas_args->rets[0]): 0; in rtas_call()
495 /* For RTAS_BUSY (-2), delay for 1 millisecond. For an extended busy status
507 order = status - RTAS_EXTENDED_DELAY_MIN; in rtas_busy_delay_time()
508 for (ms = 1; order > 0; order--) in rtas_busy_delay_time()
516 /* For an RTAS busy status code, perform the hinted delay. */
535 case -1: /* Hardware Error */ in rtas_error_rc()
536 rc = -EIO; in rtas_error_rc()
538 case -3: /* Bad indicator/domain/etc */ in rtas_error_rc()
539 rc = -EINVAL; in rtas_error_rc()
541 case -9000: /* Isolation error */ in rtas_error_rc()
542 rc = -EFAULT; in rtas_error_rc()
544 case -9001: /* Outstanding TCE/PTE */ in rtas_error_rc()
545 rc = -EEXIST; in rtas_error_rc()
547 case -9002: /* No usable slot */ in rtas_error_rc()
548 rc = -ENODEV; in rtas_error_rc()
551 printk(KERN_ERR "%s: unexpected RTAS error %d\n", in rtas_error_rc()
553 rc = -ERANGE; in rtas_error_rc()
561 int token = rtas_token("get-power-level"); in rtas_get_power_level()
565 return -ENOENT; in rtas_get_power_level()
578 int token = rtas_token("set-power-level"); in rtas_set_power_level()
582 return -ENOENT; in rtas_set_power_level()
596 int token = rtas_token("get-sensor-state"); in rtas_get_sensor()
600 return -ENOENT; in rtas_get_sensor()
614 int token = rtas_token("get-sensor-state"); in rtas_get_sensor_fast()
618 return -ENOENT; in rtas_get_sensor_fast()
637 indicators = of_get_property(rtas.dev, "rtas-indicators", &proplen); in rtas_indicator_present()
657 int token = rtas_token("set-indicator"); in rtas_set_indicator()
661 return -ENOENT; in rtas_set_indicator()
674 * Ignoring RTAS extended delay
679 int token = rtas_token("set-indicator"); in rtas_set_indicator_fast()
682 return -ENOENT; in rtas_set_indicator_fast()
696 * rtas_ibm_suspend_me() - Call ibm,suspend-me to suspend the LPAR.
698 * @fw_status: RTAS call status will be placed here if not NULL.
712 * 0 - The partition has resumed from suspend, possibly after
714 * -ECANCELED - The operation was aborted.
715 * -EAGAIN - There were other CPUs not in H_JOIN at the time of the call.
716 * -EBUSY - Some other condition prevented the suspend from succeeding.
717 * -EIO - Hardware/platform error.
724 fwrc = rtas_call(rtas_token("ibm,suspend-me"), 0, 1, NULL); in rtas_ibm_suspend_me()
731 ret = -ECANCELED; in rtas_ibm_suspend_me()
734 ret = -EAGAIN; in rtas_ibm_suspend_me()
738 ret = -EBUSY; in rtas_ibm_suspend_me()
740 case -1: in rtas_ibm_suspend_me()
742 ret = -EIO; in rtas_ibm_suspend_me()
756 printk("RTAS system-reboot returned %d\n", in rtas_restart()
757 rtas_call(rtas_token("system-reboot"), 0, 1, NULL)); in rtas_restart()
766 printk("RTAS power-off returned %d\n", in rtas_power_off()
767 rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1)); in rtas_power_off()
776 printk("RTAS power-off returned %d\n", in rtas_halt()
777 rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1)); in rtas_halt()
789 * Firmware with the ibm,extended-os-term property is guaranteed in rtas_os_term()
790 * to always return from an ibm,os-term call. Earlier versions without in rtas_os_term()
794 if (RTAS_UNKNOWN_SERVICE == rtas_token("ibm,os-term") || in rtas_os_term()
795 RTAS_UNKNOWN_SERVICE == rtas_token("ibm,extended-os-term")) in rtas_os_term()
801 status = rtas_call(rtas_token("ibm,os-term"), 1, 1, NULL, in rtas_os_term()
806 printk(KERN_EMERG "ibm,os-term call failed %d\n", status); in rtas_os_term()
810 * rtas_activate_firmware() - Activate a new version of firmware.
825 token = rtas_token("ibm,activate-firmware"); in rtas_activate_firmware()
827 pr_notice("ibm,activate-firmware method unavailable\n"); in rtas_activate_firmware()
836 pr_err("ibm,activate-firmware failed (%i)\n", fwrc); in rtas_activate_firmware()
841 * rtas_call_reentrant() - Used for reentrant rtas calls
842 * @token: Token for desired reentrant RTAS call
846 * @...: Inputs for desired RTAS call
848 * According to LoPAR documentation, only "ibm,int-on", "ibm,int-off",
849 * "ibm,get-xive" and "ibm,set-xive" are currently reentrant.
850 * Reentrant calls need their own rtas_args buffer, so not using rtas.args, but
853 * Return: -1 on error,
854 * First output value of RTAS call if (nret > 0),
864 if (!rtas.entry || token == RTAS_UNKNOWN_SERVICE) in rtas_call_reentrant()
865 return -1; in rtas_call_reentrant()
870 /* We use the per-cpu (PACA) rtas args buffer */ in rtas_call_reentrant()
871 args = local_paca->rtas_args_reentrant; in rtas_call_reentrant()
878 for (i = 0; i < nret - 1; ++i) in rtas_call_reentrant()
879 outputs[i] = be32_to_cpu(args->rets[i + 1]); in rtas_call_reentrant()
882 ret = be32_to_cpu(args->rets[0]); in rtas_call_reentrant()
893 * Find a specific pseries error log in an RTAS extended event log.
894 * @log: RTAS error/event log
903 (struct rtas_ext_event_log_v6 *)log->buffer; in get_pseries_errorlog()
916 log_end = log->buffer + ext_log_length; in get_pseries_errorlog()
917 p = ext_log->vendor_log; in get_pseries_errorlog()
933 * arbitrary physical addresses to RTAS calls. A number of RTAS calls
936 * be used inside the kernel and not exposed to userspace.
940 * subset of RTAS calls.
942 * Accordingly, we filter RTAS requests to check that the call is
951 /* Indexes into the args buffer, -1 if not used */
961 { "ibm,activate-firmware", -1, -1, -1, -1, -1 },
962 { "ibm,configure-connector", -1, 0, -1, 1, -1, 4096 }, /* Special cased */
963 { "display-character", -1, -1, -1, -1, -1 },
964 { "ibm,display-message", -1, 0, -1, -1, -1 },
965 { "ibm,errinjct", -1, 2, -1, -1, -1, 1024 },
966 { "ibm,close-errinjct", -1, -1, -1, -1, -1 },
967 { "ibm,open-errinjct", -1, -1, -1, -1, -1 },
968 { "ibm,get-config-addr-info2", -1, -1, -1, -1, -1 },
969 { "ibm,get-dynamic-sensor-state", -1, 1, -1, -1, -1 },
970 { "ibm,get-indices", -1, 2, 3, -1, -1 },
971 { "get-power-level", -1, -1, -1, -1, -1 },
972 { "get-sensor-state", -1, -1, -1, -1, -1 },
973 { "ibm,get-system-parameter", -1, 1, 2, -1, -1 },
974 { "get-time-of-day", -1, -1, -1, -1, -1 },
975 { "ibm,get-vpd", -1, 0, -1, 1, 2 },
976 { "ibm,lpar-perftools", -1, 2, 3, -1, -1 },
977 { "ibm,platform-dump", -1, 4, 5, -1, -1 },
978 { "ibm,read-slot-reset-state", -1, -1, -1, -1, -1 },
979 { "ibm,scan-log-dump", -1, 0, 1, -1, -1 },
980 { "ibm,set-dynamic-indicator", -1, 2, -1, -1, -1 },
981 { "ibm,set-eeh-option", -1, -1, -1, -1, -1 },
982 { "set-indicator", -1, -1, -1, -1, -1 },
983 { "set-power-level", -1, -1, -1, -1, -1 },
984 { "set-time-for-power-on", -1, -1, -1, -1, -1 },
985 { "ibm,set-system-parameter", -1, 1, -1, -1, -1 },
986 { "set-time-of-day", -1, -1, -1, -1, -1 },
988 { "ibm,suspend-me", -1, -1, -1, -1, -1 },
989 { "ibm,update-nodes", -1, 0, -1, -1, -1, 4096 },
990 { "ibm,update-properties", -1, 0, -1, -1, -1, 4096 },
992 { "ibm,physical-attestation", -1, 0, 1, -1, -1 },
1013 if (token != f->token) in block_rtas_call()
1016 if (f->buf_idx1 != -1) { in block_rtas_call()
1017 base = be32_to_cpu(args->args[f->buf_idx1]); in block_rtas_call()
1018 if (f->size_idx1 != -1) in block_rtas_call()
1019 size = be32_to_cpu(args->args[f->size_idx1]); in block_rtas_call()
1020 else if (f->fixed_size) in block_rtas_call()
1021 size = f->fixed_size; in block_rtas_call()
1025 end = base + size - 1; in block_rtas_call()
1030 if (f->buf_idx2 != -1) { in block_rtas_call()
1031 base = be32_to_cpu(args->args[f->buf_idx2]); in block_rtas_call()
1032 if (f->size_idx2 != -1) in block_rtas_call()
1033 size = be32_to_cpu(args->args[f->size_idx2]); in block_rtas_call()
1034 else if (f->fixed_size) in block_rtas_call()
1035 size = f->fixed_size; in block_rtas_call()
1038 end = base + size - 1; in block_rtas_call()
1041 * Special case for ibm,configure-connector where the in block_rtas_call()
1044 if (!strcmp(f->name, "ibm,configure-connector") && in block_rtas_call()
1056 pr_err_ratelimited("sys_rtas: RTAS call blocked - exploit attempt?\n"); in block_rtas_call()
1057 pr_err_ratelimited("sys_rtas: token=0x%x, nargs=%d (called by %s)\n", in block_rtas_call()
1058 token, nargs, current->comm); in block_rtas_call()
1085 SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) in SYSCALL_DEFINE1() argument
1093 return -EPERM; in SYSCALL_DEFINE1()
1095 if (!rtas.entry) in SYSCALL_DEFINE1()
1096 return -EINVAL; in SYSCALL_DEFINE1()
1099 return -EFAULT; in SYSCALL_DEFINE1()
1108 return -EINVAL; in SYSCALL_DEFINE1()
1111 if (copy_from_user(args.args, uargs->args, in SYSCALL_DEFINE1()
1113 return -EFAULT; in SYSCALL_DEFINE1()
1116 return -EINVAL; in SYSCALL_DEFINE1()
1122 return -EINVAL; in SYSCALL_DEFINE1()
1125 if (token == rtas_token("ibm,suspend-me")) { in SYSCALL_DEFINE1()
1135 if (rc == -EAGAIN) in SYSCALL_DEFINE1()
1137 else if (rc == -EIO) in SYSCALL_DEFINE1()
1138 args.rets[0] = cpu_to_be32(-1); in SYSCALL_DEFINE1()
1148 rtas.args = args; in SYSCALL_DEFINE1()
1149 do_enter_rtas(__pa(&rtas.args)); in SYSCALL_DEFINE1()
1150 args = rtas.args; in SYSCALL_DEFINE1()
1152 /* A -1 return code indicates that the last command couldn't in SYSCALL_DEFINE1()
1154 if (be32_to_cpu(args.rets[0]) == -1) in SYSCALL_DEFINE1()
1167 if (copy_to_user(uargs->args + nargs, in SYSCALL_DEFINE1()
1170 return -EFAULT; in SYSCALL_DEFINE1()
1176 * Call early during boot, before mem init, to retrieve the RTAS
1177 * information from the device-tree and allocate the RMO buffer for userland
1186 /* Get RTAS dev node and fill up our "rtas" structure with infos in rtas_initialize()
1189 rtas.dev = of_find_node_by_name(NULL, "rtas"); in rtas_initialize()
1190 if (!rtas.dev) in rtas_initialize()
1193 no_base = of_property_read_u32(rtas.dev, "linux,rtas-base", &base); in rtas_initialize()
1194 no_size = of_property_read_u32(rtas.dev, "rtas-size", &size); in rtas_initialize()
1196 of_node_put(rtas.dev); in rtas_initialize()
1197 rtas.dev = NULL; in rtas_initialize()
1201 rtas.base = base; in rtas_initialize()
1202 rtas.size = size; in rtas_initialize()
1203 no_entry = of_property_read_u32(rtas.dev, "linux,rtas-entry", &entry); in rtas_initialize()
1204 rtas.entry = no_entry ? rtas.base : entry; in rtas_initialize()
1206 /* If RTAS was found, allocate the RMO buffer for it and look for in rtas_initialize()
1207 * the stop-self token if any in rtas_initialize()
1216 panic("ERROR: RTAS: Failed to allocate %lx bytes below %pa\n", in rtas_initialize()
1220 rtas_last_error_token = rtas_token("rtas-last-error"); in rtas_initialize()
1231 if (depth != 1 || strcmp(uname, "rtas") != 0) in early_init_dt_scan_rtas()
1234 basep = of_get_flat_dt_prop(node, "linux,rtas-base", NULL); in early_init_dt_scan_rtas()
1235 entryp = of_get_flat_dt_prop(node, "linux,rtas-entry", NULL); in early_init_dt_scan_rtas()
1236 sizep = of_get_flat_dt_prop(node, "rtas-size", NULL); in early_init_dt_scan_rtas()
1239 rtas.base = *basep; in early_init_dt_scan_rtas()
1240 rtas.entry = *entryp; in early_init_dt_scan_rtas()
1241 rtas.size = *sizep; in early_init_dt_scan_rtas()
1245 basep = of_get_flat_dt_prop(node, "put-term-char", NULL); in early_init_dt_scan_rtas()
1249 basep = of_get_flat_dt_prop(node, "get-term-char", NULL); in early_init_dt_scan_rtas()
1273 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL); in rtas_give_timebase()
1279 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL); in rtas_give_timebase()