Home | History | Annotate | Line # | Download | only in acpi
acpi_wakedev.c revision 1.20.4.2
      1  1.20.4.1    bouyer /* $NetBSD: acpi_wakedev.c,v 1.20.4.2 2011/03/05 15:10:16 bouyer Exp $ */
      2       1.1  jmcneill 
      3       1.1  jmcneill /*-
      4  1.20.4.2    bouyer  * Copyright (c) 2009, 2010, 2011 Jared D. McNeill <jmcneill (at) invisible.ca>
      5       1.1  jmcneill  * All rights reserved.
      6       1.1  jmcneill  *
      7       1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8       1.1  jmcneill  * modification, are permitted provided that the following conditions
      9       1.1  jmcneill  * are met:
     10       1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11       1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12       1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15       1.1  jmcneill  *
     16       1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17       1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18       1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19       1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20       1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21       1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22       1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23       1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24       1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25       1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     27       1.1  jmcneill  */
     28       1.1  jmcneill 
     29       1.1  jmcneill #include <sys/cdefs.h>
     30  1.20.4.1    bouyer __KERNEL_RCSID(0, "$NetBSD: acpi_wakedev.c,v 1.20.4.2 2011/03/05 15:10:16 bouyer Exp $");
     31       1.1  jmcneill 
     32       1.1  jmcneill #include <sys/param.h>
     33       1.3    jruoho #include <sys/device.h>
     34  1.20.4.2    bouyer #include <sys/kmem.h>
     35       1.1  jmcneill #include <sys/sysctl.h>
     36       1.1  jmcneill 
     37       1.3    jruoho #include <dev/acpi/acpireg.h>
     38       1.1  jmcneill #include <dev/acpi/acpivar.h>
     39      1.19    jruoho #include <dev/acpi/acpi_pci.h>
     40      1.13    jruoho #include <dev/acpi/acpi_power.h>
     41       1.1  jmcneill #include <dev/acpi/acpi_wakedev.h>
     42       1.1  jmcneill 
     43      1.13    jruoho #define _COMPONENT		ACPI_BUS_COMPONENT
     44      1.13    jruoho ACPI_MODULE_NAME		("acpi_wakedev")
     45       1.5    jruoho 
     46       1.1  jmcneill static const char * const acpi_wakedev_default[] = {
     47       1.1  jmcneill 	"PNP0C0C",	/* power button */
     48       1.1  jmcneill 	"PNP0C0E",	/* sleep button */
     49       1.1  jmcneill 	"PNP0C0D",	/* lid switch */
     50       1.1  jmcneill 	"PNP03??",	/* PC KBD port */
     51       1.1  jmcneill 	NULL,
     52       1.1  jmcneill };
     53       1.1  jmcneill 
     54  1.20.4.2    bouyer static int32_t	acpi_wakedev_acpinode = CTL_EOL;
     55  1.20.4.2    bouyer static int32_t	acpi_wakedev_wakenode = CTL_EOL;
     56       1.9    jruoho 
     57  1.20.4.2    bouyer static void	acpi_wakedev_power_add(struct acpi_devnode *, ACPI_OBJECT *);
     58  1.20.4.2    bouyer static void	acpi_wakedev_power_set(struct acpi_devnode *, bool);
     59  1.20.4.2    bouyer static void	acpi_wakedev_method(struct acpi_devnode *, int);
     60       1.5    jruoho 
     61  1.20.4.2    bouyer void
     62  1.20.4.2    bouyer acpi_wakedev_init(struct acpi_devnode *ad)
     63       1.1  jmcneill {
     64  1.20.4.2    bouyer 	ACPI_OBJECT *elm, *obj;
     65  1.20.4.2    bouyer 	ACPI_INTEGER val;
     66  1.20.4.2    bouyer 	ACPI_HANDLE hdl;
     67  1.20.4.2    bouyer 	ACPI_BUFFER buf;
     68  1.20.4.2    bouyer 	ACPI_STATUS rv;
     69       1.1  jmcneill 
     70  1.20.4.2    bouyer 	KASSERT(ad != NULL && ad->ad_wakedev == NULL);
     71  1.20.4.2    bouyer 	KASSERT(ad->ad_devinfo->Type == ACPI_TYPE_DEVICE);
     72       1.9    jruoho 
     73  1.20.4.2    bouyer 	rv = acpi_eval_struct(ad->ad_handle, "_PRW", &buf);
     74       1.9    jruoho 
     75  1.20.4.2    bouyer 	if (ACPI_FAILURE(rv))
     76  1.20.4.2    bouyer 		goto out;
     77       1.9    jruoho 
     78  1.20.4.2    bouyer 	obj = buf.Pointer;
     79  1.20.4.2    bouyer 
     80  1.20.4.2    bouyer 	if (obj->Type != ACPI_TYPE_PACKAGE) {
     81  1.20.4.2    bouyer 		rv = AE_TYPE;
     82  1.20.4.2    bouyer 		goto out;
     83  1.20.4.2    bouyer 	}
     84  1.20.4.2    bouyer 
     85  1.20.4.2    bouyer 	if (obj->Package.Count < 2 || obj->Package.Count > UINT32_MAX) {
     86  1.20.4.2    bouyer 		rv = AE_LIMIT;
     87  1.20.4.2    bouyer 		goto out;
     88  1.20.4.2    bouyer 	}
     89  1.20.4.2    bouyer 
     90  1.20.4.2    bouyer 	/*
     91  1.20.4.2    bouyer 	 * As noted in ACPI 3.0 (section 7.2.10), the _PRW object is
     92  1.20.4.2    bouyer 	 * a package in which the first element is either an integer
     93  1.20.4.2    bouyer 	 * or again a package. In the latter case the package inside
     94  1.20.4.2    bouyer 	 * the package element has two elements, a reference handle
     95  1.20.4.2    bouyer 	 * and the GPE number.
     96  1.20.4.2    bouyer 	 */
     97  1.20.4.2    bouyer 	elm = &obj->Package.Elements[0];
     98  1.20.4.2    bouyer 
     99  1.20.4.2    bouyer 	switch (elm->Type) {
    100  1.20.4.2    bouyer 
    101  1.20.4.2    bouyer 	case ACPI_TYPE_INTEGER:
    102  1.20.4.2    bouyer 		val = elm->Integer.Value;
    103  1.20.4.2    bouyer 		hdl = NULL;
    104  1.20.4.2    bouyer 		break;
    105  1.20.4.2    bouyer 
    106  1.20.4.2    bouyer 	case ACPI_TYPE_PACKAGE:
    107  1.20.4.2    bouyer 
    108  1.20.4.2    bouyer 		if (elm->Package.Count < 2) {
    109  1.20.4.2    bouyer 			rv = AE_LIMIT;
    110  1.20.4.2    bouyer 			goto out;
    111  1.20.4.2    bouyer 		}
    112  1.20.4.2    bouyer 
    113  1.20.4.2    bouyer 		rv = AE_TYPE;
    114  1.20.4.2    bouyer 
    115  1.20.4.2    bouyer 		if (elm->Package.Elements[0].Type != ACPI_TYPE_LOCAL_REFERENCE)
    116  1.20.4.2    bouyer 			goto out;
    117  1.20.4.2    bouyer 
    118  1.20.4.2    bouyer 		if (elm->Package.Elements[1].Type != ACPI_TYPE_INTEGER)
    119  1.20.4.2    bouyer 			goto out;
    120  1.20.4.2    bouyer 
    121  1.20.4.2    bouyer 		hdl = elm->Package.Elements[0].Reference.Handle;
    122  1.20.4.2    bouyer 		val = elm->Package.Elements[1].Integer.Value;
    123  1.20.4.2    bouyer 		break;
    124  1.20.4.2    bouyer 
    125  1.20.4.2    bouyer 	default:
    126  1.20.4.2    bouyer 		rv = AE_TYPE;
    127  1.20.4.2    bouyer 		goto out;
    128  1.20.4.2    bouyer 	}
    129  1.20.4.2    bouyer 
    130  1.20.4.2    bouyer 	ad->ad_wakedev = kmem_zalloc(sizeof(*ad->ad_wakedev), KM_NOSLEEP);
    131  1.20.4.2    bouyer 
    132  1.20.4.2    bouyer 	if (ad->ad_wakedev == NULL)
    133      1.18    gsutre 		return;
    134      1.18    gsutre 
    135  1.20.4.2    bouyer 	ad->ad_wakedev->aw_handle = hdl;
    136  1.20.4.2    bouyer 	ad->ad_wakedev->aw_number = val;
    137       1.9    jruoho 
    138  1.20.4.2    bouyer  	/*
    139  1.20.4.2    bouyer 	 * The second element in _PRW is an integer
    140  1.20.4.2    bouyer 	 * that contains the lowest sleep state that
    141  1.20.4.2    bouyer 	 * can be entered while still providing wakeup.
    142  1.20.4.2    bouyer 	 */
    143  1.20.4.2    bouyer 	elm = &obj->Package.Elements[1];
    144       1.9    jruoho 
    145  1.20.4.2    bouyer 	if (elm->Type == ACPI_TYPE_INTEGER)
    146  1.20.4.2    bouyer 		ad->ad_wakedev->aw_state = elm->Integer.Value;
    147  1.20.4.2    bouyer 
    148  1.20.4.2    bouyer 	/*
    149  1.20.4.2    bouyer 	 * The rest of the elements are reference
    150  1.20.4.2    bouyer 	 * handles to power resources. Store these.
    151  1.20.4.2    bouyer 	 */
    152  1.20.4.2    bouyer 	acpi_wakedev_power_add(ad, obj);
    153  1.20.4.2    bouyer 
    154  1.20.4.2    bouyer 	/*
    155  1.20.4.2    bouyer 	 * Last but not least, mark the GPE for wake.
    156  1.20.4.2    bouyer 	 */
    157  1.20.4.2    bouyer 	rv = AcpiSetupGpeForWake(ad->ad_handle, hdl, val);
    158  1.20.4.2    bouyer 
    159  1.20.4.2    bouyer out:
    160  1.20.4.2    bouyer 	if (buf.Pointer != NULL)
    161  1.20.4.2    bouyer 		ACPI_FREE(buf.Pointer);
    162  1.20.4.2    bouyer 
    163  1.20.4.2    bouyer 	if (ACPI_FAILURE(rv) && rv != AE_NOT_FOUND)
    164  1.20.4.2    bouyer 		aprint_error_dev(ad->ad_root, "failed to evaluate _PRW "
    165  1.20.4.2    bouyer 		    "for %s: %s\n", ad->ad_name, AcpiFormatException(rv));
    166  1.20.4.2    bouyer }
    167  1.20.4.2    bouyer 
    168  1.20.4.2    bouyer static void
    169  1.20.4.2    bouyer acpi_wakedev_power_add(struct acpi_devnode *ad, ACPI_OBJECT *obj)
    170  1.20.4.2    bouyer {
    171  1.20.4.2    bouyer 	struct acpi_wakedev *aw = ad->ad_wakedev;
    172  1.20.4.2    bouyer 	uint32_t i, j, n;
    173  1.20.4.2    bouyer 	ACPI_OBJECT *elm;
    174  1.20.4.2    bouyer 	ACPI_HANDLE hdl;
    175  1.20.4.2    bouyer 	ACPI_STATUS rv;
    176  1.20.4.2    bouyer 
    177  1.20.4.2    bouyer 	for (i = 0; i < __arraycount(aw->aw_power); i++)
    178  1.20.4.2    bouyer 		aw->aw_power[i] = NULL;
    179  1.20.4.2    bouyer 
    180  1.20.4.2    bouyer 	n = obj->Package.Count;
    181  1.20.4.2    bouyer 
    182  1.20.4.2    bouyer 	if (n < 3 || n - 2 > __arraycount(aw->aw_power))
    183      1.18    gsutre 		return;
    184       1.9    jruoho 
    185  1.20.4.2    bouyer 	for (i = 2, j = 0; i < n; i++, j++) {
    186  1.20.4.2    bouyer 
    187  1.20.4.2    bouyer 		elm = &obj->Package.Elements[i];
    188  1.20.4.2    bouyer 		rv = acpi_eval_reference_handle(elm, &hdl);
    189  1.20.4.2    bouyer 
    190  1.20.4.2    bouyer 		if (ACPI_FAILURE(rv))
    191  1.20.4.2    bouyer 			continue;
    192  1.20.4.2    bouyer 
    193  1.20.4.2    bouyer 		ad->ad_wakedev->aw_power[j] = hdl;
    194  1.20.4.2    bouyer 	}
    195  1.20.4.2    bouyer }
    196  1.20.4.2    bouyer 
    197  1.20.4.2    bouyer static void
    198  1.20.4.2    bouyer acpi_wakedev_power_set(struct acpi_devnode *ad, bool enable)
    199  1.20.4.2    bouyer {
    200  1.20.4.2    bouyer 	struct acpi_wakedev *aw = ad->ad_wakedev;
    201  1.20.4.2    bouyer 	uint8_t i;
    202  1.20.4.2    bouyer 
    203  1.20.4.2    bouyer 	for (i = 0; i < __arraycount(aw->aw_power); i++) {
    204  1.20.4.2    bouyer 
    205  1.20.4.2    bouyer 		if (aw->aw_power[i] == NULL)
    206  1.20.4.2    bouyer 			continue;
    207  1.20.4.2    bouyer 
    208  1.20.4.2    bouyer 		(void)acpi_power_res(aw->aw_power[i], ad->ad_handle, enable);
    209  1.20.4.2    bouyer 	}
    210       1.1  jmcneill }
    211       1.1  jmcneill 
    212       1.7    jruoho void
    213       1.7    jruoho acpi_wakedev_add(struct acpi_devnode *ad)
    214       1.1  jmcneill {
    215  1.20.4.2    bouyer 	struct acpi_wakedev *aw;
    216      1.19    jruoho 	const char *str = NULL;
    217      1.19    jruoho 	device_t dev;
    218       1.1  jmcneill 	int err;
    219       1.1  jmcneill 
    220  1.20.4.2    bouyer 	KASSERT(ad != NULL && ad->ad_wakedev != NULL);
    221       1.7    jruoho 	KASSERT((ad->ad_flags & ACPI_DEVICE_WAKEUP) != 0);
    222       1.1  jmcneill 
    223  1.20.4.2    bouyer 	aw = ad->ad_wakedev;
    224  1.20.4.2    bouyer 	aw->aw_enable = false;
    225       1.1  jmcneill 
    226       1.1  jmcneill 	if (acpi_match_hid(ad->ad_devinfo, acpi_wakedev_default))
    227  1.20.4.2    bouyer 		aw->aw_enable = true;
    228       1.1  jmcneill 
    229      1.18    gsutre 	if (acpi_wakedev_acpinode == CTL_EOL ||
    230      1.18    gsutre 	    acpi_wakedev_wakenode == CTL_EOL)
    231       1.7    jruoho 		return;
    232       1.1  jmcneill 
    233      1.19    jruoho 	if (ad->ad_device != NULL)
    234      1.19    jruoho 		str = device_xname(ad->ad_device);
    235      1.19    jruoho 	else {
    236      1.19    jruoho 		dev = acpi_pcidev_find_dev(ad);
    237      1.19    jruoho 
    238      1.19    jruoho 		if (dev != NULL)
    239      1.19    jruoho 			str = device_xname(dev);
    240      1.19    jruoho 	}
    241      1.19    jruoho 
    242      1.19    jruoho 	if (str == NULL)
    243      1.19    jruoho 		return;
    244      1.19    jruoho 
    245      1.18    gsutre 	err = sysctl_createv(NULL, 0, NULL, NULL,
    246      1.19    jruoho 	    CTLFLAG_READWRITE, CTLTYPE_BOOL, str,
    247  1.20.4.2    bouyer 	    NULL, NULL, 0, &aw->aw_enable, 0, CTL_HW,
    248      1.19    jruoho 	    acpi_wakedev_acpinode, acpi_wakedev_wakenode,
    249       1.9    jruoho 	    CTL_CREATE, CTL_EOL);
    250       1.6    jruoho 
    251       1.7    jruoho 	if (err != 0)
    252      1.12    jruoho 		aprint_error_dev(ad->ad_root, "sysctl_createv"
    253      1.20    jruoho 		    "(hw.acpi.wake.%s) failed (err %d)\n", str, err);
    254       1.1  jmcneill }
    255       1.1  jmcneill 
    256  1.20.4.2    bouyer SYSCTL_SETUP(sysctl_acpi_wakedev_setup, "sysctl hw.acpi.wake subtree setup")
    257  1.20.4.2    bouyer {
    258  1.20.4.2    bouyer 	const struct sysctlnode *rnode;
    259  1.20.4.2    bouyer 	int err;
    260  1.20.4.2    bouyer 
    261  1.20.4.2    bouyer 	err = sysctl_createv(NULL, 0, NULL, &rnode,
    262  1.20.4.2    bouyer 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw",
    263  1.20.4.2    bouyer 	    NULL, NULL, 0, NULL, 0,
    264  1.20.4.2    bouyer 	    CTL_HW, CTL_EOL);
    265  1.20.4.2    bouyer 
    266  1.20.4.2    bouyer 	if (err != 0)
    267  1.20.4.2    bouyer 		return;
    268  1.20.4.2    bouyer 
    269  1.20.4.2    bouyer 	err = sysctl_createv(NULL, 0, &rnode, &rnode,
    270  1.20.4.2    bouyer 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "acpi",
    271  1.20.4.2    bouyer 	    NULL, NULL, 0, NULL, 0,
    272  1.20.4.2    bouyer 	    CTL_CREATE, CTL_EOL);
    273  1.20.4.2    bouyer 
    274  1.20.4.2    bouyer 	if (err != 0)
    275  1.20.4.2    bouyer 		return;
    276  1.20.4.2    bouyer 
    277  1.20.4.2    bouyer 	acpi_wakedev_acpinode = rnode->sysctl_num;
    278  1.20.4.2    bouyer 
    279  1.20.4.2    bouyer 	err = sysctl_createv(NULL, 0, &rnode, &rnode,
    280  1.20.4.2    bouyer 	    CTLFLAG_PERMANENT, CTLTYPE_NODE,
    281  1.20.4.2    bouyer 	    "wake", SYSCTL_DESCR("ACPI device wake-up"),
    282  1.20.4.2    bouyer 	    NULL, 0, NULL, 0,
    283  1.20.4.2    bouyer 	    CTL_CREATE, CTL_EOL);
    284  1.20.4.2    bouyer 
    285  1.20.4.2    bouyer 	if (err != 0)
    286  1.20.4.2    bouyer 		return;
    287  1.20.4.2    bouyer 
    288  1.20.4.2    bouyer 	acpi_wakedev_wakenode = rnode->sysctl_num;
    289  1.20.4.2    bouyer }
    290  1.20.4.2    bouyer 
    291       1.1  jmcneill void
    292       1.4    jruoho acpi_wakedev_commit(struct acpi_softc *sc, int state)
    293       1.1  jmcneill {
    294       1.7    jruoho 	struct acpi_devnode *ad;
    295  1.20.4.2    bouyer 	ACPI_INTEGER val;
    296  1.20.4.2    bouyer 	ACPI_HANDLE hdl;
    297       1.1  jmcneill 
    298       1.4    jruoho 	/*
    299      1.13    jruoho 	 * To prepare a device for wakeup:
    300       1.4    jruoho 	 *
    301  1.20.4.2    bouyer 	 *  1.	Set the wake GPE.
    302       1.4    jruoho 	 *
    303  1.20.4.2    bouyer 	 *  2.	Turn on power resources.
    304       1.4    jruoho 	 *
    305  1.20.4.2    bouyer 	 *  3.	Execute _DSW or _PSW method.
    306       1.4    jruoho 	 */
    307      1.12    jruoho 	SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
    308       1.7    jruoho 
    309  1.20.4.2    bouyer 		if (ad->ad_wakedev == NULL)
    310  1.20.4.2    bouyer 			continue;
    311  1.20.4.2    bouyer 
    312  1.20.4.2    bouyer 		if (state > ad->ad_wakedev->aw_state)
    313  1.20.4.2    bouyer 			continue;
    314  1.20.4.2    bouyer 
    315  1.20.4.2    bouyer 		hdl = ad->ad_wakedev->aw_handle;
    316  1.20.4.2    bouyer 		val = ad->ad_wakedev->aw_number;
    317  1.20.4.2    bouyer 
    318  1.20.4.2    bouyer 		if (state == ACPI_STATE_S0) {
    319  1.20.4.2    bouyer 			(void)AcpiSetGpeWakeMask(hdl, val, ACPI_GPE_DISABLE);
    320       1.7    jruoho 			continue;
    321  1.20.4.2    bouyer 		}
    322       1.4    jruoho 
    323  1.20.4.2    bouyer 		(void)AcpiSetGpeWakeMask(hdl, val, ACPI_GPE_ENABLE);
    324  1.20.4.2    bouyer 
    325  1.20.4.2    bouyer 		acpi_wakedev_power_set(ad, true);
    326  1.20.4.2    bouyer 		acpi_wakedev_method(ad, state);
    327       1.1  jmcneill 	}
    328       1.1  jmcneill }
    329       1.4    jruoho 
    330       1.4    jruoho static void
    331  1.20.4.2    bouyer acpi_wakedev_method(struct acpi_devnode *ad, int state)
    332       1.4    jruoho {
    333  1.20.4.2    bouyer 	const bool enable = ad->ad_wakedev->aw_enable;
    334       1.4    jruoho 	ACPI_OBJECT_LIST arg;
    335       1.4    jruoho 	ACPI_OBJECT obj[3];
    336       1.4    jruoho 	ACPI_STATUS rv;
    337       1.4    jruoho 
    338       1.4    jruoho 	/*
    339       1.4    jruoho 	 * First try to call the Device Sleep Wake control method, _DSW.
    340       1.4    jruoho 	 * Only if this is not available, resort to to the Power State
    341       1.4    jruoho 	 * Wake control method, _PSW, which was deprecated in ACPI 3.0.
    342       1.4    jruoho 	 *
    343       1.4    jruoho 	 * The arguments to these methods are as follows:
    344       1.4    jruoho 	 *
    345       1.4    jruoho 	 *		arg0		arg1		arg2
    346       1.4    jruoho 	 *		----		----		----
    347       1.4    jruoho 	 *	 _PSW	0: disable
    348       1.4    jruoho 	 *		1: enable
    349       1.4    jruoho 	 *
    350       1.4    jruoho 	 *	 _DSW	0: disable	0: S0		0: D0
    351       1.4    jruoho 	 *		1: enable	1: S1		1: D0 or D1
    352       1.4    jruoho 	 *						2: D0, D1, or D2
    353       1.4    jruoho 	 *				x: Sx		3: D0, D1, D2 or D3
    354       1.4    jruoho 	 */
    355       1.4    jruoho 	arg.Count = 3;
    356       1.4    jruoho 	arg.Pointer = obj;
    357       1.4    jruoho 
    358       1.4    jruoho 	obj[0].Integer.Value = enable;
    359       1.4    jruoho 	obj[1].Integer.Value = state;
    360      1.14    jruoho 	obj[2].Integer.Value = ACPI_STATE_D0;
    361       1.4    jruoho 
    362       1.4    jruoho 	obj[0].Type = obj[1].Type = obj[2].Type = ACPI_TYPE_INTEGER;
    363       1.4    jruoho 
    364       1.4    jruoho 	rv = AcpiEvaluateObject(ad->ad_handle, "_DSW", &arg, NULL);
    365       1.4    jruoho 
    366       1.4    jruoho 	if (ACPI_SUCCESS(rv))
    367       1.4    jruoho 		return;
    368       1.4    jruoho 
    369       1.4    jruoho 	if (rv != AE_NOT_FOUND)
    370       1.4    jruoho 		goto fail;
    371       1.4    jruoho 
    372       1.4    jruoho 	rv = acpi_eval_set_integer(ad->ad_handle, "_PSW", enable);
    373       1.4    jruoho 
    374       1.4    jruoho 	if (ACPI_FAILURE(rv) && rv != AE_NOT_FOUND)
    375       1.4    jruoho 		goto fail;
    376       1.4    jruoho 
    377       1.4    jruoho 	return;
    378       1.4    jruoho 
    379       1.4    jruoho fail:
    380      1.12    jruoho 	aprint_error_dev(ad->ad_root, "failed to evaluate wake "
    381       1.4    jruoho 	    "control method: %s\n", AcpiFormatException(rv));
    382       1.4    jruoho }
    383