intel_telemetry_debugfs.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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. return -ENODEV;
  808. err = telemetry_debugfs_check_evts();
  809. if (err < 0)
  810. return -EINVAL;
  811. register_pm_notifier(&pm_notifier);
  812. err = -ENOMEM;
  813. debugfs_conf->telemetry_dbg_dir = debugfs_create_dir("telemetry", NULL);
  814. if (!debugfs_conf->telemetry_dbg_dir)
  815. goto out_pm;
  816. f = debugfs_create_file("pss_info", S_IFREG | S_IRUGO,
  817. debugfs_conf->telemetry_dbg_dir, NULL,
  818. &telem_pss_ops);
  819. if (!f) {
  820. pr_err("pss_sample_info debugfs register failed\n");
  821. goto out;
  822. }
  823. f = debugfs_create_file("ioss_info", S_IFREG | S_IRUGO,
  824. debugfs_conf->telemetry_dbg_dir, NULL,
  825. &telem_ioss_ops);
  826. if (!f) {
  827. pr_err("ioss_sample_info debugfs register failed\n");
  828. goto out;
  829. }
  830. f = debugfs_create_file("soc_states", S_IFREG | S_IRUGO,
  831. debugfs_conf->telemetry_dbg_dir,
  832. NULL, &telem_socstate_ops);
  833. if (!f) {
  834. pr_err("ioss_sample_info debugfs register failed\n");
  835. goto out;
  836. }
  837. f = debugfs_create_file("s0ix_residency_usec", S_IFREG | S_IRUGO,
  838. debugfs_conf->telemetry_dbg_dir,
  839. NULL, &telem_s0ix_fops);
  840. if (!f) {
  841. pr_err("s0ix_residency_usec debugfs register failed\n");
  842. goto out;
  843. }
  844. f = debugfs_create_file("pss_trace_verbosity", S_IFREG | S_IRUGO,
  845. debugfs_conf->telemetry_dbg_dir, NULL,
  846. &telem_pss_trc_verb_ops);
  847. if (!f) {
  848. pr_err("pss_trace_verbosity debugfs register failed\n");
  849. goto out;
  850. }
  851. f = debugfs_create_file("ioss_trace_verbosity", S_IFREG | S_IRUGO,
  852. debugfs_conf->telemetry_dbg_dir, NULL,
  853. &telem_ioss_trc_verb_ops);
  854. if (!f) {
  855. pr_err("ioss_trace_verbosity debugfs register failed\n");
  856. goto out;
  857. }
  858. return 0;
  859. out:
  860. debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir);
  861. debugfs_conf->telemetry_dbg_dir = NULL;
  862. out_pm:
  863. unregister_pm_notifier(&pm_notifier);
  864. return err;
  865. }
  866. static void __exit telemetry_debugfs_exit(void)
  867. {
  868. debugfs_remove_recursive(debugfs_conf->telemetry_dbg_dir);
  869. debugfs_conf->telemetry_dbg_dir = NULL;
  870. unregister_pm_notifier(&pm_notifier);
  871. }
  872. late_initcall(telemetry_debugfs_init);
  873. module_exit(telemetry_debugfs_exit);
  874. MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
  875. MODULE_DESCRIPTION("Intel SoC Telemetry debugfs Interface");
  876. MODULE_VERSION(DRIVER_VERSION);
  877. MODULE_LICENSE("GPL");