blob: 2c2d9f643df0591f2afb4e4c3bb471a86e82f6bd [file] [log] [blame]
Paul Mackerrasd662ed22009-01-09 17:01:53 +11001/*
2 * Performance counter support - PowerPC-specific definitions.
3 *
4 * Copyright 2008-2009 Paul Mackerras, IBM Corporation.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
Paul Mackerras45749102009-01-09 20:21:55 +110011#include <linux/types.h>
12
Paul Mackerras99744582009-06-15 21:45:16 +100013#include <asm/hw_irq.h>
14
Paul Mackerras45749102009-01-09 20:21:55 +110015#define MAX_HWCOUNTERS 8
16#define MAX_EVENT_ALTERNATIVES 8
Paul Mackerrasab7ef2e2009-04-29 22:38:51 +100017#define MAX_LIMITED_HWCOUNTERS 2
Paul Mackerras45749102009-01-09 20:21:55 +110018
19/*
20 * This struct provides the constants and functions needed to
21 * describe the PMU on a particular POWER-family CPU.
22 */
23struct power_pmu {
24 int n_counter;
25 int max_alternatives;
26 u64 add_fields;
27 u64 test_adder;
Paul Mackerrasef923212009-05-14 13:29:14 +100028 int (*compute_mmcr)(u64 events[], int n_ev,
Paul Mackerras45749102009-01-09 20:21:55 +110029 unsigned int hwc[], u64 mmcr[]);
Paul Mackerrasef923212009-05-14 13:29:14 +100030 int (*get_constraint)(u64 event, u64 *mskp, u64 *valp);
31 int (*get_alternatives)(u64 event, unsigned int flags,
32 u64 alt[]);
Paul Mackerras45749102009-01-09 20:21:55 +110033 void (*disable_pmc)(unsigned int pmc, u64 mmcr[]);
Paul Mackerrasef923212009-05-14 13:29:14 +100034 int (*limited_pmc_event)(u64 event);
Paul Mackerras0bbd0d42009-05-14 13:31:48 +100035 u32 flags;
Paul Mackerras45749102009-01-09 20:21:55 +110036 int n_generic;
37 int *generic_events;
Paul Mackerras106b5062009-06-11 14:55:42 +100038 int (*cache_events)[PERF_COUNT_HW_CACHE_MAX]
39 [PERF_COUNT_HW_CACHE_OP_MAX]
40 [PERF_COUNT_HW_CACHE_RESULT_MAX];
Paul Mackerras45749102009-01-09 20:21:55 +110041};
42
43extern struct power_pmu *ppmu;
44
45/*
Paul Mackerras0bbd0d42009-05-14 13:31:48 +100046 * Values for power_pmu.flags
47 */
48#define PPMU_LIMITED_PMC5_6 1 /* PMC5/6 have limited function */
49#define PPMU_ALT_SIPR 2 /* uses alternate posn for SIPR/HV */
50
51/*
Paul Mackerrasab7ef2e2009-04-29 22:38:51 +100052 * Values for flags to get_alternatives()
53 */
54#define PPMU_LIMITED_PMC_OK 1 /* can put this on a limited PMC */
55#define PPMU_LIMITED_PMC_REQD 2 /* have to put this on a limited PMC */
56#define PPMU_ONLY_COUNT_RUN 4 /* only counting in run state */
57
Paul Mackerras0bbd0d42009-05-14 13:31:48 +100058struct pt_regs;
59extern unsigned long perf_misc_flags(struct pt_regs *regs);
Paul Mackerras0bbd0d42009-05-14 13:31:48 +100060extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
61
Paul Mackerrasab7ef2e2009-04-29 22:38:51 +100062/*
Paul Mackerras105988c2009-06-17 21:50:04 +100063 * Only override the default definitions in include/linux/perf_counter.h
64 * if we have hardware PMU support.
65 */
66#ifdef CONFIG_PPC_PERF_CTRS
67#define perf_misc_flags(regs) perf_misc_flags(regs)
68#endif
69
70/*
Paul Mackerras45749102009-01-09 20:21:55 +110071 * The power_pmu.get_constraint function returns a 64-bit value and
72 * a 64-bit mask that express the constraints between this event and
73 * other events.
74 *
75 * The value and mask are divided up into (non-overlapping) bitfields
76 * of three different types:
77 *
78 * Select field: this expresses the constraint that some set of bits
79 * in MMCR* needs to be set to a specific value for this event. For a
80 * select field, the mask contains 1s in every bit of the field, and
81 * the value contains a unique value for each possible setting of the
82 * MMCR* bits. The constraint checking code will ensure that two events
83 * that set the same field in their masks have the same value in their
84 * value dwords.
85 *
86 * Add field: this expresses the constraint that there can be at most
87 * N events in a particular class. A field of k bits can be used for
88 * N <= 2^(k-1) - 1. The mask has the most significant bit of the field
89 * set (and the other bits 0), and the value has only the least significant
90 * bit of the field set. In addition, the 'add_fields' and 'test_adder'
91 * in the struct power_pmu for this processor come into play. The
92 * add_fields value contains 1 in the LSB of the field, and the
93 * test_adder contains 2^(k-1) - 1 - N in the field.
94 *
95 * NAND field: this expresses the constraint that you may not have events
96 * in all of a set of classes. (For example, on PPC970, you can't select
97 * events from the FPU, ISU and IDU simultaneously, although any two are
98 * possible.) For N classes, the field is N+1 bits wide, and each class
99 * is assigned one bit from the least-significant N bits. The mask has
100 * only the most-significant bit set, and the value has only the bit
101 * for the event's class set. The test_adder has the least significant
102 * bit set in the field.
103 *
104 * If an event is not subject to the constraint expressed by a particular
105 * field, then it will have 0 in both the mask and value for that field.
106 */