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, int shareable)
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;
99 res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
101 res->irq_resource[i].start = irq;
102 res->irq_resource[i].end = irq;
103 pcibios_penalize_isa_irq(irq, 1);
107 pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, u32 dma)
110 while (i < PNP_MAX_DMA &&
111 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
113 if (i < PNP_MAX_DMA) {
114 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
116 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
119 res->dma_resource[i].start = dma;
120 res->dma_resource[i].end = dma;
125 pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
129 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
132 if (i < PNP_MAX_PORT) {
133 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
134 if (len <= 0 || (io + len -1) >= 0x10003) {
135 res->port_resource[i].flags |= IORESOURCE_DISABLED;
138 res->port_resource[i].start = io;
139 res->port_resource[i].end = io + len - 1;
144 pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
148 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
151 if (i < PNP_MAX_MEM) {
152 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
154 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
157 res->mem_resource[i].start = mem;
158 res->mem_resource[i].end = mem + len - 1;
163 pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
164 struct acpi_resource *res)
166 struct acpi_resource_address64 addr, *p = &addr;
169 status = acpi_resource_to_address64(res, p);
170 if (!ACPI_SUCCESS(status)) {
171 pnp_warn("PnPACPI: failed to convert resource type %d",
176 if (p->producer_consumer == ACPI_PRODUCER)
179 if (p->resource_type == ACPI_MEMORY_RANGE)
180 pnpacpi_parse_allocated_memresource(res_table,
181 p->minimum, p->address_length);
182 else if (p->resource_type == ACPI_IO_RANGE)
183 pnpacpi_parse_allocated_ioresource(res_table,
184 p->minimum, p->address_length);
187 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
190 struct pnp_resource_table *res_table = (struct pnp_resource_table *)data;
194 case ACPI_RESOURCE_TYPE_IRQ:
196 * Per spec, only one interrupt per descriptor is allowed in
197 * _CRS, but some firmware violates this, so parse them all.
199 for (i = 0; i < res->data.irq.interrupt_count; i++) {
200 pnpacpi_parse_allocated_irqresource(res_table,
201 res->data.irq.interrupts[i],
202 res->data.irq.triggering,
203 res->data.irq.polarity,
204 res->data.irq.sharable);
208 case ACPI_RESOURCE_TYPE_DMA:
209 if (res->data.dma.channel_count > 0)
210 pnpacpi_parse_allocated_dmaresource(res_table,
211 res->data.dma.channels[0]);
214 case ACPI_RESOURCE_TYPE_IO:
215 pnpacpi_parse_allocated_ioresource(res_table,
216 res->data.io.minimum,
217 res->data.io.address_length);
220 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
221 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
224 case ACPI_RESOURCE_TYPE_FIXED_IO:
225 pnpacpi_parse_allocated_ioresource(res_table,
226 res->data.fixed_io.address,
227 res->data.fixed_io.address_length);
230 case ACPI_RESOURCE_TYPE_VENDOR:
233 case ACPI_RESOURCE_TYPE_END_TAG:
236 case ACPI_RESOURCE_TYPE_MEMORY24:
237 pnpacpi_parse_allocated_memresource(res_table,
238 res->data.memory24.minimum,
239 res->data.memory24.address_length);
241 case ACPI_RESOURCE_TYPE_MEMORY32:
242 pnpacpi_parse_allocated_memresource(res_table,
243 res->data.memory32.minimum,
244 res->data.memory32.address_length);
246 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
247 pnpacpi_parse_allocated_memresource(res_table,
248 res->data.fixed_memory32.address,
249 res->data.fixed_memory32.address_length);
251 case ACPI_RESOURCE_TYPE_ADDRESS16:
252 case ACPI_RESOURCE_TYPE_ADDRESS32:
253 case ACPI_RESOURCE_TYPE_ADDRESS64:
254 pnpacpi_parse_allocated_address_space(res_table, res);
257 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
258 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
262 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
263 if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
266 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
267 pnpacpi_parse_allocated_irqresource(res_table,
268 res->data.extended_irq.interrupts[i],
269 res->data.extended_irq.triggering,
270 res->data.extended_irq.polarity,
271 res->data.extended_irq.sharable);
275 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
279 pnp_warn("PnPACPI: unknown resource type %d", res->type);
286 acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle, struct pnp_resource_table *res)
288 /* Blank the resource table values */
289 pnp_init_resource_table(res);
291 return acpi_walk_resources(handle, METHOD_NAME__CRS, pnpacpi_allocated_resource, res);
294 static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_resource_dma *p)
297 struct pnp_dma * dma;
299 if (p->channel_count == 0)
301 dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL);
305 for(i = 0; i < p->channel_count; i++)
306 dma->map |= 1 << p->channels[i];
309 dma->flags |= IORESOURCE_DMA_MASTER;
311 case ACPI_COMPATIBILITY:
312 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
315 dma->flags |= IORESOURCE_DMA_TYPEA;
318 dma->flags |= IORESOURCE_DMA_TYPEB;
321 dma->flags |= IORESOURCE_DMA_TYPEF;
324 /* Set a default value ? */
325 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
326 pnp_err("Invalid DMA type");
328 switch (p->transfer) {
329 case ACPI_TRANSFER_8:
330 dma->flags |= IORESOURCE_DMA_8BIT;
332 case ACPI_TRANSFER_8_16:
333 dma->flags |= IORESOURCE_DMA_8AND16BIT;
335 case ACPI_TRANSFER_16:
336 dma->flags |= IORESOURCE_DMA_16BIT;
339 /* Set a default value ? */
340 dma->flags |= IORESOURCE_DMA_8AND16BIT;
341 pnp_err("Invalid DMA transfer type");
344 pnp_register_dma_resource(option, dma);
349 static void pnpacpi_parse_irq_option(struct pnp_option *option,
350 struct acpi_resource_irq *p)
355 if (p->interrupt_count == 0)
357 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
361 for(i = 0; i < p->interrupt_count; i++)
362 if (p->interrupts[i])
363 __set_bit(p->interrupts[i], irq->map);
364 irq->flags = irq_flags(p->triggering, p->polarity);
366 pnp_register_irq_resource(option, irq);
370 static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
371 struct acpi_resource_extended_irq *p)
376 if (p->interrupt_count == 0)
378 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
382 for(i = 0; i < p->interrupt_count; i++)
383 if (p->interrupts[i])
384 __set_bit(p->interrupts[i], irq->map);
385 irq->flags = irq_flags(p->triggering, p->polarity);
387 pnp_register_irq_resource(option, irq);
392 pnpacpi_parse_port_option(struct pnp_option *option,
393 struct acpi_resource_io *io)
395 struct pnp_port *port;
397 if (io->address_length == 0)
399 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
402 port->min = io->minimum;
403 port->max = io->maximum;
404 port->align = io->alignment;
405 port->size = io->address_length;
406 port->flags = ACPI_DECODE_16 == io->io_decode ?
407 PNP_PORT_FLAG_16BITADDR : 0;
408 pnp_register_port_resource(option, port);
413 pnpacpi_parse_fixed_port_option(struct pnp_option *option,
414 struct acpi_resource_fixed_io *io)
416 struct pnp_port *port;
418 if (io->address_length == 0)
420 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
423 port->min = port->max = io->address;
424 port->size = io->address_length;
426 port->flags = PNP_PORT_FLAG_FIXED;
427 pnp_register_port_resource(option, port);
432 pnpacpi_parse_mem24_option(struct pnp_option *option,
433 struct acpi_resource_memory24 *p)
437 if (p->address_length == 0)
439 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
442 mem->min = p->minimum;
443 mem->max = p->maximum;
444 mem->align = p->alignment;
445 mem->size = p->address_length;
447 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
448 IORESOURCE_MEM_WRITEABLE : 0;
450 pnp_register_mem_resource(option, mem);
455 pnpacpi_parse_mem32_option(struct pnp_option *option,
456 struct acpi_resource_memory32 *p)
460 if (p->address_length == 0)
462 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
465 mem->min = p->minimum;
466 mem->max = p->maximum;
467 mem->align = p->alignment;
468 mem->size = p->address_length;
470 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
471 IORESOURCE_MEM_WRITEABLE : 0;
473 pnp_register_mem_resource(option, mem);
478 pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
479 struct acpi_resource_fixed_memory32 *p)
483 if (p->address_length == 0)
485 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
488 mem->min = mem->max = p->address;
489 mem->size = p->address_length;
492 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
493 IORESOURCE_MEM_WRITEABLE : 0;
495 pnp_register_mem_resource(option, mem);
500 pnpacpi_parse_address_option(struct pnp_option *option, struct acpi_resource *r)
502 struct acpi_resource_address64 addr, *p = &addr;
505 struct pnp_port *port;
507 status = acpi_resource_to_address64(r, p);
508 if (!ACPI_SUCCESS(status)) {
509 pnp_warn("PnPACPI: failed to convert resource type %d", r->type);
513 if (p->address_length == 0)
516 if (p->resource_type == ACPI_MEMORY_RANGE) {
517 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
520 mem->min = mem->max = p->minimum;
521 mem->size = p->address_length;
523 mem->flags = (p->info.mem.write_protect ==
524 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE : 0;
525 pnp_register_mem_resource(option, mem);
526 } else if (p->resource_type == ACPI_IO_RANGE) {
527 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
530 port->min = port->max = p->minimum;
531 port->size = p->address_length;
533 port->flags = PNP_PORT_FLAG_FIXED;
534 pnp_register_port_resource(option, port);
538 struct acpipnp_parse_option_s {
539 struct pnp_option *option;
540 struct pnp_option *option_independent;
544 static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
548 struct acpipnp_parse_option_s *parse_data = (struct acpipnp_parse_option_s *)data;
549 struct pnp_dev *dev = parse_data->dev;
550 struct pnp_option *option = parse_data->option;
553 case ACPI_RESOURCE_TYPE_IRQ:
554 pnpacpi_parse_irq_option(option, &res->data.irq);
557 case ACPI_RESOURCE_TYPE_DMA:
558 pnpacpi_parse_dma_option(option, &res->data.dma);
561 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
562 switch (res->data.start_dpf.compatibility_priority) {
563 case ACPI_GOOD_CONFIGURATION:
564 priority = PNP_RES_PRIORITY_PREFERRED;
567 case ACPI_ACCEPTABLE_CONFIGURATION:
568 priority = PNP_RES_PRIORITY_ACCEPTABLE;
571 case ACPI_SUB_OPTIMAL_CONFIGURATION:
572 priority = PNP_RES_PRIORITY_FUNCTIONAL;
575 priority = PNP_RES_PRIORITY_INVALID;
578 /* TBD: Considering performace/robustness bits */
579 option = pnp_register_dependent_option(dev, priority);
582 parse_data->option = option;
585 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
586 /*only one EndDependentFn is allowed*/
587 if (!parse_data->option_independent) {
588 pnp_warn("PnPACPI: more than one EndDependentFn");
591 parse_data->option = parse_data->option_independent;
592 parse_data->option_independent = NULL;
595 case ACPI_RESOURCE_TYPE_IO:
596 pnpacpi_parse_port_option(option, &res->data.io);
599 case ACPI_RESOURCE_TYPE_FIXED_IO:
600 pnpacpi_parse_fixed_port_option(option,
601 &res->data.fixed_io);
604 case ACPI_RESOURCE_TYPE_VENDOR:
605 case ACPI_RESOURCE_TYPE_END_TAG:
608 case ACPI_RESOURCE_TYPE_MEMORY24:
609 pnpacpi_parse_mem24_option(option, &res->data.memory24);
612 case ACPI_RESOURCE_TYPE_MEMORY32:
613 pnpacpi_parse_mem32_option(option, &res->data.memory32);
616 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
617 pnpacpi_parse_fixed_mem32_option(option,
618 &res->data.fixed_memory32);
621 case ACPI_RESOURCE_TYPE_ADDRESS16:
622 case ACPI_RESOURCE_TYPE_ADDRESS32:
623 case ACPI_RESOURCE_TYPE_ADDRESS64:
624 pnpacpi_parse_address_option(option, res);
627 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
630 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
631 pnpacpi_parse_ext_irq_option(option,
632 &res->data.extended_irq);
635 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
639 pnp_warn("PnPACPI: unknown resource type %d", res->type);
646 acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
650 struct acpipnp_parse_option_s parse_data;
652 parse_data.option = pnp_register_independent_option(dev);
653 if (!parse_data.option)
655 parse_data.option_independent = parse_data.option;
656 parse_data.dev = dev;
657 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
658 pnpacpi_option_resource, &parse_data);
663 static int pnpacpi_supported_resource(struct acpi_resource *res)
666 case ACPI_RESOURCE_TYPE_IRQ:
667 case ACPI_RESOURCE_TYPE_DMA:
668 case ACPI_RESOURCE_TYPE_IO:
669 case ACPI_RESOURCE_TYPE_FIXED_IO:
670 case ACPI_RESOURCE_TYPE_MEMORY24:
671 case ACPI_RESOURCE_TYPE_MEMORY32:
672 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
673 case ACPI_RESOURCE_TYPE_ADDRESS16:
674 case ACPI_RESOURCE_TYPE_ADDRESS32:
675 case ACPI_RESOURCE_TYPE_ADDRESS64:
676 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
685 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
688 int *res_cnt = (int *)data;
690 if (pnpacpi_supported_resource(res))
695 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
697 struct acpi_resource **resource = (struct acpi_resource **)data;
699 if (pnpacpi_supported_resource(res)) {
700 (*resource)->type = res->type;
701 (*resource)->length = sizeof(struct acpi_resource);
708 int pnpacpi_build_resource_template(acpi_handle handle,
709 struct acpi_buffer *buffer)
711 struct acpi_resource *resource;
715 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
716 pnpacpi_count_resources, &res_cnt);
717 if (ACPI_FAILURE(status)) {
718 pnp_err("Evaluate _CRS failed");
723 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
724 buffer->pointer = kcalloc(1, buffer->length - 1, GFP_KERNEL);
725 if (!buffer->pointer)
727 pnp_dbg("Res cnt %d", res_cnt);
728 resource = (struct acpi_resource *)buffer->pointer;
729 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
730 pnpacpi_type_resources, &resource);
731 if (ACPI_FAILURE(status)) {
732 kfree(buffer->pointer);
733 pnp_err("Evaluate _CRS failed");
736 /* resource will pointer the end resource now */
737 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
742 static void pnpacpi_encode_irq(struct acpi_resource *resource,
745 int triggering, polarity;
747 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
748 resource->data.irq.triggering = triggering;
749 resource->data.irq.polarity = polarity;
750 if (triggering == ACPI_EDGE_SENSITIVE)
751 resource->data.irq.sharable = ACPI_EXCLUSIVE;
753 resource->data.irq.sharable = ACPI_SHARED;
754 resource->data.irq.interrupt_count = 1;
755 resource->data.irq.interrupts[0] = p->start;
758 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
761 int triggering, polarity;
763 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
764 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
765 resource->data.extended_irq.triggering = triggering;
766 resource->data.extended_irq.polarity = polarity;
767 if (triggering == ACPI_EDGE_SENSITIVE)
768 resource->data.irq.sharable = ACPI_EXCLUSIVE;
770 resource->data.irq.sharable = ACPI_SHARED;
771 resource->data.extended_irq.interrupt_count = 1;
772 resource->data.extended_irq.interrupts[0] = p->start;
775 static void pnpacpi_encode_dma(struct acpi_resource *resource,
778 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
779 if (p->flags & IORESOURCE_DMA_COMPATIBLE)
780 resource->data.dma.type = ACPI_COMPATIBILITY;
781 else if (p->flags & IORESOURCE_DMA_TYPEA)
782 resource->data.dma.type = ACPI_TYPE_A;
783 else if (p->flags & IORESOURCE_DMA_TYPEB)
784 resource->data.dma.type = ACPI_TYPE_B;
785 else if (p->flags & IORESOURCE_DMA_TYPEF)
786 resource->data.dma.type = ACPI_TYPE_F;
787 if (p->flags & IORESOURCE_DMA_8BIT)
788 resource->data.dma.transfer = ACPI_TRANSFER_8;
789 else if (p->flags & IORESOURCE_DMA_8AND16BIT)
790 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
791 else if (p->flags & IORESOURCE_DMA_16BIT)
792 resource->data.dma.transfer = ACPI_TRANSFER_16;
793 resource->data.dma.bus_master = p->flags & IORESOURCE_DMA_MASTER;
794 resource->data.dma.channel_count = 1;
795 resource->data.dma.channels[0] = p->start;
798 static void pnpacpi_encode_io(struct acpi_resource *resource,
801 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
802 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR)?
803 ACPI_DECODE_16 : ACPI_DECODE_10;
804 resource->data.io.minimum = p->start;
805 resource->data.io.maximum = p->end;
806 resource->data.io.alignment = 0; /* Correct? */
807 resource->data.io.address_length = p->end - p->start + 1;
810 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
813 resource->data.fixed_io.address = p->start;
814 resource->data.fixed_io.address_length = p->end - p->start + 1;
817 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
820 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
821 resource->data.memory24.write_protect =
822 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
823 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
824 resource->data.memory24.minimum = p->start;
825 resource->data.memory24.maximum = p->end;
826 resource->data.memory24.alignment = 0;
827 resource->data.memory24.address_length = p->end - p->start + 1;
830 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
833 resource->data.memory32.write_protect =
834 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
835 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
836 resource->data.memory32.minimum = p->start;
837 resource->data.memory32.maximum = p->end;
838 resource->data.memory32.alignment = 0;
839 resource->data.memory32.address_length = p->end - p->start + 1;
842 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
845 resource->data.fixed_memory32.write_protect =
846 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
847 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
848 resource->data.fixed_memory32.address = p->start;
849 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
852 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
853 struct acpi_buffer *buffer)
856 /* pnpacpi_build_resource_template allocates extra mem */
857 int res_cnt = (buffer->length - 1)/sizeof(struct acpi_resource) - 1;
858 struct acpi_resource *resource = (struct acpi_resource*)buffer->pointer;
859 int port = 0, irq = 0, dma = 0, mem = 0;
861 pnp_dbg("res cnt %d", res_cnt);
862 while (i < res_cnt) {
863 switch(resource->type) {
864 case ACPI_RESOURCE_TYPE_IRQ:
865 pnp_dbg("Encode irq");
866 pnpacpi_encode_irq(resource,
867 &res_table->irq_resource[irq]);
871 case ACPI_RESOURCE_TYPE_DMA:
872 pnp_dbg("Encode dma");
873 pnpacpi_encode_dma(resource,
874 &res_table->dma_resource[dma]);
877 case ACPI_RESOURCE_TYPE_IO:
878 pnp_dbg("Encode io");
879 pnpacpi_encode_io(resource,
880 &res_table->port_resource[port]);
883 case ACPI_RESOURCE_TYPE_FIXED_IO:
884 pnp_dbg("Encode fixed io");
885 pnpacpi_encode_fixed_io(resource,
886 &res_table->port_resource[port]);
889 case ACPI_RESOURCE_TYPE_MEMORY24:
890 pnp_dbg("Encode mem24");
891 pnpacpi_encode_mem24(resource,
892 &res_table->mem_resource[mem]);
895 case ACPI_RESOURCE_TYPE_MEMORY32:
896 pnp_dbg("Encode mem32");
897 pnpacpi_encode_mem32(resource,
898 &res_table->mem_resource[mem]);
901 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
902 pnp_dbg("Encode fixed mem32");
903 pnpacpi_encode_fixed_mem32(resource,
904 &res_table->mem_resource[mem]);
907 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
908 pnp_dbg("Encode ext irq");
909 pnpacpi_encode_ext_irq(resource,
910 &res_table->irq_resource[irq]);
913 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
914 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
915 case ACPI_RESOURCE_TYPE_VENDOR:
916 case ACPI_RESOURCE_TYPE_END_TAG:
917 case ACPI_RESOURCE_TYPE_ADDRESS16:
918 case ACPI_RESOURCE_TYPE_ADDRESS32:
919 case ACPI_RESOURCE_TYPE_ADDRESS64:
920 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
921 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
922 default: /* other type */
923 pnp_warn("unknown resource type %d", resource->type);