Use acpi_compatible_match() / acpi_compatible_lookup().diff -r1.42 -r1.43 src/sys/dev/acpi/acpi_button.c
(thorpej)
--- src/sys/dev/acpi/acpi_button.c 2015/04/23 23:23:00 1.42
+++ src/sys/dev/acpi/acpi_button.c 2021/01/29 15:24:00 1.43
--- src/sys/dev/acpi/com_acpi.c 2019/03/01 09:21:06 1.40
+++ src/sys/dev/acpi/com_acpi.c 2021/01/29 15:24:00 1.41
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: com_acpi.c,v 1.40 2019/03/01 09:21:06 mlelstv Exp $ */ | 1 | /* $NetBSD: com_acpi.c,v 1.41 2021/01/29 15:24:00 thorpej Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca> | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. The name of the author may not be used to endorse or promote products | 12 | * 2. The name of the author may not be used to endorse or promote products | |
13 | * derived from this software without specific prior written permission. | 13 | * derived from this software without specific prior written permission. | |
14 | * | 14 | * | |
@@ -16,99 +16,108 @@ | @@ -16,99 +16,108 @@ | |||
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
20 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 20 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
22 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 22 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | * SUCH DAMAGE. | 25 | * SUCH DAMAGE. | |
26 | */ | 26 | */ | |
27 | 27 | |||
28 | #include <sys/cdefs.h> | 28 | #include <sys/cdefs.h> | |
29 | __KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.40 2019/03/01 09:21:06 mlelstv Exp $"); | 29 | __KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.41 2021/01/29 15:24:00 thorpej Exp $"); | |
30 | 30 | |||
31 | #include <sys/param.h> | 31 | #include <sys/param.h> | |
32 | #include <sys/device.h> | 32 | #include <sys/device.h> | |
33 | #include <sys/systm.h> | 33 | #include <sys/systm.h> | |
34 | #include <sys/termios.h> | 34 | #include <sys/termios.h> | |
35 | 35 | |||
36 | #include <dev/acpi/acpivar.h> | 36 | #include <dev/acpi/acpivar.h> | |
37 | #include <dev/acpi/acpi_intr.h> | 37 | #include <dev/acpi/acpi_intr.h> | |
38 | 38 | |||
39 | #include <dev/ic/comvar.h> | 39 | #include <dev/ic/comvar.h> | |
40 | 40 | |||
41 | static int com_acpi_match(device_t, cfdata_t , void *); | 41 | static int com_acpi_match(device_t, cfdata_t , void *); | |
42 | static void com_acpi_attach(device_t, device_t, void *); | 42 | static void com_acpi_attach(device_t, device_t, void *); | |
43 | 43 | |||
44 | struct com_acpi_softc { | 44 | struct com_acpi_softc { | |
45 | struct com_softc sc_com; | 45 | struct com_softc sc_com; | |
46 | void *sc_ih; | 46 | void *sc_ih; | |
47 | }; | 47 | }; | |
48 | 48 | |||
49 | CFATTACH_DECL_NEW(com_acpi, sizeof(struct com_acpi_softc), com_acpi_match, | 49 | CFATTACH_DECL_NEW(com_acpi, sizeof(struct com_acpi_softc), com_acpi_match, | |
50 | com_acpi_attach, NULL, NULL); | 50 | com_acpi_attach, NULL, NULL); | |
51 | 51 | |||
52 | /* | 52 | /* | |
53 | * Supported device IDs | 53 | * Supported device IDs | |
54 | */ | 54 | */ | |
55 | 55 | |||
56 | static const char * const com_acpi_ids[] = { | 56 | static const struct device_compatible_entry compat_data[] = { | |
57 | "PNP0500", /* Standard PC COM port */ | 57 | /* Standard PC COM port */ | |
58 | "PNP0501", /* 16550A-compatible COM port */ | 58 | { .compat = "PNP0500", .value = COM_TYPE_NORMAL }, | |
59 | "PNP0510", /* Generic IRDA-compatible device */ | |||
60 | "PNP0511", /* Generic IRDA-compatible device */ | |||
61 | "IBM0071", /* IBM ThinkPad IRDA device */ | |||
62 | "SMCF010", /* SMC SuperIO IRDA device */ | |||
63 | "NSC6001", /* NSC IRDA device */ | |||
64 | "FUJ02E6", /* Fujitsu Serial Pen Tablet */ | |||
65 | "HISI0031", /* Hisilicon UART */ | |||
66 | "8250dw", /* Designware APB UART */ | |||
67 | NULL | |||
68 | }; | |||
69 | 59 | |||
70 | /* | 60 | /* 16550A-compatible COM port */ | |
71 | * Subset of supported device IDs of type COM_TYPE_DW_APB | 61 | { .compat = "PNP0501", .value = COM_TYPE_NORMAL }, | |
72 | */ | 62 | ||
73 | static const char * const com_acpi_dw_ids[] = { | 63 | /* Generic IRDA-compatible device */ | |
74 | "HISI0031", /* Hisilicon UART */ | 64 | { .compat = "PNP0510", .value = COM_TYPE_NORMAL }, | |
75 | "8250dw", /* Designware APB UART */ | 65 | ||
76 | NULL | 66 | /* Generic IRDA-compatible device */ | |
67 | { .compat = "PNP0511", .value = COM_TYPE_NORMAL }, | |||
68 | ||||
69 | /* IBM ThinkPad IRDA device */ | |||
70 | { .compat = "IBM0071", .value = COM_TYPE_NORMAL }, | |||
71 | ||||
72 | /* SMC SuperIO IRDA device */ | |||
73 | { .compat = "SMCF010", .value = COM_TYPE_NORMAL }, | |||
74 | ||||
75 | /* NSC IRDA device */ | |||
76 | { .compat = "NSC6001", .value = COM_TYPE_NORMAL }, | |||
77 | ||||
78 | /* Fujitsu Serial Pen Tablet */ | |||
79 | { .compat = "FUJ02E6", .value = COM_TYPE_NORMAL }, | |||
80 | ||||
81 | /* Hisilicon UART */ | |||
82 | { .compat = "HISI0031", .value = COM_TYPE_DW_APB }, | |||
83 | ||||
84 | /* Designware APB UART */ | |||
85 | { .compat = "8250dw", .value = COM_TYPE_DW_APB }, | |||
86 | ||||
87 | DEVICE_COMPAT_EOL | |||
77 | }; | 88 | }; | |
78 | 89 | |||
79 | /* | 90 | /* | |
80 | * com_acpi_match: autoconf(9) match routine | 91 | * com_acpi_match: autoconf(9) match routine | |
81 | */ | 92 | */ | |
82 | static int | 93 | static int | |
83 | com_acpi_match(device_t parent, cfdata_t match, void *aux) | 94 | com_acpi_match(device_t parent, cfdata_t match, void *aux) | |
84 | { | 95 | { | |
85 | struct acpi_attach_args *aa = aux; | 96 | struct acpi_attach_args *aa = aux; | |
86 | 97 | |||
87 | if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) | 98 | return acpi_compatible_match(aa, compat_data); | |
88 | return 0; | |||
89 | ||||
90 | return acpi_match_hid(aa->aa_node->ad_devinfo, com_acpi_ids); | |||
91 | } | 99 | } | |
92 | 100 | |||
93 | /* | 101 | /* | |
94 | * com_acpi_attach: autoconf(9) attach routine | 102 | * com_acpi_attach: autoconf(9) attach routine | |
95 | */ | 103 | */ | |
96 | static void | 104 | static void | |
97 | com_acpi_attach(device_t parent, device_t self, void *aux) | 105 | com_acpi_attach(device_t parent, device_t self, void *aux) | |
98 | { | 106 | { | |
99 | struct com_acpi_softc *asc = device_private(self); | 107 | struct com_acpi_softc *asc = device_private(self); | |
100 | struct com_softc *sc = &asc->sc_com; | 108 | struct com_softc *sc = &asc->sc_com; | |
101 | struct acpi_attach_args *aa = aux; | 109 | struct acpi_attach_args *aa = aux; | |
110 | const struct device_compatible_entry *dce; | |||
102 | struct acpi_resources res; | 111 | struct acpi_resources res; | |
103 | struct acpi_io *io; | 112 | struct acpi_io *io; | |
104 | struct acpi_mem *mem; | 113 | struct acpi_mem *mem; | |
105 | struct acpi_irq *irq; | 114 | struct acpi_irq *irq; | |
106 | bus_space_tag_t iot; | 115 | bus_space_tag_t iot; | |
107 | bus_space_handle_t ioh; | 116 | bus_space_handle_t ioh; | |
108 | bus_addr_t base; | 117 | bus_addr_t base; | |
109 | bus_size_t size; | 118 | bus_size_t size; | |
110 | ACPI_STATUS rv; | 119 | ACPI_STATUS rv; | |
111 | ACPI_INTEGER clock_freq; | 120 | ACPI_INTEGER clock_freq; | |
112 | 121 | |||
113 | sc->sc_dev = self; | 122 | sc->sc_dev = self; | |
114 | 123 | |||
@@ -143,28 +152,32 @@ com_acpi_attach(device_t parent, device_ | @@ -143,28 +152,32 @@ com_acpi_attach(device_t parent, device_ | |||
143 | aprint_error_dev(self, "unable to find irq resource\n"); | 152 | aprint_error_dev(self, "unable to find irq resource\n"); | |
144 | goto out; | 153 | goto out; | |
145 | } | 154 | } | |
146 | 155 | |||
147 | if (!com_is_console(iot, base, &ioh)) | 156 | if (!com_is_console(iot, base, &ioh)) | |
148 | if (bus_space_map(iot, base, size, 0, &ioh)) { | 157 | if (bus_space_map(iot, base, size, 0, &ioh)) { | |
149 | aprint_error_dev(self, "can't map i/o space\n"); | 158 | aprint_error_dev(self, "can't map i/o space\n"); | |
150 | goto out; | 159 | goto out; | |
151 | } | 160 | } | |
152 | com_init_regs(&sc->sc_regs, iot, ioh, base); | 161 | com_init_regs(&sc->sc_regs, iot, ioh, base); | |
153 | 162 | |||
154 | aprint_normal("%s", device_xname(self)); | 163 | aprint_normal("%s", device_xname(self)); | |
155 | 164 | |||
156 | if (acpi_match_hid(aa->aa_node->ad_devinfo, com_acpi_dw_ids) != 0) { | 165 | dce = acpi_compatible_lookup(aa, compat_data); | |
157 | sc->sc_type = COM_TYPE_DW_APB; | 166 | KASSERT(dce != NULL); | |
167 | ||||
168 | sc->sc_type = dce->value; | |||
169 | ||||
170 | if (sc->sc_type == COM_TYPE_DW_APB) { | |||
158 | SET(sc->sc_hwflags, COM_HW_POLL); /* XXX */ | 171 | SET(sc->sc_hwflags, COM_HW_POLL); /* XXX */ | |
159 | } else { | 172 | } else { | |
160 | if (com_probe_subr(&sc->sc_regs) == 0) { | 173 | if (com_probe_subr(&sc->sc_regs) == 0) { | |
161 | aprint_error(": com probe failed\n"); | 174 | aprint_error(": com probe failed\n"); | |
162 | goto out; | 175 | goto out; | |
163 | } | 176 | } | |
164 | } | 177 | } | |
165 | 178 | |||
166 | rv = acpi_dsd_integer(aa->aa_node->ad_handle, "clock-frequency", | 179 | rv = acpi_dsd_integer(aa->aa_node->ad_handle, "clock-frequency", | |
167 | &clock_freq); | 180 | &clock_freq); | |
168 | if (ACPI_SUCCESS(rv)) | 181 | if (ACPI_SUCCESS(rv)) | |
169 | sc->sc_frequency = clock_freq; | 182 | sc->sc_frequency = clock_freq; | |
170 | else | 183 | else |
--- src/sys/dev/acpi/pckbc_acpi.c 2020/12/06 12:23:13 1.38
+++ src/sys/dev/acpi/pckbc_acpi.c 2021/01/29 15:24:00 1.39
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: pckbc_acpi.c,v 1.38 2020/12/06 12:23:13 jmcneill Exp $ */ | 1 | /* $NetBSD: pckbc_acpi.c,v 1.39 2021/01/29 15:24:00 thorpej Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2000 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2000 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 Jason R. Thorpe. | 8 | * by Jason R. Thorpe. | |
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. | |
@@ -32,27 +32,27 @@ | @@ -32,27 +32,27 @@ | |||
32 | /* | 32 | /* | |
33 | * ACPI attachment for the PC Keyboard Controller driver. | 33 | * ACPI attachment for the PC Keyboard Controller driver. | |
34 | * | 34 | * | |
35 | * This is a little wonky. The keyboard controller actually | 35 | * This is a little wonky. The keyboard controller actually | |
36 | * has 2 ACPI nodes: one for the controller and the keyboard | 36 | * has 2 ACPI nodes: one for the controller and the keyboard | |
37 | * interrupt, and one for the aux port (mouse) interrupt. | 37 | * interrupt, and one for the aux port (mouse) interrupt. | |
38 | * | 38 | * | |
39 | * For this reason, we actually attach *two* instances of this | 39 | * For this reason, we actually attach *two* instances of this | |
40 | * driver. After both of them have been found, then we attach | 40 | * driver. After both of them have been found, then we attach | |
41 | * sub-devices. | 41 | * sub-devices. | |
42 | */ | 42 | */ | |
43 | 43 | |||
44 | #include <sys/cdefs.h> | 44 | #include <sys/cdefs.h> | |
45 | __KERNEL_RCSID(0, "$NetBSD: pckbc_acpi.c,v 1.38 2020/12/06 12:23:13 jmcneill Exp $"); | 45 | __KERNEL_RCSID(0, "$NetBSD: pckbc_acpi.c,v 1.39 2021/01/29 15:24:00 thorpej Exp $"); | |
46 | 46 | |||
47 | #include <sys/param.h> | 47 | #include <sys/param.h> | |
48 | #include <sys/callout.h> | 48 | #include <sys/callout.h> | |
49 | #include <sys/device.h> | 49 | #include <sys/device.h> | |
50 | #include <sys/malloc.h> | 50 | #include <sys/malloc.h> | |
51 | #include <sys/systm.h> | 51 | #include <sys/systm.h> | |
52 | 52 | |||
53 | #include <dev/acpi/acpivar.h> | 53 | #include <dev/acpi/acpivar.h> | |
54 | #include <dev/acpi/acpi_intr.h> | 54 | #include <dev/acpi/acpi_intr.h> | |
55 | 55 | |||
56 | #include <dev/isa/isareg.h> | 56 | #include <dev/isa/isareg.h> | |
57 | 57 | |||
58 | #include <dev/ic/i8042reg.h> | 58 | #include <dev/ic/i8042reg.h> | |
@@ -73,87 +73,74 @@ struct pckbc_acpi_softc { | @@ -73,87 +73,74 @@ struct pckbc_acpi_softc { | |||
73 | /* Save first port: */ | 73 | /* Save first port: */ | |
74 | static struct pckbc_acpi_softc *first; | 74 | static struct pckbc_acpi_softc *first; | |
75 | 75 | |||
76 | CFATTACH_DECL_NEW(pckbc_acpi, sizeof(struct pckbc_acpi_softc), | 76 | CFATTACH_DECL_NEW(pckbc_acpi, sizeof(struct pckbc_acpi_softc), | |
77 | pckbc_acpi_match, pckbc_acpi_attach, NULL, NULL); | 77 | pckbc_acpi_match, pckbc_acpi_attach, NULL, NULL); | |
78 | 78 | |||
79 | static void pckbc_acpi_intr_establish(struct pckbc_softc *, pckbc_slot_t); | 79 | static void pckbc_acpi_intr_establish(struct pckbc_softc *, pckbc_slot_t); | |
80 | static void pckbc_acpi_finish_attach(device_t); | 80 | static void pckbc_acpi_finish_attach(device_t); | |
81 | 81 | |||
82 | /* | 82 | /* | |
83 | * Supported Device IDs | 83 | * Supported Device IDs | |
84 | */ | 84 | */ | |
85 | 85 | |||
86 | static const char * const pckbc_acpi_ids_kbd[] = { | 86 | static const struct device_compatible_entry compat_data[] = { | |
87 | "PNP03??", /* Standard PC KBD port */ | 87 | /* Standard PC KBD port */ | |
88 | NULL | 88 | { .compat = "PNP03??", .value = PCKBC_KBD_SLOT }, | |
89 | }; | 89 | ||
90 | /* (Nobody else here but us mouses...) */ | |||
91 | { .compat = "PNP0F03", .value = PCKBC_AUX_SLOT }, | |||
92 | { .compat = "PNP0F0E", .value = PCKBC_AUX_SLOT }, | |||
93 | { .compat = "PNP0F12", .value = PCKBC_AUX_SLOT }, | |||
94 | { .compat = "PNP0F13", .value = PCKBC_AUX_SLOT }, | |||
95 | { .compat = "PNP0F19", .value = PCKBC_AUX_SLOT }, | |||
96 | { .compat = "PNP0F1B", .value = PCKBC_AUX_SLOT }, | |||
97 | { .compat = "PNP0F1C", .value = PCKBC_AUX_SLOT }, | |||
98 | { .compat = "SYN0302", .value = PCKBC_AUX_SLOT }, | |||
90 | 99 | |||
91 | static const char * const pckbc_acpi_ids_ms[] = { | 100 | DEVICE_COMPAT_EOL | |
92 | "PNP0F03", | |||
93 | "PNP0F0E", | |||
94 | "PNP0F12", | |||
95 | "PNP0F13", | |||
96 | "PNP0F19", | |||
97 | "PNP0F1B", | |||
98 | "PNP0F1C", | |||
99 | "SYN0302", | |||
100 | NULL | |||
101 | }; | 101 | }; | |
102 | 102 | |||
103 | /* | 103 | /* | |
104 | * pckbc_acpi_match: autoconf(9) match routine | 104 | * pckbc_acpi_match: autoconf(9) match routine | |
105 | */ | 105 | */ | |
106 | static int | 106 | static int | |
107 | pckbc_acpi_match(device_t parent, cfdata_t match, void *aux) | 107 | pckbc_acpi_match(device_t parent, cfdata_t match, void *aux) | |
108 | { | 108 | { | |
109 | struct acpi_attach_args *aa = aux; | 109 | struct acpi_attach_args *aa = aux; | |
110 | int rv; | |||
111 | ||||
112 | if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) | |||
113 | return 0; | |||
114 | 110 | |||
115 | rv = acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_kbd); | 111 | return acpi_compatible_match(aa, compat_data); | |
116 | if (rv) | |||
117 | return rv; | |||
118 | rv = acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_ms); | |||
119 | if (rv) | |||
120 | return rv; | |||
121 | return 0; | |||
122 | } | 112 | } | |
123 | 113 | |||
124 | static void | 114 | static void | |
125 | pckbc_acpi_attach(device_t parent, device_t self, void *aux) | 115 | pckbc_acpi_attach(device_t parent, device_t self, void *aux) | |
126 | { | 116 | { | |
127 | struct pckbc_acpi_softc *psc = device_private(self); | 117 | struct pckbc_acpi_softc *psc = device_private(self); | |
128 | struct pckbc_softc *sc = &psc->sc_pckbc; | 118 | struct pckbc_softc *sc = &psc->sc_pckbc; | |
129 | struct pckbc_internal *t; | 119 | struct pckbc_internal *t; | |
130 | struct acpi_attach_args *aa = aux; | 120 | struct acpi_attach_args *aa = aux; | |
121 | const struct device_compatible_entry *dce; | |||
131 | bus_space_handle_t ioh_d, ioh_c; | 122 | bus_space_handle_t ioh_d, ioh_c; | |
132 | struct acpi_resources res; | 123 | struct acpi_resources res; | |
133 | struct acpi_io *io0, *io1, *ioswap; | 124 | struct acpi_io *io0, *io1, *ioswap; | |
134 | struct acpi_irq *irq; | 125 | struct acpi_irq *irq; | |
135 | ACPI_STATUS rv; | 126 | ACPI_STATUS rv; | |
136 | 127 | |||
137 | sc->sc_dv = self; | 128 | sc->sc_dv = self; | |
138 | 129 | |||
139 | if (acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_kbd)) { | 130 | dce = acpi_compatible_lookup(aa, compat_data); | |
140 | psc->sc_slot = PCKBC_KBD_SLOT; | 131 | KASSERT(dce != NULL); | |
141 | } else if (acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_ms)) { | 132 | ||
142 | psc->sc_slot = PCKBC_AUX_SLOT; | 133 | psc->sc_slot = dce->value; | |
143 | } else { | |||
144 | aprint_error(": unknown port!\n"); | |||
145 | panic("pckbc_acpi_attach: impossible"); | |||
146 | } | |||
147 | 134 | |||
148 | aprint_normal(" (%s port)", pckbc_slot_names[psc->sc_slot]); | 135 | aprint_normal(" (%s port)", pckbc_slot_names[psc->sc_slot]); | |
149 | 136 | |||
150 | /* parse resources */ | 137 | /* parse resources */ | |
151 | rv = acpi_resource_parse(sc->sc_dv, aa->aa_node->ad_handle, "_CRS", | 138 | rv = acpi_resource_parse(sc->sc_dv, aa->aa_node->ad_handle, "_CRS", | |
152 | &res, &acpi_resource_parse_ops_default); | 139 | &res, &acpi_resource_parse_ops_default); | |
153 | if (ACPI_FAILURE(rv)) | 140 | if (ACPI_FAILURE(rv)) | |
154 | return; | 141 | return; | |
155 | 142 | |||
156 | /* find our IRQ */ | 143 | /* find our IRQ */ | |
157 | irq = acpi_res_irq(&res, 0); | 144 | irq = acpi_res_irq(&res, 0); | |
158 | if (irq == NULL) { | 145 | if (irq == NULL) { | |
159 | aprint_error_dev(self, "unable to find irq resource\n"); | 146 | aprint_error_dev(self, "unable to find irq resource\n"); |
--- src/sys/dev/acpi/tpm_acpi.c 2021/01/16 01:23:04 1.12
+++ src/sys/dev/acpi/tpm_acpi.c 2021/01/29 15:24:00 1.13
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: tpm_acpi.c,v 1.12 2021/01/16 01:23:04 thorpej Exp $ */ | 1 | /* $NetBSD: tpm_acpi.c,v 1.13 2021/01/29 15:24:00 thorpej Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2012, 2019 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2012, 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 Christos Zoulas and Maxime Villard. | 8 | * by Christos Zoulas and 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. | |
@@ -20,136 +20,129 @@ | @@ -20,136 +20,129 @@ | |||
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 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.12 2021/01/16 01:23:04 thorpej Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.13 2021/01/29 15:24:00 thorpej Exp $"); | |
34 | 34 | |||
35 | #include <sys/param.h> | 35 | #include <sys/param.h> | |
36 | #include <sys/systm.h> | 36 | #include <sys/systm.h> | |
37 | #include <sys/device.h> | 37 | #include <sys/device.h> | |
38 | #include <sys/bus.h> | 38 | #include <sys/bus.h> | |
39 | #include <sys/pmf.h> | 39 | #include <sys/pmf.h> | |
40 | 40 | |||
41 | #include <dev/ic/tpmreg.h> | 41 | #include <dev/ic/tpmreg.h> | |
42 | #include <dev/ic/tpmvar.h> | 42 | #include <dev/ic/tpmvar.h> | |
43 | 43 | |||
44 | #include <dev/acpi/acpireg.h> | 44 | #include <dev/acpi/acpireg.h> | |
45 | #include <dev/acpi/acpivar.h> | 45 | #include <dev/acpi/acpivar.h> | |
46 | 46 | |||
47 | #include "ioconf.h" | 47 | #include "ioconf.h" | |
48 | 48 | |||
49 | #define _COMPONENT ACPI_RESOURCE_COMPONENT | 49 | #define _COMPONENT ACPI_RESOURCE_COMPONENT | |
50 | ACPI_MODULE_NAME ("tpm_acpi") | 50 | ACPI_MODULE_NAME ("tpm_acpi") | |
51 | 51 | |||
52 | static int tpm_acpi_match(device_t, cfdata_t, void *); | 52 | static int tpm_acpi_match(device_t, cfdata_t, void *); | |
53 | static void tpm_acpi_attach(device_t, device_t, void *); | 53 | static void tpm_acpi_attach(device_t, device_t, void *); | |
54 | 54 | |||
55 | CFATTACH_DECL_NEW(tpm_acpi, sizeof(struct tpm_softc), tpm_acpi_match, | 55 | CFATTACH_DECL_NEW(tpm_acpi, sizeof(struct tpm_softc), tpm_acpi_match, | |
56 | tpm_acpi_attach, NULL, NULL); | 56 | tpm_acpi_attach, NULL, NULL); | |
57 | 57 | |||
58 | /* | 58 | static const struct device_compatible_entry compat_data[] = { | |
59 | * Supported TPM 1.2 devices. | 59 | { .compat = "PNP0C31", .value = TPM_1_2 }, | |
60 | */ | 60 | { .compat = "MSFT0101", .value = TPM_2_0 }, | |
61 | static const char * const tpm_1_2_acpi_ids[] = { | 61 | DEVICE_COMPAT_EOL | |
62 | "PNP0C31", | |||
63 | NULL | |||
64 | }; | |||
65 | ||||
66 | /* | |||
67 | * Supported TPM 2.0 devices. | |||
68 | */ | |||
69 | static const char * const tpm2_acpi_ids[] = { | |||
70 | "MSFT0101", | |||
71 | NULL | |||
72 | }; | 62 | }; | |
73 | 63 | |||
74 | static int | 64 | static int | |
75 | tpm_acpi_match(device_t parent, cfdata_t match, void *aux) | 65 | tpm_acpi_match(device_t parent, cfdata_t match, void *aux) | |
76 | { | 66 | { | |
77 | struct acpi_attach_args *aa = aux; | 67 | struct acpi_attach_args *aa = aux; | |
68 | const struct device_compatible_entry *dce; | |||
78 | ACPI_TABLE_TPM2 *tpm2; | 69 | ACPI_TABLE_TPM2 *tpm2; | |
79 | ACPI_STATUS rv; | 70 | ACPI_STATUS rv; | |
80 | 71 | int ret; | ||
81 | if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) | |||
82 | return 0; | |||
83 | 72 | |||
84 | /* We support only one TPM. */ | 73 | /* We support only one TPM. */ | |
85 | if (tpm_cd.cd_devs && tpm_cd.cd_devs[0]) | 74 | if (tpm_cd.cd_devs && tpm_cd.cd_devs[0]) | |
86 | return 0; | 75 | return 0; | |
87 | 76 | |||
88 | if (acpi_match_hid(aa->aa_node->ad_devinfo, tpm_1_2_acpi_ids)) { | 77 | ret = acpi_compatible_match(aa, compat_data); | |
78 | if (ret == 0) | |||
79 | return 0; | |||
80 | ||||
81 | dce = acpi_compatible_lookup(aa, compat_data); | |||
82 | KASSERT(dce != NULL); | |||
83 | ||||
84 | if (dce->value == TPM_1_2) { | |||
89 | /* XXX assume TPM 1.2 devices are memory-mapped. */ | 85 | /* XXX assume TPM 1.2 devices are memory-mapped. */ | |
90 | return 1; | 86 | return ret; | |
91 | } | 87 | } | |
92 | 88 | |||
93 | if (!acpi_match_hid(aa->aa_node->ad_devinfo, tpm2_acpi_ids)) | |||
94 | return 0; | |||
95 | ||||
96 | /* Make sure it uses TIS, and not CRB. */ | 89 | /* Make sure it uses TIS, and not CRB. */ | |
97 | rv = AcpiGetTable(ACPI_SIG_TPM2, 1, (ACPI_TABLE_HEADER **)&tpm2); | 90 | rv = AcpiGetTable(ACPI_SIG_TPM2, 1, (ACPI_TABLE_HEADER **)&tpm2); | |
98 | if (ACPI_FAILURE(rv)) | 91 | if (ACPI_FAILURE(rv)) | |
99 | return 0; | 92 | return 0; | |
100 | if (tpm2->StartMethod != ACPI_TPM2_MEMORY_MAPPED) | 93 | if (tpm2->StartMethod != ACPI_TPM2_MEMORY_MAPPED) | |
101 | return 0; | 94 | return 0; | |
102 | 95 | |||
103 | return 1; | 96 | return ret; | |
104 | } | 97 | } | |
105 | 98 | |||
106 | static void | 99 | static void | |
107 | tpm_acpi_attach(device_t parent, device_t self, void *aux) | 100 | tpm_acpi_attach(device_t parent, device_t self, void *aux) | |
108 | { | 101 | { | |
109 | struct tpm_softc *sc = device_private(self); | 102 | struct tpm_softc *sc = device_private(self); | |
110 | struct acpi_attach_args *aa = aux; | 103 | struct acpi_attach_args *aa = aux; | |
104 | const struct device_compatible_entry *dce; | |||
111 | struct acpi_resources res; | 105 | struct acpi_resources res; | |
112 | struct acpi_mem *mem; | 106 | struct acpi_mem *mem; | |
113 | bus_addr_t base; | 107 | bus_addr_t base; | |
114 | bus_addr_t size; | 108 | bus_addr_t size; | |
115 | int rv; | 109 | int rv; | |
116 | 110 | |||
117 | rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", &res, | 111 | rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", &res, | |
118 | &acpi_resource_parse_ops_default); | 112 | &acpi_resource_parse_ops_default); | |
119 | if (ACPI_FAILURE(rv)) { | 113 | if (ACPI_FAILURE(rv)) { | |
120 | aprint_error_dev(self, "cannot parse resources %d\n", rv); | 114 | aprint_error_dev(self, "cannot parse resources %d\n", rv); | |
121 | return; | 115 | return; | |
122 | } | 116 | } | |
123 | 117 | |||
124 | mem = acpi_res_mem(&res, 0); | 118 | mem = acpi_res_mem(&res, 0); | |
125 | if (mem == NULL) { | 119 | if (mem == NULL) { | |
126 | aprint_error_dev(self, "cannot find mem\n"); | 120 | aprint_error_dev(self, "cannot find mem\n"); | |
127 | goto out; | 121 | goto out; | |
128 | } | 122 | } | |
129 | if (mem->ar_length != TPM_SPACE_SIZE) { | 123 | if (mem->ar_length != TPM_SPACE_SIZE) { | |
130 | aprint_error_dev(self, "wrong size mem %"PRIu64" != %u\n", | 124 | aprint_error_dev(self, "wrong size mem %"PRIu64" != %u\n", | |
131 | (uint64_t)mem->ar_length, TPM_SPACE_SIZE); | 125 | (uint64_t)mem->ar_length, TPM_SPACE_SIZE); | |
132 | goto out; | 126 | goto out; | |
133 | } | 127 | } | |
134 | base = mem->ar_base; | 128 | base = mem->ar_base; | |
135 | size = mem->ar_length; | 129 | size = mem->ar_length; | |
136 | 130 | |||
131 | dce = acpi_compatible_lookup(aa, compat_data); | |||
132 | KASSERT(dce != NULL); | |||
133 | ||||
137 | sc->sc_dev = self; | 134 | sc->sc_dev = self; | |
138 | if (acpi_match_hid(aa->aa_node->ad_devinfo, tpm_1_2_acpi_ids)) { | 135 | sc->sc_ver = dce->value; | |
139 | sc->sc_ver = TPM_1_2; | |||
140 | } else { | |||
141 | sc->sc_ver = TPM_2_0; | |||
142 | } | |||
143 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); | 136 | mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); | |
144 | sc->sc_busy = false; | 137 | sc->sc_busy = false; | |
145 | sc->sc_intf = &tpm_intf_tis12; | 138 | sc->sc_intf = &tpm_intf_tis12; | |
146 | sc->sc_bt = aa->aa_memt; | 139 | sc->sc_bt = aa->aa_memt; | |
147 | if (bus_space_map(sc->sc_bt, base, size, 0, &sc->sc_bh)) { | 140 | if (bus_space_map(sc->sc_bt, base, size, 0, &sc->sc_bh)) { | |
148 | aprint_error_dev(sc->sc_dev, "cannot map registers\n"); | 141 | aprint_error_dev(sc->sc_dev, "cannot map registers\n"); | |
149 | goto out; | 142 | goto out; | |
150 | } | 143 | } | |
151 | 144 | |||
152 | if ((rv = (*sc->sc_intf->probe)(sc->sc_bt, sc->sc_bh)) != 0) { | 145 | if ((rv = (*sc->sc_intf->probe)(sc->sc_bt, sc->sc_bh)) != 0) { | |
153 | aprint_error_dev(sc->sc_dev, "probe failed, rv=%d\n", rv); | 146 | aprint_error_dev(sc->sc_dev, "probe failed, rv=%d\n", rv); | |
154 | goto out1; | 147 | goto out1; | |
155 | } | 148 | } |