4 * @remark Copyright 2004 Oprofile Authors
5 * @remark Read the file COPYING
7 * @author Zwane Mwaikambo
10 #include <linux/init.h>
11 #include <linux/oprofile.h>
12 #include <linux/errno.h>
13 #include <linux/sysdev.h>
14 #include <asm/semaphore.h>
16 #include "op_counter.h"
17 #include "op_arm_model.h"
19 static struct op_arm_model_spec *pmu_model;
20 static int pmu_enabled;
21 static struct semaphore pmu_sem;
23 struct op_counter_config counter_config[OP_MAX_COUNTER];
25 static int pmu_create_files(struct super_block *sb, struct dentry *root)
29 for (i = 0; i < pmu_model->num_counters; i++) {
33 snprintf(buf, sizeof buf, "%d", i);
34 dir = oprofilefs_mkdir(sb, root, buf);
35 oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled);
36 oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event);
37 oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count);
38 oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask);
39 oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel);
40 oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user);
46 static int pmu_setup(void)
50 spin_lock(&oprofilefs_lock);
51 ret = pmu_model->setup_ctrs();
52 spin_unlock(&oprofilefs_lock);
56 static int pmu_start(void)
62 ret = pmu_model->start();
69 static void pmu_stop(void)
79 static int pmu_suspend(struct sys_device *dev, pm_message_t state)
86 static int pmu_resume(struct sys_device *dev)
93 static struct sysdev_class oprofile_sysclass = {
94 set_kset_name("oprofile"),
96 .suspend = pmu_suspend,
99 static struct sys_device device_oprofile = {
101 .cls = &oprofile_sysclass,
104 static int __init init_driverfs(void)
108 if (!(ret = sysdev_class_register(&oprofile_sysclass)))
109 ret = sysdev_register(&device_oprofile);
114 static void exit_driverfs(void)
116 sysdev_unregister(&device_oprofile);
117 sysdev_class_unregister(&oprofile_sysclass);
120 #define init_driverfs() do { } while (0)
121 #define exit_driverfs() do { } while (0)
122 #endif /* CONFIG_PM */
124 int __init pmu_init(struct oprofile_operations *ops, struct op_arm_model_spec *spec)
126 init_MUTEX(&pmu_sem);
128 if (spec->init() < 0)
133 ops->create_files = pmu_create_files;
134 ops->setup = pmu_setup;
135 ops->shutdown = pmu_stop;
136 ops->start = pmu_start;
137 ops->stop = pmu_stop;
138 ops->cpu_type = pmu_model->name;
139 printk(KERN_INFO "oprofile: using %s PMU\n", spec->name);