1 // SPDX-License-Identifier: GPL-2.0
3 * Intel SOC Telemetry debugfs Driver: Currently supports APL
4 * Copyright (c) 2015, Intel Corporation.
7 * This file provides the debugfs interfaces for telemetry.
8 * /sys/kernel/debug/telemetry/pss_info: Shows Primary Control Sub-Sys Counters
9 * /sys/kernel/debug/telemetry/ioss_info: Shows IO Sub-System Counters
10 * /sys/kernel/debug/telemetry/soc_states: Shows SoC State
11 * /sys/kernel/debug/telemetry/pss_trace_verbosity: Read and Change Tracing
12 * Verbosity via firmware
13 * /sys/kernel/debug/telemetry/ioss_race_verbosity: Write and Change Tracing
14 * Verbosity via firmware
16 #include <linux/debugfs.h>
17 #include <linux/device.h>
18 #include <linux/mfd/intel_pmc_bxt.h>
19 #include <linux/module.h>
20 #include <linux/pci.h>
21 #include <linux/seq_file.h>
22 #include <linux/suspend.h>
24 #include <asm/cpu_device_id.h>
25 #include <asm/intel-family.h>
26 #include <asm/intel_telemetry.h>
28 #define DRIVER_NAME "telemetry_soc_debugfs"
29 #define DRIVER_VERSION "1.0.0"
31 /* ApolloLake SoC Event-IDs */
32 #define TELEM_APL_PSS_PSTATES_ID 0x2802
33 #define TELEM_APL_PSS_IDLE_ID 0x2806
34 #define TELEM_APL_PCS_IDLE_BLOCKED_ID 0x2C00
35 #define TELEM_APL_PCS_S0IX_BLOCKED_ID 0x2C01
36 #define TELEM_APL_PSS_WAKEUP_ID 0x2C02
37 #define TELEM_APL_PSS_LTR_BLOCKING_ID 0x2C03
39 #define TELEM_APL_S0IX_TOTAL_OCC_ID 0x4000
40 #define TELEM_APL_S0IX_SHLW_OCC_ID 0x4001
41 #define TELEM_APL_S0IX_DEEP_OCC_ID 0x4002
42 #define TELEM_APL_S0IX_TOTAL_RES_ID 0x4800
43 #define TELEM_APL_S0IX_SHLW_RES_ID 0x4801
44 #define TELEM_APL_S0IX_DEEP_RES_ID 0x4802
45 #define TELEM_APL_D0IX_ID 0x581A
46 #define TELEM_APL_D3_ID 0x5819
47 #define TELEM_APL_PG_ID 0x5818
49 #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
50 #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
51 #define TELEM_SSRAM_READ_TIMEOUT 10
53 #define TELEM_MASK_BIT 1
54 #define TELEM_MASK_BYTE 0xFF
55 #define BYTES_PER_LONG 8
56 #define TELEM_APL_MASK_PCS_STATE 0xF
58 /* Max events in bitmap to check for */
59 #define TELEM_PSS_IDLE_EVTS 25
60 #define TELEM_PSS_IDLE_BLOCKED_EVTS 20
61 #define TELEM_PSS_S0IX_BLOCKED_EVTS 20
62 #define TELEM_PSS_S0IX_WAKEUP_EVTS 20
63 #define TELEM_PSS_LTR_BLOCKING_EVTS 20
64 #define TELEM_IOSS_DX_D0IX_EVTS 25
65 #define TELEM_IOSS_PG_EVTS 30
67 #define TELEM_CHECK_AND_PARSE_EVTS(EVTID, EVTNUM, BUF, EVTLOG, EVTDAT, MASK) { \
68 if (evtlog[index].telem_evtid == (EVTID)) { \
69 for (idx = 0; idx < (EVTNUM); idx++) \
70 (BUF)[idx] = ((EVTLOG) >> (EVTDAT)[idx].bit_pos) & \
76 #define TELEM_CHECK_AND_PARSE_CTRS(EVTID, CTR) { \
77 if (evtlog[index].telem_evtid == (EVTID)) { \
78 (CTR) = evtlog[index].telem_evtlog; \
83 static u8 suspend_prep_ok
;
84 static u32 suspend_shlw_ctr_temp
, suspend_deep_ctr_temp
;
85 static u64 suspend_shlw_res_temp
, suspend_deep_res_temp
;
87 struct telemetry_susp_stats
{
94 /* Bitmap definitions for default counters in APL */
95 struct telem_pss_idle_stateinfo
{
100 static struct telem_pss_idle_stateinfo telem_apl_pss_idle_data
[] = {
109 {"IA_MODULE0_C7", 32},
110 {"IA_MODULE1_C7", 33},
112 {"IUNIT_PROCESSING_IDLE", 41},
113 {"FAR_MEM_IDLE", 43},
114 {"DISPLAY_IDLE", 44},
115 {"IUNIT_INPUT_SYSTEM_IDLE", 45},
119 struct telem_pcs_blkd_info
{
124 static struct telem_pcs_blkd_info telem_apl_pcs_idle_blkd_data
[] = {
127 {"MODULE_ACTIONS_PENDING", 16},
129 {"DISPLAY_WAKE", 32},
134 static struct telem_pcs_blkd_info telem_apl_pcs_s0ix_blkd_data
[] = {
137 {"WAKE_DEADLINE_PENDING", 16},
145 struct telem_pss_ltr_info
{
150 static struct telem_pss_ltr_info telem_apl_pss_ltr_data
[] = {
154 {"DFX_FORCE_LTR", 24},
160 struct telem_pss_wakeup_info
{
165 static struct telem_pss_wakeup_info telem_apl_pss_wakeup
[] = {
168 {"VOLTAGE_REG_INT", 16},
169 {"DROWSY_TIMER (HOTPLUG)", 24},
175 struct telem_ioss_d0ix_stateinfo
{
180 static struct telem_ioss_d0ix_stateinfo telem_apl_ioss_d0ix_data
[] = {
202 struct telem_ioss_pg_info
{
207 static struct telem_ioss_pg_info telem_apl_ioss_pg_data
[] = {
236 struct telemetry_debugfs_conf
{
237 struct telemetry_susp_stats suspend_stats
;
238 struct dentry
*telemetry_dbg_dir
;
241 struct telem_ioss_d0ix_stateinfo
*ioss_d0ix_data
;
242 struct telem_pss_idle_stateinfo
*pss_idle_data
;
243 struct telem_pcs_blkd_info
*pcs_idle_blkd_data
;
244 struct telem_pcs_blkd_info
*pcs_s0ix_blkd_data
;
245 struct telem_pss_wakeup_info
*pss_wakeup
;
246 struct telem_pss_ltr_info
*pss_ltr_data
;
247 struct telem_ioss_pg_info
*ioss_pg_data
;
248 u8 pcs_idle_blkd_evts
;
249 u8 pcs_s0ix_blkd_evts
;
257 u16 pss_ltr_blocking_id
;
258 u16 pcs_idle_blkd_id
;
259 u16 pcs_s0ix_blkd_id
;
260 u16 s0ix_total_occ_id
;
261 u16 s0ix_shlw_occ_id
;
262 u16 s0ix_deep_occ_id
;
263 u16 s0ix_total_res_id
;
264 u16 s0ix_shlw_res_id
;
265 u16 s0ix_deep_res_id
;
274 static struct telemetry_debugfs_conf
*debugfs_conf
;
276 static struct telemetry_debugfs_conf telem_apl_debugfs_conf
= {
277 .pss_idle_data
= telem_apl_pss_idle_data
,
278 .pcs_idle_blkd_data
= telem_apl_pcs_idle_blkd_data
,
279 .pcs_s0ix_blkd_data
= telem_apl_pcs_s0ix_blkd_data
,
280 .pss_ltr_data
= telem_apl_pss_ltr_data
,
281 .pss_wakeup
= telem_apl_pss_wakeup
,
282 .ioss_d0ix_data
= telem_apl_ioss_d0ix_data
,
283 .ioss_pg_data
= telem_apl_ioss_pg_data
,
285 .pss_idle_evts
= ARRAY_SIZE(telem_apl_pss_idle_data
),
286 .pcs_idle_blkd_evts
= ARRAY_SIZE(telem_apl_pcs_idle_blkd_data
),
287 .pcs_s0ix_blkd_evts
= ARRAY_SIZE(telem_apl_pcs_s0ix_blkd_data
),
288 .pss_ltr_evts
= ARRAY_SIZE(telem_apl_pss_ltr_data
),
289 .pss_wakeup_evts
= ARRAY_SIZE(telem_apl_pss_wakeup
),
290 .ioss_d0ix_evts
= ARRAY_SIZE(telem_apl_ioss_d0ix_data
),
291 .ioss_pg_evts
= ARRAY_SIZE(telem_apl_ioss_pg_data
),
293 .pstates_id
= TELEM_APL_PSS_PSTATES_ID
,
294 .pss_idle_id
= TELEM_APL_PSS_IDLE_ID
,
295 .pcs_idle_blkd_id
= TELEM_APL_PCS_IDLE_BLOCKED_ID
,
296 .pcs_s0ix_blkd_id
= TELEM_APL_PCS_S0IX_BLOCKED_ID
,
297 .pss_wakeup_id
= TELEM_APL_PSS_WAKEUP_ID
,
298 .pss_ltr_blocking_id
= TELEM_APL_PSS_LTR_BLOCKING_ID
,
299 .s0ix_total_occ_id
= TELEM_APL_S0IX_TOTAL_OCC_ID
,
300 .s0ix_shlw_occ_id
= TELEM_APL_S0IX_SHLW_OCC_ID
,
301 .s0ix_deep_occ_id
= TELEM_APL_S0IX_DEEP_OCC_ID
,
302 .s0ix_total_res_id
= TELEM_APL_S0IX_TOTAL_RES_ID
,
303 .s0ix_shlw_res_id
= TELEM_APL_S0IX_SHLW_RES_ID
,
304 .s0ix_deep_res_id
= TELEM_APL_S0IX_DEEP_RES_ID
,
305 .ioss_d0ix_id
= TELEM_APL_D0IX_ID
,
306 .ioss_d3_id
= TELEM_APL_D3_ID
,
307 .ioss_pg_id
= TELEM_APL_PG_ID
,
310 static const struct x86_cpu_id telemetry_debugfs_cpu_ids
[] = {
311 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT
, &telem_apl_debugfs_conf
),
312 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_PLUS
, &telem_apl_debugfs_conf
),
315 MODULE_DEVICE_TABLE(x86cpu
, telemetry_debugfs_cpu_ids
);
317 static int telemetry_debugfs_check_evts(void)
319 if ((debugfs_conf
->pss_idle_evts
> TELEM_PSS_IDLE_EVTS
) ||
320 (debugfs_conf
->pcs_idle_blkd_evts
> TELEM_PSS_IDLE_BLOCKED_EVTS
) ||
321 (debugfs_conf
->pcs_s0ix_blkd_evts
> TELEM_PSS_S0IX_BLOCKED_EVTS
) ||
322 (debugfs_conf
->pss_ltr_evts
> TELEM_PSS_LTR_BLOCKING_EVTS
) ||
323 (debugfs_conf
->pss_wakeup_evts
> TELEM_PSS_S0IX_WAKEUP_EVTS
) ||
324 (debugfs_conf
->ioss_d0ix_evts
> TELEM_IOSS_DX_D0IX_EVTS
) ||
325 (debugfs_conf
->ioss_pg_evts
> TELEM_IOSS_PG_EVTS
))
331 static int telem_pss_states_show(struct seq_file
*s
, void *unused
)
333 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
334 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
335 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
336 u32 pcs_idle_blkd
[TELEM_PSS_IDLE_BLOCKED_EVTS
],
337 pcs_s0ix_blkd
[TELEM_PSS_S0IX_BLOCKED_EVTS
],
338 pss_s0ix_wakeup
[TELEM_PSS_S0IX_WAKEUP_EVTS
],
339 pss_ltr_blkd
[TELEM_PSS_LTR_BLOCKING_EVTS
],
340 pss_idle
[TELEM_PSS_IDLE_EVTS
];
341 int index
, idx
, ret
, err
= 0;
344 ret
= telemetry_read_eventlog(TELEM_PSS
, evtlog
,
345 TELEM_MAX_OS_ALLOCATED_EVENTS
);
349 err
= telemetry_get_evtname(TELEM_PSS
, name
,
350 TELEM_MAX_OS_ALLOCATED_EVENTS
);
354 seq_puts(s
, "\n----------------------------------------------------\n");
355 seq_puts(s
, "\tPSS TELEM EVENTLOG (Residency = field/19.2 us\n");
356 seq_puts(s
, "----------------------------------------------------\n");
357 for (index
= 0; index
< ret
; index
++) {
358 seq_printf(s
, "%-32s %llu\n",
359 name
[index
], evtlog
[index
].telem_evtlog
);
361 /* Fetch PSS IDLE State */
362 if (evtlog
[index
].telem_evtid
== conf
->pss_idle_id
) {
363 pss_idle
[conf
->pss_idle_evts
- 1] =
364 (evtlog
[index
].telem_evtlog
>>
365 conf
->pss_idle_data
[conf
->pss_idle_evts
- 1].bit_pos
) &
366 TELEM_APL_MASK_PCS_STATE
;
369 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_idle_id
,
370 conf
->pss_idle_evts
- 1,
371 pss_idle
, evtlog
[index
].telem_evtlog
,
372 conf
->pss_idle_data
, TELEM_MASK_BIT
);
374 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_idle_blkd_id
,
375 conf
->pcs_idle_blkd_evts
,
377 evtlog
[index
].telem_evtlog
,
378 conf
->pcs_idle_blkd_data
,
381 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_s0ix_blkd_id
,
382 conf
->pcs_s0ix_blkd_evts
,
384 evtlog
[index
].telem_evtlog
,
385 conf
->pcs_s0ix_blkd_data
,
388 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_wakeup_id
,
389 conf
->pss_wakeup_evts
,
391 evtlog
[index
].telem_evtlog
,
392 conf
->pss_wakeup
, TELEM_MASK_BYTE
);
394 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_ltr_blocking_id
,
395 conf
->pss_ltr_evts
, pss_ltr_blkd
,
396 evtlog
[index
].telem_evtlog
,
397 conf
->pss_ltr_data
, TELEM_MASK_BYTE
);
399 if (evtlog
[index
].telem_evtid
== debugfs_conf
->pstates_id
)
400 pstates
= evtlog
[index
].telem_evtlog
;
403 seq_puts(s
, "\n--------------------------------------\n");
404 seq_puts(s
, "PStates\n");
405 seq_puts(s
, "--------------------------------------\n");
406 seq_puts(s
, "Domain\t\t\t\tFreq(Mhz)\n");
407 seq_printf(s
, " IA\t\t\t\t %llu\n GT\t\t\t\t %llu\n",
408 (pstates
& TELEM_MASK_BYTE
)*100,
409 ((pstates
>> 8) & TELEM_MASK_BYTE
)*50/3);
411 seq_printf(s
, " IUNIT\t\t\t\t %llu\n SA\t\t\t\t %llu\n",
412 ((pstates
>> 16) & TELEM_MASK_BYTE
)*25,
413 ((pstates
>> 24) & TELEM_MASK_BYTE
)*50/3);
415 seq_puts(s
, "\n--------------------------------------\n");
416 seq_puts(s
, "PSS IDLE Status\n");
417 seq_puts(s
, "--------------------------------------\n");
418 seq_puts(s
, "Device\t\t\t\t\tIDLE\n");
419 for (index
= 0; index
< debugfs_conf
->pss_idle_evts
; index
++) {
420 seq_printf(s
, "%-32s\t%u\n",
421 debugfs_conf
->pss_idle_data
[index
].name
,
425 seq_puts(s
, "\n--------------------------------------\n");
426 seq_puts(s
, "PSS Idle blkd Status (~1ms saturating bucket)\n");
427 seq_puts(s
, "--------------------------------------\n");
428 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
429 for (index
= 0; index
< debugfs_conf
->pcs_idle_blkd_evts
; index
++) {
430 seq_printf(s
, "%-32s\t%u\n",
431 debugfs_conf
->pcs_idle_blkd_data
[index
].name
,
432 pcs_idle_blkd
[index
]);
435 seq_puts(s
, "\n--------------------------------------\n");
436 seq_puts(s
, "PSS S0ix blkd Status (~1ms saturating bucket)\n");
437 seq_puts(s
, "--------------------------------------\n");
438 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
439 for (index
= 0; index
< debugfs_conf
->pcs_s0ix_blkd_evts
; index
++) {
440 seq_printf(s
, "%-32s\t%u\n",
441 debugfs_conf
->pcs_s0ix_blkd_data
[index
].name
,
442 pcs_s0ix_blkd
[index
]);
445 seq_puts(s
, "\n--------------------------------------\n");
446 seq_puts(s
, "LTR Blocking Status (~1ms saturating bucket)\n");
447 seq_puts(s
, "--------------------------------------\n");
448 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
449 for (index
= 0; index
< debugfs_conf
->pss_ltr_evts
; index
++) {
450 seq_printf(s
, "%-32s\t%u\n",
451 debugfs_conf
->pss_ltr_data
[index
].name
,
452 pss_s0ix_wakeup
[index
]);
455 seq_puts(s
, "\n--------------------------------------\n");
456 seq_puts(s
, "Wakes Status (~1ms saturating bucket)\n");
457 seq_puts(s
, "--------------------------------------\n");
458 seq_puts(s
, "Wakes\t\t\t\t\tCount\n");
459 for (index
= 0; index
< debugfs_conf
->pss_wakeup_evts
; index
++) {
460 seq_printf(s
, "%-32s\t%u\n",
461 debugfs_conf
->pss_wakeup
[index
].name
,
462 pss_ltr_blkd
[index
]);
468 DEFINE_SHOW_ATTRIBUTE(telem_pss_states
);
470 static int telem_ioss_states_show(struct seq_file
*s
, void *unused
)
472 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
473 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
476 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
477 TELEM_MAX_OS_ALLOCATED_EVENTS
);
481 err
= telemetry_get_evtname(TELEM_IOSS
, name
,
482 TELEM_MAX_OS_ALLOCATED_EVENTS
);
486 seq_puts(s
, "--------------------------------------\n");
487 seq_puts(s
, "\tI0SS TELEMETRY EVENTLOG\n");
488 seq_puts(s
, "--------------------------------------\n");
489 for (index
= 0; index
< ret
; index
++) {
490 seq_printf(s
, "%-32s 0x%llx\n",
491 name
[index
], evtlog
[index
].telem_evtlog
);
497 DEFINE_SHOW_ATTRIBUTE(telem_ioss_states
);
499 static int telem_soc_states_show(struct seq_file
*s
, void *unused
)
501 u32 d3_sts
[TELEM_IOSS_DX_D0IX_EVTS
], d0ix_sts
[TELEM_IOSS_DX_D0IX_EVTS
];
502 u32 pg_sts
[TELEM_IOSS_PG_EVTS
], pss_idle
[TELEM_PSS_IDLE_EVTS
];
503 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
504 u32 s0ix_total_ctr
= 0, s0ix_shlw_ctr
= 0, s0ix_deep_ctr
= 0;
505 u64 s0ix_total_res
= 0, s0ix_shlw_res
= 0, s0ix_deep_res
= 0;
506 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
507 struct pci_dev
*dev
= NULL
;
512 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
513 TELEM_MAX_OS_ALLOCATED_EVENTS
);
517 for (index
= 0; index
< ret
; index
++) {
518 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d3_id
,
519 conf
->ioss_d0ix_evts
,
520 d3_sts
, evtlog
[index
].telem_evtlog
,
521 conf
->ioss_d0ix_data
,
524 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_pg_id
, conf
->ioss_pg_evts
,
525 pg_sts
, evtlog
[index
].telem_evtlog
,
526 conf
->ioss_pg_data
, TELEM_MASK_BIT
);
528 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d0ix_id
,
529 conf
->ioss_d0ix_evts
,
530 d0ix_sts
, evtlog
[index
].telem_evtlog
,
531 conf
->ioss_d0ix_data
,
534 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_occ_id
,
537 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
540 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
543 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_res_id
,
546 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
549 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
553 seq_puts(s
, "\n---------------------------------------------------\n");
554 seq_puts(s
, "S0IX Type\t\t\t Occurrence\t\t Residency(us)\n");
555 seq_puts(s
, "---------------------------------------------------\n");
557 seq_printf(s
, "S0IX Shallow\t\t\t %10u\t %10llu\n",
559 conf
->suspend_stats
.shlw_ctr
,
560 (u64
)((s0ix_shlw_res
-
561 conf
->suspend_stats
.shlw_res
)*10/192));
563 seq_printf(s
, "S0IX Deep\t\t\t %10u\t %10llu\n",
565 conf
->suspend_stats
.deep_ctr
,
566 (u64
)((s0ix_deep_res
-
567 conf
->suspend_stats
.deep_res
)*10/192));
569 seq_printf(s
, "Suspend(With S0ixShallow)\t %10u\t %10llu\n",
570 conf
->suspend_stats
.shlw_ctr
,
571 (u64
)(conf
->suspend_stats
.shlw_res
*10)/192);
573 seq_printf(s
, "Suspend(With S0ixDeep)\t\t %10u\t %10llu\n",
574 conf
->suspend_stats
.deep_ctr
,
575 (u64
)(conf
->suspend_stats
.deep_res
*10)/192);
577 seq_printf(s
, "TOTAL S0IX\t\t\t %10u\t %10llu\n", s0ix_total_ctr
,
578 (u64
)(s0ix_total_res
*10/192));
579 seq_puts(s
, "\n-------------------------------------------------\n");
580 seq_puts(s
, "\t\tDEVICE STATES\n");
581 seq_puts(s
, "-------------------------------------------------\n");
583 for_each_pci_dev(dev
) {
584 pci_read_config_word(dev
, dev
->pm_cap
+ PCI_PM_CTRL
, &pmcsr
);
585 d3_state
= ((pmcsr
& PCI_PM_CTRL_STATE_MASK
) ==
586 (__force
int)PCI_D3hot
) ? 1 : 0;
588 seq_printf(s
, "pci %04x %04X %s %20.20s: ",
589 dev
->vendor
, dev
->device
, dev_name(&dev
->dev
),
590 dev_driver_string(&dev
->dev
));
591 seq_printf(s
, " d3:%x\n", d3_state
);
594 seq_puts(s
, "\n--------------------------------------\n");
595 seq_puts(s
, "D3/D0i3 Status\n");
596 seq_puts(s
, "--------------------------------------\n");
597 seq_puts(s
, "Block\t\t D3\t D0i3\n");
598 for (index
= 0; index
< conf
->ioss_d0ix_evts
; index
++) {
599 seq_printf(s
, "%-10s\t %u\t %u\n",
600 conf
->ioss_d0ix_data
[index
].name
,
601 d3_sts
[index
], d0ix_sts
[index
]);
604 seq_puts(s
, "\n--------------------------------------\n");
605 seq_puts(s
, "South Complex PowerGate Status\n");
606 seq_puts(s
, "--------------------------------------\n");
607 seq_puts(s
, "Device\t\t PG\n");
608 for (index
= 0; index
< conf
->ioss_pg_evts
; index
++) {
609 seq_printf(s
, "%-10s\t %u\n",
610 conf
->ioss_pg_data
[index
].name
,
614 evtlog
->telem_evtid
= conf
->pss_idle_id
;
615 ret
= telemetry_read_events(TELEM_PSS
, evtlog
, 1);
619 seq_puts(s
, "\n-----------------------------------------\n");
620 seq_puts(s
, "North Idle Status\n");
621 seq_puts(s
, "-----------------------------------------\n");
622 for (idx
= 0; idx
< conf
->pss_idle_evts
- 1; idx
++) {
623 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
624 conf
->pss_idle_data
[idx
].bit_pos
) &
628 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
629 conf
->pss_idle_data
[idx
].bit_pos
) &
630 TELEM_APL_MASK_PCS_STATE
;
632 for (index
= 0; index
< conf
->pss_idle_evts
; index
++) {
633 seq_printf(s
, "%-30s %u\n",
634 conf
->pss_idle_data
[index
].name
,
638 seq_puts(s
, "\nPCS_STATUS Code\n");
639 seq_puts(s
, "0:C0 1:C1 2:C1_DN_WT_DEV 3:C2 4:C2_WT_DE_MEM_UP\n");
640 seq_puts(s
, "5:C2_WT_DE_MEM_DOWN 6:C2_UP_WT_DEV 7:C2_DN 8:C2_VOA\n");
641 seq_puts(s
, "9:C2_VOA_UP 10:S0IX_PRE 11:S0IX\n");
646 DEFINE_SHOW_ATTRIBUTE(telem_soc_states
);
648 static int telem_s0ix_res_get(void *data
, u64
*val
)
650 struct telemetry_plt_config
*plt_config
= telemetry_get_pltdata();
654 ret
= intel_pmc_s0ix_counter_read(plt_config
->pmc
, &s0ix_total_res
);
656 pr_err("Failed to read S0ix residency");
660 *val
= s0ix_total_res
;
665 DEFINE_DEBUGFS_ATTRIBUTE(telem_s0ix_fops
, telem_s0ix_res_get
, NULL
, "%llu\n");
667 static int telem_pss_trc_verb_show(struct seq_file
*s
, void *unused
)
672 err
= telemetry_get_trace_verbosity(TELEM_PSS
, &verbosity
);
674 pr_err("Get PSS Trace Verbosity Failed with Error %d\n", err
);
678 seq_printf(s
, "PSS Trace Verbosity %u\n", verbosity
);
682 static ssize_t
telem_pss_trc_verb_write(struct file
*file
,
683 const char __user
*userbuf
,
684 size_t count
, loff_t
*ppos
)
689 err
= kstrtou32_from_user(userbuf
, count
, 0, &verbosity
);
693 err
= telemetry_set_trace_verbosity(TELEM_PSS
, verbosity
);
695 pr_err("Changing PSS Trace Verbosity Failed. Error %d\n", err
);
702 static int telem_pss_trc_verb_open(struct inode
*inode
, struct file
*file
)
704 return single_open(file
, telem_pss_trc_verb_show
, inode
->i_private
);
707 static const struct file_operations telem_pss_trc_verb_ops
= {
708 .open
= telem_pss_trc_verb_open
,
710 .write
= telem_pss_trc_verb_write
,
712 .release
= single_release
,
715 static int telem_ioss_trc_verb_show(struct seq_file
*s
, void *unused
)
720 err
= telemetry_get_trace_verbosity(TELEM_IOSS
, &verbosity
);
722 pr_err("Get IOSS Trace Verbosity Failed with Error %d\n", err
);
726 seq_printf(s
, "IOSS Trace Verbosity %u\n", verbosity
);
730 static ssize_t
telem_ioss_trc_verb_write(struct file
*file
,
731 const char __user
*userbuf
,
732 size_t count
, loff_t
*ppos
)
737 err
= kstrtou32_from_user(userbuf
, count
, 0, &verbosity
);
741 err
= telemetry_set_trace_verbosity(TELEM_IOSS
, verbosity
);
743 pr_err("Changing IOSS Trace Verbosity Failed. Error %d\n", err
);
750 static int telem_ioss_trc_verb_open(struct inode
*inode
, struct file
*file
)
752 return single_open(file
, telem_ioss_trc_verb_show
, inode
->i_private
);
755 static const struct file_operations telem_ioss_trc_verb_ops
= {
756 .open
= telem_ioss_trc_verb_open
,
758 .write
= telem_ioss_trc_verb_write
,
760 .release
= single_release
,
763 static int pm_suspend_prep_cb(void)
765 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
766 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
769 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
770 TELEM_MAX_OS_ALLOCATED_EVENTS
);
776 for (index
= 0; index
< ret
; index
++) {
778 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
779 suspend_shlw_ctr_temp
);
781 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
782 suspend_deep_ctr_temp
);
784 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
785 suspend_shlw_res_temp
);
787 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
788 suspend_deep_res_temp
);
795 static int pm_suspend_exit_cb(void)
797 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
798 static u32 suspend_shlw_ctr_exit
, suspend_deep_ctr_exit
;
799 static u64 suspend_shlw_res_exit
, suspend_deep_res_exit
;
800 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
803 if (!suspend_prep_ok
)
806 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
807 TELEM_MAX_OS_ALLOCATED_EVENTS
);
811 for (index
= 0; index
< ret
; index
++) {
812 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
813 suspend_shlw_ctr_exit
);
815 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
816 suspend_deep_ctr_exit
);
818 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
819 suspend_shlw_res_exit
);
821 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
822 suspend_deep_res_exit
);
825 if ((suspend_shlw_ctr_exit
< suspend_shlw_ctr_temp
) ||
826 (suspend_deep_ctr_exit
< suspend_deep_ctr_temp
) ||
827 (suspend_shlw_res_exit
< suspend_shlw_res_temp
) ||
828 (suspend_deep_res_exit
< suspend_deep_res_temp
)) {
829 pr_err("Wrong s0ix counters detected\n");
834 * Due to some design limitations in the firmware, sometimes the
835 * counters do not get updated by the time we reach here. As a
836 * workaround, we try to see if this was a genuine case of sleep
837 * failure or not by cross-checking from PMC GCR registers directly.
839 if (suspend_shlw_ctr_exit
== suspend_shlw_ctr_temp
&&
840 suspend_deep_ctr_exit
== suspend_deep_ctr_temp
) {
841 struct telemetry_plt_config
*plt_config
= telemetry_get_pltdata();
842 struct intel_pmc_dev
*pmc
= plt_config
->pmc
;
844 ret
= intel_pmc_gcr_read64(pmc
, PMC_GCR_TELEM_SHLW_S0IX_REG
,
845 &suspend_shlw_res_exit
);
849 ret
= intel_pmc_gcr_read64(pmc
, PMC_GCR_TELEM_DEEP_S0IX_REG
,
850 &suspend_deep_res_exit
);
854 if (suspend_shlw_res_exit
> suspend_shlw_res_temp
)
855 suspend_shlw_ctr_exit
++;
857 if (suspend_deep_res_exit
> suspend_deep_res_temp
)
858 suspend_deep_ctr_exit
++;
861 suspend_shlw_ctr_exit
-= suspend_shlw_ctr_temp
;
862 suspend_deep_ctr_exit
-= suspend_deep_ctr_temp
;
863 suspend_shlw_res_exit
-= suspend_shlw_res_temp
;
864 suspend_deep_res_exit
-= suspend_deep_res_temp
;
866 if (suspend_shlw_ctr_exit
!= 0) {
867 conf
->suspend_stats
.shlw_ctr
+=
868 suspend_shlw_ctr_exit
;
870 conf
->suspend_stats
.shlw_res
+=
871 suspend_shlw_res_exit
;
874 if (suspend_deep_ctr_exit
!= 0) {
875 conf
->suspend_stats
.deep_ctr
+=
876 suspend_deep_ctr_exit
;
878 conf
->suspend_stats
.deep_res
+=
879 suspend_deep_res_exit
;
887 static int pm_notification(struct notifier_block
*this,
888 unsigned long event
, void *ptr
)
891 case PM_SUSPEND_PREPARE
:
892 return pm_suspend_prep_cb();
893 case PM_POST_SUSPEND
:
894 return pm_suspend_exit_cb();
900 static struct notifier_block pm_notifier
= {
901 .notifier_call
= pm_notification
,
904 static int __init
telemetry_debugfs_init(void)
906 const struct x86_cpu_id
*id
;
910 /* Only APL supported for now */
911 id
= x86_match_cpu(telemetry_debugfs_cpu_ids
);
915 debugfs_conf
= (struct telemetry_debugfs_conf
*)id
->driver_data
;
917 if (!telemetry_get_pltdata()) {
918 pr_info("Invalid pltconfig, ensure IPC1 device is enabled in BIOS\n");
922 err
= telemetry_debugfs_check_evts();
924 pr_info("telemetry_debugfs_check_evts failed\n");
928 register_pm_notifier(&pm_notifier
);
930 dir
= debugfs_create_dir("telemetry", NULL
);
931 debugfs_conf
->telemetry_dbg_dir
= dir
;
933 debugfs_create_file("pss_info", S_IFREG
| S_IRUGO
, dir
, NULL
,
934 &telem_pss_states_fops
);
935 debugfs_create_file("ioss_info", S_IFREG
| S_IRUGO
, dir
, NULL
,
936 &telem_ioss_states_fops
);
937 debugfs_create_file("soc_states", S_IFREG
| S_IRUGO
, dir
, NULL
,
938 &telem_soc_states_fops
);
939 debugfs_create_file("s0ix_residency_usec", S_IFREG
| S_IRUGO
, dir
, NULL
,
941 debugfs_create_file("pss_trace_verbosity", S_IFREG
| S_IRUGO
, dir
, NULL
,
942 &telem_pss_trc_verb_ops
);
943 debugfs_create_file("ioss_trace_verbosity", S_IFREG
| S_IRUGO
, dir
,
944 NULL
, &telem_ioss_trc_verb_ops
);
948 static void __exit
telemetry_debugfs_exit(void)
950 debugfs_remove_recursive(debugfs_conf
->telemetry_dbg_dir
);
951 debugfs_conf
->telemetry_dbg_dir
= NULL
;
952 unregister_pm_notifier(&pm_notifier
);
955 late_initcall(telemetry_debugfs_init
);
956 module_exit(telemetry_debugfs_exit
);
958 MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
959 MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface");
960 MODULE_VERSION(DRIVER_VERSION
);
961 MODULE_LICENSE("GPL v2");