2025-03-12 16:58:24 -05:00
|
|
|
// 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).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) "CRB_FFA: " fmt
|
|
|
|
|
|
|
|
#include <linux/arm_ffa.h>
|
2025-07-08 17:51:51 -05:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/moduleparam.h>
|
2025-03-12 16:58:24 -05:00
|
|
|
#include "tpm_crb_ffa.h"
|
|
|
|
|
2025-07-08 17:51:51 -05:00
|
|
|
static unsigned int busy_timeout_ms = 2000;
|
|
|
|
|
|
|
|
module_param(busy_timeout_ms, uint, 0644);
|
|
|
|
MODULE_PARM_DESC(busy_timeout_ms,
|
|
|
|
"Maximum time in ms to retry before giving up on busy");
|
|
|
|
|
2025-03-12 16:58:24 -05:00
|
|
|
/* TPM service function status codes */
|
|
|
|
#define CRB_FFA_OK 0x05000001
|
|
|
|
#define CRB_FFA_OK_RESULTS_RETURNED 0x05000002
|
|
|
|
#define CRB_FFA_NOFUNC 0x8e000001
|
|
|
|
#define CRB_FFA_NOTSUP 0x8e000002
|
|
|
|
#define CRB_FFA_INVARG 0x8e000005
|
|
|
|
#define CRB_FFA_INV_CRB_CTRL_DATA 0x8e000006
|
|
|
|
#define CRB_FFA_ALREADY 0x8e000009
|
|
|
|
#define CRB_FFA_DENIED 0x8e00000a
|
|
|
|
#define CRB_FFA_NOMEM 0x8e00000b
|
|
|
|
|
|
|
|
#define CRB_FFA_VERSION_MAJOR 1
|
|
|
|
#define CRB_FFA_VERSION_MINOR 0
|
|
|
|
|
|
|
|
/* version encoding */
|
|
|
|
#define CRB_FFA_MAJOR_VERSION_MASK GENMASK(30, 16)
|
|
|
|
#define CRB_FFA_MINOR_VERSION_MASK GENMASK(15, 0)
|
|
|
|
#define CRB_FFA_MAJOR_VERSION(x) ((u16)(FIELD_GET(CRB_FFA_MAJOR_VERSION_MASK, (x))))
|
|
|
|
#define CRB_FFA_MINOR_VERSION(x) ((u16)(FIELD_GET(CRB_FFA_MINOR_VERSION_MASK, (x))))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2025-04-30 10:47:23 -05:00
|
|
|
* 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
|
2025-03-12 16:58:24 -05:00
|
|
|
* 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
|
|
|
|
|
|
|
|
/*
|
2025-04-30 10:47:23 -05:00
|
|
|
* 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.
|
2025-03-12 16:58:24 -05:00
|
|
|
* 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
|
|
|
|
|
|
|
|
struct tpm_crb_ffa {
|
|
|
|
struct ffa_device *ffa_dev;
|
|
|
|
u16 major_version;
|
|
|
|
u16 minor_version;
|
|
|
|
/* lock to protect sending of FF-A messages: */
|
|
|
|
struct mutex msg_data_lock;
|
2025-04-15 19:50:12 +01:00
|
|
|
union {
|
|
|
|
struct ffa_send_direct_data direct_msg_data;
|
|
|
|
struct ffa_send_direct_data2 direct_msg_data2;
|
|
|
|
};
|
2025-03-12 16:58:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct tpm_crb_ffa *tpm_crb_ffa;
|
tpm: tpm_crb_ffa: try to probe tpm_crb_ffa when it's built-in
To generate the boot_aggregate log in the IMA subsystem using TPM PCR
values, the TPM driver must be built as built-in and must be probed
before the IMA subsystem is initialized.
However, when the TPM device operates over the FF-A protocol using the
CRB interface, probing fails and returns -EPROBE_DEFER if the
tpm_crb_ffa device — an FF-A device that provides the communication
interface to the tpm_crb driver — has not yet been probed.
This issue occurs because both crb_acpi_driver_init() and
tpm_crb_ffa_driver_init() are registered with device_initcall. As a
result, crb_acpi_driver_init() may be invoked before
tpm_crb_ffa_driver_init(), which is responsible for probing the
tpm_crb_ffa device.
When this happens, IMA fails to detect the TPM device and logs the
following message:
| ima: No TPM chip found, activating TPM-bypass!
Consequently, it cannot generate the boot_aggregate log with the PCR
values provided by the TPM.
To resolve this issue, the tpm_crb_ffa_init() function explicitly
attempts to probe the tpm_crb_ffa by register tpm_crb_ffa driver so that
when tpm_crb_ffa device is created before tpm_crb_ffa_init(), probe the
tpm_crb_ffa device in tpm_crb_ffa_init() to finish probe the TPM device
completely.
This ensures that the TPM device using CRB over FF-A can be successfully
probed, even if crb_acpi_driver_init() is called first.
[ jarkko: reformatted some of the paragraphs because they were going past
the 75 character boundary. ]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2025-07-19 13:27:46 +03:00
|
|
|
static struct ffa_driver tpm_crb_ffa_driver;
|
2025-03-12 16:58:24 -05:00
|
|
|
|
|
|
|
static int 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)
|
|
|
|
{
|
tpm: tpm_crb_ffa: try to probe tpm_crb_ffa when it's built-in
To generate the boot_aggregate log in the IMA subsystem using TPM PCR
values, the TPM driver must be built as built-in and must be probed
before the IMA subsystem is initialized.
However, when the TPM device operates over the FF-A protocol using the
CRB interface, probing fails and returns -EPROBE_DEFER if the
tpm_crb_ffa device — an FF-A device that provides the communication
interface to the tpm_crb driver — has not yet been probed.
This issue occurs because both crb_acpi_driver_init() and
tpm_crb_ffa_driver_init() are registered with device_initcall. As a
result, crb_acpi_driver_init() may be invoked before
tpm_crb_ffa_driver_init(), which is responsible for probing the
tpm_crb_ffa device.
When this happens, IMA fails to detect the TPM device and logs the
following message:
| ima: No TPM chip found, activating TPM-bypass!
Consequently, it cannot generate the boot_aggregate log with the PCR
values provided by the TPM.
To resolve this issue, the tpm_crb_ffa_init() function explicitly
attempts to probe the tpm_crb_ffa by register tpm_crb_ffa driver so that
when tpm_crb_ffa device is created before tpm_crb_ffa_init(), probe the
tpm_crb_ffa device in tpm_crb_ffa_init() to finish probe the TPM device
completely.
This ensures that the TPM device using CRB over FF-A can be successfully
probed, even if crb_acpi_driver_init() is called first.
[ jarkko: reformatted some of the paragraphs because they were going past
the 75 character boundary. ]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2025-07-19 13:27:46 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-12 16:58:24 -05:00
|
|
|
if (!tpm_crb_ffa)
|
tpm: tpm_crb_ffa: try to probe tpm_crb_ffa when it's built-in
To generate the boot_aggregate log in the IMA subsystem using TPM PCR
values, the TPM driver must be built as built-in and must be probed
before the IMA subsystem is initialized.
However, when the TPM device operates over the FF-A protocol using the
CRB interface, probing fails and returns -EPROBE_DEFER if the
tpm_crb_ffa device — an FF-A device that provides the communication
interface to the tpm_crb driver — has not yet been probed.
This issue occurs because both crb_acpi_driver_init() and
tpm_crb_ffa_driver_init() are registered with device_initcall. As a
result, crb_acpi_driver_init() may be invoked before
tpm_crb_ffa_driver_init(), which is responsible for probing the
tpm_crb_ffa device.
When this happens, IMA fails to detect the TPM device and logs the
following message:
| ima: No TPM chip found, activating TPM-bypass!
Consequently, it cannot generate the boot_aggregate log with the PCR
values provided by the TPM.
To resolve this issue, the tpm_crb_ffa_init() function explicitly
attempts to probe the tpm_crb_ffa by register tpm_crb_ffa driver so that
when tpm_crb_ffa device is created before tpm_crb_ffa_init(), probe the
tpm_crb_ffa device in tpm_crb_ffa_init() to finish probe the TPM device
completely.
This ensures that the TPM device using CRB over FF-A can be successfully
probed, even if crb_acpi_driver_init() is called first.
[ jarkko: reformatted some of the paragraphs because they were going past
the 75 character boundary. ]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2025-07-19 13:27:46 +03:00
|
|
|
ret = -ENOENT;
|
2025-03-12 16:58:24 -05:00
|
|
|
|
|
|
|
if (IS_ERR_VALUE(tpm_crb_ffa))
|
tpm: tpm_crb_ffa: try to probe tpm_crb_ffa when it's built-in
To generate the boot_aggregate log in the IMA subsystem using TPM PCR
values, the TPM driver must be built as built-in and must be probed
before the IMA subsystem is initialized.
However, when the TPM device operates over the FF-A protocol using the
CRB interface, probing fails and returns -EPROBE_DEFER if the
tpm_crb_ffa device — an FF-A device that provides the communication
interface to the tpm_crb driver — has not yet been probed.
This issue occurs because both crb_acpi_driver_init() and
tpm_crb_ffa_driver_init() are registered with device_initcall. As a
result, crb_acpi_driver_init() may be invoked before
tpm_crb_ffa_driver_init(), which is responsible for probing the
tpm_crb_ffa device.
When this happens, IMA fails to detect the TPM device and logs the
following message:
| ima: No TPM chip found, activating TPM-bypass!
Consequently, it cannot generate the boot_aggregate log with the PCR
values provided by the TPM.
To resolve this issue, the tpm_crb_ffa_init() function explicitly
attempts to probe the tpm_crb_ffa by register tpm_crb_ffa driver so that
when tpm_crb_ffa device is created before tpm_crb_ffa_init(), probe the
tpm_crb_ffa device in tpm_crb_ffa_init() to finish probe the TPM device
completely.
This ensures that the TPM device using CRB over FF-A can be successfully
probed, even if crb_acpi_driver_init() is called first.
[ jarkko: reformatted some of the paragraphs because they were going past
the 75 character boundary. ]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2025-07-19 13:27:46 +03:00
|
|
|
ret = -ENODEV;
|
2025-03-12 16:58:24 -05:00
|
|
|
|
tpm: tpm_crb_ffa: try to probe tpm_crb_ffa when it's built-in
To generate the boot_aggregate log in the IMA subsystem using TPM PCR
values, the TPM driver must be built as built-in and must be probed
before the IMA subsystem is initialized.
However, when the TPM device operates over the FF-A protocol using the
CRB interface, probing fails and returns -EPROBE_DEFER if the
tpm_crb_ffa device — an FF-A device that provides the communication
interface to the tpm_crb driver — has not yet been probed.
This issue occurs because both crb_acpi_driver_init() and
tpm_crb_ffa_driver_init() are registered with device_initcall. As a
result, crb_acpi_driver_init() may be invoked before
tpm_crb_ffa_driver_init(), which is responsible for probing the
tpm_crb_ffa device.
When this happens, IMA fails to detect the TPM device and logs the
following message:
| ima: No TPM chip found, activating TPM-bypass!
Consequently, it cannot generate the boot_aggregate log with the PCR
values provided by the TPM.
To resolve this issue, the tpm_crb_ffa_init() function explicitly
attempts to probe the tpm_crb_ffa by register tpm_crb_ffa driver so that
when tpm_crb_ffa device is created before tpm_crb_ffa_init(), probe the
tpm_crb_ffa device in tpm_crb_ffa_init() to finish probe the TPM device
completely.
This ensures that the TPM device using CRB over FF-A can be successfully
probed, even if crb_acpi_driver_init() is called first.
[ jarkko: reformatted some of the paragraphs because they were going past
the 75 character boundary. ]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2025-07-19 13:27:46 +03:00
|
|
|
return ret;
|
2025-03-12 16:58:24 -05:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tpm_crb_ffa_init);
|
|
|
|
|
2025-07-08 17:51:51 -05:00
|
|
|
static int __tpm_crb_ffa_try_send_receive(unsigned long func_id,
|
|
|
|
unsigned long a0, unsigned long a1,
|
|
|
|
unsigned long a2)
|
2025-03-12 16:58:24 -05:00
|
|
|
{
|
|
|
|
const struct ffa_msg_ops *msg_ops;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
msg_ops = tpm_crb_ffa->ffa_dev->ops->msg_ops;
|
|
|
|
|
2025-04-15 19:50:12 +01:00
|
|
|
if (ffa_partition_supports_direct_req2_recv(tpm_crb_ffa->ffa_dev)) {
|
2025-07-08 17:51:50 -05:00
|
|
|
tpm_crb_ffa->direct_msg_data2 = (struct ffa_send_direct_data2){
|
|
|
|
.data = { func_id, a0, a1, a2 },
|
|
|
|
};
|
2025-04-15 19:50:12 +01:00
|
|
|
|
|
|
|
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 {
|
2025-07-08 17:51:50 -05:00
|
|
|
tpm_crb_ffa->direct_msg_data = (struct ffa_send_direct_data){
|
|
|
|
.data1 = func_id,
|
|
|
|
.data2 = a0,
|
|
|
|
.data3 = a1,
|
|
|
|
.data4 = a2,
|
|
|
|
};
|
2025-04-15 19:50:12 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2025-03-12 16:58:24 -05:00
|
|
|
|
2025-07-08 17:51:51 -05:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __tpm_crb_ffa_send_receive(unsigned long func_id, unsigned long a0,
|
|
|
|
unsigned long a1, unsigned long a2)
|
|
|
|
{
|
|
|
|
ktime_t start, stop;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!tpm_crb_ffa)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
start = ktime_get();
|
|
|
|
stop = ktime_add(start, ms_to_ktime(busy_timeout_ms));
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
ret = __tpm_crb_ffa_try_send_receive(func_id, a0, a1, a2);
|
|
|
|
if (ret != -EBUSY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
usleep_range(50, 100);
|
|
|
|
if (ktime_after(ktime_get(), stop)) {
|
|
|
|
dev_warn(&tpm_crb_ffa->ffa_dev->dev,
|
|
|
|
"Busy retry timed out\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2025-03-12 16:58:24 -05:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2025-07-01 03:37:36 +03:00
|
|
|
static int tpm_crb_ffa_get_interface_version(u16 *major, u16 *minor)
|
2025-03-12 16:58:24 -05:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!tpm_crb_ffa)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
if (IS_ERR_VALUE(tpm_crb_ffa))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!major || !minor)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
guard(mutex)(&tpm_crb_ffa->msg_data_lock);
|
|
|
|
|
2025-07-08 17:51:49 -05:00
|
|
|
rc = __tpm_crb_ffa_send_receive(CRB_FFA_GET_INTERFACE_VERSION, 0x00, 0x00, 0x00);
|
2025-03-12 16:58:24 -05:00
|
|
|
if (!rc) {
|
2025-04-15 19:50:12 +01:00
|
|
|
if (ffa_partition_supports_direct_req2_recv(tpm_crb_ffa->ffa_dev)) {
|
|
|
|
*major = CRB_FFA_MAJOR_VERSION(tpm_crb_ffa->direct_msg_data2.data[1]);
|
|
|
|
*minor = CRB_FFA_MINOR_VERSION(tpm_crb_ffa->direct_msg_data2.data[1]);
|
|
|
|
} else {
|
|
|
|
*major = CRB_FFA_MAJOR_VERSION(tpm_crb_ffa->direct_msg_data.data2);
|
|
|
|
*minor = CRB_FFA_MINOR_VERSION(tpm_crb_ffa->direct_msg_data.data2);
|
|
|
|
}
|
2025-03-12 16:58:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 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;
|
|
|
|
|
|
|
|
if (IS_ERR_VALUE(tpm_crb_ffa))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
guard(mutex)(&tpm_crb_ffa->msg_data_lock);
|
|
|
|
|
2025-07-08 17:51:49 -05:00
|
|
|
return __tpm_crb_ffa_send_receive(CRB_FFA_START, request_type, locality, 0x00);
|
2025-03-12 16:58:24 -05:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tpm_crb_ffa_start);
|
|
|
|
|
|
|
|
static int 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
|
|
|
|
|
2025-04-15 19:50:12 +01:00
|
|
|
if (!ffa_partition_supports_direct_recv(ffa_dev) &&
|
|
|
|
!ffa_partition_supports_direct_req2_recv(ffa_dev)) {
|
2025-04-15 19:50:13 +01:00
|
|
|
dev_warn(&ffa_dev->dev, "partition doesn't support direct message receive.\n");
|
2025-03-12 16:58:24 -05:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = kzalloc(sizeof(*tpm_crb_ffa), GFP_KERNEL);
|
|
|
|
if (!p)
|
|
|
|
return -ENOMEM;
|
|
|
|
tpm_crb_ffa = p;
|
|
|
|
|
|
|
|
mutex_init(&tpm_crb_ffa->msg_data_lock);
|
|
|
|
tpm_crb_ffa->ffa_dev = ffa_dev;
|
|
|
|
ffa_dev_set_drvdata(ffa_dev, tpm_crb_ffa);
|
|
|
|
|
|
|
|
/* 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) {
|
2025-04-15 19:50:13 +01:00
|
|
|
dev_err(&ffa_dev->dev, "failed to get crb interface version. rc:%d\n", rc);
|
2025-03-12 16:58:24 -05:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2025-04-15 19:50:13 +01:00
|
|
|
dev_info(&ffa_dev->dev, "ABI version %u.%u\n", tpm_crb_ffa->major_version,
|
2025-03-12 16:58:24 -05:00
|
|
|
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)) {
|
2025-04-15 19:50:13 +01:00
|
|
|
dev_warn(&ffa_dev->dev, "Incompatible ABI version\n");
|
2025-03-12 16:58:24 -05:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(tpm_crb_ffa);
|
|
|
|
tpm_crb_ffa = ERR_PTR(-ENODEV);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_crb_ffa_remove(struct ffa_device *ffa_dev)
|
|
|
|
{
|
|
|
|
kfree(tpm_crb_ffa);
|
|
|
|
tpm_crb_ffa = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ffa_device_id tpm_crb_ffa_device_id[] = {
|
|
|
|
/* 17b862a4-1806-4faf-86b3-089a58353861 */
|
|
|
|
{ UUID_INIT(0x17b862a4, 0x1806, 0x4faf,
|
|
|
|
0x86, 0xb3, 0x08, 0x9a, 0x58, 0x35, 0x38, 0x61) },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ffa_driver tpm_crb_ffa_driver = {
|
|
|
|
.name = "ffa-crb",
|
|
|
|
.probe = tpm_crb_ffa_probe,
|
|
|
|
.remove = tpm_crb_ffa_remove,
|
|
|
|
.id_table = tpm_crb_ffa_device_id,
|
|
|
|
};
|
|
|
|
|
tpm: tpm_crb_ffa: try to probe tpm_crb_ffa when it's built-in
To generate the boot_aggregate log in the IMA subsystem using TPM PCR
values, the TPM driver must be built as built-in and must be probed
before the IMA subsystem is initialized.
However, when the TPM device operates over the FF-A protocol using the
CRB interface, probing fails and returns -EPROBE_DEFER if the
tpm_crb_ffa device — an FF-A device that provides the communication
interface to the tpm_crb driver — has not yet been probed.
This issue occurs because both crb_acpi_driver_init() and
tpm_crb_ffa_driver_init() are registered with device_initcall. As a
result, crb_acpi_driver_init() may be invoked before
tpm_crb_ffa_driver_init(), which is responsible for probing the
tpm_crb_ffa device.
When this happens, IMA fails to detect the TPM device and logs the
following message:
| ima: No TPM chip found, activating TPM-bypass!
Consequently, it cannot generate the boot_aggregate log with the PCR
values provided by the TPM.
To resolve this issue, the tpm_crb_ffa_init() function explicitly
attempts to probe the tpm_crb_ffa by register tpm_crb_ffa driver so that
when tpm_crb_ffa device is created before tpm_crb_ffa_init(), probe the
tpm_crb_ffa device in tpm_crb_ffa_init() to finish probe the TPM device
completely.
This ensures that the TPM device using CRB over FF-A can be successfully
probed, even if crb_acpi_driver_init() is called first.
[ jarkko: reformatted some of the paragraphs because they were going past
the 75 character boundary. ]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2025-07-19 13:27:46 +03:00
|
|
|
#ifdef MODULE
|
2025-03-12 16:58:24 -05:00
|
|
|
module_ffa_driver(tpm_crb_ffa_driver);
|
tpm: tpm_crb_ffa: try to probe tpm_crb_ffa when it's built-in
To generate the boot_aggregate log in the IMA subsystem using TPM PCR
values, the TPM driver must be built as built-in and must be probed
before the IMA subsystem is initialized.
However, when the TPM device operates over the FF-A protocol using the
CRB interface, probing fails and returns -EPROBE_DEFER if the
tpm_crb_ffa device — an FF-A device that provides the communication
interface to the tpm_crb driver — has not yet been probed.
This issue occurs because both crb_acpi_driver_init() and
tpm_crb_ffa_driver_init() are registered with device_initcall. As a
result, crb_acpi_driver_init() may be invoked before
tpm_crb_ffa_driver_init(), which is responsible for probing the
tpm_crb_ffa device.
When this happens, IMA fails to detect the TPM device and logs the
following message:
| ima: No TPM chip found, activating TPM-bypass!
Consequently, it cannot generate the boot_aggregate log with the PCR
values provided by the TPM.
To resolve this issue, the tpm_crb_ffa_init() function explicitly
attempts to probe the tpm_crb_ffa by register tpm_crb_ffa driver so that
when tpm_crb_ffa device is created before tpm_crb_ffa_init(), probe the
tpm_crb_ffa device in tpm_crb_ffa_init() to finish probe the TPM device
completely.
This ensures that the TPM device using CRB over FF-A can be successfully
probed, even if crb_acpi_driver_init() is called first.
[ jarkko: reformatted some of the paragraphs because they were going past
the 75 character boundary. ]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
2025-07-19 13:27:46 +03:00
|
|
|
#endif
|
2025-03-12 16:58:24 -05:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Arm");
|
|
|
|
MODULE_DESCRIPTION("TPM CRB FFA driver");
|
|
|
|
MODULE_LICENSE("GPL");
|