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;
54 flags |= IORESOURCE_IRQ_SHAREABLE;
59 static void decode_irq_flags(int flag, int *triggering, int *polarity)
62 case IORESOURCE_IRQ_LOWLEVEL:
63 *triggering = ACPI_LEVEL_SENSITIVE;
64 *polarity = ACPI_ACTIVE_LOW;
66 case IORESOURCE_IRQ_HIGHLEVEL:
67 *triggering = ACPI_LEVEL_SENSITIVE;
68 *polarity = ACPI_ACTIVE_HIGH;
70 case IORESOURCE_IRQ_LOWEDGE:
71 *triggering = ACPI_EDGE_SENSITIVE;
72 *polarity = ACPI_ACTIVE_LOW;
74 case IORESOURCE_IRQ_HIGHEDGE:
75 *triggering = ACPI_EDGE_SENSITIVE;
76 *polarity = ACPI_ACTIVE_HIGH;
81 static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
82 u32 gsi, int triggering,
83 int polarity, int shareable)
89 static unsigned char warned;
94 for (i = 0; i < PNP_MAX_IRQ; i++) {
95 res = pnp_get_resource(dev, IORESOURCE_IRQ, i);
96 if (!pnp_resource_valid(res))
99 if (i >= PNP_MAX_IRQ) {
101 printk(KERN_WARNING "pnpacpi: exceeded the max number"
102 " of IRQ resources: %d\n", PNP_MAX_IRQ);
108 * in IO-APIC mode, use overrided attribute. Two reasons:
109 * 1. BIOS bug in DSDT
110 * 2. BIOS uses IO-APIC mode Interrupt Source Override
112 if (!acpi_get_override_irq(gsi, &t, &p)) {
113 t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
114 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
116 if (triggering != t || polarity != p) {
117 dev_warn(&dev->dev, "IRQ %d override to %s, %s\n",
118 gsi, t ? "edge":"level", p ? "low":"high");
124 res->flags = IORESOURCE_IRQ; // Also clears _UNSET flag
125 res->flags |= irq_flags(triggering, polarity, shareable);
126 irq = acpi_register_gsi(gsi, triggering, polarity);
128 res->flags |= IORESOURCE_DISABLED;
134 pcibios_penalize_isa_irq(irq, 1);
137 static int dma_flags(int type, int bus_master, int transfer)
142 flags |= IORESOURCE_DMA_MASTER;
144 case ACPI_COMPATIBILITY:
145 flags |= IORESOURCE_DMA_COMPATIBLE;
148 flags |= IORESOURCE_DMA_TYPEA;
151 flags |= IORESOURCE_DMA_TYPEB;
154 flags |= IORESOURCE_DMA_TYPEF;
157 /* Set a default value ? */
158 flags |= IORESOURCE_DMA_COMPATIBLE;
159 pnp_err("Invalid DMA type");
162 case ACPI_TRANSFER_8:
163 flags |= IORESOURCE_DMA_8BIT;
165 case ACPI_TRANSFER_8_16:
166 flags |= IORESOURCE_DMA_8AND16BIT;
168 case ACPI_TRANSFER_16:
169 flags |= IORESOURCE_DMA_16BIT;
172 /* Set a default value ? */
173 flags |= IORESOURCE_DMA_8AND16BIT;
174 pnp_err("Invalid DMA transfer type");
180 static void pnpacpi_parse_allocated_dmaresource(struct pnp_dev *dev,
183 struct resource *res;
185 static unsigned char warned;
187 for (i = 0; i < PNP_MAX_DMA; i++) {
188 res = pnp_get_resource(dev, IORESOURCE_DMA, i);
189 if (!pnp_resource_valid(res))
192 if (i < PNP_MAX_DMA) {
193 res->flags = IORESOURCE_DMA; // Also clears _UNSET flag
196 res->flags |= IORESOURCE_DISABLED;
201 } else if (!warned) {
202 printk(KERN_WARNING "pnpacpi: exceeded the max number of DMA "
203 "resources: %d \n", PNP_MAX_DMA);
208 static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev,
209 u64 io, u64 len, int io_decode)
211 struct resource *res;
213 static unsigned char warned;
215 for (i = 0; i < PNP_MAX_PORT; i++) {
216 res = pnp_get_resource(dev, IORESOURCE_IO, i);
217 if (!pnp_resource_valid(res))
220 if (i < PNP_MAX_PORT) {
221 res->flags = IORESOURCE_IO; // Also clears _UNSET flag
222 if (io_decode == ACPI_DECODE_16)
223 res->flags |= PNP_PORT_FLAG_16BITADDR;
224 if (len <= 0 || (io + len - 1) >= 0x10003) {
225 res->flags |= IORESOURCE_DISABLED;
229 res->end = io + len - 1;
230 } else if (!warned) {
231 printk(KERN_WARNING "pnpacpi: exceeded the max number of IO "
232 "resources: %d \n", PNP_MAX_PORT);
237 static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
241 struct resource *res;
243 static unsigned char warned;
245 for (i = 0; i < PNP_MAX_MEM; i++) {
246 res = pnp_get_resource(dev, IORESOURCE_MEM, i);
247 if (!pnp_resource_valid(res))
250 if (i < PNP_MAX_MEM) {
251 res->flags = IORESOURCE_MEM; // Also clears _UNSET flag
253 res->flags |= IORESOURCE_DISABLED;
256 if (write_protect == ACPI_READ_WRITE_MEMORY)
257 res->flags |= IORESOURCE_MEM_WRITEABLE;
260 res->end = mem + len - 1;
261 } else if (!warned) {
262 printk(KERN_WARNING "pnpacpi: exceeded the max number of mem "
263 "resources: %d\n", PNP_MAX_MEM);
268 static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev,
269 struct acpi_resource *res)
271 struct acpi_resource_address64 addr, *p = &addr;
274 status = acpi_resource_to_address64(res, p);
275 if (!ACPI_SUCCESS(status)) {
276 dev_warn(&dev->dev, "failed to convert resource type %d\n",
281 if (p->producer_consumer == ACPI_PRODUCER)
284 if (p->resource_type == ACPI_MEMORY_RANGE)
285 pnpacpi_parse_allocated_memresource(dev,
286 p->minimum, p->address_length,
287 p->info.mem.write_protect);
288 else if (p->resource_type == ACPI_IO_RANGE)
289 pnpacpi_parse_allocated_ioresource(dev,
290 p->minimum, p->address_length,
291 p->granularity == 0xfff ? ACPI_DECODE_10 :
295 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
298 struct pnp_dev *dev = data;
299 struct acpi_resource_irq *irq;
300 struct acpi_resource_dma *dma;
301 struct acpi_resource_io *io;
302 struct acpi_resource_fixed_io *fixed_io;
303 struct acpi_resource_memory24 *memory24;
304 struct acpi_resource_memory32 *memory32;
305 struct acpi_resource_fixed_memory32 *fixed_memory32;
306 struct acpi_resource_extended_irq *extended_irq;
310 case ACPI_RESOURCE_TYPE_IRQ:
312 * Per spec, only one interrupt per descriptor is allowed in
313 * _CRS, but some firmware violates this, so parse them all.
315 irq = &res->data.irq;
316 for (i = 0; i < irq->interrupt_count; i++) {
317 pnpacpi_parse_allocated_irqresource(dev,
325 case ACPI_RESOURCE_TYPE_DMA:
326 dma = &res->data.dma;
327 if (dma->channel_count > 0)
328 pnpacpi_parse_allocated_dmaresource(dev,
330 dma_flags(dma->type, dma->bus_master,
334 case ACPI_RESOURCE_TYPE_IO:
336 pnpacpi_parse_allocated_ioresource(dev,
342 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
343 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
346 case ACPI_RESOURCE_TYPE_FIXED_IO:
347 fixed_io = &res->data.fixed_io;
348 pnpacpi_parse_allocated_ioresource(dev,
350 fixed_io->address_length,
354 case ACPI_RESOURCE_TYPE_VENDOR:
357 case ACPI_RESOURCE_TYPE_END_TAG:
360 case ACPI_RESOURCE_TYPE_MEMORY24:
361 memory24 = &res->data.memory24;
362 pnpacpi_parse_allocated_memresource(dev,
364 memory24->address_length,
365 memory24->write_protect);
367 case ACPI_RESOURCE_TYPE_MEMORY32:
368 memory32 = &res->data.memory32;
369 pnpacpi_parse_allocated_memresource(dev,
371 memory32->address_length,
372 memory32->write_protect);
374 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
375 fixed_memory32 = &res->data.fixed_memory32;
376 pnpacpi_parse_allocated_memresource(dev,
377 fixed_memory32->address,
378 fixed_memory32->address_length,
379 fixed_memory32->write_protect);
381 case ACPI_RESOURCE_TYPE_ADDRESS16:
382 case ACPI_RESOURCE_TYPE_ADDRESS32:
383 case ACPI_RESOURCE_TYPE_ADDRESS64:
384 pnpacpi_parse_allocated_address_space(dev, res);
387 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
388 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
392 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
393 extended_irq = &res->data.extended_irq;
394 if (extended_irq->producer_consumer == ACPI_PRODUCER)
397 for (i = 0; i < extended_irq->interrupt_count; i++) {
398 pnpacpi_parse_allocated_irqresource(dev,
399 extended_irq->interrupts[i],
400 extended_irq->triggering,
401 extended_irq->polarity,
402 extended_irq->sharable);
406 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
410 dev_warn(&dev->dev, "unknown resource type %d in _CRS\n",
418 acpi_status pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
420 acpi_handle handle = dev->data;
422 dev_dbg(&dev->dev, "parse allocated resources\n");
424 pnp_init_resources(dev);
426 return acpi_walk_resources(handle, METHOD_NAME__CRS,
427 pnpacpi_allocated_resource, dev);
430 static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev,
431 struct pnp_option *option,
432 struct acpi_resource_dma *p)
437 if (p->channel_count == 0)
439 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
443 for (i = 0; i < p->channel_count; i++)
444 dma->map |= 1 << p->channels[i];
446 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
448 pnp_register_dma_resource(dev, option, dma);
451 static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev,
452 struct pnp_option *option,
453 struct acpi_resource_irq *p)
458 if (p->interrupt_count == 0)
460 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
464 for (i = 0; i < p->interrupt_count; i++)
465 if (p->interrupts[i])
466 __set_bit(p->interrupts[i], irq->map);
467 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
469 pnp_register_irq_resource(dev, option, irq);
472 static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,
473 struct pnp_option *option,
474 struct acpi_resource_extended_irq *p)
479 if (p->interrupt_count == 0)
481 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
485 for (i = 0; i < p->interrupt_count; i++)
486 if (p->interrupts[i])
487 __set_bit(p->interrupts[i], irq->map);
488 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
490 pnp_register_irq_resource(dev, option, irq);
493 static __init void pnpacpi_parse_port_option(struct pnp_dev *dev,
494 struct pnp_option *option,
495 struct acpi_resource_io *io)
497 struct pnp_port *port;
499 if (io->address_length == 0)
501 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
504 port->min = io->minimum;
505 port->max = io->maximum;
506 port->align = io->alignment;
507 port->size = io->address_length;
508 port->flags = ACPI_DECODE_16 == io->io_decode ?
509 PNP_PORT_FLAG_16BITADDR : 0;
510 pnp_register_port_resource(dev, option, port);
513 static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev,
514 struct pnp_option *option,
515 struct acpi_resource_fixed_io *io)
517 struct pnp_port *port;
519 if (io->address_length == 0)
521 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
524 port->min = port->max = io->address;
525 port->size = io->address_length;
527 port->flags = PNP_PORT_FLAG_FIXED;
528 pnp_register_port_resource(dev, option, port);
531 static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev,
532 struct pnp_option *option,
533 struct acpi_resource_memory24 *p)
537 if (p->address_length == 0)
539 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
542 mem->min = p->minimum;
543 mem->max = p->maximum;
544 mem->align = p->alignment;
545 mem->size = p->address_length;
547 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
548 IORESOURCE_MEM_WRITEABLE : 0;
550 pnp_register_mem_resource(dev, option, mem);
553 static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev,
554 struct pnp_option *option,
555 struct acpi_resource_memory32 *p)
559 if (p->address_length == 0)
561 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
564 mem->min = p->minimum;
565 mem->max = p->maximum;
566 mem->align = p->alignment;
567 mem->size = p->address_length;
569 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
570 IORESOURCE_MEM_WRITEABLE : 0;
572 pnp_register_mem_resource(dev, option, mem);
575 static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev,
576 struct pnp_option *option,
577 struct acpi_resource_fixed_memory32 *p)
581 if (p->address_length == 0)
583 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
586 mem->min = mem->max = p->address;
587 mem->size = p->address_length;
590 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
591 IORESOURCE_MEM_WRITEABLE : 0;
593 pnp_register_mem_resource(dev, option, mem);
596 static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,
597 struct pnp_option *option,
598 struct acpi_resource *r)
600 struct acpi_resource_address64 addr, *p = &addr;
603 struct pnp_port *port;
605 status = acpi_resource_to_address64(r, p);
606 if (!ACPI_SUCCESS(status)) {
607 pnp_warn("PnPACPI: failed to convert resource type %d",
612 if (p->address_length == 0)
615 if (p->resource_type == ACPI_MEMORY_RANGE) {
616 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
619 mem->min = mem->max = p->minimum;
620 mem->size = p->address_length;
622 mem->flags = (p->info.mem.write_protect ==
623 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
625 pnp_register_mem_resource(dev, option, mem);
626 } else if (p->resource_type == ACPI_IO_RANGE) {
627 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
630 port->min = port->max = p->minimum;
631 port->size = p->address_length;
633 port->flags = PNP_PORT_FLAG_FIXED;
634 pnp_register_port_resource(dev, option, port);
638 struct acpipnp_parse_option_s {
639 struct pnp_option *option;
640 struct pnp_option *option_independent;
644 static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
648 struct acpipnp_parse_option_s *parse_data = data;
649 struct pnp_dev *dev = parse_data->dev;
650 struct pnp_option *option = parse_data->option;
653 case ACPI_RESOURCE_TYPE_IRQ:
654 pnpacpi_parse_irq_option(dev, option, &res->data.irq);
657 case ACPI_RESOURCE_TYPE_DMA:
658 pnpacpi_parse_dma_option(dev, option, &res->data.dma);
661 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
662 switch (res->data.start_dpf.compatibility_priority) {
663 case ACPI_GOOD_CONFIGURATION:
664 priority = PNP_RES_PRIORITY_PREFERRED;
667 case ACPI_ACCEPTABLE_CONFIGURATION:
668 priority = PNP_RES_PRIORITY_ACCEPTABLE;
671 case ACPI_SUB_OPTIMAL_CONFIGURATION:
672 priority = PNP_RES_PRIORITY_FUNCTIONAL;
675 priority = PNP_RES_PRIORITY_INVALID;
678 /* TBD: Consider performance/robustness bits */
679 option = pnp_register_dependent_option(dev, priority);
682 parse_data->option = option;
685 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
686 /*only one EndDependentFn is allowed */
687 if (!parse_data->option_independent) {
688 dev_warn(&dev->dev, "more than one EndDependentFn "
692 parse_data->option = parse_data->option_independent;
693 parse_data->option_independent = NULL;
694 dev_dbg(&dev->dev, "end dependent options\n");
697 case ACPI_RESOURCE_TYPE_IO:
698 pnpacpi_parse_port_option(dev, option, &res->data.io);
701 case ACPI_RESOURCE_TYPE_FIXED_IO:
702 pnpacpi_parse_fixed_port_option(dev, option,
703 &res->data.fixed_io);
706 case ACPI_RESOURCE_TYPE_VENDOR:
707 case ACPI_RESOURCE_TYPE_END_TAG:
710 case ACPI_RESOURCE_TYPE_MEMORY24:
711 pnpacpi_parse_mem24_option(dev, option, &res->data.memory24);
714 case ACPI_RESOURCE_TYPE_MEMORY32:
715 pnpacpi_parse_mem32_option(dev, option, &res->data.memory32);
718 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
719 pnpacpi_parse_fixed_mem32_option(dev, option,
720 &res->data.fixed_memory32);
723 case ACPI_RESOURCE_TYPE_ADDRESS16:
724 case ACPI_RESOURCE_TYPE_ADDRESS32:
725 case ACPI_RESOURCE_TYPE_ADDRESS64:
726 pnpacpi_parse_address_option(dev, option, res);
729 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
732 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
733 pnpacpi_parse_ext_irq_option(dev, option,
734 &res->data.extended_irq);
737 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
741 dev_warn(&dev->dev, "unknown resource type %d in _PRS\n",
749 acpi_status __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev)
751 acpi_handle handle = dev->data;
753 struct acpipnp_parse_option_s parse_data;
755 dev_dbg(&dev->dev, "parse resource options\n");
757 parse_data.option = pnp_register_independent_option(dev);
758 if (!parse_data.option)
760 parse_data.option_independent = parse_data.option;
761 parse_data.dev = dev;
762 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
763 pnpacpi_option_resource, &parse_data);
768 static int pnpacpi_supported_resource(struct acpi_resource *res)
771 case ACPI_RESOURCE_TYPE_IRQ:
772 case ACPI_RESOURCE_TYPE_DMA:
773 case ACPI_RESOURCE_TYPE_IO:
774 case ACPI_RESOURCE_TYPE_FIXED_IO:
775 case ACPI_RESOURCE_TYPE_MEMORY24:
776 case ACPI_RESOURCE_TYPE_MEMORY32:
777 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
778 case ACPI_RESOURCE_TYPE_ADDRESS16:
779 case ACPI_RESOURCE_TYPE_ADDRESS32:
780 case ACPI_RESOURCE_TYPE_ADDRESS64:
781 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
790 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
795 if (pnpacpi_supported_resource(res))
800 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
802 struct acpi_resource **resource = data;
804 if (pnpacpi_supported_resource(res)) {
805 (*resource)->type = res->type;
806 (*resource)->length = sizeof(struct acpi_resource);
813 int pnpacpi_build_resource_template(struct pnp_dev *dev,
814 struct acpi_buffer *buffer)
816 acpi_handle handle = dev->data;
817 struct acpi_resource *resource;
821 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
822 pnpacpi_count_resources, &res_cnt);
823 if (ACPI_FAILURE(status)) {
824 dev_err(&dev->dev, "can't evaluate _CRS\n");
829 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
830 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
831 if (!buffer->pointer)
834 resource = (struct acpi_resource *)buffer->pointer;
835 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
836 pnpacpi_type_resources, &resource);
837 if (ACPI_FAILURE(status)) {
838 kfree(buffer->pointer);
839 dev_err(&dev->dev, "can't evaluate _CRS\n");
842 /* resource will pointer the end resource now */
843 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
848 static void pnpacpi_encode_irq(struct pnp_dev *dev,
849 struct acpi_resource *resource,
852 struct acpi_resource_irq *irq = &resource->data.irq;
853 int triggering, polarity;
855 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
856 irq->triggering = triggering;
857 irq->polarity = polarity;
858 if (triggering == ACPI_EDGE_SENSITIVE)
859 irq->sharable = ACPI_EXCLUSIVE;
861 irq->sharable = ACPI_SHARED;
862 irq->interrupt_count = 1;
863 irq->interrupts[0] = p->start;
865 dev_dbg(&dev->dev, " encode irq %d %s %s %s\n", (int) p->start,
866 triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
867 polarity == ACPI_ACTIVE_LOW ? "low" : "high",
868 irq->sharable == ACPI_SHARED ? "shared" : "exclusive");
871 static void pnpacpi_encode_ext_irq(struct pnp_dev *dev,
872 struct acpi_resource *resource,
875 struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq;
876 int triggering, polarity;
878 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
879 extended_irq->producer_consumer = ACPI_CONSUMER;
880 extended_irq->triggering = triggering;
881 extended_irq->polarity = polarity;
882 if (triggering == ACPI_EDGE_SENSITIVE)
883 extended_irq->sharable = ACPI_EXCLUSIVE;
885 extended_irq->sharable = ACPI_SHARED;
886 extended_irq->interrupt_count = 1;
887 extended_irq->interrupts[0] = p->start;
889 dev_dbg(&dev->dev, " encode irq %d %s %s %s\n", (int) p->start,
890 triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
891 polarity == ACPI_ACTIVE_LOW ? "low" : "high",
892 extended_irq->sharable == ACPI_SHARED ? "shared" : "exclusive");
895 static void pnpacpi_encode_dma(struct pnp_dev *dev,
896 struct acpi_resource *resource,
899 struct acpi_resource_dma *dma = &resource->data.dma;
901 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
902 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
903 case IORESOURCE_DMA_TYPEA:
904 dma->type = ACPI_TYPE_A;
906 case IORESOURCE_DMA_TYPEB:
907 dma->type = ACPI_TYPE_B;
909 case IORESOURCE_DMA_TYPEF:
910 dma->type = ACPI_TYPE_F;
913 dma->type = ACPI_COMPATIBILITY;
916 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
917 case IORESOURCE_DMA_8BIT:
918 dma->transfer = ACPI_TRANSFER_8;
920 case IORESOURCE_DMA_8AND16BIT:
921 dma->transfer = ACPI_TRANSFER_8_16;
924 dma->transfer = ACPI_TRANSFER_16;
927 dma->bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
928 dma->channel_count = 1;
929 dma->channels[0] = p->start;
931 dev_dbg(&dev->dev, " encode dma %d "
932 "type %#x transfer %#x master %d\n",
933 (int) p->start, dma->type, dma->transfer, dma->bus_master);
936 static void pnpacpi_encode_io(struct pnp_dev *dev,
937 struct acpi_resource *resource,
940 struct acpi_resource_io *io = &resource->data.io;
942 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
943 io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
944 ACPI_DECODE_16 : ACPI_DECODE_10;
945 io->minimum = p->start;
946 io->maximum = p->end;
947 io->alignment = 0; /* Correct? */
948 io->address_length = p->end - p->start + 1;
950 dev_dbg(&dev->dev, " encode io %#llx-%#llx decode %#x\n",
951 (unsigned long long) p->start, (unsigned long long) p->end,
955 static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,
956 struct acpi_resource *resource,
959 struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io;
961 fixed_io->address = p->start;
962 fixed_io->address_length = p->end - p->start + 1;
964 dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n",
965 (unsigned long long) p->start, (unsigned long long) p->end);
968 static void pnpacpi_encode_mem24(struct pnp_dev *dev,
969 struct acpi_resource *resource,
972 struct acpi_resource_memory24 *memory24 = &resource->data.memory24;
974 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
975 memory24->write_protect =
976 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
977 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
978 memory24->minimum = p->start;
979 memory24->maximum = p->end;
980 memory24->alignment = 0;
981 memory24->address_length = p->end - p->start + 1;
983 dev_dbg(&dev->dev, " encode mem24 %#llx-%#llx write_protect %#x\n",
984 (unsigned long long) p->start, (unsigned long long) p->end,
985 memory24->write_protect);
988 static void pnpacpi_encode_mem32(struct pnp_dev *dev,
989 struct acpi_resource *resource,
992 struct acpi_resource_memory32 *memory32 = &resource->data.memory32;
994 memory32->write_protect =
995 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
996 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
997 memory32->minimum = p->start;
998 memory32->maximum = p->end;
999 memory32->alignment = 0;
1000 memory32->address_length = p->end - p->start + 1;
1002 dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx write_protect %#x\n",
1003 (unsigned long long) p->start, (unsigned long long) p->end,
1004 memory32->write_protect);
1007 static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev,
1008 struct acpi_resource *resource,
1011 struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32;
1013 fixed_memory32->write_protect =
1014 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
1015 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
1016 fixed_memory32->address = p->start;
1017 fixed_memory32->address_length = p->end - p->start + 1;
1019 dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx "
1020 "write_protect %#x\n",
1021 (unsigned long long) p->start, (unsigned long long) p->end,
1022 fixed_memory32->write_protect);
1025 int pnpacpi_encode_resources(struct pnp_dev *dev, struct acpi_buffer *buffer)
1028 /* pnpacpi_build_resource_template allocates extra mem */
1029 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
1030 struct acpi_resource *resource = buffer->pointer;
1031 int port = 0, irq = 0, dma = 0, mem = 0;
1033 dev_dbg(&dev->dev, "encode %d resources\n", res_cnt);
1034 while (i < res_cnt) {
1035 switch (resource->type) {
1036 case ACPI_RESOURCE_TYPE_IRQ:
1037 pnpacpi_encode_irq(dev, resource,
1038 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
1042 case ACPI_RESOURCE_TYPE_DMA:
1043 pnpacpi_encode_dma(dev, resource,
1044 pnp_get_resource(dev, IORESOURCE_DMA, dma));
1047 case ACPI_RESOURCE_TYPE_IO:
1048 pnpacpi_encode_io(dev, resource,
1049 pnp_get_resource(dev, IORESOURCE_IO, port));
1052 case ACPI_RESOURCE_TYPE_FIXED_IO:
1053 pnpacpi_encode_fixed_io(dev, resource,
1054 pnp_get_resource(dev, IORESOURCE_IO, port));
1057 case ACPI_RESOURCE_TYPE_MEMORY24:
1058 pnpacpi_encode_mem24(dev, resource,
1059 pnp_get_resource(dev, IORESOURCE_MEM, mem));
1062 case ACPI_RESOURCE_TYPE_MEMORY32:
1063 pnpacpi_encode_mem32(dev, resource,
1064 pnp_get_resource(dev, IORESOURCE_MEM, mem));
1067 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
1068 pnpacpi_encode_fixed_mem32(dev, resource,
1069 pnp_get_resource(dev, IORESOURCE_MEM, mem));
1072 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
1073 pnpacpi_encode_ext_irq(dev, resource,
1074 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
1077 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
1078 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
1079 case ACPI_RESOURCE_TYPE_VENDOR:
1080 case ACPI_RESOURCE_TYPE_END_TAG:
1081 case ACPI_RESOURCE_TYPE_ADDRESS16:
1082 case ACPI_RESOURCE_TYPE_ADDRESS32:
1083 case ACPI_RESOURCE_TYPE_ADDRESS64:
1084 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
1085 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
1086 default: /* other type */
1087 dev_warn(&dev->dev, "can't encode unknown resource "
1088 "type %d\n", resource->type);