* [Qemu-devel] [PATCH] ppc: Improve emulation of THRM registers
[not found] <mailman.8327.1466309535.1213.qemu-devel@nongnu.org>
@ 2016-06-19 15:09 ` G 3
2016-06-19 21:11 ` Benjamin Herrenschmidt
2016-06-19 22:10 ` Programmingkid
1 sibling, 1 reply; 4+ messages in thread
From: G 3 @ 2016-06-19 15:09 UTC (permalink / raw)
To: qemu-devel, benh
On 6/19/16 12:12 AM, qemu-devel-request@nongnu.org wrote:
> Message: 5
> Date: Sun, 19 Jun 2016 10:54:13 +1000
> From: Benjamin Herrenschmidt<benh@kernel.crashing.org>
> To:qemu-ppc@nongnu.org
> Cc:qemu-devel@nongnu.org,david@gibson.dropbear.id.au, Mark
> Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Alexander Graf
> <agraf@suse.de>
> Subject: [Qemu-devel] [PATCH] ppc: Improve emulation of THRM registers
> Message-ID:<1466297653.24271.101.camel@kernel.crashing.org>
> Content-Type: text/plain; charset="UTF-8"
>
> The 75x and 74xx processors have some thermal monitoring SPRs that
> some OSes such as MacOS do use. Our current "dumb" implementation
> isn't good enough and will cause some versions of MacOS to hang during
> boot.
>
> This lifts an improved emulation from MacOnLinux and adapts it to
> qemu, thus fixing the problem.
>
Which versions of the Mac OS hang?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] ppc: Improve emulation of THRM registers
2016-06-19 15:09 ` [Qemu-devel] [PATCH] ppc: Improve emulation of THRM registers G 3
@ 2016-06-19 21:11 ` Benjamin Herrenschmidt
0 siblings, 0 replies; 4+ messages in thread
From: Benjamin Herrenschmidt @ 2016-06-19 21:11 UTC (permalink / raw)
To: G 3, qemu-devel
On Sun, 2016-06-19 at 11:09 -0400, G 3 wrote:
> On 6/19/16 12:12 AM, qemu-devel-request@nongnu.org wrote:
> > Message: 5
> > Date: Sun, 19 Jun 2016 10:54:13 +1000
> > From: Benjamin Herrenschmidt<benh@kernel.crashing.org>
> > To:qemu-ppc@nongnu.org
> > Cc:qemu-devel@nongnu.org,david@gibson.dropbear.id.au, Mark
> > Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Alexander
> > Graf
> > <agraf@suse.de>
> > Subject: [Qemu-devel] [PATCH] ppc: Improve emulation of THRM
> > registers
> > Message-ID:<1466297653.24271.101.camel@kernel.crashing.org>
> > Content-Type: text/plain; charset="UTF-8"
> >
> > The 75x and 74xx processors have some thermal monitoring SPRs that
> > some OSes such as MacOS do use. Our current "dumb" implementation
> > isn't good enough and will cause some versions of MacOS to hang
> > during
> > boot.
> >
> > This lifts an improved emulation from MacOnLinux and adapts it to
> > qemu, thus fixing the problem.
> >
> Which versions of the Mac OS hang?
The Apple CPU Plugin in 9.2.x afaik (well 9.2.2 for sure).
Cheers,
Ben.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH] ppc: Improve emulation of THRM registers
[not found] <mailman.8327.1466309535.1213.qemu-devel@nongnu.org>
2016-06-19 15:09 ` [Qemu-devel] [PATCH] ppc: Improve emulation of THRM registers G 3
@ 2016-06-19 22:10 ` Programmingkid
1 sibling, 0 replies; 4+ messages in thread
From: Programmingkid @ 2016-06-19 22:10 UTC (permalink / raw)
To: qemu-devel
On Jun 19, 2016, at 12:12 AM, qemu-devel-request@nongnu.org wrote:
> Message: 5
> Date: Sun, 19 Jun 2016 10:54:13 +1000
> From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> To: qemu-ppc@nongnu.org
> Cc: qemu-devel@nongnu.org, david@gibson.dropbear.id.au, Mark
> Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Alexander Graf
> <agraf@suse.de>
> Subject: [Qemu-devel] [PATCH] ppc: Improve emulation of THRM registers
> Message-ID: <1466297653.24271.101.camel@kernel.crashing.org>
> Content-Type: text/plain; charset="UTF-8"
>
> The 75x and 74xx processors have some thermal monitoring SPRs that
> some OSes such as MacOS do use. Our current "dumb" implementation
> isn't good enough and will cause some versions of MacOS to hang during
> boot.
>
> This lifts an improved emulation from MacOnLinux and adapts it to
> qemu, thus fixing the problem.
>
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
> target-ppc/helper.h | 1 +
> target-ppc/misc_helper.c | 41 +++++++++++++++++++++++++++++++++++++++++
> target-ppc/translate_init.c | 13 ++++++++++---
> 3 files changed, 52 insertions(+), 3 deletions(-)
>
> diff --git a/target-ppc/helper.h b/target-ppc/helper.h
> index f4410a8..18eb52f 100644
> --- a/target-ppc/helper.h
> +++ b/target-ppc/helper.h
> @@ -670,3 +670,4 @@ DEF_HELPER_4(dscli, void, env, fprp, fprp, i32)
> DEF_HELPER_4(dscliq, void, env, fprp, fprp, i32)
>
> DEF_HELPER_1(tbegin, void, env)
> +DEF_HELPER_1(fixup_thrm, void, env)
> diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c
> index 7d41b01..4315778 100644
> --- a/target-ppc/misc_helper.c
> +++ b/target-ppc/misc_helper.c
> @@ -166,3 +166,44 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value)
> {
> hreg_store_msr(env, value, 0);
> }
> +
> +/* This code is lifted from MacOnLinux. It is called whenever
> + * THRM1,2 or 3 is read an fixes up the values in such a way
> + * that will mac MacOS not hang. These registers exist on some
> + * 75x and 74xx processors.
> + */
> +void helper_fixup_thrm(CPUPPCState *env)
> +{
> + target_ulong v, t;
> + int i;
> +
> +#define THRM1_TIN (1 << 31)
> +#define THRM1_TIV (1 << 30)
> +#define THRM1_THRES(x) ((x&0x7f)<<23)
> +#define THRM1_TID (1<<2)
> +#define THRM1_TIE (1<<1)
> +#define THRM1_V (1<<0)
> +#define THRM3_E (1<<0)
> +
> + if(!(env->spr[SPR_THRM3] & THRM3_E)) {
> + return;
> + }
> +
> + /* Note: Thermal interrupts are unimplemented */
> + for (i=SPR_THRM1 ; i<= SPR_THRM2 ; i++) {
> + v = env->spr[i];
> + if (!(v & THRM1_V)) {
> + continue;
> + }
> + v |= THRM1_TIV;
> + v &= ~THRM1_TIN;
> + t = v & THRM1_THRES(127);
> + if ((v & THRM1_TID) && t < THRM1_THRES(24)) {
> + v |= THRM1_TIN;
> + }
> + if (!(v & THRM1_TID) && t > THRM1_THRES(24)) {
> + v |= THRM1_TIN;
> + }
> + env->spr[i] = v;
> + }
> +}
> diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
> index ca894ff..0f18abf 100644
> --- a/target-ppc/translate_init.c
> +++ b/target-ppc/translate_init.c
> @@ -1179,23 +1179,30 @@ static void gen_spr_amr(CPUPPCState *env, bool has_iamr)
> }
> #endif /* TARGET_PPC64 */
>
> +static void spr_read_thrm(DisasContext *ctx, int gprn, int sprn)
> +{
> + gen_helper_fixup_thrm(cpu_env);
> + gen_load_spr(cpu_gpr[gprn], sprn);
> + spr_load_dump_spr(sprn);
> +}
> +
> static void gen_spr_thrm (CPUPPCState *env)
> {
> /* Thermal management */
> /* XXX : not implemented */
> spr_register(env, SPR_THRM1, "THRM1",
> SPR_NOACCESS, SPR_NOACCESS,
> - &spr_read_generic, &spr_write_generic,
> + &spr_read_thrm, &spr_write_generic,
> 0x00000000);
> /* XXX : not implemented */
> spr_register(env, SPR_THRM2, "THRM2",
> SPR_NOACCESS, SPR_NOACCESS,
> - &spr_read_generic, &spr_write_generic,
> + &spr_read_thrm, &spr_write_generic,
> 0x00000000);
> /* XXX : not implemented */
> spr_register(env, SPR_THRM3, "THRM3",
> SPR_NOACCESS, SPR_NOACCESS,
> - &spr_read_generic, &spr_write_generic,
> + &spr_read_thrm, &spr_write_generic,
> 0x00000000);
> }
>
I have test this patch using Mac OS 10.2.8, Mac OS 10.4.0, and Mac OS 9.2.2. They all worked. Mac OS 9.2.2 successfully booted with the multiprocessing folder in the Extensions folder.
Excellent job.
Reviewed-by: John Arbuckle <programmingkidx@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH] ppc: Improve emulation of THRM registers
@ 2016-06-19 0:54 Benjamin Herrenschmidt
0 siblings, 0 replies; 4+ messages in thread
From: Benjamin Herrenschmidt @ 2016-06-19 0:54 UTC (permalink / raw)
To: qemu-ppc; +Cc: qemu-devel, david, Mark Cave-Ayland, Alexander Graf
The 75x and 74xx processors have some thermal monitoring SPRs that
some OSes such as MacOS do use. Our current "dumb" implementation
isn't good enough and will cause some versions of MacOS to hang during
boot.
This lifts an improved emulation from MacOnLinux and adapts it to
qemu, thus fixing the problem.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
target-ppc/helper.h | 1 +
target-ppc/misc_helper.c | 41 +++++++++++++++++++++++++++++++++++++++++
target-ppc/translate_init.c | 13 ++++++++++---
3 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/target-ppc/helper.h b/target-ppc/helper.h
index f4410a8..18eb52f 100644
--- a/target-ppc/helper.h
+++ b/target-ppc/helper.h
@@ -670,3 +670,4 @@ DEF_HELPER_4(dscli, void, env, fprp, fprp, i32)
DEF_HELPER_4(dscliq, void, env, fprp, fprp, i32)
DEF_HELPER_1(tbegin, void, env)
+DEF_HELPER_1(fixup_thrm, void, env)
diff --git a/target-ppc/misc_helper.c b/target-ppc/misc_helper.c
index 7d41b01..4315778 100644
--- a/target-ppc/misc_helper.c
+++ b/target-ppc/misc_helper.c
@@ -166,3 +166,44 @@ void ppc_store_msr(CPUPPCState *env, target_ulong value)
{
hreg_store_msr(env, value, 0);
}
+
+/* This code is lifted from MacOnLinux. It is called whenever
+ * THRM1,2 or 3 is read an fixes up the values in such a way
+ * that will mac MacOS not hang. These registers exist on some
+ * 75x and 74xx processors.
+ */
+void helper_fixup_thrm(CPUPPCState *env)
+{
+ target_ulong v, t;
+ int i;
+
+#define THRM1_TIN (1 << 31)
+#define THRM1_TIV (1 << 30)
+#define THRM1_THRES(x) ((x&0x7f)<<23)
+#define THRM1_TID (1<<2)
+#define THRM1_TIE (1<<1)
+#define THRM1_V (1<<0)
+#define THRM3_E (1<<0)
+
+ if(!(env->spr[SPR_THRM3] & THRM3_E)) {
+ return;
+ }
+
+ /* Note: Thermal interrupts are unimplemented */
+ for (i=SPR_THRM1 ; i<= SPR_THRM2 ; i++) {
+ v = env->spr[i];
+ if (!(v & THRM1_V)) {
+ continue;
+ }
+ v |= THRM1_TIV;
+ v &= ~THRM1_TIN;
+ t = v & THRM1_THRES(127);
+ if ((v & THRM1_TID) && t < THRM1_THRES(24)) {
+ v |= THRM1_TIN;
+ }
+ if (!(v & THRM1_TID) && t > THRM1_THRES(24)) {
+ v |= THRM1_TIN;
+ }
+ env->spr[i] = v;
+ }
+}
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index ca894ff..0f18abf 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -1179,23 +1179,30 @@ static void gen_spr_amr(CPUPPCState *env, bool has_iamr)
}
#endif /* TARGET_PPC64 */
+static void spr_read_thrm(DisasContext *ctx, int gprn, int sprn)
+{
+ gen_helper_fixup_thrm(cpu_env);
+ gen_load_spr(cpu_gpr[gprn], sprn);
+ spr_load_dump_spr(sprn);
+}
+
static void gen_spr_thrm (CPUPPCState *env)
{
/* Thermal management */
/* XXX : not implemented */
spr_register(env, SPR_THRM1, "THRM1",
SPR_NOACCESS, SPR_NOACCESS,
- &spr_read_generic, &spr_write_generic,
+ &spr_read_thrm, &spr_write_generic,
0x00000000);
/* XXX : not implemented */
spr_register(env, SPR_THRM2, "THRM2",
SPR_NOACCESS, SPR_NOACCESS,
- &spr_read_generic, &spr_write_generic,
+ &spr_read_thrm, &spr_write_generic,
0x00000000);
/* XXX : not implemented */
spr_register(env, SPR_THRM3, "THRM3",
SPR_NOACCESS, SPR_NOACCESS,
- &spr_read_generic, &spr_write_generic,
+ &spr_read_thrm, &spr_write_generic,
0x00000000);
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-06-19 22:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.8327.1466309535.1213.qemu-devel@nongnu.org>
2016-06-19 15:09 ` [Qemu-devel] [PATCH] ppc: Improve emulation of THRM registers G 3
2016-06-19 21:11 ` Benjamin Herrenschmidt
2016-06-19 22:10 ` Programmingkid
2016-06-19 0:54 Benjamin Herrenschmidt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).