Home | History | Annotate | Line # | Download | only in acpi
aibs_acpi.c revision 1.2.2.2
      1  1.2.2.2  cherry /* $NetBSD: aibs_acpi.c,v 1.2.2.2 2011/06/23 14:19:57 cherry Exp $ */
      2  1.2.2.2  cherry 
      3  1.2.2.2  cherry /*-
      4  1.2.2.2  cherry  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5  1.2.2.2  cherry  * All rights reserved.
      6  1.2.2.2  cherry  *
      7  1.2.2.2  cherry  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.2.2  cherry  * by Jukka Ruohonen.
      9  1.2.2.2  cherry  *
     10  1.2.2.2  cherry  * Redistribution and use in source and binary forms, with or without
     11  1.2.2.2  cherry  * modification, are permitted provided that the following conditions
     12  1.2.2.2  cherry  * are met:
     13  1.2.2.2  cherry  * 1. Redistributions of source code must retain the above copyright
     14  1.2.2.2  cherry  *    notice, this list of conditions and the following disclaimer.
     15  1.2.2.2  cherry  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.2.2  cherry  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.2.2  cherry  *    documentation and/or other materials provided with the distribution.
     18  1.2.2.2  cherry  *
     19  1.2.2.2  cherry  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2.2.2  cherry  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2.2.2  cherry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2.2.2  cherry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2.2.2  cherry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2.2.2  cherry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2.2.2  cherry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2.2.2  cherry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2.2.2  cherry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2.2.2  cherry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2.2.2  cherry  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2.2.2  cherry  */
     31  1.2.2.2  cherry 
     32  1.2.2.2  cherry /*	$OpenBSD: atk0110.c,v 1.1 2009/07/23 01:38:16 cnst Exp $	*/
     33  1.2.2.2  cherry /*
     34  1.2.2.2  cherry  * Copyright (c) 2009 Constantine A. Murenin <cnst+netbsd (at) bugmail.mojo.ru>
     35  1.2.2.2  cherry  *
     36  1.2.2.2  cherry  * Permission to use, copy, modify, and distribute this software for any
     37  1.2.2.2  cherry  * purpose with or without fee is hereby granted, provided that the above
     38  1.2.2.2  cherry  * copyright notice and this permission notice appear in all copies.
     39  1.2.2.2  cherry  *
     40  1.2.2.2  cherry  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     41  1.2.2.2  cherry  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     42  1.2.2.2  cherry  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     43  1.2.2.2  cherry  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     44  1.2.2.2  cherry  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     45  1.2.2.2  cherry  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     46  1.2.2.2  cherry  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     47  1.2.2.2  cherry  */
     48  1.2.2.2  cherry 
     49  1.2.2.2  cherry #include <sys/cdefs.h>
     50  1.2.2.2  cherry __KERNEL_RCSID(0, "$NetBSD: aibs_acpi.c,v 1.2.2.2 2011/06/23 14:19:57 cherry Exp $");
     51  1.2.2.2  cherry 
     52  1.2.2.2  cherry #include <sys/param.h>
     53  1.2.2.2  cherry #include <sys/kmem.h>
     54  1.2.2.2  cherry #include <sys/module.h>
     55  1.2.2.2  cherry 
     56  1.2.2.2  cherry #include <dev/acpi/acpireg.h>
     57  1.2.2.2  cherry #include <dev/acpi/acpivar.h>
     58  1.2.2.2  cherry 
     59  1.2.2.2  cherry /*
     60  1.2.2.2  cherry  * ASUSTeK AI Booster (ACPI ASOC ATK0110).
     61  1.2.2.2  cherry  *
     62  1.2.2.2  cherry  * This code was originally written for OpenBSD after the techniques
     63  1.2.2.2  cherry  * described in the Linux's asus_atk0110.c and FreeBSD's acpi_aiboost.c
     64  1.2.2.2  cherry  * were verified to be accurate on the actual hardware kindly provided by
     65  1.2.2.2  cherry  * Sam Fourman Jr.  It was subsequently ported from OpenBSD to DragonFly BSD,
     66  1.2.2.2  cherry  * and then to the NetBSD's sysmon_envsys(9) framework.
     67  1.2.2.2  cherry  *
     68  1.2.2.2  cherry  *				  -- Constantine A. Murenin <http://cnst.su/>
     69  1.2.2.2  cherry  */
     70  1.2.2.2  cherry 
     71  1.2.2.2  cherry #define _COMPONENT		 ACPI_RESOURCE_COMPONENT
     72  1.2.2.2  cherry ACPI_MODULE_NAME		 ("acpi_aibs")
     73  1.2.2.2  cherry 
     74  1.2.2.2  cherry #define AIBS_MUX_HWMON		 0x00000006
     75  1.2.2.2  cherry #define AIBS_MUX_MGMT		 0x00000011
     76  1.2.2.2  cherry 
     77  1.2.2.2  cherry #define AIBS_TYPE(x)		 (((x) >> 16) & 0xff)
     78  1.2.2.2  cherry #define AIBS_TYPE_VOLT		 2
     79  1.2.2.2  cherry #define AIBS_TYPE_TEMP		 3
     80  1.2.2.2  cherry #define AIBS_TYPE_FAN		 4
     81  1.2.2.2  cherry 
     82  1.2.2.2  cherry struct aibs_sensor {
     83  1.2.2.2  cherry 	envsys_data_t			 as_sensor;
     84  1.2.2.2  cherry 	uint64_t			 as_type;
     85  1.2.2.2  cherry 	uint64_t			 as_liml;
     86  1.2.2.2  cherry 	uint64_t			 as_limh;
     87  1.2.2.2  cherry 
     88  1.2.2.2  cherry 	SIMPLEQ_ENTRY(aibs_sensor)	 as_list;
     89  1.2.2.2  cherry };
     90  1.2.2.2  cherry 
     91  1.2.2.2  cherry struct aibs_softc {
     92  1.2.2.2  cherry 	device_t			 sc_dev;
     93  1.2.2.2  cherry 	struct acpi_devnode		*sc_node;
     94  1.2.2.2  cherry 	struct sysmon_envsys		*sc_sme;
     95  1.2.2.2  cherry 	bool				 sc_model;	/* new model = true */
     96  1.2.2.2  cherry 
     97  1.2.2.2  cherry 	SIMPLEQ_HEAD(, aibs_sensor)	 as_head;
     98  1.2.2.2  cherry };
     99  1.2.2.2  cherry 
    100  1.2.2.2  cherry static int	aibs_match(device_t, cfdata_t, void *);
    101  1.2.2.2  cherry static void	aibs_attach(device_t, device_t, void *);
    102  1.2.2.2  cherry static int	aibs_detach(device_t, int);
    103  1.2.2.2  cherry 
    104  1.2.2.2  cherry static void	aibs_init(device_t);
    105  1.2.2.2  cherry static void	aibs_init_new(device_t);
    106  1.2.2.2  cherry static void	aibs_init_old(device_t, int);
    107  1.2.2.2  cherry 
    108  1.2.2.2  cherry static void	aibs_sensor_add(device_t, ACPI_OBJECT *);
    109  1.2.2.2  cherry static bool	aibs_sensor_value(device_t, struct aibs_sensor *, uint64_t *);
    110  1.2.2.2  cherry static void	aibs_sensor_refresh(struct sysmon_envsys *, envsys_data_t *);
    111  1.2.2.2  cherry static void	aibs_sensor_limits(struct sysmon_envsys *, envsys_data_t *,
    112  1.2.2.2  cherry 				   sysmon_envsys_lim_t *, uint32_t *);
    113  1.2.2.2  cherry 
    114  1.2.2.2  cherry CFATTACH_DECL_NEW(aibs, sizeof(struct aibs_softc),
    115  1.2.2.2  cherry     aibs_match, aibs_attach, aibs_detach, NULL);
    116  1.2.2.2  cherry 
    117  1.2.2.2  cherry static const char* const aibs_hid[] = {
    118  1.2.2.2  cherry 	"ATK0110",
    119  1.2.2.2  cherry 	NULL
    120  1.2.2.2  cherry };
    121  1.2.2.2  cherry 
    122  1.2.2.2  cherry static int
    123  1.2.2.2  cherry aibs_match(device_t parent, cfdata_t match, void *aux)
    124  1.2.2.2  cherry {
    125  1.2.2.2  cherry 	struct acpi_attach_args *aa = aux;
    126  1.2.2.2  cherry 
    127  1.2.2.2  cherry 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
    128  1.2.2.2  cherry 		return 0;
    129  1.2.2.2  cherry 
    130  1.2.2.2  cherry 	return acpi_match_hid(aa->aa_node->ad_devinfo, aibs_hid);
    131  1.2.2.2  cherry }
    132  1.2.2.2  cherry 
    133  1.2.2.2  cherry static void
    134  1.2.2.2  cherry aibs_attach(device_t parent, device_t self, void *aux)
    135  1.2.2.2  cherry {
    136  1.2.2.2  cherry 	struct aibs_softc *sc = device_private(self);
    137  1.2.2.2  cherry 	struct acpi_attach_args *aa = aux;
    138  1.2.2.2  cherry 
    139  1.2.2.2  cherry 	sc->sc_dev = self;
    140  1.2.2.2  cherry 	sc->sc_node = aa->aa_node;
    141  1.2.2.2  cherry 
    142  1.2.2.2  cherry 	aprint_naive("\n");
    143  1.2.2.2  cherry 	aprint_normal(": ASUSTeK AI Booster\n");
    144  1.2.2.2  cherry 
    145  1.2.2.2  cherry 	sc->sc_sme = sysmon_envsys_create();
    146  1.2.2.2  cherry 
    147  1.2.2.2  cherry 	sc->sc_sme->sme_cookie = sc;
    148  1.2.2.2  cherry 	sc->sc_sme->sme_name = device_xname(self);
    149  1.2.2.2  cherry 	sc->sc_sme->sme_refresh = aibs_sensor_refresh;
    150  1.2.2.2  cherry 	sc->sc_sme->sme_get_limits = aibs_sensor_limits;
    151  1.2.2.2  cherry 
    152  1.2.2.2  cherry 	aibs_init(self);
    153  1.2.2.2  cherry 	SIMPLEQ_INIT(&sc->as_head);
    154  1.2.2.2  cherry 
    155  1.2.2.2  cherry 	if (sc->sc_model != false)
    156  1.2.2.2  cherry 		aibs_init_new(self);
    157  1.2.2.2  cherry 	else {
    158  1.2.2.2  cherry 		aibs_init_old(self, AIBS_TYPE_FAN);
    159  1.2.2.2  cherry 		aibs_init_old(self, AIBS_TYPE_TEMP);
    160  1.2.2.2  cherry 		aibs_init_old(self, AIBS_TYPE_VOLT);
    161  1.2.2.2  cherry 	}
    162  1.2.2.2  cherry 
    163  1.2.2.2  cherry 	(void)pmf_device_register(self, NULL, NULL);
    164  1.2.2.2  cherry 
    165  1.2.2.2  cherry 	if (sc->sc_sme->sme_nsensors == 0) {
    166  1.2.2.2  cherry 		aprint_error_dev(self, "no sensors found\n");
    167  1.2.2.2  cherry 		sysmon_envsys_destroy(sc->sc_sme);
    168  1.2.2.2  cherry 		sc->sc_sme = NULL;
    169  1.2.2.2  cherry 		return;
    170  1.2.2.2  cherry 	}
    171  1.2.2.2  cherry 
    172  1.2.2.2  cherry 	if (sysmon_envsys_register(sc->sc_sme) != 0)
    173  1.2.2.2  cherry 		aprint_error_dev(self, "failed to register with sysmon\n");
    174  1.2.2.2  cherry }
    175  1.2.2.2  cherry 
    176  1.2.2.2  cherry static int
    177  1.2.2.2  cherry aibs_detach(device_t self, int flags)
    178  1.2.2.2  cherry {
    179  1.2.2.2  cherry 	struct aibs_softc *sc = device_private(self);
    180  1.2.2.2  cherry 	struct aibs_sensor *as;
    181  1.2.2.2  cherry 
    182  1.2.2.2  cherry 	pmf_device_deregister(self);
    183  1.2.2.2  cherry 
    184  1.2.2.2  cherry 	if (sc->sc_sme != NULL)
    185  1.2.2.2  cherry 		sysmon_envsys_unregister(sc->sc_sme);
    186  1.2.2.2  cherry 
    187  1.2.2.2  cherry 	while (SIMPLEQ_FIRST(&sc->as_head) != NULL) {
    188  1.2.2.2  cherry 		as = SIMPLEQ_FIRST(&sc->as_head);
    189  1.2.2.2  cherry 		SIMPLEQ_REMOVE_HEAD(&sc->as_head, as_list);
    190  1.2.2.2  cherry 		kmem_free(as, sizeof(*as));
    191  1.2.2.2  cherry 	}
    192  1.2.2.2  cherry 
    193  1.2.2.2  cherry 	return 0;
    194  1.2.2.2  cherry }
    195  1.2.2.2  cherry 
    196  1.2.2.2  cherry static void
    197  1.2.2.2  cherry aibs_init(device_t self)
    198  1.2.2.2  cherry {
    199  1.2.2.2  cherry 	struct aibs_softc *sc = device_private(self);
    200  1.2.2.2  cherry 	ACPI_HANDLE tmp;
    201  1.2.2.2  cherry 	ACPI_STATUS rv;
    202  1.2.2.2  cherry 
    203  1.2.2.2  cherry 	/*
    204  1.2.2.2  cherry 	 * Old model uses the tuple { TSIF, VSIF, FSIF } to
    205  1.2.2.2  cherry 	 * enumerate the sensors and { RTMP, RVLT, RFAN }
    206  1.2.2.2  cherry 	 * to obtain the values. New mode uses GGRP for the
    207  1.2.2.2  cherry 	 * enumeration and { GITM, SITM } as accessors.
    208  1.2.2.2  cherry 	 */
    209  1.2.2.2  cherry 	rv = AcpiGetHandle(sc->sc_node->ad_handle, "GGRP", &tmp);
    210  1.2.2.2  cherry 
    211  1.2.2.2  cherry 	if (ACPI_FAILURE(rv)) {
    212  1.2.2.2  cherry 		sc->sc_model = false;
    213  1.2.2.2  cherry 		return;
    214  1.2.2.2  cherry 	}
    215  1.2.2.2  cherry 
    216  1.2.2.2  cherry 	rv = AcpiGetHandle(sc->sc_node->ad_handle, "GITM", &tmp);
    217  1.2.2.2  cherry 
    218  1.2.2.2  cherry 	if (ACPI_FAILURE(rv)) {
    219  1.2.2.2  cherry 		sc->sc_model = false;
    220  1.2.2.2  cherry 		return;
    221  1.2.2.2  cherry 	}
    222  1.2.2.2  cherry 
    223  1.2.2.2  cherry 	rv = AcpiGetHandle(sc->sc_node->ad_handle, "SITM", &tmp);
    224  1.2.2.2  cherry 
    225  1.2.2.2  cherry 	if (ACPI_FAILURE(rv)) {
    226  1.2.2.2  cherry 		sc->sc_model = false;
    227  1.2.2.2  cherry 		return;
    228  1.2.2.2  cherry 	}
    229  1.2.2.2  cherry 
    230  1.2.2.2  cherry 	sc->sc_model = true;
    231  1.2.2.2  cherry }
    232  1.2.2.2  cherry 
    233  1.2.2.2  cherry static void
    234  1.2.2.2  cherry aibs_init_new(device_t self)
    235  1.2.2.2  cherry {
    236  1.2.2.2  cherry 	struct aibs_softc *sc = device_private(self);
    237  1.2.2.2  cherry 	ACPI_OBJECT_LIST arg;
    238  1.2.2.2  cherry 	ACPI_OBJECT id, *obj;
    239  1.2.2.2  cherry 	ACPI_BUFFER buf;
    240  1.2.2.2  cherry 	ACPI_STATUS rv;
    241  1.2.2.2  cherry 	uint32_t i, n;
    242  1.2.2.2  cherry 
    243  1.2.2.2  cherry 	arg.Count = 1;
    244  1.2.2.2  cherry 	arg.Pointer = &id;
    245  1.2.2.2  cherry 
    246  1.2.2.2  cherry 	id.Type = ACPI_TYPE_INTEGER;
    247  1.2.2.2  cherry 	id.Integer.Value = AIBS_MUX_HWMON;
    248  1.2.2.2  cherry 
    249  1.2.2.2  cherry 	buf.Pointer = NULL;
    250  1.2.2.2  cherry 	buf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    251  1.2.2.2  cherry 
    252  1.2.2.2  cherry 	rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "GGRP", &arg, &buf);
    253  1.2.2.2  cherry 
    254  1.2.2.2  cherry 	if (ACPI_FAILURE(rv))
    255  1.2.2.2  cherry 		goto out;
    256  1.2.2.2  cherry 
    257  1.2.2.2  cherry 	obj = buf.Pointer;
    258  1.2.2.2  cherry 
    259  1.2.2.2  cherry 	if (obj->Type != ACPI_TYPE_PACKAGE) {
    260  1.2.2.2  cherry 		rv = AE_TYPE;
    261  1.2.2.2  cherry 		goto out;
    262  1.2.2.2  cherry 	}
    263  1.2.2.2  cherry 
    264  1.2.2.2  cherry 	if (obj->Package.Count > UINT32_MAX) {
    265  1.2.2.2  cherry 		rv = AE_AML_NUMERIC_OVERFLOW;
    266  1.2.2.2  cherry 		goto out;
    267  1.2.2.2  cherry 	}
    268  1.2.2.2  cherry 
    269  1.2.2.2  cherry 	n = obj->Package.Count;
    270  1.2.2.2  cherry 
    271  1.2.2.2  cherry 	if (n == 0) {
    272  1.2.2.2  cherry 		rv = AE_NOT_EXIST;
    273  1.2.2.2  cherry 		goto out;
    274  1.2.2.2  cherry 	}
    275  1.2.2.2  cherry 
    276  1.2.2.2  cherry 	for (i = 0; i < n; i++)
    277  1.2.2.2  cherry 		aibs_sensor_add(self, &obj->Package.Elements[i]);
    278  1.2.2.2  cherry 
    279  1.2.2.2  cherry out:
    280  1.2.2.2  cherry 	if (buf.Pointer != NULL)
    281  1.2.2.2  cherry 		ACPI_FREE(buf.Pointer);
    282  1.2.2.2  cherry 
    283  1.2.2.2  cherry 	if (ACPI_FAILURE(rv)) {
    284  1.2.2.2  cherry 
    285  1.2.2.2  cherry 		aprint_error_dev(self, "failed to evaluate "
    286  1.2.2.2  cherry 		    "GGRP: %s\n", AcpiFormatException(rv));
    287  1.2.2.2  cherry 	}
    288  1.2.2.2  cherry }
    289  1.2.2.2  cherry 
    290  1.2.2.2  cherry static void
    291  1.2.2.2  cherry aibs_init_old(device_t self, int type)
    292  1.2.2.2  cherry {
    293  1.2.2.2  cherry 	struct aibs_softc *sc = device_private(self);
    294  1.2.2.2  cherry 	char path[] = "?SIF";
    295  1.2.2.2  cherry 	ACPI_OBJECT *elm, *obj;
    296  1.2.2.2  cherry 	ACPI_BUFFER buf;
    297  1.2.2.2  cherry 	ACPI_STATUS rv;
    298  1.2.2.2  cherry 	uint32_t i, n;
    299  1.2.2.2  cherry 
    300  1.2.2.2  cherry 	switch (type) {
    301  1.2.2.2  cherry 
    302  1.2.2.2  cherry 	case AIBS_TYPE_FAN:
    303  1.2.2.2  cherry 		path[0] = 'F';
    304  1.2.2.2  cherry 		break;
    305  1.2.2.2  cherry 
    306  1.2.2.2  cherry 	case AIBS_TYPE_TEMP:
    307  1.2.2.2  cherry 		path[0] = 'T';
    308  1.2.2.2  cherry 		break;
    309  1.2.2.2  cherry 
    310  1.2.2.2  cherry 	case AIBS_TYPE_VOLT:
    311  1.2.2.2  cherry 		path[0] = 'V';
    312  1.2.2.2  cherry 		break;
    313  1.2.2.2  cherry 
    314  1.2.2.2  cherry 	default:
    315  1.2.2.2  cherry 		return;
    316  1.2.2.2  cherry 	}
    317  1.2.2.2  cherry 
    318  1.2.2.2  cherry 	rv = acpi_eval_struct(sc->sc_node->ad_handle, path, &buf);
    319  1.2.2.2  cherry 
    320  1.2.2.2  cherry 	if (ACPI_FAILURE(rv))
    321  1.2.2.2  cherry 		goto out;
    322  1.2.2.2  cherry 
    323  1.2.2.2  cherry 	obj = buf.Pointer;
    324  1.2.2.2  cherry 
    325  1.2.2.2  cherry 	if (obj->Type != ACPI_TYPE_PACKAGE) {
    326  1.2.2.2  cherry 		rv = AE_TYPE;
    327  1.2.2.2  cherry 		goto out;
    328  1.2.2.2  cherry 	}
    329  1.2.2.2  cherry 
    330  1.2.2.2  cherry 	elm = obj->Package.Elements;
    331  1.2.2.2  cherry 
    332  1.2.2.2  cherry 	if (elm[0].Type != ACPI_TYPE_INTEGER) {
    333  1.2.2.2  cherry 		rv = AE_TYPE;
    334  1.2.2.2  cherry 		goto out;
    335  1.2.2.2  cherry 	}
    336  1.2.2.2  cherry 
    337  1.2.2.2  cherry 	if (elm[0].Integer.Value > UINT32_MAX) {
    338  1.2.2.2  cherry 		rv = AE_AML_NUMERIC_OVERFLOW;
    339  1.2.2.2  cherry 		goto out;
    340  1.2.2.2  cherry 	}
    341  1.2.2.2  cherry 
    342  1.2.2.2  cherry 	n = elm[0].Integer.Value;
    343  1.2.2.2  cherry 
    344  1.2.2.2  cherry 	if (n == 0) {
    345  1.2.2.2  cherry 		rv = AE_NOT_EXIST;
    346  1.2.2.2  cherry 		goto out;
    347  1.2.2.2  cherry 	}
    348  1.2.2.2  cherry 
    349  1.2.2.2  cherry 	if (obj->Package.Count - 1 != n) {
    350  1.2.2.2  cherry 		rv = AE_BAD_VALUE;
    351  1.2.2.2  cherry 		goto out;
    352  1.2.2.2  cherry 	}
    353  1.2.2.2  cherry 
    354  1.2.2.2  cherry 	for (i = 1; i < obj->Package.Count; i++) {
    355  1.2.2.2  cherry 
    356  1.2.2.2  cherry 		if (elm[i].Type != ACPI_TYPE_PACKAGE)
    357  1.2.2.2  cherry 			continue;
    358  1.2.2.2  cherry 
    359  1.2.2.2  cherry 		aibs_sensor_add(self, &elm[i]);
    360  1.2.2.2  cherry 	}
    361  1.2.2.2  cherry 
    362  1.2.2.2  cherry out:
    363  1.2.2.2  cherry 	if (buf.Pointer != NULL)
    364  1.2.2.2  cherry 		ACPI_FREE(buf.Pointer);
    365  1.2.2.2  cherry 
    366  1.2.2.2  cherry 	if (ACPI_FAILURE(rv)) {
    367  1.2.2.2  cherry 
    368  1.2.2.2  cherry 		aprint_error_dev(self, "failed to evaluate "
    369  1.2.2.2  cherry 		    "%s: %s\n", path, AcpiFormatException(rv));
    370  1.2.2.2  cherry 	}
    371  1.2.2.2  cherry }
    372  1.2.2.2  cherry 
    373  1.2.2.2  cherry static void
    374  1.2.2.2  cherry aibs_sensor_add(device_t self, ACPI_OBJECT *obj)
    375  1.2.2.2  cherry {
    376  1.2.2.2  cherry 	struct aibs_softc *sc = device_private(self);
    377  1.2.2.2  cherry 	struct aibs_sensor *as;
    378  1.2.2.2  cherry 	int ena, len, lhi, llo;
    379  1.2.2.2  cherry 	const char *name;
    380  1.2.2.2  cherry 	ACPI_STATUS rv;
    381  1.2.2.2  cherry 
    382  1.2.2.2  cherry 	as = NULL;
    383  1.2.2.2  cherry 	rv = AE_OK;
    384  1.2.2.2  cherry 
    385  1.2.2.2  cherry 	if (obj->Type != ACPI_TYPE_PACKAGE) {
    386  1.2.2.2  cherry 		rv = AE_TYPE;
    387  1.2.2.2  cherry 		goto out;
    388  1.2.2.2  cherry 	}
    389  1.2.2.2  cherry 
    390  1.2.2.2  cherry 	/*
    391  1.2.2.2  cherry 	 * The known formats are:
    392  1.2.2.2  cherry 	 *
    393  1.2.2.2  cherry 	 *	index		type		old		new
    394  1.2.2.2  cherry 	 *	-----		----		---		---
    395  1.2.2.2  cherry 	 *	0		integer		flags		flags
    396  1.2.2.2  cherry 	 *	1		string		name		name
    397  1.2.2.2  cherry 	 *	2		integer		limit1		unknown
    398  1.2.2.2  cherry 	 *	3		integer		limit2		unknown
    399  1.2.2.2  cherry 	 *	4		integer		enable		limit1
    400  1.2.2.2  cherry 	 *	5		integer		-		limit2
    401  1.2.2.2  cherry 	 *	6		integer		-		enable
    402  1.2.2.2  cherry 	 */
    403  1.2.2.2  cherry 	if (sc->sc_model != false) {
    404  1.2.2.2  cherry 		len = 7;
    405  1.2.2.2  cherry 		llo = 4;
    406  1.2.2.2  cherry 		lhi = 5;
    407  1.2.2.2  cherry 		ena = 6;
    408  1.2.2.2  cherry 	} else {
    409  1.2.2.2  cherry 		len = 5;
    410  1.2.2.2  cherry 		llo = 2;
    411  1.2.2.2  cherry 		lhi = 3;
    412  1.2.2.2  cherry 		ena = 4;
    413  1.2.2.2  cherry 	}
    414  1.2.2.2  cherry 
    415  1.2.2.2  cherry 	if (obj->Package.Count != (uint32_t)len) {
    416  1.2.2.2  cherry 		rv = AE_LIMIT;
    417  1.2.2.2  cherry 		goto out;
    418  1.2.2.2  cherry 	}
    419  1.2.2.2  cherry 
    420  1.2.2.2  cherry 	if (obj->Package.Elements[0].Type != ACPI_TYPE_INTEGER ||
    421  1.2.2.2  cherry 	    obj->Package.Elements[1].Type != ACPI_TYPE_STRING ||
    422  1.2.2.2  cherry 	    obj->Package.Elements[llo].Type != ACPI_TYPE_INTEGER ||
    423  1.2.2.2  cherry 	    obj->Package.Elements[lhi].Type != ACPI_TYPE_INTEGER ||
    424  1.2.2.2  cherry 	    obj->Package.Elements[ena].Type != ACPI_TYPE_INTEGER) {
    425  1.2.2.2  cherry 		rv = AE_TYPE;
    426  1.2.2.2  cherry 		goto out;
    427  1.2.2.2  cherry 	}
    428  1.2.2.2  cherry 
    429  1.2.2.2  cherry 	as = kmem_zalloc(sizeof(*as), KM_SLEEP);
    430  1.2.2.2  cherry 
    431  1.2.2.2  cherry 	if (as == NULL) {
    432  1.2.2.2  cherry 		rv = AE_NO_MEMORY;
    433  1.2.2.2  cherry 		goto out;
    434  1.2.2.2  cherry 	}
    435  1.2.2.2  cherry 
    436  1.2.2.2  cherry 	name = obj->Package.Elements[1].String.Pointer;
    437  1.2.2.2  cherry 
    438  1.2.2.2  cherry 	as->as_type = obj->Package.Elements[0].Integer.Value;
    439  1.2.2.2  cherry 	as->as_liml = obj->Package.Elements[llo].Integer.Value;
    440  1.2.2.2  cherry 	as->as_limh = obj->Package.Elements[lhi].Integer.Value;
    441  1.2.2.2  cherry 
    442  1.2.2.2  cherry 	if (sc->sc_model != false)
    443  1.2.2.2  cherry 		as->as_limh += as->as_liml;	/* A range in the new model. */
    444  1.2.2.2  cherry 
    445  1.2.2.2  cherry 	switch (AIBS_TYPE(as->as_type)) {
    446  1.2.2.2  cherry 
    447  1.2.2.2  cherry 	case AIBS_TYPE_FAN:
    448  1.2.2.2  cherry 		as->as_sensor.units = ENVSYS_SFANRPM;
    449  1.2.2.2  cherry 		as->as_sensor.flags |= ENVSYS_FMONLIMITS;
    450  1.2.2.2  cherry 		break;
    451  1.2.2.2  cherry 
    452  1.2.2.2  cherry 	case AIBS_TYPE_TEMP:
    453  1.2.2.2  cherry 		as->as_sensor.units = ENVSYS_STEMP;
    454  1.2.2.2  cherry 		as->as_sensor.flags |= ENVSYS_FMONLIMITS;
    455  1.2.2.2  cherry 		break;
    456  1.2.2.2  cherry 
    457  1.2.2.2  cherry 	case AIBS_TYPE_VOLT:
    458  1.2.2.2  cherry 		as->as_sensor.units = ENVSYS_SVOLTS_DC;
    459  1.2.2.2  cherry 		as->as_sensor.flags |= ENVSYS_FMONLIMITS;
    460  1.2.2.2  cherry 		break;
    461  1.2.2.2  cherry 
    462  1.2.2.2  cherry 	default:
    463  1.2.2.2  cherry 		rv = AE_TYPE;
    464  1.2.2.2  cherry 		goto out;
    465  1.2.2.2  cherry 	}
    466  1.2.2.2  cherry 
    467  1.2.2.2  cherry 	(void)strlcpy(as->as_sensor.desc, name, sizeof(as->as_sensor.desc));
    468  1.2.2.2  cherry 	as->as_sensor.state = ENVSYS_SINVALID;
    469  1.2.2.2  cherry 
    470  1.2.2.2  cherry 	if (sysmon_envsys_sensor_attach(sc->sc_sme, &as->as_sensor) != 0) {
    471  1.2.2.2  cherry 		rv = AE_AML_INTERNAL;
    472  1.2.2.2  cherry 		goto out;
    473  1.2.2.2  cherry 	}
    474  1.2.2.2  cherry 
    475  1.2.2.2  cherry 	SIMPLEQ_INSERT_TAIL(&sc->as_head, as, as_list);
    476  1.2.2.2  cherry 
    477  1.2.2.2  cherry out:
    478  1.2.2.2  cherry 	if (ACPI_FAILURE(rv)) {
    479  1.2.2.2  cherry 
    480  1.2.2.2  cherry 		if (as != NULL)
    481  1.2.2.2  cherry 			kmem_free(as, sizeof(*as));
    482  1.2.2.2  cherry 
    483  1.2.2.2  cherry 		aprint_error_dev(self, "failed to add "
    484  1.2.2.2  cherry 		    "sensor: %s\n",  AcpiFormatException(rv));
    485  1.2.2.2  cherry 	}
    486  1.2.2.2  cherry }
    487  1.2.2.2  cherry 
    488  1.2.2.2  cherry static bool
    489  1.2.2.2  cherry aibs_sensor_value(device_t self, struct aibs_sensor *as, uint64_t *val)
    490  1.2.2.2  cherry {
    491  1.2.2.2  cherry 	struct aibs_softc *sc = device_private(self);
    492  1.2.2.2  cherry 	uint32_t type, *ret, cmb[3];
    493  1.2.2.2  cherry 	ACPI_OBJECT_LIST arg;
    494  1.2.2.2  cherry 	ACPI_OBJECT cmi, tmp;
    495  1.2.2.2  cherry 	ACPI_OBJECT *obj;
    496  1.2.2.2  cherry 	ACPI_BUFFER buf;
    497  1.2.2.2  cherry 	ACPI_STATUS rv;
    498  1.2.2.2  cherry 	const char *path;
    499  1.2.2.2  cherry 
    500  1.2.2.2  cherry 	if (sc->sc_model != false) {
    501  1.2.2.2  cherry 
    502  1.2.2.2  cherry 		path = "GITM";
    503  1.2.2.2  cherry 
    504  1.2.2.2  cherry 		cmb[0] = as->as_type;
    505  1.2.2.2  cherry 		cmb[1] = 0;
    506  1.2.2.2  cherry 		cmb[2] = 0;
    507  1.2.2.2  cherry 
    508  1.2.2.2  cherry 		arg.Count = 1;
    509  1.2.2.2  cherry 		arg.Pointer = &tmp;
    510  1.2.2.2  cherry 
    511  1.2.2.2  cherry 		tmp.Buffer.Length = sizeof(cmb);
    512  1.2.2.2  cherry 		tmp.Buffer.Pointer = (uint8_t *)cmb;
    513  1.2.2.2  cherry 		tmp.Type = type = ACPI_TYPE_BUFFER;
    514  1.2.2.2  cherry 
    515  1.2.2.2  cherry 	} else {
    516  1.2.2.2  cherry 
    517  1.2.2.2  cherry 		arg.Count = 1;
    518  1.2.2.2  cherry 		arg.Pointer = &cmi;
    519  1.2.2.2  cherry 
    520  1.2.2.2  cherry 		cmi.Integer.Value = as->as_type;
    521  1.2.2.2  cherry 		cmi.Type = type = ACPI_TYPE_INTEGER;
    522  1.2.2.2  cherry 
    523  1.2.2.2  cherry 		switch (AIBS_TYPE(as->as_type)) {
    524  1.2.2.2  cherry 
    525  1.2.2.2  cherry 		case AIBS_TYPE_FAN:
    526  1.2.2.2  cherry 			path = "RFAN";
    527  1.2.2.2  cherry 			break;
    528  1.2.2.2  cherry 
    529  1.2.2.2  cherry 		case AIBS_TYPE_TEMP:
    530  1.2.2.2  cherry 			path = "RTMP";
    531  1.2.2.2  cherry 			break;
    532  1.2.2.2  cherry 
    533  1.2.2.2  cherry 		case AIBS_TYPE_VOLT:
    534  1.2.2.2  cherry 			path = "RVLT";
    535  1.2.2.2  cherry 			break;
    536  1.2.2.2  cherry 
    537  1.2.2.2  cherry 		default:
    538  1.2.2.2  cherry 			return false;
    539  1.2.2.2  cherry 		}
    540  1.2.2.2  cherry 	}
    541  1.2.2.2  cherry 
    542  1.2.2.2  cherry 	buf.Pointer = NULL;
    543  1.2.2.2  cherry 	buf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    544  1.2.2.2  cherry 
    545  1.2.2.2  cherry 	rv = AcpiEvaluateObject(sc->sc_node->ad_handle, path, &arg, &buf);
    546  1.2.2.2  cherry 
    547  1.2.2.2  cherry 	if (ACPI_FAILURE(rv))
    548  1.2.2.2  cherry 		goto out;
    549  1.2.2.2  cherry 
    550  1.2.2.2  cherry 	obj = buf.Pointer;
    551  1.2.2.2  cherry 
    552  1.2.2.2  cherry 	if (obj->Type != type) {
    553  1.2.2.2  cherry 		rv = AE_TYPE;
    554  1.2.2.2  cherry 		goto out;
    555  1.2.2.2  cherry 	}
    556  1.2.2.2  cherry 
    557  1.2.2.2  cherry 	if (sc->sc_model != true)
    558  1.2.2.2  cherry 		*val = obj->Integer.Value;
    559  1.2.2.2  cherry 	else {
    560  1.2.2.2  cherry 		/*
    561  1.2.2.2  cherry 		 * The return buffer contains at least:
    562  1.2.2.2  cherry 		 *
    563  1.2.2.2  cherry 		 *	uint32_t buf[0]	 flags
    564  1.2.2.2  cherry 		 *	uint32_t buf[1]	 return value
    565  1.2.2.2  cherry 		 *	uint8_t  buf[2-] unknown
    566  1.2.2.2  cherry 		 */
    567  1.2.2.2  cherry 		if (obj->Buffer.Length < 8) {
    568  1.2.2.2  cherry 			rv = AE_BUFFER_OVERFLOW;
    569  1.2.2.2  cherry 			goto out;
    570  1.2.2.2  cherry 		}
    571  1.2.2.2  cherry 
    572  1.2.2.2  cherry 		ret = (uint32_t *)obj->Buffer.Pointer;
    573  1.2.2.2  cherry 
    574  1.2.2.2  cherry 		if (ret[0] == 0) {
    575  1.2.2.2  cherry 			rv = AE_BAD_VALUE;
    576  1.2.2.2  cherry 			goto out;
    577  1.2.2.2  cherry 		}
    578  1.2.2.2  cherry 
    579  1.2.2.2  cherry 		*val = ret[1];
    580  1.2.2.2  cherry 	}
    581  1.2.2.2  cherry 
    582  1.2.2.2  cherry out:
    583  1.2.2.2  cherry 	if (buf.Pointer != NULL)
    584  1.2.2.2  cherry 		ACPI_FREE(buf.Pointer);
    585  1.2.2.2  cherry 
    586  1.2.2.2  cherry 	if (ACPI_FAILURE(rv)) {
    587  1.2.2.2  cherry 
    588  1.2.2.2  cherry 		aprint_error_dev(self, "failed to evaluate "
    589  1.2.2.2  cherry 		    "%s: %s\n", path, AcpiFormatException(rv));
    590  1.2.2.2  cherry 
    591  1.2.2.2  cherry 		return false;
    592  1.2.2.2  cherry 	}
    593  1.2.2.2  cherry 
    594  1.2.2.2  cherry 	return true;
    595  1.2.2.2  cherry }
    596  1.2.2.2  cherry 
    597  1.2.2.2  cherry static void
    598  1.2.2.2  cherry aibs_sensor_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
    599  1.2.2.2  cherry {
    600  1.2.2.2  cherry 	struct aibs_softc *sc = sme->sme_cookie;
    601  1.2.2.2  cherry 	struct aibs_sensor *tmp, *as = NULL;
    602  1.2.2.2  cherry 	envsys_data_t *s = edata;
    603  1.2.2.2  cherry 	uint64_t val = 0;
    604  1.2.2.2  cherry 
    605  1.2.2.2  cherry 	SIMPLEQ_FOREACH(tmp, &sc->as_head, as_list) {
    606  1.2.2.2  cherry 
    607  1.2.2.2  cherry 		if (tmp->as_sensor.sensor == s->sensor) {
    608  1.2.2.2  cherry 			as = tmp;
    609  1.2.2.2  cherry 			break;
    610  1.2.2.2  cherry 		}
    611  1.2.2.2  cherry 	}
    612  1.2.2.2  cherry 
    613  1.2.2.2  cherry 	if (as == NULL) {
    614  1.2.2.2  cherry 		aprint_debug_dev(sc->sc_dev, "failed to find sensor\n");
    615  1.2.2.2  cherry 		return;
    616  1.2.2.2  cherry 	}
    617  1.2.2.2  cherry 
    618  1.2.2.2  cherry 	as->as_sensor.state = ENVSYS_SINVALID;
    619  1.2.2.2  cherry 	as->as_sensor.flags |= ENVSYS_FMONNOTSUPP;
    620  1.2.2.2  cherry 
    621  1.2.2.2  cherry 	if (aibs_sensor_value(sc->sc_dev, as, &val) != true)
    622  1.2.2.2  cherry 		return;
    623  1.2.2.2  cherry 
    624  1.2.2.2  cherry 	switch (as->as_sensor.units) {
    625  1.2.2.2  cherry 
    626  1.2.2.2  cherry 	case ENVSYS_SFANRPM:
    627  1.2.2.2  cherry 		as->as_sensor.value_cur = val;
    628  1.2.2.2  cherry 		break;
    629  1.2.2.2  cherry 
    630  1.2.2.2  cherry 	case ENVSYS_STEMP:
    631  1.2.2.2  cherry 
    632  1.2.2.2  cherry 		if (val == 0)
    633  1.2.2.2  cherry 			return;
    634  1.2.2.2  cherry 
    635  1.2.2.2  cherry 		as->as_sensor.value_cur = val * 100 * 1000 + 273150000;
    636  1.2.2.2  cherry 		break;
    637  1.2.2.2  cherry 
    638  1.2.2.2  cherry 	case ENVSYS_SVOLTS_DC:
    639  1.2.2.2  cherry 		as->as_sensor.value_cur = val * 1000;
    640  1.2.2.2  cherry 		break;
    641  1.2.2.2  cherry 
    642  1.2.2.2  cherry 	default:
    643  1.2.2.2  cherry 		return;
    644  1.2.2.2  cherry 	}
    645  1.2.2.2  cherry 
    646  1.2.2.2  cherry 	as->as_sensor.state = ENVSYS_SVALID;
    647  1.2.2.2  cherry 	as->as_sensor.flags &= ~ENVSYS_FMONNOTSUPP;
    648  1.2.2.2  cherry }
    649  1.2.2.2  cherry 
    650  1.2.2.2  cherry static void
    651  1.2.2.2  cherry aibs_sensor_limits(struct sysmon_envsys *sme, envsys_data_t *edata,
    652  1.2.2.2  cherry     sysmon_envsys_lim_t *limits, uint32_t *props)
    653  1.2.2.2  cherry {
    654  1.2.2.2  cherry 	struct aibs_softc *sc = sme->sme_cookie;
    655  1.2.2.2  cherry 	struct aibs_sensor *tmp, *as = NULL;
    656  1.2.2.2  cherry 	sysmon_envsys_lim_t *lim = limits;
    657  1.2.2.2  cherry 	envsys_data_t *s = edata;
    658  1.2.2.2  cherry 
    659  1.2.2.2  cherry 	SIMPLEQ_FOREACH(tmp, &sc->as_head, as_list) {
    660  1.2.2.2  cherry 
    661  1.2.2.2  cherry 		if (tmp->as_sensor.sensor == s->sensor) {
    662  1.2.2.2  cherry 			as = tmp;
    663  1.2.2.2  cherry 			break;
    664  1.2.2.2  cherry 		}
    665  1.2.2.2  cherry 	}
    666  1.2.2.2  cherry 
    667  1.2.2.2  cherry 	if (as == NULL) {
    668  1.2.2.2  cherry 		aprint_debug_dev(sc->sc_dev, "failed to find sensor\n");
    669  1.2.2.2  cherry 		return;
    670  1.2.2.2  cherry 	}
    671  1.2.2.2  cherry 
    672  1.2.2.2  cherry 	switch (as->as_sensor.units) {
    673  1.2.2.2  cherry 
    674  1.2.2.2  cherry 	case ENVSYS_SFANRPM:
    675  1.2.2.2  cherry 
    676  1.2.2.2  cherry 		/*
    677  1.2.2.2  cherry 		 * Some boards have strange limits for fans.
    678  1.2.2.2  cherry 		 */
    679  1.2.2.2  cherry 		if (as->as_liml == 0) {
    680  1.2.2.2  cherry 			lim->sel_warnmin = as->as_limh;
    681  1.2.2.2  cherry 			*props = PROP_WARNMIN;
    682  1.2.2.2  cherry 
    683  1.2.2.2  cherry 		} else {
    684  1.2.2.2  cherry 			lim->sel_warnmin = as->as_liml;
    685  1.2.2.2  cherry 			lim->sel_warnmax = as->as_limh;
    686  1.2.2.2  cherry 			*props = PROP_WARNMIN | PROP_WARNMAX;
    687  1.2.2.2  cherry 		}
    688  1.2.2.2  cherry 
    689  1.2.2.2  cherry 		break;
    690  1.2.2.2  cherry 
    691  1.2.2.2  cherry 	case ENVSYS_STEMP:
    692  1.2.2.2  cherry 		lim->sel_critmax = as->as_limh * 100 * 1000 + 273150000;
    693  1.2.2.2  cherry 		lim->sel_warnmax = as->as_liml * 100 * 1000 + 273150000;
    694  1.2.2.2  cherry 
    695  1.2.2.2  cherry 		*props = PROP_CRITMAX | PROP_WARNMAX;
    696  1.2.2.2  cherry 		break;
    697  1.2.2.2  cherry 
    698  1.2.2.2  cherry 	case ENVSYS_SVOLTS_DC:
    699  1.2.2.2  cherry 		lim->sel_critmin = as->as_liml * 1000;
    700  1.2.2.2  cherry 		lim->sel_critmax = as->as_limh * 1000;
    701  1.2.2.2  cherry 		*props = PROP_CRITMIN | PROP_CRITMAX;
    702  1.2.2.2  cherry 		break;
    703  1.2.2.2  cherry 
    704  1.2.2.2  cherry 	default:
    705  1.2.2.2  cherry 		return;
    706  1.2.2.2  cherry 	}
    707  1.2.2.2  cherry }
    708  1.2.2.2  cherry 
    709  1.2.2.2  cherry MODULE(MODULE_CLASS_DRIVER, aibs, NULL);
    710  1.2.2.2  cherry 
    711  1.2.2.2  cherry #ifdef _MODULE
    712  1.2.2.2  cherry #include "ioconf.c"
    713  1.2.2.2  cherry #endif
    714  1.2.2.2  cherry 
    715  1.2.2.2  cherry static int
    716  1.2.2.2  cherry aibs_modcmd(modcmd_t cmd, void *aux)
    717  1.2.2.2  cherry {
    718  1.2.2.2  cherry 	int rv = 0;
    719  1.2.2.2  cherry 
    720  1.2.2.2  cherry 	switch (cmd) {
    721  1.2.2.2  cherry 
    722  1.2.2.2  cherry 	case MODULE_CMD_INIT:
    723  1.2.2.2  cherry 
    724  1.2.2.2  cherry #ifdef _MODULE
    725  1.2.2.2  cherry 		rv = config_init_component(cfdriver_ioconf_aibs,
    726  1.2.2.2  cherry 		    cfattach_ioconf_aibs, cfdata_ioconf_aibs);
    727  1.2.2.2  cherry #endif
    728  1.2.2.2  cherry 		break;
    729  1.2.2.2  cherry 
    730  1.2.2.2  cherry 	case MODULE_CMD_FINI:
    731  1.2.2.2  cherry 
    732  1.2.2.2  cherry #ifdef _MODULE
    733  1.2.2.2  cherry 		rv = config_fini_component(cfdriver_ioconf_aibs,
    734  1.2.2.2  cherry 		    cfattach_ioconf_aibs, cfdata_ioconf_aibs);
    735  1.2.2.2  cherry #endif
    736  1.2.2.2  cherry 		break;
    737  1.2.2.2  cherry 
    738  1.2.2.2  cherry 	default:
    739  1.2.2.2  cherry 		rv = ENOTTY;
    740  1.2.2.2  cherry 	}
    741  1.2.2.2  cherry 
    742  1.2.2.2  cherry 	return rv;
    743  1.2.2.2  cherry }
    744