2 * pnpacpi -- PnP ACPI driver
4 * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
5 * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/acpi.h>
23 #include <linux/pci.h>
27 #define valid_IRQ(i) (1)
29 #define valid_IRQ(i) (((i) != 0) && ((i) != 2))
35 static int irq_flags(int triggering, int polarity)
37 if (triggering == ACPI_LEVEL_SENSITIVE) {
38 if (polarity == ACPI_ACTIVE_LOW)
39 return IORESOURCE_IRQ_LOWLEVEL;
41 return IORESOURCE_IRQ_HIGHLEVEL;
43 if (polarity == ACPI_ACTIVE_LOW)
44 return IORESOURCE_IRQ_LOWEDGE;
46 return IORESOURCE_IRQ_HIGHEDGE;
50 static void decode_irq_flags(int flag, int *triggering, int *polarity)
53 case IORESOURCE_IRQ_LOWLEVEL:
54 *triggering = ACPI_LEVEL_SENSITIVE;
55 *polarity = ACPI_ACTIVE_LOW;
57 case IORESOURCE_IRQ_HIGHLEVEL:
58 *triggering = ACPI_LEVEL_SENSITIVE;
59 *polarity = ACPI_ACTIVE_HIGH;
61 case IORESOURCE_IRQ_LOWEDGE:
62 *triggering = ACPI_EDGE_SENSITIVE;
63 *polarity = ACPI_ACTIVE_LOW;
65 case IORESOURCE_IRQ_HIGHEDGE:
66 *triggering = ACPI_EDGE_SENSITIVE;
67 *polarity = ACPI_ACTIVE_HIGH;
72 static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res,
73 u32 gsi, int triggering,
74 int polarity, int shareable)
79 static unsigned char warned;
84 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
87 if (i >= PNP_MAX_IRQ) {
89 printk(KERN_WARNING "pnpacpi: exceeded the max number"
90 " of IRQ resources: %d\n", PNP_MAX_IRQ);
96 * in IO-APIC mode, use overrided attribute. Two reasons:
98 * 2. BIOS uses IO-APIC mode Interrupt Source Override
100 if (!acpi_get_override_irq(gsi, &t, &p)) {
101 t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
102 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
104 if (triggering != t || polarity != p) {
105 pnp_warn("IRQ %d override to %s, %s",
106 gsi, t ? "edge":"level", p ? "low":"high");
112 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
113 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
114 irq = acpi_register_gsi(gsi, triggering, polarity);
116 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
121 res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
123 res->irq_resource[i].start = irq;
124 res->irq_resource[i].end = irq;
125 pcibios_penalize_isa_irq(irq, 1);
128 static int dma_flags(int type, int bus_master, int transfer)
133 flags |= IORESOURCE_DMA_MASTER;
135 case ACPI_COMPATIBILITY:
136 flags |= IORESOURCE_DMA_COMPATIBLE;
139 flags |= IORESOURCE_DMA_TYPEA;
142 flags |= IORESOURCE_DMA_TYPEB;
145 flags |= IORESOURCE_DMA_TYPEF;
148 /* Set a default value ? */
149 flags |= IORESOURCE_DMA_COMPATIBLE;
150 pnp_err("Invalid DMA type");
153 case ACPI_TRANSFER_8:
154 flags |= IORESOURCE_DMA_8BIT;
156 case ACPI_TRANSFER_8_16:
157 flags |= IORESOURCE_DMA_8AND16BIT;
159 case ACPI_TRANSFER_16:
160 flags |= IORESOURCE_DMA_16BIT;
163 /* Set a default value ? */
164 flags |= IORESOURCE_DMA_8AND16BIT;
165 pnp_err("Invalid DMA transfer type");
171 static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
173 int bus_master, int transfer)
176 static unsigned char warned;
178 while (i < PNP_MAX_DMA &&
179 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
181 if (i < PNP_MAX_DMA) {
182 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
183 res->dma_resource[i].flags |=
184 dma_flags(type, bus_master, transfer);
186 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
189 res->dma_resource[i].start = dma;
190 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);
198 static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
199 u64 io, u64 len, int io_decode)
202 static unsigned char warned;
204 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
207 if (i < PNP_MAX_PORT) {
208 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
209 if (io_decode == ACPI_DECODE_16)
210 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
211 if (len <= 0 || (io + len - 1) >= 0x10003) {
212 res->port_resource[i].flags |= IORESOURCE_DISABLED;
215 res->port_resource[i].start = io;
216 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);
224 static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
229 static unsigned char warned;
231 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
234 if (i < PNP_MAX_MEM) {
235 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
237 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
240 if (write_protect == ACPI_READ_WRITE_MEMORY)
241 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
243 res->mem_resource[i].start = mem;
244 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);
252 static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
253 struct acpi_resource *res)
255 struct acpi_resource_address64 addr, *p = &addr;
258 status = acpi_resource_to_address64(res, p);
259 if (!ACPI_SUCCESS(status)) {
260 pnp_warn("PnPACPI: failed to convert resource type %d",
265 if (p->producer_consumer == ACPI_PRODUCER)
268 if (p->resource_type == ACPI_MEMORY_RANGE)
269 pnpacpi_parse_allocated_memresource(res_table,
270 p->minimum, p->address_length,
271 p->info.mem.write_protect);
272 else if (p->resource_type == ACPI_IO_RANGE)
273 pnpacpi_parse_allocated_ioresource(res_table,
274 p->minimum, p->address_length,
275 p->granularity == 0xfff ? ACPI_DECODE_10 :
279 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
282 struct pnp_resource_table *res_table = data;
286 case ACPI_RESOURCE_TYPE_IRQ:
288 * Per spec, only one interrupt per descriptor is allowed in
289 * _CRS, but some firmware violates this, so parse them all.
291 for (i = 0; i < res->data.irq.interrupt_count; i++) {
292 pnpacpi_parse_allocated_irqresource(res_table,
293 res->data.irq.interrupts[i],
294 res->data.irq.triggering,
295 res->data.irq.polarity,
296 res->data.irq.sharable);
300 case ACPI_RESOURCE_TYPE_DMA:
301 if (res->data.dma.channel_count > 0)
302 pnpacpi_parse_allocated_dmaresource(res_table,
303 res->data.dma.channels[0],
305 res->data.dma.bus_master,
306 res->data.dma.transfer);
309 case ACPI_RESOURCE_TYPE_IO:
310 pnpacpi_parse_allocated_ioresource(res_table,
311 res->data.io.minimum,
312 res->data.io.address_length,
313 res->data.io.io_decode);
316 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
317 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
320 case ACPI_RESOURCE_TYPE_FIXED_IO:
321 pnpacpi_parse_allocated_ioresource(res_table,
322 res->data.fixed_io.address,
323 res->data.fixed_io.address_length,
327 case ACPI_RESOURCE_TYPE_VENDOR:
330 case ACPI_RESOURCE_TYPE_END_TAG:
333 case ACPI_RESOURCE_TYPE_MEMORY24:
334 pnpacpi_parse_allocated_memresource(res_table,
335 res->data.memory24.minimum,
336 res->data.memory24.address_length,
337 res->data.memory24.write_protect);
339 case ACPI_RESOURCE_TYPE_MEMORY32:
340 pnpacpi_parse_allocated_memresource(res_table,
341 res->data.memory32.minimum,
342 res->data.memory32.address_length,
343 res->data.memory32.write_protect);
345 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
346 pnpacpi_parse_allocated_memresource(res_table,
347 res->data.fixed_memory32.address,
348 res->data.fixed_memory32.address_length,
349 res->data.fixed_memory32.write_protect);
351 case ACPI_RESOURCE_TYPE_ADDRESS16:
352 case ACPI_RESOURCE_TYPE_ADDRESS32:
353 case ACPI_RESOURCE_TYPE_ADDRESS64:
354 pnpacpi_parse_allocated_address_space(res_table, res);
357 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
358 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
362 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
363 if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
366 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
367 pnpacpi_parse_allocated_irqresource(res_table,
368 res->data.extended_irq.interrupts[i],
369 res->data.extended_irq.triggering,
370 res->data.extended_irq.polarity,
371 res->data.extended_irq.sharable);
375 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
379 pnp_warn("PnPACPI: unknown resource type %d", res->type);
386 acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
387 struct pnp_resource_table * res)
389 /* Blank the resource table values */
390 pnp_init_resource_table(res);
392 return acpi_walk_resources(handle, METHOD_NAME__CRS,
393 pnpacpi_allocated_resource, res);
396 static __init void pnpacpi_parse_dma_option(struct pnp_option *option,
397 struct acpi_resource_dma *p)
402 if (p->channel_count == 0)
404 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
408 for (i = 0; i < p->channel_count; i++)
409 dma->map |= 1 << p->channels[i];
411 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
413 pnp_register_dma_resource(option, dma);
416 static __init void pnpacpi_parse_irq_option(struct pnp_option *option,
417 struct acpi_resource_irq *p)
422 if (p->interrupt_count == 0)
424 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
428 for (i = 0; i < p->interrupt_count; i++)
429 if (p->interrupts[i])
430 __set_bit(p->interrupts[i], irq->map);
431 irq->flags = irq_flags(p->triggering, p->polarity);
433 pnp_register_irq_resource(option, irq);
436 static __init void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
437 struct acpi_resource_extended_irq *p)
442 if (p->interrupt_count == 0)
444 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
448 for (i = 0; i < p->interrupt_count; i++)
449 if (p->interrupts[i])
450 __set_bit(p->interrupts[i], irq->map);
451 irq->flags = irq_flags(p->triggering, p->polarity);
453 pnp_register_irq_resource(option, irq);
456 static __init void pnpacpi_parse_port_option(struct pnp_option *option,
457 struct acpi_resource_io *io)
459 struct pnp_port *port;
461 if (io->address_length == 0)
463 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
466 port->min = io->minimum;
467 port->max = io->maximum;
468 port->align = io->alignment;
469 port->size = io->address_length;
470 port->flags = ACPI_DECODE_16 == io->io_decode ?
471 PNP_PORT_FLAG_16BITADDR : 0;
472 pnp_register_port_resource(option, port);
475 static __init void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
476 struct acpi_resource_fixed_io *io)
478 struct pnp_port *port;
480 if (io->address_length == 0)
482 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
485 port->min = port->max = io->address;
486 port->size = io->address_length;
488 port->flags = PNP_PORT_FLAG_FIXED;
489 pnp_register_port_resource(option, port);
492 static __init void pnpacpi_parse_mem24_option(struct pnp_option *option,
493 struct acpi_resource_memory24 *p)
497 if (p->address_length == 0)
499 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
502 mem->min = p->minimum;
503 mem->max = p->maximum;
504 mem->align = p->alignment;
505 mem->size = p->address_length;
507 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
508 IORESOURCE_MEM_WRITEABLE : 0;
510 pnp_register_mem_resource(option, mem);
513 static __init void pnpacpi_parse_mem32_option(struct pnp_option *option,
514 struct acpi_resource_memory32 *p)
518 if (p->address_length == 0)
520 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
523 mem->min = p->minimum;
524 mem->max = p->maximum;
525 mem->align = p->alignment;
526 mem->size = p->address_length;
528 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
529 IORESOURCE_MEM_WRITEABLE : 0;
531 pnp_register_mem_resource(option, mem);
534 static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
535 struct acpi_resource_fixed_memory32 *p)
539 if (p->address_length == 0)
541 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
544 mem->min = mem->max = p->address;
545 mem->size = p->address_length;
548 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
549 IORESOURCE_MEM_WRITEABLE : 0;
551 pnp_register_mem_resource(option, mem);
554 static __init void pnpacpi_parse_address_option(struct pnp_option *option,
555 struct acpi_resource *r)
557 struct acpi_resource_address64 addr, *p = &addr;
560 struct pnp_port *port;
562 status = acpi_resource_to_address64(r, p);
563 if (!ACPI_SUCCESS(status)) {
564 pnp_warn("PnPACPI: failed to convert resource type %d",
569 if (p->address_length == 0)
572 if (p->resource_type == ACPI_MEMORY_RANGE) {
573 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
576 mem->min = mem->max = p->minimum;
577 mem->size = p->address_length;
579 mem->flags = (p->info.mem.write_protect ==
580 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
582 pnp_register_mem_resource(option, mem);
583 } else if (p->resource_type == ACPI_IO_RANGE) {
584 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
587 port->min = port->max = p->minimum;
588 port->size = p->address_length;
590 port->flags = PNP_PORT_FLAG_FIXED;
591 pnp_register_port_resource(option, port);
595 struct acpipnp_parse_option_s {
596 struct pnp_option *option;
597 struct pnp_option *option_independent;
601 static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
605 struct acpipnp_parse_option_s *parse_data = data;
606 struct pnp_dev *dev = parse_data->dev;
607 struct pnp_option *option = parse_data->option;
610 case ACPI_RESOURCE_TYPE_IRQ:
611 pnpacpi_parse_irq_option(option, &res->data.irq);
614 case ACPI_RESOURCE_TYPE_DMA:
615 pnpacpi_parse_dma_option(option, &res->data.dma);
618 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
619 switch (res->data.start_dpf.compatibility_priority) {
620 case ACPI_GOOD_CONFIGURATION:
621 priority = PNP_RES_PRIORITY_PREFERRED;
624 case ACPI_ACCEPTABLE_CONFIGURATION:
625 priority = PNP_RES_PRIORITY_ACCEPTABLE;
628 case ACPI_SUB_OPTIMAL_CONFIGURATION:
629 priority = PNP_RES_PRIORITY_FUNCTIONAL;
632 priority = PNP_RES_PRIORITY_INVALID;
635 /* TBD: Consider performance/robustness bits */
636 option = pnp_register_dependent_option(dev, priority);
639 parse_data->option = option;
642 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
643 /*only one EndDependentFn is allowed */
644 if (!parse_data->option_independent) {
645 pnp_warn("PnPACPI: more than one EndDependentFn");
648 parse_data->option = parse_data->option_independent;
649 parse_data->option_independent = NULL;
652 case ACPI_RESOURCE_TYPE_IO:
653 pnpacpi_parse_port_option(option, &res->data.io);
656 case ACPI_RESOURCE_TYPE_FIXED_IO:
657 pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io);
660 case ACPI_RESOURCE_TYPE_VENDOR:
661 case ACPI_RESOURCE_TYPE_END_TAG:
664 case ACPI_RESOURCE_TYPE_MEMORY24:
665 pnpacpi_parse_mem24_option(option, &res->data.memory24);
668 case ACPI_RESOURCE_TYPE_MEMORY32:
669 pnpacpi_parse_mem32_option(option, &res->data.memory32);
672 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
673 pnpacpi_parse_fixed_mem32_option(option,
674 &res->data.fixed_memory32);
677 case ACPI_RESOURCE_TYPE_ADDRESS16:
678 case ACPI_RESOURCE_TYPE_ADDRESS32:
679 case ACPI_RESOURCE_TYPE_ADDRESS64:
680 pnpacpi_parse_address_option(option, res);
683 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
686 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
687 pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq);
690 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
694 pnp_warn("PnPACPI: unknown resource type %d", res->type);
701 acpi_status __init pnpacpi_parse_resource_option_data(acpi_handle handle,
705 struct acpipnp_parse_option_s parse_data;
707 parse_data.option = pnp_register_independent_option(dev);
708 if (!parse_data.option)
710 parse_data.option_independent = parse_data.option;
711 parse_data.dev = dev;
712 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
713 pnpacpi_option_resource, &parse_data);
718 static int pnpacpi_supported_resource(struct acpi_resource *res)
721 case ACPI_RESOURCE_TYPE_IRQ:
722 case ACPI_RESOURCE_TYPE_DMA:
723 case ACPI_RESOURCE_TYPE_IO:
724 case ACPI_RESOURCE_TYPE_FIXED_IO:
725 case ACPI_RESOURCE_TYPE_MEMORY24:
726 case ACPI_RESOURCE_TYPE_MEMORY32:
727 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
728 case ACPI_RESOURCE_TYPE_ADDRESS16:
729 case ACPI_RESOURCE_TYPE_ADDRESS32:
730 case ACPI_RESOURCE_TYPE_ADDRESS64:
731 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
740 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
745 if (pnpacpi_supported_resource(res))
750 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
752 struct acpi_resource **resource = data;
754 if (pnpacpi_supported_resource(res)) {
755 (*resource)->type = res->type;
756 (*resource)->length = sizeof(struct acpi_resource);
763 int pnpacpi_build_resource_template(acpi_handle handle,
764 struct acpi_buffer *buffer)
766 struct acpi_resource *resource;
770 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
771 pnpacpi_count_resources, &res_cnt);
772 if (ACPI_FAILURE(status)) {
773 pnp_err("Evaluate _CRS failed");
778 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
779 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
780 if (!buffer->pointer)
782 pnp_dbg("Res cnt %d", res_cnt);
783 resource = (struct acpi_resource *)buffer->pointer;
784 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
785 pnpacpi_type_resources, &resource);
786 if (ACPI_FAILURE(status)) {
787 kfree(buffer->pointer);
788 pnp_err("Evaluate _CRS failed");
791 /* resource will pointer the end resource now */
792 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
797 static void pnpacpi_encode_irq(struct acpi_resource *resource,
800 int triggering, polarity;
802 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
803 resource->data.irq.triggering = triggering;
804 resource->data.irq.polarity = polarity;
805 if (triggering == ACPI_EDGE_SENSITIVE)
806 resource->data.irq.sharable = ACPI_EXCLUSIVE;
808 resource->data.irq.sharable = ACPI_SHARED;
809 resource->data.irq.interrupt_count = 1;
810 resource->data.irq.interrupts[0] = p->start;
813 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
816 int triggering, polarity;
818 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
819 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
820 resource->data.extended_irq.triggering = triggering;
821 resource->data.extended_irq.polarity = polarity;
822 if (triggering == ACPI_EDGE_SENSITIVE)
823 resource->data.irq.sharable = ACPI_EXCLUSIVE;
825 resource->data.irq.sharable = ACPI_SHARED;
826 resource->data.extended_irq.interrupt_count = 1;
827 resource->data.extended_irq.interrupts[0] = p->start;
830 static void pnpacpi_encode_dma(struct acpi_resource *resource,
833 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
834 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
835 case IORESOURCE_DMA_TYPEA:
836 resource->data.dma.type = ACPI_TYPE_A;
838 case IORESOURCE_DMA_TYPEB:
839 resource->data.dma.type = ACPI_TYPE_B;
841 case IORESOURCE_DMA_TYPEF:
842 resource->data.dma.type = ACPI_TYPE_F;
845 resource->data.dma.type = ACPI_COMPATIBILITY;
848 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
849 case IORESOURCE_DMA_8BIT:
850 resource->data.dma.transfer = ACPI_TRANSFER_8;
852 case IORESOURCE_DMA_8AND16BIT:
853 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
856 resource->data.dma.transfer = ACPI_TRANSFER_16;
859 resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
860 resource->data.dma.channel_count = 1;
861 resource->data.dma.channels[0] = p->start;
864 static void pnpacpi_encode_io(struct acpi_resource *resource,
867 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
868 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
869 ACPI_DECODE_16 : ACPI_DECODE_10;
870 resource->data.io.minimum = p->start;
871 resource->data.io.maximum = p->end;
872 resource->data.io.alignment = 0; /* Correct? */
873 resource->data.io.address_length = p->end - p->start + 1;
876 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
879 resource->data.fixed_io.address = p->start;
880 resource->data.fixed_io.address_length = p->end - p->start + 1;
883 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
886 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
887 resource->data.memory24.write_protect =
888 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
889 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
890 resource->data.memory24.minimum = p->start;
891 resource->data.memory24.maximum = p->end;
892 resource->data.memory24.alignment = 0;
893 resource->data.memory24.address_length = p->end - p->start + 1;
896 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
899 resource->data.memory32.write_protect =
900 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
901 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
902 resource->data.memory32.minimum = p->start;
903 resource->data.memory32.maximum = p->end;
904 resource->data.memory32.alignment = 0;
905 resource->data.memory32.address_length = p->end - p->start + 1;
908 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
911 resource->data.fixed_memory32.write_protect =
912 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
913 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
914 resource->data.fixed_memory32.address = p->start;
915 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
918 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
919 struct acpi_buffer *buffer)
922 /* pnpacpi_build_resource_template allocates extra mem */
923 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
924 struct acpi_resource *resource = buffer->pointer;
925 int port = 0, irq = 0, dma = 0, mem = 0;
927 pnp_dbg("res cnt %d", res_cnt);
928 while (i < res_cnt) {
929 switch (resource->type) {
930 case ACPI_RESOURCE_TYPE_IRQ:
931 pnp_dbg("Encode irq");
932 pnpacpi_encode_irq(resource,
933 &res_table->irq_resource[irq]);
937 case ACPI_RESOURCE_TYPE_DMA:
938 pnp_dbg("Encode dma");
939 pnpacpi_encode_dma(resource,
940 &res_table->dma_resource[dma]);
943 case ACPI_RESOURCE_TYPE_IO:
944 pnp_dbg("Encode io");
945 pnpacpi_encode_io(resource,
946 &res_table->port_resource[port]);
949 case ACPI_RESOURCE_TYPE_FIXED_IO:
950 pnp_dbg("Encode fixed io");
951 pnpacpi_encode_fixed_io(resource,
953 port_resource[port]);
956 case ACPI_RESOURCE_TYPE_MEMORY24:
957 pnp_dbg("Encode mem24");
958 pnpacpi_encode_mem24(resource,
959 &res_table->mem_resource[mem]);
962 case ACPI_RESOURCE_TYPE_MEMORY32:
963 pnp_dbg("Encode mem32");
964 pnpacpi_encode_mem32(resource,
965 &res_table->mem_resource[mem]);
968 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
969 pnp_dbg("Encode fixed mem32");
970 pnpacpi_encode_fixed_mem32(resource,
975 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
976 pnp_dbg("Encode ext irq");
977 pnpacpi_encode_ext_irq(resource,
978 &res_table->irq_resource[irq]);
981 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
982 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
983 case ACPI_RESOURCE_TYPE_VENDOR:
984 case ACPI_RESOURCE_TYPE_END_TAG:
985 case ACPI_RESOURCE_TYPE_ADDRESS16:
986 case ACPI_RESOURCE_TYPE_ADDRESS32:
987 case ACPI_RESOURCE_TYPE_ADDRESS64:
988 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
989 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
990 default: /* other type */
991 pnp_warn("unknown resource type %d", resource->type);