Skip to content

Commit 93adeaf

Browse files
Maciej W. Rozyckiralfbaechle
authored andcommitted
MIPS: Determine the presence of IEEE Std 754-2008 features
Determine the presence of and the amount of control available over IEEE Std 754-2008 features. In the case of a hardware FPU being used examine the FIR register for the presence of the HAS2008 bit and then the FCSR register for the writability of the ABS2008 and NAN2008 bits and the hardwired state of each of these bits if read-only. Update the initial FCSR contents used for threads and the FCSR writability mask accordingly. For full FPU emulation and MIPS32 or MIPS64 processors make the FCSR ABS2008 and NAN2008 bits writable. Signed-off-by: Maciej W. Rozycki <macro@imgtec.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Matthew Fortune <Matthew.Fortune@imgtec.com> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/11480/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 2b5e869 commit 93adeaf

1 file changed

Lines changed: 74 additions & 2 deletions

File tree

‎arch/mips/kernel/cpu-probe.c‎

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,78 @@ static inline void cpu_set_fpu_fcsr_mask(struct cpuinfo_mips *c)
9898
c->fpu_msk31 = ~(fcsr0 ^ fcsr1) & ~mask;
9999
}
100100

101+
/*
102+
* Determine the IEEE 754 NaN encodings and ABS.fmt/NEG.fmt execution modes
103+
* supported by FPU hardware.
104+
*/
105+
static void cpu_set_fpu_2008(struct cpuinfo_mips *c)
106+
{
107+
if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
108+
MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
109+
MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6)) {
110+
unsigned long sr, fir, fcsr, fcsr0, fcsr1;
111+
112+
sr = read_c0_status();
113+
__enable_fpu(FPU_AS_IS);
114+
115+
fir = read_32bit_cp1_register(CP1_REVISION);
116+
if (fir & MIPS_FPIR_HAS2008) {
117+
fcsr = read_32bit_cp1_register(CP1_STATUS);
118+
119+
fcsr0 = fcsr & ~(FPU_CSR_ABS2008 | FPU_CSR_NAN2008);
120+
write_32bit_cp1_register(CP1_STATUS, fcsr0);
121+
fcsr0 = read_32bit_cp1_register(CP1_STATUS);
122+
123+
fcsr1 = fcsr | FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
124+
write_32bit_cp1_register(CP1_STATUS, fcsr1);
125+
fcsr1 = read_32bit_cp1_register(CP1_STATUS);
126+
127+
write_32bit_cp1_register(CP1_STATUS, fcsr);
128+
129+
if (!(fcsr0 & FPU_CSR_NAN2008))
130+
c->options |= MIPS_CPU_NAN_LEGACY;
131+
if (fcsr1 & FPU_CSR_NAN2008)
132+
c->options |= MIPS_CPU_NAN_2008;
133+
134+
if ((fcsr0 ^ fcsr1) & FPU_CSR_ABS2008)
135+
c->fpu_msk31 &= ~FPU_CSR_ABS2008;
136+
else
137+
c->fpu_csr31 |= fcsr & FPU_CSR_ABS2008;
138+
139+
if ((fcsr0 ^ fcsr1) & FPU_CSR_NAN2008)
140+
c->fpu_msk31 &= ~FPU_CSR_NAN2008;
141+
else
142+
c->fpu_csr31 |= fcsr & FPU_CSR_NAN2008;
143+
} else {
144+
c->options |= MIPS_CPU_NAN_LEGACY;
145+
}
146+
147+
write_c0_status(sr);
148+
} else {
149+
c->options |= MIPS_CPU_NAN_LEGACY;
150+
}
151+
}
152+
153+
/*
154+
* Set the IEEE 754 NaN encodings and ABS.fmt/NEG.fmt execution modes
155+
* for the FPU emulator. Clear the flags where required in case called
156+
* from `fpu_disable', to override details obtained from FPU hardware.
157+
*/
158+
static void cpu_set_nofpu_2008(struct cpuinfo_mips *c)
159+
{
160+
c->fpu_csr31 &= ~(FPU_CSR_ABS2008 | FPU_CSR_NAN2008);
161+
if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
162+
MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
163+
MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6)) {
164+
c->options |= MIPS_CPU_NAN_2008 | MIPS_CPU_NAN_LEGACY;
165+
c->fpu_msk31 &= ~(FPU_CSR_ABS2008 | FPU_CSR_NAN2008);
166+
} else {
167+
c->options &= ~MIPS_CPU_NAN_2008;
168+
c->options |= MIPS_CPU_NAN_LEGACY;
169+
c->fpu_msk31 |= FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
170+
}
171+
}
172+
101173
/*
102174
* Set the FIR feature flags for the FPU emulator.
103175
*/
@@ -139,7 +211,7 @@ static void cpu_set_fpu_opts(struct cpuinfo_mips *c)
139211
}
140212

141213
cpu_set_fpu_fcsr_mask(c);
142-
c->options |= MIPS_CPU_NAN_LEGACY;
214+
cpu_set_fpu_2008(c);
143215
}
144216

145217
/*
@@ -150,7 +222,7 @@ static void cpu_set_nofpu_opts(struct cpuinfo_mips *c)
150222
c->options &= ~MIPS_CPU_FPU;
151223
c->fpu_msk31 = mips_nofpu_msk31;
152224

153-
c->options |= MIPS_CPU_NAN_LEGACY;
225+
cpu_set_nofpu_2008(c);
154226
cpu_set_nofpu_id(c);
155227
}
156228

0 commit comments

Comments
 (0)