@@ -466,12 +466,25 @@ static void loongson3_smp_finish(void)
466466static void __init loongson3_smp_setup (void )
467467{
468468 int i = 0 , num = 0 ; /* i: physical id, num: logical id */
469+ int max_cpus = 0 ;
469470
470471 init_cpu_possible (cpu_none_mask );
471472
473+ for (i = 0 ; i < ARRAY_SIZE (smp_group ); i ++ ) {
474+ if (!smp_group [i ])
475+ break ;
476+ max_cpus += loongson_sysconf .cores_per_node ;
477+ }
478+
479+ if (max_cpus < loongson_sysconf .nr_cpus ) {
480+ pr_err ("SMP Groups are less than the number of CPUs\n" );
481+ loongson_sysconf .nr_cpus = max_cpus ? max_cpus : 1 ;
482+ }
483+
472484 /* For unified kernel, NR_CPUS is the maximum possible value,
473485 * loongson_sysconf.nr_cpus is the really present value
474486 */
487+ i = 0 ;
475488 while (i < loongson_sysconf .nr_cpus ) {
476489 if (loongson_sysconf .reserved_cpus_mask & (1 <<i )) {
477490 /* Reserved physical CPU cores */
@@ -492,14 +505,14 @@ static void __init loongson3_smp_setup(void)
492505 __cpu_logical_map [num ] = -1 ;
493506 num ++ ;
494507 }
495-
496508 csr_ipi_probe ();
497509 ipi_set0_regs_init ();
498510 ipi_clear0_regs_init ();
499511 ipi_status0_regs_init ();
500512 ipi_en0_regs_init ();
501513 ipi_mailbox_buf_init ();
502- ipi_write_enable (0 );
514+ if (smp_group [0 ])
515+ ipi_write_enable (0 );
503516
504517 cpu_set_core (& cpu_data [0 ],
505518 cpu_logical_map (0 ) % loongson_sysconf .cores_per_package );
@@ -818,6 +831,9 @@ static int loongson3_disable_clock(unsigned int cpu)
818831 uint64_t core_id = cpu_core (& cpu_data [cpu ]);
819832 uint64_t package_id = cpu_data [cpu ].package ;
820833
834+ if (!loongson_chipcfg [package_id ] || !loongson_freqctrl [package_id ])
835+ return 0 ;
836+
821837 if ((read_c0_prid () & PRID_REV_MASK ) == PRID_REV_LOONGSON3A_R1 ) {
822838 LOONGSON_CHIPCFG (package_id ) &= ~(1 << (12 + core_id ));
823839 } else {
@@ -832,6 +848,9 @@ static int loongson3_enable_clock(unsigned int cpu)
832848 uint64_t core_id = cpu_core (& cpu_data [cpu ]);
833849 uint64_t package_id = cpu_data [cpu ].package ;
834850
851+ if (!loongson_chipcfg [package_id ] || !loongson_freqctrl [package_id ])
852+ return 0 ;
853+
835854 if ((read_c0_prid () & PRID_REV_MASK ) == PRID_REV_LOONGSON3A_R1 ) {
836855 LOONGSON_CHIPCFG (package_id ) |= 1 << (12 + core_id );
837856 } else {
0 commit comments