/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __TSM_MR_H
#define __TSM_MR_H

#include <crypto/hash_info.h>


struct tsm_measurement_register {
	const char *mr_name;
	void *mr_value;
	u32 mr_size;
	u32 mr_flags;
	enum hash_algo mr_hash;
};

#define TSM_MR_F_NOHASH 1
#define TSM_MR_F_WRITABLE 2
#define TSM_MR_F_READABLE 4
#define TSM_MR_F_LIVE 8
#define TSM_MR_F_RTMR (TSM_MR_F_LIVE | TSM_MR_F_WRITABLE)

#define TSM_MR_(mr, hash)                              \
	.mr_name = #mr, .mr_size = hash##_DIGEST_SIZE, \
	.mr_hash = HASH_ALGO_##hash, .mr_flags = TSM_MR_F_READABLE


struct tsm_measurements {
	const struct tsm_measurement_register *mrs;
	size_t nr_mrs;
	int (*refresh)(const struct tsm_measurements *tm);
	int (*write)(const struct tsm_measurements *tm,
		     const struct tsm_measurement_register *mr, const u8 *data);
};

const struct attribute_group *
tsm_mr_create_attribute_group(const struct tsm_measurements *tm);
void tsm_mr_free_attribute_group(const struct attribute_group *attr_grp);

#endif
