debugfs.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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. #include <asm/cpu_device_id.h>
  24. #include <asm/intel-family.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. X86_MATCH_VFM(INTEL_ATOM_GOLDMONT, &telem_apl_debugfs_conf),
  280. X86_MATCH_VFM(INTEL_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. DEFINE_SHOW_ATTRIBUTE(telem_pss_states);
  415. static int telem_ioss_states_show(struct seq_file *s, void *unused)
  416. {
  417. struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
  418. const char *name[TELEM_MAX_OS_ALLOCATED_EVENTS];
  419. int index, ret, err;
  420. ret = telemetry_read_eventlog(TELEM_IOSS, evtlog,
  421. TELEM_MAX_OS_ALLOCATED_EVENTS);
  422. if (ret < 0)
  423. return ret;
  424. err = telemetry_get_evtname(TELEM_IOSS, name,
  425. TELEM_MAX_OS_ALLOCATED_EVENTS);
  426. if (err < 0)
  427. return err;
  428. seq_puts(s, "--------------------------------------\n");
  429. seq_puts(s, "\tI0SS TELEMETRY EVENTLOG\n");
  430. seq_puts(s, "--------------------------------------\n");
  431. for (index = 0; index < ret; index++) {
  432. seq_printf(s, "%-32s 0x%llx\n",
  433. name[index], evtlog[index].telem_evtlog);
  434. }
  435. return 0;
  436. }
  437. DEFINE_SHOW_ATTRIBUTE(telem_ioss_states);
  438. static int telem_soc_states_show(struct seq_file *s, void *unused)
  439. {
  440. u32 d3_sts[TELEM_IOSS_DX_D0IX_EVTS], d0ix_sts[TELEM_IOSS_DX_D0IX_EVTS];
  441. u32 pg_sts[TELEM_IOSS_PG_EVTS], pss_idle[TELEM_PSS_IDLE_EVTS];
  442. struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
  443. u32 s0ix_total_ctr = 0, s0ix_shlw_ctr = 0, s0ix_deep_ctr = 0;
  444. u64 s0ix_total_res = 0, s0ix_shlw_res = 0, s0ix_deep_res = 0;
  445. struct telemetry_debugfs_conf *conf = debugfs_conf;
  446. struct pci_dev *dev = NULL;
  447. int index, idx, ret;
  448. u32 d3_state;
  449. u16 pmcsr;
  450. ret = telemetry_read_eventlog(TELEM_IOSS, evtlog,
  451. TELEM_MAX_OS_ALLOCATED_EVENTS);
  452. if (ret < 0)
  453. return ret;
  454. for (index = 0; index < ret; index++) {
  455. TELEM_CHECK_AND_PARSE_EVTS(conf->ioss_d3_id,
  456. conf->ioss_d0ix_evts,
  457. d3_sts, evtlog[index].telem_evtlog,
  458. conf->ioss_d0ix_data,
  459. TELEM_MASK_BIT);
  460. TELEM_CHECK_AND_PARSE_EVTS(conf->ioss_pg_id, conf->ioss_pg_evts,
  461. pg_sts, evtlog[index].telem_evtlog,
  462. conf->ioss_pg_data, TELEM_MASK_BIT);
  463. TELEM_CHECK_AND_PARSE_EVTS(conf->ioss_d0ix_id,
  464. conf->ioss_d0ix_evts,
  465. d0ix_sts, evtlog[index].telem_evtlog,
  466. conf->ioss_d0ix_data,
  467. TELEM_MASK_BIT);
  468. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_total_occ_id,
  469. s0ix_total_ctr);
  470. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id,
  471. s0ix_shlw_ctr);
  472. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id,
  473. s0ix_deep_ctr);
  474. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_total_res_id,
  475. s0ix_total_res);
  476. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id,
  477. s0ix_shlw_res);
  478. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id,
  479. s0ix_deep_res);
  480. }
  481. seq_puts(s, "\n---------------------------------------------------\n");
  482. seq_puts(s, "S0IX Type\t\t\t Occurrence\t\t Residency(us)\n");
  483. seq_puts(s, "---------------------------------------------------\n");
  484. seq_printf(s, "S0IX Shallow\t\t\t %10u\t %10llu\n",
  485. s0ix_shlw_ctr -
  486. conf->suspend_stats.shlw_ctr,
  487. (u64)((s0ix_shlw_res -
  488. conf->suspend_stats.shlw_res)*10/192));
  489. seq_printf(s, "S0IX Deep\t\t\t %10u\t %10llu\n",
  490. s0ix_deep_ctr -
  491. conf->suspend_stats.deep_ctr,
  492. (u64)((s0ix_deep_res -
  493. conf->suspend_stats.deep_res)*10/192));
  494. seq_printf(s, "Suspend(With S0ixShallow)\t %10u\t %10llu\n",
  495. conf->suspend_stats.shlw_ctr,
  496. (u64)(conf->suspend_stats.shlw_res*10)/192);
  497. seq_printf(s, "Suspend(With S0ixDeep)\t\t %10u\t %10llu\n",
  498. conf->suspend_stats.deep_ctr,
  499. (u64)(conf->suspend_stats.deep_res*10)/192);
  500. seq_printf(s, "TOTAL S0IX\t\t\t %10u\t %10llu\n", s0ix_total_ctr,
  501. (u64)(s0ix_total_res*10/192));
  502. seq_puts(s, "\n-------------------------------------------------\n");
  503. seq_puts(s, "\t\tDEVICE STATES\n");
  504. seq_puts(s, "-------------------------------------------------\n");
  505. for_each_pci_dev(dev) {
  506. pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
  507. d3_state = ((pmcsr & PCI_PM_CTRL_STATE_MASK) ==
  508. (__force int)PCI_D3hot) ? 1 : 0;
  509. seq_printf(s, "pci %04x %04X %s %20.20s: ",
  510. dev->vendor, dev->device, dev_name(&dev->dev),
  511. dev_driver_string(&dev->dev));
  512. seq_printf(s, " d3:%x\n", d3_state);
  513. }
  514. seq_puts(s, "\n--------------------------------------\n");
  515. seq_puts(s, "D3/D0i3 Status\n");
  516. seq_puts(s, "--------------------------------------\n");
  517. seq_puts(s, "Block\t\t D3\t D0i3\n");
  518. for (index = 0; index < conf->ioss_d0ix_evts; index++) {
  519. seq_printf(s, "%-10s\t %u\t %u\n",
  520. conf->ioss_d0ix_data[index].name,
  521. d3_sts[index], d0ix_sts[index]);
  522. }
  523. seq_puts(s, "\n--------------------------------------\n");
  524. seq_puts(s, "South Complex PowerGate Status\n");
  525. seq_puts(s, "--------------------------------------\n");
  526. seq_puts(s, "Device\t\t PG\n");
  527. for (index = 0; index < conf->ioss_pg_evts; index++) {
  528. seq_printf(s, "%-10s\t %u\n",
  529. conf->ioss_pg_data[index].name,
  530. pg_sts[index]);
  531. }
  532. evtlog->telem_evtid = conf->pss_idle_id;
  533. ret = telemetry_read_events(TELEM_PSS, evtlog, 1);
  534. if (ret < 0)
  535. return ret;
  536. seq_puts(s, "\n-----------------------------------------\n");
  537. seq_puts(s, "North Idle Status\n");
  538. seq_puts(s, "-----------------------------------------\n");
  539. for (idx = 0; idx < conf->pss_idle_evts - 1; idx++) {
  540. pss_idle[idx] = (evtlog->telem_evtlog >>
  541. conf->pss_idle_data[idx].bit_pos) &
  542. TELEM_MASK_BIT;
  543. }
  544. pss_idle[idx] = (evtlog->telem_evtlog >>
  545. conf->pss_idle_data[idx].bit_pos) &
  546. TELEM_APL_MASK_PCS_STATE;
  547. for (index = 0; index < conf->pss_idle_evts; index++) {
  548. seq_printf(s, "%-30s %u\n",
  549. conf->pss_idle_data[index].name,
  550. pss_idle[index]);
  551. }
  552. seq_puts(s, "\nPCS_STATUS Code\n");
  553. seq_puts(s, "0:C0 1:C1 2:C1_DN_WT_DEV 3:C2 4:C2_WT_DE_MEM_UP\n");
  554. seq_puts(s, "5:C2_WT_DE_MEM_DOWN 6:C2_UP_WT_DEV 7:C2_DN 8:C2_VOA\n");
  555. seq_puts(s, "9:C2_VOA_UP 10:S0IX_PRE 11:S0IX\n");
  556. return 0;
  557. }
  558. DEFINE_SHOW_ATTRIBUTE(telem_soc_states);
  559. static int telem_s0ix_res_get(void *data, u64 *val)
  560. {
  561. struct telemetry_plt_config *plt_config = telemetry_get_pltdata();
  562. u64 s0ix_total_res;
  563. int ret;
  564. ret = intel_pmc_s0ix_counter_read(plt_config->pmc, &s0ix_total_res);
  565. if (ret) {
  566. pr_err("Failed to read S0ix residency");
  567. return ret;
  568. }
  569. *val = s0ix_total_res;
  570. return 0;
  571. }
  572. DEFINE_DEBUGFS_ATTRIBUTE(telem_s0ix_fops, telem_s0ix_res_get, NULL, "%llu\n");
  573. static int telem_pss_trc_verb_show(struct seq_file *s, void *unused)
  574. {
  575. u32 verbosity;
  576. int err;
  577. err = telemetry_get_trace_verbosity(TELEM_PSS, &verbosity);
  578. if (err) {
  579. pr_err("Get PSS Trace Verbosity Failed with Error %d\n", err);
  580. return -EFAULT;
  581. }
  582. seq_printf(s, "PSS Trace Verbosity %u\n", verbosity);
  583. return 0;
  584. }
  585. static ssize_t telem_pss_trc_verb_write(struct file *file,
  586. const char __user *userbuf,
  587. size_t count, loff_t *ppos)
  588. {
  589. u32 verbosity;
  590. int err;
  591. err = kstrtou32_from_user(userbuf, count, 0, &verbosity);
  592. if (err)
  593. return err;
  594. err = telemetry_set_trace_verbosity(TELEM_PSS, verbosity);
  595. if (err) {
  596. pr_err("Changing PSS Trace Verbosity Failed. Error %d\n", err);
  597. return err;
  598. }
  599. return count;
  600. }
  601. static int telem_pss_trc_verb_open(struct inode *inode, struct file *file)
  602. {
  603. return single_open(file, telem_pss_trc_verb_show, inode->i_private);
  604. }
  605. static const struct file_operations telem_pss_trc_verb_ops = {
  606. .open = telem_pss_trc_verb_open,
  607. .read = seq_read,
  608. .write = telem_pss_trc_verb_write,
  609. .llseek = seq_lseek,
  610. .release = single_release,
  611. };
  612. static int telem_ioss_trc_verb_show(struct seq_file *s, void *unused)
  613. {
  614. u32 verbosity;
  615. int err;
  616. err = telemetry_get_trace_verbosity(TELEM_IOSS, &verbosity);
  617. if (err) {
  618. pr_err("Get IOSS Trace Verbosity Failed with Error %d\n", err);
  619. return -EFAULT;
  620. }
  621. seq_printf(s, "IOSS Trace Verbosity %u\n", verbosity);
  622. return 0;
  623. }
  624. static ssize_t telem_ioss_trc_verb_write(struct file *file,
  625. const char __user *userbuf,
  626. size_t count, loff_t *ppos)
  627. {
  628. u32 verbosity;
  629. int err;
  630. err = kstrtou32_from_user(userbuf, count, 0, &verbosity);
  631. if (err)
  632. return err;
  633. err = telemetry_set_trace_verbosity(TELEM_IOSS, verbosity);
  634. if (err) {
  635. pr_err("Changing IOSS Trace Verbosity Failed. Error %d\n", err);
  636. return err;
  637. }
  638. return count;
  639. }
  640. static int telem_ioss_trc_verb_open(struct inode *inode, struct file *file)
  641. {
  642. return single_open(file, telem_ioss_trc_verb_show, inode->i_private);
  643. }
  644. static const struct file_operations telem_ioss_trc_verb_ops = {
  645. .open = telem_ioss_trc_verb_open,
  646. .read = seq_read,
  647. .write = telem_ioss_trc_verb_write,
  648. .llseek = seq_lseek,
  649. .release = single_release,
  650. };
  651. static int pm_suspend_prep_cb(void)
  652. {
  653. struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
  654. struct telemetry_debugfs_conf *conf = debugfs_conf;
  655. int ret, index;
  656. ret = telemetry_raw_read_eventlog(TELEM_IOSS, evtlog,
  657. TELEM_MAX_OS_ALLOCATED_EVENTS);
  658. if (ret < 0) {
  659. suspend_prep_ok = 0;
  660. goto out;
  661. }
  662. for (index = 0; index < ret; index++) {
  663. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id,
  664. suspend_shlw_ctr_temp);
  665. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id,
  666. suspend_deep_ctr_temp);
  667. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id,
  668. suspend_shlw_res_temp);
  669. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id,
  670. suspend_deep_res_temp);
  671. }
  672. suspend_prep_ok = 1;
  673. out:
  674. return NOTIFY_OK;
  675. }
  676. static int pm_suspend_exit_cb(void)
  677. {
  678. struct telemetry_evtlog evtlog[TELEM_MAX_OS_ALLOCATED_EVENTS];
  679. static u32 suspend_shlw_ctr_exit, suspend_deep_ctr_exit;
  680. static u64 suspend_shlw_res_exit, suspend_deep_res_exit;
  681. struct telemetry_debugfs_conf *conf = debugfs_conf;
  682. int ret, index;
  683. if (!suspend_prep_ok)
  684. goto out;
  685. ret = telemetry_raw_read_eventlog(TELEM_IOSS, evtlog,
  686. TELEM_MAX_OS_ALLOCATED_EVENTS);
  687. if (ret < 0)
  688. goto out;
  689. for (index = 0; index < ret; index++) {
  690. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_occ_id,
  691. suspend_shlw_ctr_exit);
  692. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_occ_id,
  693. suspend_deep_ctr_exit);
  694. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_shlw_res_id,
  695. suspend_shlw_res_exit);
  696. TELEM_CHECK_AND_PARSE_CTRS(conf->s0ix_deep_res_id,
  697. suspend_deep_res_exit);
  698. }
  699. if ((suspend_shlw_ctr_exit < suspend_shlw_ctr_temp) ||
  700. (suspend_deep_ctr_exit < suspend_deep_ctr_temp) ||
  701. (suspend_shlw_res_exit < suspend_shlw_res_temp) ||
  702. (suspend_deep_res_exit < suspend_deep_res_temp)) {
  703. pr_err("Wrong s0ix counters detected\n");
  704. goto out;
  705. }
  706. /*
  707. * Due to some design limitations in the firmware, sometimes the
  708. * counters do not get updated by the time we reach here. As a
  709. * workaround, we try to see if this was a genuine case of sleep
  710. * failure or not by cross-checking from PMC GCR registers directly.
  711. */
  712. if (suspend_shlw_ctr_exit == suspend_shlw_ctr_temp &&
  713. suspend_deep_ctr_exit == suspend_deep_ctr_temp) {
  714. struct telemetry_plt_config *plt_config = telemetry_get_pltdata();
  715. struct intel_pmc_dev *pmc = plt_config->pmc;
  716. ret = intel_pmc_gcr_read64(pmc, PMC_GCR_TELEM_SHLW_S0IX_REG,
  717. &suspend_shlw_res_exit);
  718. if (ret < 0)
  719. goto out;
  720. ret = intel_pmc_gcr_read64(pmc, PMC_GCR_TELEM_DEEP_S0IX_REG,
  721. &suspend_deep_res_exit);
  722. if (ret < 0)
  723. goto out;
  724. if (suspend_shlw_res_exit > suspend_shlw_res_temp)
  725. suspend_shlw_ctr_exit++;
  726. if (suspend_deep_res_exit > suspend_deep_res_temp)
  727. suspend_deep_ctr_exit++;
  728. }
  729. suspend_shlw_ctr_exit -= suspend_shlw_ctr_temp;
  730. suspend_deep_ctr_exit -= suspend_deep_ctr_temp;
  731. suspend_shlw_res_exit -= suspend_shlw_res_temp;
  732. suspend_deep_res_exit -= suspend_deep_res_temp;
  733. if (suspend_shlw_ctr_exit != 0) {
  734. conf->suspend_stats.shlw_ctr +=
  735. suspend_shlw_ctr_exit;
  736. conf->suspend_stats.shlw_res +=
  737. suspend_shlw_res_exit;
  738. }
  739. if (suspend_deep_ctr_exit != 0) {
  740. conf->suspend_stats.deep_ctr +=
  741. suspend_deep_ctr_exit;
  742. conf->suspend_stats.deep_res +=
  743. suspend_deep_res_exit;
  744. }
  745. out:
  746. suspend_prep_ok = 0;
  747. return NOTIFY_OK;
  748. }
  749. static int pm_notification(struct notifier_block *this,
  750. unsigned long event, void *ptr)
  751. {
  752. switch (event) {
  753. case PM_SUSPEND_PREPARE:
  754. return pm_suspend_prep_cb();
  755. case PM_POST_SUSPEND:
  756. return pm_suspend_exit_cb();
  757. }
  758. return NOTIFY_DONE;
  759. }
  760. static struct notifier_block pm_notifier = {
  761. .notifier_call = pm_notification,
  762. };
  763. static int __init telemetry_debugfs_init(void)
  764. {
  765. const struct x86_cpu_id *id;
  766. int err;
  767. struct dentry *dir;
  768. /* Only APL supported for now */
  769. id = x86_match_cpu(telemetry_debugfs_cpu_ids);
  770. if (!id)
  771. return -ENODEV;
  772. debugfs_conf = (struct telemetry_debugfs_conf *)id->driver_data;
  773. if (!telemetry_get_pltdata()) {
  774. pr_info("Invalid pltconfig, ensure IPC1 device is enabled in BIOS\n");
  775. return -ENODEV;
  776. }
  777. err = telemetry_debugfs_check_evts();
  778. if (err < 0) {
  779. pr_info("telemetry_debugfs_check_evts failed\n");
  780. return -EINVAL;
  781. }
  782. register_pm_notifier(&pm_notifier);
  783. dir = debugfs_create_dir("telemetry", NULL);
  784. debugfs_conf->telemetry_dbg_dir = dir;
  785. debugfs_create_file("pss_info", S_IFREG | S_IRUGO, dir, NULL,
  786. &telem_pss_states_fops);
  787. debugfs_create_file("ioss_info", S_IFREG | S_IRUGO, dir, NULL,
  788. &telem_ioss_states_fops);
  789. debugfs_create_file("soc_states", S_IFREG | S_IRUGO, dir, NULL,
  790. &telem_soc_states_fops);
  791. debugfs_create_file("s0ix_residency_usec", S_IFREG | S_IRUGO, dir, NULL,
  792. &telem_s0ix_fops);
  793. debugfs_create_file("pss_trace_verbosity", S_IFREG | S_IRUGO, dir, NULL,
  794. &telem_pss_trc_verb_ops);
  795. debugfs_create_file("ioss_trace_verbosity", S_IFREG | S_IRUGO, dir,
  796. NULL, &telem_ioss_trc_verb_ops);
  797. return 0;
  798. }
  799. static void __exit telemetry_debugfs_exit(void)
  800. {
  801. debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir);
  802. debugfs_conf->telemetry_dbg_dir = NULL;
  803. unregister_pm_notifier(&pm_notifier);
  804. }
  805. late_initcall(telemetry_debugfs_init);
  806. module_exit(telemetry_debugfs_exit);
  807. MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
  808. MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface");
  809. MODULE_VERSION(DRIVER_VERSION);
  810. MODULE_LICENSE("GPL v2");