Home | History | Annotate | Line # | Download | only in acpi
acpi_util.c revision 1.4.2.4
      1  1.4.2.4  uebayasi /*	$NetBSD: acpi_util.c,v 1.4.2.4 2010/11/06 08:08:27 uebayasi Exp $ */
      2  1.4.2.2  uebayasi 
      3  1.4.2.2  uebayasi /*-
      4  1.4.2.2  uebayasi  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
      5  1.4.2.2  uebayasi  * All rights reserved.
      6  1.4.2.2  uebayasi  *
      7  1.4.2.2  uebayasi  * This code is derived from software contributed to The NetBSD Foundation
      8  1.4.2.2  uebayasi  * by Charles M. Hannum of By Noon Software, Inc.
      9  1.4.2.2  uebayasi  *
     10  1.4.2.2  uebayasi  * Redistribution and use in source and binary forms, with or without
     11  1.4.2.2  uebayasi  * modification, are permitted provided that the following conditions
     12  1.4.2.2  uebayasi  * are met:
     13  1.4.2.2  uebayasi  * 1. Redistributions of source code must retain the above copyright
     14  1.4.2.2  uebayasi  *    notice, this list of conditions and the following disclaimer.
     15  1.4.2.2  uebayasi  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.4.2.2  uebayasi  *    notice, this list of conditions and the following disclaimer in the
     17  1.4.2.2  uebayasi  *    documentation and/or other materials provided with the distribution.
     18  1.4.2.2  uebayasi  *
     19  1.4.2.2  uebayasi  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.4.2.2  uebayasi  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.4.2.2  uebayasi  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.4.2.2  uebayasi  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.4.2.2  uebayasi  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.4.2.2  uebayasi  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.4.2.2  uebayasi  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.4.2.2  uebayasi  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.4.2.2  uebayasi  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.4.2.2  uebayasi  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.4.2.2  uebayasi  * POSSIBILITY OF SUCH DAMAGE.
     30  1.4.2.2  uebayasi  */
     31  1.4.2.2  uebayasi 
     32  1.4.2.2  uebayasi /*
     33  1.4.2.2  uebayasi  * Copyright 2001, 2003 Wasabi Systems, Inc.
     34  1.4.2.2  uebayasi  * All rights reserved.
     35  1.4.2.2  uebayasi  *
     36  1.4.2.2  uebayasi  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     37  1.4.2.2  uebayasi  *
     38  1.4.2.2  uebayasi  * Redistribution and use in source and binary forms, with or without
     39  1.4.2.2  uebayasi  * modification, are permitted provided that the following conditions
     40  1.4.2.2  uebayasi  * are met:
     41  1.4.2.2  uebayasi  * 1. Redistributions of source code must retain the above copyright
     42  1.4.2.2  uebayasi  *    notice, this list of conditions and the following disclaimer.
     43  1.4.2.2  uebayasi  * 2. Redistributions in binary form must reproduce the above copyright
     44  1.4.2.2  uebayasi  *    notice, this list of conditions and the following disclaimer in the
     45  1.4.2.2  uebayasi  *    documentation and/or other materials provided with the distribution.
     46  1.4.2.2  uebayasi  * 3. All advertising materials mentioning features or use of this software
     47  1.4.2.2  uebayasi  *    must display the following acknowledgement:
     48  1.4.2.2  uebayasi  *	This product includes software developed for the NetBSD Project by
     49  1.4.2.2  uebayasi  *	Wasabi Systems, Inc.
     50  1.4.2.2  uebayasi  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     51  1.4.2.2  uebayasi  *    or promote products derived from this software without specific prior
     52  1.4.2.2  uebayasi  *    written permission.
     53  1.4.2.2  uebayasi  *
     54  1.4.2.2  uebayasi  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     55  1.4.2.2  uebayasi  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     56  1.4.2.2  uebayasi  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     57  1.4.2.2  uebayasi  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     58  1.4.2.2  uebayasi  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     59  1.4.2.2  uebayasi  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     60  1.4.2.2  uebayasi  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     61  1.4.2.2  uebayasi  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     62  1.4.2.2  uebayasi  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     63  1.4.2.2  uebayasi  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     64  1.4.2.2  uebayasi  * POSSIBILITY OF SUCH DAMAGE.
     65  1.4.2.2  uebayasi  */
     66  1.4.2.2  uebayasi 
     67  1.4.2.2  uebayasi #include <sys/cdefs.h>
     68  1.4.2.4  uebayasi __KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.4.2.4 2010/11/06 08:08:27 uebayasi Exp $");
     69  1.4.2.2  uebayasi 
     70  1.4.2.2  uebayasi #include <sys/param.h>
     71  1.4.2.2  uebayasi 
     72  1.4.2.2  uebayasi #include <dev/acpi/acpireg.h>
     73  1.4.2.2  uebayasi #include <dev/acpi/acpivar.h>
     74  1.4.2.2  uebayasi 
     75  1.4.2.2  uebayasi #define _COMPONENT		ACPI_BUS_COMPONENT
     76  1.4.2.2  uebayasi ACPI_MODULE_NAME		("acpi_util")
     77  1.4.2.2  uebayasi 
     78  1.4.2.3  uebayasi static void	acpi_clean_node(ACPI_HANDLE, void *);
     79  1.4.2.3  uebayasi 
     80  1.4.2.2  uebayasi /*
     81  1.4.2.2  uebayasi  * Evaluate an integer object.
     82  1.4.2.2  uebayasi  */
     83  1.4.2.2  uebayasi ACPI_STATUS
     84  1.4.2.2  uebayasi acpi_eval_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER *valp)
     85  1.4.2.2  uebayasi {
     86  1.4.2.2  uebayasi 	ACPI_OBJECT obj;
     87  1.4.2.2  uebayasi 	ACPI_BUFFER buf;
     88  1.4.2.2  uebayasi 	ACPI_STATUS rv;
     89  1.4.2.2  uebayasi 
     90  1.4.2.2  uebayasi 	if (handle == NULL)
     91  1.4.2.2  uebayasi 		handle = ACPI_ROOT_OBJECT;
     92  1.4.2.2  uebayasi 
     93  1.4.2.4  uebayasi 	(void)memset(&obj, 0, sizeof(obj));
     94  1.4.2.2  uebayasi 	buf.Pointer = &obj;
     95  1.4.2.2  uebayasi 	buf.Length = sizeof(obj);
     96  1.4.2.2  uebayasi 
     97  1.4.2.2  uebayasi 	rv = AcpiEvaluateObject(handle, path, NULL, &buf);
     98  1.4.2.2  uebayasi 
     99  1.4.2.2  uebayasi 	if (ACPI_FAILURE(rv))
    100  1.4.2.2  uebayasi 		return rv;
    101  1.4.2.2  uebayasi 
    102  1.4.2.4  uebayasi 	/* Check that evaluation produced a return value. */
    103  1.4.2.4  uebayasi 	if (buf.Length == 0)
    104  1.4.2.4  uebayasi 		return AE_NULL_OBJECT;
    105  1.4.2.4  uebayasi 
    106  1.4.2.2  uebayasi 	if (obj.Type != ACPI_TYPE_INTEGER)
    107  1.4.2.2  uebayasi 		return AE_TYPE;
    108  1.4.2.2  uebayasi 
    109  1.4.2.2  uebayasi 	if (valp != NULL)
    110  1.4.2.2  uebayasi 		*valp = obj.Integer.Value;
    111  1.4.2.2  uebayasi 
    112  1.4.2.2  uebayasi 	return AE_OK;
    113  1.4.2.2  uebayasi }
    114  1.4.2.2  uebayasi 
    115  1.4.2.2  uebayasi /*
    116  1.4.2.2  uebayasi  * Evaluate an integer object with a single integer input parameter.
    117  1.4.2.2  uebayasi  */
    118  1.4.2.2  uebayasi ACPI_STATUS
    119  1.4.2.2  uebayasi acpi_eval_set_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER val)
    120  1.4.2.2  uebayasi {
    121  1.4.2.2  uebayasi 	ACPI_OBJECT_LIST arg;
    122  1.4.2.2  uebayasi 	ACPI_OBJECT obj;
    123  1.4.2.2  uebayasi 
    124  1.4.2.2  uebayasi 	if (handle == NULL)
    125  1.4.2.2  uebayasi 		handle = ACPI_ROOT_OBJECT;
    126  1.4.2.2  uebayasi 
    127  1.4.2.2  uebayasi 	obj.Type = ACPI_TYPE_INTEGER;
    128  1.4.2.2  uebayasi 	obj.Integer.Value = val;
    129  1.4.2.2  uebayasi 
    130  1.4.2.2  uebayasi 	arg.Count = 1;
    131  1.4.2.2  uebayasi 	arg.Pointer = &obj;
    132  1.4.2.2  uebayasi 
    133  1.4.2.2  uebayasi 	return AcpiEvaluateObject(handle, path, &arg, NULL);
    134  1.4.2.2  uebayasi }
    135  1.4.2.2  uebayasi 
    136  1.4.2.2  uebayasi /*
    137  1.4.2.2  uebayasi  * Evaluate a (Unicode) string object.
    138  1.4.2.2  uebayasi  */
    139  1.4.2.2  uebayasi ACPI_STATUS
    140  1.4.2.2  uebayasi acpi_eval_string(ACPI_HANDLE handle, const char *path, char **stringp)
    141  1.4.2.2  uebayasi {
    142  1.4.2.2  uebayasi 	ACPI_OBJECT *obj;
    143  1.4.2.2  uebayasi 	ACPI_BUFFER buf;
    144  1.4.2.2  uebayasi 	ACPI_STATUS rv;
    145  1.4.2.2  uebayasi 
    146  1.4.2.2  uebayasi 	rv = acpi_eval_struct(handle, path, &buf);
    147  1.4.2.2  uebayasi 
    148  1.4.2.2  uebayasi 	if (ACPI_FAILURE(rv))
    149  1.4.2.2  uebayasi 		return rv;
    150  1.4.2.2  uebayasi 
    151  1.4.2.2  uebayasi 	obj = buf.Pointer;
    152  1.4.2.2  uebayasi 
    153  1.4.2.2  uebayasi 	if (obj->Type != ACPI_TYPE_STRING) {
    154  1.4.2.2  uebayasi 		rv = AE_TYPE;
    155  1.4.2.2  uebayasi 		goto out;
    156  1.4.2.2  uebayasi 	}
    157  1.4.2.2  uebayasi 
    158  1.4.2.2  uebayasi 	if (obj->String.Length == 0) {
    159  1.4.2.2  uebayasi 		rv = AE_BAD_DATA;
    160  1.4.2.2  uebayasi 		goto out;
    161  1.4.2.2  uebayasi 	}
    162  1.4.2.2  uebayasi 
    163  1.4.2.2  uebayasi 	*stringp = ACPI_ALLOCATE(obj->String.Length + 1);
    164  1.4.2.2  uebayasi 
    165  1.4.2.2  uebayasi 	if (*stringp == NULL) {
    166  1.4.2.2  uebayasi 		rv = AE_NO_MEMORY;
    167  1.4.2.2  uebayasi 		goto out;
    168  1.4.2.2  uebayasi 	}
    169  1.4.2.2  uebayasi 
    170  1.4.2.2  uebayasi 	(void)memcpy(*stringp, obj->String.Pointer, obj->String.Length);
    171  1.4.2.2  uebayasi 
    172  1.4.2.2  uebayasi 	(*stringp)[obj->String.Length] = '\0';
    173  1.4.2.2  uebayasi 
    174  1.4.2.2  uebayasi out:
    175  1.4.2.2  uebayasi 	ACPI_FREE(buf.Pointer);
    176  1.4.2.2  uebayasi 
    177  1.4.2.2  uebayasi 	return rv;
    178  1.4.2.2  uebayasi }
    179  1.4.2.2  uebayasi 
    180  1.4.2.2  uebayasi /*
    181  1.4.2.2  uebayasi  * Evaluate a structure. Caller must free buf.Pointer by ACPI_FREE().
    182  1.4.2.2  uebayasi  */
    183  1.4.2.2  uebayasi ACPI_STATUS
    184  1.4.2.2  uebayasi acpi_eval_struct(ACPI_HANDLE handle, const char *path, ACPI_BUFFER *buf)
    185  1.4.2.2  uebayasi {
    186  1.4.2.2  uebayasi 
    187  1.4.2.2  uebayasi 	if (handle == NULL)
    188  1.4.2.2  uebayasi 		handle = ACPI_ROOT_OBJECT;
    189  1.4.2.2  uebayasi 
    190  1.4.2.2  uebayasi 	buf->Pointer = NULL;
    191  1.4.2.2  uebayasi 	buf->Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    192  1.4.2.2  uebayasi 
    193  1.4.2.2  uebayasi 	return AcpiEvaluateObject(handle, path, NULL, buf);
    194  1.4.2.2  uebayasi }
    195  1.4.2.2  uebayasi 
    196  1.4.2.2  uebayasi /*
    197  1.4.2.2  uebayasi  * Evaluate a reference handle from an element in a package.
    198  1.4.2.2  uebayasi  */
    199  1.4.2.2  uebayasi ACPI_STATUS
    200  1.4.2.2  uebayasi acpi_eval_reference_handle(ACPI_OBJECT *elm, ACPI_HANDLE *handle)
    201  1.4.2.2  uebayasi {
    202  1.4.2.2  uebayasi 
    203  1.4.2.2  uebayasi 	if (elm == NULL || handle == NULL)
    204  1.4.2.2  uebayasi 		return AE_BAD_PARAMETER;
    205  1.4.2.2  uebayasi 
    206  1.4.2.2  uebayasi 	switch (elm->Type) {
    207  1.4.2.2  uebayasi 
    208  1.4.2.2  uebayasi 	case ACPI_TYPE_ANY:
    209  1.4.2.2  uebayasi 	case ACPI_TYPE_LOCAL_REFERENCE:
    210  1.4.2.2  uebayasi 
    211  1.4.2.2  uebayasi 		if (elm->Reference.Handle == NULL)
    212  1.4.2.2  uebayasi 			return AE_NULL_ENTRY;
    213  1.4.2.2  uebayasi 
    214  1.4.2.2  uebayasi 		*handle = elm->Reference.Handle;
    215  1.4.2.2  uebayasi 
    216  1.4.2.2  uebayasi 		return AE_OK;
    217  1.4.2.2  uebayasi 
    218  1.4.2.2  uebayasi 	case ACPI_TYPE_STRING:
    219  1.4.2.2  uebayasi 		return AcpiGetHandle(NULL, elm->String.Pointer, handle);
    220  1.4.2.2  uebayasi 
    221  1.4.2.2  uebayasi 	default:
    222  1.4.2.2  uebayasi 		return AE_TYPE;
    223  1.4.2.2  uebayasi 	}
    224  1.4.2.2  uebayasi }
    225  1.4.2.2  uebayasi 
    226  1.4.2.2  uebayasi /*
    227  1.4.2.2  uebayasi  * Iterate over all objects in a package, and pass them all
    228  1.4.2.2  uebayasi  * to a function. If the called function returns non-AE_OK,
    229  1.4.2.2  uebayasi  * the iteration is stopped and that value is returned.
    230  1.4.2.2  uebayasi  */
    231  1.4.2.2  uebayasi ACPI_STATUS
    232  1.4.2.2  uebayasi acpi_foreach_package_object(ACPI_OBJECT *pkg,
    233  1.4.2.2  uebayasi     ACPI_STATUS (*func)(ACPI_OBJECT *, void *), void *arg)
    234  1.4.2.2  uebayasi {
    235  1.4.2.2  uebayasi 	ACPI_STATUS rv = AE_OK;
    236  1.4.2.2  uebayasi 	uint32_t i;
    237  1.4.2.2  uebayasi 
    238  1.4.2.2  uebayasi 	if (pkg == NULL)
    239  1.4.2.2  uebayasi 		return AE_BAD_PARAMETER;
    240  1.4.2.2  uebayasi 
    241  1.4.2.2  uebayasi 	if (pkg->Type != ACPI_TYPE_PACKAGE)
    242  1.4.2.2  uebayasi 		return AE_TYPE;
    243  1.4.2.2  uebayasi 
    244  1.4.2.2  uebayasi 	for (i = 0; i < pkg->Package.Count; i++) {
    245  1.4.2.2  uebayasi 
    246  1.4.2.2  uebayasi 		rv = (*func)(&pkg->Package.Elements[i], arg);
    247  1.4.2.2  uebayasi 
    248  1.4.2.2  uebayasi 		if (ACPI_FAILURE(rv))
    249  1.4.2.2  uebayasi 			break;
    250  1.4.2.2  uebayasi 	}
    251  1.4.2.2  uebayasi 
    252  1.4.2.2  uebayasi 	return rv;
    253  1.4.2.2  uebayasi }
    254  1.4.2.2  uebayasi 
    255  1.4.2.2  uebayasi /*
    256  1.4.2.2  uebayasi  * Fetch data info the specified (empty) ACPI buffer.
    257  1.4.2.2  uebayasi  * Caller must free buf.Pointer by ACPI_FREE().
    258  1.4.2.2  uebayasi  */
    259  1.4.2.2  uebayasi ACPI_STATUS
    260  1.4.2.2  uebayasi acpi_get(ACPI_HANDLE handle, ACPI_BUFFER *buf,
    261  1.4.2.2  uebayasi     ACPI_STATUS (*getit)(ACPI_HANDLE, ACPI_BUFFER *))
    262  1.4.2.2  uebayasi {
    263  1.4.2.2  uebayasi 
    264  1.4.2.2  uebayasi 	buf->Pointer = NULL;
    265  1.4.2.2  uebayasi 	buf->Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    266  1.4.2.2  uebayasi 
    267  1.4.2.2  uebayasi 	return (*getit)(handle, buf);
    268  1.4.2.2  uebayasi }
    269  1.4.2.2  uebayasi 
    270  1.4.2.2  uebayasi /*
    271  1.4.2.2  uebayasi  * Get a device node from a handle.
    272  1.4.2.2  uebayasi  */
    273  1.4.2.2  uebayasi struct acpi_devnode *
    274  1.4.2.2  uebayasi acpi_get_node(ACPI_HANDLE handle)
    275  1.4.2.2  uebayasi {
    276  1.4.2.2  uebayasi 	struct acpi_devnode *ad;
    277  1.4.2.3  uebayasi 	ACPI_STATUS rv;
    278  1.4.2.2  uebayasi 
    279  1.4.2.3  uebayasi 	if (handle == NULL)
    280  1.4.2.2  uebayasi 		return NULL;
    281  1.4.2.2  uebayasi 
    282  1.4.2.3  uebayasi 	rv = AcpiGetData(handle, acpi_clean_node, (void **)&ad);
    283  1.4.2.2  uebayasi 
    284  1.4.2.3  uebayasi 	if (ACPI_FAILURE(rv))
    285  1.4.2.3  uebayasi 		return NULL;
    286  1.4.2.3  uebayasi 
    287  1.4.2.3  uebayasi 	return ad;
    288  1.4.2.3  uebayasi }
    289  1.4.2.2  uebayasi 
    290  1.4.2.3  uebayasi /*
    291  1.4.2.3  uebayasi  * Associate a device node with a handle.
    292  1.4.2.3  uebayasi  */
    293  1.4.2.3  uebayasi void
    294  1.4.2.3  uebayasi acpi_set_node(struct acpi_devnode *ad)
    295  1.4.2.3  uebayasi {
    296  1.4.2.2  uebayasi 
    297  1.4.2.3  uebayasi 	(void)AcpiAttachData(ad->ad_handle, acpi_clean_node, ad);
    298  1.4.2.3  uebayasi }
    299  1.4.2.3  uebayasi 
    300  1.4.2.3  uebayasi static void
    301  1.4.2.3  uebayasi acpi_clean_node(ACPI_HANDLE handle, void *aux)
    302  1.4.2.3  uebayasi {
    303  1.4.2.3  uebayasi 	/* Nothing. */
    304  1.4.2.2  uebayasi }
    305  1.4.2.2  uebayasi 
    306  1.4.2.2  uebayasi /*
    307  1.4.2.2  uebayasi  * Return a complete pathname from a handle.
    308  1.4.2.2  uebayasi  *
    309  1.4.2.2  uebayasi  * Note that the function uses static data storage;
    310  1.4.2.2  uebayasi  * if the data is needed for future use, it should be
    311  1.4.2.2  uebayasi  * copied before any subsequent calls overwrite it.
    312  1.4.2.2  uebayasi  */
    313  1.4.2.2  uebayasi const char *
    314  1.4.2.2  uebayasi acpi_name(ACPI_HANDLE handle)
    315  1.4.2.2  uebayasi {
    316  1.4.2.2  uebayasi 	static char name[80];
    317  1.4.2.2  uebayasi 	ACPI_BUFFER buf;
    318  1.4.2.2  uebayasi 	ACPI_STATUS rv;
    319  1.4.2.2  uebayasi 
    320  1.4.2.2  uebayasi 	if (handle == NULL)
    321  1.4.2.2  uebayasi 		handle = ACPI_ROOT_OBJECT;
    322  1.4.2.2  uebayasi 
    323  1.4.2.2  uebayasi 	buf.Pointer = name;
    324  1.4.2.2  uebayasi 	buf.Length = sizeof(name);
    325  1.4.2.2  uebayasi 
    326  1.4.2.2  uebayasi 	rv = AcpiGetName(handle, ACPI_FULL_PATHNAME, &buf);
    327  1.4.2.2  uebayasi 
    328  1.4.2.2  uebayasi 	if (ACPI_FAILURE(rv))
    329  1.4.2.2  uebayasi 		return "UNKNOWN";
    330  1.4.2.2  uebayasi 
    331  1.4.2.2  uebayasi 	return name;
    332  1.4.2.2  uebayasi }
    333  1.4.2.2  uebayasi 
    334  1.4.2.2  uebayasi /*
    335  1.4.2.2  uebayasi  * Match given IDs against _HID and _CIDs.
    336  1.4.2.2  uebayasi  */
    337  1.4.2.2  uebayasi int
    338  1.4.2.2  uebayasi acpi_match_hid(ACPI_DEVICE_INFO *ad, const char * const *ids)
    339  1.4.2.2  uebayasi {
    340  1.4.2.2  uebayasi 	uint32_t i, n;
    341  1.4.2.2  uebayasi 	char *id;
    342  1.4.2.2  uebayasi 
    343  1.4.2.2  uebayasi 	while (*ids) {
    344  1.4.2.2  uebayasi 
    345  1.4.2.2  uebayasi 		if ((ad->Valid & ACPI_VALID_HID) != 0) {
    346  1.4.2.2  uebayasi 
    347  1.4.2.2  uebayasi 			if (pmatch(ad->HardwareId.String, *ids, NULL) == 2)
    348  1.4.2.2  uebayasi 				return 1;
    349  1.4.2.2  uebayasi 		}
    350  1.4.2.2  uebayasi 
    351  1.4.2.2  uebayasi 		if ((ad->Valid & ACPI_VALID_CID) != 0) {
    352  1.4.2.2  uebayasi 
    353  1.4.2.2  uebayasi 			n = ad->CompatibleIdList.Count;
    354  1.4.2.2  uebayasi 
    355  1.4.2.2  uebayasi 			for (i = 0; i < n; i++) {
    356  1.4.2.2  uebayasi 
    357  1.4.2.2  uebayasi 				id = ad->CompatibleIdList.Ids[i].String;
    358  1.4.2.2  uebayasi 
    359  1.4.2.2  uebayasi 				if (pmatch(id, *ids, NULL) == 2)
    360  1.4.2.2  uebayasi 					return 1;
    361  1.4.2.2  uebayasi 			}
    362  1.4.2.2  uebayasi 		}
    363  1.4.2.2  uebayasi 
    364  1.4.2.2  uebayasi 		ids++;
    365  1.4.2.2  uebayasi 	}
    366  1.4.2.2  uebayasi 
    367  1.4.2.2  uebayasi 	return 0;
    368  1.4.2.2  uebayasi }
    369  1.4.2.2  uebayasi 
    370