1 // SPDX-License-Identifier: GPL-2.0
2 /* Nehalem/SandBridge/Haswell/Broadwell/Skylake uncore support */
5 /* Uncore IMC PCI IDs */
6 #define PCI_DEVICE_ID_INTEL_SNB_IMC 0x0100
7 #define PCI_DEVICE_ID_INTEL_IVB_IMC 0x0154
8 #define PCI_DEVICE_ID_INTEL_IVB_E3_IMC 0x0150
9 #define PCI_DEVICE_ID_INTEL_HSW_IMC 0x0c00
10 #define PCI_DEVICE_ID_INTEL_HSW_U_IMC 0x0a04
11 #define PCI_DEVICE_ID_INTEL_BDW_IMC 0x1604
12 #define PCI_DEVICE_ID_INTEL_SKL_U_IMC 0x1904
13 #define PCI_DEVICE_ID_INTEL_SKL_Y_IMC 0x190c
14 #define PCI_DEVICE_ID_INTEL_SKL_HD_IMC 0x1900
15 #define PCI_DEVICE_ID_INTEL_SKL_HQ_IMC 0x1910
16 #define PCI_DEVICE_ID_INTEL_SKL_SD_IMC 0x190f
17 #define PCI_DEVICE_ID_INTEL_SKL_SQ_IMC 0x191f
18 #define PCI_DEVICE_ID_INTEL_SKL_E3_IMC 0x1918
19 #define PCI_DEVICE_ID_INTEL_KBL_Y_IMC 0x590c
20 #define PCI_DEVICE_ID_INTEL_KBL_U_IMC 0x5904
21 #define PCI_DEVICE_ID_INTEL_KBL_UQ_IMC 0x5914
22 #define PCI_DEVICE_ID_INTEL_KBL_SD_IMC 0x590f
23 #define PCI_DEVICE_ID_INTEL_KBL_SQ_IMC 0x591f
24 #define PCI_DEVICE_ID_INTEL_KBL_HQ_IMC 0x5910
25 #define PCI_DEVICE_ID_INTEL_KBL_WQ_IMC 0x5918
26 #define PCI_DEVICE_ID_INTEL_CFL_2U_IMC 0x3ecc
27 #define PCI_DEVICE_ID_INTEL_CFL_4U_IMC 0x3ed0
28 #define PCI_DEVICE_ID_INTEL_CFL_4H_IMC 0x3e10
29 #define PCI_DEVICE_ID_INTEL_CFL_6H_IMC 0x3ec4
30 #define PCI_DEVICE_ID_INTEL_CFL_2S_D_IMC 0x3e0f
31 #define PCI_DEVICE_ID_INTEL_CFL_4S_D_IMC 0x3e1f
32 #define PCI_DEVICE_ID_INTEL_CFL_6S_D_IMC 0x3ec2
33 #define PCI_DEVICE_ID_INTEL_CFL_8S_D_IMC 0x3e30
34 #define PCI_DEVICE_ID_INTEL_CFL_4S_W_IMC 0x3e18
35 #define PCI_DEVICE_ID_INTEL_CFL_6S_W_IMC 0x3ec6
36 #define PCI_DEVICE_ID_INTEL_CFL_8S_W_IMC 0x3e31
37 #define PCI_DEVICE_ID_INTEL_CFL_4S_S_IMC 0x3e33
38 #define PCI_DEVICE_ID_INTEL_CFL_6S_S_IMC 0x3eca
39 #define PCI_DEVICE_ID_INTEL_CFL_8S_S_IMC 0x3e32
40 #define PCI_DEVICE_ID_INTEL_AML_YD_IMC 0x590c
41 #define PCI_DEVICE_ID_INTEL_AML_YQ_IMC 0x590d
42 #define PCI_DEVICE_ID_INTEL_WHL_UQ_IMC 0x3ed0
43 #define PCI_DEVICE_ID_INTEL_WHL_4_UQ_IMC 0x3e34
44 #define PCI_DEVICE_ID_INTEL_WHL_UD_IMC 0x3e35
45 #define PCI_DEVICE_ID_INTEL_ICL_U_IMC 0x8a02
46 #define PCI_DEVICE_ID_INTEL_ICL_U2_IMC 0x8a12
49 /* SNB event control */
50 #define SNB_UNC_CTL_EV_SEL_MASK 0x000000ff
51 #define SNB_UNC_CTL_UMASK_MASK 0x0000ff00
52 #define SNB_UNC_CTL_EDGE_DET (1 << 18)
53 #define SNB_UNC_CTL_EN (1 << 22)
54 #define SNB_UNC_CTL_INVERT (1 << 23)
55 #define SNB_UNC_CTL_CMASK_MASK 0x1f000000
56 #define NHM_UNC_CTL_CMASK_MASK 0xff000000
57 #define NHM_UNC_FIXED_CTR_CTL_EN (1 << 0)
59 #define SNB_UNC_RAW_EVENT_MASK (SNB_UNC_CTL_EV_SEL_MASK | \
60 SNB_UNC_CTL_UMASK_MASK | \
61 SNB_UNC_CTL_EDGE_DET | \
62 SNB_UNC_CTL_INVERT | \
63 SNB_UNC_CTL_CMASK_MASK)
65 #define NHM_UNC_RAW_EVENT_MASK (SNB_UNC_CTL_EV_SEL_MASK | \
66 SNB_UNC_CTL_UMASK_MASK | \
67 SNB_UNC_CTL_EDGE_DET | \
68 SNB_UNC_CTL_INVERT | \
69 NHM_UNC_CTL_CMASK_MASK)
71 /* SNB global control register */
72 #define SNB_UNC_PERF_GLOBAL_CTL 0x391
73 #define SNB_UNC_FIXED_CTR_CTRL 0x394
74 #define SNB_UNC_FIXED_CTR 0x395
76 /* SNB uncore global control */
77 #define SNB_UNC_GLOBAL_CTL_CORE_ALL ((1 << 4) - 1)
78 #define SNB_UNC_GLOBAL_CTL_EN (1 << 29)
80 /* SNB Cbo register */
81 #define SNB_UNC_CBO_0_PERFEVTSEL0 0x700
82 #define SNB_UNC_CBO_0_PER_CTR0 0x706
83 #define SNB_UNC_CBO_MSR_OFFSET 0x10
85 /* SNB ARB register */
86 #define SNB_UNC_ARB_PER_CTR0 0x3b0
87 #define SNB_UNC_ARB_PERFEVTSEL0 0x3b2
88 #define SNB_UNC_ARB_MSR_OFFSET 0x10
90 /* NHM global control register */
91 #define NHM_UNC_PERF_GLOBAL_CTL 0x391
92 #define NHM_UNC_FIXED_CTR 0x394
93 #define NHM_UNC_FIXED_CTR_CTRL 0x395
95 /* NHM uncore global control */
96 #define NHM_UNC_GLOBAL_CTL_EN_PC_ALL ((1ULL << 8) - 1)
97 #define NHM_UNC_GLOBAL_CTL_EN_FC (1ULL << 32)
99 /* NHM uncore register */
100 #define NHM_UNC_PERFEVTSEL0 0x3c0
101 #define NHM_UNC_UNCORE_PMC0 0x3b0
103 /* SKL uncore global control */
104 #define SKL_UNC_PERF_GLOBAL_CTL 0xe01
105 #define SKL_UNC_GLOBAL_CTL_CORE_ALL ((1 << 5) - 1)
107 /* ICL Cbo register */
108 #define ICL_UNC_CBO_CONFIG 0x396
109 #define ICL_UNC_NUM_CBO_MASK 0xf
110 #define ICL_UNC_CBO_0_PER_CTR0 0x702
111 #define ICL_UNC_CBO_MSR_OFFSET 0x8
113 DEFINE_UNCORE_FORMAT_ATTR(event
, event
, "config:0-7");
114 DEFINE_UNCORE_FORMAT_ATTR(umask
, umask
, "config:8-15");
115 DEFINE_UNCORE_FORMAT_ATTR(edge
, edge
, "config:18");
116 DEFINE_UNCORE_FORMAT_ATTR(inv
, inv
, "config:23");
117 DEFINE_UNCORE_FORMAT_ATTR(cmask5
, cmask
, "config:24-28");
118 DEFINE_UNCORE_FORMAT_ATTR(cmask8
, cmask
, "config:24-31");
120 /* Sandy Bridge uncore support */
121 static void snb_uncore_msr_enable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
123 struct hw_perf_event
*hwc
= &event
->hw
;
125 if (hwc
->idx
< UNCORE_PMC_IDX_FIXED
)
126 wrmsrl(hwc
->config_base
, hwc
->config
| SNB_UNC_CTL_EN
);
128 wrmsrl(hwc
->config_base
, SNB_UNC_CTL_EN
);
131 static void snb_uncore_msr_disable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
133 wrmsrl(event
->hw
.config_base
, 0);
136 static void snb_uncore_msr_init_box(struct intel_uncore_box
*box
)
138 if (box
->pmu
->pmu_idx
== 0) {
139 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL
,
140 SNB_UNC_GLOBAL_CTL_EN
| SNB_UNC_GLOBAL_CTL_CORE_ALL
);
144 static void snb_uncore_msr_enable_box(struct intel_uncore_box
*box
)
146 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL
,
147 SNB_UNC_GLOBAL_CTL_EN
| SNB_UNC_GLOBAL_CTL_CORE_ALL
);
150 static void snb_uncore_msr_exit_box(struct intel_uncore_box
*box
)
152 if (box
->pmu
->pmu_idx
== 0)
153 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL
, 0);
156 static struct uncore_event_desc snb_uncore_events
[] = {
157 INTEL_UNCORE_EVENT_DESC(clockticks
, "event=0xff,umask=0x00"),
158 { /* end: all zeroes */ },
161 static struct attribute
*snb_uncore_formats_attr
[] = {
162 &format_attr_event
.attr
,
163 &format_attr_umask
.attr
,
164 &format_attr_edge
.attr
,
165 &format_attr_inv
.attr
,
166 &format_attr_cmask5
.attr
,
170 static const struct attribute_group snb_uncore_format_group
= {
172 .attrs
= snb_uncore_formats_attr
,
175 static struct intel_uncore_ops snb_uncore_msr_ops
= {
176 .init_box
= snb_uncore_msr_init_box
,
177 .enable_box
= snb_uncore_msr_enable_box
,
178 .exit_box
= snb_uncore_msr_exit_box
,
179 .disable_event
= snb_uncore_msr_disable_event
,
180 .enable_event
= snb_uncore_msr_enable_event
,
181 .read_counter
= uncore_msr_read_counter
,
184 static struct event_constraint snb_uncore_arb_constraints
[] = {
185 UNCORE_EVENT_CONSTRAINT(0x80, 0x1),
186 UNCORE_EVENT_CONSTRAINT(0x83, 0x1),
190 static struct intel_uncore_type snb_uncore_cbox
= {
195 .fixed_ctr_bits
= 48,
196 .perf_ctr
= SNB_UNC_CBO_0_PER_CTR0
,
197 .event_ctl
= SNB_UNC_CBO_0_PERFEVTSEL0
,
198 .fixed_ctr
= SNB_UNC_FIXED_CTR
,
199 .fixed_ctl
= SNB_UNC_FIXED_CTR_CTRL
,
201 .event_mask
= SNB_UNC_RAW_EVENT_MASK
,
202 .msr_offset
= SNB_UNC_CBO_MSR_OFFSET
,
203 .ops
= &snb_uncore_msr_ops
,
204 .format_group
= &snb_uncore_format_group
,
205 .event_descs
= snb_uncore_events
,
208 static struct intel_uncore_type snb_uncore_arb
= {
213 .perf_ctr
= SNB_UNC_ARB_PER_CTR0
,
214 .event_ctl
= SNB_UNC_ARB_PERFEVTSEL0
,
215 .event_mask
= SNB_UNC_RAW_EVENT_MASK
,
216 .msr_offset
= SNB_UNC_ARB_MSR_OFFSET
,
217 .constraints
= snb_uncore_arb_constraints
,
218 .ops
= &snb_uncore_msr_ops
,
219 .format_group
= &snb_uncore_format_group
,
222 static struct intel_uncore_type
*snb_msr_uncores
[] = {
228 void snb_uncore_cpu_init(void)
230 uncore_msr_uncores
= snb_msr_uncores
;
231 if (snb_uncore_cbox
.num_boxes
> boot_cpu_data
.x86_max_cores
)
232 snb_uncore_cbox
.num_boxes
= boot_cpu_data
.x86_max_cores
;
235 static void skl_uncore_msr_init_box(struct intel_uncore_box
*box
)
237 if (box
->pmu
->pmu_idx
== 0) {
238 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL
,
239 SNB_UNC_GLOBAL_CTL_EN
| SKL_UNC_GLOBAL_CTL_CORE_ALL
);
242 /* The 8th CBOX has different MSR space */
243 if (box
->pmu
->pmu_idx
== 7)
244 __set_bit(UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS
, &box
->flags
);
247 static void skl_uncore_msr_enable_box(struct intel_uncore_box
*box
)
249 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL
,
250 SNB_UNC_GLOBAL_CTL_EN
| SKL_UNC_GLOBAL_CTL_CORE_ALL
);
253 static void skl_uncore_msr_exit_box(struct intel_uncore_box
*box
)
255 if (box
->pmu
->pmu_idx
== 0)
256 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL
, 0);
259 static struct intel_uncore_ops skl_uncore_msr_ops
= {
260 .init_box
= skl_uncore_msr_init_box
,
261 .enable_box
= skl_uncore_msr_enable_box
,
262 .exit_box
= skl_uncore_msr_exit_box
,
263 .disable_event
= snb_uncore_msr_disable_event
,
264 .enable_event
= snb_uncore_msr_enable_event
,
265 .read_counter
= uncore_msr_read_counter
,
268 static struct intel_uncore_type skl_uncore_cbox
= {
273 .fixed_ctr_bits
= 48,
274 .perf_ctr
= SNB_UNC_CBO_0_PER_CTR0
,
275 .event_ctl
= SNB_UNC_CBO_0_PERFEVTSEL0
,
276 .fixed_ctr
= SNB_UNC_FIXED_CTR
,
277 .fixed_ctl
= SNB_UNC_FIXED_CTR_CTRL
,
279 .event_mask
= SNB_UNC_RAW_EVENT_MASK
,
280 .msr_offset
= SNB_UNC_CBO_MSR_OFFSET
,
281 .ops
= &skl_uncore_msr_ops
,
282 .format_group
= &snb_uncore_format_group
,
283 .event_descs
= snb_uncore_events
,
286 static struct intel_uncore_type
*skl_msr_uncores
[] = {
292 void skl_uncore_cpu_init(void)
294 uncore_msr_uncores
= skl_msr_uncores
;
295 if (skl_uncore_cbox
.num_boxes
> boot_cpu_data
.x86_max_cores
)
296 skl_uncore_cbox
.num_boxes
= boot_cpu_data
.x86_max_cores
;
297 snb_uncore_arb
.ops
= &skl_uncore_msr_ops
;
300 static struct intel_uncore_type icl_uncore_cbox
= {
304 .perf_ctr
= ICL_UNC_CBO_0_PER_CTR0
,
305 .event_ctl
= SNB_UNC_CBO_0_PERFEVTSEL0
,
306 .event_mask
= SNB_UNC_RAW_EVENT_MASK
,
307 .msr_offset
= ICL_UNC_CBO_MSR_OFFSET
,
308 .ops
= &skl_uncore_msr_ops
,
309 .format_group
= &snb_uncore_format_group
,
312 static struct uncore_event_desc icl_uncore_events
[] = {
313 INTEL_UNCORE_EVENT_DESC(clockticks
, "event=0xff"),
314 { /* end: all zeroes */ },
317 static struct attribute
*icl_uncore_clock_formats_attr
[] = {
318 &format_attr_event
.attr
,
322 static struct attribute_group icl_uncore_clock_format_group
= {
324 .attrs
= icl_uncore_clock_formats_attr
,
327 static struct intel_uncore_type icl_uncore_clockbox
= {
331 .fixed_ctr_bits
= 48,
332 .fixed_ctr
= SNB_UNC_FIXED_CTR
,
333 .fixed_ctl
= SNB_UNC_FIXED_CTR_CTRL
,
335 .event_mask
= SNB_UNC_CTL_EV_SEL_MASK
,
336 .format_group
= &icl_uncore_clock_format_group
,
337 .ops
= &skl_uncore_msr_ops
,
338 .event_descs
= icl_uncore_events
,
341 static struct intel_uncore_type
*icl_msr_uncores
[] = {
344 &icl_uncore_clockbox
,
348 static int icl_get_cbox_num(void)
352 rdmsrl(ICL_UNC_CBO_CONFIG
, num_boxes
);
354 return num_boxes
& ICL_UNC_NUM_CBO_MASK
;
357 void icl_uncore_cpu_init(void)
359 uncore_msr_uncores
= icl_msr_uncores
;
360 icl_uncore_cbox
.num_boxes
= icl_get_cbox_num();
361 snb_uncore_arb
.ops
= &skl_uncore_msr_ops
;
368 static struct uncore_event_desc snb_uncore_imc_events
[] = {
369 INTEL_UNCORE_EVENT_DESC(data_reads
, "event=0x01"),
370 INTEL_UNCORE_EVENT_DESC(data_reads
.scale
, "6.103515625e-5"),
371 INTEL_UNCORE_EVENT_DESC(data_reads
.unit
, "MiB"),
373 INTEL_UNCORE_EVENT_DESC(data_writes
, "event=0x02"),
374 INTEL_UNCORE_EVENT_DESC(data_writes
.scale
, "6.103515625e-5"),
375 INTEL_UNCORE_EVENT_DESC(data_writes
.unit
, "MiB"),
377 { /* end: all zeroes */ },
380 #define SNB_UNCORE_PCI_IMC_EVENT_MASK 0xff
381 #define SNB_UNCORE_PCI_IMC_BAR_OFFSET 0x48
383 /* page size multiple covering all config regs */
384 #define SNB_UNCORE_PCI_IMC_MAP_SIZE 0x6000
386 #define SNB_UNCORE_PCI_IMC_DATA_READS 0x1
387 #define SNB_UNCORE_PCI_IMC_DATA_READS_BASE 0x5050
388 #define SNB_UNCORE_PCI_IMC_DATA_WRITES 0x2
389 #define SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE 0x5054
390 #define SNB_UNCORE_PCI_IMC_CTR_BASE SNB_UNCORE_PCI_IMC_DATA_READS_BASE
392 enum perf_snb_uncore_imc_freerunning_types
{
393 SNB_PCI_UNCORE_IMC_DATA
= 0,
394 SNB_PCI_UNCORE_IMC_FREERUNNING_TYPE_MAX
,
397 static struct freerunning_counters snb_uncore_imc_freerunning
[] = {
398 [SNB_PCI_UNCORE_IMC_DATA
] = { SNB_UNCORE_PCI_IMC_DATA_READS_BASE
, 0x4, 0x0, 2, 32 },
401 static struct attribute
*snb_uncore_imc_formats_attr
[] = {
402 &format_attr_event
.attr
,
406 static const struct attribute_group snb_uncore_imc_format_group
= {
408 .attrs
= snb_uncore_imc_formats_attr
,
411 static void snb_uncore_imc_init_box(struct intel_uncore_box
*box
)
413 struct pci_dev
*pdev
= box
->pci_dev
;
414 int where
= SNB_UNCORE_PCI_IMC_BAR_OFFSET
;
415 resource_size_t addr
;
418 pci_read_config_dword(pdev
, where
, &pci_dword
);
421 #ifdef CONFIG_PHYS_ADDR_T_64BIT
422 pci_read_config_dword(pdev
, where
+ 4, &pci_dword
);
423 addr
|= ((resource_size_t
)pci_dword
<< 32);
426 addr
&= ~(PAGE_SIZE
- 1);
428 box
->io_addr
= ioremap(addr
, SNB_UNCORE_PCI_IMC_MAP_SIZE
);
429 box
->hrtimer_duration
= UNCORE_SNB_IMC_HRTIMER_INTERVAL
;
432 static void snb_uncore_imc_enable_box(struct intel_uncore_box
*box
)
435 static void snb_uncore_imc_disable_box(struct intel_uncore_box
*box
)
438 static void snb_uncore_imc_enable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
441 static void snb_uncore_imc_disable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
445 * Keep the custom event_init() function compatible with old event
446 * encoding for free running counters.
448 static int snb_uncore_imc_event_init(struct perf_event
*event
)
450 struct intel_uncore_pmu
*pmu
;
451 struct intel_uncore_box
*box
;
452 struct hw_perf_event
*hwc
= &event
->hw
;
453 u64 cfg
= event
->attr
.config
& SNB_UNCORE_PCI_IMC_EVENT_MASK
;
456 if (event
->attr
.type
!= event
->pmu
->type
)
459 pmu
= uncore_event_to_pmu(event
);
460 /* no device found for this pmu */
461 if (pmu
->func_id
< 0)
464 /* Sampling not supported yet */
465 if (hwc
->sample_period
)
468 /* unsupported modes and filters */
469 if (event
->attr
.sample_period
) /* no sampling */
473 * Place all uncore events for a particular physical package
479 /* check only supported bits are set */
480 if (event
->attr
.config
& ~SNB_UNCORE_PCI_IMC_EVENT_MASK
)
483 box
= uncore_pmu_to_box(pmu
, event
->cpu
);
484 if (!box
|| box
->cpu
< 0)
487 event
->cpu
= box
->cpu
;
488 event
->pmu_private
= box
;
490 event
->event_caps
|= PERF_EV_CAP_READ_ACTIVE_PKG
;
493 event
->hw
.last_tag
= ~0ULL;
494 event
->hw
.extra_reg
.idx
= EXTRA_REG_NONE
;
495 event
->hw
.branch_reg
.idx
= EXTRA_REG_NONE
;
497 * check event is known (whitelist, determines counter)
500 case SNB_UNCORE_PCI_IMC_DATA_READS
:
501 base
= SNB_UNCORE_PCI_IMC_DATA_READS_BASE
;
502 idx
= UNCORE_PMC_IDX_FREERUNNING
;
504 case SNB_UNCORE_PCI_IMC_DATA_WRITES
:
505 base
= SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE
;
506 idx
= UNCORE_PMC_IDX_FREERUNNING
;
512 /* must be done before validate_group */
513 event
->hw
.event_base
= base
;
516 /* Convert to standard encoding format for freerunning counters */
517 event
->hw
.config
= ((cfg
- 1) << 8) | 0x10ff;
519 /* no group validation needed, we have free running counters */
524 static int snb_uncore_imc_hw_config(struct intel_uncore_box
*box
, struct perf_event
*event
)
529 int snb_pci2phy_map_init(int devid
)
531 struct pci_dev
*dev
= NULL
;
532 struct pci2phy_map
*map
;
535 dev
= pci_get_device(PCI_VENDOR_ID_INTEL
, devid
, dev
);
539 bus
= dev
->bus
->number
;
540 segment
= pci_domain_nr(dev
->bus
);
542 raw_spin_lock(&pci2phy_map_lock
);
543 map
= __find_pci2phy_map(segment
);
545 raw_spin_unlock(&pci2phy_map_lock
);
549 map
->pbus_to_physid
[bus
] = 0;
550 raw_spin_unlock(&pci2phy_map_lock
);
557 static struct pmu snb_uncore_imc_pmu
= {
558 .task_ctx_nr
= perf_invalid_context
,
559 .event_init
= snb_uncore_imc_event_init
,
560 .add
= uncore_pmu_event_add
,
561 .del
= uncore_pmu_event_del
,
562 .start
= uncore_pmu_event_start
,
563 .stop
= uncore_pmu_event_stop
,
564 .read
= uncore_pmu_event_read
,
565 .capabilities
= PERF_PMU_CAP_NO_EXCLUDE
,
568 static struct intel_uncore_ops snb_uncore_imc_ops
= {
569 .init_box
= snb_uncore_imc_init_box
,
570 .exit_box
= uncore_mmio_exit_box
,
571 .enable_box
= snb_uncore_imc_enable_box
,
572 .disable_box
= snb_uncore_imc_disable_box
,
573 .disable_event
= snb_uncore_imc_disable_event
,
574 .enable_event
= snb_uncore_imc_enable_event
,
575 .hw_config
= snb_uncore_imc_hw_config
,
576 .read_counter
= uncore_mmio_read_counter
,
579 static struct intel_uncore_type snb_uncore_imc
= {
583 .num_freerunning_types
= SNB_PCI_UNCORE_IMC_FREERUNNING_TYPE_MAX
,
584 .freerunning
= snb_uncore_imc_freerunning
,
585 .event_descs
= snb_uncore_imc_events
,
586 .format_group
= &snb_uncore_imc_format_group
,
587 .ops
= &snb_uncore_imc_ops
,
588 .pmu
= &snb_uncore_imc_pmu
,
591 static struct intel_uncore_type
*snb_pci_uncores
[] = {
592 [SNB_PCI_UNCORE_IMC
] = &snb_uncore_imc
,
596 static const struct pci_device_id snb_uncore_pci_ids
[] = {
598 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SNB_IMC
),
599 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
601 { /* end: all zeroes */ },
604 static const struct pci_device_id ivb_uncore_pci_ids
[] = {
606 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_IVB_IMC
),
607 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
610 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_IVB_E3_IMC
),
611 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
613 { /* end: all zeroes */ },
616 static const struct pci_device_id hsw_uncore_pci_ids
[] = {
618 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_HSW_IMC
),
619 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
622 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_HSW_U_IMC
),
623 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
625 { /* end: all zeroes */ },
628 static const struct pci_device_id bdw_uncore_pci_ids
[] = {
630 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_BDW_IMC
),
631 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
633 { /* end: all zeroes */ },
636 static const struct pci_device_id skl_uncore_pci_ids
[] = {
638 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_Y_IMC
),
639 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
642 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_U_IMC
),
643 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
646 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_HD_IMC
),
647 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
650 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_HQ_IMC
),
651 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
654 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_SD_IMC
),
655 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
658 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_SQ_IMC
),
659 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
662 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_E3_IMC
),
663 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
666 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_KBL_Y_IMC
),
667 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
670 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_KBL_U_IMC
),
671 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
674 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_KBL_UQ_IMC
),
675 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
678 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_KBL_SD_IMC
),
679 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
682 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_KBL_SQ_IMC
),
683 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
686 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_KBL_HQ_IMC
),
687 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
690 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_KBL_WQ_IMC
),
691 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
694 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_2U_IMC
),
695 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
698 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_4U_IMC
),
699 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
702 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_4H_IMC
),
703 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
706 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_6H_IMC
),
707 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
710 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_2S_D_IMC
),
711 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
714 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_4S_D_IMC
),
715 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
718 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_6S_D_IMC
),
719 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
722 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_8S_D_IMC
),
723 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
726 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_4S_W_IMC
),
727 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
730 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_6S_W_IMC
),
731 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
734 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_8S_W_IMC
),
735 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
738 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_4S_S_IMC
),
739 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
742 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_6S_S_IMC
),
743 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
746 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_CFL_8S_S_IMC
),
747 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
750 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_AML_YD_IMC
),
751 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
754 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_AML_YQ_IMC
),
755 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
758 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_WHL_UQ_IMC
),
759 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
762 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_WHL_4_UQ_IMC
),
763 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
766 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_WHL_UD_IMC
),
767 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
769 { /* end: all zeroes */ },
772 static const struct pci_device_id icl_uncore_pci_ids
[] = {
774 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ICL_U_IMC
),
775 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
778 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_ICL_U2_IMC
),
779 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
781 { /* end: all zeroes */ },
784 static struct pci_driver snb_uncore_pci_driver
= {
785 .name
= "snb_uncore",
786 .id_table
= snb_uncore_pci_ids
,
789 static struct pci_driver ivb_uncore_pci_driver
= {
790 .name
= "ivb_uncore",
791 .id_table
= ivb_uncore_pci_ids
,
794 static struct pci_driver hsw_uncore_pci_driver
= {
795 .name
= "hsw_uncore",
796 .id_table
= hsw_uncore_pci_ids
,
799 static struct pci_driver bdw_uncore_pci_driver
= {
800 .name
= "bdw_uncore",
801 .id_table
= bdw_uncore_pci_ids
,
804 static struct pci_driver skl_uncore_pci_driver
= {
805 .name
= "skl_uncore",
806 .id_table
= skl_uncore_pci_ids
,
809 static struct pci_driver icl_uncore_pci_driver
= {
810 .name
= "icl_uncore",
811 .id_table
= icl_uncore_pci_ids
,
814 struct imc_uncore_pci_dev
{
816 struct pci_driver
*driver
;
818 #define IMC_DEV(a, d) \
819 { .pci_id = PCI_DEVICE_ID_INTEL_##a, .driver = (d) }
821 static const struct imc_uncore_pci_dev desktop_imc_pci_ids
[] = {
822 IMC_DEV(SNB_IMC
, &snb_uncore_pci_driver
),
823 IMC_DEV(IVB_IMC
, &ivb_uncore_pci_driver
), /* 3rd Gen Core processor */
824 IMC_DEV(IVB_E3_IMC
, &ivb_uncore_pci_driver
), /* Xeon E3-1200 v2/3rd Gen Core processor */
825 IMC_DEV(HSW_IMC
, &hsw_uncore_pci_driver
), /* 4th Gen Core Processor */
826 IMC_DEV(HSW_U_IMC
, &hsw_uncore_pci_driver
), /* 4th Gen Core ULT Mobile Processor */
827 IMC_DEV(BDW_IMC
, &bdw_uncore_pci_driver
), /* 5th Gen Core U */
828 IMC_DEV(SKL_Y_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core Y */
829 IMC_DEV(SKL_U_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core U */
830 IMC_DEV(SKL_HD_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core H Dual Core */
831 IMC_DEV(SKL_HQ_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core H Quad Core */
832 IMC_DEV(SKL_SD_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core S Dual Core */
833 IMC_DEV(SKL_SQ_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core S Quad Core */
834 IMC_DEV(SKL_E3_IMC
, &skl_uncore_pci_driver
), /* Xeon E3 V5 Gen Core processor */
835 IMC_DEV(KBL_Y_IMC
, &skl_uncore_pci_driver
), /* 7th Gen Core Y */
836 IMC_DEV(KBL_U_IMC
, &skl_uncore_pci_driver
), /* 7th Gen Core U */
837 IMC_DEV(KBL_UQ_IMC
, &skl_uncore_pci_driver
), /* 7th Gen Core U Quad Core */
838 IMC_DEV(KBL_SD_IMC
, &skl_uncore_pci_driver
), /* 7th Gen Core S Dual Core */
839 IMC_DEV(KBL_SQ_IMC
, &skl_uncore_pci_driver
), /* 7th Gen Core S Quad Core */
840 IMC_DEV(KBL_HQ_IMC
, &skl_uncore_pci_driver
), /* 7th Gen Core H Quad Core */
841 IMC_DEV(KBL_WQ_IMC
, &skl_uncore_pci_driver
), /* 7th Gen Core S 4 cores Work Station */
842 IMC_DEV(CFL_2U_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core U 2 Cores */
843 IMC_DEV(CFL_4U_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core U 4 Cores */
844 IMC_DEV(CFL_4H_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core H 4 Cores */
845 IMC_DEV(CFL_6H_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core H 6 Cores */
846 IMC_DEV(CFL_2S_D_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 2 Cores Desktop */
847 IMC_DEV(CFL_4S_D_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 4 Cores Desktop */
848 IMC_DEV(CFL_6S_D_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 6 Cores Desktop */
849 IMC_DEV(CFL_8S_D_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 8 Cores Desktop */
850 IMC_DEV(CFL_4S_W_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 4 Cores Work Station */
851 IMC_DEV(CFL_6S_W_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 6 Cores Work Station */
852 IMC_DEV(CFL_8S_W_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 8 Cores Work Station */
853 IMC_DEV(CFL_4S_S_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 4 Cores Server */
854 IMC_DEV(CFL_6S_S_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 6 Cores Server */
855 IMC_DEV(CFL_8S_S_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core S 8 Cores Server */
856 IMC_DEV(AML_YD_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core Y Mobile Dual Core */
857 IMC_DEV(AML_YQ_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core Y Mobile Quad Core */
858 IMC_DEV(WHL_UQ_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core U Mobile Quad Core */
859 IMC_DEV(WHL_4_UQ_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core U Mobile Quad Core */
860 IMC_DEV(WHL_UD_IMC
, &skl_uncore_pci_driver
), /* 8th Gen Core U Mobile Dual Core */
861 IMC_DEV(ICL_U_IMC
, &icl_uncore_pci_driver
), /* 10th Gen Core Mobile */
862 IMC_DEV(ICL_U2_IMC
, &icl_uncore_pci_driver
), /* 10th Gen Core Mobile */
867 #define for_each_imc_pci_id(x, t) \
868 for (x = (t); (x)->pci_id; x++)
870 static struct pci_driver
*imc_uncore_find_dev(void)
872 const struct imc_uncore_pci_dev
*p
;
875 for_each_imc_pci_id(p
, desktop_imc_pci_ids
) {
876 ret
= snb_pci2phy_map_init(p
->pci_id
);
883 static int imc_uncore_pci_init(void)
885 struct pci_driver
*imc_drv
= imc_uncore_find_dev();
890 uncore_pci_uncores
= snb_pci_uncores
;
891 uncore_pci_driver
= imc_drv
;
896 int snb_uncore_pci_init(void)
898 return imc_uncore_pci_init();
901 int ivb_uncore_pci_init(void)
903 return imc_uncore_pci_init();
905 int hsw_uncore_pci_init(void)
907 return imc_uncore_pci_init();
910 int bdw_uncore_pci_init(void)
912 return imc_uncore_pci_init();
915 int skl_uncore_pci_init(void)
917 return imc_uncore_pci_init();
920 /* end of Sandy Bridge uncore support */
922 /* Nehalem uncore support */
923 static void nhm_uncore_msr_disable_box(struct intel_uncore_box
*box
)
925 wrmsrl(NHM_UNC_PERF_GLOBAL_CTL
, 0);
928 static void nhm_uncore_msr_enable_box(struct intel_uncore_box
*box
)
930 wrmsrl(NHM_UNC_PERF_GLOBAL_CTL
, NHM_UNC_GLOBAL_CTL_EN_PC_ALL
| NHM_UNC_GLOBAL_CTL_EN_FC
);
933 static void nhm_uncore_msr_enable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
935 struct hw_perf_event
*hwc
= &event
->hw
;
937 if (hwc
->idx
< UNCORE_PMC_IDX_FIXED
)
938 wrmsrl(hwc
->config_base
, hwc
->config
| SNB_UNC_CTL_EN
);
940 wrmsrl(hwc
->config_base
, NHM_UNC_FIXED_CTR_CTL_EN
);
943 static struct attribute
*nhm_uncore_formats_attr
[] = {
944 &format_attr_event
.attr
,
945 &format_attr_umask
.attr
,
946 &format_attr_edge
.attr
,
947 &format_attr_inv
.attr
,
948 &format_attr_cmask8
.attr
,
952 static const struct attribute_group nhm_uncore_format_group
= {
954 .attrs
= nhm_uncore_formats_attr
,
957 static struct uncore_event_desc nhm_uncore_events
[] = {
958 INTEL_UNCORE_EVENT_DESC(clockticks
, "event=0xff,umask=0x00"),
959 INTEL_UNCORE_EVENT_DESC(qmc_writes_full_any
, "event=0x2f,umask=0x0f"),
960 INTEL_UNCORE_EVENT_DESC(qmc_normal_reads_any
, "event=0x2c,umask=0x0f"),
961 INTEL_UNCORE_EVENT_DESC(qhl_request_ioh_reads
, "event=0x20,umask=0x01"),
962 INTEL_UNCORE_EVENT_DESC(qhl_request_ioh_writes
, "event=0x20,umask=0x02"),
963 INTEL_UNCORE_EVENT_DESC(qhl_request_remote_reads
, "event=0x20,umask=0x04"),
964 INTEL_UNCORE_EVENT_DESC(qhl_request_remote_writes
, "event=0x20,umask=0x08"),
965 INTEL_UNCORE_EVENT_DESC(qhl_request_local_reads
, "event=0x20,umask=0x10"),
966 INTEL_UNCORE_EVENT_DESC(qhl_request_local_writes
, "event=0x20,umask=0x20"),
967 { /* end: all zeroes */ },
970 static struct intel_uncore_ops nhm_uncore_msr_ops
= {
971 .disable_box
= nhm_uncore_msr_disable_box
,
972 .enable_box
= nhm_uncore_msr_enable_box
,
973 .disable_event
= snb_uncore_msr_disable_event
,
974 .enable_event
= nhm_uncore_msr_enable_event
,
975 .read_counter
= uncore_msr_read_counter
,
978 static struct intel_uncore_type nhm_uncore
= {
983 .fixed_ctr_bits
= 48,
984 .event_ctl
= NHM_UNC_PERFEVTSEL0
,
985 .perf_ctr
= NHM_UNC_UNCORE_PMC0
,
986 .fixed_ctr
= NHM_UNC_FIXED_CTR
,
987 .fixed_ctl
= NHM_UNC_FIXED_CTR_CTRL
,
988 .event_mask
= NHM_UNC_RAW_EVENT_MASK
,
989 .event_descs
= nhm_uncore_events
,
990 .ops
= &nhm_uncore_msr_ops
,
991 .format_group
= &nhm_uncore_format_group
,
994 static struct intel_uncore_type
*nhm_msr_uncores
[] = {
999 void nhm_uncore_cpu_init(void)
1001 uncore_msr_uncores
= nhm_msr_uncores
;
1004 /* end of Nehalem uncore support */