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>
27 #include <linux/module.h>
28 #include <linux/pci.h>
29 #include <linux/seq_file.h>
30 #include <linux/suspend.h>
32 #include <asm/cpu_device_id.h>
33 #include <asm/intel-family.h>
34 #include <asm/intel_pmc_ipc.h>
35 #include <asm/intel_punit_ipc.h>
36 #include <asm/intel_telemetry.h>
38 #define DRIVER_NAME "telemetry_soc_debugfs"
39 #define DRIVER_VERSION "1.0.0"
41 /* ApolloLake SoC Event-IDs */
42 #define TELEM_APL_PSS_PSTATES_ID 0x2802
43 #define TELEM_APL_PSS_IDLE_ID 0x2806
44 #define TELEM_APL_PCS_IDLE_BLOCKED_ID 0x2C00
45 #define TELEM_APL_PCS_S0IX_BLOCKED_ID 0x2C01
46 #define TELEM_APL_PSS_WAKEUP_ID 0x2C02
47 #define TELEM_APL_PSS_LTR_BLOCKING_ID 0x2C03
49 #define TELEM_APL_S0IX_TOTAL_OCC_ID 0x4000
50 #define TELEM_APL_S0IX_SHLW_OCC_ID 0x4001
51 #define TELEM_APL_S0IX_DEEP_OCC_ID 0x4002
52 #define TELEM_APL_S0IX_TOTAL_RES_ID 0x4800
53 #define TELEM_APL_S0IX_SHLW_RES_ID 0x4801
54 #define TELEM_APL_S0IX_DEEP_RES_ID 0x4802
55 #define TELEM_APL_D0IX_ID 0x581A
56 #define TELEM_APL_D3_ID 0x5819
57 #define TELEM_APL_PG_ID 0x5818
59 #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
60 #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
61 #define TELEM_SSRAM_READ_TIMEOUT 10
63 #define TELEM_MASK_BIT 1
64 #define TELEM_MASK_BYTE 0xFF
65 #define BYTES_PER_LONG 8
66 #define TELEM_APL_MASK_PCS_STATE 0xF
68 /* Max events in bitmap to check for */
69 #define TELEM_PSS_IDLE_EVTS 25
70 #define TELEM_PSS_IDLE_BLOCKED_EVTS 20
71 #define TELEM_PSS_S0IX_BLOCKED_EVTS 20
72 #define TELEM_PSS_S0IX_WAKEUP_EVTS 20
73 #define TELEM_PSS_LTR_BLOCKING_EVTS 20
74 #define TELEM_IOSS_DX_D0IX_EVTS 25
75 #define TELEM_IOSS_PG_EVTS 30
77 #define TELEM_DEBUGFS_CPU(model, data) \
78 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&data}
80 #define TELEM_CHECK_AND_PARSE_EVTS(EVTID, EVTNUM, BUF, EVTLOG, EVTDAT, MASK) { \
81 if (evtlog[index].telem_evtid == (EVTID)) { \
82 for (idx = 0; idx < (EVTNUM); idx++) \
83 (BUF)[idx] = ((EVTLOG) >> (EVTDAT)[idx].bit_pos) & \
89 #define TELEM_CHECK_AND_PARSE_CTRS(EVTID, CTR) { \
90 if (evtlog[index].telem_evtid == (EVTID)) { \
91 (CTR) = evtlog[index].telem_evtlog; \
96 static u8 suspend_prep_ok
;
97 static u32 suspend_shlw_ctr_temp
, suspend_deep_ctr_temp
;
98 static u64 suspend_shlw_res_temp
, suspend_deep_res_temp
;
100 struct telemetry_susp_stats
{
111 /* Bitmap definitions for default counters in APL */
112 struct telem_pss_idle_stateinfo
{
117 static struct telem_pss_idle_stateinfo telem_apl_pss_idle_data
[] = {
126 {"IA_MODULE0_C7", 32},
127 {"IA_MODULE1_C7", 33},
129 {"IUNIT_PROCESSING_IDLE", 41},
130 {"FAR_MEM_IDLE", 43},
131 {"DISPLAY_IDLE", 44},
132 {"IUNIT_INPUT_SYSTEM_IDLE", 45},
136 struct telem_pcs_blkd_info
{
141 static struct telem_pcs_blkd_info telem_apl_pcs_idle_blkd_data
[] = {
144 {"MODULE_ACTIONS_PENDING", 16},
146 {"DISPLAY_WAKE", 32},
151 static struct telem_pcs_blkd_info telem_apl_pcs_s0ix_blkd_data
[] = {
154 {"WAKE_DEADLINE_PENDING", 16},
162 struct telem_pss_ltr_info
{
167 static struct telem_pss_ltr_info telem_apl_pss_ltr_data
[] = {
171 {"DFX_FORCE_LTR", 24},
177 struct telem_pss_wakeup_info
{
182 static struct telem_pss_wakeup_info telem_apl_pss_wakeup
[] = {
185 {"VOLTAGE_REG_INT", 16},
186 {"DROWSY_TIMER (HOTPLUG)", 24},
192 struct telem_ioss_d0ix_stateinfo
{
197 static struct telem_ioss_d0ix_stateinfo telem_apl_ioss_d0ix_data
[] = {
219 struct telem_ioss_pg_info
{
224 static struct telem_ioss_pg_info telem_apl_ioss_pg_data
[] = {
254 struct telemetry_debugfs_conf
{
255 struct telemetry_susp_stats suspend_stats
;
256 struct dentry
*telemetry_dbg_dir
;
259 struct telem_ioss_d0ix_stateinfo
*ioss_d0ix_data
;
260 struct telem_pss_idle_stateinfo
*pss_idle_data
;
261 struct telem_pcs_blkd_info
*pcs_idle_blkd_data
;
262 struct telem_pcs_blkd_info
*pcs_s0ix_blkd_data
;
263 struct telem_pss_wakeup_info
*pss_wakeup
;
264 struct telem_pss_ltr_info
*pss_ltr_data
;
265 struct telem_ioss_pg_info
*ioss_pg_data
;
266 u8 pcs_idle_blkd_evts
;
267 u8 pcs_s0ix_blkd_evts
;
275 u16 pss_ltr_blocking_id
;
276 u16 pcs_idle_blkd_id
;
277 u16 pcs_s0ix_blkd_id
;
278 u16 s0ix_total_occ_id
;
279 u16 s0ix_shlw_occ_id
;
280 u16 s0ix_deep_occ_id
;
281 u16 s0ix_total_res_id
;
282 u16 s0ix_shlw_res_id
;
283 u16 s0ix_deep_res_id
;
292 static struct telemetry_debugfs_conf
*debugfs_conf
;
294 static struct telemetry_debugfs_conf telem_apl_debugfs_conf
= {
295 .pss_idle_data
= telem_apl_pss_idle_data
,
296 .pcs_idle_blkd_data
= telem_apl_pcs_idle_blkd_data
,
297 .pcs_s0ix_blkd_data
= telem_apl_pcs_s0ix_blkd_data
,
298 .pss_ltr_data
= telem_apl_pss_ltr_data
,
299 .pss_wakeup
= telem_apl_pss_wakeup
,
300 .ioss_d0ix_data
= telem_apl_ioss_d0ix_data
,
301 .ioss_pg_data
= telem_apl_ioss_pg_data
,
303 .pss_idle_evts
= ARRAY_SIZE(telem_apl_pss_idle_data
),
304 .pcs_idle_blkd_evts
= ARRAY_SIZE(telem_apl_pcs_idle_blkd_data
),
305 .pcs_s0ix_blkd_evts
= ARRAY_SIZE(telem_apl_pcs_s0ix_blkd_data
),
306 .pss_ltr_evts
= ARRAY_SIZE(telem_apl_pss_ltr_data
),
307 .pss_wakeup_evts
= ARRAY_SIZE(telem_apl_pss_wakeup
),
308 .ioss_d0ix_evts
= ARRAY_SIZE(telem_apl_ioss_d0ix_data
),
309 .ioss_pg_evts
= ARRAY_SIZE(telem_apl_ioss_pg_data
),
311 .pstates_id
= TELEM_APL_PSS_PSTATES_ID
,
312 .pss_idle_id
= TELEM_APL_PSS_IDLE_ID
,
313 .pcs_idle_blkd_id
= TELEM_APL_PCS_IDLE_BLOCKED_ID
,
314 .pcs_s0ix_blkd_id
= TELEM_APL_PCS_S0IX_BLOCKED_ID
,
315 .pss_wakeup_id
= TELEM_APL_PSS_WAKEUP_ID
,
316 .pss_ltr_blocking_id
= TELEM_APL_PSS_LTR_BLOCKING_ID
,
317 .s0ix_total_occ_id
= TELEM_APL_S0IX_TOTAL_OCC_ID
,
318 .s0ix_shlw_occ_id
= TELEM_APL_S0IX_SHLW_OCC_ID
,
319 .s0ix_deep_occ_id
= TELEM_APL_S0IX_DEEP_OCC_ID
,
320 .s0ix_total_res_id
= TELEM_APL_S0IX_TOTAL_RES_ID
,
321 .s0ix_shlw_res_id
= TELEM_APL_S0IX_SHLW_RES_ID
,
322 .s0ix_deep_res_id
= TELEM_APL_S0IX_DEEP_RES_ID
,
323 .ioss_d0ix_id
= TELEM_APL_D0IX_ID
,
324 .ioss_d3_id
= TELEM_APL_D3_ID
,
325 .ioss_pg_id
= TELEM_APL_PG_ID
,
328 static const struct x86_cpu_id telemetry_debugfs_cpu_ids
[] = {
329 TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT
, telem_apl_debugfs_conf
),
330 TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT_PLUS
, telem_apl_debugfs_conf
),
334 MODULE_DEVICE_TABLE(x86cpu
, telemetry_debugfs_cpu_ids
);
336 static int telemetry_debugfs_check_evts(void)
338 if ((debugfs_conf
->pss_idle_evts
> TELEM_PSS_IDLE_EVTS
) ||
339 (debugfs_conf
->pcs_idle_blkd_evts
> TELEM_PSS_IDLE_BLOCKED_EVTS
) ||
340 (debugfs_conf
->pcs_s0ix_blkd_evts
> TELEM_PSS_S0IX_BLOCKED_EVTS
) ||
341 (debugfs_conf
->pss_ltr_evts
> TELEM_PSS_LTR_BLOCKING_EVTS
) ||
342 (debugfs_conf
->pss_wakeup_evts
> TELEM_PSS_S0IX_WAKEUP_EVTS
) ||
343 (debugfs_conf
->ioss_d0ix_evts
> TELEM_IOSS_DX_D0IX_EVTS
) ||
344 (debugfs_conf
->ioss_pg_evts
> TELEM_IOSS_PG_EVTS
))
350 static int telem_pss_states_show(struct seq_file
*s
, void *unused
)
352 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
353 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
354 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
355 u32 pcs_idle_blkd
[TELEM_PSS_IDLE_BLOCKED_EVTS
],
356 pcs_s0ix_blkd
[TELEM_PSS_S0IX_BLOCKED_EVTS
],
357 pss_s0ix_wakeup
[TELEM_PSS_S0IX_WAKEUP_EVTS
],
358 pss_ltr_blkd
[TELEM_PSS_LTR_BLOCKING_EVTS
],
359 pss_idle
[TELEM_PSS_IDLE_EVTS
];
360 int index
, idx
, ret
, err
= 0;
363 ret
= telemetry_read_eventlog(TELEM_PSS
, evtlog
,
364 TELEM_MAX_OS_ALLOCATED_EVENTS
);
368 err
= telemetry_get_evtname(TELEM_PSS
, name
,
369 TELEM_MAX_OS_ALLOCATED_EVENTS
);
373 seq_puts(s
, "\n----------------------------------------------------\n");
374 seq_puts(s
, "\tPSS TELEM EVENTLOG (Residency = field/19.2 us\n");
375 seq_puts(s
, "----------------------------------------------------\n");
376 for (index
= 0; index
< ret
; index
++) {
377 seq_printf(s
, "%-32s %llu\n",
378 name
[index
], evtlog
[index
].telem_evtlog
);
380 /* Fetch PSS IDLE State */
381 if (evtlog
[index
].telem_evtid
== conf
->pss_idle_id
) {
382 pss_idle
[conf
->pss_idle_evts
- 1] =
383 (evtlog
[index
].telem_evtlog
>>
384 conf
->pss_idle_data
[conf
->pss_idle_evts
- 1].bit_pos
) &
385 TELEM_APL_MASK_PCS_STATE
;
389 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_idle_id
,
390 conf
->pss_idle_evts
- 1,
391 pss_idle
, evtlog
[index
].telem_evtlog
,
392 conf
->pss_idle_data
, TELEM_MASK_BIT
);
394 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_idle_blkd_id
,
395 conf
->pcs_idle_blkd_evts
,
397 evtlog
[index
].telem_evtlog
,
398 conf
->pcs_idle_blkd_data
,
401 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_s0ix_blkd_id
,
402 conf
->pcs_s0ix_blkd_evts
,
404 evtlog
[index
].telem_evtlog
,
405 conf
->pcs_s0ix_blkd_data
,
409 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_wakeup_id
,
410 conf
->pss_wakeup_evts
,
412 evtlog
[index
].telem_evtlog
,
413 conf
->pss_wakeup
, TELEM_MASK_BYTE
);
415 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_ltr_blocking_id
,
416 conf
->pss_ltr_evts
, pss_ltr_blkd
,
417 evtlog
[index
].telem_evtlog
,
418 conf
->pss_ltr_data
, TELEM_MASK_BYTE
);
420 if (evtlog
[index
].telem_evtid
== debugfs_conf
->pstates_id
)
421 pstates
= evtlog
[index
].telem_evtlog
;
424 seq_puts(s
, "\n--------------------------------------\n");
425 seq_puts(s
, "PStates\n");
426 seq_puts(s
, "--------------------------------------\n");
427 seq_puts(s
, "Domain\t\t\t\tFreq(Mhz)\n");
428 seq_printf(s
, " IA\t\t\t\t %llu\n GT\t\t\t\t %llu\n",
429 (pstates
& TELEM_MASK_BYTE
)*100,
430 ((pstates
>> 8) & TELEM_MASK_BYTE
)*50/3);
432 seq_printf(s
, " IUNIT\t\t\t\t %llu\n SA\t\t\t\t %llu\n",
433 ((pstates
>> 16) & TELEM_MASK_BYTE
)*25,
434 ((pstates
>> 24) & TELEM_MASK_BYTE
)*50/3);
436 seq_puts(s
, "\n--------------------------------------\n");
437 seq_puts(s
, "PSS IDLE Status\n");
438 seq_puts(s
, "--------------------------------------\n");
439 seq_puts(s
, "Device\t\t\t\t\tIDLE\n");
440 for (index
= 0; index
< debugfs_conf
->pss_idle_evts
; index
++) {
441 seq_printf(s
, "%-32s\t%u\n",
442 debugfs_conf
->pss_idle_data
[index
].name
,
446 seq_puts(s
, "\n--------------------------------------\n");
447 seq_puts(s
, "PSS Idle blkd Status (~1ms saturating bucket)\n");
448 seq_puts(s
, "--------------------------------------\n");
449 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
450 for (index
= 0; index
< debugfs_conf
->pcs_idle_blkd_evts
; index
++) {
451 seq_printf(s
, "%-32s\t%u\n",
452 debugfs_conf
->pcs_idle_blkd_data
[index
].name
,
453 pcs_idle_blkd
[index
]);
456 seq_puts(s
, "\n--------------------------------------\n");
457 seq_puts(s
, "PSS S0ix blkd Status (~1ms saturating bucket)\n");
458 seq_puts(s
, "--------------------------------------\n");
459 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
460 for (index
= 0; index
< debugfs_conf
->pcs_s0ix_blkd_evts
; index
++) {
461 seq_printf(s
, "%-32s\t%u\n",
462 debugfs_conf
->pcs_s0ix_blkd_data
[index
].name
,
463 pcs_s0ix_blkd
[index
]);
466 seq_puts(s
, "\n--------------------------------------\n");
467 seq_puts(s
, "LTR Blocking Status (~1ms saturating bucket)\n");
468 seq_puts(s
, "--------------------------------------\n");
469 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
470 for (index
= 0; index
< debugfs_conf
->pss_ltr_evts
; index
++) {
471 seq_printf(s
, "%-32s\t%u\n",
472 debugfs_conf
->pss_ltr_data
[index
].name
,
473 pss_s0ix_wakeup
[index
]);
476 seq_puts(s
, "\n--------------------------------------\n");
477 seq_puts(s
, "Wakes Status (~1ms saturating bucket)\n");
478 seq_puts(s
, "--------------------------------------\n");
479 seq_puts(s
, "Wakes\t\t\t\t\tCount\n");
480 for (index
= 0; index
< debugfs_conf
->pss_wakeup_evts
; index
++) {
481 seq_printf(s
, "%-32s\t%u\n",
482 debugfs_conf
->pss_wakeup
[index
].name
,
483 pss_ltr_blkd
[index
]);
489 static int telem_pss_state_open(struct inode
*inode
, struct file
*file
)
491 return single_open(file
, telem_pss_states_show
, inode
->i_private
);
494 static const struct file_operations telem_pss_ops
= {
495 .open
= telem_pss_state_open
,
498 .release
= single_release
,
502 static int telem_ioss_states_show(struct seq_file
*s
, void *unused
)
504 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
505 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
508 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
509 TELEM_MAX_OS_ALLOCATED_EVENTS
);
513 err
= telemetry_get_evtname(TELEM_IOSS
, name
,
514 TELEM_MAX_OS_ALLOCATED_EVENTS
);
518 seq_puts(s
, "--------------------------------------\n");
519 seq_puts(s
, "\tI0SS TELEMETRY EVENTLOG\n");
520 seq_puts(s
, "--------------------------------------\n");
521 for (index
= 0; index
< ret
; index
++) {
522 seq_printf(s
, "%-32s 0x%llx\n",
523 name
[index
], evtlog
[index
].telem_evtlog
);
529 static int telem_ioss_state_open(struct inode
*inode
, struct file
*file
)
531 return single_open(file
, telem_ioss_states_show
, inode
->i_private
);
534 static const struct file_operations telem_ioss_ops
= {
535 .open
= telem_ioss_state_open
,
538 .release
= single_release
,
541 static int telem_soc_states_show(struct seq_file
*s
, void *unused
)
543 u32 d3_sts
[TELEM_IOSS_DX_D0IX_EVTS
], d0ix_sts
[TELEM_IOSS_DX_D0IX_EVTS
];
544 u32 pg_sts
[TELEM_IOSS_PG_EVTS
], pss_idle
[TELEM_PSS_IDLE_EVTS
];
545 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
546 u32 s0ix_total_ctr
= 0, s0ix_shlw_ctr
= 0, s0ix_deep_ctr
= 0;
547 u64 s0ix_total_res
= 0, s0ix_shlw_res
= 0, s0ix_deep_res
= 0;
548 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
549 struct pci_dev
*dev
= NULL
;
554 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
555 TELEM_MAX_OS_ALLOCATED_EVENTS
);
559 for (index
= 0; index
< ret
; index
++) {
560 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d3_id
,
561 conf
->ioss_d0ix_evts
,
562 d3_sts
, evtlog
[index
].telem_evtlog
,
563 conf
->ioss_d0ix_data
,
566 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_pg_id
, conf
->ioss_pg_evts
,
567 pg_sts
, evtlog
[index
].telem_evtlog
,
568 conf
->ioss_pg_data
, TELEM_MASK_BIT
);
570 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d0ix_id
,
571 conf
->ioss_d0ix_evts
,
572 d0ix_sts
, evtlog
[index
].telem_evtlog
,
573 conf
->ioss_d0ix_data
,
576 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_occ_id
,
579 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
582 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
585 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_res_id
,
588 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
591 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
595 seq_puts(s
, "\n---------------------------------------------------\n");
596 seq_puts(s
, "S0IX Type\t\t\t Occurrence\t\t Residency(us)\n");
597 seq_puts(s
, "---------------------------------------------------\n");
599 seq_printf(s
, "S0IX Shallow\t\t\t %10u\t %10llu\n",
601 conf
->suspend_stats
.shlw_ctr
-
602 conf
->suspend_stats
.shlw_swake_ctr
,
603 (u64
)((s0ix_shlw_res
-
604 conf
->suspend_stats
.shlw_res
-
605 conf
->suspend_stats
.shlw_swake_res
)*10/192));
607 seq_printf(s
, "S0IX Deep\t\t\t %10u\t %10llu\n",
609 conf
->suspend_stats
.deep_ctr
-
610 conf
->suspend_stats
.deep_swake_ctr
,
611 (u64
)((s0ix_deep_res
-
612 conf
->suspend_stats
.deep_res
-
613 conf
->suspend_stats
.deep_swake_res
)*10/192));
615 seq_printf(s
, "Suspend(With S0ixShallow)\t %10u\t %10llu\n",
616 conf
->suspend_stats
.shlw_ctr
,
617 (u64
)(conf
->suspend_stats
.shlw_res
*10)/192);
619 seq_printf(s
, "Suspend(With S0ixDeep)\t\t %10u\t %10llu\n",
620 conf
->suspend_stats
.deep_ctr
,
621 (u64
)(conf
->suspend_stats
.deep_res
*10)/192);
623 seq_printf(s
, "Suspend(With Shallow-Wakes)\t %10u\t %10llu\n",
624 conf
->suspend_stats
.shlw_swake_ctr
+
625 conf
->suspend_stats
.deep_swake_ctr
,
626 (u64
)((conf
->suspend_stats
.shlw_swake_res
+
627 conf
->suspend_stats
.deep_swake_res
)*10/192));
629 seq_printf(s
, "S0IX+Suspend Total\t\t %10u\t %10llu\n", s0ix_total_ctr
,
630 (u64
)(s0ix_total_res
*10/192));
631 seq_puts(s
, "\n-------------------------------------------------\n");
632 seq_puts(s
, "\t\tDEVICE STATES\n");
633 seq_puts(s
, "-------------------------------------------------\n");
635 for_each_pci_dev(dev
) {
636 pci_read_config_word(dev
, dev
->pm_cap
+ PCI_PM_CTRL
, &pmcsr
);
637 d3_state
= ((pmcsr
& PCI_PM_CTRL_STATE_MASK
) ==
638 (__force
int)PCI_D3hot
) ? 1 : 0;
640 seq_printf(s
, "pci %04x %04X %s %20.20s: ",
641 dev
->vendor
, dev
->device
, dev_name(&dev
->dev
),
642 dev_driver_string(&dev
->dev
));
643 seq_printf(s
, " d3:%x\n", d3_state
);
646 seq_puts(s
, "\n--------------------------------------\n");
647 seq_puts(s
, "D3/D0i3 Status\n");
648 seq_puts(s
, "--------------------------------------\n");
649 seq_puts(s
, "Block\t\t D3\t D0i3\n");
650 for (index
= 0; index
< conf
->ioss_d0ix_evts
; index
++) {
651 seq_printf(s
, "%-10s\t %u\t %u\n",
652 conf
->ioss_d0ix_data
[index
].name
,
653 d3_sts
[index
], d0ix_sts
[index
]);
656 seq_puts(s
, "\n--------------------------------------\n");
657 seq_puts(s
, "South Complex PowerGate Status\n");
658 seq_puts(s
, "--------------------------------------\n");
659 seq_puts(s
, "Device\t\t PG\n");
660 for (index
= 0; index
< conf
->ioss_pg_evts
; index
++) {
661 seq_printf(s
, "%-10s\t %u\n",
662 conf
->ioss_pg_data
[index
].name
,
666 evtlog
->telem_evtid
= conf
->pss_idle_id
;
667 ret
= telemetry_read_events(TELEM_PSS
, evtlog
, 1);
671 seq_puts(s
, "\n-----------------------------------------\n");
672 seq_puts(s
, "North Idle Status\n");
673 seq_puts(s
, "-----------------------------------------\n");
674 for (idx
= 0; idx
< conf
->pss_idle_evts
- 1; idx
++) {
675 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
676 conf
->pss_idle_data
[idx
].bit_pos
) &
680 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
681 conf
->pss_idle_data
[idx
].bit_pos
) &
682 TELEM_APL_MASK_PCS_STATE
;
684 for (index
= 0; index
< conf
->pss_idle_evts
; index
++) {
685 seq_printf(s
, "%-30s %u\n",
686 conf
->pss_idle_data
[index
].name
,
690 seq_puts(s
, "\nPCS_STATUS Code\n");
691 seq_puts(s
, "0:C0 1:C1 2:C1_DN_WT_DEV 3:C2 4:C2_WT_DE_MEM_UP\n");
692 seq_puts(s
, "5:C2_WT_DE_MEM_DOWN 6:C2_UP_WT_DEV 7:C2_DN 8:C2_VOA\n");
693 seq_puts(s
, "9:C2_VOA_UP 10:S0IX_PRE 11:S0IX\n");
698 static int telem_soc_state_open(struct inode
*inode
, struct file
*file
)
700 return single_open(file
, telem_soc_states_show
, inode
->i_private
);
703 static const struct file_operations telem_socstate_ops
= {
704 .open
= telem_soc_state_open
,
707 .release
= single_release
,
710 static int telem_s0ix_res_get(void *data
, u64
*val
)
715 ret
= intel_pmc_s0ix_counter_read(&s0ix_total_res
);
717 pr_err("Failed to read S0ix residency");
721 *val
= s0ix_total_res
;
726 DEFINE_DEBUGFS_ATTRIBUTE(telem_s0ix_fops
, telem_s0ix_res_get
, NULL
, "%llu\n");
728 static int telem_pss_trc_verb_show(struct seq_file
*s
, void *unused
)
733 err
= telemetry_get_trace_verbosity(TELEM_PSS
, &verbosity
);
735 pr_err("Get PSS Trace Verbosity Failed with Error %d\n", err
);
739 seq_printf(s
, "PSS Trace Verbosity %u\n", verbosity
);
743 static ssize_t
telem_pss_trc_verb_write(struct file
*file
,
744 const char __user
*userbuf
,
745 size_t count
, loff_t
*ppos
)
750 if (kstrtou32_from_user(userbuf
, count
, 0, &verbosity
))
753 err
= telemetry_set_trace_verbosity(TELEM_PSS
, verbosity
);
755 pr_err("Changing PSS Trace Verbosity Failed. Error %d\n", err
);
762 static int telem_pss_trc_verb_open(struct inode
*inode
, struct file
*file
)
764 return single_open(file
, telem_pss_trc_verb_show
, inode
->i_private
);
767 static const struct file_operations telem_pss_trc_verb_ops
= {
768 .open
= telem_pss_trc_verb_open
,
770 .write
= telem_pss_trc_verb_write
,
772 .release
= single_release
,
776 static int telem_ioss_trc_verb_show(struct seq_file
*s
, void *unused
)
781 err
= telemetry_get_trace_verbosity(TELEM_IOSS
, &verbosity
);
783 pr_err("Get IOSS Trace Verbosity Failed with Error %d\n", err
);
787 seq_printf(s
, "IOSS Trace Verbosity %u\n", verbosity
);
791 static ssize_t
telem_ioss_trc_verb_write(struct file
*file
,
792 const char __user
*userbuf
,
793 size_t count
, loff_t
*ppos
)
798 if (kstrtou32_from_user(userbuf
, count
, 0, &verbosity
))
801 err
= telemetry_set_trace_verbosity(TELEM_IOSS
, verbosity
);
803 pr_err("Changing IOSS Trace Verbosity Failed. Error %d\n", err
);
810 static int telem_ioss_trc_verb_open(struct inode
*inode
, struct file
*file
)
812 return single_open(file
, telem_ioss_trc_verb_show
, inode
->i_private
);
815 static const struct file_operations telem_ioss_trc_verb_ops
= {
816 .open
= telem_ioss_trc_verb_open
,
818 .write
= telem_ioss_trc_verb_write
,
820 .release
= single_release
,
823 static int pm_suspend_prep_cb(void)
825 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
826 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
829 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
830 TELEM_MAX_OS_ALLOCATED_EVENTS
);
836 for (index
= 0; index
< ret
; index
++) {
838 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
839 suspend_shlw_ctr_temp
);
841 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
842 suspend_deep_ctr_temp
);
844 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
845 suspend_shlw_res_temp
);
847 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
848 suspend_deep_res_temp
);
855 static int pm_suspend_exit_cb(void)
857 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
858 static u32 suspend_shlw_ctr_exit
, suspend_deep_ctr_exit
;
859 static u64 suspend_shlw_res_exit
, suspend_deep_res_exit
;
860 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
863 if (!suspend_prep_ok
)
866 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
867 TELEM_MAX_OS_ALLOCATED_EVENTS
);
871 for (index
= 0; index
< ret
; index
++) {
872 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
873 suspend_shlw_ctr_exit
);
875 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
876 suspend_deep_ctr_exit
);
878 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
879 suspend_shlw_res_exit
);
881 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
882 suspend_deep_res_exit
);
885 if ((suspend_shlw_ctr_exit
< suspend_shlw_ctr_temp
) ||
886 (suspend_deep_ctr_exit
< suspend_deep_ctr_temp
) ||
887 (suspend_shlw_res_exit
< suspend_shlw_res_temp
) ||
888 (suspend_deep_res_exit
< suspend_deep_res_temp
)) {
889 pr_err("Wrong s0ix counters detected\n");
893 suspend_shlw_ctr_exit
-= suspend_shlw_ctr_temp
;
894 suspend_deep_ctr_exit
-= suspend_deep_ctr_temp
;
895 suspend_shlw_res_exit
-= suspend_shlw_res_temp
;
896 suspend_deep_res_exit
-= suspend_deep_res_temp
;
898 if (suspend_shlw_ctr_exit
== 1) {
899 conf
->suspend_stats
.shlw_ctr
+=
900 suspend_shlw_ctr_exit
;
902 conf
->suspend_stats
.shlw_res
+=
903 suspend_shlw_res_exit
;
905 /* Shallow Wakes Case */
906 else if (suspend_shlw_ctr_exit
> 1) {
907 conf
->suspend_stats
.shlw_swake_ctr
+=
908 suspend_shlw_ctr_exit
;
910 conf
->suspend_stats
.shlw_swake_res
+=
911 suspend_shlw_res_exit
;
914 if (suspend_deep_ctr_exit
== 1) {
915 conf
->suspend_stats
.deep_ctr
+=
916 suspend_deep_ctr_exit
;
918 conf
->suspend_stats
.deep_res
+=
919 suspend_deep_res_exit
;
922 /* Shallow Wakes Case */
923 else if (suspend_deep_ctr_exit
> 1) {
924 conf
->suspend_stats
.deep_swake_ctr
+=
925 suspend_deep_ctr_exit
;
927 conf
->suspend_stats
.deep_swake_res
+=
928 suspend_deep_res_exit
;
936 static int pm_notification(struct notifier_block
*this,
937 unsigned long event
, void *ptr
)
940 case PM_SUSPEND_PREPARE
:
941 return pm_suspend_prep_cb();
942 case PM_POST_SUSPEND
:
943 return pm_suspend_exit_cb();
949 static struct notifier_block pm_notifier
= {
950 .notifier_call
= pm_notification
,
953 static int __init
telemetry_debugfs_init(void)
955 const struct x86_cpu_id
*id
;
959 /* Only APL supported for now */
960 id
= x86_match_cpu(telemetry_debugfs_cpu_ids
);
964 debugfs_conf
= (struct telemetry_debugfs_conf
*)id
->driver_data
;
966 err
= telemetry_pltconfig_valid();
970 err
= telemetry_debugfs_check_evts();
974 register_pm_notifier(&pm_notifier
);
977 debugfs_conf
->telemetry_dbg_dir
= debugfs_create_dir("telemetry", NULL
);
978 if (!debugfs_conf
->telemetry_dbg_dir
)
981 f
= debugfs_create_file("pss_info", S_IFREG
| S_IRUGO
,
982 debugfs_conf
->telemetry_dbg_dir
, NULL
,
985 pr_err("pss_sample_info debugfs register failed\n");
989 f
= debugfs_create_file("ioss_info", S_IFREG
| S_IRUGO
,
990 debugfs_conf
->telemetry_dbg_dir
, NULL
,
993 pr_err("ioss_sample_info debugfs register failed\n");
997 f
= debugfs_create_file("soc_states", S_IFREG
| S_IRUGO
,
998 debugfs_conf
->telemetry_dbg_dir
,
999 NULL
, &telem_socstate_ops
);
1001 pr_err("ioss_sample_info debugfs register failed\n");
1005 f
= debugfs_create_file("s0ix_residency_usec", S_IFREG
| S_IRUGO
,
1006 debugfs_conf
->telemetry_dbg_dir
,
1007 NULL
, &telem_s0ix_fops
);
1009 pr_err("s0ix_residency_usec debugfs register failed\n");
1013 f
= debugfs_create_file("pss_trace_verbosity", S_IFREG
| S_IRUGO
,
1014 debugfs_conf
->telemetry_dbg_dir
, NULL
,
1015 &telem_pss_trc_verb_ops
);
1017 pr_err("pss_trace_verbosity debugfs register failed\n");
1021 f
= debugfs_create_file("ioss_trace_verbosity", S_IFREG
| S_IRUGO
,
1022 debugfs_conf
->telemetry_dbg_dir
, NULL
,
1023 &telem_ioss_trc_verb_ops
);
1025 pr_err("ioss_trace_verbosity debugfs register failed\n");
1032 debugfs_remove_recursive(debugfs_conf
->telemetry_dbg_dir
);
1033 debugfs_conf
->telemetry_dbg_dir
= NULL
;
1035 unregister_pm_notifier(&pm_notifier
);
1040 static void __exit
telemetry_debugfs_exit(void)
1042 debugfs_remove_recursive(debugfs_conf
->telemetry_dbg_dir
);
1043 debugfs_conf
->telemetry_dbg_dir
= NULL
;
1044 unregister_pm_notifier(&pm_notifier
);
1047 late_initcall(telemetry_debugfs_init
);
1048 module_exit(telemetry_debugfs_exit
);
1050 MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
1051 MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface");
1052 MODULE_VERSION(DRIVER_VERSION
);
1053 MODULE_LICENSE("GPL");