dev/ic/tpm: Tidy up headers. - Add include guards. - Add necessary includes. - Sort includes. - Use _BYTE_ORDER, not BYTE_ORDER, for public header.diff -r1.16 -r1.17 src/sys/dev/ic/tpm.c
(riastradh)
--- src/sys/dev/ic/tpm.c 2019/10/09 14:03:58 1.16
+++ src/sys/dev/ic/tpm.c 2021/01/04 18:22:19 1.17
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: tpm.c,v 1.16 2019/10/09 14:03:58 maxv Exp $ */ | 1 | /* $NetBSD: tpm.c,v 1.17 2021/01/04 18:22:19 riastradh Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -38,37 +38,39 @@ | @@ -38,37 +38,39 @@ | |||
38 | * purpose with or without fee is hereby granted, provided that the above | 38 | * purpose with or without fee is hereby granted, provided that the above | |
39 | * copyright notice and this permission notice appear in all copies. | 39 | * copyright notice and this permission notice appear in all copies. | |
40 | * | 40 | * | |
41 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 41 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
42 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 42 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
43 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 43 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
44 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 44 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
45 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN | 45 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN | |
46 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | 46 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
47 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 47 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
48 | */ | 48 | */ | |
49 | 49 | |||
50 | #include <sys/cdefs.h> | 50 | #include <sys/cdefs.h> | |
51 | __KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.16 2019/10/09 14:03:58 maxv Exp $"); | 51 | __KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.17 2021/01/04 18:22:19 riastradh Exp $"); | |
52 | 52 | |||
53 | #include <sys/param.h> | 53 | #include <sys/param.h> | |
54 | #include <sys/systm.h> | 54 | #include <sys/types.h> | |
55 | ||||
56 | #include <sys/bus.h> | |||
57 | #include <sys/conf.h> | |||
58 | #include <sys/device.h> | |||
55 | #include <sys/kernel.h> | 59 | #include <sys/kernel.h> | |
56 | #include <sys/malloc.h> | 60 | #include <sys/malloc.h> | |
57 | #include <sys/proc.h> | |||
58 | #include <sys/device.h> | |||
59 | #include <sys/conf.h> | |||
60 | #include <sys/bus.h> | |||
61 | #include <sys/pmf.h> | 61 | #include <sys/pmf.h> | |
62 | #include <sys/proc.h> | |||
63 | #include <sys/systm.h> | |||
62 | 64 | |||
63 | #include <dev/ic/tpmreg.h> | 65 | #include <dev/ic/tpmreg.h> | |
64 | #include <dev/ic/tpmvar.h> | 66 | #include <dev/ic/tpmvar.h> | |
65 | 67 | |||
66 | #include "ioconf.h" | 68 | #include "ioconf.h" | |
67 | 69 | |||
68 | CTASSERT(sizeof(struct tpm_header) == 10); | 70 | CTASSERT(sizeof(struct tpm_header) == 10); | |
69 | 71 | |||
70 | #define TPM_BUFSIZ 1024 | 72 | #define TPM_BUFSIZ 1024 | |
71 | 73 | |||
72 | #define TPM_PARAM_SIZE 0x0001 /* that's a flag */ | 74 | #define TPM_PARAM_SIZE 0x0001 /* that's a flag */ | |
73 | 75 | |||
74 | /* Timeouts. */ | 76 | /* Timeouts. */ |
--- src/sys/dev/ic/tpmreg.h 2019/10/09 07:30:58 1.6
+++ src/sys/dev/ic/tpmreg.h 2021/01/04 18:22:19 1.7
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: tpmreg.h,v 1.6 2019/10/09 07:30:58 maxv Exp $ */ | 1 | /* $NetBSD: tpmreg.h,v 1.7 2021/01/04 18:22:19 riastradh Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -19,27 +19,35 @@ | @@ -19,27 +19,35 @@ | |||
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | 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 | 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 | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 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 | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 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 | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if (BYTE_ORDER == LITTLE_ENDIAN) | 32 | #ifndef DEV_IC_TPMREG_H | |
33 | #define DEV_IC_TPMREG_H | |||
34 | ||||
35 | #include <sys/types.h> | |||
36 | ||||
37 | #include <sys/cdefs.h> | |||
38 | #include <sys/endian.h> | |||
39 | ||||
40 | #if (_BYTE_ORDER == _LITTLE_ENDIAN) | |||
33 | #define TPM_BE16(a) bswap16(a) | 41 | #define TPM_BE16(a) bswap16(a) | |
34 | #define TPM_BE32(a) bswap32(a) | 42 | #define TPM_BE32(a) bswap32(a) | |
35 | #else | 43 | #else | |
36 | #define TPM_BE16(a) (a) | 44 | #define TPM_BE16(a) (a) | |
37 | #define TPM_BE32(a) (a) | 45 | #define TPM_BE32(a) (a) | |
38 | #endif | 46 | #endif | |
39 | 47 | |||
40 | struct tpm_header { | 48 | struct tpm_header { | |
41 | uint16_t tag; | 49 | uint16_t tag; | |
42 | uint32_t length; | 50 | uint32_t length; | |
43 | uint32_t code; | 51 | uint32_t code; | |
44 | } __packed; | 52 | } __packed; | |
45 | 53 | |||
@@ -95,13 +103,15 @@ struct tpm_header { | @@ -95,13 +103,15 @@ struct tpm_header { | |||
95 | #define TPM_STS_DATA_AVAIL __BIT(4) | 103 | #define TPM_STS_DATA_AVAIL __BIT(4) | |
96 | #define TPM_STS_DATA_EXPECT __BIT(3) | 104 | #define TPM_STS_DATA_EXPECT __BIT(3) | |
97 | #define TPM_STS_SELFTEST_DONE __BIT(2) | 105 | #define TPM_STS_SELFTEST_DONE __BIT(2) | |
98 | #define TPM_STS_RESP_RETRY __BIT(1) | 106 | #define TPM_STS_RESP_RETRY __BIT(1) | |
99 | 107 | |||
100 | #define TPM_DATA 0x0024 /* 32bit register */ | 108 | #define TPM_DATA 0x0024 /* 32bit register */ | |
101 | #define TPM_ID 0x0f00 /* 32bit register */ | 109 | #define TPM_ID 0x0f00 /* 32bit register */ | |
102 | #define TPM_REV 0x0f04 /* 8bit register */ | 110 | #define TPM_REV 0x0f04 /* 8bit register */ | |
103 | 111 | |||
104 | /* | 112 | /* | |
105 | * Five localities, 4K per locality. | 113 | * Five localities, 4K per locality. | |
106 | */ | 114 | */ | |
107 | #define TPM_SPACE_SIZE 0x5000 | 115 | #define TPM_SPACE_SIZE 0x5000 | |
116 | ||||
117 | #endif /* DEV_IC_TPMREG_H */ |
--- src/sys/dev/ic/tpmvar.h 2019/10/09 14:03:58 1.7
+++ src/sys/dev/ic/tpmvar.h 2021/01/04 18:22:19 1.8
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: tpmvar.h,v 1.7 2019/10/09 14:03:58 maxv Exp $ */ | 1 | /* $NetBSD: tpmvar.h,v 1.8 2021/01/04 18:22:19 riastradh Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2019 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Maxime Villard. | 8 | * by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -19,51 +19,60 @@ | @@ -19,51 +19,60 @@ | |||
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | 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 | 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 | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 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 | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 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 | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #ifndef DEV_IC_TPMVAR_H | |||
33 | #define DEV_IC_TPMVAR_H | |||
34 | ||||
35 | #include <sys/types.h> | |||
36 | ||||
32 | #define TPM_API_VERSION 1 | 37 | #define TPM_API_VERSION 1 | |
33 | 38 | |||
34 | enum tpm_version { | 39 | enum tpm_version { | |
35 | TPM_1_2, | 40 | TPM_1_2, | |
36 | TPM_2_0 | 41 | TPM_2_0 | |
37 | }; | 42 | }; | |
38 | 43 | |||
39 | enum itf_version { | 44 | enum itf_version { | |
40 | TIS_1_2, | 45 | TIS_1_2, | |
41 | CRB | 46 | CRB | |
42 | }; | 47 | }; | |
43 | 48 | |||
44 | struct tpm_ioc_getinfo { | 49 | struct tpm_ioc_getinfo { | |
45 | uint32_t api_version; | 50 | uint32_t api_version; | |
46 | uint32_t tpm_version; | 51 | uint32_t tpm_version; | |
47 | uint32_t itf_version; | 52 | uint32_t itf_version; | |
48 | uint32_t device_id; | 53 | uint32_t device_id; | |
49 | uint32_t device_rev; | 54 | uint32_t device_rev; | |
50 | uint32_t device_caps; | 55 | uint32_t device_caps; | |
51 | }; | 56 | }; | |
52 | 57 | |||
53 | #define TPM_IOC_GETINFO _IOR ('N', 0, struct tpm_ioc_getinfo) | 58 | #define TPM_IOC_GETINFO _IOR ('N', 0, struct tpm_ioc_getinfo) | |
54 | 59 | |||
55 | #ifdef _KERNEL | 60 | #ifdef _KERNEL | |
56 | 61 | |||
62 | #include <sys/bus.h> | |||
63 | #include <sys/device_if.h> | |||
64 | #include <sys/mutex.h> | |||
65 | ||||
57 | struct tpm_softc; | 66 | struct tpm_softc; | |
58 | 67 | |||
59 | struct tpm_intf { | 68 | struct tpm_intf { | |
60 | enum itf_version version; | 69 | enum itf_version version; | |
61 | int (*probe)(bus_space_tag_t, bus_space_handle_t); | 70 | int (*probe)(bus_space_tag_t, bus_space_handle_t); | |
62 | int (*init)(struct tpm_softc *); | 71 | int (*init)(struct tpm_softc *); | |
63 | int (*start)(struct tpm_softc *, int); | 72 | int (*start)(struct tpm_softc *, int); | |
64 | int (*read)(struct tpm_softc *, void *, size_t, size_t *, int); | 73 | int (*read)(struct tpm_softc *, void *, size_t, size_t *, int); | |
65 | int (*write)(struct tpm_softc *, const void *, size_t); | 74 | int (*write)(struct tpm_softc *, const void *, size_t); | |
66 | int (*end)(struct tpm_softc *, int, int); | 75 | int (*end)(struct tpm_softc *, int, int); | |
67 | }; | 76 | }; | |
68 | 77 | |||
69 | extern const struct tpm_intf tpm_intf_tis12; | 78 | extern const struct tpm_intf tpm_intf_tis12; | |
@@ -78,13 +87,15 @@ struct tpm_softc { | @@ -78,13 +87,15 @@ struct tpm_softc { | |||
78 | bus_space_tag_t sc_bt; | 87 | bus_space_tag_t sc_bt; | |
79 | bus_space_handle_t sc_bh; | 88 | bus_space_handle_t sc_bh; | |
80 | 89 | |||
81 | uint32_t sc_devid; | 90 | uint32_t sc_devid; | |
82 | uint32_t sc_rev; | 91 | uint32_t sc_rev; | |
83 | uint32_t sc_status; | 92 | uint32_t sc_status; | |
84 | uint32_t sc_caps; | 93 | uint32_t sc_caps; | |
85 | }; | 94 | }; | |
86 | 95 | |||
87 | bool tpm_suspend(device_t, const pmf_qual_t *); | 96 | bool tpm_suspend(device_t, const pmf_qual_t *); | |
88 | bool tpm_resume(device_t, const pmf_qual_t *); | 97 | bool tpm_resume(device_t, const pmf_qual_t *); | |
89 | 98 | |||
90 | #endif | 99 | #endif | |
100 | ||||
101 | #endif /* DEV_IC_TPMVAR_H */ |