Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh...
[pandora-kernel.git] / arch / arm / oprofile / common.c
index 6f8bc1f..0a007b9 100644 (file)
 #include <linux/init.h>
 #include <linux/oprofile.h>
 #include <linux/errno.h>
+#include <linux/slab.h>
 #include <linux/sysdev.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 
 #include "op_counter.h"
 #include "op_arm_model.h"
 
 static struct op_arm_model_spec *op_arm_model;
 static int op_arm_enabled;
-static struct semaphore op_arm_sem;
+static DEFINE_MUTEX(op_arm_mutex);
 
-struct op_counter_config counter_config[OP_MAX_COUNTER];
+struct op_counter_config *counter_config;
 
 static int op_arm_create_files(struct super_block *sb, struct dentry *root)
 {
@@ -28,7 +29,7 @@ static int op_arm_create_files(struct super_block *sb, struct dentry *root)
 
        for (i = 0; i < op_arm_model->num_counters; i++) {
                struct dentry *dir;
-               char buf[2];
+               char buf[4];
 
                snprintf(buf, sizeof buf, "%d", i);
                dir = oprofilefs_mkdir(sb, root, buf);
@@ -57,40 +58,40 @@ static int op_arm_start(void)
 {
        int ret = -EBUSY;
 
-       down(&op_arm_sem);
+       mutex_lock(&op_arm_mutex);
        if (!op_arm_enabled) {
                ret = op_arm_model->start();
                op_arm_enabled = !ret;
        }
-       up(&op_arm_sem);
+       mutex_unlock(&op_arm_mutex);
        return ret;
 }
 
 static void op_arm_stop(void)
 {
-       down(&op_arm_sem);
+       mutex_lock(&op_arm_mutex);
        if (op_arm_enabled)
                op_arm_model->stop();
        op_arm_enabled = 0;
-       up(&op_arm_sem);
+       mutex_unlock(&op_arm_mutex);
 }
 
 #ifdef CONFIG_PM
 static int op_arm_suspend(struct sys_device *dev, pm_message_t state)
 {
-       down(&op_arm_sem);
+       mutex_lock(&op_arm_mutex);
        if (op_arm_enabled)
                op_arm_model->stop();
-       up(&op_arm_sem);
+       mutex_unlock(&op_arm_mutex);
        return 0;
 }
 
 static int op_arm_resume(struct sys_device *dev)
 {
-       down(&op_arm_sem);
+       mutex_lock(&op_arm_mutex);
        if (op_arm_enabled && op_arm_model->start())
                op_arm_enabled = 0;
-       up(&op_arm_sem);
+       mutex_unlock(&op_arm_mutex);
        return 0;
 }
 
@@ -134,13 +135,24 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
        spec = &op_xscale_spec;
 #endif
 
-       if (spec) {
-               init_MUTEX(&op_arm_sem);
+#ifdef CONFIG_OPROFILE_ARMV6
+       spec = &op_armv6_spec;
+#endif
+
+#ifdef CONFIG_OPROFILE_MPCORE
+       spec = &op_mpcore_spec;
+#endif
 
+       if (spec) {
                ret = spec->init();
                if (ret < 0)
                        return ret;
 
+               counter_config = kcalloc(spec->num_counters, sizeof(struct op_counter_config),
+                                        GFP_KERNEL);
+               if (!counter_config)
+                       return -ENOMEM;
+
                op_arm_model = spec;
                init_driverfs();
                ops->create_files = op_arm_create_files;
@@ -162,5 +174,5 @@ void oprofile_arch_exit(void)
                exit_driverfs();
                op_arm_model = NULL;
        }
+       kfree(counter_config);
 }
-