Home | History | Annotate | Line # | Download | only in acpi
acpi_resource.c revision 1.12
      1  1.12     kochi /*	$NetBSD: acpi_resource.c,v 1.12 2004/04/11 08:36:19 kochi 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  * Copyright (c) 2000 Michael Smith
     40   1.1   thorpej  * Copyright (c) 2000 BSDi
     41   1.1   thorpej  * All rights reserved.
     42   1.1   thorpej  *
     43   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     44   1.1   thorpej  * modification, are permitted provided that the following conditions
     45   1.1   thorpej  * are met:
     46   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     47   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     48   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     50   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     51  1.10     kochi  *
     52   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     53   1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54   1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  1.10     kochi  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     56   1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57   1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58   1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59   1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60   1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61   1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  1.10     kochi  * SUCH DAMAGE.
     63   1.1   thorpej  */
     64   1.1   thorpej 
     65   1.1   thorpej /*
     66   1.1   thorpej  * ACPI resource parsing.
     67   1.1   thorpej  */
     68   1.2     lukem 
     69   1.2     lukem #include <sys/cdefs.h>
     70  1.12     kochi __KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.12 2004/04/11 08:36:19 kochi Exp $");
     71   1.1   thorpej 
     72   1.1   thorpej #include <sys/param.h>
     73   1.1   thorpej #include <sys/systm.h>
     74   1.1   thorpej #include <sys/device.h>
     75   1.1   thorpej 
     76   1.1   thorpej #include <dev/acpi/acpica.h>
     77   1.1   thorpej #include <dev/acpi/acpireg.h>
     78   1.1   thorpej #include <dev/acpi/acpivar.h>
     79   1.1   thorpej 
     80   1.4   thorpej #define	_COMPONENT	ACPI_RESOURCE_COMPONENT
     81   1.4   thorpej ACPI_MODULE_NAME("RESOURCE")
     82   1.1   thorpej 
     83  1.12     kochi struct resource_parse_callback_arg {
     84  1.12     kochi 	const struct acpi_resource_parse_ops *ops;
     85  1.12     kochi 	struct device *dev;
     86  1.12     kochi 	void *context;
     87  1.12     kochi };
     88  1.12     kochi 
     89  1.12     kochi static ACPI_STATUS
     90  1.12     kochi acpi_resource_parse_callback(ACPI_RESOURCE *res, void *context)
     91   1.1   thorpej {
     92  1.12     kochi 	struct resource_parse_callback_arg *arg = context;
     93  1.12     kochi 	const struct acpi_resource_parse_ops *ops;
     94   1.1   thorpej 	int i;
     95   1.1   thorpej 
     96  1.12     kochi 	ops = arg->ops;
     97   1.1   thorpej 
     98  1.12     kochi 	switch (res->Id) {
     99  1.12     kochi 	case ACPI_RSTYPE_FIXED_IO:
    100  1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    101  1.12     kochi 				     "FixedIo 0x%x/%d\n",
    102  1.12     kochi 				     res->Data.FixedIo.BaseAddress,
    103  1.12     kochi 				     res->Data.FixedIo.RangeLength));
    104  1.12     kochi 		(*ops->ioport)(arg->dev, arg->context,
    105  1.12     kochi 		    res->Data.FixedIo.BaseAddress,
    106  1.12     kochi 		    res->Data.FixedIo.RangeLength);
    107  1.12     kochi 		break;
    108   1.1   thorpej 
    109  1.12     kochi 	case ACPI_RSTYPE_IO:
    110  1.12     kochi 		if (res->Data.Io.MinBaseAddress ==
    111   1.1   thorpej 			    res->Data.Io.MaxBaseAddress) {
    112   1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    113  1.12     kochi 					     "Io 0x%x/%d\n",
    114  1.12     kochi 					     res->Data.Io.MinBaseAddress,
    115  1.12     kochi 					     res->Data.Io.RangeLength));
    116  1.12     kochi 			(*ops->ioport)(arg->dev, arg->context,
    117  1.12     kochi 			    res->Data.Io.MinBaseAddress,
    118  1.12     kochi 			    res->Data.Io.RangeLength);
    119  1.12     kochi 		} else {
    120   1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    121  1.12     kochi 					     "Io 0x%x-0x%x/%d\n",
    122  1.12     kochi 					     res->Data.Io.MinBaseAddress,
    123  1.12     kochi 					     res->Data.Io.MaxBaseAddress,
    124  1.12     kochi 					     res->Data.Io.RangeLength));
    125  1.12     kochi 			(*ops->iorange)(arg->dev, arg->context,
    126  1.12     kochi 			    res->Data.Io.MinBaseAddress,
    127  1.12     kochi 			    res->Data.Io.MaxBaseAddress,
    128  1.12     kochi 			    res->Data.Io.RangeLength,
    129  1.12     kochi 			    res->Data.Io.Alignment);
    130  1.12     kochi 		}
    131  1.12     kochi 		break;
    132   1.1   thorpej 
    133  1.12     kochi 	case ACPI_RSTYPE_FIXED_MEM32:
    134  1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    135  1.12     kochi 				     "FixedMemory32 0x%x/%d\n",
    136  1.12     kochi 				     res->Data.FixedMemory32.RangeBaseAddress,
    137  1.12     kochi 				     res->Data.FixedMemory32.RangeLength));
    138  1.12     kochi 		(*ops->memory)(arg->dev, arg->context,
    139  1.12     kochi 		    res->Data.FixedMemory32.RangeBaseAddress,
    140  1.12     kochi 		    res->Data.FixedMemory32.RangeLength);
    141  1.12     kochi 		break;
    142  1.12     kochi 
    143  1.12     kochi 	case ACPI_RSTYPE_MEM32:
    144  1.12     kochi 		if (res->Data.Memory32.MinBaseAddress ==
    145  1.12     kochi 		    res->Data.Memory32.MaxBaseAddress) {
    146   1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    147  1.12     kochi 					     "Memory32 0x%x/%d\n",
    148  1.12     kochi 					     res->Data.Memory32.MinBaseAddress,
    149  1.12     kochi 					     res->Data.Memory32.RangeLength));
    150  1.12     kochi 			(*ops->memory)(arg->dev, arg->context,
    151  1.12     kochi 			    res->Data.Memory32.MinBaseAddress,
    152  1.12     kochi 			    res->Data.Memory32.RangeLength);
    153  1.12     kochi 		} else {
    154   1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    155  1.12     kochi 					     "Memory32 0x%x-0x%x/%d\n",
    156  1.12     kochi 					     res->Data.Memory32.MinBaseAddress,
    157  1.12     kochi 					     res->Data.Memory32.MaxBaseAddress,
    158  1.12     kochi 					     res->Data.Memory32.RangeLength));
    159  1.12     kochi 			(*ops->memrange)(arg->dev, arg->context,
    160  1.12     kochi 			    res->Data.Memory32.MinBaseAddress,
    161  1.12     kochi 			    res->Data.Memory32.MaxBaseAddress,
    162  1.12     kochi 			    res->Data.Memory32.RangeLength,
    163  1.12     kochi 			    res->Data.Memory32.Alignment);
    164  1.12     kochi 		}
    165  1.12     kochi 		break;
    166   1.1   thorpej 
    167  1.12     kochi 	case ACPI_RSTYPE_MEM24:
    168  1.12     kochi 		if (res->Data.Memory24.MinBaseAddress ==
    169  1.12     kochi 		    res->Data.Memory24.MaxBaseAddress) {
    170   1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    171  1.12     kochi 					     "Memory24 0x%x/%d\n",
    172  1.12     kochi 					     res->Data.Memory24.MinBaseAddress,
    173  1.12     kochi 					     res->Data.Memory24.RangeLength));
    174  1.12     kochi 			(*ops->memory)(arg->dev, arg->context,
    175  1.12     kochi 			    res->Data.Memory24.MinBaseAddress,
    176  1.12     kochi 			    res->Data.Memory24.RangeLength);
    177  1.12     kochi 		} else {
    178   1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    179  1.12     kochi 					     "Memory24 0x%x-0x%x/%d\n",
    180  1.12     kochi 					     res->Data.Memory24.MinBaseAddress,
    181  1.12     kochi 					     res->Data.Memory24.MaxBaseAddress,
    182  1.12     kochi 					     res->Data.Memory24.RangeLength));
    183  1.12     kochi 			(*ops->memrange)(arg->dev, arg->context,
    184  1.12     kochi 			    res->Data.Memory24.MinBaseAddress,
    185  1.12     kochi 			    res->Data.Memory24.MaxBaseAddress,
    186  1.12     kochi 			    res->Data.Memory24.RangeLength,
    187  1.12     kochi 			    res->Data.Memory24.Alignment);
    188  1.12     kochi 		}
    189  1.12     kochi 		break;
    190   1.1   thorpej 
    191  1.12     kochi 	case ACPI_RSTYPE_IRQ:
    192  1.12     kochi 		for (i = 0; i < res->Data.Irq.NumberOfInterrupts; i++) {
    193   1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    194  1.12     kochi 					     "IRQ %d\n",
    195  1.12     kochi 					     res->Data.Irq.Interrupts[i]));
    196  1.12     kochi 			(*ops->irq)(arg->dev, arg->context,
    197  1.12     kochi 			    res->Data.Irq.Interrupts[i],
    198  1.12     kochi 			    res->Data.Irq.EdgeLevel);
    199  1.12     kochi 		}
    200  1.12     kochi 		break;
    201   1.1   thorpej 
    202  1.12     kochi 	case ACPI_RSTYPE_DMA:
    203  1.12     kochi 		for (i = 0; i < res->Data.Dma.NumberOfChannels; i++) {
    204   1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    205  1.12     kochi 					     "DRQ %d\n",
    206  1.12     kochi 					     res->Data.Dma.Channels[i]));
    207  1.12     kochi 			(*ops->drq)(arg->dev, arg->context,
    208  1.12     kochi 			    res->Data.Dma.Channels[i]);
    209   1.1   thorpej 		}
    210  1.12     kochi 		break;
    211  1.12     kochi 
    212  1.12     kochi 	case ACPI_RSTYPE_START_DPF:
    213  1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    214  1.12     kochi 				     "Start dependant functions: %d\n",
    215  1.12     kochi 				     res->Data.StartDpf.CompatibilityPriority));
    216  1.12     kochi 		(*ops->start_dep)(arg->dev, arg->context,
    217  1.12     kochi 		    res->Data.StartDpf.CompatibilityPriority);
    218  1.12     kochi 		break;
    219  1.12     kochi 
    220  1.12     kochi 	case ACPI_RSTYPE_END_DPF:
    221  1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    222  1.12     kochi 				     "End dependant functions\n"));
    223  1.12     kochi 		(*ops->end_dep)(arg->dev, arg->context);
    224  1.12     kochi 
    225  1.12     kochi 	case ACPI_RSTYPE_ADDRESS32:
    226  1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    227  1.12     kochi 				     "Address32 unimplemented\n"));
    228  1.12     kochi 		break;
    229  1.12     kochi 
    230  1.12     kochi 	case ACPI_RSTYPE_ADDRESS16:
    231  1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    232  1.12     kochi 				     "Address16 unimplemented\n"));
    233  1.12     kochi 		break;
    234  1.12     kochi 
    235  1.12     kochi 	case ACPI_RSTYPE_EXT_IRQ:
    236  1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    237  1.12     kochi 				     "ExtendedIrq unimplemented\n"));
    238  1.12     kochi 		break;
    239  1.12     kochi 
    240  1.12     kochi 	case ACPI_RSTYPE_VENDOR:
    241  1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    242  1.12     kochi 				     "VendorSpecific unimplemented\n"));
    243  1.12     kochi 		break;
    244  1.12     kochi 
    245  1.12     kochi 	default:
    246  1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    247  1.12     kochi 				     "Unknown resource type: %d\n", res->Id));
    248  1.12     kochi 		break;
    249  1.12     kochi 	}
    250  1.12     kochi 
    251  1.12     kochi 	return AE_OK;
    252  1.12     kochi }
    253  1.12     kochi 
    254  1.12     kochi 
    255  1.12     kochi /*
    256  1.12     kochi  * acpi_resource_parse:
    257  1.12     kochi  *
    258  1.12     kochi  *	Parse a device node's resources and fill them in for the
    259  1.12     kochi  *	client.
    260  1.12     kochi  *
    261  1.12     kochi  *	This API supports _CRS (current resources) and
    262  1.12     kochi  *	_PRS (possible resources).
    263  1.12     kochi  *
    264  1.12     kochi  *	Note that it might be nice to also locate ACPI-specific resource
    265  1.12     kochi  *	items, such as GPE bits.
    266  1.12     kochi  */
    267  1.12     kochi ACPI_STATUS
    268  1.12     kochi acpi_resource_parse(struct device *dev, ACPI_HANDLE handle, char *path,
    269  1.12     kochi     void *arg, const struct acpi_resource_parse_ops *ops)
    270  1.12     kochi {
    271  1.12     kochi 	struct resource_parse_callback_arg cbarg;
    272  1.12     kochi 	ACPI_STATUS rv;
    273  1.12     kochi 
    274  1.12     kochi 	ACPI_FUNCTION_TRACE(__FUNCTION__);
    275  1.12     kochi 
    276  1.12     kochi 	(*ops->init)(dev, arg, &cbarg.context);
    277  1.12     kochi 	cbarg.ops = ops;
    278  1.12     kochi 	cbarg.dev = dev;
    279  1.12     kochi 
    280  1.12     kochi 	rv =AcpiWalkResources(handle, path, acpi_resource_parse_callback,
    281  1.12     kochi 	    &cbarg);
    282  1.12     kochi 	if (ACPI_FAILURE(rv)) {
    283  1.12     kochi 		printf("%s: ACPI: unable to get %s resources: %s\n",
    284  1.12     kochi 		    dev->dv_xname, path, AcpiFormatException(rv));
    285  1.12     kochi 		return_ACPI_STATUS(rv);
    286   1.1   thorpej 	}
    287   1.1   thorpej 
    288  1.12     kochi 	(*ops->fini)(dev, cbarg.context);
    289   1.1   thorpej 
    290   1.1   thorpej 	return_ACPI_STATUS(AE_OK);
    291   1.1   thorpej }
    292   1.1   thorpej 
    293   1.1   thorpej /*
    294   1.1   thorpej  * acpi_resource_print:
    295   1.1   thorpej  *
    296   1.1   thorpej  *	Print the resources assigned to a device.
    297   1.1   thorpej  */
    298   1.1   thorpej void
    299   1.1   thorpej acpi_resource_print(struct device *dev, struct acpi_resources *res)
    300   1.1   thorpej {
    301   1.1   thorpej 	const char *sep;
    302   1.1   thorpej 
    303   1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_io) &&
    304   1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_iorange) &&
    305   1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_mem) &&
    306   1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_memrange) &&
    307   1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_irq) &&
    308   1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_drq))
    309   1.1   thorpej 		return;
    310   1.1   thorpej 
    311   1.1   thorpej 	printf("%s:", dev->dv_xname);
    312   1.1   thorpej 
    313   1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_io) == 0) {
    314   1.1   thorpej 		struct acpi_io *ar;
    315   1.1   thorpej 
    316   1.1   thorpej 		sep = "";
    317   1.1   thorpej 		printf(" io ");
    318   1.3     lukem 		SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
    319   1.1   thorpej 			printf("%s0x%x", sep, ar->ar_base);
    320   1.1   thorpej 			if (ar->ar_length > 1)
    321   1.1   thorpej 				printf("-0x%x", ar->ar_base +
    322   1.1   thorpej 				    ar->ar_length - 1);
    323   1.1   thorpej 			sep = ",";
    324   1.1   thorpej 		}
    325   1.1   thorpej 	}
    326   1.1   thorpej 
    327   1.1   thorpej 	/* XXX iorange */
    328   1.1   thorpej 
    329   1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_mem) == 0) {
    330   1.1   thorpej 		struct acpi_mem *ar;
    331   1.1   thorpej 
    332   1.1   thorpej 		sep = "";
    333   1.1   thorpej 		printf(" mem ");
    334   1.3     lukem 		SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
    335   1.1   thorpej 			printf("%s0x%x", sep, ar->ar_base);
    336   1.1   thorpej 			if (ar->ar_length > 1)
    337   1.1   thorpej 				printf("-0x%x", ar->ar_base +
    338   1.1   thorpej 				    ar->ar_length - 1);
    339   1.1   thorpej 			sep = ",";
    340   1.1   thorpej 		}
    341   1.1   thorpej 	}
    342   1.1   thorpej 
    343   1.1   thorpej 	/* XXX memrange */
    344   1.1   thorpej 
    345   1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_irq) == 0) {
    346   1.1   thorpej 		struct acpi_irq *ar;
    347   1.1   thorpej 
    348   1.1   thorpej 		sep = "";
    349   1.1   thorpej 		printf(" irq ");
    350   1.3     lukem 		SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
    351   1.1   thorpej 			printf("%s%d", sep, ar->ar_irq);
    352   1.1   thorpej 			sep = ",";
    353   1.1   thorpej 		}
    354   1.1   thorpej 	}
    355   1.1   thorpej 
    356   1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_drq) == 0) {
    357   1.1   thorpej 		struct acpi_drq *ar;
    358   1.1   thorpej 
    359   1.1   thorpej 		sep = "";
    360   1.1   thorpej 		printf(" drq ");
    361   1.3     lukem 		SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
    362   1.1   thorpej 			printf("%s%d", sep, ar->ar_drq);
    363   1.1   thorpej 			sep = ",";
    364   1.1   thorpej 		}
    365   1.1   thorpej 	}
    366   1.1   thorpej 
    367   1.1   thorpej 	printf("\n");
    368   1.1   thorpej }
    369   1.1   thorpej 
    370   1.1   thorpej struct acpi_io *
    371   1.1   thorpej acpi_res_io(struct acpi_resources *res, int idx)
    372   1.1   thorpej {
    373   1.1   thorpej 	struct acpi_io *ar;
    374   1.1   thorpej 
    375   1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
    376   1.1   thorpej 		if (ar->ar_index == idx)
    377  1.11     kochi 			return ar;
    378   1.1   thorpej 	}
    379  1.11     kochi 	return NULL;
    380   1.1   thorpej }
    381   1.1   thorpej 
    382   1.1   thorpej struct acpi_iorange *
    383   1.1   thorpej acpi_res_iorange(struct acpi_resources *res, int idx)
    384   1.1   thorpej {
    385   1.1   thorpej 	struct acpi_iorange *ar;
    386   1.1   thorpej 
    387   1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_iorange, ar_list) {
    388   1.1   thorpej 		if (ar->ar_index == idx)
    389  1.11     kochi 			return ar;
    390   1.1   thorpej 	}
    391  1.11     kochi 	return NULL;
    392   1.1   thorpej }
    393   1.1   thorpej 
    394   1.1   thorpej struct acpi_mem *
    395   1.1   thorpej acpi_res_mem(struct acpi_resources *res, int idx)
    396   1.1   thorpej {
    397   1.1   thorpej 	struct acpi_mem *ar;
    398   1.1   thorpej 
    399   1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
    400   1.1   thorpej 		if (ar->ar_index == idx)
    401  1.11     kochi 			return ar;
    402   1.1   thorpej 	}
    403  1.11     kochi 	return NULL;
    404   1.1   thorpej }
    405   1.1   thorpej 
    406   1.1   thorpej struct acpi_memrange *
    407   1.1   thorpej acpi_res_memrange(struct acpi_resources *res, int idx)
    408   1.1   thorpej {
    409   1.1   thorpej 	struct acpi_memrange *ar;
    410   1.1   thorpej 
    411   1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_memrange, ar_list) {
    412   1.1   thorpej 		if (ar->ar_index == idx)
    413  1.11     kochi 			return ar;
    414   1.1   thorpej 	}
    415  1.11     kochi 	return NULL;
    416   1.1   thorpej }
    417   1.1   thorpej 
    418   1.1   thorpej struct acpi_irq *
    419   1.1   thorpej acpi_res_irq(struct acpi_resources *res, int idx)
    420   1.1   thorpej {
    421   1.1   thorpej 	struct acpi_irq *ar;
    422   1.1   thorpej 
    423   1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
    424   1.1   thorpej 		if (ar->ar_index == idx)
    425  1.11     kochi 			return ar;
    426   1.1   thorpej 	}
    427  1.11     kochi 	return NULL;
    428   1.1   thorpej }
    429   1.1   thorpej 
    430   1.1   thorpej struct acpi_drq *
    431   1.1   thorpej acpi_res_drq(struct acpi_resources *res, int idx)
    432   1.1   thorpej {
    433   1.1   thorpej 	struct acpi_drq *ar;
    434   1.1   thorpej 
    435   1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
    436   1.1   thorpej 		if (ar->ar_index == idx)
    437  1.11     kochi 			return ar;
    438   1.1   thorpej 	}
    439  1.11     kochi 	return NULL;
    440   1.1   thorpej }
    441   1.1   thorpej 
    442   1.1   thorpej /*****************************************************************************
    443   1.1   thorpej  * Default ACPI resource parse operations.
    444   1.1   thorpej  *****************************************************************************/
    445   1.1   thorpej 
    446   1.1   thorpej static void	acpi_res_parse_init(struct device *, void *, void **);
    447   1.1   thorpej static void	acpi_res_parse_fini(struct device *, void *);
    448   1.1   thorpej 
    449   1.1   thorpej static void	acpi_res_parse_ioport(struct device *, void *, uint32_t,
    450   1.1   thorpej 		    uint32_t);
    451   1.1   thorpej static void	acpi_res_parse_iorange(struct device *, void *, uint32_t,
    452   1.1   thorpej 		    uint32_t, uint32_t, uint32_t);
    453   1.1   thorpej 
    454   1.1   thorpej static void	acpi_res_parse_memory(struct device *, void *, uint32_t,
    455   1.1   thorpej 		    uint32_t);
    456   1.1   thorpej static void	acpi_res_parse_memrange(struct device *, void *, uint32_t,
    457   1.1   thorpej 		    uint32_t, uint32_t, uint32_t);
    458   1.1   thorpej 
    459   1.5      matt static void	acpi_res_parse_irq(struct device *, void *, uint32_t, uint32_t);
    460   1.1   thorpej static void	acpi_res_parse_drq(struct device *, void *, uint32_t);
    461   1.1   thorpej 
    462   1.1   thorpej static void	acpi_res_parse_start_dep(struct device *, void *, int);
    463   1.1   thorpej static void	acpi_res_parse_end_dep(struct device *, void *);
    464   1.1   thorpej 
    465   1.1   thorpej const struct acpi_resource_parse_ops acpi_resource_parse_ops_default = {
    466   1.1   thorpej 	acpi_res_parse_init,
    467   1.1   thorpej 	acpi_res_parse_fini,
    468   1.1   thorpej 
    469   1.1   thorpej 	acpi_res_parse_ioport,
    470   1.1   thorpej 	acpi_res_parse_iorange,
    471   1.1   thorpej 
    472   1.1   thorpej 	acpi_res_parse_memory,
    473   1.1   thorpej 	acpi_res_parse_memrange,
    474   1.1   thorpej 
    475   1.1   thorpej 	acpi_res_parse_irq,
    476   1.1   thorpej 	acpi_res_parse_drq,
    477   1.1   thorpej 
    478   1.1   thorpej 	acpi_res_parse_start_dep,
    479   1.1   thorpej 	acpi_res_parse_end_dep,
    480   1.1   thorpej };
    481   1.1   thorpej 
    482   1.1   thorpej static void
    483   1.1   thorpej acpi_res_parse_init(struct device *dev, void *arg, void **contextp)
    484   1.1   thorpej {
    485   1.1   thorpej 	struct acpi_resources *res = arg;
    486   1.1   thorpej 
    487   1.1   thorpej 	SIMPLEQ_INIT(&res->ar_io);
    488   1.1   thorpej 	res->ar_nio = 0;
    489   1.1   thorpej 
    490   1.1   thorpej 	SIMPLEQ_INIT(&res->ar_iorange);
    491   1.1   thorpej 	res->ar_niorange = 0;
    492   1.1   thorpej 
    493   1.1   thorpej 	SIMPLEQ_INIT(&res->ar_mem);
    494   1.1   thorpej 	res->ar_nmem = 0;
    495   1.1   thorpej 
    496   1.1   thorpej 	SIMPLEQ_INIT(&res->ar_memrange);
    497   1.1   thorpej 	res->ar_nmemrange = 0;
    498   1.1   thorpej 
    499   1.1   thorpej 	SIMPLEQ_INIT(&res->ar_irq);
    500   1.1   thorpej 	res->ar_nirq = 0;
    501   1.1   thorpej 
    502   1.1   thorpej 	SIMPLEQ_INIT(&res->ar_drq);
    503   1.1   thorpej 	res->ar_ndrq = 0;
    504   1.1   thorpej 
    505   1.1   thorpej 	*contextp = res;
    506   1.1   thorpej }
    507   1.1   thorpej 
    508   1.1   thorpej static void
    509   1.1   thorpej acpi_res_parse_fini(struct device *dev, void *context)
    510   1.1   thorpej {
    511   1.1   thorpej 	struct acpi_resources *res = context;
    512   1.1   thorpej 
    513   1.1   thorpej 	/* Print the resources we're using. */
    514   1.1   thorpej 	acpi_resource_print(dev, res);
    515   1.1   thorpej }
    516   1.1   thorpej 
    517   1.1   thorpej static void
    518   1.1   thorpej acpi_res_parse_ioport(struct device *dev, void *context, uint32_t base,
    519   1.1   thorpej     uint32_t length)
    520   1.1   thorpej {
    521   1.1   thorpej 	struct acpi_resources *res = context;
    522   1.1   thorpej 	struct acpi_io *ar;
    523   1.7  jdolecek 
    524   1.7  jdolecek 	/*
    525   1.7  jdolecek 	 * Check if there is another I/O port directly below/under
    526   1.7  jdolecek 	 * this one.
    527   1.7  jdolecek 	 */
    528   1.7  jdolecek 	SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
    529   1.7  jdolecek 		if (ar->ar_base == base + length ) {
    530   1.7  jdolecek 			/*
    531   1.7  jdolecek 			 * Entry just below existing entry - adjust
    532   1.7  jdolecek 			 * the entry and return.
    533   1.7  jdolecek 			 */
    534   1.7  jdolecek 			ar->ar_base = base;
    535   1.7  jdolecek 			ar->ar_length += length;
    536   1.7  jdolecek 			return;
    537   1.7  jdolecek 		} else if (ar->ar_base + ar->ar_length == base) {
    538   1.7  jdolecek 			/*
    539   1.7  jdolecek 			 * Entry just above existing entry - adjust
    540   1.7  jdolecek 			 * the entry and return.
    541   1.7  jdolecek 			 */
    542   1.7  jdolecek 			ar->ar_length += length;
    543   1.7  jdolecek 			return;
    544   1.7  jdolecek 		}
    545   1.7  jdolecek 	}
    546   1.1   thorpej 
    547   1.1   thorpej 	ar = AcpiOsAllocate(sizeof(*ar));
    548   1.1   thorpej 	if (ar == NULL) {
    549   1.1   thorpej 		printf("%s: ACPI: unable to allocate I/O resource %d\n",
    550   1.1   thorpej 		    dev->dv_xname, res->ar_nio);
    551   1.1   thorpej 		res->ar_nio++;
    552   1.1   thorpej 		return;
    553   1.1   thorpej 	}
    554   1.1   thorpej 
    555   1.1   thorpej 	ar->ar_index = res->ar_nio++;
    556   1.1   thorpej 	ar->ar_base = base;
    557   1.1   thorpej 	ar->ar_length = length;
    558   1.1   thorpej 
    559   1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_io, ar, ar_list);
    560   1.1   thorpej }
    561   1.1   thorpej 
    562   1.1   thorpej static void
    563   1.1   thorpej acpi_res_parse_iorange(struct device *dev, void *context, uint32_t low,
    564   1.1   thorpej     uint32_t high, uint32_t length, uint32_t align)
    565   1.1   thorpej {
    566   1.1   thorpej 	struct acpi_resources *res = context;
    567   1.1   thorpej 	struct acpi_iorange *ar;
    568   1.1   thorpej 
    569   1.1   thorpej 	ar = AcpiOsAllocate(sizeof(*ar));
    570   1.1   thorpej 	if (ar == NULL) {
    571   1.1   thorpej 		printf("%s: ACPI: unable to allocate I/O range resource %d\n",
    572   1.1   thorpej 		    dev->dv_xname, res->ar_niorange);
    573   1.1   thorpej 		res->ar_niorange++;
    574   1.1   thorpej 		return;
    575   1.1   thorpej 	}
    576   1.1   thorpej 
    577   1.1   thorpej 	ar->ar_index = res->ar_niorange++;
    578   1.1   thorpej 	ar->ar_low = low;
    579   1.1   thorpej 	ar->ar_high = high;
    580   1.1   thorpej 	ar->ar_length = length;
    581   1.1   thorpej 	ar->ar_align = align;
    582   1.1   thorpej 
    583   1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_iorange, ar, ar_list);
    584   1.1   thorpej }
    585   1.1   thorpej 
    586   1.1   thorpej static void
    587   1.1   thorpej acpi_res_parse_memory(struct device *dev, void *context, uint32_t base,
    588   1.1   thorpej     uint32_t length)
    589   1.1   thorpej {
    590   1.1   thorpej 	struct acpi_resources *res = context;
    591   1.1   thorpej 	struct acpi_mem *ar;
    592   1.1   thorpej 
    593   1.1   thorpej 	ar = AcpiOsAllocate(sizeof(*ar));
    594   1.1   thorpej 	if (ar == NULL) {
    595   1.1   thorpej 		printf("%s: ACPI: unable to allocate Memory resource %d\n",
    596   1.1   thorpej 		    dev->dv_xname, res->ar_nmem);
    597   1.1   thorpej 		res->ar_nmem++;
    598   1.1   thorpej 		return;
    599   1.1   thorpej 	}
    600   1.1   thorpej 
    601   1.1   thorpej 	ar->ar_index = res->ar_nmem++;
    602   1.1   thorpej 	ar->ar_base = base;
    603   1.1   thorpej 	ar->ar_length = length;
    604   1.1   thorpej 
    605   1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_mem, ar, ar_list);
    606   1.1   thorpej }
    607   1.1   thorpej 
    608   1.1   thorpej static void
    609   1.1   thorpej acpi_res_parse_memrange(struct device *dev, void *context, uint32_t low,
    610   1.1   thorpej     uint32_t high, uint32_t length, uint32_t align)
    611   1.1   thorpej {
    612   1.1   thorpej 	struct acpi_resources *res = context;
    613   1.1   thorpej 	struct acpi_memrange *ar;
    614   1.1   thorpej 
    615   1.1   thorpej 	ar = AcpiOsAllocate(sizeof(*ar));
    616   1.1   thorpej 	if (ar == NULL) {
    617   1.1   thorpej 		printf("%s: ACPI: unable to allocate Memory range resource "
    618   1.1   thorpej 		    "%d\n", dev->dv_xname, res->ar_nmemrange);
    619   1.1   thorpej 		res->ar_nmemrange++;
    620   1.1   thorpej 		return;
    621   1.1   thorpej 	}
    622   1.1   thorpej 
    623   1.1   thorpej 	ar->ar_index = res->ar_nmemrange++;
    624   1.1   thorpej 	ar->ar_low = low;
    625   1.1   thorpej 	ar->ar_high = high;
    626   1.1   thorpej 	ar->ar_length = length;
    627   1.1   thorpej 	ar->ar_align = align;
    628   1.1   thorpej 
    629   1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_memrange, ar, ar_list);
    630   1.1   thorpej }
    631   1.1   thorpej 
    632   1.1   thorpej static void
    633   1.5      matt acpi_res_parse_irq(struct device *dev, void *context, uint32_t irq, uint32_t type)
    634   1.1   thorpej {
    635   1.1   thorpej 	struct acpi_resources *res = context;
    636   1.1   thorpej 	struct acpi_irq *ar;
    637   1.1   thorpej 
    638   1.1   thorpej 	ar = AcpiOsAllocate(sizeof(*ar));
    639   1.1   thorpej 	if (ar == NULL) {
    640   1.1   thorpej 		printf("%s: ACPI: unable to allocate IRQ resource %d\n",
    641   1.1   thorpej 		    dev->dv_xname, res->ar_nirq);
    642   1.1   thorpej 		res->ar_nirq++;
    643   1.1   thorpej 		return;
    644   1.1   thorpej 	}
    645   1.1   thorpej 
    646   1.1   thorpej 	ar->ar_index = res->ar_nirq++;
    647   1.1   thorpej 	ar->ar_irq = irq;
    648   1.5      matt 	ar->ar_type = type;
    649   1.1   thorpej 
    650   1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_irq, ar, ar_list);
    651   1.1   thorpej }
    652   1.1   thorpej 
    653   1.1   thorpej static void
    654   1.1   thorpej acpi_res_parse_drq(struct device *dev, void *context, uint32_t drq)
    655   1.1   thorpej {
    656   1.1   thorpej 	struct acpi_resources *res = context;
    657   1.1   thorpej 	struct acpi_drq *ar;
    658   1.1   thorpej 
    659   1.1   thorpej 	ar = AcpiOsAllocate(sizeof(*ar));
    660   1.1   thorpej 	if (ar == NULL) {
    661   1.1   thorpej 		printf("%s: ACPI: unable to allocate DRQ resource %d\n",
    662   1.1   thorpej 		    dev->dv_xname, res->ar_ndrq);
    663   1.1   thorpej 		res->ar_ndrq++;
    664   1.1   thorpej 		return;
    665   1.1   thorpej 	}
    666   1.1   thorpej 
    667   1.1   thorpej 	ar->ar_index = res->ar_ndrq++;
    668   1.1   thorpej 	ar->ar_drq = drq;
    669   1.1   thorpej 
    670   1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_drq, ar, ar_list);
    671   1.1   thorpej }
    672   1.1   thorpej 
    673   1.1   thorpej static void
    674   1.1   thorpej acpi_res_parse_start_dep(struct device *dev, void *context, int preference)
    675   1.1   thorpej {
    676  1.10     kochi 
    677   1.1   thorpej 	printf("%s: ACPI: dependant functions not supported\n",
    678   1.1   thorpej 	    dev->dv_xname);
    679   1.1   thorpej }
    680   1.1   thorpej 
    681   1.1   thorpej static void
    682   1.1   thorpej acpi_res_parse_end_dep(struct device *dev, void *context)
    683   1.1   thorpej {
    684   1.1   thorpej 
    685   1.1   thorpej 	/* Nothing to do. */
    686   1.1   thorpej }
    687