Skip to content

Commit 336e255

Browse files
nathanlynchmpe
authored andcommitted
powerpc/rtas: document rtas_call()
rtas_call() has a complex calling convention, non-standard return values, and many users. Add kernel-doc for it and remove the less structured commentary from rtas.h. Signed-off-by: Nathan Lynch <[email protected]> Reviewed-by: Andrew Donnellan <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f6aa37c commit 336e255

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

arch/powerpc/include/asm/rtas.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@
3333
#define RTAS_THREADS_ACTIVE -9005 /* Multiple processor threads active */
3434
#define RTAS_OUTSTANDING_COPROC -9006 /* Outstanding coprocessor operations */
3535

36-
/*
37-
* In general to call RTAS use rtas_token("string") to lookup
38-
* an RTAS token for the given string (e.g. "event-scan").
39-
* To actually perform the call use
40-
* ret = rtas_call(token, n_in, n_out, ...)
41-
* Where n_in is the number of input parameters and
42-
* n_out is the number of output parameters
43-
*
44-
* If the "string" is invalid on this system, RTAS_UNKNOWN_SERVICE
45-
* will be returned as a token. rtas_call() does look for this
46-
* token and error out gracefully so rtas_call(rtas_token("str"), ...)
47-
* may be safely used for one-shot calls to RTAS.
48-
*
49-
*/
50-
5136
/* RTAS event classes */
5237
#define RTAS_INTERNAL_ERROR 0x80000000 /* set bit 0 */
5338
#define RTAS_EPOW_WARNING 0x40000000 /* set bit 1 */

arch/powerpc/kernel/rtas.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,64 @@ void rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret,
467467
static int ibm_open_errinjct_token;
468468
static 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+
*/
470528
int rtas_call(int token, int nargs, int nret, int *outputs, ...)
471529
{
472530
va_list list;

0 commit comments

Comments
 (0)