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.
29 #include <asm/rtas.h>
46 /* This is here deliberately so it's only used in this file */
49 struct rtas_t rtas = { variable
52 EXPORT_SYMBOL(rtas);
63 * If non-NULL, this gets called when the kernel terminates.
69 /* RTAS use home made raw locking instead of spin_lock_irqsave
80 arch_spin_lock(&rtas.lock); in lock_rtas()
86 arch_spin_unlock(&rtas.lock); in unlock_rtas()
93 * are designed only for very early low-level debugging, which
94 * is why the token is hard-coded to 10.
100 if (!rtas.base) in call_rtas_display_status()
104 rtas_call_unlocked(&rtas.args, 10, 1, 1, NULL, c); in call_rtas_display_status()
114 while (width-- > 0) in call_rtas_display_status_delay()
125 if (width--) { in call_rtas_display_status_delay()
141 * hardcode rtas.base/entry etc.
150 if (!rtas.base) in udbg_rtascon_putc()
169 if (!rtas.base) in udbg_rtascon_getc_poll()
170 return -1; in udbg_rtascon_getc_poll()
173 return -1; in udbg_rtascon_getc_poll()
182 while ((c = udbg_rtascon_getc_poll()) == -1) in udbg_rtascon_getc()
210 if (!rtas.base) in rtas_progress()
215 if ((root = of_find_node_by_path("/rtas"))) { in rtas_progress()
217 "ibm,display-line-length", NULL))) in rtas_progress()
220 "ibm,form-feed", NULL))) in rtas_progress()
223 "ibm,display-number-of-lines", NULL))) in rtas_progress()
226 "ibm,display-truncation-length", NULL); in rtas_progress()
229 display_character = rtas_token("display-character"); in rtas_progress()
230 set_indicator = rtas_token("set-indicator"); in rtas_progress()
278 if (current_line > display_lines-1) in rtas_progress()
279 current_line = display_lines-1; in rtas_progress()
284 /* RTAS wants CR-LF, not just LF */ in rtas_progress()
290 /* CR might be used to re-draw a line, so we'll in rtas_progress()
301 width--; in rtas_progress()
315 EXPORT_SYMBOL(rtas_progress); /* needed by rtas_flash module */
320 if (rtas.dev == NULL) in rtas_token()
322 tokp = of_get_property(rtas.dev, service, NULL); in rtas_token()
335 * Return the firmware-specified size of the error log buffer
336 * for all rtas calls that require an error buffer argument.
337 * This includes 'check-exception' and 'rtas-last-error'.
345 rtas_error_log_max = rtas_token ("rtas-error-log-max"); in rtas_get_error_log_max()
348 printk (KERN_WARNING "RTAS: bad log buffer size %d\n", in rtas_get_error_log_max()
361 * most recent failed call to rtas. Because the error text
362 * might go stale if there are any other intervening rtas calls,
364 * the error (i.e. with rtas.lock still held from the previous call).
372 if (rtas_last_error_token == -1) in __fetch_rtas_last_error()
384 save_args = rtas.args; in __fetch_rtas_last_error()
385 rtas.args = err_args; in __fetch_rtas_last_error()
387 enter_rtas(__pa(&rtas.args)); in __fetch_rtas_last_error()
389 err_args = rtas.args; in __fetch_rtas_last_error()
390 rtas.args = save_args; in __fetch_rtas_last_error()
422 args->token = cpu_to_be32(token); in va_rtas_call_unlocked()
423 args->nargs = cpu_to_be32(nargs); in va_rtas_call_unlocked()
424 args->nret = cpu_to_be32(nret); in va_rtas_call_unlocked()
425 args->rets = &(args->args[nargs]); in va_rtas_call_unlocked()
428 args->args[i] = cpu_to_be32(va_arg(list, __u32)); in va_rtas_call_unlocked()
431 args->rets[i] = 0; in va_rtas_call_unlocked()
454 if (!rtas.entry || token == RTAS_UNKNOWN_SERVICE) in rtas_call()
455 return -1; in rtas_call()
459 /* We use the global rtas args buffer */ in rtas_call()
460 rtas_args = &rtas.args; in rtas_call()
466 /* A -1 return code indicates that the last command couldn't in rtas_call()
468 if (be32_to_cpu(rtas_args->rets[0]) == -1) in rtas_call()
472 for (i = 0; i < nret-1; ++i) in rtas_call()
473 outputs[i] = be32_to_cpu(rtas_args->rets[i+1]); in rtas_call()
474 ret = (nret > 0)? be32_to_cpu(rtas_args->rets[0]): 0; in rtas_call()
487 /* For RTAS_BUSY (-2), delay for 1 millisecond. For an extended busy status
499 order = status - RTAS_EXTENDED_DELAY_MIN; in rtas_busy_delay_time()
500 for (ms = 1; order > 0; order--) in rtas_busy_delay_time()
508 /* For an RTAS busy status code, perform the hinted delay. */
527 case -1: /* Hardware Error */ in rtas_error_rc()
528 rc = -EIO; in rtas_error_rc()
530 case -3: /* Bad indicator/domain/etc */ in rtas_error_rc()
531 rc = -EINVAL; in rtas_error_rc()
533 case -9000: /* Isolation error */ in rtas_error_rc()
534 rc = -EFAULT; in rtas_error_rc()
536 case -9001: /* Outstanding TCE/PTE */ in rtas_error_rc()
537 rc = -EEXIST; in rtas_error_rc()
539 case -9002: /* No usable slot */ in rtas_error_rc()
540 rc = -ENODEV; in rtas_error_rc()
543 printk(KERN_ERR "%s: unexpected RTAS error %d\n", in rtas_error_rc()
545 rc = -ERANGE; in rtas_error_rc()
553 int token = rtas_token("get-power-level"); in rtas_get_power_level()
557 return -ENOENT; in rtas_get_power_level()
570 int token = rtas_token("set-power-level"); in rtas_set_power_level()
574 return -ENOENT; in rtas_set_power_level()
588 int token = rtas_token("get-sensor-state"); in rtas_get_sensor()
592 return -ENOENT; in rtas_get_sensor()
606 int token = rtas_token("get-sensor-state"); in rtas_get_sensor_fast()
610 return -ENOENT; in rtas_get_sensor_fast()
629 indicators = of_get_property(rtas.dev, "rtas-indicators", &proplen); in rtas_indicator_present()
649 int token = rtas_token("set-indicator"); in rtas_set_indicator()
653 return -ENOENT; in rtas_set_indicator()
666 * Ignoring RTAS extended delay
671 int token = rtas_token("set-indicator"); in rtas_set_indicator_fast()
674 return -ENOENT; in rtas_set_indicator_fast()
691 printk("RTAS system-reboot returned %d\n", in rtas_restart()
692 rtas_call(rtas_token("system-reboot"), 0, 1, NULL)); in rtas_restart()
701 printk("RTAS power-off returned %d\n", in rtas_power_off()
702 rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1)); in rtas_power_off()
711 printk("RTAS power-off returned %d\n", in rtas_halt()
712 rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1)); in rtas_halt()
724 * Firmware with the ibm,extended-os-term property is guaranteed in rtas_os_term()
725 * to always return from an ibm,os-term call. Earlier versions without in rtas_os_term()
729 if (RTAS_UNKNOWN_SERVICE == rtas_token("ibm,os-term") || in rtas_os_term()
730 RTAS_UNKNOWN_SERVICE == rtas_token("ibm,extended-os-term")) in rtas_os_term()
736 status = rtas_call(rtas_token("ibm,os-term"), 1, 1, NULL, in rtas_os_term()
741 printk(KERN_EMERG "ibm,os-term call failed %d\n", status); in rtas_os_term()
753 printk(KERN_DEBUG "calling ibm,suspend-me on cpu %i\n", smp_processor_id()); in __rtas_suspend_last_cpu()
755 while (rc == H_MULTI_THREADS_ACTIVE && !atomic_read(&data->done) && in __rtas_suspend_last_cpu()
756 !atomic_read(&data->error)) in __rtas_suspend_last_cpu()
757 rc = rtas_call(data->token, 0, 1, NULL); in __rtas_suspend_last_cpu()
759 if (rc || atomic_read(&data->error)) { in __rtas_suspend_last_cpu()
760 printk(KERN_DEBUG "ibm,suspend-me returned %d\n", rc); in __rtas_suspend_last_cpu()
764 if (atomic_read(&data->error)) in __rtas_suspend_last_cpu()
765 rc = atomic_read(&data->error); in __rtas_suspend_last_cpu()
767 atomic_set(&data->error, rc); in __rtas_suspend_last_cpu()
771 atomic_set(&data->done, 1); in __rtas_suspend_last_cpu()
777 if (atomic_dec_return(&data->working) == 0) in __rtas_suspend_last_cpu()
778 complete(data->complete); in __rtas_suspend_last_cpu()
785 atomic_inc(&data->working); in rtas_suspend_last_cpu()
795 atomic_inc(&data->working); in __rtas_suspend_cpu()
801 while (rc == H_SUCCESS && !atomic_read(&data->done) && !atomic_read(&data->error)) in __rtas_suspend_cpu()
817 atomic_set(&data->error, rc); in __rtas_suspend_cpu()
821 atomic_set(&data->done, 1); in __rtas_suspend_cpu()
831 if (atomic_dec_return(&data->working) == 0) in __rtas_suspend_cpu()
832 complete(data->complete); in __rtas_suspend_cpu()
854 if (!rtas_service_present("ibm,suspend-me")) in rtas_ibm_suspend_me()
855 return -ENOSYS; in rtas_ibm_suspend_me()
866 return -EAGAIN; in rtas_ibm_suspend_me()
870 return -EIO; in rtas_ibm_suspend_me()
876 data.token = rtas_token("ibm,suspend-me"); in rtas_ibm_suspend_me()
884 * rtas call in rtas_ibm_suspend_me()
902 * rtas_call_reentrant() - Used for reentrant rtas calls
903 * @token: Token for desired reentrant RTAS call
907 * @...: Inputs for desired RTAS call
909 * According to LoPAR documentation, only "ibm,int-on", "ibm,int-off",
910 * "ibm,get-xive" and "ibm,set-xive" are currently reentrant.
911 * Reentrant calls need their own rtas_args buffer, so not using rtas.args, but
914 * Return: -1 on error,
915 * First output value of RTAS call if (nret > 0),
925 if (!rtas.entry || token == RTAS_UNKNOWN_SERVICE) in rtas_call_reentrant()
926 return -1; in rtas_call_reentrant()
931 /* We use the per-cpu (PACA) rtas args buffer */ in rtas_call_reentrant()
932 args = local_paca->rtas_args_reentrant; in rtas_call_reentrant()
939 for (i = 0; i < nret - 1; ++i) in rtas_call_reentrant()
940 outputs[i] = be32_to_cpu(args->rets[i + 1]); in rtas_call_reentrant()
943 ret = be32_to_cpu(args->rets[0]); in rtas_call_reentrant()
954 return -ENOSYS; in rtas_ibm_suspend_me()
959 * Find a specific pseries error log in an RTAS extended event log.
960 * @log: RTAS error/event log
969 (struct rtas_ext_event_log_v6 *)log->buffer; in get_pseries_errorlog()
982 log_end = log->buffer + ext_log_length; in get_pseries_errorlog()
983 p = ext_log->vendor_log; in get_pseries_errorlog()
999 * arbitrary physical addresses to RTAS calls. A number of RTAS calls
1002 * be used inside the kernel and not exposed to userspace.
1006 * subset of RTAS calls.
1008 * Accordingly, we filter RTAS requests to check that the call is
1017 /* Indexes into the args buffer, -1 if not used */
1027 { "ibm,activate-firmware", -1, -1, -1, -1, -1 },
1028 { "ibm,configure-connector", -1, 0, -1, 1, -1, 4096 }, /* Special cased */
1029 { "display-character", -1, -1, -1, -1, -1 },
1030 { "ibm,display-message", -1, 0, -1, -1, -1 },
1031 { "ibm,errinjct", -1, 2, -1, -1, -1, 1024 },
1032 { "ibm,close-errinjct", -1, -1, -1, -1, -1 },
1033 { "ibm,open-errinct", -1, -1, -1, -1, -1 },
1034 { "ibm,get-config-addr-info2", -1, -1, -1, -1, -1 },
1035 { "ibm,get-dynamic-sensor-state", -1, 1, -1, -1, -1 },
1036 { "ibm,get-indices", -1, 2, 3, -1, -1 },
1037 { "get-power-level", -1, -1, -1, -1, -1 },
1038 { "get-sensor-state", -1, -1, -1, -1, -1 },
1039 { "ibm,get-system-parameter", -1, 1, 2, -1, -1 },
1040 { "get-time-of-day", -1, -1, -1, -1, -1 },
1041 { "ibm,get-vpd", -1, 0, -1, 1, 2 },
1042 { "ibm,lpar-perftools", -1, 2, 3, -1, -1 },
1043 { "ibm,platform-dump", -1, 4, 5, -1, -1 },
1044 { "ibm,read-slot-reset-state", -1, -1, -1, -1, -1 },
1045 { "ibm,scan-log-dump", -1, 0, 1, -1, -1 },
1046 { "ibm,set-dynamic-indicator", -1, 2, -1, -1, -1 },
1047 { "ibm,set-eeh-option", -1, -1, -1, -1, -1 },
1048 { "set-indicator", -1, -1, -1, -1, -1 },
1049 { "set-power-level", -1, -1, -1, -1, -1 },
1050 { "set-time-for-power-on", -1, -1, -1, -1, -1 },
1051 { "ibm,set-system-parameter", -1, 1, -1, -1, -1 },
1052 { "set-time-of-day", -1, -1, -1, -1, -1 },
1053 { "ibm,suspend-me", -1, -1, -1, -1, -1 },
1054 { "ibm,update-nodes", -1, 0, -1, -1, -1, 4096 },
1055 { "ibm,update-properties", -1, 0, -1, -1, -1, 4096 },
1056 { "ibm,physical-attestation", -1, 0, 1, -1, -1 },
1077 if (token != f->token) in block_rtas_call()
1080 if (f->buf_idx1 != -1) { in block_rtas_call()
1081 base = be32_to_cpu(args->args[f->buf_idx1]); in block_rtas_call()
1082 if (f->size_idx1 != -1) in block_rtas_call()
1083 size = be32_to_cpu(args->args[f->size_idx1]); in block_rtas_call()
1084 else if (f->fixed_size) in block_rtas_call()
1085 size = f->fixed_size; in block_rtas_call()
1089 end = base + size - 1; in block_rtas_call()
1094 if (f->buf_idx2 != -1) { in block_rtas_call()
1095 base = be32_to_cpu(args->args[f->buf_idx2]); in block_rtas_call()
1096 if (f->size_idx2 != -1) in block_rtas_call()
1097 size = be32_to_cpu(args->args[f->size_idx2]); in block_rtas_call()
1098 else if (f->fixed_size) in block_rtas_call()
1099 size = f->fixed_size; in block_rtas_call()
1102 end = base + size - 1; in block_rtas_call()
1105 * Special case for ibm,configure-connector where the in block_rtas_call()
1108 if (!strcmp(f->name, "ibm,configure-connector") && in block_rtas_call()
1120 pr_err_ratelimited("sys_rtas: RTAS call blocked - exploit attempt?\n"); in block_rtas_call()
1121 pr_err_ratelimited("sys_rtas: token=0x%x, nargs=%d (called by %s)\n", in block_rtas_call()
1122 token, nargs, current->comm); in block_rtas_call()
1137 SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) in SYSCALL_DEFINE1() argument
1145 return -EPERM; in SYSCALL_DEFINE1()
1147 if (!rtas.entry) in SYSCALL_DEFINE1()
1148 return -EINVAL; in SYSCALL_DEFINE1()
1151 return -EFAULT; in SYSCALL_DEFINE1()
1160 return -EINVAL; in SYSCALL_DEFINE1()
1163 if (copy_from_user(args.args, uargs->args, in SYSCALL_DEFINE1()
1165 return -EFAULT; in SYSCALL_DEFINE1()
1168 return -EINVAL; in SYSCALL_DEFINE1()
1174 return -EINVAL; in SYSCALL_DEFINE1()
1187 if (rc == -EAGAIN) in SYSCALL_DEFINE1()
1189 else if (rc == -EIO) in SYSCALL_DEFINE1()
1190 args.rets[0] = cpu_to_be32(-1); in SYSCALL_DEFINE1()
1200 rtas.args = args; in SYSCALL_DEFINE1()
1201 enter_rtas(__pa(&rtas.args)); in SYSCALL_DEFINE1()
1202 args = rtas.args; in SYSCALL_DEFINE1()
1204 /* A -1 return code indicates that the last command couldn't in SYSCALL_DEFINE1()
1206 if (be32_to_cpu(args.rets[0]) == -1) in SYSCALL_DEFINE1()
1219 if (copy_to_user(uargs->args + nargs, in SYSCALL_DEFINE1()
1222 return -EFAULT; in SYSCALL_DEFINE1()
1228 * Call early during boot, before mem init, to retrieve the RTAS
1229 * information from the device-tree and allocate the RMO buffer for userland
1241 /* Get RTAS dev node and fill up our "rtas" structure with infos in rtas_initialize()
1244 rtas.dev = of_find_node_by_name(NULL, "rtas"); in rtas_initialize()
1245 if (!rtas.dev) in rtas_initialize()
1248 no_base = of_property_read_u32(rtas.dev, "linux,rtas-base", &base); in rtas_initialize()
1249 no_size = of_property_read_u32(rtas.dev, "rtas-size", &size); in rtas_initialize()
1251 of_node_put(rtas.dev); in rtas_initialize()
1252 rtas.dev = NULL; in rtas_initialize()
1256 rtas.base = base; in rtas_initialize()
1257 rtas.size = size; in rtas_initialize()
1258 no_entry = of_property_read_u32(rtas.dev, "linux,rtas-entry", &entry); in rtas_initialize()
1259 rtas.entry = no_entry ? rtas.base : entry; in rtas_initialize()
1261 /* If RTAS was found, allocate the RMO buffer for it and look for in rtas_initialize()
1262 * the stop-self token if any in rtas_initialize()
1267 ibm_suspend_me_token = rtas_token("ibm,suspend-me"); in rtas_initialize()
1273 panic("ERROR: RTAS: Failed to allocate %lx bytes below %pa\n", in rtas_initialize()
1277 rtas_last_error_token = rtas_token("rtas-last-error"); in rtas_initialize()
1292 if (depth != 1 || strcmp(uname, "rtas") != 0) in early_init_dt_scan_rtas()
1295 basep = of_get_flat_dt_prop(node, "linux,rtas-base", NULL); in early_init_dt_scan_rtas()
1296 entryp = of_get_flat_dt_prop(node, "linux,rtas-entry", NULL); in early_init_dt_scan_rtas()
1297 sizep = of_get_flat_dt_prop(node, "rtas-size", NULL); in early_init_dt_scan_rtas()
1300 rtas.base = *basep; in early_init_dt_scan_rtas()
1301 rtas.entry = *entryp; in early_init_dt_scan_rtas()
1302 rtas.size = *sizep; in early_init_dt_scan_rtas()
1306 basep = of_get_flat_dt_prop(node, "put-term-char", NULL); in early_init_dt_scan_rtas()
1310 basep = of_get_flat_dt_prop(node, "get-term-char", NULL); in early_init_dt_scan_rtas()
1334 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL); in rtas_give_timebase()
1340 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL); in rtas_give_timebase()