rsparser.c 26.4 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 172 173
static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
						u32 dma, int type,
						int bus_master, int transfer)
L
Linus Torvalds 已提交
174 175
{
	int i = 0;
176
	static unsigned char warned;
B
Bjorn Helgaas 已提交
177

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

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

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

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

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

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

B
Bjorn Helgaas 已提交
252 253
static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
						  struct acpi_resource *res)
254 255 256 257 258 259 260
{
	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 已提交
261
			 res->type);
262 263 264
		return;
	}

265 266 267
	if (p->producer_consumer == ACPI_PRODUCER)
		return;

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

static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
B
Bjorn Helgaas 已提交
280
					      void *data)
L
Linus Torvalds 已提交
281
{
282
	struct pnp_resource_table *res_table = data;
283 284 285 286 287 288 289 290
	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;
291
	int i;
L
Linus Torvalds 已提交
292

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

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

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

	case ACPI_RESOURCE_TYPE_START_DEPENDENT:
	case ACPI_RESOURCE_TYPE_END_DEPENDENT:
		break;

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

	case ACPI_RESOURCE_TYPE_VENDOR:
		break;

	case ACPI_RESOURCE_TYPE_END_TAG:
		break;

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

	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
373 374
		if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
			return AE_OK;
375 376 377
		break;

	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
378 379
		extended_irq = &res->data.extended_irq;
		if (extended_irq->producer_consumer == ACPI_PRODUCER)
380 381
			return AE_OK;

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

	case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
L
Linus Torvalds 已提交
392
		break;
393

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

L
Linus Torvalds 已提交
399 400 401
	return AE_OK;
}

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

B
Bjorn Helgaas 已提交
408 409
	return acpi_walk_resources(handle, METHOD_NAME__CRS,
				   pnpacpi_allocated_resource, res);
L
Linus Torvalds 已提交
410 411
}

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

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

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

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

B
Bjorn Helgaas 已提交
429
	pnp_register_dma_resource(option, dma);
L
Linus Torvalds 已提交
430 431
}

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

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

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

	pnp_register_irq_resource(option, irq);
}

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

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

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

	pnp_register_irq_resource(option, irq);
}

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

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

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

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

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

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

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

B
Bjorn Helgaas 已提交
526
	pnp_register_mem_resource(option, mem);
L
Linus Torvalds 已提交
527 528
}

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

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

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

B
Bjorn Helgaas 已提交
547
	pnp_register_mem_resource(option, mem);
L
Linus Torvalds 已提交
548 549
}

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

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

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

B
Bjorn Helgaas 已提交
567
	pnp_register_mem_resource(option, mem);
L
Linus Torvalds 已提交
568 569
}

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

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

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

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

L
Linus Torvalds 已提交
611 612
struct acpipnp_parse_option_s {
	struct pnp_option *option;
M
Matthieu Castet 已提交
613
	struct pnp_option *option_independent;
L
Linus Torvalds 已提交
614 615 616
	struct pnp_dev *dev;
};

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

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

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

B
Bjorn Helgaas 已提交
634 635 636 637
	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 已提交
638
			break;
639

B
Bjorn Helgaas 已提交
640 641
		case ACPI_ACCEPTABLE_CONFIGURATION:
			priority = PNP_RES_PRIORITY_ACCEPTABLE;
M
Matthieu Castet 已提交
642
			break;
643

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

B
Bjorn Helgaas 已提交
658 659 660 661 662 663 664 665 666
	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;
667

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

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

B
Bjorn Helgaas 已提交
676 677 678
	case ACPI_RESOURCE_TYPE_VENDOR:
	case ACPI_RESOURCE_TYPE_END_TAG:
		break;
679

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

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

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

B
Bjorn Helgaas 已提交
693 694 695 696 697
	case ACPI_RESOURCE_TYPE_ADDRESS16:
	case ACPI_RESOURCE_TYPE_ADDRESS32:
	case ACPI_RESOURCE_TYPE_ADDRESS64:
		pnpacpi_parse_address_option(option, res);
		break;
698

B
Bjorn Helgaas 已提交
699 700 701 702 703 704 705 706 707 708 709 710 711
	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 已提交
712
	}
B
Bjorn Helgaas 已提交
713

L
Linus Torvalds 已提交
714 715 716
	return AE_OK;
}

717 718
acpi_status __init pnpacpi_parse_resource_option_data(acpi_handle handle,
						      struct pnp_dev *dev)
L
Linus Torvalds 已提交
719 720 721 722 723 724 725
{
	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 已提交
726
	parse_data.option_independent = parse_data.option;
L
Linus Torvalds 已提交
727
	parse_data.dev = dev;
B
Bob Moore 已提交
728
	status = acpi_walk_resources(handle, METHOD_NAME__PRS,
B
Bjorn Helgaas 已提交
729
				     pnpacpi_option_resource, &parse_data);
L
Linus Torvalds 已提交
730 731 732 733

	return status;
}

734
static int pnpacpi_supported_resource(struct acpi_resource *res)
L
Linus Torvalds 已提交
735
{
736
	switch (res->type) {
B
Bob Moore 已提交
737 738 739 740 741 742 743 744 745 746
	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:
747
	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
748
		return 1;
L
Linus Torvalds 已提交
749
	}
750 751 752 753 754 755 756
	return 0;
}

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

	if (pnpacpi_supported_resource(res))
		(*res_cnt)++;
L
Linus Torvalds 已提交
763 764 765
	return AE_OK;
}

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

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

	return AE_OK;
}

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

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

	return 0;
}

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

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

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

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

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

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

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

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

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

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

static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
899
				    struct resource *p)
L
Linus Torvalds 已提交
900
{
901 902 903 904
	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 已提交
905 906 907
}

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

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

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

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

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

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

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

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

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