@@ -352,7 +352,12 @@ __setup("nohtw", htw_disable);
352352static int mips_ftlb_disabled ;
353353static int mips_has_ftlb_configured ;
354354
355- static int set_ftlb_enable (struct cpuinfo_mips * c , int enable );
355+ enum ftlb_flags {
356+ FTLB_EN = 1 << 0 ,
357+ FTLB_SET_PROB = 1 << 1 ,
358+ };
359+
360+ static int set_ftlb_enable (struct cpuinfo_mips * c , enum ftlb_flags flags );
356361
357362static int __init ftlb_disable (char * s )
358363{
@@ -371,8 +376,6 @@ static int __init ftlb_disable(char *s)
371376 return 1 ;
372377 }
373378
374- back_to_back_c0_hazard ();
375-
376379 config4 = read_c0_config4 ();
377380
378381 /* Check that FTLB has been disabled */
@@ -531,7 +534,7 @@ static unsigned int calculate_ftlb_probability(struct cpuinfo_mips *c)
531534 return 3 ;
532535}
533536
534- static int set_ftlb_enable (struct cpuinfo_mips * c , int enable )
537+ static int set_ftlb_enable (struct cpuinfo_mips * c , enum ftlb_flags flags )
535538{
536539 unsigned int config ;
537540
@@ -542,33 +545,33 @@ static int set_ftlb_enable(struct cpuinfo_mips *c, int enable)
542545 case CPU_P6600 :
543546 /* proAptiv & related cores use Config6 to enable the FTLB */
544547 config = read_c0_config6 ();
545- /* Clear the old probability value */
546- config &= ~(3 << MIPS_CONF6_FTLBP_SHIFT );
547- if (enable )
548- /* Enable FTLB */
549- write_c0_config6 (config |
550- (calculate_ftlb_probability (c )
551- << MIPS_CONF6_FTLBP_SHIFT )
552- | MIPS_CONF6_FTLBEN );
548+
549+ if (flags & FTLB_EN )
550+ config |= MIPS_CONF6_FTLBEN ;
553551 else
554- /* Disable FTLB */
555- write_c0_config6 (config & ~MIPS_CONF6_FTLBEN );
552+ config &= ~MIPS_CONF6_FTLBEN ;
553+
554+ if (flags & FTLB_SET_PROB ) {
555+ config &= ~(3 << MIPS_CONF6_FTLBP_SHIFT );
556+ config |= calculate_ftlb_probability (c )
557+ << MIPS_CONF6_FTLBP_SHIFT ;
558+ }
559+
560+ write_c0_config6 (config );
561+ back_to_back_c0_hazard ();
556562 break ;
557563 case CPU_I6400 :
558- /* I6400 & related cores use Config7 to configure FTLB */
559- config = read_c0_config7 ();
560- /* Clear the old probability value */
561- config &= ~(3 << MIPS_CONF7_FTLBP_SHIFT );
562- write_c0_config7 (config | (calculate_ftlb_probability (c )
563- << MIPS_CONF7_FTLBP_SHIFT ));
564- break ;
564+ /* There's no way to disable the FTLB */
565+ if (!(flags & FTLB_EN ))
566+ return 1 ;
567+ return 0 ;
565568 case CPU_LOONGSON3 :
566569 /* Flush ITLB, DTLB, VTLB and FTLB */
567570 write_c0_diag (LOONGSON_DIAG_ITLB | LOONGSON_DIAG_DTLB |
568571 LOONGSON_DIAG_VTLB | LOONGSON_DIAG_FTLB );
569572 /* Loongson-3 cores use Config6 to enable the FTLB */
570573 config = read_c0_config6 ();
571- if (enable )
574+ if (flags & FTLB_EN )
572575 /* Enable FTLB */
573576 write_c0_config6 (config & ~MIPS_CONF6_FTLBDIS );
574577 else
@@ -788,6 +791,7 @@ static inline unsigned int decode_config4(struct cpuinfo_mips *c)
788791 PAGE_SIZE , config4 );
789792 /* Switch FTLB off */
790793 set_ftlb_enable (c , 0 );
794+ mips_ftlb_disabled = 1 ;
791795 break ;
792796 }
793797 c -> tlbsizeftlbsets = 1 <<
@@ -852,7 +856,7 @@ static void decode_configs(struct cpuinfo_mips *c)
852856 c -> scache .flags = MIPS_CACHE_NOT_PRESENT ;
853857
854858 /* Enable FTLB if present and not disabled */
855- set_ftlb_enable (c , ! mips_ftlb_disabled );
859+ set_ftlb_enable (c , mips_ftlb_disabled ? 0 : FTLB_EN );
856860
857861 ok = decode_config0 (c ); /* Read Config registers. */
858862 BUG_ON (!ok ); /* Arch spec violation! */
@@ -902,6 +906,9 @@ static void decode_configs(struct cpuinfo_mips *c)
902906 }
903907 }
904908
909+ /* configure the FTLB write probability */
910+ set_ftlb_enable (c , (mips_ftlb_disabled ? 0 : FTLB_EN ) | FTLB_SET_PROB );
911+
905912 mips_probe_watch_registers (c );
906913
907914#ifndef CONFIG_MIPS_CPS
0 commit comments