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)
38 if (triggering == ACPI_LEVEL_SENSITIVE) {
39 if(polarity == ACPI_ACTIVE_LOW)
40 flag = IORESOURCE_IRQ_LOWLEVEL;
42 flag = IORESOURCE_IRQ_HIGHLEVEL;
45 if(polarity == ACPI_ACTIVE_LOW)
46 flag = IORESOURCE_IRQ_LOWEDGE;
48 flag = IORESOURCE_IRQ_HIGHEDGE;
53 static void decode_irq_flags(int flag, int *triggering, int *polarity)
56 case IORESOURCE_IRQ_LOWLEVEL:
57 *triggering = ACPI_LEVEL_SENSITIVE;
58 *polarity = ACPI_ACTIVE_LOW;
60 case IORESOURCE_IRQ_HIGHLEVEL:
61 *triggering = ACPI_LEVEL_SENSITIVE;
62 *polarity = ACPI_ACTIVE_HIGH;
64 case IORESOURCE_IRQ_LOWEDGE:
65 *triggering = ACPI_EDGE_SENSITIVE;
66 *polarity = ACPI_ACTIVE_LOW;
68 case IORESOURCE_IRQ_HIGHEDGE:
69 *triggering = ACPI_EDGE_SENSITIVE;
70 *polarity = ACPI_ACTIVE_HIGH;
76 pnpacpi_parse_allocated_irqresource(struct pnp_resource_table * res, u32 gsi,
77 int triggering, int polarity)
85 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
91 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
92 irq = acpi_register_gsi(gsi, triggering, polarity);
94 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
98 res->irq_resource[i].start = irq;
99 res->irq_resource[i].end = irq;
100 pcibios_penalize_isa_irq(irq, 1);
104 pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table * res, u32 dma)
107 while (i < PNP_MAX_DMA &&
108 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
110 if (i < PNP_MAX_DMA) {
111 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
113 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
116 res->dma_resource[i].start = dma;
117 res->dma_resource[i].end = dma;
122 pnpacpi_parse_allocated_ioresource(struct pnp_resource_table * res,
126 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
129 if (i < PNP_MAX_PORT) {
130 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
131 if (len <= 0 || (io + len -1) >= 0x10003) {
132 res->port_resource[i].flags |= IORESOURCE_DISABLED;
135 res->port_resource[i].start = io;
136 res->port_resource[i].end = io + len - 1;
141 pnpacpi_parse_allocated_memresource(struct pnp_resource_table * res,
145 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
148 if (i < PNP_MAX_MEM) {
149 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
151 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
154 res->mem_resource[i].start = mem;
155 res->mem_resource[i].end = mem + len - 1;
160 pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
161 struct acpi_resource *res)
163 struct acpi_resource_address64 addr, *p = &addr;
166 status = acpi_resource_to_address64(res, p);
167 if (!ACPI_SUCCESS(status)) {
168 pnp_warn("PnPACPI: failed to convert resource type %d",
173 if (p->resource_type == ACPI_MEMORY_RANGE)
174 pnpacpi_parse_allocated_memresource(res_table,
175 p->minimum, p->address_length);
176 else if (p->resource_type == ACPI_IO_RANGE)
177 pnpacpi_parse_allocated_ioresource(res_table,
178 p->minimum, p->address_length);
181 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
184 struct pnp_resource_table * res_table = (struct pnp_resource_table *)data;
188 case ACPI_RESOURCE_TYPE_IRQ:
190 * Per spec, only one interrupt per descriptor is allowed in
191 * _CRS, but some firmware violates this, so parse them all.
193 for (i = 0; i < res->data.irq.interrupt_count; i++) {
194 pnpacpi_parse_allocated_irqresource(res_table,
195 res->data.irq.interrupts[i],
196 res->data.irq.triggering,
197 res->data.irq.polarity);
201 case ACPI_RESOURCE_TYPE_DMA:
202 if (res->data.dma.channel_count > 0)
203 pnpacpi_parse_allocated_dmaresource(res_table,
204 res->data.dma.channels[0]);
207 case ACPI_RESOURCE_TYPE_IO:
208 pnpacpi_parse_allocated_ioresource(res_table,
209 res->data.io.minimum,
210 res->data.io.address_length);
213 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
214 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
217 case ACPI_RESOURCE_TYPE_FIXED_IO:
218 pnpacpi_parse_allocated_ioresource(res_table,
219 res->data.fixed_io.address,
220 res->data.fixed_io.address_length);
223 case ACPI_RESOURCE_TYPE_VENDOR:
226 case ACPI_RESOURCE_TYPE_END_TAG:
229 case ACPI_RESOURCE_TYPE_MEMORY24:
230 pnpacpi_parse_allocated_memresource(res_table,
231 res->data.memory24.minimum,
232 res->data.memory24.address_length);
234 case ACPI_RESOURCE_TYPE_MEMORY32:
235 pnpacpi_parse_allocated_memresource(res_table,
236 res->data.memory32.minimum,
237 res->data.memory32.address_length);
239 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
240 pnpacpi_parse_allocated_memresource(res_table,
241 res->data.fixed_memory32.address,
242 res->data.fixed_memory32.address_length);
244 case ACPI_RESOURCE_TYPE_ADDRESS16:
245 case ACPI_RESOURCE_TYPE_ADDRESS32:
246 case ACPI_RESOURCE_TYPE_ADDRESS64:
247 pnpacpi_parse_allocated_address_space(res_table, res);
250 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
253 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
254 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
255 pnpacpi_parse_allocated_irqresource(res_table,
256 res->data.extended_irq.interrupts[i],
257 res->data.extended_irq.triggering,
258 res->data.extended_irq.polarity);
262 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
266 pnp_warn("PnPACPI: unknown resource type %d", res->type);
273 acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle, struct pnp_resource_table * res)
275 /* Blank the resource table values */
276 pnp_init_resource_table(res);
278 return acpi_walk_resources(handle, METHOD_NAME__CRS, pnpacpi_allocated_resource, res);
281 static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_resource_dma *p)
284 struct pnp_dma * dma;
286 if (p->channel_count == 0)
288 dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL);
292 for(i = 0; i < p->channel_count; i++)
293 dma->map |= 1 << p->channels[i];
296 dma->flags |= IORESOURCE_DMA_MASTER;
298 case ACPI_COMPATIBILITY:
299 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
302 dma->flags |= IORESOURCE_DMA_TYPEA;
305 dma->flags |= IORESOURCE_DMA_TYPEB;
308 dma->flags |= IORESOURCE_DMA_TYPEF;
311 /* Set a default value ? */
312 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
313 pnp_err("Invalid DMA type");
315 switch (p->transfer) {
316 case ACPI_TRANSFER_8:
317 dma->flags |= IORESOURCE_DMA_8BIT;
319 case ACPI_TRANSFER_8_16:
320 dma->flags |= IORESOURCE_DMA_8AND16BIT;
322 case ACPI_TRANSFER_16:
323 dma->flags |= IORESOURCE_DMA_16BIT;
326 /* Set a default value ? */
327 dma->flags |= IORESOURCE_DMA_8AND16BIT;
328 pnp_err("Invalid DMA transfer type");
331 pnp_register_dma_resource(option,dma);
336 static void pnpacpi_parse_irq_option(struct pnp_option *option,
337 struct acpi_resource_irq *p)
340 struct pnp_irq * irq;
342 if (p->interrupt_count == 0)
344 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
348 for(i = 0; i < p->interrupt_count; i++)
349 if (p->interrupts[i])
350 __set_bit(p->interrupts[i], irq->map);
351 irq->flags = irq_flags(p->triggering, p->polarity);
353 pnp_register_irq_resource(option, irq);
357 static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
358 struct acpi_resource_extended_irq *p)
361 struct pnp_irq * irq;
363 if (p->interrupt_count == 0)
365 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
369 for(i = 0; i < p->interrupt_count; i++)
370 if (p->interrupts[i])
371 __set_bit(p->interrupts[i], irq->map);
372 irq->flags = irq_flags(p->triggering, p->polarity);
374 pnp_register_irq_resource(option, irq);
379 pnpacpi_parse_port_option(struct pnp_option *option,
380 struct acpi_resource_io *io)
382 struct pnp_port * port;
384 if (io->address_length == 0)
386 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
389 port->min = io->minimum;
390 port->max = io->maximum;
391 port->align = io->alignment;
392 port->size = io->address_length;
393 port->flags = ACPI_DECODE_16 == io->io_decode ?
394 PNP_PORT_FLAG_16BITADDR : 0;
395 pnp_register_port_resource(option,port);
400 pnpacpi_parse_fixed_port_option(struct pnp_option *option,
401 struct acpi_resource_fixed_io *io)
403 struct pnp_port * port;
405 if (io->address_length == 0)
407 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
410 port->min = port->max = io->address;
411 port->size = io->address_length;
413 port->flags = PNP_PORT_FLAG_FIXED;
414 pnp_register_port_resource(option,port);
419 pnpacpi_parse_mem24_option(struct pnp_option *option,
420 struct acpi_resource_memory24 *p)
422 struct pnp_mem * mem;
424 if (p->address_length == 0)
426 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
429 mem->min = p->minimum;
430 mem->max = p->maximum;
431 mem->align = p->alignment;
432 mem->size = p->address_length;
434 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
435 IORESOURCE_MEM_WRITEABLE : 0;
437 pnp_register_mem_resource(option,mem);
442 pnpacpi_parse_mem32_option(struct pnp_option *option,
443 struct acpi_resource_memory32 *p)
445 struct pnp_mem * mem;
447 if (p->address_length == 0)
449 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
452 mem->min = p->minimum;
453 mem->max = p->maximum;
454 mem->align = p->alignment;
455 mem->size = p->address_length;
457 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
458 IORESOURCE_MEM_WRITEABLE : 0;
460 pnp_register_mem_resource(option,mem);
465 pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
466 struct acpi_resource_fixed_memory32 *p)
468 struct pnp_mem * mem;
470 if (p->address_length == 0)
472 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
475 mem->min = mem->max = p->address;
476 mem->size = p->address_length;
479 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
480 IORESOURCE_MEM_WRITEABLE : 0;
482 pnp_register_mem_resource(option,mem);
487 pnpacpi_parse_address_option(struct pnp_option *option, struct acpi_resource *r)
489 struct acpi_resource_address64 addr, *p = &addr;
491 struct pnp_mem * mem;
492 struct pnp_port * port;
494 status = acpi_resource_to_address64(r, p);
495 if (!ACPI_SUCCESS(status)) {
496 pnp_warn("PnPACPI: failed to convert resource type %d", r->type);
500 if (p->address_length == 0)
503 if (p->resource_type == ACPI_MEMORY_RANGE) {
504 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
507 mem->min = mem->max = p->minimum;
508 mem->size = p->address_length;
510 mem->flags = (p->info.mem.write_protect ==
511 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE : 0;
512 pnp_register_mem_resource(option,mem);
513 } else if (p->resource_type == ACPI_IO_RANGE) {
514 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
517 port->min = port->max = p->minimum;
518 port->size = p->address_length;
520 port->flags = PNP_PORT_FLAG_FIXED;
521 pnp_register_port_resource(option,port);
525 struct acpipnp_parse_option_s {
526 struct pnp_option *option;
527 struct pnp_option *option_independent;
531 static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
535 struct acpipnp_parse_option_s *parse_data = (struct acpipnp_parse_option_s *)data;
536 struct pnp_dev *dev = parse_data->dev;
537 struct pnp_option *option = parse_data->option;
540 case ACPI_RESOURCE_TYPE_IRQ:
541 pnpacpi_parse_irq_option(option, &res->data.irq);
544 case ACPI_RESOURCE_TYPE_DMA:
545 pnpacpi_parse_dma_option(option, &res->data.dma);
548 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
549 switch (res->data.start_dpf.compatibility_priority) {
550 case ACPI_GOOD_CONFIGURATION:
551 priority = PNP_RES_PRIORITY_PREFERRED;
554 case ACPI_ACCEPTABLE_CONFIGURATION:
555 priority = PNP_RES_PRIORITY_ACCEPTABLE;
558 case ACPI_SUB_OPTIMAL_CONFIGURATION:
559 priority = PNP_RES_PRIORITY_FUNCTIONAL;
562 priority = PNP_RES_PRIORITY_INVALID;
565 /* TBD: Considering performace/robustness bits */
566 option = pnp_register_dependent_option(dev, priority);
569 parse_data->option = option;
572 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
573 /*only one EndDependentFn is allowed*/
574 if (!parse_data->option_independent) {
575 pnp_warn("PnPACPI: more than one EndDependentFn");
578 parse_data->option = parse_data->option_independent;
579 parse_data->option_independent = NULL;
582 case ACPI_RESOURCE_TYPE_IO:
583 pnpacpi_parse_port_option(option, &res->data.io);
586 case ACPI_RESOURCE_TYPE_FIXED_IO:
587 pnpacpi_parse_fixed_port_option(option,
588 &res->data.fixed_io);
591 case ACPI_RESOURCE_TYPE_VENDOR:
592 case ACPI_RESOURCE_TYPE_END_TAG:
595 case ACPI_RESOURCE_TYPE_MEMORY24:
596 pnpacpi_parse_mem24_option(option, &res->data.memory24);
599 case ACPI_RESOURCE_TYPE_MEMORY32:
600 pnpacpi_parse_mem32_option(option, &res->data.memory32);
603 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
604 pnpacpi_parse_fixed_mem32_option(option,
605 &res->data.fixed_memory32);
608 case ACPI_RESOURCE_TYPE_ADDRESS16:
609 case ACPI_RESOURCE_TYPE_ADDRESS32:
610 case ACPI_RESOURCE_TYPE_ADDRESS64:
611 pnpacpi_parse_address_option(option, res);
614 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
617 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
618 pnpacpi_parse_ext_irq_option(option,
619 &res->data.extended_irq);
622 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
626 pnp_warn("PnPACPI: unknown resource type %d", res->type);
633 acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
637 struct acpipnp_parse_option_s parse_data;
639 parse_data.option = pnp_register_independent_option(dev);
640 if (!parse_data.option)
642 parse_data.option_independent = parse_data.option;
643 parse_data.dev = dev;
644 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
645 pnpacpi_option_resource, &parse_data);
653 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
656 int *res_cnt = (int *)data;
658 case ACPI_RESOURCE_TYPE_IRQ:
659 case ACPI_RESOURCE_TYPE_DMA:
660 case ACPI_RESOURCE_TYPE_IO:
661 case ACPI_RESOURCE_TYPE_FIXED_IO:
662 case ACPI_RESOURCE_TYPE_MEMORY24:
663 case ACPI_RESOURCE_TYPE_MEMORY32:
664 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
665 case ACPI_RESOURCE_TYPE_ADDRESS16:
666 case ACPI_RESOURCE_TYPE_ADDRESS32:
667 case ACPI_RESOURCE_TYPE_ADDRESS64:
668 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
670 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
671 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
672 case ACPI_RESOURCE_TYPE_VENDOR:
673 case ACPI_RESOURCE_TYPE_END_TAG:
674 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
681 static acpi_status pnpacpi_type_resources(struct acpi_resource *res,
684 struct acpi_resource **resource = (struct acpi_resource **)data;
686 case ACPI_RESOURCE_TYPE_IRQ:
687 case ACPI_RESOURCE_TYPE_DMA:
688 case ACPI_RESOURCE_TYPE_IO:
689 case ACPI_RESOURCE_TYPE_FIXED_IO:
690 case ACPI_RESOURCE_TYPE_MEMORY24:
691 case ACPI_RESOURCE_TYPE_MEMORY32:
692 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
693 case ACPI_RESOURCE_TYPE_ADDRESS16:
694 case ACPI_RESOURCE_TYPE_ADDRESS32:
695 case ACPI_RESOURCE_TYPE_ADDRESS64:
696 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
697 (*resource)->type = res->type;
699 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
700 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
701 case ACPI_RESOURCE_TYPE_VENDOR:
702 case ACPI_RESOURCE_TYPE_END_TAG:
703 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
711 int pnpacpi_build_resource_template(acpi_handle handle,
712 struct acpi_buffer *buffer)
714 struct acpi_resource *resource;
718 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
719 pnpacpi_count_resources, &res_cnt);
720 if (ACPI_FAILURE(status)) {
721 pnp_err("Evaluate _CRS failed");
726 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
727 buffer->pointer = kcalloc(1, buffer->length - 1, GFP_KERNEL);
728 if (!buffer->pointer)
730 pnp_dbg("Res cnt %d", res_cnt);
731 resource = (struct acpi_resource *)buffer->pointer;
732 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
733 pnpacpi_type_resources, &resource);
734 if (ACPI_FAILURE(status)) {
735 kfree(buffer->pointer);
736 pnp_err("Evaluate _CRS failed");
739 /* resource will pointer the end resource now */
740 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
745 static void pnpacpi_encode_irq(struct acpi_resource *resource,
748 int triggering, polarity;
750 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering,
752 resource->type = ACPI_RESOURCE_TYPE_IRQ;
753 resource->length = sizeof(struct acpi_resource);
754 resource->data.irq.triggering = triggering;
755 resource->data.irq.polarity = polarity;
756 if (triggering == ACPI_EDGE_SENSITIVE)
757 resource->data.irq.sharable = ACPI_EXCLUSIVE;
759 resource->data.irq.sharable = ACPI_SHARED;
760 resource->data.irq.interrupt_count = 1;
761 resource->data.irq.interrupts[0] = p->start;
764 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
767 int triggering, polarity;
769 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering,
771 resource->type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
772 resource->length = sizeof(struct acpi_resource);
773 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
774 resource->data.extended_irq.triggering = triggering;
775 resource->data.extended_irq.polarity = polarity;
776 if (triggering == ACPI_EDGE_SENSITIVE)
777 resource->data.irq.sharable = ACPI_EXCLUSIVE;
779 resource->data.irq.sharable = ACPI_SHARED;
780 resource->data.extended_irq.interrupt_count = 1;
781 resource->data.extended_irq.interrupts[0] = p->start;
784 static void pnpacpi_encode_dma(struct acpi_resource *resource,
787 resource->type = ACPI_RESOURCE_TYPE_DMA;
788 resource->length = sizeof(struct acpi_resource);
789 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
790 if (p->flags & IORESOURCE_DMA_COMPATIBLE)
791 resource->data.dma.type = ACPI_COMPATIBILITY;
792 else if (p->flags & IORESOURCE_DMA_TYPEA)
793 resource->data.dma.type = ACPI_TYPE_A;
794 else if (p->flags & IORESOURCE_DMA_TYPEB)
795 resource->data.dma.type = ACPI_TYPE_B;
796 else if (p->flags & IORESOURCE_DMA_TYPEF)
797 resource->data.dma.type = ACPI_TYPE_F;
798 if (p->flags & IORESOURCE_DMA_8BIT)
799 resource->data.dma.transfer = ACPI_TRANSFER_8;
800 else if (p->flags & IORESOURCE_DMA_8AND16BIT)
801 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
802 else if (p->flags & IORESOURCE_DMA_16BIT)
803 resource->data.dma.transfer = ACPI_TRANSFER_16;
804 resource->data.dma.bus_master = p->flags & IORESOURCE_DMA_MASTER;
805 resource->data.dma.channel_count = 1;
806 resource->data.dma.channels[0] = p->start;
809 static void pnpacpi_encode_io(struct acpi_resource *resource,
812 resource->type = ACPI_RESOURCE_TYPE_IO;
813 resource->length = sizeof(struct acpi_resource);
814 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
815 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR)?
816 ACPI_DECODE_16 : ACPI_DECODE_10;
817 resource->data.io.minimum = p->start;
818 resource->data.io.maximum = p->end;
819 resource->data.io.alignment = 0; /* Correct? */
820 resource->data.io.address_length = p->end - p->start + 1;
823 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
826 resource->type = ACPI_RESOURCE_TYPE_FIXED_IO;
827 resource->length = sizeof(struct acpi_resource);
828 resource->data.fixed_io.address = p->start;
829 resource->data.fixed_io.address_length = p->end - p->start + 1;
832 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
835 resource->type = ACPI_RESOURCE_TYPE_MEMORY24;
836 resource->length = sizeof(struct acpi_resource);
837 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
838 resource->data.memory24.write_protect =
839 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
840 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
841 resource->data.memory24.minimum = p->start;
842 resource->data.memory24.maximum = p->end;
843 resource->data.memory24.alignment = 0;
844 resource->data.memory24.address_length = p->end - p->start + 1;
847 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
850 resource->type = ACPI_RESOURCE_TYPE_MEMORY32;
851 resource->length = sizeof(struct acpi_resource);
852 resource->data.memory32.write_protect =
853 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
854 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
855 resource->data.memory32.minimum = p->start;
856 resource->data.memory32.maximum = p->end;
857 resource->data.memory32.alignment = 0;
858 resource->data.memory32.address_length = p->end - p->start + 1;
861 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
864 resource->type = ACPI_RESOURCE_TYPE_FIXED_MEMORY32;
865 resource->length = sizeof(struct acpi_resource);
866 resource->data.fixed_memory32.write_protect =
867 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
868 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
869 resource->data.fixed_memory32.address = p->start;
870 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
873 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
874 struct acpi_buffer *buffer)
877 /* pnpacpi_build_resource_template allocates extra mem */
878 int res_cnt = (buffer->length - 1)/sizeof(struct acpi_resource) - 1;
879 struct acpi_resource *resource = (struct acpi_resource*)buffer->pointer;
880 int port = 0, irq = 0, dma = 0, mem = 0;
882 pnp_dbg("res cnt %d", res_cnt);
883 while (i < res_cnt) {
884 switch(resource->type) {
885 case ACPI_RESOURCE_TYPE_IRQ:
886 pnp_dbg("Encode irq");
887 pnpacpi_encode_irq(resource,
888 &res_table->irq_resource[irq]);
892 case ACPI_RESOURCE_TYPE_DMA:
893 pnp_dbg("Encode dma");
894 pnpacpi_encode_dma(resource,
895 &res_table->dma_resource[dma]);
898 case ACPI_RESOURCE_TYPE_IO:
899 pnp_dbg("Encode io");
900 pnpacpi_encode_io(resource,
901 &res_table->port_resource[port]);
904 case ACPI_RESOURCE_TYPE_FIXED_IO:
905 pnp_dbg("Encode fixed io");
906 pnpacpi_encode_fixed_io(resource,
907 &res_table->port_resource[port]);
910 case ACPI_RESOURCE_TYPE_MEMORY24:
911 pnp_dbg("Encode mem24");
912 pnpacpi_encode_mem24(resource,
913 &res_table->mem_resource[mem]);
916 case ACPI_RESOURCE_TYPE_MEMORY32:
917 pnp_dbg("Encode mem32");
918 pnpacpi_encode_mem32(resource,
919 &res_table->mem_resource[mem]);
922 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
923 pnp_dbg("Encode fixed mem32");
924 pnpacpi_encode_fixed_mem32(resource,
925 &res_table->mem_resource[mem]);
928 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
929 pnp_dbg("Encode ext irq");
930 pnpacpi_encode_ext_irq(resource,
931 &res_table->irq_resource[irq]);
934 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
935 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
936 case ACPI_RESOURCE_TYPE_VENDOR:
937 case ACPI_RESOURCE_TYPE_END_TAG:
938 case ACPI_RESOURCE_TYPE_ADDRESS16:
939 case ACPI_RESOURCE_TYPE_ADDRESS32:
940 case ACPI_RESOURCE_TYPE_ADDRESS64:
941 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
942 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
943 default: /* other type */
944 pnp_warn("unknown resource type %d", resource->type);