MIPS: Hang if run on a secondary CPU
PATCH v4 1/1 MIPS: Hang if run on a secondary CPU
Some systems are configured such that multiple CPUs begin running from their reset vector following a system reset. If this occurs then U-Boot will be run on multiple CPUs simultaneously, which causes all sorts of issues as the multiple instances of U-Boot clobber each other.
Prevent this from happening by simply hanging with an infinite loop if we run on a CPU whose ID, as determined by GlobalNumber or EBase.CPUNum as appropriate, is non-zero.
---
Changes in v4:
- Presume Config5 is present for MIPSr6, as the arch says it will be
Changes in v3:
- Fix branch target for MIPSr6 case... Oops!
Changes in v2:
- Rebase atop u-boot-mips/next
- Execute a wait instruction in the loop
- Fill delay slots with NOPs
arch/mips/cpu/start.S | 21 ++++++++++++++++++++- arch/mips/include/asm/mipsregs.h | 7 +++++++ 2 files changed, 27 insertions(+), 1 deletion(-)
arch/mips/cpu/start.S +20 -1
@@ -108,9 +108,28 @@ ENTRY(_start) .align 4 reset: +#if __mips_isa_rev >= 6 + mfc0 t0, CP0_CONFIG, 5 + and t0, t0, MIPS_CONF5_VP + beqz t0, 1f + nop + + b 2f + mfc0 t0, CP0_GLOBALNUMBER +#endif + +1: mfc0 t0, CP0_EBASE + and t0, t0, EBASE_CPUNUM + + /* Hang if this isn't the first CPU in the system */ +2: beqz t0, 4f + nop +3: wait + b 3b + nop /* Clear watch registers */ - MTC0 zero, CP0_WATCHLO +4: MTC0 zero, CP0_WATCHLO mtc0 zero, CP0_WATCHHI /* WP(Watch Pending), SW0/1 should be cleared */
arch/mips/include/asm/mipsregs.h +7 -0
@@ -39,6 +39,7 @@#define CP0_ENTRYLO0 $2#define CP0_ENTRYLO1 $3#define CP0_CONF $3 +#define CP0_GLOBALNUMBER $3, 1#define CP0_CONTEXT $4#define CP0_PAGEMASK $5#define CP0_WIRED $6
@@ -361,6 +362,11 @@#define CAUSEF_BD (_ULCAST_(1) << 31)/* +* Bits in the coprocessor 0 EBase register. +*/ +#define EBASE_CPUNUM 0x3ff + +/* * Bits in the coprocessor 0 config register. */ /* Generic bits. */
@@ -553,6 +559,7 @@#define MIPS_CONF5_MRP (_ULCAST_(1) << 3)#define MIPS_CONF5_LLB (_ULCAST_(1) << 4)#define MIPS_CONF5_MVH (_ULCAST_(1) << 5) +#define MIPS_CONF5_VP (_ULCAST_(1) << 7)#define MIPS_CONF5_FRE (_ULCAST_(1) << 8)#define MIPS_CONF5_UFE (_ULCAST_(1) << 9)#define MIPS_CONF5_L2C (_ULCAST_(1) << 10)
Signature · 1 line
2.10.0
PATCH v4 1/1 MIPS: Hang if run on a secondary CPU
Am 21.09.2016 um 15:59 schrieb Paul Burton:
Quoted 38 lines
Some systems are configured such that multiple CPUs begin running from their reset vector following a system reset. If this occurs then U-Boot will be run on multiple CPUs simultaneously, which causes all sorts of issues as the multiple instances of U-Boot clobber each other.
Prevent this from happening by simply hanging with an infinite loop if we run on a CPU whose ID, as determined by GlobalNumber or EBase.CPUNum as appropriate, is non-zero.
Signed-off-by Paul Burton <[email protected]>---
Changes in v4:
- Presume Config5 is present for MIPSr6, as the arch says it will beChanges in v3:
- Fix branch target for MIPSr6 case... Oops!Changes in v2:
- Rebase atop u-boot-mips/next
- Execute a wait instruction in the loop
- Fill delay slots with NOPsarch/mips/cpu/start.S | 21 ++++++++++++++++++++- arch/mips/include/asm/mipsregs.h | 7 +++++++ 2 files changed, 27 insertions(+), 1 deletion(-)arch/mips/cpu/start.S +2
-0@@ -108,9 +108,28 @@ ENTRY(_start) .align 4 reset: +#if __mips_isa_rev >= 6 + mfc0 t0, CP0_CONFIG, 5
arch/mips/cpu/start.S ENTRY(_start) · line 122
Quoted 10 lines
arch/mips/cpu/start.S +10
-0+ and t0, t0, MIPS_CONF5_VP + beqz t0, 1f + nop + + b 2f + mfc0 t0, CP0_GLOBALNUMBER +#endif + +1: mfc0 t0, CP0_EBASE + and t0, t0, EBASE_CPUNUM
just nit-picking but actually you're creating dead code for MIPS r6 by the permanent branch to label 2. Maybe it's better to move these two lines to the #else branch of "#if __mips_isa_rev >= 6" and save the branch to label 2?
Quoted 47 lines
arch/mips/cpu/start.S +8
-1+ + /* Hang if this isn't the first CPU in the system */ +2: beqz t0, 4f + nop +3: wait + b 3b + nop /* Clear watch registers */ - MTC0 zero, CP0_WATCHLO +4: MTC0 zero, CP0_WATCHLO mtc0 zero, CP0_WATCHHI /* WP(Watch Pending), SW0/1 should be cleared */arch/mips/include/asm/mipsregs.h +7
-0@@ -39,6 +39,7 @@#define CP0_ENTRYLO0 $2#define CP0_ENTRYLO1 $3#define CP0_CONF $3 +#define CP0_GLOBALNUMBER $3, 1#define CP0_CONTEXT $4#define CP0_PAGEMASK $5#define CP0_WIRED $6@@ -361,6 +362,11 @@#define CAUSEF_BD (_ULCAST_(1) << 31)/* +* Bits in the coprocessor 0 EBase register. +*/ +#define EBASE_CPUNUM 0x3ff + +/* * Bits in the coprocessor 0 config register. */ /* Generic bits. */ @@ -553,6 +559,7 @@#define MIPS_CONF5_MRP (_ULCAST_(1) << 3)#define MIPS_CONF5_LLB (_ULCAST_(1) << 4)#define MIPS_CONF5_MVH (_ULCAST_(1) << 5) +#define MIPS_CONF5_VP (_ULCAST_(1) << 7)#define MIPS_CONF5_FRE (_ULCAST_(1) << 8)#define MIPS_CONF5_UFE (_ULCAST_(1) << 9)#define MIPS_CONF5_L2C (_ULCAST_(1) << 10)
Signature · 9 lines
- Daniel -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 473 bytes Desc: OpenPGP digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160921/d1b712ee/attachment.sig>
PATCH v4 1/1 MIPS: Hang if run on a secondary CPU
Quoted 47 lines · On Wednesday, 21 September 2016 16:19:58 BST Daniel Schwierzeck wrote:
Am 21.09.2016 um 15:59 schrieb Paul Burton:
Quoted 46 lines
Some systems are configured such that multiple CPUs begin running from their reset vector following a system reset. If this occurs then U-Boot will be run on multiple CPUs simultaneously, which causes all sorts of issues as the multiple instances of U-Boot clobber each other.
Prevent this from happening by simply hanging with an infinite loop if we run on a CPU whose ID, as determined by GlobalNumber or EBase.CPUNum as appropriate, is non-zero.
Signed-off-by Paul Burton <[email protected]>---
Changes in v4:
- Presume Config5 is present for MIPSr6, as the arch says it will beChanges in v3:
- Fix branch target for MIPSr6 case... Oops!Changes in v2:
- Rebase atop u-boot-mips/next
- Execute a wait instruction in the loop
- Fill delay slots with NOPsarch/mips/cpu/start.S | 21 ++++++++++++++++++++- arch/mips/include/asm/mipsregs.h | 7 +++++++ 2 files changed, 27 insertions(+), 1 deletion(-)arch/mips/cpu/start.S +9
-0@@ -108,9 +108,28 @@ ENTRY(_start) .align 4 reset: +#if __mips_isa_rev >= 6 + mfc0 t0, CP0_CONFIG, 5 + and t0, t0, MIPS_CONF5_VP + beqz t0, 1f + nop + + b 2f + mfc0 t0, CP0_GLOBALNUMBER +#endif
Quoted 8 lines
arch/mips/cpu/start.S ENTRY(_start) · line 122
Quoted 3 lines
arch/mips/cpu/start.S +3
-0+ +1: mfc0 t0, CP0_EBASE + and t0, t0, EBASE_CPUNUMjust nit-picking but actually you're creating dead code for MIPS r6 by the permanent branch to label 2. Maybe it's better to move these two lines to the #else branch of "#if
__mips_isa_rev>= 6" and save the branch to label 2?
Hi Daniel,
That's not the case because the Config5.VP bit may be 0, in which case the branch to the "1" label will be taken & we'll read EBase.CPUNum. Sadly we can't rely on the GlobalNumber register being implemented on all MIPSr6 systems since the architecture only requires it when VPs are implemented.
Thanks,
Paul
Quoted 62 lines
Quoted 62 lines
arch/mips/cpu/start.S +8
-1+ + /* Hang if this isn't the first CPU in the system */ +2: beqz t0, 4f + nop +3: wait + b 3b + nop /* Clear watch registers */ - MTC0 zero, CP0_WATCHLO +4: MTC0 zero, CP0_WATCHLOarch/mips/cpu/start.S +0
-0mtc0 zero, CP0_WATCHHI /* WP(Watch Pending), SW0/1 should be cleared */(quoted diff) +0
-0
b/arch/mips/include/asm/mipsregs.hindex b4c2dff..9ab5063 100644arch/mips/include/asm/mipsregs.h +1
-0@@ -39,6 +39,7 @@#define CP0_ENTRYLO0 $2#define CP0_ENTRYLO1 $3#define CP0_CONF $3 +#define CP0_GLOBALNUMBER $3, 1#define
CP0_CONTEXT$4
#defineCP0_PAGEMASK$5
#defineCP0_WIRED$6arch/mips/include/asm/mipsregs.h +5
-0@@ -361,6 +362,11 @@#define CAUSEF_BD (_ULCAST_(1) << 31)/* +* Bits in the coprocessor 0 EBase register. +*/ +#define EBASE_CPUNUM 0x3ff + +/* * Bits in the coprocessor 0 config register.
*//* Generic bits. */
arch/mips/include/asm/mipsregs.h +1
-0@@ -553,6 +559,7 @@#define MIPS_CONF5_MRP (_ULCAST_(1) << 3)#define MIPS_CONF5_LLB (_ULCAST_(1) << 4)#define MIPS_CONF5_MVH (_ULCAST_(1) << 5) +#define MIPS_CONF5_VP (_ULCAST_(1) << 7)#define
MIPS_CONF5_FRE(_ULCAST_(1)<< 8)
#defineMIPS_CONF5_UFE(_ULCAST_(1)<< 9)
#defineMIPS_CONF5_L2C(_ULCAST_(1)<< 10)