Home | History | Annotate | Line # | Download | only in acpi
acpi.c revision 1.6
      1  1.6  tsutsui /*	$NetBSD: acpi.c,v 1.6 2002/01/12 16:43:53 tsutsui Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*
      4  1.1  thorpej  * Copyright 2001 Wasabi Systems, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  1.1  thorpej  *
      9  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     10  1.1  thorpej  * modification, are permitted provided that the following conditions
     11  1.1  thorpej  * are met:
     12  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     13  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     14  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     17  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     18  1.1  thorpej  *    must display the following acknowledgement:
     19  1.1  thorpej  *	This product includes software developed for the NetBSD Project by
     20  1.1  thorpej  *	Wasabi Systems, Inc.
     21  1.1  thorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1  thorpej  *    or promote products derived from this software without specific prior
     23  1.1  thorpej  *    written permission.
     24  1.1  thorpej  *
     25  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1  thorpej  */
     37  1.1  thorpej 
     38  1.1  thorpej /*
     39  1.1  thorpej  * Autoconfiguration support for the Intel ACPI Component Architecture
     40  1.1  thorpej  * ACPI reference implementation.
     41  1.1  thorpej  */
     42  1.5    lukem 
     43  1.5    lukem #include <sys/cdefs.h>
     44  1.6  tsutsui __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.6 2002/01/12 16:43:53 tsutsui Exp $");
     45  1.1  thorpej 
     46  1.1  thorpej #include <sys/param.h>
     47  1.1  thorpej #include <sys/systm.h>
     48  1.1  thorpej #include <sys/device.h>
     49  1.1  thorpej #include <sys/malloc.h>
     50  1.1  thorpej 
     51  1.1  thorpej #include <dev/acpi/acpica.h>
     52  1.1  thorpej #include <dev/acpi/acpireg.h>
     53  1.1  thorpej #include <dev/acpi/acpivar.h>
     54  1.1  thorpej #include <dev/acpi/acpi_osd.h>
     55  1.1  thorpej 
     56  1.1  thorpej #ifdef ENABLE_DEBUGGER
     57  1.1  thorpej #define	ACPI_DBGR_INIT		0x01
     58  1.1  thorpej #define	ACPI_DBGR_TABLES	0x02
     59  1.1  thorpej #define	ACPI_DBGR_ENABLE	0x04
     60  1.1  thorpej #define	ACPI_DBGR_PROBE		0x08
     61  1.1  thorpej #define	ACPI_DBGR_RUNNING	0x10
     62  1.1  thorpej 
     63  1.1  thorpej int	acpi_dbgr = 0x00;
     64  1.1  thorpej #endif
     65  1.1  thorpej 
     66  1.1  thorpej int	acpi_match(struct device *, struct cfdata *, void *);
     67  1.1  thorpej void	acpi_attach(struct device *, struct device *, void *);
     68  1.1  thorpej 
     69  1.1  thorpej int	acpi_print(void *aux, const char *);
     70  1.1  thorpej 
     71  1.1  thorpej extern struct cfdriver acpi_cd;
     72  1.1  thorpej 
     73  1.1  thorpej struct cfattach acpi_ca = {
     74  1.1  thorpej 	sizeof(struct acpi_softc), acpi_match, acpi_attach,
     75  1.1  thorpej };
     76  1.1  thorpej 
     77  1.1  thorpej /*
     78  1.1  thorpej  * This is a flag we set when the ACPI subsystem is active.  Machine
     79  1.1  thorpej  * dependent code may wish to skip other steps (such as attaching
     80  1.1  thorpej  * subsystems that ACPI supercedes) when ACPI is active.
     81  1.1  thorpej  */
     82  1.1  thorpej int	acpi_active;
     83  1.1  thorpej 
     84  1.1  thorpej /*
     85  1.1  thorpej  * Pointer to the ACPI subsystem's state.  There can be only
     86  1.1  thorpej  * one ACPI instance.
     87  1.1  thorpej  */
     88  1.1  thorpej struct acpi_softc *acpi_softc;
     89  1.1  thorpej 
     90  1.1  thorpej void		acpi_shutdown(void *);
     91  1.1  thorpej ACPI_STATUS	acpi_disable(struct acpi_softc *sc);
     92  1.1  thorpej void		acpi_build_tree(struct acpi_softc *);
     93  1.1  thorpej ACPI_STATUS	acpi_make_devnode(ACPI_HANDLE, UINT32, void *, void **);
     94  1.1  thorpej 
     95  1.1  thorpej void		acpi_enable_fixed_events(struct acpi_softc *);
     96  1.1  thorpej 
     97  1.1  thorpej /*
     98  1.1  thorpej  * acpi_probe:
     99  1.1  thorpej  *
    100  1.1  thorpej  *	Probe for ACPI support.  This is called by the
    101  1.1  thorpej  *	machine-dependent ACPI front-end.  All of the
    102  1.1  thorpej  *	actual work is done by ACPICA.
    103  1.1  thorpej  *
    104  1.1  thorpej  *	NOTE: This is not an autoconfiguration interface function.
    105  1.1  thorpej  */
    106  1.1  thorpej int
    107  1.1  thorpej acpi_probe(void)
    108  1.1  thorpej {
    109  1.1  thorpej 	static int beenhere;
    110  1.1  thorpej 	ACPI_STATUS rv;
    111  1.1  thorpej 
    112  1.1  thorpej 	if (beenhere != 0)
    113  1.1  thorpej 		panic("acpi_probe: ACPI has already been probed");
    114  1.1  thorpej 	beenhere = 1;
    115  1.1  thorpej 
    116  1.1  thorpej 	/*
    117  1.1  thorpej 	 * Start up ACPICA.
    118  1.1  thorpej 	 */
    119  1.1  thorpej #ifdef ENABLE_DEBUGGER
    120  1.1  thorpej 	if (acpi_dbgr & ACPI_DBGR_INIT)
    121  1.1  thorpej 		acpi_osd_debugger();
    122  1.1  thorpej #endif
    123  1.1  thorpej 
    124  1.1  thorpej 	rv = AcpiInitializeSubsystem();
    125  1.1  thorpej 	if (rv != AE_OK) {
    126  1.1  thorpej 		printf("ACPI: unable to initialize ACPICA: %d\n", rv);
    127  1.1  thorpej 		return (0);
    128  1.1  thorpej 	}
    129  1.1  thorpej 
    130  1.1  thorpej #ifdef ENABLE_DEBUGGER
    131  1.1  thorpej 	if (acpi_dbgr & ACPI_DBGR_TABLES)
    132  1.1  thorpej 		acpi_osd_debugger();
    133  1.1  thorpej #endif
    134  1.1  thorpej 
    135  1.1  thorpej 	rv = AcpiLoadTables();
    136  1.1  thorpej 	if (rv != AE_OK) {
    137  1.1  thorpej 		printf("ACPI: unable to load tables: %d\n", rv);
    138  1.1  thorpej 		return (0);
    139  1.1  thorpej 	}
    140  1.1  thorpej 
    141  1.1  thorpej 	/*
    142  1.1  thorpej 	 * Looks like we have ACPI!
    143  1.1  thorpej 	 */
    144  1.1  thorpej 
    145  1.1  thorpej 	return (1);
    146  1.1  thorpej }
    147  1.1  thorpej 
    148  1.1  thorpej /*
    149  1.1  thorpej  * acpi_match:
    150  1.1  thorpej  *
    151  1.1  thorpej  *	Autoconfiguration `match' routine.
    152  1.1  thorpej  */
    153  1.1  thorpej int
    154  1.1  thorpej acpi_match(struct device *parent, struct cfdata *match, void *aux)
    155  1.1  thorpej {
    156  1.1  thorpej 	struct acpibus_attach_args *aa = aux;
    157  1.1  thorpej 
    158  1.1  thorpej 	if (strcmp(aa->aa_busname, acpi_cd.cd_name) != 0)
    159  1.1  thorpej 		return (0);
    160  1.1  thorpej 
    161  1.1  thorpej 	/*
    162  1.1  thorpej 	 * XXX Check other locators?  Hard to know -- machine
    163  1.1  thorpej 	 * dependent code has already checked for the presence
    164  1.1  thorpej 	 * of ACPI by calling acpi_probe(), so I suppose we
    165  1.1  thorpej 	 * don't really have to do anything else.
    166  1.1  thorpej 	 */
    167  1.1  thorpej 	return (1);
    168  1.1  thorpej }
    169  1.1  thorpej 
    170  1.1  thorpej /*
    171  1.1  thorpej  * acpi_attach:
    172  1.1  thorpej  *
    173  1.1  thorpej  *	Autoconfiguration `attach' routine.  Finish initializing
    174  1.1  thorpej  *	ACPICA (some initialization was done in acpi_probe(),
    175  1.1  thorpej  *	which was required to check for the presence of ACPI),
    176  1.1  thorpej  *	and enable the ACPI subsystem.
    177  1.1  thorpej  */
    178  1.1  thorpej void
    179  1.1  thorpej acpi_attach(struct device *parent, struct device *self, void *aux)
    180  1.1  thorpej {
    181  1.1  thorpej 	struct acpi_softc *sc = (void *) self;
    182  1.1  thorpej 	struct acpibus_attach_args *aa = aux;
    183  1.1  thorpej 	ACPI_STATUS rv;
    184  1.1  thorpej 
    185  1.1  thorpej 	printf("\n");
    186  1.1  thorpej 
    187  1.1  thorpej 	if (acpi_softc != NULL)
    188  1.1  thorpej 		panic("acpi_attach: ACPI has already been attached");
    189  1.1  thorpej 
    190  1.1  thorpej 	sc->sc_iot = aa->aa_iot;
    191  1.1  thorpej 	sc->sc_memt = aa->aa_memt;
    192  1.1  thorpej 	sc->sc_pc = aa->aa_pc;
    193  1.1  thorpej 	sc->sc_pciflags = aa->aa_pciflags;
    194  1.1  thorpej 
    195  1.1  thorpej 	acpi_softc = sc;
    196  1.1  thorpej 
    197  1.1  thorpej 	/*
    198  1.1  thorpej 	 * Install the default address space handlers.
    199  1.1  thorpej 	 */
    200  1.1  thorpej 
    201  1.1  thorpej 	rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
    202  1.1  thorpej 	    ACPI_ADR_SPACE_SYSTEM_MEMORY, ACPI_DEFAULT_HANDLER, NULL, NULL);
    203  1.1  thorpej 	if (rv != AE_OK) {
    204  1.1  thorpej 		printf("%s: unable to install SYSTEM MEMORY handler: %d\n",
    205  1.1  thorpej 		    sc->sc_dev.dv_xname, rv);
    206  1.1  thorpej 		return;
    207  1.1  thorpej 	}
    208  1.1  thorpej 
    209  1.1  thorpej 	rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
    210  1.1  thorpej 	    ACPI_ADR_SPACE_SYSTEM_IO, ACPI_DEFAULT_HANDLER, NULL, NULL);
    211  1.1  thorpej 	if (rv != AE_OK) {
    212  1.1  thorpej 		printf("%s: unable to install SYSTEM IO handler: %d\n",
    213  1.1  thorpej 		    sc->sc_dev.dv_xname, rv);
    214  1.1  thorpej 		return;
    215  1.1  thorpej 	}
    216  1.1  thorpej 
    217  1.1  thorpej 	rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
    218  1.1  thorpej 	    ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
    219  1.1  thorpej 	if (rv != AE_OK) {
    220  1.1  thorpej 		printf("%s: unable to install PCI CONFIG handler: %d\n",
    221  1.1  thorpej 		    sc->sc_dev.dv_xname, rv);
    222  1.1  thorpej 		return;
    223  1.1  thorpej 	}
    224  1.1  thorpej 
    225  1.1  thorpej 	/*
    226  1.1  thorpej 	 * Bring ACPI on-line.
    227  1.1  thorpej 	 *
    228  1.1  thorpej 	 * Note that we request that _STA (device init) and _INI (object init)
    229  1.1  thorpej 	 * methods not be run.
    230  1.1  thorpej 	 *
    231  1.1  thorpej 	 * XXX We need to arrange for the object init pass after we have
    232  1.1  thorpej 	 * XXX attached all of our children.
    233  1.1  thorpej 	 */
    234  1.1  thorpej #ifdef ENABLE_DEBUGGER
    235  1.1  thorpej 	if (acpi_dbgr & ACPI_DBGR_ENABLE)
    236  1.1  thorpej 		acpi_osd_debugger();
    237  1.1  thorpej #endif
    238  1.1  thorpej 	rv = AcpiEnableSubsystem(ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
    239  1.1  thorpej 	if (rv != AE_OK) {
    240  1.1  thorpej 		printf("%s: unable to enable ACPI: %d\n",
    241  1.1  thorpej 		    sc->sc_dev.dv_xname, rv);
    242  1.1  thorpej 		return;
    243  1.1  thorpej 	}
    244  1.1  thorpej 	acpi_active = 1;
    245  1.1  thorpej 
    246  1.1  thorpej 	/*
    247  1.1  thorpej 	 * Set up the default sleep state to enter when various
    248  1.1  thorpej 	 * switches are activated.
    249  1.1  thorpej 	 */
    250  1.1  thorpej 	sc->sc_switch_sleep[ACPI_SWITCH_POWERBUTTON] = ACPI_STATE_S5;
    251  1.1  thorpej 	sc->sc_switch_sleep[ACPI_SWITCH_SLEEPBUTTON] = ACPI_STATE_S1;
    252  1.1  thorpej 	sc->sc_switch_sleep[ACPI_SWITCH_LID]	     = ACPI_STATE_S1;
    253  1.1  thorpej 
    254  1.1  thorpej 	/* Our current state is "awake". */
    255  1.1  thorpej 	sc->sc_sleepstate = ACPI_STATE_S0;
    256  1.1  thorpej 
    257  1.1  thorpej 	/*
    258  1.1  thorpej 	 * Check for fixed-hardware features.
    259  1.1  thorpej 	 */
    260  1.1  thorpej 	acpi_enable_fixed_events(sc);
    261  1.1  thorpej 
    262  1.1  thorpej 	/*
    263  1.1  thorpej 	 * Scan the namespace and build our device tree.
    264  1.1  thorpej 	 */
    265  1.1  thorpej #ifdef ENABLE_DEBUGGER
    266  1.1  thorpej 	if (acpi_dbgr & ACPI_DBGR_PROBE)
    267  1.1  thorpej 		acpi_osd_debugger();
    268  1.1  thorpej #endif
    269  1.1  thorpej 	acpi_build_tree(sc);
    270  1.1  thorpej 
    271  1.1  thorpej 	/*
    272  1.1  thorpej 	 * Register a shutdown hook that disables certain ACPI
    273  1.1  thorpej 	 * events that might happen and confuse us while we're
    274  1.1  thorpej 	 * trying to shut down.
    275  1.1  thorpej 	 */
    276  1.1  thorpej 	sc->sc_sdhook = shutdownhook_establish(acpi_shutdown, sc);
    277  1.1  thorpej 	if (sc->sc_sdhook == NULL)
    278  1.1  thorpej 		printf("%s: WARNING: unable to register shutdown hook\n",
    279  1.1  thorpej 		    sc->sc_dev.dv_xname);
    280  1.1  thorpej 
    281  1.1  thorpej #ifdef ENABLE_DEBUGGER
    282  1.1  thorpej 	if (acpi_dbgr & ACPI_DBGR_RUNNING)
    283  1.1  thorpej 		acpi_osd_debugger();
    284  1.1  thorpej #endif
    285  1.1  thorpej }
    286  1.1  thorpej 
    287  1.1  thorpej /*
    288  1.1  thorpej  * acpi_shutdown:
    289  1.1  thorpej  *
    290  1.1  thorpej  *	Shutdown hook for ACPI -- disable some events that
    291  1.1  thorpej  *	might confuse us.
    292  1.1  thorpej  */
    293  1.1  thorpej void
    294  1.1  thorpej acpi_shutdown(void *arg)
    295  1.1  thorpej {
    296  1.1  thorpej 	struct acpi_softc *sc = arg;
    297  1.1  thorpej 
    298  1.1  thorpej 	if (acpi_disable(sc) != AE_OK)
    299  1.1  thorpej 		printf("%s: WARNING: unable to disable ACPI\n",
    300  1.1  thorpej 		    sc->sc_dev.dv_xname);
    301  1.1  thorpej }
    302  1.1  thorpej 
    303  1.1  thorpej /*
    304  1.1  thorpej  * acpi_disable:
    305  1.1  thorpej  *
    306  1.1  thorpej  *	Disable ACPI.
    307  1.1  thorpej  */
    308  1.1  thorpej ACPI_STATUS
    309  1.1  thorpej acpi_disable(struct acpi_softc *sc)
    310  1.1  thorpej {
    311  1.1  thorpej 	ACPI_STATUS rv = AE_OK;
    312  1.1  thorpej 
    313  1.1  thorpej 	if (acpi_active) {
    314  1.1  thorpej 		rv = AcpiDisable();
    315  1.1  thorpej 		if (rv == AE_OK)
    316  1.1  thorpej 			acpi_active = 0;
    317  1.1  thorpej 	}
    318  1.1  thorpej 	return (rv);
    319  1.1  thorpej }
    320  1.1  thorpej 
    321  1.1  thorpej struct acpi_make_devnode_state {
    322  1.1  thorpej 	struct acpi_softc *softc;
    323  1.1  thorpej 	struct acpi_scope *scope;
    324  1.1  thorpej };
    325  1.1  thorpej 
    326  1.1  thorpej /*
    327  1.1  thorpej  * acpi_build_tree:
    328  1.1  thorpej  *
    329  1.1  thorpej  *	Scan relevant portions of the ACPI namespace and attach
    330  1.1  thorpej  *	child devices.
    331  1.1  thorpej  */
    332  1.1  thorpej void
    333  1.1  thorpej acpi_build_tree(struct acpi_softc *sc)
    334  1.1  thorpej {
    335  1.1  thorpej 	static const char *scopes[] = {
    336  1.1  thorpej 		"\\_PR_",	/* ACPI 1.0 processor namespace */
    337  1.1  thorpej 		"\\_SB_",	/* system bus namespace */
    338  1.1  thorpej 		"\\_SI_",	/* system idicator namespace */
    339  1.1  thorpej 		"\\_TZ_",	/* ACPI 1.0 thermal zone namespace */
    340  1.1  thorpej 		NULL,
    341  1.1  thorpej 	};
    342  1.1  thorpej 	struct acpi_attach_args aa;
    343  1.1  thorpej 	struct acpi_make_devnode_state state;
    344  1.1  thorpej 	struct acpi_scope *as;
    345  1.1  thorpej 	struct acpi_devnode *ad;
    346  1.1  thorpej 	ACPI_HANDLE parent;
    347  1.1  thorpej 	int i;
    348  1.1  thorpej 
    349  1.1  thorpej 	TAILQ_INIT(&sc->sc_scopes);
    350  1.1  thorpej 
    351  1.1  thorpej 	state.softc = sc;
    352  1.1  thorpej 
    353  1.1  thorpej 	/*
    354  1.1  thorpej 	 * Scan the namespace and build our tree.
    355  1.1  thorpej 	 */
    356  1.1  thorpej 	for (i = 0; scopes[i] != NULL; i++) {
    357  1.1  thorpej 		as = malloc(sizeof(*as), M_DEVBUF, M_WAITOK);
    358  1.1  thorpej 		as->as_name = scopes[i];
    359  1.1  thorpej 		TAILQ_INIT(&as->as_devnodes);
    360  1.1  thorpej 
    361  1.1  thorpej 		TAILQ_INSERT_TAIL(&sc->sc_scopes, as, as_list);
    362  1.1  thorpej 
    363  1.1  thorpej 		state.scope = as;
    364  1.1  thorpej 
    365  1.1  thorpej 		if (AcpiGetHandle(ACPI_ROOT_OBJECT, (char *) scopes[i],
    366  1.1  thorpej 		    &parent) == AE_OK) {
    367  1.1  thorpej 			AcpiWalkNamespace(ACPI_TYPE_ANY, parent, 100,
    368  1.1  thorpej 			    acpi_make_devnode, &state, NULL);
    369  1.1  thorpej 		}
    370  1.1  thorpej 
    371  1.1  thorpej 		/* Now, for this namespace, try and attach the devices. */
    372  1.1  thorpej 		TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) {
    373  1.1  thorpej 			aa.aa_node = ad;
    374  1.1  thorpej 			aa.aa_iot = sc->sc_iot;
    375  1.1  thorpej 			aa.aa_memt = sc->sc_memt;
    376  1.1  thorpej 			aa.aa_pc = sc->sc_pc;
    377  1.1  thorpej 			aa.aa_pciflags = sc->sc_pciflags;
    378  1.1  thorpej 
    379  1.1  thorpej 			/*
    380  1.1  thorpej 			 * XXX We only attach devices which are:
    381  1.1  thorpej 			 *
    382  1.1  thorpej 			 *	- present
    383  1.1  thorpej 			 *	- enabled
    384  1.1  thorpej 			 *	- to be shown
    385  1.1  thorpej 			 *	- functioning properly
    386  1.1  thorpej 			 *
    387  1.1  thorpej 			 * However, if enabled, it's decoding resources,
    388  1.1  thorpej 			 * so we should claim them, if possible.  Requires
    389  1.1  thorpej 			 * changes to bus_space(9).
    390  1.1  thorpej 			 */
    391  1.1  thorpej 			if ((ad->ad_devinfo.CurrentStatus &
    392  1.1  thorpej 			     (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
    393  1.1  thorpej 			      ACPI_STA_DEV_SHOW|ACPI_STA_DEV_OK)) !=
    394  1.1  thorpej 			    (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
    395  1.1  thorpej 			     ACPI_STA_DEV_SHOW|ACPI_STA_DEV_OK))
    396  1.1  thorpej 				continue;
    397  1.1  thorpej 
    398  1.1  thorpej 			/*
    399  1.1  thorpej 			 * XXX Same problem as above...
    400  1.1  thorpej 			 */
    401  1.1  thorpej 			if ((ad->ad_devinfo.Valid & ACPI_VALID_HID) == 0)
    402  1.1  thorpej 				continue;
    403  1.1  thorpej 
    404  1.1  thorpej 			ad->ad_device = config_found(&sc->sc_dev,
    405  1.1  thorpej 			    &aa, acpi_print);
    406  1.1  thorpej 		}
    407  1.1  thorpej 	}
    408  1.1  thorpej }
    409  1.1  thorpej 
    410  1.1  thorpej /*
    411  1.1  thorpej  * acpi_make_devnode:
    412  1.1  thorpej  *
    413  1.1  thorpej  *	Make an ACPI devnode.
    414  1.1  thorpej  */
    415  1.1  thorpej ACPI_STATUS
    416  1.1  thorpej acpi_make_devnode(ACPI_HANDLE handle, UINT32 level, void *context,
    417  1.1  thorpej     void **status)
    418  1.1  thorpej {
    419  1.1  thorpej 	struct acpi_make_devnode_state *state = context;
    420  1.4  thorpej #ifdef ACPI_DEBUG
    421  1.1  thorpej 	struct acpi_softc *sc = state->softc;
    422  1.4  thorpej #endif
    423  1.1  thorpej 	struct acpi_scope *as = state->scope;
    424  1.1  thorpej 	struct acpi_devnode *ad;
    425  1.1  thorpej 	ACPI_OBJECT_TYPE type;
    426  1.1  thorpej 	ACPI_STATUS rv;
    427  1.1  thorpej 
    428  1.1  thorpej 	if (AcpiGetType(handle, &type) == AE_OK) {
    429  1.1  thorpej 		switch (type) {
    430  1.1  thorpej 		case ACPI_TYPE_DEVICE:
    431  1.1  thorpej 		case ACPI_TYPE_PROCESSOR:
    432  1.1  thorpej 		case ACPI_TYPE_THERMAL:
    433  1.1  thorpej 		case ACPI_TYPE_POWER:
    434  1.6  tsutsui 			ad = malloc(sizeof(*ad), M_DEVBUF, M_NOWAIT|M_ZERO);
    435  1.1  thorpej 			if (ad == NULL)
    436  1.1  thorpej 				return (AE_NO_MEMORY);
    437  1.1  thorpej 
    438  1.1  thorpej 			ad->ad_handle = handle;
    439  1.1  thorpej 			ad->ad_level = level;
    440  1.1  thorpej 			ad->ad_scope = as;
    441  1.1  thorpej 			ad->ad_type = type;
    442  1.1  thorpej 
    443  1.1  thorpej 			TAILQ_INSERT_TAIL(&as->as_devnodes, ad, ad_list);
    444  1.1  thorpej 
    445  1.1  thorpej 			rv = AcpiGetObjectInfo(handle, &ad->ad_devinfo);
    446  1.1  thorpej 			if (rv != AE_OK)
    447  1.1  thorpej 				goto out;
    448  1.1  thorpej 
    449  1.1  thorpej 			if ((ad->ad_devinfo.Valid & ACPI_VALID_HID) == 0)
    450  1.1  thorpej 				goto out;
    451  1.1  thorpej 
    452  1.1  thorpej #ifdef ACPI_DEBUG
    453  1.1  thorpej 			printf("%s: HID %s found in scope %s level %d\n",
    454  1.1  thorpej 			    sc->sc_dev.dv_xname, ad->ad_devinfo.HardwareId,
    455  1.1  thorpej 			    as->as_name, ad->ad_level);
    456  1.1  thorpej 			if (ad->ad_devinfo.Valid & ACPI_VALID_UID)
    457  1.1  thorpej 				printf("       UID %s\n",
    458  1.1  thorpej 				    ad->ad_devinfo.UniqueId);
    459  1.1  thorpej 			if (ad->ad_devinfo.Valid & ACPI_VALID_ADR)
    460  1.1  thorpej 				printf("       ADR 0x%016qx\n",
    461  1.1  thorpej 				    ad->ad_devinfo.Address);
    462  1.1  thorpej 			if (ad->ad_devinfo.Valid & ACPI_VALID_STA)
    463  1.1  thorpej 				printf("       STA 0x%08x\n",
    464  1.1  thorpej 				    ad->ad_devinfo.CurrentStatus);
    465  1.1  thorpej #endif
    466  1.1  thorpej 		}
    467  1.1  thorpej 	}
    468  1.1  thorpej  out:
    469  1.1  thorpej 	return (AE_OK);
    470  1.1  thorpej }
    471  1.1  thorpej 
    472  1.1  thorpej /*
    473  1.1  thorpej  * acpi_print:
    474  1.1  thorpej  *
    475  1.1  thorpej  *	Autoconfiguration print routine.
    476  1.1  thorpej  */
    477  1.1  thorpej int
    478  1.1  thorpej acpi_print(void *aux, const char *pnp)
    479  1.1  thorpej {
    480  1.1  thorpej 	struct acpi_attach_args *aa = aux;
    481  1.4  thorpej 	char *str;
    482  1.1  thorpej 
    483  1.4  thorpej 	if (pnp) {
    484  1.4  thorpej 		printf("%s ", aa->aa_node->ad_devinfo.HardwareId);
    485  1.4  thorpej 		if (acpi_eval_string(aa->aa_node->ad_handle,
    486  1.4  thorpej 		    "_STR", &str) == AE_OK) {
    487  1.4  thorpej 			printf("[%s] ", str);
    488  1.4  thorpej 			AcpiOsFree(str);
    489  1.4  thorpej 		}
    490  1.4  thorpej 		printf("at %s", pnp);
    491  1.4  thorpej 	}
    492  1.1  thorpej 
    493  1.1  thorpej 	return (UNCONF);
    494  1.1  thorpej }
    495  1.1  thorpej 
    496  1.1  thorpej /*****************************************************************************
    497  1.1  thorpej  * ACPI fixed-hardware feature handlers
    498  1.1  thorpej  *****************************************************************************/
    499  1.1  thorpej 
    500  1.1  thorpej UINT32		acpi_fixed_power_button_handler(void *);
    501  1.1  thorpej UINT32		acpi_fixed_sleep_button_handler(void *);
    502  1.1  thorpej 
    503  1.1  thorpej /*
    504  1.1  thorpej  * acpi_enable_fixed_events:
    505  1.1  thorpej  *
    506  1.1  thorpej  *	Enable any fixed-hardware feature handlers.
    507  1.1  thorpej  */
    508  1.1  thorpej void
    509  1.1  thorpej acpi_enable_fixed_events(struct acpi_softc *sc)
    510  1.1  thorpej {
    511  1.1  thorpej 	static int beenhere;
    512  1.1  thorpej 	ACPI_STATUS rv;
    513  1.1  thorpej 
    514  1.1  thorpej 	/*
    515  1.1  thorpej 	 * Check for fixed-hardware buttons.
    516  1.1  thorpej 	 */
    517  1.1  thorpej 
    518  1.1  thorpej 	if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->PwrButton == 0) {
    519  1.1  thorpej 		if (beenhere == 0)
    520  1.1  thorpej 			printf("%s: fixed-feature power button present\n",
    521  1.1  thorpej 			    sc->sc_dev.dv_xname);
    522  1.1  thorpej 		rv = AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON,
    523  1.1  thorpej 		    acpi_fixed_power_button_handler, sc);
    524  1.1  thorpej 		if (rv != AE_OK)
    525  1.1  thorpej 			printf("%s: unable to install handler for fixed "
    526  1.1  thorpej 			    "power button: %d\n", sc->sc_dev.dv_xname, rv);
    527  1.1  thorpej 	}
    528  1.1  thorpej 
    529  1.1  thorpej 	if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->SleepButton == 0) {
    530  1.1  thorpej 		if (beenhere == 0)
    531  1.1  thorpej 			printf("%s: fixed-feature sleep button present\n",
    532  1.1  thorpej 			    sc->sc_dev.dv_xname);
    533  1.1  thorpej 		rv = AcpiInstallFixedEventHandler(ACPI_EVENT_SLEEP_BUTTON,
    534  1.1  thorpej 		    acpi_fixed_sleep_button_handler, sc);
    535  1.1  thorpej 		if (rv != AE_OK)
    536  1.1  thorpej 			printf("%s: unable to install handler for fixed "
    537  1.1  thorpej 			    "power button: %d\n", sc->sc_dev.dv_xname, rv);
    538  1.1  thorpej 	}
    539  1.1  thorpej 
    540  1.1  thorpej 	beenhere = 1;
    541  1.1  thorpej }
    542  1.1  thorpej 
    543  1.1  thorpej /*
    544  1.1  thorpej  * acpi_fixed_power_button_handler:
    545  1.1  thorpej  *
    546  1.1  thorpej  *	Fixed event handler for the power button.
    547  1.1  thorpej  */
    548  1.1  thorpej UINT32
    549  1.1  thorpej acpi_fixed_power_button_handler(void *context)
    550  1.1  thorpej {
    551  1.1  thorpej 	struct acpi_softc *sc = context;
    552  1.1  thorpej 
    553  1.1  thorpej 	/* XXX XXX XXX */
    554  1.1  thorpej 
    555  1.1  thorpej 	printf("%s: fixed power button pressed\n", sc->sc_dev.dv_xname);
    556  1.1  thorpej 
    557  1.1  thorpej 	return (INTERRUPT_HANDLED);
    558  1.1  thorpej }
    559  1.1  thorpej 
    560  1.1  thorpej /*
    561  1.1  thorpej  * acpi_fixed_sleep_button_handler:
    562  1.1  thorpej  *
    563  1.1  thorpej  *	Fixed event handler for the sleep button.
    564  1.1  thorpej  */
    565  1.1  thorpej UINT32
    566  1.1  thorpej acpi_fixed_sleep_button_handler(void *context)
    567  1.1  thorpej {
    568  1.1  thorpej 	struct acpi_softc *sc = context;
    569  1.1  thorpej 
    570  1.1  thorpej 	/* XXX XXX XXX */
    571  1.1  thorpej 
    572  1.1  thorpej 	printf("%s: fixed sleep button pressed\n", sc->sc_dev.dv_xname);
    573  1.1  thorpej 
    574  1.1  thorpej 	return (INTERRUPT_HANDLED);
    575  1.1  thorpej }
    576  1.1  thorpej 
    577  1.1  thorpej /*****************************************************************************
    578  1.1  thorpej  * ACPI utility routines.
    579  1.1  thorpej  *****************************************************************************/
    580  1.1  thorpej 
    581  1.2  thorpej /*
    582  1.2  thorpej  * acpi_eval_integer:
    583  1.2  thorpej  *
    584  1.2  thorpej  *	Evaluate an integer object.
    585  1.2  thorpej  */
    586  1.1  thorpej ACPI_STATUS
    587  1.1  thorpej acpi_eval_integer(ACPI_HANDLE handle, char *path, int *valp)
    588  1.1  thorpej {
    589  1.1  thorpej 	ACPI_STATUS rv;
    590  1.1  thorpej 	ACPI_BUFFER buf;
    591  1.1  thorpej 	ACPI_OBJECT param;
    592  1.1  thorpej 
    593  1.1  thorpej 	if (handle == NULL)
    594  1.1  thorpej 		handle = ACPI_ROOT_OBJECT;
    595  1.1  thorpej 
    596  1.1  thorpej 	buf.Pointer = &param;
    597  1.1  thorpej 	buf.Length = sizeof(param);
    598  1.1  thorpej 
    599  1.1  thorpej 	rv = AcpiEvaluateObject(handle, path, NULL, &buf);
    600  1.1  thorpej 	if (rv == AE_OK) {
    601  1.1  thorpej 		if (param.Type == ACPI_TYPE_INTEGER)
    602  1.1  thorpej 			*valp = param.Integer.Value;
    603  1.1  thorpej 		else
    604  1.1  thorpej 			rv = AE_TYPE;
    605  1.1  thorpej 	}
    606  1.1  thorpej 
    607  1.4  thorpej 	return (rv);
    608  1.4  thorpej }
    609  1.4  thorpej 
    610  1.4  thorpej /*
    611  1.4  thorpej  * acpi_eval_string:
    612  1.4  thorpej  *
    613  1.4  thorpej  *	Evaluage a (Unicode) string object.
    614  1.4  thorpej  */
    615  1.4  thorpej ACPI_STATUS
    616  1.4  thorpej acpi_eval_string(ACPI_HANDLE handle, char *path, char **stringp)
    617  1.4  thorpej {
    618  1.4  thorpej 	ACPI_STATUS rv;
    619  1.4  thorpej 	ACPI_BUFFER buf;
    620  1.4  thorpej 	ACPI_OBJECT param;
    621  1.4  thorpej 
    622  1.4  thorpej 	if (handle == NULL)
    623  1.4  thorpej 		handle = ACPI_ROOT_OBJECT;
    624  1.4  thorpej 
    625  1.4  thorpej 	buf.Pointer = NULL;
    626  1.4  thorpej 	buf.Length = 0;
    627  1.4  thorpej 
    628  1.4  thorpej 	rv = AcpiEvaluateObject(handle, path, NULL, &buf);
    629  1.4  thorpej 	if (rv != AE_BUFFER_OVERFLOW)
    630  1.4  thorpej 		return (rv);
    631  1.4  thorpej 
    632  1.4  thorpej 	buf.Pointer = AcpiOsAllocate(buf.Length);
    633  1.4  thorpej 	if (buf.Pointer == NULL)
    634  1.4  thorpej 		return (AE_NO_MEMORY);
    635  1.4  thorpej 
    636  1.4  thorpej 	rv = AcpiEvaluateObject(handle, path, NULL, &buf);
    637  1.4  thorpej 	if (rv == AE_OK) {
    638  1.4  thorpej 		if (param.Type == ACPI_TYPE_STRING) {
    639  1.4  thorpej 			*stringp = buf.Pointer;
    640  1.4  thorpej 			return (AE_OK);
    641  1.4  thorpej 		}
    642  1.4  thorpej 		rv = AE_TYPE;
    643  1.4  thorpej 	}
    644  1.4  thorpej 
    645  1.4  thorpej 	AcpiOsFree(buf.Pointer);
    646  1.1  thorpej 	return (rv);
    647  1.2  thorpej }
    648  1.2  thorpej 
    649  1.2  thorpej /*
    650  1.2  thorpej  * acpi_get:
    651  1.2  thorpej  *
    652  1.2  thorpej  *	Fetch data info the specified (empty) ACPI buffer.
    653  1.2  thorpej  */
    654  1.2  thorpej ACPI_STATUS
    655  1.2  thorpej acpi_get(ACPI_HANDLE handle, ACPI_BUFFER *buf,
    656  1.2  thorpej     ACPI_STATUS (*getit)(ACPI_HANDLE, ACPI_BUFFER *))
    657  1.2  thorpej {
    658  1.2  thorpej 	ACPI_STATUS rv;
    659  1.2  thorpej 
    660  1.2  thorpej 	buf->Pointer = NULL;
    661  1.2  thorpej 	buf->Length = 0;
    662  1.2  thorpej 
    663  1.2  thorpej 	rv = (*getit)(handle, buf);
    664  1.2  thorpej 	if (rv != AE_BUFFER_OVERFLOW)
    665  1.2  thorpej 		return (rv);
    666  1.2  thorpej 
    667  1.2  thorpej 	buf->Pointer = AcpiOsCallocate(buf->Length);
    668  1.2  thorpej 	if (buf->Pointer == NULL)
    669  1.2  thorpej 		return (AE_NO_MEMORY);
    670  1.2  thorpej 
    671  1.2  thorpej 	return ((*getit)(handle, buf));
    672  1.1  thorpej }
    673