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 && !warned) {
88 printk(KERN_ERR "pnpacpi: exceeded the max number of IRQ "
89 "resources: %d \n", PNP_MAX_IRQ);
94 * in IO-APIC mode, use overrided attribute. Two reasons:
96 * 2. BIOS uses IO-APIC mode Interrupt Source Override
98 if (!acpi_get_override_irq(gsi, &t, &p)) {
99 t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
100 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
102 if (triggering != t || polarity != p) {
103 pnp_warn("IRQ %d override to %s, %s",
104 gsi, t ? "edge":"level", p ? "low":"high");
110 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
111 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
112 irq = acpi_register_gsi(gsi, triggering, polarity);
114 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
119 res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
121 res->irq_resource[i].start = irq;
122 res->irq_resource[i].end = irq;
123 pcibios_penalize_isa_irq(irq, 1);
126 static int dma_flags(int type, int bus_master, int transfer)
131 flags |= IORESOURCE_DMA_MASTER;
133 case ACPI_COMPATIBILITY:
134 flags |= IORESOURCE_DMA_COMPATIBLE;
137 flags |= IORESOURCE_DMA_TYPEA;
140 flags |= IORESOURCE_DMA_TYPEB;
143 flags |= IORESOURCE_DMA_TYPEF;
146 /* Set a default value ? */
147 flags |= IORESOURCE_DMA_COMPATIBLE;
148 pnp_err("Invalid DMA type");
151 case ACPI_TRANSFER_8:
152 flags |= IORESOURCE_DMA_8BIT;
154 case ACPI_TRANSFER_8_16:
155 flags |= IORESOURCE_DMA_8AND16BIT;
157 case ACPI_TRANSFER_16:
158 flags |= IORESOURCE_DMA_16BIT;
161 /* Set a default value ? */
162 flags |= IORESOURCE_DMA_8AND16BIT;
163 pnp_err("Invalid DMA transfer type");
169 static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
171 int bus_master, int transfer)
174 static unsigned char warned;
176 while (i < PNP_MAX_DMA &&
177 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
179 if (i < PNP_MAX_DMA) {
180 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
181 res->dma_resource[i].flags |=
182 dma_flags(type, bus_master, transfer);
184 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
187 res->dma_resource[i].start = dma;
188 res->dma_resource[i].end = dma;
189 } else if (!warned) {
190 printk(KERN_ERR "pnpacpi: exceeded the max number of DMA "
191 "resources: %d \n", PNP_MAX_DMA);
196 static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
197 u64 io, u64 len, int io_decode)
200 static unsigned char warned;
202 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
205 if (i < PNP_MAX_PORT) {
206 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
207 if (io_decode == ACPI_DECODE_16)
208 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
209 if (len <= 0 || (io + len - 1) >= 0x10003) {
210 res->port_resource[i].flags |= IORESOURCE_DISABLED;
213 res->port_resource[i].start = io;
214 res->port_resource[i].end = io + len - 1;
215 } else if (!warned) {
216 printk(KERN_ERR "pnpacpi: exceeded the max number of IO "
217 "resources: %d \n", PNP_MAX_PORT);
221 static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
226 static unsigned char warned;
228 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
231 if (i < PNP_MAX_MEM) {
232 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
234 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
237 if (write_protect == ACPI_READ_WRITE_MEMORY)
238 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
240 res->mem_resource[i].start = mem;
241 res->mem_resource[i].end = mem + len - 1;
242 } else if (!warned) {
243 printk(KERN_ERR "pnpacpi: exceeded the max number of mem "
244 "resources: %d\n", PNP_MAX_MEM);
248 static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
249 struct acpi_resource *res)
251 struct acpi_resource_address64 addr, *p = &addr;
254 status = acpi_resource_to_address64(res, p);
255 if (!ACPI_SUCCESS(status)) {
256 pnp_warn("PnPACPI: failed to convert resource type %d",
261 if (p->producer_consumer == ACPI_PRODUCER)
264 if (p->resource_type == ACPI_MEMORY_RANGE)
265 pnpacpi_parse_allocated_memresource(res_table,
266 p->minimum, p->address_length,
267 p->info.mem.write_protect);
268 else if (p->resource_type == ACPI_IO_RANGE)
269 pnpacpi_parse_allocated_ioresource(res_table,
270 p->minimum, p->address_length,
271 p->granularity == 0xfff ? ACPI_DECODE_10 :
275 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
278 struct pnp_resource_table *res_table = data;
282 case ACPI_RESOURCE_TYPE_IRQ:
284 * Per spec, only one interrupt per descriptor is allowed in
285 * _CRS, but some firmware violates this, so parse them all.
287 for (i = 0; i < res->data.irq.interrupt_count; i++) {
288 pnpacpi_parse_allocated_irqresource(res_table,
289 res->data.irq.interrupts[i],
290 res->data.irq.triggering,
291 res->data.irq.polarity,
292 res->data.irq.sharable);
296 case ACPI_RESOURCE_TYPE_DMA:
297 if (res->data.dma.channel_count > 0)
298 pnpacpi_parse_allocated_dmaresource(res_table,
299 res->data.dma.channels[0],
301 res->data.dma.bus_master,
302 res->data.dma.transfer);
305 case ACPI_RESOURCE_TYPE_IO:
306 pnpacpi_parse_allocated_ioresource(res_table,
307 res->data.io.minimum,
308 res->data.io.address_length,
309 res->data.io.io_decode);
312 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
313 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
316 case ACPI_RESOURCE_TYPE_FIXED_IO:
317 pnpacpi_parse_allocated_ioresource(res_table,
318 res->data.fixed_io.address,
319 res->data.fixed_io.address_length,
323 case ACPI_RESOURCE_TYPE_VENDOR:
326 case ACPI_RESOURCE_TYPE_END_TAG:
329 case ACPI_RESOURCE_TYPE_MEMORY24:
330 pnpacpi_parse_allocated_memresource(res_table,
331 res->data.memory24.minimum,
332 res->data.memory24.address_length,
333 res->data.memory24.write_protect);
335 case ACPI_RESOURCE_TYPE_MEMORY32:
336 pnpacpi_parse_allocated_memresource(res_table,
337 res->data.memory32.minimum,
338 res->data.memory32.address_length,
339 res->data.memory32.write_protect);
341 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
342 pnpacpi_parse_allocated_memresource(res_table,
343 res->data.fixed_memory32.address,
344 res->data.fixed_memory32.address_length,
345 res->data.fixed_memory32.write_protect);
347 case ACPI_RESOURCE_TYPE_ADDRESS16:
348 case ACPI_RESOURCE_TYPE_ADDRESS32:
349 case ACPI_RESOURCE_TYPE_ADDRESS64:
350 pnpacpi_parse_allocated_address_space(res_table, res);
353 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
354 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
358 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
359 if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
362 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
363 pnpacpi_parse_allocated_irqresource(res_table,
364 res->data.extended_irq.interrupts[i],
365 res->data.extended_irq.triggering,
366 res->data.extended_irq.polarity,
367 res->data.extended_irq.sharable);
371 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
375 pnp_warn("PnPACPI: unknown resource type %d", res->type);
382 acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
383 struct pnp_resource_table * res)
385 /* Blank the resource table values */
386 pnp_init_resource_table(res);
388 return acpi_walk_resources(handle, METHOD_NAME__CRS,
389 pnpacpi_allocated_resource, res);
392 static void pnpacpi_parse_dma_option(struct pnp_option *option,
393 struct acpi_resource_dma *p)
398 if (p->channel_count == 0)
400 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
404 for (i = 0; i < p->channel_count; i++)
405 dma->map |= 1 << p->channels[i];
407 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
409 pnp_register_dma_resource(option, dma);
412 static void pnpacpi_parse_irq_option(struct pnp_option *option,
413 struct acpi_resource_irq *p)
418 if (p->interrupt_count == 0)
420 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
424 for (i = 0; i < p->interrupt_count; i++)
425 if (p->interrupts[i])
426 __set_bit(p->interrupts[i], irq->map);
427 irq->flags = irq_flags(p->triggering, p->polarity);
429 pnp_register_irq_resource(option, irq);
432 static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
433 struct acpi_resource_extended_irq *p)
438 if (p->interrupt_count == 0)
440 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
444 for (i = 0; i < p->interrupt_count; i++)
445 if (p->interrupts[i])
446 __set_bit(p->interrupts[i], irq->map);
447 irq->flags = irq_flags(p->triggering, p->polarity);
449 pnp_register_irq_resource(option, irq);
452 static void pnpacpi_parse_port_option(struct pnp_option *option,
453 struct acpi_resource_io *io)
455 struct pnp_port *port;
457 if (io->address_length == 0)
459 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
462 port->min = io->minimum;
463 port->max = io->maximum;
464 port->align = io->alignment;
465 port->size = io->address_length;
466 port->flags = ACPI_DECODE_16 == io->io_decode ?
467 PNP_PORT_FLAG_16BITADDR : 0;
468 pnp_register_port_resource(option, port);
471 static void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
472 struct acpi_resource_fixed_io *io)
474 struct pnp_port *port;
476 if (io->address_length == 0)
478 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
481 port->min = port->max = io->address;
482 port->size = io->address_length;
484 port->flags = PNP_PORT_FLAG_FIXED;
485 pnp_register_port_resource(option, port);
488 static void pnpacpi_parse_mem24_option(struct pnp_option *option,
489 struct acpi_resource_memory24 *p)
493 if (p->address_length == 0)
495 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
498 mem->min = p->minimum;
499 mem->max = p->maximum;
500 mem->align = p->alignment;
501 mem->size = p->address_length;
503 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
504 IORESOURCE_MEM_WRITEABLE : 0;
506 pnp_register_mem_resource(option, mem);
509 static void pnpacpi_parse_mem32_option(struct pnp_option *option,
510 struct acpi_resource_memory32 *p)
514 if (p->address_length == 0)
516 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
519 mem->min = p->minimum;
520 mem->max = p->maximum;
521 mem->align = p->alignment;
522 mem->size = p->address_length;
524 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
525 IORESOURCE_MEM_WRITEABLE : 0;
527 pnp_register_mem_resource(option, mem);
530 static void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
531 struct acpi_resource_fixed_memory32 *p)
535 if (p->address_length == 0)
537 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
540 mem->min = mem->max = p->address;
541 mem->size = p->address_length;
544 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
545 IORESOURCE_MEM_WRITEABLE : 0;
547 pnp_register_mem_resource(option, mem);
550 static void pnpacpi_parse_address_option(struct pnp_option *option,
551 struct acpi_resource *r)
553 struct acpi_resource_address64 addr, *p = &addr;
556 struct pnp_port *port;
558 status = acpi_resource_to_address64(r, p);
559 if (!ACPI_SUCCESS(status)) {
560 pnp_warn("PnPACPI: failed to convert resource type %d",
565 if (p->address_length == 0)
568 if (p->resource_type == ACPI_MEMORY_RANGE) {
569 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
572 mem->min = mem->max = p->minimum;
573 mem->size = p->address_length;
575 mem->flags = (p->info.mem.write_protect ==
576 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
578 pnp_register_mem_resource(option, mem);
579 } else if (p->resource_type == ACPI_IO_RANGE) {
580 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
583 port->min = port->max = p->minimum;
584 port->size = p->address_length;
586 port->flags = PNP_PORT_FLAG_FIXED;
587 pnp_register_port_resource(option, port);
591 struct acpipnp_parse_option_s {
592 struct pnp_option *option;
593 struct pnp_option *option_independent;
597 static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
601 struct acpipnp_parse_option_s *parse_data = data;
602 struct pnp_dev *dev = parse_data->dev;
603 struct pnp_option *option = parse_data->option;
606 case ACPI_RESOURCE_TYPE_IRQ:
607 pnpacpi_parse_irq_option(option, &res->data.irq);
610 case ACPI_RESOURCE_TYPE_DMA:
611 pnpacpi_parse_dma_option(option, &res->data.dma);
614 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
615 switch (res->data.start_dpf.compatibility_priority) {
616 case ACPI_GOOD_CONFIGURATION:
617 priority = PNP_RES_PRIORITY_PREFERRED;
620 case ACPI_ACCEPTABLE_CONFIGURATION:
621 priority = PNP_RES_PRIORITY_ACCEPTABLE;
624 case ACPI_SUB_OPTIMAL_CONFIGURATION:
625 priority = PNP_RES_PRIORITY_FUNCTIONAL;
628 priority = PNP_RES_PRIORITY_INVALID;
631 /* TBD: Consider performance/robustness bits */
632 option = pnp_register_dependent_option(dev, priority);
635 parse_data->option = option;
638 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
639 /*only one EndDependentFn is allowed */
640 if (!parse_data->option_independent) {
641 pnp_warn("PnPACPI: more than one EndDependentFn");
644 parse_data->option = parse_data->option_independent;
645 parse_data->option_independent = NULL;
648 case ACPI_RESOURCE_TYPE_IO:
649 pnpacpi_parse_port_option(option, &res->data.io);
652 case ACPI_RESOURCE_TYPE_FIXED_IO:
653 pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io);
656 case ACPI_RESOURCE_TYPE_VENDOR:
657 case ACPI_RESOURCE_TYPE_END_TAG:
660 case ACPI_RESOURCE_TYPE_MEMORY24:
661 pnpacpi_parse_mem24_option(option, &res->data.memory24);
664 case ACPI_RESOURCE_TYPE_MEMORY32:
665 pnpacpi_parse_mem32_option(option, &res->data.memory32);
668 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
669 pnpacpi_parse_fixed_mem32_option(option,
670 &res->data.fixed_memory32);
673 case ACPI_RESOURCE_TYPE_ADDRESS16:
674 case ACPI_RESOURCE_TYPE_ADDRESS32:
675 case ACPI_RESOURCE_TYPE_ADDRESS64:
676 pnpacpi_parse_address_option(option, res);
679 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
682 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
683 pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq);
686 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
690 pnp_warn("PnPACPI: unknown resource type %d", res->type);
697 acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
698 struct pnp_dev * dev)
701 struct acpipnp_parse_option_s parse_data;
703 parse_data.option = pnp_register_independent_option(dev);
704 if (!parse_data.option)
706 parse_data.option_independent = parse_data.option;
707 parse_data.dev = dev;
708 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
709 pnpacpi_option_resource, &parse_data);
714 static int pnpacpi_supported_resource(struct acpi_resource *res)
717 case ACPI_RESOURCE_TYPE_IRQ:
718 case ACPI_RESOURCE_TYPE_DMA:
719 case ACPI_RESOURCE_TYPE_IO:
720 case ACPI_RESOURCE_TYPE_FIXED_IO:
721 case ACPI_RESOURCE_TYPE_MEMORY24:
722 case ACPI_RESOURCE_TYPE_MEMORY32:
723 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
724 case ACPI_RESOURCE_TYPE_ADDRESS16:
725 case ACPI_RESOURCE_TYPE_ADDRESS32:
726 case ACPI_RESOURCE_TYPE_ADDRESS64:
727 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
736 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
741 if (pnpacpi_supported_resource(res))
746 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
748 struct acpi_resource **resource = data;
750 if (pnpacpi_supported_resource(res)) {
751 (*resource)->type = res->type;
752 (*resource)->length = sizeof(struct acpi_resource);
759 int pnpacpi_build_resource_template(acpi_handle handle,
760 struct acpi_buffer *buffer)
762 struct acpi_resource *resource;
766 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
767 pnpacpi_count_resources, &res_cnt);
768 if (ACPI_FAILURE(status)) {
769 pnp_err("Evaluate _CRS failed");
774 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
775 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
776 if (!buffer->pointer)
778 pnp_dbg("Res cnt %d", res_cnt);
779 resource = (struct acpi_resource *)buffer->pointer;
780 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
781 pnpacpi_type_resources, &resource);
782 if (ACPI_FAILURE(status)) {
783 kfree(buffer->pointer);
784 pnp_err("Evaluate _CRS failed");
787 /* resource will pointer the end resource now */
788 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
793 static void pnpacpi_encode_irq(struct acpi_resource *resource,
796 int triggering, polarity;
798 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
799 resource->data.irq.triggering = triggering;
800 resource->data.irq.polarity = polarity;
801 if (triggering == ACPI_EDGE_SENSITIVE)
802 resource->data.irq.sharable = ACPI_EXCLUSIVE;
804 resource->data.irq.sharable = ACPI_SHARED;
805 resource->data.irq.interrupt_count = 1;
806 resource->data.irq.interrupts[0] = p->start;
809 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
812 int triggering, polarity;
814 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
815 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
816 resource->data.extended_irq.triggering = triggering;
817 resource->data.extended_irq.polarity = polarity;
818 if (triggering == ACPI_EDGE_SENSITIVE)
819 resource->data.irq.sharable = ACPI_EXCLUSIVE;
821 resource->data.irq.sharable = ACPI_SHARED;
822 resource->data.extended_irq.interrupt_count = 1;
823 resource->data.extended_irq.interrupts[0] = p->start;
826 static void pnpacpi_encode_dma(struct acpi_resource *resource,
829 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
830 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
831 case IORESOURCE_DMA_TYPEA:
832 resource->data.dma.type = ACPI_TYPE_A;
834 case IORESOURCE_DMA_TYPEB:
835 resource->data.dma.type = ACPI_TYPE_B;
837 case IORESOURCE_DMA_TYPEF:
838 resource->data.dma.type = ACPI_TYPE_F;
841 resource->data.dma.type = ACPI_COMPATIBILITY;
844 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
845 case IORESOURCE_DMA_8BIT:
846 resource->data.dma.transfer = ACPI_TRANSFER_8;
848 case IORESOURCE_DMA_8AND16BIT:
849 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
852 resource->data.dma.transfer = ACPI_TRANSFER_16;
855 resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
856 resource->data.dma.channel_count = 1;
857 resource->data.dma.channels[0] = p->start;
860 static void pnpacpi_encode_io(struct acpi_resource *resource,
863 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
864 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
865 ACPI_DECODE_16 : ACPI_DECODE_10;
866 resource->data.io.minimum = p->start;
867 resource->data.io.maximum = p->end;
868 resource->data.io.alignment = 0; /* Correct? */
869 resource->data.io.address_length = p->end - p->start + 1;
872 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
875 resource->data.fixed_io.address = p->start;
876 resource->data.fixed_io.address_length = p->end - p->start + 1;
879 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
882 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
883 resource->data.memory24.write_protect =
884 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
885 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
886 resource->data.memory24.minimum = p->start;
887 resource->data.memory24.maximum = p->end;
888 resource->data.memory24.alignment = 0;
889 resource->data.memory24.address_length = p->end - p->start + 1;
892 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
895 resource->data.memory32.write_protect =
896 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
897 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
898 resource->data.memory32.minimum = p->start;
899 resource->data.memory32.maximum = p->end;
900 resource->data.memory32.alignment = 0;
901 resource->data.memory32.address_length = p->end - p->start + 1;
904 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
907 resource->data.fixed_memory32.write_protect =
908 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
909 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
910 resource->data.fixed_memory32.address = p->start;
911 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
914 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
915 struct acpi_buffer *buffer)
918 /* pnpacpi_build_resource_template allocates extra mem */
919 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
920 struct acpi_resource *resource = buffer->pointer;
921 int port = 0, irq = 0, dma = 0, mem = 0;
923 pnp_dbg("res cnt %d", res_cnt);
924 while (i < res_cnt) {
925 switch (resource->type) {
926 case ACPI_RESOURCE_TYPE_IRQ:
927 pnp_dbg("Encode irq");
928 pnpacpi_encode_irq(resource,
929 &res_table->irq_resource[irq]);
933 case ACPI_RESOURCE_TYPE_DMA:
934 pnp_dbg("Encode dma");
935 pnpacpi_encode_dma(resource,
936 &res_table->dma_resource[dma]);
939 case ACPI_RESOURCE_TYPE_IO:
940 pnp_dbg("Encode io");
941 pnpacpi_encode_io(resource,
942 &res_table->port_resource[port]);
945 case ACPI_RESOURCE_TYPE_FIXED_IO:
946 pnp_dbg("Encode fixed io");
947 pnpacpi_encode_fixed_io(resource,
949 port_resource[port]);
952 case ACPI_RESOURCE_TYPE_MEMORY24:
953 pnp_dbg("Encode mem24");
954 pnpacpi_encode_mem24(resource,
955 &res_table->mem_resource[mem]);
958 case ACPI_RESOURCE_TYPE_MEMORY32:
959 pnp_dbg("Encode mem32");
960 pnpacpi_encode_mem32(resource,
961 &res_table->mem_resource[mem]);
964 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
965 pnp_dbg("Encode fixed mem32");
966 pnpacpi_encode_fixed_mem32(resource,
971 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
972 pnp_dbg("Encode ext irq");
973 pnpacpi_encode_ext_irq(resource,
974 &res_table->irq_resource[irq]);
977 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
978 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
979 case ACPI_RESOURCE_TYPE_VENDOR:
980 case ACPI_RESOURCE_TYPE_END_TAG:
981 case ACPI_RESOURCE_TYPE_ADDRESS16:
982 case ACPI_RESOURCE_TYPE_ADDRESS32:
983 case ACPI_RESOURCE_TYPE_ADDRESS64:
984 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
985 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
986 default: /* other type */
987 pnp_warn("unknown resource type %d", resource->type);