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 edge_level, int active_high_low)
38 if (edge_level == ACPI_LEVEL_SENSITIVE) {
39 if(active_high_low == ACPI_ACTIVE_LOW)
40 flag = IORESOURCE_IRQ_LOWLEVEL;
42 flag = IORESOURCE_IRQ_HIGHLEVEL;
45 if(active_high_low == ACPI_ACTIVE_LOW)
46 flag = IORESOURCE_IRQ_LOWEDGE;
48 flag = IORESOURCE_IRQ_HIGHEDGE;
53 static void decode_irq_flags(int flag, int *edge_level, int *active_high_low)
56 case IORESOURCE_IRQ_LOWLEVEL:
57 *edge_level = ACPI_LEVEL_SENSITIVE;
58 *active_high_low = ACPI_ACTIVE_LOW;
60 case IORESOURCE_IRQ_HIGHLEVEL:
61 *edge_level = ACPI_LEVEL_SENSITIVE;
62 *active_high_low = ACPI_ACTIVE_HIGH;
64 case IORESOURCE_IRQ_LOWEDGE:
65 *edge_level = ACPI_EDGE_SENSITIVE;
66 *active_high_low = ACPI_ACTIVE_LOW;
68 case IORESOURCE_IRQ_HIGHEDGE:
69 *edge_level = ACPI_EDGE_SENSITIVE;
70 *active_high_low = ACPI_ACTIVE_HIGH;
76 pnpacpi_parse_allocated_irqresource(struct pnp_resource_table * res, int irq)
79 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
82 if (i < PNP_MAX_IRQ) {
83 res->irq_resource[i].flags = IORESOURCE_IRQ; //Also clears _UNSET flag
85 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
88 res->irq_resource[i].start =(unsigned long) irq;
89 res->irq_resource[i].end = (unsigned long) irq;
94 pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table * res, int dma)
97 while (i < PNP_MAX_DMA &&
98 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
100 if (i < PNP_MAX_DMA) {
101 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
103 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
106 res->dma_resource[i].start =(unsigned long) dma;
107 res->dma_resource[i].end = (unsigned long) dma;
112 pnpacpi_parse_allocated_ioresource(struct pnp_resource_table * res,
116 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
119 if (i < PNP_MAX_PORT) {
120 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
121 if (len <= 0 || (io + len -1) >= 0x10003) {
122 res->port_resource[i].flags |= IORESOURCE_DISABLED;
125 res->port_resource[i].start = (unsigned long) io;
126 res->port_resource[i].end = (unsigned long)(io + len - 1);
131 pnpacpi_parse_allocated_memresource(struct pnp_resource_table * res,
135 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
138 if (i < PNP_MAX_MEM) {
139 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
141 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
144 res->mem_resource[i].start = (unsigned long) mem;
145 res->mem_resource[i].end = (unsigned long)(mem + len - 1);
150 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
153 struct pnp_resource_table * res_table = (struct pnp_resource_table *)data;
156 case ACPI_RSTYPE_IRQ:
157 if ((res->data.irq.number_of_interrupts > 0) &&
158 valid_IRQ(res->data.irq.interrupts[0])) {
159 pnpacpi_parse_allocated_irqresource(res_table,
160 acpi_register_gsi(res->data.irq.interrupts[0],
161 res->data.irq.edge_level,
162 res->data.irq.active_high_low));
163 pcibios_penalize_isa_irq(res->data.irq.interrupts[0], 1);
167 case ACPI_RSTYPE_EXT_IRQ:
168 if ((res->data.extended_irq.number_of_interrupts > 0) &&
169 valid_IRQ(res->data.extended_irq.interrupts[0])) {
170 pnpacpi_parse_allocated_irqresource(res_table,
171 acpi_register_gsi(res->data.extended_irq.interrupts[0],
172 res->data.extended_irq.edge_level,
173 res->data.extended_irq.active_high_low));
174 pcibios_penalize_isa_irq(res->data.extended_irq.interrupts[0], 1);
177 case ACPI_RSTYPE_DMA:
178 if (res->data.dma.number_of_channels > 0)
179 pnpacpi_parse_allocated_dmaresource(res_table,
180 res->data.dma.channels[0]);
183 pnpacpi_parse_allocated_ioresource(res_table,
184 res->data.io.min_base_address,
185 res->data.io.range_length);
187 case ACPI_RSTYPE_FIXED_IO:
188 pnpacpi_parse_allocated_ioresource(res_table,
189 res->data.fixed_io.base_address,
190 res->data.fixed_io.range_length);
192 case ACPI_RSTYPE_MEM24:
193 pnpacpi_parse_allocated_memresource(res_table,
194 res->data.memory24.min_base_address,
195 res->data.memory24.range_length);
197 case ACPI_RSTYPE_MEM32:
198 pnpacpi_parse_allocated_memresource(res_table,
199 res->data.memory32.min_base_address,
200 res->data.memory32.range_length);
202 case ACPI_RSTYPE_FIXED_MEM32:
203 pnpacpi_parse_allocated_memresource(res_table,
204 res->data.fixed_memory32.range_base_address,
205 res->data.fixed_memory32.range_length);
207 case ACPI_RSTYPE_ADDRESS16:
208 pnpacpi_parse_allocated_memresource(res_table,
209 res->data.address16.min_address_range,
210 res->data.address16.address_length);
212 case ACPI_RSTYPE_ADDRESS32:
213 pnpacpi_parse_allocated_memresource(res_table,
214 res->data.address32.min_address_range,
215 res->data.address32.address_length);
217 case ACPI_RSTYPE_ADDRESS64:
218 pnpacpi_parse_allocated_memresource(res_table,
219 res->data.address64.min_address_range,
220 res->data.address64.address_length);
222 case ACPI_RSTYPE_VENDOR:
225 pnp_warn("PnPACPI: unknown resource type %d", res->id);
232 acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle, struct pnp_resource_table * res)
234 /* Blank the resource table values */
235 pnp_init_resource_table(res);
237 return acpi_walk_resources(handle, METHOD_NAME__CRS, pnpacpi_allocated_resource, res);
240 static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_resource_dma *p)
243 struct pnp_dma * dma;
245 if (p->number_of_channels == 0)
247 dma = pnpacpi_kmalloc(sizeof(struct pnp_dma), GFP_KERNEL);
251 for(i = 0; i < p->number_of_channels; i++)
252 dma->map |= 1 << p->channels[i];
255 dma->flags |= IORESOURCE_DMA_MASTER;
257 case ACPI_COMPATIBILITY:
258 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
261 dma->flags |= IORESOURCE_DMA_TYPEA;
264 dma->flags |= IORESOURCE_DMA_TYPEB;
267 dma->flags |= IORESOURCE_DMA_TYPEF;
270 /* Set a default value ? */
271 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
272 pnp_err("Invalid DMA type");
274 switch (p->transfer) {
275 case ACPI_TRANSFER_8:
276 dma->flags |= IORESOURCE_DMA_8BIT;
278 case ACPI_TRANSFER_8_16:
279 dma->flags |= IORESOURCE_DMA_8AND16BIT;
281 case ACPI_TRANSFER_16:
282 dma->flags |= IORESOURCE_DMA_16BIT;
285 /* Set a default value ? */
286 dma->flags |= IORESOURCE_DMA_8AND16BIT;
287 pnp_err("Invalid DMA transfer type");
290 pnp_register_dma_resource(option,dma);
295 static void pnpacpi_parse_irq_option(struct pnp_option *option,
296 struct acpi_resource_irq *p)
299 struct pnp_irq * irq;
301 if (p->number_of_interrupts == 0)
303 irq = pnpacpi_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL);
307 for(i = 0; i < p->number_of_interrupts; i++)
308 if (p->interrupts[i])
309 __set_bit(p->interrupts[i], irq->map);
310 irq->flags = irq_flags(p->edge_level, p->active_high_low);
312 pnp_register_irq_resource(option, irq);
316 static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
317 struct acpi_resource_ext_irq *p)
320 struct pnp_irq * irq;
322 if (p->number_of_interrupts == 0)
324 irq = pnpacpi_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL);
328 for(i = 0; i < p->number_of_interrupts; i++)
329 if (p->interrupts[i])
330 __set_bit(p->interrupts[i], irq->map);
331 irq->flags = irq_flags(p->edge_level, p->active_high_low);
333 pnp_register_irq_resource(option, irq);
338 pnpacpi_parse_port_option(struct pnp_option *option,
339 struct acpi_resource_io *io)
341 struct pnp_port * port;
343 if (io->range_length == 0)
345 port = pnpacpi_kmalloc(sizeof(struct pnp_port), GFP_KERNEL);
348 port->min = io->min_base_address;
349 port->max = io->max_base_address;
350 port->align = io->alignment;
351 port->size = io->range_length;
352 port->flags = ACPI_DECODE_16 == io->io_decode ?
353 PNP_PORT_FLAG_16BITADDR : 0;
354 pnp_register_port_resource(option,port);
359 pnpacpi_parse_fixed_port_option(struct pnp_option *option,
360 struct acpi_resource_fixed_io *io)
362 struct pnp_port * port;
364 if (io->range_length == 0)
366 port = pnpacpi_kmalloc(sizeof(struct pnp_port), GFP_KERNEL);
369 port->min = port->max = io->base_address;
370 port->size = io->range_length;
372 port->flags = PNP_PORT_FLAG_FIXED;
373 pnp_register_port_resource(option,port);
378 pnpacpi_parse_mem24_option(struct pnp_option *option,
379 struct acpi_resource_mem24 *p)
381 struct pnp_mem * mem;
383 if (p->range_length == 0)
385 mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL);
388 mem->min = p->min_base_address;
389 mem->max = p->max_base_address;
390 mem->align = p->alignment;
391 mem->size = p->range_length;
393 mem->flags = (ACPI_READ_WRITE_MEMORY == p->read_write_attribute) ?
394 IORESOURCE_MEM_WRITEABLE : 0;
396 pnp_register_mem_resource(option,mem);
401 pnpacpi_parse_mem32_option(struct pnp_option *option,
402 struct acpi_resource_mem32 *p)
404 struct pnp_mem * mem;
406 if (p->range_length == 0)
408 mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL);
411 mem->min = p->min_base_address;
412 mem->max = p->max_base_address;
413 mem->align = p->alignment;
414 mem->size = p->range_length;
416 mem->flags = (ACPI_READ_WRITE_MEMORY == p->read_write_attribute) ?
417 IORESOURCE_MEM_WRITEABLE : 0;
419 pnp_register_mem_resource(option,mem);
424 pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
425 struct acpi_resource_fixed_mem32 *p)
427 struct pnp_mem * mem;
429 if (p->range_length == 0)
431 mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL);
434 mem->min = mem->max = p->range_base_address;
435 mem->size = p->range_length;
438 mem->flags = (ACPI_READ_WRITE_MEMORY == p->read_write_attribute) ?
439 IORESOURCE_MEM_WRITEABLE : 0;
441 pnp_register_mem_resource(option,mem);
445 struct acpipnp_parse_option_s {
446 struct pnp_option *option;
447 struct pnp_option *option_independent;
451 static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
455 struct acpipnp_parse_option_s *parse_data = (struct acpipnp_parse_option_s *)data;
456 struct pnp_dev *dev = parse_data->dev;
457 struct pnp_option *option = parse_data->option;
460 case ACPI_RSTYPE_IRQ:
461 pnpacpi_parse_irq_option(option, &res->data.irq);
463 case ACPI_RSTYPE_EXT_IRQ:
464 pnpacpi_parse_ext_irq_option(option,
465 &res->data.extended_irq);
467 case ACPI_RSTYPE_DMA:
468 pnpacpi_parse_dma_option(option, &res->data.dma);
471 pnpacpi_parse_port_option(option, &res->data.io);
473 case ACPI_RSTYPE_FIXED_IO:
474 pnpacpi_parse_fixed_port_option(option,
475 &res->data.fixed_io);
477 case ACPI_RSTYPE_MEM24:
478 pnpacpi_parse_mem24_option(option, &res->data.memory24);
480 case ACPI_RSTYPE_MEM32:
481 pnpacpi_parse_mem32_option(option, &res->data.memory32);
483 case ACPI_RSTYPE_FIXED_MEM32:
484 pnpacpi_parse_fixed_mem32_option(option,
485 &res->data.fixed_memory32);
487 case ACPI_RSTYPE_START_DPF:
488 switch (res->data.start_dpf.compatibility_priority) {
489 case ACPI_GOOD_CONFIGURATION:
490 priority = PNP_RES_PRIORITY_PREFERRED;
493 case ACPI_ACCEPTABLE_CONFIGURATION:
494 priority = PNP_RES_PRIORITY_ACCEPTABLE;
497 case ACPI_SUB_OPTIMAL_CONFIGURATION:
498 priority = PNP_RES_PRIORITY_FUNCTIONAL;
501 priority = PNP_RES_PRIORITY_INVALID;
504 /* TBD: Considering performace/robustness bits */
505 option = pnp_register_dependent_option(dev, priority);
508 parse_data->option = option;
510 case ACPI_RSTYPE_END_DPF:
511 /*only one EndDependentFn is allowed*/
512 if (!parse_data->option_independent) {
513 pnp_warn("PnPACPI: more than one EndDependentFn");
516 parse_data->option = parse_data->option_independent;
517 parse_data->option_independent = NULL;
520 pnp_warn("PnPACPI: unknown resource type %d", res->id);
527 acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
531 struct acpipnp_parse_option_s parse_data;
533 parse_data.option = pnp_register_independent_option(dev);
534 if (!parse_data.option)
536 parse_data.option_independent = parse_data.option;
537 parse_data.dev = dev;
538 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
539 pnpacpi_option_resource, &parse_data);
547 static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
550 int *res_cnt = (int *)data;
552 case ACPI_RSTYPE_IRQ:
553 case ACPI_RSTYPE_EXT_IRQ:
554 case ACPI_RSTYPE_DMA:
556 case ACPI_RSTYPE_FIXED_IO:
557 case ACPI_RSTYPE_MEM24:
558 case ACPI_RSTYPE_MEM32:
559 case ACPI_RSTYPE_FIXED_MEM32:
561 case ACPI_RSTYPE_ADDRESS16:
562 case ACPI_RSTYPE_ADDRESS32:
563 case ACPI_RSTYPE_ADDRESS64:
572 static acpi_status pnpacpi_type_resources(struct acpi_resource *res,
575 struct acpi_resource **resource = (struct acpi_resource **)data;
577 case ACPI_RSTYPE_IRQ:
578 case ACPI_RSTYPE_EXT_IRQ:
579 case ACPI_RSTYPE_DMA:
581 case ACPI_RSTYPE_FIXED_IO:
582 case ACPI_RSTYPE_MEM24:
583 case ACPI_RSTYPE_MEM32:
584 case ACPI_RSTYPE_FIXED_MEM32:
586 case ACPI_RSTYPE_ADDRESS16:
587 case ACPI_RSTYPE_ADDRESS32:
588 case ACPI_RSTYPE_ADDRESS64:
590 (*resource)->id = res->id;
599 int pnpacpi_build_resource_template(acpi_handle handle,
600 struct acpi_buffer *buffer)
602 struct acpi_resource *resource;
606 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
607 pnpacpi_count_resources, &res_cnt);
608 if (ACPI_FAILURE(status)) {
609 pnp_err("Evaluate _CRS failed");
614 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
615 buffer->pointer = pnpacpi_kmalloc(buffer->length - 1, GFP_KERNEL);
616 if (!buffer->pointer)
618 pnp_dbg("Res cnt %d", res_cnt);
619 resource = (struct acpi_resource *)buffer->pointer;
620 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
621 pnpacpi_type_resources, &resource);
622 if (ACPI_FAILURE(status)) {
623 kfree(buffer->pointer);
624 pnp_err("Evaluate _CRS failed");
627 /* resource will pointer the end resource now */
628 resource->id = ACPI_RSTYPE_END_TAG;
633 static void pnpacpi_encode_irq(struct acpi_resource *resource,
636 int edge_level, active_high_low;
638 decode_irq_flags(p->flags & IORESOURCE_BITS, &edge_level,
640 resource->id = ACPI_RSTYPE_IRQ;
641 resource->length = sizeof(struct acpi_resource);
642 resource->data.irq.edge_level = edge_level;
643 resource->data.irq.active_high_low = active_high_low;
644 if (edge_level == ACPI_EDGE_SENSITIVE)
645 resource->data.irq.shared_exclusive = ACPI_EXCLUSIVE;
647 resource->data.irq.shared_exclusive = ACPI_SHARED;
648 resource->data.irq.number_of_interrupts = 1;
649 resource->data.irq.interrupts[0] = p->start;
652 static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
655 int edge_level, active_high_low;
657 decode_irq_flags(p->flags & IORESOURCE_BITS, &edge_level,
659 resource->id = ACPI_RSTYPE_EXT_IRQ;
660 resource->length = sizeof(struct acpi_resource);
661 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
662 resource->data.extended_irq.edge_level = edge_level;
663 resource->data.extended_irq.active_high_low = active_high_low;
664 if (edge_level == ACPI_EDGE_SENSITIVE)
665 resource->data.irq.shared_exclusive = ACPI_EXCLUSIVE;
667 resource->data.irq.shared_exclusive = ACPI_SHARED;
668 resource->data.extended_irq.number_of_interrupts = 1;
669 resource->data.extended_irq.interrupts[0] = p->start;
672 static void pnpacpi_encode_dma(struct acpi_resource *resource,
675 resource->id = ACPI_RSTYPE_DMA;
676 resource->length = sizeof(struct acpi_resource);
677 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
678 if (p->flags & IORESOURCE_DMA_COMPATIBLE)
679 resource->data.dma.type = ACPI_COMPATIBILITY;
680 else if (p->flags & IORESOURCE_DMA_TYPEA)
681 resource->data.dma.type = ACPI_TYPE_A;
682 else if (p->flags & IORESOURCE_DMA_TYPEB)
683 resource->data.dma.type = ACPI_TYPE_B;
684 else if (p->flags & IORESOURCE_DMA_TYPEF)
685 resource->data.dma.type = ACPI_TYPE_F;
686 if (p->flags & IORESOURCE_DMA_8BIT)
687 resource->data.dma.transfer = ACPI_TRANSFER_8;
688 else if (p->flags & IORESOURCE_DMA_8AND16BIT)
689 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
690 else if (p->flags & IORESOURCE_DMA_16BIT)
691 resource->data.dma.transfer = ACPI_TRANSFER_16;
692 resource->data.dma.bus_master = p->flags & IORESOURCE_DMA_MASTER;
693 resource->data.dma.number_of_channels = 1;
694 resource->data.dma.channels[0] = p->start;
697 static void pnpacpi_encode_io(struct acpi_resource *resource,
700 resource->id = ACPI_RSTYPE_IO;
701 resource->length = sizeof(struct acpi_resource);
702 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
703 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR)?
704 ACPI_DECODE_16 : ACPI_DECODE_10;
705 resource->data.io.min_base_address = p->start;
706 resource->data.io.max_base_address = p->end;
707 resource->data.io.alignment = 0; /* Correct? */
708 resource->data.io.range_length = p->end - p->start + 1;
711 static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
714 resource->id = ACPI_RSTYPE_FIXED_IO;
715 resource->length = sizeof(struct acpi_resource);
716 resource->data.fixed_io.base_address = p->start;
717 resource->data.fixed_io.range_length = p->end - p->start + 1;
720 static void pnpacpi_encode_mem24(struct acpi_resource *resource,
723 resource->id = ACPI_RSTYPE_MEM24;
724 resource->length = sizeof(struct acpi_resource);
725 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
726 resource->data.memory24.read_write_attribute =
727 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
728 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
729 resource->data.memory24.min_base_address = p->start;
730 resource->data.memory24.max_base_address = p->end;
731 resource->data.memory24.alignment = 0;
732 resource->data.memory24.range_length = p->end - p->start + 1;
735 static void pnpacpi_encode_mem32(struct acpi_resource *resource,
738 resource->id = ACPI_RSTYPE_MEM32;
739 resource->length = sizeof(struct acpi_resource);
740 resource->data.memory32.read_write_attribute =
741 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
742 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
743 resource->data.memory32.min_base_address = p->start;
744 resource->data.memory32.max_base_address = p->end;
745 resource->data.memory32.alignment = 0;
746 resource->data.memory32.range_length = p->end - p->start + 1;
749 static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
752 resource->id = ACPI_RSTYPE_FIXED_MEM32;
753 resource->length = sizeof(struct acpi_resource);
754 resource->data.fixed_memory32.read_write_attribute =
755 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
756 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
757 resource->data.fixed_memory32.range_base_address = p->start;
758 resource->data.fixed_memory32.range_length = p->end - p->start + 1;
761 int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
762 struct acpi_buffer *buffer)
765 /* pnpacpi_build_resource_template allocates extra mem */
766 int res_cnt = (buffer->length - 1)/sizeof(struct acpi_resource) - 1;
767 struct acpi_resource *resource = (struct acpi_resource*)buffer->pointer;
768 int port = 0, irq = 0, dma = 0, mem = 0;
770 pnp_dbg("res cnt %d", res_cnt);
771 while (i < res_cnt) {
772 switch(resource->id) {
773 case ACPI_RSTYPE_IRQ:
774 pnp_dbg("Encode irq");
775 pnpacpi_encode_irq(resource,
776 &res_table->irq_resource[irq]);
780 case ACPI_RSTYPE_EXT_IRQ:
781 pnp_dbg("Encode ext irq");
782 pnpacpi_encode_ext_irq(resource,
783 &res_table->irq_resource[irq]);
786 case ACPI_RSTYPE_DMA:
787 pnp_dbg("Encode dma");
788 pnpacpi_encode_dma(resource,
789 &res_table->dma_resource[dma]);
793 pnp_dbg("Encode io");
794 pnpacpi_encode_io(resource,
795 &res_table->port_resource[port]);
798 case ACPI_RSTYPE_FIXED_IO:
799 pnp_dbg("Encode fixed io");
800 pnpacpi_encode_fixed_io(resource,
801 &res_table->port_resource[port]);
804 case ACPI_RSTYPE_MEM24:
805 pnp_dbg("Encode mem24");
806 pnpacpi_encode_mem24(resource,
807 &res_table->mem_resource[mem]);
810 case ACPI_RSTYPE_MEM32:
811 pnp_dbg("Encode mem32");
812 pnpacpi_encode_mem32(resource,
813 &res_table->mem_resource[mem]);
816 case ACPI_RSTYPE_FIXED_MEM32:
817 pnp_dbg("Encode fixed mem32");
818 pnpacpi_encode_fixed_mem32(resource,
819 &res_table->mem_resource[mem]);
822 default: /* other type */
823 pnp_warn("unknown resource type %d", resource->id);