intel_telemetry_pltdrv.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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_READ_TELE_TRACE_CTRL,
  856. 0, 0, NULL, &temp);
  857. if (ret) {
  858. pr_err("PSS TRACE_CTRL Read Failed\n");
  859. goto out;
  860. }
  861. TELEM_CLEAR_VERBOSITY_BITS(temp);
  862. TELEM_SET_VERBOSITY_BITS(temp, verbosity);
  863. ret = intel_punit_ipc_command(
  864. IPC_PUNIT_BIOS_WRITE_TELE_TRACE_CTRL,
  865. 0, 0, &temp, NULL);
  866. if (ret) {
  867. pr_err("PSS TRACE_CTRL Verbosity Set Failed\n");
  868. goto out;
  869. }
  870. break;
  871. case TELEM_IOSS:
  872. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  873. IOSS_TELEM_TRACE_CTL_READ, NULL, 0, &temp,
  874. IOSS_TELEM_READ_WORD);
  875. if (ret) {
  876. pr_err("IOSS TRACE_CTL Read Failed\n");
  877. goto out;
  878. }
  879. TELEM_CLEAR_VERBOSITY_BITS(temp);
  880. TELEM_SET_VERBOSITY_BITS(temp, verbosity);
  881. ret = intel_pmc_ipc_command(PMC_IPC_PMC_TELEMTRY,
  882. IOSS_TELEM_TRACE_CTL_WRITE, (u8 *)&temp,
  883. IOSS_TELEM_WRITE_FOURBYTES, NULL, 0);
  884. if (ret) {
  885. pr_err("IOSS TRACE_CTL Verbosity Set Failed\n");
  886. goto out;
  887. }
  888. break;
  889. default:
  890. pr_err("Unknown Telemetry Unit Specified %d\n", telem_unit);
  891. ret = -EINVAL;
  892. break;
  893. }
  894. out:
  895. mutex_unlock(&(telm_conf->telem_trace_lock));
  896. return ret;
  897. }
  898. static struct telemetry_core_ops telm_pltops = {
  899. .get_trace_verbosity = telemetry_plt_get_trace_verbosity,
  900. .set_trace_verbosity = telemetry_plt_set_trace_verbosity,
  901. .set_sampling_period = telemetry_plt_set_sampling_period,
  902. .get_sampling_period = telemetry_plt_get_sampling_period,
  903. .raw_read_eventlog = telemetry_plt_raw_read_eventlog,
  904. .get_eventconfig = telemetry_plt_get_eventconfig,
  905. .update_events = telemetry_plt_update_events,
  906. .read_eventlog = telemetry_plt_read_eventlog,
  907. .reset_events = telemetry_plt_reset_events,
  908. .add_events = telemetry_plt_add_events,
  909. };
  910. static int telemetry_pltdrv_probe(struct platform_device *pdev)
  911. {
  912. struct resource *res0 = NULL, *res1 = NULL;
  913. const struct x86_cpu_id *id;
  914. int size, ret = -ENOMEM;
  915. id = x86_match_cpu(telemetry_cpu_ids);
  916. if (!id)
  917. return -ENODEV;
  918. telm_conf = (struct telemetry_plt_config *)id->driver_data;
  919. res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  920. if (!res0) {
  921. ret = -EINVAL;
  922. goto out;
  923. }
  924. size = resource_size(res0);
  925. if (!devm_request_mem_region(&pdev->dev, res0->start, size,
  926. pdev->name)) {
  927. ret = -EBUSY;
  928. goto out;
  929. }
  930. telm_conf->pss_config.ssram_base_addr = res0->start;
  931. telm_conf->pss_config.ssram_size = size;
  932. res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  933. if (!res1) {
  934. ret = -EINVAL;
  935. goto out;
  936. }
  937. size = resource_size(res1);
  938. if (!devm_request_mem_region(&pdev->dev, res1->start, size,
  939. pdev->name)) {
  940. ret = -EBUSY;
  941. goto out;
  942. }
  943. telm_conf->ioss_config.ssram_base_addr = res1->start;
  944. telm_conf->ioss_config.ssram_size = size;
  945. telm_conf->pss_config.regmap = ioremap_nocache(
  946. telm_conf->pss_config.ssram_base_addr,
  947. telm_conf->pss_config.ssram_size);
  948. if (!telm_conf->pss_config.regmap) {
  949. ret = -ENOMEM;
  950. goto out;
  951. }
  952. telm_conf->ioss_config.regmap = ioremap_nocache(
  953. telm_conf->ioss_config.ssram_base_addr,
  954. telm_conf->ioss_config.ssram_size);
  955. if (!telm_conf->ioss_config.regmap) {
  956. ret = -ENOMEM;
  957. goto out;
  958. }
  959. mutex_init(&telm_conf->telem_lock);
  960. mutex_init(&telm_conf->telem_trace_lock);
  961. ret = telemetry_setup(pdev);
  962. if (ret)
  963. goto out;
  964. ret = telemetry_set_pltdata(&telm_pltops, telm_conf);
  965. if (ret) {
  966. dev_err(&pdev->dev, "TELEMTRY Set Pltops Failed.\n");
  967. goto out;
  968. }
  969. return 0;
  970. out:
  971. if (res0)
  972. release_mem_region(res0->start, resource_size(res0));
  973. if (res1)
  974. release_mem_region(res1->start, resource_size(res1));
  975. if (telm_conf->pss_config.regmap)
  976. iounmap(telm_conf->pss_config.regmap);
  977. if (telm_conf->ioss_config.regmap)
  978. iounmap(telm_conf->ioss_config.regmap);
  979. dev_err(&pdev->dev, "TELEMTRY Setup Failed.\n");
  980. return ret;
  981. }
  982. static int telemetry_pltdrv_remove(struct platform_device *pdev)
  983. {
  984. telemetry_clear_pltdata();
  985. iounmap(telm_conf->pss_config.regmap);
  986. iounmap(telm_conf->ioss_config.regmap);
  987. return 0;
  988. }
  989. static struct platform_driver telemetry_soc_driver = {
  990. .probe = telemetry_pltdrv_probe,
  991. .remove = telemetry_pltdrv_remove,
  992. .driver = {
  993. .name = DRIVER_NAME,
  994. },
  995. };
  996. static int __init telemetry_module_init(void)
  997. {
  998. pr_info(DRIVER_NAME ": version %s loaded\n", DRIVER_VERSION);
  999. return platform_driver_register(&telemetry_soc_driver);
  1000. }
  1001. static void __exit telemetry_module_exit(void)
  1002. {
  1003. platform_driver_unregister(&telemetry_soc_driver);
  1004. }
  1005. device_initcall(telemetry_module_init);
  1006. module_exit(telemetry_module_exit);
  1007. MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
  1008. MODULE_DESCRIPTION("Intel SoC Telemetry Platform Driver");
  1009. MODULE_VERSION(DRIVER_VERSION);
  1010. MODULE_LICENSE("GPL");