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 <asm/semaphore.h>
15 #include "op_counter.h"
16 #include "op_arm_model.h"
18 static struct op_arm_model_spec *pmu_model;
19 static int pmu_enabled;
20 static struct semaphore pmu_sem;
22 static int pmu_start(void);
23 static int pmu_setup(void);
24 static void pmu_stop(void);
25 static int pmu_create_files(struct super_block *, struct dentry *);
27 static struct oprofile_operations pmu_ops = {
28 .create_files = pmu_create_files,
36 static struct sys_device device_oprofile = {
38 .cls = &oprofile_sysclass,
41 static int __init init_driverfs(void)
45 if (!(ret = sysdev_class_register(&oprofile_sysclass)))
46 ret = sys_device_register(&device_oprofile);
51 static void __exit exit_driverfs(void)
53 sys_device_unregister(&device_oprofile);
54 sysdev_class_unregister(&oprofile_sysclass);
57 #define init_driverfs() do { } while (0)
58 #define exit_driverfs() do { } while (0)
59 #endif /* CONFIG_PM */
61 struct op_counter_config counter_config[OP_MAX_COUNTER];
63 static int pmu_create_files(struct super_block *sb, struct dentry *root)
67 for (i = 0; i < pmu_model->num_counters; i++) {
71 snprintf(buf, sizeof buf, "%d", i);
72 dir = oprofilefs_mkdir(sb, root, buf);
73 oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled);
74 oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event);
75 oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count);
76 oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask);
77 oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel);
78 oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user);
84 static int pmu_setup(void)
88 spin_lock(&oprofilefs_lock);
89 ret = pmu_model->setup_ctrs();
90 spin_unlock(&oprofilefs_lock);
94 static int pmu_start(void)
100 ret = pmu_model->start();
107 static void pmu_stop(void)
116 int __init pmu_init(struct oprofile_operations **ops, struct op_arm_model_spec *spec)
118 init_MUTEX(&pmu_sem);
120 if (spec->init() < 0)
126 pmu_ops.cpu_type = pmu_model->name;
127 printk(KERN_INFO "oprofile: using %s PMU\n", spec->name);