rsparser.c 26.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
/*
 * pnpacpi -- PnP ACPI driver
 *
 * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
 * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
B
Bob Moore 已提交
6
 *
L
Linus Torvalds 已提交
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
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include <linux/kernel.h>
#include <linux/acpi.h>
#include <linux/pci.h>
#include "pnpacpi.h"

#ifdef CONFIG_IA64
#define valid_IRQ(i) (1)
#else
#define valid_IRQ(i) (((i) != 0) && ((i) != 2))
#endif

/*
 * Allocated Resources
 */
B
Bob Moore 已提交
35
static int irq_flags(int triggering, int polarity)
L
Linus Torvalds 已提交
36
{
B
Bob Moore 已提交
37
	if (triggering == ACPI_LEVEL_SENSITIVE) {
B
Bjorn Helgaas 已提交
38
		if (polarity == ACPI_ACTIVE_LOW)
B
Bjorn Helgaas 已提交
39
			return IORESOURCE_IRQ_LOWLEVEL;
L
Linus Torvalds 已提交
40
		else
B
Bjorn Helgaas 已提交
41
			return IORESOURCE_IRQ_HIGHLEVEL;
B
Bjorn Helgaas 已提交
42
	} else {
B
Bjorn Helgaas 已提交
43
		if (polarity == ACPI_ACTIVE_LOW)
B
Bjorn Helgaas 已提交
44
			return IORESOURCE_IRQ_LOWEDGE;
L
Linus Torvalds 已提交
45
		else
B
Bjorn Helgaas 已提交
46
			return IORESOURCE_IRQ_HIGHEDGE;
L
Linus Torvalds 已提交
47 48 49
	}
}

B
Bob Moore 已提交
50
static void decode_irq_flags(int flag, int *triggering, int *polarity)
L
Linus Torvalds 已提交
51 52 53
{
	switch (flag) {
	case IORESOURCE_IRQ_LOWLEVEL:
B
Bob Moore 已提交
54 55
		*triggering = ACPI_LEVEL_SENSITIVE;
		*polarity = ACPI_ACTIVE_LOW;
L
Linus Torvalds 已提交
56
		break;
B
Bjorn Helgaas 已提交
57
	case IORESOURCE_IRQ_HIGHLEVEL:
B
Bob Moore 已提交
58 59
		*triggering = ACPI_LEVEL_SENSITIVE;
		*polarity = ACPI_ACTIVE_HIGH;
L
Linus Torvalds 已提交
60 61
		break;
	case IORESOURCE_IRQ_LOWEDGE:
B
Bob Moore 已提交
62 63
		*triggering = ACPI_EDGE_SENSITIVE;
		*polarity = ACPI_ACTIVE_LOW;
L
Linus Torvalds 已提交
64 65
		break;
	case IORESOURCE_IRQ_HIGHEDGE:
B
Bob Moore 已提交
66 67
		*triggering = ACPI_EDGE_SENSITIVE;
		*polarity = ACPI_ACTIVE_HIGH;
L
Linus Torvalds 已提交
68 69 70 71
		break;
	}
}

B
Bjorn Helgaas 已提交
72 73 74
static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res,
						u32 gsi, int triggering,
						int polarity, int shareable)
L
Linus Torvalds 已提交
75 76
{
	int i = 0;
77
	int irq;
78
	int p, t;
79
	static unsigned char warned;
80 81 82 83

	if (!valid_IRQ(gsi))
		return;

L
Linus Torvalds 已提交
84
	while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
B
Bjorn Helgaas 已提交
85
	       i < PNP_MAX_IRQ)
L
Linus Torvalds 已提交
86
		i++;
87 88 89 90 91 92
	if (i >= PNP_MAX_IRQ) {
		if (!warned) {
			printk(KERN_WARNING "pnpacpi: exceeded the max number"
				" of IRQ resources: %d\n", PNP_MAX_IRQ);
			warned = 1;
		}
93
		return;
94
	}
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	/*
	 * in IO-APIC mode, use overrided attribute. Two reasons:
	 * 1. BIOS bug in DSDT
	 * 2. BIOS uses IO-APIC mode Interrupt Source Override
	 */
	if (!acpi_get_override_irq(gsi, &t, &p)) {
		t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
		p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;

		if (triggering != t || polarity != p) {
			pnp_warn("IRQ %d override to %s, %s",
				gsi, t ? "edge":"level", p ? "low":"high");
			triggering = t;
			polarity = p;
		}
	}

B
Bjorn Helgaas 已提交
112
	res->irq_resource[i].flags = IORESOURCE_IRQ;	// Also clears _UNSET flag
113
	res->irq_resource[i].flags |= irq_flags(triggering, polarity);
B
Bob Moore 已提交
114
	irq = acpi_register_gsi(gsi, triggering, polarity);
115 116 117
	if (irq < 0) {
		res->irq_resource[i].flags |= IORESOURCE_DISABLED;
		return;
L
Linus Torvalds 已提交
118
	}
119

120 121 122
	if (shareable)
		res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;

123 124 125
	res->irq_resource[i].start = irq;
	res->irq_resource[i].end = irq;
	pcibios_penalize_isa_irq(irq, 1);
L
Linus Torvalds 已提交
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
static int dma_flags(int type, int bus_master, int transfer)
{
	int flags = 0;

	if (bus_master)
		flags |= IORESOURCE_DMA_MASTER;
	switch (type) {
	case ACPI_COMPATIBILITY:
		flags |= IORESOURCE_DMA_COMPATIBLE;
		break;
	case ACPI_TYPE_A:
		flags |= IORESOURCE_DMA_TYPEA;
		break;
	case ACPI_TYPE_B:
		flags |= IORESOURCE_DMA_TYPEB;
		break;
	case ACPI_TYPE_F:
		flags |= IORESOURCE_DMA_TYPEF;
		break;
	default:
		/* Set a default value ? */
		flags |= IORESOURCE_DMA_COMPATIBLE;
		pnp_err("Invalid DMA type");
	}
	switch (transfer) {
	case ACPI_TRANSFER_8:
		flags |= IORESOURCE_DMA_8BIT;
		break;
	case ACPI_TRANSFER_8_16:
		flags |= IORESOURCE_DMA_8AND16BIT;
		break;
	case ACPI_TRANSFER_16:
		flags |= IORESOURCE_DMA_16BIT;
		break;
	default:
		/* Set a default value ? */
		flags |= IORESOURCE_DMA_8AND16BIT;
		pnp_err("Invalid DMA transfer type");
	}

	return flags;
}

B
Bjorn Helgaas 已提交
171
static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
172
						u32 dma, int flags)
L
Linus Torvalds 已提交
173 174
{
	int i = 0;
175
	static unsigned char warned;
B
Bjorn Helgaas 已提交
176

177
	while (i < PNP_MAX_DMA &&
B
Bjorn Helgaas 已提交
178
	       !(res->dma_resource[i].flags & IORESOURCE_UNSET))
L
Linus Torvalds 已提交
179 180
		i++;
	if (i < PNP_MAX_DMA) {
B
Bjorn Helgaas 已提交
181
		res->dma_resource[i].flags = IORESOURCE_DMA;	// Also clears _UNSET flag
182
		res->dma_resource[i].flags |= flags;
L
Linus Torvalds 已提交
183 184 185 186
		if (dma == -1) {
			res->dma_resource[i].flags |= IORESOURCE_DISABLED;
			return;
		}
187 188
		res->dma_resource[i].start = dma;
		res->dma_resource[i].end = dma;
189
	} else if (!warned) {
190
		printk(KERN_WARNING "pnpacpi: exceeded the max number of DMA "
191
				"resources: %d \n", PNP_MAX_DMA);
192
		warned = 1;
L
Linus Torvalds 已提交
193 194 195
	}
}

B
Bjorn Helgaas 已提交
196 197
static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
					       u64 io, u64 len, int io_decode)
L
Linus Torvalds 已提交
198 199
{
	int i = 0;
200
	static unsigned char warned;
B
Bjorn Helgaas 已提交
201

L
Linus Torvalds 已提交
202
	while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
B
Bjorn Helgaas 已提交
203
	       i < PNP_MAX_PORT)
L
Linus Torvalds 已提交
204 205
		i++;
	if (i < PNP_MAX_PORT) {
B
Bjorn Helgaas 已提交
206
		res->port_resource[i].flags = IORESOURCE_IO;	// Also clears _UNSET flag
207 208
		if (io_decode == ACPI_DECODE_16)
			res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
B
Bjorn Helgaas 已提交
209
		if (len <= 0 || (io + len - 1) >= 0x10003) {
L
Linus Torvalds 已提交
210 211 212
			res->port_resource[i].flags |= IORESOURCE_DISABLED;
			return;
		}
213 214
		res->port_resource[i].start = io;
		res->port_resource[i].end = io + len - 1;
215
	} else if (!warned) {
216
		printk(KERN_WARNING "pnpacpi: exceeded the max number of IO "
217
				"resources: %d \n", PNP_MAX_PORT);
218
		warned = 1;
L
Linus Torvalds 已提交
219 220 221
	}
}

B
Bjorn Helgaas 已提交
222 223 224
static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
						u64 mem, u64 len,
						int write_protect)
L
Linus Torvalds 已提交
225 226
{
	int i = 0;
227
	static unsigned char warned;
B
Bjorn Helgaas 已提交
228

L
Linus Torvalds 已提交
229
	while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
B
Bjorn Helgaas 已提交
230
	       (i < PNP_MAX_MEM))
L
Linus Torvalds 已提交
231 232
		i++;
	if (i < PNP_MAX_MEM) {
B
Bjorn Helgaas 已提交
233
		res->mem_resource[i].flags = IORESOURCE_MEM;	// Also clears _UNSET flag
L
Linus Torvalds 已提交
234 235 236 237
		if (len <= 0) {
			res->mem_resource[i].flags |= IORESOURCE_DISABLED;
			return;
		}
B
Bjorn Helgaas 已提交
238
		if (write_protect == ACPI_READ_WRITE_MEMORY)
239 240
			res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;

241 242
		res->mem_resource[i].start = mem;
		res->mem_resource[i].end = mem + len - 1;
243
	} else if (!warned) {
244
		printk(KERN_WARNING "pnpacpi: exceeded the max number of mem "
245
				"resources: %d\n", PNP_MAX_MEM);
246
		warned = 1;
L
Linus Torvalds 已提交
247 248 249
	}
}

B
Bjorn Helgaas 已提交
250 251
static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
						  struct acpi_resource *res)
252 253 254 255 256 257 258
{
	struct acpi_resource_address64 addr, *p = &addr;
	acpi_status status;

	status = acpi_resource_to_address64(res, p);
	if (!ACPI_SUCCESS(status)) {
		pnp_warn("PnPACPI: failed to convert resource type %d",
B
Bjorn Helgaas 已提交
259
			 res->type);
260 261 262
		return;
	}

263 264 265
	if (p->producer_consumer == ACPI_PRODUCER)
		return;

266 267
	if (p->resource_type == ACPI_MEMORY_RANGE)
		pnpacpi_parse_allocated_memresource(res_table,
B
Bjorn Helgaas 已提交
268 269
			p->minimum, p->address_length,
			p->info.mem.write_protect);
270 271
	else if (p->resource_type == ACPI_IO_RANGE)
		pnpacpi_parse_allocated_ioresource(res_table,
B
Bjorn Helgaas 已提交
272 273 274
			p->minimum, p->address_length,
			p->granularity == 0xfff ? ACPI_DECODE_10 :
				ACPI_DECODE_16);
275
}
L
Linus Torvalds 已提交
276 277

static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
B
Bjorn Helgaas 已提交
278
					      void *data)
L
Linus Torvalds 已提交
279
{
280
	struct pnp_resource_table *res_table = data;
281 282 283 284 285 286 287 288
	struct acpi_resource_irq *irq;
	struct acpi_resource_dma *dma;
	struct acpi_resource_io *io;
	struct acpi_resource_fixed_io *fixed_io;
	struct acpi_resource_memory24 *memory24;
	struct acpi_resource_memory32 *memory32;
	struct acpi_resource_fixed_memory32 *fixed_memory32;
	struct acpi_resource_extended_irq *extended_irq;
289
	int i;
L
Linus Torvalds 已提交
290

291
	switch (res->type) {
B
Bob Moore 已提交
292
	case ACPI_RESOURCE_TYPE_IRQ:
293 294 295 296
		/*
		 * Per spec, only one interrupt per descriptor is allowed in
		 * _CRS, but some firmware violates this, so parse them all.
		 */
297 298
		irq = &res->data.irq;
		for (i = 0; i < irq->interrupt_count; i++) {
299
			pnpacpi_parse_allocated_irqresource(res_table,
300 301 302 303
				irq->interrupts[i],
				irq->triggering,
				irq->polarity,
				irq->sharable);
L
Linus Torvalds 已提交
304 305 306
		}
		break;

B
Bob Moore 已提交
307
	case ACPI_RESOURCE_TYPE_DMA:
308 309
		dma = &res->data.dma;
		if (dma->channel_count > 0)
B
Bob Moore 已提交
310
			pnpacpi_parse_allocated_dmaresource(res_table,
311
				dma->channels[0],
312 313
				dma_flags(dma->type, dma->bus_master,
					  dma->transfer));
L
Linus Torvalds 已提交
314
		break;
315

B
Bob Moore 已提交
316
	case ACPI_RESOURCE_TYPE_IO:
317
		io = &res->data.io;
B
Bob Moore 已提交
318
		pnpacpi_parse_allocated_ioresource(res_table,
319 320 321
			io->minimum,
			io->address_length,
			io->io_decode);
L
Linus Torvalds 已提交
322
		break;
323 324 325 326 327

	case ACPI_RESOURCE_TYPE_START_DEPENDENT:
	case ACPI_RESOURCE_TYPE_END_DEPENDENT:
		break;

B
Bob Moore 已提交
328
	case ACPI_RESOURCE_TYPE_FIXED_IO:
329
		fixed_io = &res->data.fixed_io;
B
Bob Moore 已提交
330
		pnpacpi_parse_allocated_ioresource(res_table,
331 332
			fixed_io->address,
			fixed_io->address_length,
B
Bjorn Helgaas 已提交
333
			ACPI_DECODE_10);
L
Linus Torvalds 已提交
334
		break;
335 336 337 338 339 340 341

	case ACPI_RESOURCE_TYPE_VENDOR:
		break;

	case ACPI_RESOURCE_TYPE_END_TAG:
		break;

B
Bob Moore 已提交
342
	case ACPI_RESOURCE_TYPE_MEMORY24:
343
		memory24 = &res->data.memory24;
B
Bob Moore 已提交
344
		pnpacpi_parse_allocated_memresource(res_table,
345 346 347
			memory24->minimum,
			memory24->address_length,
			memory24->write_protect);
L
Linus Torvalds 已提交
348
		break;
B
Bob Moore 已提交
349
	case ACPI_RESOURCE_TYPE_MEMORY32:
350
		memory32 = &res->data.memory32;
B
Bob Moore 已提交
351
		pnpacpi_parse_allocated_memresource(res_table,
352 353 354
			memory32->minimum,
			memory32->address_length,
			memory32->write_protect);
L
Linus Torvalds 已提交
355
		break;
B
Bob Moore 已提交
356
	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
357
		fixed_memory32 = &res->data.fixed_memory32;
B
Bob Moore 已提交
358
		pnpacpi_parse_allocated_memresource(res_table,
359 360 361
			fixed_memory32->address,
			fixed_memory32->address_length,
			fixed_memory32->write_protect);
L
Linus Torvalds 已提交
362
		break;
B
Bob Moore 已提交
363 364 365
	case ACPI_RESOURCE_TYPE_ADDRESS16:
	case ACPI_RESOURCE_TYPE_ADDRESS32:
	case ACPI_RESOURCE_TYPE_ADDRESS64:
366
		pnpacpi_parse_allocated_address_space(res_table, res);
L
Linus Torvalds 已提交
367
		break;
368 369

	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
370 371
		if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
			return AE_OK;
372 373 374
		break;

	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
375 376
		extended_irq = &res->data.extended_irq;
		if (extended_irq->producer_consumer == ACPI_PRODUCER)
377 378
			return AE_OK;

379
		for (i = 0; i < extended_irq->interrupt_count; i++) {
380
			pnpacpi_parse_allocated_irqresource(res_table,
381 382 383 384
				extended_irq->interrupts[i],
				extended_irq->triggering,
				extended_irq->polarity,
				extended_irq->sharable);
385 386 387 388
		}
		break;

	case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
L
Linus Torvalds 已提交
389
		break;
390

L
Linus Torvalds 已提交
391
	default:
392
		pnp_warn("PnPACPI: unknown resource type %d", res->type);
L
Linus Torvalds 已提交
393 394
		return AE_ERROR;
	}
B
Bjorn Helgaas 已提交
395

L
Linus Torvalds 已提交
396 397 398
	return AE_OK;
}

B
Bjorn Helgaas 已提交
399 400
acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
					     struct pnp_resource_table * res)
L
Linus Torvalds 已提交
401 402 403 404
{
	/* Blank the resource table values */
	pnp_init_resource_table(res);

B
Bjorn Helgaas 已提交
405 406
	return acpi_walk_resources(handle, METHOD_NAME__CRS,
				   pnpacpi_allocated_resource, res);
L
Linus Torvalds 已提交
407 408
}

409 410
static __init void pnpacpi_parse_dma_option(struct pnp_option *option,
					    struct acpi_resource_dma *p)
L
Linus Torvalds 已提交
411 412
{
	int i;
B
Bjorn Helgaas 已提交
413
	struct pnp_dma *dma;
L
Linus Torvalds 已提交
414

B
Bob Moore 已提交
415
	if (p->channel_count == 0)
L
Linus Torvalds 已提交
416
		return;
417
	dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
L
Linus Torvalds 已提交
418 419 420
	if (!dma)
		return;

B
Bjorn Helgaas 已提交
421
	for (i = 0; i < p->channel_count; i++)
L
Linus Torvalds 已提交
422
		dma->map |= 1 << p->channels[i];
423 424

	dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
L
Linus Torvalds 已提交
425

B
Bjorn Helgaas 已提交
426
	pnp_register_dma_resource(option, dma);
L
Linus Torvalds 已提交
427 428
}

429 430
static __init void pnpacpi_parse_irq_option(struct pnp_option *option,
					    struct acpi_resource_irq *p)
L
Linus Torvalds 已提交
431 432
{
	int i;
B
Bjorn Helgaas 已提交
433 434
	struct pnp_irq *irq;

B
Bob Moore 已提交
435
	if (p->interrupt_count == 0)
L
Linus Torvalds 已提交
436
		return;
437
	irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
L
Linus Torvalds 已提交
438 439 440
	if (!irq)
		return;

B
Bjorn Helgaas 已提交
441
	for (i = 0; i < p->interrupt_count; i++)
L
Linus Torvalds 已提交
442 443
		if (p->interrupts[i])
			__set_bit(p->interrupts[i], irq->map);
B
Bob Moore 已提交
444
	irq->flags = irq_flags(p->triggering, p->polarity);
L
Linus Torvalds 已提交
445 446 447 448

	pnp_register_irq_resource(option, irq);
}

449 450
static __init void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
					struct acpi_resource_extended_irq *p)
L
Linus Torvalds 已提交
451 452
{
	int i;
B
Bjorn Helgaas 已提交
453
	struct pnp_irq *irq;
L
Linus Torvalds 已提交
454

B
Bob Moore 已提交
455
	if (p->interrupt_count == 0)
L
Linus Torvalds 已提交
456
		return;
457
	irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
L
Linus Torvalds 已提交
458 459 460
	if (!irq)
		return;

B
Bjorn Helgaas 已提交
461
	for (i = 0; i < p->interrupt_count; i++)
L
Linus Torvalds 已提交
462 463
		if (p->interrupts[i])
			__set_bit(p->interrupts[i], irq->map);
B
Bob Moore 已提交
464
	irq->flags = irq_flags(p->triggering, p->polarity);
L
Linus Torvalds 已提交
465 466 467 468

	pnp_register_irq_resource(option, irq);
}

469 470
static __init void pnpacpi_parse_port_option(struct pnp_option *option,
					     struct acpi_resource_io *io)
L
Linus Torvalds 已提交
471
{
B
Bjorn Helgaas 已提交
472
	struct pnp_port *port;
L
Linus Torvalds 已提交
473

B
Bob Moore 已提交
474
	if (io->address_length == 0)
L
Linus Torvalds 已提交
475
		return;
476
	port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
L
Linus Torvalds 已提交
477 478
	if (!port)
		return;
B
Bob Moore 已提交
479 480
	port->min = io->minimum;
	port->max = io->maximum;
L
Linus Torvalds 已提交
481
	port->align = io->alignment;
B
Bob Moore 已提交
482 483
	port->size = io->address_length;
	port->flags = ACPI_DECODE_16 == io->io_decode ?
B
Bjorn Helgaas 已提交
484
	    PNP_PORT_FLAG_16BITADDR : 0;
B
Bjorn Helgaas 已提交
485
	pnp_register_port_resource(option, port);
L
Linus Torvalds 已提交
486 487
}

488 489
static __init void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
					struct acpi_resource_fixed_io *io)
L
Linus Torvalds 已提交
490
{
B
Bjorn Helgaas 已提交
491
	struct pnp_port *port;
L
Linus Torvalds 已提交
492

B
Bob Moore 已提交
493
	if (io->address_length == 0)
L
Linus Torvalds 已提交
494
		return;
495
	port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
L
Linus Torvalds 已提交
496 497
	if (!port)
		return;
B
Bob Moore 已提交
498 499
	port->min = port->max = io->address;
	port->size = io->address_length;
L
Linus Torvalds 已提交
500 501
	port->align = 0;
	port->flags = PNP_PORT_FLAG_FIXED;
B
Bjorn Helgaas 已提交
502
	pnp_register_port_resource(option, port);
L
Linus Torvalds 已提交
503 504
}

505 506
static __init void pnpacpi_parse_mem24_option(struct pnp_option *option,
					      struct acpi_resource_memory24 *p)
L
Linus Torvalds 已提交
507
{
B
Bjorn Helgaas 已提交
508
	struct pnp_mem *mem;
L
Linus Torvalds 已提交
509

B
Bob Moore 已提交
510
	if (p->address_length == 0)
L
Linus Torvalds 已提交
511
		return;
512
	mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
L
Linus Torvalds 已提交
513 514
	if (!mem)
		return;
B
Bob Moore 已提交
515 516
	mem->min = p->minimum;
	mem->max = p->maximum;
L
Linus Torvalds 已提交
517
	mem->align = p->alignment;
B
Bob Moore 已提交
518
	mem->size = p->address_length;
L
Linus Torvalds 已提交
519

B
Bob Moore 已提交
520
	mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
B
Bjorn Helgaas 已提交
521
	    IORESOURCE_MEM_WRITEABLE : 0;
L
Linus Torvalds 已提交
522

B
Bjorn Helgaas 已提交
523
	pnp_register_mem_resource(option, mem);
L
Linus Torvalds 已提交
524 525
}

526 527
static __init void pnpacpi_parse_mem32_option(struct pnp_option *option,
					      struct acpi_resource_memory32 *p)
L
Linus Torvalds 已提交
528
{
B
Bjorn Helgaas 已提交
529
	struct pnp_mem *mem;
L
Linus Torvalds 已提交
530

B
Bob Moore 已提交
531
	if (p->address_length == 0)
L
Linus Torvalds 已提交
532
		return;
533
	mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
L
Linus Torvalds 已提交
534 535
	if (!mem)
		return;
B
Bob Moore 已提交
536 537
	mem->min = p->minimum;
	mem->max = p->maximum;
L
Linus Torvalds 已提交
538
	mem->align = p->alignment;
B
Bob Moore 已提交
539
	mem->size = p->address_length;
L
Linus Torvalds 已提交
540

B
Bob Moore 已提交
541
	mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
B
Bjorn Helgaas 已提交
542
	    IORESOURCE_MEM_WRITEABLE : 0;
L
Linus Torvalds 已提交
543

B
Bjorn Helgaas 已提交
544
	pnp_register_mem_resource(option, mem);
L
Linus Torvalds 已提交
545 546
}

547 548
static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
					struct acpi_resource_fixed_memory32 *p)
L
Linus Torvalds 已提交
549
{
B
Bjorn Helgaas 已提交
550
	struct pnp_mem *mem;
L
Linus Torvalds 已提交
551

B
Bob Moore 已提交
552
	if (p->address_length == 0)
L
Linus Torvalds 已提交
553
		return;
554
	mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
L
Linus Torvalds 已提交
555 556
	if (!mem)
		return;
B
Bob Moore 已提交
557 558
	mem->min = mem->max = p->address;
	mem->size = p->address_length;
L
Linus Torvalds 已提交
559 560
	mem->align = 0;

B
Bob Moore 已提交
561
	mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
B
Bjorn Helgaas 已提交
562
	    IORESOURCE_MEM_WRITEABLE : 0;
L
Linus Torvalds 已提交
563

B
Bjorn Helgaas 已提交
564
	pnp_register_mem_resource(option, mem);
L
Linus Torvalds 已提交
565 566
}

567 568
static __init void pnpacpi_parse_address_option(struct pnp_option *option,
						struct acpi_resource *r)
569 570 571
{
	struct acpi_resource_address64 addr, *p = &addr;
	acpi_status status;
B
Bjorn Helgaas 已提交
572 573
	struct pnp_mem *mem;
	struct pnp_port *port;
574 575 576

	status = acpi_resource_to_address64(r, p);
	if (!ACPI_SUCCESS(status)) {
B
Bjorn Helgaas 已提交
577 578
		pnp_warn("PnPACPI: failed to convert resource type %d",
			 r->type);
579 580 581 582 583 584 585
		return;
	}

	if (p->address_length == 0)
		return;

	if (p->resource_type == ACPI_MEMORY_RANGE) {
586
		mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
587 588
		if (!mem)
			return;
L
Len Brown 已提交
589
		mem->min = mem->max = p->minimum;
590 591
		mem->size = p->address_length;
		mem->align = 0;
L
Len Brown 已提交
592
		mem->flags = (p->info.mem.write_protect ==
B
Bjorn Helgaas 已提交
593 594
			      ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
		    : 0;
B
Bjorn Helgaas 已提交
595
		pnp_register_mem_resource(option, mem);
596
	} else if (p->resource_type == ACPI_IO_RANGE) {
597
		port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
598 599
		if (!port)
			return;
L
Len Brown 已提交
600
		port->min = port->max = p->minimum;
601 602 603
		port->size = p->address_length;
		port->align = 0;
		port->flags = PNP_PORT_FLAG_FIXED;
B
Bjorn Helgaas 已提交
604
		pnp_register_port_resource(option, port);
605 606 607
	}
}

L
Linus Torvalds 已提交
608 609
struct acpipnp_parse_option_s {
	struct pnp_option *option;
M
Matthieu Castet 已提交
610
	struct pnp_option *option_independent;
L
Linus Torvalds 已提交
611 612 613
	struct pnp_dev *dev;
};

614 615
static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
						  void *data)
L
Linus Torvalds 已提交
616 617
{
	int priority = 0;
618
	struct acpipnp_parse_option_s *parse_data = data;
L
Linus Torvalds 已提交
619 620 621
	struct pnp_dev *dev = parse_data->dev;
	struct pnp_option *option = parse_data->option;

622
	switch (res->type) {
B
Bjorn Helgaas 已提交
623 624 625
	case ACPI_RESOURCE_TYPE_IRQ:
		pnpacpi_parse_irq_option(option, &res->data.irq);
		break;
626

B
Bjorn Helgaas 已提交
627 628 629
	case ACPI_RESOURCE_TYPE_DMA:
		pnpacpi_parse_dma_option(option, &res->data.dma);
		break;
630

B
Bjorn Helgaas 已提交
631 632 633 634
	case ACPI_RESOURCE_TYPE_START_DEPENDENT:
		switch (res->data.start_dpf.compatibility_priority) {
		case ACPI_GOOD_CONFIGURATION:
			priority = PNP_RES_PRIORITY_PREFERRED;
L
Linus Torvalds 已提交
635
			break;
636

B
Bjorn Helgaas 已提交
637 638
		case ACPI_ACCEPTABLE_CONFIGURATION:
			priority = PNP_RES_PRIORITY_ACCEPTABLE;
M
Matthieu Castet 已提交
639
			break;
640

B
Bjorn Helgaas 已提交
641 642
		case ACPI_SUB_OPTIMAL_CONFIGURATION:
			priority = PNP_RES_PRIORITY_FUNCTIONAL;
643
			break;
B
Bjorn Helgaas 已提交
644 645
		default:
			priority = PNP_RES_PRIORITY_INVALID;
646
			break;
B
Bjorn Helgaas 已提交
647
		}
B
Bjorn Helgaas 已提交
648
		/* TBD: Consider performance/robustness bits */
B
Bjorn Helgaas 已提交
649 650 651 652 653
		option = pnp_register_dependent_option(dev, priority);
		if (!option)
			return AE_ERROR;
		parse_data->option = option;
		break;
654

B
Bjorn Helgaas 已提交
655 656 657 658 659 660 661 662 663
	case ACPI_RESOURCE_TYPE_END_DEPENDENT:
		/*only one EndDependentFn is allowed */
		if (!parse_data->option_independent) {
			pnp_warn("PnPACPI: more than one EndDependentFn");
			return AE_ERROR;
		}
		parse_data->option = parse_data->option_independent;
		parse_data->option_independent = NULL;
		break;
664

B
Bjorn Helgaas 已提交
665 666 667
	case ACPI_RESOURCE_TYPE_IO:
		pnpacpi_parse_port_option(option, &res->data.io);
		break;
668

B
Bjorn Helgaas 已提交
669 670 671
	case ACPI_RESOURCE_TYPE_FIXED_IO:
		pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io);
		break;
672

B
Bjorn Helgaas 已提交
673 674 675
	case ACPI_RESOURCE_TYPE_VENDOR:
	case ACPI_RESOURCE_TYPE_END_TAG:
		break;
676

B
Bjorn Helgaas 已提交
677 678 679
	case ACPI_RESOURCE_TYPE_MEMORY24:
		pnpacpi_parse_mem24_option(option, &res->data.memory24);
		break;
680

B
Bjorn Helgaas 已提交
681 682 683
	case ACPI_RESOURCE_TYPE_MEMORY32:
		pnpacpi_parse_mem32_option(option, &res->data.memory32);
		break;
684

B
Bjorn Helgaas 已提交
685 686 687 688
	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
		pnpacpi_parse_fixed_mem32_option(option,
						 &res->data.fixed_memory32);
		break;
689

B
Bjorn Helgaas 已提交
690 691 692 693 694
	case ACPI_RESOURCE_TYPE_ADDRESS16:
	case ACPI_RESOURCE_TYPE_ADDRESS32:
	case ACPI_RESOURCE_TYPE_ADDRESS64:
		pnpacpi_parse_address_option(option, res);
		break;
695

B
Bjorn Helgaas 已提交
696 697 698 699 700 701 702 703 704 705 706 707 708
	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
		break;

	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
		pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq);
		break;

	case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
		break;

	default:
		pnp_warn("PnPACPI: unknown resource type %d", res->type);
		return AE_ERROR;
L
Linus Torvalds 已提交
709
	}
B
Bjorn Helgaas 已提交
710

L
Linus Torvalds 已提交
711 712 713
	return AE_OK;
}

714 715
acpi_status __init pnpacpi_parse_resource_option_data(acpi_handle handle,
						      struct pnp_dev *dev)
L
Linus Torvalds 已提交
716 717 718 719 720 721 722
{
	acpi_status status;
	struct acpipnp_parse_option_s parse_data;

	parse_data.option = pnp_register_independent_option(dev);
	if (!parse_data.option)
		return AE_ERROR;
M
Matthieu Castet 已提交
723
	parse_data.option_independent = parse_data.option;
L
Linus Torvalds 已提交
724
	parse_data.dev = dev;
B
Bob Moore 已提交
725
	status = acpi_walk_resources(handle, METHOD_NAME__PRS,
B
Bjorn Helgaas 已提交
726
				     pnpacpi_option_resource, &parse_data);
L
Linus Torvalds 已提交
727 728 729 730

	return status;
}

731
static int pnpacpi_supported_resource(struct acpi_resource *res)
L
Linus Torvalds 已提交
732
{
733
	switch (res->type) {
B
Bob Moore 已提交
734 735 736 737 738 739 740 741 742 743
	case ACPI_RESOURCE_TYPE_IRQ:
	case ACPI_RESOURCE_TYPE_DMA:
	case ACPI_RESOURCE_TYPE_IO:
	case ACPI_RESOURCE_TYPE_FIXED_IO:
	case ACPI_RESOURCE_TYPE_MEMORY24:
	case ACPI_RESOURCE_TYPE_MEMORY32:
	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
	case ACPI_RESOURCE_TYPE_ADDRESS16:
	case ACPI_RESOURCE_TYPE_ADDRESS32:
	case ACPI_RESOURCE_TYPE_ADDRESS64:
744
	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
745
		return 1;
L
Linus Torvalds 已提交
746
	}
747 748 749 750 751 752 753
	return 0;
}

/*
 * Set resource
 */
static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
B
Bjorn Helgaas 已提交
754
					   void *data)
755
{
756
	int *res_cnt = data;
757 758 759

	if (pnpacpi_supported_resource(res))
		(*res_cnt)++;
L
Linus Torvalds 已提交
760 761 762
	return AE_OK;
}

B
Bjorn Helgaas 已提交
763
static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
L
Linus Torvalds 已提交
764
{
765
	struct acpi_resource **resource = data;
766 767

	if (pnpacpi_supported_resource(res)) {
768
		(*resource)->type = res->type;
769
		(*resource)->length = sizeof(struct acpi_resource);
L
Linus Torvalds 已提交
770 771 772 773 774 775
		(*resource)++;
	}

	return AE_OK;
}

B
Bob Moore 已提交
776
int pnpacpi_build_resource_template(acpi_handle handle,
B
Bjorn Helgaas 已提交
777
				    struct acpi_buffer *buffer)
L
Linus Torvalds 已提交
778 779 780 781 782
{
	struct acpi_resource *resource;
	int res_cnt = 0;
	acpi_status status;

B
Bob Moore 已提交
783
	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
B
Bjorn Helgaas 已提交
784
				     pnpacpi_count_resources, &res_cnt);
L
Linus Torvalds 已提交
785 786 787 788 789 790 791
	if (ACPI_FAILURE(status)) {
		pnp_err("Evaluate _CRS failed");
		return -EINVAL;
	}
	if (!res_cnt)
		return -EINVAL;
	buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
792
	buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
L
Linus Torvalds 已提交
793 794 795 796
	if (!buffer->pointer)
		return -ENOMEM;
	pnp_dbg("Res cnt %d", res_cnt);
	resource = (struct acpi_resource *)buffer->pointer;
B
Bob Moore 已提交
797
	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
B
Bjorn Helgaas 已提交
798
				     pnpacpi_type_resources, &resource);
L
Linus Torvalds 已提交
799 800 801 802 803 804
	if (ACPI_FAILURE(status)) {
		kfree(buffer->pointer);
		pnp_err("Evaluate _CRS failed");
		return -EINVAL;
	}
	/* resource will pointer the end resource now */
B
Bob Moore 已提交
805
	resource->type = ACPI_RESOURCE_TYPE_END_TAG;
L
Linus Torvalds 已提交
806 807 808 809

	return 0;
}

B
Bob Moore 已提交
810
static void pnpacpi_encode_irq(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
811
			       struct resource *p)
L
Linus Torvalds 已提交
812
{
813
	struct acpi_resource_irq *irq = &resource->data.irq;
B
Bob Moore 已提交
814
	int triggering, polarity;
B
Bjorn Helgaas 已提交
815 816

	decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
817 818
	irq->triggering = triggering;
	irq->polarity = polarity;
B
Bob Moore 已提交
819
	if (triggering == ACPI_EDGE_SENSITIVE)
820
		irq->sharable = ACPI_EXCLUSIVE;
L
Linus Torvalds 已提交
821
	else
822 823 824
		irq->sharable = ACPI_SHARED;
	irq->interrupt_count = 1;
	irq->interrupts[0] = p->start;
L
Linus Torvalds 已提交
825 826 827
}

static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
828
				   struct resource *p)
L
Linus Torvalds 已提交
829
{
830
	struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq;
B
Bob Moore 已提交
831
	int triggering, polarity;
B
Bjorn Helgaas 已提交
832 833

	decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
834 835 836
	extended_irq->producer_consumer = ACPI_CONSUMER;
	extended_irq->triggering = triggering;
	extended_irq->polarity = polarity;
B
Bob Moore 已提交
837
	if (triggering == ACPI_EDGE_SENSITIVE)
838
		extended_irq->sharable = ACPI_EXCLUSIVE;
L
Linus Torvalds 已提交
839
	else
840 841 842
		extended_irq->sharable = ACPI_SHARED;
	extended_irq->interrupt_count = 1;
	extended_irq->interrupts[0] = p->start;
L
Linus Torvalds 已提交
843 844 845
}

static void pnpacpi_encode_dma(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
846
			       struct resource *p)
L
Linus Torvalds 已提交
847
{
848 849
	struct acpi_resource_dma *dma = &resource->data.dma;

L
Linus Torvalds 已提交
850
	/* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
851
	switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
B
Bjorn Helgaas 已提交
852
	case IORESOURCE_DMA_TYPEA:
853
		dma->type = ACPI_TYPE_A;
B
Bjorn Helgaas 已提交
854 855
		break;
	case IORESOURCE_DMA_TYPEB:
856
		dma->type = ACPI_TYPE_B;
B
Bjorn Helgaas 已提交
857 858
		break;
	case IORESOURCE_DMA_TYPEF:
859
		dma->type = ACPI_TYPE_F;
B
Bjorn Helgaas 已提交
860 861
		break;
	default:
862
		dma->type = ACPI_COMPATIBILITY;
863 864 865
	}

	switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
B
Bjorn Helgaas 已提交
866
	case IORESOURCE_DMA_8BIT:
867
		dma->transfer = ACPI_TRANSFER_8;
B
Bjorn Helgaas 已提交
868 869
		break;
	case IORESOURCE_DMA_8AND16BIT:
870
		dma->transfer = ACPI_TRANSFER_8_16;
B
Bjorn Helgaas 已提交
871 872
		break;
	default:
873
		dma->transfer = ACPI_TRANSFER_16;
874 875
	}

876 877 878
	dma->bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
	dma->channel_count = 1;
	dma->channels[0] = p->start;
L
Linus Torvalds 已提交
879 880 881
}

static void pnpacpi_encode_io(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
882
			      struct resource *p)
L
Linus Torvalds 已提交
883
{
884 885
	struct acpi_resource_io *io = &resource->data.io;

L
Linus Torvalds 已提交
886
	/* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
887
	io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
B
Bjorn Helgaas 已提交
888
	    ACPI_DECODE_16 : ACPI_DECODE_10;
889 890 891 892
	io->minimum = p->start;
	io->maximum = p->end;
	io->alignment = 0;	/* Correct? */
	io->address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
893 894 895
}

static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
896
				    struct resource *p)
L
Linus Torvalds 已提交
897
{
898 899 900 901
	struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io;

	fixed_io->address = p->start;
	fixed_io->address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
902 903 904
}

static void pnpacpi_encode_mem24(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
905
				 struct resource *p)
L
Linus Torvalds 已提交
906
{
907 908
	struct acpi_resource_memory24 *memory24 = &resource->data.memory24;

L
Linus Torvalds 已提交
909
	/* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
910
	memory24->write_protect =
B
Bjorn Helgaas 已提交
911 912
	    (p->flags & IORESOURCE_MEM_WRITEABLE) ?
	    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
913 914 915 916
	memory24->minimum = p->start;
	memory24->maximum = p->end;
	memory24->alignment = 0;
	memory24->address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
917 918 919
}

static void pnpacpi_encode_mem32(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
920
				 struct resource *p)
L
Linus Torvalds 已提交
921
{
922 923 924
	struct acpi_resource_memory32 *memory32 = &resource->data.memory32;

	memory32->write_protect =
B
Bjorn Helgaas 已提交
925 926
	    (p->flags & IORESOURCE_MEM_WRITEABLE) ?
	    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
927 928 929 930
	memory32->minimum = p->start;
	memory32->maximum = p->end;
	memory32->alignment = 0;
	memory32->address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
931 932 933
}

static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
934
				       struct resource *p)
L
Linus Torvalds 已提交
935
{
936 937 938
	struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32;

	fixed_memory32->write_protect =
B
Bjorn Helgaas 已提交
939 940
	    (p->flags & IORESOURCE_MEM_WRITEABLE) ?
	    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
941 942
	fixed_memory32->address = p->start;
	fixed_memory32->address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
943 944
}

B
Bob Moore 已提交
945
int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
B
Bjorn Helgaas 已提交
946
			     struct acpi_buffer *buffer)
L
Linus Torvalds 已提交
947 948 949
{
	int i = 0;
	/* pnpacpi_build_resource_template allocates extra mem */
B
Bjorn Helgaas 已提交
950
	int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
951
	struct acpi_resource *resource = buffer->pointer;
L
Linus Torvalds 已提交
952 953 954 955
	int port = 0, irq = 0, dma = 0, mem = 0;

	pnp_dbg("res cnt %d", res_cnt);
	while (i < res_cnt) {
B
Bjorn Helgaas 已提交
956
		switch (resource->type) {
B
Bob Moore 已提交
957
		case ACPI_RESOURCE_TYPE_IRQ:
L
Linus Torvalds 已提交
958
			pnp_dbg("Encode irq");
B
Bob Moore 已提交
959
			pnpacpi_encode_irq(resource,
B
Bjorn Helgaas 已提交
960
					   &res_table->irq_resource[irq]);
L
Linus Torvalds 已提交
961 962 963
			irq++;
			break;

B
Bob Moore 已提交
964
		case ACPI_RESOURCE_TYPE_DMA:
L
Linus Torvalds 已提交
965
			pnp_dbg("Encode dma");
B
Bob Moore 已提交
966
			pnpacpi_encode_dma(resource,
B
Bjorn Helgaas 已提交
967
					   &res_table->dma_resource[dma]);
B
Bjorn Helgaas 已提交
968
			dma++;
L
Linus Torvalds 已提交
969
			break;
B
Bob Moore 已提交
970
		case ACPI_RESOURCE_TYPE_IO:
L
Linus Torvalds 已提交
971
			pnp_dbg("Encode io");
B
Bob Moore 已提交
972
			pnpacpi_encode_io(resource,
B
Bjorn Helgaas 已提交
973
					  &res_table->port_resource[port]);
B
Bjorn Helgaas 已提交
974
			port++;
L
Linus Torvalds 已提交
975
			break;
B
Bob Moore 已提交
976
		case ACPI_RESOURCE_TYPE_FIXED_IO:
L
Linus Torvalds 已提交
977 978
			pnp_dbg("Encode fixed io");
			pnpacpi_encode_fixed_io(resource,
B
Bjorn Helgaas 已提交
979 980
						&res_table->
						port_resource[port]);
B
Bjorn Helgaas 已提交
981
			port++;
L
Linus Torvalds 已提交
982
			break;
B
Bob Moore 已提交
983
		case ACPI_RESOURCE_TYPE_MEMORY24:
L
Linus Torvalds 已提交
984 985
			pnp_dbg("Encode mem24");
			pnpacpi_encode_mem24(resource,
B
Bjorn Helgaas 已提交
986
					     &res_table->mem_resource[mem]);
B
Bjorn Helgaas 已提交
987
			mem++;
L
Linus Torvalds 已提交
988
			break;
B
Bob Moore 已提交
989
		case ACPI_RESOURCE_TYPE_MEMORY32:
L
Linus Torvalds 已提交
990 991
			pnp_dbg("Encode mem32");
			pnpacpi_encode_mem32(resource,
B
Bjorn Helgaas 已提交
992
					     &res_table->mem_resource[mem]);
B
Bjorn Helgaas 已提交
993
			mem++;
L
Linus Torvalds 已提交
994
			break;
B
Bob Moore 已提交
995
		case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
L
Linus Torvalds 已提交
996 997
			pnp_dbg("Encode fixed mem32");
			pnpacpi_encode_fixed_mem32(resource,
B
Bjorn Helgaas 已提交
998 999
						   &res_table->
						   mem_resource[mem]);
B
Bjorn Helgaas 已提交
1000
			mem++;
L
Linus Torvalds 已提交
1001
			break;
1002 1003 1004
		case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
			pnp_dbg("Encode ext irq");
			pnpacpi_encode_ext_irq(resource,
B
Bjorn Helgaas 已提交
1005
					       &res_table->irq_resource[irq]);
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
			irq++;
			break;
		case ACPI_RESOURCE_TYPE_START_DEPENDENT:
		case ACPI_RESOURCE_TYPE_END_DEPENDENT:
		case ACPI_RESOURCE_TYPE_VENDOR:
		case ACPI_RESOURCE_TYPE_END_TAG:
		case ACPI_RESOURCE_TYPE_ADDRESS16:
		case ACPI_RESOURCE_TYPE_ADDRESS32:
		case ACPI_RESOURCE_TYPE_ADDRESS64:
		case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
		case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
B
Bjorn Helgaas 已提交
1017
		default:	/* other type */
1018
			pnp_warn("unknown resource type %d", resource->type);
L
Linus Torvalds 已提交
1019 1020
			return -EINVAL;
		}
B
Bjorn Helgaas 已提交
1021 1022
		resource++;
		i++;
L
Linus Torvalds 已提交
1023 1024 1025
	}
	return 0;
}