summaryrefslogtreecommitdiff
path: root/sys/dev/acpi/acpi_resource.c
blob: c19a67eb13b94690e71a4089ce09ca60f190dd57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
/*	$NetBSD: acpi_resource.c,v 1.9 2003/11/03 18:07:10 mycroft Exp $	*/

/*
 * Copyright 2001 Wasabi Systems, Inc.
 * All rights reserved.
 *
 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed for the NetBSD Project by
 *	Wasabi Systems, Inc.
 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*-
 * Copyright (c) 2000 Michael Smith
 * Copyright (c) 2000 BSDi
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *              
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.         
 */

/*
 * ACPI resource parsing.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.9 2003/11/03 18:07:10 mycroft Exp $");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <dev/acpi/acpica.h>
#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>

#define	_COMPONENT	ACPI_RESOURCE_COMPONENT
ACPI_MODULE_NAME("RESOURCE")

/*
 * acpi_resource_parse:
 *
 *	Parse a device node's resources and fill them in for the
 *	client.
 *
 *	Note that it might be nice to also locate ACPI-specific resource
 *	items, such as GPE bits.
 */
ACPI_STATUS
acpi_resource_parse(struct device *dev, struct acpi_devnode *ad,
    void *arg, const struct acpi_resource_parse_ops *ops)
{
	ACPI_BUFFER buf;
	ACPI_RESOURCE *res;
	char *cur, *last;
	ACPI_STATUS status;
	void *context;
	int i;

	ACPI_FUNCTION_TRACE(__FUNCTION__);

	/*
	 * XXX Note, this means we only get devices that are currently
	 * decoding their address space.  This might not be what we
	 * want, in the long term.
	 */

	status = acpi_get(ad->ad_handle, &buf, AcpiGetCurrentResources);
	if (ACPI_FAILURE(status)) {
		printf("%s: ACPI: unable to get Current Resources: %s\n",
		    dev->dv_xname, AcpiFormatException(status));
		return_ACPI_STATUS(status);
	}

	ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "got %d bytes of _CRS\n",
	    buf.Length));

	(*ops->init)(dev, arg, &context);

	cur = buf.Pointer;
	last = cur + buf.Length;
	while (cur < last) {
		res = (ACPI_RESOURCE *) cur;
		cur += res->Length;

		switch (res->Id) {
		case ACPI_RSTYPE_END_TAG:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
			cur = last;
			break;

		case ACPI_RSTYPE_FIXED_IO:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
			    "FixedIo 0x%x/%d\n",
			    res->Data.FixedIo.BaseAddress,
			    res->Data.FixedIo.RangeLength));
			(*ops->ioport)(dev, context,
			    res->Data.FixedIo.BaseAddress,
			    res->Data.FixedIo.RangeLength);
			break;

		case ACPI_RSTYPE_IO:
			if (res->Data.Io.MinBaseAddress ==
			    res->Data.Io.MaxBaseAddress) {
				ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
				    "Io 0x%x/%d\n",
				    res->Data.Io.MinBaseAddress,
				    res->Data.Io.RangeLength));
				(*ops->ioport)(dev, context,
				    res->Data.Io.MinBaseAddress,
				    res->Data.Io.RangeLength);
			} else {
				ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
				    "Io 0x%x-0x%x/%d\n",
				    res->Data.Io.MinBaseAddress,
				    res->Data.Io.MaxBaseAddress,
				    res->Data.Io.RangeLength));
				(*ops->iorange)(dev, context,
				    res->Data.Io.MinBaseAddress,
				    res->Data.Io.MaxBaseAddress,
				    res->Data.Io.RangeLength,
				    res->Data.Io.Alignment);
			}
			break;

		case ACPI_RSTYPE_FIXED_MEM32:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
			    "FixedMemory32 0x%x/%d\n",
			    res->Data.FixedMemory32.RangeBaseAddress,
			    res->Data.FixedMemory32.RangeLength));
			(*ops->memory)(dev, context,
			    res->Data.FixedMemory32.RangeBaseAddress,
			    res->Data.FixedMemory32.RangeLength);
			break;

		case ACPI_RSTYPE_MEM32:
			if (res->Data.Memory32.MinBaseAddress ==
			    res->Data.Memory32.MaxBaseAddress) {
				ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, 
				    "Memory32 0x%x/%d\n",
				    res->Data.Memory32.MinBaseAddress,
				    res->Data.Memory32.RangeLength));
				(*ops->memory)(dev, context,
				    res->Data.Memory32.MinBaseAddress,
				    res->Data.Memory32.RangeLength);
			} else {
				ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
				    "Memory32 0x%x-0x%x/%d\n",
				    res->Data.Memory32.MinBaseAddress,
				    res->Data.Memory32.MaxBaseAddress,
				    res->Data.Memory32.RangeLength));
				(*ops->memrange)(dev, context,
				    res->Data.Memory32.MinBaseAddress,
				    res->Data.Memory32.MaxBaseAddress,
				    res->Data.Memory32.RangeLength,
				    res->Data.Memory32.Alignment);
			}
			break;

		case ACPI_RSTYPE_MEM24:
			if (res->Data.Memory24.MinBaseAddress ==
			    res->Data.Memory24.MaxBaseAddress) {
				ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, 
				    "Memory24 0x%x/%d\n",
				    res->Data.Memory24.MinBaseAddress,
				    res->Data.Memory24.RangeLength));
				(*ops->memory)(dev, context,
				    res->Data.Memory24.MinBaseAddress,
				    res->Data.Memory24.RangeLength);
			} else {
				ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
				    "Memory24 0x%x-0x%x/%d\n",
				    res->Data.Memory24.MinBaseAddress,
				    res->Data.Memory24.MaxBaseAddress,
				    res->Data.Memory24.RangeLength));
				(*ops->memrange)(dev, context,
				    res->Data.Memory24.MinBaseAddress,
				    res->Data.Memory24.MaxBaseAddress,
				    res->Data.Memory24.RangeLength,
				    res->Data.Memory24.Alignment);
			}
			break;

		case ACPI_RSTYPE_IRQ:
			for (i = 0; i < res->Data.Irq.NumberOfInterrupts; i++) {
				ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
				    "IRQ %d\n", res->Data.Irq.Interrupts[i]));
				(*ops->irq)(dev, context,
				    res->Data.Irq.Interrupts[i],
				    res->Data.Irq.EdgeLevel);
			}
			break;

		case ACPI_RSTYPE_DMA:
			for (i = 0; i < res->Data.Dma.NumberOfChannels; i++) {
				ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
				    "DRQ %d\n", res->Data.Dma.Channels[i]));
				(*ops->drq)(dev, context,
				    res->Data.Dma.Channels[i]);
			}
			break;

		case ACPI_RSTYPE_START_DPF:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
			    "Start dependant functions: %d\n",
			     res->Data.StartDpf.CompatibilityPriority));
			(*ops->start_dep)(dev, context,
			    res->Data.StartDpf.CompatibilityPriority);
			break;

		case ACPI_RSTYPE_END_DPF:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
			    "End dependant functions\n"));
			(*ops->end_dep)(dev, context);

		case ACPI_RSTYPE_ADDRESS32:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
			    "Address32 unimplemented\n"));
			break;

		case ACPI_RSTYPE_ADDRESS16:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
			    "Address16 unimplemented\n"));
			break;

		case ACPI_RSTYPE_EXT_IRQ:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
			    "ExtendedIrq unimplemented\n"));
			break;

		case ACPI_RSTYPE_VENDOR:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
			    "VendorSpecific unimplemented\n"));
			break;

		default:
			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
			    "Unknown resource type: %d\n", res->Id));
			break;
		}
	}

	AcpiOsFree(buf.Pointer);
	(*ops->fini)(dev, context);

	return_ACPI_STATUS(AE_OK);
}

/*
 * acpi_resource_print:
 *
 *	Print the resources assigned to a device.
 */
void
acpi_resource_print(struct device *dev, struct acpi_resources *res)
{
	const char *sep;

	if (SIMPLEQ_EMPTY(&res->ar_io) &&
	    SIMPLEQ_EMPTY(&res->ar_iorange) &&
	    SIMPLEQ_EMPTY(&res->ar_mem) &&
	    SIMPLEQ_EMPTY(&res->ar_memrange) &&
	    SIMPLEQ_EMPTY(&res->ar_irq) &&
	    SIMPLEQ_EMPTY(&res->ar_drq))
		return;

	printf("%s:", dev->dv_xname);

	if (SIMPLEQ_EMPTY(&res->ar_io) == 0) {
		struct acpi_io *ar;

		sep = "";
		printf(" io ");
		SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
			printf("%s0x%x", sep, ar->ar_base);
			if (ar->ar_length > 1)
				printf("-0x%x", ar->ar_base +
				    ar->ar_length - 1);
			sep = ",";
		}
	}

	/* XXX iorange */

	if (SIMPLEQ_EMPTY(&res->ar_mem) == 0) {
		struct acpi_mem *ar;

		sep = "";
		printf(" mem ");
		SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
			printf("%s0x%x", sep, ar->ar_base);
			if (ar->ar_length > 1)
				printf("-0x%x", ar->ar_base +
				    ar->ar_length - 1);
			sep = ",";
		}
	}

	/* XXX memrange */

	if (SIMPLEQ_EMPTY(&res->ar_irq) == 0) {
		struct acpi_irq *ar;

		sep = "";
		printf(" irq ");
		SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
			printf("%s%d", sep, ar->ar_irq);
			sep = ",";
		}
	}

	if (SIMPLEQ_EMPTY(&res->ar_drq) == 0) {
		struct acpi_drq *ar;

		sep = "";
		printf(" drq ");
		SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
			printf("%s%d", sep, ar->ar_drq);
			sep = ",";
		}
	}

	printf("\n");
}

struct acpi_io *
acpi_res_io(struct acpi_resources *res, int idx)
{
	struct acpi_io *ar;

	SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
		if (ar->ar_index == idx)
			return (ar);
	}
	return (NULL);
}

struct acpi_iorange *
acpi_res_iorange(struct acpi_resources *res, int idx)
{
	struct acpi_iorange *ar;

	SIMPLEQ_FOREACH(ar, &res->ar_iorange, ar_list) {
		if (ar->ar_index == idx)
			return (ar);
	}
	return (NULL);
}

struct acpi_mem *
acpi_res_mem(struct acpi_resources *res, int idx)
{
	struct acpi_mem *ar;

	SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
		if (ar->ar_index == idx)
			return (ar);
	}
	return (NULL);
}

struct acpi_memrange *
acpi_res_memrange(struct acpi_resources *res, int idx)
{
	struct acpi_memrange *ar;

	SIMPLEQ_FOREACH(ar, &res->ar_memrange, ar_list) {
		if (ar->ar_index == idx)
			return (ar);
	}
	return (NULL);
}

struct acpi_irq *
acpi_res_irq(struct acpi_resources *res, int idx)
{
	struct acpi_irq *ar;

	SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
		if (ar->ar_index == idx)
			return (ar);
	}
	return (NULL);
}

struct acpi_drq *
acpi_res_drq(struct acpi_resources *res, int idx)
{
	struct acpi_drq *ar;

	SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
		if (ar->ar_index == idx)
			return (ar);
	}
	return (NULL);
}

/*****************************************************************************
 * Default ACPI resource parse operations.
 *****************************************************************************/

static void	acpi_res_parse_init(struct device *, void *, void **);
static void	acpi_res_parse_fini(struct device *, void *);

static void	acpi_res_parse_ioport(struct device *, void *, uint32_t,
		    uint32_t);
static void	acpi_res_parse_iorange(struct device *, void *, uint32_t,
		    uint32_t, uint32_t, uint32_t);

static void	acpi_res_parse_memory(struct device *, void *, uint32_t,
		    uint32_t);
static void	acpi_res_parse_memrange(struct device *, void *, uint32_t,
		    uint32_t, uint32_t, uint32_t);

static void	acpi_res_parse_irq(struct device *, void *, uint32_t, uint32_t);
static void	acpi_res_parse_drq(struct device *, void *, uint32_t);

static void	acpi_res_parse_start_dep(struct device *, void *, int);
static void	acpi_res_parse_end_dep(struct device *, void *);

const struct acpi_resource_parse_ops acpi_resource_parse_ops_default = {
	acpi_res_parse_init,
	acpi_res_parse_fini,

	acpi_res_parse_ioport,
	acpi_res_parse_iorange,

	acpi_res_parse_memory,
	acpi_res_parse_memrange,

	acpi_res_parse_irq,
	acpi_res_parse_drq,

	acpi_res_parse_start_dep,
	acpi_res_parse_end_dep,
};

static void
acpi_res_parse_init(struct device *dev, void *arg, void **contextp)
{
	struct acpi_resources *res = arg;

	SIMPLEQ_INIT(&res->ar_io);
	res->ar_nio = 0;

	SIMPLEQ_INIT(&res->ar_iorange);
	res->ar_niorange = 0;

	SIMPLEQ_INIT(&res->ar_mem);
	res->ar_nmem = 0;

	SIMPLEQ_INIT(&res->ar_memrange);
	res->ar_nmemrange = 0;

	SIMPLEQ_INIT(&res->ar_irq);
	res->ar_nirq = 0;

	SIMPLEQ_INIT(&res->ar_drq);
	res->ar_ndrq = 0;

	*contextp = res;
}

static void
acpi_res_parse_fini(struct device *dev, void *context)
{
	struct acpi_resources *res = context;

	/* Print the resources we're using. */
	acpi_resource_print(dev, res);
}

static void
acpi_res_parse_ioport(struct device *dev, void *context, uint32_t base,
    uint32_t length)
{
	struct acpi_resources *res = context;
	struct acpi_io *ar;

	/*
	 * Check if there is another I/O port directly below/under
	 * this one.
	 */
	SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
		if (ar->ar_base == base + length ) {
			/*
			 * Entry just below existing entry - adjust
			 * the entry and return.
			 */
			ar->ar_base = base;
			ar->ar_length += length;
			return;
		} else if (ar->ar_base + ar->ar_length == base) {
			/*
			 * Entry just above existing entry - adjust
			 * the entry and return.
			 */
			ar->ar_length += length;
			return;
		}
	}

	ar = AcpiOsAllocate(sizeof(*ar));
	if (ar == NULL) {
		printf("%s: ACPI: unable to allocate I/O resource %d\n",
		    dev->dv_xname, res->ar_nio);
		res->ar_nio++;
		return;
	}

	ar->ar_index = res->ar_nio++;
	ar->ar_base = base;
	ar->ar_length = length;

	SIMPLEQ_INSERT_TAIL(&res->ar_io, ar, ar_list);
}

static void
acpi_res_parse_iorange(struct device *dev, void *context, uint32_t low,
    uint32_t high, uint32_t length, uint32_t align)
{
	struct acpi_resources *res = context;
	struct acpi_iorange *ar;

	ar = AcpiOsAllocate(sizeof(*ar));
	if (ar == NULL) {
		printf("%s: ACPI: unable to allocate I/O range resource %d\n",
		    dev->dv_xname, res->ar_niorange);
		res->ar_niorange++;
		return;
	}

	ar->ar_index = res->ar_niorange++;
	ar->ar_low = low;
	ar->ar_high = high;
	ar->ar_length = length;
	ar->ar_align = align;

	SIMPLEQ_INSERT_TAIL(&res->ar_iorange, ar, ar_list);
}

static void
acpi_res_parse_memory(struct device *dev, void *context, uint32_t base,
    uint32_t length)
{
	struct acpi_resources *res = context;
	struct acpi_mem *ar;

	ar = AcpiOsAllocate(sizeof(*ar));
	if (ar == NULL) {
		printf("%s: ACPI: unable to allocate Memory resource %d\n",
		    dev->dv_xname, res->ar_nmem);
		res->ar_nmem++;
		return;
	}

	ar->ar_index = res->ar_nmem++;
	ar->ar_base = base;
	ar->ar_length = length;

	SIMPLEQ_INSERT_TAIL(&res->ar_mem, ar, ar_list);
}

static void
acpi_res_parse_memrange(struct device *dev, void *context, uint32_t low,
    uint32_t high, uint32_t length, uint32_t align)
{
	struct acpi_resources *res = context;
	struct acpi_memrange *ar;

	ar = AcpiOsAllocate(sizeof(*ar));
	if (ar == NULL) {
		printf("%s: ACPI: unable to allocate Memory range resource "
		    "%d\n", dev->dv_xname, res->ar_nmemrange);
		res->ar_nmemrange++;
		return;
	}

	ar->ar_index = res->ar_nmemrange++;
	ar->ar_low = low;
	ar->ar_high = high;
	ar->ar_length = length;
	ar->ar_align = align;

	SIMPLEQ_INSERT_TAIL(&res->ar_memrange, ar, ar_list);
}

static void
acpi_res_parse_irq(struct device *dev, void *context, uint32_t irq, uint32_t type)
{
	struct acpi_resources *res = context;
	struct acpi_irq *ar;

	ar = AcpiOsAllocate(sizeof(*ar));
	if (ar == NULL) {
		printf("%s: ACPI: unable to allocate IRQ resource %d\n",
		    dev->dv_xname, res->ar_nirq);
		res->ar_nirq++;
		return;
	}

	ar->ar_index = res->ar_nirq++;
	ar->ar_irq = irq;
	ar->ar_type = type;

	SIMPLEQ_INSERT_TAIL(&res->ar_irq, ar, ar_list);
}

static void
acpi_res_parse_drq(struct device *dev, void *context, uint32_t drq)
{
	struct acpi_resources *res = context;
	struct acpi_drq *ar;

	ar = AcpiOsAllocate(sizeof(*ar));
	if (ar == NULL) {
		printf("%s: ACPI: unable to allocate DRQ resource %d\n",
		    dev->dv_xname, res->ar_ndrq);
		res->ar_ndrq++;
		return;
	}

	ar->ar_index = res->ar_ndrq++;
	ar->ar_drq = drq;

	SIMPLEQ_INSERT_TAIL(&res->ar_drq, ar, ar_list);
}

static void
acpi_res_parse_start_dep(struct device *dev, void *context, int preference)
{
	
	printf("%s: ACPI: dependant functions not supported\n",
	    dev->dv_xname);
}

static void
acpi_res_parse_end_dep(struct device *dev, void *context)
{

	/* Nothing to do. */
}