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
19 /* SNB event control */
20 #define SNB_UNC_CTL_EV_SEL_MASK 0x000000ff
21 #define SNB_UNC_CTL_UMASK_MASK 0x0000ff00
22 #define SNB_UNC_CTL_EDGE_DET (1 << 18)
23 #define SNB_UNC_CTL_EN (1 << 22)
24 #define SNB_UNC_CTL_INVERT (1 << 23)
25 #define SNB_UNC_CTL_CMASK_MASK 0x1f000000
26 #define NHM_UNC_CTL_CMASK_MASK 0xff000000
27 #define NHM_UNC_FIXED_CTR_CTL_EN (1 << 0)
29 #define SNB_UNC_RAW_EVENT_MASK (SNB_UNC_CTL_EV_SEL_MASK | \
30 SNB_UNC_CTL_UMASK_MASK | \
31 SNB_UNC_CTL_EDGE_DET | \
32 SNB_UNC_CTL_INVERT | \
33 SNB_UNC_CTL_CMASK_MASK)
35 #define NHM_UNC_RAW_EVENT_MASK (SNB_UNC_CTL_EV_SEL_MASK | \
36 SNB_UNC_CTL_UMASK_MASK | \
37 SNB_UNC_CTL_EDGE_DET | \
38 SNB_UNC_CTL_INVERT | \
39 NHM_UNC_CTL_CMASK_MASK)
41 /* SNB global control register */
42 #define SNB_UNC_PERF_GLOBAL_CTL 0x391
43 #define SNB_UNC_FIXED_CTR_CTRL 0x394
44 #define SNB_UNC_FIXED_CTR 0x395
46 /* SNB uncore global control */
47 #define SNB_UNC_GLOBAL_CTL_CORE_ALL ((1 << 4) - 1)
48 #define SNB_UNC_GLOBAL_CTL_EN (1 << 29)
50 /* SNB Cbo register */
51 #define SNB_UNC_CBO_0_PERFEVTSEL0 0x700
52 #define SNB_UNC_CBO_0_PER_CTR0 0x706
53 #define SNB_UNC_CBO_MSR_OFFSET 0x10
55 /* SNB ARB register */
56 #define SNB_UNC_ARB_PER_CTR0 0x3b0
57 #define SNB_UNC_ARB_PERFEVTSEL0 0x3b2
58 #define SNB_UNC_ARB_MSR_OFFSET 0x10
60 /* NHM global control register */
61 #define NHM_UNC_PERF_GLOBAL_CTL 0x391
62 #define NHM_UNC_FIXED_CTR 0x394
63 #define NHM_UNC_FIXED_CTR_CTRL 0x395
65 /* NHM uncore global control */
66 #define NHM_UNC_GLOBAL_CTL_EN_PC_ALL ((1ULL << 8) - 1)
67 #define NHM_UNC_GLOBAL_CTL_EN_FC (1ULL << 32)
69 /* NHM uncore register */
70 #define NHM_UNC_PERFEVTSEL0 0x3c0
71 #define NHM_UNC_UNCORE_PMC0 0x3b0
73 /* SKL uncore global control */
74 #define SKL_UNC_PERF_GLOBAL_CTL 0xe01
75 #define SKL_UNC_GLOBAL_CTL_CORE_ALL ((1 << 5) - 1)
77 DEFINE_UNCORE_FORMAT_ATTR(event
, event
, "config:0-7");
78 DEFINE_UNCORE_FORMAT_ATTR(umask
, umask
, "config:8-15");
79 DEFINE_UNCORE_FORMAT_ATTR(edge
, edge
, "config:18");
80 DEFINE_UNCORE_FORMAT_ATTR(inv
, inv
, "config:23");
81 DEFINE_UNCORE_FORMAT_ATTR(cmask5
, cmask
, "config:24-28");
82 DEFINE_UNCORE_FORMAT_ATTR(cmask8
, cmask
, "config:24-31");
84 /* Sandy Bridge uncore support */
85 static void snb_uncore_msr_enable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
87 struct hw_perf_event
*hwc
= &event
->hw
;
89 if (hwc
->idx
< UNCORE_PMC_IDX_FIXED
)
90 wrmsrl(hwc
->config_base
, hwc
->config
| SNB_UNC_CTL_EN
);
92 wrmsrl(hwc
->config_base
, SNB_UNC_CTL_EN
);
95 static void snb_uncore_msr_disable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
97 wrmsrl(event
->hw
.config_base
, 0);
100 static void snb_uncore_msr_init_box(struct intel_uncore_box
*box
)
102 if (box
->pmu
->pmu_idx
== 0) {
103 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL
,
104 SNB_UNC_GLOBAL_CTL_EN
| SNB_UNC_GLOBAL_CTL_CORE_ALL
);
108 static void snb_uncore_msr_enable_box(struct intel_uncore_box
*box
)
110 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL
,
111 SNB_UNC_GLOBAL_CTL_EN
| SNB_UNC_GLOBAL_CTL_CORE_ALL
);
114 static void snb_uncore_msr_exit_box(struct intel_uncore_box
*box
)
116 if (box
->pmu
->pmu_idx
== 0)
117 wrmsrl(SNB_UNC_PERF_GLOBAL_CTL
, 0);
120 static struct uncore_event_desc snb_uncore_events
[] = {
121 INTEL_UNCORE_EVENT_DESC(clockticks
, "event=0xff,umask=0x00"),
122 { /* end: all zeroes */ },
125 static struct attribute
*snb_uncore_formats_attr
[] = {
126 &format_attr_event
.attr
,
127 &format_attr_umask
.attr
,
128 &format_attr_edge
.attr
,
129 &format_attr_inv
.attr
,
130 &format_attr_cmask5
.attr
,
134 static const struct attribute_group snb_uncore_format_group
= {
136 .attrs
= snb_uncore_formats_attr
,
139 static struct intel_uncore_ops snb_uncore_msr_ops
= {
140 .init_box
= snb_uncore_msr_init_box
,
141 .enable_box
= snb_uncore_msr_enable_box
,
142 .exit_box
= snb_uncore_msr_exit_box
,
143 .disable_event
= snb_uncore_msr_disable_event
,
144 .enable_event
= snb_uncore_msr_enable_event
,
145 .read_counter
= uncore_msr_read_counter
,
148 static struct event_constraint snb_uncore_arb_constraints
[] = {
149 UNCORE_EVENT_CONSTRAINT(0x80, 0x1),
150 UNCORE_EVENT_CONSTRAINT(0x83, 0x1),
154 static struct intel_uncore_type snb_uncore_cbox
= {
159 .fixed_ctr_bits
= 48,
160 .perf_ctr
= SNB_UNC_CBO_0_PER_CTR0
,
161 .event_ctl
= SNB_UNC_CBO_0_PERFEVTSEL0
,
162 .fixed_ctr
= SNB_UNC_FIXED_CTR
,
163 .fixed_ctl
= SNB_UNC_FIXED_CTR_CTRL
,
165 .event_mask
= SNB_UNC_RAW_EVENT_MASK
,
166 .msr_offset
= SNB_UNC_CBO_MSR_OFFSET
,
167 .ops
= &snb_uncore_msr_ops
,
168 .format_group
= &snb_uncore_format_group
,
169 .event_descs
= snb_uncore_events
,
172 static struct intel_uncore_type snb_uncore_arb
= {
177 .perf_ctr
= SNB_UNC_ARB_PER_CTR0
,
178 .event_ctl
= SNB_UNC_ARB_PERFEVTSEL0
,
179 .event_mask
= SNB_UNC_RAW_EVENT_MASK
,
180 .msr_offset
= SNB_UNC_ARB_MSR_OFFSET
,
181 .constraints
= snb_uncore_arb_constraints
,
182 .ops
= &snb_uncore_msr_ops
,
183 .format_group
= &snb_uncore_format_group
,
186 static struct intel_uncore_type
*snb_msr_uncores
[] = {
192 void snb_uncore_cpu_init(void)
194 uncore_msr_uncores
= snb_msr_uncores
;
195 if (snb_uncore_cbox
.num_boxes
> boot_cpu_data
.x86_max_cores
)
196 snb_uncore_cbox
.num_boxes
= boot_cpu_data
.x86_max_cores
;
199 static void skl_uncore_msr_init_box(struct intel_uncore_box
*box
)
201 if (box
->pmu
->pmu_idx
== 0) {
202 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL
,
203 SNB_UNC_GLOBAL_CTL_EN
| SKL_UNC_GLOBAL_CTL_CORE_ALL
);
207 static void skl_uncore_msr_enable_box(struct intel_uncore_box
*box
)
209 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL
,
210 SNB_UNC_GLOBAL_CTL_EN
| SKL_UNC_GLOBAL_CTL_CORE_ALL
);
213 static void skl_uncore_msr_exit_box(struct intel_uncore_box
*box
)
215 if (box
->pmu
->pmu_idx
== 0)
216 wrmsrl(SKL_UNC_PERF_GLOBAL_CTL
, 0);
219 static struct intel_uncore_ops skl_uncore_msr_ops
= {
220 .init_box
= skl_uncore_msr_init_box
,
221 .enable_box
= skl_uncore_msr_enable_box
,
222 .exit_box
= skl_uncore_msr_exit_box
,
223 .disable_event
= snb_uncore_msr_disable_event
,
224 .enable_event
= snb_uncore_msr_enable_event
,
225 .read_counter
= uncore_msr_read_counter
,
228 static struct intel_uncore_type skl_uncore_cbox
= {
233 .fixed_ctr_bits
= 48,
234 .perf_ctr
= SNB_UNC_CBO_0_PER_CTR0
,
235 .event_ctl
= SNB_UNC_CBO_0_PERFEVTSEL0
,
236 .fixed_ctr
= SNB_UNC_FIXED_CTR
,
237 .fixed_ctl
= SNB_UNC_FIXED_CTR_CTRL
,
239 .event_mask
= SNB_UNC_RAW_EVENT_MASK
,
240 .msr_offset
= SNB_UNC_CBO_MSR_OFFSET
,
241 .ops
= &skl_uncore_msr_ops
,
242 .format_group
= &snb_uncore_format_group
,
243 .event_descs
= snb_uncore_events
,
246 static struct intel_uncore_type
*skl_msr_uncores
[] = {
252 void skl_uncore_cpu_init(void)
254 uncore_msr_uncores
= skl_msr_uncores
;
255 if (skl_uncore_cbox
.num_boxes
> boot_cpu_data
.x86_max_cores
)
256 skl_uncore_cbox
.num_boxes
= boot_cpu_data
.x86_max_cores
;
257 snb_uncore_arb
.ops
= &skl_uncore_msr_ops
;
264 static struct uncore_event_desc snb_uncore_imc_events
[] = {
265 INTEL_UNCORE_EVENT_DESC(data_reads
, "event=0x01"),
266 INTEL_UNCORE_EVENT_DESC(data_reads
.scale
, "6.103515625e-5"),
267 INTEL_UNCORE_EVENT_DESC(data_reads
.unit
, "MiB"),
269 INTEL_UNCORE_EVENT_DESC(data_writes
, "event=0x02"),
270 INTEL_UNCORE_EVENT_DESC(data_writes
.scale
, "6.103515625e-5"),
271 INTEL_UNCORE_EVENT_DESC(data_writes
.unit
, "MiB"),
273 { /* end: all zeroes */ },
276 #define SNB_UNCORE_PCI_IMC_EVENT_MASK 0xff
277 #define SNB_UNCORE_PCI_IMC_BAR_OFFSET 0x48
279 /* page size multiple covering all config regs */
280 #define SNB_UNCORE_PCI_IMC_MAP_SIZE 0x6000
282 #define SNB_UNCORE_PCI_IMC_DATA_READS 0x1
283 #define SNB_UNCORE_PCI_IMC_DATA_READS_BASE 0x5050
284 #define SNB_UNCORE_PCI_IMC_DATA_WRITES 0x2
285 #define SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE 0x5054
286 #define SNB_UNCORE_PCI_IMC_CTR_BASE SNB_UNCORE_PCI_IMC_DATA_READS_BASE
288 static struct attribute
*snb_uncore_imc_formats_attr
[] = {
289 &format_attr_event
.attr
,
293 static const struct attribute_group snb_uncore_imc_format_group
= {
295 .attrs
= snb_uncore_imc_formats_attr
,
298 static void snb_uncore_imc_init_box(struct intel_uncore_box
*box
)
300 struct pci_dev
*pdev
= box
->pci_dev
;
301 int where
= SNB_UNCORE_PCI_IMC_BAR_OFFSET
;
302 resource_size_t addr
;
305 pci_read_config_dword(pdev
, where
, &pci_dword
);
308 #ifdef CONFIG_PHYS_ADDR_T_64BIT
309 pci_read_config_dword(pdev
, where
+ 4, &pci_dword
);
310 addr
|= ((resource_size_t
)pci_dword
<< 32);
313 addr
&= ~(PAGE_SIZE
- 1);
315 box
->io_addr
= ioremap(addr
, SNB_UNCORE_PCI_IMC_MAP_SIZE
);
316 box
->hrtimer_duration
= UNCORE_SNB_IMC_HRTIMER_INTERVAL
;
319 static void snb_uncore_imc_exit_box(struct intel_uncore_box
*box
)
321 iounmap(box
->io_addr
);
324 static void snb_uncore_imc_enable_box(struct intel_uncore_box
*box
)
327 static void snb_uncore_imc_disable_box(struct intel_uncore_box
*box
)
330 static void snb_uncore_imc_enable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
333 static void snb_uncore_imc_disable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
336 static u64
snb_uncore_imc_read_counter(struct intel_uncore_box
*box
, struct perf_event
*event
)
338 struct hw_perf_event
*hwc
= &event
->hw
;
340 return (u64
)*(unsigned int *)(box
->io_addr
+ hwc
->event_base
);
344 * custom event_init() function because we define our own fixed, free
345 * running counters, so we do not want to conflict with generic uncore
346 * logic. Also simplifies processing
348 static int snb_uncore_imc_event_init(struct perf_event
*event
)
350 struct intel_uncore_pmu
*pmu
;
351 struct intel_uncore_box
*box
;
352 struct hw_perf_event
*hwc
= &event
->hw
;
353 u64 cfg
= event
->attr
.config
& SNB_UNCORE_PCI_IMC_EVENT_MASK
;
356 if (event
->attr
.type
!= event
->pmu
->type
)
359 pmu
= uncore_event_to_pmu(event
);
360 /* no device found for this pmu */
361 if (pmu
->func_id
< 0)
364 /* Sampling not supported yet */
365 if (hwc
->sample_period
)
368 /* unsupported modes and filters */
369 if (event
->attr
.exclude_user
||
370 event
->attr
.exclude_kernel
||
371 event
->attr
.exclude_hv
||
372 event
->attr
.exclude_idle
||
373 event
->attr
.exclude_host
||
374 event
->attr
.exclude_guest
||
375 event
->attr
.sample_period
) /* no sampling */
379 * Place all uncore events for a particular physical package
385 /* check only supported bits are set */
386 if (event
->attr
.config
& ~SNB_UNCORE_PCI_IMC_EVENT_MASK
)
389 box
= uncore_pmu_to_box(pmu
, event
->cpu
);
390 if (!box
|| box
->cpu
< 0)
393 event
->cpu
= box
->cpu
;
394 event
->pmu_private
= box
;
396 event
->event_caps
|= PERF_EV_CAP_READ_ACTIVE_PKG
;
399 event
->hw
.last_tag
= ~0ULL;
400 event
->hw
.extra_reg
.idx
= EXTRA_REG_NONE
;
401 event
->hw
.branch_reg
.idx
= EXTRA_REG_NONE
;
403 * check event is known (whitelist, determines counter)
406 case SNB_UNCORE_PCI_IMC_DATA_READS
:
407 base
= SNB_UNCORE_PCI_IMC_DATA_READS_BASE
;
408 idx
= UNCORE_PMC_IDX_FIXED
;
410 case SNB_UNCORE_PCI_IMC_DATA_WRITES
:
411 base
= SNB_UNCORE_PCI_IMC_DATA_WRITES_BASE
;
412 idx
= UNCORE_PMC_IDX_FIXED
+ 1;
418 /* must be done before validate_group */
419 event
->hw
.event_base
= base
;
420 event
->hw
.config
= cfg
;
423 /* no group validation needed, we have free running counters */
428 static int snb_uncore_imc_hw_config(struct intel_uncore_box
*box
, struct perf_event
*event
)
433 static void snb_uncore_imc_event_start(struct perf_event
*event
, int flags
)
435 struct intel_uncore_box
*box
= uncore_event_to_box(event
);
438 if (WARN_ON_ONCE(!(event
->hw
.state
& PERF_HES_STOPPED
)))
444 list_add_tail(&event
->active_entry
, &box
->active_list
);
446 count
= snb_uncore_imc_read_counter(box
, event
);
447 local64_set(&event
->hw
.prev_count
, count
);
449 if (box
->n_active
== 1)
450 uncore_pmu_start_hrtimer(box
);
453 static void snb_uncore_imc_event_stop(struct perf_event
*event
, int flags
)
455 struct intel_uncore_box
*box
= uncore_event_to_box(event
);
456 struct hw_perf_event
*hwc
= &event
->hw
;
458 if (!(hwc
->state
& PERF_HES_STOPPED
)) {
461 WARN_ON_ONCE(hwc
->state
& PERF_HES_STOPPED
);
462 hwc
->state
|= PERF_HES_STOPPED
;
464 list_del(&event
->active_entry
);
466 if (box
->n_active
== 0)
467 uncore_pmu_cancel_hrtimer(box
);
470 if ((flags
& PERF_EF_UPDATE
) && !(hwc
->state
& PERF_HES_UPTODATE
)) {
472 * Drain the remaining delta count out of a event
473 * that we are disabling:
475 uncore_perf_event_update(box
, event
);
476 hwc
->state
|= PERF_HES_UPTODATE
;
480 static int snb_uncore_imc_event_add(struct perf_event
*event
, int flags
)
482 struct intel_uncore_box
*box
= uncore_event_to_box(event
);
483 struct hw_perf_event
*hwc
= &event
->hw
;
488 hwc
->state
= PERF_HES_UPTODATE
| PERF_HES_STOPPED
;
489 if (!(flags
& PERF_EF_START
))
490 hwc
->state
|= PERF_HES_ARCH
;
492 snb_uncore_imc_event_start(event
, 0);
497 static void snb_uncore_imc_event_del(struct perf_event
*event
, int flags
)
499 snb_uncore_imc_event_stop(event
, PERF_EF_UPDATE
);
502 int snb_pci2phy_map_init(int devid
)
504 struct pci_dev
*dev
= NULL
;
505 struct pci2phy_map
*map
;
508 dev
= pci_get_device(PCI_VENDOR_ID_INTEL
, devid
, dev
);
512 bus
= dev
->bus
->number
;
513 segment
= pci_domain_nr(dev
->bus
);
515 raw_spin_lock(&pci2phy_map_lock
);
516 map
= __find_pci2phy_map(segment
);
518 raw_spin_unlock(&pci2phy_map_lock
);
522 map
->pbus_to_physid
[bus
] = 0;
523 raw_spin_unlock(&pci2phy_map_lock
);
530 static struct pmu snb_uncore_imc_pmu
= {
531 .task_ctx_nr
= perf_invalid_context
,
532 .event_init
= snb_uncore_imc_event_init
,
533 .add
= snb_uncore_imc_event_add
,
534 .del
= snb_uncore_imc_event_del
,
535 .start
= snb_uncore_imc_event_start
,
536 .stop
= snb_uncore_imc_event_stop
,
537 .read
= uncore_pmu_event_read
,
540 static struct intel_uncore_ops snb_uncore_imc_ops
= {
541 .init_box
= snb_uncore_imc_init_box
,
542 .exit_box
= snb_uncore_imc_exit_box
,
543 .enable_box
= snb_uncore_imc_enable_box
,
544 .disable_box
= snb_uncore_imc_disable_box
,
545 .disable_event
= snb_uncore_imc_disable_event
,
546 .enable_event
= snb_uncore_imc_enable_event
,
547 .hw_config
= snb_uncore_imc_hw_config
,
548 .read_counter
= snb_uncore_imc_read_counter
,
551 static struct intel_uncore_type snb_uncore_imc
= {
555 .fixed_ctr_bits
= 32,
556 .fixed_ctr
= SNB_UNCORE_PCI_IMC_CTR_BASE
,
557 .event_descs
= snb_uncore_imc_events
,
558 .format_group
= &snb_uncore_imc_format_group
,
559 .perf_ctr
= SNB_UNCORE_PCI_IMC_DATA_READS_BASE
,
560 .event_mask
= SNB_UNCORE_PCI_IMC_EVENT_MASK
,
561 .ops
= &snb_uncore_imc_ops
,
562 .pmu
= &snb_uncore_imc_pmu
,
565 static struct intel_uncore_type
*snb_pci_uncores
[] = {
566 [SNB_PCI_UNCORE_IMC
] = &snb_uncore_imc
,
570 static const struct pci_device_id snb_uncore_pci_ids
[] = {
572 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SNB_IMC
),
573 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
575 { /* end: all zeroes */ },
578 static const struct pci_device_id ivb_uncore_pci_ids
[] = {
580 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_IVB_IMC
),
581 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
584 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_IVB_E3_IMC
),
585 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
587 { /* end: all zeroes */ },
590 static const struct pci_device_id hsw_uncore_pci_ids
[] = {
592 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_HSW_IMC
),
593 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
596 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_HSW_U_IMC
),
597 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
599 { /* end: all zeroes */ },
602 static const struct pci_device_id bdw_uncore_pci_ids
[] = {
604 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_BDW_IMC
),
605 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
607 { /* end: all zeroes */ },
610 static const struct pci_device_id skl_uncore_pci_ids
[] = {
612 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_Y_IMC
),
613 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
616 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_U_IMC
),
617 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
620 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_HD_IMC
),
621 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
624 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_HQ_IMC
),
625 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
628 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_SD_IMC
),
629 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
632 PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_SKL_SQ_IMC
),
633 .driver_data
= UNCORE_PCI_DEV_DATA(SNB_PCI_UNCORE_IMC
, 0),
636 { /* end: all zeroes */ },
639 static struct pci_driver snb_uncore_pci_driver
= {
640 .name
= "snb_uncore",
641 .id_table
= snb_uncore_pci_ids
,
644 static struct pci_driver ivb_uncore_pci_driver
= {
645 .name
= "ivb_uncore",
646 .id_table
= ivb_uncore_pci_ids
,
649 static struct pci_driver hsw_uncore_pci_driver
= {
650 .name
= "hsw_uncore",
651 .id_table
= hsw_uncore_pci_ids
,
654 static struct pci_driver bdw_uncore_pci_driver
= {
655 .name
= "bdw_uncore",
656 .id_table
= bdw_uncore_pci_ids
,
659 static struct pci_driver skl_uncore_pci_driver
= {
660 .name
= "skl_uncore",
661 .id_table
= skl_uncore_pci_ids
,
664 struct imc_uncore_pci_dev
{
666 struct pci_driver
*driver
;
668 #define IMC_DEV(a, d) \
669 { .pci_id = PCI_DEVICE_ID_INTEL_##a, .driver = (d) }
671 static const struct imc_uncore_pci_dev desktop_imc_pci_ids
[] = {
672 IMC_DEV(SNB_IMC
, &snb_uncore_pci_driver
),
673 IMC_DEV(IVB_IMC
, &ivb_uncore_pci_driver
), /* 3rd Gen Core processor */
674 IMC_DEV(IVB_E3_IMC
, &ivb_uncore_pci_driver
), /* Xeon E3-1200 v2/3rd Gen Core processor */
675 IMC_DEV(HSW_IMC
, &hsw_uncore_pci_driver
), /* 4th Gen Core Processor */
676 IMC_DEV(HSW_U_IMC
, &hsw_uncore_pci_driver
), /* 4th Gen Core ULT Mobile Processor */
677 IMC_DEV(BDW_IMC
, &bdw_uncore_pci_driver
), /* 5th Gen Core U */
678 IMC_DEV(SKL_Y_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core Y */
679 IMC_DEV(SKL_U_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core U */
680 IMC_DEV(SKL_HD_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core H Dual Core */
681 IMC_DEV(SKL_HQ_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core H Quad Core */
682 IMC_DEV(SKL_SD_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core S Dual Core */
683 IMC_DEV(SKL_SQ_IMC
, &skl_uncore_pci_driver
), /* 6th Gen Core S Quad Core */
688 #define for_each_imc_pci_id(x, t) \
689 for (x = (t); (x)->pci_id; x++)
691 static struct pci_driver
*imc_uncore_find_dev(void)
693 const struct imc_uncore_pci_dev
*p
;
696 for_each_imc_pci_id(p
, desktop_imc_pci_ids
) {
697 ret
= snb_pci2phy_map_init(p
->pci_id
);
704 static int imc_uncore_pci_init(void)
706 struct pci_driver
*imc_drv
= imc_uncore_find_dev();
711 uncore_pci_uncores
= snb_pci_uncores
;
712 uncore_pci_driver
= imc_drv
;
717 int snb_uncore_pci_init(void)
719 return imc_uncore_pci_init();
722 int ivb_uncore_pci_init(void)
724 return imc_uncore_pci_init();
726 int hsw_uncore_pci_init(void)
728 return imc_uncore_pci_init();
731 int bdw_uncore_pci_init(void)
733 return imc_uncore_pci_init();
736 int skl_uncore_pci_init(void)
738 return imc_uncore_pci_init();
741 /* end of Sandy Bridge uncore support */
743 /* Nehalem uncore support */
744 static void nhm_uncore_msr_disable_box(struct intel_uncore_box
*box
)
746 wrmsrl(NHM_UNC_PERF_GLOBAL_CTL
, 0);
749 static void nhm_uncore_msr_enable_box(struct intel_uncore_box
*box
)
751 wrmsrl(NHM_UNC_PERF_GLOBAL_CTL
, NHM_UNC_GLOBAL_CTL_EN_PC_ALL
| NHM_UNC_GLOBAL_CTL_EN_FC
);
754 static void nhm_uncore_msr_enable_event(struct intel_uncore_box
*box
, struct perf_event
*event
)
756 struct hw_perf_event
*hwc
= &event
->hw
;
758 if (hwc
->idx
< UNCORE_PMC_IDX_FIXED
)
759 wrmsrl(hwc
->config_base
, hwc
->config
| SNB_UNC_CTL_EN
);
761 wrmsrl(hwc
->config_base
, NHM_UNC_FIXED_CTR_CTL_EN
);
764 static struct attribute
*nhm_uncore_formats_attr
[] = {
765 &format_attr_event
.attr
,
766 &format_attr_umask
.attr
,
767 &format_attr_edge
.attr
,
768 &format_attr_inv
.attr
,
769 &format_attr_cmask8
.attr
,
773 static const struct attribute_group nhm_uncore_format_group
= {
775 .attrs
= nhm_uncore_formats_attr
,
778 static struct uncore_event_desc nhm_uncore_events
[] = {
779 INTEL_UNCORE_EVENT_DESC(clockticks
, "event=0xff,umask=0x00"),
780 INTEL_UNCORE_EVENT_DESC(qmc_writes_full_any
, "event=0x2f,umask=0x0f"),
781 INTEL_UNCORE_EVENT_DESC(qmc_normal_reads_any
, "event=0x2c,umask=0x0f"),
782 INTEL_UNCORE_EVENT_DESC(qhl_request_ioh_reads
, "event=0x20,umask=0x01"),
783 INTEL_UNCORE_EVENT_DESC(qhl_request_ioh_writes
, "event=0x20,umask=0x02"),
784 INTEL_UNCORE_EVENT_DESC(qhl_request_remote_reads
, "event=0x20,umask=0x04"),
785 INTEL_UNCORE_EVENT_DESC(qhl_request_remote_writes
, "event=0x20,umask=0x08"),
786 INTEL_UNCORE_EVENT_DESC(qhl_request_local_reads
, "event=0x20,umask=0x10"),
787 INTEL_UNCORE_EVENT_DESC(qhl_request_local_writes
, "event=0x20,umask=0x20"),
788 { /* end: all zeroes */ },
791 static struct intel_uncore_ops nhm_uncore_msr_ops
= {
792 .disable_box
= nhm_uncore_msr_disable_box
,
793 .enable_box
= nhm_uncore_msr_enable_box
,
794 .disable_event
= snb_uncore_msr_disable_event
,
795 .enable_event
= nhm_uncore_msr_enable_event
,
796 .read_counter
= uncore_msr_read_counter
,
799 static struct intel_uncore_type nhm_uncore
= {
804 .fixed_ctr_bits
= 48,
805 .event_ctl
= NHM_UNC_PERFEVTSEL0
,
806 .perf_ctr
= NHM_UNC_UNCORE_PMC0
,
807 .fixed_ctr
= NHM_UNC_FIXED_CTR
,
808 .fixed_ctl
= NHM_UNC_FIXED_CTR_CTRL
,
809 .event_mask
= NHM_UNC_RAW_EVENT_MASK
,
810 .event_descs
= nhm_uncore_events
,
811 .ops
= &nhm_uncore_msr_ops
,
812 .format_group
= &nhm_uncore_format_group
,
815 static struct intel_uncore_type
*nhm_msr_uncores
[] = {
820 void nhm_uncore_cpu_init(void)
822 uncore_msr_uncores
= nhm_msr_uncores
;
825 /* end of Nehalem uncore support */