xref: /titanic_52/usr/src/uts/common/io/tpm/tpm_ddi.h (revision 69112edd987c28fa551d4f8d9362a84a45365f17)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_TPM_DDI_H
28 #define	_TPM_DDI_H
29 
30 /* Duration index is SHORT, MEDIUM, LONG, UNDEFINED */
31 #define	TPM_DURATION_MAX_IDX	3
32 
33 /*
34  * IO buffer size: this seems sufficient, but feel free to modify
35  * This should be at minimum 765
36  */
37 #define	TPM_IO_BUF_SIZE		4096
38 
39 #define	TPM_IO_TIMEOUT		10000000
40 
41 /*
42  * Flags to keep track of for the allocated resources
43  * so we know what to deallocate later on
44  */
45 enum tpm_ddi_resources_flags {
46 	TPM_OPENED = 0x001,
47 	TPM_DIDMINOR = 0x002,
48 	TPM_DIDREGSMAP = 0x004,
49 	TPM_DIDINTMUTEX = 0x008,
50 	TPM_DIDINTCV = 0x010,
51 	TPM_DID_IO_ALLOC = 0x100,
52 	TPM_DID_IO_MUTEX = 0x200,
53 	TPM_DID_IO_CV = 0x400,
54 	TPM_DID_MUTEX = 0x800,
55 	TPM_DID_SOFT_STATE = 0x1000,
56 #ifdef sun4v
57 	TPM_HSVC_REGISTERED = 0x2000
58 #endif
59 };
60 
61 typedef struct tpm_state tpm_state_t;
62 
63 /* TPM specific data structure */
64 struct tpm_state {
65 	/* TPM specific */
66 	TPM_CAP_VERSION_INFO vers_info;
67 
68 	/* OS specific */
69 	int 		instance;
70 	dev_info_t 	*dip;
71 	ddi_acc_handle_t handle;
72 
73 	kmutex_t	dev_lock;
74 	uint8_t		dev_held;
75 
76 	/*
77 	 * For read/write
78 	 */
79 	uint8_t		*iobuf;
80 	size_t		bufsize;
81 	uint8_t		iobuf_inuse;
82 	kmutex_t	iobuf_lock;
83 	kcondvar_t	iobuf_cv;
84 
85 	/*
86 	 * For supporting the interrupt
87 	 */
88 	uint8_t			intr_enabled;
89 	ddi_intr_handle_t	*h_array;
90 	uint_t			intr_pri;
91 	unsigned int		state;
92 
93 	uint8_t		*addr;		/* where TPM is mapped to */
94 	char		locality;	/* keep track of the locality */
95 
96 	uint32_t flags;		/* flags to keep track of what is allocated */
97 	clock_t duration[4];	/* short,medium,long,undefined */
98 	clock_t timeout_a;
99 	clock_t timeout_b;
100 	clock_t timeout_c;
101 	clock_t timeout_d;
102 	clock_t timeout_poll;
103 
104 	ddi_device_acc_attr_t accattr;
105 
106 	/* For power management. */
107 	kmutex_t	pm_mutex;
108 	kcondvar_t	suspend_cv;
109 	uint32_t	suspended;
110 
111 #ifdef KCF_TPM_RNG_PROVIDER
112 	/* For RNG */
113 	crypto_kcf_provider_handle_t	n_prov;
114 #endif
115 };
116 
117 #endif	/* _TPM_DDI_H */
118