amd_hsmp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _ASM_X86_AMD_HSMP_H_
  3. #define _ASM_X86_AMD_HSMP_H_
  4. #include <linux/types.h>
  5. #pragma pack(4)
  6. #define HSMP_MAX_MSG_LEN 8
  7. /*
  8. * HSMP Messages supported
  9. */
  10. enum hsmp_message_ids {
  11. HSMP_TEST = 1, /* 01h Increments input value by 1 */
  12. HSMP_GET_SMU_VER, /* 02h SMU FW version */
  13. HSMP_GET_PROTO_VER, /* 03h HSMP interface version */
  14. HSMP_GET_SOCKET_POWER, /* 04h average package power consumption */
  15. HSMP_SET_SOCKET_POWER_LIMIT, /* 05h Set the socket power limit */
  16. HSMP_GET_SOCKET_POWER_LIMIT, /* 06h Get current socket power limit */
  17. HSMP_GET_SOCKET_POWER_LIMIT_MAX,/* 07h Get maximum socket power value */
  18. HSMP_SET_BOOST_LIMIT, /* 08h Set a core maximum frequency limit */
  19. HSMP_SET_BOOST_LIMIT_SOCKET, /* 09h Set socket maximum frequency level */
  20. HSMP_GET_BOOST_LIMIT, /* 0Ah Get current frequency limit */
  21. HSMP_GET_PROC_HOT, /* 0Bh Get PROCHOT status */
  22. HSMP_SET_XGMI_LINK_WIDTH, /* 0Ch Set max and min width of xGMI Link */
  23. HSMP_SET_DF_PSTATE, /* 0Dh Alter APEnable/Disable messages behavior */
  24. HSMP_SET_AUTO_DF_PSTATE, /* 0Eh Enable DF P-State Performance Boost algorithm */
  25. HSMP_GET_FCLK_MCLK, /* 0Fh Get FCLK and MEMCLK for current socket */
  26. HSMP_GET_CCLK_THROTTLE_LIMIT, /* 10h Get CCLK frequency limit in socket */
  27. HSMP_GET_C0_PERCENT, /* 11h Get average C0 residency in socket */
  28. HSMP_SET_NBIO_DPM_LEVEL, /* 12h Set max/min LCLK DPM Level for a given NBIO */
  29. HSMP_GET_NBIO_DPM_LEVEL, /* 13h Get LCLK DPM level min and max for a given NBIO */
  30. HSMP_GET_DDR_BANDWIDTH, /* 14h Get theoretical maximum and current DDR Bandwidth */
  31. HSMP_GET_TEMP_MONITOR, /* 15h Get socket temperature */
  32. HSMP_GET_DIMM_TEMP_RANGE, /* 16h Get per-DIMM temperature range and refresh rate */
  33. HSMP_GET_DIMM_POWER, /* 17h Get per-DIMM power consumption */
  34. HSMP_GET_DIMM_THERMAL, /* 18h Get per-DIMM thermal sensors */
  35. HSMP_GET_SOCKET_FREQ_LIMIT, /* 19h Get current active frequency per socket */
  36. HSMP_GET_CCLK_CORE_LIMIT, /* 1Ah Get CCLK frequency limit per core */
  37. HSMP_GET_RAILS_SVI, /* 1Bh Get SVI-based Telemetry for all rails */
  38. HSMP_GET_SOCKET_FMAX_FMIN, /* 1Ch Get Fmax and Fmin per socket */
  39. HSMP_GET_IOLINK_BANDWITH, /* 1Dh Get current bandwidth on IO Link */
  40. HSMP_GET_XGMI_BANDWITH, /* 1Eh Get current bandwidth on xGMI Link */
  41. HSMP_SET_GMI3_WIDTH, /* 1Fh Set max and min GMI3 Link width */
  42. HSMP_SET_PCI_RATE, /* 20h Control link rate on PCIe devices */
  43. HSMP_SET_POWER_MODE, /* 21h Select power efficiency profile policy */
  44. HSMP_SET_PSTATE_MAX_MIN, /* 22h Set the max and min DF P-State */
  45. HSMP_GET_METRIC_TABLE_VER, /* 23h Get metrics table version */
  46. HSMP_GET_METRIC_TABLE, /* 24h Get metrics table */
  47. HSMP_GET_METRIC_TABLE_DRAM_ADDR,/* 25h Get metrics table dram address */
  48. HSMP_SET_XGMI_PSTATE_RANGE, /* 26h Set xGMI P-state range */
  49. HSMP_CPU_RAIL_ISO_FREQ_POLICY, /* 27h Get/Set Cpu Iso frequency policy */
  50. HSMP_DFC_ENABLE_CTRL, /* 28h Enable/Disable DF C-state */
  51. HSMP_GET_RAPL_UNITS = 0x30, /* 30h Get scaling factor for energy */
  52. HSMP_GET_RAPL_CORE_COUNTER, /* 31h Get core energy counter value */
  53. HSMP_GET_RAPL_PACKAGE_COUNTER, /* 32h Get package energy counter value */
  54. HSMP_MSG_ID_MAX,
  55. };
  56. struct hsmp_message {
  57. __u32 msg_id; /* Message ID */
  58. __u16 num_args; /* Number of input argument words in message */
  59. __u16 response_sz; /* Number of expected output/response words */
  60. __u32 args[HSMP_MAX_MSG_LEN]; /* argument/response buffer */
  61. __u16 sock_ind; /* socket number */
  62. };
  63. enum hsmp_msg_type {
  64. HSMP_RSVD = -1,
  65. HSMP_SET = 0,
  66. HSMP_GET = 1,
  67. HSMP_SET_GET = 2,
  68. };
  69. enum hsmp_proto_versions {
  70. HSMP_PROTO_VER2 = 2,
  71. HSMP_PROTO_VER3,
  72. HSMP_PROTO_VER4,
  73. HSMP_PROTO_VER5,
  74. HSMP_PROTO_VER6,
  75. HSMP_PROTO_VER7
  76. };
  77. struct hsmp_msg_desc {
  78. int num_args;
  79. int response_sz;
  80. enum hsmp_msg_type type;
  81. };
  82. /*
  83. * User may use these comments as reference, please find the
  84. * supported list of messages and message definition in the
  85. * HSMP chapter of respective family/model PPR.
  86. *
  87. * Not supported messages would return -ENOMSG.
  88. */
  89. static const struct hsmp_msg_desc hsmp_msg_desc_table[]
  90. __attribute__((unused)) = {
  91. /* RESERVED */
  92. {0, 0, HSMP_RSVD},
  93. /*
  94. * HSMP_TEST, num_args = 1, response_sz = 1
  95. * input: args[0] = xx
  96. * output: args[0] = xx + 1
  97. */
  98. {1, 1, HSMP_GET},
  99. /*
  100. * HSMP_GET_SMU_VER, num_args = 0, response_sz = 1
  101. * output: args[0] = smu fw ver
  102. */
  103. {0, 1, HSMP_GET},
  104. /*
  105. * HSMP_GET_PROTO_VER, num_args = 0, response_sz = 1
  106. * output: args[0] = proto version
  107. */
  108. {0, 1, HSMP_GET},
  109. /*
  110. * HSMP_GET_SOCKET_POWER, num_args = 0, response_sz = 1
  111. * output: args[0] = socket power in mWatts
  112. */
  113. {0, 1, HSMP_GET},
  114. /*
  115. * HSMP_SET_SOCKET_POWER_LIMIT, num_args = 1, response_sz = 0
  116. * input: args[0] = power limit value in mWatts
  117. */
  118. {1, 0, HSMP_SET},
  119. /*
  120. * HSMP_GET_SOCKET_POWER_LIMIT, num_args = 0, response_sz = 1
  121. * output: args[0] = socket power limit value in mWatts
  122. */
  123. {0, 1, HSMP_GET},
  124. /*
  125. * HSMP_GET_SOCKET_POWER_LIMIT_MAX, num_args = 0, response_sz = 1
  126. * output: args[0] = maximuam socket power limit in mWatts
  127. */
  128. {0, 1, HSMP_GET},
  129. /*
  130. * HSMP_SET_BOOST_LIMIT, num_args = 1, response_sz = 0
  131. * input: args[0] = apic id[31:16] + boost limit value in MHz[15:0]
  132. */
  133. {1, 0, HSMP_SET},
  134. /*
  135. * HSMP_SET_BOOST_LIMIT_SOCKET, num_args = 1, response_sz = 0
  136. * input: args[0] = boost limit value in MHz
  137. */
  138. {1, 0, HSMP_SET},
  139. /*
  140. * HSMP_GET_BOOST_LIMIT, num_args = 1, response_sz = 1
  141. * input: args[0] = apic id
  142. * output: args[0] = boost limit value in MHz
  143. */
  144. {1, 1, HSMP_GET},
  145. /*
  146. * HSMP_GET_PROC_HOT, num_args = 0, response_sz = 1
  147. * output: args[0] = proc hot status
  148. */
  149. {0, 1, HSMP_GET},
  150. /*
  151. * HSMP_SET_XGMI_LINK_WIDTH, num_args = 1, response_sz = 0
  152. * input: args[0] = min link width[15:8] + max link width[7:0]
  153. */
  154. {1, 0, HSMP_SET},
  155. /*
  156. * HSMP_SET_DF_PSTATE, num_args = 1, response_sz = 0
  157. * input: args[0] = df pstate[7:0]
  158. */
  159. {1, 0, HSMP_SET},
  160. /* HSMP_SET_AUTO_DF_PSTATE, num_args = 0, response_sz = 0 */
  161. {0, 0, HSMP_SET},
  162. /*
  163. * HSMP_GET_FCLK_MCLK, num_args = 0, response_sz = 2
  164. * output: args[0] = fclk in MHz, args[1] = mclk in MHz
  165. */
  166. {0, 2, HSMP_GET},
  167. /*
  168. * HSMP_GET_CCLK_THROTTLE_LIMIT, num_args = 0, response_sz = 1
  169. * output: args[0] = core clock in MHz
  170. */
  171. {0, 1, HSMP_GET},
  172. /*
  173. * HSMP_GET_C0_PERCENT, num_args = 0, response_sz = 1
  174. * output: args[0] = average c0 residency
  175. */
  176. {0, 1, HSMP_GET},
  177. /*
  178. * HSMP_SET_NBIO_DPM_LEVEL, num_args = 1, response_sz = 0
  179. * input: args[0] = nbioid[23:16] + max dpm level[15:8] + min dpm level[7:0]
  180. */
  181. {1, 0, HSMP_SET},
  182. /*
  183. * HSMP_GET_NBIO_DPM_LEVEL, num_args = 1, response_sz = 1
  184. * input: args[0] = nbioid[23:16]
  185. * output: args[0] = max dpm level[15:8] + min dpm level[7:0]
  186. */
  187. {1, 1, HSMP_GET},
  188. /*
  189. * HSMP_GET_DDR_BANDWIDTH, num_args = 0, response_sz = 1
  190. * output: args[0] = max bw in Gbps[31:20] + utilised bw in Gbps[19:8] +
  191. * bw in percentage[7:0]
  192. */
  193. {0, 1, HSMP_GET},
  194. /*
  195. * HSMP_GET_TEMP_MONITOR, num_args = 0, response_sz = 1
  196. * output: args[0] = temperature in degree celsius. [15:8] integer part +
  197. * [7:5] fractional part
  198. */
  199. {0, 1, HSMP_GET},
  200. /*
  201. * HSMP_GET_DIMM_TEMP_RANGE, num_args = 1, response_sz = 1
  202. * input: args[0] = DIMM address[7:0]
  203. * output: args[0] = refresh rate[3] + temperature range[2:0]
  204. */
  205. {1, 1, HSMP_GET},
  206. /*
  207. * HSMP_GET_DIMM_POWER, num_args = 1, response_sz = 1
  208. * input: args[0] = DIMM address[7:0]
  209. * output: args[0] = DIMM power in mW[31:17] + update rate in ms[16:8] +
  210. * DIMM address[7:0]
  211. */
  212. {1, 1, HSMP_GET},
  213. /*
  214. * HSMP_GET_DIMM_THERMAL, num_args = 1, response_sz = 1
  215. * input: args[0] = DIMM address[7:0]
  216. * output: args[0] = temperature in degree celsius[31:21] + update rate in ms[16:8] +
  217. * DIMM address[7:0]
  218. */
  219. {1, 1, HSMP_GET},
  220. /*
  221. * HSMP_GET_SOCKET_FREQ_LIMIT, num_args = 0, response_sz = 1
  222. * output: args[0] = frequency in MHz[31:16] + frequency source[15:0]
  223. */
  224. {0, 1, HSMP_GET},
  225. /*
  226. * HSMP_GET_CCLK_CORE_LIMIT, num_args = 1, response_sz = 1
  227. * input: args[0] = apic id [31:0]
  228. * output: args[0] = frequency in MHz[31:0]
  229. */
  230. {1, 1, HSMP_GET},
  231. /*
  232. * HSMP_GET_RAILS_SVI, num_args = 0, response_sz = 1
  233. * output: args[0] = power in mW[31:0]
  234. */
  235. {0, 1, HSMP_GET},
  236. /*
  237. * HSMP_GET_SOCKET_FMAX_FMIN, num_args = 0, response_sz = 1
  238. * output: args[0] = fmax in MHz[31:16] + fmin in MHz[15:0]
  239. */
  240. {0, 1, HSMP_GET},
  241. /*
  242. * HSMP_GET_IOLINK_BANDWITH, num_args = 1, response_sz = 1
  243. * input: args[0] = link id[15:8] + bw type[2:0]
  244. * output: args[0] = io bandwidth in Mbps[31:0]
  245. */
  246. {1, 1, HSMP_GET},
  247. /*
  248. * HSMP_GET_XGMI_BANDWITH, num_args = 1, response_sz = 1
  249. * input: args[0] = link id[15:8] + bw type[2:0]
  250. * output: args[0] = xgmi bandwidth in Mbps[31:0]
  251. */
  252. {1, 1, HSMP_GET},
  253. /*
  254. * HSMP_SET_GMI3_WIDTH, num_args = 1, response_sz = 0
  255. * input: args[0] = min link width[15:8] + max link width[7:0]
  256. */
  257. {1, 0, HSMP_SET},
  258. /*
  259. * HSMP_SET_PCI_RATE, num_args = 1, response_sz = 1
  260. * input: args[0] = link rate control value
  261. * output: args[0] = previous link rate control value
  262. */
  263. {1, 1, HSMP_SET},
  264. /*
  265. * HSMP_SET_POWER_MODE, num_args = 1, response_sz = 0
  266. * input: args[0] = power efficiency mode[2:0]
  267. */
  268. {1, 1, HSMP_SET_GET},
  269. /*
  270. * HSMP_SET_PSTATE_MAX_MIN, num_args = 1, response_sz = 0
  271. * input: args[0] = min df pstate[15:8] + max df pstate[7:0]
  272. */
  273. {1, 0, HSMP_SET},
  274. /*
  275. * HSMP_GET_METRIC_TABLE_VER, num_args = 0, response_sz = 1
  276. * output: args[0] = metrics table version
  277. */
  278. {0, 1, HSMP_GET},
  279. /*
  280. * HSMP_GET_METRIC_TABLE, num_args = 0, response_sz = 0
  281. */
  282. {0, 0, HSMP_GET},
  283. /*
  284. * HSMP_GET_METRIC_TABLE_DRAM_ADDR, num_args = 0, response_sz = 2
  285. * output: args[0] = lower 32 bits of the address
  286. * output: args[1] = upper 32 bits of the address
  287. */
  288. {0, 2, HSMP_GET},
  289. /*
  290. * HSMP_SET_XGMI_PSTATE_RANGE, num_args = 1, response_sz = 0
  291. * input: args[0] = min xGMI p-state[15:8] + max xGMI p-state[7:0]
  292. */
  293. {1, 0, HSMP_SET},
  294. /*
  295. * HSMP_CPU_RAIL_ISO_FREQ_POLICY, num_args = 1, response_sz = 1
  296. * input: args[0] = set/get policy[31] +
  297. * disable/enable independent control[0]
  298. * output: args[0] = current policy[0]
  299. */
  300. {1, 1, HSMP_SET_GET},
  301. /*
  302. * HSMP_DFC_ENABLE_CTRL, num_args = 1, response_sz = 1
  303. * input: args[0] = set/get policy[31] + enable/disable DFC[0]
  304. * output: args[0] = current policy[0]
  305. */
  306. {1, 1, HSMP_SET_GET},
  307. /* RESERVED(0x29-0x2f) */
  308. {0, 0, HSMP_RSVD},
  309. {0, 0, HSMP_RSVD},
  310. {0, 0, HSMP_RSVD},
  311. {0, 0, HSMP_RSVD},
  312. {0, 0, HSMP_RSVD},
  313. {0, 0, HSMP_RSVD},
  314. {0, 0, HSMP_RSVD},
  315. /*
  316. * HSMP_GET_RAPL_UNITS, response_sz = 1
  317. * output: args[0] = tu value[19:16] + esu value[12:8]
  318. */
  319. {0, 1, HSMP_GET},
  320. /*
  321. * HSMP_GET_RAPL_CORE_COUNTER, num_args = 1, response_sz = 1
  322. * input: args[0] = apic id[15:0]
  323. * output: args[0] = lower 32 bits of energy
  324. * output: args[1] = upper 32 bits of energy
  325. */
  326. {1, 2, HSMP_GET},
  327. /*
  328. * HSMP_GET_RAPL_PACKAGE_COUNTER, num_args = 0, response_sz = 1
  329. * output: args[0] = lower 32 bits of energy
  330. * output: args[1] = upper 32 bits of energy
  331. */
  332. {0, 2, HSMP_GET},
  333. };
  334. /* Metrics table (supported only with proto version 6) */
  335. struct hsmp_metric_table {
  336. __u32 accumulation_counter;
  337. /* TEMPERATURE */
  338. __u32 max_socket_temperature;
  339. __u32 max_vr_temperature;
  340. __u32 max_hbm_temperature;
  341. __u64 max_socket_temperature_acc;
  342. __u64 max_vr_temperature_acc;
  343. __u64 max_hbm_temperature_acc;
  344. /* POWER */
  345. __u32 socket_power_limit;
  346. __u32 max_socket_power_limit;
  347. __u32 socket_power;
  348. /* ENERGY */
  349. __u64 timestamp;
  350. __u64 socket_energy_acc;
  351. __u64 ccd_energy_acc;
  352. __u64 xcd_energy_acc;
  353. __u64 aid_energy_acc;
  354. __u64 hbm_energy_acc;
  355. /* FREQUENCY */
  356. __u32 cclk_frequency_limit;
  357. __u32 gfxclk_frequency_limit;
  358. __u32 fclk_frequency;
  359. __u32 uclk_frequency;
  360. __u32 socclk_frequency[4];
  361. __u32 vclk_frequency[4];
  362. __u32 dclk_frequency[4];
  363. __u32 lclk_frequency[4];
  364. __u64 gfxclk_frequency_acc[8];
  365. __u64 cclk_frequency_acc[96];
  366. /* FREQUENCY RANGE */
  367. __u32 max_cclk_frequency;
  368. __u32 min_cclk_frequency;
  369. __u32 max_gfxclk_frequency;
  370. __u32 min_gfxclk_frequency;
  371. __u32 fclk_frequency_table[4];
  372. __u32 uclk_frequency_table[4];
  373. __u32 socclk_frequency_table[4];
  374. __u32 vclk_frequency_table[4];
  375. __u32 dclk_frequency_table[4];
  376. __u32 lclk_frequency_table[4];
  377. __u32 max_lclk_dpm_range;
  378. __u32 min_lclk_dpm_range;
  379. /* XGMI */
  380. __u32 xgmi_width;
  381. __u32 xgmi_bitrate;
  382. __u64 xgmi_read_bandwidth_acc[8];
  383. __u64 xgmi_write_bandwidth_acc[8];
  384. /* ACTIVITY */
  385. __u32 socket_c0_residency;
  386. __u32 socket_gfx_busy;
  387. __u32 dram_bandwidth_utilization;
  388. __u64 socket_c0_residency_acc;
  389. __u64 socket_gfx_busy_acc;
  390. __u64 dram_bandwidth_acc;
  391. __u32 max_dram_bandwidth;
  392. __u64 dram_bandwidth_utilization_acc;
  393. __u64 pcie_bandwidth_acc[4];
  394. /* THROTTLERS */
  395. __u32 prochot_residency_acc;
  396. __u32 ppt_residency_acc;
  397. __u32 socket_thm_residency_acc;
  398. __u32 vr_thm_residency_acc;
  399. __u32 hbm_thm_residency_acc;
  400. __u32 spare;
  401. /* New items at the end to maintain driver compatibility */
  402. __u32 gfxclk_frequency[8];
  403. };
  404. /* Reset to default packing */
  405. #pragma pack()
  406. /* Define unique ioctl command for hsmp msgs using generic _IOWR */
  407. #define HSMP_BASE_IOCTL_NR 0xF8
  408. #define HSMP_IOCTL_CMD _IOWR(HSMP_BASE_IOCTL_NR, 0, struct hsmp_message)
  409. #endif /*_ASM_X86_AMD_HSMP_H_*/