Skip to contentSkip to conversation

MIPS: micromips: Fix improper definition of ISA exception bit.

PATCH Superseded Steven J. Hill 4 participants 9 messages Jun 5, 2013 MIPS

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 MIPS: micromips: Fix improper definition of ISA exception bit.

The ISA exception bit selects whether exceptions are taken in classic or microMIPS mode. This bit is Config3.ISAOnExc and was improperly defined as bits 16 and 17 instead of just bit 16. A new function was added so that platforms could set this bit when running a kernel compiled with only microMIPS instructions.

---
Changes from v5:
* Make 'set_micromips_exception_mode' function to always be called.

 arch/mips/include/asm/mipsregs.h |   18 +++++++++++++++++-
 arch/mips/kernel/cpu-probe.c     |    3 ---
 arch/mips/kernel/traps.c         |    5 +++++
 3 files changed, 22 insertions(+), 4 deletions(-)
arch/mips/include/asm/mipsregs.h +17 -1
index 87e6207..cc0f5d7 100644
@@ -596,7 +596,7 @@
 #define MIPS_CONF3_RXI		(_ULCAST_(1) << 12)
 #define MIPS_CONF3_ULRI		(_ULCAST_(1) << 13)
 #define MIPS_CONF3_ISA		(_ULCAST_(3) << 14)
-#define MIPS_CONF3_ISA_OE	(_ULCAST_(3) << 16)
+#define MIPS_CONF3_ISA_OE	(_ULCAST_(1) << 16)
 #define MIPS_CONF3_VZ		(_ULCAST_(1) << 23)
 
 #define MIPS_CONF4_MMUSIZEEXT	(_ULCAST_(255) << 0)
@@ -1161,6 +1161,22 @@ do {									\
 #define write_c0_brcm_sleepcount(val)	__write_32bit_c0_register($22, 7, val)
 
 /*
+ * Set exceptions to be taken in microMIPS mode only, otherwise
+ * set for classic exceptions.
+ */
+static inline void set_micromips_exception_mode(void)
+{
+	unsigned int config3 = read_c0_config3();
+
+#ifdef CONFIG_CPU_MICROMIPS
+	if (config3 & MIPS_CONF3_ISA)
+		write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
+	else
+#endif
+		write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
+}
+
+/*
  * Macros to access the floating point coprocessor control registers
  */
 #define read_32bit_cp1_register(source)					\
arch/mips/kernel/cpu-probe.c +0 -3
index c6568bf..b0d04a2 100644
@@ -272,9 +272,6 @@ static inline unsigned int decode_config3(struct cpuinfo_mips *c)
 		c->options |= MIPS_CPU_ULRI;
 	if (config3 & MIPS_CONF3_ISA)
 		c->options |= MIPS_CPU_MICROMIPS;
-#ifdef CONFIG_CPU_MICROMIPS
-	write_c0_config3(read_c0_config3() | MIPS_CONF3_ISA_OE);
-#endif
 	if (config3 & MIPS_CONF3_VZ)
 		c->ases |= MIPS_ASE_VZ;
 
arch/mips/kernel/traps.c +5 -0
index a75ae40..151ed59 100644
@@ -1837,6 +1837,11 @@ void __init trap_init(void)
 			ebase += (read_c0_ebase() & 0x3ffff000);
 	}
 
+	/*
+	 * Set microMIPS exceptions for platforms that support it.
+	 */
+	set_micromips_exception_mode();
+
 	if (board_ebase_setup)
 		board_ebase_setup();
 	per_cpu_trap_init(true);
Signature · 1 line
1.7.2.5
#1 lore raw

Hello.

Quoted 5 lines · Steven J. Hill

The ISA exception bit selects whether exceptions are taken in classic or microMIPS mode. This bit is Config3.ISAOnExc and was improperly defined as bits 16 and 17 instead of just bit 16. A new function was added so that platforms could set this bit when running a kernel compiled with only microMIPS instructions.

Ahem, isn't that function a material for another patch?

Quoted 46 lines

---
Changes from v5:
* Make 'set_micromips_exception_mode' function to always be called.

  arch/mips/include/asm/mipsregs.h |   18 +++++++++++++++++-
  arch/mips/kernel/cpu-probe.c     |    3 ---
  arch/mips/kernel/traps.c         |    5 +++++
  3 files changed, 22 insertions(+), 4 deletions(-)
arch/mips/include/asm/mipsregs.h +17 -1
index 87e6207..cc0f5d7 100644
@@ -596,7 +596,7 @@
  #define MIPS_CONF3_RXI		(_ULCAST_(1) << 12)
  #define MIPS_CONF3_ULRI		(_ULCAST_(1) << 13)
  #define MIPS_CONF3_ISA		(_ULCAST_(3) << 14)
-#define MIPS_CONF3_ISA_OE	(_ULCAST_(3) << 16)
+#define MIPS_CONF3_ISA_OE	(_ULCAST_(1) << 16)
  #define MIPS_CONF3_VZ		(_ULCAST_(1) << 23)
 
  #define MIPS_CONF4_MMUSIZEEXT	(_ULCAST_(255) << 0)
@@ -1161,6 +1161,22 @@ do {									\
  #define write_c0_brcm_sleepcount(val)	__write_32bit_c0_register($22, 7, val)
 
  /*
+ * Set exceptions to be taken in microMIPS mode only, otherwise
+ * set for classic exceptions.
+ */
+static inline void set_micromips_exception_mode(void)
+{
+	unsigned int config3 = read_c0_config3();
+
+#ifdef CONFIG_CPU_MICROMIPS
+	if (config3 & MIPS_CONF3_ISA)
+		write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
+	else
+#endif
+		write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
+}
+
+/*
   * Macros to access the floating point coprocessor control registers
   */
  #define read_32bit_cp1_register(source)					\

[...]

arch/mips/kernel/traps.c void __init trap_init(void) · line 1843

Quoted 12 lines
arch/mips/kernel/traps.c +4 -0
index a75ae40..151ed59 100644
@@ -1837,6 +1837,11 @@ void __init trap_init(void)
  			ebase += (read_c0_ebase() & 0x3ffff000);
  	}
 
+	/*
+	 * Set microMIPS exceptions for platforms that support it.
+	 */
+	set_micromips_exception_mode();

If we have reduced the call sites to 1, do we still need the
function? :-)

WBR, Sergei

#2 lore raw
Quoted 11 lines · Sergei Shtylyov

Hello.

Quoted 5 lines · Steven J. Hill

The ISA exception bit selects whether exceptions are taken in classic or microMIPS mode. This bit is Config3.ISAOnExc and was improperly defined as bits 16 and 17 instead of just bit 16. A new function was added so that platforms could set this bit when running a kernel compiled with only microMIPS instructions.

Ahem, isn't that function a material for another patch?

I think you might be going overboard. The entire patch relates to exactly one bit a config register, can't you let it be a single patch?

David Daney

Quoted 68 lines
Quoted 47 lines

---
Changes from v5:
* Make 'set_micromips_exception_mode' function to always be called.

  arch/mips/include/asm/mipsregs.h |   18 +++++++++++++++++-
  arch/mips/kernel/cpu-probe.c     |    3 ---
  arch/mips/kernel/traps.c         |    5 +++++
  3 files changed, 22 insertions(+), 4 deletions(-)
arch/mips/include/asm/mipsregs.h +17 -1
index 87e6207..cc0f5d7 100644
@@ -596,7 +596,7 @@
  #define MIPS_CONF3_RXI        (_ULCAST_(1) << 12)
  #define MIPS_CONF3_ULRI        (_ULCAST_(1) << 13)
  #define MIPS_CONF3_ISA        (_ULCAST_(3) << 14)
-#define MIPS_CONF3_ISA_OE    (_ULCAST_(3) << 16)
+#define MIPS_CONF3_ISA_OE    (_ULCAST_(1) << 16)
  #define MIPS_CONF3_VZ        (_ULCAST_(1) << 23)
  #define MIPS_CONF4_MMUSIZEEXT    (_ULCAST_(255) << 0)
@@ -1161,6 +1161,22 @@ do {                                    \
  #define write_c0_brcm_sleepcount(val)
 __write_32bit_c0_register($22, 7, val)
  /*
+ * Set exceptions to be taken in microMIPS mode only, otherwise
+ * set for classic exceptions.
+ */
+static inline void set_micromips_exception_mode(void)
+{
+    unsigned int config3 = read_c0_config3();
+
+#ifdef CONFIG_CPU_MICROMIPS
+    if (config3 & MIPS_CONF3_ISA)
+        write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
+    else
+#endif
+        write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
+}
+
+/*
   * Macros to access the floating point coprocessor control registers
   */
  #define read_32bit_cp1_register(source)                    \

[...]

arch/mips/kernel/traps.c void __init trap_init(void) · line 1842

Quoted 11 lines
arch/mips/kernel/traps.c +4 -0
index a75ae40..151ed59 100644
@@ -1837,6 +1837,11 @@ void __init trap_init(void)
              ebase += (read_c0_ebase() & 0x3ffff000);
      }
+    /*
+     * Set microMIPS exceptions for platforms that support it.
+     */
+    set_micromips_exception_mode();

If we have reduced the call sites to 1, do we still need the
function? :-)

WBR, Sergei

#3 lore raw
Quoted 11 lines · David Daney
Quoted 10 lines · Sergei Shtylyov

Hello.

Quoted 5 lines · Steven J. Hill

The ISA exception bit selects whether exceptions are taken in classic or microMIPS mode. This bit is Config3.ISAOnExc and was improperly defined as bits 16 and 17 instead of just bit 16. A new function was added so that platforms could set this bit when running a kernel compiled with only microMIPS instructions.

Quoted 4 lines
Quoted 1 line

Ahem, isn't that function a material for another patch?

I think you might be going overboard. The entire patch relates to exactly one bit a config register, can't you let it be a single patch?

The purpose of the patch declared in its subject is just to fix the
bit itself.
Instead the patch does zillion other things, which IMHO not even always can be considered fixes, so no, I'm not feeling like I'm going overboard with this.

Quoted 1 line

David Daney

WBR, Sergei

#4 lore raw
In reply to Steven J. Hill
Quoted 10 lines · Steven J. Hill

The ISA exception bit selects whether exceptions are taken in classic or microMIPS mode. This bit is Config3.ISAOnExc and was improperly defined as bits 16 and 17 instead of just bit 16. A new function was added so that platforms could set this bit when running a kernel compiled with only microMIPS instructions.

---
Changes from v5:
* Make 'set_micromips_exception_mode' function to always be called.

Version 5 was better in my opinion...

Quoted 26 lines
  arch/mips/include/asm/mipsregs.h |   18 +++++++++++++++++-
  arch/mips/kernel/cpu-probe.c     |    3 ---
  arch/mips/kernel/traps.c         |    5 +++++
  3 files changed, 22 insertions(+), 4 deletions(-)
arch/mips/include/asm/mipsregs.h +4 -1
index 87e6207..cc0f5d7 100644
@@ -596,7 +596,7 @@
  #define MIPS_CONF3_RXI		(_ULCAST_(1) << 12)
  #define MIPS_CONF3_ULRI		(_ULCAST_(1) << 13)
  #define MIPS_CONF3_ISA		(_ULCAST_(3) << 14)
-#define MIPS_CONF3_ISA_OE	(_ULCAST_(3) << 16)
+#define MIPS_CONF3_ISA_OE	(_ULCAST_(1) << 16)
  #define MIPS_CONF3_VZ		(_ULCAST_(1) << 23)
 
  #define MIPS_CONF4_MMUSIZEEXT	(_ULCAST_(255) << 0)
@@ -1161,6 +1161,22 @@ do {									\
  #define write_c0_brcm_sleepcount(val)	__write_32bit_c0_register($22, 7, val)
 
  /*
+ * Set exceptions to be taken in microMIPS mode only, otherwise
+ * set for classic exceptions.
+ */

arch/mips/include/asm/mipsregs.h do { \ · line 1176

Quoted 10 lines
arch/mips/include/asm/mipsregs.h +10 -0
+static inline void set_micromips_exception_mode(void)
+{
+	unsigned int config3 = read_c0_config3();
+
+#ifdef CONFIG_CPU_MICROMIPS
+	if (config3 & MIPS_CONF3_ISA)
+		write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
+	else
+#endif
+		write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);

You can only manipulate this bit if you know microMIPS is supported. So I think you should either not touch it for the non-microMIPS case, or make the write conditional on the presence of microMIPS support in the CPU.

David Daney

Quoted 3 lines
arch/mips/include/asm/mipsregs.h +3 -0
+}
+
+/*
#5 lore raw
Quoted 5 lines · David Daney

You can only manipulate this bit if you know microMIPS is supported. So I think you should either not touch it for the non-microMIPS case, or make the write conditional on the presence of microMIPS support in the CPU.

I decided to surround with SYS_SUPPORTS_MICROMIPS so the function could be optimized out in v7 of the patch.

#6 lore raw
Quoted 10 lines · Steven J. Hill
Quoted 7 lines · David Daney

You can only manipulate this bit if you know microMIPS is supported. So I think you should either not touch it for the non-microMIPS case, or make the write conditional on the presence of microMIPS support in the CPU.

I decided to surround with SYS_SUPPORTS_MICROMIPS so the function could be optimized out in v7 of the patch.

Since this is (AFAICT) run after cpu_probe, and cpu probe sets MIPS_CPU_MICROMIPS in options[0] if config3 has MIPS_CONF3_ISA set (as seen in the context), couldn't you do just the following in cpu_trap:

	if (cpu_has_mmips) {
		unsigned int config3 = read_c0_config3();

		if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
			write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
		else
			write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
	}

Regards
Jonas

#7 lore raw
Quoted 17 lines · Jonas Gorski
Quoted 10 lines · Steven J. Hill
Quoted 7 lines · David Daney

You can only manipulate this bit if you know microMIPS is supported. So I think you should either not touch it for the non-microMIPS case, or make the write conditional on the presence of microMIPS support in the CPU.

I decided to surround with SYS_SUPPORTS_MICROMIPS so the function could be optimized out in v7 of the patch.

Since this is (AFAICT) run after cpu_probe, and cpu probe sets MIPS_CPU_MICROMIPS in options[0] if config3 has MIPS_CONF3_ISA set (as seen in the context), couldn't you do just the following in cpu_trap:

Quoted 9 lines
	if (cpu_has_mmips) {
		unsigned int config3 = read_c0_config3();

		if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
			write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
		else
			write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
	}

Yes, that would work. It even looks nicer.

David Daney

Quoted 5 lines

Regards
Jonas

#8 lore raw
In reply to Jonas Gorski
Quoted 11 lines · Jonas Gorski
	if (cpu_has_mmips) {
		unsigned int config3 = read_c0_config3();

		if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
			write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
		else
			write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
	}

I like this being in 'trap_init' instead. Any objections?