1 // SPDX-License-Identifier: GPL-2.0-only
3 #define pr_fmt(fmt) "papr-sysparm: " fmt
6 #include <linux/init.h>
7 #include <linux/kernel.h>
8 #include <linux/printk.h>
9 #include <linux/slab.h>
11 #include <asm/papr-sysparm.h>
12 #include <asm/rtas-work-area.h>
14 struct papr_sysparm_buf *papr_sysparm_buf_alloc(void)
16 struct papr_sysparm_buf *buf = kzalloc(sizeof(*buf), GFP_KERNEL);
21 void papr_sysparm_buf_free(struct papr_sysparm_buf *buf)
27 * papr_sysparm_get() - Retrieve the value of a PAPR system parameter.
28 * @param: PAPR system parameter token as described in
29 * 7.3.16 "System Parameters Option".
30 * @buf: A &struct papr_sysparm_buf as returned from papr_sysparm_buf_alloc().
32 * Place the result of querying the specified parameter, if available,
33 * in @buf. The result includes a be16 length header followed by the
34 * value, which may be a string or binary data. See &struct papr_sysparm_buf.
36 * Since there is at least one parameter (60, OS Service Entitlement
37 * Status) where the results depend on the incoming contents of the
38 * work area, the caller-supplied buffer is copied unmodified into the
39 * work area before calling ibm,get-system-parameter.
41 * A defined parameter may not be implemented on a given system, and
42 * some implemented parameters may not be available to all partitions
43 * on a system. A parameter's disposition may change at any time due
44 * to system configuration changes or partition migration.
46 * Context: This function may sleep.
48 * Return: 0 on success, -errno otherwise. @buf is unmodified on error.
51 int papr_sysparm_get(papr_sysparm_t param, struct papr_sysparm_buf *buf)
53 const s32 token = rtas_function_token(RTAS_FN_IBM_GET_SYSTEM_PARAMETER);
54 struct rtas_work_area *work_area;
63 if (token == RTAS_UNKNOWN_SERVICE)
66 work_area = rtas_work_area_alloc(sizeof(*buf));
68 memcpy(rtas_work_area_raw_buf(work_area), buf, sizeof(*buf));
71 fwrc = rtas_call(token, 3, 1, NULL, param.token,
72 rtas_work_area_phys(work_area),
73 rtas_work_area_size(work_area));
74 } while (rtas_busy_delay(fwrc));
79 memcpy(buf, rtas_work_area_raw_buf(work_area), sizeof(*buf));
81 case -3: /* parameter not implemented */
84 case -9002: /* this partition not authorized to retrieve this parameter */
87 case -9999: /* "parameter error" e.g. the buffer is too small */
91 pr_err("unexpected ibm,get-system-parameter result %d\n", fwrc);
93 case -1: /* Hardware/platform error */
98 rtas_work_area_free(work_area);
103 int papr_sysparm_set(papr_sysparm_t param, const struct papr_sysparm_buf *buf)
105 const s32 token = rtas_function_token(RTAS_FN_IBM_SET_SYSTEM_PARAMETER);
106 struct rtas_work_area *work_area;
115 if (token == RTAS_UNKNOWN_SERVICE)
118 work_area = rtas_work_area_alloc(sizeof(*buf));
120 memcpy(rtas_work_area_raw_buf(work_area), buf, sizeof(*buf));
123 fwrc = rtas_call(token, 2, 1, NULL, param.token,
124 rtas_work_area_phys(work_area));
125 } while (rtas_busy_delay(fwrc));
131 case -3: /* parameter not supported */
134 case -9002: /* this partition not authorized to modify this parameter */
137 case -9999: /* "parameter error" e.g. invalid input data */
141 pr_err("unexpected ibm,set-system-parameter result %d\n", fwrc);
143 case -1: /* Hardware/platform error */
148 rtas_work_area_free(work_area);