// SPDX-License-Identifier: GPL-2.0+
/*
 * Common features for sandbox TPM1 and TPM2 implementations
 *
 * Copyright 2021 Google LLC
 */

#define LOG_CATEGORY	UCLASS_TPM

#include <tpm-v1.h>
#include <tpm-v2.h>
#include <asm/unaligned.h>
#include "sandbox_common.h"

#define TPM_ERR_CODE_OFS	(2 + 4)		/* after tag and size */

int sb_tpm_index_to_seq(u32 index)
{
	index &= ~HR_NV_INDEX;
	switch (index) {
	case FIRMWARE_NV_INDEX:
		return NV_SEQ_FIRMWARE;
	case KERNEL_NV_INDEX:
		return NV_SEQ_KERNEL;
	case BACKUP_NV_INDEX:
		return NV_SEQ_BACKUP;
	case FWMP_NV_INDEX:
		return NV_SEQ_FWMP;
	case MRC_REC_HASH_NV_INDEX:
		return NV_SEQ_REC_HASH;
	case 0:
		return NV_SEQ_GLOBAL_LOCK;
	case TPM_NV_INDEX_LOCK:
		return NV_SEQ_ENABLE_LOCKING;
	}

	printf("Invalid nv index %#x\n", index);
	return -1;
}

void sb_tpm_read_data(const struct nvdata_state nvdata[NV_SEQ_COUNT],
		      enum sandbox_nv_space seq, u8 *buf, int data_ofs,
		      int length)
{
	const struct nvdata_state *nvd = &nvdata[seq];

	if (!nvd->present)
		put_unaligned_be32(TPM_BADINDEX, buf + TPM_ERR_CODE_OFS);
	else if (length > nvd->length)
		put_unaligned_be32(TPM_BAD_DATASIZE, buf + TPM_ERR_CODE_OFS);
	else
		memcpy(buf + data_ofs, &nvd->data, length);
}

void sb_tpm_write_data(struct nvdata_state nvdata[NV_SEQ_COUNT],
		       enum sandbox_nv_space seq, const u8 *buf, int data_ofs,
		       int length)
{
	struct nvdata_state *nvd = &nvdata[seq];

	if (length > nvd->length)
		log_err("Invalid length %x (max %x)\n", length, nvd->length);
	else
		memcpy(&nvdata[seq].data, buf + data_ofs, length);
}

void sb_tpm_define_data(struct nvdata_state nvdata[NV_SEQ_COUNT],
			enum sandbox_nv_space seq, int length)
{
	struct nvdata_state *nvd = &nvdata[seq];

	if (length > NV_DATA_SIZE)
		log_err("Invalid length %x (max %x)\n", length, NV_DATA_SIZE);
	nvd->length = length;
	nvd->present = true;
}
