target/ppc: Refactor sleep and its variants to use a common helper
With sleep, doze, nap, rvwinkle and stop instructions moved to decodetree, the helper these instructions used : gen_helper_pminsn, should now be renamed to gen_helper_PMINSN, abiding by the decodetree standards. Do the same. Also refactor their translation routine to use a common do_sleep routine since they share majority of the code. Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Reviewed-by: Glenn Miles <milesg@linux.ibm.com> Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com> Signed-off-by: Chinmay Rath <rathc@linux.ibm.com> Tested-by: Aniket Sahu <asahu1x@linux.ibm.com> Link: https://lore.kernel.org/qemu-devel/20260827133010.278889-20-rathc@linux.ibm.com Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Ojaswin Mujoo committed
Aug 27, 2026 at 18:59 UTC
f2a6c83d41e2fef28a0905c2ea8c57df1e0d66aa
3 files changed
+17
-86
target/ppc/helper.h
+1
-1
@@ -18,7 +18,7 @@ DEF_HELPER_1(rfdi, void, env)
18
DEF_HELPER_1(rfmci, void, env)
19
#if defined(TARGET_PPC64)
20
DEF_HELPER_2(scv, noreturn, env, i32)
21
-DEF_HELPER_2(pminsn, void, env, i32)
21
+DEF_HELPER_2(PMINSN, void, env, i32)
22
DEF_HELPER_1(rfid, void, env)
23
DEF_HELPER_1(rfscv, void, env)
24
DEF_HELPER_1(hrfid, void, env)
target/ppc/tcg-excp_helper.c
+1
-1
@@ -459,7 +459,7 @@ void helper_scv(CPUPPCState *env, uint32_t lev)
459
}
460
}
461
462
-void helper_pminsn(CPUPPCState *env, uint32_t insn)
462
+void helper_PMINSN(CPUPPCState *env, uint32_t insn)
463
{
464
CPUState *cs = env_cpu(env);
465
target/ppc/translate/processor-ctrl-impl.c.inc
+15
-84
@@ -104,102 +104,33 @@ static bool trans_MSGSYNC(DisasContext *ctx, arg_MSGSYNC *a)
104
return true;
105
}
106
107
-static bool do_doze(DisasContext *ctx, arg_DOZE *a)
108
-{
109
- REQUIRE_64BIT(ctx);
110
-
111
-#if defined(CONFIG_USER_ONLY)
112
- gen_priv_opc(ctx);
113
-#else
114
- TCGv_i32 t;
115
-
116
- REQUIRE_HV(ctx);
117
- translator_io_start(&ctx->base);
118
- t = tcg_constant_i32(PPC_PM_DOZE);
119
- gen_helper_pminsn(tcg_env, t);
120
- /* Stop translation, as the CPU is supposed to sleep from now */
121
- gen_exception_nip(ctx, EXCP_HLT, ctx->base.pc_next);
122
-#endif /* defined(CONFIG_USER_ONLY) */
123
- return true;
124
-}
125
-TRANS_FLAGS2(PM_ISA206, DOZE, do_doze);
126
-
127
-static bool do_nap(DisasContext *ctx, arg_NAP *a)
107
+/*
108
+ * Helper to handle DOZE, NAP, SLEEP, RVWINKLE & STOP. Since none of them use
109
+ * any arguments just use a placeholder arg_SLEEP.
110
+ */
111
+static bool do_sleep(DisasContext *ctx, arg_SLEEP *a, powerpc_pm_insn_t type)
112
{
113
REQUIRE_64BIT(ctx);
114
115
#if defined(CONFIG_USER_ONLY)
116
gen_priv_opc(ctx);
133
-#else
117
+#elif defined(TARGET_PPC64)
118
TCGv_i32 t;
119
120
REQUIRE_HV(ctx);
121
translator_io_start(&ctx->base);
138
- t = tcg_constant_i32(PPC_PM_NAP);
139
- gen_helper_pminsn(tcg_env, t);
122
+ t = tcg_constant_i32(type);
123
+ gen_helper_PMINSN(tcg_env, t);
124
/* Stop translation, as the CPU is supposed to sleep from now */
125
gen_exception_nip(ctx, EXCP_HLT, ctx->base.pc_next);
142
-#endif /* defined(CONFIG_USER_ONLY) */
143
- return true;
144
-}
145
-TRANS_FLAGS2(PM_ISA206, NAP, do_nap);
146
-
147
-static bool do_sleep(DisasContext *ctx, arg_SLEEP *a)
148
-{
149
- REQUIRE_64BIT(ctx);
150
-
151
-#if defined(CONFIG_USER_ONLY)
152
- gen_priv_opc(ctx);
126
#else
154
- TCGv_i32 t;
155
-
156
- REQUIRE_HV(ctx);
157
- translator_io_start(&ctx->base);
158
- t = tcg_constant_i32(PPC_PM_SLEEP);
159
- gen_helper_pminsn(tcg_env, t);
160
- /* Stop translation, as the CPU is supposed to sleep from now */
161
- gen_exception_nip(ctx, EXCP_HLT, ctx->base.pc_next);
162
-#endif /* defined(CONFIG_USER_ONLY) */
163
- return true;
164
-}
165
-TRANS_FLAGS2(PM_ISA206, SLEEP, do_sleep);
166
-
167
-static bool do_rvwinkle(DisasContext *ctx, arg_RVWINKLE *a)
168
-{
169
- REQUIRE_64BIT(ctx);
170
-
171
-#if defined(CONFIG_USER_ONLY)
172
- gen_priv_opc(ctx);
173
-#else
174
- TCGv_i32 t;
175
-
176
- REQUIRE_HV(ctx);
177
- translator_io_start(&ctx->base);
178
- t = tcg_constant_i32(PPC_PM_RVWINKLE);
179
- gen_helper_pminsn(tcg_env, t);
180
- /* Stop translation, as the CPU is supposed to sleep from now */
181
- gen_exception_nip(ctx, EXCP_HLT, ctx->base.pc_next);
182
-#endif /* defined(CONFIG_USER_ONLY) */
127
+ qemu_build_not_reached();
128
+#endif
129
return true;
130
}
185
-TRANS_FLAGS2(PM_ISA206, RVWINKLE, do_rvwinkle);
186
-
187
-static bool do_stop(DisasContext *ctx, arg_STOP *a)
188
-{
189
- REQUIRE_64BIT(ctx);
131
191
-#if defined(CONFIG_USER_ONLY)
192
- gen_priv_opc(ctx);
193
-#else
194
- TCGv_i32 t;
195
-
196
- REQUIRE_HV(ctx);
197
- translator_io_start(&ctx->base);
198
- t = tcg_constant_i32(PPC_PM_STOP);
199
- gen_helper_pminsn(tcg_env, t);
200
- /* Stop translation, as the CPU is supposed to sleep from now */
201
- gen_exception_nip(ctx, EXCP_HLT, ctx->base.pc_next);
202
-#endif /* defined(CONFIG_USER_ONLY) */
203
- return true;
204
-}
205
-TRANS_FLAGS2(ISA300, STOP, do_stop);
132
+TRANS_FLAGS2(PM_ISA206, DOZE, do_sleep, PPC_PM_DOZE);
133
+TRANS_FLAGS2(PM_ISA206, NAP, do_sleep, PPC_PM_NAP);
134
+TRANS_FLAGS2(PM_ISA206, SLEEP, do_sleep, PPC_PM_SLEEP);
135
+TRANS_FLAGS2(PM_ISA206, RVWINKLE, do_sleep, PPC_PM_RVWINKLE);
136
+TRANS_FLAGS2(ISA300, STOP, do_sleep, PPC_PM_STOP);