drivers/char/tpm/tpm_crb_ffa.c

Source file repositories/reference/linux-study-clean/drivers/char/tpm/tpm_crb_ffa.c

File Facts

System
Linux kernel
Corpus path
drivers/char/tpm/tpm_crb_ffa.c
Extension
.c
Size
11415 bytes
Lines
415
Domain
Driver Families
Bucket
drivers/char
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

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;
	union {
		struct ffa_send_direct_data direct_msg_data;
		struct ffa_send_direct_data2 direct_msg_data2;
	};
};

static struct tpm_crb_ffa *tpm_crb_ffa;
static struct ffa_driver tpm_crb_ffa_driver;

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)
{
	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;
		}
	}

	if (!tpm_crb_ffa)
		ret = -ENOENT;

	if (IS_ERR_VALUE(tpm_crb_ffa))
		ret = -ENODEV;

	return ret;
}
EXPORT_SYMBOL_GPL(tpm_crb_ffa_init);

static int __tpm_crb_ffa_try_send_receive(unsigned long func_id,
					  unsigned long a0, unsigned long a1,
					  unsigned long a2)

Annotation

Implementation Notes