Skip to contentSkip to conversation

m68k: Add 060 PCR info to /proc/cpuinfo

PATCH In review Daniel Palmer 2 participants 6 messages Nov 19 – Nov 22 m68k architecture

lore
Share & tools
lore
#0 lore raw

cover m68k: Add 060 PCR info to /proc/cpuinfo

Apparently the rev6 060 can overclock to ~100MHz but mine seems to only manage ~60MHz (I wonder if some part of it that other OSes don't use doesn't actually like overclocking...).

I started to wonder if I actually had a rev6 and noticed you can't see this info from /proc/cpuinfo right now.

So I added it. The only messy part I think is the FPU asm changes to stop m68060.h from breaking the build.

Daniel Palmer (4):
m68k: Add and use wrapper for FPU inline asm
m68k: Add and use defines for 68060 PCR register
m68k: Add helpers to read and write the 68060's PCR
m68k: show the 68060's PCR in /proc/cpuinfo

 arch/m68k/atari/config.c       |  7 ++--
 arch/m68k/include/asm/fpu.h    |  6 ++++
 arch/m68k/include/asm/m68060.h | 34 ++++++++++++++++++
 arch/m68k/kernel/head.S        |  3 +-
 arch/m68k/kernel/process.c     | 19 +++++-----
 arch/m68k/kernel/setup_mm.c    | 23 +++++++++----
 arch/m68k/kernel/signal.c      | 63 ++++++++--------------------------
 7 files changed, 85 insertions(+), 70 deletions(-)
 create mode 100644 arch/m68k/include/asm/m68060.h
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/4 m68k: Add and use wrapper for FPU inline asm

The assembler will refuse to assemble instructions that aren't supported on the current "chip". This includes the FPU instructions.

For inline asm blocks that need to use chip specific instructions we manually set chip to the one needed to get the assembler to take the instructions and since chip propagates to all of the following inline asm blocks in the same source file we set it to generic "68k" after the instructions.

The problem with this is that in a kernel built for only the 68040 or 68060 "68k" doesn't allow for the FPU instructions. Currently if the above pattern happens earlier in the same file (maybe via an include) chip will be set to 68k and FPU instructions will fail to assemble.

FPU instructions are a bit of pain because we also need to consider coldfire. Coldfire doesn't want the same chip as classic m68k.

Add FPU_ASM() to wrap FPU instruction inline asm and do the right chip dance for classic m68k and coldfire, and use it in signal.c where the fsave/frestore were duplicated for coldfire.

---
 arch/m68k/include/asm/fpu.h |  6 ++++
 arch/m68k/kernel/process.c  | 19 ++++++-----
 arch/m68k/kernel/setup_mm.c |  2 +-
 arch/m68k/kernel/signal.c   | 63 +++++++++----------------------------
 4 files changed, 32 insertions(+), 58 deletions(-)
arch/m68k/include/asm/fpu.h +6 -0
index ab12be88d75f..5ff246444e67 100644
@@ -21,4 +21,10 @@
 #define FPSTATESIZE (0)
 #endif
 
+#ifdef CONFIG_COLDFIRE
+#define FPU_ASM(insns)	insns
+#else
+#define FPU_ASM(insns)	".chip 68k/68881\n\t" insns "\n\t.chip 68k"
+#endif
+
 #endif /* __M68K_FPU_H */
arch/m68k/kernel/process.c +11 -8
index f5a07a70e938..ef76d2aea12c 100644
@@ -34,6 +34,7 @@
 #include <linux/uaccess.h>
 #include <linux/elfcore.h>
 
+#include <asm/fpu.h>
 #include <asm/traps.h>
 #include <asm/machdep.h>
 #include <asm/setup.h>
@@ -97,7 +98,7 @@ void flush_thread(void)
 #ifdef CONFIG_FPU
 	if (!FPU_IS_EMU) {
 		unsigned long zero = 0;
-		asm volatile("frestore %0": :"m" (zero));
+		asm volatile (FPU_ASM("frestore %0") : : "m" (zero));
 	}
 #endif
 }
@@ -182,7 +183,8 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
 #ifdef CONFIG_FPU
 	if (!FPU_IS_EMU) {
 		/* Copy the current fpu state */
-		asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0]) : "memory");
+		asm volatile (FPU_ASM("fsave %0")
+			      : : "m" (p->thread.fpstate[0]) : "memory");
 
 		if (!CPU_IS_060 ? p->thread.fpstate[0] : p->thread.fpstate[2]) {
 			if (CPU_IS_COLDFIRE) {
@@ -197,8 +199,8 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
 						"m" (p->thread.fpcntl[2])
 					      : "memory");
 			} else {
-				asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
-					      "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
+				asm volatile (FPU_ASM("fmovemx %/fp0-%/fp7,%0\n\t"
+						      "fmoveml %/fpiar/%/fpcr/%/fpsr,%1")
 					      :
 					      : "m" (p->thread.fp[0]),
 						"m" (p->thread.fpcntl[0])
@@ -207,7 +209,8 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
 		}
 
 		/* Restore the state in case the fpu was busy */
-		asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
+		asm volatile (FPU_ASM("frestore %0")
+			      : : "m" (p->thread.fpstate[0]));
 	}
 #endif /* CONFIG_FPU */
 
@@ -235,7 +238,7 @@ int elf_core_copy_task_fpregs(struct task_struct *t, elf_fpregset_t *fpu)
 		char fpustate[216];
 
 		/* First dump the fpu context to avoid protocol violation.  */
-		asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
+		asm volatile (FPU_ASM("fsave %0") : : "m" (fpustate[0]) : "memory");
 		if (!CPU_IS_060 ? !fpustate[0] : !fpustate[2])
 			return 0;
 
@@ -251,11 +254,11 @@ int elf_core_copy_task_fpregs(struct task_struct *t, elf_fpregset_t *fpu)
 					"m" (fpu->fpregs[0])
 				      : "memory");
 		} else {
-			asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
+			asm volatile (FPU_ASM("fmovem %/fpiar/%/fpcr/%/fpsr,%0")
 				      :
 				      : "m" (fpu->fpcntl[0])
 				      : "memory");
-			asm volatile ("fmovemx %/fp0-%/fp7,%0"
+			asm volatile (FPU_ASM("fmovemx %/fp0-%/fp7,%0")
 				      :
 				      : "m" (fpu->fpregs[0])
 				      : "memory");
arch/m68k/kernel/setup_mm.c +1 -1
index c7e8de0d34bb..51b5881078cd 100644
@@ -223,7 +223,7 @@ void __init setup_arch(char **cmdline_p)
 	/* clear the fpu if we have one */
 	if (m68k_fputype & (FPU_68881|FPU_68882|FPU_68040|FPU_68060|FPU_COLDFIRE)) {
 		volatile int zero = 0;
-		asm volatile ("frestore %0" : : "m" (zero));
+		asm volatile (FPU_ASM("frestore %0") : : "m" (zero));
 	}
 #endif
 
arch/m68k/kernel/signal.c +14 -49

117 lines not on this page · raw message

Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/4 m68k: Add and use defines for 68060 PCR register

In reply to Daniel Palmer

Add some defines for the various bits in the 68060s PCR register and then remove the magic numbers in the places that use them.

---
 arch/m68k/include/asm/m68060.h | 15 +++++++++++++++
 arch/m68k/kernel/head.S        |  3 ++-
 arch/m68k/kernel/setup_mm.c    |  6 ++++--
 3 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 arch/m68k/include/asm/m68060.h
arch/m68k/include/asm/m68060.h new file +15 -0
new file mode 100644
index 000000000000..a69ccde11693
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_M68K_M68060_H
+#define _ASM_M68K_M68060_H
+
+/* From MC68060 User's Manual (section 3.2.2.5) */
+#define M68060_PCR_ID		0xffff0000
+#define M68060_PCR_ID_68060	0x0430
+#define M68060_PCR_ID_68LC060	0x0431		/* LC or EC */
+#define M68060_PCR_REVISION	0x0000ff00
+#define M68060_PCR_EDEBUG	0x00000080	/* internal state on idle bus cycles */
+#define M68060_PCR_I14		0x00000020	/* Reserved: errata I14 workaround */
+#define M68060_PCR_DFP		0x00000002	/* disable the FPU */
+#define M68060_PCR_ESS		0x00000001	/* enable superscalar dispatch */
+
+#endif /* _ASM_M68K_M68060_H */
arch/m68k/kernel/head.S +2 -1
index 502eeae49eaf..7d90069e9af1 100644
@@ -264,6 +264,7 @@
 #include <asm/entry.h>
 #include <asm/page.h>
 #include <asm/asm-offsets.h>
+#include <asm/m68060.h>
 #ifdef CONFIG_MAC
 #  include <asm/machw.h>
 #endif
@@ -1484,7 +1485,7 @@ L(cache68060):
 	/* MMU stuff works in copyback mode now, so enable the cache */
 	movec	%d0,%cacr
 	/* enable superscalar dispatch in PCR */
-	moveq	#1,%d0
+	moveq	#M68060_PCR_ESS,%d0
 	.chip	68060
 	movec	%d0,%pcr
 
arch/m68k/kernel/setup_mm.c +4 -2
index 51b5881078cd..7abff6266837 100644
@@ -9,6 +9,7 @@
  * This file handles the architecture-dependent parts of system setup
  */
 
+#include <linux/bitfield.h>
 #include <linux/kernel.h>
 #include <linux/cpu.h>
 #include <linux/mm.h>
@@ -35,6 +36,7 @@
 #include <asm/fpu.h>
 #include <asm/irq.h>
 #include <asm/io.h>
+#include <asm/m68060.h>
 #include <asm/machdep.h>
 #ifdef CONFIG_AMIGA
 #include <asm/amigahw.h>
@@ -232,10 +234,10 @@ void __init setup_arch(char **cmdline_p)
 
 		asm (".chip 68060; movec %%pcr,%0; .chip 68k"
 		     : "=d" (pcr));
-		if (((pcr >> 8) & 0xff) <= 5) {
+		if (FIELD_GET(M68060_PCR_REVISION, pcr) <= 5) {
 			pr_warn("Enabling workaround for errata I14\n");
 			asm (".chip 68060; movec %0,%%pcr; .chip 68k"
-			     : : "d" (pcr | 0x20));
+			     : : "d" (pcr | M68060_PCR_I14));
 		}
 	}
 
Signature · 1 line
2.55.0
#3 lore raw

PATCH 3/4 m68k: Add helpers to read and write the 68060's PCR

In reply to Daniel Palmer

We access the PCR in a few places and the next commit will add another so refactor the PCR accesses into a little helper.

---
 arch/m68k/atari/config.c       |  7 ++-----
 arch/m68k/include/asm/m68060.h | 19 +++++++++++++++++++
 arch/m68k/kernel/setup_mm.c    |  7 ++-----
 3 files changed, 23 insertions(+), 10 deletions(-)
arch/m68k/atari/config.c +2 -5
index bdafc86241b7..a63117891410 100644
@@ -47,6 +47,7 @@
 #include <asm/hwtest.h>
 #include <asm/io.h>
 #include <asm/config.h>
+#include <asm/m68060.h>
 
 #include "atari.h"
 
@@ -512,11 +513,7 @@ static void atari_reset(void)
 		unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040);
 		if (CPU_IS_060) {
 			/* 68060: clear PCR to turn off superscalar operation */
-			asm volatile ("\n"
-				"	.chip 68060\n"
-				"	movec %0,%%pcr\n"
-				"	.chip 68k"
-				: : "d" (0));
+			m68060_set_pcr(0);
 		}
 
 		asm volatile ("\n"
arch/m68k/include/asm/m68060.h +19 -0
index a69ccde11693..3d9d0f1a741f 100644
@@ -12,4 +12,23 @@
 #define M68060_PCR_DFP		0x00000002	/* disable the FPU */
 #define M68060_PCR_ESS		0x00000001	/* enable superscalar dispatch */
 
+#ifndef __ASSEMBLY__
+
+#include <linux/types.h>
+
+static inline u32 m68060_get_pcr(void)
+{
+	u32 pcr;
+
+	asm volatile (".chip 68060; movec %%pcr,%0; .chip 68k" : "=d" (pcr));
+	return pcr;
+}
+
+static inline void m68060_set_pcr(u32 pcr)
+{
+	asm volatile (".chip 68060; movec %0,%%pcr; .chip 68k" : : "d" (pcr));
+}
+
+#endif /* __ASSEMBLY__ */
+
 #endif /* _ASM_M68K_M68060_H */
arch/m68k/kernel/setup_mm.c +2 -5
index 7abff6266837..41b595256ad1 100644
@@ -230,14 +230,11 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
 	if (CPU_IS_060) {
-		u32 pcr;
+		u32 pcr = m68060_get_pcr();
 
-		asm (".chip 68060; movec %%pcr,%0; .chip 68k"
-		     : "=d" (pcr));
 		if (FIELD_GET(M68060_PCR_REVISION, pcr) <= 5) {
 			pr_warn("Enabling workaround for errata I14\n");
-			asm (".chip 68060; movec %0,%%pcr; .chip 68k"
-			     : : "d" (pcr | M68060_PCR_I14));
+			m68060_set_pcr(pcr | M68060_PCR_I14);
 		}
 	}
 
Signature · 1 line
2.55.0
#4 lore raw

PATCH 4/4 m68k: show the 68060's PCR in /proc/cpuinfo

In reply to Daniel Palmer

Add the revision information etc from the PCR to /proc/cpuinfo. This is useful to confirm the 68060 you have is actually the revision written on the chip.

My Amiga A4000 with a full 68060, revision 6 looks like this:

CPU: 68060
MMU: 68060
FPU: 68060
Clocking: 49.3MHz
BogoMips: 98.71
Calibration: 493568 loops
PCR: 0x04300601 (ID 0x0430, revision 6, superscalar)

---
 arch/m68k/kernel/setup_mm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/m68k/kernel/setup_mm.c +10 -0
index 41b595256ad1..c61c00959c54 100644
@@ -451,6 +451,16 @@ static int show_cpuinfo(struct seq_file *m, void *v)
 		   clockfreq/1000000,(clockfreq/100000)%10,
 		   loops_per_jiffy/(500000/HZ),(loops_per_jiffy/(5000/HZ))%100,
 		   loops_per_jiffy);
+	if (CPU_IS_060) {
+		u32 pcr = m68060_get_pcr();
+		u32 id = FIELD_GET(M68060_PCR_ID, pcr);
+
+		seq_printf(m, "PCR:\t\t0x%08x (ID 0x%04x%s, revision %u%s%s)\n",
+			   pcr, id, id == M68060_PCR_ID_68LC060 ? " LC/EC" : "",
+			   (unsigned int)FIELD_GET(M68060_PCR_REVISION, pcr),
+			   pcr & M68060_PCR_ESS ? ", superscalar" : "",
+			   pcr & M68060_PCR_I14 ? ", I14 workaround" : "");
+	}
 	return 0;
 }
 
Signature · 1 line
2.55.0
Tested-by on the v1 series
#5 lore raw
In reply to Daniel Palmer

Hi Daniel,

Quoted 7 lines · Daniel Palmer

Apparently the rev6 060 can overclock to ~100MHz but mine seems to only manage ~60MHz (I wonder if some part of it that other OSes don't use doesn't actually like overclocking...).

I started to wonder if I actually had a rev6 and noticed you can't see this info from /proc/cpuinfo right now.

Tested on v7.4-rc3 plus this series, with a multi-platform config and with a 060-only one. Both kernels build without warnings, boot to userspace and run fine.

# cat /proc/cpuinfo
CPU:            68060
MMU:            68060
FPU:            68882
Clocking:       49.1MHz
BogoMips:       98.20
Calibration:    491008 loops
PCR:            0x04300601 (ID 0x0430, revision 6, superscalar)
Signature · 2 lines
bye,
p.