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(struct pnp_dev *dev, int flags, int *triggering,
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;
89 static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
90 u32 gsi, int triggering,
91 int polarity, int shareable)
100 * in IO-APIC mode, use overrided attribute. Two reasons:
101 * 1. BIOS bug in DSDT
102 * 2. BIOS uses IO-APIC mode Interrupt Source Override
104 if (!acpi_get_override_irq(gsi, &t, &p)) {
105 t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
106 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
108 if (triggering != t || polarity != p) {
109 dev_warn(&dev->dev, "IRQ %d override to %s, %s\n",
110 gsi, t ? "edge":"level", p ? "low":"high");
116 flags = irq_flags(triggering, polarity, shareable);
117 irq = acpi_register_gsi(gsi, triggering, polarity);
119 pcibios_penalize_isa_irq(irq, 1);
121 flags |= IORESOURCE_DISABLED;
123 pnp_add_irq_resource(dev, irq, flags);
126 static int dma_flags(int type, int bus_master, int transfer)
131 flags |= IORESOURCE_DMA_MASTER;
133 case ACPI_COMPATIBILITY:
134 flags |= IORESOURCE_DMA_COMPATIBLE;
137 flags |= IORESOURCE_DMA_TYPEA;
140 flags |= IORESOURCE_DMA_TYPEB;
143 flags |= IORESOURCE_DMA_TYPEF;
146 /* Set a default value ? */
147 flags |= IORESOURCE_DMA_COMPATIBLE;
148 pnp_err("Invalid DMA type");
151 case ACPI_TRANSFER_8:
152 flags |= IORESOURCE_DMA_8BIT;
154 case ACPI_TRANSFER_8_16:
155 flags |= IORESOURCE_DMA_8AND16BIT;
157 case ACPI_TRANSFER_16:
158 flags |= IORESOURCE_DMA_16BIT;
161 /* Set a default value ? */
162 flags |= IORESOURCE_DMA_8AND16BIT;
163 pnp_err("Invalid DMA transfer type");
169 static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start,
170 u64 len, int io_decode)
173 u64 end = start + len - 1;
175 if (io_decode == ACPI_DECODE_16)
176 flags |= PNP_PORT_FLAG_16BITADDR;
177 if (len == 0 || end >= 0x10003)
178 flags |= IORESOURCE_DISABLED;
180 pnp_add_io_resource(dev, start, end, flags);
183 static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
188 u64 end = start + len - 1;
191 flags |= IORESOURCE_DISABLED;
192 if (write_protect == ACPI_READ_WRITE_MEMORY)
193 flags |= IORESOURCE_MEM_WRITEABLE;
195 pnp_add_mem_resource(dev, start, end, flags);
198 static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev,
199 struct acpi_resource *res)
201 struct acpi_resource_address64 addr, *p = &addr;
204 status = acpi_resource_to_address64(res, p);
205 if (!ACPI_SUCCESS(status)) {
206 dev_warn(&dev->dev, "failed to convert resource type %d\n",
211 if (p->producer_consumer == ACPI_PRODUCER)
214 if (p->resource_type == ACPI_MEMORY_RANGE)
215 pnpacpi_parse_allocated_memresource(dev,
216 p->minimum, p->address_length,
217 p->info.mem.write_protect);
218 else if (p->resource_type == ACPI_IO_RANGE)
219 pnpacpi_parse_allocated_ioresource(dev,
220 p->minimum, p->address_length,
221 p->granularity == 0xfff ? ACPI_DECODE_10 :
225 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
228 struct pnp_dev *dev = data;
229 struct acpi_resource_irq *irq;
230 struct acpi_resource_dma *dma;
231 struct acpi_resource_io *io;
232 struct acpi_resource_fixed_io *fixed_io;
233 struct acpi_resource_memory24 *memory24;
234 struct acpi_resource_memory32 *memory32;
235 struct acpi_resource_fixed_memory32 *fixed_memory32;
236 struct acpi_resource_extended_irq *extended_irq;
240 case ACPI_RESOURCE_TYPE_IRQ:
242 * Per spec, only one interrupt per descriptor is allowed in
243 * _CRS, but some firmware violates this, so parse them all.
245 irq = &res->data.irq;
246 for (i = 0; i < irq->interrupt_count; i++) {
247 pnpacpi_parse_allocated_irqresource(dev,
255 case ACPI_RESOURCE_TYPE_DMA:
256 dma = &res->data.dma;
257 if (dma->channel_count > 0) {
258 flags = dma_flags(dma->type, dma->bus_master,
260 if (dma->channels[0] == (u8) -1)
261 flags |= IORESOURCE_DISABLED;
262 pnp_add_dma_resource(dev, dma->channels[0], flags);
266 case ACPI_RESOURCE_TYPE_IO:
268 pnpacpi_parse_allocated_ioresource(dev,
274 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
275 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
278 case ACPI_RESOURCE_TYPE_FIXED_IO:
279 fixed_io = &res->data.fixed_io;
280 pnpacpi_parse_allocated_ioresource(dev,
282 fixed_io->address_length,
286 case ACPI_RESOURCE_TYPE_VENDOR:
289 case ACPI_RESOURCE_TYPE_END_TAG:
292 case ACPI_RESOURCE_TYPE_MEMORY24:
293 memory24 = &res->data.memory24;
294 pnpacpi_parse_allocated_memresource(dev,
296 memory24->address_length,
297 memory24->write_protect);
299 case ACPI_RESOURCE_TYPE_MEMORY32:
300 memory32 = &res->data.memory32;
301 pnpacpi_parse_allocated_memresource(dev,
303 memory32->address_length,
304 memory32->write_protect);
306 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
307 fixed_memory32 = &res->data.fixed_memory32;
308 pnpacpi_parse_allocated_memresource(dev,
309 fixed_memory32->address,
310 fixed_memory32->address_length,
311 fixed_memory32->write_protect);
313 case ACPI_RESOURCE_TYPE_ADDRESS16:
314 case ACPI_RESOURCE_TYPE_ADDRESS32:
315 case ACPI_RESOURCE_TYPE_ADDRESS64:
316 pnpacpi_parse_allocated_address_space(dev, res);
319 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
320 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
324 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
325 extended_irq = &res->data.extended_irq;
326 if (extended_irq->producer_consumer == ACPI_PRODUCER)
329 for (i = 0; i < extended_irq->interrupt_count; i++) {
330 pnpacpi_parse_allocated_irqresource(dev,
331 extended_irq->interrupts[i],
332 extended_irq->triggering,
333 extended_irq->polarity,
334 extended_irq->sharable);
338 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
342 dev_warn(&dev->dev, "unknown resource type %d in _CRS\n",
350 int pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
352 acpi_handle handle = dev->data;
355 dev_dbg(&dev->dev, "parse allocated resources\n");
357 pnp_init_resources(dev);
359 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
360 pnpacpi_allocated_resource, dev);
362 if (ACPI_FAILURE(status)) {
363 if (status != AE_NOT_FOUND)
364 dev_err(&dev->dev, "can't evaluate _CRS: %d", status);
370 static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev,
371 struct pnp_option *option,
372 struct acpi_resource_dma *p)
377 if (p->channel_count == 0)
379 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
383 for (i = 0; i < p->channel_count; i++)
384 dma->map |= 1 << p->channels[i];
386 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
388 pnp_register_dma_resource(dev, option, dma);
391 static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev,
392 struct pnp_option *option,
393 struct acpi_resource_irq *p)
398 if (p->interrupt_count == 0)
400 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
404 for (i = 0; i < p->interrupt_count; i++)
405 if (p->interrupts[i])
406 __set_bit(p->interrupts[i], irq->map);
407 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
409 pnp_register_irq_resource(dev, option, irq);
412 static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,
413 struct pnp_option *option,
414 struct acpi_resource_extended_irq *p)
419 if (p->interrupt_count == 0)
421 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
425 for (i = 0; i < p->interrupt_count; i++)
426 if (p->interrupts[i])
427 __set_bit(p->interrupts[i], irq->map);
428 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
430 pnp_register_irq_resource(dev, option, irq);
433 static __init void pnpacpi_parse_port_option(struct pnp_dev *dev,
434 struct pnp_option *option,
435 struct acpi_resource_io *io)
437 struct pnp_port *port;
439 if (io->address_length == 0)
441 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
444 port->min = io->minimum;
445 port->max = io->maximum;
446 port->align = io->alignment;
447 port->size = io->address_length;
448 port->flags = ACPI_DECODE_16 == io->io_decode ?
449 PNP_PORT_FLAG_16BITADDR : 0;
450 pnp_register_port_resource(dev, option, port);
453 static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev,
454 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(dev, option, port);
471 static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev,
472 struct pnp_option *option,
473 struct acpi_resource_memory24 *p)
477 if (p->address_length == 0)
479 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
482 mem->min = p->minimum;
483 mem->max = p->maximum;
484 mem->align = p->alignment;
485 mem->size = p->address_length;
487 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
488 IORESOURCE_MEM_WRITEABLE : 0;
490 pnp_register_mem_resource(dev, option, mem);
493 static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev,
494 struct pnp_option *option,
495 struct acpi_resource_memory32 *p)
499 if (p->address_length == 0)
501 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
504 mem->min = p->minimum;
505 mem->max = p->maximum;
506 mem->align = p->alignment;
507 mem->size = p->address_length;
509 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
510 IORESOURCE_MEM_WRITEABLE : 0;
512 pnp_register_mem_resource(dev, option, mem);
515 static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev,
516 struct pnp_option *option,
517 struct acpi_resource_fixed_memory32 *p)
521 if (p->address_length == 0)
523 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
526 mem->min = mem->max = p->address;
527 mem->size = p->address_length;
530 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
531 IORESOURCE_MEM_WRITEABLE : 0;
533 pnp_register_mem_resource(dev, option, mem);
536 static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,
537 struct pnp_option *option,
538 struct acpi_resource *r)
540 struct acpi_resource_address64 addr, *p = &addr;
543 struct pnp_port *port;
545 status = acpi_resource_to_address64(r, p);
546 if (!ACPI_SUCCESS(status)) {
547 pnp_warn("PnPACPI: failed to convert resource type %d",
552 if (p->address_length == 0)
555 if (p->resource_type == ACPI_MEMORY_RANGE) {
556 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
559 mem->min = mem->max = p->minimum;
560 mem->size = p->address_length;
562 mem->flags = (p->info.mem.write_protect ==
563 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
565 pnp_register_mem_resource(dev, option, mem);
566 } else if (p->resource_type == ACPI_IO_RANGE) {
567 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
570 port->min = port->max = p->minimum;
571 port->size = p->address_length;
573 port->flags = PNP_PORT_FLAG_FIXED;
574 pnp_register_port_resource(dev, option, port);
578 struct acpipnp_parse_option_s {
579 struct pnp_option *option;
580 struct pnp_option *option_independent;
584 static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
588 struct acpipnp_parse_option_s *parse_data = data;
589 struct pnp_dev *dev = parse_data->dev;
590 struct pnp_option *option = parse_data->option;
593 case ACPI_RESOURCE_TYPE_IRQ:
594 pnpacpi_parse_irq_option(dev, option, &res->data.irq);
597 case ACPI_RESOURCE_TYPE_DMA:
598 pnpacpi_parse_dma_option(dev, option, &res->data.dma);
601 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
602 switch (res->data.start_dpf.compatibility_priority) {
603 case ACPI_GOOD_CONFIGURATION:
604 priority = PNP_RES_PRIORITY_PREFERRED;
607 case ACPI_ACCEPTABLE_CONFIGURATION:
608 priority = PNP_RES_PRIORITY_ACCEPTABLE;
611 case ACPI_SUB_OPTIMAL_CONFIGURATION:
612 priority = PNP_RES_PRIORITY_FUNCTIONAL;
615 priority = PNP_RES_PRIORITY_INVALID;
618 /* TBD: Consider performance/robustness bits */
619 option = pnp_register_dependent_option(dev, priority);
622 parse_data->option = option;
625 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
626 /*only one EndDependentFn is allowed */
627 if (!parse_data->option_independent) {
628 dev_warn(&dev->dev, "more than one EndDependentFn "
632 parse_data->option = parse_data->option_independent;
633 parse_data->option_independent = NULL;
634 dev_dbg(&dev->dev, "end dependent options\n");
637 case ACPI_RESOURCE_TYPE_IO:
638 pnpacpi_parse_port_option(dev, option, &res->data.io);
641 case ACPI_RESOURCE_TYPE_FIXED_IO:
642 pnpacpi_parse_fixed_port_option(dev, option,
643 &res->data.fixed_io);
646 case ACPI_RESOURCE_TYPE_VENDOR:
647 case ACPI_RESOURCE_TYPE_END_TAG:
650 case ACPI_RESOURCE_TYPE_MEMORY24:
651 pnpacpi_parse_mem24_option(dev, option, &res->data.memory24);
654 case ACPI_RESOURCE_TYPE_MEMORY32:
655 pnpacpi_parse_mem32_option(dev, option, &res->data.memory32);
658 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
659 pnpacpi_parse_fixed_mem32_option(dev, option,
660 &res->data.fixed_memory32);
663 case ACPI_RESOURCE_TYPE_ADDRESS16:
664 case ACPI_RESOURCE_TYPE_ADDRESS32:
665 case ACPI_RESOURCE_TYPE_ADDRESS64:
666 pnpacpi_parse_address_option(dev, option, res);
669 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
672 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
673 pnpacpi_parse_ext_irq_option(dev, option,
674 &res->data.extended_irq);
677 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
681 dev_warn(&dev->dev, "unknown resource type %d in _PRS\n",
689 int __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev)
691 acpi_handle handle = dev->data;
693 struct acpipnp_parse_option_s parse_data;
695 dev_dbg(&dev->dev, "parse resource options\n");
697 parse_data.option = pnp_register_independent_option(dev);
698 if (!parse_data.option)
701 parse_data.option_independent = parse_data.option;
702 parse_data.dev = dev;
703 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
704 pnpacpi_option_resource, &parse_data);
706 if (ACPI_FAILURE(status)) {
707 if (status != AE_NOT_FOUND)
708 dev_err(&dev->dev, "can't evaluate _PRS: %d", status);
714 static int pnpacpi_supported_resource(struct acpi_resource *res)
717 case ACPI_RESOURCE_TYPE_IRQ:
718 case ACPI_RESOURCE_TYPE_DMA:
719 case ACPI_RESOURCE_TYPE_IO:
720 case ACPI_RESOURCE_TYPE_FIXED_IO:
721 case ACPI_RESOURCE_TYPE_MEMORY24:
722 case ACPI_RESOURCE_TYPE_MEMORY32:
723 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
724 case ACPI_RESOURCE_TYPE_ADDRESS16:
725 case ACPI_RESOURCE_TYPE_ADDRESS32:
726 case ACPI_RESOURCE_TYPE_ADDRESS64:
727 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
736 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
741 if (pnpacpi_supported_resource(res))
746 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
748 struct acpi_resource **resource = data;
750 if (pnpacpi_supported_resource(res)) {
751 (*resource)->type = res->type;
752 (*resource)->length = sizeof(struct acpi_resource);
759 int pnpacpi_build_resource_template(struct pnp_dev *dev,
760 struct acpi_buffer *buffer)
762 acpi_handle handle = dev->data;
763 struct acpi_resource *resource;
767 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
768 pnpacpi_count_resources, &res_cnt);
769 if (ACPI_FAILURE(status)) {
770 dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status);
775 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
776 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
777 if (!buffer->pointer)
780 resource = (struct acpi_resource *)buffer->pointer;
781 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
782 pnpacpi_type_resources, &resource);
783 if (ACPI_FAILURE(status)) {
784 kfree(buffer->pointer);
785 dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status);
788 /* resource will pointer the end resource now */
789 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
794 static void pnpacpi_encode_irq(struct pnp_dev *dev,
795 struct acpi_resource *resource,
798 struct acpi_resource_irq *irq = &resource->data.irq;
799 int triggering, polarity;
801 decode_irq_flags(dev, p->flags, &triggering, &polarity);
802 irq->triggering = triggering;
803 irq->polarity = polarity;
804 if (triggering == ACPI_EDGE_SENSITIVE)
805 irq->sharable = ACPI_EXCLUSIVE;
807 irq->sharable = ACPI_SHARED;
808 irq->interrupt_count = 1;
809 irq->interrupts[0] = p->start;
811 dev_dbg(&dev->dev, " encode irq %d %s %s %s\n", (int) p->start,
812 triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
813 polarity == ACPI_ACTIVE_LOW ? "low" : "high",
814 irq->sharable == ACPI_SHARED ? "shared" : "exclusive");
817 static void pnpacpi_encode_ext_irq(struct pnp_dev *dev,
818 struct acpi_resource *resource,
821 struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq;
822 int triggering, polarity;
824 decode_irq_flags(dev, p->flags, &triggering, &polarity);
825 extended_irq->producer_consumer = ACPI_CONSUMER;
826 extended_irq->triggering = triggering;
827 extended_irq->polarity = polarity;
828 if (triggering == ACPI_EDGE_SENSITIVE)
829 extended_irq->sharable = ACPI_EXCLUSIVE;
831 extended_irq->sharable = ACPI_SHARED;
832 extended_irq->interrupt_count = 1;
833 extended_irq->interrupts[0] = p->start;
835 dev_dbg(&dev->dev, " encode irq %d %s %s %s\n", (int) p->start,
836 triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
837 polarity == ACPI_ACTIVE_LOW ? "low" : "high",
838 extended_irq->sharable == ACPI_SHARED ? "shared" : "exclusive");
841 static void pnpacpi_encode_dma(struct pnp_dev *dev,
842 struct acpi_resource *resource,
845 struct acpi_resource_dma *dma = &resource->data.dma;
847 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
848 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
849 case IORESOURCE_DMA_TYPEA:
850 dma->type = ACPI_TYPE_A;
852 case IORESOURCE_DMA_TYPEB:
853 dma->type = ACPI_TYPE_B;
855 case IORESOURCE_DMA_TYPEF:
856 dma->type = ACPI_TYPE_F;
859 dma->type = ACPI_COMPATIBILITY;
862 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
863 case IORESOURCE_DMA_8BIT:
864 dma->transfer = ACPI_TRANSFER_8;
866 case IORESOURCE_DMA_8AND16BIT:
867 dma->transfer = ACPI_TRANSFER_8_16;
870 dma->transfer = ACPI_TRANSFER_16;
873 dma->bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
874 dma->channel_count = 1;
875 dma->channels[0] = p->start;
877 dev_dbg(&dev->dev, " encode dma %d "
878 "type %#x transfer %#x master %d\n",
879 (int) p->start, dma->type, dma->transfer, dma->bus_master);
882 static void pnpacpi_encode_io(struct pnp_dev *dev,
883 struct acpi_resource *resource,
886 struct acpi_resource_io *io = &resource->data.io;
888 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
889 io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
890 ACPI_DECODE_16 : ACPI_DECODE_10;
891 io->minimum = p->start;
892 io->maximum = p->end;
893 io->alignment = 0; /* Correct? */
894 io->address_length = p->end - p->start + 1;
896 dev_dbg(&dev->dev, " encode io %#llx-%#llx decode %#x\n",
897 (unsigned long long) p->start, (unsigned long long) p->end,
901 static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,
902 struct acpi_resource *resource,
905 struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io;
907 fixed_io->address = p->start;
908 fixed_io->address_length = p->end - p->start + 1;
910 dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n",
911 (unsigned long long) p->start, (unsigned long long) p->end);
914 static void pnpacpi_encode_mem24(struct pnp_dev *dev,
915 struct acpi_resource *resource,
918 struct acpi_resource_memory24 *memory24 = &resource->data.memory24;
920 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
921 memory24->write_protect =
922 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
923 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
924 memory24->minimum = p->start;
925 memory24->maximum = p->end;
926 memory24->alignment = 0;
927 memory24->address_length = p->end - p->start + 1;
929 dev_dbg(&dev->dev, " encode mem24 %#llx-%#llx write_protect %#x\n",
930 (unsigned long long) p->start, (unsigned long long) p->end,
931 memory24->write_protect);
934 static void pnpacpi_encode_mem32(struct pnp_dev *dev,
935 struct acpi_resource *resource,
938 struct acpi_resource_memory32 *memory32 = &resource->data.memory32;
940 memory32->write_protect =
941 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
942 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
943 memory32->minimum = p->start;
944 memory32->maximum = p->end;
945 memory32->alignment = 0;
946 memory32->address_length = p->end - p->start + 1;
948 dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx write_protect %#x\n",
949 (unsigned long long) p->start, (unsigned long long) p->end,
950 memory32->write_protect);
953 static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev,
954 struct acpi_resource *resource,
957 struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32;
959 fixed_memory32->write_protect =
960 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
961 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
962 fixed_memory32->address = p->start;
963 fixed_memory32->address_length = p->end - p->start + 1;
965 dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx "
966 "write_protect %#x\n",
967 (unsigned long long) p->start, (unsigned long long) p->end,
968 fixed_memory32->write_protect);
971 int pnpacpi_encode_resources(struct pnp_dev *dev, struct acpi_buffer *buffer)
974 /* pnpacpi_build_resource_template allocates extra mem */
975 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
976 struct acpi_resource *resource = buffer->pointer;
977 int port = 0, irq = 0, dma = 0, mem = 0;
979 dev_dbg(&dev->dev, "encode %d resources\n", res_cnt);
980 while (i < res_cnt) {
981 switch (resource->type) {
982 case ACPI_RESOURCE_TYPE_IRQ:
983 pnpacpi_encode_irq(dev, resource,
984 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
988 case ACPI_RESOURCE_TYPE_DMA:
989 pnpacpi_encode_dma(dev, resource,
990 pnp_get_resource(dev, IORESOURCE_DMA, dma));
993 case ACPI_RESOURCE_TYPE_IO:
994 pnpacpi_encode_io(dev, resource,
995 pnp_get_resource(dev, IORESOURCE_IO, port));
998 case ACPI_RESOURCE_TYPE_FIXED_IO:
999 pnpacpi_encode_fixed_io(dev, resource,
1000 pnp_get_resource(dev, IORESOURCE_IO, port));
1003 case ACPI_RESOURCE_TYPE_MEMORY24:
1004 pnpacpi_encode_mem24(dev, resource,
1005 pnp_get_resource(dev, IORESOURCE_MEM, mem));
1008 case ACPI_RESOURCE_TYPE_MEMORY32:
1009 pnpacpi_encode_mem32(dev, resource,
1010 pnp_get_resource(dev, IORESOURCE_MEM, mem));
1013 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
1014 pnpacpi_encode_fixed_mem32(dev, resource,
1015 pnp_get_resource(dev, IORESOURCE_MEM, mem));
1018 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
1019 pnpacpi_encode_ext_irq(dev, resource,
1020 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
1023 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
1024 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
1025 case ACPI_RESOURCE_TYPE_VENDOR:
1026 case ACPI_RESOURCE_TYPE_END_TAG:
1027 case ACPI_RESOURCE_TYPE_ADDRESS16:
1028 case ACPI_RESOURCE_TYPE_ADDRESS32:
1029 case ACPI_RESOURCE_TYPE_ADDRESS64:
1030 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
1031 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
1032 default: /* other type */
1033 dev_warn(&dev->dev, "can't encode unknown resource "
1034 "type %d\n", resource->type);