intel_telemetry_pltdrv.c 31 KB

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