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-family.h>
36 #include <asm/intel_pmc_ipc.h>
37 #include <asm/intel_punit_ipc.h>
38 #include <asm/intel_telemetry.h>
40 #define DRIVER_NAME "telemetry_soc_debugfs"
41 #define DRIVER_VERSION "1.0.0"
43 /* ApolloLake SoC Event-IDs */
44 #define TELEM_APL_PSS_PSTATES_ID 0x2802
45 #define TELEM_APL_PSS_IDLE_ID 0x2806
46 #define TELEM_APL_PCS_IDLE_BLOCKED_ID 0x2C00
47 #define TELEM_APL_PCS_S0IX_BLOCKED_ID 0x2C01
48 #define TELEM_APL_PSS_WAKEUP_ID 0x2C02
49 #define TELEM_APL_PSS_LTR_BLOCKING_ID 0x2C03
51 #define TELEM_APL_S0IX_TOTAL_OCC_ID 0x4000
52 #define TELEM_APL_S0IX_SHLW_OCC_ID 0x4001
53 #define TELEM_APL_S0IX_DEEP_OCC_ID 0x4002
54 #define TELEM_APL_S0IX_TOTAL_RES_ID 0x4800
55 #define TELEM_APL_S0IX_SHLW_RES_ID 0x4801
56 #define TELEM_APL_S0IX_DEEP_RES_ID 0x4802
57 #define TELEM_APL_D0IX_ID 0x581A
58 #define TELEM_APL_D3_ID 0x5819
59 #define TELEM_APL_PG_ID 0x5818
61 #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
62 #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
63 #define TELEM_SSRAM_READ_TIMEOUT 10
65 #define TELEM_MASK_BIT 1
66 #define TELEM_MASK_BYTE 0xFF
67 #define BYTES_PER_LONG 8
68 #define TELEM_APL_MASK_PCS_STATE 0xF
70 /* Max events in bitmap to check for */
71 #define TELEM_PSS_IDLE_EVTS 25
72 #define TELEM_PSS_IDLE_BLOCKED_EVTS 20
73 #define TELEM_PSS_S0IX_BLOCKED_EVTS 20
74 #define TELEM_PSS_S0IX_WAKEUP_EVTS 20
75 #define TELEM_PSS_LTR_BLOCKING_EVTS 20
76 #define TELEM_IOSS_DX_D0IX_EVTS 25
77 #define TELEM_IOSS_PG_EVTS 30
79 #define TELEM_EVT_LEN(x) (sizeof(x)/sizeof((x)[0]))
81 #define TELEM_DEBUGFS_CPU(model, data) \
82 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&data}
84 #define TELEM_CHECK_AND_PARSE_EVTS(EVTID, EVTNUM, BUF, EVTLOG, EVTDAT, MASK) { \
85 if (evtlog[index].telem_evtid == (EVTID)) { \
86 for (idx = 0; idx < (EVTNUM); idx++) \
87 (BUF)[idx] = ((EVTLOG) >> (EVTDAT)[idx].bit_pos) & \
93 #define TELEM_CHECK_AND_PARSE_CTRS(EVTID, CTR) { \
94 if (evtlog[index].telem_evtid == (EVTID)) { \
95 (CTR) = evtlog[index].telem_evtlog; \
100 #ifdef CONFIG_PM_SLEEP
101 static u8 suspend_prep_ok
;
102 static u32 suspend_shlw_ctr_temp
, suspend_deep_ctr_temp
;
103 static u64 suspend_shlw_res_temp
, suspend_deep_res_temp
;
106 struct telemetry_susp_stats
{
117 /* Bitmap definitions for default counters in APL */
118 struct telem_pss_idle_stateinfo
{
123 static struct telem_pss_idle_stateinfo telem_apl_pss_idle_data
[] = {
132 {"IA_MODULE0_C7", 32},
133 {"IA_MODULE1_C7", 33},
135 {"IUNIT_PROCESSING_IDLE", 41},
136 {"FAR_MEM_IDLE", 43},
137 {"DISPLAY_IDLE", 44},
138 {"IUNIT_INPUT_SYSTEM_IDLE", 45},
142 struct telem_pcs_blkd_info
{
147 static struct telem_pcs_blkd_info telem_apl_pcs_idle_blkd_data
[] = {
150 {"MODULE_ACTIONS_PENDING", 16},
152 {"DISPLAY_WAKE", 32},
157 static struct telem_pcs_blkd_info telem_apl_pcs_s0ix_blkd_data
[] = {
160 {"WAKE_DEADLINE_PENDING", 16},
168 struct telem_pss_ltr_info
{
173 static struct telem_pss_ltr_info telem_apl_pss_ltr_data
[] = {
177 {"DFX_FORCE_LTR", 24},
183 struct telem_pss_wakeup_info
{
188 static struct telem_pss_wakeup_info telem_apl_pss_wakeup
[] = {
191 {"VOLTAGE_REG_INT", 16},
192 {"DROWSY_TIMER (HOTPLUG)", 24},
198 struct telem_ioss_d0ix_stateinfo
{
203 static struct telem_ioss_d0ix_stateinfo telem_apl_ioss_d0ix_data
[] = {
225 struct telem_ioss_pg_info
{
230 static struct telem_ioss_pg_info telem_apl_ioss_pg_data
[] = {
260 struct telemetry_debugfs_conf
{
261 struct telemetry_susp_stats suspend_stats
;
262 struct dentry
*telemetry_dbg_dir
;
265 struct telem_ioss_d0ix_stateinfo
*ioss_d0ix_data
;
266 struct telem_pss_idle_stateinfo
*pss_idle_data
;
267 struct telem_pcs_blkd_info
*pcs_idle_blkd_data
;
268 struct telem_pcs_blkd_info
*pcs_s0ix_blkd_data
;
269 struct telem_pss_wakeup_info
*pss_wakeup
;
270 struct telem_pss_ltr_info
*pss_ltr_data
;
271 struct telem_ioss_pg_info
*ioss_pg_data
;
272 u8 pcs_idle_blkd_evts
;
273 u8 pcs_s0ix_blkd_evts
;
281 u16 pss_ltr_blocking_id
;
282 u16 pcs_idle_blkd_id
;
283 u16 pcs_s0ix_blkd_id
;
284 u16 s0ix_total_occ_id
;
285 u16 s0ix_shlw_occ_id
;
286 u16 s0ix_deep_occ_id
;
287 u16 s0ix_total_res_id
;
288 u16 s0ix_shlw_res_id
;
289 u16 s0ix_deep_res_id
;
298 static struct telemetry_debugfs_conf
*debugfs_conf
;
300 static struct telemetry_debugfs_conf telem_apl_debugfs_conf
= {
301 .pss_idle_data
= telem_apl_pss_idle_data
,
302 .pcs_idle_blkd_data
= telem_apl_pcs_idle_blkd_data
,
303 .pcs_s0ix_blkd_data
= telem_apl_pcs_s0ix_blkd_data
,
304 .pss_ltr_data
= telem_apl_pss_ltr_data
,
305 .pss_wakeup
= telem_apl_pss_wakeup
,
306 .ioss_d0ix_data
= telem_apl_ioss_d0ix_data
,
307 .ioss_pg_data
= telem_apl_ioss_pg_data
,
309 .pss_idle_evts
= TELEM_EVT_LEN(telem_apl_pss_idle_data
),
310 .pcs_idle_blkd_evts
= TELEM_EVT_LEN(telem_apl_pcs_idle_blkd_data
),
311 .pcs_s0ix_blkd_evts
= TELEM_EVT_LEN(telem_apl_pcs_s0ix_blkd_data
),
312 .pss_ltr_evts
= TELEM_EVT_LEN(telem_apl_pss_ltr_data
),
313 .pss_wakeup_evts
= TELEM_EVT_LEN(telem_apl_pss_wakeup
),
314 .ioss_d0ix_evts
= TELEM_EVT_LEN(telem_apl_ioss_d0ix_data
),
315 .ioss_pg_evts
= TELEM_EVT_LEN(telem_apl_ioss_pg_data
),
317 .pstates_id
= TELEM_APL_PSS_PSTATES_ID
,
318 .pss_idle_id
= TELEM_APL_PSS_IDLE_ID
,
319 .pcs_idle_blkd_id
= TELEM_APL_PCS_IDLE_BLOCKED_ID
,
320 .pcs_s0ix_blkd_id
= TELEM_APL_PCS_S0IX_BLOCKED_ID
,
321 .pss_wakeup_id
= TELEM_APL_PSS_WAKEUP_ID
,
322 .pss_ltr_blocking_id
= TELEM_APL_PSS_LTR_BLOCKING_ID
,
323 .s0ix_total_occ_id
= TELEM_APL_S0IX_TOTAL_OCC_ID
,
324 .s0ix_shlw_occ_id
= TELEM_APL_S0IX_SHLW_OCC_ID
,
325 .s0ix_deep_occ_id
= TELEM_APL_S0IX_DEEP_OCC_ID
,
326 .s0ix_total_res_id
= TELEM_APL_S0IX_TOTAL_RES_ID
,
327 .s0ix_shlw_res_id
= TELEM_APL_S0IX_SHLW_RES_ID
,
328 .s0ix_deep_res_id
= TELEM_APL_S0IX_DEEP_RES_ID
,
329 .ioss_d0ix_id
= TELEM_APL_D0IX_ID
,
330 .ioss_d3_id
= TELEM_APL_D3_ID
,
331 .ioss_pg_id
= TELEM_APL_PG_ID
,
334 static const struct x86_cpu_id telemetry_debugfs_cpu_ids
[] = {
335 TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT
, telem_apl_debugfs_conf
),
339 MODULE_DEVICE_TABLE(x86cpu
, telemetry_debugfs_cpu_ids
);
341 static int telemetry_debugfs_check_evts(void)
343 if ((debugfs_conf
->pss_idle_evts
> TELEM_PSS_IDLE_EVTS
) ||
344 (debugfs_conf
->pcs_idle_blkd_evts
> TELEM_PSS_IDLE_BLOCKED_EVTS
) ||
345 (debugfs_conf
->pcs_s0ix_blkd_evts
> TELEM_PSS_S0IX_BLOCKED_EVTS
) ||
346 (debugfs_conf
->pss_ltr_evts
> TELEM_PSS_LTR_BLOCKING_EVTS
) ||
347 (debugfs_conf
->pss_wakeup_evts
> TELEM_PSS_S0IX_WAKEUP_EVTS
) ||
348 (debugfs_conf
->ioss_d0ix_evts
> TELEM_IOSS_DX_D0IX_EVTS
) ||
349 (debugfs_conf
->ioss_pg_evts
> TELEM_IOSS_PG_EVTS
))
355 static int telem_pss_states_show(struct seq_file
*s
, void *unused
)
357 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
358 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
359 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
360 u32 pcs_idle_blkd
[TELEM_PSS_IDLE_BLOCKED_EVTS
],
361 pcs_s0ix_blkd
[TELEM_PSS_S0IX_BLOCKED_EVTS
],
362 pss_s0ix_wakeup
[TELEM_PSS_S0IX_WAKEUP_EVTS
],
363 pss_ltr_blkd
[TELEM_PSS_LTR_BLOCKING_EVTS
],
364 pss_idle
[TELEM_PSS_IDLE_EVTS
];
365 int index
, idx
, ret
, err
= 0;
368 ret
= telemetry_read_eventlog(TELEM_PSS
, evtlog
,
369 TELEM_MAX_OS_ALLOCATED_EVENTS
);
373 err
= telemetry_get_evtname(TELEM_PSS
, name
,
374 TELEM_MAX_OS_ALLOCATED_EVENTS
);
378 seq_puts(s
, "\n----------------------------------------------------\n");
379 seq_puts(s
, "\tPSS TELEM EVENTLOG (Residency = field/19.2 us\n");
380 seq_puts(s
, "----------------------------------------------------\n");
381 for (index
= 0; index
< ret
; index
++) {
382 seq_printf(s
, "%-32s %llu\n",
383 name
[index
], evtlog
[index
].telem_evtlog
);
385 /* Fetch PSS IDLE State */
386 if (evtlog
[index
].telem_evtid
== conf
->pss_idle_id
) {
387 pss_idle
[conf
->pss_idle_evts
- 1] =
388 (evtlog
[index
].telem_evtlog
>>
389 conf
->pss_idle_data
[conf
->pss_idle_evts
- 1].bit_pos
) &
390 TELEM_APL_MASK_PCS_STATE
;
394 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_idle_id
,
395 conf
->pss_idle_evts
- 1,
396 pss_idle
, evtlog
[index
].telem_evtlog
,
397 conf
->pss_idle_data
, TELEM_MASK_BIT
);
399 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_idle_blkd_id
,
400 conf
->pcs_idle_blkd_evts
,
402 evtlog
[index
].telem_evtlog
,
403 conf
->pcs_idle_blkd_data
,
406 TELEM_CHECK_AND_PARSE_EVTS(conf
->pcs_s0ix_blkd_id
,
407 conf
->pcs_s0ix_blkd_evts
,
409 evtlog
[index
].telem_evtlog
,
410 conf
->pcs_s0ix_blkd_data
,
414 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_wakeup_id
,
415 conf
->pss_wakeup_evts
,
417 evtlog
[index
].telem_evtlog
,
418 conf
->pss_wakeup
, TELEM_MASK_BYTE
);
420 TELEM_CHECK_AND_PARSE_EVTS(conf
->pss_ltr_blocking_id
,
421 conf
->pss_ltr_evts
, pss_ltr_blkd
,
422 evtlog
[index
].telem_evtlog
,
423 conf
->pss_ltr_data
, TELEM_MASK_BYTE
);
425 if (evtlog
[index
].telem_evtid
== debugfs_conf
->pstates_id
)
426 pstates
= evtlog
[index
].telem_evtlog
;
429 seq_puts(s
, "\n--------------------------------------\n");
430 seq_puts(s
, "PStates\n");
431 seq_puts(s
, "--------------------------------------\n");
432 seq_puts(s
, "Domain\t\t\t\tFreq(Mhz)\n");
433 seq_printf(s
, " IA\t\t\t\t %llu\n GT\t\t\t\t %llu\n",
434 (pstates
& TELEM_MASK_BYTE
)*100,
435 ((pstates
>> 8) & TELEM_MASK_BYTE
)*50/3);
437 seq_printf(s
, " IUNIT\t\t\t\t %llu\n SA\t\t\t\t %llu\n",
438 ((pstates
>> 16) & TELEM_MASK_BYTE
)*25,
439 ((pstates
>> 24) & TELEM_MASK_BYTE
)*50/3);
441 seq_puts(s
, "\n--------------------------------------\n");
442 seq_puts(s
, "PSS IDLE Status\n");
443 seq_puts(s
, "--------------------------------------\n");
444 seq_puts(s
, "Device\t\t\t\t\tIDLE\n");
445 for (index
= 0; index
< debugfs_conf
->pss_idle_evts
; index
++) {
446 seq_printf(s
, "%-32s\t%u\n",
447 debugfs_conf
->pss_idle_data
[index
].name
,
451 seq_puts(s
, "\n--------------------------------------\n");
452 seq_puts(s
, "PSS Idle blkd Status (~1ms saturating bucket)\n");
453 seq_puts(s
, "--------------------------------------\n");
454 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
455 for (index
= 0; index
< debugfs_conf
->pcs_idle_blkd_evts
; index
++) {
456 seq_printf(s
, "%-32s\t%u\n",
457 debugfs_conf
->pcs_idle_blkd_data
[index
].name
,
458 pcs_idle_blkd
[index
]);
461 seq_puts(s
, "\n--------------------------------------\n");
462 seq_puts(s
, "PSS S0ix blkd Status (~1ms saturating bucket)\n");
463 seq_puts(s
, "--------------------------------------\n");
464 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
465 for (index
= 0; index
< debugfs_conf
->pcs_s0ix_blkd_evts
; index
++) {
466 seq_printf(s
, "%-32s\t%u\n",
467 debugfs_conf
->pcs_s0ix_blkd_data
[index
].name
,
468 pcs_s0ix_blkd
[index
]);
471 seq_puts(s
, "\n--------------------------------------\n");
472 seq_puts(s
, "LTR Blocking Status (~1ms saturating bucket)\n");
473 seq_puts(s
, "--------------------------------------\n");
474 seq_puts(s
, "Blocker\t\t\t\t\tCount\n");
475 for (index
= 0; index
< debugfs_conf
->pss_ltr_evts
; index
++) {
476 seq_printf(s
, "%-32s\t%u\n",
477 debugfs_conf
->pss_ltr_data
[index
].name
,
478 pss_s0ix_wakeup
[index
]);
481 seq_puts(s
, "\n--------------------------------------\n");
482 seq_puts(s
, "Wakes Status (~1ms saturating bucket)\n");
483 seq_puts(s
, "--------------------------------------\n");
484 seq_puts(s
, "Wakes\t\t\t\t\tCount\n");
485 for (index
= 0; index
< debugfs_conf
->pss_wakeup_evts
; index
++) {
486 seq_printf(s
, "%-32s\t%u\n",
487 debugfs_conf
->pss_wakeup
[index
].name
,
488 pss_ltr_blkd
[index
]);
494 static int telem_pss_state_open(struct inode
*inode
, struct file
*file
)
496 return single_open(file
, telem_pss_states_show
, inode
->i_private
);
499 static const struct file_operations telem_pss_ops
= {
500 .open
= telem_pss_state_open
,
503 .release
= single_release
,
507 static int telem_ioss_states_show(struct seq_file
*s
, void *unused
)
509 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
510 const char *name
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
513 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
514 TELEM_MAX_OS_ALLOCATED_EVENTS
);
518 err
= telemetry_get_evtname(TELEM_IOSS
, name
,
519 TELEM_MAX_OS_ALLOCATED_EVENTS
);
523 seq_puts(s
, "--------------------------------------\n");
524 seq_puts(s
, "\tI0SS TELEMETRY EVENTLOG\n");
525 seq_puts(s
, "--------------------------------------\n");
526 for (index
= 0; index
< ret
; index
++) {
527 seq_printf(s
, "%-32s 0x%llx\n",
528 name
[index
], evtlog
[index
].telem_evtlog
);
534 static int telem_ioss_state_open(struct inode
*inode
, struct file
*file
)
536 return single_open(file
, telem_ioss_states_show
, inode
->i_private
);
539 static const struct file_operations telem_ioss_ops
= {
540 .open
= telem_ioss_state_open
,
543 .release
= single_release
,
546 static int telem_soc_states_show(struct seq_file
*s
, void *unused
)
548 u32 d3_sts
[TELEM_IOSS_DX_D0IX_EVTS
], d0ix_sts
[TELEM_IOSS_DX_D0IX_EVTS
];
549 u32 pg_sts
[TELEM_IOSS_PG_EVTS
], pss_idle
[TELEM_PSS_IDLE_EVTS
];
550 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
551 u32 s0ix_total_ctr
= 0, s0ix_shlw_ctr
= 0, s0ix_deep_ctr
= 0;
552 u64 s0ix_total_res
= 0, s0ix_shlw_res
= 0, s0ix_deep_res
= 0;
553 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
554 struct pci_dev
*dev
= NULL
;
559 ret
= telemetry_read_eventlog(TELEM_IOSS
, evtlog
,
560 TELEM_MAX_OS_ALLOCATED_EVENTS
);
564 for (index
= 0; index
< ret
; index
++) {
565 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d3_id
,
566 conf
->ioss_d0ix_evts
,
567 d3_sts
, evtlog
[index
].telem_evtlog
,
568 conf
->ioss_d0ix_data
,
571 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_pg_id
, conf
->ioss_pg_evts
,
572 pg_sts
, evtlog
[index
].telem_evtlog
,
573 conf
->ioss_pg_data
, TELEM_MASK_BIT
);
575 TELEM_CHECK_AND_PARSE_EVTS(conf
->ioss_d0ix_id
,
576 conf
->ioss_d0ix_evts
,
577 d0ix_sts
, evtlog
[index
].telem_evtlog
,
578 conf
->ioss_d0ix_data
,
581 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_occ_id
,
584 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
587 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
590 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_total_res_id
,
593 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
596 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
600 seq_puts(s
, "\n---------------------------------------------------\n");
601 seq_puts(s
, "S0IX Type\t\t\t Occurrence\t\t Residency(us)\n");
602 seq_puts(s
, "---------------------------------------------------\n");
604 seq_printf(s
, "S0IX Shallow\t\t\t %10u\t %10llu\n",
606 conf
->suspend_stats
.shlw_ctr
-
607 conf
->suspend_stats
.shlw_swake_ctr
,
608 (u64
)((s0ix_shlw_res
-
609 conf
->suspend_stats
.shlw_res
-
610 conf
->suspend_stats
.shlw_swake_res
)*10/192));
612 seq_printf(s
, "S0IX Deep\t\t\t %10u\t %10llu\n",
614 conf
->suspend_stats
.deep_ctr
-
615 conf
->suspend_stats
.deep_swake_ctr
,
616 (u64
)((s0ix_deep_res
-
617 conf
->suspend_stats
.deep_res
-
618 conf
->suspend_stats
.deep_swake_res
)*10/192));
620 seq_printf(s
, "Suspend(With S0ixShallow)\t %10u\t %10llu\n",
621 conf
->suspend_stats
.shlw_ctr
,
622 (u64
)(conf
->suspend_stats
.shlw_res
*10)/192);
624 seq_printf(s
, "Suspend(With S0ixDeep)\t\t %10u\t %10llu\n",
625 conf
->suspend_stats
.deep_ctr
,
626 (u64
)(conf
->suspend_stats
.deep_res
*10)/192);
628 seq_printf(s
, "Suspend(With Shallow-Wakes)\t %10u\t %10llu\n",
629 conf
->suspend_stats
.shlw_swake_ctr
+
630 conf
->suspend_stats
.deep_swake_ctr
,
631 (u64
)((conf
->suspend_stats
.shlw_swake_res
+
632 conf
->suspend_stats
.deep_swake_res
)*10/192));
634 seq_printf(s
, "S0IX+Suspend Total\t\t %10u\t %10llu\n", s0ix_total_ctr
,
635 (u64
)(s0ix_total_res
*10/192));
636 seq_puts(s
, "\n-------------------------------------------------\n");
637 seq_puts(s
, "\t\tDEVICE STATES\n");
638 seq_puts(s
, "-------------------------------------------------\n");
640 for_each_pci_dev(dev
) {
641 pci_read_config_word(dev
, dev
->pm_cap
+ PCI_PM_CTRL
, &pmcsr
);
642 d3_state
= ((pmcsr
& PCI_PM_CTRL_STATE_MASK
) ==
643 (__force
int)PCI_D3hot
) ? 1 : 0;
645 seq_printf(s
, "pci %04x %04X %s %20.20s: ",
646 dev
->vendor
, dev
->device
, dev_name(&dev
->dev
),
647 dev_driver_string(&dev
->dev
));
648 seq_printf(s
, " d3:%x\n", d3_state
);
651 seq_puts(s
, "\n--------------------------------------\n");
652 seq_puts(s
, "D3/D0i3 Status\n");
653 seq_puts(s
, "--------------------------------------\n");
654 seq_puts(s
, "Block\t\t D3\t D0i3\n");
655 for (index
= 0; index
< conf
->ioss_d0ix_evts
; index
++) {
656 seq_printf(s
, "%-10s\t %u\t %u\n",
657 conf
->ioss_d0ix_data
[index
].name
,
658 d3_sts
[index
], d0ix_sts
[index
]);
661 seq_puts(s
, "\n--------------------------------------\n");
662 seq_puts(s
, "South Complex PowerGate Status\n");
663 seq_puts(s
, "--------------------------------------\n");
664 seq_puts(s
, "Device\t\t PG\n");
665 for (index
= 0; index
< conf
->ioss_pg_evts
; index
++) {
666 seq_printf(s
, "%-10s\t %u\n",
667 conf
->ioss_pg_data
[index
].name
,
671 evtlog
->telem_evtid
= conf
->pss_idle_id
;
672 ret
= telemetry_read_events(TELEM_PSS
, evtlog
, 1);
676 seq_puts(s
, "\n-----------------------------------------\n");
677 seq_puts(s
, "North Idle Status\n");
678 seq_puts(s
, "-----------------------------------------\n");
679 for (idx
= 0; idx
< conf
->pss_idle_evts
- 1; idx
++) {
680 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
681 conf
->pss_idle_data
[idx
].bit_pos
) &
685 pss_idle
[idx
] = (evtlog
->telem_evtlog
>>
686 conf
->pss_idle_data
[idx
].bit_pos
) &
687 TELEM_APL_MASK_PCS_STATE
;
689 for (index
= 0; index
< conf
->pss_idle_evts
; index
++) {
690 seq_printf(s
, "%-30s %u\n",
691 conf
->pss_idle_data
[index
].name
,
695 seq_puts(s
, "\nPCS_STATUS Code\n");
696 seq_puts(s
, "0:C0 1:C1 2:C1_DN_WT_DEV 3:C2 4:C2_WT_DE_MEM_UP\n");
697 seq_puts(s
, "5:C2_WT_DE_MEM_DOWN 6:C2_UP_WT_DEV 7:C2_DN 8:C2_VOA\n");
698 seq_puts(s
, "9:C2_VOA_UP 10:S0IX_PRE 11:S0IX\n");
703 static int telem_soc_state_open(struct inode
*inode
, struct file
*file
)
705 return single_open(file
, telem_soc_states_show
, inode
->i_private
);
708 static const struct file_operations telem_socstate_ops
= {
709 .open
= telem_soc_state_open
,
712 .release
= single_release
,
715 static int telem_pss_trc_verb_show(struct seq_file
*s
, void *unused
)
720 err
= telemetry_get_trace_verbosity(TELEM_PSS
, &verbosity
);
722 pr_err("Get PSS Trace Verbosity Failed with Error %d\n", err
);
726 seq_printf(s
, "PSS Trace Verbosity %u\n", verbosity
);
730 static ssize_t
telem_pss_trc_verb_write(struct file
*file
,
731 const char __user
*userbuf
,
732 size_t count
, loff_t
*ppos
)
737 if (kstrtou32_from_user(userbuf
, count
, 0, &verbosity
))
740 err
= telemetry_set_trace_verbosity(TELEM_PSS
, verbosity
);
742 pr_err("Changing PSS Trace Verbosity Failed. Error %d\n", err
);
749 static int telem_pss_trc_verb_open(struct inode
*inode
, struct file
*file
)
751 return single_open(file
, telem_pss_trc_verb_show
, inode
->i_private
);
754 static const struct file_operations telem_pss_trc_verb_ops
= {
755 .open
= telem_pss_trc_verb_open
,
757 .write
= telem_pss_trc_verb_write
,
759 .release
= single_release
,
763 static int telem_ioss_trc_verb_show(struct seq_file
*s
, void *unused
)
768 err
= telemetry_get_trace_verbosity(TELEM_IOSS
, &verbosity
);
770 pr_err("Get IOSS Trace Verbosity Failed with Error %d\n", err
);
774 seq_printf(s
, "IOSS Trace Verbosity %u\n", verbosity
);
778 static ssize_t
telem_ioss_trc_verb_write(struct file
*file
,
779 const char __user
*userbuf
,
780 size_t count
, loff_t
*ppos
)
785 if (kstrtou32_from_user(userbuf
, count
, 0, &verbosity
))
788 err
= telemetry_set_trace_verbosity(TELEM_IOSS
, verbosity
);
790 pr_err("Changing IOSS Trace Verbosity Failed. Error %d\n", err
);
797 static int telem_ioss_trc_verb_open(struct inode
*inode
, struct file
*file
)
799 return single_open(file
, telem_ioss_trc_verb_show
, inode
->i_private
);
802 static const struct file_operations telem_ioss_trc_verb_ops
= {
803 .open
= telem_ioss_trc_verb_open
,
805 .write
= telem_ioss_trc_verb_write
,
807 .release
= single_release
,
810 #ifdef CONFIG_PM_SLEEP
811 static int pm_suspend_prep_cb(void)
813 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
814 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
817 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
818 TELEM_MAX_OS_ALLOCATED_EVENTS
);
824 for (index
= 0; index
< ret
; index
++) {
826 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
827 suspend_shlw_ctr_temp
);
829 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
830 suspend_deep_ctr_temp
);
832 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
833 suspend_shlw_res_temp
);
835 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
836 suspend_deep_res_temp
);
843 static int pm_suspend_exit_cb(void)
845 struct telemetry_evtlog evtlog
[TELEM_MAX_OS_ALLOCATED_EVENTS
];
846 static u32 suspend_shlw_ctr_exit
, suspend_deep_ctr_exit
;
847 static u64 suspend_shlw_res_exit
, suspend_deep_res_exit
;
848 struct telemetry_debugfs_conf
*conf
= debugfs_conf
;
851 if (!suspend_prep_ok
)
854 ret
= telemetry_raw_read_eventlog(TELEM_IOSS
, evtlog
,
855 TELEM_MAX_OS_ALLOCATED_EVENTS
);
859 for (index
= 0; index
< ret
; index
++) {
860 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_occ_id
,
861 suspend_shlw_ctr_exit
);
863 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_occ_id
,
864 suspend_deep_ctr_exit
);
866 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_shlw_res_id
,
867 suspend_shlw_res_exit
);
869 TELEM_CHECK_AND_PARSE_CTRS(conf
->s0ix_deep_res_id
,
870 suspend_deep_res_exit
);
873 if ((suspend_shlw_ctr_exit
< suspend_shlw_ctr_temp
) ||
874 (suspend_deep_ctr_exit
< suspend_deep_ctr_temp
) ||
875 (suspend_shlw_res_exit
< suspend_shlw_res_temp
) ||
876 (suspend_deep_res_exit
< suspend_deep_res_temp
)) {
877 pr_err("Wrong s0ix counters detected\n");
881 suspend_shlw_ctr_exit
-= suspend_shlw_ctr_temp
;
882 suspend_deep_ctr_exit
-= suspend_deep_ctr_temp
;
883 suspend_shlw_res_exit
-= suspend_shlw_res_temp
;
884 suspend_deep_res_exit
-= suspend_deep_res_temp
;
886 if (suspend_shlw_ctr_exit
== 1) {
887 conf
->suspend_stats
.shlw_ctr
+=
888 suspend_shlw_ctr_exit
;
890 conf
->suspend_stats
.shlw_res
+=
891 suspend_shlw_res_exit
;
893 /* Shallow Wakes Case */
894 else if (suspend_shlw_ctr_exit
> 1) {
895 conf
->suspend_stats
.shlw_swake_ctr
+=
896 suspend_shlw_ctr_exit
;
898 conf
->suspend_stats
.shlw_swake_res
+=
899 suspend_shlw_res_exit
;
902 if (suspend_deep_ctr_exit
== 1) {
903 conf
->suspend_stats
.deep_ctr
+=
904 suspend_deep_ctr_exit
;
906 conf
->suspend_stats
.deep_res
+=
907 suspend_deep_res_exit
;
910 /* Shallow Wakes Case */
911 else if (suspend_deep_ctr_exit
> 1) {
912 conf
->suspend_stats
.deep_swake_ctr
+=
913 suspend_deep_ctr_exit
;
915 conf
->suspend_stats
.deep_swake_res
+=
916 suspend_deep_res_exit
;
924 static int pm_notification(struct notifier_block
*this,
925 unsigned long event
, void *ptr
)
928 case PM_SUSPEND_PREPARE
:
929 return pm_suspend_prep_cb();
930 case PM_POST_SUSPEND
:
931 return pm_suspend_exit_cb();
937 static struct notifier_block pm_notifier
= {
938 .notifier_call
= pm_notification
,
940 #endif /* CONFIG_PM_SLEEP */
942 static int __init
telemetry_debugfs_init(void)
944 const struct x86_cpu_id
*id
;
948 /* Only APL supported for now */
949 id
= x86_match_cpu(telemetry_debugfs_cpu_ids
);
953 debugfs_conf
= (struct telemetry_debugfs_conf
*)id
->driver_data
;
955 err
= telemetry_pltconfig_valid();
959 err
= telemetry_debugfs_check_evts();
964 #ifdef CONFIG_PM_SLEEP
965 register_pm_notifier(&pm_notifier
);
966 #endif /* CONFIG_PM_SLEEP */
968 debugfs_conf
->telemetry_dbg_dir
= debugfs_create_dir("telemetry", NULL
);
969 if (!debugfs_conf
->telemetry_dbg_dir
)
972 f
= debugfs_create_file("pss_info", S_IFREG
| S_IRUGO
,
973 debugfs_conf
->telemetry_dbg_dir
, NULL
,
976 pr_err("pss_sample_info debugfs register failed\n");
980 f
= debugfs_create_file("ioss_info", S_IFREG
| S_IRUGO
,
981 debugfs_conf
->telemetry_dbg_dir
, NULL
,
984 pr_err("ioss_sample_info debugfs register failed\n");
988 f
= debugfs_create_file("soc_states", S_IFREG
| S_IRUGO
,
989 debugfs_conf
->telemetry_dbg_dir
,
990 NULL
, &telem_socstate_ops
);
992 pr_err("ioss_sample_info debugfs register failed\n");
996 f
= debugfs_create_file("pss_trace_verbosity", S_IFREG
| S_IRUGO
,
997 debugfs_conf
->telemetry_dbg_dir
, NULL
,
998 &telem_pss_trc_verb_ops
);
1000 pr_err("pss_trace_verbosity debugfs register failed\n");
1004 f
= debugfs_create_file("ioss_trace_verbosity", S_IFREG
| S_IRUGO
,
1005 debugfs_conf
->telemetry_dbg_dir
, NULL
,
1006 &telem_ioss_trc_verb_ops
);
1008 pr_err("ioss_trace_verbosity debugfs register failed\n");
1015 debugfs_remove_recursive(debugfs_conf
->telemetry_dbg_dir
);
1016 debugfs_conf
->telemetry_dbg_dir
= NULL
;
1021 static void __exit
telemetry_debugfs_exit(void)
1023 debugfs_remove_recursive(debugfs_conf
->telemetry_dbg_dir
);
1024 debugfs_conf
->telemetry_dbg_dir
= NULL
;
1027 late_initcall(telemetry_debugfs_init
);
1028 module_exit(telemetry_debugfs_exit
);
1030 MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
1031 MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface");
1032 MODULE_VERSION(DRIVER_VERSION
);
1033 MODULE_LICENSE("GPL");