intel_telemetry_debugfs.c 29 KB

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