162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci#ifndef _UAPI_ASM_X86_AMD_HSMP_H_
462306a36Sopenharmony_ci#define _UAPI_ASM_X86_AMD_HSMP_H_
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/types.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#pragma pack(4)
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define HSMP_MAX_MSG_LEN 8
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci/*
1362306a36Sopenharmony_ci * HSMP Messages supported
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_cienum hsmp_message_ids {
1662306a36Sopenharmony_ci	HSMP_TEST = 1,			/* 01h Increments input value by 1 */
1762306a36Sopenharmony_ci	HSMP_GET_SMU_VER,		/* 02h SMU FW version */
1862306a36Sopenharmony_ci	HSMP_GET_PROTO_VER,		/* 03h HSMP interface version */
1962306a36Sopenharmony_ci	HSMP_GET_SOCKET_POWER,		/* 04h average package power consumption */
2062306a36Sopenharmony_ci	HSMP_SET_SOCKET_POWER_LIMIT,	/* 05h Set the socket power limit */
2162306a36Sopenharmony_ci	HSMP_GET_SOCKET_POWER_LIMIT,	/* 06h Get current socket power limit */
2262306a36Sopenharmony_ci	HSMP_GET_SOCKET_POWER_LIMIT_MAX,/* 07h Get maximum socket power value */
2362306a36Sopenharmony_ci	HSMP_SET_BOOST_LIMIT,		/* 08h Set a core maximum frequency limit */
2462306a36Sopenharmony_ci	HSMP_SET_BOOST_LIMIT_SOCKET,	/* 09h Set socket maximum frequency level */
2562306a36Sopenharmony_ci	HSMP_GET_BOOST_LIMIT,		/* 0Ah Get current frequency limit */
2662306a36Sopenharmony_ci	HSMP_GET_PROC_HOT,		/* 0Bh Get PROCHOT status */
2762306a36Sopenharmony_ci	HSMP_SET_XGMI_LINK_WIDTH,	/* 0Ch Set max and min width of xGMI Link */
2862306a36Sopenharmony_ci	HSMP_SET_DF_PSTATE,		/* 0Dh Alter APEnable/Disable messages behavior */
2962306a36Sopenharmony_ci	HSMP_SET_AUTO_DF_PSTATE,	/* 0Eh Enable DF P-State Performance Boost algorithm */
3062306a36Sopenharmony_ci	HSMP_GET_FCLK_MCLK,		/* 0Fh Get FCLK and MEMCLK for current socket */
3162306a36Sopenharmony_ci	HSMP_GET_CCLK_THROTTLE_LIMIT,	/* 10h Get CCLK frequency limit in socket */
3262306a36Sopenharmony_ci	HSMP_GET_C0_PERCENT,		/* 11h Get average C0 residency in socket */
3362306a36Sopenharmony_ci	HSMP_SET_NBIO_DPM_LEVEL,	/* 12h Set max/min LCLK DPM Level for a given NBIO */
3462306a36Sopenharmony_ci	HSMP_GET_NBIO_DPM_LEVEL,	/* 13h Get LCLK DPM level min and max for a given NBIO */
3562306a36Sopenharmony_ci	HSMP_GET_DDR_BANDWIDTH,		/* 14h Get theoretical maximum and current DDR Bandwidth */
3662306a36Sopenharmony_ci	HSMP_GET_TEMP_MONITOR,		/* 15h Get socket temperature */
3762306a36Sopenharmony_ci	HSMP_GET_DIMM_TEMP_RANGE,	/* 16h Get per-DIMM temperature range and refresh rate */
3862306a36Sopenharmony_ci	HSMP_GET_DIMM_POWER,		/* 17h Get per-DIMM power consumption */
3962306a36Sopenharmony_ci	HSMP_GET_DIMM_THERMAL,		/* 18h Get per-DIMM thermal sensors */
4062306a36Sopenharmony_ci	HSMP_GET_SOCKET_FREQ_LIMIT,	/* 19h Get current active frequency per socket */
4162306a36Sopenharmony_ci	HSMP_GET_CCLK_CORE_LIMIT,	/* 1Ah Get CCLK frequency limit per core */
4262306a36Sopenharmony_ci	HSMP_GET_RAILS_SVI,		/* 1Bh Get SVI-based Telemetry for all rails */
4362306a36Sopenharmony_ci	HSMP_GET_SOCKET_FMAX_FMIN,	/* 1Ch Get Fmax and Fmin per socket */
4462306a36Sopenharmony_ci	HSMP_GET_IOLINK_BANDWITH,	/* 1Dh Get current bandwidth on IO Link */
4562306a36Sopenharmony_ci	HSMP_GET_XGMI_BANDWITH,		/* 1Eh Get current bandwidth on xGMI Link */
4662306a36Sopenharmony_ci	HSMP_SET_GMI3_WIDTH,		/* 1Fh Set max and min GMI3 Link width */
4762306a36Sopenharmony_ci	HSMP_SET_PCI_RATE,		/* 20h Control link rate on PCIe devices */
4862306a36Sopenharmony_ci	HSMP_SET_POWER_MODE,		/* 21h Select power efficiency profile policy */
4962306a36Sopenharmony_ci	HSMP_SET_PSTATE_MAX_MIN,	/* 22h Set the max and min DF P-State  */
5062306a36Sopenharmony_ci	HSMP_MSG_ID_MAX,
5162306a36Sopenharmony_ci};
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_cistruct hsmp_message {
5462306a36Sopenharmony_ci	__u32	msg_id;			/* Message ID */
5562306a36Sopenharmony_ci	__u16	num_args;		/* Number of input argument words in message */
5662306a36Sopenharmony_ci	__u16	response_sz;		/* Number of expected output/response words */
5762306a36Sopenharmony_ci	__u32	args[HSMP_MAX_MSG_LEN];	/* argument/response buffer */
5862306a36Sopenharmony_ci	__u16	sock_ind;		/* socket number */
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cienum hsmp_msg_type {
6262306a36Sopenharmony_ci	HSMP_RSVD = -1,
6362306a36Sopenharmony_ci	HSMP_SET  = 0,
6462306a36Sopenharmony_ci	HSMP_GET  = 1,
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_cistruct hsmp_msg_desc {
6862306a36Sopenharmony_ci	int num_args;
6962306a36Sopenharmony_ci	int response_sz;
7062306a36Sopenharmony_ci	enum hsmp_msg_type type;
7162306a36Sopenharmony_ci};
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/*
7462306a36Sopenharmony_ci * User may use these comments as reference, please find the
7562306a36Sopenharmony_ci * supported list of messages and message definition in the
7662306a36Sopenharmony_ci * HSMP chapter of respective family/model PPR.
7762306a36Sopenharmony_ci *
7862306a36Sopenharmony_ci * Not supported messages would return -ENOMSG.
7962306a36Sopenharmony_ci */
8062306a36Sopenharmony_cistatic const struct hsmp_msg_desc hsmp_msg_desc_table[] = {
8162306a36Sopenharmony_ci	/* RESERVED */
8262306a36Sopenharmony_ci	{0, 0, HSMP_RSVD},
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	/*
8562306a36Sopenharmony_ci	 * HSMP_TEST, num_args = 1, response_sz = 1
8662306a36Sopenharmony_ci	 * input:  args[0] = xx
8762306a36Sopenharmony_ci	 * output: args[0] = xx + 1
8862306a36Sopenharmony_ci	 */
8962306a36Sopenharmony_ci	{1, 1, HSMP_GET},
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci	/*
9262306a36Sopenharmony_ci	 * HSMP_GET_SMU_VER, num_args = 0, response_sz = 1
9362306a36Sopenharmony_ci	 * output: args[0] = smu fw ver
9462306a36Sopenharmony_ci	 */
9562306a36Sopenharmony_ci	{0, 1, HSMP_GET},
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci	/*
9862306a36Sopenharmony_ci	 * HSMP_GET_PROTO_VER, num_args = 0, response_sz = 1
9962306a36Sopenharmony_ci	 * output: args[0] = proto version
10062306a36Sopenharmony_ci	 */
10162306a36Sopenharmony_ci	{0, 1, HSMP_GET},
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci	/*
10462306a36Sopenharmony_ci	 * HSMP_GET_SOCKET_POWER, num_args = 0, response_sz = 1
10562306a36Sopenharmony_ci	 * output: args[0] = socket power in mWatts
10662306a36Sopenharmony_ci	 */
10762306a36Sopenharmony_ci	{0, 1, HSMP_GET},
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci	/*
11062306a36Sopenharmony_ci	 * HSMP_SET_SOCKET_POWER_LIMIT, num_args = 1, response_sz = 0
11162306a36Sopenharmony_ci	 * input: args[0] = power limit value in mWatts
11262306a36Sopenharmony_ci	 */
11362306a36Sopenharmony_ci	{1, 0, HSMP_SET},
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci	/*
11662306a36Sopenharmony_ci	 * HSMP_GET_SOCKET_POWER_LIMIT, num_args = 0, response_sz = 1
11762306a36Sopenharmony_ci	 * output: args[0] = socket power limit value in mWatts
11862306a36Sopenharmony_ci	 */
11962306a36Sopenharmony_ci	{0, 1, HSMP_GET},
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci	/*
12262306a36Sopenharmony_ci	 * HSMP_GET_SOCKET_POWER_LIMIT_MAX, num_args = 0, response_sz = 1
12362306a36Sopenharmony_ci	 * output: args[0] = maximuam socket power limit in mWatts
12462306a36Sopenharmony_ci	 */
12562306a36Sopenharmony_ci	{0, 1, HSMP_GET},
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci	/*
12862306a36Sopenharmony_ci	 * HSMP_SET_BOOST_LIMIT, num_args = 1, response_sz = 0
12962306a36Sopenharmony_ci	 * input: args[0] = apic id[31:16] + boost limit value in MHz[15:0]
13062306a36Sopenharmony_ci	 */
13162306a36Sopenharmony_ci	{1, 0, HSMP_SET},
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci	/*
13462306a36Sopenharmony_ci	 * HSMP_SET_BOOST_LIMIT_SOCKET, num_args = 1, response_sz = 0
13562306a36Sopenharmony_ci	 * input: args[0] = boost limit value in MHz
13662306a36Sopenharmony_ci	 */
13762306a36Sopenharmony_ci	{1, 0, HSMP_SET},
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci	/*
14062306a36Sopenharmony_ci	 * HSMP_GET_BOOST_LIMIT, num_args = 1, response_sz = 1
14162306a36Sopenharmony_ci	 * input: args[0] = apic id
14262306a36Sopenharmony_ci	 * output: args[0] = boost limit value in MHz
14362306a36Sopenharmony_ci	 */
14462306a36Sopenharmony_ci	{1, 1, HSMP_GET},
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci	/*
14762306a36Sopenharmony_ci	 * HSMP_GET_PROC_HOT, num_args = 0, response_sz = 1
14862306a36Sopenharmony_ci	 * output: args[0] = proc hot status
14962306a36Sopenharmony_ci	 */
15062306a36Sopenharmony_ci	{0, 1, HSMP_GET},
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	/*
15362306a36Sopenharmony_ci	 * HSMP_SET_XGMI_LINK_WIDTH, num_args = 1, response_sz = 0
15462306a36Sopenharmony_ci	 * input: args[0] = min link width[15:8] + max link width[7:0]
15562306a36Sopenharmony_ci	 */
15662306a36Sopenharmony_ci	{1, 0, HSMP_SET},
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci	/*
15962306a36Sopenharmony_ci	 * HSMP_SET_DF_PSTATE, num_args = 1, response_sz = 0
16062306a36Sopenharmony_ci	 * input: args[0] = df pstate[7:0]
16162306a36Sopenharmony_ci	 */
16262306a36Sopenharmony_ci	{1, 0, HSMP_SET},
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci	/* HSMP_SET_AUTO_DF_PSTATE, num_args = 0, response_sz = 0 */
16562306a36Sopenharmony_ci	{0, 0, HSMP_SET},
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci	/*
16862306a36Sopenharmony_ci	 * HSMP_GET_FCLK_MCLK, num_args = 0, response_sz = 2
16962306a36Sopenharmony_ci	 * output: args[0] = fclk in MHz, args[1] = mclk in MHz
17062306a36Sopenharmony_ci	 */
17162306a36Sopenharmony_ci	{0, 2, HSMP_GET},
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci	/*
17462306a36Sopenharmony_ci	 * HSMP_GET_CCLK_THROTTLE_LIMIT, num_args = 0, response_sz = 1
17562306a36Sopenharmony_ci	 * output: args[0] = core clock in MHz
17662306a36Sopenharmony_ci	 */
17762306a36Sopenharmony_ci	{0, 1, HSMP_GET},
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci	/*
18062306a36Sopenharmony_ci	 * HSMP_GET_C0_PERCENT, num_args = 0, response_sz = 1
18162306a36Sopenharmony_ci	 * output: args[0] = average c0 residency
18262306a36Sopenharmony_ci	 */
18362306a36Sopenharmony_ci	{0, 1, HSMP_GET},
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci	/*
18662306a36Sopenharmony_ci	 * HSMP_SET_NBIO_DPM_LEVEL, num_args = 1, response_sz = 0
18762306a36Sopenharmony_ci	 * input: args[0] = nbioid[23:16] + max dpm level[15:8] + min dpm level[7:0]
18862306a36Sopenharmony_ci	 */
18962306a36Sopenharmony_ci	{1, 0, HSMP_SET},
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci	/*
19262306a36Sopenharmony_ci	 * HSMP_GET_NBIO_DPM_LEVEL, num_args = 1, response_sz = 1
19362306a36Sopenharmony_ci	 * input: args[0] = nbioid[23:16]
19462306a36Sopenharmony_ci	 * output: args[0] = max dpm level[15:8] + min dpm level[7:0]
19562306a36Sopenharmony_ci	 */
19662306a36Sopenharmony_ci	{1, 1, HSMP_GET},
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci	/*
19962306a36Sopenharmony_ci	 * HSMP_GET_DDR_BANDWIDTH, num_args = 0, response_sz = 1
20062306a36Sopenharmony_ci	 * output: args[0] = max bw in Gbps[31:20] + utilised bw in Gbps[19:8] +
20162306a36Sopenharmony_ci	 * bw in percentage[7:0]
20262306a36Sopenharmony_ci	 */
20362306a36Sopenharmony_ci	{0, 1, HSMP_GET},
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci	/*
20662306a36Sopenharmony_ci	 * HSMP_GET_TEMP_MONITOR, num_args = 0, response_sz = 1
20762306a36Sopenharmony_ci	 * output: args[0] = temperature in degree celsius. [15:8] integer part +
20862306a36Sopenharmony_ci	 * [7:5] fractional part
20962306a36Sopenharmony_ci	 */
21062306a36Sopenharmony_ci	{0, 1, HSMP_GET},
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci	/*
21362306a36Sopenharmony_ci	 * HSMP_GET_DIMM_TEMP_RANGE, num_args = 1, response_sz = 1
21462306a36Sopenharmony_ci	 * input: args[0] = DIMM address[7:0]
21562306a36Sopenharmony_ci	 * output: args[0] = refresh rate[3] + temperature range[2:0]
21662306a36Sopenharmony_ci	 */
21762306a36Sopenharmony_ci	{1, 1, HSMP_GET},
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci	/*
22062306a36Sopenharmony_ci	 * HSMP_GET_DIMM_POWER, num_args = 1, response_sz = 1
22162306a36Sopenharmony_ci	 * input: args[0] = DIMM address[7:0]
22262306a36Sopenharmony_ci	 * output: args[0] = DIMM power in mW[31:17] + update rate in ms[16:8] +
22362306a36Sopenharmony_ci	 * DIMM address[7:0]
22462306a36Sopenharmony_ci	 */
22562306a36Sopenharmony_ci	{1, 1, HSMP_GET},
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci	/*
22862306a36Sopenharmony_ci	 * HSMP_GET_DIMM_THERMAL, num_args = 1, response_sz = 1
22962306a36Sopenharmony_ci	 * input: args[0] = DIMM address[7:0]
23062306a36Sopenharmony_ci	 * output: args[0] = temperature in degree celcius[31:21] + update rate in ms[16:8] +
23162306a36Sopenharmony_ci	 * DIMM address[7:0]
23262306a36Sopenharmony_ci	 */
23362306a36Sopenharmony_ci	{1, 1, HSMP_GET},
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci	/*
23662306a36Sopenharmony_ci	 * HSMP_GET_SOCKET_FREQ_LIMIT, num_args = 0, response_sz = 1
23762306a36Sopenharmony_ci	 * output: args[0] = frequency in MHz[31:16] + frequency source[15:0]
23862306a36Sopenharmony_ci	 */
23962306a36Sopenharmony_ci	{0, 1, HSMP_GET},
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci	/*
24262306a36Sopenharmony_ci	 * HSMP_GET_CCLK_CORE_LIMIT, num_args = 1, response_sz = 1
24362306a36Sopenharmony_ci	 * input: args[0] = apic id [31:0]
24462306a36Sopenharmony_ci	 * output: args[0] = frequency in MHz[31:0]
24562306a36Sopenharmony_ci	 */
24662306a36Sopenharmony_ci	{1, 1, HSMP_GET},
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci	/*
24962306a36Sopenharmony_ci	 * HSMP_GET_RAILS_SVI, num_args = 0, response_sz = 1
25062306a36Sopenharmony_ci	 * output: args[0] = power in mW[31:0]
25162306a36Sopenharmony_ci	 */
25262306a36Sopenharmony_ci	{0, 1, HSMP_GET},
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci	/*
25562306a36Sopenharmony_ci	 * HSMP_GET_SOCKET_FMAX_FMIN, num_args = 0, response_sz = 1
25662306a36Sopenharmony_ci	 * output: args[0] = fmax in MHz[31:16] + fmin in MHz[15:0]
25762306a36Sopenharmony_ci	 */
25862306a36Sopenharmony_ci	{0, 1, HSMP_GET},
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci	/*
26162306a36Sopenharmony_ci	 * HSMP_GET_IOLINK_BANDWITH, num_args = 1, response_sz = 1
26262306a36Sopenharmony_ci	 * input: args[0] = link id[15:8] + bw type[2:0]
26362306a36Sopenharmony_ci	 * output: args[0] = io bandwidth in Mbps[31:0]
26462306a36Sopenharmony_ci	 */
26562306a36Sopenharmony_ci	{1, 1, HSMP_GET},
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci	/*
26862306a36Sopenharmony_ci	 * HSMP_GET_XGMI_BANDWITH, num_args = 1, response_sz = 1
26962306a36Sopenharmony_ci	 * input: args[0] = link id[15:8] + bw type[2:0]
27062306a36Sopenharmony_ci	 * output: args[0] = xgmi bandwidth in Mbps[31:0]
27162306a36Sopenharmony_ci	 */
27262306a36Sopenharmony_ci	{1, 1, HSMP_GET},
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci	/*
27562306a36Sopenharmony_ci	 * HSMP_SET_GMI3_WIDTH, num_args = 1, response_sz = 0
27662306a36Sopenharmony_ci	 * input: args[0] = min link width[15:8] + max link width[7:0]
27762306a36Sopenharmony_ci	 */
27862306a36Sopenharmony_ci	{1, 0, HSMP_SET},
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci	/*
28162306a36Sopenharmony_ci	 * HSMP_SET_PCI_RATE, num_args = 1, response_sz = 1
28262306a36Sopenharmony_ci	 * input: args[0] = link rate control value
28362306a36Sopenharmony_ci	 * output: args[0] = previous link rate control value
28462306a36Sopenharmony_ci	 */
28562306a36Sopenharmony_ci	{1, 1, HSMP_SET},
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci	/*
28862306a36Sopenharmony_ci	 * HSMP_SET_POWER_MODE, num_args = 1, response_sz = 0
28962306a36Sopenharmony_ci	 * input: args[0] = power efficiency mode[2:0]
29062306a36Sopenharmony_ci	 */
29162306a36Sopenharmony_ci	{1, 0, HSMP_SET},
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci	/*
29462306a36Sopenharmony_ci	 * HSMP_SET_PSTATE_MAX_MIN, num_args = 1, response_sz = 0
29562306a36Sopenharmony_ci	 * input: args[0] = min df pstate[15:8] + max df pstate[7:0]
29662306a36Sopenharmony_ci	 */
29762306a36Sopenharmony_ci	{1, 0, HSMP_SET},
29862306a36Sopenharmony_ci};
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_ci/* Reset to default packing */
30162306a36Sopenharmony_ci#pragma pack()
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ci/* Define unique ioctl command for hsmp msgs using generic _IOWR */
30462306a36Sopenharmony_ci#define HSMP_BASE_IOCTL_NR	0xF8
30562306a36Sopenharmony_ci#define HSMP_IOCTL_CMD		_IOWR(HSMP_BASE_IOCTL_NR, 0, struct hsmp_message)
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci#endif /*_ASM_X86_AMD_HSMP_H_*/
308