gator: Prevent BUG() when no device-tree cpu nodes present.
authorJon Medhurst <tixy@linaro.org>
Mon, 17 Jun 2013 09:15:08 +0000 (10:15 +0100)
committerJon Medhurst <tixy@linaro.org>
Tue, 8 Oct 2013 13:57:44 +0000 (14:57 +0100)
When IKS support is enabled in gator but we are running on boards
without a device-tree or where there are no cpu nodes in the
device-tree, then calc_first_cluster_size will call BUG_ON() because
mpidr_cpuids_count == 0.

To work around this, we will instead set a flag to indicate we haven't
managed to create an mpidr table and fallback to the behaviour we would
have if IKS wasn't enabled. This means that IKS support will only
function as expected if there are device-tree nodes for CPUs but we
expect that to always be the case anyway.

Signed-off-by: Jon Medhurst <tixy@linaro.org>
drivers/gator/gator_iks.c

index 932be26bfcf7f57d7995a289a85aa27c398b52d8..ed2c6dd8d4c7456ca1e026a92f3d9e9f1afdf7e0 100644 (file)
@@ -14,6 +14,7 @@
 #include <asm/smp_plat.h>
 #include <trace/events/power_cpu_migrate.h>
 
+static bool map_cpuids;
 static int mpidr_cpuids[NR_CPUS];
 static int __lcpu_to_pcpu[NR_CPUS];
 
@@ -40,7 +41,7 @@ static void calc_first_cluster_size(void)
                ++mpidr_cpuids_count;
        }
 
-       BUG_ON(mpidr_cpuids_count != nr_cpu_ids);
+       map_cpuids = (mpidr_cpuids_count == nr_cpu_ids);
 }
 
 static int linearize_mpidr(int mpidr)
@@ -58,6 +59,10 @@ static int linearize_mpidr(int mpidr)
 int lcpu_to_pcpu(const int lcpu)
 {
        int pcpu;
+
+       if (!map_cpuids)
+               return lcpu;
+
        BUG_ON(lcpu >= nr_cpu_ids || lcpu < 0);
        pcpu = __lcpu_to_pcpu[lcpu];
        BUG_ON(pcpu >= nr_cpu_ids || pcpu < 0);
@@ -67,6 +72,10 @@ int lcpu_to_pcpu(const int lcpu)
 int pcpu_to_lcpu(const int pcpu)
 {
        int lcpu;
+
+       if (!map_cpuids)
+               return pcpu;
+
        BUG_ON(pcpu >= nr_cpu_ids || pcpu < 0);
        for (lcpu = 0; lcpu < nr_cpu_ids; ++lcpu) {
                if (__lcpu_to_pcpu[lcpu] == pcpu) {
@@ -114,6 +123,10 @@ GATOR_DEFINE_PROBE(cpu_migrate_current, TP_PROTO(u64 timestamp, u32 cpu_hwid))
 static int gator_migrate_start(void)
 {
        int retval = 0;
+
+       if (!map_cpuids)
+               return retval;
+
        if (retval == 0)
                retval = GATOR_REGISTER_TRACE(cpu_migrate_begin);
        if (retval == 0)
@@ -130,6 +143,9 @@ static int gator_migrate_start(void)
 
 static void gator_migrate_stop(void)
 {
+       if (!map_cpuids)
+               return;
+
        GATOR_UNREGISTER_TRACE(cpu_migrate_current);
        GATOR_UNREGISTER_TRACE(cpu_migrate_finish);
        GATOR_UNREGISTER_TRACE(cpu_migrate_begin);