intel_telemetry_pltdrv.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  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");