rsparser.c 25.8 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 80 81 82

	if (!valid_IRQ(gsi))
		return;

L
Linus Torvalds 已提交
83
	while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
B
Bjorn Helgaas 已提交
84
	       i < PNP_MAX_IRQ)
L
Linus Torvalds 已提交
85
		i++;
86 87 88
	if (i >= PNP_MAX_IRQ) {
		printk(KERN_ERR "pnpacpi: exceeded the max number of IRQ "
				"resources: %d \n", PNP_MAX_IRQ);
89
		return;
90
	}
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
	/*
	 * 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 已提交
108
	res->irq_resource[i].flags = IORESOURCE_IRQ;	// Also clears _UNSET flag
109
	res->irq_resource[i].flags |= irq_flags(triggering, polarity);
B
Bob Moore 已提交
110
	irq = acpi_register_gsi(gsi, triggering, polarity);
111 112 113
	if (irq < 0) {
		res->irq_resource[i].flags |= IORESOURCE_DISABLED;
		return;
L
Linus Torvalds 已提交
114
	}
115

116 117 118
	if (shareable)
		res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;

119 120 121
	res->irq_resource[i].start = irq;
	res->irq_resource[i].end = irq;
	pcibios_penalize_isa_irq(irq, 1);
L
Linus Torvalds 已提交
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
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 已提交
167 168 169
static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
						u32 dma, int type,
						int bus_master, int transfer)
L
Linus Torvalds 已提交
170 171
{
	int i = 0;
B
Bjorn Helgaas 已提交
172

173
	while (i < PNP_MAX_DMA &&
B
Bjorn Helgaas 已提交
174
	       !(res->dma_resource[i].flags & IORESOURCE_UNSET))
L
Linus Torvalds 已提交
175 176
		i++;
	if (i < PNP_MAX_DMA) {
B
Bjorn Helgaas 已提交
177 178 179
		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 已提交
180 181 182 183
		if (dma == -1) {
			res->dma_resource[i].flags |= IORESOURCE_DISABLED;
			return;
		}
184 185
		res->dma_resource[i].start = dma;
		res->dma_resource[i].end = dma;
186 187 188
	} else {
		printk(KERN_ERR "pnpacpi: exceeded the max number of DMA "
				"resources: %d \n", PNP_MAX_DMA);
L
Linus Torvalds 已提交
189 190 191
	}
}

B
Bjorn Helgaas 已提交
192 193
static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
					       u64 io, u64 len, int io_decode)
L
Linus Torvalds 已提交
194 195
{
	int i = 0;
B
Bjorn Helgaas 已提交
196

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

B
Bjorn Helgaas 已提交
216 217 218
static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
						u64 mem, u64 len,
						int write_protect)
L
Linus Torvalds 已提交
219 220
{
	int i = 0;
B
Bjorn Helgaas 已提交
221

L
Linus Torvalds 已提交
222
	while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
B
Bjorn Helgaas 已提交
223
	       (i < PNP_MAX_MEM))
L
Linus Torvalds 已提交
224 225
		i++;
	if (i < PNP_MAX_MEM) {
B
Bjorn Helgaas 已提交
226
		res->mem_resource[i].flags = IORESOURCE_MEM;	// Also clears _UNSET flag
L
Linus Torvalds 已提交
227 228 229 230
		if (len <= 0) {
			res->mem_resource[i].flags |= IORESOURCE_DISABLED;
			return;
		}
B
Bjorn Helgaas 已提交
231
		if (write_protect == ACPI_READ_WRITE_MEMORY)
232 233
			res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;

234 235
		res->mem_resource[i].start = mem;
		res->mem_resource[i].end = mem + len - 1;
236 237 238
	} else {
		printk(KERN_ERR "pnpacpi: exceeded the max number of mem "
				"resources: %d\n", PNP_MAX_MEM);
L
Linus Torvalds 已提交
239 240 241
	}
}

B
Bjorn Helgaas 已提交
242 243
static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
						  struct acpi_resource *res)
244 245 246 247 248 249 250
{
	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 已提交
251
			 res->type);
252 253 254
		return;
	}

255 256 257
	if (p->producer_consumer == ACPI_PRODUCER)
		return;

258 259
	if (p->resource_type == ACPI_MEMORY_RANGE)
		pnpacpi_parse_allocated_memresource(res_table,
B
Bjorn Helgaas 已提交
260 261
			p->minimum, p->address_length,
			p->info.mem.write_protect);
262 263
	else if (p->resource_type == ACPI_IO_RANGE)
		pnpacpi_parse_allocated_ioresource(res_table,
B
Bjorn Helgaas 已提交
264 265 266
			p->minimum, p->address_length,
			p->granularity == 0xfff ? ACPI_DECODE_10 :
				ACPI_DECODE_16);
267
}
L
Linus Torvalds 已提交
268 269

static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
B
Bjorn Helgaas 已提交
270
					      void *data)
L
Linus Torvalds 已提交
271
{
272
	struct pnp_resource_table *res_table = data;
273
	int i;
L
Linus Torvalds 已提交
274

275
	switch (res->type) {
B
Bob Moore 已提交
276
	case ACPI_RESOURCE_TYPE_IRQ:
277 278 279 280
		/*
		 * Per spec, only one interrupt per descriptor is allowed in
		 * _CRS, but some firmware violates this, so parse them all.
		 */
B
Bob Moore 已提交
281
		for (i = 0; i < res->data.irq.interrupt_count; i++) {
282
			pnpacpi_parse_allocated_irqresource(res_table,
B
Bjorn Helgaas 已提交
283 284 285 286
				res->data.irq.interrupts[i],
				res->data.irq.triggering,
				res->data.irq.polarity,
				res->data.irq.sharable);
L
Linus Torvalds 已提交
287 288 289
		}
		break;

B
Bob Moore 已提交
290 291 292
	case ACPI_RESOURCE_TYPE_DMA:
		if (res->data.dma.channel_count > 0)
			pnpacpi_parse_allocated_dmaresource(res_table,
B
Bjorn Helgaas 已提交
293 294 295 296
				res->data.dma.channels[0],
				res->data.dma.type,
				res->data.dma.bus_master,
				res->data.dma.transfer);
L
Linus Torvalds 已提交
297
		break;
298

B
Bob Moore 已提交
299 300
	case ACPI_RESOURCE_TYPE_IO:
		pnpacpi_parse_allocated_ioresource(res_table,
B
Bjorn Helgaas 已提交
301 302 303
			res->data.io.minimum,
			res->data.io.address_length,
			res->data.io.io_decode);
L
Linus Torvalds 已提交
304
		break;
305 306 307 308 309

	case ACPI_RESOURCE_TYPE_START_DEPENDENT:
	case ACPI_RESOURCE_TYPE_END_DEPENDENT:
		break;

B
Bob Moore 已提交
310 311
	case ACPI_RESOURCE_TYPE_FIXED_IO:
		pnpacpi_parse_allocated_ioresource(res_table,
B
Bjorn Helgaas 已提交
312 313 314
			res->data.fixed_io.address,
			res->data.fixed_io.address_length,
			ACPI_DECODE_10);
L
Linus Torvalds 已提交
315
		break;
316 317 318 319 320 321 322

	case ACPI_RESOURCE_TYPE_VENDOR:
		break;

	case ACPI_RESOURCE_TYPE_END_TAG:
		break;

B
Bob Moore 已提交
323 324
	case ACPI_RESOURCE_TYPE_MEMORY24:
		pnpacpi_parse_allocated_memresource(res_table,
B
Bjorn Helgaas 已提交
325 326 327
			res->data.memory24.minimum,
			res->data.memory24.address_length,
			res->data.memory24.write_protect);
L
Linus Torvalds 已提交
328
		break;
B
Bob Moore 已提交
329 330
	case ACPI_RESOURCE_TYPE_MEMORY32:
		pnpacpi_parse_allocated_memresource(res_table,
B
Bjorn Helgaas 已提交
331 332 333
			res->data.memory32.minimum,
			res->data.memory32.address_length,
			res->data.memory32.write_protect);
L
Linus Torvalds 已提交
334
		break;
B
Bob Moore 已提交
335 336
	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
		pnpacpi_parse_allocated_memresource(res_table,
B
Bjorn Helgaas 已提交
337 338 339
			res->data.fixed_memory32.address,
			res->data.fixed_memory32.address_length,
			res->data.fixed_memory32.write_protect);
L
Linus Torvalds 已提交
340
		break;
B
Bob Moore 已提交
341 342 343
	case ACPI_RESOURCE_TYPE_ADDRESS16:
	case ACPI_RESOURCE_TYPE_ADDRESS32:
	case ACPI_RESOURCE_TYPE_ADDRESS64:
344
		pnpacpi_parse_allocated_address_space(res_table, res);
L
Linus Torvalds 已提交
345
		break;
346 347

	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
348 349
		if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
			return AE_OK;
350 351 352
		break;

	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
353 354 355
		if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
			return AE_OK;

356 357
		for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
			pnpacpi_parse_allocated_irqresource(res_table,
B
Bjorn Helgaas 已提交
358 359 360 361
				res->data.extended_irq.interrupts[i],
				res->data.extended_irq.triggering,
				res->data.extended_irq.polarity,
				res->data.extended_irq.sharable);
362 363 364 365
		}
		break;

	case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
L
Linus Torvalds 已提交
366
		break;
367

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

L
Linus Torvalds 已提交
373 374 375
	return AE_OK;
}

B
Bjorn Helgaas 已提交
376 377
acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
					     struct pnp_resource_table * res)
L
Linus Torvalds 已提交
378 379 380 381
{
	/* Blank the resource table values */
	pnp_init_resource_table(res);

B
Bjorn Helgaas 已提交
382 383
	return acpi_walk_resources(handle, METHOD_NAME__CRS,
				   pnpacpi_allocated_resource, res);
L
Linus Torvalds 已提交
384 385
}

B
Bjorn Helgaas 已提交
386 387
static void pnpacpi_parse_dma_option(struct pnp_option *option,
				     struct acpi_resource_dma *p)
L
Linus Torvalds 已提交
388 389
{
	int i;
B
Bjorn Helgaas 已提交
390
	struct pnp_dma *dma;
L
Linus Torvalds 已提交
391

B
Bob Moore 已提交
392
	if (p->channel_count == 0)
L
Linus Torvalds 已提交
393
		return;
394
	dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
L
Linus Torvalds 已提交
395 396 397
	if (!dma)
		return;

B
Bjorn Helgaas 已提交
398
	for (i = 0; i < p->channel_count; i++)
L
Linus Torvalds 已提交
399
		dma->map |= 1 << p->channels[i];
400 401

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

B
Bjorn Helgaas 已提交
403
	pnp_register_dma_resource(option, dma);
L
Linus Torvalds 已提交
404 405 406
}

static void pnpacpi_parse_irq_option(struct pnp_option *option,
B
Bjorn Helgaas 已提交
407
				     struct acpi_resource_irq *p)
L
Linus Torvalds 已提交
408 409
{
	int i;
B
Bjorn Helgaas 已提交
410 411
	struct pnp_irq *irq;

B
Bob Moore 已提交
412
	if (p->interrupt_count == 0)
L
Linus Torvalds 已提交
413
		return;
414
	irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
L
Linus Torvalds 已提交
415 416 417
	if (!irq)
		return;

B
Bjorn Helgaas 已提交
418
	for (i = 0; i < p->interrupt_count; i++)
L
Linus Torvalds 已提交
419 420
		if (p->interrupts[i])
			__set_bit(p->interrupts[i], irq->map);
B
Bob Moore 已提交
421
	irq->flags = irq_flags(p->triggering, p->polarity);
L
Linus Torvalds 已提交
422 423 424 425 426

	pnp_register_irq_resource(option, irq);
}

static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
B
Bjorn Helgaas 已提交
427
					 struct acpi_resource_extended_irq *p)
L
Linus Torvalds 已提交
428 429
{
	int i;
B
Bjorn Helgaas 已提交
430
	struct pnp_irq *irq;
L
Linus Torvalds 已提交
431

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

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

	pnp_register_irq_resource(option, irq);
}

B
Bjorn Helgaas 已提交
446 447
static void pnpacpi_parse_port_option(struct pnp_option *option,
				      struct acpi_resource_io *io)
L
Linus Torvalds 已提交
448
{
B
Bjorn Helgaas 已提交
449
	struct pnp_port *port;
L
Linus Torvalds 已提交
450

B
Bob Moore 已提交
451
	if (io->address_length == 0)
L
Linus Torvalds 已提交
452
		return;
453
	port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
L
Linus Torvalds 已提交
454 455
	if (!port)
		return;
B
Bob Moore 已提交
456 457
	port->min = io->minimum;
	port->max = io->maximum;
L
Linus Torvalds 已提交
458
	port->align = io->alignment;
B
Bob Moore 已提交
459 460
	port->size = io->address_length;
	port->flags = ACPI_DECODE_16 == io->io_decode ?
B
Bjorn Helgaas 已提交
461
	    PNP_PORT_FLAG_16BITADDR : 0;
B
Bjorn Helgaas 已提交
462
	pnp_register_port_resource(option, port);
L
Linus Torvalds 已提交
463 464
}

B
Bjorn Helgaas 已提交
465 466
static void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
					    struct acpi_resource_fixed_io *io)
L
Linus Torvalds 已提交
467
{
B
Bjorn Helgaas 已提交
468
	struct pnp_port *port;
L
Linus Torvalds 已提交
469

B
Bob Moore 已提交
470
	if (io->address_length == 0)
L
Linus Torvalds 已提交
471
		return;
472
	port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
L
Linus Torvalds 已提交
473 474
	if (!port)
		return;
B
Bob Moore 已提交
475 476
	port->min = port->max = io->address;
	port->size = io->address_length;
L
Linus Torvalds 已提交
477 478
	port->align = 0;
	port->flags = PNP_PORT_FLAG_FIXED;
B
Bjorn Helgaas 已提交
479
	pnp_register_port_resource(option, port);
L
Linus Torvalds 已提交
480 481
}

B
Bjorn Helgaas 已提交
482 483
static void pnpacpi_parse_mem24_option(struct pnp_option *option,
				       struct acpi_resource_memory24 *p)
L
Linus Torvalds 已提交
484
{
B
Bjorn Helgaas 已提交
485
	struct pnp_mem *mem;
L
Linus Torvalds 已提交
486

B
Bob Moore 已提交
487
	if (p->address_length == 0)
L
Linus Torvalds 已提交
488
		return;
489
	mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
L
Linus Torvalds 已提交
490 491
	if (!mem)
		return;
B
Bob Moore 已提交
492 493
	mem->min = p->minimum;
	mem->max = p->maximum;
L
Linus Torvalds 已提交
494
	mem->align = p->alignment;
B
Bob Moore 已提交
495
	mem->size = p->address_length;
L
Linus Torvalds 已提交
496

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

B
Bjorn Helgaas 已提交
500
	pnp_register_mem_resource(option, mem);
L
Linus Torvalds 已提交
501 502
}

B
Bjorn Helgaas 已提交
503 504
static void pnpacpi_parse_mem32_option(struct pnp_option *option,
				       struct acpi_resource_memory32 *p)
L
Linus Torvalds 已提交
505
{
B
Bjorn Helgaas 已提交
506
	struct pnp_mem *mem;
L
Linus Torvalds 已提交
507

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

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

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

B
Bjorn Helgaas 已提交
524 525
static void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
					 struct acpi_resource_fixed_memory32 *p)
L
Linus Torvalds 已提交
526
{
B
Bjorn Helgaas 已提交
527
	struct pnp_mem *mem;
L
Linus Torvalds 已提交
528

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

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

B
Bjorn Helgaas 已提交
541
	pnp_register_mem_resource(option, mem);
L
Linus Torvalds 已提交
542 543
}

B
Bjorn Helgaas 已提交
544 545
static void pnpacpi_parse_address_option(struct pnp_option *option,
					 struct acpi_resource *r)
546 547 548
{
	struct acpi_resource_address64 addr, *p = &addr;
	acpi_status status;
B
Bjorn Helgaas 已提交
549 550
	struct pnp_mem *mem;
	struct pnp_port *port;
551 552 553

	status = acpi_resource_to_address64(r, p);
	if (!ACPI_SUCCESS(status)) {
B
Bjorn Helgaas 已提交
554 555
		pnp_warn("PnPACPI: failed to convert resource type %d",
			 r->type);
556 557 558 559 560 561 562
		return;
	}

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

	if (p->resource_type == ACPI_MEMORY_RANGE) {
563
		mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
564 565
		if (!mem)
			return;
L
Len Brown 已提交
566
		mem->min = mem->max = p->minimum;
567 568
		mem->size = p->address_length;
		mem->align = 0;
L
Len Brown 已提交
569
		mem->flags = (p->info.mem.write_protect ==
B
Bjorn Helgaas 已提交
570 571
			      ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
		    : 0;
B
Bjorn Helgaas 已提交
572
		pnp_register_mem_resource(option, mem);
573
	} else if (p->resource_type == ACPI_IO_RANGE) {
574
		port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
575 576
		if (!port)
			return;
L
Len Brown 已提交
577
		port->min = port->max = p->minimum;
578 579 580
		port->size = p->address_length;
		port->align = 0;
		port->flags = PNP_PORT_FLAG_FIXED;
B
Bjorn Helgaas 已提交
581
		pnp_register_port_resource(option, port);
582 583 584
	}
}

L
Linus Torvalds 已提交
585 586
struct acpipnp_parse_option_s {
	struct pnp_option *option;
M
Matthieu Castet 已提交
587
	struct pnp_option *option_independent;
L
Linus Torvalds 已提交
588 589 590
	struct pnp_dev *dev;
};

B
Bob Moore 已提交
591
static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
B
Bjorn Helgaas 已提交
592
					   void *data)
L
Linus Torvalds 已提交
593 594
{
	int priority = 0;
595
	struct acpipnp_parse_option_s *parse_data = data;
L
Linus Torvalds 已提交
596 597 598
	struct pnp_dev *dev = parse_data->dev;
	struct pnp_option *option = parse_data->option;

599
	switch (res->type) {
B
Bjorn Helgaas 已提交
600 601 602
	case ACPI_RESOURCE_TYPE_IRQ:
		pnpacpi_parse_irq_option(option, &res->data.irq);
		break;
603

B
Bjorn Helgaas 已提交
604 605 606
	case ACPI_RESOURCE_TYPE_DMA:
		pnpacpi_parse_dma_option(option, &res->data.dma);
		break;
607

B
Bjorn Helgaas 已提交
608 609 610 611
	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 已提交
612
			break;
613

B
Bjorn Helgaas 已提交
614 615
		case ACPI_ACCEPTABLE_CONFIGURATION:
			priority = PNP_RES_PRIORITY_ACCEPTABLE;
M
Matthieu Castet 已提交
616
			break;
617

B
Bjorn Helgaas 已提交
618 619
		case ACPI_SUB_OPTIMAL_CONFIGURATION:
			priority = PNP_RES_PRIORITY_FUNCTIONAL;
620
			break;
B
Bjorn Helgaas 已提交
621 622
		default:
			priority = PNP_RES_PRIORITY_INVALID;
623
			break;
B
Bjorn Helgaas 已提交
624
		}
B
Bjorn Helgaas 已提交
625
		/* TBD: Consider performance/robustness bits */
B
Bjorn Helgaas 已提交
626 627 628 629 630
		option = pnp_register_dependent_option(dev, priority);
		if (!option)
			return AE_ERROR;
		parse_data->option = option;
		break;
631

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

B
Bjorn Helgaas 已提交
642 643 644
	case ACPI_RESOURCE_TYPE_IO:
		pnpacpi_parse_port_option(option, &res->data.io);
		break;
645

B
Bjorn Helgaas 已提交
646 647 648
	case ACPI_RESOURCE_TYPE_FIXED_IO:
		pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io);
		break;
649

B
Bjorn Helgaas 已提交
650 651 652
	case ACPI_RESOURCE_TYPE_VENDOR:
	case ACPI_RESOURCE_TYPE_END_TAG:
		break;
653

B
Bjorn Helgaas 已提交
654 655 656
	case ACPI_RESOURCE_TYPE_MEMORY24:
		pnpacpi_parse_mem24_option(option, &res->data.memory24);
		break;
657

B
Bjorn Helgaas 已提交
658 659 660
	case ACPI_RESOURCE_TYPE_MEMORY32:
		pnpacpi_parse_mem32_option(option, &res->data.memory32);
		break;
661

B
Bjorn Helgaas 已提交
662 663 664 665
	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
		pnpacpi_parse_fixed_mem32_option(option,
						 &res->data.fixed_memory32);
		break;
666

B
Bjorn Helgaas 已提交
667 668 669 670 671
	case ACPI_RESOURCE_TYPE_ADDRESS16:
	case ACPI_RESOURCE_TYPE_ADDRESS32:
	case ACPI_RESOURCE_TYPE_ADDRESS64:
		pnpacpi_parse_address_option(option, res);
		break;
672

B
Bjorn Helgaas 已提交
673 674 675 676 677 678 679 680 681 682 683 684 685
	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 已提交
686
	}
B
Bjorn Helgaas 已提交
687

L
Linus Torvalds 已提交
688 689 690
	return AE_OK;
}

B
Bob Moore 已提交
691
acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
B
Bjorn Helgaas 已提交
692
					       struct pnp_dev * dev)
L
Linus Torvalds 已提交
693 694 695 696 697 698 699
{
	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 已提交
700
	parse_data.option_independent = parse_data.option;
L
Linus Torvalds 已提交
701
	parse_data.dev = dev;
B
Bob Moore 已提交
702
	status = acpi_walk_resources(handle, METHOD_NAME__PRS,
B
Bjorn Helgaas 已提交
703
				     pnpacpi_option_resource, &parse_data);
L
Linus Torvalds 已提交
704 705 706 707

	return status;
}

708
static int pnpacpi_supported_resource(struct acpi_resource *res)
L
Linus Torvalds 已提交
709
{
710
	switch (res->type) {
B
Bob Moore 已提交
711 712 713 714 715 716 717 718 719 720
	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:
721
	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
722
		return 1;
L
Linus Torvalds 已提交
723
	}
724 725 726 727 728 729 730
	return 0;
}

/*
 * Set resource
 */
static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
B
Bjorn Helgaas 已提交
731
					   void *data)
732
{
733
	int *res_cnt = data;
734 735 736

	if (pnpacpi_supported_resource(res))
		(*res_cnt)++;
L
Linus Torvalds 已提交
737 738 739
	return AE_OK;
}

B
Bjorn Helgaas 已提交
740
static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
L
Linus Torvalds 已提交
741
{
742
	struct acpi_resource **resource = data;
743 744

	if (pnpacpi_supported_resource(res)) {
745
		(*resource)->type = res->type;
746
		(*resource)->length = sizeof(struct acpi_resource);
L
Linus Torvalds 已提交
747 748 749 750 751 752
		(*resource)++;
	}

	return AE_OK;
}

B
Bob Moore 已提交
753
int pnpacpi_build_resource_template(acpi_handle handle,
B
Bjorn Helgaas 已提交
754
				    struct acpi_buffer *buffer)
L
Linus Torvalds 已提交
755 756 757 758 759
{
	struct acpi_resource *resource;
	int res_cnt = 0;
	acpi_status status;

B
Bob Moore 已提交
760
	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
B
Bjorn Helgaas 已提交
761
				     pnpacpi_count_resources, &res_cnt);
L
Linus Torvalds 已提交
762 763 764 765 766 767 768
	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;
769
	buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
L
Linus Torvalds 已提交
770 771 772 773
	if (!buffer->pointer)
		return -ENOMEM;
	pnp_dbg("Res cnt %d", res_cnt);
	resource = (struct acpi_resource *)buffer->pointer;
B
Bob Moore 已提交
774
	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
B
Bjorn Helgaas 已提交
775
				     pnpacpi_type_resources, &resource);
L
Linus Torvalds 已提交
776 777 778 779 780 781
	if (ACPI_FAILURE(status)) {
		kfree(buffer->pointer);
		pnp_err("Evaluate _CRS failed");
		return -EINVAL;
	}
	/* resource will pointer the end resource now */
B
Bob Moore 已提交
782
	resource->type = ACPI_RESOURCE_TYPE_END_TAG;
L
Linus Torvalds 已提交
783 784 785 786

	return 0;
}

B
Bob Moore 已提交
787
static void pnpacpi_encode_irq(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
788
			       struct resource *p)
L
Linus Torvalds 已提交
789
{
B
Bob Moore 已提交
790
	int triggering, polarity;
B
Bjorn Helgaas 已提交
791 792

	decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
B
Bob Moore 已提交
793 794 795 796
	resource->data.irq.triggering = triggering;
	resource->data.irq.polarity = polarity;
	if (triggering == ACPI_EDGE_SENSITIVE)
		resource->data.irq.sharable = ACPI_EXCLUSIVE;
L
Linus Torvalds 已提交
797
	else
B
Bob Moore 已提交
798 799
		resource->data.irq.sharable = ACPI_SHARED;
	resource->data.irq.interrupt_count = 1;
L
Linus Torvalds 已提交
800 801 802 803
	resource->data.irq.interrupts[0] = p->start;
}

static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
804
				   struct resource *p)
L
Linus Torvalds 已提交
805
{
B
Bob Moore 已提交
806
	int triggering, polarity;
B
Bjorn Helgaas 已提交
807 808

	decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
L
Linus Torvalds 已提交
809
	resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
B
Bob Moore 已提交
810 811 812 813
	resource->data.extended_irq.triggering = triggering;
	resource->data.extended_irq.polarity = polarity;
	if (triggering == ACPI_EDGE_SENSITIVE)
		resource->data.irq.sharable = ACPI_EXCLUSIVE;
L
Linus Torvalds 已提交
814
	else
B
Bob Moore 已提交
815 816
		resource->data.irq.sharable = ACPI_SHARED;
	resource->data.extended_irq.interrupt_count = 1;
L
Linus Torvalds 已提交
817 818 819 820
	resource->data.extended_irq.interrupts[0] = p->start;
}

static void pnpacpi_encode_dma(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
821
			       struct resource *p)
L
Linus Torvalds 已提交
822 823
{
	/* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
824
	switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
B
Bjorn Helgaas 已提交
825 826 827 828 829 830 831 832 833 834 835
	case IORESOURCE_DMA_TYPEA:
		resource->data.dma.type = ACPI_TYPE_A;
		break;
	case IORESOURCE_DMA_TYPEB:
		resource->data.dma.type = ACPI_TYPE_B;
		break;
	case IORESOURCE_DMA_TYPEF:
		resource->data.dma.type = ACPI_TYPE_F;
		break;
	default:
		resource->data.dma.type = ACPI_COMPATIBILITY;
836 837 838
	}

	switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
B
Bjorn Helgaas 已提交
839 840 841 842 843 844 845 846
	case IORESOURCE_DMA_8BIT:
		resource->data.dma.transfer = ACPI_TRANSFER_8;
		break;
	case IORESOURCE_DMA_8AND16BIT:
		resource->data.dma.transfer = ACPI_TRANSFER_8_16;
		break;
	default:
		resource->data.dma.transfer = ACPI_TRANSFER_16;
847 848 849
	}

	resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
B
Bob Moore 已提交
850
	resource->data.dma.channel_count = 1;
L
Linus Torvalds 已提交
851 852 853 854
	resource->data.dma.channels[0] = p->start;
}

static void pnpacpi_encode_io(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
855
			      struct resource *p)
L
Linus Torvalds 已提交
856 857
{
	/* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
B
Bjorn Helgaas 已提交
858 859
	resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
	    ACPI_DECODE_16 : ACPI_DECODE_10;
B
Bob Moore 已提交
860 861
	resource->data.io.minimum = p->start;
	resource->data.io.maximum = p->end;
B
Bjorn Helgaas 已提交
862
	resource->data.io.alignment = 0;	/* Correct? */
B
Bob Moore 已提交
863
	resource->data.io.address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
864 865 866
}

static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
867
				    struct resource *p)
L
Linus Torvalds 已提交
868
{
B
Bob Moore 已提交
869 870
	resource->data.fixed_io.address = p->start;
	resource->data.fixed_io.address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
871 872 873
}

static void pnpacpi_encode_mem24(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
874
				 struct resource *p)
L
Linus Torvalds 已提交
875 876
{
	/* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
B
Bob Moore 已提交
877
	resource->data.memory24.write_protect =
B
Bjorn Helgaas 已提交
878 879
	    (p->flags & IORESOURCE_MEM_WRITEABLE) ?
	    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
B
Bob Moore 已提交
880 881
	resource->data.memory24.minimum = p->start;
	resource->data.memory24.maximum = p->end;
L
Linus Torvalds 已提交
882
	resource->data.memory24.alignment = 0;
B
Bob Moore 已提交
883
	resource->data.memory24.address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
884 885 886
}

static void pnpacpi_encode_mem32(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
887
				 struct resource *p)
L
Linus Torvalds 已提交
888
{
B
Bob Moore 已提交
889
	resource->data.memory32.write_protect =
B
Bjorn Helgaas 已提交
890 891
	    (p->flags & IORESOURCE_MEM_WRITEABLE) ?
	    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
B
Bob Moore 已提交
892 893
	resource->data.memory32.minimum = p->start;
	resource->data.memory32.maximum = p->end;
L
Linus Torvalds 已提交
894
	resource->data.memory32.alignment = 0;
B
Bob Moore 已提交
895
	resource->data.memory32.address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
896 897 898
}

static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
B
Bjorn Helgaas 已提交
899
				       struct resource *p)
L
Linus Torvalds 已提交
900
{
B
Bob Moore 已提交
901
	resource->data.fixed_memory32.write_protect =
B
Bjorn Helgaas 已提交
902 903
	    (p->flags & IORESOURCE_MEM_WRITEABLE) ?
	    ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
B
Bob Moore 已提交
904 905
	resource->data.fixed_memory32.address = p->start;
	resource->data.fixed_memory32.address_length = p->end - p->start + 1;
L
Linus Torvalds 已提交
906 907
}

B
Bob Moore 已提交
908
int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
B
Bjorn Helgaas 已提交
909
			     struct acpi_buffer *buffer)
L
Linus Torvalds 已提交
910 911 912
{
	int i = 0;
	/* pnpacpi_build_resource_template allocates extra mem */
B
Bjorn Helgaas 已提交
913
	int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
914
	struct acpi_resource *resource = buffer->pointer;
L
Linus Torvalds 已提交
915 916 917 918
	int port = 0, irq = 0, dma = 0, mem = 0;

	pnp_dbg("res cnt %d", res_cnt);
	while (i < res_cnt) {
B
Bjorn Helgaas 已提交
919
		switch (resource->type) {
B
Bob Moore 已提交
920
		case ACPI_RESOURCE_TYPE_IRQ:
L
Linus Torvalds 已提交
921
			pnp_dbg("Encode irq");
B
Bob Moore 已提交
922
			pnpacpi_encode_irq(resource,
B
Bjorn Helgaas 已提交
923
					   &res_table->irq_resource[irq]);
L
Linus Torvalds 已提交
924 925 926
			irq++;
			break;

B
Bob Moore 已提交
927
		case ACPI_RESOURCE_TYPE_DMA:
L
Linus Torvalds 已提交
928
			pnp_dbg("Encode dma");
B
Bob Moore 已提交
929
			pnpacpi_encode_dma(resource,
B
Bjorn Helgaas 已提交
930
					   &res_table->dma_resource[dma]);
B
Bjorn Helgaas 已提交
931
			dma++;
L
Linus Torvalds 已提交
932
			break;
B
Bob Moore 已提交
933
		case ACPI_RESOURCE_TYPE_IO:
L
Linus Torvalds 已提交
934
			pnp_dbg("Encode io");
B
Bob Moore 已提交
935
			pnpacpi_encode_io(resource,
B
Bjorn Helgaas 已提交
936
					  &res_table->port_resource[port]);
B
Bjorn Helgaas 已提交
937
			port++;
L
Linus Torvalds 已提交
938
			break;
B
Bob Moore 已提交
939
		case ACPI_RESOURCE_TYPE_FIXED_IO:
L
Linus Torvalds 已提交
940 941
			pnp_dbg("Encode fixed io");
			pnpacpi_encode_fixed_io(resource,
B
Bjorn Helgaas 已提交
942 943
						&res_table->
						port_resource[port]);
B
Bjorn Helgaas 已提交
944
			port++;
L
Linus Torvalds 已提交
945
			break;
B
Bob Moore 已提交
946
		case ACPI_RESOURCE_TYPE_MEMORY24:
L
Linus Torvalds 已提交
947 948
			pnp_dbg("Encode mem24");
			pnpacpi_encode_mem24(resource,
B
Bjorn Helgaas 已提交
949
					     &res_table->mem_resource[mem]);
B
Bjorn Helgaas 已提交
950
			mem++;
L
Linus Torvalds 已提交
951
			break;
B
Bob Moore 已提交
952
		case ACPI_RESOURCE_TYPE_MEMORY32:
L
Linus Torvalds 已提交
953 954
			pnp_dbg("Encode mem32");
			pnpacpi_encode_mem32(resource,
B
Bjorn Helgaas 已提交
955
					     &res_table->mem_resource[mem]);
B
Bjorn Helgaas 已提交
956
			mem++;
L
Linus Torvalds 已提交
957
			break;
B
Bob Moore 已提交
958
		case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
L
Linus Torvalds 已提交
959 960
			pnp_dbg("Encode fixed mem32");
			pnpacpi_encode_fixed_mem32(resource,
B
Bjorn Helgaas 已提交
961 962
						   &res_table->
						   mem_resource[mem]);
B
Bjorn Helgaas 已提交
963
			mem++;
L
Linus Torvalds 已提交
964
			break;
965 966 967
		case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
			pnp_dbg("Encode ext irq");
			pnpacpi_encode_ext_irq(resource,
B
Bjorn Helgaas 已提交
968
					       &res_table->irq_resource[irq]);
969 970 971 972 973 974 975 976 977 978 979
			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 已提交
980
		default:	/* other type */
981
			pnp_warn("unknown resource type %d", resource->type);
L
Linus Torvalds 已提交
982 983
			return -EINVAL;
		}
B
Bjorn Helgaas 已提交
984 985
		resource++;
		i++;
L
Linus Torvalds 已提交
986 987 988
	}
	return 0;
}