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>
24 #include <linux/pnp.h>
29 #define valid_IRQ(i) (1)
31 #define valid_IRQ(i) (((i) != 0) && ((i) != 2))
37 static int irq_flags(int triggering, int polarity, int shareable)
41 if (triggering == ACPI_LEVEL_SENSITIVE) {
42 if (polarity == ACPI_ACTIVE_LOW)
43 flags = IORESOURCE_IRQ_LOWLEVEL;
45 flags = IORESOURCE_IRQ_HIGHLEVEL;
47 if (polarity == ACPI_ACTIVE_LOW)
48 flags = IORESOURCE_IRQ_LOWEDGE;
50 flags = IORESOURCE_IRQ_HIGHEDGE;
53 if (shareable == ACPI_SHARED)
54 flags |= IORESOURCE_IRQ_SHAREABLE;
59 static void decode_irq_flags(struct pnp_dev *dev, int flags, int *triggering,
60 int *polarity, int *shareable)
62 switch (flags & (IORESOURCE_IRQ_LOWLEVEL | IORESOURCE_IRQ_HIGHLEVEL |
63 IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE)) {
64 case IORESOURCE_IRQ_LOWLEVEL:
65 *triggering = ACPI_LEVEL_SENSITIVE;
66 *polarity = ACPI_ACTIVE_LOW;
68 case IORESOURCE_IRQ_HIGHLEVEL:
69 *triggering = ACPI_LEVEL_SENSITIVE;
70 *polarity = ACPI_ACTIVE_HIGH;
72 case IORESOURCE_IRQ_LOWEDGE:
73 *triggering = ACPI_EDGE_SENSITIVE;
74 *polarity = ACPI_ACTIVE_LOW;
76 case IORESOURCE_IRQ_HIGHEDGE:
77 *triggering = ACPI_EDGE_SENSITIVE;
78 *polarity = ACPI_ACTIVE_HIGH;
81 dev_err(&dev->dev, "can't encode invalid IRQ mode %#x\n",
83 *triggering = ACPI_EDGE_SENSITIVE;
84 *polarity = ACPI_ACTIVE_HIGH;
88 if (flags & IORESOURCE_IRQ_SHAREABLE)
89 *shareable = ACPI_SHARED;
91 *shareable = ACPI_EXCLUSIVE;
94 static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
95 u32 gsi, int triggering,
96 int polarity, int shareable)
105 * in IO-APIC mode, use overrided attribute. Two reasons:
106 * 1. BIOS bug in DSDT
107 * 2. BIOS uses IO-APIC mode Interrupt Source Override
109 if (!acpi_get_override_irq(gsi, &t, &p)) {
110 t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
111 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
113 if (triggering != t || polarity != p) {
114 dev_warn(&dev->dev, "IRQ %d override to %s, %s\n",
115 gsi, t ? "edge":"level", p ? "low":"high");
121 flags = irq_flags(triggering, polarity, shareable);
122 irq = acpi_register_gsi(gsi, triggering, polarity);
124 pcibios_penalize_isa_irq(irq, 1);
126 flags |= IORESOURCE_DISABLED;
128 pnp_add_irq_resource(dev, irq, flags);
131 static int dma_flags(int type, int bus_master, int transfer)
136 flags |= IORESOURCE_DMA_MASTER;
138 case ACPI_COMPATIBILITY:
139 flags |= IORESOURCE_DMA_COMPATIBLE;
142 flags |= IORESOURCE_DMA_TYPEA;
145 flags |= IORESOURCE_DMA_TYPEB;
148 flags |= IORESOURCE_DMA_TYPEF;
151 /* Set a default value ? */
152 flags |= IORESOURCE_DMA_COMPATIBLE;
153 pnp_err("Invalid DMA type");
156 case ACPI_TRANSFER_8:
157 flags |= IORESOURCE_DMA_8BIT;
159 case ACPI_TRANSFER_8_16:
160 flags |= IORESOURCE_DMA_8AND16BIT;
162 case ACPI_TRANSFER_16:
163 flags |= IORESOURCE_DMA_16BIT;
166 /* Set a default value ? */
167 flags |= IORESOURCE_DMA_8AND16BIT;
168 pnp_err("Invalid DMA transfer type");
174 static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start,
175 u64 len, int io_decode)
178 u64 end = start + len - 1;
180 if (io_decode == ACPI_DECODE_16)
181 flags |= PNP_PORT_FLAG_16BITADDR;
182 if (len == 0 || end >= 0x10003)
183 flags |= IORESOURCE_DISABLED;
185 pnp_add_io_resource(dev, start, end, flags);
188 static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
193 u64 end = start + len - 1;
196 flags |= IORESOURCE_DISABLED;
197 if (write_protect == ACPI_READ_WRITE_MEMORY)
198 flags |= IORESOURCE_MEM_WRITEABLE;
200 pnp_add_mem_resource(dev, start, end, flags);
203 static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev,
204 struct acpi_resource *res)
206 struct acpi_resource_address64 addr, *p = &addr;
209 status = acpi_resource_to_address64(res, p);
210 if (!ACPI_SUCCESS(status)) {
211 dev_warn(&dev->dev, "failed to convert resource type %d\n",
216 if (p->producer_consumer == ACPI_PRODUCER)
219 if (p->resource_type == ACPI_MEMORY_RANGE)
220 pnpacpi_parse_allocated_memresource(dev,
221 p->minimum, p->address_length,
222 p->info.mem.write_protect);
223 else if (p->resource_type == ACPI_IO_RANGE)
224 pnpacpi_parse_allocated_ioresource(dev,
225 p->minimum, p->address_length,
226 p->granularity == 0xfff ? ACPI_DECODE_10 :
230 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
233 struct pnp_dev *dev = data;
234 struct acpi_resource_irq *irq;
235 struct acpi_resource_dma *dma;
236 struct acpi_resource_io *io;
237 struct acpi_resource_fixed_io *fixed_io;
238 struct acpi_resource_memory24 *memory24;
239 struct acpi_resource_memory32 *memory32;
240 struct acpi_resource_fixed_memory32 *fixed_memory32;
241 struct acpi_resource_extended_irq *extended_irq;
245 case ACPI_RESOURCE_TYPE_IRQ:
247 * Per spec, only one interrupt per descriptor is allowed in
248 * _CRS, but some firmware violates this, so parse them all.
250 irq = &res->data.irq;
251 for (i = 0; i < irq->interrupt_count; i++) {
252 pnpacpi_parse_allocated_irqresource(dev,
260 case ACPI_RESOURCE_TYPE_DMA:
261 dma = &res->data.dma;
262 if (dma->channel_count > 0) {
263 flags = dma_flags(dma->type, dma->bus_master,
265 if (dma->channels[0] == (u8) -1)
266 flags |= IORESOURCE_DISABLED;
267 pnp_add_dma_resource(dev, dma->channels[0], flags);
271 case ACPI_RESOURCE_TYPE_IO:
273 pnpacpi_parse_allocated_ioresource(dev,
279 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
280 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
283 case ACPI_RESOURCE_TYPE_FIXED_IO:
284 fixed_io = &res->data.fixed_io;
285 pnpacpi_parse_allocated_ioresource(dev,
287 fixed_io->address_length,
291 case ACPI_RESOURCE_TYPE_VENDOR:
294 case ACPI_RESOURCE_TYPE_END_TAG:
297 case ACPI_RESOURCE_TYPE_MEMORY24:
298 memory24 = &res->data.memory24;
299 pnpacpi_parse_allocated_memresource(dev,
301 memory24->address_length,
302 memory24->write_protect);
304 case ACPI_RESOURCE_TYPE_MEMORY32:
305 memory32 = &res->data.memory32;
306 pnpacpi_parse_allocated_memresource(dev,
308 memory32->address_length,
309 memory32->write_protect);
311 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
312 fixed_memory32 = &res->data.fixed_memory32;
313 pnpacpi_parse_allocated_memresource(dev,
314 fixed_memory32->address,
315 fixed_memory32->address_length,
316 fixed_memory32->write_protect);
318 case ACPI_RESOURCE_TYPE_ADDRESS16:
319 case ACPI_RESOURCE_TYPE_ADDRESS32:
320 case ACPI_RESOURCE_TYPE_ADDRESS64:
321 pnpacpi_parse_allocated_address_space(dev, res);
324 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
325 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
329 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
330 extended_irq = &res->data.extended_irq;
331 if (extended_irq->producer_consumer == ACPI_PRODUCER)
334 for (i = 0; i < extended_irq->interrupt_count; i++) {
335 pnpacpi_parse_allocated_irqresource(dev,
336 extended_irq->interrupts[i],
337 extended_irq->triggering,
338 extended_irq->polarity,
339 extended_irq->sharable);
343 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
347 dev_warn(&dev->dev, "unknown resource type %d in _CRS\n",
355 int pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
357 acpi_handle handle = dev->data;
360 dev_dbg(&dev->dev, "parse allocated resources\n");
362 pnp_init_resources(dev);
364 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
365 pnpacpi_allocated_resource, dev);
367 if (ACPI_FAILURE(status)) {
368 if (status != AE_NOT_FOUND)
369 dev_err(&dev->dev, "can't evaluate _CRS: %d", status);
375 static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev,
376 struct pnp_option *option,
377 struct acpi_resource_dma *p)
382 if (p->channel_count == 0)
384 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
388 for (i = 0; i < p->channel_count; i++)
389 dma->map |= 1 << p->channels[i];
391 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
393 pnp_register_dma_resource(dev, option, dma);
396 static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev,
397 struct pnp_option *option,
398 struct acpi_resource_irq *p)
403 if (p->interrupt_count == 0)
405 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
409 for (i = 0; i < p->interrupt_count; i++)
410 if (p->interrupts[i])
411 __set_bit(p->interrupts[i], irq->map);
412 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
414 pnp_register_irq_resource(dev, option, irq);
417 static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,
418 struct pnp_option *option,
419 struct acpi_resource_extended_irq *p)
424 if (p->interrupt_count == 0)
426 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
430 for (i = 0; i < p->interrupt_count; i++)
431 if (p->interrupts[i])
432 __set_bit(p->interrupts[i], irq->map);
433 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
435 pnp_register_irq_resource(dev, option, irq);
438 static __init void pnpacpi_parse_port_option(struct pnp_dev *dev,
439 struct pnp_option *option,
440 struct acpi_resource_io *io)
442 struct pnp_port *port;
444 if (io->address_length == 0)
446 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
449 port->min = io->minimum;
450 port->max = io->maximum;
451 port->align = io->alignment;
452 port->size = io->address_length;
453 port->flags = ACPI_DECODE_16 == io->io_decode ?
454 PNP_PORT_FLAG_16BITADDR : 0;
455 pnp_register_port_resource(dev, option, port);
458 static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev,
459 struct pnp_option *option,
460 struct acpi_resource_fixed_io *io)
462 struct pnp_port *port;
464 if (io->address_length == 0)
466 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
469 port->min = port->max = io->address;
470 port->size = io->address_length;
472 port->flags = PNP_PORT_FLAG_FIXED;
473 pnp_register_port_resource(dev, option, port);
476 static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev,
477 struct pnp_option *option,
478 struct acpi_resource_memory24 *p)
482 if (p->address_length == 0)
484 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
487 mem->min = p->minimum;
488 mem->max = p->maximum;
489 mem->align = p->alignment;
490 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(dev, option, mem);
498 static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev,
499 struct pnp_option *option,
500 struct acpi_resource_memory32 *p)
504 if (p->address_length == 0)
506 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
509 mem->min = p->minimum;
510 mem->max = p->maximum;
511 mem->align = p->alignment;
512 mem->size = p->address_length;
514 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
515 IORESOURCE_MEM_WRITEABLE : 0;
517 pnp_register_mem_resource(dev, option, mem);
520 static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev,
521 struct pnp_option *option,
522 struct acpi_resource_fixed_memory32 *p)
526 if (p->address_length == 0)
528 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
531 mem->min = mem->max = p->address;
532 mem->size = p->address_length;
535 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
536 IORESOURCE_MEM_WRITEABLE : 0;
538 pnp_register_mem_resource(dev, option, mem);
541 static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,
542 struct pnp_option *option,
543 struct acpi_resource *r)
545 struct acpi_resource_address64 addr, *p = &addr;
548 struct pnp_port *port;
550 status = acpi_resource_to_address64(r, p);
551 if (!ACPI_SUCCESS(status)) {
552 pnp_warn("PnPACPI: failed to convert resource type %d",
557 if (p->address_length == 0)
560 if (p->resource_type == ACPI_MEMORY_RANGE) {
561 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
564 mem->min = mem->max = p->minimum;
565 mem->size = p->address_length;
567 mem->flags = (p->info.mem.write_protect ==
568 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
570 pnp_register_mem_resource(dev, option, mem);
571 } else if (p->resource_type == ACPI_IO_RANGE) {
572 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
575 port->min = port->max = p->minimum;
576 port->size = p->address_length;
578 port->flags = PNP_PORT_FLAG_FIXED;
579 pnp_register_port_resource(dev, option, port);
583 struct acpipnp_parse_option_s {
584 struct pnp_option *option;
585 struct pnp_option *option_independent;
589 static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
593 struct acpipnp_parse_option_s *parse_data = data;
594 struct pnp_dev *dev = parse_data->dev;
595 struct pnp_option *option = parse_data->option;
598 case ACPI_RESOURCE_TYPE_IRQ:
599 pnpacpi_parse_irq_option(dev, option, &res->data.irq);
602 case ACPI_RESOURCE_TYPE_DMA:
603 pnpacpi_parse_dma_option(dev, option, &res->data.dma);
606 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
607 switch (res->data.start_dpf.compatibility_priority) {
608 case ACPI_GOOD_CONFIGURATION:
609 priority = PNP_RES_PRIORITY_PREFERRED;
612 case ACPI_ACCEPTABLE_CONFIGURATION:
613 priority = PNP_RES_PRIORITY_ACCEPTABLE;
616 case ACPI_SUB_OPTIMAL_CONFIGURATION:
617 priority = PNP_RES_PRIORITY_FUNCTIONAL;
620 priority = PNP_RES_PRIORITY_INVALID;
623 /* TBD: Consider performance/robustness bits */
624 option = pnp_register_dependent_option(dev, priority);
627 parse_data->option = option;
630 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
631 /*only one EndDependentFn is allowed */
632 if (!parse_data->option_independent) {
633 dev_warn(&dev->dev, "more than one EndDependentFn "
637 parse_data->option = parse_data->option_independent;
638 parse_data->option_independent = NULL;
639 dev_dbg(&dev->dev, "end dependent options\n");
642 case ACPI_RESOURCE_TYPE_IO:
643 pnpacpi_parse_port_option(dev, option, &res->data.io);
646 case ACPI_RESOURCE_TYPE_FIXED_IO:
647 pnpacpi_parse_fixed_port_option(dev, option,
648 &res->data.fixed_io);
651 case ACPI_RESOURCE_TYPE_VENDOR:
652 case ACPI_RESOURCE_TYPE_END_TAG:
655 case ACPI_RESOURCE_TYPE_MEMORY24:
656 pnpacpi_parse_mem24_option(dev, option, &res->data.memory24);
659 case ACPI_RESOURCE_TYPE_MEMORY32:
660 pnpacpi_parse_mem32_option(dev, option, &res->data.memory32);
663 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
664 pnpacpi_parse_fixed_mem32_option(dev, option,
665 &res->data.fixed_memory32);
668 case ACPI_RESOURCE_TYPE_ADDRESS16:
669 case ACPI_RESOURCE_TYPE_ADDRESS32:
670 case ACPI_RESOURCE_TYPE_ADDRESS64:
671 pnpacpi_parse_address_option(dev, option, res);
674 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
677 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
678 pnpacpi_parse_ext_irq_option(dev, option,
679 &res->data.extended_irq);
682 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
686 dev_warn(&dev->dev, "unknown resource type %d in _PRS\n",
694 int __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev)
696 acpi_handle handle = dev->data;
698 struct acpipnp_parse_option_s parse_data;
700 dev_dbg(&dev->dev, "parse resource options\n");
702 parse_data.option = pnp_register_independent_option(dev);
703 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);
711 if (ACPI_FAILURE(status)) {
712 if (status != AE_NOT_FOUND)
713 dev_err(&dev->dev, "can't evaluate _PRS: %d", status);
719 static int pnpacpi_supported_resource(struct acpi_resource *res)
722 case ACPI_RESOURCE_TYPE_IRQ:
723 case ACPI_RESOURCE_TYPE_DMA:
724 case ACPI_RESOURCE_TYPE_IO:
725 case ACPI_RESOURCE_TYPE_FIXED_IO:
726 case ACPI_RESOURCE_TYPE_MEMORY24:
727 case ACPI_RESOURCE_TYPE_MEMORY32:
728 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
729 case ACPI_RESOURCE_TYPE_ADDRESS16:
730 case ACPI_RESOURCE_TYPE_ADDRESS32:
731 case ACPI_RESOURCE_TYPE_ADDRESS64:
732 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
741 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
746 if (pnpacpi_supported_resource(res))
751 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
753 struct acpi_resource **resource = data;
755 if (pnpacpi_supported_resource(res)) {
756 (*resource)->type = res->type;
757 (*resource)->length = sizeof(struct acpi_resource);
758 if (res->type == ACPI_RESOURCE_TYPE_IRQ)
759 (*resource)->data.irq.descriptor_length =
760 res->data.irq.descriptor_length;
767 int pnpacpi_build_resource_template(struct pnp_dev *dev,
768 struct acpi_buffer *buffer)
770 acpi_handle handle = dev->data;
771 struct acpi_resource *resource;
775 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
776 pnpacpi_count_resources, &res_cnt);
777 if (ACPI_FAILURE(status)) {
778 dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status);
783 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
784 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
785 if (!buffer->pointer)
788 resource = (struct acpi_resource *)buffer->pointer;
789 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
790 pnpacpi_type_resources, &resource);
791 if (ACPI_FAILURE(status)) {
792 kfree(buffer->pointer);
793 dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status);
796 /* resource will pointer the end resource now */
797 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
802 static void pnpacpi_encode_irq(struct pnp_dev *dev,
803 struct acpi_resource *resource,
806 struct acpi_resource_irq *irq = &resource->data.irq;
807 int triggering, polarity, shareable;
809 decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable);
810 irq->triggering = triggering;
811 irq->polarity = polarity;
812 irq->sharable = shareable;
813 irq->interrupt_count = 1;
814 irq->interrupts[0] = p->start;
816 dev_dbg(&dev->dev, " encode irq %d %s %s %s (%d-byte descriptor)\n",
818 triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
819 polarity == ACPI_ACTIVE_LOW ? "low" : "high",
820 irq->sharable == ACPI_SHARED ? "shared" : "exclusive",
821 irq->descriptor_length);
824 static void pnpacpi_encode_ext_irq(struct pnp_dev *dev,
825 struct acpi_resource *resource,
828 struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq;
829 int triggering, polarity, shareable;
831 decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable);
832 extended_irq->producer_consumer = ACPI_CONSUMER;
833 extended_irq->triggering = triggering;
834 extended_irq->polarity = polarity;
835 extended_irq->sharable = shareable;
836 extended_irq->interrupt_count = 1;
837 extended_irq->interrupts[0] = p->start;
839 dev_dbg(&dev->dev, " encode irq %d %s %s %s\n", (int) p->start,
840 triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
841 polarity == ACPI_ACTIVE_LOW ? "low" : "high",
842 extended_irq->sharable == ACPI_SHARED ? "shared" : "exclusive");
845 static void pnpacpi_encode_dma(struct pnp_dev *dev,
846 struct acpi_resource *resource,
849 struct acpi_resource_dma *dma = &resource->data.dma;
851 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
852 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
853 case IORESOURCE_DMA_TYPEA:
854 dma->type = ACPI_TYPE_A;
856 case IORESOURCE_DMA_TYPEB:
857 dma->type = ACPI_TYPE_B;
859 case IORESOURCE_DMA_TYPEF:
860 dma->type = ACPI_TYPE_F;
863 dma->type = ACPI_COMPATIBILITY;
866 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
867 case IORESOURCE_DMA_8BIT:
868 dma->transfer = ACPI_TRANSFER_8;
870 case IORESOURCE_DMA_8AND16BIT:
871 dma->transfer = ACPI_TRANSFER_8_16;
874 dma->transfer = ACPI_TRANSFER_16;
877 dma->bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
878 dma->channel_count = 1;
879 dma->channels[0] = p->start;
881 dev_dbg(&dev->dev, " encode dma %d "
882 "type %#x transfer %#x master %d\n",
883 (int) p->start, dma->type, dma->transfer, dma->bus_master);
886 static void pnpacpi_encode_io(struct pnp_dev *dev,
887 struct acpi_resource *resource,
890 struct acpi_resource_io *io = &resource->data.io;
892 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
893 io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
894 ACPI_DECODE_16 : ACPI_DECODE_10;
895 io->minimum = p->start;
896 io->maximum = p->end;
897 io->alignment = 0; /* Correct? */
898 io->address_length = p->end - p->start + 1;
900 dev_dbg(&dev->dev, " encode io %#llx-%#llx decode %#x\n",
901 (unsigned long long) p->start, (unsigned long long) p->end,
905 static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,
906 struct acpi_resource *resource,
909 struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io;
911 fixed_io->address = p->start;
912 fixed_io->address_length = p->end - p->start + 1;
914 dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n",
915 (unsigned long long) p->start, (unsigned long long) p->end);
918 static void pnpacpi_encode_mem24(struct pnp_dev *dev,
919 struct acpi_resource *resource,
922 struct acpi_resource_memory24 *memory24 = &resource->data.memory24;
924 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
925 memory24->write_protect =
926 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
927 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
928 memory24->minimum = p->start;
929 memory24->maximum = p->end;
930 memory24->alignment = 0;
931 memory24->address_length = p->end - p->start + 1;
933 dev_dbg(&dev->dev, " encode mem24 %#llx-%#llx write_protect %#x\n",
934 (unsigned long long) p->start, (unsigned long long) p->end,
935 memory24->write_protect);
938 static void pnpacpi_encode_mem32(struct pnp_dev *dev,
939 struct acpi_resource *resource,
942 struct acpi_resource_memory32 *memory32 = &resource->data.memory32;
944 memory32->write_protect =
945 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
946 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
947 memory32->minimum = p->start;
948 memory32->maximum = p->end;
949 memory32->alignment = 0;
950 memory32->address_length = p->end - p->start + 1;
952 dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx write_protect %#x\n",
953 (unsigned long long) p->start, (unsigned long long) p->end,
954 memory32->write_protect);
957 static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev,
958 struct acpi_resource *resource,
961 struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32;
963 fixed_memory32->write_protect =
964 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
965 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
966 fixed_memory32->address = p->start;
967 fixed_memory32->address_length = p->end - p->start + 1;
969 dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx "
970 "write_protect %#x\n",
971 (unsigned long long) p->start, (unsigned long long) p->end,
972 fixed_memory32->write_protect);
975 int pnpacpi_encode_resources(struct pnp_dev *dev, struct acpi_buffer *buffer)
978 /* pnpacpi_build_resource_template allocates extra mem */
979 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
980 struct acpi_resource *resource = buffer->pointer;
981 int port = 0, irq = 0, dma = 0, mem = 0;
983 dev_dbg(&dev->dev, "encode %d resources\n", res_cnt);
984 while (i < res_cnt) {
985 switch (resource->type) {
986 case ACPI_RESOURCE_TYPE_IRQ:
987 pnpacpi_encode_irq(dev, resource,
988 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
992 case ACPI_RESOURCE_TYPE_DMA:
993 pnpacpi_encode_dma(dev, resource,
994 pnp_get_resource(dev, IORESOURCE_DMA, dma));
997 case ACPI_RESOURCE_TYPE_IO:
998 pnpacpi_encode_io(dev, resource,
999 pnp_get_resource(dev, IORESOURCE_IO, port));
1002 case ACPI_RESOURCE_TYPE_FIXED_IO:
1003 pnpacpi_encode_fixed_io(dev, resource,
1004 pnp_get_resource(dev, IORESOURCE_IO, port));
1007 case ACPI_RESOURCE_TYPE_MEMORY24:
1008 pnpacpi_encode_mem24(dev, resource,
1009 pnp_get_resource(dev, IORESOURCE_MEM, mem));
1012 case ACPI_RESOURCE_TYPE_MEMORY32:
1013 pnpacpi_encode_mem32(dev, resource,
1014 pnp_get_resource(dev, IORESOURCE_MEM, mem));
1017 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
1018 pnpacpi_encode_fixed_mem32(dev, resource,
1019 pnp_get_resource(dev, IORESOURCE_MEM, mem));
1022 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
1023 pnpacpi_encode_ext_irq(dev, resource,
1024 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
1027 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
1028 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
1029 case ACPI_RESOURCE_TYPE_VENDOR:
1030 case ACPI_RESOURCE_TYPE_END_TAG:
1031 case ACPI_RESOURCE_TYPE_ADDRESS16:
1032 case ACPI_RESOURCE_TYPE_ADDRESS32:
1033 case ACPI_RESOURCE_TYPE_ADDRESS64:
1034 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
1035 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
1036 default: /* other type */
1037 dev_warn(&dev->dev, "can't encode unknown resource "
1038 "type %d\n", resource->type);