Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: ccp - Add support for getting and setting DBC parameters

After software has authenticated a dynamic boost control request,
it can fetch and set supported parameters using a selection of messages.

Add support for these messages and export the ability to do this to
userspace.

Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Mario Limonciello and committed by
Herbert Xu
e2cfe05e d9408716

+109
+41
drivers/crypto/ccp/dbc.c
··· 74 74 return ret; 75 75 } 76 76 77 + static int send_dbc_parameter(struct psp_dbc_device *dbc_dev) 78 + { 79 + dbc_dev->mbox->req.header.payload_size = sizeof(dbc_dev->mbox->dbc_param); 80 + 81 + switch (dbc_dev->mbox->dbc_param.user.msg_index) { 82 + case PARAM_SET_FMAX_CAP: 83 + case PARAM_SET_PWR_CAP: 84 + case PARAM_SET_GFX_MODE: 85 + return send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_SET_PARAMETER); 86 + case PARAM_GET_FMAX_CAP: 87 + case PARAM_GET_PWR_CAP: 88 + case PARAM_GET_CURR_TEMP: 89 + case PARAM_GET_FMAX_MAX: 90 + case PARAM_GET_FMAX_MIN: 91 + case PARAM_GET_SOC_PWR_MAX: 92 + case PARAM_GET_SOC_PWR_MIN: 93 + case PARAM_GET_SOC_PWR_CUR: 94 + case PARAM_GET_GFX_MODE: 95 + return send_dbc_cmd(dbc_dev, PSP_DYNAMIC_BOOST_GET_PARAMETER); 96 + } 97 + 98 + return -EINVAL; 99 + } 100 + 77 101 void dbc_dev_destroy(struct psp_device *psp) 78 102 { 79 103 struct psp_dbc_device *dbc_dev = psp->dbc_data; ··· 155 131 156 132 if (copy_to_user(argp, &dbc_dev->mbox->dbc_set_uid.user, 157 133 sizeof(struct dbc_user_setuid))) { 134 + ret = -EFAULT; 135 + goto unlock; 136 + } 137 + break; 138 + case DBCIOCPARAM: 139 + if (copy_from_user(&dbc_dev->mbox->dbc_param.user, argp, 140 + sizeof(struct dbc_user_param))) { 141 + ret = -EFAULT; 142 + goto unlock; 143 + } 144 + 145 + ret = send_dbc_parameter(dbc_dev); 146 + if (ret) 147 + goto unlock; 148 + 149 + if (copy_to_user(argp, &dbc_dev->mbox->dbc_param.user, 150 + sizeof(struct dbc_user_param))) { 158 151 ret = -EFAULT; 159 152 goto unlock; 160 153 }
+6
drivers/crypto/ccp/dbc.h
··· 38 38 struct dbc_user_setuid user; 39 39 } __packed; 40 40 41 + struct dbc_param { 42 + struct psp_req_buffer_hdr header; 43 + struct dbc_user_param user; 44 + } __packed; 45 + 41 46 union dbc_buffer { 42 47 struct psp_request req; 43 48 struct dbc_nonce dbc_nonce; 44 49 struct dbc_set_uid dbc_set_uid; 50 + struct dbc_param dbc_param; 45 51 }; 46 52 47 53 void dbc_dev_destroy(struct psp_device *psp);
+2
include/linux/psp-platform-access.h
··· 10 10 PSP_I2C_REQ_BUS_CMD = 0x64, 11 11 PSP_DYNAMIC_BOOST_GET_NONCE, 12 12 PSP_DYNAMIC_BOOST_SET_UID, 13 + PSP_DYNAMIC_BOOST_GET_PARAMETER, 14 + PSP_DYNAMIC_BOOST_SET_PARAMETER, 13 15 }; 14 16 15 17 struct psp_req_buffer_hdr {
+60
include/uapi/linux/psp-dbc.h
··· 46 46 } __packed; 47 47 48 48 /** 49 + * struct dbc_user_param - Parameter exchange structure (input/output). 50 + * @msg_index: Message indicating what parameter to set or get (input) 51 + * @param: 4 byte parameter, units are message specific. (input/output) 52 + * @signature: 32 byte signature. 53 + * - When sending a message this is to be created by software 54 + * using a previous nonce (input) 55 + * - For interpreting results, this signature is updated by the 56 + * PSP to allow software to validate the authenticity of the 57 + * results. 58 + */ 59 + struct dbc_user_param { 60 + __u32 msg_index; 61 + __u32 param; 62 + __u8 signature[DBC_SIG_SIZE]; 63 + } __packed; 64 + 65 + /** 49 66 * Dynamic Boost Control (DBC) IOC 50 67 * 51 68 * possible return codes for all DBC IOCTLs: ··· 100 83 * The UID can only be set once until the system is rebooted. 101 84 */ 102 85 #define DBCIOCUID _IOW(DBC_IOC_TYPE, 0x2, struct dbc_user_setuid) 86 + 87 + /** 88 + * DBCIOCPARAM - Set or get a parameter from the PSP. 89 + * This request will only work after DBCIOCUID has successfully 90 + * set the UID of the calling process. 91 + * Whether the parameter is set or get is controlled by the 92 + * message ID in the request. 93 + * This command must be sent using a 32 byte signature built 94 + * using the nonce fetched from DBCIOCNONCE. 95 + * When the command succeeds, the 32 byte signature will be 96 + * updated by the PSP for software to authenticate the results. 97 + */ 98 + #define DBCIOCPARAM _IOWR(DBC_IOC_TYPE, 0x3, struct dbc_user_param) 99 + 100 + /** 101 + * enum dbc_cmd_msg - Messages utilized by DBCIOCPARAM 102 + * @PARAM_GET_FMAX_CAP: Get frequency cap (MHz) 103 + * @PARAM_SET_FMAX_CAP: Set frequency cap (MHz) 104 + * @PARAM_GET_PWR_CAP: Get socket power cap (mW) 105 + * @PARAM_SET_PWR_CAP: Set socket power cap (mW) 106 + * @PARAM_GET_GFX_MODE: Get graphics mode (0/1) 107 + * @PARAM_SET_GFX_MODE: Set graphics mode (0/1) 108 + * @PARAM_GET_CURR_TEMP: Get current temperature (degrees C) 109 + * @PARAM_GET_FMAX_MAX: Get maximum allowed value for frequency (MHz) 110 + * @PARAM_GET_FMAX_MIN: Get minimum allowed value for frequency (MHz) 111 + * @PARAM_GET_SOC_PWR_MAX: Get maximum allowed value for SoC power (mw) 112 + * @PARAM_GET_SOC_PWR_MIN: Get minimum allowed value for SoC power (mw) 113 + * @PARAM_GET_SOC_PWR_CUR: Get current value for SoC Power (mW) 114 + */ 115 + enum dbc_cmd_msg { 116 + PARAM_GET_FMAX_CAP = 0x3, 117 + PARAM_SET_FMAX_CAP = 0x4, 118 + PARAM_GET_PWR_CAP = 0x5, 119 + PARAM_SET_PWR_CAP = 0x6, 120 + PARAM_GET_GFX_MODE = 0x7, 121 + PARAM_SET_GFX_MODE = 0x8, 122 + PARAM_GET_CURR_TEMP = 0x9, 123 + PARAM_GET_FMAX_MAX = 0xA, 124 + PARAM_GET_FMAX_MIN = 0xB, 125 + PARAM_GET_SOC_PWR_MAX = 0xC, 126 + PARAM_GET_SOC_PWR_MIN = 0xD, 127 + PARAM_GET_SOC_PWR_CUR = 0xE, 128 + }; 103 129 104 130 #endif /* __PSP_DBC_USER_H__ */