PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/platform/x86/intel_telemetry_core.c

http://github.com/torvalds/linux
C | 455 lines | 238 code | 61 blank | 156 comment | 14 complexity | 8a05c8c740a5ca8b17a526c7cefdc9a2 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Intel SoC Core Telemetry Driver
  4. * Copyright (C) 2015, Intel Corporation.
  5. * All Rights Reserved.
  6. *
  7. * Telemetry Framework provides platform related PM and performance statistics.
  8. * This file provides the core telemetry API implementation.
  9. */
  10. #include <linux/device.h>
  11. #include <linux/module.h>
  12. #include <asm/intel_telemetry.h>
  13. #define DRIVER_NAME "intel_telemetry_core"
  14. struct telemetry_core_config {
  15. struct telemetry_plt_config *plt_config;
  16. const struct telemetry_core_ops *telem_ops;
  17. };
  18. static struct telemetry_core_config telm_core_conf;
  19. static int telemetry_def_update_events(struct telemetry_evtconfig pss_evtconfig,
  20. struct telemetry_evtconfig ioss_evtconfig)
  21. {
  22. return 0;
  23. }
  24. static int telemetry_def_set_sampling_period(u8 pss_period, u8 ioss_period)
  25. {
  26. return 0;
  27. }
  28. static int telemetry_def_get_sampling_period(u8 *pss_min_period,
  29. u8 *pss_max_period,
  30. u8 *ioss_min_period,
  31. u8 *ioss_max_period)
  32. {
  33. return 0;
  34. }
  35. static int telemetry_def_get_eventconfig(
  36. struct telemetry_evtconfig *pss_evtconfig,
  37. struct telemetry_evtconfig *ioss_evtconfig,
  38. int pss_len, int ioss_len)
  39. {
  40. return 0;
  41. }
  42. static int telemetry_def_get_trace_verbosity(enum telemetry_unit telem_unit,
  43. u32 *verbosity)
  44. {
  45. return 0;
  46. }
  47. static int telemetry_def_set_trace_verbosity(enum telemetry_unit telem_unit,
  48. u32 verbosity)
  49. {
  50. return 0;
  51. }
  52. static int telemetry_def_raw_read_eventlog(enum telemetry_unit telem_unit,
  53. struct telemetry_evtlog *evtlog,
  54. int len, int log_all_evts)
  55. {
  56. return 0;
  57. }
  58. static int telemetry_def_read_eventlog(enum telemetry_unit telem_unit,
  59. struct telemetry_evtlog *evtlog,
  60. int len, int log_all_evts)
  61. {
  62. return 0;
  63. }
  64. static int telemetry_def_add_events(u8 num_pss_evts, u8 num_ioss_evts,
  65. u32 *pss_evtmap, u32 *ioss_evtmap)
  66. {
  67. return 0;
  68. }
  69. static int telemetry_def_reset_events(void)
  70. {
  71. return 0;
  72. }
  73. static const struct telemetry_core_ops telm_defpltops = {
  74. .set_sampling_period = telemetry_def_set_sampling_period,
  75. .get_sampling_period = telemetry_def_get_sampling_period,
  76. .get_trace_verbosity = telemetry_def_get_trace_verbosity,
  77. .set_trace_verbosity = telemetry_def_set_trace_verbosity,
  78. .raw_read_eventlog = telemetry_def_raw_read_eventlog,
  79. .get_eventconfig = telemetry_def_get_eventconfig,
  80. .read_eventlog = telemetry_def_read_eventlog,
  81. .update_events = telemetry_def_update_events,
  82. .reset_events = telemetry_def_reset_events,
  83. .add_events = telemetry_def_add_events,
  84. };
  85. /**
  86. * telemetry_update_events() - Update telemetry Configuration
  87. * @pss_evtconfig: PSS related config. No change if num_evts = 0.
  88. * @pss_evtconfig: IOSS related config. No change if num_evts = 0.
  89. *
  90. * This API updates the IOSS & PSS Telemetry configuration. Old config
  91. * is overwritten. Call telemetry_reset_events when logging is over
  92. * All sample period values should be in the form of:
  93. * bits[6:3] -> value; bits [0:2]-> Exponent; Period = (Value *16^Exponent)
  94. *
  95. * Return: 0 success, < 0 for failure
  96. */
  97. int telemetry_update_events(struct telemetry_evtconfig pss_evtconfig,
  98. struct telemetry_evtconfig ioss_evtconfig)
  99. {
  100. return telm_core_conf.telem_ops->update_events(pss_evtconfig,
  101. ioss_evtconfig);
  102. }
  103. EXPORT_SYMBOL_GPL(telemetry_update_events);
  104. /**
  105. * telemetry_set_sampling_period() - Sets the IOSS & PSS sampling period
  106. * @pss_period: placeholder for PSS Period to be set.
  107. * Set to 0 if not required to be updated
  108. * @ioss_period: placeholder for IOSS Period to be set
  109. * Set to 0 if not required to be updated
  110. *
  111. * All values should be in the form of:
  112. * bits[6:3] -> value; bits [0:2]-> Exponent; Period = (Value *16^Exponent)
  113. *
  114. * Return: 0 success, < 0 for failure
  115. */
  116. int telemetry_set_sampling_period(u8 pss_period, u8 ioss_period)
  117. {
  118. return telm_core_conf.telem_ops->set_sampling_period(pss_period,
  119. ioss_period);
  120. }
  121. EXPORT_SYMBOL_GPL(telemetry_set_sampling_period);
  122. /**
  123. * telemetry_get_sampling_period() - Get IOSS & PSS min & max sampling period
  124. * @pss_min_period: placeholder for PSS Min Period supported
  125. * @pss_max_period: placeholder for PSS Max Period supported
  126. * @ioss_min_period: placeholder for IOSS Min Period supported
  127. * @ioss_max_period: placeholder for IOSS Max Period supported
  128. *
  129. * All values should be in the form of:
  130. * bits[6:3] -> value; bits [0:2]-> Exponent; Period = (Value *16^Exponent)
  131. *
  132. * Return: 0 success, < 0 for failure
  133. */
  134. int telemetry_get_sampling_period(u8 *pss_min_period, u8 *pss_max_period,
  135. u8 *ioss_min_period, u8 *ioss_max_period)
  136. {
  137. return telm_core_conf.telem_ops->get_sampling_period(pss_min_period,
  138. pss_max_period,
  139. ioss_min_period,
  140. ioss_max_period);
  141. }
  142. EXPORT_SYMBOL_GPL(telemetry_get_sampling_period);
  143. /**
  144. * telemetry_reset_events() - Restore the IOSS & PSS configuration to default
  145. *
  146. * Return: 0 success, < 0 for failure
  147. */
  148. int telemetry_reset_events(void)
  149. {
  150. return telm_core_conf.telem_ops->reset_events();
  151. }
  152. EXPORT_SYMBOL_GPL(telemetry_reset_events);
  153. /**
  154. * telemetry_get_eventconfig() - Returns the pss and ioss events enabled
  155. * @pss_evtconfig: Pointer to PSS related configuration.
  156. * @pss_evtconfig: Pointer to IOSS related configuration.
  157. * @pss_len: Number of u32 elements allocated for pss_evtconfig array
  158. * @ioss_len: Number of u32 elements allocated for ioss_evtconfig array
  159. *
  160. * Return: 0 success, < 0 for failure
  161. */
  162. int telemetry_get_eventconfig(struct telemetry_evtconfig *pss_evtconfig,
  163. struct telemetry_evtconfig *ioss_evtconfig,
  164. int pss_len, int ioss_len)
  165. {
  166. return telm_core_conf.telem_ops->get_eventconfig(pss_evtconfig,
  167. ioss_evtconfig,
  168. pss_len, ioss_len);
  169. }
  170. EXPORT_SYMBOL_GPL(telemetry_get_eventconfig);
  171. /**
  172. * telemetry_add_events() - Add IOSS & PSS configuration to existing settings.
  173. * @num_pss_evts: Number of PSS Events (<29) in pss_evtmap. Can be 0.
  174. * @num_ioss_evts: Number of IOSS Events (<29) in ioss_evtmap. Can be 0.
  175. * @pss_evtmap: Array of PSS Event-IDs to Enable
  176. * @ioss_evtmap: Array of PSS Event-IDs to Enable
  177. *
  178. * Events are appended to Old Configuration. In case of total events > 28, it
  179. * returns error. Call telemetry_reset_events to reset after eventlog done
  180. *
  181. * Return: 0 success, < 0 for failure
  182. */
  183. int telemetry_add_events(u8 num_pss_evts, u8 num_ioss_evts,
  184. u32 *pss_evtmap, u32 *ioss_evtmap)
  185. {
  186. return telm_core_conf.telem_ops->add_events(num_pss_evts,
  187. num_ioss_evts, pss_evtmap,
  188. ioss_evtmap);
  189. }
  190. EXPORT_SYMBOL_GPL(telemetry_add_events);
  191. /**
  192. * telemetry_read_events() - Fetches samples as specified by evtlog.telem_evt_id
  193. * @telem_unit: Specify whether IOSS or PSS Read
  194. * @evtlog: Array of telemetry_evtlog structs to fill data
  195. * evtlog.telem_evt_id specifies the ids to read
  196. * @len: Length of array of evtlog
  197. *
  198. * Return: number of eventlogs read for success, < 0 for failure
  199. */
  200. int telemetry_read_events(enum telemetry_unit telem_unit,
  201. struct telemetry_evtlog *evtlog, int len)
  202. {
  203. return telm_core_conf.telem_ops->read_eventlog(telem_unit, evtlog,
  204. len, 0);
  205. }
  206. EXPORT_SYMBOL_GPL(telemetry_read_events);
  207. /**
  208. * telemetry_raw_read_events() - Fetch samples specified by evtlog.telem_evt_id
  209. * @telem_unit: Specify whether IOSS or PSS Read
  210. * @evtlog: Array of telemetry_evtlog structs to fill data
  211. * evtlog.telem_evt_id specifies the ids to read
  212. * @len: Length of array of evtlog
  213. *
  214. * The caller must take care of locking in this case.
  215. *
  216. * Return: number of eventlogs read for success, < 0 for failure
  217. */
  218. int telemetry_raw_read_events(enum telemetry_unit telem_unit,
  219. struct telemetry_evtlog *evtlog, int len)
  220. {
  221. return telm_core_conf.telem_ops->raw_read_eventlog(telem_unit, evtlog,
  222. len, 0);
  223. }
  224. EXPORT_SYMBOL_GPL(telemetry_raw_read_events);
  225. /**
  226. * telemetry_read_eventlog() - Fetch the Telemetry log from PSS or IOSS
  227. * @telem_unit: Specify whether IOSS or PSS Read
  228. * @evtlog: Array of telemetry_evtlog structs to fill data
  229. * @len: Length of array of evtlog
  230. *
  231. * Return: number of eventlogs read for success, < 0 for failure
  232. */
  233. int telemetry_read_eventlog(enum telemetry_unit telem_unit,
  234. struct telemetry_evtlog *evtlog, int len)
  235. {
  236. return telm_core_conf.telem_ops->read_eventlog(telem_unit, evtlog,
  237. len, 1);
  238. }
  239. EXPORT_SYMBOL_GPL(telemetry_read_eventlog);
  240. /**
  241. * telemetry_raw_read_eventlog() - Fetch the Telemetry log from PSS or IOSS
  242. * @telem_unit: Specify whether IOSS or PSS Read
  243. * @evtlog: Array of telemetry_evtlog structs to fill data
  244. * @len: Length of array of evtlog
  245. *
  246. * The caller must take care of locking in this case.
  247. *
  248. * Return: number of eventlogs read for success, < 0 for failure
  249. */
  250. int telemetry_raw_read_eventlog(enum telemetry_unit telem_unit,
  251. struct telemetry_evtlog *evtlog, int len)
  252. {
  253. return telm_core_conf.telem_ops->raw_read_eventlog(telem_unit, evtlog,
  254. len, 1);
  255. }
  256. EXPORT_SYMBOL_GPL(telemetry_raw_read_eventlog);
  257. /**
  258. * telemetry_get_trace_verbosity() - Get the IOSS & PSS Trace verbosity
  259. * @telem_unit: Specify whether IOSS or PSS Read
  260. * @verbosity: Pointer to return Verbosity
  261. *
  262. * Return: 0 success, < 0 for failure
  263. */
  264. int telemetry_get_trace_verbosity(enum telemetry_unit telem_unit,
  265. u32 *verbosity)
  266. {
  267. return telm_core_conf.telem_ops->get_trace_verbosity(telem_unit,
  268. verbosity);
  269. }
  270. EXPORT_SYMBOL_GPL(telemetry_get_trace_verbosity);
  271. /**
  272. * telemetry_set_trace_verbosity() - Update the IOSS & PSS Trace verbosity
  273. * @telem_unit: Specify whether IOSS or PSS Read
  274. * @verbosity: Verbosity to set
  275. *
  276. * Return: 0 success, < 0 for failure
  277. */
  278. int telemetry_set_trace_verbosity(enum telemetry_unit telem_unit, u32 verbosity)
  279. {
  280. return telm_core_conf.telem_ops->set_trace_verbosity(telem_unit,
  281. verbosity);
  282. }
  283. EXPORT_SYMBOL_GPL(telemetry_set_trace_verbosity);
  284. /**
  285. * telemetry_set_pltdata() - Set the platform specific Data
  286. * @ops: Pointer to ops structure
  287. * @pltconfig: Platform config data
  288. *
  289. * Usage by other than telemetry pltdrv module is invalid
  290. *
  291. * Return: 0 success, < 0 for failure
  292. */
  293. int telemetry_set_pltdata(const struct telemetry_core_ops *ops,
  294. struct telemetry_plt_config *pltconfig)
  295. {
  296. if (ops)
  297. telm_core_conf.telem_ops = ops;
  298. if (pltconfig)
  299. telm_core_conf.plt_config = pltconfig;
  300. return 0;
  301. }
  302. EXPORT_SYMBOL_GPL(telemetry_set_pltdata);
  303. /**
  304. * telemetry_clear_pltdata() - Clear the platform specific Data
  305. *
  306. * Usage by other than telemetry pltdrv module is invalid
  307. *
  308. * Return: 0 success, < 0 for failure
  309. */
  310. int telemetry_clear_pltdata(void)
  311. {
  312. telm_core_conf.telem_ops = &telm_defpltops;
  313. telm_core_conf.plt_config = NULL;
  314. return 0;
  315. }
  316. EXPORT_SYMBOL_GPL(telemetry_clear_pltdata);
  317. /**
  318. * telemetry_pltconfig_valid() - Checkif platform config is valid
  319. *
  320. * Usage by other than telemetry module is invalid
  321. *
  322. * Return: 0 success, < 0 for failure
  323. */
  324. int telemetry_pltconfig_valid(void)
  325. {
  326. if (telm_core_conf.plt_config)
  327. return 0;
  328. else
  329. return -EINVAL;
  330. }
  331. EXPORT_SYMBOL_GPL(telemetry_pltconfig_valid);
  332. static inline int telemetry_get_pssevtname(enum telemetry_unit telem_unit,
  333. const char **name, int len)
  334. {
  335. struct telemetry_unit_config psscfg;
  336. int i;
  337. if (!telm_core_conf.plt_config)
  338. return -EINVAL;
  339. psscfg = telm_core_conf.plt_config->pss_config;
  340. if (len > psscfg.ssram_evts_used)
  341. len = psscfg.ssram_evts_used;
  342. for (i = 0; i < len; i++)
  343. name[i] = psscfg.telem_evts[i].name;
  344. return 0;
  345. }
  346. static inline int telemetry_get_iossevtname(enum telemetry_unit telem_unit,
  347. const char **name, int len)
  348. {
  349. struct telemetry_unit_config iosscfg;
  350. int i;
  351. if (!(telm_core_conf.plt_config))
  352. return -EINVAL;
  353. iosscfg = telm_core_conf.plt_config->ioss_config;
  354. if (len > iosscfg.ssram_evts_used)
  355. len = iosscfg.ssram_evts_used;
  356. for (i = 0; i < len; i++)
  357. name[i] = iosscfg.telem_evts[i].name;
  358. return 0;
  359. }
  360. /**
  361. * telemetry_get_evtname() - Checkif platform config is valid
  362. * @telem_unit: Telemetry Unit to check
  363. * @name: Array of character pointers to contain name
  364. * @len: length of array name provided by user
  365. *
  366. * Usage by other than telemetry debugfs module is invalid
  367. *
  368. * Return: 0 success, < 0 for failure
  369. */
  370. int telemetry_get_evtname(enum telemetry_unit telem_unit,
  371. const char **name, int len)
  372. {
  373. int ret = -EINVAL;
  374. if (telem_unit == TELEM_PSS)
  375. ret = telemetry_get_pssevtname(telem_unit, name, len);
  376. else if (telem_unit == TELEM_IOSS)
  377. ret = telemetry_get_iossevtname(telem_unit, name, len);
  378. return ret;
  379. }
  380. EXPORT_SYMBOL_GPL(telemetry_get_evtname);
  381. static int __init telemetry_module_init(void)
  382. {
  383. pr_info(pr_fmt(DRIVER_NAME) " Init\n");
  384. telm_core_conf.telem_ops = &telm_defpltops;
  385. return 0;
  386. }
  387. static void __exit telemetry_module_exit(void)
  388. {
  389. }
  390. module_init(telemetry_module_init);
  391. module_exit(telemetry_module_exit);
  392. MODULE_AUTHOR("Souvik Kumar Chakravarty <souvik.k.chakravarty@intel.com>");
  393. MODULE_DESCRIPTION("Intel SoC Telemetry Interface");
  394. MODULE_LICENSE("GPL v2");