Home | History | Annotate | Line # | Download | only in acpi
acpi_resource.c revision 1.42.6.1
      1  1.42.6.1    martin /*	$NetBSD: acpi_resource.c,v 1.42.6.1 2024/07/03 19:13:20 martin 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.42.6.1    martin __KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.42.6.1 2024/07/03 19:13:20 martin Exp $");
     71       1.1   thorpej 
     72       1.1   thorpej #include <sys/param.h>
     73      1.32    jruoho #include <sys/device.h>
     74       1.1   thorpej #include <sys/systm.h>
     75       1.1   thorpej 
     76       1.1   thorpej #include <dev/acpi/acpireg.h>
     77       1.1   thorpej #include <dev/acpi/acpivar.h>
     78       1.1   thorpej 
     79       1.4   thorpej #define	_COMPONENT	ACPI_RESOURCE_COMPONENT
     80       1.4   thorpej ACPI_MODULE_NAME("RESOURCE")
     81       1.1   thorpej 
     82      1.13     kochi static ACPI_STATUS acpi_resource_parse_callback(ACPI_RESOURCE *, void *);
     83      1.13     kochi 
     84      1.12     kochi struct resource_parse_callback_arg {
     85      1.12     kochi 	const struct acpi_resource_parse_ops *ops;
     86      1.42  jmcneill 	bool include_producer;
     87      1.28    cegger 	device_t dev;
     88      1.12     kochi 	void *context;
     89      1.12     kochi };
     90      1.12     kochi 
     91      1.12     kochi static ACPI_STATUS
     92      1.12     kochi acpi_resource_parse_callback(ACPI_RESOURCE *res, void *context)
     93       1.1   thorpej {
     94      1.12     kochi 	struct resource_parse_callback_arg *arg = context;
     95      1.12     kochi 	const struct acpi_resource_parse_ops *ops;
     96       1.1   thorpej 	int i;
     97       1.1   thorpej 
     98      1.24     perry 	ACPI_FUNCTION_TRACE(__func__);
     99      1.15     kochi 
    100      1.12     kochi 	ops = arg->ops;
    101       1.1   thorpej 
    102      1.19     kochi 	switch (res->Type) {
    103      1.37   msaitoh 	case ACPI_RESOURCE_TYPE_END_TAG:
    104      1.37   msaitoh 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
    105      1.37   msaitoh 		break;
    106      1.19     kochi 	case ACPI_RESOURCE_TYPE_FIXED_IO:
    107      1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    108      1.31    jruoho 				     "FixedIo 0x%x/%u\n",
    109      1.19     kochi 				     res->Data.FixedIo.Address,
    110      1.19     kochi 				     res->Data.FixedIo.AddressLength));
    111      1.13     kochi 		if (ops->ioport)
    112      1.13     kochi 			(*ops->ioport)(arg->dev, arg->context,
    113      1.19     kochi 			    res->Data.FixedIo.Address,
    114      1.19     kochi 			    res->Data.FixedIo.AddressLength);
    115      1.12     kochi 		break;
    116       1.1   thorpej 
    117      1.19     kochi 	case ACPI_RESOURCE_TYPE_IO:
    118      1.19     kochi 		if (res->Data.Io.Minimum ==
    119      1.22     njoly 		    res->Data.Io.Maximum) {
    120       1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    121      1.31    jruoho 					     "Io 0x%x/%u\n",
    122      1.19     kochi 					     res->Data.Io.Minimum,
    123      1.19     kochi 					     res->Data.Io.AddressLength));
    124      1.13     kochi 			if (ops->ioport)
    125      1.13     kochi 				(*ops->ioport)(arg->dev, arg->context,
    126      1.19     kochi 				    res->Data.Io.Minimum,
    127      1.19     kochi 				    res->Data.Io.AddressLength);
    128      1.12     kochi 		} else {
    129       1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    130      1.31    jruoho 					     "Io 0x%x-0x%x/%u\n",
    131      1.19     kochi 					     res->Data.Io.Minimum,
    132      1.19     kochi 					     res->Data.Io.Maximum,
    133      1.19     kochi 					     res->Data.Io.AddressLength));
    134      1.22     njoly 			if (ops->iorange)
    135      1.13     kochi 				(*ops->iorange)(arg->dev, arg->context,
    136      1.19     kochi 				    res->Data.Io.Minimum,
    137      1.19     kochi 				    res->Data.Io.Maximum,
    138      1.19     kochi 				    res->Data.Io.AddressLength,
    139      1.13     kochi 				    res->Data.Io.Alignment);
    140      1.12     kochi 		}
    141      1.12     kochi 		break;
    142       1.1   thorpej 
    143      1.19     kochi 	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
    144      1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    145      1.31    jruoho 				     "FixedMemory32 0x%x/%u\n",
    146      1.19     kochi 				     res->Data.FixedMemory32.Address,
    147      1.19     kochi 				     res->Data.FixedMemory32.AddressLength));
    148      1.13     kochi 		if (ops->memory)
    149      1.13     kochi 			(*ops->memory)(arg->dev, arg->context,
    150      1.19     kochi 			    res->Data.FixedMemory32.Address,
    151      1.39  jmcneill 			    res->Data.FixedMemory32.AddressLength,
    152      1.41  jmcneill 			    res->Data.FixedMemory32.Address);
    153      1.12     kochi 		break;
    154      1.12     kochi 
    155      1.19     kochi 	case ACPI_RESOURCE_TYPE_MEMORY32:
    156      1.19     kochi 		if (res->Data.Memory32.Minimum ==
    157      1.19     kochi 		    res->Data.Memory32.Maximum) {
    158       1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    159      1.31    jruoho 					     "Memory32 0x%x/%u\n",
    160      1.19     kochi 					     res->Data.Memory32.Minimum,
    161      1.19     kochi 					     res->Data.Memory32.AddressLength));
    162      1.13     kochi 			if (ops->memory)
    163      1.13     kochi 				(*ops->memory)(arg->dev, arg->context,
    164      1.19     kochi 				    res->Data.Memory32.Minimum,
    165      1.39  jmcneill 				    res->Data.Memory32.AddressLength,
    166      1.41  jmcneill 				    res->Data.Memory32.Minimum);
    167      1.12     kochi 		} else {
    168       1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    169      1.31    jruoho 					     "Memory32 0x%x-0x%x/%u\n",
    170      1.19     kochi 					     res->Data.Memory32.Minimum,
    171      1.19     kochi 					     res->Data.Memory32.Maximum,
    172      1.19     kochi 					     res->Data.Memory32.AddressLength));
    173      1.13     kochi 			if (ops->memrange)
    174      1.13     kochi 				(*ops->memrange)(arg->dev, arg->context,
    175      1.19     kochi 				    res->Data.Memory32.Minimum,
    176      1.19     kochi 				    res->Data.Memory32.Maximum,
    177      1.19     kochi 				    res->Data.Memory32.AddressLength,
    178      1.13     kochi 				    res->Data.Memory32.Alignment);
    179      1.12     kochi 		}
    180      1.12     kochi 		break;
    181       1.1   thorpej 
    182      1.19     kochi 	case ACPI_RESOURCE_TYPE_MEMORY24:
    183      1.19     kochi 		if (res->Data.Memory24.Minimum ==
    184      1.19     kochi 		    res->Data.Memory24.Maximum) {
    185       1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    186      1.31    jruoho 					     "Memory24 0x%x/%u\n",
    187      1.19     kochi 					     res->Data.Memory24.Minimum,
    188      1.19     kochi 					     res->Data.Memory24.AddressLength));
    189      1.13     kochi 			if (ops->memory)
    190      1.13     kochi 				(*ops->memory)(arg->dev, arg->context,
    191      1.19     kochi 				    res->Data.Memory24.Minimum,
    192      1.39  jmcneill 				    res->Data.Memory24.AddressLength,
    193      1.41  jmcneill 				    res->Data.Memory24.Minimum);
    194      1.12     kochi 		} else {
    195       1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    196      1.31    jruoho 					     "Memory24 0x%x-0x%x/%u\n",
    197      1.19     kochi 					     res->Data.Memory24.Minimum,
    198      1.19     kochi 					     res->Data.Memory24.Maximum,
    199      1.19     kochi 					     res->Data.Memory24.AddressLength));
    200      1.13     kochi 			if (ops->memrange)
    201      1.13     kochi 				(*ops->memrange)(arg->dev, arg->context,
    202      1.19     kochi 				    res->Data.Memory24.Minimum,
    203      1.19     kochi 				    res->Data.Memory24.Maximum,
    204      1.19     kochi 				    res->Data.Memory24.AddressLength,
    205      1.13     kochi 				    res->Data.Memory24.Alignment);
    206      1.12     kochi 		}
    207      1.12     kochi 		break;
    208       1.1   thorpej 
    209      1.19     kochi 	case ACPI_RESOURCE_TYPE_IRQ:
    210      1.19     kochi 		for (i = 0; i < res->Data.Irq.InterruptCount; i++) {
    211       1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    212      1.31    jruoho 					     "IRQ %u\n",
    213      1.12     kochi 					     res->Data.Irq.Interrupts[i]));
    214      1.13     kochi 			if (ops->irq)
    215      1.13     kochi 				(*ops->irq)(arg->dev, arg->context,
    216      1.13     kochi 				    res->Data.Irq.Interrupts[i],
    217      1.19     kochi 				    res->Data.Irq.Triggering);
    218      1.12     kochi 		}
    219      1.12     kochi 		break;
    220       1.1   thorpej 
    221      1.19     kochi 	case ACPI_RESOURCE_TYPE_DMA:
    222      1.19     kochi 		for (i = 0; i < res->Data.Dma.ChannelCount; i++) {
    223       1.1   thorpej 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    224      1.31    jruoho 					     "DRQ %u\n",
    225      1.12     kochi 					     res->Data.Dma.Channels[i]));
    226      1.13     kochi 			if (ops->drq)
    227      1.13     kochi 				(*ops->drq)(arg->dev, arg->context,
    228      1.13     kochi 				    res->Data.Dma.Channels[i]);
    229       1.1   thorpej 		}
    230      1.12     kochi 		break;
    231      1.12     kochi 
    232      1.19     kochi 	case ACPI_RESOURCE_TYPE_START_DEPENDENT:
    233      1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    234      1.35       wiz 				     "Start dependent functions: %u\n",
    235      1.12     kochi 				     res->Data.StartDpf.CompatibilityPriority));
    236      1.13     kochi 		if (ops->start_dep)
    237      1.13     kochi 			(*ops->start_dep)(arg->dev, arg->context,
    238      1.13     kochi 			    res->Data.StartDpf.CompatibilityPriority);
    239      1.12     kochi 		break;
    240      1.12     kochi 
    241      1.19     kochi 	case ACPI_RESOURCE_TYPE_END_DEPENDENT:
    242      1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    243      1.35       wiz 				     "End dependent functions\n"));
    244      1.13     kochi 		if (ops->end_dep)
    245      1.13     kochi 			(*ops->end_dep)(arg->dev, arg->context);
    246      1.22     njoly 		break;
    247      1.12     kochi 
    248      1.19     kochi 	case ACPI_RESOURCE_TYPE_ADDRESS32:
    249      1.22     njoly 		/* XXX Only fixed size supported for now */
    250  1.42.6.1    martin 		if (res->Data.Address32.Address.AddressLength == 0)
    251      1.22     njoly 			break;
    252      1.38  jmcneill #define ADDRESS32_FIXED2(r)						\
    253      1.22     njoly 	((r)->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&	\
    254      1.22     njoly 	 (r)->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED)
    255      1.22     njoly 		switch (res->Data.Address32.ResourceType) {
    256      1.22     njoly 		case ACPI_MEMORY_RANGE:
    257      1.38  jmcneill 			if (ADDRESS32_FIXED2(res)) {
    258      1.22     njoly 				if (ops->memory)
    259      1.22     njoly 					(*ops->memory)(arg->dev, arg->context,
    260      1.36  christos 					    res->Data.Address32.Address.Minimum,
    261      1.39  jmcneill 					    res->Data.Address32.Address.AddressLength,
    262      1.41  jmcneill 					    res->Data.Address32.Address.Minimum +
    263      1.41  jmcneill 					        res->Data.Address32.Address.TranslationOffset);
    264      1.22     njoly 			} else {
    265      1.22     njoly 				if (ops->memrange)
    266      1.22     njoly 					(*ops->memrange)(arg->dev, arg->context,
    267      1.36  christos 					    res->Data.Address32.Address.Minimum,
    268      1.36  christos 					    res->Data.Address32.Address.Maximum,
    269      1.36  christos 					    res->Data.Address32.Address.AddressLength,
    270      1.36  christos 					    res->Data.Address32.Address.Granularity);
    271      1.22     njoly 			}
    272      1.22     njoly 			break;
    273      1.22     njoly 		case ACPI_IO_RANGE:
    274      1.38  jmcneill 			if (ADDRESS32_FIXED2(res)) {
    275      1.22     njoly 				if (ops->ioport)
    276      1.22     njoly 					(*ops->ioport)(arg->dev, arg->context,
    277      1.36  christos 					    res->Data.Address32.Address.Minimum,
    278      1.36  christos 					    res->Data.Address32.Address.AddressLength);
    279      1.22     njoly 			} else {
    280      1.22     njoly 				if (ops->iorange)
    281      1.22     njoly 					(*ops->iorange)(arg->dev, arg->context,
    282      1.36  christos 					    res->Data.Address32.Address.Minimum,
    283      1.36  christos 					    res->Data.Address32.Address.Maximum,
    284      1.36  christos 					    res->Data.Address32.Address.AddressLength,
    285      1.36  christos 					    res->Data.Address32.Address.Granularity);
    286      1.22     njoly 			}
    287      1.22     njoly 			break;
    288      1.22     njoly 		case ACPI_BUS_NUMBER_RANGE:
    289      1.22     njoly 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    290      1.22     njoly 				      "Address32/BusNumber unimplemented\n"));
    291      1.22     njoly 			break;
    292      1.22     njoly 		}
    293      1.38  jmcneill #undef ADDRESS32_FIXED2
    294      1.12     kochi 		break;
    295      1.12     kochi 
    296      1.19     kochi 	case ACPI_RESOURCE_TYPE_ADDRESS16:
    297      1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    298      1.12     kochi 				     "Address16 unimplemented\n"));
    299      1.12     kochi 		break;
    300      1.12     kochi 
    301      1.37   msaitoh 	case ACPI_RESOURCE_TYPE_ADDRESS64:
    302      1.38  jmcneill #ifdef _LP64
    303      1.38  jmcneill 		/* XXX Only fixed size supported for now */
    304  1.42.6.1    martin 		if (res->Data.Address64.Address.AddressLength == 0)
    305      1.38  jmcneill 			break;
    306      1.38  jmcneill #define ADDRESS64_FIXED2(r)						\
    307      1.38  jmcneill 	((r)->Data.Address64.MinAddressFixed == ACPI_ADDRESS_FIXED &&	\
    308      1.38  jmcneill 	 (r)->Data.Address64.MaxAddressFixed == ACPI_ADDRESS_FIXED)
    309      1.38  jmcneill 		switch (res->Data.Address64.ResourceType) {
    310      1.38  jmcneill 		case ACPI_MEMORY_RANGE:
    311      1.38  jmcneill 			if (ADDRESS64_FIXED2(res)) {
    312      1.38  jmcneill 				if (ops->memory)
    313      1.38  jmcneill 					(*ops->memory)(arg->dev, arg->context,
    314      1.38  jmcneill 					    res->Data.Address64.Address.Minimum,
    315      1.39  jmcneill 					    res->Data.Address64.Address.AddressLength,
    316      1.41  jmcneill 					    res->Data.Address64.Address.Minimum +
    317      1.41  jmcneill 					        res->Data.Address64.Address.TranslationOffset);
    318      1.38  jmcneill 			} else {
    319      1.38  jmcneill 				if (ops->memrange)
    320      1.38  jmcneill 					(*ops->memrange)(arg->dev, arg->context,
    321      1.38  jmcneill 					    res->Data.Address64.Address.Minimum,
    322      1.38  jmcneill 					    res->Data.Address64.Address.Maximum,
    323      1.38  jmcneill 					    res->Data.Address64.Address.AddressLength,
    324      1.38  jmcneill 					    res->Data.Address64.Address.Granularity);
    325      1.38  jmcneill 			}
    326      1.38  jmcneill 			break;
    327      1.38  jmcneill 		case ACPI_IO_RANGE:
    328      1.38  jmcneill 			if (ADDRESS64_FIXED2(res)) {
    329      1.38  jmcneill 				if (ops->ioport)
    330      1.38  jmcneill 					(*ops->ioport)(arg->dev, arg->context,
    331      1.38  jmcneill 					    res->Data.Address64.Address.Minimum,
    332      1.38  jmcneill 					    res->Data.Address64.Address.AddressLength);
    333      1.38  jmcneill 			} else {
    334      1.38  jmcneill 				if (ops->iorange)
    335      1.38  jmcneill 					(*ops->iorange)(arg->dev, arg->context,
    336      1.38  jmcneill 					    res->Data.Address64.Address.Minimum,
    337      1.38  jmcneill 					    res->Data.Address64.Address.Maximum,
    338      1.38  jmcneill 					    res->Data.Address64.Address.AddressLength,
    339      1.38  jmcneill 					    res->Data.Address64.Address.Granularity);
    340      1.38  jmcneill 			}
    341      1.38  jmcneill 			break;
    342      1.38  jmcneill 		case ACPI_BUS_NUMBER_RANGE:
    343      1.38  jmcneill 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    344      1.38  jmcneill 				      "Address64/BusNumber unimplemented\n"));
    345      1.38  jmcneill 			break;
    346      1.38  jmcneill 		}
    347      1.38  jmcneill #undef ADDRESS64_FIXED2
    348      1.38  jmcneill #else
    349      1.37   msaitoh 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    350      1.37   msaitoh 				     "Address64 unimplemented\n"));
    351      1.38  jmcneill #endif
    352      1.37   msaitoh 		break;
    353      1.19     kochi 	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
    354      1.19     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    355      1.19     kochi 				     "Extended address64 unimplemented\n"));
    356      1.19     kochi 		break;
    357      1.19     kochi 
    358      1.19     kochi 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
    359      1.42  jmcneill 		if (!arg->include_producer &&
    360      1.42  jmcneill 		    res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
    361      1.29  kiyohara 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    362      1.29  kiyohara 			    "ignored ExtIRQ producer\n"));
    363      1.29  kiyohara 			break;
    364      1.29  kiyohara 		}
    365      1.29  kiyohara 		for (i = 0; i < res->Data.ExtendedIrq.InterruptCount; i++) {
    366      1.29  kiyohara 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    367      1.31    jruoho 				     "ExtIRQ %u\n",
    368      1.29  kiyohara 				     res->Data.ExtendedIrq.Interrupts[i]));
    369      1.29  kiyohara 			if (ops->irq)
    370      1.29  kiyohara 				(*ops->irq)(arg->dev, arg->context,
    371      1.29  kiyohara 				    res->Data.ExtendedIrq.Interrupts[i],
    372      1.29  kiyohara 				    res->Data.ExtendedIrq.Triggering);
    373      1.29  kiyohara 		}
    374      1.19     kochi 		break;
    375      1.19     kochi 
    376      1.19     kochi 	case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
    377      1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    378      1.22     njoly 				     "GenericRegister unimplemented\n"));
    379      1.12     kochi 		break;
    380      1.12     kochi 
    381      1.19     kochi 	case ACPI_RESOURCE_TYPE_VENDOR:
    382      1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    383      1.12     kochi 				     "VendorSpecific unimplemented\n"));
    384      1.12     kochi 		break;
    385      1.12     kochi 
    386      1.12     kochi 	default:
    387      1.12     kochi 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
    388      1.31    jruoho 				     "Unknown resource type: %u\n", res->Type));
    389      1.12     kochi 		break;
    390      1.12     kochi 	}
    391      1.12     kochi 
    392      1.15     kochi 	return_ACPI_STATUS(AE_OK);
    393      1.12     kochi }
    394      1.12     kochi 
    395      1.12     kochi 
    396      1.12     kochi /*
    397      1.12     kochi  * acpi_resource_parse:
    398      1.12     kochi  *
    399      1.12     kochi  *	Parse a device node's resources and fill them in for the
    400      1.12     kochi  *	client.
    401      1.12     kochi  *
    402      1.12     kochi  *	This API supports _CRS (current resources) and
    403      1.12     kochi  *	_PRS (possible resources).
    404      1.12     kochi  *
    405      1.12     kochi  *	Note that it might be nice to also locate ACPI-specific resource
    406      1.12     kochi  *	items, such as GPE bits.
    407      1.12     kochi  */
    408      1.12     kochi ACPI_STATUS
    409      1.28    cegger acpi_resource_parse(device_t dev, ACPI_HANDLE handle, const char *path,
    410      1.12     kochi     void *arg, const struct acpi_resource_parse_ops *ops)
    411      1.12     kochi {
    412      1.12     kochi 	struct resource_parse_callback_arg cbarg;
    413      1.12     kochi 	ACPI_STATUS rv;
    414      1.12     kochi 
    415      1.24     perry 	ACPI_FUNCTION_TRACE(__func__);
    416      1.12     kochi 
    417      1.13     kochi 	if (ops->init)
    418      1.13     kochi 		(*ops->init)(dev, arg, &cbarg.context);
    419      1.13     kochi 	else
    420      1.13     kochi 		cbarg.context = arg;
    421      1.12     kochi 	cbarg.ops = ops;
    422      1.12     kochi 	cbarg.dev = dev;
    423      1.42  jmcneill 	cbarg.include_producer = false;
    424      1.12     kochi 
    425      1.17  christos 	rv = AcpiWalkResources(handle, path, acpi_resource_parse_callback,
    426      1.12     kochi 	    &cbarg);
    427      1.12     kochi 	if (ACPI_FAILURE(rv)) {
    428      1.23  jmcneill 		aprint_error_dev(dev, "ACPI: unable to get %s resources: %s\n",
    429      1.23  jmcneill 		    path, AcpiFormatException(rv));
    430      1.12     kochi 		return_ACPI_STATUS(rv);
    431       1.1   thorpej 	}
    432       1.1   thorpej 
    433      1.13     kochi 	if (ops->fini)
    434      1.13     kochi 		(*ops->fini)(dev, cbarg.context);
    435       1.1   thorpej 
    436       1.1   thorpej 	return_ACPI_STATUS(AE_OK);
    437       1.1   thorpej }
    438       1.1   thorpej 
    439       1.1   thorpej /*
    440      1.42  jmcneill  * acpi_resource_parse_any:
    441      1.42  jmcneill  *
    442      1.42  jmcneill  *	Parse a device node's resources and fill them in for the
    443      1.42  jmcneill  *	client. Like acpi_resource_parse, but doesn't skip ResourceProducer
    444      1.42  jmcneill  *	type resources.
    445      1.42  jmcneill  */
    446      1.42  jmcneill ACPI_STATUS
    447      1.42  jmcneill acpi_resource_parse_any(device_t dev, ACPI_HANDLE handle, const char *path,
    448      1.42  jmcneill     void *arg, const struct acpi_resource_parse_ops *ops)
    449      1.42  jmcneill {
    450      1.42  jmcneill 	struct resource_parse_callback_arg cbarg;
    451      1.42  jmcneill 	ACPI_STATUS rv;
    452      1.42  jmcneill 
    453      1.42  jmcneill 	ACPI_FUNCTION_TRACE(__func__);
    454      1.42  jmcneill 
    455      1.42  jmcneill 	if (ops->init)
    456      1.42  jmcneill 		(*ops->init)(dev, arg, &cbarg.context);
    457      1.42  jmcneill 	else
    458      1.42  jmcneill 		cbarg.context = arg;
    459      1.42  jmcneill 	cbarg.ops = ops;
    460      1.42  jmcneill 	cbarg.dev = dev;
    461      1.42  jmcneill 	cbarg.include_producer = true;
    462      1.42  jmcneill 
    463      1.42  jmcneill 	rv = AcpiWalkResources(handle, path, acpi_resource_parse_callback,
    464      1.42  jmcneill 	    &cbarg);
    465      1.42  jmcneill 	if (ACPI_FAILURE(rv)) {
    466      1.42  jmcneill 		aprint_error_dev(dev, "ACPI: unable to get %s resources: %s\n",
    467      1.42  jmcneill 		    path, AcpiFormatException(rv));
    468      1.42  jmcneill 		return_ACPI_STATUS(rv);
    469      1.42  jmcneill 	}
    470      1.42  jmcneill 
    471      1.42  jmcneill 	if (ops->fini)
    472      1.42  jmcneill 		(*ops->fini)(dev, cbarg.context);
    473      1.42  jmcneill 
    474      1.42  jmcneill 	return_ACPI_STATUS(AE_OK);
    475      1.42  jmcneill }
    476      1.42  jmcneill 
    477      1.42  jmcneill 
    478      1.42  jmcneill /*
    479       1.1   thorpej  * acpi_resource_print:
    480       1.1   thorpej  *
    481       1.1   thorpej  *	Print the resources assigned to a device.
    482       1.1   thorpej  */
    483       1.1   thorpej void
    484      1.28    cegger acpi_resource_print(device_t dev, struct acpi_resources *res)
    485       1.1   thorpej {
    486       1.1   thorpej 	const char *sep;
    487       1.1   thorpej 
    488       1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_io) &&
    489       1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_iorange) &&
    490       1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_mem) &&
    491       1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_memrange) &&
    492       1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_irq) &&
    493       1.1   thorpej 	    SIMPLEQ_EMPTY(&res->ar_drq))
    494       1.1   thorpej 		return;
    495       1.1   thorpej 
    496      1.27  jmcneill 	aprint_normal(":");
    497       1.1   thorpej 
    498       1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_io) == 0) {
    499       1.1   thorpej 		struct acpi_io *ar;
    500       1.1   thorpej 
    501       1.1   thorpej 		sep = "";
    502      1.23  jmcneill 		aprint_normal(" io ");
    503       1.3     lukem 		SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
    504      1.23  jmcneill 			aprint_normal("%s0x%x", sep, ar->ar_base);
    505       1.1   thorpej 			if (ar->ar_length > 1)
    506      1.23  jmcneill 				aprint_normal("-0x%x", ar->ar_base +
    507       1.1   thorpej 				    ar->ar_length - 1);
    508       1.1   thorpej 			sep = ",";
    509       1.1   thorpej 		}
    510       1.1   thorpej 	}
    511       1.1   thorpej 
    512       1.1   thorpej 	/* XXX iorange */
    513       1.1   thorpej 
    514       1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_mem) == 0) {
    515       1.1   thorpej 		struct acpi_mem *ar;
    516       1.1   thorpej 
    517       1.1   thorpej 		sep = "";
    518      1.23  jmcneill 		aprint_normal(" mem ");
    519       1.3     lukem 		SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
    520      1.38  jmcneill 			aprint_normal("%s0x%" PRIx64, sep,
    521      1.38  jmcneill 			    (uint64_t)ar->ar_base);
    522       1.1   thorpej 			if (ar->ar_length > 1)
    523      1.38  jmcneill 				aprint_normal("-0x%" PRIx64,
    524      1.38  jmcneill 				    (uint64_t)ar->ar_base +
    525       1.1   thorpej 				    ar->ar_length - 1);
    526       1.1   thorpej 			sep = ",";
    527       1.1   thorpej 		}
    528       1.1   thorpej 	}
    529       1.1   thorpej 
    530       1.1   thorpej 	/* XXX memrange */
    531       1.1   thorpej 
    532       1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_irq) == 0) {
    533       1.1   thorpej 		struct acpi_irq *ar;
    534       1.1   thorpej 
    535       1.1   thorpej 		sep = "";
    536      1.23  jmcneill 		aprint_normal(" irq ");
    537       1.3     lukem 		SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
    538      1.23  jmcneill 			aprint_normal("%s%d", sep, ar->ar_irq);
    539       1.1   thorpej 			sep = ",";
    540       1.1   thorpej 		}
    541       1.1   thorpej 	}
    542       1.1   thorpej 
    543       1.1   thorpej 	if (SIMPLEQ_EMPTY(&res->ar_drq) == 0) {
    544       1.1   thorpej 		struct acpi_drq *ar;
    545       1.1   thorpej 
    546       1.1   thorpej 		sep = "";
    547      1.23  jmcneill 		aprint_normal(" drq ");
    548       1.3     lukem 		SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
    549      1.23  jmcneill 			aprint_normal("%s%d", sep, ar->ar_drq);
    550       1.1   thorpej 			sep = ",";
    551       1.1   thorpej 		}
    552       1.1   thorpej 	}
    553       1.1   thorpej 
    554      1.23  jmcneill 	aprint_normal("\n");
    555      1.27  jmcneill 	aprint_naive("\n");
    556       1.1   thorpej }
    557       1.1   thorpej 
    558      1.14     kochi /*
    559      1.14     kochi  * acpi_resource_cleanup:
    560      1.14     kochi  *
    561      1.14     kochi  *	Free all allocated buffers
    562      1.14     kochi  */
    563      1.14     kochi void
    564      1.14     kochi acpi_resource_cleanup(struct acpi_resources *res)
    565      1.14     kochi {
    566      1.14     kochi 	while (!SIMPLEQ_EMPTY(&res->ar_io)) {
    567      1.14     kochi 		struct acpi_io *ar;
    568      1.14     kochi 		ar = SIMPLEQ_FIRST(&res->ar_io);
    569      1.14     kochi 		SIMPLEQ_REMOVE_HEAD(&res->ar_io, ar_list);
    570      1.30   mlelstv 		ACPI_FREE(ar);
    571      1.14     kochi 	}
    572      1.14     kochi 
    573      1.14     kochi 	while (!SIMPLEQ_EMPTY(&res->ar_iorange)) {
    574      1.14     kochi 		struct acpi_iorange *ar;
    575      1.14     kochi 		ar = SIMPLEQ_FIRST(&res->ar_iorange);
    576      1.14     kochi 		SIMPLEQ_REMOVE_HEAD(&res->ar_iorange, ar_list);
    577      1.30   mlelstv 		ACPI_FREE(ar);
    578      1.14     kochi 	}
    579      1.14     kochi 
    580      1.14     kochi 	while (!SIMPLEQ_EMPTY(&res->ar_mem)) {
    581      1.14     kochi 		struct acpi_mem *ar;
    582      1.14     kochi 		ar = SIMPLEQ_FIRST(&res->ar_mem);
    583      1.14     kochi 		SIMPLEQ_REMOVE_HEAD(&res->ar_mem, ar_list);
    584      1.30   mlelstv 		ACPI_FREE(ar);
    585      1.14     kochi 	}
    586      1.14     kochi 
    587      1.14     kochi 	while (!SIMPLEQ_EMPTY(&res->ar_memrange)) {
    588      1.14     kochi 		struct acpi_memrange *ar;
    589      1.14     kochi 		ar = SIMPLEQ_FIRST(&res->ar_memrange);
    590      1.14     kochi 		SIMPLEQ_REMOVE_HEAD(&res->ar_memrange, ar_list);
    591      1.30   mlelstv 		ACPI_FREE(ar);
    592      1.14     kochi 	}
    593      1.14     kochi 
    594      1.14     kochi 	while (!SIMPLEQ_EMPTY(&res->ar_irq)) {
    595      1.14     kochi 		struct acpi_irq *ar;
    596      1.14     kochi 		ar = SIMPLEQ_FIRST(&res->ar_irq);
    597      1.14     kochi 		SIMPLEQ_REMOVE_HEAD(&res->ar_irq, ar_list);
    598      1.30   mlelstv 		ACPI_FREE(ar);
    599      1.14     kochi 	}
    600      1.14     kochi 
    601      1.14     kochi 	while (!SIMPLEQ_EMPTY(&res->ar_drq)) {
    602      1.14     kochi 		struct acpi_drq *ar;
    603      1.14     kochi 		ar = SIMPLEQ_FIRST(&res->ar_drq);
    604      1.14     kochi 		SIMPLEQ_REMOVE_HEAD(&res->ar_drq, ar_list);
    605      1.30   mlelstv 		ACPI_FREE(ar);
    606      1.14     kochi 	}
    607      1.14     kochi 
    608      1.16     perry 	res->ar_nio = res->ar_niorange = res->ar_nmem =
    609      1.14     kochi 	    res->ar_nmemrange = res->ar_nirq = res->ar_ndrq = 0;
    610      1.14     kochi }
    611      1.14     kochi 
    612       1.1   thorpej struct acpi_io *
    613       1.1   thorpej acpi_res_io(struct acpi_resources *res, int idx)
    614       1.1   thorpej {
    615       1.1   thorpej 	struct acpi_io *ar;
    616       1.1   thorpej 
    617       1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
    618       1.1   thorpej 		if (ar->ar_index == idx)
    619      1.11     kochi 			return ar;
    620       1.1   thorpej 	}
    621      1.11     kochi 	return NULL;
    622       1.1   thorpej }
    623       1.1   thorpej 
    624       1.1   thorpej struct acpi_iorange *
    625       1.1   thorpej acpi_res_iorange(struct acpi_resources *res, int idx)
    626       1.1   thorpej {
    627       1.1   thorpej 	struct acpi_iorange *ar;
    628       1.1   thorpej 
    629       1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_iorange, ar_list) {
    630       1.1   thorpej 		if (ar->ar_index == idx)
    631      1.11     kochi 			return ar;
    632       1.1   thorpej 	}
    633      1.11     kochi 	return NULL;
    634       1.1   thorpej }
    635       1.1   thorpej 
    636       1.1   thorpej struct acpi_mem *
    637       1.1   thorpej acpi_res_mem(struct acpi_resources *res, int idx)
    638       1.1   thorpej {
    639       1.1   thorpej 	struct acpi_mem *ar;
    640       1.1   thorpej 
    641       1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
    642       1.1   thorpej 		if (ar->ar_index == idx)
    643      1.11     kochi 			return ar;
    644       1.1   thorpej 	}
    645      1.11     kochi 	return NULL;
    646       1.1   thorpej }
    647       1.1   thorpej 
    648       1.1   thorpej struct acpi_memrange *
    649       1.1   thorpej acpi_res_memrange(struct acpi_resources *res, int idx)
    650       1.1   thorpej {
    651       1.1   thorpej 	struct acpi_memrange *ar;
    652       1.1   thorpej 
    653       1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_memrange, ar_list) {
    654       1.1   thorpej 		if (ar->ar_index == idx)
    655      1.11     kochi 			return ar;
    656       1.1   thorpej 	}
    657      1.11     kochi 	return NULL;
    658       1.1   thorpej }
    659       1.1   thorpej 
    660       1.1   thorpej struct acpi_irq *
    661       1.1   thorpej acpi_res_irq(struct acpi_resources *res, int idx)
    662       1.1   thorpej {
    663       1.1   thorpej 	struct acpi_irq *ar;
    664       1.1   thorpej 
    665       1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
    666       1.1   thorpej 		if (ar->ar_index == idx)
    667      1.11     kochi 			return ar;
    668       1.1   thorpej 	}
    669      1.11     kochi 	return NULL;
    670       1.1   thorpej }
    671       1.1   thorpej 
    672       1.1   thorpej struct acpi_drq *
    673       1.1   thorpej acpi_res_drq(struct acpi_resources *res, int idx)
    674       1.1   thorpej {
    675       1.1   thorpej 	struct acpi_drq *ar;
    676       1.1   thorpej 
    677       1.1   thorpej 	SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
    678       1.1   thorpej 		if (ar->ar_index == idx)
    679      1.11     kochi 			return ar;
    680       1.1   thorpej 	}
    681      1.11     kochi 	return NULL;
    682       1.1   thorpej }
    683       1.1   thorpej 
    684       1.1   thorpej /*****************************************************************************
    685       1.1   thorpej  * Default ACPI resource parse operations.
    686       1.1   thorpej  *****************************************************************************/
    687       1.1   thorpej 
    688      1.28    cegger static void	acpi_res_parse_init(device_t, void *, void **);
    689      1.28    cegger static void	acpi_res_parse_fini(device_t, void *);
    690       1.1   thorpej 
    691      1.28    cegger static void	acpi_res_parse_ioport(device_t, void *, uint32_t,
    692       1.1   thorpej 		    uint32_t);
    693      1.28    cegger static void	acpi_res_parse_iorange(device_t, void *, uint32_t,
    694       1.1   thorpej 		    uint32_t, uint32_t, uint32_t);
    695       1.1   thorpej 
    696      1.38  jmcneill static void	acpi_res_parse_memory(device_t, void *, uint64_t,
    697      1.41  jmcneill 		    uint64_t, uint64_t);
    698      1.38  jmcneill static void	acpi_res_parse_memrange(device_t, void *, uint64_t,
    699      1.38  jmcneill 		    uint64_t, uint64_t, uint64_t);
    700       1.1   thorpej 
    701      1.28    cegger static void	acpi_res_parse_irq(device_t, void *, uint32_t, uint32_t);
    702      1.28    cegger static void	acpi_res_parse_drq(device_t, void *, uint32_t);
    703       1.1   thorpej 
    704      1.28    cegger static void	acpi_res_parse_start_dep(device_t, void *, int);
    705      1.28    cegger static void	acpi_res_parse_end_dep(device_t, void *);
    706       1.1   thorpej 
    707       1.1   thorpej const struct acpi_resource_parse_ops acpi_resource_parse_ops_default = {
    708      1.13     kochi 	.init = acpi_res_parse_init,
    709      1.13     kochi 	.fini = acpi_res_parse_fini,
    710       1.1   thorpej 
    711      1.13     kochi 	.ioport = acpi_res_parse_ioport,
    712      1.13     kochi 	.iorange = acpi_res_parse_iorange,
    713       1.1   thorpej 
    714      1.13     kochi 	.memory = acpi_res_parse_memory,
    715      1.13     kochi 	.memrange = acpi_res_parse_memrange,
    716       1.1   thorpej 
    717      1.13     kochi 	.irq = acpi_res_parse_irq,
    718      1.13     kochi 	.drq = acpi_res_parse_drq,
    719       1.1   thorpej 
    720      1.13     kochi 	.start_dep = acpi_res_parse_start_dep,
    721      1.13     kochi 	.end_dep = acpi_res_parse_end_dep,
    722       1.1   thorpej };
    723       1.1   thorpej 
    724      1.34    jruoho const struct acpi_resource_parse_ops acpi_resource_parse_ops_quiet = {
    725      1.34    jruoho 	.init = acpi_res_parse_init,
    726      1.34    jruoho 	.fini = NULL,
    727      1.34    jruoho 
    728      1.34    jruoho 	.ioport = acpi_res_parse_ioport,
    729      1.34    jruoho 	.iorange = acpi_res_parse_iorange,
    730      1.34    jruoho 
    731      1.34    jruoho 	.memory = acpi_res_parse_memory,
    732      1.34    jruoho 	.memrange = acpi_res_parse_memrange,
    733      1.34    jruoho 
    734      1.34    jruoho 	.irq = acpi_res_parse_irq,
    735      1.34    jruoho 	.drq = acpi_res_parse_drq,
    736      1.34    jruoho 
    737      1.34    jruoho 	.start_dep = acpi_res_parse_start_dep,
    738      1.34    jruoho 	.end_dep = acpi_res_parse_end_dep,
    739      1.34    jruoho };
    740      1.34    jruoho 
    741       1.1   thorpej static void
    742      1.28    cegger acpi_res_parse_init(device_t dev, void *arg, void **contextp)
    743       1.1   thorpej {
    744       1.1   thorpej 	struct acpi_resources *res = arg;
    745       1.1   thorpej 
    746       1.1   thorpej 	SIMPLEQ_INIT(&res->ar_io);
    747       1.1   thorpej 	res->ar_nio = 0;
    748       1.1   thorpej 
    749       1.1   thorpej 	SIMPLEQ_INIT(&res->ar_iorange);
    750       1.1   thorpej 	res->ar_niorange = 0;
    751       1.1   thorpej 
    752       1.1   thorpej 	SIMPLEQ_INIT(&res->ar_mem);
    753       1.1   thorpej 	res->ar_nmem = 0;
    754       1.1   thorpej 
    755       1.1   thorpej 	SIMPLEQ_INIT(&res->ar_memrange);
    756       1.1   thorpej 	res->ar_nmemrange = 0;
    757       1.1   thorpej 
    758       1.1   thorpej 	SIMPLEQ_INIT(&res->ar_irq);
    759       1.1   thorpej 	res->ar_nirq = 0;
    760       1.1   thorpej 
    761       1.1   thorpej 	SIMPLEQ_INIT(&res->ar_drq);
    762       1.1   thorpej 	res->ar_ndrq = 0;
    763       1.1   thorpej 
    764       1.1   thorpej 	*contextp = res;
    765       1.1   thorpej }
    766       1.1   thorpej 
    767       1.1   thorpej static void
    768      1.28    cegger acpi_res_parse_fini(device_t dev, void *context)
    769       1.1   thorpej {
    770       1.1   thorpej 	struct acpi_resources *res = context;
    771       1.1   thorpej 
    772       1.1   thorpej 	/* Print the resources we're using. */
    773       1.1   thorpej 	acpi_resource_print(dev, res);
    774       1.1   thorpej }
    775       1.1   thorpej 
    776       1.1   thorpej static void
    777      1.28    cegger acpi_res_parse_ioport(device_t dev, void *context, uint32_t base,
    778       1.1   thorpej     uint32_t length)
    779       1.1   thorpej {
    780       1.1   thorpej 	struct acpi_resources *res = context;
    781       1.1   thorpej 	struct acpi_io *ar;
    782       1.7  jdolecek 
    783       1.7  jdolecek 	/*
    784       1.7  jdolecek 	 * Check if there is another I/O port directly below/under
    785       1.7  jdolecek 	 * this one.
    786       1.7  jdolecek 	 */
    787       1.7  jdolecek 	SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
    788       1.7  jdolecek 		if (ar->ar_base == base + length ) {
    789       1.7  jdolecek 			/*
    790       1.7  jdolecek 			 * Entry just below existing entry - adjust
    791       1.7  jdolecek 			 * the entry and return.
    792       1.7  jdolecek 			 */
    793       1.7  jdolecek 			ar->ar_base = base;
    794       1.7  jdolecek 			ar->ar_length += length;
    795       1.7  jdolecek 			return;
    796       1.7  jdolecek 		} else if (ar->ar_base + ar->ar_length == base) {
    797       1.7  jdolecek 			/*
    798       1.7  jdolecek 			 * Entry just above existing entry - adjust
    799       1.7  jdolecek 			 * the entry and return.
    800       1.7  jdolecek 			 */
    801       1.7  jdolecek 			ar->ar_length += length;
    802       1.7  jdolecek 			return;
    803       1.7  jdolecek 		}
    804       1.7  jdolecek 	}
    805       1.1   thorpej 
    806      1.30   mlelstv 	ar = ACPI_ALLOCATE(sizeof(*ar));
    807       1.1   thorpej 	if (ar == NULL) {
    808      1.23  jmcneill 		aprint_error_dev(dev, "ACPI: unable to allocate I/O resource %d\n",
    809      1.23  jmcneill 		    res->ar_nio);
    810       1.1   thorpej 		res->ar_nio++;
    811       1.1   thorpej 		return;
    812       1.1   thorpej 	}
    813       1.1   thorpej 
    814       1.1   thorpej 	ar->ar_index = res->ar_nio++;
    815       1.1   thorpej 	ar->ar_base = base;
    816       1.1   thorpej 	ar->ar_length = length;
    817       1.1   thorpej 
    818       1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_io, ar, ar_list);
    819       1.1   thorpej }
    820       1.1   thorpej 
    821       1.1   thorpej static void
    822      1.28    cegger acpi_res_parse_iorange(device_t dev, void *context, uint32_t low,
    823       1.1   thorpej     uint32_t high, uint32_t length, uint32_t align)
    824       1.1   thorpej {
    825       1.1   thorpej 	struct acpi_resources *res = context;
    826       1.1   thorpej 	struct acpi_iorange *ar;
    827       1.1   thorpej 
    828      1.30   mlelstv 	ar = ACPI_ALLOCATE(sizeof(*ar));
    829       1.1   thorpej 	if (ar == NULL) {
    830      1.23  jmcneill 		aprint_error_dev(dev, "ACPI: unable to allocate I/O range resource %d\n",
    831      1.23  jmcneill 		    res->ar_niorange);
    832       1.1   thorpej 		res->ar_niorange++;
    833       1.1   thorpej 		return;
    834       1.1   thorpej 	}
    835       1.1   thorpej 
    836       1.1   thorpej 	ar->ar_index = res->ar_niorange++;
    837       1.1   thorpej 	ar->ar_low = low;
    838       1.1   thorpej 	ar->ar_high = high;
    839       1.1   thorpej 	ar->ar_length = length;
    840       1.1   thorpej 	ar->ar_align = align;
    841       1.1   thorpej 
    842       1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_iorange, ar, ar_list);
    843       1.1   thorpej }
    844       1.1   thorpej 
    845       1.1   thorpej static void
    846      1.38  jmcneill acpi_res_parse_memory(device_t dev, void *context, uint64_t base,
    847      1.41  jmcneill     uint64_t length, uint64_t xbase)
    848       1.1   thorpej {
    849       1.1   thorpej 	struct acpi_resources *res = context;
    850       1.1   thorpej 	struct acpi_mem *ar;
    851       1.1   thorpej 
    852      1.30   mlelstv 	ar = ACPI_ALLOCATE(sizeof(*ar));
    853       1.1   thorpej 	if (ar == NULL) {
    854      1.23  jmcneill 		aprint_error_dev(dev, "ACPI: unable to allocate Memory resource %d\n",
    855      1.23  jmcneill 		    res->ar_nmem);
    856       1.1   thorpej 		res->ar_nmem++;
    857       1.1   thorpej 		return;
    858       1.1   thorpej 	}
    859       1.1   thorpej 
    860       1.1   thorpej 	ar->ar_index = res->ar_nmem++;
    861       1.1   thorpej 	ar->ar_base = base;
    862       1.1   thorpej 	ar->ar_length = length;
    863      1.41  jmcneill 	ar->ar_xbase = xbase;
    864       1.1   thorpej 
    865       1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_mem, ar, ar_list);
    866       1.1   thorpej }
    867       1.1   thorpej 
    868       1.1   thorpej static void
    869      1.38  jmcneill acpi_res_parse_memrange(device_t dev, void *context, uint64_t low,
    870      1.38  jmcneill     uint64_t high, uint64_t length, uint64_t align)
    871       1.1   thorpej {
    872       1.1   thorpej 	struct acpi_resources *res = context;
    873       1.1   thorpej 	struct acpi_memrange *ar;
    874       1.1   thorpej 
    875      1.30   mlelstv 	ar = ACPI_ALLOCATE(sizeof(*ar));
    876       1.1   thorpej 	if (ar == NULL) {
    877      1.23  jmcneill 		aprint_error_dev(dev, "ACPI: unable to allocate Memory range resource %d\n",
    878      1.23  jmcneill 		    res->ar_nmemrange);
    879       1.1   thorpej 		res->ar_nmemrange++;
    880       1.1   thorpej 		return;
    881       1.1   thorpej 	}
    882       1.1   thorpej 
    883       1.1   thorpej 	ar->ar_index = res->ar_nmemrange++;
    884       1.1   thorpej 	ar->ar_low = low;
    885       1.1   thorpej 	ar->ar_high = high;
    886       1.1   thorpej 	ar->ar_length = length;
    887       1.1   thorpej 	ar->ar_align = align;
    888       1.1   thorpej 
    889       1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_memrange, ar, ar_list);
    890       1.1   thorpej }
    891       1.1   thorpej 
    892       1.1   thorpej static void
    893      1.28    cegger acpi_res_parse_irq(device_t dev, void *context, uint32_t irq, uint32_t type)
    894       1.1   thorpej {
    895       1.1   thorpej 	struct acpi_resources *res = context;
    896       1.1   thorpej 	struct acpi_irq *ar;
    897       1.1   thorpej 
    898      1.30   mlelstv 	ar = ACPI_ALLOCATE(sizeof(*ar));
    899       1.1   thorpej 	if (ar == NULL) {
    900      1.23  jmcneill 		aprint_error_dev(dev, "ACPI: unable to allocate IRQ resource %d\n",
    901      1.23  jmcneill 		    res->ar_nirq);
    902       1.1   thorpej 		res->ar_nirq++;
    903       1.1   thorpej 		return;
    904       1.1   thorpej 	}
    905       1.1   thorpej 
    906       1.1   thorpej 	ar->ar_index = res->ar_nirq++;
    907       1.1   thorpej 	ar->ar_irq = irq;
    908       1.5      matt 	ar->ar_type = type;
    909       1.1   thorpej 
    910       1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_irq, ar, ar_list);
    911       1.1   thorpej }
    912       1.1   thorpej 
    913       1.1   thorpej static void
    914      1.28    cegger acpi_res_parse_drq(device_t dev, void *context, uint32_t drq)
    915       1.1   thorpej {
    916       1.1   thorpej 	struct acpi_resources *res = context;
    917       1.1   thorpej 	struct acpi_drq *ar;
    918       1.1   thorpej 
    919      1.30   mlelstv 	ar = ACPI_ALLOCATE(sizeof(*ar));
    920       1.1   thorpej 	if (ar == NULL) {
    921      1.23  jmcneill 		aprint_error_dev(dev, "ACPI: unable to allocate DRQ resource %d\n",
    922      1.23  jmcneill 		    res->ar_ndrq);
    923       1.1   thorpej 		res->ar_ndrq++;
    924       1.1   thorpej 		return;
    925       1.1   thorpej 	}
    926       1.1   thorpej 
    927       1.1   thorpej 	ar->ar_index = res->ar_ndrq++;
    928       1.1   thorpej 	ar->ar_drq = drq;
    929       1.1   thorpej 
    930       1.1   thorpej 	SIMPLEQ_INSERT_TAIL(&res->ar_drq, ar, ar_list);
    931       1.1   thorpej }
    932       1.1   thorpej 
    933       1.1   thorpej static void
    934      1.28    cegger acpi_res_parse_start_dep(device_t dev, void *context,
    935      1.21  christos     int preference)
    936       1.1   thorpej {
    937      1.10     kochi 
    938      1.35       wiz 	aprint_error_dev(dev, "ACPI: dependent functions not supported\n");
    939       1.1   thorpej }
    940       1.1   thorpej 
    941       1.1   thorpej static void
    942      1.28    cegger acpi_res_parse_end_dep(device_t dev, void *context)
    943       1.1   thorpej {
    944       1.1   thorpej 
    945       1.1   thorpej 	/* Nothing to do. */
    946       1.1   thorpej }
    947