2 * Intel SOC Telemetry debugfs Driver: Currently supports APL
3 * Copyright (c) 2015, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * This file provides the debugfs interfaces for telemetry.
16 * /sys/kernel/debug/telemetry/pss_info: Shows Primary Control Sub-Sys Counters
17 * /sys/kernel/debug/telemetry/ioss_info: Shows IO Sub-System Counters
18 * /sys/kernel/debug/telemetry/soc_states: Shows SoC State
19 * /sys/kernel/debug/telemetry/pss_trace_verbosity: Read and Change Tracing
20 * Verbosity via firmware
21 * /sys/kernel/debug/telemetry/ioss_race_verbosity: Write and Change Tracing
22 * Verbosity via firmware
24 #include <linux/debugfs.h>
25 #include <linux/device.h>
26 #include <linux/module.h>
27 #include <linux/pci.h>
28 #include <linux/seq_file.h>
29 #include <linux/suspend.h>
31 #include <asm/cpu_device_id.h>
32 #include <asm/intel-family.h>
33 #include <asm/intel_pmc_ipc.h>
34 #include <asm/intel_telemetry.h>
36 #define DRIVER_NAME "telemetry_soc_debugfs"
37 #define DRIVER_VERSION "1.0.0"
39 /* ApolloLake SoC Event-IDs */
40 #define TELEM_APL_PSS_PSTATES_ID 0x2802
41 #define TELEM_APL_PSS_IDLE_ID 0x2806
42 #define TELEM_APL_PCS_IDLE_BLOCKED_ID 0x2C00
43 #define TELEM_APL_PCS_S0IX_BLOCKED_ID 0x2C01
44 #define TELEM_APL_PSS_WAKEUP_ID 0x2C02
45 #define TELEM_APL_PSS_LTR_BLOCKING_ID 0x2C03
47 #define TELEM_APL_S0IX_TOTAL_OCC_ID 0x4000
48 #define TELEM_APL_S0IX_SHLW_OCC_ID 0x4001
49 #define TELEM_APL_S0IX_DEEP_OCC_ID 0x4002
50 #define TELEM_APL_S0IX_TOTAL_RES_ID 0x4800
51 #define TELEM_APL_S0IX_SHLW_RES_ID 0x4801
52 #define TELEM_APL_S0IX_DEEP_RES_ID 0x4802
53 #define TELEM_APL_D0IX_ID 0x581A
54 #define TELEM_APL_D3_ID 0x5819
55 #define TELEM_APL_PG_ID 0x5818
57 #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
58 #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
59 #define TELEM_SSRAM_READ_TIMEOUT 10
61 #define TELEM_MASK_BIT 1
62 #define TELEM_MASK_BYTE 0xFF
63 #define BYTES_PER_LONG 8
64 #define TELEM_APL_MASK_PCS_STATE 0xF
66 /* Max events in bitmap to check for */
67 #define TELEM_PSS_IDLE_EVTS 25
68 #define TELEM_PSS_IDLE_BLOCKED_EVTS 20
69 #define TELEM_PSS_S0IX_BLOCKED_EVTS 20
70 #define TELEM_PSS_S0IX_WAKEUP_EVTS 20
71 #define TELEM_PSS_LTR_BLOCKING_EVTS 20
72 #define TELEM_IOSS_DX_D0IX_EVTS 25
73 #define TELEM_IOSS_PG_EVTS 30
75 #define TELEM_DEBUGFS_CPU(model, data) \
76 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&data}
78 #define TELEM_CHECK_AND_PARSE_EVTS(EVTID, EVTNUM, BUF, EVTLOG, EVTDAT, MASK) { \
79 if (evtlog[index].telem_evtid == (EVTID)) { \
80 for (idx = 0; idx < (EVTNUM); idx++) \
81 (BUF)[idx] = ((EVTLOG) >> (EVTDAT)[idx].bit_pos) & \
87 #define TELEM_CHECK_AND_PARSE_CTRS(EVTID, CTR) { \
88 if (evtlog[index].telem_evtid == (EVTID)) { \
89 (CTR) = evtlog[index].telem_evtlog; \
94 static u8 suspend_prep_ok
;
95 static u32 suspend_shlw_ctr_temp
, suspend_deep_ctr_temp
;
96 static u64 suspend_shlw_res_temp
, suspend_deep_res_temp
;
98 struct telemetry_susp_stats
{
105 /* Bitmap definitions for default counters in APL */
106 struct telem_pss_idle_stateinfo
{
111 static struct telem_pss_idle_stateinfo telem_apl_pss_idle_data
[] = {
120 {"IA_MODULE0_C7", 32},
121 {"IA_MODULE1_C7", 33},
123 {"IUNIT_PROCESSING_IDLE", 41},
124 {"FAR_MEM_IDLE", 43},
125 {"DISPLAY_IDLE", 44},
126 {"IUNIT_INPUT_SYSTEM_IDLE", 45},
130 struct telem_pcs_blkd_info
{
135 static struct telem_pcs_blkd_info telem_apl_pcs_idle_blkd_data
[] = {
138 {"MODULE_ACTIONS_PENDING", 16},
140 {"DISPLAY_WAKE", 32},
145 static struct telem_pcs_blkd_info telem_apl_pcs_s0ix_blkd_data
[] = {
148 {"WAKE_DEADLINE_PENDING", 16},
156 struct telem_pss_ltr_info
{
161 static struct telem_pss_ltr_info telem_apl_pss_ltr_data
[] = {
165 {"DFX_FORCE_LTR", 24},
171 struct telem_pss_wakeup_info
{
176 static struct telem_pss_wakeup_info telem_apl_pss_wakeup
[] = {
179 {"VOLTAGE_REG_INT", 16},
180 {"DROWSY_TIMER (HOTPLUG)", 24},
186 struct telem_ioss_d0ix_stateinfo
{
191 static struct telem_ioss_d0ix_stateinfo telem_apl_ioss_d0ix_data
[] = {
213 struct telem_ioss_pg_info
{
218 static struct telem_ioss_pg_info telem_apl_ioss_pg_data
[] = {
247 struct telemetry_debugfs_conf
{
248 struct telemetry_susp_stats suspend_stats
;
249 struct dentry
*telemetry_dbg_dir
;
252 struct telem_ioss_d0ix_stateinfo
*ioss_d0ix_data
;
253 struct telem_pss_idle_stateinfo
*pss_idle_data
;
254 struct telem_pcs_blkd_info
*pcs_idle_blkd_data
;
255 struct telem_pcs_blkd_info
*pcs_s0ix_blkd_data
;
256 struct telem_pss_wakeup_info
*pss_wakeup
;
257 struct telem_pss_ltr_info
*pss_ltr_data
;
258 struct telem_ioss_pg_info
*ioss_pg_data
;
259 u8 pcs_idle_blkd_evts
;
260 u8 pcs_s0ix_blkd_evts
;
268 u16 pss_ltr_blocking_id
;
269 u16 pcs_idle_blkd_id
;
270 u16 pcs_s0ix_blkd_id
;
271 u16 s0ix_total_occ_id
;
272 u16 s0ix_shlw_occ_id
;
273 u16 s0ix_deep_occ_id
;
274 u16 s0ix_total_res_id
;
275 u16 s0ix_shlw_res_id
;
276 u16 s0ix_deep_res_id
;
285 static struct telemetry_debugfs_conf
*debugfs_conf
;
287 static struct telemetry_debugfs_conf telem_apl_debugfs_conf
= {
288 .pss_idle_data
= telem_apl_pss_idle_data
,
289 .pcs_idle_blkd_data
= telem_apl_pcs_idle_blkd_data
,
290 .pcs_s0ix_blkd_data
= telem_apl_pcs_s0ix_blkd_data
,
291 .pss_ltr_data
= telem_apl_pss_ltr_data
,
292 .pss_wakeup
= telem_apl_pss_wakeup
,
293 .ioss_d0ix_data
= telem_apl_ioss_d0ix_data
,
294 .ioss_pg_data
= telem_apl_ioss_pg_data
,
296 .pss_idle_evts
= ARRAY_SIZE(telem_apl_pss_idle_data
),
297 .pcs_idle_blkd_evts
= ARRAY_SIZE(telem_apl_pcs_idle_blkd_data
),
298 .pcs_s0ix_blkd_evts
= ARRAY_SIZE(telem_apl_pcs_s0ix_blkd_data
),
299 .pss_ltr_evts
= ARRAY_SIZE(telem_apl_pss_ltr_data
),
300 .pss_wakeup_evts
= ARRAY_SIZE(telem_apl_pss_wakeup
),
301 .ioss_d0ix_evts
= ARRAY_SIZE(telem_apl_ioss_d0ix_data
),
302 .ioss_pg_evts
= ARRAY_SIZE(telem_apl_ioss_pg_data
),
304 .pstates_id
= TELEM_APL_PSS_PSTATES_ID
,
305 .pss_idle_id
= TELEM_APL_PSS_IDLE_ID
,
306 .pcs_idle_blkd_id
= TELEM_APL_PCS_IDLE_BLOCKED_ID
,
307 .pcs_s0ix_blkd_id
= TELEM_APL_PCS_S0IX_BLOCKED_ID
,
308 .pss_wakeup_id
= TELEM_APL_PSS_WAKEUP_ID
,
309 .pss_ltr_blocking_id
= TELEM_APL_PSS_LTR_BLOCKING_ID
,
310 .s0ix_total_occ_id
= TELEM_APL_S0IX_TOTAL_OCC_ID
,
311 .s0ix_shlw_occ_id
= TELEM_APL_S0IX_SHLW_OCC_ID
,
312 .s0ix_deep_occ_id
= TELEM_APL_S0IX_DEEP_OCC_ID
,
313 .s0ix_total_res_id
= TELEM_APL_S0IX_TOTAL_RES_ID
,
314 .s0ix_shlw_res_id
= TELEM_APL_S0IX_SHLW_RES_ID
,
315 .s0ix_deep_res_id
= TELEM_APL_S0IX_DEEP_RES_ID
,
316 .ioss_d0ix_id
= TELEM_APL_D0IX_ID
,
317 .ioss_d3_id
= TELEM_APL_D3_ID
,
318 .ioss_pg_id
= TELEM_APL_PG_ID
,
321 static const struct x86_cpu_id telemetry_debugfs_cpu_ids
[] = {
322 TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT
, telem_apl_debugfs_conf
),
323 TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GEMINI_LAKE
, telem_apl_debugfs_conf
),
327 MODULE_DEVICE_TABLE(x86cpu
, telemetry_debugfs_cpu_ids
);
329 static int telemetry_debugfs_check_evts(void)
331 if ((debugfs_conf
->pss_idle_evts
> TELEM_PSS_IDLE_EVTS
) ||
332 (debugfs_conf
->pcs_idle_blkd_evts
> TELEM_PSS_IDLE_BLOCKED_EVTS
) ||
333 (debugfs_conf
->pcs_s0ix_blkd_evts
> TELEM_PSS_S0IX_BLOCKED_EVTS
) ||
334 (debugfs_conf
->pss_ltr_evts
> TELEM_PSS_LTR_BLOCKING_EVTS
) ||
335 (debugfs_conf
->pss_wakeup_evts
> TELEM_PSS_S0IX_WAKEUP_EVTS
) ||
336 (debugfs_conf
->ioss_d0ix_evts
> TELEM_IOSS_DX_D0IX_EVTS
) ||
337 (debugfs_conf
->ioss_pg_evts
> TELEM_IOSS_PG_EVTS
))
343 static int telem_pss_states_show(struct seq_file
*s
, void *unused
)
345 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
346 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
347 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
348 u32 pcs_idle_blkd
[TELEM_PSS_IDLE_BLOCKED_EVTS
],
349 pcs_s0ix_blkd
[TELEM_PSS_S0IX_BLOCKED_EVTS
],
350 pss_s0ix_wakeup
[TELEM_PSS_S0IX_WAKEUP_EVTS
],
351 pss_ltr_blkd
[TELEM_PSS_LTR_BLOCKING_EVTS
],
352 pss_idle
[TELEM_PSS_IDLE_EVTS
];
353 int index
, idx
, ret
, err
= 0;
356 ret
= telemetry_read_eventlog(TELEM_PSS
, evtlog
,
357 TELEM_MAX_OS_ALLOCATED_EVENTS
);
361 err
= telemetry_get_evtname(TELEM_PSS
, name
,
362 TELEM_MAX_OS_ALLOCATED_EVENTS
);
366 seq_puts(s
, "\n----------------------------------------------------\n");
367 seq_puts(s
, "\tPSS TELEM EVENTLOG (Residency = field/19.2 us\n");
368 seq_puts(s
, "----------------------------------------------------\n");
369 for (index
= 0; index
< ret
; index
++) {
370 seq_printf(s
, "%-32s %llu\n",
371 name
[index
], evtlog
[index
].telem_evtlog
);
373 /* Fetch PSS IDLE State */
374 if (evtlog
[index
].telem_evtid
== conf
->pss_idle_id
) {
375 pss_idle
[conf
->pss_idle_evts
- 1] =
376 (evtlog
[index
].telem_evtlog
>>
377 conf
->pss_idle_data
[conf
->pss_idle_evts
- 1].bit_pos
) &
378 TELEM_APL_MASK_PCS_STATE
;
381 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_idle_id
,
382 conf
->pss_idle_evts
- 1,
383 pss_idle
, evtlog
[index
].telem_evtlog
,
384 conf
->pss_idle_data
, TELEM_MASK_BIT
);
386 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_idle_blkd_id
,
387 conf
->pcs_idle_blkd_evts
,
389 evtlog
[index
].telem_evtlog
,
390 conf
->pcs_idle_blkd_data
,
393 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_s0ix_blkd_id
,
394 conf
->pcs_s0ix_blkd_evts
,
396 evtlog
[index
].telem_evtlog
,
397 conf
->pcs_s0ix_blkd_data
,
400 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_wakeup_id
,
401 conf
->pss_wakeup_evts
,
403 evtlog
[index
].telem_evtlog
,
404 conf
->pss_wakeup
, TELEM_MASK_BYTE
);
406 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_ltr_blocking_id
,
407 conf
->pss_ltr_evts
, pss_ltr_blkd
,
408 evtlog
[index
].telem_evtlog
,
409 conf
->pss_ltr_data
, TELEM_MASK_BYTE
);
411 if (evtlog
[index
].telem_evtid
== debugfs_conf
->pstates_id
)
412 pstates
= evtlog
[index
].telem_evtlog
;
415 seq_puts(s
, "\n--------------------------------------\n");
416 seq_puts(s
, "PStates\n");
417 seq_puts(s
, "--------------------------------------\n");
418 seq_puts(s
, "Domain\t\t\t\tFreq(Mhz)\n");
419 seq_printf(s
, " IA\t\t\t\t %llu\n GT\t\t\t\t %llu\n",
420 (pstates
& TELEM_MASK_BYTE
)*100,
421 ((pstates
>> 8) & TELEM_MASK_BYTE
)*50/3);
423 seq_printf(s
, " IUNIT\t\t\t\t %llu\n SA\t\t\t\t %llu\n",
424 ((pstates
>> 16) & TELEM_MASK_BYTE
)*25,
425 ((pstates
>> 24) & TELEM_MASK_BYTE
)*50/3);
427 seq_puts(s
, "\n--------------------------------------\n");
428 seq_puts(s
, "PSS IDLE Status\n");
429 seq_puts(s
, "--------------------------------------\n");
430 seq_puts(s
, "Device\t\t\t\t\tIDLE\n");
431 for (index
= 0; index
< debugfs_conf
->pss_idle_evts
; index
++) {
432 seq_printf(s
, "%-32s\t%u\n",
433 debugfs_conf
->pss_idle_data
[index
].name
,
437 seq_puts(s
, "\n--------------------------------------\n");
438 seq_puts(s
, "PSS Idle blkd Status (~1ms saturating bucket)\n");
439 seq_puts(s
, "--------------------------------------\n");
440 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
441 for (index
= 0; index
< debugfs_conf
->pcs_idle_blkd_evts
; index
++) {
442 seq_printf(s
, "%-32s\t%u\n",
443 debugfs_conf
->pcs_idle_blkd_data
[index
].name
,
444 pcs_idle_blkd
[index
]);
447 seq_puts(s
, "\n--------------------------------------\n");
448 seq_puts(s
, "PSS S0ix blkd Status (~1ms saturating bucket)\n");
449 seq_puts(s
, "--------------------------------------\n");
450 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
451 for (index
= 0; index
< debugfs_conf
->pcs_s0ix_blkd_evts
; index
++) {
452 seq_printf(s
, "%-32s\t%u\n",
453 debugfs_conf
->pcs_s0ix_blkd_data
[index
].name
,
454 pcs_s0ix_blkd
[index
]);
457 seq_puts(s
, "\n--------------------------------------\n");
458 seq_puts(s
, "LTR Blocking Status (~1ms saturating bucket)\n");
459 seq_puts(s
, "--------------------------------------\n");
460 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
461 for (index
= 0; index
< debugfs_conf
->pss_ltr_evts
; index
++) {
462 seq_printf(s
, "%-32s\t%u\n",
463 debugfs_conf
->pss_ltr_data
[index
].name
,
464 pss_s0ix_wakeup
[index
]);
467 seq_puts(s
, "\n--------------------------------------\n");
468 seq_puts(s
, "Wakes Status (~1ms saturating bucket)\n");
469 seq_puts(s
, "--------------------------------------\n");
470 seq_puts(s
, "Wakes\t\t\t\t\tCount\n");
471 for (index
= 0; index
< debugfs_conf
->pss_wakeup_evts
; index
++) {
472 seq_printf(s
, "%-32s\t%u\n",
473 debugfs_conf
->pss_wakeup
[index
].name
,
474 pss_ltr_blkd
[index
]);
480 static int telem_pss_state_open(struct inode
*inode
, struct file
*file
)
482 return single_open(file
, telem_pss_states_show
, inode
->i_private
);
485 static const struct file_operations telem_pss_ops
= {
486 .open
= telem_pss_state_open
,
489 .release
= single_release
,
492 static int telem_ioss_states_show(struct seq_file
*s
, void *unused
)
494 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
495 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
498 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
499 TELEM_MAX_OS_ALLOCATED_EVENTS
);
503 err
= telemetry_get_evtname(TELEM_IOSS
, name
,
504 TELEM_MAX_OS_ALLOCATED_EVENTS
);
508 seq_puts(s
, "--------------------------------------\n");
509 seq_puts(s
, "\tI0SS TELEMETRY EVENTLOG\n");
510 seq_puts(s
, "--------------------------------------\n");
511 for (index
= 0; index
< ret
; index
++) {
512 seq_printf(s
, "%-32s 0x%llx\n",
513 name
[index
], evtlog
[index
].telem_evtlog
);
519 static int telem_ioss_state_open(struct inode
*inode
, struct file
*file
)
521 return single_open(file
, telem_ioss_states_show
, inode
->i_private
);
524 static const struct file_operations telem_ioss_ops
= {
525 .open
= telem_ioss_state_open
,
528 .release
= single_release
,
531 static int telem_soc_states_show(struct seq_file
*s
, void *unused
)
533 u32 d3_sts
[TELEM_IOSS_DX_D0IX_EVTS
], d0ix_sts
[TELEM_IOSS_DX_D0IX_EVTS
];
534 u32 pg_sts
[TELEM_IOSS_PG_EVTS
], pss_idle
[TELEM_PSS_IDLE_EVTS
];
535 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
536 u32 s0ix_total_ctr
= 0, s0ix_shlw_ctr
= 0, s0ix_deep_ctr
= 0;
537 u64 s0ix_total_res
= 0, s0ix_shlw_res
= 0, s0ix_deep_res
= 0;
538 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
539 struct pci_dev
*dev
= NULL
;
544 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
545 TELEM_MAX_OS_ALLOCATED_EVENTS
);
549 for (index
= 0; index
< ret
; index
++) {
550 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d3_id
,
551 conf
->ioss_d0ix_evts
,
552 d3_sts
, evtlog
[index
].telem_evtlog
,
553 conf
->ioss_d0ix_data
,
556 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_pg_id
, conf
->ioss_pg_evts
,
557 pg_sts
, evtlog
[index
].telem_evtlog
,
558 conf
->ioss_pg_data
, TELEM_MASK_BIT
);
560 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d0ix_id
,
561 conf
->ioss_d0ix_evts
,
562 d0ix_sts
, evtlog
[index
].telem_evtlog
,
563 conf
->ioss_d0ix_data
,
566 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_occ_id
,
569 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
572 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
575 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_res_id
,
578 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
581 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
585 seq_puts(s
, "\n---------------------------------------------------\n");
586 seq_puts(s
, "S0IX Type\t\t\t Occurrence\t\t Residency(us)\n");
587 seq_puts(s
, "---------------------------------------------------\n");
589 seq_printf(s
, "S0IX Shallow\t\t\t %10u\t %10llu\n",
591 conf
->suspend_stats
.shlw_ctr
,
592 (u64
)((s0ix_shlw_res
-
593 conf
->suspend_stats
.shlw_res
)*10/192));
595 seq_printf(s
, "S0IX Deep\t\t\t %10u\t %10llu\n",
597 conf
->suspend_stats
.deep_ctr
,
598 (u64
)((s0ix_deep_res
-
599 conf
->suspend_stats
.deep_res
)*10/192));
601 seq_printf(s
, "Suspend(With S0ixShallow)\t %10u\t %10llu\n",
602 conf
->suspend_stats
.shlw_ctr
,
603 (u64
)(conf
->suspend_stats
.shlw_res
*10)/192);
605 seq_printf(s
, "Suspend(With S0ixDeep)\t\t %10u\t %10llu\n",
606 conf
->suspend_stats
.deep_ctr
,
607 (u64
)(conf
->suspend_stats
.deep_res
*10)/192);
609 seq_printf(s
, "TOTAL S0IX\t\t\t %10u\t %10llu\n", s0ix_total_ctr
,
610 (u64
)(s0ix_total_res
*10/192));
611 seq_puts(s
, "\n-------------------------------------------------\n");
612 seq_puts(s
, "\t\tDEVICE STATES\n");
613 seq_puts(s
, "-------------------------------------------------\n");
615 for_each_pci_dev(dev
) {
616 pci_read_config_word(dev
, dev
->pm_cap
+ PCI_PM_CTRL
, &pmcsr
);
617 d3_state
= ((pmcsr
& PCI_PM_CTRL_STATE_MASK
) ==
618 (__force
int)PCI_D3hot
) ? 1 : 0;
620 seq_printf(s
, "pci %04x %04X %s %20.20s: ",
621 dev
->vendor
, dev
->device
, dev_name(&dev
->dev
),
622 dev_driver_string(&dev
->dev
));
623 seq_printf(s
, " d3:%x\n", d3_state
);
626 seq_puts(s
, "\n--------------------------------------\n");
627 seq_puts(s
, "D3/D0i3 Status\n");
628 seq_puts(s
, "--------------------------------------\n");
629 seq_puts(s
, "Block\t\t D3\t D0i3\n");
630 for (index
= 0; index
< conf
->ioss_d0ix_evts
; index
++) {
631 seq_printf(s
, "%-10s\t %u\t %u\n",
632 conf
->ioss_d0ix_data
[index
].name
,
633 d3_sts
[index
], d0ix_sts
[index
]);
636 seq_puts(s
, "\n--------------------------------------\n");
637 seq_puts(s
, "South Complex PowerGate Status\n");
638 seq_puts(s
, "--------------------------------------\n");
639 seq_puts(s
, "Device\t\t PG\n");
640 for (index
= 0; index
< conf
->ioss_pg_evts
; index
++) {
641 seq_printf(s
, "%-10s\t %u\n",
642 conf
->ioss_pg_data
[index
].name
,
646 evtlog
->telem_evtid
= conf
->pss_idle_id
;
647 ret
= telemetry_read_events(TELEM_PSS
, evtlog
, 1);
651 seq_puts(s
, "\n-----------------------------------------\n");
652 seq_puts(s
, "North Idle Status\n");
653 seq_puts(s
, "-----------------------------------------\n");
654 for (idx
= 0; idx
< conf
->pss_idle_evts
- 1; idx
++) {
655 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
656 conf
->pss_idle_data
[idx
].bit_pos
) &
660 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
661 conf
->pss_idle_data
[idx
].bit_pos
) &
662 TELEM_APL_MASK_PCS_STATE
;
664 for (index
= 0; index
< conf
->pss_idle_evts
; index
++) {
665 seq_printf(s
, "%-30s %u\n",
666 conf
->pss_idle_data
[index
].name
,
670 seq_puts(s
, "\nPCS_STATUS Code\n");
671 seq_puts(s
, "0:C0 1:C1 2:C1_DN_WT_DEV 3:C2 4:C2_WT_DE_MEM_UP\n");
672 seq_puts(s
, "5:C2_WT_DE_MEM_DOWN 6:C2_UP_WT_DEV 7:C2_DN 8:C2_VOA\n");
673 seq_puts(s
, "9:C2_VOA_UP 10:S0IX_PRE 11:S0IX\n");
678 static int telem_soc_state_open(struct inode
*inode
, struct file
*file
)
680 return single_open(file
, telem_soc_states_show
, inode
->i_private
);
683 static const struct file_operations telem_socstate_ops
= {
684 .open
= telem_soc_state_open
,
687 .release
= single_release
,
690 static int telem_s0ix_res_get(void *data
, u64
*val
)
695 ret
= intel_pmc_s0ix_counter_read(&s0ix_total_res
);
697 pr_err("Failed to read S0ix residency");
701 *val
= s0ix_total_res
;
706 DEFINE_DEBUGFS_ATTRIBUTE(telem_s0ix_fops
, telem_s0ix_res_get
, NULL
, "%llu\n");
708 static int telem_pss_trc_verb_show(struct seq_file
*s
, void *unused
)
713 err
= telemetry_get_trace_verbosity(TELEM_PSS
, &verbosity
);
715 pr_err("Get PSS Trace Verbosity Failed with Error %d\n", err
);
719 seq_printf(s
, "PSS Trace Verbosity %u\n", verbosity
);
723 static ssize_t
telem_pss_trc_verb_write(struct file
*file
,
724 const char __user
*userbuf
,
725 size_t count
, loff_t
*ppos
)
730 if (kstrtou32_from_user(userbuf
, count
, 0, &verbosity
))
733 err
= telemetry_set_trace_verbosity(TELEM_PSS
, verbosity
);
735 pr_err("Changing PSS Trace Verbosity Failed. Error %d\n", err
);
742 static int telem_pss_trc_verb_open(struct inode
*inode
, struct file
*file
)
744 return single_open(file
, telem_pss_trc_verb_show
, inode
->i_private
);
747 static const struct file_operations telem_pss_trc_verb_ops
= {
748 .open
= telem_pss_trc_verb_open
,
750 .write
= telem_pss_trc_verb_write
,
752 .release
= single_release
,
755 static int telem_ioss_trc_verb_show(struct seq_file
*s
, void *unused
)
760 err
= telemetry_get_trace_verbosity(TELEM_IOSS
, &verbosity
);
762 pr_err("Get IOSS Trace Verbosity Failed with Error %d\n", err
);
766 seq_printf(s
, "IOSS Trace Verbosity %u\n", verbosity
);
770 static ssize_t
telem_ioss_trc_verb_write(struct file
*file
,
771 const char __user
*userbuf
,
772 size_t count
, loff_t
*ppos
)
777 if (kstrtou32_from_user(userbuf
, count
, 0, &verbosity
))
780 err
= telemetry_set_trace_verbosity(TELEM_IOSS
, verbosity
);
782 pr_err("Changing IOSS Trace Verbosity Failed. Error %d\n", err
);
789 static int telem_ioss_trc_verb_open(struct inode
*inode
, struct file
*file
)
791 return single_open(file
, telem_ioss_trc_verb_show
, inode
->i_private
);
794 static const struct file_operations telem_ioss_trc_verb_ops
= {
795 .open
= telem_ioss_trc_verb_open
,
797 .write
= telem_ioss_trc_verb_write
,
799 .release
= single_release
,
802 static int pm_suspend_prep_cb(void)
804 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
805 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
808 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
809 TELEM_MAX_OS_ALLOCATED_EVENTS
);
815 for (index
= 0; index
< ret
; index
++) {
817 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
818 suspend_shlw_ctr_temp
);
820 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
821 suspend_deep_ctr_temp
);
823 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
824 suspend_shlw_res_temp
);
826 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
827 suspend_deep_res_temp
);
834 static int pm_suspend_exit_cb(void)
836 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
837 static u32 suspend_shlw_ctr_exit
, suspend_deep_ctr_exit
;
838 static u64 suspend_shlw_res_exit
, suspend_deep_res_exit
;
839 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
842 if (!suspend_prep_ok
)
845 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
846 TELEM_MAX_OS_ALLOCATED_EVENTS
);
850 for (index
= 0; index
< ret
; index
++) {
851 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
852 suspend_shlw_ctr_exit
);
854 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
855 suspend_deep_ctr_exit
);
857 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
858 suspend_shlw_res_exit
);
860 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
861 suspend_deep_res_exit
);
864 if ((suspend_shlw_ctr_exit
< suspend_shlw_ctr_temp
) ||
865 (suspend_deep_ctr_exit
< suspend_deep_ctr_temp
) ||
866 (suspend_shlw_res_exit
< suspend_shlw_res_temp
) ||
867 (suspend_deep_res_exit
< suspend_deep_res_temp
)) {
868 pr_err("Wrong s0ix counters detected\n");
873 * Due to some design limitations in the firmware, sometimes the
874 * counters do not get updated by the time we reach here. As a
875 * workaround, we try to see if this was a genuine case of sleep
876 * failure or not by cross-checking from PMC GCR registers directly.
878 if (suspend_shlw_ctr_exit
== suspend_shlw_ctr_temp
&&
879 suspend_deep_ctr_exit
== suspend_deep_ctr_temp
) {
880 ret
= intel_pmc_gcr_read64(PMC_GCR_TELEM_SHLW_S0IX_REG
,
881 &suspend_shlw_res_exit
);
885 ret
= intel_pmc_gcr_read64(PMC_GCR_TELEM_DEEP_S0IX_REG
,
886 &suspend_deep_res_exit
);
890 if (suspend_shlw_res_exit
> suspend_shlw_res_temp
)
891 suspend_shlw_ctr_exit
++;
893 if (suspend_deep_res_exit
> suspend_deep_res_temp
)
894 suspend_deep_ctr_exit
++;
897 suspend_shlw_ctr_exit
-= suspend_shlw_ctr_temp
;
898 suspend_deep_ctr_exit
-= suspend_deep_ctr_temp
;
899 suspend_shlw_res_exit
-= suspend_shlw_res_temp
;
900 suspend_deep_res_exit
-= suspend_deep_res_temp
;
902 if (suspend_shlw_ctr_exit
!= 0) {
903 conf
->suspend_stats
.shlw_ctr
+=
904 suspend_shlw_ctr_exit
;
906 conf
->suspend_stats
.shlw_res
+=
907 suspend_shlw_res_exit
;
910 if (suspend_deep_ctr_exit
!= 0) {
911 conf
->suspend_stats
.deep_ctr
+=
912 suspend_deep_ctr_exit
;
914 conf
->suspend_stats
.deep_res
+=
915 suspend_deep_res_exit
;
923 static int pm_notification(struct notifier_block
*this,
924 unsigned long event
, void *ptr
)
927 case PM_SUSPEND_PREPARE
:
928 return pm_suspend_prep_cb();
929 case PM_POST_SUSPEND
:
930 return pm_suspend_exit_cb();
936 static struct notifier_block pm_notifier
= {
937 .notifier_call
= pm_notification
,
940 static int __init
telemetry_debugfs_init(void)
942 const struct x86_cpu_id
*id
;
946 /* Only APL supported for now */
947 id
= x86_match_cpu(telemetry_debugfs_cpu_ids
);
951 debugfs_conf
= (struct telemetry_debugfs_conf
*)id
->driver_data
;
953 err
= telemetry_pltconfig_valid();
957 err
= telemetry_debugfs_check_evts();
961 register_pm_notifier(&pm_notifier
);
964 debugfs_conf
->telemetry_dbg_dir
= debugfs_create_dir("telemetry", NULL
);
965 if (!debugfs_conf
->telemetry_dbg_dir
)
968 f
= debugfs_create_file("pss_info", S_IFREG
| S_IRUGO
,
969 debugfs_conf
->telemetry_dbg_dir
, NULL
,
972 pr_err("pss_sample_info debugfs register failed\n");
976 f
= debugfs_create_file("ioss_info", S_IFREG
| S_IRUGO
,
977 debugfs_conf
->telemetry_dbg_dir
, NULL
,
980 pr_err("ioss_sample_info debugfs register failed\n");
984 f
= debugfs_create_file("soc_states", S_IFREG
| S_IRUGO
,
985 debugfs_conf
->telemetry_dbg_dir
,
986 NULL
, &telem_socstate_ops
);
988 pr_err("ioss_sample_info debugfs register failed\n");
992 f
= debugfs_create_file("s0ix_residency_usec", S_IFREG
| S_IRUGO
,
993 debugfs_conf
->telemetry_dbg_dir
,
994 NULL
, &telem_s0ix_fops
);
996 pr_err("s0ix_residency_usec debugfs register failed\n");
1000 f
= debugfs_create_file("pss_trace_verbosity", S_IFREG
| S_IRUGO
,
1001 debugfs_conf
->telemetry_dbg_dir
, NULL
,
1002 &telem_pss_trc_verb_ops
);
1004 pr_err("pss_trace_verbosity debugfs register failed\n");
1008 f
= debugfs_create_file("ioss_trace_verbosity", S_IFREG
| S_IRUGO
,
1009 debugfs_conf
->telemetry_dbg_dir
, NULL
,
1010 &telem_ioss_trc_verb_ops
);
1012 pr_err("ioss_trace_verbosity debugfs register failed\n");
1019 debugfs_remove_recursive(debugfs_conf
->telemetry_dbg_dir
);
1020 debugfs_conf
->telemetry_dbg_dir
= NULL
;
1022 unregister_pm_notifier(&pm_notifier
);
1027 static void __exit
telemetry_debugfs_exit(void)
1029 debugfs_remove_recursive(debugfs_conf
->telemetry_dbg_dir
);
1030 debugfs_conf
->telemetry_dbg_dir
= NULL
;
1031 unregister_pm_notifier(&pm_notifier
);
1034 late_initcall(telemetry_debugfs_init
);
1035 module_exit(telemetry_debugfs_exit
);
1037 MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
1038 MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface");
1039 MODULE_VERSION(DRIVER_VERSION
);
1040 MODULE_LICENSE("GPL");