| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: acpi.c,v 1.211 2010/08/06 23:38:34 jruoho Exp $ */ | | 1 | /* $NetBSD: acpi.c,v 1.212 2010/08/07 09:41:19 jruoho 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. |
| @@ -20,26 +20,61 @@ | | | @@ -20,26 +20,61 @@ |
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 | * Copyright (c) 2003 Wasabi Systems, Inc. |
| | | 34 | * All rights reserved. |
| | | 35 | * |
| | | 36 | * Written by Frank van der Linden for Wasabi Systems, Inc. |
| | | 37 | * |
| | | 38 | * Redistribution and use in source and binary forms, with or without |
| | | 39 | * modification, are permitted provided that the following conditions |
| | | 40 | * are met: |
| | | 41 | * 1. Redistributions of source code must retain the above copyright |
| | | 42 | * notice, this list of conditions and the following disclaimer. |
| | | 43 | * 2. Redistributions in binary form must reproduce the above copyright |
| | | 44 | * notice, this list of conditions and the following disclaimer in the |
| | | 45 | * documentation and/or other materials provided with the distribution. |
| | | 46 | * 3. All advertising materials mentioning features or use of this software |
| | | 47 | * must display the following acknowledgement: |
| | | 48 | * This product includes software developed for the NetBSD Project by |
| | | 49 | * Wasabi Systems, Inc. |
| | | 50 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse |
| | | 51 | * or promote products derived from this software without specific prior |
| | | 52 | * written permission. |
| | | 53 | * |
| | | 54 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND |
| | | 55 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| | | 56 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| | | 57 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
| | | 58 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| | | 59 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| | | 60 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| | | 61 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| | | 62 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| | | 63 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| | | 64 | * POSSIBILITY OF SUCH DAMAGE. |
| | | 65 | */ |
| | | 66 | |
| | | 67 | /* |
33 | * Copyright 2001, 2003 Wasabi Systems, Inc. | | 68 | * Copyright 2001, 2003 Wasabi Systems, Inc. |
34 | * All rights reserved. | | 69 | * All rights reserved. |
35 | * | | 70 | * |
36 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. | | 71 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. |
37 | * | | 72 | * |
38 | * Redistribution and use in source and binary forms, with or without | | 73 | * Redistribution and use in source and binary forms, with or without |
39 | * modification, are permitted provided that the following conditions | | 74 | * modification, are permitted provided that the following conditions |
40 | * are met: | | 75 | * are met: |
41 | * 1. Redistributions of source code must retain the above copyright | | 76 | * 1. Redistributions of source code must retain the above copyright |
42 | * notice, this list of conditions and the following disclaimer. | | 77 | * notice, this list of conditions and the following disclaimer. |
43 | * 2. Redistributions in binary form must reproduce the above copyright | | 78 | * 2. Redistributions in binary form must reproduce the above copyright |
44 | * notice, this list of conditions and the following disclaimer in the | | 79 | * notice, this list of conditions and the following disclaimer in the |
45 | * documentation and/or other materials provided with the distribution. | | 80 | * documentation and/or other materials provided with the distribution. |
| @@ -55,27 +90,27 @@ | | | @@ -55,27 +90,27 @@ |
55 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 90 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
56 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 91 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
57 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | | 92 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
58 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 93 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
59 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 94 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
60 | * 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 |
61 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 96 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
62 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 97 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
63 | * 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 |
64 | * POSSIBILITY OF SUCH DAMAGE. | | 99 | * POSSIBILITY OF SUCH DAMAGE. |
65 | */ | | 100 | */ |
66 | | | 101 | |
67 | #include <sys/cdefs.h> | | 102 | #include <sys/cdefs.h> |
68 | __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.211 2010/08/06 23:38:34 jruoho Exp $"); | | 103 | __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.212 2010/08/07 09:41:19 jruoho Exp $"); |
69 | | | 104 | |
70 | #include "opt_acpi.h" | | 105 | #include "opt_acpi.h" |
71 | #include "opt_pcifixup.h" | | 106 | #include "opt_pcifixup.h" |
72 | | | 107 | |
73 | #include <sys/param.h> | | 108 | #include <sys/param.h> |
74 | #include <sys/device.h> | | 109 | #include <sys/device.h> |
75 | #include <sys/kernel.h> | | 110 | #include <sys/kernel.h> |
76 | #include <sys/malloc.h> | | 111 | #include <sys/malloc.h> |
77 | #include <sys/module.h> | | 112 | #include <sys/module.h> |
78 | #include <sys/mutex.h> | | 113 | #include <sys/mutex.h> |
79 | #include <sys/sysctl.h> | | 114 | #include <sys/sysctl.h> |
80 | #include <sys/systm.h> | | 115 | #include <sys/systm.h> |
81 | #include <sys/timetc.h> | | 116 | #include <sys/timetc.h> |
| @@ -118,26 +153,27 @@ static int acpi_dbgr = 0x00; | | | @@ -118,26 +153,27 @@ static int acpi_dbgr = 0x00; |
118 | * dependent code may wish to skip other steps (such as attaching | | 153 | * dependent code may wish to skip other steps (such as attaching |
119 | * subsystems that ACPI supercedes) when ACPI is active. | | 154 | * subsystems that ACPI supercedes) when ACPI is active. |
120 | */ | | 155 | */ |
121 | int acpi_active; | | 156 | int acpi_active; |
122 | int acpi_force_load; | | 157 | int acpi_force_load; |
123 | int acpi_suspended = 0; | | 158 | int acpi_suspended = 0; |
124 | int acpi_verbose_loaded = 0; | | 159 | int acpi_verbose_loaded = 0; |
125 | | | 160 | |
126 | struct acpi_softc *acpi_softc; | | 161 | struct acpi_softc *acpi_softc; |
127 | static uint64_t acpi_root_pointer; | | 162 | static uint64_t acpi_root_pointer; |
128 | extern kmutex_t acpi_interrupt_list_mtx; | | 163 | extern kmutex_t acpi_interrupt_list_mtx; |
129 | extern struct cfdriver acpi_cd; | | 164 | extern struct cfdriver acpi_cd; |
130 | static ACPI_HANDLE acpi_scopes[4]; | | 165 | static ACPI_HANDLE acpi_scopes[4]; |
| | | 166 | static ACPI_TABLE_HEADER *madt_header; |
131 | | | 167 | |
132 | /* | | 168 | /* |
133 | * This structure provides a context for the ACPI | | 169 | * This structure provides a context for the ACPI |
134 | * namespace walk performed in acpi_build_tree(). | | 170 | * namespace walk performed in acpi_build_tree(). |
135 | */ | | 171 | */ |
136 | struct acpi_walkcontext { | | 172 | struct acpi_walkcontext { |
137 | struct acpi_softc *aw_sc; | | 173 | struct acpi_softc *aw_sc; |
138 | struct acpi_devnode *aw_parent; | | 174 | struct acpi_devnode *aw_parent; |
139 | }; | | 175 | }; |
140 | | | 176 | |
141 | /* | | 177 | /* |
142 | * Ignored HIDs. | | 178 | * Ignored HIDs. |
143 | */ | | 179 | */ |
| @@ -1595,54 +1631,28 @@ sysctl_hw_acpi_sleepstates(SYSCTLFN_ARGS | | | @@ -1595,54 +1631,28 @@ sysctl_hw_acpi_sleepstates(SYSCTLFN_ARGS |
1595 | | | 1631 | |
1596 | node = *rnode; | | 1632 | node = *rnode; |
1597 | node.sysctl_data = &t; | | 1633 | node.sysctl_data = &t; |
1598 | | | 1634 | |
1599 | err = sysctl_lookup(SYSCTLFN_CALL(&node)); | | 1635 | err = sysctl_lookup(SYSCTLFN_CALL(&node)); |
1600 | | | 1636 | |
1601 | if (err || newp == NULL) | | 1637 | if (err || newp == NULL) |
1602 | return err; | | 1638 | return err; |
1603 | | | 1639 | |
1604 | return 0; | | 1640 | return 0; |
1605 | } | | 1641 | } |
1606 | | | 1642 | |
1607 | /* | | 1643 | /* |
1608 | * Miscellaneous. | | 1644 | * Tables. |
1609 | */ | | 1645 | */ |
1610 | static bool | | | |
1611 | acpi_is_scope(struct acpi_devnode *ad) | | | |
1612 | { | | | |
1613 | int i; | | | |
1614 | | | | |
1615 | /* | | | |
1616 | * Return true if the node is a root scope. | | | |
1617 | */ | | | |
1618 | if (ad->ad_parent == NULL) | | | |
1619 | return false; | | | |
1620 | | | | |
1621 | if (ad->ad_parent->ad_handle != ACPI_ROOT_OBJECT) | | | |
1622 | return false; | | | |
1623 | | | | |
1624 | for (i = 0; i < __arraycount(acpi_scopes); i++) { | | | |
1625 | | | | |
1626 | if (acpi_scopes[i] == NULL) | | | |
1627 | continue; | | | |
1628 | | | | |
1629 | if (ad->ad_handle == acpi_scopes[i]) | | | |
1630 | return true; | | | |
1631 | } | | | |
1632 | | | | |
1633 | return false; | | | |
1634 | } | | | |
1635 | | | | |
1636 | ACPI_PHYSICAL_ADDRESS | | 1646 | ACPI_PHYSICAL_ADDRESS |
1637 | acpi_OsGetRootPointer(void) | | 1647 | acpi_OsGetRootPointer(void) |
1638 | { | | 1648 | { |
1639 | ACPI_PHYSICAL_ADDRESS PhysicalAddress; | | 1649 | ACPI_PHYSICAL_ADDRESS PhysicalAddress; |
1640 | | | 1650 | |
1641 | /* | | 1651 | /* |
1642 | * We let MD code handle this since there are multiple ways to do it: | | 1652 | * We let MD code handle this since there are multiple ways to do it: |
1643 | * | | 1653 | * |
1644 | * IA-32: Use AcpiFindRootPointer() to locate the RSDP. | | 1654 | * IA-32: Use AcpiFindRootPointer() to locate the RSDP. |
1645 | * | | 1655 | * |
1646 | * IA-64: Use the EFI. | | 1656 | * IA-64: Use the EFI. |
1647 | */ | | 1657 | */ |
1648 | PhysicalAddress = acpi_md_OsGetRootPointer(); | | 1658 | PhysicalAddress = acpi_md_OsGetRootPointer(); |
| @@ -1680,26 +1690,103 @@ acpi_map_rsdt(void) | | | @@ -1680,26 +1690,103 @@ acpi_map_rsdt(void) |
1680 | } | | 1690 | } |
1681 | | | 1691 | |
1682 | static void | | 1692 | static void |
1683 | acpi_unmap_rsdt(ACPI_TABLE_HEADER *rsdt) | | 1693 | acpi_unmap_rsdt(ACPI_TABLE_HEADER *rsdt) |
1684 | { | | 1694 | { |
1685 | | | 1695 | |
1686 | if (rsdt == NULL) | | 1696 | if (rsdt == NULL) |
1687 | return; | | 1697 | return; |
1688 | | | 1698 | |
1689 | AcpiOsUnmapMemory(rsdt, sizeof(ACPI_TABLE_HEADER)); | | 1699 | AcpiOsUnmapMemory(rsdt, sizeof(ACPI_TABLE_HEADER)); |
1690 | } | | 1700 | } |
1691 | | | 1701 | |
1692 | /* | | 1702 | /* |
| | | 1703 | * XXX: Refactor to be a generic function that maps tables. |
| | | 1704 | */ |
| | | 1705 | ACPI_STATUS |
| | | 1706 | acpi_madt_map(void) |
| | | 1707 | { |
| | | 1708 | ACPI_STATUS rv; |
| | | 1709 | |
| | | 1710 | if (madt_header != NULL) |
| | | 1711 | return AE_ALREADY_EXISTS; |
| | | 1712 | |
| | | 1713 | rv = AcpiGetTable(ACPI_SIG_MADT, 1, &madt_header); |
| | | 1714 | |
| | | 1715 | if (ACPI_FAILURE(rv)) |
| | | 1716 | return rv; |
| | | 1717 | |
| | | 1718 | return AE_OK; |
| | | 1719 | } |
| | | 1720 | |
| | | 1721 | void |
| | | 1722 | acpi_madt_unmap(void) |
| | | 1723 | { |
| | | 1724 | madt_header = NULL; |
| | | 1725 | } |
| | | 1726 | |
| | | 1727 | /* |
| | | 1728 | * XXX: Refactor to be a generic function that walks tables. |
| | | 1729 | */ |
| | | 1730 | void |
| | | 1731 | acpi_madt_walk(ACPI_STATUS (*func)(ACPI_SUBTABLE_HEADER *, void *), void *aux) |
| | | 1732 | { |
| | | 1733 | ACPI_SUBTABLE_HEADER *hdrp; |
| | | 1734 | char *madtend, *where; |
| | | 1735 | |
| | | 1736 | madtend = (char *)madt_header + madt_header->Length; |
| | | 1737 | where = (char *)madt_header + sizeof (ACPI_TABLE_MADT); |
| | | 1738 | |
| | | 1739 | while (where < madtend) { |
| | | 1740 | |
| | | 1741 | hdrp = (ACPI_SUBTABLE_HEADER *)where; |
| | | 1742 | |
| | | 1743 | if (ACPI_FAILURE(func(hdrp, aux))) |
| | | 1744 | break; |
| | | 1745 | |
| | | 1746 | where += hdrp->Length; |
| | | 1747 | } |
| | | 1748 | } |
| | | 1749 | |
| | | 1750 | /* |
| | | 1751 | * Miscellaneous. |
| | | 1752 | */ |
| | | 1753 | static bool |
| | | 1754 | acpi_is_scope(struct acpi_devnode *ad) |
| | | 1755 | { |
| | | 1756 | int i; |
| | | 1757 | |
| | | 1758 | /* |
| | | 1759 | * Return true if the node is a root scope. |
| | | 1760 | */ |
| | | 1761 | if (ad->ad_parent == NULL) |
| | | 1762 | return false; |
| | | 1763 | |
| | | 1764 | if (ad->ad_parent->ad_handle != ACPI_ROOT_OBJECT) |
| | | 1765 | return false; |
| | | 1766 | |
| | | 1767 | for (i = 0; i < __arraycount(acpi_scopes); i++) { |
| | | 1768 | |
| | | 1769 | if (acpi_scopes[i] == NULL) |
| | | 1770 | continue; |
| | | 1771 | |
| | | 1772 | if (ad->ad_handle == acpi_scopes[i]) |
| | | 1773 | return true; |
| | | 1774 | } |
| | | 1775 | |
| | | 1776 | return false; |
| | | 1777 | } |
| | | 1778 | |
| | | 1779 | /* |
1693 | * ACPIVERBOSE. | | 1780 | * ACPIVERBOSE. |
1694 | */ | | 1781 | */ |
1695 | void | | 1782 | void |
1696 | acpi_load_verbose(void) | | 1783 | acpi_load_verbose(void) |
1697 | { | | 1784 | { |
1698 | | | 1785 | |
1699 | if (acpi_verbose_loaded == 0) { | | 1786 | if (acpi_verbose_loaded == 0) { |
1700 | mutex_enter(&module_lock); | | 1787 | mutex_enter(&module_lock); |
1701 | module_autoload("acpiverbose", MODULE_CLASS_MISC); | | 1788 | module_autoload("acpiverbose", MODULE_CLASS_MISC); |
1702 | mutex_exit(&module_lock); | | 1789 | mutex_exit(&module_lock); |
1703 | } | | 1790 | } |
1704 | } | | 1791 | } |
1705 | | | 1792 | |