intel_telemetry_debugfs.c 28 KB

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