add support for reset registers in PCI config spacediff -r1.247 -r1.248 src/sys/dev/acpi/acpi.c
(jmcneill)
--- src/sys/dev/acpi/acpi.c 2011/07/17 02:32:01 1.247
+++ src/sys/dev/acpi/acpi.c 2011/08/01 11:25:59 1.248
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: acpi.c,v 1.247 2011/07/17 02:32:01 jakllsch Exp $ */ | 1 | /* $NetBSD: acpi.c,v 1.248 2011/08/01 11:25:59 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2003, 2007 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 Charles M. Hannum of By Noon Software, Inc. | 8 | * by Charles M. Hannum of By Noon Software, Inc. | |
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. | |
@@ -90,27 +90,27 @@ | @@ -90,27 +90,27 @@ | |||
90 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 90 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
91 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 91 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
92 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | 92 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | |
93 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 93 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
94 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 94 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
95 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 95 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
96 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 96 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
97 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 97 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
98 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 98 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
99 | * POSSIBILITY OF SUCH DAMAGE. | 99 | * POSSIBILITY OF SUCH DAMAGE. | |
100 | */ | 100 | */ | |
101 | 101 | |||
102 | #include <sys/cdefs.h> | 102 | #include <sys/cdefs.h> | |
103 | __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.247 2011/07/17 02:32:01 jakllsch Exp $"); | 103 | __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.248 2011/08/01 11:25:59 jmcneill Exp $"); | |
104 | 104 | |||
105 | #include "opt_acpi.h" | 105 | #include "opt_acpi.h" | |
106 | #include "opt_pcifixup.h" | 106 | #include "opt_pcifixup.h" | |
107 | 107 | |||
108 | #include <sys/param.h> | 108 | #include <sys/param.h> | |
109 | #include <sys/device.h> | 109 | #include <sys/device.h> | |
110 | #include <sys/kernel.h> | 110 | #include <sys/kernel.h> | |
111 | #include <sys/kmem.h> | 111 | #include <sys/kmem.h> | |
112 | #include <sys/malloc.h> | 112 | #include <sys/malloc.h> | |
113 | #include <sys/module.h> | 113 | #include <sys/module.h> | |
114 | #include <sys/mutex.h> | 114 | #include <sys/mutex.h> | |
115 | #include <sys/sysctl.h> | 115 | #include <sys/sysctl.h> | |
116 | #include <sys/systm.h> | 116 | #include <sys/systm.h> | |
@@ -338,26 +338,66 @@ acpi_disable(void) | @@ -338,26 +338,66 @@ acpi_disable(void) | |||
338 | 338 | |||
339 | KASSERT(acpi_active != 0); | 339 | KASSERT(acpi_active != 0); | |
340 | 340 | |||
341 | if (AcpiGbl_FADT.SmiCommand != 0) | 341 | if (AcpiGbl_FADT.SmiCommand != 0) | |
342 | AcpiDisable(); | 342 | AcpiDisable(); | |
343 | } | 343 | } | |
344 | 344 | |||
345 | int | 345 | int | |
346 | acpi_check(device_t parent, const char *ifattr) | 346 | acpi_check(device_t parent, const char *ifattr) | |
347 | { | 347 | { | |
348 | return (config_search_ia(acpi_submatch, parent, ifattr, NULL) != NULL); | 348 | return (config_search_ia(acpi_submatch, parent, ifattr, NULL) != NULL); | |
349 | } | 349 | } | |
350 | 350 | |||
351 | int | |||
352 | acpi_reset(void) | |||
353 | { | |||
354 | struct acpi_softc *sc = acpi_softc; | |||
355 | ACPI_GENERIC_ADDRESS *ResetReg; | |||
356 | ACPI_PCI_ID PciId; | |||
357 | ACPI_STATUS status; | |||
358 | ||||
359 | if (sc == NULL) | |||
360 | return ENXIO; | |||
361 | ||||
362 | ResetReg = &AcpiGbl_FADT.ResetRegister; | |||
363 | ||||
364 | /* Check if the reset register is supported */ | |||
365 | if (!(AcpiGbl_FADT.Flags & ACPI_FADT_RESET_REGISTER) || | |||
366 | !ResetReg->Address) { | |||
367 | return ENOENT; | |||
368 | } | |||
369 | ||||
370 | switch (ResetReg->SpaceId) { | |||
371 | case ACPI_ADR_SPACE_PCI_CONFIG: | |||
372 | PciId.Segment = PciId.Bus = 0; | |||
373 | PciId.Device = ACPI_GAS_PCI_DEV(ResetReg->Address); | |||
374 | PciId.Function = ACPI_GAS_PCI_FUNC(ResetReg->Address); | |||
375 | status = AcpiOsWritePciConfiguration(&PciId, | |||
376 | ACPI_GAS_PCI_REGOFF(ResetReg->Address), | |||
377 | AcpiGbl_FADT.ResetValue, ResetReg->BitWidth); | |||
378 | break; | |||
379 | case ACPI_ADR_SPACE_SYSTEM_IO: | |||
380 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: | |||
381 | status = AcpiReset(); | |||
382 | break; | |||
383 | default: | |||
384 | status = AE_TYPE; | |||
385 | break; | |||
386 | } | |||
387 | ||||
388 | return ACPI_FAILURE(status) ? EIO : 0; | |||
389 | } | |||
390 | ||||
351 | /* | 391 | /* | |
352 | * Autoconfiguration. | 392 | * Autoconfiguration. | |
353 | */ | 393 | */ | |
354 | static int | 394 | static int | |
355 | acpi_match(device_t parent, cfdata_t match, void *aux) | 395 | acpi_match(device_t parent, cfdata_t match, void *aux) | |
356 | { | 396 | { | |
357 | /* | 397 | /* | |
358 | * XXX: Nada; MD code has called acpi_probe(). | 398 | * XXX: Nada; MD code has called acpi_probe(). | |
359 | */ | 399 | */ | |
360 | return 1; | 400 | return 1; | |
361 | } | 401 | } | |
362 | 402 | |||
363 | static int | 403 | static int |
--- src/sys/dev/acpi/acpireg.h 2010/10/12 19:10:50 1.11
+++ src/sys/dev/acpi/acpireg.h 2011/08/01 11:25:59 1.12
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: acpireg.h,v 1.11 2010/10/12 19:10:50 gsutre Exp $ */ | 1 | /* $NetBSD: acpireg.h,v 1.12 2011/08/01 11:25:59 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright 2001 Wasabi Systems, Inc. | 4 | * Copyright 2001 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 | |
@@ -51,26 +51,30 @@ | @@ -51,26 +51,30 @@ | |||
51 | #define ACPI_OSC_QUERY __BIT(0) | 51 | #define ACPI_OSC_QUERY __BIT(0) | |
52 | #define ACPI_OSC_ERROR __BIT(1) | 52 | #define ACPI_OSC_ERROR __BIT(1) | |
53 | #define ACPI_OSC_ERROR_UUID __BIT(2) | 53 | #define ACPI_OSC_ERROR_UUID __BIT(2) | |
54 | #define ACPI_OSC_ERROR_REV __BIT(3) | 54 | #define ACPI_OSC_ERROR_REV __BIT(3) | |
55 | #define ACPI_OSC_ERROR_MASKED __BIT(4) | 55 | #define ACPI_OSC_ERROR_MASKED __BIT(4) | |
56 | 56 | |||
57 | /* | 57 | /* | |
58 | * PCI functions. | 58 | * PCI functions. | |
59 | */ | 59 | */ | |
60 | #define ACPI_ADR_PCI_DEV(x) (((x) >> 16) & 0xffff) | 60 | #define ACPI_ADR_PCI_DEV(x) (((x) >> 16) & 0xffff) | |
61 | #define ACPI_ADR_PCI_FUNC(x) ((x) & 0xffff) | 61 | #define ACPI_ADR_PCI_FUNC(x) ((x) & 0xffff) | |
62 | #define ACPI_ADR_PCI_ALLFUNCS 0xffff | 62 | #define ACPI_ADR_PCI_ALLFUNCS 0xffff | |
63 | 63 | |||
64 | #define ACPI_GAS_PCI_DEV(x) (((x) >> 32) & 0xffff) | |||
65 | #define ACPI_GAS_PCI_FUNC(x) (((x) >> 16) & 0xffff) | |||
66 | #define ACPI_GAS_PCI_REGOFF(x) ((x) & 0xffff) | |||
67 | ||||
64 | /* | 68 | /* | |
65 | * ACPI driver components. | 69 | * ACPI driver components. | |
66 | */ | 70 | */ | |
67 | #define ACPI_BUS_COMPONENT 0x00010000 | 71 | #define ACPI_BUS_COMPONENT 0x00010000 | |
68 | #define ACPI_ACAD_COMPONENT 0x00020000 | 72 | #define ACPI_ACAD_COMPONENT 0x00020000 | |
69 | #define ACPI_BAT_COMPONENT 0x00040000 | 73 | #define ACPI_BAT_COMPONENT 0x00040000 | |
70 | #define ACPI_BUTTON_COMPONENT 0x00080000 | 74 | #define ACPI_BUTTON_COMPONENT 0x00080000 | |
71 | #define ACPI_EC_COMPONENT 0x00100000 | 75 | #define ACPI_EC_COMPONENT 0x00100000 | |
72 | #define ACPI_LID_COMPONENT 0x00200000 | 76 | #define ACPI_LID_COMPONENT 0x00200000 | |
73 | #define ACPI_RESOURCE_COMPONENT 0x00400000 | 77 | #define ACPI_RESOURCE_COMPONENT 0x00400000 | |
74 | #define ACPI_TZ_COMPONENT 0x00800000 | 78 | #define ACPI_TZ_COMPONENT 0x00800000 | |
75 | #define ACPI_DISPLAY_COMPONENT 0x01000000 | 79 | #define ACPI_DISPLAY_COMPONENT 0x01000000 | |
76 | 80 |
--- src/sys/dev/acpi/acpivar.h 2011/06/21 03:37:21 1.72
+++ src/sys/dev/acpi/acpivar.h 2011/08/01 11:25:59 1.73
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: acpivar.h,v 1.72 2011/06/21 03:37:21 jruoho Exp $ */ | 1 | /* $NetBSD: acpivar.h,v 1.73 2011/08/01 11:25:59 jmcneill Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright 2001 Wasabi Systems, Inc. | 4 | * Copyright 2001 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 | |
@@ -287,26 +287,28 @@ struct acpi_resource_parse_ops { | @@ -287,26 +287,28 @@ struct acpi_resource_parse_ops { | |||
287 | void (*end_dep)(device_t, void *); | 287 | void (*end_dep)(device_t, void *); | |
288 | }; | 288 | }; | |
289 | 289 | |||
290 | extern struct acpi_softc *acpi_softc; | 290 | extern struct acpi_softc *acpi_softc; | |
291 | extern int acpi_active; | 291 | extern int acpi_active; | |
292 | 292 | |||
293 | extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default; | 293 | extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default; | |
294 | extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_quiet; | 294 | extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_quiet; | |
295 | 295 | |||
296 | int acpi_probe(void); | 296 | int acpi_probe(void); | |
297 | void acpi_disable(void); | 297 | void acpi_disable(void); | |
298 | int acpi_check(device_t, const char *); | 298 | int acpi_check(device_t, const char *); | |
299 | 299 | |||
300 | int acpi_reset(void); | |||
301 | ||||
300 | ACPI_PHYSICAL_ADDRESS acpi_OsGetRootPointer(void); | 302 | ACPI_PHYSICAL_ADDRESS acpi_OsGetRootPointer(void); | |
301 | 303 | |||
302 | bool acpi_register_notify(struct acpi_devnode *, | 304 | bool acpi_register_notify(struct acpi_devnode *, | |
303 | ACPI_NOTIFY_HANDLER); | 305 | ACPI_NOTIFY_HANDLER); | |
304 | void acpi_deregister_notify(struct acpi_devnode *); | 306 | void acpi_deregister_notify(struct acpi_devnode *); | |
305 | 307 | |||
306 | ACPI_STATUS acpi_resource_parse(device_t, ACPI_HANDLE, const char *, | 308 | ACPI_STATUS acpi_resource_parse(device_t, ACPI_HANDLE, const char *, | |
307 | void *, const struct acpi_resource_parse_ops *); | 309 | void *, const struct acpi_resource_parse_ops *); | |
308 | void acpi_resource_print(device_t, struct acpi_resources *); | 310 | void acpi_resource_print(device_t, struct acpi_resources *); | |
309 | void acpi_resource_cleanup(struct acpi_resources *); | 311 | void acpi_resource_cleanup(struct acpi_resources *); | |
310 | 312 | |||
311 | void * acpi_pci_link_devbyhandle(ACPI_HANDLE); | 313 | void * acpi_pci_link_devbyhandle(ACPI_HANDLE); | |
312 | void acpi_pci_link_add_reference(void *, int, int, int, int); | 314 | void acpi_pci_link_add_reference(void *, int, int, int, int); |