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)
83 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
90 * in IO-APIC mode, use overrided attribute. Two reasons:
92 * 2. BIOS uses IO-APIC mode Interrupt Source Override
94 if (!acpi_get_override_irq(gsi, &t, &p)) {
95 t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
96 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
98 if (triggering != t || polarity != p) {
99 pnp_warn("IRQ %d override to %s, %s",
100 gsi, t ? "edge":"level", p ? "low":"high");
106 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
107 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
108 irq = acpi_register_gsi(gsi, triggering, polarity);
110 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
115 res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
117 res->irq_resource[i].start = irq;
118 res->irq_resource[i].end = irq;
119 pcibios_penalize_isa_irq(irq, 1);
122 static int dma_flags(int type, int bus_master, int transfer)
127 flags |= IORESOURCE_DMA_MASTER;
129 case ACPI_COMPATIBILITY:
130 flags |= IORESOURCE_DMA_COMPATIBLE;
133 flags |= IORESOURCE_DMA_TYPEA;
136 flags |= IORESOURCE_DMA_TYPEB;
139 flags |= IORESOURCE_DMA_TYPEF;
142 /* Set a default value ? */
143 flags |= IORESOURCE_DMA_COMPATIBLE;
144 pnp_err("Invalid DMA type");
147 case ACPI_TRANSFER_8:
148 flags |= IORESOURCE_DMA_8BIT;
150 case ACPI_TRANSFER_8_16:
151 flags |= IORESOURCE_DMA_8AND16BIT;
153 case ACPI_TRANSFER_16:
154 flags |= IORESOURCE_DMA_16BIT;
157 /* Set a default value ? */
158 flags |= IORESOURCE_DMA_8AND16BIT;
159 pnp_err("Invalid DMA transfer type");
165 static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
167 int bus_master, int transfer)
171 while (i < PNP_MAX_DMA &&
172 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
174 if (i < PNP_MAX_DMA) {
175 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
176 res->dma_resource[i].flags |=
177 dma_flags(type, bus_master, transfer);
179 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
182 res->dma_resource[i].start = dma;
183 res->dma_resource[i].end = dma;
187 static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
188 u64 io, u64 len, int io_decode)
192 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
195 if (i < PNP_MAX_PORT) {
196 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
197 if (io_decode == ACPI_DECODE_16)
198 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
199 if (len <= 0 || (io + len - 1) >= 0x10003) {
200 res->port_resource[i].flags |= IORESOURCE_DISABLED;
203 res->port_resource[i].start = io;
204 res->port_resource[i].end = io + len - 1;
208 static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
214 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
217 if (i < PNP_MAX_MEM) {
218 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
220 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
223 if (write_protect == ACPI_READ_WRITE_MEMORY)
224 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
226 res->mem_resource[i].start = mem;
227 res->mem_resource[i].end = mem + len - 1;
231 static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
232 struct acpi_resource *res)
234 struct acpi_resource_address64 addr, *p = &addr;
237 status = acpi_resource_to_address64(res, p);
238 if (!ACPI_SUCCESS(status)) {
239 pnp_warn("PnPACPI: failed to convert resource type %d",
244 if (p->producer_consumer == ACPI_PRODUCER)
247 if (p->resource_type == ACPI_MEMORY_RANGE)
248 pnpacpi_parse_allocated_memresource(res_table,
249 p->minimum, p->address_length,
250 p->info.mem.write_protect);
251 else if (p->resource_type == ACPI_IO_RANGE)
252 pnpacpi_parse_allocated_ioresource(res_table,
253 p->minimum, p->address_length,
254 p->granularity == 0xfff ? ACPI_DECODE_10 :
258 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
261 struct pnp_resource_table *res_table = data;
265 case ACPI_RESOURCE_TYPE_IRQ:
267 * Per spec, only one interrupt per descriptor is allowed in
268 * _CRS, but some firmware violates this, so parse them all.
270 for (i = 0; i < res->data.irq.interrupt_count; i++) {
271 pnpacpi_parse_allocated_irqresource(res_table,
272 res->data.irq.interrupts[i],
273 res->data.irq.triggering,
274 res->data.irq.polarity,
275 res->data.irq.sharable);
279 case ACPI_RESOURCE_TYPE_DMA:
280 if (res->data.dma.channel_count > 0)
281 pnpacpi_parse_allocated_dmaresource(res_table,
282 res->data.dma.channels[0],
284 res->data.dma.bus_master,
285 res->data.dma.transfer);
288 case ACPI_RESOURCE_TYPE_IO:
289 pnpacpi_parse_allocated_ioresource(res_table,
290 res->data.io.minimum,
291 res->data.io.address_length,
292 res->data.io.io_decode);
295 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
296 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
299 case ACPI_RESOURCE_TYPE_FIXED_IO:
300 pnpacpi_parse_allocated_ioresource(res_table,
301 res->data.fixed_io.address,
302 res->data.fixed_io.address_length,
306 case ACPI_RESOURCE_TYPE_VENDOR:
309 case ACPI_RESOURCE_TYPE_END_TAG:
312 case ACPI_RESOURCE_TYPE_MEMORY24:
313 pnpacpi_parse_allocated_memresource(res_table,
314 res->data.memory24.minimum,
315 res->data.memory24.address_length,
316 res->data.memory24.write_protect);
318 case ACPI_RESOURCE_TYPE_MEMORY32:
319 pnpacpi_parse_allocated_memresource(res_table,
320 res->data.memory32.minimum,
321 res->data.memory32.address_length,
322 res->data.memory32.write_protect);
324 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
325 pnpacpi_parse_allocated_memresource(res_table,
326 res->data.fixed_memory32.address,
327 res->data.fixed_memory32.address_length,
328 res->data.fixed_memory32.write_protect);
330 case ACPI_RESOURCE_TYPE_ADDRESS16:
331 case ACPI_RESOURCE_TYPE_ADDRESS32:
332 case ACPI_RESOURCE_TYPE_ADDRESS64:
333 pnpacpi_parse_allocated_address_space(res_table, res);
336 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
337 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
341 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
342 if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
345 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
346 pnpacpi_parse_allocated_irqresource(res_table,
347 res->data.extended_irq.interrupts[i],
348 res->data.extended_irq.triggering,
349 res->data.extended_irq.polarity,
350 res->data.extended_irq.sharable);
354 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
358 pnp_warn("PnPACPI: unknown resource type %d", res->type);
365 acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
366 struct pnp_resource_table * res)
368 /* Blank the resource table values */
369 pnp_init_resource_table(res);
371 return acpi_walk_resources(handle, METHOD_NAME__CRS,
372 pnpacpi_allocated_resource, res);
375 static void pnpacpi_parse_dma_option(struct pnp_option *option,
376 struct acpi_resource_dma *p)
381 if (p->channel_count == 0)
383 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
387 for (i = 0; i < p->channel_count; i++)
388 dma->map |= 1 << p->channels[i];
390 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
392 pnp_register_dma_resource(option, dma);
395 static void pnpacpi_parse_irq_option(struct pnp_option *option,
396 struct acpi_resource_irq *p)
401 if (p->interrupt_count == 0)
403 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
407 for (i = 0; i < p->interrupt_count; i++)
408 if (p->interrupts[i])
409 __set_bit(p->interrupts[i], irq->map);
410 irq->flags = irq_flags(p->triggering, p->polarity);
412 pnp_register_irq_resource(option, irq);
415 static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
416 struct acpi_resource_extended_irq *p)
421 if (p->interrupt_count == 0)
423 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
427 for (i = 0; i < p->interrupt_count; i++)
428 if (p->interrupts[i])
429 __set_bit(p->interrupts[i], irq->map);
430 irq->flags = irq_flags(p->triggering, p->polarity);
432 pnp_register_irq_resource(option, irq);
435 static void pnpacpi_parse_port_option(struct pnp_option *option,
436 struct acpi_resource_io *io)
438 struct pnp_port *port;
440 if (io->address_length == 0)
442 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
445 port->min = io->minimum;
446 port->max = io->maximum;
447 port->align = io->alignment;
448 port->size = io->address_length;
449 port->flags = ACPI_DECODE_16 == io->io_decode ?
450 PNP_PORT_FLAG_16BITADDR : 0;
451 pnp_register_port_resource(option, port);
454 static void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
455 struct acpi_resource_fixed_io *io)
457 struct pnp_port *port;
459 if (io->address_length == 0)
461 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
464 port->min = port->max = io->address;
465 port->size = io->address_length;
467 port->flags = PNP_PORT_FLAG_FIXED;
468 pnp_register_port_resource(option, port);
471 static void pnpacpi_parse_mem24_option(struct pnp_option *option,
472 struct acpi_resource_memory24 *p)
476 if (p->address_length == 0)
478 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
481 mem->min = p->minimum;
482 mem->max = p->maximum;
483 mem->align = p->alignment;
484 mem->size = p->address_length;
486 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
487 IORESOURCE_MEM_WRITEABLE : 0;
489 pnp_register_mem_resource(option, mem);
492 static void pnpacpi_parse_mem32_option(struct pnp_option *option,
493 struct acpi_resource_memory32 *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 void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
514 struct acpi_resource_fixed_memory32 *p)
518 if (p->address_length == 0)
520 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
523 mem->min = mem->max = p->address;
524 mem->size = p->address_length;
527 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
528 IORESOURCE_MEM_WRITEABLE : 0;
530 pnp_register_mem_resource(option, mem);
533 static void pnpacpi_parse_address_option(struct pnp_option *option,
534 struct acpi_resource *r)
536 struct acpi_resource_address64 addr, *p = &addr;
539 struct pnp_port *port;
541 status = acpi_resource_to_address64(r, p);
542 if (!ACPI_SUCCESS(status)) {
543 pnp_warn("PnPACPI: failed to convert resource type %d",
548 if (p->address_length == 0)
551 if (p->resource_type == ACPI_MEMORY_RANGE) {
552 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
555 mem->min = mem->max = p->minimum;
556 mem->size = p->address_length;
558 mem->flags = (p->info.mem.write_protect ==
559 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
561 pnp_register_mem_resource(option, mem);
562 } else if (p->resource_type == ACPI_IO_RANGE) {
563 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
566 port->min = port->max = p->minimum;
567 port->size = p->address_length;
569 port->flags = PNP_PORT_FLAG_FIXED;
570 pnp_register_port_resource(option, port);
574 struct acpipnp_parse_option_s {
575 struct pnp_option *option;
576 struct pnp_option *option_independent;
580 static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
584 struct acpipnp_parse_option_s *parse_data = data;
585 struct pnp_dev *dev = parse_data->dev;
586 struct pnp_option *option = parse_data->option;
589 case ACPI_RESOURCE_TYPE_IRQ:
590 pnpacpi_parse_irq_option(option, &res->data.irq);
593 case ACPI_RESOURCE_TYPE_DMA:
594 pnpacpi_parse_dma_option(option, &res->data.dma);
597 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
598 switch (res->data.start_dpf.compatibility_priority) {
599 case ACPI_GOOD_CONFIGURATION:
600 priority = PNP_RES_PRIORITY_PREFERRED;
603 case ACPI_ACCEPTABLE_CONFIGURATION:
604 priority = PNP_RES_PRIORITY_ACCEPTABLE;
607 case ACPI_SUB_OPTIMAL_CONFIGURATION:
608 priority = PNP_RES_PRIORITY_FUNCTIONAL;
611 priority = PNP_RES_PRIORITY_INVALID;
614 /* TBD: Consider performance/robustness bits */
615 option = pnp_register_dependent_option(dev, priority);
618 parse_data->option = option;
621 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
622 /*only one EndDependentFn is allowed */
623 if (!parse_data->option_independent) {
624 pnp_warn("PnPACPI: more than one EndDependentFn");
627 parse_data->option = parse_data->option_independent;
628 parse_data->option_independent = NULL;
631 case ACPI_RESOURCE_TYPE_IO:
632 pnpacpi_parse_port_option(option, &res->data.io);
635 case ACPI_RESOURCE_TYPE_FIXED_IO:
636 pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io);
639 case ACPI_RESOURCE_TYPE_VENDOR:
640 case ACPI_RESOURCE_TYPE_END_TAG:
643 case ACPI_RESOURCE_TYPE_MEMORY24:
644 pnpacpi_parse_mem24_option(option, &res->data.memory24);
647 case ACPI_RESOURCE_TYPE_MEMORY32:
648 pnpacpi_parse_mem32_option(option, &res->data.memory32);
651 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
652 pnpacpi_parse_fixed_mem32_option(option,
653 &res->data.fixed_memory32);
656 case ACPI_RESOURCE_TYPE_ADDRESS16:
657 case ACPI_RESOURCE_TYPE_ADDRESS32:
658 case ACPI_RESOURCE_TYPE_ADDRESS64:
659 pnpacpi_parse_address_option(option, res);
662 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
665 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
666 pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq);
669 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
673 pnp_warn("PnPACPI: unknown resource type %d", res->type);
680 acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
681 struct pnp_dev * dev)
684 struct acpipnp_parse_option_s parse_data;
686 parse_data.option = pnp_register_independent_option(dev);
687 if (!parse_data.option)
689 parse_data.option_independent = parse_data.option;
690 parse_data.dev = dev;
691 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
692 pnpacpi_option_resource, &parse_data);
697 static int pnpacpi_supported_resource(struct acpi_resource *res)
700 case ACPI_RESOURCE_TYPE_IRQ:
701 case ACPI_RESOURCE_TYPE_DMA:
702 case ACPI_RESOURCE_TYPE_IO:
703 case ACPI_RESOURCE_TYPE_FIXED_IO:
704 case ACPI_RESOURCE_TYPE_MEMORY24:
705 case ACPI_RESOURCE_TYPE_MEMORY32:
706 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
707 case ACPI_RESOURCE_TYPE_ADDRESS16:
708 case ACPI_RESOURCE_TYPE_ADDRESS32:
709 case ACPI_RESOURCE_TYPE_ADDRESS64:
710 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
719 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
724 if (pnpacpi_supported_resource(res))
729 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
731 struct acpi_resource **resource = data;
733 if (pnpacpi_supported_resource(res)) {
734 (*resource)->type = res->type;
735 (*resource)->length = sizeof(struct acpi_resource);
742 int pnpacpi_build_resource_template(acpi_handle handle,
743 struct acpi_buffer *buffer)
745 struct acpi_resource *resource;
749 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
750 pnpacpi_count_resources, &res_cnt);
751 if (ACPI_FAILURE(status)) {
752 pnp_err("Evaluate _CRS failed");
757 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
758 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
759 if (!buffer->pointer)
761 pnp_dbg("Res cnt %d", res_cnt);
762 resource = (struct acpi_resource *)buffer->pointer;
763 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
764 pnpacpi_type_resources, &resource);
765 if (ACPI_FAILURE(status)) {
766 kfree(buffer->pointer);
767 pnp_err("Evaluate _CRS failed");
770 /* resource will pointer the end resource now */
771 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
776 static void pnpacpi_encode_irq(struct acpi_resource *resource,
779 int triggering, polarity;
781 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
782 resource->data.irq.triggering = triggering;
783 resource->data.irq.polarity = polarity;
784 if (triggering == ACPI_EDGE_SENSITIVE)
785 resource->data.irq.sharable = ACPI_EXCLUSIVE;
787 resource->data.irq.sharable = ACPI_SHARED;
788 resource->data.irq.interrupt_count = 1;
789 resource->data.irq.interrupts[0] = p->start;
792 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
795 int triggering, polarity;
797 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
798 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
799 resource->data.extended_irq.triggering = triggering;
800 resource->data.extended_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.extended_irq.interrupt_count = 1;
806 resource->data.extended_irq.interrupts[0] = p->start;
809 static void pnpacpi_encode_dma(struct acpi_resource *resource,
812 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
813 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
814 case IORESOURCE_DMA_TYPEA:
815 resource->data.dma.type = ACPI_TYPE_A;
817 case IORESOURCE_DMA_TYPEB:
818 resource->data.dma.type = ACPI_TYPE_B;
820 case IORESOURCE_DMA_TYPEF:
821 resource->data.dma.type = ACPI_TYPE_F;
824 resource->data.dma.type = ACPI_COMPATIBILITY;
827 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
828 case IORESOURCE_DMA_8BIT:
829 resource->data.dma.transfer = ACPI_TRANSFER_8;
831 case IORESOURCE_DMA_8AND16BIT:
832 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
835 resource->data.dma.transfer = ACPI_TRANSFER_16;
838 resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
839 resource->data.dma.channel_count = 1;
840 resource->data.dma.channels[0] = p->start;
843 static void pnpacpi_encode_io(struct acpi_resource *resource,
846 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
847 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
848 ACPI_DECODE_16 : ACPI_DECODE_10;
849 resource->data.io.minimum = p->start;
850 resource->data.io.maximum = p->end;
851 resource->data.io.alignment = 0; /* Correct? */
852 resource->data.io.address_length = p->end - p->start + 1;
855 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
858 resource->data.fixed_io.address = p->start;
859 resource->data.fixed_io.address_length = p->end - p->start + 1;
862 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
865 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
866 resource->data.memory24.write_protect =
867 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
868 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
869 resource->data.memory24.minimum = p->start;
870 resource->data.memory24.maximum = p->end;
871 resource->data.memory24.alignment = 0;
872 resource->data.memory24.address_length = p->end - p->start + 1;
875 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
878 resource->data.memory32.write_protect =
879 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
880 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
881 resource->data.memory32.minimum = p->start;
882 resource->data.memory32.maximum = p->end;
883 resource->data.memory32.alignment = 0;
884 resource->data.memory32.address_length = p->end - p->start + 1;
887 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
890 resource->data.fixed_memory32.write_protect =
891 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
892 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
893 resource->data.fixed_memory32.address = p->start;
894 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
897 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
898 struct acpi_buffer *buffer)
901 /* pnpacpi_build_resource_template allocates extra mem */
902 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
903 struct acpi_resource *resource = buffer->pointer;
904 int port = 0, irq = 0, dma = 0, mem = 0;
906 pnp_dbg("res cnt %d", res_cnt);
907 while (i < res_cnt) {
908 switch (resource->type) {
909 case ACPI_RESOURCE_TYPE_IRQ:
910 pnp_dbg("Encode irq");
911 pnpacpi_encode_irq(resource,
912 &res_table->irq_resource[irq]);
916 case ACPI_RESOURCE_TYPE_DMA:
917 pnp_dbg("Encode dma");
918 pnpacpi_encode_dma(resource,
919 &res_table->dma_resource[dma]);
922 case ACPI_RESOURCE_TYPE_IO:
923 pnp_dbg("Encode io");
924 pnpacpi_encode_io(resource,
925 &res_table->port_resource[port]);
928 case ACPI_RESOURCE_TYPE_FIXED_IO:
929 pnp_dbg("Encode fixed io");
930 pnpacpi_encode_fixed_io(resource,
932 port_resource[port]);
935 case ACPI_RESOURCE_TYPE_MEMORY24:
936 pnp_dbg("Encode mem24");
937 pnpacpi_encode_mem24(resource,
938 &res_table->mem_resource[mem]);
941 case ACPI_RESOURCE_TYPE_MEMORY32:
942 pnp_dbg("Encode mem32");
943 pnpacpi_encode_mem32(resource,
944 &res_table->mem_resource[mem]);
947 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
948 pnp_dbg("Encode fixed mem32");
949 pnpacpi_encode_fixed_mem32(resource,
954 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
955 pnp_dbg("Encode ext irq");
956 pnpacpi_encode_ext_irq(resource,
957 &res_table->irq_resource[irq]);
960 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
961 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
962 case ACPI_RESOURCE_TYPE_VENDOR:
963 case ACPI_RESOURCE_TYPE_END_TAG:
964 case ACPI_RESOURCE_TYPE_ADDRESS16:
965 case ACPI_RESOURCE_TYPE_ADDRESS32:
966 case ACPI_RESOURCE_TYPE_ADDRESS64:
967 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
968 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
969 default: /* other type */
970 pnp_warn("unknown resource type %d", resource->type);