spapr: add ibm,(get|set)-system-parameter
PATCH v2 1/1 spapr: add ibm,(get|set)-system-parameter
This adds very basic handlers for ibm,get-system-parameter and ibm,set-system-parameter RTAS calls.
The only parameter handled at the moment is "platform-processor-diagnostics-run-mode" which is always disabled and does not support changing. This is expected to make "ppc64_cpu --run-mode=1" happy.
---
Changes:
v2:
* addressed comments from Alex Graf
--- hw/ppc/spapr_rtas.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
hw/ppc/spapr_rtas.c +48 -0
@@ -224,6 +224,50 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, env->msr =0 ; } +#define DIAGNOSTICS_RUN_MODE 42 + +static void rtas_ibm_get_system_parameter (PowerPCCPU *cpu, +sPAPREnvironment *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +target_ulong papameter =rtas_ld (args,0 ); +target_ulong buffer =rtas_ld (args,1 ); +target_ulong length =rtas_ld (args,2 ); +target_ulong ret =-3 ;/* System parameter is not supported */ + +switch (papameter) { +case DIAGNOSTICS_RUN_MODE : +if (length ==1 ) { +rtas_st (buffer,0 ,0 ); + ret =0 ;/* Success */ + } +break ; + } + +rtas_st (rets,0 , ret); +} + +static void rtas_ibm_set_system_parameter (PowerPCCPU *cpu, +sPAPREnvironment *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +target_ulong papameter =rtas_ld (args,0 ); +/* target_ulong buffer = rtas_ld(args, 1); */ +target_ulong ret =-3 ;/* System parameter is not supported */ + +switch (papameter) { +case DIAGNOSTICS_RUN_MODE : + ret =-9002 ;/* Setting not allowed/authorized */ +break ; + } + +rtas_st (rets,0 , ret); +} + static struct rtas_call { const char *name; spapr_rtas_fn fn;
@@ -345,6 +389,10 @@ static void core_rtas_register_types(void) rtas_query_cpu_stopped_state);spapr_rtas_register ("start-cpu" , rtas_start_cpu);spapr_rtas_register ("stop-self" , rtas_stop_self); +spapr_rtas_register ("ibm,get-system-parameter" , + rtas_ibm_get_system_parameter); +spapr_rtas_register ("ibm,set-system-parameter" , + rtas_ibm_set_system_parameter); }type_init (core_rtas_register_types)
Signature · 1 line
1.8.4.rc4
Re: [Qemu-devel] [PATCH v2] spapr: add ibm, (get|set)-system-parameter
Quoted 27 lines · Alexey Kardashevskiy
This adds very basic handlers for ibm,get-system-parameter and ibm,set-system-parameter RTAS calls.
The only parameter handled at the moment is "platform-processor-diagnostics-run-mode" which is always disabled and does not support changing. This is expected to make "
ppc64_cpu--run-mode=1" happy.Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* addressed comments from Alex Graf
---hw/ppc/spapr_rtas.c| 48 ++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 48 insertions(+)hw/ppc/spapr_rtas.c +2
-0@@ -224,6 +224,50 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, env->msr =0 ; } +#define DIAGNOSTICS_RUN_MODE 42 +
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 238
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+static void rtas_ibm_get_system_parameter (PowerPCCPU *cpu, +sPAPREnvironment *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +target_ulong papameter =rtas_ld (args,0 ); +target_ulong buffer =rtas_ld (args,1 ); +target_ulong length =rtas_ld (args,2 ); +target_ulong ret =-3 ;/* System parameter is not supported */
Is this an RTAS function defined return value or a global RTAS return value?
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 244
Quoted 6 lines
hw/ppc/spapr_rtas.c +6
-0+ +switch (papameter) { +case DIAGNOSTICS_RUN_MODE : +if (length ==1 ) { +rtas_st (buffer,0 ,0 ); + ret =0 ;/* Success */
I assume this one is RTAS global?
Quoted 5 lines
hw/ppc/spapr_rtas.c +5
-0+ } +break ; + } + +rtas_st (rets,0 , ret);
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 259
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+} + +static void rtas_ibm_set_system_parameter (PowerPCCPU *cpu, +sPAPREnvironment *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +target_ulong papameter =rtas_ld (args,0 ); +/* target_ulong buffer = rtas_ld(args, 1); */
Not addressed. Just remove this line until it gets used.
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 264
Quoted 5 lines
hw/ppc/spapr_rtas.c +5
-0+target_ulong ret =-3 ;/* System parameter is not supported */ + +switch (papameter) { +case DIAGNOSTICS_RUN_MODE : + ret =-9002 ;/* Setting not allowed/authorized */
-9002 seems to always mean "Not Authorized".
In fact, reading through the PAPR spec it seems as if we can easily give return values reasonable names:
#define RTAS_OUT_SUCCESS 0 #define RTAS_OUT_ERROR -1 #define RTAS_OUT_BUSY -2 #define RTAS_OUT_NOT_SUPPORTED -3 #define RTAS_OUT_NOMEM -5 #define RTAS_OUT_NOT_AUTHORIZED -9002 #define RTAS_OUT_PARAM_ERROR -9999
We can't always have a 1:1 map between name and number, but at least name -> number should always be unique:
(ibm,configure-connector) #define RTAS_OUT_DR_CONN_UNUSABLE -9003 #define RTAS_OUT_DR_CONN_NOT_SUPPORTED -9002 #define RTAS_OUT_DR_SYSTEM_NOT_SUPPORTED -9001
Do you see cases where this wouldn't work out? That way we don't have to have explicit comments in the code explaining what a return value really means, making the code more easy to read.
Alex
Re: [Qemu-devel] [PATCH v2] spapr: add ibm, (get|set)-system-parameter
Quoted 28 lines · Alexander Graf
Quoted 25 lines · Alexey Kardashevskiy
This adds very basic handlers for ibm,get-system-parameter and ibm,set-system-parameter RTAS calls.
The only parameter handled at the moment is "platform-processor-diagnostics-run-mode" which is always disabled and does not support changing. This is expected to make "
ppc64_cpu--run-mode=1" happy.Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* addressed comments from Alex Graf
---hw/ppc/spapr_rtas.c| 48 ++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 48 insertions(+)hw/ppc/spapr_rtas.c +0
-0@@ -224,6 +224,50 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, env->msr =0 ; }
Quoted 14 lines
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 238
Quoted 12 lines
hw/ppc/spapr_rtas.c +12
-0+#define DIAGNOSTICS_RUN_MODE 42 + +static void rtas_ibm_get_system_parameter (PowerPCCPU *cpu, +sPAPREnvironment *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +target_ulong papameter =rtas_ld (args,0 ); +target_ulong buffer =rtas_ld (args,1 ); +target_ulong length =rtas_ld (args,2 ); +target_ulong ret =-3 ;/* System parameter is not supported */ Is this an RTAS function defined return value or a global RTAS return value?
Sorry for my ignorance, I do not understand the question. So far every RTAS call I looked at defined all return codes right in the description of the call.
Like this (sorry, cut-n-paste from PDF killed formatting but the point is still valid):
7.3.16.2 ibm,set-system-parameter
Table 96. ibm,set-system-parameter Argument Call Buffer Parameter Type
Name
Token
Values
Token for ibm,set-system-parameter
Number Inputs
In
2
Number Outputs 1
Parameter
Token number of the target system parameter
buffer
Out
Real address of data buffer
Status 0: Success
-1: Hardware Error
-2: Busy, Try again later
-3: System parameter not supported
-9002: Setting not allowed/authorized
-9999: Parameter Error
990x:Extended delay where x is a number 0-5 (see text below)
Quoted 18 lines
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 244
Quoted 6 lines
hw/ppc/spapr_rtas.c +6
-0+ +switch (papameter) { +case DIAGNOSTICS_RUN_MODE : +if (length ==1 ) { +rtas_st (buffer,0 ,0 ); + ret =0 ;/* Success */ I assume this one is RTAS global?
Quoted 9 lines
hw/ppc/spapr_rtas.c +9
-0+ } +break ; + } + +rtas_st (rets,0 , ret); +} + +static void rtas_ibm_set_system_parameter(PowerPCCPU *cpu, + sPAPREnvironment *spapr,
Quoted 8 lines
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 259
Quoted 6 lines
hw/ppc/spapr_rtas.c +6
-0+ uint32_t token, uint32_t nargs, + target_ulong args, + uint32_t nret, target_ulong rets) +{ + target_ulong papameter = rtas_ld(args, 0); +/* target_ulong buffer = rtas_ld(args, 1); */ Not addressed. Just remove this line until it gets used.
What is bad in having such a comment? I thought by having one return per function we help other people from the future to add functionality easier and such comment would help them too.
Quoted 11 lines
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 264
Quoted 5 lines
hw/ppc/spapr_rtas.c +5
-0+target_ulong ret =-3 ;/* System parameter is not supported */ + +switch (papameter) { +case DIAGNOSTICS_RUN_MODE : + ret =-9002 ;/* Setting not allowed/authorized */ -9002 seems to always mean "Not Authorized".
In fact, reading through the PAPR spec it seems as if we can easily give return values reasonable names:
Quoted 7 lines
#define RTAS_OUT_SUCCESS 0 #define RTAS_OUT_ERROR -1 #define RTAS_OUT_BUSY -2 #define RTAS_OUT_NOT_SUPPORTED -3 #define RTAS_OUT_NOMEM -5 #define RTAS_OUT_NOT_AUTHORIZED -9002 #define RTAS_OUT_PARAM_ERROR -9999
These are RTAS local, noone else really cares about them. The kernel uses numbers too (arch/powerpc/kernel/rtas.c). Why should I replace easy understandable (look at spec -> look at gdb -> everything is clear) numbers with definitions?
Quoted 11 lines
We can't always have a 1:1 map between name and number, but at least name -> number should always be unique:
(ibm,configure-connector) #define RTAS_OUT_DR_CONN_UNUSABLE -9003 #define RTAS_OUT_DR_CONN_NOT_SUPPORTED -9002 #define RTAS_OUT_DR_SYSTEM_NOT_SUPPORTED -9001Do you see cases where this wouldn't work out? That way we don't have to have explicit comments in the code explaining what a return value really means, making the code more easy to read.
I need to skim the whole PAPR to make sure that this is the case and then skim the guest kernel to make sure it is not broken somewhere. And I do not see any profit from this job and it will definitely make my life harder as I really (really) want to see exact numbers in the code when I debug binary interface.
However you can always ignore my comments and say "do what I say" and I'll do, no big deal. Thanks.
Signature · 1 line
Alexey
Re: [Qemu-devel] [PATCH v2] spapr: add ibm, (get|set)-system-parameter
Quoted 45 lines · Alexey Kardashevskiy
Quoted 28 lines · Alexander Graf
Quoted 25 lines · Alexey Kardashevskiy
This adds very basic handlers for ibm,get-system-parameter and ibm,set-system-parameter RTAS calls.
The only parameter handled at the moment is "platform-processor-diagnostics-run-mode" which is always disabled and does not support changing. This is expected to make "
ppc64_cpu--run-mode=1" happy.Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* addressed comments from Alex Graf
---hw/ppc/spapr_rtas.c| 48 ++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 48 insertions(+)hw/ppc/spapr_rtas.c +0
-0@@ -224,6 +224,50 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, env->msr =0 ; }Quoted 14 lines
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 238
Quoted 12 lines
hw/ppc/spapr_rtas.c +12
-0+#define DIAGNOSTICS_RUN_MODE 42 + +static void rtas_ibm_get_system_parameter (PowerPCCPU *cpu, +sPAPREnvironment *spapr, +uint32_t token,uint32_t nargs, +target_ulong args, +uint32_t nret,target_ulong rets) +{ +target_ulong papameter =rtas_ld (args,0 ); +target_ulong buffer =rtas_ld (args,1 ); +target_ulong length =rtas_ld (args,2 ); +target_ulong ret =-3 ;/* System parameter is not supported */ Is this an RTAS function defined return value or a global RTAS return value?
Quoted 2 lines
Sorry for my ignorance, I do not understand the question. So far every RTAS call I looked at defined all return codes right in the description of the call.
It's just a prelude to the suggestion further down.
Quoted 57 lines
Like this (sorry, cut-n-paste from PDF killed formatting but the point is still valid):
7.3.16.2 ibm,set-system-parameter
Table 96. ibm,set-system-parameter Argument Call Buffer Parameter Type
Name
Token
Values
Token for ibm,set-system-parameter
Number Inputs
In
2
Number Outputs 1
Parameter
Token number of the target system parameter
buffer
Out
Real address of data buffer
Status 0: Success
-1: Hardware Error
-2: Busy, Try again later
-3: System parameter not supported
-9002: Setting not allowed/authorized
-9999: Parameter Error
990x:Extended delay where x is a number 0-5 (see text below)Quoted 18 lines
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 244
Quoted 6 lines
hw/ppc/spapr_rtas.c +6
-0+ +switch (papameter) { +case DIAGNOSTICS_RUN_MODE : +if (length ==1 ) { +rtas_st (buffer,0 ,0 ); + ret =0 ;/* Success */ I assume this one is RTAS global?
Quoted 9 lines
hw/ppc/spapr_rtas.c +9
-0+ } +break ; + } + +rtas_st (rets,0 , ret); +} + +static void rtas_ibm_set_system_parameter(PowerPCCPU *cpu, + sPAPREnvironment *spapr,Quoted 8 lines
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 259
Quoted 6 lines
hw/ppc/spapr_rtas.c +6
-0+ uint32_t token, uint32_t nargs, + target_ulong args, + uint32_t nret, target_ulong rets) +{ + target_ulong papameter = rtas_ld(args, 0); +/* target_ulong buffer = rtas_ld(args, 1); */ Not addressed. Just remove this line until it gets used.
Quoted 3 lines
What is bad in having such a comment? I thought by having one return per function we help other people from the future to add functionality easier and such comment would help them too.
One return per function makes the code flow easier. It's only partly about future functionality.
I do see your point and I've usually written code the same way, until I had it rejected upstream. I'm honestly not sure which way is better. We have 3 choices here:
1) Keep it as comment
2) Add __attribute__((unused))
3) Remove the line
I like option 1 the least. But if you insist on it I won't nack the patch because of it.
Quoted 22 lines
Quoted 13 lines
hw/ppc/spapr_rtas.c static void rtas_stop_self(PowerPCCPU *cpu, sPAPREnvironment *spapr, · line 264
Quoted 7 lines
hw/ppc/spapr_rtas.c +5
-0+target_ulong ret =-3 ;/* System parameter is not supported */ + +switch (papameter) { +case DIAGNOSTICS_RUN_MODE : + ret =-9002 ;/* Setting not allowed/authorized */ -9002 seems to always mean "Not Authorized".
In fact, reading through the PAPR spec it seems as if we can easily give return values reasonable names:
Quoted 7 lines
#define
RTAS_OUT_SUCCESS0
#defineRTAS_OUT_ERROR-1
#defineRTAS_OUT_BUSY-2
#defineRTAS_OUT_NOT_SUPPORTED-3
#defineRTAS_OUT_NOMEM-5
#defineRTAS_OUT_NOT_AUTHORIZED-9002
#defineRTAS_OUT_PARAM_ERROR-9999
Quoted 4 lines
These are RTAS local, noone else really cares about them. The kernel uses numbers too (
arch/powerpc/kernel/rtas.c). Why should I replace easy understandable (look at spec -> look at gdb -> everything is clear) numbers with definitions?
For the same reason that you use -ENOINT or -EINVAL in kernel code. For the same reason that you use H_SUCCESS rather than 0 as return value for hypercalls.
In general it makes the code easier to read for people who don't have the spec in front of them.
Quoted 10 lines
Quoted 10 lines
We can't always have a 1:1 map between name and number, but at least name -> number should always be unique:
(ibm,configure-connector)
#defineRTAS_OUT_DR_CONN_UNUSABLE-9003
#defineRTAS_OUT_DR_CONN_NOT_SUPPORTED-9002
#defineRTAS_OUT_DR_SYSTEM_NOT_SUPPORTED-9001
Quoted 7 lines
Quoted 3 lines
Do you see cases where this wouldn't work out? That way we don't have to have explicit comments in the code explaining what a return value really means, making the code more easy to read.
I need to skim the whole PAPR to make sure that this is the case and then skim the guest kernel to make sure it is not broken somewhere. And I do not
Why? The guest kernel doesn't care, does it? Worst case we call a return value by a name internally to QEMU that's not appropriate.
Quoted 3 lines
see any profit from this job and it will definitely make my life harder as I really (really) want to see exact numbers in the code when I debug binary interface.
You still see them, no?
Quoted 2 lines
However you can always ignore my comments and say "do what I say" and I'll do, no big deal. Thanks.
This is review that should've happened back when the first RTAS code got in. I'm not trying to make your life hard, I'm trying to make sure we have code that's readable and maintainable by non-Alex(ey)s :).
Alex