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_CML_H1_IMC 0x9b44
46 #define PCI_DEVICE_ID_INTEL_CML_H2_IMC 0x9b54
47 #define PCI_DEVICE_ID_INTEL_CML_H3_IMC 0x9b64
48 #define PCI_DEVICE_ID_INTEL_CML_U1_IMC 0x9b51
49 #define PCI_DEVICE_ID_INTEL_CML_U2_IMC 0x9b61
50 #define PCI_DEVICE_ID_INTEL_CML_U3_IMC 0x9b71
51 #define PCI_DEVICE_ID_INTEL_CML_S1_IMC 0x9b33
52 #define PCI_DEVICE_ID_INTEL_CML_S2_IMC 0x9b43
53 #define PCI_DEVICE_ID_INTEL_CML_S3_IMC 0x9b53
54 #define PCI_DEVICE_ID_INTEL_CML_S4_IMC 0x9b63
55 #define PCI_DEVICE_ID_INTEL_CML_S5_IMC 0x9b73
56 #define PCI_DEVICE_ID_INTEL_ICL_U_IMC 0x8a02
57 #define PCI_DEVICE_ID_INTEL_ICL_U2_IMC 0x8a12
58 #define PCI_DEVICE_ID_INTEL_TGL_U1_IMC 0x9a02
59 #define PCI_DEVICE_ID_INTEL_TGL_U2_IMC 0x9a04
60 #define PCI_DEVICE_ID_INTEL_TGL_U3_IMC 0x9a12
61 #define PCI_DEVICE_ID_INTEL_TGL_U4_IMC 0x9a14
62 #define PCI_DEVICE_ID_INTEL_TGL_H_IMC 0x9a36
65 /* SNB event control */
66 #define SNB_UNC_CTL_EV_SEL_MASK 0x000000ff
67 #define SNB_UNC_CTL_UMASK_MASK 0x0000ff00
68 #define SNB_UNC_CTL_EDGE_DET (1 << 18)
69 #define SNB_UNC_CTL_EN (1 << 22)
70 #define SNB_UNC_CTL_INVERT (1 << 23)
71 #define SNB_UNC_CTL_CMASK_MASK 0x1f000000
72 #define NHM_UNC_CTL_CMASK_MASK 0xff000000
73 #define NHM_UNC_FIXED_CTR_CTL_EN (1 << 0)
75 #define SNB_UNC_RAW_EVENT_MASK (SNB_UNC_CTL_EV_SEL_MASK | \
76 SNB_UNC_CTL_UMASK_MASK | \
77 SNB_UNC_CTL_EDGE_DET | \
78 SNB_UNC_CTL_INVERT | \
79 SNB_UNC_CTL_CMASK_MASK)
81 #define NHM_UNC_RAW_EVENT_MASK (SNB_UNC_CTL_EV_SEL_MASK | \
82 SNB_UNC_CTL_UMASK_MASK | \
83 SNB_UNC_CTL_EDGE_DET | \
84 SNB_UNC_CTL_INVERT | \
85 NHM_UNC_CTL_CMASK_MASK)
87 /* SNB global control register */
88 #define SNB_UNC_PERF_GLOBAL_CTL 0x391
89 #define SNB_UNC_FIXED_CTR_CTRL 0x394
90 #define SNB_UNC_FIXED_CTR 0x395
92 /* SNB uncore global control */
93 #define SNB_UNC_GLOBAL_CTL_CORE_ALL ((1 << 4) - 1)
94 #define SNB_UNC_GLOBAL_CTL_EN (1 << 29)
96 /* SNB Cbo register */
97 #define SNB_UNC_CBO_0_PERFEVTSEL0 0x700
98 #define SNB_UNC_CBO_0_PER_CTR0 0x706
99 #define SNB_UNC_CBO_MSR_OFFSET 0x10
101 /* SNB ARB register */
102 #define SNB_UNC_ARB_PER_CTR0 0x3b0
103 #define SNB_UNC_ARB_PERFEVTSEL0 0x3b2
104 #define SNB_UNC_ARB_MSR_OFFSET 0x10
106 /* NHM global control register */
107 #define NHM_UNC_PERF_GLOBAL_CTL 0x391
108 #define NHM_UNC_FIXED_CTR 0x394
109 #define NHM_UNC_FIXED_CTR_CTRL 0x395
111 /* NHM uncore global control */
112 #define NHM_UNC_GLOBAL_CTL_EN_PC_ALL ((1ULL << 8) - 1)
113 #define NHM_UNC_GLOBAL_CTL_EN_FC (1ULL << 32)
115 /* NHM uncore register */
116 #define NHM_UNC_PERFEVTSEL0 0x3c0
117 #define NHM_UNC_UNCORE_PMC0 0x3b0
119 /* SKL uncore global control */
120 #define SKL_UNC_PERF_GLOBAL_CTL 0xe01
121 #define SKL_UNC_GLOBAL_CTL_CORE_ALL ((1 << 5) - 1)
123 /* ICL Cbo register */
124 #define ICL_UNC_CBO_CONFIG 0x396
125 #define ICL_UNC_NUM_CBO_MASK 0xf
126 #define ICL_UNC_CBO_0_PER_CTR0 0x702
127 #define ICL_UNC_CBO_MSR_OFFSET 0x8
129 DEFINE_UNCORE_FORMAT_ATTR(event, event, "config:0-7");
130 DEFINE_UNCORE_FORMAT_ATTR(umask, umask, "config:8-15");
131 DEFINE_UNCORE_FORMAT_ATTR(edge, edge, "config:18");
132 DEFINE_UNCORE_FORMAT_ATTR(inv, inv, "config:23");
133 DEFINE_UNCORE_FORMAT_ATTR(cmask5, cmask, "config:24-28");
134 DEFINE_UNCORE_FORMAT_ATTR(cmask8, cmask, "config:24-31");
136 /* Sandy Bridge uncore support */
137 static void snb_uncore_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event)
139 struct hw_perf_event *hwc = &event->hw;
141 if (hwc->idx < UNCORE_PMC_IDX_FIXED)
142 wrmsrl(hwc->config_base, hwc->config | SNB_UNC_CTL_EN);
144 wrmsrl(hwc->config_base, SNB_UNC_CTL_EN);
147 static void snb_uncore_msr_disable_event(struct intel_uncore_box *box, struct perf_event *event)
149 wrmsrl(event->hw.config_base, 0);
152 static void snb_uncore_msr_init_box(struct intel_uncore_box *box)
154 if (box->pmu->pmu_idx == 0) {
155 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL,
156 SNB_UNC_GLOBAL_CTL_EN | SNB_UNC_GLOBAL_CTL_CORE_ALL);
160 static void snb_uncore_msr_enable_box(struct intel_uncore_box *box)
162 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL,
163 SNB_UNC_GLOBAL_CTL_EN | SNB_UNC_GLOBAL_CTL_CORE_ALL);
166 static void snb_uncore_msr_exit_box(struct intel_uncore_box *box)
168 if (box->pmu->pmu_idx == 0)
169 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL, 0);
172 static struct uncore_event_desc snb_uncore_events[] = {
173 INTEL_UNCORE_EVENT_DESC(clockticks, "event=0xff,umask=0x00"),
174 { /* end: all zeroes */ },
177 static struct attribute *snb_uncore_formats_attr[] = {
178 &format_attr_event.attr,
179 &format_attr_umask.attr,
180 &format_attr_edge.attr,
181 &format_attr_inv.attr,
182 &format_attr_cmask5.attr,
186 static const struct attribute_group snb_uncore_format_group = {
188 .attrs = snb_uncore_formats_attr,
191 static struct intel_uncore_ops snb_uncore_msr_ops = {
192 .init_box = snb_uncore_msr_init_box,
193 .enable_box = snb_uncore_msr_enable_box,
194 .exit_box = snb_uncore_msr_exit_box,
195 .disable_event = snb_uncore_msr_disable_event,
196 .enable_event = snb_uncore_msr_enable_event,
197 .read_counter = uncore_msr_read_counter,
200 static struct event_constraint snb_uncore_arb_constraints[] = {
201 UNCORE_EVENT_CONSTRAINT(0x80, 0x1),
202 UNCORE_EVENT_CONSTRAINT(0x83, 0x1),
206 static struct intel_uncore_type snb_uncore_cbox = {
211 .fixed_ctr_bits = 48,
212 .perf_ctr = SNB_UNC_CBO_0_PER_CTR0,
213 .event_ctl = SNB_UNC_CBO_0_PERFEVTSEL0,
214 .fixed_ctr = SNB_UNC_FIXED_CTR,
215 .fixed_ctl = SNB_UNC_FIXED_CTR_CTRL,
217 .event_mask = SNB_UNC_RAW_EVENT_MASK,
218 .msr_offset = SNB_UNC_CBO_MSR_OFFSET,
219 .ops = &snb_uncore_msr_ops,
220 .format_group = &snb_uncore_format_group,
221 .event_descs = snb_uncore_events,
224 static struct intel_uncore_type snb_uncore_arb = {
229 .perf_ctr = SNB_UNC_ARB_PER_CTR0,
230 .event_ctl = SNB_UNC_ARB_PERFEVTSEL0,
231 .event_mask = SNB_UNC_RAW_EVENT_MASK,
232 .msr_offset = SNB_UNC_ARB_MSR_OFFSET,
233 .constraints = snb_uncore_arb_constraints,
234 .ops = &snb_uncore_msr_ops,
235 .format_group = &snb_uncore_format_group,
238 static struct intel_uncore_type *snb_msr_uncores[] = {
244 void snb_uncore_cpu_init(void)
246 uncore_msr_uncores = snb_msr_uncores;
247 if (snb_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
248 snb_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
251 static void skl_uncore_msr_init_box(struct intel_uncore_box *box)
253 if (box->pmu->pmu_idx == 0) {
254 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL,
255 SNB_UNC_GLOBAL_CTL_EN | SKL_UNC_GLOBAL_CTL_CORE_ALL);
258 /* The 8th CBOX has different MSR space */
259 if (box->pmu->pmu_idx == 7)
260 __set_bit(UNCORE_BOX_FLAG_CFL8_CBOX_MSR_OFFS, &box->flags);
263 static void skl_uncore_msr_enable_box(struct intel_uncore_box *box)
265 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL,
266 SNB_UNC_GLOBAL_CTL_EN | SKL_UNC_GLOBAL_CTL_CORE_ALL);
269 static void skl_uncore_msr_exit_box(struct intel_uncore_box *box)
271 if (box->pmu->pmu_idx == 0)
272 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL, 0);
275 static struct intel_uncore_ops skl_uncore_msr_ops = {
276 .init_box = skl_uncore_msr_init_box,
277 .enable_box = skl_uncore_msr_enable_box,
278 .exit_box = skl_uncore_msr_exit_box,
279 .disable_event = snb_uncore_msr_disable_event,
280 .enable_event = snb_uncore_msr_enable_event,
281 .read_counter = uncore_msr_read_counter,
284 static struct intel_uncore_type skl_uncore_cbox = {
289 .fixed_ctr_bits = 48,
290 .perf_ctr = SNB_UNC_CBO_0_PER_CTR0,
291 .event_ctl = SNB_UNC_CBO_0_PERFEVTSEL0,
292 .fixed_ctr = SNB_UNC_FIXED_CTR,
293 .fixed_ctl = SNB_UNC_FIXED_CTR_CTRL,
295 .event_mask = SNB_UNC_RAW_EVENT_MASK,
296 .msr_offset = SNB_UNC_CBO_MSR_OFFSET,
297 .ops = &skl_uncore_msr_ops,
298 .format_group = &snb_uncore_format_group,
299 .event_descs = snb_uncore_events,
302 static struct intel_uncore_type *skl_msr_uncores[] = {
308 void skl_uncore_cpu_init(void)
310 uncore_msr_uncores = skl_msr_uncores;
311 if (skl_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores)
312 skl_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores;
313 snb_uncore_arb.ops = &skl_uncore_msr_ops;
316 static struct intel_uncore_type icl_uncore_cbox = {
320 .perf_ctr = ICL_UNC_CBO_0_PER_CTR0,
321 .event_ctl = SNB_UNC_CBO_0_PERFEVTSEL0,
322 .event_mask = SNB_UNC_RAW_EVENT_MASK,
323 .msr_offset = ICL_UNC_CBO_MSR_OFFSET,
324 .ops = &skl_uncore_msr_ops,
325 .format_group = &snb_uncore_format_group,
328 static struct uncore_event_desc icl_uncore_events[] = {
329 INTEL_UNCORE_EVENT_DESC(clockticks, "event=0xff"),
330 { /* end: all zeroes */ },
333 static struct attribute *icl_uncore_clock_formats_attr[] = {
334 &format_attr_event.attr,
338 static struct attribute_group icl_uncore_clock_format_group = {
340 .attrs = icl_uncore_clock_formats_attr,
343 static struct intel_uncore_type icl_uncore_clockbox = {
347 .fixed_ctr_bits = 48,
348 .fixed_ctr = SNB_UNC_FIXED_CTR,
349 .fixed_ctl = SNB_UNC_FIXED_CTR_CTRL,
351 .event_mask = SNB_UNC_CTL_EV_SEL_MASK,
352 .format_group = &icl_uncore_clock_format_group,
353 .ops = &skl_uncore_msr_ops,
354 .event_descs = icl_uncore_events,
357 static struct intel_uncore_type *icl_msr_uncores[] = {
360 &icl_uncore_clockbox,
364 static int icl_get_cbox_num(void)
368 rdmsrl(ICL_UNC_CBO_CONFIG, num_boxes);
370 return num_boxes & ICL_UNC_NUM_CBO_MASK;
373 void icl_uncore_cpu_init(void)
375 uncore_msr_uncores = icl_msr_uncores;
376 icl_uncore_cbox.num_boxes = icl_get_cbox_num();
377 snb_uncore_arb.ops = &skl_uncore_msr_ops;
384 static struct uncore_event_desc snb_uncore_imc_events[] = {
385 INTEL_UNCORE_EVENT_DESC(data_reads, "event=0x01"),
386 INTEL_UNCORE_EVENT_DESC(data_reads.scale, "6.103515625e-5"),
387 INTEL_UNCORE_EVENT_DESC(data_reads.unit, "MiB"),
389 INTEL_UNCORE_EVENT_DESC(data_writes, "event=0x02"),
390 INTEL_UNCORE_EVENT_DESC(data_writes.scale, "6.103515625e-5"),
391 INTEL_UNCORE_EVENT_DESC(data_writes.unit, "MiB"),
393 { /* end: all zeroes */ },
396 #define SNB_UNCORE_PCI_IMC_EVENT_MASK 0xff
397 #define SNB_UNCORE_PCI_IMC_BAR_OFFSET 0x48
399 /* page size multiple covering all config regs */
400 #define SNB_UNCORE_PCI_IMC_MAP_SIZE 0x6000
402 #define SNB_UNCORE_PCI_IMC_DATA_READS 0x1
403 #define SNB_UNCORE_PCI_IMC_DATA_READS_BASE 0x5050
404 #define SNB_UNCORE_PCI_IMC_DATA_WRITES 0x2
405 #define SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE 0x5054
406 #define SNB_UNCORE_PCI_IMC_CTR_BASE SNB_UNCORE_PCI_IMC_DATA_READS_BASE
408 enum perf_snb_uncore_imc_freerunning_types {
409 SNB_PCI_UNCORE_IMC_DATA = 0,
410 SNB_PCI_UNCORE_IMC_FREERUNNING_TYPE_MAX,
413 static struct freerunning_counters snb_uncore_imc_freerunning[] = {
414 [SNB_PCI_UNCORE_IMC_DATA] = { SNB_UNCORE_PCI_IMC_DATA_READS_BASE, 0x4, 0x0, 2, 32 },
417 static struct attribute *snb_uncore_imc_formats_attr[] = {
418 &format_attr_event.attr,
422 static const struct attribute_group snb_uncore_imc_format_group = {
424 .attrs = snb_uncore_imc_formats_attr,
427 static void snb_uncore_imc_init_box(struct intel_uncore_box *box)
429 struct intel_uncore_type *type = box->pmu->type;
430 struct pci_dev *pdev = box->pci_dev;
431 int where = SNB_UNCORE_PCI_IMC_BAR_OFFSET;
432 resource_size_t addr;
435 pci_read_config_dword(pdev, where, &pci_dword);
438 #ifdef CONFIG_PHYS_ADDR_T_64BIT
439 pci_read_config_dword(pdev, where + 4, &pci_dword);
440 addr |= ((resource_size_t)pci_dword << 32);
443 addr &= ~(PAGE_SIZE - 1);
445 box->io_addr = ioremap(addr, type->mmio_map_size);
447 pr_warn("perf uncore: Failed to ioremap for %s.\n", type->name);
449 box->hrtimer_duration = UNCORE_SNB_IMC_HRTIMER_INTERVAL;
452 static void snb_uncore_imc_enable_box(struct intel_uncore_box *box)
455 static void snb_uncore_imc_disable_box(struct intel_uncore_box *box)
458 static void snb_uncore_imc_enable_event(struct intel_uncore_box *box, struct perf_event *event)
461 static void snb_uncore_imc_disable_event(struct intel_uncore_box *box, struct perf_event *event)
465 * Keep the custom event_init() function compatible with old event
466 * encoding for free running counters.
468 static int snb_uncore_imc_event_init(struct perf_event *event)
470 struct intel_uncore_pmu *pmu;
471 struct intel_uncore_box *box;
472 struct hw_perf_event *hwc = &event->hw;
473 u64 cfg = event->attr.config & SNB_UNCORE_PCI_IMC_EVENT_MASK;
476 if (event->attr.type != event->pmu->type)
479 pmu = uncore_event_to_pmu(event);
480 /* no device found for this pmu */
481 if (pmu->func_id < 0)
484 /* Sampling not supported yet */
485 if (hwc->sample_period)
488 /* unsupported modes and filters */
489 if (event->attr.sample_period) /* no sampling */
493 * Place all uncore events for a particular physical package
499 /* check only supported bits are set */
500 if (event->attr.config & ~SNB_UNCORE_PCI_IMC_EVENT_MASK)
503 box = uncore_pmu_to_box(pmu, event->cpu);
504 if (!box || box->cpu < 0)
507 event->cpu = box->cpu;
508 event->pmu_private = box;
510 event->event_caps |= PERF_EV_CAP_READ_ACTIVE_PKG;
513 event->hw.last_tag = ~0ULL;
514 event->hw.extra_reg.idx = EXTRA_REG_NONE;
515 event->hw.branch_reg.idx = EXTRA_REG_NONE;
517 * check event is known (whitelist, determines counter)
520 case SNB_UNCORE_PCI_IMC_DATA_READS:
521 base = SNB_UNCORE_PCI_IMC_DATA_READS_BASE;
522 idx = UNCORE_PMC_IDX_FREERUNNING;
524 case SNB_UNCORE_PCI_IMC_DATA_WRITES:
525 base = SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE;
526 idx = UNCORE_PMC_IDX_FREERUNNING;
532 /* must be done before validate_group */
533 event->hw.event_base = base;
536 /* Convert to standard encoding format for freerunning counters */
537 event->hw.config = ((cfg - 1) << 8) | 0x10ff;
539 /* no group validation needed, we have free running counters */
544 static int snb_uncore_imc_hw_config(struct intel_uncore_box *box, struct perf_event *event)
549 int snb_pci2phy_map_init(int devid)
551 struct pci_dev *dev = NULL;
552 struct pci2phy_map *map;
555 dev = pci_get_device(PCI_VENDOR_ID_INTEL, devid, dev);
559 bus = dev->bus->number;
560 segment = pci_domain_nr(dev->bus);
562 raw_spin_lock(&pci2phy_map_lock);
563 map = __find_pci2phy_map(segment);
565 raw_spin_unlock(&pci2phy_map_lock);
569 map->pbus_to_physid[bus] = 0;
570 raw_spin_unlock(&pci2phy_map_lock);
577 static struct pmu snb_uncore_imc_pmu = {
578 .task_ctx_nr = perf_invalid_context,
579 .event_init = snb_uncore_imc_event_init,
580 .add = uncore_pmu_event_add,
581 .del = uncore_pmu_event_del,
582 .start = uncore_pmu_event_start,
583 .stop = uncore_pmu_event_stop,
584 .read = uncore_pmu_event_read,
585 .capabilities = PERF_PMU_CAP_NO_EXCLUDE,
588 static struct intel_uncore_ops snb_uncore_imc_ops = {
589 .init_box = snb_uncore_imc_init_box,
590 .exit_box = uncore_mmio_exit_box,
591 .enable_box = snb_uncore_imc_enable_box,
592 .disable_box = snb_uncore_imc_disable_box,
593 .disable_event = snb_uncore_imc_disable_event,
594 .enable_event = snb_uncore_imc_enable_event,
595 .hw_config = snb_uncore_imc_hw_config,
596 .read_counter = uncore_mmio_read_counter,
599 static struct intel_uncore_type snb_uncore_imc = {
603 .num_freerunning_types = SNB_PCI_UNCORE_IMC_FREERUNNING_TYPE_MAX,
604 .mmio_map_size = SNB_UNCORE_PCI_IMC_MAP_SIZE,
605 .freerunning = snb_uncore_imc_freerunning,
606 .event_descs = snb_uncore_imc_events,
607 .format_group = &snb_uncore_imc_format_group,
608 .ops = &snb_uncore_imc_ops,
609 .pmu = &snb_uncore_imc_pmu,
612 static struct intel_uncore_type *snb_pci_uncores[] = {
613 [SNB_PCI_UNCORE_IMC] = &snb_uncore_imc,
617 static const struct pci_device_id snb_uncore_pci_ids[] = {
619 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SNB_IMC),
620 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
622 { /* end: all zeroes */ },
625 static const struct pci_device_id ivb_uncore_pci_ids[] = {
627 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IVB_IMC),
628 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
631 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IVB_E3_IMC),
632 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
634 { /* end: all zeroes */ },
637 static const struct pci_device_id hsw_uncore_pci_ids[] = {
639 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HSW_IMC),
640 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
643 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_HSW_U_IMC),
644 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
646 { /* end: all zeroes */ },
649 static const struct pci_device_id bdw_uncore_pci_ids[] = {
651 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BDW_IMC),
652 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
654 { /* end: all zeroes */ },
657 static const struct pci_device_id skl_uncore_pci_ids[] = {
659 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SKL_Y_IMC),
660 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
663 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SKL_U_IMC),
664 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
667 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SKL_HD_IMC),
668 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
671 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SKL_HQ_IMC),
672 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
675 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SKL_SD_IMC),
676 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
679 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SKL_SQ_IMC),
680 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
683 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SKL_E3_IMC),
684 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
687 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBL_Y_IMC),
688 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
691 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBL_U_IMC),
692 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
695 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBL_UQ_IMC),
696 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
699 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBL_SD_IMC),
700 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
703 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBL_SQ_IMC),
704 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
707 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBL_HQ_IMC),
708 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
711 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_KBL_WQ_IMC),
712 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
715 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_2U_IMC),
716 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
719 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_4U_IMC),
720 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
723 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_4H_IMC),
724 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
727 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_6H_IMC),
728 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
731 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_2S_D_IMC),
732 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
735 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_4S_D_IMC),
736 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
739 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_6S_D_IMC),
740 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
743 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_8S_D_IMC),
744 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
747 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_4S_W_IMC),
748 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
751 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_6S_W_IMC),
752 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
755 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_8S_W_IMC),
756 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
759 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_4S_S_IMC),
760 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
763 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_6S_S_IMC),
764 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
767 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CFL_8S_S_IMC),
768 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
771 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AML_YD_IMC),
772 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
775 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AML_YQ_IMC),
776 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
779 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WHL_UQ_IMC),
780 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
783 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WHL_4_UQ_IMC),
784 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
787 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_WHL_UD_IMC),
788 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
791 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_H1_IMC),
792 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
795 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_H2_IMC),
796 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
799 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_H3_IMC),
800 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
803 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_U1_IMC),
804 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
807 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_U2_IMC),
808 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
811 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_U3_IMC),
812 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
815 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_S1_IMC),
816 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
819 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_S2_IMC),
820 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
823 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_S3_IMC),
824 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
827 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_S4_IMC),
828 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
831 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CML_S5_IMC),
832 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
834 { /* end: all zeroes */ },
837 static const struct pci_device_id icl_uncore_pci_ids[] = {
839 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICL_U_IMC),
840 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
843 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICL_U2_IMC),
844 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
846 { /* end: all zeroes */ },
849 static struct pci_driver snb_uncore_pci_driver = {
850 .name = "snb_uncore",
851 .id_table = snb_uncore_pci_ids,
854 static struct pci_driver ivb_uncore_pci_driver = {
855 .name = "ivb_uncore",
856 .id_table = ivb_uncore_pci_ids,
859 static struct pci_driver hsw_uncore_pci_driver = {
860 .name = "hsw_uncore",
861 .id_table = hsw_uncore_pci_ids,
864 static struct pci_driver bdw_uncore_pci_driver = {
865 .name = "bdw_uncore",
866 .id_table = bdw_uncore_pci_ids,
869 static struct pci_driver skl_uncore_pci_driver = {
870 .name = "skl_uncore",
871 .id_table = skl_uncore_pci_ids,
874 static struct pci_driver icl_uncore_pci_driver = {
875 .name = "icl_uncore",
876 .id_table = icl_uncore_pci_ids,
879 struct imc_uncore_pci_dev {
881 struct pci_driver *driver;
883 #define IMC_DEV(a, d) \
884 { .pci_id = PCI_DEVICE_ID_INTEL_##a, .driver = (d) }
886 static const struct imc_uncore_pci_dev desktop_imc_pci_ids[] = {
887 IMC_DEV(SNB_IMC, &snb_uncore_pci_driver),
888 IMC_DEV(IVB_IMC, &ivb_uncore_pci_driver), /* 3rd Gen Core processor */
889 IMC_DEV(IVB_E3_IMC, &ivb_uncore_pci_driver), /* Xeon E3-1200 v2/3rd Gen Core processor */
890 IMC_DEV(HSW_IMC, &hsw_uncore_pci_driver), /* 4th Gen Core Processor */
891 IMC_DEV(HSW_U_IMC, &hsw_uncore_pci_driver), /* 4th Gen Core ULT Mobile Processor */
892 IMC_DEV(BDW_IMC, &bdw_uncore_pci_driver), /* 5th Gen Core U */
893 IMC_DEV(SKL_Y_IMC, &skl_uncore_pci_driver), /* 6th Gen Core Y */
894 IMC_DEV(SKL_U_IMC, &skl_uncore_pci_driver), /* 6th Gen Core U */
895 IMC_DEV(SKL_HD_IMC, &skl_uncore_pci_driver), /* 6th Gen Core H Dual Core */
896 IMC_DEV(SKL_HQ_IMC, &skl_uncore_pci_driver), /* 6th Gen Core H Quad Core */
897 IMC_DEV(SKL_SD_IMC, &skl_uncore_pci_driver), /* 6th Gen Core S Dual Core */
898 IMC_DEV(SKL_SQ_IMC, &skl_uncore_pci_driver), /* 6th Gen Core S Quad Core */
899 IMC_DEV(SKL_E3_IMC, &skl_uncore_pci_driver), /* Xeon E3 V5 Gen Core processor */
900 IMC_DEV(KBL_Y_IMC, &skl_uncore_pci_driver), /* 7th Gen Core Y */
901 IMC_DEV(KBL_U_IMC, &skl_uncore_pci_driver), /* 7th Gen Core U */
902 IMC_DEV(KBL_UQ_IMC, &skl_uncore_pci_driver), /* 7th Gen Core U Quad Core */
903 IMC_DEV(KBL_SD_IMC, &skl_uncore_pci_driver), /* 7th Gen Core S Dual Core */
904 IMC_DEV(KBL_SQ_IMC, &skl_uncore_pci_driver), /* 7th Gen Core S Quad Core */
905 IMC_DEV(KBL_HQ_IMC, &skl_uncore_pci_driver), /* 7th Gen Core H Quad Core */
906 IMC_DEV(KBL_WQ_IMC, &skl_uncore_pci_driver), /* 7th Gen Core S 4 cores Work Station */
907 IMC_DEV(CFL_2U_IMC, &skl_uncore_pci_driver), /* 8th Gen Core U 2 Cores */
908 IMC_DEV(CFL_4U_IMC, &skl_uncore_pci_driver), /* 8th Gen Core U 4 Cores */
909 IMC_DEV(CFL_4H_IMC, &skl_uncore_pci_driver), /* 8th Gen Core H 4 Cores */
910 IMC_DEV(CFL_6H_IMC, &skl_uncore_pci_driver), /* 8th Gen Core H 6 Cores */
911 IMC_DEV(CFL_2S_D_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 2 Cores Desktop */
912 IMC_DEV(CFL_4S_D_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 4 Cores Desktop */
913 IMC_DEV(CFL_6S_D_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 6 Cores Desktop */
914 IMC_DEV(CFL_8S_D_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 8 Cores Desktop */
915 IMC_DEV(CFL_4S_W_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 4 Cores Work Station */
916 IMC_DEV(CFL_6S_W_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 6 Cores Work Station */
917 IMC_DEV(CFL_8S_W_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 8 Cores Work Station */
918 IMC_DEV(CFL_4S_S_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 4 Cores Server */
919 IMC_DEV(CFL_6S_S_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 6 Cores Server */
920 IMC_DEV(CFL_8S_S_IMC, &skl_uncore_pci_driver), /* 8th Gen Core S 8 Cores Server */
921 IMC_DEV(AML_YD_IMC, &skl_uncore_pci_driver), /* 8th Gen Core Y Mobile Dual Core */
922 IMC_DEV(AML_YQ_IMC, &skl_uncore_pci_driver), /* 8th Gen Core Y Mobile Quad Core */
923 IMC_DEV(WHL_UQ_IMC, &skl_uncore_pci_driver), /* 8th Gen Core U Mobile Quad Core */
924 IMC_DEV(WHL_4_UQ_IMC, &skl_uncore_pci_driver), /* 8th Gen Core U Mobile Quad Core */
925 IMC_DEV(WHL_UD_IMC, &skl_uncore_pci_driver), /* 8th Gen Core U Mobile Dual Core */
926 IMC_DEV(CML_H1_IMC, &skl_uncore_pci_driver),
927 IMC_DEV(CML_H2_IMC, &skl_uncore_pci_driver),
928 IMC_DEV(CML_H3_IMC, &skl_uncore_pci_driver),
929 IMC_DEV(CML_U1_IMC, &skl_uncore_pci_driver),
930 IMC_DEV(CML_U2_IMC, &skl_uncore_pci_driver),
931 IMC_DEV(CML_U3_IMC, &skl_uncore_pci_driver),
932 IMC_DEV(CML_S1_IMC, &skl_uncore_pci_driver),
933 IMC_DEV(CML_S2_IMC, &skl_uncore_pci_driver),
934 IMC_DEV(CML_S3_IMC, &skl_uncore_pci_driver),
935 IMC_DEV(CML_S4_IMC, &skl_uncore_pci_driver),
936 IMC_DEV(CML_S5_IMC, &skl_uncore_pci_driver),
937 IMC_DEV(ICL_U_IMC, &icl_uncore_pci_driver), /* 10th Gen Core Mobile */
938 IMC_DEV(ICL_U2_IMC, &icl_uncore_pci_driver), /* 10th Gen Core Mobile */
943 #define for_each_imc_pci_id(x, t) \
944 for (x = (t); (x)->pci_id; x++)
946 static struct pci_driver *imc_uncore_find_dev(void)
948 const struct imc_uncore_pci_dev *p;
951 for_each_imc_pci_id(p, desktop_imc_pci_ids) {
952 ret = snb_pci2phy_map_init(p->pci_id);
959 static int imc_uncore_pci_init(void)
961 struct pci_driver *imc_drv = imc_uncore_find_dev();
966 uncore_pci_uncores = snb_pci_uncores;
967 uncore_pci_driver = imc_drv;
972 int snb_uncore_pci_init(void)
974 return imc_uncore_pci_init();
977 int ivb_uncore_pci_init(void)
979 return imc_uncore_pci_init();
981 int hsw_uncore_pci_init(void)
983 return imc_uncore_pci_init();
986 int bdw_uncore_pci_init(void)
988 return imc_uncore_pci_init();
991 int skl_uncore_pci_init(void)
993 return imc_uncore_pci_init();
996 /* end of Sandy Bridge uncore support */
998 /* Nehalem uncore support */
999 static void nhm_uncore_msr_disable_box(struct intel_uncore_box *box)
1001 wrmsrl(NHM_UNC_PERF_GLOBAL_CTL, 0);
1004 static void nhm_uncore_msr_enable_box(struct intel_uncore_box *box)
1006 wrmsrl(NHM_UNC_PERF_GLOBAL_CTL, NHM_UNC_GLOBAL_CTL_EN_PC_ALL | NHM_UNC_GLOBAL_CTL_EN_FC);
1009 static void nhm_uncore_msr_enable_event(struct intel_uncore_box *box, struct perf_event *event)
1011 struct hw_perf_event *hwc = &event->hw;
1013 if (hwc->idx < UNCORE_PMC_IDX_FIXED)
1014 wrmsrl(hwc->config_base, hwc->config | SNB_UNC_CTL_EN);
1016 wrmsrl(hwc->config_base, NHM_UNC_FIXED_CTR_CTL_EN);
1019 static struct attribute *nhm_uncore_formats_attr[] = {
1020 &format_attr_event.attr,
1021 &format_attr_umask.attr,
1022 &format_attr_edge.attr,
1023 &format_attr_inv.attr,
1024 &format_attr_cmask8.attr,
1028 static const struct attribute_group nhm_uncore_format_group = {
1030 .attrs = nhm_uncore_formats_attr,
1033 static struct uncore_event_desc nhm_uncore_events[] = {
1034 INTEL_UNCORE_EVENT_DESC(clockticks, "event=0xff,umask=0x00"),
1035 INTEL_UNCORE_EVENT_DESC(qmc_writes_full_any, "event=0x2f,umask=0x0f"),
1036 INTEL_UNCORE_EVENT_DESC(qmc_normal_reads_any, "event=0x2c,umask=0x0f"),
1037 INTEL_UNCORE_EVENT_DESC(qhl_request_ioh_reads, "event=0x20,umask=0x01"),
1038 INTEL_UNCORE_EVENT_DESC(qhl_request_ioh_writes, "event=0x20,umask=0x02"),
1039 INTEL_UNCORE_EVENT_DESC(qhl_request_remote_reads, "event=0x20,umask=0x04"),
1040 INTEL_UNCORE_EVENT_DESC(qhl_request_remote_writes, "event=0x20,umask=0x08"),
1041 INTEL_UNCORE_EVENT_DESC(qhl_request_local_reads, "event=0x20,umask=0x10"),
1042 INTEL_UNCORE_EVENT_DESC(qhl_request_local_writes, "event=0x20,umask=0x20"),
1043 { /* end: all zeroes */ },
1046 static struct intel_uncore_ops nhm_uncore_msr_ops = {
1047 .disable_box = nhm_uncore_msr_disable_box,
1048 .enable_box = nhm_uncore_msr_enable_box,
1049 .disable_event = snb_uncore_msr_disable_event,
1050 .enable_event = nhm_uncore_msr_enable_event,
1051 .read_counter = uncore_msr_read_counter,
1054 static struct intel_uncore_type nhm_uncore = {
1058 .perf_ctr_bits = 48,
1059 .fixed_ctr_bits = 48,
1060 .event_ctl = NHM_UNC_PERFEVTSEL0,
1061 .perf_ctr = NHM_UNC_UNCORE_PMC0,
1062 .fixed_ctr = NHM_UNC_FIXED_CTR,
1063 .fixed_ctl = NHM_UNC_FIXED_CTR_CTRL,
1064 .event_mask = NHM_UNC_RAW_EVENT_MASK,
1065 .event_descs = nhm_uncore_events,
1066 .ops = &nhm_uncore_msr_ops,
1067 .format_group = &nhm_uncore_format_group,
1070 static struct intel_uncore_type *nhm_msr_uncores[] = {
1075 void nhm_uncore_cpu_init(void)
1077 uncore_msr_uncores = nhm_msr_uncores;
1080 /* end of Nehalem uncore support */
1082 /* Tiger Lake MMIO uncore support */
1084 static const struct pci_device_id tgl_uncore_pci_ids[] = {
1086 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TGL_U1_IMC),
1087 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
1090 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TGL_U2_IMC),
1091 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
1094 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TGL_U3_IMC),
1095 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
1098 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TGL_U4_IMC),
1099 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
1102 PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TGL_H_IMC),
1103 .driver_data = UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC, 0),
1105 { /* end: all zeroes */ }
1108 enum perf_tgl_uncore_imc_freerunning_types {
1109 TGL_MMIO_UNCORE_IMC_DATA_TOTAL,
1110 TGL_MMIO_UNCORE_IMC_DATA_READ,
1111 TGL_MMIO_UNCORE_IMC_DATA_WRITE,
1112 TGL_MMIO_UNCORE_IMC_FREERUNNING_TYPE_MAX
1115 static struct freerunning_counters tgl_l_uncore_imc_freerunning[] = {
1116 [TGL_MMIO_UNCORE_IMC_DATA_TOTAL] = { 0x5040, 0x0, 0x0, 1, 64 },
1117 [TGL_MMIO_UNCORE_IMC_DATA_READ] = { 0x5058, 0x0, 0x0, 1, 64 },
1118 [TGL_MMIO_UNCORE_IMC_DATA_WRITE] = { 0x50A0, 0x0, 0x0, 1, 64 },
1121 static struct freerunning_counters tgl_uncore_imc_freerunning[] = {
1122 [TGL_MMIO_UNCORE_IMC_DATA_TOTAL] = { 0xd840, 0x0, 0x0, 1, 64 },
1123 [TGL_MMIO_UNCORE_IMC_DATA_READ] = { 0xd858, 0x0, 0x0, 1, 64 },
1124 [TGL_MMIO_UNCORE_IMC_DATA_WRITE] = { 0xd8A0, 0x0, 0x0, 1, 64 },
1127 static struct uncore_event_desc tgl_uncore_imc_events[] = {
1128 INTEL_UNCORE_EVENT_DESC(data_total, "event=0xff,umask=0x10"),
1129 INTEL_UNCORE_EVENT_DESC(data_total.scale, "6.103515625e-5"),
1130 INTEL_UNCORE_EVENT_DESC(data_total.unit, "MiB"),
1132 INTEL_UNCORE_EVENT_DESC(data_read, "event=0xff,umask=0x20"),
1133 INTEL_UNCORE_EVENT_DESC(data_read.scale, "6.103515625e-5"),
1134 INTEL_UNCORE_EVENT_DESC(data_read.unit, "MiB"),
1136 INTEL_UNCORE_EVENT_DESC(data_write, "event=0xff,umask=0x30"),
1137 INTEL_UNCORE_EVENT_DESC(data_write.scale, "6.103515625e-5"),
1138 INTEL_UNCORE_EVENT_DESC(data_write.unit, "MiB"),
1140 { /* end: all zeroes */ }
1143 static struct pci_dev *tgl_uncore_get_mc_dev(void)
1145 const struct pci_device_id *ids = tgl_uncore_pci_ids;
1146 struct pci_dev *mc_dev = NULL;
1148 while (ids && ids->vendor) {
1149 mc_dev = pci_get_device(PCI_VENDOR_ID_INTEL, ids->device, NULL);
1158 #define TGL_UNCORE_MMIO_IMC_MEM_OFFSET 0x10000
1159 #define TGL_UNCORE_PCI_IMC_MAP_SIZE 0xe000
1161 static void tgl_uncore_imc_freerunning_init_box(struct intel_uncore_box *box)
1163 struct pci_dev *pdev = tgl_uncore_get_mc_dev();
1164 struct intel_uncore_pmu *pmu = box->pmu;
1165 struct intel_uncore_type *type = pmu->type;
1166 resource_size_t addr;
1170 pr_warn("perf uncore: Cannot find matched IMC device.\n");
1174 pci_read_config_dword(pdev, SNB_UNCORE_PCI_IMC_BAR_OFFSET, &mch_bar);
1175 /* MCHBAR is disabled */
1176 if (!(mch_bar & BIT(0))) {
1177 pr_warn("perf uncore: MCHBAR is disabled. Failed to map IMC free-running counters.\n");
1181 addr = (resource_size_t)(mch_bar + TGL_UNCORE_MMIO_IMC_MEM_OFFSET * pmu->pmu_idx);
1183 #ifdef CONFIG_PHYS_ADDR_T_64BIT
1184 pci_read_config_dword(pdev, SNB_UNCORE_PCI_IMC_BAR_OFFSET + 4, &mch_bar);
1185 addr |= ((resource_size_t)mch_bar << 32);
1188 box->io_addr = ioremap(addr, type->mmio_map_size);
1190 pr_warn("perf uncore: Failed to ioremap for %s.\n", type->name);
1193 static struct intel_uncore_ops tgl_uncore_imc_freerunning_ops = {
1194 .init_box = tgl_uncore_imc_freerunning_init_box,
1195 .exit_box = uncore_mmio_exit_box,
1196 .read_counter = uncore_mmio_read_counter,
1197 .hw_config = uncore_freerunning_hw_config,
1200 static struct attribute *tgl_uncore_imc_formats_attr[] = {
1201 &format_attr_event.attr,
1202 &format_attr_umask.attr,
1206 static const struct attribute_group tgl_uncore_imc_format_group = {
1208 .attrs = tgl_uncore_imc_formats_attr,
1211 static struct intel_uncore_type tgl_uncore_imc_free_running = {
1212 .name = "imc_free_running",
1215 .num_freerunning_types = TGL_MMIO_UNCORE_IMC_FREERUNNING_TYPE_MAX,
1216 .mmio_map_size = TGL_UNCORE_PCI_IMC_MAP_SIZE,
1217 .freerunning = tgl_uncore_imc_freerunning,
1218 .ops = &tgl_uncore_imc_freerunning_ops,
1219 .event_descs = tgl_uncore_imc_events,
1220 .format_group = &tgl_uncore_imc_format_group,
1223 static struct intel_uncore_type *tgl_mmio_uncores[] = {
1224 &tgl_uncore_imc_free_running,
1228 void tgl_l_uncore_mmio_init(void)
1230 tgl_uncore_imc_free_running.freerunning = tgl_l_uncore_imc_freerunning;
1231 uncore_mmio_uncores = tgl_mmio_uncores;
1234 void tgl_uncore_mmio_init(void)
1236 uncore_mmio_uncores = tgl_mmio_uncores;
1239 /* end of Tiger Lake MMIO uncore support */