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)
38 if (triggering == ACPI_LEVEL_SENSITIVE) {
39 if (polarity == ACPI_ACTIVE_LOW)
40 flag = IORESOURCE_IRQ_LOWLEVEL;
42 flag = IORESOURCE_IRQ_HIGHLEVEL;
45 if (polarity == ACPI_ACTIVE_LOW)
46 flag = IORESOURCE_IRQ_LOWEDGE;
48 flag = IORESOURCE_IRQ_HIGHEDGE;
53 static void decode_irq_flags(int flag, int *triggering, int *polarity)
56 case IORESOURCE_IRQ_LOWLEVEL:
57 *triggering = ACPI_LEVEL_SENSITIVE;
58 *polarity = ACPI_ACTIVE_LOW;
60 case IORESOURCE_IRQ_HIGHLEVEL:
61 *triggering = ACPI_LEVEL_SENSITIVE;
62 *polarity = ACPI_ACTIVE_HIGH;
64 case IORESOURCE_IRQ_LOWEDGE:
65 *triggering = ACPI_EDGE_SENSITIVE;
66 *polarity = ACPI_ACTIVE_LOW;
68 case IORESOURCE_IRQ_HIGHEDGE:
69 *triggering = ACPI_EDGE_SENSITIVE;
70 *polarity = ACPI_ACTIVE_HIGH;
76 pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, u32 gsi,
77 int triggering, int polarity)
85 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
91 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
92 irq = acpi_register_gsi(gsi, triggering, polarity);
94 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
98 res->irq_resource[i].start = irq;
99 res->irq_resource[i].end = irq;
100 pcibios_penalize_isa_irq(irq, 1);
104 pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, u32 dma)
107 while (i < PNP_MAX_DMA &&
108 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
110 if (i < PNP_MAX_DMA) {
111 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
113 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
116 res->dma_resource[i].start = dma;
117 res->dma_resource[i].end = dma;
122 pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
126 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
129 if (i < PNP_MAX_PORT) {
130 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
131 if (len <= 0 || (io + len -1) >= 0x10003) {
132 res->port_resource[i].flags |= IORESOURCE_DISABLED;
135 res->port_resource[i].start = io;
136 res->port_resource[i].end = io + len - 1;
141 pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
145 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
148 if (i < PNP_MAX_MEM) {
149 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
151 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
154 res->mem_resource[i].start = mem;
155 res->mem_resource[i].end = mem + len - 1;
160 pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
161 struct acpi_resource *res)
163 struct acpi_resource_address64 addr, *p = &addr;
166 status = acpi_resource_to_address64(res, p);
167 if (!ACPI_SUCCESS(status)) {
168 pnp_warn("PnPACPI: failed to convert resource type %d",
173 if (p->resource_type == ACPI_MEMORY_RANGE)
174 pnpacpi_parse_allocated_memresource(res_table,
175 p->minimum, p->address_length);
176 else if (p->resource_type == ACPI_IO_RANGE)
177 pnpacpi_parse_allocated_ioresource(res_table,
178 p->minimum, p->address_length);
181 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
184 struct pnp_resource_table *res_table = (struct pnp_resource_table *)data;
188 case ACPI_RESOURCE_TYPE_IRQ:
190 * Per spec, only one interrupt per descriptor is allowed in
191 * _CRS, but some firmware violates this, so parse them all.
193 for (i = 0; i < res->data.irq.interrupt_count; i++) {
194 pnpacpi_parse_allocated_irqresource(res_table,
195 res->data.irq.interrupts[i],
196 res->data.irq.triggering,
197 res->data.irq.polarity);
201 case ACPI_RESOURCE_TYPE_DMA:
202 if (res->data.dma.channel_count > 0)
203 pnpacpi_parse_allocated_dmaresource(res_table,
204 res->data.dma.channels[0]);
207 case ACPI_RESOURCE_TYPE_IO:
208 pnpacpi_parse_allocated_ioresource(res_table,
209 res->data.io.minimum,
210 res->data.io.address_length);
213 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
214 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
217 case ACPI_RESOURCE_TYPE_FIXED_IO:
218 pnpacpi_parse_allocated_ioresource(res_table,
219 res->data.fixed_io.address,
220 res->data.fixed_io.address_length);
223 case ACPI_RESOURCE_TYPE_VENDOR:
226 case ACPI_RESOURCE_TYPE_END_TAG:
229 case ACPI_RESOURCE_TYPE_MEMORY24:
230 pnpacpi_parse_allocated_memresource(res_table,
231 res->data.memory24.minimum,
232 res->data.memory24.address_length);
234 case ACPI_RESOURCE_TYPE_MEMORY32:
235 pnpacpi_parse_allocated_memresource(res_table,
236 res->data.memory32.minimum,
237 res->data.memory32.address_length);
239 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
240 pnpacpi_parse_allocated_memresource(res_table,
241 res->data.fixed_memory32.address,
242 res->data.fixed_memory32.address_length);
244 case ACPI_RESOURCE_TYPE_ADDRESS16:
245 case ACPI_RESOURCE_TYPE_ADDRESS32:
246 case ACPI_RESOURCE_TYPE_ADDRESS64:
247 pnpacpi_parse_allocated_address_space(res_table, res);
250 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
253 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
254 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
255 pnpacpi_parse_allocated_irqresource(res_table,
256 res->data.extended_irq.interrupts[i],
257 res->data.extended_irq.triggering,
258 res->data.extended_irq.polarity);
262 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
266 pnp_warn("PnPACPI: unknown resource type %d", res->type);
273 acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle, struct pnp_resource_table *res)
275 /* Blank the resource table values */
276 pnp_init_resource_table(res);
278 return acpi_walk_resources(handle, METHOD_NAME__CRS, pnpacpi_allocated_resource, res);
281 static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_resource_dma *p)
284 struct pnp_dma * dma;
286 if (p->channel_count == 0)
288 dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL);
292 for(i = 0; i < p->channel_count; i++)
293 dma->map |= 1 << p->channels[i];
296 dma->flags |= IORESOURCE_DMA_MASTER;
298 case ACPI_COMPATIBILITY:
299 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
302 dma->flags |= IORESOURCE_DMA_TYPEA;
305 dma->flags |= IORESOURCE_DMA_TYPEB;
308 dma->flags |= IORESOURCE_DMA_TYPEF;
311 /* Set a default value ? */
312 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
313 pnp_err("Invalid DMA type");
315 switch (p->transfer) {
316 case ACPI_TRANSFER_8:
317 dma->flags |= IORESOURCE_DMA_8BIT;
319 case ACPI_TRANSFER_8_16:
320 dma->flags |= IORESOURCE_DMA_8AND16BIT;
322 case ACPI_TRANSFER_16:
323 dma->flags |= IORESOURCE_DMA_16BIT;
326 /* Set a default value ? */
327 dma->flags |= IORESOURCE_DMA_8AND16BIT;
328 pnp_err("Invalid DMA transfer type");
331 pnp_register_dma_resource(option, dma);
336 static void pnpacpi_parse_irq_option(struct pnp_option *option,
337 struct acpi_resource_irq *p)
342 if (p->interrupt_count == 0)
344 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
348 for(i = 0; i < p->interrupt_count; i++)
349 if (p->interrupts[i])
350 __set_bit(p->interrupts[i], irq->map);
351 irq->flags = irq_flags(p->triggering, p->polarity);
353 pnp_register_irq_resource(option, irq);
357 static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
358 struct acpi_resource_extended_irq *p)
363 if (p->interrupt_count == 0)
365 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
369 for(i = 0; i < p->interrupt_count; i++)
370 if (p->interrupts[i])
371 __set_bit(p->interrupts[i], irq->map);
372 irq->flags = irq_flags(p->triggering, p->polarity);
374 pnp_register_irq_resource(option, irq);
379 pnpacpi_parse_port_option(struct pnp_option *option,
380 struct acpi_resource_io *io)
382 struct pnp_port *port;
384 if (io->address_length == 0)
386 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
389 port->min = io->minimum;
390 port->max = io->maximum;
391 port->align = io->alignment;
392 port->size = io->address_length;
393 port->flags = ACPI_DECODE_16 == io->io_decode ?
394 PNP_PORT_FLAG_16BITADDR : 0;
395 pnp_register_port_resource(option, port);
400 pnpacpi_parse_fixed_port_option(struct pnp_option *option,
401 struct acpi_resource_fixed_io *io)
403 struct pnp_port *port;
405 if (io->address_length == 0)
407 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
410 port->min = port->max = io->address;
411 port->size = io->address_length;
413 port->flags = PNP_PORT_FLAG_FIXED;
414 pnp_register_port_resource(option, port);
419 pnpacpi_parse_mem24_option(struct pnp_option *option,
420 struct acpi_resource_memory24 *p)
424 if (p->address_length == 0)
426 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
429 mem->min = p->minimum;
430 mem->max = p->maximum;
431 mem->align = p->alignment;
432 mem->size = p->address_length;
434 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
435 IORESOURCE_MEM_WRITEABLE : 0;
437 pnp_register_mem_resource(option, mem);
442 pnpacpi_parse_mem32_option(struct pnp_option *option,
443 struct acpi_resource_memory32 *p)
447 if (p->address_length == 0)
449 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
452 mem->min = p->minimum;
453 mem->max = p->maximum;
454 mem->align = p->alignment;
455 mem->size = p->address_length;
457 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
458 IORESOURCE_MEM_WRITEABLE : 0;
460 pnp_register_mem_resource(option, mem);
465 pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
466 struct acpi_resource_fixed_memory32 *p)
470 if (p->address_length == 0)
472 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
475 mem->min = mem->max = p->address;
476 mem->size = p->address_length;
479 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
480 IORESOURCE_MEM_WRITEABLE : 0;
482 pnp_register_mem_resource(option, mem);
487 pnpacpi_parse_address_option(struct pnp_option *option, struct acpi_resource *r)
489 struct acpi_resource_address64 addr, *p = &addr;
492 struct pnp_port *port;
494 status = acpi_resource_to_address64(r, p);
495 if (!ACPI_SUCCESS(status)) {
496 pnp_warn("PnPACPI: failed to convert resource type %d", r->type);
500 if (p->address_length == 0)
503 if (p->resource_type == ACPI_MEMORY_RANGE) {
504 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
507 mem->min = mem->max = p->minimum;
508 mem->size = p->address_length;
510 mem->flags = (p->info.mem.write_protect ==
511 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE : 0;
512 pnp_register_mem_resource(option, mem);
513 } else if (p->resource_type == ACPI_IO_RANGE) {
514 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
517 port->min = port->max = p->minimum;
518 port->size = p->address_length;
520 port->flags = PNP_PORT_FLAG_FIXED;
521 pnp_register_port_resource(option, port);
525 struct acpipnp_parse_option_s {
526 struct pnp_option *option;
527 struct pnp_option *option_independent;
531 static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
535 struct acpipnp_parse_option_s *parse_data = (struct acpipnp_parse_option_s *)data;
536 struct pnp_dev *dev = parse_data->dev;
537 struct pnp_option *option = parse_data->option;
540 case ACPI_RESOURCE_TYPE_IRQ:
541 pnpacpi_parse_irq_option(option, &res->data.irq);
544 case ACPI_RESOURCE_TYPE_DMA:
545 pnpacpi_parse_dma_option(option, &res->data.dma);
548 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
549 switch (res->data.start_dpf.compatibility_priority) {
550 case ACPI_GOOD_CONFIGURATION:
551 priority = PNP_RES_PRIORITY_PREFERRED;
554 case ACPI_ACCEPTABLE_CONFIGURATION:
555 priority = PNP_RES_PRIORITY_ACCEPTABLE;
558 case ACPI_SUB_OPTIMAL_CONFIGURATION:
559 priority = PNP_RES_PRIORITY_FUNCTIONAL;
562 priority = PNP_RES_PRIORITY_INVALID;
565 /* TBD: Considering performace/robustness bits */
566 option = pnp_register_dependent_option(dev, priority);
569 parse_data->option = option;
572 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
573 /*only one EndDependentFn is allowed*/
574 if (!parse_data->option_independent) {
575 pnp_warn("PnPACPI: more than one EndDependentFn");
578 parse_data->option = parse_data->option_independent;
579 parse_data->option_independent = NULL;
582 case ACPI_RESOURCE_TYPE_IO:
583 pnpacpi_parse_port_option(option, &res->data.io);
586 case ACPI_RESOURCE_TYPE_FIXED_IO:
587 pnpacpi_parse_fixed_port_option(option,
588 &res->data.fixed_io);
591 case ACPI_RESOURCE_TYPE_VENDOR:
592 case ACPI_RESOURCE_TYPE_END_TAG:
595 case ACPI_RESOURCE_TYPE_MEMORY24:
596 pnpacpi_parse_mem24_option(option, &res->data.memory24);
599 case ACPI_RESOURCE_TYPE_MEMORY32:
600 pnpacpi_parse_mem32_option(option, &res->data.memory32);
603 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
604 pnpacpi_parse_fixed_mem32_option(option,
605 &res->data.fixed_memory32);
608 case ACPI_RESOURCE_TYPE_ADDRESS16:
609 case ACPI_RESOURCE_TYPE_ADDRESS32:
610 case ACPI_RESOURCE_TYPE_ADDRESS64:
611 pnpacpi_parse_address_option(option, res);
614 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
617 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
618 pnpacpi_parse_ext_irq_option(option,
619 &res->data.extended_irq);
622 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
626 pnp_warn("PnPACPI: unknown resource type %d", res->type);
633 acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
637 struct acpipnp_parse_option_s parse_data;
639 parse_data.option = pnp_register_independent_option(dev);
640 if (!parse_data.option)
642 parse_data.option_independent = parse_data.option;
643 parse_data.dev = dev;
644 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
645 pnpacpi_option_resource, &parse_data);
650 static int pnpacpi_supported_resource(struct acpi_resource *res)
653 case ACPI_RESOURCE_TYPE_IRQ:
654 case ACPI_RESOURCE_TYPE_DMA:
655 case ACPI_RESOURCE_TYPE_IO:
656 case ACPI_RESOURCE_TYPE_FIXED_IO:
657 case ACPI_RESOURCE_TYPE_MEMORY24:
658 case ACPI_RESOURCE_TYPE_MEMORY32:
659 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
660 case ACPI_RESOURCE_TYPE_ADDRESS16:
661 case ACPI_RESOURCE_TYPE_ADDRESS32:
662 case ACPI_RESOURCE_TYPE_ADDRESS64:
663 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
672 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
675 int *res_cnt = (int *)data;
677 if (pnpacpi_supported_resource(res))
682 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
684 struct acpi_resource **resource = (struct acpi_resource **)data;
686 if (pnpacpi_supported_resource(res)) {
687 (*resource)->type = res->type;
688 (*resource)->length = sizeof(struct acpi_resource);
695 int pnpacpi_build_resource_template(acpi_handle handle,
696 struct acpi_buffer *buffer)
698 struct acpi_resource *resource;
702 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
703 pnpacpi_count_resources, &res_cnt);
704 if (ACPI_FAILURE(status)) {
705 pnp_err("Evaluate _CRS failed");
710 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
711 buffer->pointer = kcalloc(1, buffer->length - 1, GFP_KERNEL);
712 if (!buffer->pointer)
714 pnp_dbg("Res cnt %d", res_cnt);
715 resource = (struct acpi_resource *)buffer->pointer;
716 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
717 pnpacpi_type_resources, &resource);
718 if (ACPI_FAILURE(status)) {
719 kfree(buffer->pointer);
720 pnp_err("Evaluate _CRS failed");
723 /* resource will pointer the end resource now */
724 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
729 static void pnpacpi_encode_irq(struct acpi_resource *resource,
732 int triggering, polarity;
734 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
735 resource->data.irq.triggering = triggering;
736 resource->data.irq.polarity = polarity;
737 if (triggering == ACPI_EDGE_SENSITIVE)
738 resource->data.irq.sharable = ACPI_EXCLUSIVE;
740 resource->data.irq.sharable = ACPI_SHARED;
741 resource->data.irq.interrupt_count = 1;
742 resource->data.irq.interrupts[0] = p->start;
745 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
748 int triggering, polarity;
750 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
751 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
752 resource->data.extended_irq.triggering = triggering;
753 resource->data.extended_irq.polarity = polarity;
754 if (triggering == ACPI_EDGE_SENSITIVE)
755 resource->data.irq.sharable = ACPI_EXCLUSIVE;
757 resource->data.irq.sharable = ACPI_SHARED;
758 resource->data.extended_irq.interrupt_count = 1;
759 resource->data.extended_irq.interrupts[0] = p->start;
762 static void pnpacpi_encode_dma(struct acpi_resource *resource,
765 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
766 if (p->flags & IORESOURCE_DMA_COMPATIBLE)
767 resource->data.dma.type = ACPI_COMPATIBILITY;
768 else if (p->flags & IORESOURCE_DMA_TYPEA)
769 resource->data.dma.type = ACPI_TYPE_A;
770 else if (p->flags & IORESOURCE_DMA_TYPEB)
771 resource->data.dma.type = ACPI_TYPE_B;
772 else if (p->flags & IORESOURCE_DMA_TYPEF)
773 resource->data.dma.type = ACPI_TYPE_F;
774 if (p->flags & IORESOURCE_DMA_8BIT)
775 resource->data.dma.transfer = ACPI_TRANSFER_8;
776 else if (p->flags & IORESOURCE_DMA_8AND16BIT)
777 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
778 else if (p->flags & IORESOURCE_DMA_16BIT)
779 resource->data.dma.transfer = ACPI_TRANSFER_16;
780 resource->data.dma.bus_master = p->flags & IORESOURCE_DMA_MASTER;
781 resource->data.dma.channel_count = 1;
782 resource->data.dma.channels[0] = p->start;
785 static void pnpacpi_encode_io(struct acpi_resource *resource,
788 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
789 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR)?
790 ACPI_DECODE_16 : ACPI_DECODE_10;
791 resource->data.io.minimum = p->start;
792 resource->data.io.maximum = p->end;
793 resource->data.io.alignment = 0; /* Correct? */
794 resource->data.io.address_length = p->end - p->start + 1;
797 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
800 resource->data.fixed_io.address = p->start;
801 resource->data.fixed_io.address_length = p->end - p->start + 1;
804 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
807 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
808 resource->data.memory24.write_protect =
809 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
810 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
811 resource->data.memory24.minimum = p->start;
812 resource->data.memory24.maximum = p->end;
813 resource->data.memory24.alignment = 0;
814 resource->data.memory24.address_length = p->end - p->start + 1;
817 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
820 resource->data.memory32.write_protect =
821 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
822 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
823 resource->data.memory32.minimum = p->start;
824 resource->data.memory32.maximum = p->end;
825 resource->data.memory32.alignment = 0;
826 resource->data.memory32.address_length = p->end - p->start + 1;
829 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
832 resource->data.fixed_memory32.write_protect =
833 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
834 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
835 resource->data.fixed_memory32.address = p->start;
836 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
839 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
840 struct acpi_buffer *buffer)
843 /* pnpacpi_build_resource_template allocates extra mem */
844 int res_cnt = (buffer->length - 1)/sizeof(struct acpi_resource) - 1;
845 struct acpi_resource *resource = (struct acpi_resource*)buffer->pointer;
846 int port = 0, irq = 0, dma = 0, mem = 0;
848 pnp_dbg("res cnt %d", res_cnt);
849 while (i < res_cnt) {
850 switch(resource->type) {
851 case ACPI_RESOURCE_TYPE_IRQ:
852 pnp_dbg("Encode irq");
853 pnpacpi_encode_irq(resource,
854 &res_table->irq_resource[irq]);
858 case ACPI_RESOURCE_TYPE_DMA:
859 pnp_dbg("Encode dma");
860 pnpacpi_encode_dma(resource,
861 &res_table->dma_resource[dma]);
864 case ACPI_RESOURCE_TYPE_IO:
865 pnp_dbg("Encode io");
866 pnpacpi_encode_io(resource,
867 &res_table->port_resource[port]);
870 case ACPI_RESOURCE_TYPE_FIXED_IO:
871 pnp_dbg("Encode fixed io");
872 pnpacpi_encode_fixed_io(resource,
873 &res_table->port_resource[port]);
876 case ACPI_RESOURCE_TYPE_MEMORY24:
877 pnp_dbg("Encode mem24");
878 pnpacpi_encode_mem24(resource,
879 &res_table->mem_resource[mem]);
882 case ACPI_RESOURCE_TYPE_MEMORY32:
883 pnp_dbg("Encode mem32");
884 pnpacpi_encode_mem32(resource,
885 &res_table->mem_resource[mem]);
888 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
889 pnp_dbg("Encode fixed mem32");
890 pnpacpi_encode_fixed_mem32(resource,
891 &res_table->mem_resource[mem]);
894 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
895 pnp_dbg("Encode ext irq");
896 pnpacpi_encode_ext_irq(resource,
897 &res_table->irq_resource[irq]);
900 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
901 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
902 case ACPI_RESOURCE_TYPE_VENDOR:
903 case ACPI_RESOURCE_TYPE_END_TAG:
904 case ACPI_RESOURCE_TYPE_ADDRESS16:
905 case ACPI_RESOURCE_TYPE_ADDRESS32:
906 case ACPI_RESOURCE_TYPE_ADDRESS64:
907 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
908 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
909 default: /* other type */
910 pnp_warn("unknown resource type %d", resource->type);