linux/arch/powerpc/platforms/pseries/papr-rtas-common.h
Haren Myneni ecc45d4f8c powerpc/pseries: Define common functions for RTAS sequence calls
The RTAS call can be normal where retrieves the data form the
hypervisor once or sequence based RTAS call which has to
issue multiple times until the complete data is obtained. For
some of these sequence RTAS calls, the OS should not interleave
calls with different input until the sequence is completed.
The data is collected for each call and copy to the buffer
for the entire sequence during ioctl() handle and then expose
this buffer to the user space with read() handle.

One such sequence RTAS call is ibm,get-vpd and its support is
already included in the current code. To add the similar support
for other sequence based calls, move the common functions in to
separate file and update papr_rtas_sequence struct with the
following callbacks so that RTAS call specific code will be
defined and executed to complete the sequence.

struct papr_rtas_sequence {
        int error;
        void params;
        void (*begin) (struct papr_rtas_sequence *);
        void (*end) (struct papr_rtas_sequence *);
        const char * (*work) (struct papr_rtas_sequence *, size_t *);
};

params: Input parameters used to pass for RTAS call.
Begin:	RTAS call specific function to initialize data
	including work area allocation.
End:	RTAS call specific function to free up resources
	(free work area) after the sequence is completed.
Work:	The actual RTAS call specific function which collects
	the data from the hypervisor.

Signed-off-by: Haren Myneni <haren@linux.ibm.com>
Tested-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/20250416225743.596462-2-haren@linux.ibm.com
2025-04-17 11:42:29 +05:30

61 lines
2.3 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _ASM_POWERPC_PAPR_RTAS_COMMON_H
#define _ASM_POWERPC_PAPR_RTAS_COMMON_H
#include <linux/types.h>
/*
* Return codes for sequence based RTAS calls.
* Not listed under PAPR+ v2.13 7.2.8: "Return Codes".
* But defined in the specific section of each RTAS call.
*/
#define RTAS_SEQ_COMPLETE 0 /* All data has been retrieved. */
#define RTAS_SEQ_MORE_DATA 1 /* More data is available */
#define RTAS_SEQ_START_OVER -4 /* Data changed, restart call sequence. */
/*
* Internal "blob" APIs for accumulating RTAS call results into
* an immutable buffer to be attached to a file descriptor.
*/
struct papr_rtas_blob {
const char *data;
size_t len;
};
/**
* struct papr_sequence - State for managing a sequence of RTAS calls.
* @error: Shall be zero as long as the sequence has not encountered an error,
* -ve errno otherwise. Use papr_rtas_sequence_set_err() to update.
* @params: Parameter block to pass to rtas_*() calls.
* @begin: Work area allocation and initialize the needed parameter
* values passed to RTAS call
* @end: Free the allocated work area
* @work: Obtain data with RTAS call and invoke it until the sequence is
* completed.
*
*/
struct papr_rtas_sequence {
int error;
void *params;
void (*begin)(struct papr_rtas_sequence *seq);
void (*end)(struct papr_rtas_sequence *seq);
const char *(*work)(struct papr_rtas_sequence *seq, size_t *len);
};
extern bool papr_rtas_blob_has_data(const struct papr_rtas_blob *blob);
extern void papr_rtas_blob_free(const struct papr_rtas_blob *blob);
extern int papr_rtas_sequence_set_err(struct papr_rtas_sequence *seq,
int err);
extern const struct papr_rtas_blob *papr_rtas_retrieve(struct papr_rtas_sequence *seq);
extern long papr_rtas_setup_file_interface(struct papr_rtas_sequence *seq,
const struct file_operations *fops, char *name);
extern bool papr_rtas_sequence_should_stop(const struct papr_rtas_sequence *seq,
s32 status, bool init_state);
extern ssize_t papr_rtas_common_handle_read(struct file *file,
char __user *buf, size_t size, loff_t *off);
extern int papr_rtas_common_handle_release(struct inode *inode,
struct file *file);
extern loff_t papr_rtas_common_handle_seek(struct file *file, loff_t off,
int whence);
#endif /* _ASM_POWERPC_PAPR_RTAS_COMMON_H */