Skip to content

Commit 35e6de3

Browse files
paulburtonralfbaechle
authored andcommitted
MIPS: traps: Ensure L1 & L2 ECC checking match for CM3 systems
On systems with CM3, we must ensure that the L1 & L2 ECC enables are set to the same value. This is presumed by the hardware & cache corruption can occur when it is not the case. Support enabling & disabling the L2 ECC checking on CM3 systems where this is controlled via a GCR, and ensure that it matches the state of L1 ECC checking. Remove I6400 from the switch statement it will no longer hit, and which was incorrect since the L2 ECC enable bit isn't in the CP0 ErrCtl register. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/14413/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent d65e567 commit 35e6de3

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

‎arch/mips/include/asm/mips-cm.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ BUILD_CM_R_(config, MIPS_CM_GCB_OFS + 0x00)
187187
BUILD_CM_RW(base, MIPS_CM_GCB_OFS + 0x08)
188188
BUILD_CM_RW(access, MIPS_CM_GCB_OFS + 0x20)
189189
BUILD_CM_R_(rev, MIPS_CM_GCB_OFS + 0x30)
190+
BUILD_CM_RW(err_control, MIPS_CM_GCB_OFS + 0x38)
190191
BUILD_CM_RW(error_mask, MIPS_CM_GCB_OFS + 0x40)
191192
BUILD_CM_RW(error_cause, MIPS_CM_GCB_OFS + 0x48)
192193
BUILD_CM_RW(error_addr, MIPS_CM_GCB_OFS + 0x50)
@@ -266,6 +267,12 @@ BUILD_CM_Cx_R_(tcid_8_priority, 0x80)
266267
#define CM_REV_CM2_5 CM_ENCODE_REV(7, 0)
267268
#define CM_REV_CM3 CM_ENCODE_REV(8, 0)
268269

270+
/* GCR_ERR_CONTROL register fields */
271+
#define CM_GCR_ERR_CONTROL_L2_ECC_EN_SHF 1
272+
#define CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK (_ULCAST_(0x1) << 1)
273+
#define CM_GCR_ERR_CONTROL_L2_ECC_SUPPORT_SHF 0
274+
#define CM_GCR_ERR_CONTROL_L2_ECC_SUPPORT_MSK (_ULCAST_(0x1) << 0)
275+
269276
/* GCR_ERROR_CAUSE register fields */
270277
#define CM_GCR_ERROR_CAUSE_ERRTYPE_SHF 27
271278
#define CM_GCR_ERROR_CAUSE_ERRTYPE_MSK (_ULCAST_(0x1f) << 27)

‎arch/mips/kernel/traps.c‎

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <asm/idle.h>
5252
#include <asm/mips-cm.h>
5353
#include <asm/mips-r2-to-r6-emul.h>
54+
#include <asm/mips-cm.h>
5455
#include <asm/mipsregs.h>
5556
#include <asm/mipsmtregs.h>
5657
#include <asm/module.h>
@@ -1644,6 +1645,65 @@ __setup("nol2par", nol2parity);
16441645
*/
16451646
static inline void parity_protection_init(void)
16461647
{
1648+
#define ERRCTL_PE 0x80000000
1649+
#define ERRCTL_L2P 0x00800000
1650+
1651+
if (mips_cm_revision() >= CM_REV_CM3) {
1652+
ulong gcr_ectl, cp0_ectl;
1653+
1654+
/*
1655+
* With CM3 systems we need to ensure that the L1 & L2
1656+
* parity enables are set to the same value, since this
1657+
* is presumed by the hardware engineers.
1658+
*
1659+
* If the user disabled either of L1 or L2 ECC checking,
1660+
* disable both.
1661+
*/
1662+
l1parity &= l2parity;
1663+
l2parity &= l1parity;
1664+
1665+
/* Probe L1 ECC support */
1666+
cp0_ectl = read_c0_ecc();
1667+
write_c0_ecc(cp0_ectl | ERRCTL_PE);
1668+
back_to_back_c0_hazard();
1669+
cp0_ectl = read_c0_ecc();
1670+
1671+
/* Probe L2 ECC support */
1672+
gcr_ectl = read_gcr_err_control();
1673+
1674+
if (!(gcr_ectl & CM_GCR_ERR_CONTROL_L2_ECC_SUPPORT_MSK) ||
1675+
!(cp0_ectl & ERRCTL_PE)) {
1676+
/*
1677+
* One of L1 or L2 ECC checking isn't supported,
1678+
* so we cannot enable either.
1679+
*/
1680+
l1parity = l2parity = 0;
1681+
}
1682+
1683+
/* Configure L1 ECC checking */
1684+
if (l1parity)
1685+
cp0_ectl |= ERRCTL_PE;
1686+
else
1687+
cp0_ectl &= ~ERRCTL_PE;
1688+
write_c0_ecc(cp0_ectl);
1689+
back_to_back_c0_hazard();
1690+
WARN_ON(!!(read_c0_ecc() & ERRCTL_PE) != l1parity);
1691+
1692+
/* Configure L2 ECC checking */
1693+
if (l2parity)
1694+
gcr_ectl |= CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
1695+
else
1696+
gcr_ectl &= ~CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
1697+
write_gcr_err_control(gcr_ectl);
1698+
gcr_ectl = read_gcr_err_control();
1699+
gcr_ectl &= CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
1700+
WARN_ON(!!gcr_ectl != l2parity);
1701+
1702+
pr_info("Cache parity protection %sabled\n",
1703+
l1parity ? "en" : "dis");
1704+
return;
1705+
}
1706+
16471707
switch (current_cpu_type()) {
16481708
case CPU_24K:
16491709
case CPU_34K:
@@ -1654,11 +1714,8 @@ static inline void parity_protection_init(void)
16541714
case CPU_PROAPTIV:
16551715
case CPU_P5600:
16561716
case CPU_QEMU_GENERIC:
1657-
case CPU_I6400:
16581717
case CPU_P6600:
16591718
{
1660-
#define ERRCTL_PE 0x80000000
1661-
#define ERRCTL_L2P 0x00800000
16621719
unsigned long errctl;
16631720
unsigned int l1parity_present, l2parity_present;
16641721

0 commit comments

Comments
 (0)