blob: 90193b1538a03d3545c8015cb21768e0ea881dc9 [file] [log] [blame]
Paolo Ciarrocchid4413732008-02-19 23:51:27 +01001/*
Robert Richteradf5ec02008-07-22 21:08:48 +02002 * @file op_model_athlon.c
Barry Kasindorfbd87f1f2007-12-18 18:05:58 +01003 * athlon / K7 / K8 / Family 10h model-specific MSR operations
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Robert Richteradf5ec02008-07-22 21:08:48 +02005 * @remark Copyright 2002-2008 OProfile authors
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * @remark Read the file COPYING
7 *
8 * @author John Levon
9 * @author Philippe Elie
10 * @author Graydon Hoare
Robert Richteradf5ec02008-07-22 21:08:48 +020011 * @author Robert Richter <robert.richter@amd.com>
Barry Kasindorf56784f12008-07-22 21:08:55 +020012 * @author Barry Kasindorf
Robert Richteradf5ec02008-07-22 21:08:48 +020013*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include <linux/oprofile.h>
Barry Kasindorf56784f12008-07-22 21:08:55 +020016#include <linux/device.h>
17#include <linux/pci.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/ptrace.h>
20#include <asm/msr.h>
Don Zickus3e4ff112006-06-26 13:57:01 +020021#include <asm/nmi.h>
Paolo Ciarrocchid4413732008-02-19 23:51:27 +010022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "op_x86_model.h"
24#include "op_counter.h"
25
26#define NUM_COUNTERS 4
27#define NUM_CONTROLS 4
28
Paolo Ciarrocchid4413732008-02-19 23:51:27 +010029#define CTR_IS_RESERVED(msrs, c) (msrs->counters[(c)].addr ? 1 : 0)
30#define CTR_READ(l, h, msrs, c) do {rdmsr(msrs->counters[(c)].addr, (l), (h)); } while (0)
31#define CTR_WRITE(l, msrs, c) do {wrmsr(msrs->counters[(c)].addr, -(unsigned int)(l), -1); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define CTR_OVERFLOWED(n) (!((n) & (1U<<31)))
33
Paolo Ciarrocchid4413732008-02-19 23:51:27 +010034#define CTRL_IS_RESERVED(msrs, c) (msrs->controls[(c)].addr ? 1 : 0)
35#define CTRL_READ(l, h, msrs, c) do {rdmsr(msrs->controls[(c)].addr, (l), (h)); } while (0)
36#define CTRL_WRITE(l, h, msrs, c) do {wrmsr(msrs->controls[(c)].addr, (l), (h)); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#define CTRL_SET_ACTIVE(n) (n |= (1<<22))
38#define CTRL_SET_INACTIVE(n) (n &= ~(1<<22))
Barry Kasindorfbd87f1f2007-12-18 18:05:58 +010039#define CTRL_CLEAR_LO(x) (x &= (1<<21))
40#define CTRL_CLEAR_HI(x) (x &= 0xfffffcf0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define CTRL_SET_ENABLE(val) (val |= 1<<20)
Paolo Ciarrocchid4413732008-02-19 23:51:27 +010042#define CTRL_SET_USR(val, u) (val |= ((u & 1) << 16))
43#define CTRL_SET_KERN(val, k) (val |= ((k & 1) << 17))
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define CTRL_SET_UM(val, m) (val |= (m << 8))
Barry Kasindorfbd87f1f2007-12-18 18:05:58 +010045#define CTRL_SET_EVENT_LOW(val, e) (val |= (e & 0xff))
46#define CTRL_SET_EVENT_HIGH(val, e) (val |= ((e >> 8) & 0xf))
47#define CTRL_SET_HOST_ONLY(val, h) (val |= ((h & 1) << 9))
48#define CTRL_SET_GUEST_ONLY(val, h) (val |= ((h & 1) << 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Barry Kasindorf56784f12008-07-22 21:08:55 +020050#define IBS_FETCH_CTL_HIGH_MASK 0xFFFFFFFF
51/* high dword bit IbsFetchCtl[bit 49] */
52#define IBS_FETCH_VALID_BIT (1UL << 17)
53/* high dword bit IbsFetchCtl[bit 52] */
54#define IBS_FETCH_PHY_ADDR_VALID_BIT (1UL << 20)
55/* high dword bit IbsFetchCtl[bit 48] */
56#define IBS_FETCH_ENABLE (1UL << 16)
57
58#define IBS_FETCH_CTL_CNT_MASK 0x00000000FFFF0000UL
59#define IBS_FETCH_CTL_MAX_CNT_MASK 0x000000000000FFFFUL
60
61/*IbsOpCtl masks/bits */
62#define IBS_OP_VALID_BIT (1ULL<<18) /* IbsOpCtl[bit18] */
63#define IBS_OP_ENABLE (1ULL<<17) /* IBS_OP_ENABLE[bit17]*/
64
65/* Codes used in cpu_buffer.c */
66#define IBS_FETCH_BEGIN 3
67#define IBS_OP_BEGIN 4
68
69/*IbsOpData3 masks */
70#define IBS_CTL_LVT_OFFSET_VALID_BIT (1ULL<<8)
71
72/*PCI Extended Configuration Constants */
73/* MSR to set the IBS control register APIC LVT offset */
74#define IBS_LVT_OFFSET_PCI 0x1CC
75
76struct ibs_fetch_sample {
77 /* MSRC001_1031 IBS Fetch Linear Address Register */
78 unsigned int ibs_fetch_lin_addr_low;
79 unsigned int ibs_fetch_lin_addr_high;
80 /* MSRC001_1030 IBS Fetch Control Register */
81 unsigned int ibs_fetch_ctl_low;
82 unsigned int ibs_fetch_ctl_high;
83 /* MSRC001_1032 IBS Fetch Physical Address Register */
84 unsigned int ibs_fetch_phys_addr_low;
85 unsigned int ibs_fetch_phys_addr_high;
86};
87
88struct ibs_op_sample {
89 /* MSRC001_1034 IBS Op Logical Address Register (IbsRIP) */
90 unsigned int ibs_op_rip_low;
91 unsigned int ibs_op_rip_high;
92 /* MSRC001_1035 IBS Op Data Register */
93 unsigned int ibs_op_data1_low;
94 unsigned int ibs_op_data1_high;
95 /* MSRC001_1036 IBS Op Data 2 Register */
96 unsigned int ibs_op_data2_low;
97 unsigned int ibs_op_data2_high;
98 /* MSRC001_1037 IBS Op Data 3 Register */
99 unsigned int ibs_op_data3_low;
100 unsigned int ibs_op_data3_high;
101 /* MSRC001_1038 IBS DC Linear Address Register (IbsDcLinAd) */
102 unsigned int ibs_dc_linear_low;
103 unsigned int ibs_dc_linear_high;
104 /* MSRC001_1039 IBS DC Physical Address Register (IbsDcPhysAd) */
105 unsigned int ibs_dc_phys_low;
106 unsigned int ibs_dc_phys_high;
107};
108
109/*
110 * unitialize the APIC for the IBS interrupts if needed on AMD Family10h+
111*/
112static void clear_ibs_nmi(void);
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static unsigned long reset_value[NUM_COUNTERS];
Barry Kasindorf56784f12008-07-22 21:08:55 +0200115static int ibs_allowed; /* AMD Family10h and later */
116
117struct op_ibs_config {
118 unsigned long op_enabled;
119 unsigned long fetch_enabled;
120 unsigned long max_cnt_fetch;
121 unsigned long max_cnt_op;
122 unsigned long rand_en;
123 unsigned long dispatched_ops;
124};
125
126static struct op_ibs_config ibs_config;
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100127
Robert Richter6657fe42008-07-22 21:08:50 +0200128/* functions for op_amd_spec */
Robert Richterdfa15422008-07-22 21:08:49 +0200129
Robert Richter6657fe42008-07-22 21:08:50 +0200130static void op_amd_fill_in_addresses(struct op_msrs * const msrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Don Zickuscb9c4482006-09-26 10:52:26 +0200132 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100134 for (i = 0; i < NUM_COUNTERS; i++) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200135 if (reserve_perfctr_nmi(MSR_K7_PERFCTR0 + i))
136 msrs->counters[i].addr = MSR_K7_PERFCTR0 + i;
137 else
138 msrs->counters[i].addr = 0;
139 }
140
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100141 for (i = 0; i < NUM_CONTROLS; i++) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200142 if (reserve_evntsel_nmi(MSR_K7_EVNTSEL0 + i))
143 msrs->controls[i].addr = MSR_K7_EVNTSEL0 + i;
144 else
145 msrs->controls[i].addr = 0;
146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100149
Robert Richter6657fe42008-07-22 21:08:50 +0200150static void op_amd_setup_ctrs(struct op_msrs const * const msrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
152 unsigned int low, high;
153 int i;
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 /* clear all counters */
156 for (i = 0 ; i < NUM_CONTROLS; ++i) {
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100157 if (unlikely(!CTRL_IS_RESERVED(msrs, i)))
Don Zickuscb9c4482006-09-26 10:52:26 +0200158 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 CTRL_READ(low, high, msrs, i);
Barry Kasindorfbd87f1f2007-12-18 18:05:58 +0100160 CTRL_CLEAR_LO(low);
161 CTRL_CLEAR_HI(high);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 CTRL_WRITE(low, high, msrs, i);
163 }
Don Zickuscb9c4482006-09-26 10:52:26 +0200164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /* avoid a false detection of ctr overflows in NMI handler */
166 for (i = 0; i < NUM_COUNTERS; ++i) {
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100167 if (unlikely(!CTR_IS_RESERVED(msrs, i)))
Don Zickuscb9c4482006-09-26 10:52:26 +0200168 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 CTR_WRITE(1, msrs, i);
170 }
171
172 /* enable active counters */
173 for (i = 0; i < NUM_COUNTERS; ++i) {
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100174 if ((counter_config[i].enabled) && (CTR_IS_RESERVED(msrs, i))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 reset_value[i] = counter_config[i].count;
176
177 CTR_WRITE(counter_config[i].count, msrs, i);
178
179 CTRL_READ(low, high, msrs, i);
Barry Kasindorfbd87f1f2007-12-18 18:05:58 +0100180 CTRL_CLEAR_LO(low);
181 CTRL_CLEAR_HI(high);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 CTRL_SET_ENABLE(low);
183 CTRL_SET_USR(low, counter_config[i].user);
184 CTRL_SET_KERN(low, counter_config[i].kernel);
185 CTRL_SET_UM(low, counter_config[i].unit_mask);
Barry Kasindorfbd87f1f2007-12-18 18:05:58 +0100186 CTRL_SET_EVENT_LOW(low, counter_config[i].event);
187 CTRL_SET_EVENT_HIGH(high, counter_config[i].event);
188 CTRL_SET_HOST_ONLY(high, 0);
189 CTRL_SET_GUEST_ONLY(high, 0);
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 CTRL_WRITE(low, high, msrs, i);
192 } else {
193 reset_value[i] = 0;
194 }
195 }
196}
197
Robert Richter7939d2b2008-07-22 21:08:56 +0200198static inline int
199op_amd_handle_ibs(struct pt_regs * const regs,
200 struct op_msrs const * const msrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
202 unsigned int low, high;
Barry Kasindorf56784f12008-07-22 21:08:55 +0200203 struct ibs_fetch_sample ibs_fetch;
204 struct ibs_op_sample ibs_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Robert Richter7939d2b2008-07-22 21:08:56 +0200206 if (!ibs_allowed)
207 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Robert Richter7939d2b2008-07-22 21:08:56 +0200209 if (ibs_config.fetch_enabled) {
Barry Kasindorf56784f12008-07-22 21:08:55 +0200210 rdmsr(MSR_AMD64_IBSFETCHCTL, low, high);
211 if (high & IBS_FETCH_VALID_BIT) {
212 ibs_fetch.ibs_fetch_ctl_high = high;
213 ibs_fetch.ibs_fetch_ctl_low = low;
214 rdmsr(MSR_AMD64_IBSFETCHLINAD, low, high);
215 ibs_fetch.ibs_fetch_lin_addr_high = high;
216 ibs_fetch.ibs_fetch_lin_addr_low = low;
217 rdmsr(MSR_AMD64_IBSFETCHPHYSAD, low, high);
218 ibs_fetch.ibs_fetch_phys_addr_high = high;
219 ibs_fetch.ibs_fetch_phys_addr_low = low;
220
221 oprofile_add_ibs_sample(regs,
222 (unsigned int *)&ibs_fetch,
223 IBS_FETCH_BEGIN);
224
225 /*reenable the IRQ */
226 rdmsr(MSR_AMD64_IBSFETCHCTL, low, high);
227 high &= ~(IBS_FETCH_VALID_BIT);
228 high |= IBS_FETCH_ENABLE;
229 low &= IBS_FETCH_CTL_MAX_CNT_MASK;
230 wrmsr(MSR_AMD64_IBSFETCHCTL, low, high);
231 }
232 }
233
Robert Richter7939d2b2008-07-22 21:08:56 +0200234 if (ibs_config.op_enabled) {
Barry Kasindorf56784f12008-07-22 21:08:55 +0200235 rdmsr(MSR_AMD64_IBSOPCTL, low, high);
236 if (low & IBS_OP_VALID_BIT) {
237 rdmsr(MSR_AMD64_IBSOPRIP, low, high);
238 ibs_op.ibs_op_rip_low = low;
239 ibs_op.ibs_op_rip_high = high;
240 rdmsr(MSR_AMD64_IBSOPDATA, low, high);
241 ibs_op.ibs_op_data1_low = low;
242 ibs_op.ibs_op_data1_high = high;
243 rdmsr(MSR_AMD64_IBSOPDATA2, low, high);
244 ibs_op.ibs_op_data2_low = low;
245 ibs_op.ibs_op_data2_high = high;
246 rdmsr(MSR_AMD64_IBSOPDATA3, low, high);
247 ibs_op.ibs_op_data3_low = low;
248 ibs_op.ibs_op_data3_high = high;
249 rdmsr(MSR_AMD64_IBSDCLINAD, low, high);
250 ibs_op.ibs_dc_linear_low = low;
251 ibs_op.ibs_dc_linear_high = high;
252 rdmsr(MSR_AMD64_IBSDCPHYSAD, low, high);
253 ibs_op.ibs_dc_phys_low = low;
254 ibs_op.ibs_dc_phys_high = high;
255
256 /* reenable the IRQ */
257 oprofile_add_ibs_sample(regs,
258 (unsigned int *)&ibs_op,
259 IBS_OP_BEGIN);
260 rdmsr(MSR_AMD64_IBSOPCTL, low, high);
261 low &= ~(IBS_OP_VALID_BIT);
262 low |= IBS_OP_ENABLE;
263 wrmsr(MSR_AMD64_IBSOPCTL, low, high);
264 }
265 }
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 return 1;
268}
269
Robert Richter7939d2b2008-07-22 21:08:56 +0200270static int op_amd_check_ctrs(struct pt_regs * const regs,
271 struct op_msrs const * const msrs)
272{
273 unsigned int low, high;
274 int i;
275
276 for (i = 0 ; i < NUM_COUNTERS; ++i) {
277 if (!reset_value[i])
278 continue;
279 CTR_READ(low, high, msrs, i);
280 if (CTR_OVERFLOWED(low)) {
281 oprofile_add_sample(regs, i);
282 CTR_WRITE(reset_value[i], msrs, i);
283 }
284 }
285
286 op_amd_handle_ibs(regs, msrs);
287
288 /* See op_model_ppro.c */
289 return 1;
290}
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100291
Robert Richter6657fe42008-07-22 21:08:50 +0200292static void op_amd_start(struct op_msrs const * const msrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
294 unsigned int low, high;
295 int i;
296 for (i = 0 ; i < NUM_COUNTERS ; ++i) {
297 if (reset_value[i]) {
298 CTRL_READ(low, high, msrs, i);
299 CTRL_SET_ACTIVE(low);
300 CTRL_WRITE(low, high, msrs, i);
301 }
302 }
Barry Kasindorf56784f12008-07-22 21:08:55 +0200303 if (ibs_allowed && ibs_config.fetch_enabled) {
304 low = (ibs_config.max_cnt_fetch >> 4) & 0xFFFF;
305 high = IBS_FETCH_ENABLE;
306 wrmsr(MSR_AMD64_IBSFETCHCTL, low, high);
307 }
308
309 if (ibs_allowed && ibs_config.op_enabled) {
310 low = ((ibs_config.max_cnt_op >> 4) & 0xFFFF) + IBS_OP_ENABLE;
311 high = 0;
312 wrmsr(MSR_AMD64_IBSOPCTL, low, high);
313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
316
Robert Richter6657fe42008-07-22 21:08:50 +0200317static void op_amd_stop(struct op_msrs const * const msrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100319 unsigned int low, high;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 int i;
321
322 /* Subtle: stop on all counters to avoid race with
323 * setting our pm callback */
324 for (i = 0 ; i < NUM_COUNTERS ; ++i) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200325 if (!reset_value[i])
326 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 CTRL_READ(low, high, msrs, i);
328 CTRL_SET_INACTIVE(low);
329 CTRL_WRITE(low, high, msrs, i);
330 }
Barry Kasindorf56784f12008-07-22 21:08:55 +0200331
332 if (ibs_allowed && ibs_config.fetch_enabled) {
333 low = 0; /* clear max count and enable */
334 high = 0;
335 wrmsr(MSR_AMD64_IBSFETCHCTL, low, high);
336 }
337
338 if (ibs_allowed && ibs_config.op_enabled) {
339 low = 0; /* clear max count and enable */
340 high = 0;
341 wrmsr(MSR_AMD64_IBSOPCTL, low, high);
342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
Robert Richter6657fe42008-07-22 21:08:50 +0200345static void op_amd_shutdown(struct op_msrs const * const msrs)
Don Zickuscb9c4482006-09-26 10:52:26 +0200346{
347 int i;
348
349 for (i = 0 ; i < NUM_COUNTERS ; ++i) {
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100350 if (CTR_IS_RESERVED(msrs, i))
Don Zickuscb9c4482006-09-26 10:52:26 +0200351 release_perfctr_nmi(MSR_K7_PERFCTR0 + i);
352 }
353 for (i = 0 ; i < NUM_CONTROLS ; ++i) {
Paolo Ciarrocchid4413732008-02-19 23:51:27 +0100354 if (CTRL_IS_RESERVED(msrs, i))
Don Zickuscb9c4482006-09-26 10:52:26 +0200355 release_evntsel_nmi(MSR_K7_EVNTSEL0 + i);
356 }
357}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Robert Richter7d77f2d2008-07-22 21:08:57 +0200359static u8 ibs_eilvt_off;
360
Barry Kasindorf56784f12008-07-22 21:08:55 +0200361static inline void apic_init_ibs_nmi_per_cpu(void *arg)
362{
Robert Richter7d77f2d2008-07-22 21:08:57 +0200363 ibs_eilvt_off = setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_NMI, 0);
Barry Kasindorf56784f12008-07-22 21:08:55 +0200364}
365
366static inline void apic_clear_ibs_nmi_per_cpu(void *arg)
367{
368 setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1);
369}
370
Robert Richter7d77f2d2008-07-22 21:08:57 +0200371static int pfm_amd64_setup_eilvt(void)
372{
373#define IBSCTL_LVTOFFSETVAL (1 << 8)
374#define IBSCTL 0x1cc
375 struct pci_dev *cpu_cfg;
376 int nodes;
377 u32 value = 0;
378
379 /* per CPU setup */
380 on_each_cpu(apic_init_ibs_nmi_per_cpu, NULL, 0, 1);
381
382 nodes = 0;
383 cpu_cfg = NULL;
384 do {
385 cpu_cfg = pci_get_device(PCI_VENDOR_ID_AMD,
386 PCI_DEVICE_ID_AMD_10H_NB_MISC,
387 cpu_cfg);
388 if (!cpu_cfg)
389 break;
390 ++nodes;
391 pci_write_config_dword(cpu_cfg, IBSCTL, ibs_eilvt_off
392 | IBSCTL_LVTOFFSETVAL);
393 pci_read_config_dword(cpu_cfg, IBSCTL, &value);
394 if (value != (ibs_eilvt_off | IBSCTL_LVTOFFSETVAL)) {
395 printk(KERN_DEBUG "Failed to setup IBS LVT offset, "
396 "IBSCTL = 0x%08x", value);
397 return 1;
398 }
399 } while (1);
400
401 if (!nodes) {
402 printk(KERN_DEBUG "No CPU node configured for IBS");
403 return 1;
404 }
405
406#ifdef CONFIG_NUMA
407 /* Sanity check */
408 /* Works only for 64bit with proper numa implementation. */
409 if (nodes != num_possible_nodes()) {
410 printk(KERN_DEBUG "Failed to setup CPU node(s) for IBS, "
411 "found: %d, expected %d",
412 nodes, num_possible_nodes());
413 return 1;
414 }
415#endif
416 return 0;
417}
418
Barry Kasindorf56784f12008-07-22 21:08:55 +0200419/*
420 * initialize the APIC for the IBS interrupts
Robert Richter7d77f2d2008-07-22 21:08:57 +0200421 * if available (AMD Family10h rev B0 and later)
Barry Kasindorf56784f12008-07-22 21:08:55 +0200422 */
423static void setup_ibs(void)
424{
Barry Kasindorf56784f12008-07-22 21:08:55 +0200425 ibs_allowed = boot_cpu_has(X86_FEATURE_IBS);
426
427 if (!ibs_allowed)
428 return;
429
Robert Richter7d77f2d2008-07-22 21:08:57 +0200430 if (pfm_amd64_setup_eilvt())
431 ibs_allowed = 0;
Barry Kasindorf56784f12008-07-22 21:08:55 +0200432}
433
434
435/*
436 * unitialize the APIC for the IBS interrupts if needed on AMD Family10h
437 * rev B0 and later */
438static void clear_ibs_nmi(void)
439{
440 if (ibs_allowed)
441 on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1, 1);
442}
443
444static void setup_ibs_files(struct super_block *sb, struct dentry *root)
445{
446 char buf[12];
447 struct dentry *dir;
448
449 if (!ibs_allowed)
450 return;
451
452 /* setup some reasonable defaults */
453 ibs_config.max_cnt_fetch = 250000;
454 ibs_config.fetch_enabled = 0;
455 ibs_config.max_cnt_op = 250000;
456 ibs_config.op_enabled = 0;
457 ibs_config.dispatched_ops = 1;
458 snprintf(buf, sizeof(buf), "ibs_fetch");
459 dir = oprofilefs_mkdir(sb, root, buf);
460 oprofilefs_create_ulong(sb, dir, "rand_enable",
461 &ibs_config.rand_en);
462 oprofilefs_create_ulong(sb, dir, "enable",
463 &ibs_config.fetch_enabled);
464 oprofilefs_create_ulong(sb, dir, "max_count",
465 &ibs_config.max_cnt_fetch);
466 snprintf(buf, sizeof(buf), "ibs_uops");
467 dir = oprofilefs_mkdir(sb, root, buf);
468 oprofilefs_create_ulong(sb, dir, "enable",
469 &ibs_config.op_enabled);
470 oprofilefs_create_ulong(sb, dir, "max_count",
471 &ibs_config.max_cnt_op);
472 oprofilefs_create_ulong(sb, dir, "dispatched_ops",
473 &ibs_config.dispatched_ops);
474}
475
Robert Richteradf5ec02008-07-22 21:08:48 +0200476static int op_amd_init(struct oprofile_operations *ops)
477{
478 return 0;
479}
480
481static void op_amd_exit(void)
482{
483}
484
Robert Richter6657fe42008-07-22 21:08:50 +0200485struct op_x86_model_spec const op_amd_spec = {
Robert Richteradf5ec02008-07-22 21:08:48 +0200486 .init = op_amd_init,
487 .exit = op_amd_exit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 .num_counters = NUM_COUNTERS,
489 .num_controls = NUM_CONTROLS,
Robert Richter6657fe42008-07-22 21:08:50 +0200490 .fill_in_addresses = &op_amd_fill_in_addresses,
491 .setup_ctrs = &op_amd_setup_ctrs,
492 .check_ctrs = &op_amd_check_ctrs,
493 .start = &op_amd_start,
494 .stop = &op_amd_stop,
495 .shutdown = &op_amd_shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496};