tpmvar.h revision 1.5 1 /* $NetBSD: tpmvar.h,v 1.5 2019/10/08 18:43:02 maxv Exp $ */
2
3 /*
4 * Copyright (c) 2019 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Maxime Villard.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #define TPM_API_VERSION 1
33
34 enum tpm_version {
35 TPM_1_2,
36 TPM_2_0
37 };
38
39 struct tpm_ioc_getinfo {
40 uint32_t api_version;
41 uint32_t tpm_version;
42 uint32_t device_id;
43 uint32_t device_rev;
44 uint32_t device_caps;
45 };
46
47 #define TPM_IOC_GETINFO _IOR ('N', 0, struct tpm_ioc_getinfo)
48
49 #ifdef _KERNEL
50
51 struct tpm_softc {
52 device_t sc_dev;
53 enum tpm_version sc_ver;
54 kmutex_t sc_lock;
55 bool sc_busy;
56
57 int (*sc_init)(struct tpm_softc *);
58 int (*sc_start)(struct tpm_softc *, int);
59 int (*sc_read)(struct tpm_softc *, void *, size_t, size_t *, int);
60 int (*sc_write)(struct tpm_softc *, const void *, size_t);
61 int (*sc_end)(struct tpm_softc *, int, int);
62
63 bus_space_tag_t sc_bt;
64 bus_space_handle_t sc_bh;
65
66 uint32_t sc_devid;
67 uint32_t sc_rev;
68 uint32_t sc_status;
69 uint32_t sc_caps;
70 };
71
72 bool tpm12_suspend(device_t, const pmf_qual_t *);
73 bool tpm12_resume(device_t, const pmf_qual_t *);
74
75 int tpm_tis12_probe(bus_space_tag_t, bus_space_handle_t);
76 int tpm_tis12_init(struct tpm_softc *);
77 int tpm_tis12_start(struct tpm_softc *, int);
78 int tpm_tis12_read(struct tpm_softc *, void *, size_t, size_t *, int);
79 int tpm_tis12_write(struct tpm_softc *, const void *, size_t);
80 int tpm_tis12_end(struct tpm_softc *, int, int);
81
82 #endif
83