Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Intel SOC Telemetry debugfs Driver: Currently supports APL
  4 * Copyright (c) 2015, Intel Corporation.
  5 * All Rights Reserved.
  6 *
 
 
 
 
 
 
 
 
 
  7 * This file provides the debugfs interfaces for telemetry.
  8 * /sys/kernel/debug/telemetry/pss_info: Shows Primary Control Sub-Sys Counters
  9 * /sys/kernel/debug/telemetry/ioss_info: Shows IO Sub-System Counters
 10 * /sys/kernel/debug/telemetry/soc_states: Shows SoC State
 11 * /sys/kernel/debug/telemetry/pss_trace_verbosity: Read and Change Tracing
 12 *				Verbosity via firmware
 13 * /sys/kernel/debug/telemetry/ioss_race_verbosity: Write and Change Tracing
 14 *				Verbosity via firmware
 15 */
 16#include <linux/debugfs.h>
 17#include <linux/device.h>
 18#include <linux/mfd/intel_pmc_bxt.h>
 19#include <linux/module.h>
 20#include <linux/pci.h>
 
 
 21#include <linux/seq_file.h>
 
 
 
 22#include <linux/suspend.h>
 23
 24#include <asm/cpu_device_id.h>
 25#include <asm/intel-family.h>
 
 
 26#include <asm/intel_telemetry.h>
 27
 28#define DRIVER_NAME			"telemetry_soc_debugfs"
 29#define DRIVER_VERSION			"1.0.0"
 30
 31/* ApolloLake SoC Event-IDs */
 32#define TELEM_APL_PSS_PSTATES_ID	0x2802
 33#define TELEM_APL_PSS_IDLE_ID		0x2806
 34#define TELEM_APL_PCS_IDLE_BLOCKED_ID	0x2C00
 35#define TELEM_APL_PCS_S0IX_BLOCKED_ID	0x2C01
 36#define TELEM_APL_PSS_WAKEUP_ID		0x2C02
 37#define TELEM_APL_PSS_LTR_BLOCKING_ID	0x2C03
 38
 39#define TELEM_APL_S0IX_TOTAL_OCC_ID	0x4000
 40#define TELEM_APL_S0IX_SHLW_OCC_ID	0x4001
 41#define TELEM_APL_S0IX_DEEP_OCC_ID	0x4002
 42#define TELEM_APL_S0IX_TOTAL_RES_ID	0x4800
 43#define TELEM_APL_S0IX_SHLW_RES_ID	0x4801
 44#define TELEM_APL_S0IX_DEEP_RES_ID	0x4802
 45#define TELEM_APL_D0IX_ID		0x581A
 46#define TELEM_APL_D3_ID			0x5819
 47#define TELEM_APL_PG_ID			0x5818
 48
 49#define TELEM_INFO_SRAMEVTS_MASK	0xFF00
 50#define TELEM_INFO_SRAMEVTS_SHIFT	0x8
 51#define TELEM_SSRAM_READ_TIMEOUT	10
 52
 53#define TELEM_MASK_BIT			1
 54#define TELEM_MASK_BYTE			0xFF
 55#define BYTES_PER_LONG			8
 56#define TELEM_APL_MASK_PCS_STATE	0xF
 57
 58/* Max events in bitmap to check for */
 59#define TELEM_PSS_IDLE_EVTS		25
 60#define TELEM_PSS_IDLE_BLOCKED_EVTS	20
 61#define TELEM_PSS_S0IX_BLOCKED_EVTS	20
 62#define TELEM_PSS_S0IX_WAKEUP_EVTS	20
 63#define TELEM_PSS_LTR_BLOCKING_EVTS	20
 64#define TELEM_IOSS_DX_D0IX_EVTS		25
 65#define TELEM_IOSS_PG_EVTS		30
 66
 
 
 
 
 
 67#define TELEM_CHECK_AND_PARSE_EVTS(EVTID, EVTNUM, BUF, EVTLOG, EVTDAT, MASK) { \
 68	if (evtlog[index].telem_evtid == (EVTID)) { \
 69		for (idx = 0; idx < (EVTNUM); idx++) \
 70			(BUF)[idx] = ((EVTLOG) >> (EVTDAT)[idx].bit_pos) & \
 71				     (MASK); \
 72	continue; \
 73	} \
 74}
 75
 76#define TELEM_CHECK_AND_PARSE_CTRS(EVTID, CTR) { \
 77	if (evtlog[index].telem_evtid == (EVTID)) { \
 78		(CTR) = evtlog[index].telem_evtlog; \
 79		continue; \
 80	} \
 81}
 82
 
 83static u8 suspend_prep_ok;
 84static u32 suspend_shlw_ctr_temp, suspend_deep_ctr_temp;
 85static u64 suspend_shlw_res_temp, suspend_deep_res_temp;
 
 86
 87struct telemetry_susp_stats {
 
 
 
 
 88	u32 shlw_ctr;
 89	u32 deep_ctr;
 90	u64 shlw_res;
 91	u64 deep_res;
 92};
 93
 94/* Bitmap definitions for default counters in APL */
 95struct telem_pss_idle_stateinfo {
 96	const char *name;
 97	u32 bit_pos;
 98};
 99
100static struct telem_pss_idle_stateinfo telem_apl_pss_idle_data[] = {
101	{"IA_CORE0_C1E",		0},
102	{"IA_CORE1_C1E",		1},
103	{"IA_CORE2_C1E",		2},
104	{"IA_CORE3_C1E",		3},
105	{"IA_CORE0_C6",			16},
106	{"IA_CORE1_C6",			17},
107	{"IA_CORE2_C6",			18},
108	{"IA_CORE3_C6",			19},
109	{"IA_MODULE0_C7",		32},
110	{"IA_MODULE1_C7",		33},
111	{"GT_RC6",			40},
112	{"IUNIT_PROCESSING_IDLE",	41},
113	{"FAR_MEM_IDLE",		43},
114	{"DISPLAY_IDLE",		44},
115	{"IUNIT_INPUT_SYSTEM_IDLE",	45},
116	{"PCS_STATUS",			60},
117};
118
119struct telem_pcs_blkd_info {
120	const char *name;
121	u32 bit_pos;
122};
123
124static struct telem_pcs_blkd_info telem_apl_pcs_idle_blkd_data[] = {
125	{"COMPUTE",			0},
126	{"MISC",			8},
127	{"MODULE_ACTIONS_PENDING",	16},
128	{"LTR",				24},
129	{"DISPLAY_WAKE",		32},
130	{"ISP_WAKE",			40},
131	{"PSF0_ACTIVE",			48},
132};
133
134static struct telem_pcs_blkd_info telem_apl_pcs_s0ix_blkd_data[] = {
135	{"LTR",				0},
136	{"IRTL",			8},
137	{"WAKE_DEADLINE_PENDING",	16},
138	{"DISPLAY",			24},
139	{"ISP",				32},
140	{"CORE",			40},
141	{"PMC",				48},
142	{"MISC",			56},
143};
144
145struct telem_pss_ltr_info {
146	const char *name;
147	u32 bit_pos;
148};
149
150static struct telem_pss_ltr_info telem_apl_pss_ltr_data[] = {
151	{"CORE_ACTIVE",		0},
152	{"MEM_UP",		8},
153	{"DFX",			16},
154	{"DFX_FORCE_LTR",	24},
155	{"DISPLAY",		32},
156	{"ISP",			40},
157	{"SOUTH",		48},
158};
159
160struct telem_pss_wakeup_info {
161	const char *name;
162	u32 bit_pos;
163};
164
165static struct telem_pss_wakeup_info telem_apl_pss_wakeup[] = {
166	{"IP_IDLE",			0},
167	{"DISPLAY_WAKE",		8},
168	{"VOLTAGE_REG_INT",		16},
169	{"DROWSY_TIMER (HOTPLUG)",	24},
170	{"CORE_WAKE",			32},
171	{"MISC_S0IX",			40},
172	{"MISC_ABORT",			56},
173};
174
175struct telem_ioss_d0ix_stateinfo {
176	const char *name;
177	u32 bit_pos;
178};
179
180static struct telem_ioss_d0ix_stateinfo telem_apl_ioss_d0ix_data[] = {
181	{"CSE",		0},
182	{"SCC2",	1},
183	{"GMM",		2},
184	{"XDCI",	3},
185	{"XHCI",	4},
186	{"ISH",		5},
187	{"AVS",		6},
188	{"PCIE0P1",	7},
189	{"PECI0P0",	8},
190	{"LPSS",	9},
191	{"SCC",		10},
192	{"PWM",		11},
193	{"PCIE1_P3",    12},
194	{"PCIE1_P2",    13},
195	{"PCIE1_P1",    14},
196	{"PCIE1_P0",    15},
197	{"CNV",		16},
198	{"SATA",	17},
199	{"PRTC",	18},
200};
201
202struct telem_ioss_pg_info {
203	const char *name;
204	u32 bit_pos;
205};
206
207static struct telem_ioss_pg_info telem_apl_ioss_pg_data[] = {
208	{"LPSS",	0},
209	{"SCC",		1},
210	{"P2SB",	2},
211	{"SCC2",	3},
212	{"GMM",		4},
213	{"PCIE0",	5},
214	{"XDCI",	6},
215	{"xHCI",	7},
216	{"CSE",		8},
217	{"SPI",		9},
218	{"AVSPGD4",	10},
219	{"AVSPGD3",	11},
220	{"AVSPGD2",	12},
221	{"AVSPGD1",	13},
222	{"ISH",		14},
223	{"EXI",		15},
224	{"NPKVRC",	16},
225	{"NPKVNN",	17},
226	{"CUNIT",	18},
227	{"FUSE_CTRL",	19},
228	{"PCIE1",	20},
229	{"CNV",		21},
230	{"LPC",		22},
231	{"SATA",	23},
232	{"SMB",		24},
233	{"PRTC",	25},
234};
235
 
236struct telemetry_debugfs_conf {
237	struct telemetry_susp_stats suspend_stats;
238	struct dentry *telemetry_dbg_dir;
239
240	/* Bitmap Data */
241	struct telem_ioss_d0ix_stateinfo *ioss_d0ix_data;
242	struct telem_pss_idle_stateinfo *pss_idle_data;
243	struct telem_pcs_blkd_info *pcs_idle_blkd_data;
244	struct telem_pcs_blkd_info *pcs_s0ix_blkd_data;
245	struct telem_pss_wakeup_info *pss_wakeup;
246	struct telem_pss_ltr_info *pss_ltr_data;
247	struct telem_ioss_pg_info *ioss_pg_data;
248	u8 pcs_idle_blkd_evts;
249	u8 pcs_s0ix_blkd_evts;
250	u8 pss_wakeup_evts;
251	u8 pss_idle_evts;
252	u8 pss_ltr_evts;
253	u8 ioss_d0ix_evts;
254	u8 ioss_pg_evts;
255
256	/* IDs */
257	u16  pss_ltr_blocking_id;
258	u16  pcs_idle_blkd_id;
259	u16  pcs_s0ix_blkd_id;
260	u16  s0ix_total_occ_id;
261	u16  s0ix_shlw_occ_id;
262	u16  s0ix_deep_occ_id;
263	u16  s0ix_total_res_id;
264	u16  s0ix_shlw_res_id;
265	u16  s0ix_deep_res_id;
266	u16  pss_wakeup_id;
267	u16  ioss_d0ix_id;
268	u16  pstates_id;
269	u16  pss_idle_id;
270	u16  ioss_d3_id;
271	u16  ioss_pg_id;
272};
273
274static struct telemetry_debugfs_conf *debugfs_conf;
275
276static struct telemetry_debugfs_conf telem_apl_debugfs_conf = {
277	.pss_idle_data = telem_apl_pss_idle_data,
278	.pcs_idle_blkd_data = telem_apl_pcs_idle_blkd_data,
279	.pcs_s0ix_blkd_data = telem_apl_pcs_s0ix_blkd_data,
280	.pss_ltr_data = telem_apl_pss_ltr_data,
281	.pss_wakeup = telem_apl_pss_wakeup,
282	.ioss_d0ix_data = telem_apl_ioss_d0ix_data,
283	.ioss_pg_data = telem_apl_ioss_pg_data,
284
285	.pss_idle_evts = ARRAY_SIZE(telem_apl_pss_idle_data),
286	.pcs_idle_blkd_evts = ARRAY_SIZE(telem_apl_pcs_idle_blkd_data),
287	.pcs_s0ix_blkd_evts = ARRAY_SIZE(telem_apl_pcs_s0ix_blkd_data),
288	.pss_ltr_evts = ARRAY_SIZE(telem_apl_pss_ltr_data),
289	.pss_wakeup_evts = ARRAY_SIZE(telem_apl_pss_wakeup),
290	.ioss_d0ix_evts = ARRAY_SIZE(telem_apl_ioss_d0ix_data),
291	.ioss_pg_evts = ARRAY_SIZE(telem_apl_ioss_pg_data),
292
293	.pstates_id = TELEM_APL_PSS_PSTATES_ID,
294	.pss_idle_id = TELEM_APL_PSS_IDLE_ID,
295	.pcs_idle_blkd_id = TELEM_APL_PCS_IDLE_BLOCKED_ID,
296	.pcs_s0ix_blkd_id = TELEM_APL_PCS_S0IX_BLOCKED_ID,
297	.pss_wakeup_id = TELEM_APL_PSS_WAKEUP_ID,
298	.pss_ltr_blocking_id = TELEM_APL_PSS_LTR_BLOCKING_ID,
299	.s0ix_total_occ_id = TELEM_APL_S0IX_TOTAL_OCC_ID,
300	.s0ix_shlw_occ_id = TELEM_APL_S0IX_SHLW_OCC_ID,
301	.s0ix_deep_occ_id = TELEM_APL_S0IX_DEEP_OCC_ID,
302	.s0ix_total_res_id = TELEM_APL_S0IX_TOTAL_RES_ID,
303	.s0ix_shlw_res_id = TELEM_APL_S0IX_SHLW_RES_ID,
304	.s0ix_deep_res_id = TELEM_APL_S0IX_DEEP_RES_ID,
305	.ioss_d0ix_id = TELEM_APL_D0IX_ID,
306	.ioss_d3_id = TELEM_APL_D3_ID,
307	.ioss_pg_id = TELEM_APL_PG_ID,
308};
309
310static const struct x86_cpu_id telemetry_debugfs_cpu_ids[] = {
311	X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT,	&telem_apl_debugfs_conf),
312	X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT_PLUS,	&telem_apl_debugfs_conf),
313	{}
314};
 
315MODULE_DEVICE_TABLE(x86cpu, telemetry_debugfs_cpu_ids);
316
317static int telemetry_debugfs_check_evts(void)
318{
319	if ((debugfs_conf->pss_idle_evts > TELEM_PSS_IDLE_EVTS) ||
320	    (debugfs_conf->pcs_idle_blkd_evts > TELEM_PSS_IDLE_BLOCKED_EVTS) ||
321	    (debugfs_conf->pcs_s0ix_blkd_evts > TELEM_PSS_S0IX_BLOCKED_EVTS) ||
322	    (debugfs_conf->pss_ltr_evts > TELEM_PSS_LTR_BLOCKING_EVTS) ||
323	    (debugfs_conf->pss_wakeup_evts > TELEM_PSS_S0IX_WAKEUP_EVTS) ||
324	    (debugfs_conf->ioss_d0ix_evts > TELEM_IOSS_DX_D0IX_EVTS) ||
325	    (debugfs_conf->ioss_pg_evts > TELEM_IOSS_PG_EVTS))
326		return -EINVAL;
327
328	return 0;
329}
330
331static int telem_pss_states_show(struct seq_file *s, void *unused)
332{
333	struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
334	struct telemetry_debugfs_conf *conf = debugfs_conf;
335	const char *name[TELEM_MAX_OS_ALLOCATED_EVENTS];
336	u32 pcs_idle_blkd[TELEM_PSS_IDLE_BLOCKED_EVTS],
337	    pcs_s0ix_blkd[TELEM_PSS_S0IX_BLOCKED_EVTS],
338	    pss_s0ix_wakeup[TELEM_PSS_S0IX_WAKEUP_EVTS],
339	    pss_ltr_blkd[TELEM_PSS_LTR_BLOCKING_EVTS],
340	    pss_idle[TELEM_PSS_IDLE_EVTS];
341	int index, idx, ret, err = 0;
342	u64 pstates = 0;
343
344	ret = telemetry_read_eventlog(TELEM_PSS, evtlog,
345				      TELEM_MAX_OS_ALLOCATED_EVENTS);
346	if (ret < 0)
347		return ret;
348
349	err = telemetry_get_evtname(TELEM_PSS, name,
350				    TELEM_MAX_OS_ALLOCATED_EVENTS);
351	if (err < 0)
352		return err;
353
354	seq_puts(s, "\n----------------------------------------------------\n");
355	seq_puts(s, "\tPSS TELEM EVENTLOG (Residency = field/19.2 us\n");
356	seq_puts(s, "----------------------------------------------------\n");
357	for (index = 0; index < ret; index++) {
358		seq_printf(s, "%-32s %llu\n",
359			   name[index], evtlog[index].telem_evtlog);
360
361		/* Fetch PSS IDLE State */
362		if (evtlog[index].telem_evtid == conf->pss_idle_id) {
363			pss_idle[conf->pss_idle_evts - 1] =
364			(evtlog[index].telem_evtlog >>
365			conf->pss_idle_data[conf->pss_idle_evts - 1].bit_pos) &
366			TELEM_APL_MASK_PCS_STATE;
367		}
368
 
369		TELEM_CHECK_AND_PARSE_EVTS(conf->pss_idle_id,
370					   conf->pss_idle_evts - 1,
371					   pss_idle, evtlog[index].telem_evtlog,
372					   conf->pss_idle_data, TELEM_MASK_BIT);
373
374		TELEM_CHECK_AND_PARSE_EVTS(conf->pcs_idle_blkd_id,
375					   conf->pcs_idle_blkd_evts,
376					   pcs_idle_blkd,
377					   evtlog[index].telem_evtlog,
378					   conf->pcs_idle_blkd_data,
379					   TELEM_MASK_BYTE);
380
381		TELEM_CHECK_AND_PARSE_EVTS(conf->pcs_s0ix_blkd_id,
382					   conf->pcs_s0ix_blkd_evts,
383					   pcs_s0ix_blkd,
384					   evtlog[index].telem_evtlog,
385					   conf->pcs_s0ix_blkd_data,
386					   TELEM_MASK_BYTE);
387
 
388		TELEM_CHECK_AND_PARSE_EVTS(conf->pss_wakeup_id,
389					   conf->pss_wakeup_evts,
390					   pss_s0ix_wakeup,
391					   evtlog[index].telem_evtlog,
392					   conf->pss_wakeup, TELEM_MASK_BYTE);
393
394		TELEM_CHECK_AND_PARSE_EVTS(conf->pss_ltr_blocking_id,
395					   conf->pss_ltr_evts, pss_ltr_blkd,
396					   evtlog[index].telem_evtlog,
397					   conf->pss_ltr_data, TELEM_MASK_BYTE);
398
399		if (evtlog[index].telem_evtid == debugfs_conf->pstates_id)
400			pstates = evtlog[index].telem_evtlog;
401	}
402
403	seq_puts(s, "\n--------------------------------------\n");
404	seq_puts(s, "PStates\n");
405	seq_puts(s, "--------------------------------------\n");
406	seq_puts(s, "Domain\t\t\t\tFreq(Mhz)\n");
407	seq_printf(s, " IA\t\t\t\t %llu\n GT\t\t\t\t %llu\n",
408		   (pstates & TELEM_MASK_BYTE)*100,
409		   ((pstates >> 8) & TELEM_MASK_BYTE)*50/3);
410
411	seq_printf(s, " IUNIT\t\t\t\t %llu\n SA\t\t\t\t %llu\n",
412		   ((pstates >> 16) & TELEM_MASK_BYTE)*25,
413		   ((pstates >> 24) & TELEM_MASK_BYTE)*50/3);
414
415	seq_puts(s, "\n--------------------------------------\n");
416	seq_puts(s, "PSS IDLE Status\n");
417	seq_puts(s, "--------------------------------------\n");
418	seq_puts(s, "Device\t\t\t\t\tIDLE\n");
419	for (index = 0; index < debugfs_conf->pss_idle_evts; index++) {
420		seq_printf(s, "%-32s\t%u\n",
421			   debugfs_conf->pss_idle_data[index].name,
422			   pss_idle[index]);
423	}
424
425	seq_puts(s, "\n--------------------------------------\n");
426	seq_puts(s, "PSS Idle blkd Status (~1ms saturating bucket)\n");
427	seq_puts(s, "--------------------------------------\n");
428	seq_puts(s, "Blocker\t\t\t\t\tCount\n");
429	for (index = 0; index < debugfs_conf->pcs_idle_blkd_evts; index++) {
430		seq_printf(s, "%-32s\t%u\n",
431			   debugfs_conf->pcs_idle_blkd_data[index].name,
432			   pcs_idle_blkd[index]);
433	}
434
435	seq_puts(s, "\n--------------------------------------\n");
436	seq_puts(s, "PSS S0ix blkd Status (~1ms saturating bucket)\n");
437	seq_puts(s, "--------------------------------------\n");
438	seq_puts(s, "Blocker\t\t\t\t\tCount\n");
439	for (index = 0; index < debugfs_conf->pcs_s0ix_blkd_evts; index++) {
440		seq_printf(s, "%-32s\t%u\n",
441			   debugfs_conf->pcs_s0ix_blkd_data[index].name,
442			   pcs_s0ix_blkd[index]);
443	}
444
445	seq_puts(s, "\n--------------------------------------\n");
446	seq_puts(s, "LTR Blocking Status (~1ms saturating bucket)\n");
447	seq_puts(s, "--------------------------------------\n");
448	seq_puts(s, "Blocker\t\t\t\t\tCount\n");
449	for (index = 0; index < debugfs_conf->pss_ltr_evts; index++) {
450		seq_printf(s, "%-32s\t%u\n",
451			   debugfs_conf->pss_ltr_data[index].name,
452			   pss_s0ix_wakeup[index]);
453	}
454
455	seq_puts(s, "\n--------------------------------------\n");
456	seq_puts(s, "Wakes Status (~1ms saturating bucket)\n");
457	seq_puts(s, "--------------------------------------\n");
458	seq_puts(s, "Wakes\t\t\t\t\tCount\n");
459	for (index = 0; index < debugfs_conf->pss_wakeup_evts; index++) {
460		seq_printf(s, "%-32s\t%u\n",
461			   debugfs_conf->pss_wakeup[index].name,
462			   pss_ltr_blkd[index]);
463	}
464
465	return 0;
466}
467
468DEFINE_SHOW_ATTRIBUTE(telem_pss_states);
 
 
 
 
 
 
 
 
 
 
 
469
470static int telem_ioss_states_show(struct seq_file *s, void *unused)
471{
472	struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
473	const char *name[TELEM_MAX_OS_ALLOCATED_EVENTS];
474	int index, ret, err;
475
476	ret = telemetry_read_eventlog(TELEM_IOSS, evtlog,
477				      TELEM_MAX_OS_ALLOCATED_EVENTS);
478	if (ret < 0)
479		return ret;
480
481	err = telemetry_get_evtname(TELEM_IOSS, name,
482				    TELEM_MAX_OS_ALLOCATED_EVENTS);
483	if (err < 0)
484		return err;
485
486	seq_puts(s, "--------------------------------------\n");
487	seq_puts(s, "\tI0SS TELEMETRY EVENTLOG\n");
488	seq_puts(s, "--------------------------------------\n");
489	for (index = 0; index < ret; index++) {
490		seq_printf(s, "%-32s 0x%llx\n",
491			   name[index], evtlog[index].telem_evtlog);
492	}
493
494	return 0;
495}
496
497DEFINE_SHOW_ATTRIBUTE(telem_ioss_states);
 
 
 
 
 
 
 
 
 
 
498
499static int telem_soc_states_show(struct seq_file *s, void *unused)
500{
501	u32 d3_sts[TELEM_IOSS_DX_D0IX_EVTS], d0ix_sts[TELEM_IOSS_DX_D0IX_EVTS];
502	u32 pg_sts[TELEM_IOSS_PG_EVTS], pss_idle[TELEM_PSS_IDLE_EVTS];
503	struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
504	u32 s0ix_total_ctr = 0, s0ix_shlw_ctr = 0, s0ix_deep_ctr = 0;
505	u64 s0ix_total_res = 0, s0ix_shlw_res = 0, s0ix_deep_res = 0;
506	struct telemetry_debugfs_conf *conf = debugfs_conf;
507	struct pci_dev *dev = NULL;
508	int index, idx, ret;
509	u32 d3_state;
510	u16 pmcsr;
511
512	ret = telemetry_read_eventlog(TELEM_IOSS, evtlog,
513				      TELEM_MAX_OS_ALLOCATED_EVENTS);
514	if (ret < 0)
515		return ret;
516
517	for (index = 0; index < ret; index++) {
518		TELEM_CHECK_AND_PARSE_EVTS(conf->ioss_d3_id,
519					   conf->ioss_d0ix_evts,
520					   d3_sts, evtlog[index].telem_evtlog,
521					   conf->ioss_d0ix_data,
522					   TELEM_MASK_BIT);
523
524		TELEM_CHECK_AND_PARSE_EVTS(conf->ioss_pg_id, conf->ioss_pg_evts,
525					   pg_sts, evtlog[index].telem_evtlog,
526					   conf->ioss_pg_data, TELEM_MASK_BIT);
527
528		TELEM_CHECK_AND_PARSE_EVTS(conf->ioss_d0ix_id,
529					   conf->ioss_d0ix_evts,
530					   d0ix_sts, evtlog[index].telem_evtlog,
531					   conf->ioss_d0ix_data,
532					   TELEM_MASK_BIT);
533
534		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_total_occ_id,
535					   s0ix_total_ctr);
536
537		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id,
538					   s0ix_shlw_ctr);
539
540		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id,
541					   s0ix_deep_ctr);
542
543		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_total_res_id,
544					   s0ix_total_res);
545
546		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id,
547					   s0ix_shlw_res);
548
549		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id,
550					   s0ix_deep_res);
551	}
552
553	seq_puts(s, "\n---------------------------------------------------\n");
554	seq_puts(s, "S0IX Type\t\t\t Occurrence\t\t Residency(us)\n");
555	seq_puts(s, "---------------------------------------------------\n");
556
557	seq_printf(s, "S0IX Shallow\t\t\t %10u\t %10llu\n",
558		   s0ix_shlw_ctr -
559		   conf->suspend_stats.shlw_ctr,
 
560		   (u64)((s0ix_shlw_res -
561		   conf->suspend_stats.shlw_res)*10/192));
 
562
563	seq_printf(s, "S0IX Deep\t\t\t %10u\t %10llu\n",
564		   s0ix_deep_ctr -
565		   conf->suspend_stats.deep_ctr,
 
566		   (u64)((s0ix_deep_res -
567		   conf->suspend_stats.deep_res)*10/192));
 
568
569	seq_printf(s, "Suspend(With S0ixShallow)\t %10u\t %10llu\n",
570		   conf->suspend_stats.shlw_ctr,
571		   (u64)(conf->suspend_stats.shlw_res*10)/192);
572
573	seq_printf(s, "Suspend(With S0ixDeep)\t\t %10u\t %10llu\n",
574		   conf->suspend_stats.deep_ctr,
575		   (u64)(conf->suspend_stats.deep_res*10)/192);
576
577	seq_printf(s, "TOTAL S0IX\t\t\t %10u\t %10llu\n", s0ix_total_ctr,
578		   (u64)(s0ix_total_res*10/192));
 
 
 
 
 
 
579	seq_puts(s, "\n-------------------------------------------------\n");
580	seq_puts(s, "\t\tDEVICE STATES\n");
581	seq_puts(s, "-------------------------------------------------\n");
582
583	for_each_pci_dev(dev) {
584		pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
585		d3_state = ((pmcsr & PCI_PM_CTRL_STATE_MASK) ==
586			    (__force int)PCI_D3hot) ? 1 : 0;
587
588		seq_printf(s, "pci %04x %04X %s %20.20s: ",
589			   dev->vendor, dev->device, dev_name(&dev->dev),
590			   dev_driver_string(&dev->dev));
591		seq_printf(s, " d3:%x\n", d3_state);
592	}
593
594	seq_puts(s, "\n--------------------------------------\n");
595	seq_puts(s, "D3/D0i3 Status\n");
596	seq_puts(s, "--------------------------------------\n");
597	seq_puts(s, "Block\t\t D3\t D0i3\n");
598	for (index = 0; index < conf->ioss_d0ix_evts; index++) {
599		seq_printf(s, "%-10s\t %u\t %u\n",
600			   conf->ioss_d0ix_data[index].name,
601			   d3_sts[index], d0ix_sts[index]);
602	}
603
604	seq_puts(s, "\n--------------------------------------\n");
605	seq_puts(s, "South Complex PowerGate Status\n");
606	seq_puts(s, "--------------------------------------\n");
607	seq_puts(s, "Device\t\t PG\n");
608	for (index = 0; index < conf->ioss_pg_evts; index++) {
609		seq_printf(s, "%-10s\t %u\n",
610			   conf->ioss_pg_data[index].name,
611			   pg_sts[index]);
612	}
613
614	evtlog->telem_evtid = conf->pss_idle_id;
615	ret = telemetry_read_events(TELEM_PSS, evtlog, 1);
616	if (ret < 0)
617		return ret;
618
619	seq_puts(s, "\n-----------------------------------------\n");
620	seq_puts(s, "North Idle Status\n");
621	seq_puts(s, "-----------------------------------------\n");
622	for (idx = 0; idx < conf->pss_idle_evts - 1; idx++) {
623		pss_idle[idx] =	(evtlog->telem_evtlog >>
624				conf->pss_idle_data[idx].bit_pos) &
625				TELEM_MASK_BIT;
626	}
627
628	pss_idle[idx] = (evtlog->telem_evtlog >>
629			conf->pss_idle_data[idx].bit_pos) &
630			TELEM_APL_MASK_PCS_STATE;
631
632	for (index = 0; index < conf->pss_idle_evts; index++) {
633		seq_printf(s, "%-30s %u\n",
634			   conf->pss_idle_data[index].name,
635			   pss_idle[index]);
636	}
637
638	seq_puts(s, "\nPCS_STATUS Code\n");
639	seq_puts(s, "0:C0 1:C1 2:C1_DN_WT_DEV 3:C2 4:C2_WT_DE_MEM_UP\n");
640	seq_puts(s, "5:C2_WT_DE_MEM_DOWN 6:C2_UP_WT_DEV 7:C2_DN 8:C2_VOA\n");
641	seq_puts(s, "9:C2_VOA_UP 10:S0IX_PRE 11:S0IX\n");
642
643	return 0;
644}
645
646DEFINE_SHOW_ATTRIBUTE(telem_soc_states);
647
648static int telem_s0ix_res_get(void *data, u64 *val)
649{
650	struct telemetry_plt_config *plt_config = telemetry_get_pltdata();
651	u64 s0ix_total_res;
652	int ret;
653
654	ret = intel_pmc_s0ix_counter_read(plt_config->pmc, &s0ix_total_res);
655	if (ret) {
656		pr_err("Failed to read S0ix residency");
657		return ret;
658	}
659
660	*val = s0ix_total_res;
661
662	return 0;
663}
664
665DEFINE_DEBUGFS_ATTRIBUTE(telem_s0ix_fops, telem_s0ix_res_get, NULL, "%llu\n");
 
 
 
 
 
666
667static int telem_pss_trc_verb_show(struct seq_file *s, void *unused)
668{
669	u32 verbosity;
670	int err;
671
672	err = telemetry_get_trace_verbosity(TELEM_PSS, &verbosity);
673	if (err) {
674		pr_err("Get PSS Trace Verbosity Failed with Error %d\n", err);
675		return -EFAULT;
676	}
677
678	seq_printf(s, "PSS Trace Verbosity %u\n", verbosity);
679	return 0;
680}
681
682static ssize_t telem_pss_trc_verb_write(struct file *file,
683					const char __user *userbuf,
684					size_t count, loff_t *ppos)
685{
686	u32 verbosity;
687	int err;
688
689	err = kstrtou32_from_user(userbuf, count, 0, &verbosity);
690	if (err)
691		return err;
692
693	err = telemetry_set_trace_verbosity(TELEM_PSS, verbosity);
694	if (err) {
695		pr_err("Changing PSS Trace Verbosity Failed. Error %d\n", err);
696		return err;
697	}
698
699	return count;
700}
701
702static int telem_pss_trc_verb_open(struct inode *inode, struct file *file)
703{
704	return single_open(file, telem_pss_trc_verb_show, inode->i_private);
705}
706
707static const struct file_operations telem_pss_trc_verb_ops = {
708	.open		= telem_pss_trc_verb_open,
709	.read		= seq_read,
710	.write		= telem_pss_trc_verb_write,
711	.llseek		= seq_lseek,
712	.release	= single_release,
713};
714
 
715static int telem_ioss_trc_verb_show(struct seq_file *s, void *unused)
716{
717	u32 verbosity;
718	int err;
719
720	err = telemetry_get_trace_verbosity(TELEM_IOSS, &verbosity);
721	if (err) {
722		pr_err("Get IOSS Trace Verbosity Failed with Error %d\n", err);
723		return -EFAULT;
724	}
725
726	seq_printf(s, "IOSS Trace Verbosity %u\n", verbosity);
727	return 0;
728}
729
730static ssize_t telem_ioss_trc_verb_write(struct file *file,
731					 const char __user *userbuf,
732					 size_t count, loff_t *ppos)
733{
734	u32 verbosity;
735	int err;
736
737	err = kstrtou32_from_user(userbuf, count, 0, &verbosity);
738	if (err)
739		return err;
740
741	err = telemetry_set_trace_verbosity(TELEM_IOSS, verbosity);
742	if (err) {
743		pr_err("Changing IOSS Trace Verbosity Failed. Error %d\n", err);
744		return err;
745	}
746
747	return count;
748}
749
750static int telem_ioss_trc_verb_open(struct inode *inode, struct file *file)
751{
752	return single_open(file, telem_ioss_trc_verb_show, inode->i_private);
753}
754
755static const struct file_operations telem_ioss_trc_verb_ops = {
756	.open		= telem_ioss_trc_verb_open,
757	.read		= seq_read,
758	.write		= telem_ioss_trc_verb_write,
759	.llseek		= seq_lseek,
760	.release	= single_release,
761};
762
 
763static int pm_suspend_prep_cb(void)
764{
765	struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
766	struct telemetry_debugfs_conf *conf = debugfs_conf;
767	int ret, index;
768
769	ret = telemetry_raw_read_eventlog(TELEM_IOSS, evtlog,
770			TELEM_MAX_OS_ALLOCATED_EVENTS);
771	if (ret < 0) {
772		suspend_prep_ok = 0;
773		goto out;
774	}
775
776	for (index = 0; index < ret; index++) {
777
778		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id,
779					   suspend_shlw_ctr_temp);
780
781		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id,
782					   suspend_deep_ctr_temp);
783
784		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id,
785					   suspend_shlw_res_temp);
786
787		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id,
788					   suspend_deep_res_temp);
789	}
790	suspend_prep_ok = 1;
791out:
792	return NOTIFY_OK;
793}
794
795static int pm_suspend_exit_cb(void)
796{
797	struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
798	static u32 suspend_shlw_ctr_exit, suspend_deep_ctr_exit;
799	static u64 suspend_shlw_res_exit, suspend_deep_res_exit;
800	struct telemetry_debugfs_conf *conf = debugfs_conf;
801	int ret, index;
802
803	if (!suspend_prep_ok)
804		goto out;
805
806	ret = telemetry_raw_read_eventlog(TELEM_IOSS, evtlog,
807					  TELEM_MAX_OS_ALLOCATED_EVENTS);
808	if (ret < 0)
809		goto out;
810
811	for (index = 0; index < ret; index++) {
812		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id,
813					   suspend_shlw_ctr_exit);
814
815		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id,
816					   suspend_deep_ctr_exit);
817
818		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id,
819					   suspend_shlw_res_exit);
820
821		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id,
822					   suspend_deep_res_exit);
823	}
824
825	if ((suspend_shlw_ctr_exit < suspend_shlw_ctr_temp) ||
826	    (suspend_deep_ctr_exit < suspend_deep_ctr_temp) ||
827	    (suspend_shlw_res_exit < suspend_shlw_res_temp) ||
828	    (suspend_deep_res_exit < suspend_deep_res_temp)) {
829		pr_err("Wrong s0ix counters detected\n");
830		goto out;
831	}
832
833	/*
834	 * Due to some design limitations in the firmware, sometimes the
835	 * counters do not get updated by the time we reach here. As a
836	 * workaround, we try to see if this was a genuine case of sleep
837	 * failure or not by cross-checking from PMC GCR registers directly.
838	 */
839	if (suspend_shlw_ctr_exit == suspend_shlw_ctr_temp &&
840	    suspend_deep_ctr_exit == suspend_deep_ctr_temp) {
841		struct telemetry_plt_config *plt_config = telemetry_get_pltdata();
842		struct intel_pmc_dev *pmc = plt_config->pmc;
843
844		ret = intel_pmc_gcr_read64(pmc, PMC_GCR_TELEM_SHLW_S0IX_REG,
845					  &suspend_shlw_res_exit);
846		if (ret < 0)
847			goto out;
848
849		ret = intel_pmc_gcr_read64(pmc, PMC_GCR_TELEM_DEEP_S0IX_REG,
850					  &suspend_deep_res_exit);
851		if (ret < 0)
852			goto out;
853
854		if (suspend_shlw_res_exit > suspend_shlw_res_temp)
855			suspend_shlw_ctr_exit++;
856
857		if (suspend_deep_res_exit > suspend_deep_res_temp)
858			suspend_deep_ctr_exit++;
859	}
860
861	suspend_shlw_ctr_exit -= suspend_shlw_ctr_temp;
862	suspend_deep_ctr_exit -= suspend_deep_ctr_temp;
863	suspend_shlw_res_exit -= suspend_shlw_res_temp;
864	suspend_deep_res_exit -= suspend_deep_res_temp;
865
866	if (suspend_shlw_ctr_exit != 0) {
867		conf->suspend_stats.shlw_ctr +=
868		suspend_shlw_ctr_exit;
869
870		conf->suspend_stats.shlw_res +=
871		suspend_shlw_res_exit;
872	}
 
 
 
 
 
 
 
 
873
874	if (suspend_deep_ctr_exit != 0) {
875		conf->suspend_stats.deep_ctr +=
876		suspend_deep_ctr_exit;
877
878		conf->suspend_stats.deep_res +=
879		suspend_deep_res_exit;
880	}
881
 
 
 
 
 
 
 
 
 
882out:
883	suspend_prep_ok = 0;
884	return NOTIFY_OK;
885}
886
887static int pm_notification(struct notifier_block *this,
888			   unsigned long event, void *ptr)
889{
890	switch (event) {
891	case PM_SUSPEND_PREPARE:
892		return pm_suspend_prep_cb();
893	case PM_POST_SUSPEND:
894		return pm_suspend_exit_cb();
895	}
896
897	return NOTIFY_DONE;
898}
899
900static struct notifier_block pm_notifier = {
901	.notifier_call = pm_notification,
902};
 
903
904static int __init telemetry_debugfs_init(void)
905{
906	const struct x86_cpu_id *id;
907	int err;
908	struct dentry *dir;
909
910	/* Only APL supported for now */
911	id = x86_match_cpu(telemetry_debugfs_cpu_ids);
912	if (!id)
913		return -ENODEV;
914
915	debugfs_conf = (struct telemetry_debugfs_conf *)id->driver_data;
916
917	if (!telemetry_get_pltdata()) {
918		pr_info("Invalid pltconfig, ensure IPC1 device is enabled in BIOS\n");
919		return -ENODEV;
920	}
921
922	err = telemetry_debugfs_check_evts();
923	if (err < 0) {
924		pr_info("telemetry_debugfs_check_evts failed\n");
925		return -EINVAL;
926	}
927
 
 
928	register_pm_notifier(&pm_notifier);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
929
930	dir = debugfs_create_dir("telemetry", NULL);
931	debugfs_conf->telemetry_dbg_dir = dir;
 
 
 
 
 
932
933	debugfs_create_file("pss_info", S_IFREG | S_IRUGO, dir, NULL,
934			    &telem_pss_states_fops);
935	debugfs_create_file("ioss_info", S_IFREG | S_IRUGO, dir, NULL,
936			    &telem_ioss_states_fops);
937	debugfs_create_file("soc_states", S_IFREG | S_IRUGO, dir, NULL,
938			    &telem_soc_states_fops);
939	debugfs_create_file("s0ix_residency_usec", S_IFREG | S_IRUGO, dir, NULL,
940			    &telem_s0ix_fops);
941	debugfs_create_file("pss_trace_verbosity", S_IFREG | S_IRUGO, dir, NULL,
942			    &telem_pss_trc_verb_ops);
943	debugfs_create_file("ioss_trace_verbosity", S_IFREG | S_IRUGO, dir,
944			    NULL, &telem_ioss_trc_verb_ops);
945	return 0;
 
 
 
 
 
 
946}
947
948static void __exit telemetry_debugfs_exit(void)
949{
950	debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir);
951	debugfs_conf->telemetry_dbg_dir = NULL;
952	unregister_pm_notifier(&pm_notifier);
953}
954
955late_initcall(telemetry_debugfs_init);
956module_exit(telemetry_debugfs_exit);
957
958MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
959MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface");
960MODULE_VERSION(DRIVER_VERSION);
961MODULE_LICENSE("GPL v2");
v4.10.11
 
   1/*
   2 * Intel SOC Telemetry debugfs Driver: Currently supports APL
   3 * Copyright (c) 2015, Intel Corporation.
   4 * All Rights Reserved.
   5 *
   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.
   9 *
  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
  13 * more details.
  14 *
  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
  23 */
 
 
 
  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>
  29#include <linux/io.h>
  30#include <linux/uaccess.h>
  31#include <linux/pci.h>
  32#include <linux/suspend.h>
  33
  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>
  39
  40#define DRIVER_NAME	"telemetry_soc_debugfs"
  41#define DRIVER_VERSION	"1.0.0"
  42
  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
  50
  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
  60
  61#define TELEM_INFO_SRAMEVTS_MASK	0xFF00
  62#define TELEM_INFO_SRAMEVTS_SHIFT	0x8
  63#define TELEM_SSRAM_READ_TIMEOUT	10
  64
  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
  69
  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
  78
  79#define TELEM_EVT_LEN(x) (sizeof(x)/sizeof((x)[0]))
  80
  81#define TELEM_DEBUGFS_CPU(model, data) \
  82	{ X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&data}
  83
  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) & \
  88				     (MASK); \
  89	continue; \
  90	} \
  91}
  92
  93#define TELEM_CHECK_AND_PARSE_CTRS(EVTID, CTR) { \
  94	if (evtlog[index].telem_evtid == (EVTID)) { \
  95		(CTR) = evtlog[index].telem_evtlog; \
  96		continue; \
  97	} \
  98}
  99
 100#ifdef CONFIG_PM_SLEEP
 101static u8 suspend_prep_ok;
 102static u32 suspend_shlw_ctr_temp, suspend_deep_ctr_temp;
 103static u64 suspend_shlw_res_temp, suspend_deep_res_temp;
 104#endif
 105
 106struct telemetry_susp_stats {
 107	u32 shlw_swake_ctr;
 108	u32 deep_swake_ctr;
 109	u64 shlw_swake_res;
 110	u64 deep_swake_res;
 111	u32 shlw_ctr;
 112	u32 deep_ctr;
 113	u64 shlw_res;
 114	u64 deep_res;
 115};
 116
 117/* Bitmap definitions for default counters in APL */
 118struct telem_pss_idle_stateinfo {
 119	const char *name;
 120	u32 bit_pos;
 121};
 122
 123static struct telem_pss_idle_stateinfo telem_apl_pss_idle_data[] = {
 124	{"IA_CORE0_C1E",		0},
 125	{"IA_CORE1_C1E",		1},
 126	{"IA_CORE2_C1E",		2},
 127	{"IA_CORE3_C1E",		3},
 128	{"IA_CORE0_C6",			16},
 129	{"IA_CORE1_C6",			17},
 130	{"IA_CORE2_C6",			18},
 131	{"IA_CORE3_C6",			19},
 132	{"IA_MODULE0_C7",		32},
 133	{"IA_MODULE1_C7",		33},
 134	{"GT_RC6",			40},
 135	{"IUNIT_PROCESSING_IDLE",	41},
 136	{"FAR_MEM_IDLE",		43},
 137	{"DISPLAY_IDLE",		44},
 138	{"IUNIT_INPUT_SYSTEM_IDLE",	45},
 139	{"PCS_STATUS",			60},
 140};
 141
 142struct telem_pcs_blkd_info {
 143	const char *name;
 144	u32 bit_pos;
 145};
 146
 147static struct telem_pcs_blkd_info telem_apl_pcs_idle_blkd_data[] = {
 148	{"COMPUTE",			0},
 149	{"MISC",			8},
 150	{"MODULE_ACTIONS_PENDING",	16},
 151	{"LTR",				24},
 152	{"DISPLAY_WAKE",		32},
 153	{"ISP_WAKE",			40},
 154	{"PSF0_ACTIVE",			48},
 155};
 156
 157static struct telem_pcs_blkd_info telem_apl_pcs_s0ix_blkd_data[] = {
 158	{"LTR",				0},
 159	{"IRTL",			8},
 160	{"WAKE_DEADLINE_PENDING",	16},
 161	{"DISPLAY",			24},
 162	{"ISP",				32},
 163	{"CORE",			40},
 164	{"PMC",				48},
 165	{"MISC",			56},
 166};
 167
 168struct telem_pss_ltr_info {
 169	const char *name;
 170	u32 bit_pos;
 171};
 172
 173static struct telem_pss_ltr_info telem_apl_pss_ltr_data[] = {
 174	{"CORE_ACTIVE",		0},
 175	{"MEM_UP",		8},
 176	{"DFX",			16},
 177	{"DFX_FORCE_LTR",	24},
 178	{"DISPLAY",		32},
 179	{"ISP",			40},
 180	{"SOUTH",		48},
 181};
 182
 183struct telem_pss_wakeup_info {
 184	const char *name;
 185	u32 bit_pos;
 186};
 187
 188static struct telem_pss_wakeup_info telem_apl_pss_wakeup[] = {
 189	{"IP_IDLE",			0},
 190	{"DISPLAY_WAKE",		8},
 191	{"VOLTAGE_REG_INT",		16},
 192	{"DROWSY_TIMER (HOTPLUG)",	24},
 193	{"CORE_WAKE",			32},
 194	{"MISC_S0IX",			40},
 195	{"MISC_ABORT",			56},
 196};
 197
 198struct telem_ioss_d0ix_stateinfo {
 199	const char *name;
 200	u32 bit_pos;
 201};
 202
 203static struct telem_ioss_d0ix_stateinfo telem_apl_ioss_d0ix_data[] = {
 204	{"CSE",		0},
 205	{"SCC2",	1},
 206	{"GMM",		2},
 207	{"XDCI",	3},
 208	{"XHCI",	4},
 209	{"ISH",		5},
 210	{"AVS",		6},
 211	{"PCIE0P1",	7},
 212	{"PECI0P0",	8},
 213	{"LPSS",	9},
 214	{"SCC",		10},
 215	{"PWM",		11},
 216	{"PCIE1_P3",    12},
 217	{"PCIE1_P2",    13},
 218	{"PCIE1_P1",    14},
 219	{"PCIE1_P0",    15},
 220	{"CNV",		16},
 221	{"SATA",	17},
 222	{"PRTC",	18},
 223};
 224
 225struct telem_ioss_pg_info {
 226	const char *name;
 227	u32 bit_pos;
 228};
 229
 230static struct telem_ioss_pg_info telem_apl_ioss_pg_data[] = {
 231	{"LPSS",	0},
 232	{"SCC",		1},
 233	{"P2SB",	2},
 234	{"SCC2",	3},
 235	{"GMM",		4},
 236	{"PCIE0",	5},
 237	{"XDCI",	6},
 238	{"xHCI",	7},
 239	{"CSE",		8},
 240	{"SPI",		9},
 241	{"AVSPGD4",	10},
 242	{"AVSPGD3",	11},
 243	{"AVSPGD2",	12},
 244	{"AVSPGD1",	13},
 245	{"ISH",		14},
 246	{"EXI",		15},
 247	{"NPKVRC",	16},
 248	{"NPKVNN",	17},
 249	{"CUNIT",	18},
 250	{"FUSE_CTRL",	19},
 251	{"PCIE1",	20},
 252	{"CNV",		21},
 253	{"LPC",		22},
 254	{"SATA",	23},
 255	{"SMB",		24},
 256	{"PRTC",	25},
 257};
 258
 259
 260struct telemetry_debugfs_conf {
 261	struct telemetry_susp_stats suspend_stats;
 262	struct dentry *telemetry_dbg_dir;
 263
 264	/* Bitmap Data */
 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;
 274	u8 pss_wakeup_evts;
 275	u8 pss_idle_evts;
 276	u8 pss_ltr_evts;
 277	u8 ioss_d0ix_evts;
 278	u8 ioss_pg_evts;
 279
 280	/* IDs */
 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;
 290	u16  pss_wakeup_id;
 291	u16  ioss_d0ix_id;
 292	u16  pstates_id;
 293	u16  pss_idle_id;
 294	u16  ioss_d3_id;
 295	u16  ioss_pg_id;
 296};
 297
 298static struct telemetry_debugfs_conf *debugfs_conf;
 299
 300static 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,
 308
 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),
 316
 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,
 332};
 333
 334static const struct x86_cpu_id telemetry_debugfs_cpu_ids[] = {
 335	TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_debugfs_conf),
 
 336	{}
 337};
 338
 339MODULE_DEVICE_TABLE(x86cpu, telemetry_debugfs_cpu_ids);
 340
 341static int telemetry_debugfs_check_evts(void)
 342{
 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))
 350		return -EINVAL;
 351
 352	return 0;
 353}
 354
 355static int telem_pss_states_show(struct seq_file *s, void *unused)
 356{
 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;
 366	u64 pstates = 0;
 367
 368	ret = telemetry_read_eventlog(TELEM_PSS, evtlog,
 369				      TELEM_MAX_OS_ALLOCATED_EVENTS);
 370	if (ret < 0)
 371		return ret;
 372
 373	err = telemetry_get_evtname(TELEM_PSS, name,
 374				    TELEM_MAX_OS_ALLOCATED_EVENTS);
 375	if (err < 0)
 376		return err;
 377
 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);
 384
 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;
 391		}
 392
 393
 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);
 398
 399		TELEM_CHECK_AND_PARSE_EVTS(conf->pcs_idle_blkd_id,
 400					   conf->pcs_idle_blkd_evts,
 401					   pcs_idle_blkd,
 402					   evtlog[index].telem_evtlog,
 403					   conf->pcs_idle_blkd_data,
 404					   TELEM_MASK_BYTE);
 405
 406		TELEM_CHECK_AND_PARSE_EVTS(conf->pcs_s0ix_blkd_id,
 407					   conf->pcs_s0ix_blkd_evts,
 408					   pcs_s0ix_blkd,
 409					   evtlog[index].telem_evtlog,
 410					   conf->pcs_s0ix_blkd_data,
 411					   TELEM_MASK_BYTE);
 412
 413
 414		TELEM_CHECK_AND_PARSE_EVTS(conf->pss_wakeup_id,
 415					   conf->pss_wakeup_evts,
 416					   pss_s0ix_wakeup,
 417					   evtlog[index].telem_evtlog,
 418					   conf->pss_wakeup, TELEM_MASK_BYTE);
 419
 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);
 424
 425		if (evtlog[index].telem_evtid == debugfs_conf->pstates_id)
 426			pstates = evtlog[index].telem_evtlog;
 427	}
 428
 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);
 436
 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);
 440
 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,
 448			   pss_idle[index]);
 449	}
 450
 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]);
 459	}
 460
 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]);
 469	}
 470
 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]);
 479	}
 480
 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]);
 489	}
 490
 491	return 0;
 492}
 493
 494static int telem_pss_state_open(struct inode *inode, struct file *file)
 495{
 496	return single_open(file, telem_pss_states_show, inode->i_private);
 497}
 498
 499static const struct file_operations telem_pss_ops = {
 500	.open		= telem_pss_state_open,
 501	.read		= seq_read,
 502	.llseek		= seq_lseek,
 503	.release	= single_release,
 504};
 505
 506
 507static int telem_ioss_states_show(struct seq_file *s, void *unused)
 508{
 509	struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
 510	const char *name[TELEM_MAX_OS_ALLOCATED_EVENTS];
 511	int index, ret, err;
 512
 513	ret = telemetry_read_eventlog(TELEM_IOSS, evtlog,
 514				      TELEM_MAX_OS_ALLOCATED_EVENTS);
 515	if (ret < 0)
 516		return ret;
 517
 518	err = telemetry_get_evtname(TELEM_IOSS, name,
 519				    TELEM_MAX_OS_ALLOCATED_EVENTS);
 520	if (err < 0)
 521		return err;
 522
 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);
 529	}
 530
 531	return 0;
 532}
 533
 534static int telem_ioss_state_open(struct inode *inode, struct file *file)
 535{
 536	return single_open(file, telem_ioss_states_show, inode->i_private);
 537}
 538
 539static const struct file_operations telem_ioss_ops = {
 540	.open		= telem_ioss_state_open,
 541	.read		= seq_read,
 542	.llseek		= seq_lseek,
 543	.release	= single_release,
 544};
 545
 546static int telem_soc_states_show(struct seq_file *s, void *unused)
 547{
 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;
 555	int index, idx, ret;
 556	u32 d3_state;
 557	u16 pmcsr;
 558
 559	ret = telemetry_read_eventlog(TELEM_IOSS, evtlog,
 560				      TELEM_MAX_OS_ALLOCATED_EVENTS);
 561	if (ret < 0)
 562		return ret;
 563
 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,
 569					   TELEM_MASK_BIT);
 570
 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);
 574
 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,
 579					   TELEM_MASK_BIT);
 580
 581		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_total_occ_id,
 582					   s0ix_total_ctr);
 583
 584		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id,
 585					   s0ix_shlw_ctr);
 586
 587		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id,
 588					   s0ix_deep_ctr);
 589
 590		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_total_res_id,
 591					   s0ix_total_res);
 592
 593		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id,
 594					   s0ix_shlw_res);
 595
 596		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id,
 597					   s0ix_deep_res);
 598	}
 599
 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");
 603
 604	seq_printf(s, "S0IX Shallow\t\t\t %10u\t %10llu\n",
 605		   s0ix_shlw_ctr -
 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));
 611
 612	seq_printf(s, "S0IX Deep\t\t\t %10u\t %10llu\n",
 613		   s0ix_deep_ctr -
 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));
 619
 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);
 623
 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);
 627
 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));
 633
 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");
 639
 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;
 644
 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);
 649	}
 650
 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]);
 659	}
 660
 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,
 668			   pg_sts[index]);
 669	}
 670
 671	evtlog->telem_evtid = conf->pss_idle_id;
 672	ret = telemetry_read_events(TELEM_PSS, evtlog, 1);
 673	if (ret < 0)
 674		return ret;
 675
 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) &
 682				TELEM_MASK_BIT;
 683	}
 684
 685	pss_idle[idx] = (evtlog->telem_evtlog >>
 686			conf->pss_idle_data[idx].bit_pos) &
 687			TELEM_APL_MASK_PCS_STATE;
 688
 689	for (index = 0; index < conf->pss_idle_evts; index++) {
 690		seq_printf(s, "%-30s %u\n",
 691			   conf->pss_idle_data[index].name,
 692			   pss_idle[index]);
 693	}
 694
 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");
 699
 700	return 0;
 701}
 702
 703static int telem_soc_state_open(struct inode *inode, struct file *file)
 
 
 704{
 705	return single_open(file, telem_soc_states_show, inode->i_private);
 
 
 
 
 
 
 
 
 
 
 
 
 706}
 707
 708static const struct file_operations telem_socstate_ops = {
 709	.open		= telem_soc_state_open,
 710	.read		= seq_read,
 711	.llseek		= seq_lseek,
 712	.release	= single_release,
 713};
 714
 715static int telem_pss_trc_verb_show(struct seq_file *s, void *unused)
 716{
 717	u32 verbosity;
 718	int err;
 719
 720	err = telemetry_get_trace_verbosity(TELEM_PSS, &verbosity);
 721	if (err) {
 722		pr_err("Get PSS Trace Verbosity Failed with Error %d\n", err);
 723		return -EFAULT;
 724	}
 725
 726	seq_printf(s, "PSS Trace Verbosity %u\n", verbosity);
 727	return 0;
 728}
 729
 730static ssize_t telem_pss_trc_verb_write(struct file *file,
 731					const char __user *userbuf,
 732					size_t count, loff_t *ppos)
 733{
 734	u32 verbosity;
 735	int err;
 736
 737	if (kstrtou32_from_user(userbuf, count, 0, &verbosity))
 738		return -EFAULT;
 
 739
 740	err = telemetry_set_trace_verbosity(TELEM_PSS, verbosity);
 741	if (err) {
 742		pr_err("Changing PSS Trace Verbosity Failed. Error %d\n", err);
 743		count = err;
 744	}
 745
 746	return count;
 747}
 748
 749static int telem_pss_trc_verb_open(struct inode *inode, struct file *file)
 750{
 751	return single_open(file, telem_pss_trc_verb_show, inode->i_private);
 752}
 753
 754static const struct file_operations telem_pss_trc_verb_ops = {
 755	.open		= telem_pss_trc_verb_open,
 756	.read		= seq_read,
 757	.write		= telem_pss_trc_verb_write,
 758	.llseek		= seq_lseek,
 759	.release	= single_release,
 760};
 761
 762
 763static int telem_ioss_trc_verb_show(struct seq_file *s, void *unused)
 764{
 765	u32 verbosity;
 766	int err;
 767
 768	err = telemetry_get_trace_verbosity(TELEM_IOSS, &verbosity);
 769	if (err) {
 770		pr_err("Get IOSS Trace Verbosity Failed with Error %d\n", err);
 771		return -EFAULT;
 772	}
 773
 774	seq_printf(s, "IOSS Trace Verbosity %u\n", verbosity);
 775	return 0;
 776}
 777
 778static ssize_t telem_ioss_trc_verb_write(struct file *file,
 779					 const char __user *userbuf,
 780					 size_t count, loff_t *ppos)
 781{
 782	u32 verbosity;
 783	int err;
 784
 785	if (kstrtou32_from_user(userbuf, count, 0, &verbosity))
 786		return -EFAULT;
 
 787
 788	err = telemetry_set_trace_verbosity(TELEM_IOSS, verbosity);
 789	if (err) {
 790		pr_err("Changing IOSS Trace Verbosity Failed. Error %d\n", err);
 791		count = err;
 792	}
 793
 794	return count;
 795}
 796
 797static int telem_ioss_trc_verb_open(struct inode *inode, struct file *file)
 798{
 799	return single_open(file, telem_ioss_trc_verb_show, inode->i_private);
 800}
 801
 802static const struct file_operations telem_ioss_trc_verb_ops = {
 803	.open		= telem_ioss_trc_verb_open,
 804	.read		= seq_read,
 805	.write		= telem_ioss_trc_verb_write,
 806	.llseek		= seq_lseek,
 807	.release	= single_release,
 808};
 809
 810#ifdef CONFIG_PM_SLEEP
 811static int pm_suspend_prep_cb(void)
 812{
 813	struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
 814	struct telemetry_debugfs_conf *conf = debugfs_conf;
 815	int ret, index;
 816
 817	ret = telemetry_raw_read_eventlog(TELEM_IOSS, evtlog,
 818			TELEM_MAX_OS_ALLOCATED_EVENTS);
 819	if (ret < 0) {
 820		suspend_prep_ok = 0;
 821		goto out;
 822	}
 823
 824	for (index = 0; index < ret; index++) {
 825
 826		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id,
 827					   suspend_shlw_ctr_temp);
 828
 829		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id,
 830					   suspend_deep_ctr_temp);
 831
 832		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id,
 833					   suspend_shlw_res_temp);
 834
 835		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id,
 836					   suspend_deep_res_temp);
 837	}
 838	suspend_prep_ok = 1;
 839out:
 840	return NOTIFY_OK;
 841}
 842
 843static int pm_suspend_exit_cb(void)
 844{
 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;
 849	int ret, index;
 850
 851	if (!suspend_prep_ok)
 852		goto out;
 853
 854	ret = telemetry_raw_read_eventlog(TELEM_IOSS, evtlog,
 855					  TELEM_MAX_OS_ALLOCATED_EVENTS);
 856	if (ret < 0)
 857		goto out;
 858
 859	for (index = 0; index < ret; index++) {
 860		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id,
 861					   suspend_shlw_ctr_exit);
 862
 863		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id,
 864					   suspend_deep_ctr_exit);
 865
 866		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id,
 867					   suspend_shlw_res_exit);
 868
 869		TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id,
 870					   suspend_deep_res_exit);
 871	}
 872
 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");
 878		goto out;
 879	}
 880
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 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;
 885
 886	if (suspend_shlw_ctr_exit == 1) {
 887		conf->suspend_stats.shlw_ctr +=
 888		suspend_shlw_ctr_exit;
 889
 890		conf->suspend_stats.shlw_res +=
 891		suspend_shlw_res_exit;
 892	}
 893	/* Shallow Wakes Case */
 894	else if (suspend_shlw_ctr_exit > 1) {
 895		conf->suspend_stats.shlw_swake_ctr +=
 896		suspend_shlw_ctr_exit;
 897
 898		conf->suspend_stats.shlw_swake_res +=
 899		suspend_shlw_res_exit;
 900	}
 901
 902	if (suspend_deep_ctr_exit == 1) {
 903		conf->suspend_stats.deep_ctr +=
 904		suspend_deep_ctr_exit;
 905
 906		conf->suspend_stats.deep_res +=
 907		suspend_deep_res_exit;
 908	}
 909
 910	/* Shallow Wakes Case */
 911	else if (suspend_deep_ctr_exit > 1) {
 912		conf->suspend_stats.deep_swake_ctr +=
 913		suspend_deep_ctr_exit;
 914
 915		conf->suspend_stats.deep_swake_res +=
 916		suspend_deep_res_exit;
 917	}
 918
 919out:
 920	suspend_prep_ok = 0;
 921	return NOTIFY_OK;
 922}
 923
 924static int pm_notification(struct notifier_block *this,
 925			   unsigned long event, void *ptr)
 926{
 927	switch (event) {
 928	case PM_SUSPEND_PREPARE:
 929		return pm_suspend_prep_cb();
 930	case PM_POST_SUSPEND:
 931		return pm_suspend_exit_cb();
 932	}
 933
 934	return NOTIFY_DONE;
 935}
 936
 937static struct notifier_block pm_notifier = {
 938	.notifier_call = pm_notification,
 939};
 940#endif /* CONFIG_PM_SLEEP */
 941
 942static int __init telemetry_debugfs_init(void)
 943{
 944	const struct x86_cpu_id *id;
 945	int err = -ENOMEM;
 946	struct dentry *f;
 947
 948	/* Only APL supported for now */
 949	id = x86_match_cpu(telemetry_debugfs_cpu_ids);
 950	if (!id)
 951		return -ENODEV;
 952
 953	debugfs_conf = (struct telemetry_debugfs_conf *)id->driver_data;
 954
 955	err = telemetry_pltconfig_valid();
 956	if (err < 0)
 957		return -ENODEV;
 
 958
 959	err = telemetry_debugfs_check_evts();
 960	if (err < 0)
 
 961		return -EINVAL;
 
 962
 963
 964#ifdef CONFIG_PM_SLEEP
 965	register_pm_notifier(&pm_notifier);
 966#endif /* CONFIG_PM_SLEEP */
 967
 968	debugfs_conf->telemetry_dbg_dir = debugfs_create_dir("telemetry", NULL);
 969	if (!debugfs_conf->telemetry_dbg_dir)
 970		return -ENOMEM;
 971
 972	f = debugfs_create_file("pss_info", S_IFREG | S_IRUGO,
 973				debugfs_conf->telemetry_dbg_dir, NULL,
 974				&telem_pss_ops);
 975	if (!f) {
 976		pr_err("pss_sample_info debugfs register failed\n");
 977		goto out;
 978	}
 979
 980	f = debugfs_create_file("ioss_info", S_IFREG | S_IRUGO,
 981				debugfs_conf->telemetry_dbg_dir, NULL,
 982				&telem_ioss_ops);
 983	if (!f) {
 984		pr_err("ioss_sample_info debugfs register failed\n");
 985		goto out;
 986	}
 987
 988	f = debugfs_create_file("soc_states", S_IFREG | S_IRUGO,
 989				debugfs_conf->telemetry_dbg_dir,
 990				NULL, &telem_socstate_ops);
 991	if (!f) {
 992		pr_err("ioss_sample_info debugfs register failed\n");
 993		goto out;
 994	}
 995
 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);
 999	if (!f) {
1000		pr_err("pss_trace_verbosity debugfs register failed\n");
1001		goto out;
1002	}
1003
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);
1007	if (!f) {
1008		pr_err("ioss_trace_verbosity debugfs register failed\n");
1009		goto out;
1010	}
1011
 
 
 
 
 
 
 
 
 
 
 
 
1012	return 0;
1013
1014out:
1015	debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir);
1016	debugfs_conf->telemetry_dbg_dir = NULL;
1017
1018	return err;
1019}
1020
1021static void __exit telemetry_debugfs_exit(void)
1022{
1023	debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir);
1024	debugfs_conf->telemetry_dbg_dir = NULL;
 
1025}
1026
1027late_initcall(telemetry_debugfs_init);
1028module_exit(telemetry_debugfs_exit);
1029
1030MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
1031MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface");
1032MODULE_VERSION(DRIVER_VERSION);
1033MODULE_LICENSE("GPL");