Fri Jan 29 15:24:00 2021 UTC ()
Use acpi_compatible_match() / acpi_compatible_lookup().


(thorpej)
diff -r1.42 -r1.43 src/sys/dev/acpi/acpi_button.c
diff -r1.40 -r1.41 src/sys/dev/acpi/com_acpi.c
diff -r1.38 -r1.39 src/sys/dev/acpi/pckbc_acpi.c
diff -r1.12 -r1.13 src/sys/dev/acpi/tpm_acpi.c

cvs diff -r1.42 -r1.43 src/sys/dev/acpi/acpi_button.c (switch to unified diff)

--- 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
@@ -1,237 +1,237 @@ @@ -1,237 +1,237 @@
1/* $NetBSD: acpi_button.c,v 1.42 2015/04/23 23:23:00 pgoyette Exp $ */ 1/* $NetBSD: acpi_button.c,v 1.43 2021/01/29 15:24:00 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright 2001, 2003 Wasabi Systems, Inc. 4 * Copyright 2001, 2003 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement: 18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by 19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc. 20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior 22 * or promote products derived from this software without specific prior
23 * written permission. 23 * written permission.
24 * 24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38/* 38/*
39 * ACPI Button driver. 39 * ACPI Button driver.
40 */ 40 */
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.42 2015/04/23 23:23:00 pgoyette Exp $"); 43__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.43 2021/01/29 15:24:00 thorpej Exp $");
44 44
45#include <sys/param.h> 45#include <sys/param.h>
46#include <sys/device.h> 46#include <sys/device.h>
47#include <sys/module.h> 47#include <sys/module.h>
48#include <sys/systm.h> 48#include <sys/systm.h>
49 49
50#include <dev/acpi/acpireg.h> 50#include <dev/acpi/acpireg.h>
51#include <dev/acpi/acpivar.h> 51#include <dev/acpi/acpivar.h>
52#include <dev/acpi/acpi_wakedev.h> 52#include <dev/acpi/acpi_wakedev.h>
53 53
54#define _COMPONENT ACPI_BUTTON_COMPONENT 54#define _COMPONENT ACPI_BUTTON_COMPONENT
55ACPI_MODULE_NAME ("acpi_button") 55ACPI_MODULE_NAME ("acpi_button")
56 56
57#define ACPI_NOTIFY_BUTTON 0x80 57#define ACPI_NOTIFY_BUTTON 0x80
58 58
59struct acpibut_softc { 59struct acpibut_softc {
60 struct acpi_devnode *sc_node; 60 struct acpi_devnode *sc_node;
61 struct sysmon_pswitch sc_smpsw; 61 struct sysmon_pswitch sc_smpsw;
62}; 62};
63 63
64static const char * const power_button_hid[] = { 64struct button_type {
65 "PNP0C0C", 65 const char *desc;
66 NULL 66 int type;
 67};
 68
 69static const struct button_type power_button_type = {
 70 .desc = "Power",
 71 .type = PSWITCH_TYPE_POWER
67}; 72};
68 73
69static const char * const sleep_button_hid[] = { 74static const struct button_type sleep_button_type = {
70 "PNP0C0E", 75 .desc = "Sleep",
71 NULL 76 .type = PSWITCH_TYPE_SLEEP
 77};
 78
 79static const struct device_compatible_entry compat_data[] = {
 80 { .compat = "PNP0C0C", .data = &power_button_type },
 81 { .compat = "PNP0C0E", .data = &sleep_button_type },
 82 DEVICE_COMPAT_EOL
72}; 83};
73 84
74static int acpibut_match(device_t, cfdata_t, void *); 85static int acpibut_match(device_t, cfdata_t, void *);
75static void acpibut_attach(device_t, device_t, void *); 86static void acpibut_attach(device_t, device_t, void *);
76static int acpibut_detach(device_t, int); 87static int acpibut_detach(device_t, int);
77static void acpibut_pressed_event(void *); 88static void acpibut_pressed_event(void *);
78static void acpibut_notify_handler(ACPI_HANDLE, uint32_t, void *); 89static void acpibut_notify_handler(ACPI_HANDLE, uint32_t, void *);
79 90
80CFATTACH_DECL_NEW(acpibut, sizeof(struct acpibut_softc), 91CFATTACH_DECL_NEW(acpibut, sizeof(struct acpibut_softc),
81 acpibut_match, acpibut_attach, acpibut_detach, NULL); 92 acpibut_match, acpibut_attach, acpibut_detach, NULL);
82 93
83/* 94/*
84 * acpibut_match: 95 * acpibut_match:
85 * 96 *
86 * Autoconfiguration `match' routine. 97 * Autoconfiguration `match' routine.
87 */ 98 */
88static int 99static int
89acpibut_match(device_t parent, cfdata_t match, void *aux) 100acpibut_match(device_t parent, cfdata_t match, void *aux)
90{ 101{
91 struct acpi_attach_args *aa = aux; 102 struct acpi_attach_args *aa = aux;
92 103
93 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 104 return acpi_compatible_match(aa, compat_data);
94 return 0; 
95 
96 if (acpi_match_hid(aa->aa_node->ad_devinfo, power_button_hid)) 
97 return 1; 
98 
99 if (acpi_match_hid(aa->aa_node->ad_devinfo, sleep_button_hid)) 
100 return 1; 
101 
102 return 0; 
103} 105}
104 106
105/* 107/*
106 * acpibut_attach: 108 * acpibut_attach:
107 * 109 *
108 * Autoconfiguration `attach' routine. 110 * Autoconfiguration `attach' routine.
109 */ 111 */
110static void 112static void
111acpibut_attach(device_t parent, device_t self, void *aux) 113acpibut_attach(device_t parent, device_t self, void *aux)
112{ 114{
113 struct acpibut_softc *sc = device_private(self); 115 struct acpibut_softc *sc = device_private(self);
114 struct acpi_attach_args *aa = aux; 116 struct acpi_attach_args *aa = aux;
 117 const struct device_compatible_entry *dce;
 118 const struct button_type *type;
115 struct acpi_wakedev *aw; 119 struct acpi_wakedev *aw;
116 const char *desc; 
117 120
118 sc->sc_smpsw.smpsw_name = device_xname(self); 121 sc->sc_smpsw.smpsw_name = device_xname(self);
119 122
120 if (acpi_match_hid(aa->aa_node->ad_devinfo, power_button_hid)) { 123 dce = acpi_compatible_lookup(aa, compat_data);
121 sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER; 124 KASSERT(dce != NULL);
122 desc = "Power"; 125 type = dce->data;
123 } else if (acpi_match_hid(aa->aa_node->ad_devinfo, sleep_button_hid)) { 126
124 sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_SLEEP; 127 sc->sc_smpsw.smpsw_type = type->type;
125 desc = "Sleep"; 
126 } else 
127 panic("%s: impossible", __func__); 
128 128
129 aprint_naive(": ACPI %s Button\n", desc); 129 aprint_naive(": ACPI %s Button\n", type->desc);
130 aprint_normal(": ACPI %s Button\n", desc); 130 aprint_normal(": ACPI %s Button\n", type->desc);
131 131
132 sc->sc_node = aa->aa_node; 132 sc->sc_node = aa->aa_node;
133 aw = sc->sc_node->ad_wakedev; 133 aw = sc->sc_node->ad_wakedev;
134 134
135 /* 135 /*
136 * This GPE should always be enabled. 136 * This GPE should always be enabled.
137 */ 137 */
138 if (aw != NULL) 138 if (aw != NULL)
139 (void)AcpiEnableGpe(aw->aw_handle, aw->aw_number); 139 (void)AcpiEnableGpe(aw->aw_handle, aw->aw_number);
140 140
141 (void)pmf_device_register(self, NULL, NULL); 141 (void)pmf_device_register(self, NULL, NULL);
142 (void)sysmon_pswitch_register(&sc->sc_smpsw); 142 (void)sysmon_pswitch_register(&sc->sc_smpsw);
143 (void)acpi_register_notify(sc->sc_node, acpibut_notify_handler); 143 (void)acpi_register_notify(sc->sc_node, acpibut_notify_handler);
144} 144}
145 145
146/* 146/*
147 * acpibut_detach: 147 * acpibut_detach:
148 * 148 *
149 * Autoconfiguration `detach' routine. 149 * Autoconfiguration `detach' routine.
150 */ 150 */
151static int 151static int
152acpibut_detach(device_t self, int flags) 152acpibut_detach(device_t self, int flags)
153{ 153{
154 struct acpibut_softc *sc = device_private(self); 154 struct acpibut_softc *sc = device_private(self);
155 155
156 pmf_device_deregister(self); 156 pmf_device_deregister(self);
157 acpi_deregister_notify(sc->sc_node); 157 acpi_deregister_notify(sc->sc_node);
158 sysmon_pswitch_unregister(&sc->sc_smpsw); 158 sysmon_pswitch_unregister(&sc->sc_smpsw);
159 159
160 return 0; 160 return 0;
161} 161}
162 162
163/* 163/*
164 * acpibut_pressed_event: 164 * acpibut_pressed_event:
165 * 165 *
166 * Deal with a button being pressed. 166 * Deal with a button being pressed.
167 */ 167 */
168static void 168static void
169acpibut_pressed_event(void *arg) 169acpibut_pressed_event(void *arg)
170{ 170{
171 device_t dv = arg; 171 device_t dv = arg;
172 struct acpibut_softc *sc = device_private(dv); 172 struct acpibut_softc *sc = device_private(dv);
173 173
174 aprint_debug_dev(dv, "button pressed\n"); 174 aprint_debug_dev(dv, "button pressed\n");
175 sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED); 175 sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED);
176} 176}
177 177
178/* 178/*
179 * acpibut_notify_handler: 179 * acpibut_notify_handler:
180 * 180 *
181 * Callback from ACPI interrupt handler to notify us of an event. 181 * Callback from ACPI interrupt handler to notify us of an event.
182 */ 182 */
183static void 183static void
184acpibut_notify_handler(ACPI_HANDLE handle, uint32_t notify, void *context) 184acpibut_notify_handler(ACPI_HANDLE handle, uint32_t notify, void *context)
185{ 185{
186 static const int handler = OSL_NOTIFY_HANDLER; 186 static const int handler = OSL_NOTIFY_HANDLER;
187 device_t dv = context; 187 device_t dv = context;
188 188
189 switch (notify) { 189 switch (notify) {
190 190
191 case ACPI_NOTIFY_BUTTON: 191 case ACPI_NOTIFY_BUTTON:
192 (void)AcpiOsExecute(handler, acpibut_pressed_event, dv); 192 (void)AcpiOsExecute(handler, acpibut_pressed_event, dv);
193 break; 193 break;
194 194
195 case ACPI_NOTIFY_DEVICE_WAKE: 195 case ACPI_NOTIFY_DEVICE_WAKE:
196 break; 196 break;
197 197
198 default: 198 default:
199 aprint_debug_dev(dv, "unknown notify 0x%02X\n", notify); 199 aprint_debug_dev(dv, "unknown notify 0x%02X\n", notify);
200 } 200 }
201} 201}
202 202
203MODULE(MODULE_CLASS_DRIVER, acpibut, "sysmon_power"); 203MODULE(MODULE_CLASS_DRIVER, acpibut, "sysmon_power");
204 204
205#ifdef _MODULE 205#ifdef _MODULE
206#include "ioconf.c" 206#include "ioconf.c"
207#endif 207#endif
208 208
209static int 209static int
210acpibut_modcmd(modcmd_t cmd, void *aux) 210acpibut_modcmd(modcmd_t cmd, void *aux)
211{ 211{
212 int rv = 0; 212 int rv = 0;
213 213
214 switch (cmd) { 214 switch (cmd) {
215 215
216 case MODULE_CMD_INIT: 216 case MODULE_CMD_INIT:
217 217
218#ifdef _MODULE 218#ifdef _MODULE
219 rv = config_init_component(cfdriver_ioconf_acpibut, 219 rv = config_init_component(cfdriver_ioconf_acpibut,
220 cfattach_ioconf_acpibut, cfdata_ioconf_acpibut); 220 cfattach_ioconf_acpibut, cfdata_ioconf_acpibut);
221#endif 221#endif
222 break; 222 break;
223 223
224 case MODULE_CMD_FINI: 224 case MODULE_CMD_FINI:
225 225
226#ifdef _MODULE 226#ifdef _MODULE
227 rv = config_fini_component(cfdriver_ioconf_acpibut, 227 rv = config_fini_component(cfdriver_ioconf_acpibut,
228 cfattach_ioconf_acpibut, cfdata_ioconf_acpibut); 228 cfattach_ioconf_acpibut, cfdata_ioconf_acpibut);
229#endif 229#endif
230 break; 230 break;
231 231
232 default: 232 default:
233 rv = ENOTTY; 233 rv = ENOTTY;
234 } 234 }
235 235
236 return rv; 236 return rv;
237} 237}

cvs diff -r1.40 -r1.41 src/sys/dev/acpi/com_acpi.c (switch to unified diff)

--- 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,194 +1,207 @@ @@ -1,194 +1,207 @@
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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
41static int com_acpi_match(device_t, cfdata_t , void *); 41static int com_acpi_match(device_t, cfdata_t , void *);
42static void com_acpi_attach(device_t, device_t, void *); 42static void com_acpi_attach(device_t, device_t, void *);
43 43
44struct com_acpi_softc { 44struct 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
49CFATTACH_DECL_NEW(com_acpi, sizeof(struct com_acpi_softc), com_acpi_match, 49CFATTACH_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
56static const char * const com_acpi_ids[] = { 56static 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
73static 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 */
82static int 93static int
83com_acpi_match(device_t parent, cfdata_t match, void *aux) 94com_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 */
96static void 104static void
97com_acpi_attach(device_t parent, device_t self, void *aux) 105com_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
115 /* parse resources */ 124 /* parse resources */
116 rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS", 125 rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
117 &res, &acpi_resource_parse_ops_default); 126 &res, &acpi_resource_parse_ops_default);
118 if (ACPI_FAILURE(rv)) 127 if (ACPI_FAILURE(rv))
119 return; 128 return;
120 129
121 /* find our i/o registers */ 130 /* find our i/o registers */
122 io = acpi_res_io(&res, 0); 131 io = acpi_res_io(&res, 0);
123 if (io != NULL) { 132 if (io != NULL) {
124 iot = aa->aa_iot; 133 iot = aa->aa_iot;
125 base = io->ar_base; 134 base = io->ar_base;
126 size = io->ar_length; 135 size = io->ar_length;
127 } else { 136 } else {
128 mem = acpi_res_mem(&res, 0); 137 mem = acpi_res_mem(&res, 0);
129 if (mem != NULL) { 138 if (mem != NULL) {
130 iot = aa->aa_memt; 139 iot = aa->aa_memt;
131 base = mem->ar_base; 140 base = mem->ar_base;
132 size = mem->ar_length; 141 size = mem->ar_length;
133 } else { 142 } else {
134 aprint_error_dev(self, "unable to find i/o register " 143 aprint_error_dev(self, "unable to find i/o register "
135 "and memory resource\n"); 144 "and memory resource\n");
136 goto out; 145 goto out;
137 } 146 }
138 } 147 }
139 148
140 /* find our IRQ */ 149 /* find our IRQ */
141 irq = acpi_res_irq(&res, 0); 150 irq = acpi_res_irq(&res, 0);
142 if (irq == NULL) { 151 if (irq == NULL) {
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
171 sc->sc_frequency = 115200 * 16; 184 sc->sc_frequency = 115200 * 16;
172 185
173 com_attach_subr(sc); 186 com_attach_subr(sc);
174 187
175 if (!ISSET(sc->sc_hwflags, COM_HW_POLL)) 188 if (!ISSET(sc->sc_hwflags, COM_HW_POLL))
176 asc->sc_ih = acpi_intr_establish(self, 189 asc->sc_ih = acpi_intr_establish(self,
177 (uint64_t)(uintptr_t)aa->aa_node->ad_handle, 190 (uint64_t)(uintptr_t)aa->aa_node->ad_handle,
178 IPL_SERIAL, true, comintr, sc, device_xname(self)); 191 IPL_SERIAL, true, comintr, sc, device_xname(self));
179 192
180 if (!pmf_device_register(self, NULL, com_resume)) 193 if (!pmf_device_register(self, NULL, com_resume))
181 aprint_error_dev(self, "couldn't establish a power handler\n"); 194 aprint_error_dev(self, "couldn't establish a power handler\n");
182 goto cleanup; 195 goto cleanup;
183 196
184 /* 197 /*
185 * In case of irq resource or i/o space mapping error, just set 198 * In case of irq resource or i/o space mapping error, just set
186 * a NULL power handler. This may allow us to sleep later on. 199 * a NULL power handler. This may allow us to sleep later on.
187 */ 200 */
188 out: 201 out:
189 if (!pmf_device_register(self, NULL, NULL)) 202 if (!pmf_device_register(self, NULL, NULL))
190 aprint_error_dev(self, "couldn't establish a power handler\n"); 203 aprint_error_dev(self, "couldn't establish a power handler\n");
191 204
192 cleanup: 205 cleanup:
193 acpi_resource_cleanup(&res); 206 acpi_resource_cleanup(&res);
194} 207}

cvs diff -r1.38 -r1.39 src/sys/dev/acpi/pckbc_acpi.c (switch to unified diff)

--- 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,273 +1,260 @@ @@ -1,273 +1,260 @@
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.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
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/* 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>
59#include <dev/ic/pckbcvar.h> 59#include <dev/ic/pckbcvar.h>
60 60
61#include "ioconf.h" 61#include "ioconf.h"
62 62
63static int pckbc_acpi_match(device_t, cfdata_t, void *); 63static int pckbc_acpi_match(device_t, cfdata_t, void *);
64static void pckbc_acpi_attach(device_t, device_t, void *); 64static void pckbc_acpi_attach(device_t, device_t, void *);
65 65
66struct pckbc_acpi_softc { 66struct pckbc_acpi_softc {
67 struct pckbc_softc sc_pckbc; 67 struct pckbc_softc sc_pckbc;
68 68
69 ACPI_HANDLE sc_handle; 69 ACPI_HANDLE sc_handle;
70 pckbc_slot_t sc_slot; 70 pckbc_slot_t sc_slot;
71}; 71};
72 72
73/* Save first port: */ 73/* Save first port: */
74static struct pckbc_acpi_softc *first; 74static struct pckbc_acpi_softc *first;
75 75
76CFATTACH_DECL_NEW(pckbc_acpi, sizeof(struct pckbc_acpi_softc), 76CFATTACH_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
79static void pckbc_acpi_intr_establish(struct pckbc_softc *, pckbc_slot_t); 79static void pckbc_acpi_intr_establish(struct pckbc_softc *, pckbc_slot_t);
80static void pckbc_acpi_finish_attach(device_t); 80static void pckbc_acpi_finish_attach(device_t);
81 81
82/* 82/*
83 * Supported Device IDs 83 * Supported Device IDs
84 */ 84 */
85 85
86static const char * const pckbc_acpi_ids_kbd[] = { 86static 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
91static 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 */
106static int 106static int
107pckbc_acpi_match(device_t parent, cfdata_t match, void *aux) 107pckbc_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
124static void 114static void
125pckbc_acpi_attach(device_t parent, device_t self, void *aux) 115pckbc_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");
160 goto out; 147 goto out;
161 } 148 }
162 psc->sc_handle = aa->aa_node->ad_handle; 149 psc->sc_handle = aa->aa_node->ad_handle;
163 150
164 if (psc->sc_slot == PCKBC_KBD_SLOT) 151 if (psc->sc_slot == PCKBC_KBD_SLOT)
165 first = psc; 152 first = psc;
166 153
167 if ((!first || !first->sc_pckbc.id) && 154 if ((!first || !first->sc_pckbc.id) &&
168 (psc->sc_slot == PCKBC_KBD_SLOT)) { 155 (psc->sc_slot == PCKBC_KBD_SLOT)) {
169 156
170 io0 = acpi_res_io(&res, 0); 157 io0 = acpi_res_io(&res, 0);
171 io1 = acpi_res_io(&res, 1); 158 io1 = acpi_res_io(&res, 1);
172 if (io0 == NULL || io1 == NULL) { 159 if (io0 == NULL || io1 == NULL) {
173 aprint_error_dev(self, 160 aprint_error_dev(self,
174 "unable to find i/o resources\n"); 161 "unable to find i/o resources\n");
175 goto out; 162 goto out;
176 } 163 }
177 164
178 /* 165 /*
179 * JDM: Some firmware doesn't report resources in the order we 166 * JDM: Some firmware doesn't report resources in the order we
180 * expect; sort IO resources here (lowest first) 167 * expect; sort IO resources here (lowest first)
181 */ 168 */
182 if (io0->ar_base > io1->ar_base) { 169 if (io0->ar_base > io1->ar_base) {
183 ioswap = io0; 170 ioswap = io0;
184 io0 = io1; 171 io0 = io1;
185 io1 = ioswap; 172 io1 = ioswap;
186 } 173 }
187 174
188 if (pckbc_is_console(aa->aa_iot, io0->ar_base)) { 175 if (pckbc_is_console(aa->aa_iot, io0->ar_base)) {
189 t = &pckbc_consdata; 176 t = &pckbc_consdata;
190 ioh_d = t->t_ioh_d; 177 ioh_d = t->t_ioh_d;
191 ioh_c = t->t_ioh_c; 178 ioh_c = t->t_ioh_c;
192 pckbc_console_attached = 1; 179 pckbc_console_attached = 1;
193 /* t->t_cmdbyte was initialized by cnattach */ 180 /* t->t_cmdbyte was initialized by cnattach */
194 } else { 181 } else {
195 if (bus_space_map(aa->aa_iot, io0->ar_base, 182 if (bus_space_map(aa->aa_iot, io0->ar_base,
196 io0->ar_length, 0, &ioh_d) || 183 io0->ar_length, 0, &ioh_d) ||
197 bus_space_map(aa->aa_iot, io1->ar_base, 184 bus_space_map(aa->aa_iot, io1->ar_base,
198 io1->ar_length, 0, &ioh_c)) { 185 io1->ar_length, 0, &ioh_c)) {
199 aprint_error_dev(self, 186 aprint_error_dev(self,
200 "unable to map registers\n"); 187 "unable to map registers\n");
201 goto out; 188 goto out;
202 } 189 }
203 190
204 t = malloc(sizeof(struct pckbc_internal), 191 t = malloc(sizeof(struct pckbc_internal),
205 M_DEVBUF, M_WAITOK|M_ZERO); 192 M_DEVBUF, M_WAITOK|M_ZERO);
206 t->t_iot = aa->aa_iot; 193 t->t_iot = aa->aa_iot;
207 t->t_ioh_d = ioh_d; 194 t->t_ioh_d = ioh_d;
208 t->t_ioh_c = ioh_c; 195 t->t_ioh_c = ioh_c;
209 t->t_addr = io0->ar_base; 196 t->t_addr = io0->ar_base;
210 t->t_cmdbyte = KC8_CPU; /* Enable ports */ 197 t->t_cmdbyte = KC8_CPU; /* Enable ports */
211 callout_init(&t->t_cleanup, 0); 198 callout_init(&t->t_cleanup, 0);
212 } 199 }
213 200
214 t->t_sc = &first->sc_pckbc; 201 t->t_sc = &first->sc_pckbc;
215 first->sc_pckbc.id = t; 202 first->sc_pckbc.id = t;
216 203
217 if (!pmf_device_register(self, NULL, pckbc_resume)) 204 if (!pmf_device_register(self, NULL, pckbc_resume))
218 aprint_error_dev(self, 205 aprint_error_dev(self,
219 "couldn't establish power handler\n"); 206 "couldn't establish power handler\n");
220 207
221 first->sc_pckbc.intr_establish = pckbc_acpi_intr_establish; 208 first->sc_pckbc.intr_establish = pckbc_acpi_intr_establish;
222 config_defer(first->sc_pckbc.sc_dv, pckbc_acpi_finish_attach); 209 config_defer(first->sc_pckbc.sc_dv, pckbc_acpi_finish_attach);
223 } 210 }
224 211
225out: 212out:
226 if (!pmf_device_register(self, NULL, NULL)) 213 if (!pmf_device_register(self, NULL, NULL))
227 aprint_error_dev(self, "couldn't establish power handler\n"); 214 aprint_error_dev(self, "couldn't establish power handler\n");
228 acpi_resource_cleanup(&res); 215 acpi_resource_cleanup(&res);
229} 216}
230 217
231static void 218static void
232pckbc_acpi_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot) 219pckbc_acpi_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
233{ 220{
234 struct pckbc_acpi_softc *psc = NULL; /* XXX: gcc */ 221 struct pckbc_acpi_softc *psc = NULL; /* XXX: gcc */
235 void *rv = NULL; 222 void *rv = NULL;
236 ACPI_HANDLE handle; 223 ACPI_HANDLE handle;
237 char intr_name[64]; 224 char intr_name[64];
238 int i; 225 int i;
239 226
240 /* 227 /*
241 * Note we're always called with sc == first. 228 * Note we're always called with sc == first.
242 */ 229 */
243 for (i = 0; i < pckbc_cd.cd_ndevs; i++) { 230 for (i = 0; i < pckbc_cd.cd_ndevs; i++) {
244 psc = device_lookup_private(&pckbc_cd, i); 231 psc = device_lookup_private(&pckbc_cd, i);
245 if (psc && psc->sc_slot == slot) { 232 if (psc && psc->sc_slot == slot) {
246 handle = psc->sc_handle; 233 handle = psc->sc_handle;
247 break; 234 break;
248 } 235 }
249 } 236 }
250 if (i < pckbc_cd.cd_ndevs) { 237 if (i < pckbc_cd.cd_ndevs) {
251 snprintf(intr_name, sizeof(intr_name), "%s %s", 238 snprintf(intr_name, sizeof(intr_name), "%s %s",
252 device_xname(psc->sc_pckbc.sc_dv), pckbc_slot_names[slot]); 239 device_xname(psc->sc_pckbc.sc_dv), pckbc_slot_names[slot]);
253 240
254 rv = acpi_intr_establish(sc->sc_dv, (uint64_t)(uintptr_t)handle, 241 rv = acpi_intr_establish(sc->sc_dv, (uint64_t)(uintptr_t)handle,
255 IPL_TTY, false, pckbcintr, sc, intr_name); 242 IPL_TTY, false, pckbcintr, sc, intr_name);
256 } 243 }
257 if (rv == NULL) { 244 if (rv == NULL) {
258 aprint_error_dev(sc->sc_dv, 245 aprint_error_dev(sc->sc_dv,
259 "unable to establish interrupt for %s slot\n", 246 "unable to establish interrupt for %s slot\n",
260 pckbc_slot_names[slot]); 247 pckbc_slot_names[slot]);
261 } else { 248 } else {
262 aprint_normal_dev(sc->sc_dv, "using %s for %s slot\n", 249 aprint_normal_dev(sc->sc_dv, "using %s for %s slot\n",
263 acpi_intr_string(rv, intr_name, sizeof(intr_name)), 250 acpi_intr_string(rv, intr_name, sizeof(intr_name)),
264 pckbc_slot_names[slot]); 251 pckbc_slot_names[slot]);
265 } 252 }
266} 253}
267 254
268static void 255static void
269pckbc_acpi_finish_attach(device_t dv) 256pckbc_acpi_finish_attach(device_t dv)
270{ 257{
271 258
272 pckbc_attach(device_private(dv)); 259 pckbc_attach(device_private(dv));
273} 260}

cvs diff -r1.12 -r1.13 src/sys/dev/acpi/tpm_acpi.c (switch to unified diff)

--- 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,170 +1,163 @@ @@ -1,170 +1,163 @@
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.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
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#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
50ACPI_MODULE_NAME ("tpm_acpi") 50ACPI_MODULE_NAME ("tpm_acpi")
51 51
52static int tpm_acpi_match(device_t, cfdata_t, void *); 52static int tpm_acpi_match(device_t, cfdata_t, void *);
53static void tpm_acpi_attach(device_t, device_t, void *); 53static void tpm_acpi_attach(device_t, device_t, void *);
54 54
55CFATTACH_DECL_NEW(tpm_acpi, sizeof(struct tpm_softc), tpm_acpi_match, 55CFATTACH_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/* 58static 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 },
61static 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 */ 
69static const char * const tpm2_acpi_ids[] = { 
70 "MSFT0101", 
71 NULL 
72}; 62};
73 63
74static int 64static int
75tpm_acpi_match(device_t parent, cfdata_t match, void *aux) 65tpm_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
106static void 99static void
107tpm_acpi_attach(device_t parent, device_t self, void *aux) 100tpm_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 }
156 if ((rv = (*sc->sc_intf->init)(sc)) != 0) { 149 if ((rv = (*sc->sc_intf->init)(sc)) != 0) {
157 aprint_error_dev(sc->sc_dev, "cannot init device, rv=%d\n", rv); 150 aprint_error_dev(sc->sc_dev, "cannot init device, rv=%d\n", rv);
158 goto out1; 151 goto out1;
159 } 152 }
160 153
161 if (!pmf_device_register(self, tpm_suspend, tpm_resume)) 154 if (!pmf_device_register(self, tpm_suspend, tpm_resume))
162 aprint_error_dev(self, "couldn't establish power handler\n"); 155 aprint_error_dev(self, "couldn't establish power handler\n");
163 acpi_resource_cleanup(&res); 156 acpi_resource_cleanup(&res);
164 return; 157 return;
165 158
166out1: 159out1:
167 bus_space_unmap(sc->sc_bt, sc->sc_bh, size); 160 bus_space_unmap(sc->sc_bt, sc->sc_bh, size);
168out: 161out:
169 acpi_resource_cleanup(&res); 162 acpi_resource_cleanup(&res);
170} 163}