xref: /freebsd/sys/dev/tpm/tpmvar.h (revision 9aff62dee28239f84b4aa4a3429cf26dbbf770cc)
1 /*
2  * Copyright (c) 2008, 2009 Michael Shalayeff
3  * Copyright (c) 2009, 2010 Hans-Joerg Hoexer
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
15  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
16  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _TPMVAR_H
20 #define _TPMVAR_H
21 
22 #ifdef __FreeBSD__
23 #include <sys/condvar.h>
24 #include <sys/lock.h>
25 #include <sys/mutex.h>
26 #include <sys/sx.h>
27 #endif
28 
29 struct tpm_softc {
30 #ifndef __FreeBSD__
31 	struct device sc_dev;
32 #endif
33 	void *sc_ih;
34 
35 	int	(*sc_init)(struct tpm_softc *, int, const char *);
36 	int	(*sc_start)(struct tpm_softc *, int);
37 	int	(*sc_read)(struct tpm_softc *, void *, int, size_t *, int);
38 	int	(*sc_write)(struct tpm_softc *, void *, int);
39 	int	(*sc_end)(struct tpm_softc *, int, int);
40 
41 	bus_space_tag_t sc_bt, sc_batm;
42 	bus_space_handle_t sc_bh, sc_bahm;
43 
44 	u_int32_t sc_devid;
45 	u_int32_t sc_rev;
46 	u_int32_t sc_stat;
47 	u_int32_t sc_capabilities;
48 
49 	int sc_flags;
50 #define	TPM_OPEN	0x0001
51 
52 	int	 sc_vector;
53 #ifdef __FreeBSD__
54 	void	*intr_cookie;
55 	int mem_rid, irq_rid;
56 	struct resource *mem_res, *irq_res;
57 	struct cdev *sc_cdev;
58 	/* Serialize commands and lifecycle; sc_intr_lock nests inside. */
59 	struct sx sc_lock;
60 	struct mtx sc_intr_lock;
61 	struct cv sc_intr_cv;
62 	bool sc_dying;
63 	bool sc_locality;
64 	bool sc_command_pending;
65 #endif
66 
67 #ifndef __FreeBSD__
68 	void	*sc_powerhook;
69 #endif
70 	int	 sc_suspend;
71 };
72 
73 int tpm_tis12_probe(bus_space_tag_t iot, bus_space_handle_t ioh);
74 int tpm_attach(device_t dev);
75 int tpm_detach(device_t dev);
76 int tpm_suspend(device_t dev);
77 int tpm_resume(device_t dev);
78 #endif
79