blob: 75e889156f23b36567375209cb1a8470286b2ca8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * @file nmi_int.c
3 *
Robert Richteradf5ec02008-07-22 21:08:48 +02004 * @remark Copyright 2002-2008 OProfile authors
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * @remark Read the file COPYING
6 *
7 * @author John Levon <levon@movementarian.org>
Robert Richteradf5ec02008-07-22 21:08:48 +02008 * @author Robert Richter <robert.richter@amd.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
11#include <linux/init.h>
12#include <linux/notifier.h>
13#include <linux/smp.h>
14#include <linux/oprofile.h>
15#include <linux/sysdev.h>
16#include <linux/slab.h>
Andi Kleen1cfcea12006-07-10 17:06:21 +020017#include <linux/moduleparam.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070018#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/nmi.h>
20#include <asm/msr.h>
21#include <asm/apic.h>
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +010022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "op_counter.h"
24#include "op_x86_model.h"
Don Zickus2fbe7b22006-09-26 10:52:27 +020025
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +010026static struct op_x86_model_spec const *model;
Mike Travisd18d00f2008-03-25 15:06:59 -070027static DEFINE_PER_CPU(struct op_msrs, cpu_msrs);
28static DEFINE_PER_CPU(unsigned long, saved_lvtpc);
Don Zickus2fbe7b22006-09-26 10:52:27 +020029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int nmi_start(void);
31static void nmi_stop(void);
32
33/* 0 == registered but off, 1 == registered and on */
34static int nmi_enabled = 0;
35
36#ifdef CONFIG_PM
37
Pavel Machek438510f2005-04-16 15:25:24 -070038static int nmi_suspend(struct sys_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 if (nmi_enabled == 1)
41 nmi_stop();
42 return 0;
43}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static int nmi_resume(struct sys_device *dev)
46{
47 if (nmi_enabled == 1)
48 nmi_start();
49 return 0;
50}
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052static struct sysdev_class oprofile_sysclass = {
Kay Sieversaf5ca3f42007-12-20 02:09:39 +010053 .name = "oprofile",
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .resume = nmi_resume,
55 .suspend = nmi_suspend,
56};
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058static struct sys_device device_oprofile = {
59 .id = 0,
60 .cls = &oprofile_sysclass,
61};
62
Robert P. J. Day405ae7d2007-02-17 19:13:42 +010063static int __init init_sysfs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 int error;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +010066
67 error = sysdev_class_register(&oprofile_sysclass);
68 if (!error)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 error = sysdev_register(&device_oprofile);
70 return error;
71}
72
Robert P. J. Day405ae7d2007-02-17 19:13:42 +010073static void exit_sysfs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 sysdev_unregister(&device_oprofile);
76 sysdev_class_unregister(&oprofile_sysclass);
77}
78
79#else
Robert P. J. Day405ae7d2007-02-17 19:13:42 +010080#define init_sysfs() do { } while (0)
81#define exit_sysfs() do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#endif /* CONFIG_PM */
83
Adrian Bunkc7c19f82006-09-26 10:52:27 +020084static int profile_exceptions_notify(struct notifier_block *self,
85 unsigned long val, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Don Zickus2fbe7b22006-09-26 10:52:27 +020087 struct die_args *args = (struct die_args *)data;
88 int ret = NOTIFY_DONE;
89 int cpu = smp_processor_id();
90
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +010091 switch (val) {
Don Zickus2fbe7b22006-09-26 10:52:27 +020092 case DIE_NMI:
Mike Travisd18d00f2008-03-25 15:06:59 -070093 if (model->check_ctrs(args->regs, &per_cpu(cpu_msrs, cpu)))
Don Zickus2fbe7b22006-09-26 10:52:27 +020094 ret = NOTIFY_STOP;
95 break;
96 default:
97 break;
98 }
99 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
Don Zickus2fbe7b22006-09-26 10:52:27 +0200101
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100102static void nmi_cpu_save_registers(struct op_msrs *msrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 unsigned int const nr_ctrs = model->num_counters;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100105 unsigned int const nr_ctrls = model->num_controls;
106 struct op_msr *counters = msrs->counters;
107 struct op_msr *controls = msrs->controls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 unsigned int i;
109
110 for (i = 0; i < nr_ctrs; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100111 if (counters[i].addr) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200112 rdmsr(counters[i].addr,
113 counters[i].saved.low,
114 counters[i].saved.high);
115 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 for (i = 0; i < nr_ctrls; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100119 if (controls[i].addr) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200120 rdmsr(controls[i].addr,
121 controls[i].saved.low,
122 controls[i].saved.high);
123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125}
126
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100127static void nmi_save_registers(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 int cpu = smp_processor_id();
Mike Travisd18d00f2008-03-25 15:06:59 -0700130 struct op_msrs *msrs = &per_cpu(cpu_msrs, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 nmi_cpu_save_registers(msrs);
132}
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134static void free_msrs(void)
135{
136 int i;
KAMEZAWA Hiroyukic89125992006-03-28 01:56:39 -0800137 for_each_possible_cpu(i) {
Mike Travisd18d00f2008-03-25 15:06:59 -0700138 kfree(per_cpu(cpu_msrs, i).counters);
139 per_cpu(cpu_msrs, i).counters = NULL;
140 kfree(per_cpu(cpu_msrs, i).controls);
141 per_cpu(cpu_msrs, i).controls = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
143}
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145static int allocate_msrs(void)
146{
147 int success = 1;
148 size_t controls_size = sizeof(struct op_msr) * model->num_controls;
149 size_t counters_size = sizeof(struct op_msr) * model->num_counters;
150
151 int i;
Chris Wright0939c172007-06-01 00:46:39 -0700152 for_each_possible_cpu(i) {
Mike Travisd18d00f2008-03-25 15:06:59 -0700153 per_cpu(cpu_msrs, i).counters = kmalloc(counters_size,
154 GFP_KERNEL);
155 if (!per_cpu(cpu_msrs, i).counters) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 success = 0;
157 break;
158 }
Mike Travisd18d00f2008-03-25 15:06:59 -0700159 per_cpu(cpu_msrs, i).controls = kmalloc(controls_size,
160 GFP_KERNEL);
161 if (!per_cpu(cpu_msrs, i).controls) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 success = 0;
163 break;
164 }
165 }
166
167 if (!success)
168 free_msrs();
169
170 return success;
171}
172
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100173static void nmi_cpu_setup(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
175 int cpu = smp_processor_id();
Mike Travisd18d00f2008-03-25 15:06:59 -0700176 struct op_msrs *msrs = &per_cpu(cpu_msrs, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 spin_lock(&oprofilefs_lock);
178 model->setup_ctrs(msrs);
179 spin_unlock(&oprofilefs_lock);
Mike Travisd18d00f2008-03-25 15:06:59 -0700180 per_cpu(saved_lvtpc, cpu) = apic_read(APIC_LVTPC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 apic_write(APIC_LVTPC, APIC_DM_NMI);
182}
183
Don Zickus2fbe7b22006-09-26 10:52:27 +0200184static struct notifier_block profile_exceptions_nb = {
185 .notifier_call = profile_exceptions_notify,
186 .next = NULL,
187 .priority = 0
188};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190static int nmi_setup(void)
191{
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100192 int err = 0;
Andi Kleen6c977aa2007-05-21 14:31:45 +0200193 int cpu;
Don Zickus2fbe7b22006-09-26 10:52:27 +0200194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 if (!allocate_msrs())
196 return -ENOMEM;
197
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100198 err = register_die_notifier(&profile_exceptions_nb);
199 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 free_msrs();
Don Zickus2fbe7b22006-09-26 10:52:27 +0200201 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
Don Zickus2fbe7b22006-09-26 10:52:27 +0200203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 /* We need to serialize save and setup for HT because the subset
205 * of msrs are distinct for save and setup operations
206 */
Andi Kleen6c977aa2007-05-21 14:31:45 +0200207
208 /* Assume saved/restored counters are the same on all CPUs */
Mike Travisd18d00f2008-03-25 15:06:59 -0700209 model->fill_in_addresses(&per_cpu(cpu_msrs, 0));
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100210 for_each_possible_cpu(cpu) {
Chris Wright0939c172007-06-01 00:46:39 -0700211 if (cpu != 0) {
Mike Travisd18d00f2008-03-25 15:06:59 -0700212 memcpy(per_cpu(cpu_msrs, cpu).counters,
213 per_cpu(cpu_msrs, 0).counters,
Chris Wright0939c172007-06-01 00:46:39 -0700214 sizeof(struct op_msr) * model->num_counters);
215
Mike Travisd18d00f2008-03-25 15:06:59 -0700216 memcpy(per_cpu(cpu_msrs, cpu).controls,
217 per_cpu(cpu_msrs, 0).controls,
Chris Wright0939c172007-06-01 00:46:39 -0700218 sizeof(struct op_msr) * model->num_controls);
219 }
220
Andi Kleen6c977aa2007-05-21 14:31:45 +0200221 }
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200222 on_each_cpu(nmi_save_registers, NULL, 1);
223 on_each_cpu(nmi_cpu_setup, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 nmi_enabled = 1;
225 return 0;
226}
227
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100228static void nmi_restore_registers(struct op_msrs *msrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
230 unsigned int const nr_ctrs = model->num_counters;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100231 unsigned int const nr_ctrls = model->num_controls;
232 struct op_msr *counters = msrs->counters;
233 struct op_msr *controls = msrs->controls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 unsigned int i;
235
236 for (i = 0; i < nr_ctrls; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100237 if (controls[i].addr) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200238 wrmsr(controls[i].addr,
239 controls[i].saved.low,
240 controls[i].saved.high);
241 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 for (i = 0; i < nr_ctrs; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100245 if (counters[i].addr) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200246 wrmsr(counters[i].addr,
247 counters[i].saved.low,
248 counters[i].saved.high);
249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100253static void nmi_cpu_shutdown(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 unsigned int v;
256 int cpu = smp_processor_id();
Mike Travisd18d00f2008-03-25 15:06:59 -0700257 struct op_msrs *msrs = &__get_cpu_var(cpu_msrs);
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 /* restoring APIC_LVTPC can trigger an apic error because the delivery
260 * mode and vector nr combination can be illegal. That's by design: on
261 * power on apic lvt contain a zero vector nr which are legal only for
262 * NMI delivery mode. So inhibit apic err before restoring lvtpc
263 */
264 v = apic_read(APIC_LVTERR);
265 apic_write(APIC_LVTERR, v | APIC_LVT_MASKED);
Mike Travisd18d00f2008-03-25 15:06:59 -0700266 apic_write(APIC_LVTPC, per_cpu(saved_lvtpc, cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 apic_write(APIC_LVTERR, v);
268 nmi_restore_registers(msrs);
269}
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271static void nmi_shutdown(void)
272{
Vegard Nossum93e1ade2008-06-22 09:40:18 +0200273 struct op_msrs *msrs = &get_cpu_var(cpu_msrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 nmi_enabled = 0;
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200275 on_each_cpu(nmi_cpu_shutdown, NULL, 1);
Don Zickus2fbe7b22006-09-26 10:52:27 +0200276 unregister_die_notifier(&profile_exceptions_nb);
Mike Travisd18d00f2008-03-25 15:06:59 -0700277 model->shutdown(msrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 free_msrs();
Vegard Nossum93e1ade2008-06-22 09:40:18 +0200279 put_cpu_var(cpu_msrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100282static void nmi_cpu_start(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Mike Travisd18d00f2008-03-25 15:06:59 -0700284 struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 model->start(msrs);
286}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288static int nmi_start(void)
289{
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200290 on_each_cpu(nmi_cpu_start, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 return 0;
292}
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100293
294static void nmi_cpu_stop(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Mike Travisd18d00f2008-03-25 15:06:59 -0700296 struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 model->stop(msrs);
298}
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300static void nmi_stop(void)
301{
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200302 on_each_cpu(nmi_cpu_stop, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305struct op_counter_config counter_config[OP_MAX_COUNTER];
306
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100307static int nmi_create_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
309 unsigned int i;
310
311 for (i = 0; i < model->num_counters; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100312 struct dentry *dir;
Markus Armbruster0c6856f2006-06-26 00:24:34 -0700313 char buf[4];
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100314
315 /* quick little hack to _not_ expose a counter if it is not
Don Zickuscb9c4482006-09-26 10:52:26 +0200316 * available for use. This should protect userspace app.
317 * NOTE: assumes 1:1 mapping here (that counters are organized
318 * sequentially in their struct assignment).
319 */
320 if (unlikely(!avail_to_resrv_perfctr_nmi_bit(i)))
321 continue;
322
Markus Armbruster0c6856f2006-06-26 00:24:34 -0700323 snprintf(buf, sizeof(buf), "%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 dir = oprofilefs_mkdir(sb, root, buf);
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100325 oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled);
326 oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event);
327 oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count);
328 oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask);
329 oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel);
330 oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 }
332
333 return 0;
334}
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100335
Andi Kleen1cfcea12006-07-10 17:06:21 +0200336static int p4force;
337module_param(p4force, int, 0);
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100338
339static int __init p4_init(char **cpu_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
341 __u8 cpu_model = boot_cpu_data.x86_model;
342
Andi Kleen1cfcea12006-07-10 17:06:21 +0200343 if (!p4force && (cpu_model > 6 || cpu_model == 5))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return 0;
345
346#ifndef CONFIG_SMP
347 *cpu_type = "i386/p4";
348 model = &op_p4_spec;
349 return 1;
350#else
351 switch (smp_num_siblings) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100352 case 1:
353 *cpu_type = "i386/p4";
354 model = &op_p4_spec;
355 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100357 case 2:
358 *cpu_type = "i386/p4-ht";
359 model = &op_p4_ht2_spec;
360 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362#endif
363
364 printk(KERN_INFO "oprofile: P4 HyperThreading detected with > 2 threads\n");
365 printk(KERN_INFO "oprofile: Reverting to timer mode.\n");
366 return 0;
367}
368
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100369static int __init ppro_init(char **cpu_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
371 __u8 cpu_model = boot_cpu_data.x86_model;
372
Linus Torvalds4b9f12a2008-07-24 17:29:00 -0700373 switch (cpu_model) {
374 case 0 ... 2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 *cpu_type = "i386/ppro";
Linus Torvalds4b9f12a2008-07-24 17:29:00 -0700376 break;
377 case 3 ... 5:
378 *cpu_type = "i386/pii";
379 break;
380 case 6 ... 8:
381 *cpu_type = "i386/piii";
382 break;
383 case 9:
384 *cpu_type = "i386/p6_mobile";
385 break;
386 case 10 ... 13:
387 *cpu_type = "i386/p6";
388 break;
389 case 14:
390 *cpu_type = "i386/core";
391 break;
392 case 15: case 23:
393 *cpu_type = "i386/core_2";
394 break;
395 case 26:
396 *cpu_type = "i386/core_2";
397 break;
398 default:
399 /* Unknown */
400 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402
403 model = &op_ppro_spec;
404 return 1;
405}
406
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100407/* in order to get sysfs right */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408static int using_nmi;
409
David Gibson96d08212005-09-06 15:17:26 -0700410int __init op_nmi_init(struct oprofile_operations *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
412 __u8 vendor = boot_cpu_data.x86_vendor;
413 __u8 family = boot_cpu_data.x86;
414 char *cpu_type;
Robert Richteradf5ec02008-07-22 21:08:48 +0200415 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 if (!cpu_has_apic)
418 return -ENODEV;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 switch (vendor) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100421 case X86_VENDOR_AMD:
422 /* Needs to be at least an Athlon (or hammer in 32bit mode) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100424 switch (family) {
425 default:
426 return -ENODEV;
427 case 6:
428 model = &op_athlon_spec;
429 cpu_type = "i386/athlon";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 break;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100431 case 0xf:
432 model = &op_athlon_spec;
433 /* Actually it could be i386/hammer too, but give
434 user space an consistent name. */
435 cpu_type = "x86-64/hammer";
436 break;
437 case 0x10:
438 model = &op_athlon_spec;
439 cpu_type = "x86-64/family10";
440 break;
Barry Kasindorf12f2b262008-07-22 21:08:47 +0200441 case 0x11:
442 model = &op_athlon_spec;
443 cpu_type = "x86-64/family11h";
444 break;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100445 }
446 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100448 case X86_VENDOR_INTEL:
449 switch (family) {
450 /* Pentium IV */
451 case 0xf:
452 if (!p4_init(&cpu_type))
453 return -ENODEV;
454 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100456 /* A P6-class processor */
457 case 6:
458 if (!ppro_init(&cpu_type))
459 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 break;
461
462 default:
463 return -ENODEV;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100464 }
465 break;
466
467 default:
468 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
470
Robert Richteradf5ec02008-07-22 21:08:48 +0200471 if (model->init)
472 ret = model->init(ops);
473 if (ret)
474 return ret;
475
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100476 init_sysfs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 using_nmi = 1;
478 ops->create_files = nmi_create_files;
479 ops->setup = nmi_setup;
480 ops->shutdown = nmi_shutdown;
481 ops->start = nmi_start;
482 ops->stop = nmi_stop;
483 ops->cpu_type = cpu_type;
484 printk(KERN_INFO "oprofile: using NMI interrupt.\n");
485 return 0;
486}
487
David Gibson96d08212005-09-06 15:17:26 -0700488void op_nmi_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
490 if (using_nmi)
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100491 exit_sysfs();
Robert Richteradf5ec02008-07-22 21:08:48 +0200492 if (model->exit)
493 model->exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}