@@ -467,6 +467,64 @@ void rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret,
467467static int ibm_open_errinjct_token ;
468468static int ibm_errinjct_token ;
469469
470+ /**
471+ * rtas_call() - Invoke an RTAS firmware function.
472+ * @token: Identifies the function being invoked.
473+ * @nargs: Number of input parameters. Does not include token.
474+ * @nret: Number of output parameters, including the call status.
475+ * @outputs: Array of @nret output words.
476+ * @....: List of @nargs input parameters.
477+ *
478+ * Invokes the RTAS function indicated by @token, which the caller
479+ * should obtain via rtas_token().
480+ *
481+ * The @nargs and @nret arguments must match the number of input and
482+ * output parameters specified for the RTAS function.
483+ *
484+ * rtas_call() returns RTAS status codes, not conventional Linux errno
485+ * values. Callers must translate any failure to an appropriate errno
486+ * in syscall context. Most callers of RTAS functions that can return
487+ * -2 or 990x should use rtas_busy_delay() to correctly handle those
488+ * statuses before calling again.
489+ *
490+ * The return value descriptions are adapted from 7.2.8 [RTAS] Return
491+ * Codes of the PAPR and CHRP specifications.
492+ *
493+ * Context: Process context preferably, interrupt context if
494+ * necessary. Acquires an internal spinlock and may perform
495+ * GFP_ATOMIC slab allocation in error path. Unsafe for NMI
496+ * context.
497+ * Return:
498+ * * 0 - RTAS function call succeeded.
499+ * * -1 - RTAS function encountered a hardware or
500+ * platform error, or the token is invalid,
501+ * or the function is restricted by kernel policy.
502+ * * -2 - Specs say "A necessary hardware device was busy,
503+ * and the requested function could not be
504+ * performed. The operation should be retried at
505+ * a later time." This is misleading, at least with
506+ * respect to current RTAS implementations. What it
507+ * usually means in practice is that the function
508+ * could not be completed while meeting RTAS's
509+ * deadline for returning control to the OS (250us
510+ * for PAPR/PowerVM, typically), but the call may be
511+ * immediately reattempted to resume work on it.
512+ * * -3 - Parameter error.
513+ * * -7 - Unexpected state change.
514+ * * 9000...9899 - Vendor-specific success codes.
515+ * * 9900...9905 - Advisory extended delay. Caller should try
516+ * again after ~10^x ms has elapsed, where x is
517+ * the last digit of the status [0-5]. Again going
518+ * beyond the PAPR text, 990x on PowerVM indicates
519+ * contention for RTAS-internal resources. Other
520+ * RTAS call sequences in progress should be
521+ * allowed to complete before reattempting the
522+ * call.
523+ * * -9000 - Multi-level isolation error.
524+ * * -9999...-9004 - Vendor-specific error codes.
525+ * * Additional negative values - Function-specific error.
526+ * * Additional positive values - Function-specific success.
527+ */
470528int rtas_call (int token , int nargs , int nret , int * outputs , ...)
471529{
472530 va_list list ;
0 commit comments