intel_telemetry_pltdrv.c 32 KB

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