intel_telemetry_debugfs.c 28 KB

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