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)
83 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
86 if (i >= PNP_MAX_IRQ) {
87 printk(KERN_ERR "pnpacpi: exceeded the max number of IRQ "
88 "resources: %d \n", PNP_MAX_IRQ);
92 * in IO-APIC mode, use overrided attribute. Two reasons:
94 * 2. BIOS uses IO-APIC mode Interrupt Source Override
96 if (!acpi_get_override_irq(gsi, &t, &p)) {
97 t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
98 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
100 if (triggering != t || polarity != p) {
101 pnp_warn("IRQ %d override to %s, %s",
102 gsi, t ? "edge":"level", p ? "low":"high");
108 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
109 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
110 irq = acpi_register_gsi(gsi, triggering, polarity);
112 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
117 res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
119 res->irq_resource[i].start = irq;
120 res->irq_resource[i].end = irq;
121 pcibios_penalize_isa_irq(irq, 1);
124 static int dma_flags(int type, int bus_master, int transfer)
129 flags |= IORESOURCE_DMA_MASTER;
131 case ACPI_COMPATIBILITY:
132 flags |= IORESOURCE_DMA_COMPATIBLE;
135 flags |= IORESOURCE_DMA_TYPEA;
138 flags |= IORESOURCE_DMA_TYPEB;
141 flags |= IORESOURCE_DMA_TYPEF;
144 /* Set a default value ? */
145 flags |= IORESOURCE_DMA_COMPATIBLE;
146 pnp_err("Invalid DMA type");
149 case ACPI_TRANSFER_8:
150 flags |= IORESOURCE_DMA_8BIT;
152 case ACPI_TRANSFER_8_16:
153 flags |= IORESOURCE_DMA_8AND16BIT;
155 case ACPI_TRANSFER_16:
156 flags |= IORESOURCE_DMA_16BIT;
159 /* Set a default value ? */
160 flags |= IORESOURCE_DMA_8AND16BIT;
161 pnp_err("Invalid DMA transfer type");
167 static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
169 int bus_master, int transfer)
173 while (i < PNP_MAX_DMA &&
174 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
176 if (i < PNP_MAX_DMA) {
177 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
178 res->dma_resource[i].flags |=
179 dma_flags(type, bus_master, transfer);
181 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
184 res->dma_resource[i].start = dma;
185 res->dma_resource[i].end = dma;
187 printk(KERN_ERR "pnpacpi: exceeded the max number of DMA "
188 "resources: %d \n", PNP_MAX_DMA);
192 static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
193 u64 io, u64 len, int io_decode)
197 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
200 if (i < PNP_MAX_PORT) {
201 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
202 if (io_decode == ACPI_DECODE_16)
203 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
204 if (len <= 0 || (io + len - 1) >= 0x10003) {
205 res->port_resource[i].flags |= IORESOURCE_DISABLED;
208 res->port_resource[i].start = io;
209 res->port_resource[i].end = io + len - 1;
211 printk(KERN_ERR "pnpacpi: exceeded the max number of IO "
212 "resources: %d \n", PNP_MAX_PORT);
216 static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
222 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
225 if (i < PNP_MAX_MEM) {
226 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
228 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
231 if (write_protect == ACPI_READ_WRITE_MEMORY)
232 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
234 res->mem_resource[i].start = mem;
235 res->mem_resource[i].end = mem + len - 1;
237 printk(KERN_ERR "pnpacpi: exceeded the max number of mem "
238 "resources: %d\n", PNP_MAX_MEM);
242 static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
243 struct acpi_resource *res)
245 struct acpi_resource_address64 addr, *p = &addr;
248 status = acpi_resource_to_address64(res, p);
249 if (!ACPI_SUCCESS(status)) {
250 pnp_warn("PnPACPI: failed to convert resource type %d",
255 if (p->producer_consumer == ACPI_PRODUCER)
258 if (p->resource_type == ACPI_MEMORY_RANGE)
259 pnpacpi_parse_allocated_memresource(res_table,
260 p->minimum, p->address_length,
261 p->info.mem.write_protect);
262 else if (p->resource_type == ACPI_IO_RANGE)
263 pnpacpi_parse_allocated_ioresource(res_table,
264 p->minimum, p->address_length,
265 p->granularity == 0xfff ? ACPI_DECODE_10 :
269 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
272 struct pnp_resource_table *res_table = data;
276 case ACPI_RESOURCE_TYPE_IRQ:
278 * Per spec, only one interrupt per descriptor is allowed in
279 * _CRS, but some firmware violates this, so parse them all.
281 for (i = 0; i < res->data.irq.interrupt_count; i++) {
282 pnpacpi_parse_allocated_irqresource(res_table,
283 res->data.irq.interrupts[i],
284 res->data.irq.triggering,
285 res->data.irq.polarity,
286 res->data.irq.sharable);
290 case ACPI_RESOURCE_TYPE_DMA:
291 if (res->data.dma.channel_count > 0)
292 pnpacpi_parse_allocated_dmaresource(res_table,
293 res->data.dma.channels[0],
295 res->data.dma.bus_master,
296 res->data.dma.transfer);
299 case ACPI_RESOURCE_TYPE_IO:
300 pnpacpi_parse_allocated_ioresource(res_table,
301 res->data.io.minimum,
302 res->data.io.address_length,
303 res->data.io.io_decode);
306 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
307 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
310 case ACPI_RESOURCE_TYPE_FIXED_IO:
311 pnpacpi_parse_allocated_ioresource(res_table,
312 res->data.fixed_io.address,
313 res->data.fixed_io.address_length,
317 case ACPI_RESOURCE_TYPE_VENDOR:
320 case ACPI_RESOURCE_TYPE_END_TAG:
323 case ACPI_RESOURCE_TYPE_MEMORY24:
324 pnpacpi_parse_allocated_memresource(res_table,
325 res->data.memory24.minimum,
326 res->data.memory24.address_length,
327 res->data.memory24.write_protect);
329 case ACPI_RESOURCE_TYPE_MEMORY32:
330 pnpacpi_parse_allocated_memresource(res_table,
331 res->data.memory32.minimum,
332 res->data.memory32.address_length,
333 res->data.memory32.write_protect);
335 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
336 pnpacpi_parse_allocated_memresource(res_table,
337 res->data.fixed_memory32.address,
338 res->data.fixed_memory32.address_length,
339 res->data.fixed_memory32.write_protect);
341 case ACPI_RESOURCE_TYPE_ADDRESS16:
342 case ACPI_RESOURCE_TYPE_ADDRESS32:
343 case ACPI_RESOURCE_TYPE_ADDRESS64:
344 pnpacpi_parse_allocated_address_space(res_table, res);
347 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
348 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
352 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
353 if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
356 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
357 pnpacpi_parse_allocated_irqresource(res_table,
358 res->data.extended_irq.interrupts[i],
359 res->data.extended_irq.triggering,
360 res->data.extended_irq.polarity,
361 res->data.extended_irq.sharable);
365 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
369 pnp_warn("PnPACPI: unknown resource type %d", res->type);
376 acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
377 struct pnp_resource_table * res)
379 /* Blank the resource table values */
380 pnp_init_resource_table(res);
382 return acpi_walk_resources(handle, METHOD_NAME__CRS,
383 pnpacpi_allocated_resource, res);
386 static void pnpacpi_parse_dma_option(struct pnp_option *option,
387 struct acpi_resource_dma *p)
392 if (p->channel_count == 0)
394 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
398 for (i = 0; i < p->channel_count; i++)
399 dma->map |= 1 << p->channels[i];
401 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
403 pnp_register_dma_resource(option, dma);
406 static void pnpacpi_parse_irq_option(struct pnp_option *option,
407 struct acpi_resource_irq *p)
412 if (p->interrupt_count == 0)
414 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
418 for (i = 0; i < p->interrupt_count; i++)
419 if (p->interrupts[i])
420 __set_bit(p->interrupts[i], irq->map);
421 irq->flags = irq_flags(p->triggering, p->polarity);
423 pnp_register_irq_resource(option, irq);
426 static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
427 struct acpi_resource_extended_irq *p)
432 if (p->interrupt_count == 0)
434 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
438 for (i = 0; i < p->interrupt_count; i++)
439 if (p->interrupts[i])
440 __set_bit(p->interrupts[i], irq->map);
441 irq->flags = irq_flags(p->triggering, p->polarity);
443 pnp_register_irq_resource(option, irq);
446 static void pnpacpi_parse_port_option(struct pnp_option *option,
447 struct acpi_resource_io *io)
449 struct pnp_port *port;
451 if (io->address_length == 0)
453 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
456 port->min = io->minimum;
457 port->max = io->maximum;
458 port->align = io->alignment;
459 port->size = io->address_length;
460 port->flags = ACPI_DECODE_16 == io->io_decode ?
461 PNP_PORT_FLAG_16BITADDR : 0;
462 pnp_register_port_resource(option, port);
465 static void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
466 struct acpi_resource_fixed_io *io)
468 struct pnp_port *port;
470 if (io->address_length == 0)
472 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
475 port->min = port->max = io->address;
476 port->size = io->address_length;
478 port->flags = PNP_PORT_FLAG_FIXED;
479 pnp_register_port_resource(option, port);
482 static void pnpacpi_parse_mem24_option(struct pnp_option *option,
483 struct acpi_resource_memory24 *p)
487 if (p->address_length == 0)
489 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
492 mem->min = p->minimum;
493 mem->max = p->maximum;
494 mem->align = p->alignment;
495 mem->size = p->address_length;
497 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
498 IORESOURCE_MEM_WRITEABLE : 0;
500 pnp_register_mem_resource(option, mem);
503 static void pnpacpi_parse_mem32_option(struct pnp_option *option,
504 struct acpi_resource_memory32 *p)
508 if (p->address_length == 0)
510 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
513 mem->min = p->minimum;
514 mem->max = p->maximum;
515 mem->align = p->alignment;
516 mem->size = p->address_length;
518 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
519 IORESOURCE_MEM_WRITEABLE : 0;
521 pnp_register_mem_resource(option, mem);
524 static void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
525 struct acpi_resource_fixed_memory32 *p)
529 if (p->address_length == 0)
531 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
534 mem->min = mem->max = p->address;
535 mem->size = p->address_length;
538 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
539 IORESOURCE_MEM_WRITEABLE : 0;
541 pnp_register_mem_resource(option, mem);
544 static void pnpacpi_parse_address_option(struct pnp_option *option,
545 struct acpi_resource *r)
547 struct acpi_resource_address64 addr, *p = &addr;
550 struct pnp_port *port;
552 status = acpi_resource_to_address64(r, p);
553 if (!ACPI_SUCCESS(status)) {
554 pnp_warn("PnPACPI: failed to convert resource type %d",
559 if (p->address_length == 0)
562 if (p->resource_type == ACPI_MEMORY_RANGE) {
563 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
566 mem->min = mem->max = p->minimum;
567 mem->size = p->address_length;
569 mem->flags = (p->info.mem.write_protect ==
570 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
572 pnp_register_mem_resource(option, mem);
573 } else if (p->resource_type == ACPI_IO_RANGE) {
574 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
577 port->min = port->max = p->minimum;
578 port->size = p->address_length;
580 port->flags = PNP_PORT_FLAG_FIXED;
581 pnp_register_port_resource(option, port);
585 struct acpipnp_parse_option_s {
586 struct pnp_option *option;
587 struct pnp_option *option_independent;
591 static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
595 struct acpipnp_parse_option_s *parse_data = data;
596 struct pnp_dev *dev = parse_data->dev;
597 struct pnp_option *option = parse_data->option;
600 case ACPI_RESOURCE_TYPE_IRQ:
601 pnpacpi_parse_irq_option(option, &res->data.irq);
604 case ACPI_RESOURCE_TYPE_DMA:
605 pnpacpi_parse_dma_option(option, &res->data.dma);
608 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
609 switch (res->data.start_dpf.compatibility_priority) {
610 case ACPI_GOOD_CONFIGURATION:
611 priority = PNP_RES_PRIORITY_PREFERRED;
614 case ACPI_ACCEPTABLE_CONFIGURATION:
615 priority = PNP_RES_PRIORITY_ACCEPTABLE;
618 case ACPI_SUB_OPTIMAL_CONFIGURATION:
619 priority = PNP_RES_PRIORITY_FUNCTIONAL;
622 priority = PNP_RES_PRIORITY_INVALID;
625 /* TBD: Consider performance/robustness bits */
626 option = pnp_register_dependent_option(dev, priority);
629 parse_data->option = option;
632 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
633 /*only one EndDependentFn is allowed */
634 if (!parse_data->option_independent) {
635 pnp_warn("PnPACPI: more than one EndDependentFn");
638 parse_data->option = parse_data->option_independent;
639 parse_data->option_independent = NULL;
642 case ACPI_RESOURCE_TYPE_IO:
643 pnpacpi_parse_port_option(option, &res->data.io);
646 case ACPI_RESOURCE_TYPE_FIXED_IO:
647 pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io);
650 case ACPI_RESOURCE_TYPE_VENDOR:
651 case ACPI_RESOURCE_TYPE_END_TAG:
654 case ACPI_RESOURCE_TYPE_MEMORY24:
655 pnpacpi_parse_mem24_option(option, &res->data.memory24);
658 case ACPI_RESOURCE_TYPE_MEMORY32:
659 pnpacpi_parse_mem32_option(option, &res->data.memory32);
662 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
663 pnpacpi_parse_fixed_mem32_option(option,
664 &res->data.fixed_memory32);
667 case ACPI_RESOURCE_TYPE_ADDRESS16:
668 case ACPI_RESOURCE_TYPE_ADDRESS32:
669 case ACPI_RESOURCE_TYPE_ADDRESS64:
670 pnpacpi_parse_address_option(option, res);
673 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
676 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
677 pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq);
680 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
684 pnp_warn("PnPACPI: unknown resource type %d", res->type);
691 acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
692 struct pnp_dev * dev)
695 struct acpipnp_parse_option_s parse_data;
697 parse_data.option = pnp_register_independent_option(dev);
698 if (!parse_data.option)
700 parse_data.option_independent = parse_data.option;
701 parse_data.dev = dev;
702 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
703 pnpacpi_option_resource, &parse_data);
708 static int pnpacpi_supported_resource(struct acpi_resource *res)
711 case ACPI_RESOURCE_TYPE_IRQ:
712 case ACPI_RESOURCE_TYPE_DMA:
713 case ACPI_RESOURCE_TYPE_IO:
714 case ACPI_RESOURCE_TYPE_FIXED_IO:
715 case ACPI_RESOURCE_TYPE_MEMORY24:
716 case ACPI_RESOURCE_TYPE_MEMORY32:
717 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
718 case ACPI_RESOURCE_TYPE_ADDRESS16:
719 case ACPI_RESOURCE_TYPE_ADDRESS32:
720 case ACPI_RESOURCE_TYPE_ADDRESS64:
721 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
730 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
735 if (pnpacpi_supported_resource(res))
740 static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
742 struct acpi_resource **resource = data;
744 if (pnpacpi_supported_resource(res)) {
745 (*resource)->type = res->type;
746 (*resource)->length = sizeof(struct acpi_resource);
753 int pnpacpi_build_resource_template(acpi_handle handle,
754 struct acpi_buffer *buffer)
756 struct acpi_resource *resource;
760 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
761 pnpacpi_count_resources, &res_cnt);
762 if (ACPI_FAILURE(status)) {
763 pnp_err("Evaluate _CRS failed");
768 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
769 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
770 if (!buffer->pointer)
772 pnp_dbg("Res cnt %d", res_cnt);
773 resource = (struct acpi_resource *)buffer->pointer;
774 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
775 pnpacpi_type_resources, &resource);
776 if (ACPI_FAILURE(status)) {
777 kfree(buffer->pointer);
778 pnp_err("Evaluate _CRS failed");
781 /* resource will pointer the end resource now */
782 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
787 static void pnpacpi_encode_irq(struct acpi_resource *resource,
790 int triggering, polarity;
792 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
793 resource->data.irq.triggering = triggering;
794 resource->data.irq.polarity = polarity;
795 if (triggering == ACPI_EDGE_SENSITIVE)
796 resource->data.irq.sharable = ACPI_EXCLUSIVE;
798 resource->data.irq.sharable = ACPI_SHARED;
799 resource->data.irq.interrupt_count = 1;
800 resource->data.irq.interrupts[0] = p->start;
803 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
806 int triggering, polarity;
808 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
809 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
810 resource->data.extended_irq.triggering = triggering;
811 resource->data.extended_irq.polarity = polarity;
812 if (triggering == ACPI_EDGE_SENSITIVE)
813 resource->data.irq.sharable = ACPI_EXCLUSIVE;
815 resource->data.irq.sharable = ACPI_SHARED;
816 resource->data.extended_irq.interrupt_count = 1;
817 resource->data.extended_irq.interrupts[0] = p->start;
820 static void pnpacpi_encode_dma(struct acpi_resource *resource,
823 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
824 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
825 case IORESOURCE_DMA_TYPEA:
826 resource->data.dma.type = ACPI_TYPE_A;
828 case IORESOURCE_DMA_TYPEB:
829 resource->data.dma.type = ACPI_TYPE_B;
831 case IORESOURCE_DMA_TYPEF:
832 resource->data.dma.type = ACPI_TYPE_F;
835 resource->data.dma.type = ACPI_COMPATIBILITY;
838 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
839 case IORESOURCE_DMA_8BIT:
840 resource->data.dma.transfer = ACPI_TRANSFER_8;
842 case IORESOURCE_DMA_8AND16BIT:
843 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
846 resource->data.dma.transfer = ACPI_TRANSFER_16;
849 resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
850 resource->data.dma.channel_count = 1;
851 resource->data.dma.channels[0] = p->start;
854 static void pnpacpi_encode_io(struct acpi_resource *resource,
857 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
858 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
859 ACPI_DECODE_16 : ACPI_DECODE_10;
860 resource->data.io.minimum = p->start;
861 resource->data.io.maximum = p->end;
862 resource->data.io.alignment = 0; /* Correct? */
863 resource->data.io.address_length = p->end - p->start + 1;
866 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
869 resource->data.fixed_io.address = p->start;
870 resource->data.fixed_io.address_length = p->end - p->start + 1;
873 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
876 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
877 resource->data.memory24.write_protect =
878 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
879 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
880 resource->data.memory24.minimum = p->start;
881 resource->data.memory24.maximum = p->end;
882 resource->data.memory24.alignment = 0;
883 resource->data.memory24.address_length = p->end - p->start + 1;
886 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
889 resource->data.memory32.write_protect =
890 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
891 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
892 resource->data.memory32.minimum = p->start;
893 resource->data.memory32.maximum = p->end;
894 resource->data.memory32.alignment = 0;
895 resource->data.memory32.address_length = p->end - p->start + 1;
898 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
901 resource->data.fixed_memory32.write_protect =
902 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
903 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
904 resource->data.fixed_memory32.address = p->start;
905 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
908 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
909 struct acpi_buffer *buffer)
912 /* pnpacpi_build_resource_template allocates extra mem */
913 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
914 struct acpi_resource *resource = buffer->pointer;
915 int port = 0, irq = 0, dma = 0, mem = 0;
917 pnp_dbg("res cnt %d", res_cnt);
918 while (i < res_cnt) {
919 switch (resource->type) {
920 case ACPI_RESOURCE_TYPE_IRQ:
921 pnp_dbg("Encode irq");
922 pnpacpi_encode_irq(resource,
923 &res_table->irq_resource[irq]);
927 case ACPI_RESOURCE_TYPE_DMA:
928 pnp_dbg("Encode dma");
929 pnpacpi_encode_dma(resource,
930 &res_table->dma_resource[dma]);
933 case ACPI_RESOURCE_TYPE_IO:
934 pnp_dbg("Encode io");
935 pnpacpi_encode_io(resource,
936 &res_table->port_resource[port]);
939 case ACPI_RESOURCE_TYPE_FIXED_IO:
940 pnp_dbg("Encode fixed io");
941 pnpacpi_encode_fixed_io(resource,
943 port_resource[port]);
946 case ACPI_RESOURCE_TYPE_MEMORY24:
947 pnp_dbg("Encode mem24");
948 pnpacpi_encode_mem24(resource,
949 &res_table->mem_resource[mem]);
952 case ACPI_RESOURCE_TYPE_MEMORY32:
953 pnp_dbg("Encode mem32");
954 pnpacpi_encode_mem32(resource,
955 &res_table->mem_resource[mem]);
958 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
959 pnp_dbg("Encode fixed mem32");
960 pnpacpi_encode_fixed_mem32(resource,
965 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
966 pnp_dbg("Encode ext irq");
967 pnpacpi_encode_ext_irq(resource,
968 &res_table->irq_resource[irq]);
971 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
972 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
973 case ACPI_RESOURCE_TYPE_VENDOR:
974 case ACPI_RESOURCE_TYPE_END_TAG:
975 case ACPI_RESOURCE_TYPE_ADDRESS16:
976 case ACPI_RESOURCE_TYPE_ADDRESS32:
977 case ACPI_RESOURCE_TYPE_ADDRESS64:
978 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
979 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
980 default: /* other type */
981 pnp_warn("unknown resource type %d", resource->type);