@@ -479,12 +479,25 @@ static void loongson3_smp_finish(void)
479479static void __init loongson3_smp_setup (void )
480480{
481481 int i = 0 , num = 0 ; /* i: physical id, num: logical id */
482+ int max_cpus = 0 ;
482483
483484 init_cpu_possible (cpu_none_mask );
484485
486+ for (i = 0 ; i < ARRAY_SIZE (smp_group ); i ++ ) {
487+ if (!smp_group [i ])
488+ break ;
489+ max_cpus += loongson_sysconf .cores_per_node ;
490+ }
491+
492+ if (max_cpus < loongson_sysconf .nr_cpus ) {
493+ pr_err ("SMP Groups are less than the number of CPUs\n" );
494+ loongson_sysconf .nr_cpus = max_cpus ? max_cpus : 1 ;
495+ }
496+
485497 /* For unified kernel, NR_CPUS is the maximum possible value,
486498 * loongson_sysconf.nr_cpus is the really present value
487499 */
500+ i = 0 ;
488501 while (i < loongson_sysconf .nr_cpus ) {
489502 if (loongson_sysconf .reserved_cpus_mask & (1 <<i )) {
490503 /* Reserved physical CPU cores */
@@ -505,14 +518,14 @@ static void __init loongson3_smp_setup(void)
505518 __cpu_logical_map [num ] = -1 ;
506519 num ++ ;
507520 }
508-
509521 csr_ipi_probe ();
510522 ipi_set0_regs_init ();
511523 ipi_clear0_regs_init ();
512524 ipi_status0_regs_init ();
513525 ipi_en0_regs_init ();
514526 ipi_mailbox_buf_init ();
515- ipi_write_enable (0 );
527+ if (smp_group [0 ])
528+ ipi_write_enable (0 );
516529
517530 cpu_set_core (& cpu_data [0 ],
518531 cpu_logical_map (0 ) % loongson_sysconf .cores_per_package );
@@ -830,6 +843,9 @@ static int loongson3_disable_clock(unsigned int cpu)
830843 uint64_t core_id = cpu_core (& cpu_data [cpu ]);
831844 uint64_t package_id = cpu_data [cpu ].package ;
832845
846+ if (!loongson_chipcfg [package_id ] || !loongson_freqctrl [package_id ])
847+ return 0 ;
848+
833849 if ((read_c0_prid () & PRID_REV_MASK ) == PRID_REV_LOONGSON3A_R1 ) {
834850 LOONGSON_CHIPCFG (package_id ) &= ~(1 << (12 + core_id ));
835851 } else {
@@ -844,6 +860,9 @@ static int loongson3_enable_clock(unsigned int cpu)
844860 uint64_t core_id = cpu_core (& cpu_data [cpu ]);
845861 uint64_t package_id = cpu_data [cpu ].package ;
846862
863+ if (!loongson_chipcfg [package_id ] || !loongson_freqctrl [package_id ])
864+ return 0 ;
865+
847866 if ((read_c0_prid () & PRID_REV_MASK ) == PRID_REV_LOONGSON3A_R1 ) {
848867 LOONGSON_CHIPCFG (package_id ) |= 1 << (12 + core_id );
849868 } else {
0 commit comments