intel_telemetry_pltdrv.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. /*
  2. * Intel SOC Telemetry Platform 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 platform specific telemetry implementation for APL.
  16. * It used the PUNIT and PMC IPC interfaces for configuring the counters.
  17. * The accumulated results are fetched from SRAM.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/device.h>
  22. #include <linux/debugfs.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/io.h>
  25. #include <linux/uaccess.h>
  26. #include <linux/pci.h>
  27. #include <linux/suspend.h>
  28. #include <linux/platform_device.h>
  29. #include <asm/cpu_device_id.h>
  30. #include <asm/intel-family.h>
  31. #include <asm/intel_pmc_ipc.h>
  32. #include <asm/intel_punit_ipc.h>
  33. #include <asm/intel_telemetry.h>
  34. #define DRIVER_NAME "intel_telemetry"
  35. #define DRIVER_VERSION "1.0.0"
  36. #define TELEM_TRC_VERBOSITY_MASK 0x3
  37. #define TELEM_MIN_PERIOD(x) ((x) & 0x7F0000)
  38. #define TELEM_MAX_PERIOD(x) ((x) & 0x7F000000)
  39. #define TELEM_SAMPLE_PERIOD_INVALID(x) ((x) & (BIT(7)))
  40. #define TELEM_CLEAR_SAMPLE_PERIOD(x) ((x) &= ~0x7F)
  41. #define TELEM_SAMPLING_DEFAULT_PERIOD 0xD
  42. #define TELEM_MAX_EVENTS_SRAM 28
  43. #define TELEM_SSRAM_STARTTIME_OFFSET 8
  44. #define TELEM_SSRAM_EVTLOG_OFFSET 16
  45. #define IOSS_TELEM_EVENT_READ 0x0
  46. #define IOSS_TELEM_EVENT_WRITE 0x1
  47. #define IOSS_TELEM_INFO_READ 0x2
  48. #define IOSS_TELEM_TRACE_CTL_READ 0x5
  49. #define IOSS_TELEM_TRACE_CTL_WRITE 0x6
  50. #define IOSS_TELEM_EVENT_CTL_READ 0x7
  51. #define IOSS_TELEM_EVENT_CTL_WRITE 0x8
  52. #define IOSS_TELEM_EVT_CTRL_WRITE_SIZE 0x4
  53. #define IOSS_TELEM_READ_WORD 0x1
  54. #define IOSS_TELEM_WRITE_FOURBYTES 0x4
  55. #define IOSS_TELEM_EVT_WRITE_SIZE 0x3
  56. #define TELEM_INFO_SRAMEVTS_MASK 0xFF00
  57. #define TELEM_INFO_SRAMEVTS_SHIFT 0x8
  58. #define TELEM_SSRAM_READ_TIMEOUT 10
  59. #define TELEM_INFO_NENABLES_MASK 0xFF
  60. #define TELEM_EVENT_ENABLE 0x8000
  61. #define TELEM_MASK_BIT 1
  62. #define TELEM_MASK_BYTE 0xFF
  63. #define BYTES_PER_LONG 8
  64. #define TELEM_MASK_PCS_STATE 0xF
  65. #define TELEM_DISABLE(x) ((x) &= ~(BIT(31)))
  66. #define TELEM_CLEAR_EVENTS(x) ((x) |= (BIT(30)))
  67. #define TELEM_ENABLE_SRAM_EVT_TRACE(x) ((x) &= ~(BIT(30) | BIT(24)))
  68. #define TELEM_ENABLE_PERIODIC(x) ((x) |= (BIT(23) | BIT(31) | BIT(7)))
  69. #define TELEM_EXTRACT_VERBOSITY(x, y) ((y) = (((x) >> 27) & 0x3))
  70. #define TELEM_CLEAR_VERBOSITY_BITS(x) ((x) &= ~(BIT(27) | BIT(28)))
  71. #define TELEM_SET_VERBOSITY_BITS(x, y) ((x) |= ((y) << 27))
  72. #define TELEM_CPU(model, data) \
  73. { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&data }
  74. enum telemetry_action {
  75. TELEM_UPDATE = 0,
  76. TELEM_ADD,
  77. TELEM_RESET,
  78. TELEM_ACTION_NONE
  79. };
  80. struct telem_ssram_region {
  81. u64 timestamp;
  82. u64 start_time;
  83. u64 events[TELEM_MAX_EVENTS_SRAM];
  84. };
  85. static struct telemetry_plt_config *telm_conf;
  86. /*
  87. * The following counters are programmed by default during setup.
  88. * Only 20 allocated to kernel driver
  89. */
  90. static struct telemetry_evtmap
  91. telemetry_apl_ioss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
  92. {"SOC_S0IX_TOTAL_RES", 0x4800},
  93. {"SOC_S0IX_TOTAL_OCC", 0x4000},
  94. {"SOC_S0IX_SHALLOW_RES", 0x4801},
  95. {"SOC_S0IX_SHALLOW_OCC", 0x4001},
  96. {"SOC_S0IX_DEEP_RES", 0x4802},
  97. {"SOC_S0IX_DEEP_OCC", 0x4002},
  98. {"PMC_POWER_GATE", 0x5818},
  99. {"PMC_D3_STATES", 0x5819},
  100. {"PMC_D0I3_STATES", 0x581A},
  101. {"PMC_S0IX_WAKE_REASON_GPIO", 0x6000},
  102. {"PMC_S0IX_WAKE_REASON_TIMER", 0x6001},
  103. {"PMC_S0IX_WAKE_REASON_VNNREQ", 0x6002},
  104. {"PMC_S0IX_WAKE_REASON_LOWPOWER", 0x6003},
  105. {"PMC_S0IX_WAKE_REASON_EXTERNAL", 0x6004},
  106. {"PMC_S0IX_WAKE_REASON_MISC", 0x6005},
  107. {"PMC_S0IX_BLOCKING_IPS_D3_D0I3", 0x6006},
  108. {"PMC_S0IX_BLOCKING_IPS_PG", 0x6007},
  109. {"PMC_S0IX_BLOCKING_MISC_IPS_PG", 0x6008},
  110. {"PMC_S0IX_BLOCK_IPS_VNN_REQ", 0x6009},
  111. {"PMC_S0IX_BLOCK_IPS_CLOCKS", 0x600B},
  112. };
  113. static struct telemetry_evtmap
  114. telemetry_apl_pss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
  115. {"IA_CORE0_C6_RES", 0x0400},
  116. {"IA_CORE0_C6_CTR", 0x0000},
  117. {"IA_MODULE0_C7_RES", 0x0410},
  118. {"IA_MODULE0_C7_CTR", 0x000E},
  119. {"IA_C0_RES", 0x0805},
  120. {"PCS_LTR", 0x2801},
  121. {"PSTATES", 0x2802},
  122. {"SOC_S0I3_RES", 0x0409},
  123. {"SOC_S0I3_CTR", 0x000A},
  124. {"PCS_S0I3_CTR", 0x0009},
  125. {"PCS_C1E_RES", 0x041A},
  126. {"PCS_IDLE_STATUS", 0x2806},
  127. {"IA_PERF_LIMITS", 0x280B},
  128. {"GT_PERF_LIMITS", 0x280C},
  129. {"PCS_WAKEUP_S0IX_CTR", 0x0030},
  130. {"PCS_IDLE_BLOCKED", 0x2C00},
  131. {"PCS_S0IX_BLOCKED", 0x2C01},
  132. {"PCS_S0IX_WAKE_REASONS", 0x2C02},
  133. {"PCS_LTR_BLOCKING", 0x2C03},
  134. {"PC2_AND_MEM_SHALLOW_IDLE_RES", 0x1D40},
  135. };
  136. static struct telemetry_evtmap
  137. telemetry_glk_pss_default_events[TELEM_MAX_OS_ALLOCATED_EVENTS] = {
  138. {"IA_CORE0_C6_RES", 0x0400},
  139. {"IA_CORE0_C6_CTR", 0x0000},
  140. {"IA_MODULE0_C7_RES", 0x0410},
  141. {"IA_MODULE0_C7_CTR", 0x000C},
  142. {"IA_C0_RES", 0x0805},
  143. {"PCS_LTR", 0x2801},
  144. {"PSTATES", 0x2802},
  145. {"SOC_S0I3_RES", 0x0407},
  146. {"SOC_S0I3_CTR", 0x0008},
  147. {"PCS_S0I3_CTR", 0x0007},
  148. {"PCS_C1E_RES", 0x0414},
  149. {"PCS_IDLE_STATUS", 0x2806},
  150. {"IA_PERF_LIMITS", 0x280B},
  151. {"GT_PERF_LIMITS", 0x280C},
  152. {"PCS_WAKEUP_S0IX_CTR", 0x0025},
  153. {"PCS_IDLE_BLOCKED", 0x2C00},
  154. {"PCS_S0IX_BLOCKED", 0x2C01},
  155. {"PCS_S0IX_WAKE_REASONS", 0x2C02},
  156. {"PCS_LTR_BLOCKING", 0x2C03},
  157. {"PC2_AND_MEM_SHALLOW_IDLE_RES", 0x1D40},
  158. };
  159. /* APL specific Data */
  160. static struct telemetry_plt_config telem_apl_config = {
  161. .pss_config = {
  162. .telem_evts = telemetry_apl_pss_default_events,
  163. },
  164. .ioss_config = {
  165. .telem_evts = telemetry_apl_ioss_default_events,
  166. },
  167. };
  168. /* GLK specific Data */
  169. static struct telemetry_plt_config telem_glk_config = {
  170. .pss_config = {
  171. .telem_evts = telemetry_glk_pss_default_events,
  172. },
  173. .ioss_config = {
  174. .telem_evts = telemetry_apl_ioss_default_events,
  175. },
  176. };
  177. static const struct x86_cpu_id telemetry_cpu_ids[] = {
  178. TELEM_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_config),
  179. TELEM_CPU(INTEL_FAM6_ATOM_GEMINI_LAKE, telem_glk_config),
  180. {}
  181. };
  182. MODULE_DEVICE_TABLE(x86cpu, telemetry_cpu_ids);
  183. static inline int telem_get_unitconfig(enum telemetry_unit telem_unit,
  184. struct telemetry_unit_config **unit_config)
  185. {
  186. if (telem_unit == TELEM_PSS)
  187. *unit_config = &(telm_conf->pss_config);
  188. else if (telem_unit == TELEM_IOSS)
  189. *unit_config = &(telm_conf->ioss_config);
  190. else
  191. return -EINVAL;
  192. return 0;
  193. }
  194. static int telemetry_check_evtid(enum telemetry_unit telem_unit,
  195. u32 *evtmap, u8 len,
  196. enum telemetry_action action)
  197. {
  198. struct telemetry_unit_config *unit_config;
  199. int ret;
  200. ret = telem_get_unitconfig(telem_unit, &unit_config);
  201. if (ret < 0)
  202. return ret;
  203. switch (action) {
  204. case TELEM_RESET:
  205. if (len > TELEM_MAX_EVENTS_SRAM)
  206. return -EINVAL;
  207. break;
  208. case TELEM_UPDATE:
  209. if (len > TELEM_MAX_EVENTS_SRAM)
  210. return -EINVAL;
  211. if ((len > 0) && (evtmap == NULL))
  212. return -EINVAL;
  213. break;
  214. case TELEM_ADD:
  215. if ((len + unit_config->ssram_evts_used) >
  216. TELEM_MAX_EVENTS_SRAM)
  217. return -EINVAL;
  218. if ((len > 0) && (evtmap == NULL))
  219. return -EINVAL;
  220. break;
  221. default:
  222. pr_err("Unknown Telemetry action Specified %d\n", action);
  223. return -EINVAL;
  224. }
  225. return 0;
  226. }
  227. static inline int telemetry_plt_config_ioss_event(u32 evt_id, int index)
  228. {
  229. u32 write_buf;
  230. int ret;
  231. write_buf = evt_id | TELEM_EVENT_ENABLE;
  232. write_buf <<= BITS_PER_BYTE;
  233. write_buf |= index;
  234. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  235. IOSS_TELEM_EVENT_WRITE, (u8 *)&write_buf,
  236. IOSS_TELEM_EVT_WRITE_SIZE, NULL, 0);
  237. return ret;
  238. }
  239. static inline int telemetry_plt_config_pss_event(u32 evt_id, int index)
  240. {
  241. u32 write_buf;
  242. int ret;
  243. write_buf = evt_id | TELEM_EVENT_ENABLE;
  244. ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT,
  245. index, 0, &write_buf, NULL);
  246. return ret;
  247. }
  248. static int telemetry_setup_iossevtconfig(struct telemetry_evtconfig evtconfig,
  249. enum telemetry_action action)
  250. {
  251. u8 num_ioss_evts, ioss_period;
  252. int ret, index, idx;
  253. u32 *ioss_evtmap;
  254. u32 telem_ctrl;
  255. num_ioss_evts = evtconfig.num_evts;
  256. ioss_period = evtconfig.period;
  257. ioss_evtmap = evtconfig.evtmap;
  258. /* Get telemetry EVENT CTL */
  259. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  260. IOSS_TELEM_EVENT_CTL_READ, NULL, 0,
  261. &telem_ctrl, IOSS_TELEM_READ_WORD);
  262. if (ret) {
  263. pr_err("IOSS TELEM_CTRL Read Failed\n");
  264. return ret;
  265. }
  266. /* Disable Telemetry */
  267. TELEM_DISABLE(telem_ctrl);
  268. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  269. IOSS_TELEM_EVENT_CTL_WRITE,
  270. (u8 *)&telem_ctrl,
  271. IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
  272. NULL, 0);
  273. if (ret) {
  274. pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
  275. return ret;
  276. }
  277. /* Reset Everything */
  278. if (action == TELEM_RESET) {
  279. /* Clear All Events */
  280. TELEM_CLEAR_EVENTS(telem_ctrl);
  281. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  282. IOSS_TELEM_EVENT_CTL_WRITE,
  283. (u8 *)&telem_ctrl,
  284. IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
  285. NULL, 0);
  286. if (ret) {
  287. pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
  288. return ret;
  289. }
  290. telm_conf->ioss_config.ssram_evts_used = 0;
  291. /* Configure Events */
  292. for (idx = 0; idx < num_ioss_evts; idx++) {
  293. if (telemetry_plt_config_ioss_event(
  294. telm_conf->ioss_config.telem_evts[idx].evt_id,
  295. idx)) {
  296. pr_err("IOSS TELEM_RESET Fail for data: %x\n",
  297. telm_conf->ioss_config.telem_evts[idx].evt_id);
  298. continue;
  299. }
  300. telm_conf->ioss_config.ssram_evts_used++;
  301. }
  302. }
  303. /* Re-Configure Everything */
  304. if (action == TELEM_UPDATE) {
  305. /* Clear All Events */
  306. TELEM_CLEAR_EVENTS(telem_ctrl);
  307. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  308. IOSS_TELEM_EVENT_CTL_WRITE,
  309. (u8 *)&telem_ctrl,
  310. IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
  311. NULL, 0);
  312. if (ret) {
  313. pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
  314. return ret;
  315. }
  316. telm_conf->ioss_config.ssram_evts_used = 0;
  317. /* Configure Events */
  318. for (index = 0; index < num_ioss_evts; index++) {
  319. telm_conf->ioss_config.telem_evts[index].evt_id =
  320. ioss_evtmap[index];
  321. if (telemetry_plt_config_ioss_event(
  322. telm_conf->ioss_config.telem_evts[index].evt_id,
  323. index)) {
  324. pr_err("IOSS TELEM_UPDATE Fail for Evt%x\n",
  325. ioss_evtmap[index]);
  326. continue;
  327. }
  328. telm_conf->ioss_config.ssram_evts_used++;
  329. }
  330. }
  331. /* Add some Events */
  332. if (action == TELEM_ADD) {
  333. /* Configure Events */
  334. for (index = telm_conf->ioss_config.ssram_evts_used, idx = 0;
  335. idx < num_ioss_evts; index++, idx++) {
  336. telm_conf->ioss_config.telem_evts[index].evt_id =
  337. ioss_evtmap[idx];
  338. if (telemetry_plt_config_ioss_event(
  339. telm_conf->ioss_config.telem_evts[index].evt_id,
  340. index)) {
  341. pr_err("IOSS TELEM_ADD Fail for Event %x\n",
  342. ioss_evtmap[idx]);
  343. continue;
  344. }
  345. telm_conf->ioss_config.ssram_evts_used++;
  346. }
  347. }
  348. /* Enable Periodic Telemetry Events and enable SRAM trace */
  349. TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
  350. TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
  351. TELEM_ENABLE_PERIODIC(telem_ctrl);
  352. telem_ctrl |= ioss_period;
  353. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  354. IOSS_TELEM_EVENT_CTL_WRITE,
  355. (u8 *)&telem_ctrl,
  356. IOSS_TELEM_EVT_CTRL_WRITE_SIZE, NULL, 0);
  357. if (ret) {
  358. pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
  359. return ret;
  360. }
  361. telm_conf->ioss_config.curr_period = ioss_period;
  362. return 0;
  363. }
  364. static int telemetry_setup_pssevtconfig(struct telemetry_evtconfig evtconfig,
  365. enum telemetry_action action)
  366. {
  367. u8 num_pss_evts, pss_period;
  368. int ret, index, idx;
  369. u32 *pss_evtmap;
  370. u32 telem_ctrl;
  371. num_pss_evts = evtconfig.num_evts;
  372. pss_period = evtconfig.period;
  373. pss_evtmap = evtconfig.evtmap;
  374. /* PSS Config */
  375. /* Get telemetry EVENT CTL */
  376. ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL,
  377. 0, 0, NULL, &telem_ctrl);
  378. if (ret) {
  379. pr_err("PSS TELEM_CTRL Read Failed\n");
  380. return ret;
  381. }
  382. /* Disable Telemetry */
  383. TELEM_DISABLE(telem_ctrl);
  384. ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
  385. 0, 0, &telem_ctrl, NULL);
  386. if (ret) {
  387. pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
  388. return ret;
  389. }
  390. /* Reset Everything */
  391. if (action == TELEM_RESET) {
  392. /* Clear All Events */
  393. TELEM_CLEAR_EVENTS(telem_ctrl);
  394. ret = intel_punit_ipc_command(
  395. IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
  396. 0, 0, &telem_ctrl, NULL);
  397. if (ret) {
  398. pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
  399. return ret;
  400. }
  401. telm_conf->pss_config.ssram_evts_used = 0;
  402. /* Configure Events */
  403. for (idx = 0; idx < num_pss_evts; idx++) {
  404. if (telemetry_plt_config_pss_event(
  405. telm_conf->pss_config.telem_evts[idx].evt_id,
  406. idx)) {
  407. pr_err("PSS TELEM_RESET Fail for Event %x\n",
  408. telm_conf->pss_config.telem_evts[idx].evt_id);
  409. continue;
  410. }
  411. telm_conf->pss_config.ssram_evts_used++;
  412. }
  413. }
  414. /* Re-Configure Everything */
  415. if (action == TELEM_UPDATE) {
  416. /* Clear All Events */
  417. TELEM_CLEAR_EVENTS(telem_ctrl);
  418. ret = intel_punit_ipc_command(
  419. IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
  420. 0, 0, &telem_ctrl, NULL);
  421. if (ret) {
  422. pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
  423. return ret;
  424. }
  425. telm_conf->pss_config.ssram_evts_used = 0;
  426. /* Configure Events */
  427. for (index = 0; index < num_pss_evts; index++) {
  428. telm_conf->pss_config.telem_evts[index].evt_id =
  429. pss_evtmap[index];
  430. if (telemetry_plt_config_pss_event(
  431. telm_conf->pss_config.telem_evts[index].evt_id,
  432. index)) {
  433. pr_err("PSS TELEM_UPDATE Fail for Event %x\n",
  434. pss_evtmap[index]);
  435. continue;
  436. }
  437. telm_conf->pss_config.ssram_evts_used++;
  438. }
  439. }
  440. /* Add some Events */
  441. if (action == TELEM_ADD) {
  442. /* Configure Events */
  443. for (index = telm_conf->pss_config.ssram_evts_used, idx = 0;
  444. idx < num_pss_evts; index++, idx++) {
  445. telm_conf->pss_config.telem_evts[index].evt_id =
  446. pss_evtmap[idx];
  447. if (telemetry_plt_config_pss_event(
  448. telm_conf->pss_config.telem_evts[index].evt_id,
  449. index)) {
  450. pr_err("PSS TELEM_ADD Fail for Event %x\n",
  451. pss_evtmap[idx]);
  452. continue;
  453. }
  454. telm_conf->pss_config.ssram_evts_used++;
  455. }
  456. }
  457. /* Enable Periodic Telemetry Events and enable SRAM trace */
  458. TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
  459. TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
  460. TELEM_ENABLE_PERIODIC(telem_ctrl);
  461. telem_ctrl |= pss_period;
  462. ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
  463. 0, 0, &telem_ctrl, NULL);
  464. if (ret) {
  465. pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
  466. return ret;
  467. }
  468. telm_conf->pss_config.curr_period = pss_period;
  469. return 0;
  470. }
  471. static int telemetry_setup_evtconfig(struct telemetry_evtconfig pss_evtconfig,
  472. struct telemetry_evtconfig ioss_evtconfig,
  473. enum telemetry_action action)
  474. {
  475. int ret;
  476. mutex_lock(&(telm_conf->telem_lock));
  477. if ((action == TELEM_UPDATE) && (telm_conf->telem_in_use)) {
  478. ret = -EBUSY;
  479. goto out;
  480. }
  481. ret = telemetry_check_evtid(TELEM_PSS, pss_evtconfig.evtmap,
  482. pss_evtconfig.num_evts, action);
  483. if (ret)
  484. goto out;
  485. ret = telemetry_check_evtid(TELEM_IOSS, ioss_evtconfig.evtmap,
  486. ioss_evtconfig.num_evts, action);
  487. if (ret)
  488. goto out;
  489. if (ioss_evtconfig.num_evts) {
  490. ret = telemetry_setup_iossevtconfig(ioss_evtconfig, action);
  491. if (ret)
  492. goto out;
  493. }
  494. if (pss_evtconfig.num_evts) {
  495. ret = telemetry_setup_pssevtconfig(pss_evtconfig, action);
  496. if (ret)
  497. goto out;
  498. }
  499. if ((action == TELEM_UPDATE) || (action == TELEM_ADD))
  500. telm_conf->telem_in_use = true;
  501. else
  502. telm_conf->telem_in_use = false;
  503. out:
  504. mutex_unlock(&(telm_conf->telem_lock));
  505. return ret;
  506. }
  507. static int telemetry_setup(struct platform_device *pdev)
  508. {
  509. struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;
  510. u32 read_buf, events, event_regs;
  511. int ret;
  512. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY, IOSS_TELEM_INFO_READ,
  513. NULL, 0, &read_buf, IOSS_TELEM_READ_WORD);
  514. if (ret) {
  515. dev_err(&pdev->dev, "IOSS TELEM_INFO Read Failed\n");
  516. return ret;
  517. }
  518. /* Get telemetry Info */
  519. events = (read_buf & TELEM_INFO_SRAMEVTS_MASK) >>
  520. TELEM_INFO_SRAMEVTS_SHIFT;
  521. event_regs = read_buf & TELEM_INFO_NENABLES_MASK;
  522. if ((events < TELEM_MAX_EVENTS_SRAM) ||
  523. (event_regs < TELEM_MAX_EVENTS_SRAM)) {
  524. dev_err(&pdev->dev, "IOSS:Insufficient Space for SRAM Trace\n");
  525. dev_err(&pdev->dev, "SRAM Events %d; Event Regs %d\n",
  526. events, event_regs);
  527. return -ENOMEM;
  528. }
  529. telm_conf->ioss_config.min_period = TELEM_MIN_PERIOD(read_buf);
  530. telm_conf->ioss_config.max_period = TELEM_MAX_PERIOD(read_buf);
  531. /* PUNIT Mailbox Setup */
  532. ret = intel_punit_ipc_command(IPC_PUNIT_BIOS_READ_TELE_INFO, 0, 0,
  533. NULL, &read_buf);
  534. if (ret) {
  535. dev_err(&pdev->dev, "PSS TELEM_INFO Read Failed\n");
  536. return ret;
  537. }
  538. /* Get telemetry Info */
  539. events = (read_buf & TELEM_INFO_SRAMEVTS_MASK) >>
  540. TELEM_INFO_SRAMEVTS_SHIFT;
  541. event_regs = read_buf & TELEM_INFO_SRAMEVTS_MASK;
  542. if ((events < TELEM_MAX_EVENTS_SRAM) ||
  543. (event_regs < TELEM_MAX_EVENTS_SRAM)) {
  544. dev_err(&pdev->dev, "PSS:Insufficient Space for SRAM Trace\n");
  545. dev_err(&pdev->dev, "SRAM Events %d; Event Regs %d\n",
  546. events, event_regs);
  547. return -ENOMEM;
  548. }
  549. telm_conf->pss_config.min_period = TELEM_MIN_PERIOD(read_buf);
  550. telm_conf->pss_config.max_period = TELEM_MAX_PERIOD(read_buf);
  551. pss_evtconfig.evtmap = NULL;
  552. pss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
  553. pss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
  554. ioss_evtconfig.evtmap = NULL;
  555. ioss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
  556. ioss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
  557. ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
  558. TELEM_RESET);
  559. if (ret) {
  560. dev_err(&pdev->dev, "TELEMTRY Setup Failed\n");
  561. return ret;
  562. }
  563. return 0;
  564. }
  565. static int telemetry_plt_update_events(struct telemetry_evtconfig pss_evtconfig,
  566. struct telemetry_evtconfig ioss_evtconfig)
  567. {
  568. int ret;
  569. if ((pss_evtconfig.num_evts > 0) &&
  570. (TELEM_SAMPLE_PERIOD_INVALID(pss_evtconfig.period))) {
  571. pr_err("PSS Sampling Period Out of Range\n");
  572. return -EINVAL;
  573. }
  574. if ((ioss_evtconfig.num_evts > 0) &&
  575. (TELEM_SAMPLE_PERIOD_INVALID(ioss_evtconfig.period))) {
  576. pr_err("IOSS Sampling Period Out of Range\n");
  577. return -EINVAL;
  578. }
  579. ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
  580. TELEM_UPDATE);
  581. if (ret)
  582. pr_err("TELEMTRY Config Failed\n");
  583. return ret;
  584. }
  585. static int telemetry_plt_set_sampling_period(u8 pss_period, u8 ioss_period)
  586. {
  587. u32 telem_ctrl = 0;
  588. int ret = 0;
  589. mutex_lock(&(telm_conf->telem_lock));
  590. if (ioss_period) {
  591. if (TELEM_SAMPLE_PERIOD_INVALID(ioss_period)) {
  592. pr_err("IOSS Sampling Period Out of Range\n");
  593. ret = -EINVAL;
  594. goto out;
  595. }
  596. /* Get telemetry EVENT CTL */
  597. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  598. IOSS_TELEM_EVENT_CTL_READ, NULL, 0,
  599. &telem_ctrl, IOSS_TELEM_READ_WORD);
  600. if (ret) {
  601. pr_err("IOSS TELEM_CTRL Read Failed\n");
  602. goto out;
  603. }
  604. /* Disable Telemetry */
  605. TELEM_DISABLE(telem_ctrl);
  606. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  607. IOSS_TELEM_EVENT_CTL_WRITE,
  608. (u8 *)&telem_ctrl,
  609. IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
  610. NULL, 0);
  611. if (ret) {
  612. pr_err("IOSS TELEM_CTRL Event Disable Write Failed\n");
  613. goto out;
  614. }
  615. /* Enable Periodic Telemetry Events and enable SRAM trace */
  616. TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
  617. TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
  618. TELEM_ENABLE_PERIODIC(telem_ctrl);
  619. telem_ctrl |= ioss_period;
  620. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  621. IOSS_TELEM_EVENT_CTL_WRITE,
  622. (u8 *)&telem_ctrl,
  623. IOSS_TELEM_EVT_CTRL_WRITE_SIZE,
  624. NULL, 0);
  625. if (ret) {
  626. pr_err("IOSS TELEM_CTRL Event Enable Write Failed\n");
  627. goto out;
  628. }
  629. telm_conf->ioss_config.curr_period = ioss_period;
  630. }
  631. if (pss_period) {
  632. if (TELEM_SAMPLE_PERIOD_INVALID(pss_period)) {
  633. pr_err("PSS Sampling Period Out of Range\n");
  634. ret = -EINVAL;
  635. goto out;
  636. }
  637. /* Get telemetry EVENT CTL */
  638. ret = intel_punit_ipc_command(
  639. IPC_PUNIT_BIOS_READ_TELE_EVENT_CTRL,
  640. 0, 0, NULL, &telem_ctrl);
  641. if (ret) {
  642. pr_err("PSS TELEM_CTRL Read Failed\n");
  643. goto out;
  644. }
  645. /* Disable Telemetry */
  646. TELEM_DISABLE(telem_ctrl);
  647. ret = intel_punit_ipc_command(
  648. IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
  649. 0, 0, &telem_ctrl, NULL);
  650. if (ret) {
  651. pr_err("PSS TELEM_CTRL Event Disable Write Failed\n");
  652. goto out;
  653. }
  654. /* Enable Periodic Telemetry Events and enable SRAM trace */
  655. TELEM_CLEAR_SAMPLE_PERIOD(telem_ctrl);
  656. TELEM_ENABLE_SRAM_EVT_TRACE(telem_ctrl);
  657. TELEM_ENABLE_PERIODIC(telem_ctrl);
  658. telem_ctrl |= pss_period;
  659. ret = intel_punit_ipc_command(
  660. IPC_PUNIT_BIOS_WRITE_TELE_EVENT_CTRL,
  661. 0, 0, &telem_ctrl, NULL);
  662. if (ret) {
  663. pr_err("PSS TELEM_CTRL Event Enable Write Failed\n");
  664. goto out;
  665. }
  666. telm_conf->pss_config.curr_period = pss_period;
  667. }
  668. out:
  669. mutex_unlock(&(telm_conf->telem_lock));
  670. return ret;
  671. }
  672. static int telemetry_plt_get_sampling_period(u8 *pss_min_period,
  673. u8 *pss_max_period,
  674. u8 *ioss_min_period,
  675. u8 *ioss_max_period)
  676. {
  677. *pss_min_period = telm_conf->pss_config.min_period;
  678. *pss_max_period = telm_conf->pss_config.max_period;
  679. *ioss_min_period = telm_conf->ioss_config.min_period;
  680. *ioss_max_period = telm_conf->ioss_config.max_period;
  681. return 0;
  682. }
  683. static int telemetry_plt_reset_events(void)
  684. {
  685. struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;
  686. int ret;
  687. pss_evtconfig.evtmap = NULL;
  688. pss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
  689. pss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
  690. ioss_evtconfig.evtmap = NULL;
  691. ioss_evtconfig.num_evts = TELEM_MAX_OS_ALLOCATED_EVENTS;
  692. ioss_evtconfig.period = TELEM_SAMPLING_DEFAULT_PERIOD;
  693. ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
  694. TELEM_RESET);
  695. if (ret)
  696. pr_err("TELEMTRY Reset Failed\n");
  697. return ret;
  698. }
  699. static int telemetry_plt_get_eventconfig(struct telemetry_evtconfig *pss_config,
  700. struct telemetry_evtconfig *ioss_config,
  701. int pss_len, int ioss_len)
  702. {
  703. u32 *pss_evtmap, *ioss_evtmap;
  704. u32 index;
  705. pss_evtmap = pss_config->evtmap;
  706. ioss_evtmap = ioss_config->evtmap;
  707. mutex_lock(&(telm_conf->telem_lock));
  708. pss_config->num_evts = telm_conf->pss_config.ssram_evts_used;
  709. ioss_config->num_evts = telm_conf->ioss_config.ssram_evts_used;
  710. pss_config->period = telm_conf->pss_config.curr_period;
  711. ioss_config->period = telm_conf->ioss_config.curr_period;
  712. if ((pss_len < telm_conf->pss_config.ssram_evts_used) ||
  713. (ioss_len < telm_conf->ioss_config.ssram_evts_used)) {
  714. mutex_unlock(&(telm_conf->telem_lock));
  715. return -EINVAL;
  716. }
  717. for (index = 0; index < telm_conf->pss_config.ssram_evts_used;
  718. index++) {
  719. pss_evtmap[index] =
  720. telm_conf->pss_config.telem_evts[index].evt_id;
  721. }
  722. for (index = 0; index < telm_conf->ioss_config.ssram_evts_used;
  723. index++) {
  724. ioss_evtmap[index] =
  725. telm_conf->ioss_config.telem_evts[index].evt_id;
  726. }
  727. mutex_unlock(&(telm_conf->telem_lock));
  728. return 0;
  729. }
  730. static int telemetry_plt_add_events(u8 num_pss_evts, u8 num_ioss_evts,
  731. u32 *pss_evtmap, u32 *ioss_evtmap)
  732. {
  733. struct telemetry_evtconfig pss_evtconfig, ioss_evtconfig;
  734. int ret;
  735. pss_evtconfig.evtmap = pss_evtmap;
  736. pss_evtconfig.num_evts = num_pss_evts;
  737. pss_evtconfig.period = telm_conf->pss_config.curr_period;
  738. ioss_evtconfig.evtmap = ioss_evtmap;
  739. ioss_evtconfig.num_evts = num_ioss_evts;
  740. ioss_evtconfig.period = telm_conf->ioss_config.curr_period;
  741. ret = telemetry_setup_evtconfig(pss_evtconfig, ioss_evtconfig,
  742. TELEM_ADD);
  743. if (ret)
  744. pr_err("TELEMTRY ADD Failed\n");
  745. return ret;
  746. }
  747. static int telem_evtlog_read(enum telemetry_unit telem_unit,
  748. struct telem_ssram_region *ssram_region, u8 len)
  749. {
  750. struct telemetry_unit_config *unit_config;
  751. u64 timestamp_prev, timestamp_next;
  752. int ret, index, timeout = 0;
  753. ret = telem_get_unitconfig(telem_unit, &unit_config);
  754. if (ret < 0)
  755. return ret;
  756. if (len > unit_config->ssram_evts_used)
  757. len = unit_config->ssram_evts_used;
  758. do {
  759. timestamp_prev = readq(unit_config->regmap);
  760. if (!timestamp_prev) {
  761. pr_err("Ssram under update. Please Try Later\n");
  762. return -EBUSY;
  763. }
  764. ssram_region->start_time = readq(unit_config->regmap +
  765. TELEM_SSRAM_STARTTIME_OFFSET);
  766. for (index = 0; index < len; index++) {
  767. ssram_region->events[index] =
  768. readq(unit_config->regmap + TELEM_SSRAM_EVTLOG_OFFSET +
  769. BYTES_PER_LONG*index);
  770. }
  771. timestamp_next = readq(unit_config->regmap);
  772. if (!timestamp_next) {
  773. pr_err("Ssram under update. Please Try Later\n");
  774. return -EBUSY;
  775. }
  776. if (timeout++ > TELEM_SSRAM_READ_TIMEOUT) {
  777. pr_err("Timeout while reading Events\n");
  778. return -EBUSY;
  779. }
  780. } while (timestamp_prev != timestamp_next);
  781. ssram_region->timestamp = timestamp_next;
  782. return len;
  783. }
  784. static int telemetry_plt_raw_read_eventlog(enum telemetry_unit telem_unit,
  785. struct telemetry_evtlog *evtlog,
  786. int len, int log_all_evts)
  787. {
  788. int index, idx1, ret, readlen = len;
  789. struct telem_ssram_region ssram_region;
  790. struct telemetry_evtmap *evtmap;
  791. switch (telem_unit) {
  792. case TELEM_PSS:
  793. evtmap = telm_conf->pss_config.telem_evts;
  794. break;
  795. case TELEM_IOSS:
  796. evtmap = telm_conf->ioss_config.telem_evts;
  797. break;
  798. default:
  799. pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
  800. return -EINVAL;
  801. }
  802. if (!log_all_evts)
  803. readlen = TELEM_MAX_EVENTS_SRAM;
  804. ret = telem_evtlog_read(telem_unit, &ssram_region, readlen);
  805. if (ret < 0)
  806. return ret;
  807. /* Invalid evt-id array specified via length mismatch */
  808. if ((!log_all_evts) && (len > ret))
  809. return -EINVAL;
  810. if (log_all_evts)
  811. for (index = 0; index < ret; index++) {
  812. evtlog[index].telem_evtlog = ssram_region.events[index];
  813. evtlog[index].telem_evtid = evtmap[index].evt_id;
  814. }
  815. else
  816. for (index = 0, readlen = 0; (index < ret) && (readlen < len);
  817. index++) {
  818. for (idx1 = 0; idx1 < len; idx1++) {
  819. /* Elements matched */
  820. if (evtmap[index].evt_id ==
  821. evtlog[idx1].telem_evtid) {
  822. evtlog[idx1].telem_evtlog =
  823. ssram_region.events[index];
  824. readlen++;
  825. break;
  826. }
  827. }
  828. }
  829. return readlen;
  830. }
  831. static int telemetry_plt_read_eventlog(enum telemetry_unit telem_unit,
  832. struct telemetry_evtlog *evtlog, int len, int log_all_evts)
  833. {
  834. int ret;
  835. mutex_lock(&(telm_conf->telem_lock));
  836. ret = telemetry_plt_raw_read_eventlog(telem_unit, evtlog,
  837. len, log_all_evts);
  838. mutex_unlock(&(telm_conf->telem_lock));
  839. return ret;
  840. }
  841. static int telemetry_plt_get_trace_verbosity(enum telemetry_unit telem_unit,
  842. u32 *verbosity)
  843. {
  844. u32 temp = 0;
  845. int ret;
  846. if (verbosity == NULL)
  847. return -EINVAL;
  848. mutex_lock(&(telm_conf->telem_trace_lock));
  849. switch (telem_unit) {
  850. case TELEM_PSS:
  851. ret = intel_punit_ipc_command(
  852. IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL,
  853. 0, 0, NULL, &temp);
  854. if (ret) {
  855. pr_err("PSS TRACE_CTRL Read Failed\n");
  856. goto out;
  857. }
  858. break;
  859. case TELEM_IOSS:
  860. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  861. IOSS_TELEM_TRACE_CTL_READ, NULL, 0, &temp,
  862. IOSS_TELEM_READ_WORD);
  863. if (ret) {
  864. pr_err("IOSS TRACE_CTL Read Failed\n");
  865. goto out;
  866. }
  867. break;
  868. default:
  869. pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
  870. ret = -EINVAL;
  871. break;
  872. }
  873. TELEM_EXTRACT_VERBOSITY(temp, *verbosity);
  874. out:
  875. mutex_unlock(&(telm_conf->telem_trace_lock));
  876. return ret;
  877. }
  878. static int telemetry_plt_set_trace_verbosity(enum telemetry_unit telem_unit,
  879. u32 verbosity)
  880. {
  881. u32 temp = 0;
  882. int ret;
  883. verbosity &= TELEM_TRC_VERBOSITY_MASK;
  884. mutex_lock(&(telm_conf->telem_trace_lock));
  885. switch (telem_unit) {
  886. case TELEM_PSS:
  887. ret = intel_punit_ipc_command(
  888. IPC_PUNIT_BIOS_READ_TELE_TRACE_CTRL,
  889. 0, 0, NULL, &temp);
  890. if (ret) {
  891. pr_err("PSS TRACE_CTRL Read Failed\n");
  892. goto out;
  893. }
  894. TELEM_CLEAR_VERBOSITY_BITS(temp);
  895. TELEM_SET_VERBOSITY_BITS(temp, verbosity);
  896. ret = intel_punit_ipc_command(
  897. IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL,
  898. 0, 0, &temp, NULL);
  899. if (ret) {
  900. pr_err("PSS TRACE_CTRL Verbosity Set Failed\n");
  901. goto out;
  902. }
  903. break;
  904. case TELEM_IOSS:
  905. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  906. IOSS_TELEM_TRACE_CTL_READ, NULL, 0, &temp,
  907. IOSS_TELEM_READ_WORD);
  908. if (ret) {
  909. pr_err("IOSS TRACE_CTL Read Failed\n");
  910. goto out;
  911. }
  912. TELEM_CLEAR_VERBOSITY_BITS(temp);
  913. TELEM_SET_VERBOSITY_BITS(temp, verbosity);
  914. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  915. IOSS_TELEM_TRACE_CTL_WRITE, (u8 *)&temp,
  916. IOSS_TELEM_WRITE_FOURBYTES, NULL, 0);
  917. if (ret) {
  918. pr_err("IOSS TRACE_CTL Verbosity Set Failed\n");
  919. goto out;
  920. }
  921. break;
  922. default:
  923. pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
  924. ret = -EINVAL;
  925. break;
  926. }
  927. out:
  928. mutex_unlock(&(telm_conf->telem_trace_lock));
  929. return ret;
  930. }
  931. static const struct telemetry_core_ops telm_pltops = {
  932. .get_trace_verbosity = telemetry_plt_get_trace_verbosity,
  933. .set_trace_verbosity = telemetry_plt_set_trace_verbosity,
  934. .set_sampling_period = telemetry_plt_set_sampling_period,
  935. .get_sampling_period = telemetry_plt_get_sampling_period,
  936. .raw_read_eventlog = telemetry_plt_raw_read_eventlog,
  937. .get_eventconfig = telemetry_plt_get_eventconfig,
  938. .update_events = telemetry_plt_update_events,
  939. .read_eventlog = telemetry_plt_read_eventlog,
  940. .reset_events = telemetry_plt_reset_events,
  941. .add_events = telemetry_plt_add_events,
  942. };
  943. static int telemetry_pltdrv_probe(struct platform_device *pdev)
  944. {
  945. struct resource *res0 = NULL, *res1 = NULL;
  946. const struct x86_cpu_id *id;
  947. int size, ret = -ENOMEM;
  948. id = x86_match_cpu(telemetry_cpu_ids);
  949. if (!id)
  950. return -ENODEV;
  951. telm_conf = (struct telemetry_plt_config *)id->driver_data;
  952. res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  953. if (!res0) {
  954. ret = -EINVAL;
  955. goto out;
  956. }
  957. size = resource_size(res0);
  958. if (!devm_request_mem_region(&pdev->dev, res0->start, size,
  959. pdev->name)) {
  960. ret = -EBUSY;
  961. goto out;
  962. }
  963. telm_conf->pss_config.ssram_base_addr = res0->start;
  964. telm_conf->pss_config.ssram_size = size;
  965. res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  966. if (!res1) {
  967. ret = -EINVAL;
  968. goto out;
  969. }
  970. size = resource_size(res1);
  971. if (!devm_request_mem_region(&pdev->dev, res1->start, size,
  972. pdev->name)) {
  973. ret = -EBUSY;
  974. goto out;
  975. }
  976. telm_conf->ioss_config.ssram_base_addr = res1->start;
  977. telm_conf->ioss_config.ssram_size = size;
  978. telm_conf->pss_config.regmap = ioremap_nocache(
  979. telm_conf->pss_config.ssram_base_addr,
  980. telm_conf->pss_config.ssram_size);
  981. if (!telm_conf->pss_config.regmap) {
  982. ret = -ENOMEM;
  983. goto out;
  984. }
  985. telm_conf->ioss_config.regmap = ioremap_nocache(
  986. telm_conf->ioss_config.ssram_base_addr,
  987. telm_conf->ioss_config.ssram_size);
  988. if (!telm_conf->ioss_config.regmap) {
  989. ret = -ENOMEM;
  990. goto out;
  991. }
  992. mutex_init(&telm_conf->telem_lock);
  993. mutex_init(&telm_conf->telem_trace_lock);
  994. ret = telemetry_setup(pdev);
  995. if (ret)
  996. goto out;
  997. ret = telemetry_set_pltdata(&telm_pltops, telm_conf);
  998. if (ret) {
  999. dev_err(&pdev->dev, "TELEMTRY Set Pltops Failed.\n");
  1000. goto out;
  1001. }
  1002. return 0;
  1003. out:
  1004. if (res0)
  1005. release_mem_region(res0->start, resource_size(res0));
  1006. if (res1)
  1007. release_mem_region(res1->start, resource_size(res1));
  1008. if (telm_conf->pss_config.regmap)
  1009. iounmap(telm_conf->pss_config.regmap);
  1010. if (telm_conf->ioss_config.regmap)
  1011. iounmap(telm_conf->ioss_config.regmap);
  1012. dev_err(&pdev->dev, "TELEMTRY Setup Failed.\n");
  1013. return ret;
  1014. }
  1015. static int telemetry_pltdrv_remove(struct platform_device *pdev)
  1016. {
  1017. telemetry_clear_pltdata();
  1018. iounmap(telm_conf->pss_config.regmap);
  1019. iounmap(telm_conf->ioss_config.regmap);
  1020. return 0;
  1021. }
  1022. static struct platform_driver telemetry_soc_driver = {
  1023. .probe = telemetry_pltdrv_probe,
  1024. .remove = telemetry_pltdrv_remove,
  1025. .driver = {
  1026. .name = DRIVER_NAME,
  1027. },
  1028. };
  1029. static int __init telemetry_module_init(void)
  1030. {
  1031. pr_info(DRIVER_NAME ": version %s loaded\n", DRIVER_VERSION);
  1032. return platform_driver_register(&telemetry_soc_driver);
  1033. }
  1034. static void __exit telemetry_module_exit(void)
  1035. {
  1036. platform_driver_unregister(&telemetry_soc_driver);
  1037. }
  1038. device_initcall(telemetry_module_init);
  1039. module_exit(telemetry_module_exit);
  1040. MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
  1041. MODULE_DESCRIPTION("Intel SoC Telemetry Platform Driver");
  1042. MODULE_VERSION(DRIVER_VERSION);
  1043. MODULE_LICENSE("GPL");