// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2024 Arm Ltd. * * This device driver implements the TPM CRB start method * as defined in the TPM Service Command Response Buffer * Interface Over FF-A (DEN0138).
*/
/* * Normal world sends requests with FFA_MSG_SEND_DIRECT_REQ and * responses are returned with FFA_MSG_SEND_DIRECT_RESP for normal * messages. * * All requests with FFA_MSG_SEND_DIRECT_REQ and FFA_MSG_SEND_DIRECT_RESP * are using the AArch32 or AArch64 SMC calling convention with register usage * as defined in FF-A specification: * w0: Function ID * -for 32-bit: 0x8400006F or 0x84000070 * -for 64-bit: 0xC400006F or 0xC4000070 * w1: Source/Destination IDs * w2: Reserved (MBZ) * w3-w7: Implementation defined, free to be used below
*/
/* * Returns the version of the interface that is available * Call register usage: * w3: Not used (MBZ) * w4: TPM service function ID, CRB_FFA_GET_INTERFACE_VERSION * w5-w7: Reserved (MBZ) * * Return register usage: * w3: Not used (MBZ) * w4: TPM service function status * w5: TPM service interface version * Bits[31:16]: major version * Bits[15:0]: minor version * w6-w7: Reserved (MBZ) * * Possible function status codes in register w4: * CRB_FFA_OK_RESULTS_RETURNED: The version of the interface has been * returned.
*/ #define CRB_FFA_GET_INTERFACE_VERSION 0x0f000001
/* * Notifies the TPM service that a TPM command or TPM locality request is * ready to be processed, and allows the TPM service to process it. * Call register usage: * w3: Not used (MBZ) * w4: TPM service function ID, CRB_FFA_START * w5: Start function qualifier * Bits[31:8] (MBZ) * Bits[7:0] * 0: Notifies TPM that a command is ready to be processed * 1: Notifies TPM that a locality request is ready to be processed * w6: TPM locality, one of 0..4 * -If the start function qualifier is 0, identifies the locality * from where the command originated. * -If the start function qualifier is 1, identifies the locality * of the locality request * w6-w7: Reserved (MBZ) * * Return register usage: * w3: Not used (MBZ) * w4: TPM service function status * w5-w7: Reserved (MBZ) * * Possible function status codes in register w4: * CRB_FFA_OK: the TPM service has been notified successfully * CRB_FFA_INVARG: one or more arguments are not valid * CRB_FFA_INV_CRB_CTRL_DATA: CRB control data or locality control * data at the given TPM locality is not valid * CRB_FFA_DENIED: the TPM has previously disabled locality requests and * command processing at the given locality
*/ #define CRB_FFA_START 0x0f000201
staticint tpm_crb_ffa_to_linux_errno(int errno)
{ int rc;
switch (errno) { case CRB_FFA_OK:
rc = 0; break; case CRB_FFA_OK_RESULTS_RETURNED:
rc = 0; break; case CRB_FFA_NOFUNC:
rc = -ENOENT; break; case CRB_FFA_NOTSUP:
rc = -EPERM; break; case CRB_FFA_INVARG:
rc = -EINVAL; break; case CRB_FFA_INV_CRB_CTRL_DATA:
rc = -ENOEXEC; break; case CRB_FFA_ALREADY:
rc = -EEXIST; break; case CRB_FFA_DENIED:
rc = -EACCES; break; case CRB_FFA_NOMEM:
rc = -ENOMEM; break; default:
rc = -EINVAL;
}
return rc;
}
/** * tpm_crb_ffa_init - called by the CRB driver to do any needed initialization * * This function is called by the tpm_crb driver during the tpm_crb * driver's initialization. If the tpm_crb_ffa has not been probed * yet, returns -ENOENT in order to force a retry. If th ffa_crb * driver had been probed but failed with an error, returns -ENODEV * in order to prevent further retries. * * Return: 0 on success, negative error code on failure.
*/ int tpm_crb_ffa_init(void)
{ int ret = 0;
if (!IS_MODULE(CONFIG_TCG_ARM_CRB_FFA)) {
ret = ffa_register(&tpm_crb_ffa_driver); if (ret) {
tpm_crb_ffa = ERR_PTR(-ENODEV); return ret;
}
}
ret = msg_ops->sync_send_receive2(tpm_crb_ffa->ffa_dev,
&tpm_crb_ffa->direct_msg_data2); if (!ret)
ret = tpm_crb_ffa_to_linux_errno(tpm_crb_ffa->direct_msg_data2.data[0]);
} else {
tpm_crb_ffa->direct_msg_data = (struct ffa_send_direct_data){
.data1 = func_id,
.data2 = a0,
.data3 = a1,
.data4 = a2,
};
ret = msg_ops->sync_send_receive(tpm_crb_ffa->ffa_dev,
&tpm_crb_ffa->direct_msg_data); if (!ret)
ret = tpm_crb_ffa_to_linux_errno(tpm_crb_ffa->direct_msg_data.data1);
}
/** * tpm_crb_ffa_get_interface_version() - gets the ABI version of the TPM service * @major: Pointer to caller-allocated buffer to hold the major version * number the ABI * @minor: Pointer to caller-allocated buffer to hold the minor version * number the ABI * * Returns the major and minor version of the ABI of the FF-A based TPM. * Allows the caller to evaluate its compatibility with the version of * the ABI. * * Return: 0 on success, negative error code on failure.
*/ staticint tpm_crb_ffa_get_interface_version(u16 *major, u16 *minor)
{ int rc;
/** * tpm_crb_ffa_start() - signals the TPM that a field has changed in the CRB * @request_type: Identifies whether the change to the CRB is in the command * fields or locality fields. * @locality: Specifies the locality number. * * Used by the CRB driver * that might be useful to those using or modifying it. Begins with * empty comment line, and may include additional embedded empty * comment lines. * * Return: 0 on success, negative error code on failure.
*/ int tpm_crb_ffa_start(int request_type, int locality)
{ if (!tpm_crb_ffa) return -ENOENT;
staticint tpm_crb_ffa_probe(struct ffa_device *ffa_dev)
{ struct tpm_crb_ffa *p; int rc;
/* only one instance of a TPM partition is supported */ if (tpm_crb_ffa && !IS_ERR_VALUE(tpm_crb_ffa)) return -EEXIST;
tpm_crb_ffa = ERR_PTR(-ENODEV); // set tpm_crb_ffa so we can detect probe failure
if (!ffa_partition_supports_direct_recv(ffa_dev) &&
!ffa_partition_supports_direct_req2_recv(ffa_dev)) {
dev_warn(&ffa_dev->dev, "partition doesn't support direct message receive.\n"); return -EINVAL;
}
p = kzalloc(sizeof(*tpm_crb_ffa), GFP_KERNEL); if (!p) return -ENOMEM;
tpm_crb_ffa = p;
/* if TPM is aarch32 use 32-bit SMCs */ if (!ffa_partition_check_property(ffa_dev, FFA_PARTITION_AARCH64_EXEC))
ffa_dev->ops->msg_ops->mode_32bit_set(ffa_dev);
/* verify compatibility of TPM service version number */
rc = tpm_crb_ffa_get_interface_version(&tpm_crb_ffa->major_version,
&tpm_crb_ffa->minor_version); if (rc) {
dev_err(&ffa_dev->dev, "failed to get crb interface version. rc:%d\n", rc); goto out;
}
dev_info(&ffa_dev->dev, "ABI version %u.%u\n", tpm_crb_ffa->major_version,
tpm_crb_ffa->minor_version);
if (tpm_crb_ffa->major_version != CRB_FFA_VERSION_MAJOR ||
(tpm_crb_ffa->minor_version > 0 &&
tpm_crb_ffa->minor_version < CRB_FFA_VERSION_MINOR)) {
dev_warn(&ffa_dev->dev, "Incompatible ABI version\n"); goto out;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.