diff mbox series

[v2] MIPS: Limit check_bugs32() to affected platform

Message ID 1586488859-18715-1-git-send-email-yangtiezhu@loongson.cn (mailing list archive)
State Rejected
Headers show
Series [v2] MIPS: Limit check_bugs32() to affected platform | expand

Commit Message

Tiezhu Yang April 10, 2020, 3:20 a.m. UTC
In the current code, check_bugs32() only handles MIPS32 CPU type CPU_34K,
it is better to build and call it on the affected platform.

Move check_bugs32() to the new added 34k-bugs32.c to indicate the fact that
the code is specific to the 34k CPU, and also add CONFIG_CPU_34K_BUGS32 to
control whether or not check the bugs.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---

v2:
  - Add new 34k-bugs32.c
  - Rename check_errata() to check_errata32()
  - Add CONFIG_CPU_34K_BUGS32
  - Modify commit message

 arch/mips/Kconfig             |  4 ++++
 arch/mips/include/asm/bugs.h  |  4 +++-
 arch/mips/kernel/34k-bugs32.c | 29 +++++++++++++++++++++++++++++
 arch/mips/kernel/Makefile     |  1 +
 arch/mips/kernel/cpu-probe.c  | 25 -------------------------
 5 files changed, 37 insertions(+), 26 deletions(-)
 create mode 100644 arch/mips/kernel/34k-bugs32.c

Comments

Jiaxun Yang April 10, 2020, 4:18 a.m. UTC | #1
On Fri, 10 Apr 2020 11:20:59 +0800
Tiezhu Yang <yangtiezhu@loongson.cn> wrote:

> In the current code, check_bugs32() only handles MIPS32 CPU type
> CPU_34K, it is better to build and call it on the affected platform.
> 
> Move check_bugs32() to the new added 34k-bugs32.c to indicate the
> fact that the code is specific to the 34k CPU, and also add
> CONFIG_CPU_34K_BUGS32 to control whether or not check the bugs.

Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

+Maciej, that's basically my intention.

Thanks.

> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
> 
> v2:
>   - Add new 34k-bugs32.c
>   - Rename check_errata() to check_errata32()
>   - Add CONFIG_CPU_34K_BUGS32
>   - Modify commit message
> 
>  arch/mips/Kconfig             |  4 ++++
>  arch/mips/include/asm/bugs.h  |  4 +++-
>  arch/mips/kernel/34k-bugs32.c | 29 +++++++++++++++++++++++++++++
>  arch/mips/kernel/Makefile     |  1 +
>  arch/mips/kernel/cpu-probe.c  | 25 -------------------------
>  5 files changed, 37 insertions(+), 26 deletions(-)
>  create mode 100644 arch/mips/kernel/34k-bugs32.c
> 
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index a1f973c..d95dc18 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -2619,6 +2619,10 @@ config CPU_R4X00_BUGS64
>  	bool
>  	default y if SYS_HAS_CPU_R4X00 && 64BIT && (TARGET_ISA_REV <
> 1) 
> +config CPU_34K_BUGS32
> +	bool
> +	default y if CPU_MIPS32_R2
> +
>  config MIPS_ASID_SHIFT
>  	int
>  	default 6 if CPU_R3000 || CPU_TX39XX
> diff --git a/arch/mips/include/asm/bugs.h
> b/arch/mips/include/asm/bugs.h index d72dc6e..bbf843a 100644
> --- a/arch/mips/include/asm/bugs.h
> +++ b/arch/mips/include/asm/bugs.h
> @@ -35,7 +35,9 @@ static inline void check_bugs(void)
>  	unsigned int cpu = smp_processor_id();
>  
>  	cpu_data[cpu].udelay_val = loops_per_jiffy;
> -	check_bugs32();
> +
> +	if (IS_ENABLED(CONFIG_CPU_34K_BUGS32))
> +		check_bugs32();
>  
>  	if (IS_ENABLED(CONFIG_CPU_R4X00_BUGS64))
>  		check_bugs64();
> diff --git a/arch/mips/kernel/34k-bugs32.c
> b/arch/mips/kernel/34k-bugs32.c new file mode 100644
> index 0000000..dc3ac01
> --- /dev/null
> +++ b/arch/mips/kernel/34k-bugs32.c
> @@ -0,0 +1,29 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <asm/cpu.h>
> +#include <asm/cpu-info.h>
> +#include <asm/cpu-type.h>
> +#include <asm/bugs.h>
> +
> +static inline void check_errata32(void)
> +{
> +	struct cpuinfo_mips *c = &current_cpu_data;
> +
> +	switch (current_cpu_type()) {
> +	case CPU_34K:
> +		/*
> +		 * Erratum "RPS May Cause Incorrect Instruction
> Execution"
> +		 * This code only handles VPE0, any SMP/RTOS code
> +		 * making use of VPE1 will be responsable for that
> VPE.
> +		 */
> +		if ((c->processor_id & PRID_REV_MASK) <=
> PRID_REV_34K_V1_0_2)
> +			write_c0_config7(read_c0_config7() |
> MIPS_CONF7_RPS);
> +		break;
> +	default:
> +		break;
> +	}
> +}
> +
> +void __init check_bugs32(void)
> +{
> +	check_errata32();
> +}
> diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
> index d6e97df..c2fd191 100644
> --- a/arch/mips/kernel/Makefile
> +++ b/arch/mips/kernel/Makefile
> @@ -81,6 +81,7 @@ obj-$(CONFIG_PROC_FS)		+= proc.o
>  obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
>  
>  obj-$(CONFIG_CPU_R4X00_BUGS64)	+= r4k-bugs64.o
> +obj-$(CONFIG_CPU_34K_BUGS32)	+= 34k-bugs32.o
>  
>  obj-$(CONFIG_I8253)		+= i8253.o
>  
> diff --git a/arch/mips/kernel/cpu-probe.c
> b/arch/mips/kernel/cpu-probe.c index f21a230..7179787 100644
> --- a/arch/mips/kernel/cpu-probe.c
> +++ b/arch/mips/kernel/cpu-probe.c
> @@ -14,7 +14,6 @@
>  #include <linux/stddef.h>
>  #include <linux/export.h>
>  
> -#include <asm/bugs.h>
>  #include <asm/cpu.h>
>  #include <asm/cpu-features.h>
>  #include <asm/cpu-type.h>
> @@ -461,30 +460,6 @@ static inline void cpu_set_mt_per_tc_perf(struct
> cpuinfo_mips *c) c->options |= MIPS_CPU_MT_PER_TC_PERF_COUNTERS;
>  }
>  
> -static inline void check_errata(void)
> -{
> -	struct cpuinfo_mips *c = &current_cpu_data;
> -
> -	switch (current_cpu_type()) {
> -	case CPU_34K:
> -		/*
> -		 * Erratum "RPS May Cause Incorrect Instruction
> Execution"
> -		 * This code only handles VPE0, any SMP/RTOS code
> -		 * making use of VPE1 will be responsable for that
> VPE.
> -		 */
> -		if ((c->processor_id & PRID_REV_MASK) <=
> PRID_REV_34K_V1_0_2)
> -			write_c0_config7(read_c0_config7() |
> MIPS_CONF7_RPS);
> -		break;
> -	default:
> -		break;
> -	}
> -}
> -
> -void __init check_bugs32(void)
> -{
> -	check_errata();
> -}
> -
>  /*
>   * Probe whether cpu has config register by trying to play with
>   * alternate cache bit and see whether it matters.
Jiaxun Yang April 10, 2020, 8:36 a.m. UTC | #2
On Fri, 10 Apr 2020 11:20:59 +0800
Tiezhu Yang <yangtiezhu@loongson.cn> wrote:

> In the current code, check_bugs32() only handles MIPS32 CPU type
> CPU_34K, it is better to build and call it on the affected platform.
> 
> Move check_bugs32() to the new added 34k-bugs32.c to indicate the
> fact that the code is specific to the 34k CPU, and also add
> CONFIG_CPU_34K_BUGS32 to control whether or not check the bugs.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

+Maciej, that's basically what I want.

Thanks.

> ---
> 
> v2:
>   - Add new 34k-bugs32.c
>   - Rename check_errata() to check_errata32()
>   - Add CONFIG_CPU_34K_BUGS32
>   - Modify commit message
> 
>  arch/mips/Kconfig             |  4 ++++
>  arch/mips/include/asm/bugs.h  |  4 +++-
>  arch/mips/kernel/34k-bugs32.c | 29 +++++++++++++++++++++++++++++
>  arch/mips/kernel/Makefile     |  1 +
>  arch/mips/kernel/cpu-probe.c  | 25 -------------------------
>  5 files changed, 37 insertions(+), 26 deletions(-)
>  create mode 100644 arch/mips/kernel/34k-bugs32.c
> 
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index a1f973c..d95dc18 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -2619,6 +2619,10 @@ config CPU_R4X00_BUGS64
>  	bool
>  	default y if SYS_HAS_CPU_R4X00 && 64BIT && (TARGET_ISA_REV <
> 1) 
> +config CPU_34K_BUGS32
> +	bool
> +	default y if CPU_MIPS32_R2
> +
>  config MIPS_ASID_SHIFT
>  	int
>  	default 6 if CPU_R3000 || CPU_TX39XX
> diff --git a/arch/mips/include/asm/bugs.h
> b/arch/mips/include/asm/bugs.h index d72dc6e..bbf843a 100644
> --- a/arch/mips/include/asm/bugs.h
> +++ b/arch/mips/include/asm/bugs.h
> @@ -35,7 +35,9 @@ static inline void check_bugs(void)
>  	unsigned int cpu = smp_processor_id();
>  
>  	cpu_data[cpu].udelay_val = loops_per_jiffy;
> -	check_bugs32();
> +
> +	if (IS_ENABLED(CONFIG_CPU_34K_BUGS32))
> +		check_bugs32();
>  
>  	if (IS_ENABLED(CONFIG_CPU_R4X00_BUGS64))
>  		check_bugs64();
> diff --git a/arch/mips/kernel/34k-bugs32.c
> b/arch/mips/kernel/34k-bugs32.c new file mode 100644
> index 0000000..dc3ac01
> --- /dev/null
> +++ b/arch/mips/kernel/34k-bugs32.c
> @@ -0,0 +1,29 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <asm/cpu.h>
> +#include <asm/cpu-info.h>
> +#include <asm/cpu-type.h>
> +#include <asm/bugs.h>
> +
> +static inline void check_errata32(void)
> +{
> +	struct cpuinfo_mips *c = &current_cpu_data;
> +
> +	switch (current_cpu_type()) {
> +	case CPU_34K:
> +		/*
> +		 * Erratum "RPS May Cause Incorrect Instruction
> Execution"
> +		 * This code only handles VPE0, any SMP/RTOS code
> +		 * making use of VPE1 will be responsable for that
> VPE.
> +		 */
> +		if ((c->processor_id & PRID_REV_MASK) <=
> PRID_REV_34K_V1_0_2)
> +			write_c0_config7(read_c0_config7() |
> MIPS_CONF7_RPS);
> +		break;
> +	default:
> +		break;
> +	}
> +}
> +
> +void __init check_bugs32(void)
> +{
> +	check_errata32();
> +}
> diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
> index d6e97df..c2fd191 100644
> --- a/arch/mips/kernel/Makefile
> +++ b/arch/mips/kernel/Makefile
> @@ -81,6 +81,7 @@ obj-$(CONFIG_PROC_FS)		+= proc.o
>  obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
>  
>  obj-$(CONFIG_CPU_R4X00_BUGS64)	+= r4k-bugs64.o
> +obj-$(CONFIG_CPU_34K_BUGS32)	+= 34k-bugs32.o
>  
>  obj-$(CONFIG_I8253)		+= i8253.o
>  
> diff --git a/arch/mips/kernel/cpu-probe.c
> b/arch/mips/kernel/cpu-probe.c index f21a230..7179787 100644
> --- a/arch/mips/kernel/cpu-probe.c
> +++ b/arch/mips/kernel/cpu-probe.c
> @@ -14,7 +14,6 @@
>  #include <linux/stddef.h>
>  #include <linux/export.h>
>  
> -#include <asm/bugs.h>
>  #include <asm/cpu.h>
>  #include <asm/cpu-features.h>
>  #include <asm/cpu-type.h>
> @@ -461,30 +460,6 @@ static inline void cpu_set_mt_per_tc_perf(struct
> cpuinfo_mips *c) c->options |= MIPS_CPU_MT_PER_TC_PERF_COUNTERS;
>  }
>  
> -static inline void check_errata(void)
> -{
> -	struct cpuinfo_mips *c = &current_cpu_data;
> -
> -	switch (current_cpu_type()) {
> -	case CPU_34K:
> -		/*
> -		 * Erratum "RPS May Cause Incorrect Instruction
> Execution"
> -		 * This code only handles VPE0, any SMP/RTOS code
> -		 * making use of VPE1 will be responsable for that
> VPE.
> -		 */
> -		if ((c->processor_id & PRID_REV_MASK) <=
> PRID_REV_34K_V1_0_2)
> -			write_c0_config7(read_c0_config7() |
> MIPS_CONF7_RPS);
> -		break;
> -	default:
> -		break;
> -	}
> -}
> -
> -void __init check_bugs32(void)
> -{
> -	check_errata();
> -}
> -
>  /*
>   * Probe whether cpu has config register by trying to play with
>   * alternate cache bit and see whether it matters.
Florian Fainelli April 10, 2020, 4:25 p.m. UTC | #3
On 4/9/2020 8:20 PM, Tiezhu Yang wrote:
> In the current code, check_bugs32() only handles MIPS32 CPU type CPU_34K,
> it is better to build and call it on the affected platform.
> 
> Move check_bugs32() to the new added 34k-bugs32.c to indicate the fact that
> the code is specific to the 34k CPU, and also add CONFIG_CPU_34K_BUGS32 to
> control whether or not check the bugs.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

This is not a whole lot of code, so moving this to a separate
translation unit seems a bit heavy handed, also file renames, albeit
tracked properly by git are always a challenge when doing back ports.
Tiezhu Yang April 11, 2020, 2:32 a.m. UTC | #4
On 04/11/2020 12:25 AM, Florian Fainelli wrote:
>
> On 4/9/2020 8:20 PM, Tiezhu Yang wrote:
>> In the current code, check_bugs32() only handles MIPS32 CPU type CPU_34K,
>> it is better to build and call it on the affected platform.
>>
>> Move check_bugs32() to the new added 34k-bugs32.c to indicate the fact that
>> the code is specific to the 34k CPU, and also add CONFIG_CPU_34K_BUGS32 to
>> control whether or not check the bugs.
>>
>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> This is not a whole lot of code, so moving this to a separate
> translation unit seems a bit heavy handed, also file renames, albeit
> tracked properly by git are always a challenge when doing back ports.

Hi Florian,

There exists the following three ways to do it, I'm fine either way,
maybe the first way looks better. Let us wait for the MIPS maintainer
to say what he prefer.

Hi Thomas,

What is your opinion?

1 just use CONFIG_CPU_MIPS32_R2

diff --git a/arch/mips/include/asm/bugs.h b/arch/mips/include/asm/bugs.h
index d72dc6e..743604f 100644
--- a/arch/mips/include/asm/bugs.h
+++ b/arch/mips/include/asm/bugs.h
@@ -35,7 +35,9 @@ static inline void check_bugs(void)
         unsigned int cpu = smp_processor_id();

         cpu_data[cpu].udelay_val = loops_per_jiffy;
-       check_bugs32();
+
+       if (IS_ENABLED(CONFIG_CPU_MIPS32_R2))
+               check_bugs32();

         if (IS_ENABLED(CONFIG_CPU_R4X00_BUGS64))
                 check_bugs64();
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 6ab6b03..383500b 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -461,7 +461,8 @@ static inline void cpu_set_mt_per_tc_perf(struct 
cpuinfo_mips *c)
                 c->options |= MIPS_CPU_MT_PER_TC_PERF_COUNTERS;
  }

-static inline void check_errata(void)
+#ifdef CONFIG_CPU_MIPS32_R2
+static inline void check_errata32(void)
  {
         struct cpuinfo_mips *c = &current_cpu_data;

@@ -482,8 +483,9 @@ static inline void check_errata(void)

  void __init check_bugs32(void)
  {
-       check_errata();
+       check_errata32();
  }
+#endif /* CONFIG_CPU_MIPS32_R2 */

  /*
   * Probe whether cpu has config register by trying to play with


2 add CONFIG_CPU_34K_BUGS32

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 797d7f1..e936e3c 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2605,6 +2605,10 @@ config CPU_R4X00_BUGS64
         bool
         default y if SYS_HAS_CPU_R4X00 && 64BIT && (TARGET_ISA_REV < 1)

+config CPU_34K_BUGS32
+       bool
+       default y if CPU_MIPS32_R2
+
  config MIPS_ASID_SHIFT
         int
         default 6 if CPU_R3000 || CPU_TX39XX
diff --git a/arch/mips/include/asm/bugs.h b/arch/mips/include/asm/bugs.h
index d72dc6e..bbf843a 100644
--- a/arch/mips/include/asm/bugs.h
+++ b/arch/mips/include/asm/bugs.h
@@ -35,7 +35,9 @@ static inline void check_bugs(void)
         unsigned int cpu = smp_processor_id();

         cpu_data[cpu].udelay_val = loops_per_jiffy;
-       check_bugs32();
+
+       if (IS_ENABLED(CONFIG_CPU_34K_BUGS32))
+               check_bugs32();

         if (IS_ENABLED(CONFIG_CPU_R4X00_BUGS64))
                 check_bugs64();
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 6ab6b03..670bc7c 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -461,7 +461,8 @@ static inline void cpu_set_mt_per_tc_perf(struct 
cpuinfo_mips *c)
                 c->options |= MIPS_CPU_MT_PER_TC_PERF_COUNTERS;
  }

-static inline void check_errata(void)
+#ifdef CONFIG_CPU_34K_BUGS32
+static inline void check_errata32(void)
  {
         struct cpuinfo_mips *c = &current_cpu_data;

@@ -482,8 +483,9 @@ static inline void check_errata(void)

  void __init check_bugs32(void)
  {
-       check_errata();
+       check_errata32();
  }
+#endif /* CONFIG_CPU_34K_BUGS32 */

  /*
   * Probe whether cpu has config register by trying to play with


3 add new 34k-bugs32.c and CONFIG_CPU_34K_BUGS32

just as this v2 patch:
https://lore.kernel.org/patchwork/patch/1222273/

Thanks,

Tiezhu Yang
Thomas Bogendoerfer April 14, 2020, 5:32 p.m. UTC | #5
On Sat, Apr 11, 2020 at 10:32:02AM +0800, Tiezhu Yang wrote:
> On 04/11/2020 12:25 AM, Florian Fainelli wrote:
> >
> >On 4/9/2020 8:20 PM, Tiezhu Yang wrote:
> >>In the current code, check_bugs32() only handles MIPS32 CPU type CPU_34K,
> >>it is better to build and call it on the affected platform.
> >>
> >>Move check_bugs32() to the new added 34k-bugs32.c to indicate the fact that
> >>the code is specific to the 34k CPU, and also add CONFIG_CPU_34K_BUGS32 to
> >>control whether or not check the bugs.
> >>
> >>Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> >This is not a whole lot of code, so moving this to a separate
> >translation unit seems a bit heavy handed, also file renames, albeit
> >tracked properly by git are always a challenge when doing back ports.
> 
> Hi Florian,
> 
> There exists the following three ways to do it, I'm fine either way,
> maybe the first way looks better. Let us wait for the MIPS maintainer
> to say what he prefer.
> 
> Hi Thomas,
> 
> What is your opinion?

I don't see a reason for doing that at all. The 34K workaround is only
compiled in if CONFIG_SYS_HAS_CPU_MIPS32_R2 is defined.

Thomas.
Tiezhu Yang April 15, 2020, 1:48 a.m. UTC | #6
On 04/15/2020 01:32 AM, Thomas Bogendoerfer wrote:
> On Sat, Apr 11, 2020 at 10:32:02AM +0800, Tiezhu Yang wrote:
>> On 04/11/2020 12:25 AM, Florian Fainelli wrote:
>>> On 4/9/2020 8:20 PM, Tiezhu Yang wrote:
>>>> In the current code, check_bugs32() only handles MIPS32 CPU type CPU_34K,
>>>> it is better to build and call it on the affected platform.
>>>>
>>>> Move check_bugs32() to the new added 34k-bugs32.c to indicate the fact that
>>>> the code is specific to the 34k CPU, and also add CONFIG_CPU_34K_BUGS32 to
>>>> control whether or not check the bugs.
>>>>
>>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>>> This is not a whole lot of code, so moving this to a separate
>>> translation unit seems a bit heavy handed, also file renames, albeit
>>> tracked properly by git are always a challenge when doing back ports.
>> Hi Florian,
>>
>> There exists the following three ways to do it, I'm fine either way,
>> maybe the first way looks better. Let us wait for the MIPS maintainer
>> to say what he prefer.
>>
>> Hi Thomas,
>>
>> What is your opinion?
> I don't see a reason for doing that at all. The 34K workaround is only
> compiled in if CONFIG_SYS_HAS_CPU_MIPS32_R2 is defined.

Hi Thomas,

Thanks for your reply. My initial thought is to build and call check_bugs32() only for 34K CPU,
because it is useless for other CPU types.

Do you mean to use the following modification?

diff --git a/arch/mips/include/asm/bugs.h b/arch/mips/include/asm/bugs.h
index d72dc6e..743604f 100644
--- a/arch/mips/include/asm/bugs.h
+++ b/arch/mips/include/asm/bugs.h
@@ -35,7 +35,9 @@ static inline void check_bugs(void)
          unsigned int cpu = smp_processor_id();

          cpu_data[cpu].udelay_val = loops_per_jiffy;
-       check_bugs32();
+
+       if (IS_ENABLED(CONFIG_CPU_MIPS32_R2))
+               check_bugs32();

          if (IS_ENABLED(CONFIG_CPU_R4X00_BUGS64))
                  check_bugs64();
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 6ab6b03..383500b 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -461,7 +461,8 @@ static inline void cpu_set_mt_per_tc_perf(struct
cpuinfo_mips *c)
                  c->options |= MIPS_CPU_MT_PER_TC_PERF_COUNTERS;
   }

-static inline void check_errata(void)
+#ifdef CONFIG_CPU_MIPS32_R2
+static inline void check_errata32(void)
   {
          struct cpuinfo_mips *c = &current_cpu_data;

@@ -482,8 +483,9 @@ static inline void check_errata(void)

   void __init check_bugs32(void)
   {
-       check_errata();
+       check_errata32();
   }
+#endif /* CONFIG_CPU_MIPS32_R2 */

   /*
    * Probe whether cpu has config register by trying to play with


Thanks,

Tiezhu Yang


>
> Thomas.
>
Thomas Bogendoerfer April 15, 2020, 8:31 a.m. UTC | #7
On Wed, Apr 15, 2020 at 09:48:30AM +0800, Tiezhu Yang wrote:
> On 04/15/2020 01:32 AM, Thomas Bogendoerfer wrote:
> >On Sat, Apr 11, 2020 at 10:32:02AM +0800, Tiezhu Yang wrote:
> >>On 04/11/2020 12:25 AM, Florian Fainelli wrote:
> >>>On 4/9/2020 8:20 PM, Tiezhu Yang wrote:
> >>>>In the current code, check_bugs32() only handles MIPS32 CPU type CPU_34K,
> >>>>it is better to build and call it on the affected platform.
> >>>>
> >>>>Move check_bugs32() to the new added 34k-bugs32.c to indicate the fact that
> >>>>the code is specific to the 34k CPU, and also add CONFIG_CPU_34K_BUGS32 to
> >>>>control whether or not check the bugs.
> >>>>
> >>>>Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> >>>This is not a whole lot of code, so moving this to a separate
> >>>translation unit seems a bit heavy handed, also file renames, albeit
> >>>tracked properly by git are always a challenge when doing back ports.
> >>Hi Florian,
> >>
> >>There exists the following three ways to do it, I'm fine either way,
> >>maybe the first way looks better. Let us wait for the MIPS maintainer
> >>to say what he prefer.
> >>
> >>Hi Thomas,
> >>
> >>What is your opinion?
> >I don't see a reason for doing that at all. The 34K workaround is only
> >compiled in if CONFIG_SYS_HAS_CPU_MIPS32_R2 is defined.
> 
> Hi Thomas,
> 
> Thanks for your reply. My initial thought is to build and call check_bugs32() only for 34K CPU,
> because it is useless for other CPU types.
> 
> Do you mean to use the following modification?

no, IMHO we don't need to change anything here. There is not much to save
here.

Thomas.
diff mbox series

Patch

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index a1f973c..d95dc18 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2619,6 +2619,10 @@  config CPU_R4X00_BUGS64
 	bool
 	default y if SYS_HAS_CPU_R4X00 && 64BIT && (TARGET_ISA_REV < 1)
 
+config CPU_34K_BUGS32
+	bool
+	default y if CPU_MIPS32_R2
+
 config MIPS_ASID_SHIFT
 	int
 	default 6 if CPU_R3000 || CPU_TX39XX
diff --git a/arch/mips/include/asm/bugs.h b/arch/mips/include/asm/bugs.h
index d72dc6e..bbf843a 100644
--- a/arch/mips/include/asm/bugs.h
+++ b/arch/mips/include/asm/bugs.h
@@ -35,7 +35,9 @@  static inline void check_bugs(void)
 	unsigned int cpu = smp_processor_id();
 
 	cpu_data[cpu].udelay_val = loops_per_jiffy;
-	check_bugs32();
+
+	if (IS_ENABLED(CONFIG_CPU_34K_BUGS32))
+		check_bugs32();
 
 	if (IS_ENABLED(CONFIG_CPU_R4X00_BUGS64))
 		check_bugs64();
diff --git a/arch/mips/kernel/34k-bugs32.c b/arch/mips/kernel/34k-bugs32.c
new file mode 100644
index 0000000..dc3ac01
--- /dev/null
+++ b/arch/mips/kernel/34k-bugs32.c
@@ -0,0 +1,29 @@ 
+// SPDX-License-Identifier: GPL-2.0
+#include <asm/cpu.h>
+#include <asm/cpu-info.h>
+#include <asm/cpu-type.h>
+#include <asm/bugs.h>
+
+static inline void check_errata32(void)
+{
+	struct cpuinfo_mips *c = &current_cpu_data;
+
+	switch (current_cpu_type()) {
+	case CPU_34K:
+		/*
+		 * Erratum "RPS May Cause Incorrect Instruction Execution"
+		 * This code only handles VPE0, any SMP/RTOS code
+		 * making use of VPE1 will be responsable for that VPE.
+		 */
+		if ((c->processor_id & PRID_REV_MASK) <= PRID_REV_34K_V1_0_2)
+			write_c0_config7(read_c0_config7() | MIPS_CONF7_RPS);
+		break;
+	default:
+		break;
+	}
+}
+
+void __init check_bugs32(void)
+{
+	check_errata32();
+}
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index d6e97df..c2fd191 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -81,6 +81,7 @@  obj-$(CONFIG_PROC_FS)		+= proc.o
 obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
 
 obj-$(CONFIG_CPU_R4X00_BUGS64)	+= r4k-bugs64.o
+obj-$(CONFIG_CPU_34K_BUGS32)	+= 34k-bugs32.o
 
 obj-$(CONFIG_I8253)		+= i8253.o
 
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index f21a230..7179787 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -14,7 +14,6 @@ 
 #include <linux/stddef.h>
 #include <linux/export.h>
 
-#include <asm/bugs.h>
 #include <asm/cpu.h>
 #include <asm/cpu-features.h>
 #include <asm/cpu-type.h>
@@ -461,30 +460,6 @@  static inline void cpu_set_mt_per_tc_perf(struct cpuinfo_mips *c)
 		c->options |= MIPS_CPU_MT_PER_TC_PERF_COUNTERS;
 }
 
-static inline void check_errata(void)
-{
-	struct cpuinfo_mips *c = &current_cpu_data;
-
-	switch (current_cpu_type()) {
-	case CPU_34K:
-		/*
-		 * Erratum "RPS May Cause Incorrect Instruction Execution"
-		 * This code only handles VPE0, any SMP/RTOS code
-		 * making use of VPE1 will be responsable for that VPE.
-		 */
-		if ((c->processor_id & PRID_REV_MASK) <= PRID_REV_34K_V1_0_2)
-			write_c0_config7(read_c0_config7() | MIPS_CONF7_RPS);
-		break;
-	default:
-		break;
-	}
-}
-
-void __init check_bugs32(void)
-{
-	check_errata();
-}
-
 /*
  * Probe whether cpu has config register by trying to play with
  * alternate cache bit and see whether it matters.