intel_telemetry_pltdrv.c 31 KB

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