intel_telemetry_pltdrv.c 31 KB

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