18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2012 IBM Corporation
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Author: Ashley Lai <ashleydlai@gmail.com>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Maintained by: <tpmdd-devel@lists.sourceforge.net>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Device driver for TCG/TCPA TPM (trusted platform module).
108c2ecf20Sopenharmony_ci * Specifications at www.trustedcomputinggroup.org
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifndef __TPM_IBMVTPM_H__
148c2ecf20Sopenharmony_ci#define __TPM_IBMVTPM_H__
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* vTPM Message Format 1 */
178c2ecf20Sopenharmony_cistruct ibmvtpm_crq {
188c2ecf20Sopenharmony_ci	u8 valid;
198c2ecf20Sopenharmony_ci	u8 msg;
208c2ecf20Sopenharmony_ci	__be16 len;
218c2ecf20Sopenharmony_ci	__be32 data;
228c2ecf20Sopenharmony_ci	__be64 reserved;
238c2ecf20Sopenharmony_ci} __attribute__((packed, aligned(8)));
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistruct ibmvtpm_crq_queue {
268c2ecf20Sopenharmony_ci	struct ibmvtpm_crq *crq_addr;
278c2ecf20Sopenharmony_ci	u32 index;
288c2ecf20Sopenharmony_ci	u32 num_entry;
298c2ecf20Sopenharmony_ci	wait_queue_head_t wq;
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct ibmvtpm_dev {
338c2ecf20Sopenharmony_ci	struct device *dev;
348c2ecf20Sopenharmony_ci	struct vio_dev *vdev;
358c2ecf20Sopenharmony_ci	struct ibmvtpm_crq_queue crq_queue;
368c2ecf20Sopenharmony_ci	dma_addr_t crq_dma_handle;
378c2ecf20Sopenharmony_ci	u32 rtce_size;
388c2ecf20Sopenharmony_ci	void __iomem *rtce_buf;
398c2ecf20Sopenharmony_ci	dma_addr_t rtce_dma_handle;
408c2ecf20Sopenharmony_ci	spinlock_t rtce_lock;
418c2ecf20Sopenharmony_ci	wait_queue_head_t wq;
428c2ecf20Sopenharmony_ci	u16 res_len;
438c2ecf20Sopenharmony_ci	u32 vtpm_version;
448c2ecf20Sopenharmony_ci	u8 tpm_processing_cmd;
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define CRQ_RES_BUF_SIZE	PAGE_SIZE
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/* Initialize CRQ */
508c2ecf20Sopenharmony_ci#define INIT_CRQ_CMD		0xC001000000000000LL /* Init cmd */
518c2ecf20Sopenharmony_ci#define INIT_CRQ_COMP_CMD	0xC002000000000000LL /* Init complete cmd */
528c2ecf20Sopenharmony_ci#define INIT_CRQ_RES		0x01	/* Init respond */
538c2ecf20Sopenharmony_ci#define INIT_CRQ_COMP_RES	0x02	/* Init complete respond */
548c2ecf20Sopenharmony_ci#define VALID_INIT_CRQ		0xC0	/* Valid command for init crq */
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* vTPM CRQ response is the message type | 0x80 */
578c2ecf20Sopenharmony_ci#define VTPM_MSG_RES		0x80
588c2ecf20Sopenharmony_ci#define IBMVTPM_VALID_CMD	0x80
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* vTPM CRQ message types */
618c2ecf20Sopenharmony_ci#define VTPM_GET_VERSION			0x01
628c2ecf20Sopenharmony_ci#define VTPM_GET_VERSION_RES			(0x01 | VTPM_MSG_RES)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define VTPM_TPM_COMMAND			0x02
658c2ecf20Sopenharmony_ci#define VTPM_TPM_COMMAND_RES			(0x02 | VTPM_MSG_RES)
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define VTPM_GET_RTCE_BUFFER_SIZE		0x03
688c2ecf20Sopenharmony_ci#define VTPM_GET_RTCE_BUFFER_SIZE_RES		(0x03 | VTPM_MSG_RES)
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#define VTPM_PREPARE_TO_SUSPEND			0x04
718c2ecf20Sopenharmony_ci#define VTPM_PREPARE_TO_SUSPEND_RES		(0x04 | VTPM_MSG_RES)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#endif
74