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)
82 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
88 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
89 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
90 irq = acpi_register_gsi(gsi, triggering, polarity);
92 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
97 res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
99 res->irq_resource[i].start = irq;
100 res->irq_resource[i].end = irq;
101 pcibios_penalize_isa_irq(irq, 1);
104 static int dma_flags(int type, int bus_master, int transfer)
109 flags |= IORESOURCE_DMA_MASTER;
111 case ACPI_COMPATIBILITY:
112 flags |= IORESOURCE_DMA_COMPATIBLE;
115 flags |= IORESOURCE_DMA_TYPEA;
118 flags |= IORESOURCE_DMA_TYPEB;
121 flags |= IORESOURCE_DMA_TYPEF;
124 /* Set a default value ? */
125 flags |= IORESOURCE_DMA_COMPATIBLE;
126 pnp_err("Invalid DMA type");
129 case ACPI_TRANSFER_8:
130 flags |= IORESOURCE_DMA_8BIT;
132 case ACPI_TRANSFER_8_16:
133 flags |= IORESOURCE_DMA_8AND16BIT;
135 case ACPI_TRANSFER_16:
136 flags |= IORESOURCE_DMA_16BIT;
139 /* Set a default value ? */
140 flags |= IORESOURCE_DMA_8AND16BIT;
141 pnp_err("Invalid DMA transfer type");
147 static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
149 int bus_master, int transfer)
153 while (i < PNP_MAX_DMA &&
154 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
156 if (i < PNP_MAX_DMA) {
157 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
158 res->dma_resource[i].flags |=
159 dma_flags(type, bus_master, transfer);
161 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
164 res->dma_resource[i].start = dma;
165 res->dma_resource[i].end = dma;
169 static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
170 u64 io, u64 len, int io_decode)
174 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
177 if (i < PNP_MAX_PORT) {
178 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
179 if (io_decode == ACPI_DECODE_16)
180 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
181 if (len <= 0 || (io + len - 1) >= 0x10003) {
182 res->port_resource[i].flags |= IORESOURCE_DISABLED;
185 res->port_resource[i].start = io;
186 res->port_resource[i].end = io + len - 1;
190 static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
196 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
199 if (i < PNP_MAX_MEM) {
200 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
202 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
205 if (write_protect == ACPI_READ_WRITE_MEMORY)
206 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
208 res->mem_resource[i].start = mem;
209 res->mem_resource[i].end = mem + len - 1;
213 static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
214 struct acpi_resource *res)
216 struct acpi_resource_address64 addr, *p = &addr;
219 status = acpi_resource_to_address64(res, p);
220 if (!ACPI_SUCCESS(status)) {
221 pnp_warn("PnPACPI: failed to convert resource type %d",
226 if (p->producer_consumer == ACPI_PRODUCER)
229 if (p->resource_type == ACPI_MEMORY_RANGE)
230 pnpacpi_parse_allocated_memresource(res_table,
231 p->minimum, p->address_length,
232 p->info.mem.write_protect);
233 else if (p->resource_type == ACPI_IO_RANGE)
234 pnpacpi_parse_allocated_ioresource(res_table,
235 p->minimum, p->address_length,
236 p->granularity == 0xfff ? ACPI_DECODE_10 :
240 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
243 struct pnp_resource_table *res_table = data;
247 case ACPI_RESOURCE_TYPE_IRQ:
249 * Per spec, only one interrupt per descriptor is allowed in
250 * _CRS, but some firmware violates this, so parse them all.
252 for (i = 0; i < res->data.irq.interrupt_count; i++) {
253 pnpacpi_parse_allocated_irqresource(res_table,
254 res->data.irq.interrupts[i],
255 res->data.irq.triggering,
256 res->data.irq.polarity,
257 res->data.irq.sharable);
261 case ACPI_RESOURCE_TYPE_DMA:
262 if (res->data.dma.channel_count > 0)
263 pnpacpi_parse_allocated_dmaresource(res_table,
264 res->data.dma.channels[0],
266 res->data.dma.bus_master,
267 res->data.dma.transfer);
270 case ACPI_RESOURCE_TYPE_IO:
271 pnpacpi_parse_allocated_ioresource(res_table,
272 res->data.io.minimum,
273 res->data.io.address_length,
274 res->data.io.io_decode);
277 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
278 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
281 case ACPI_RESOURCE_TYPE_FIXED_IO:
282 pnpacpi_parse_allocated_ioresource(res_table,
283 res->data.fixed_io.address,
284 res->data.fixed_io.address_length,
288 case ACPI_RESOURCE_TYPE_VENDOR:
291 case ACPI_RESOURCE_TYPE_END_TAG:
294 case ACPI_RESOURCE_TYPE_MEMORY24:
295 pnpacpi_parse_allocated_memresource(res_table,
296 res->data.memory24.minimum,
297 res->data.memory24.address_length,
298 res->data.memory24.write_protect);
300 case ACPI_RESOURCE_TYPE_MEMORY32:
301 pnpacpi_parse_allocated_memresource(res_table,
302 res->data.memory32.minimum,
303 res->data.memory32.address_length,
304 res->data.memory32.write_protect);
306 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
307 pnpacpi_parse_allocated_memresource(res_table,
308 res->data.fixed_memory32.address,
309 res->data.fixed_memory32.address_length,
310 res->data.fixed_memory32.write_protect);
312 case ACPI_RESOURCE_TYPE_ADDRESS16:
313 case ACPI_RESOURCE_TYPE_ADDRESS32:
314 case ACPI_RESOURCE_TYPE_ADDRESS64:
315 pnpacpi_parse_allocated_address_space(res_table, res);
318 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
319 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
323 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
324 if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
327 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
328 pnpacpi_parse_allocated_irqresource(res_table,
329 res->data.extended_irq.interrupts[i],
330 res->data.extended_irq.triggering,
331 res->data.extended_irq.polarity,
332 res->data.extended_irq.sharable);
336 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
340 pnp_warn("PnPACPI: unknown resource type %d", res->type);
347 acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
348 struct pnp_resource_table * res)
350 /* Blank the resource table values */
351 pnp_init_resource_table(res);
353 return acpi_walk_resources(handle, METHOD_NAME__CRS,
354 pnpacpi_allocated_resource, res);
357 static void pnpacpi_parse_dma_option(struct pnp_option *option,
358 struct acpi_resource_dma *p)
363 if (p->channel_count == 0)
365 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
369 for (i = 0; i < p->channel_count; i++)
370 dma->map |= 1 << p->channels[i];
372 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
374 pnp_register_dma_resource(option, dma);
377 static void pnpacpi_parse_irq_option(struct pnp_option *option,
378 struct acpi_resource_irq *p)
383 if (p->interrupt_count == 0)
385 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
389 for (i = 0; i < p->interrupt_count; i++)
390 if (p->interrupts[i])
391 __set_bit(p->interrupts[i], irq->map);
392 irq->flags = irq_flags(p->triggering, p->polarity);
394 pnp_register_irq_resource(option, irq);
397 static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
398 struct acpi_resource_extended_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);
414 pnp_register_irq_resource(option, irq);
417 static void pnpacpi_parse_port_option(struct pnp_option *option,
418 struct acpi_resource_io *io)
420 struct pnp_port *port;
422 if (io->address_length == 0)
424 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
427 port->min = io->minimum;
428 port->max = io->maximum;
429 port->align = io->alignment;
430 port->size = io->address_length;
431 port->flags = ACPI_DECODE_16 == io->io_decode ?
432 PNP_PORT_FLAG_16BITADDR : 0;
433 pnp_register_port_resource(option, port);
436 static void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
437 struct acpi_resource_fixed_io *io)
439 struct pnp_port *port;
441 if (io->address_length == 0)
443 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
446 port->min = port->max = io->address;
447 port->size = io->address_length;
449 port->flags = PNP_PORT_FLAG_FIXED;
450 pnp_register_port_resource(option, port);
453 static void pnpacpi_parse_mem24_option(struct pnp_option *option,
454 struct acpi_resource_memory24 *p)
458 if (p->address_length == 0)
460 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
463 mem->min = p->minimum;
464 mem->max = p->maximum;
465 mem->align = p->alignment;
466 mem->size = p->address_length;
468 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
469 IORESOURCE_MEM_WRITEABLE : 0;
471 pnp_register_mem_resource(option, mem);
474 static void pnpacpi_parse_mem32_option(struct pnp_option *option,
475 struct acpi_resource_memory32 *p)
479 if (p->address_length == 0)
481 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
484 mem->min = p->minimum;
485 mem->max = p->maximum;
486 mem->align = p->alignment;
487 mem->size = p->address_length;
489 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
490 IORESOURCE_MEM_WRITEABLE : 0;
492 pnp_register_mem_resource(option, mem);
495 static void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
496 struct acpi_resource_fixed_memory32 *p)
500 if (p->address_length == 0)
502 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
505 mem->min = mem->max = p->address;
506 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(option, mem);
515 static void pnpacpi_parse_address_option(struct pnp_option *option,
516 struct acpi_resource *r)
518 struct acpi_resource_address64 addr, *p = &addr;
521 struct pnp_port *port;
523 status = acpi_resource_to_address64(r, p);
524 if (!ACPI_SUCCESS(status)) {
525 pnp_warn("PnPACPI: failed to convert resource type %d",
530 if (p->address_length == 0)
533 if (p->resource_type == ACPI_MEMORY_RANGE) {
534 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
537 mem->min = mem->max = p->minimum;
538 mem->size = p->address_length;
540 mem->flags = (p->info.mem.write_protect ==
541 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
543 pnp_register_mem_resource(option, mem);
544 } else if (p->resource_type == ACPI_IO_RANGE) {
545 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
548 port->min = port->max = p->minimum;
549 port->size = p->address_length;
551 port->flags = PNP_PORT_FLAG_FIXED;
552 pnp_register_port_resource(option, port);
556 struct acpipnp_parse_option_s {
557 struct pnp_option *option;
558 struct pnp_option *option_independent;
562 static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
566 struct acpipnp_parse_option_s *parse_data = data;
567 struct pnp_dev *dev = parse_data->dev;
568 struct pnp_option *option = parse_data->option;
571 case ACPI_RESOURCE_TYPE_IRQ:
572 pnpacpi_parse_irq_option(option, &res->data.irq);
575 case ACPI_RESOURCE_TYPE_DMA:
576 pnpacpi_parse_dma_option(option, &res->data.dma);
579 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
580 switch (res->data.start_dpf.compatibility_priority) {
581 case ACPI_GOOD_CONFIGURATION:
582 priority = PNP_RES_PRIORITY_PREFERRED;
585 case ACPI_ACCEPTABLE_CONFIGURATION:
586 priority = PNP_RES_PRIORITY_ACCEPTABLE;
589 case ACPI_SUB_OPTIMAL_CONFIGURATION:
590 priority = PNP_RES_PRIORITY_FUNCTIONAL;
593 priority = PNP_RES_PRIORITY_INVALID;
596 /* TBD: Consider performance/robustness bits */
597 option = pnp_register_dependent_option(dev, priority);
600 parse_data->option = option;
603 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
604 /*only one EndDependentFn is allowed */
605 if (!parse_data->option_independent) {
606 pnp_warn("PnPACPI: more than one EndDependentFn");
609 parse_data->option = parse_data->option_independent;
610 parse_data->option_independent = NULL;
613 case ACPI_RESOURCE_TYPE_IO:
614 pnpacpi_parse_port_option(option, &res->data.io);
617 case ACPI_RESOURCE_TYPE_FIXED_IO:
618 pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io);
621 case ACPI_RESOURCE_TYPE_VENDOR:
622 case ACPI_RESOURCE_TYPE_END_TAG:
625 case ACPI_RESOURCE_TYPE_MEMORY24:
626 pnpacpi_parse_mem24_option(option, &res->data.memory24);
629 case ACPI_RESOURCE_TYPE_MEMORY32:
630 pnpacpi_parse_mem32_option(option, &res->data.memory32);
633 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
634 pnpacpi_parse_fixed_mem32_option(option,
635 &res->data.fixed_memory32);
638 case ACPI_RESOURCE_TYPE_ADDRESS16:
639 case ACPI_RESOURCE_TYPE_ADDRESS32:
640 case ACPI_RESOURCE_TYPE_ADDRESS64:
641 pnpacpi_parse_address_option(option, res);
644 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
647 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
648 pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq);
651 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
655 pnp_warn("PnPACPI: unknown resource type %d", res->type);
662 acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
663 struct pnp_dev * dev)
666 struct acpipnp_parse_option_s parse_data;
668 parse_data.option = pnp_register_independent_option(dev);
669 if (!parse_data.option)
671 parse_data.option_independent = parse_data.option;
672 parse_data.dev = dev;
673 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
674 pnpacpi_option_resource, &parse_data);
679 static int pnpacpi_supported_resource(struct acpi_resource *res)
682 case ACPI_RESOURCE_TYPE_IRQ:
683 case ACPI_RESOURCE_TYPE_DMA:
684 case ACPI_RESOURCE_TYPE_IO:
685 case ACPI_RESOURCE_TYPE_FIXED_IO:
686 case ACPI_RESOURCE_TYPE_MEMORY24:
687 case ACPI_RESOURCE_TYPE_MEMORY32:
688 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
689 case ACPI_RESOURCE_TYPE_ADDRESS16:
690 case ACPI_RESOURCE_TYPE_ADDRESS32:
691 case ACPI_RESOURCE_TYPE_ADDRESS64:
692 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
701 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
706 if (pnpacpi_supported_resource(res))
711 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
713 struct acpi_resource **resource = data;
715 if (pnpacpi_supported_resource(res)) {
716 (*resource)->type = res->type;
717 (*resource)->length = sizeof(struct acpi_resource);
724 int pnpacpi_build_resource_template(acpi_handle handle,
725 struct acpi_buffer *buffer)
727 struct acpi_resource *resource;
731 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
732 pnpacpi_count_resources, &res_cnt);
733 if (ACPI_FAILURE(status)) {
734 pnp_err("Evaluate _CRS failed");
739 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
740 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
741 if (!buffer->pointer)
743 pnp_dbg("Res cnt %d", res_cnt);
744 resource = (struct acpi_resource *)buffer->pointer;
745 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
746 pnpacpi_type_resources, &resource);
747 if (ACPI_FAILURE(status)) {
748 kfree(buffer->pointer);
749 pnp_err("Evaluate _CRS failed");
752 /* resource will pointer the end resource now */
753 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
758 static void pnpacpi_encode_irq(struct acpi_resource *resource,
761 int triggering, polarity;
763 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
764 resource->data.irq.triggering = triggering;
765 resource->data.irq.polarity = polarity;
766 if (triggering == ACPI_EDGE_SENSITIVE)
767 resource->data.irq.sharable = ACPI_EXCLUSIVE;
769 resource->data.irq.sharable = ACPI_SHARED;
770 resource->data.irq.interrupt_count = 1;
771 resource->data.irq.interrupts[0] = p->start;
774 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
777 int triggering, polarity;
779 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
780 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
781 resource->data.extended_irq.triggering = triggering;
782 resource->data.extended_irq.polarity = polarity;
783 if (triggering == ACPI_EDGE_SENSITIVE)
784 resource->data.irq.sharable = ACPI_EXCLUSIVE;
786 resource->data.irq.sharable = ACPI_SHARED;
787 resource->data.extended_irq.interrupt_count = 1;
788 resource->data.extended_irq.interrupts[0] = p->start;
791 static void pnpacpi_encode_dma(struct acpi_resource *resource,
794 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
795 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
796 case IORESOURCE_DMA_TYPEA:
797 resource->data.dma.type = ACPI_TYPE_A;
799 case IORESOURCE_DMA_TYPEB:
800 resource->data.dma.type = ACPI_TYPE_B;
802 case IORESOURCE_DMA_TYPEF:
803 resource->data.dma.type = ACPI_TYPE_F;
806 resource->data.dma.type = ACPI_COMPATIBILITY;
809 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
810 case IORESOURCE_DMA_8BIT:
811 resource->data.dma.transfer = ACPI_TRANSFER_8;
813 case IORESOURCE_DMA_8AND16BIT:
814 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
817 resource->data.dma.transfer = ACPI_TRANSFER_16;
820 resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
821 resource->data.dma.channel_count = 1;
822 resource->data.dma.channels[0] = p->start;
825 static void pnpacpi_encode_io(struct acpi_resource *resource,
828 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
829 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
830 ACPI_DECODE_16 : ACPI_DECODE_10;
831 resource->data.io.minimum = p->start;
832 resource->data.io.maximum = p->end;
833 resource->data.io.alignment = 0; /* Correct? */
834 resource->data.io.address_length = p->end - p->start + 1;
837 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
840 resource->data.fixed_io.address = p->start;
841 resource->data.fixed_io.address_length = p->end - p->start + 1;
844 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
847 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
848 resource->data.memory24.write_protect =
849 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
850 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
851 resource->data.memory24.minimum = p->start;
852 resource->data.memory24.maximum = p->end;
853 resource->data.memory24.alignment = 0;
854 resource->data.memory24.address_length = p->end - p->start + 1;
857 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
860 resource->data.memory32.write_protect =
861 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
862 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
863 resource->data.memory32.minimum = p->start;
864 resource->data.memory32.maximum = p->end;
865 resource->data.memory32.alignment = 0;
866 resource->data.memory32.address_length = p->end - p->start + 1;
869 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
872 resource->data.fixed_memory32.write_protect =
873 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
874 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
875 resource->data.fixed_memory32.address = p->start;
876 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
879 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
880 struct acpi_buffer *buffer)
883 /* pnpacpi_build_resource_template allocates extra mem */
884 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
885 struct acpi_resource *resource = buffer->pointer;
886 int port = 0, irq = 0, dma = 0, mem = 0;
888 pnp_dbg("res cnt %d", res_cnt);
889 while (i < res_cnt) {
890 switch (resource->type) {
891 case ACPI_RESOURCE_TYPE_IRQ:
892 pnp_dbg("Encode irq");
893 pnpacpi_encode_irq(resource,
894 &res_table->irq_resource[irq]);
898 case ACPI_RESOURCE_TYPE_DMA:
899 pnp_dbg("Encode dma");
900 pnpacpi_encode_dma(resource,
901 &res_table->dma_resource[dma]);
904 case ACPI_RESOURCE_TYPE_IO:
905 pnp_dbg("Encode io");
906 pnpacpi_encode_io(resource,
907 &res_table->port_resource[port]);
910 case ACPI_RESOURCE_TYPE_FIXED_IO:
911 pnp_dbg("Encode fixed io");
912 pnpacpi_encode_fixed_io(resource,
914 port_resource[port]);
917 case ACPI_RESOURCE_TYPE_MEMORY24:
918 pnp_dbg("Encode mem24");
919 pnpacpi_encode_mem24(resource,
920 &res_table->mem_resource[mem]);
923 case ACPI_RESOURCE_TYPE_MEMORY32:
924 pnp_dbg("Encode mem32");
925 pnpacpi_encode_mem32(resource,
926 &res_table->mem_resource[mem]);
929 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
930 pnp_dbg("Encode fixed mem32");
931 pnpacpi_encode_fixed_mem32(resource,
936 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
937 pnp_dbg("Encode ext irq");
938 pnpacpi_encode_ext_irq(resource,
939 &res_table->irq_resource[irq]);
942 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
943 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
944 case ACPI_RESOURCE_TYPE_VENDOR:
945 case ACPI_RESOURCE_TYPE_END_TAG:
946 case ACPI_RESOURCE_TYPE_ADDRESS16:
947 case ACPI_RESOURCE_TYPE_ADDRESS32:
948 case ACPI_RESOURCE_TYPE_ADDRESS64:
949 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
950 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
951 default: /* other type */
952 pnp_warn("unknown resource type %d", resource->type);