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/module.h>
25 #include <linux/init.h>
26 #include <linux/device.h>
27 #include <linux/debugfs.h>
28 #include <linux/seq_file.h>
30 #include <linux/uaccess.h>
31 #include <linux/pci.h>
32 #include <linux/suspend.h>
34 #include <asm/cpu_device_id.h>
35 #include <asm/intel_pmc_ipc.h>
36 #include <asm/intel_punit_ipc.h>
37 #include <asm/intel_telemetry.h>
39 #define DRIVER_NAME "telemetry_soc_debugfs"
40 #define DRIVER_VERSION "1.0.0"
42 /* ApolloLake SoC Event-IDs */
43 #define TELEM_APL_PSS_PSTATES_ID 0x2802
44 #define TELEM_APL_PSS_IDLE_ID 0x2806
45 #define TELEM_APL_PCS_IDLE_BLOCKED_ID 0x2C00
46 #define TELEM_APL_PCS_S0IX_BLOCKED_ID 0x2C01
47 #define TELEM_APL_PSS_WAKEUP_ID 0x2C02
48 #define TELEM_APL_PSS_LTR_BLOCKING_ID 0x2C03
50 #define TELEM_APL_S0IX_TOTAL_OCC_ID 0x4000
51 #define TELEM_APL_S0IX_SHLW_OCC_ID 0x4001
52 #define TELEM_APL_S0IX_DEEP_OCC_ID 0x4002
53 #define TELEM_APL_S0IX_TOTAL_RES_ID 0x4800
54 #define TELEM_APL_S0IX_SHLW_RES_ID 0x4801
55 #define TELEM_APL_S0IX_DEEP_RES_ID 0x4802
56 #define TELEM_APL_D0IX_ID 0x581A
57 #define TELEM_APL_D3_ID 0x5819
58 #define TELEM_APL_PG_ID 0x5818
60 #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
61 #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
62 #define TELEM_SSRAM_READ_TIMEOUT 10
64 #define TELEM_MASK_BIT 1
65 #define TELEM_MASK_BYTE 0xFF
66 #define BYTES_PER_LONG 8
67 #define TELEM_APL_MASK_PCS_STATE 0xF
69 /* Max events in bitmap to check for */
70 #define TELEM_PSS_IDLE_EVTS 25
71 #define TELEM_PSS_IDLE_BLOCKED_EVTS 20
72 #define TELEM_PSS_S0IX_BLOCKED_EVTS 20
73 #define TELEM_PSS_S0IX_WAKEUP_EVTS 20
74 #define TELEM_PSS_LTR_BLOCKING_EVTS 20
75 #define TELEM_IOSS_DX_D0IX_EVTS 25
76 #define TELEM_IOSS_PG_EVTS 30
78 #define TELEM_EVT_LEN(x) (sizeof(x)/sizeof((x)[0]))
80 #define TELEM_DEBUGFS_CPU(model, data) \
81 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&data}
83 #define TELEM_CHECK_AND_PARSE_EVTS(EVTID, EVTNUM, BUF, EVTLOG, EVTDAT, MASK) { \
84 if (evtlog[index].telem_evtid == (EVTID)) { \
85 for (idx = 0; idx < (EVTNUM); idx++) \
86 (BUF)[idx] = ((EVTLOG) >> (EVTDAT)[idx].bit_pos) & \
92 #define TELEM_CHECK_AND_PARSE_CTRS(EVTID, CTR) { \
93 if (evtlog[index].telem_evtid == (EVTID)) { \
94 (CTR) = evtlog[index].telem_evtlog; \
99 #ifdef CONFIG_PM_SLEEP
100 static u8 suspend_prep_ok
;
101 static u32 suspend_shlw_ctr_temp
, suspend_deep_ctr_temp
;
102 static u64 suspend_shlw_res_temp
, suspend_deep_res_temp
;
105 struct telemetry_susp_stats
{
116 /* Bitmap definitions for default counters in APL */
117 struct telem_pss_idle_stateinfo
{
122 static struct telem_pss_idle_stateinfo telem_apl_pss_idle_data
[] = {
131 {"IA_MODULE0_C7", 32},
132 {"IA_MODULE1_C7", 33},
134 {"IUNIT_PROCESSING_IDLE", 41},
135 {"FAR_MEM_IDLE", 43},
136 {"DISPLAY_IDLE", 44},
137 {"IUNIT_INPUT_SYSTEM_IDLE", 45},
141 struct telem_pcs_blkd_info
{
146 static struct telem_pcs_blkd_info telem_apl_pcs_idle_blkd_data
[] = {
149 {"MODULE_ACTIONS_PENDING", 16},
151 {"DISPLAY_WAKE", 32},
156 static struct telem_pcs_blkd_info telem_apl_pcs_s0ix_blkd_data
[] = {
159 {"WAKE_DEADLINE_PENDING", 16},
167 struct telem_pss_ltr_info
{
172 static struct telem_pss_ltr_info telem_apl_pss_ltr_data
[] = {
176 {"DFX_FORCE_LTR", 24},
182 struct telem_pss_wakeup_info
{
187 static struct telem_pss_wakeup_info telem_apl_pss_wakeup
[] = {
190 {"VOLTAGE_REG_INT", 16},
191 {"DROWSY_TIMER (HOTPLUG)", 24},
197 struct telem_ioss_d0ix_stateinfo
{
202 static struct telem_ioss_d0ix_stateinfo telem_apl_ioss_d0ix_data
[] = {
224 struct telem_ioss_pg_info
{
229 static struct telem_ioss_pg_info telem_apl_ioss_pg_data
[] = {
259 struct telemetry_debugfs_conf
{
260 struct telemetry_susp_stats suspend_stats
;
261 struct dentry
*telemetry_dbg_dir
;
264 struct telem_ioss_d0ix_stateinfo
*ioss_d0ix_data
;
265 struct telem_pss_idle_stateinfo
*pss_idle_data
;
266 struct telem_pcs_blkd_info
*pcs_idle_blkd_data
;
267 struct telem_pcs_blkd_info
*pcs_s0ix_blkd_data
;
268 struct telem_pss_wakeup_info
*pss_wakeup
;
269 struct telem_pss_ltr_info
*pss_ltr_data
;
270 struct telem_ioss_pg_info
*ioss_pg_data
;
271 u8 pcs_idle_blkd_evts
;
272 u8 pcs_s0ix_blkd_evts
;
280 u16 pss_ltr_blocking_id
;
281 u16 pcs_idle_blkd_id
;
282 u16 pcs_s0ix_blkd_id
;
283 u16 s0ix_total_occ_id
;
284 u16 s0ix_shlw_occ_id
;
285 u16 s0ix_deep_occ_id
;
286 u16 s0ix_total_res_id
;
287 u16 s0ix_shlw_res_id
;
288 u16 s0ix_deep_res_id
;
297 static struct telemetry_debugfs_conf
*debugfs_conf
;
299 static struct telemetry_debugfs_conf telem_apl_debugfs_conf
= {
300 .pss_idle_data
= telem_apl_pss_idle_data
,
301 .pcs_idle_blkd_data
= telem_apl_pcs_idle_blkd_data
,
302 .pcs_s0ix_blkd_data
= telem_apl_pcs_s0ix_blkd_data
,
303 .pss_ltr_data
= telem_apl_pss_ltr_data
,
304 .pss_wakeup
= telem_apl_pss_wakeup
,
305 .ioss_d0ix_data
= telem_apl_ioss_d0ix_data
,
306 .ioss_pg_data
= telem_apl_ioss_pg_data
,
308 .pss_idle_evts
= TELEM_EVT_LEN(telem_apl_pss_idle_data
),
309 .pcs_idle_blkd_evts
= TELEM_EVT_LEN(telem_apl_pcs_idle_blkd_data
),
310 .pcs_s0ix_blkd_evts
= TELEM_EVT_LEN(telem_apl_pcs_s0ix_blkd_data
),
311 .pss_ltr_evts
= TELEM_EVT_LEN(telem_apl_pss_ltr_data
),
312 .pss_wakeup_evts
= TELEM_EVT_LEN(telem_apl_pss_wakeup
),
313 .ioss_d0ix_evts
= TELEM_EVT_LEN(telem_apl_ioss_d0ix_data
),
314 .ioss_pg_evts
= TELEM_EVT_LEN(telem_apl_ioss_pg_data
),
316 .pstates_id
= TELEM_APL_PSS_PSTATES_ID
,
317 .pss_idle_id
= TELEM_APL_PSS_IDLE_ID
,
318 .pcs_idle_blkd_id
= TELEM_APL_PCS_IDLE_BLOCKED_ID
,
319 .pcs_s0ix_blkd_id
= TELEM_APL_PCS_S0IX_BLOCKED_ID
,
320 .pss_wakeup_id
= TELEM_APL_PSS_WAKEUP_ID
,
321 .pss_ltr_blocking_id
= TELEM_APL_PSS_LTR_BLOCKING_ID
,
322 .s0ix_total_occ_id
= TELEM_APL_S0IX_TOTAL_OCC_ID
,
323 .s0ix_shlw_occ_id
= TELEM_APL_S0IX_SHLW_OCC_ID
,
324 .s0ix_deep_occ_id
= TELEM_APL_S0IX_DEEP_OCC_ID
,
325 .s0ix_total_res_id
= TELEM_APL_S0IX_TOTAL_RES_ID
,
326 .s0ix_shlw_res_id
= TELEM_APL_S0IX_SHLW_RES_ID
,
327 .s0ix_deep_res_id
= TELEM_APL_S0IX_DEEP_RES_ID
,
328 .ioss_d0ix_id
= TELEM_APL_D0IX_ID
,
329 .ioss_d3_id
= TELEM_APL_D3_ID
,
330 .ioss_pg_id
= TELEM_APL_PG_ID
,
333 static const struct x86_cpu_id telemetry_debugfs_cpu_ids
[] = {
334 TELEM_DEBUGFS_CPU(0x5c, telem_apl_debugfs_conf
),
338 MODULE_DEVICE_TABLE(x86cpu
, telemetry_debugfs_cpu_ids
);
340 static int telemetry_debugfs_check_evts(void)
342 if ((debugfs_conf
->pss_idle_evts
> TELEM_PSS_IDLE_EVTS
) ||
343 (debugfs_conf
->pcs_idle_blkd_evts
> TELEM_PSS_IDLE_BLOCKED_EVTS
) ||
344 (debugfs_conf
->pcs_s0ix_blkd_evts
> TELEM_PSS_S0IX_BLOCKED_EVTS
) ||
345 (debugfs_conf
->pss_ltr_evts
> TELEM_PSS_LTR_BLOCKING_EVTS
) ||
346 (debugfs_conf
->pss_wakeup_evts
> TELEM_PSS_S0IX_WAKEUP_EVTS
) ||
347 (debugfs_conf
->ioss_d0ix_evts
> TELEM_IOSS_DX_D0IX_EVTS
) ||
348 (debugfs_conf
->ioss_pg_evts
> TELEM_IOSS_PG_EVTS
))
354 static int telem_pss_states_show(struct seq_file
*s
, void *unused
)
356 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
357 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
358 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
359 u32 pcs_idle_blkd
[TELEM_PSS_IDLE_BLOCKED_EVTS
],
360 pcs_s0ix_blkd
[TELEM_PSS_S0IX_BLOCKED_EVTS
],
361 pss_s0ix_wakeup
[TELEM_PSS_S0IX_WAKEUP_EVTS
],
362 pss_ltr_blkd
[TELEM_PSS_LTR_BLOCKING_EVTS
],
363 pss_idle
[TELEM_PSS_IDLE_EVTS
];
364 int index
, idx
, ret
, err
= 0;
367 ret
= telemetry_read_eventlog(TELEM_PSS
, evtlog
,
368 TELEM_MAX_OS_ALLOCATED_EVENTS
);
372 err
= telemetry_get_evtname(TELEM_PSS
, name
,
373 TELEM_MAX_OS_ALLOCATED_EVENTS
);
377 seq_puts(s
, "\n----------------------------------------------------\n");
378 seq_puts(s
, "\tPSS TELEM EVENTLOG (Residency = field/19.2 us\n");
379 seq_puts(s
, "----------------------------------------------------\n");
380 for (index
= 0; index
< ret
; index
++) {
381 seq_printf(s
, "%-32s %llu\n",
382 name
[index
], evtlog
[index
].telem_evtlog
);
384 /* Fetch PSS IDLE State */
385 if (evtlog
[index
].telem_evtid
== conf
->pss_idle_id
) {
386 pss_idle
[conf
->pss_idle_evts
- 1] =
387 (evtlog
[index
].telem_evtlog
>>
388 conf
->pss_idle_data
[conf
->pss_idle_evts
- 1].bit_pos
) &
389 TELEM_APL_MASK_PCS_STATE
;
393 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_idle_id
,
394 conf
->pss_idle_evts
- 1,
395 pss_idle
, evtlog
[index
].telem_evtlog
,
396 conf
->pss_idle_data
, TELEM_MASK_BIT
);
398 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_idle_blkd_id
,
399 conf
->pcs_idle_blkd_evts
,
401 evtlog
[index
].telem_evtlog
,
402 conf
->pcs_idle_blkd_data
,
405 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_s0ix_blkd_id
,
406 conf
->pcs_s0ix_blkd_evts
,
408 evtlog
[index
].telem_evtlog
,
409 conf
->pcs_s0ix_blkd_data
,
413 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_wakeup_id
,
414 conf
->pss_wakeup_evts
,
416 evtlog
[index
].telem_evtlog
,
417 conf
->pss_wakeup
, TELEM_MASK_BYTE
);
419 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_ltr_blocking_id
,
420 conf
->pss_ltr_evts
, pss_ltr_blkd
,
421 evtlog
[index
].telem_evtlog
,
422 conf
->pss_ltr_data
, TELEM_MASK_BYTE
);
424 if (evtlog
[index
].telem_evtid
== debugfs_conf
->pstates_id
)
425 pstates
= evtlog
[index
].telem_evtlog
;
428 seq_puts(s
, "\n--------------------------------------\n");
429 seq_puts(s
, "PStates\n");
430 seq_puts(s
, "--------------------------------------\n");
431 seq_puts(s
, "Domain\t\t\t\tFreq(Mhz)\n");
432 seq_printf(s
, " IA\t\t\t\t %llu\n GT\t\t\t\t %llu\n",
433 (pstates
& TELEM_MASK_BYTE
)*100,
434 ((pstates
>> 8) & TELEM_MASK_BYTE
)*50/3);
436 seq_printf(s
, " IUNIT\t\t\t\t %llu\n SA\t\t\t\t %llu\n",
437 ((pstates
>> 16) & TELEM_MASK_BYTE
)*25,
438 ((pstates
>> 24) & TELEM_MASK_BYTE
)*50/3);
440 seq_puts(s
, "\n--------------------------------------\n");
441 seq_puts(s
, "PSS IDLE Status\n");
442 seq_puts(s
, "--------------------------------------\n");
443 seq_puts(s
, "Device\t\t\t\t\tIDLE\n");
444 for (index
= 0; index
< debugfs_conf
->pss_idle_evts
; index
++) {
445 seq_printf(s
, "%-32s\t%u\n",
446 debugfs_conf
->pss_idle_data
[index
].name
,
450 seq_puts(s
, "\n--------------------------------------\n");
451 seq_puts(s
, "PSS Idle blkd Status (~1ms saturating bucket)\n");
452 seq_puts(s
, "--------------------------------------\n");
453 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
454 for (index
= 0; index
< debugfs_conf
->pcs_idle_blkd_evts
; index
++) {
455 seq_printf(s
, "%-32s\t%u\n",
456 debugfs_conf
->pcs_idle_blkd_data
[index
].name
,
457 pcs_idle_blkd
[index
]);
460 seq_puts(s
, "\n--------------------------------------\n");
461 seq_puts(s
, "PSS S0ix blkd Status (~1ms saturating bucket)\n");
462 seq_puts(s
, "--------------------------------------\n");
463 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
464 for (index
= 0; index
< debugfs_conf
->pcs_s0ix_blkd_evts
; index
++) {
465 seq_printf(s
, "%-32s\t%u\n",
466 debugfs_conf
->pcs_s0ix_blkd_data
[index
].name
,
467 pcs_s0ix_blkd
[index
]);
470 seq_puts(s
, "\n--------------------------------------\n");
471 seq_puts(s
, "LTR Blocking Status (~1ms saturating bucket)\n");
472 seq_puts(s
, "--------------------------------------\n");
473 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
474 for (index
= 0; index
< debugfs_conf
->pss_ltr_evts
; index
++) {
475 seq_printf(s
, "%-32s\t%u\n",
476 debugfs_conf
->pss_ltr_data
[index
].name
,
477 pss_s0ix_wakeup
[index
]);
480 seq_puts(s
, "\n--------------------------------------\n");
481 seq_puts(s
, "Wakes Status (~1ms saturating bucket)\n");
482 seq_puts(s
, "--------------------------------------\n");
483 seq_puts(s
, "Wakes\t\t\t\t\tCount\n");
484 for (index
= 0; index
< debugfs_conf
->pss_wakeup_evts
; index
++) {
485 seq_printf(s
, "%-32s\t%u\n",
486 debugfs_conf
->pss_wakeup
[index
].name
,
487 pss_ltr_blkd
[index
]);
493 static int telem_pss_state_open(struct inode
*inode
, struct file
*file
)
495 return single_open(file
, telem_pss_states_show
, inode
->i_private
);
498 static const struct file_operations telem_pss_ops
= {
499 .open
= telem_pss_state_open
,
502 .release
= single_release
,
506 static int telem_ioss_states_show(struct seq_file
*s
, void *unused
)
508 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
509 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
512 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
513 TELEM_MAX_OS_ALLOCATED_EVENTS
);
517 err
= telemetry_get_evtname(TELEM_IOSS
, name
,
518 TELEM_MAX_OS_ALLOCATED_EVENTS
);
522 seq_puts(s
, "--------------------------------------\n");
523 seq_puts(s
, "\tI0SS TELEMETRY EVENTLOG\n");
524 seq_puts(s
, "--------------------------------------\n");
525 for (index
= 0; index
< ret
; index
++) {
526 seq_printf(s
, "%-32s 0x%llx\n",
527 name
[index
], evtlog
[index
].telem_evtlog
);
533 static int telem_ioss_state_open(struct inode
*inode
, struct file
*file
)
535 return single_open(file
, telem_ioss_states_show
, inode
->i_private
);
538 static const struct file_operations telem_ioss_ops
= {
539 .open
= telem_ioss_state_open
,
542 .release
= single_release
,
545 static int telem_soc_states_show(struct seq_file
*s
, void *unused
)
547 u32 d3_sts
[TELEM_IOSS_DX_D0IX_EVTS
], d0ix_sts
[TELEM_IOSS_DX_D0IX_EVTS
];
548 u32 pg_sts
[TELEM_IOSS_PG_EVTS
], pss_idle
[TELEM_PSS_IDLE_EVTS
];
549 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
550 u32 s0ix_total_ctr
= 0, s0ix_shlw_ctr
= 0, s0ix_deep_ctr
= 0;
551 u64 s0ix_total_res
= 0, s0ix_shlw_res
= 0, s0ix_deep_res
= 0;
552 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
553 struct pci_dev
*dev
= NULL
;
558 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
559 TELEM_MAX_OS_ALLOCATED_EVENTS
);
563 for (index
= 0; index
< ret
; index
++) {
564 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d3_id
,
565 conf
->ioss_d0ix_evts
,
566 d3_sts
, evtlog
[index
].telem_evtlog
,
567 conf
->ioss_d0ix_data
,
570 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_pg_id
, conf
->ioss_pg_evts
,
571 pg_sts
, evtlog
[index
].telem_evtlog
,
572 conf
->ioss_pg_data
, TELEM_MASK_BIT
);
574 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d0ix_id
,
575 conf
->ioss_d0ix_evts
,
576 d0ix_sts
, evtlog
[index
].telem_evtlog
,
577 conf
->ioss_d0ix_data
,
580 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_occ_id
,
583 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
586 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
589 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_res_id
,
592 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
595 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
599 seq_puts(s
, "\n---------------------------------------------------\n");
600 seq_puts(s
, "S0IX Type\t\t\t Occurrence\t\t Residency(us)\n");
601 seq_puts(s
, "---------------------------------------------------\n");
603 seq_printf(s
, "S0IX Shallow\t\t\t %10u\t %10llu\n",
605 conf
->suspend_stats
.shlw_ctr
-
606 conf
->suspend_stats
.shlw_swake_ctr
,
607 (u64
)((s0ix_shlw_res
-
608 conf
->suspend_stats
.shlw_res
-
609 conf
->suspend_stats
.shlw_swake_res
)*10/192));
611 seq_printf(s
, "S0IX Deep\t\t\t %10u\t %10llu\n",
613 conf
->suspend_stats
.deep_ctr
-
614 conf
->suspend_stats
.deep_swake_ctr
,
615 (u64
)((s0ix_deep_res
-
616 conf
->suspend_stats
.deep_res
-
617 conf
->suspend_stats
.deep_swake_res
)*10/192));
619 seq_printf(s
, "Suspend(With S0ixShallow)\t %10u\t %10llu\n",
620 conf
->suspend_stats
.shlw_ctr
,
621 (u64
)(conf
->suspend_stats
.shlw_res
*10)/192);
623 seq_printf(s
, "Suspend(With S0ixDeep)\t\t %10u\t %10llu\n",
624 conf
->suspend_stats
.deep_ctr
,
625 (u64
)(conf
->suspend_stats
.deep_res
*10)/192);
627 seq_printf(s
, "Suspend(With Shallow-Wakes)\t %10u\t %10llu\n",
628 conf
->suspend_stats
.shlw_swake_ctr
+
629 conf
->suspend_stats
.deep_swake_ctr
,
630 (u64
)((conf
->suspend_stats
.shlw_swake_res
+
631 conf
->suspend_stats
.deep_swake_res
)*10/192));
633 seq_printf(s
, "S0IX+Suspend Total\t\t %10u\t %10llu\n", s0ix_total_ctr
,
634 (u64
)(s0ix_total_res
*10/192));
635 seq_puts(s
, "\n-------------------------------------------------\n");
636 seq_puts(s
, "\t\tDEVICE STATES\n");
637 seq_puts(s
, "-------------------------------------------------\n");
639 for_each_pci_dev(dev
) {
640 pci_read_config_word(dev
, dev
->pm_cap
+ PCI_PM_CTRL
, &pmcsr
);
641 d3_state
= ((pmcsr
& PCI_PM_CTRL_STATE_MASK
) ==
642 (__force
int)PCI_D3hot
) ? 1 : 0;
644 seq_printf(s
, "pci %04x %04X %s %20.20s: ",
645 dev
->vendor
, dev
->device
, dev_name(&dev
->dev
),
646 dev_driver_string(&dev
->dev
));
647 seq_printf(s
, " d3:%x\n", d3_state
);
650 seq_puts(s
, "\n--------------------------------------\n");
651 seq_puts(s
, "D3/D0i3 Status\n");
652 seq_puts(s
, "--------------------------------------\n");
653 seq_puts(s
, "Block\t\t D3\t D0i3\n");
654 for (index
= 0; index
< conf
->ioss_d0ix_evts
; index
++) {
655 seq_printf(s
, "%-10s\t %u\t %u\n",
656 conf
->ioss_d0ix_data
[index
].name
,
657 d3_sts
[index
], d0ix_sts
[index
]);
660 seq_puts(s
, "\n--------------------------------------\n");
661 seq_puts(s
, "South Complex PowerGate Status\n");
662 seq_puts(s
, "--------------------------------------\n");
663 seq_puts(s
, "Device\t\t PG\n");
664 for (index
= 0; index
< conf
->ioss_pg_evts
; index
++) {
665 seq_printf(s
, "%-10s\t %u\n",
666 conf
->ioss_pg_data
[index
].name
,
670 evtlog
->telem_evtid
= conf
->pss_idle_id
;
671 ret
= telemetry_read_events(TELEM_PSS
, evtlog
, 1);
675 seq_puts(s
, "\n-----------------------------------------\n");
676 seq_puts(s
, "North Idle Status\n");
677 seq_puts(s
, "-----------------------------------------\n");
678 for (idx
= 0; idx
< conf
->pss_idle_evts
- 1; idx
++) {
679 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
680 conf
->pss_idle_data
[idx
].bit_pos
) &
684 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
685 conf
->pss_idle_data
[idx
].bit_pos
) &
686 TELEM_APL_MASK_PCS_STATE
;
688 for (index
= 0; index
< conf
->pss_idle_evts
; index
++) {
689 seq_printf(s
, "%-30s %u\n",
690 conf
->pss_idle_data
[index
].name
,
694 seq_puts(s
, "\nPCS_STATUS Code\n");
695 seq_puts(s
, "0:C0 1:C1 2:C1_DN_WT_DEV 3:C2 4:C2_WT_DE_MEM_UP\n");
696 seq_puts(s
, "5:C2_WT_DE_MEM_DOWN 6:C2_UP_WT_DEV 7:C2_DN 8:C2_VOA\n");
697 seq_puts(s
, "9:C2_VOA_UP 10:S0IX_PRE 11:S0IX\n");
702 static int telem_soc_state_open(struct inode
*inode
, struct file
*file
)
704 return single_open(file
, telem_soc_states_show
, inode
->i_private
);
707 static const struct file_operations telem_socstate_ops
= {
708 .open
= telem_soc_state_open
,
711 .release
= single_release
,
714 static int telem_pss_trc_verb_show(struct seq_file
*s
, void *unused
)
719 err
= telemetry_get_trace_verbosity(TELEM_PSS
, &verbosity
);
721 pr_err("Get PSS Trace Verbosity Failed with Error %d\n", err
);
725 seq_printf(s
, "PSS Trace Verbosity %u\n", verbosity
);
729 static ssize_t
telem_pss_trc_verb_write(struct file
*file
,
730 const char __user
*userbuf
,
731 size_t count
, loff_t
*ppos
)
736 if (kstrtou32_from_user(userbuf
, count
, 0, &verbosity
))
739 err
= telemetry_set_trace_verbosity(TELEM_PSS
, verbosity
);
741 pr_err("Changing PSS Trace Verbosity Failed. Error %d\n", err
);
748 static int telem_pss_trc_verb_open(struct inode
*inode
, struct file
*file
)
750 return single_open(file
, telem_pss_trc_verb_show
, inode
->i_private
);
753 static const struct file_operations telem_pss_trc_verb_ops
= {
754 .open
= telem_pss_trc_verb_open
,
756 .write
= telem_pss_trc_verb_write
,
758 .release
= single_release
,
762 static int telem_ioss_trc_verb_show(struct seq_file
*s
, void *unused
)
767 err
= telemetry_get_trace_verbosity(TELEM_IOSS
, &verbosity
);
769 pr_err("Get IOSS Trace Verbosity Failed with Error %d\n", err
);
773 seq_printf(s
, "IOSS Trace Verbosity %u\n", verbosity
);
777 static ssize_t
telem_ioss_trc_verb_write(struct file
*file
,
778 const char __user
*userbuf
,
779 size_t count
, loff_t
*ppos
)
784 if (kstrtou32_from_user(userbuf
, count
, 0, &verbosity
))
787 err
= telemetry_set_trace_verbosity(TELEM_IOSS
, verbosity
);
789 pr_err("Changing IOSS Trace Verbosity Failed. Error %d\n", err
);
796 static int telem_ioss_trc_verb_open(struct inode
*inode
, struct file
*file
)
798 return single_open(file
, telem_ioss_trc_verb_show
, inode
->i_private
);
801 static const struct file_operations telem_ioss_trc_verb_ops
= {
802 .open
= telem_ioss_trc_verb_open
,
804 .write
= telem_ioss_trc_verb_write
,
806 .release
= single_release
,
809 #ifdef CONFIG_PM_SLEEP
810 static int pm_suspend_prep_cb(void)
812 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
813 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
816 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
817 TELEM_MAX_OS_ALLOCATED_EVENTS
);
823 for (index
= 0; index
< ret
; index
++) {
825 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
826 suspend_shlw_ctr_temp
);
828 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
829 suspend_deep_ctr_temp
);
831 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
832 suspend_shlw_res_temp
);
834 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
835 suspend_deep_res_temp
);
842 static int pm_suspend_exit_cb(void)
844 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
845 static u32 suspend_shlw_ctr_exit
, suspend_deep_ctr_exit
;
846 static u64 suspend_shlw_res_exit
, suspend_deep_res_exit
;
847 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
850 if (!suspend_prep_ok
)
853 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
854 TELEM_MAX_OS_ALLOCATED_EVENTS
);
858 for (index
= 0; index
< ret
; index
++) {
859 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
860 suspend_shlw_ctr_exit
);
862 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
863 suspend_deep_ctr_exit
);
865 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
866 suspend_shlw_res_exit
);
868 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
869 suspend_deep_res_exit
);
872 if ((suspend_shlw_ctr_exit
< suspend_shlw_ctr_temp
) ||
873 (suspend_deep_ctr_exit
< suspend_deep_ctr_temp
) ||
874 (suspend_shlw_res_exit
< suspend_shlw_res_temp
) ||
875 (suspend_deep_res_exit
< suspend_deep_res_temp
)) {
876 pr_err("Wrong s0ix counters detected\n");
880 suspend_shlw_ctr_exit
-= suspend_shlw_ctr_temp
;
881 suspend_deep_ctr_exit
-= suspend_deep_ctr_temp
;
882 suspend_shlw_res_exit
-= suspend_shlw_res_temp
;
883 suspend_deep_res_exit
-= suspend_deep_res_temp
;
885 if (suspend_shlw_ctr_exit
== 1) {
886 conf
->suspend_stats
.shlw_ctr
+=
887 suspend_shlw_ctr_exit
;
889 conf
->suspend_stats
.shlw_res
+=
890 suspend_shlw_res_exit
;
892 /* Shallow Wakes Case */
893 else if (suspend_shlw_ctr_exit
> 1) {
894 conf
->suspend_stats
.shlw_swake_ctr
+=
895 suspend_shlw_ctr_exit
;
897 conf
->suspend_stats
.shlw_swake_res
+=
898 suspend_shlw_res_exit
;
901 if (suspend_deep_ctr_exit
== 1) {
902 conf
->suspend_stats
.deep_ctr
+=
903 suspend_deep_ctr_exit
;
905 conf
->suspend_stats
.deep_res
+=
906 suspend_deep_res_exit
;
909 /* Shallow Wakes Case */
910 else if (suspend_deep_ctr_exit
> 1) {
911 conf
->suspend_stats
.deep_swake_ctr
+=
912 suspend_deep_ctr_exit
;
914 conf
->suspend_stats
.deep_swake_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
,
939 #endif /* CONFIG_PM_SLEEP */
941 static int __init
telemetry_debugfs_init(void)
943 const struct x86_cpu_id
*id
;
947 /* Only APL supported for now */
948 id
= x86_match_cpu(telemetry_debugfs_cpu_ids
);
952 debugfs_conf
= (struct telemetry_debugfs_conf
*)id
->driver_data
;
954 err
= telemetry_pltconfig_valid();
958 err
= telemetry_debugfs_check_evts();
963 #ifdef CONFIG_PM_SLEEP
964 register_pm_notifier(&pm_notifier
);
965 #endif /* CONFIG_PM_SLEEP */
967 debugfs_conf
->telemetry_dbg_dir
= debugfs_create_dir("telemetry", NULL
);
968 if (!debugfs_conf
->telemetry_dbg_dir
)
971 f
= debugfs_create_file("pss_info", S_IFREG
| S_IRUGO
,
972 debugfs_conf
->telemetry_dbg_dir
, NULL
,
975 pr_err("pss_sample_info debugfs register failed\n");
979 f
= debugfs_create_file("ioss_info", S_IFREG
| S_IRUGO
,
980 debugfs_conf
->telemetry_dbg_dir
, NULL
,
983 pr_err("ioss_sample_info debugfs register failed\n");
987 f
= debugfs_create_file("soc_states", S_IFREG
| S_IRUGO
,
988 debugfs_conf
->telemetry_dbg_dir
,
989 NULL
, &telem_socstate_ops
);
991 pr_err("ioss_sample_info debugfs register failed\n");
995 f
= debugfs_create_file("pss_trace_verbosity", S_IFREG
| S_IRUGO
,
996 debugfs_conf
->telemetry_dbg_dir
, NULL
,
997 &telem_pss_trc_verb_ops
);
999 pr_err("pss_trace_verbosity debugfs register failed\n");
1003 f
= debugfs_create_file("ioss_trace_verbosity", S_IFREG
| S_IRUGO
,
1004 debugfs_conf
->telemetry_dbg_dir
, NULL
,
1005 &telem_ioss_trc_verb_ops
);
1007 pr_err("ioss_trace_verbosity debugfs register failed\n");
1014 debugfs_remove_recursive(debugfs_conf
->telemetry_dbg_dir
);
1015 debugfs_conf
->telemetry_dbg_dir
= NULL
;
1020 static void __exit
telemetry_debugfs_exit(void)
1022 debugfs_remove_recursive(debugfs_conf
->telemetry_dbg_dir
);
1023 debugfs_conf
->telemetry_dbg_dir
= NULL
;
1026 late_initcall(telemetry_debugfs_init
);
1027 module_exit(telemetry_debugfs_exit
);
1029 MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
1030 MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface");
1031 MODULE_VERSION(DRIVER_VERSION
);
1032 MODULE_LICENSE("GPL");