xref: /openbmc/linux/drivers/char/tpm/tpm_ibmvtpm.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
1b886d83cSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2132f7629SAshley Lai /*
3132f7629SAshley Lai  * Copyright (C) 2012 IBM Corporation
4132f7629SAshley Lai  *
51a0f1b27SAshley Lai  * Author: Ashley Lai <ashleydlai@gmail.com>
6132f7629SAshley Lai  *
7132f7629SAshley Lai  * Maintained by: <tpmdd-devel@lists.sourceforge.net>
8132f7629SAshley Lai  *
9132f7629SAshley Lai  * Device driver for TCG/TCPA TPM (trusted platform module).
10132f7629SAshley Lai  * Specifications at www.trustedcomputinggroup.org
11132f7629SAshley Lai  */
12132f7629SAshley Lai 
13132f7629SAshley Lai #ifndef __TPM_IBMVTPM_H__
14132f7629SAshley Lai #define __TPM_IBMVTPM_H__
15132f7629SAshley Lai 
16132f7629SAshley Lai /* vTPM Message Format 1 */
17132f7629SAshley Lai struct ibmvtpm_crq {
18132f7629SAshley Lai 	u8 valid;
19132f7629SAshley Lai 	u8 msg;
2062dfd912Sjmlatten@linux.vnet.ibm.com 	__be16 len;
2162dfd912Sjmlatten@linux.vnet.ibm.com 	__be32 data;
2262dfd912Sjmlatten@linux.vnet.ibm.com 	__be64 reserved;
23132f7629SAshley Lai } __attribute__((packed, aligned(8)));
24132f7629SAshley Lai 
25132f7629SAshley Lai struct ibmvtpm_crq_queue {
26132f7629SAshley Lai 	struct ibmvtpm_crq *crq_addr;
27132f7629SAshley Lai 	u32 index;
28132f7629SAshley Lai 	u32 num_entry;
29d8d74ea3SStefan Berger 	wait_queue_head_t wq;
30132f7629SAshley Lai };
31132f7629SAshley Lai 
32132f7629SAshley Lai struct ibmvtpm_dev {
33132f7629SAshley Lai 	struct device *dev;
34132f7629SAshley Lai 	struct vio_dev *vdev;
35132f7629SAshley Lai 	struct ibmvtpm_crq_queue crq_queue;
36132f7629SAshley Lai 	dma_addr_t crq_dma_handle;
37132f7629SAshley Lai 	u32 rtce_size;
38132f7629SAshley Lai 	void __iomem *rtce_buf;
39132f7629SAshley Lai 	dma_addr_t rtce_dma_handle;
40132f7629SAshley Lai 	spinlock_t rtce_lock;
41b5666502SAshley Lai 	wait_queue_head_t wq;
42b5666502SAshley Lai 	u16 res_len;
43132f7629SAshley Lai 	u32 vtpm_version;
44*047d4226SStefan Berger 	u8 tpm_processing_cmd;
45132f7629SAshley Lai };
46132f7629SAshley Lai 
47132f7629SAshley Lai #define CRQ_RES_BUF_SIZE	PAGE_SIZE
48132f7629SAshley Lai 
49132f7629SAshley Lai /* Initialize CRQ */
50132f7629SAshley Lai #define INIT_CRQ_CMD		0xC001000000000000LL /* Init cmd */
51132f7629SAshley Lai #define INIT_CRQ_COMP_CMD	0xC002000000000000LL /* Init complete cmd */
52132f7629SAshley Lai #define INIT_CRQ_RES		0x01	/* Init respond */
53132f7629SAshley Lai #define INIT_CRQ_COMP_RES	0x02	/* Init complete respond */
54132f7629SAshley Lai #define VALID_INIT_CRQ		0xC0	/* Valid command for init crq */
55132f7629SAshley Lai 
56132f7629SAshley Lai /* vTPM CRQ response is the message type | 0x80 */
57132f7629SAshley Lai #define VTPM_MSG_RES		0x80
58132f7629SAshley Lai #define IBMVTPM_VALID_CMD	0x80
59132f7629SAshley Lai 
60132f7629SAshley Lai /* vTPM CRQ message types */
61132f7629SAshley Lai #define VTPM_GET_VERSION			0x01
62132f7629SAshley Lai #define VTPM_GET_VERSION_RES			(0x01 | VTPM_MSG_RES)
63132f7629SAshley Lai 
64132f7629SAshley Lai #define VTPM_TPM_COMMAND			0x02
65132f7629SAshley Lai #define VTPM_TPM_COMMAND_RES			(0x02 | VTPM_MSG_RES)
66132f7629SAshley Lai 
67132f7629SAshley Lai #define VTPM_GET_RTCE_BUFFER_SIZE		0x03
68132f7629SAshley Lai #define VTPM_GET_RTCE_BUFFER_SIZE_RES		(0x03 | VTPM_MSG_RES)
69132f7629SAshley Lai 
70132f7629SAshley Lai #define VTPM_PREPARE_TO_SUSPEND			0x04
71132f7629SAshley Lai #define VTPM_PREPARE_TO_SUSPEND_RES		(0x04 | VTPM_MSG_RES)
72132f7629SAshley Lai 
73132f7629SAshley Lai #endif
74