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
)
79 static unsigned char warned
;
84 while (!(res
->irq_resource
[i
].flags
& IORESOURCE_UNSET
) &&
87 if (i
>= PNP_MAX_IRQ
&& !warned
) {
88 printk(KERN_ERR
"pnpacpi: exceeded the max number of IRQ "
89 "resources: %d \n", PNP_MAX_IRQ
);
94 * in IO-APIC mode, use overrided attribute. Two reasons:
96 * 2. BIOS uses IO-APIC mode Interrupt Source Override
98 if (!acpi_get_override_irq(gsi
, &t
, &p
)) {
99 t
= t
? ACPI_LEVEL_SENSITIVE
: ACPI_EDGE_SENSITIVE
;
100 p
= p
? ACPI_ACTIVE_LOW
: ACPI_ACTIVE_HIGH
;
102 if (triggering
!= t
|| polarity
!= p
) {
103 pnp_warn("IRQ %d override to %s, %s",
104 gsi
, t
? "edge":"level", p
? "low":"high");
110 res
->irq_resource
[i
].flags
= IORESOURCE_IRQ
; // Also clears _UNSET flag
111 res
->irq_resource
[i
].flags
|= irq_flags(triggering
, polarity
);
112 irq
= acpi_register_gsi(gsi
, triggering
, polarity
);
114 res
->irq_resource
[i
].flags
|= IORESOURCE_DISABLED
;
119 res
->irq_resource
[i
].flags
|= IORESOURCE_IRQ_SHAREABLE
;
121 res
->irq_resource
[i
].start
= irq
;
122 res
->irq_resource
[i
].end
= irq
;
123 pcibios_penalize_isa_irq(irq
, 1);
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_dmaresource(struct pnp_resource_table
*res
,
171 int bus_master
, int transfer
)
174 static unsigned char warned
;
176 while (i
< PNP_MAX_DMA
&&
177 !(res
->dma_resource
[i
].flags
& IORESOURCE_UNSET
))
179 if (i
< PNP_MAX_DMA
) {
180 res
->dma_resource
[i
].flags
= IORESOURCE_DMA
; // Also clears _UNSET flag
181 res
->dma_resource
[i
].flags
|=
182 dma_flags(type
, bus_master
, transfer
);
184 res
->dma_resource
[i
].flags
|= IORESOURCE_DISABLED
;
187 res
->dma_resource
[i
].start
= dma
;
188 res
->dma_resource
[i
].end
= dma
;
189 } else if (!warned
) {
190 printk(KERN_ERR
"pnpacpi: exceeded the max number of DMA "
191 "resources: %d \n", PNP_MAX_DMA
);
196 static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table
*res
,
197 u64 io
, u64 len
, int io_decode
)
200 static unsigned char warned
;
202 while (!(res
->port_resource
[i
].flags
& IORESOURCE_UNSET
) &&
205 if (i
< PNP_MAX_PORT
) {
206 res
->port_resource
[i
].flags
= IORESOURCE_IO
; // Also clears _UNSET flag
207 if (io_decode
== ACPI_DECODE_16
)
208 res
->port_resource
[i
].flags
|= PNP_PORT_FLAG_16BITADDR
;
209 if (len
<= 0 || (io
+ len
- 1) >= 0x10003) {
210 res
->port_resource
[i
].flags
|= IORESOURCE_DISABLED
;
213 res
->port_resource
[i
].start
= io
;
214 res
->port_resource
[i
].end
= io
+ len
- 1;
215 } else if (!warned
) {
216 printk(KERN_ERR
"pnpacpi: exceeded the max number of IO "
217 "resources: %d \n", PNP_MAX_PORT
);
222 static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table
*res
,
227 static unsigned char warned
;
229 while (!(res
->mem_resource
[i
].flags
& IORESOURCE_UNSET
) &&
232 if (i
< PNP_MAX_MEM
) {
233 res
->mem_resource
[i
].flags
= IORESOURCE_MEM
; // Also clears _UNSET flag
235 res
->mem_resource
[i
].flags
|= IORESOURCE_DISABLED
;
238 if (write_protect
== ACPI_READ_WRITE_MEMORY
)
239 res
->mem_resource
[i
].flags
|= IORESOURCE_MEM_WRITEABLE
;
241 res
->mem_resource
[i
].start
= mem
;
242 res
->mem_resource
[i
].end
= mem
+ len
- 1;
243 } else if (!warned
) {
244 printk(KERN_ERR
"pnpacpi: exceeded the max number of mem "
245 "resources: %d\n", PNP_MAX_MEM
);
250 static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table
*res_table
,
251 struct acpi_resource
*res
)
253 struct acpi_resource_address64 addr
, *p
= &addr
;
256 status
= acpi_resource_to_address64(res
, p
);
257 if (!ACPI_SUCCESS(status
)) {
258 pnp_warn("PnPACPI: failed to convert resource type %d",
263 if (p
->producer_consumer
== ACPI_PRODUCER
)
266 if (p
->resource_type
== ACPI_MEMORY_RANGE
)
267 pnpacpi_parse_allocated_memresource(res_table
,
268 p
->minimum
, p
->address_length
,
269 p
->info
.mem
.write_protect
);
270 else if (p
->resource_type
== ACPI_IO_RANGE
)
271 pnpacpi_parse_allocated_ioresource(res_table
,
272 p
->minimum
, p
->address_length
,
273 p
->granularity
== 0xfff ? ACPI_DECODE_10
:
277 static acpi_status
pnpacpi_allocated_resource(struct acpi_resource
*res
,
280 struct pnp_resource_table
*res_table
= data
;
284 case ACPI_RESOURCE_TYPE_IRQ
:
286 * Per spec, only one interrupt per descriptor is allowed in
287 * _CRS, but some firmware violates this, so parse them all.
289 for (i
= 0; i
< res
->data
.irq
.interrupt_count
; i
++) {
290 pnpacpi_parse_allocated_irqresource(res_table
,
291 res
->data
.irq
.interrupts
[i
],
292 res
->data
.irq
.triggering
,
293 res
->data
.irq
.polarity
,
294 res
->data
.irq
.sharable
);
298 case ACPI_RESOURCE_TYPE_DMA
:
299 if (res
->data
.dma
.channel_count
> 0)
300 pnpacpi_parse_allocated_dmaresource(res_table
,
301 res
->data
.dma
.channels
[0],
303 res
->data
.dma
.bus_master
,
304 res
->data
.dma
.transfer
);
307 case ACPI_RESOURCE_TYPE_IO
:
308 pnpacpi_parse_allocated_ioresource(res_table
,
309 res
->data
.io
.minimum
,
310 res
->data
.io
.address_length
,
311 res
->data
.io
.io_decode
);
314 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
315 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
318 case ACPI_RESOURCE_TYPE_FIXED_IO
:
319 pnpacpi_parse_allocated_ioresource(res_table
,
320 res
->data
.fixed_io
.address
,
321 res
->data
.fixed_io
.address_length
,
325 case ACPI_RESOURCE_TYPE_VENDOR
:
328 case ACPI_RESOURCE_TYPE_END_TAG
:
331 case ACPI_RESOURCE_TYPE_MEMORY24
:
332 pnpacpi_parse_allocated_memresource(res_table
,
333 res
->data
.memory24
.minimum
,
334 res
->data
.memory24
.address_length
,
335 res
->data
.memory24
.write_protect
);
337 case ACPI_RESOURCE_TYPE_MEMORY32
:
338 pnpacpi_parse_allocated_memresource(res_table
,
339 res
->data
.memory32
.minimum
,
340 res
->data
.memory32
.address_length
,
341 res
->data
.memory32
.write_protect
);
343 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
344 pnpacpi_parse_allocated_memresource(res_table
,
345 res
->data
.fixed_memory32
.address
,
346 res
->data
.fixed_memory32
.address_length
,
347 res
->data
.fixed_memory32
.write_protect
);
349 case ACPI_RESOURCE_TYPE_ADDRESS16
:
350 case ACPI_RESOURCE_TYPE_ADDRESS32
:
351 case ACPI_RESOURCE_TYPE_ADDRESS64
:
352 pnpacpi_parse_allocated_address_space(res_table
, res
);
355 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
356 if (res
->data
.ext_address64
.producer_consumer
== ACPI_PRODUCER
)
360 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
361 if (res
->data
.extended_irq
.producer_consumer
== ACPI_PRODUCER
)
364 for (i
= 0; i
< res
->data
.extended_irq
.interrupt_count
; i
++) {
365 pnpacpi_parse_allocated_irqresource(res_table
,
366 res
->data
.extended_irq
.interrupts
[i
],
367 res
->data
.extended_irq
.triggering
,
368 res
->data
.extended_irq
.polarity
,
369 res
->data
.extended_irq
.sharable
);
373 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
377 pnp_warn("PnPACPI: unknown resource type %d", res
->type
);
384 acpi_status
pnpacpi_parse_allocated_resource(acpi_handle handle
,
385 struct pnp_resource_table
* res
)
387 /* Blank the resource table values */
388 pnp_init_resource_table(res
);
390 return acpi_walk_resources(handle
, METHOD_NAME__CRS
,
391 pnpacpi_allocated_resource
, res
);
394 static void pnpacpi_parse_dma_option(struct pnp_option
*option
,
395 struct acpi_resource_dma
*p
)
400 if (p
->channel_count
== 0)
402 dma
= kzalloc(sizeof(struct pnp_dma
), GFP_KERNEL
);
406 for (i
= 0; i
< p
->channel_count
; i
++)
407 dma
->map
|= 1 << p
->channels
[i
];
409 dma
->flags
= dma_flags(p
->type
, p
->bus_master
, p
->transfer
);
411 pnp_register_dma_resource(option
, dma
);
414 static void pnpacpi_parse_irq_option(struct pnp_option
*option
,
415 struct acpi_resource_irq
*p
)
420 if (p
->interrupt_count
== 0)
422 irq
= kzalloc(sizeof(struct pnp_irq
), GFP_KERNEL
);
426 for (i
= 0; i
< p
->interrupt_count
; i
++)
427 if (p
->interrupts
[i
])
428 __set_bit(p
->interrupts
[i
], irq
->map
);
429 irq
->flags
= irq_flags(p
->triggering
, p
->polarity
);
431 pnp_register_irq_resource(option
, irq
);
434 static void pnpacpi_parse_ext_irq_option(struct pnp_option
*option
,
435 struct acpi_resource_extended_irq
*p
)
440 if (p
->interrupt_count
== 0)
442 irq
= kzalloc(sizeof(struct pnp_irq
), GFP_KERNEL
);
446 for (i
= 0; i
< p
->interrupt_count
; i
++)
447 if (p
->interrupts
[i
])
448 __set_bit(p
->interrupts
[i
], irq
->map
);
449 irq
->flags
= irq_flags(p
->triggering
, p
->polarity
);
451 pnp_register_irq_resource(option
, irq
);
454 static void pnpacpi_parse_port_option(struct pnp_option
*option
,
455 struct acpi_resource_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
= io
->minimum
;
465 port
->max
= io
->maximum
;
466 port
->align
= io
->alignment
;
467 port
->size
= io
->address_length
;
468 port
->flags
= ACPI_DECODE_16
== io
->io_decode
?
469 PNP_PORT_FLAG_16BITADDR
: 0;
470 pnp_register_port_resource(option
, port
);
473 static void pnpacpi_parse_fixed_port_option(struct pnp_option
*option
,
474 struct acpi_resource_fixed_io
*io
)
476 struct pnp_port
*port
;
478 if (io
->address_length
== 0)
480 port
= kzalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
483 port
->min
= port
->max
= io
->address
;
484 port
->size
= io
->address_length
;
486 port
->flags
= PNP_PORT_FLAG_FIXED
;
487 pnp_register_port_resource(option
, port
);
490 static void pnpacpi_parse_mem24_option(struct pnp_option
*option
,
491 struct acpi_resource_memory24
*p
)
495 if (p
->address_length
== 0)
497 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
500 mem
->min
= p
->minimum
;
501 mem
->max
= p
->maximum
;
502 mem
->align
= p
->alignment
;
503 mem
->size
= p
->address_length
;
505 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->write_protect
) ?
506 IORESOURCE_MEM_WRITEABLE
: 0;
508 pnp_register_mem_resource(option
, mem
);
511 static void pnpacpi_parse_mem32_option(struct pnp_option
*option
,
512 struct acpi_resource_memory32
*p
)
516 if (p
->address_length
== 0)
518 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
521 mem
->min
= p
->minimum
;
522 mem
->max
= p
->maximum
;
523 mem
->align
= p
->alignment
;
524 mem
->size
= p
->address_length
;
526 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->write_protect
) ?
527 IORESOURCE_MEM_WRITEABLE
: 0;
529 pnp_register_mem_resource(option
, mem
);
532 static void pnpacpi_parse_fixed_mem32_option(struct pnp_option
*option
,
533 struct acpi_resource_fixed_memory32
*p
)
537 if (p
->address_length
== 0)
539 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
542 mem
->min
= mem
->max
= p
->address
;
543 mem
->size
= p
->address_length
;
546 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->write_protect
) ?
547 IORESOURCE_MEM_WRITEABLE
: 0;
549 pnp_register_mem_resource(option
, mem
);
552 static void pnpacpi_parse_address_option(struct pnp_option
*option
,
553 struct acpi_resource
*r
)
555 struct acpi_resource_address64 addr
, *p
= &addr
;
558 struct pnp_port
*port
;
560 status
= acpi_resource_to_address64(r
, p
);
561 if (!ACPI_SUCCESS(status
)) {
562 pnp_warn("PnPACPI: failed to convert resource type %d",
567 if (p
->address_length
== 0)
570 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
571 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
574 mem
->min
= mem
->max
= p
->minimum
;
575 mem
->size
= p
->address_length
;
577 mem
->flags
= (p
->info
.mem
.write_protect
==
578 ACPI_READ_WRITE_MEMORY
) ? IORESOURCE_MEM_WRITEABLE
580 pnp_register_mem_resource(option
, mem
);
581 } else if (p
->resource_type
== ACPI_IO_RANGE
) {
582 port
= kzalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
585 port
->min
= port
->max
= p
->minimum
;
586 port
->size
= p
->address_length
;
588 port
->flags
= PNP_PORT_FLAG_FIXED
;
589 pnp_register_port_resource(option
, port
);
593 struct acpipnp_parse_option_s
{
594 struct pnp_option
*option
;
595 struct pnp_option
*option_independent
;
599 static acpi_status
pnpacpi_option_resource(struct acpi_resource
*res
,
603 struct acpipnp_parse_option_s
*parse_data
= data
;
604 struct pnp_dev
*dev
= parse_data
->dev
;
605 struct pnp_option
*option
= parse_data
->option
;
608 case ACPI_RESOURCE_TYPE_IRQ
:
609 pnpacpi_parse_irq_option(option
, &res
->data
.irq
);
612 case ACPI_RESOURCE_TYPE_DMA
:
613 pnpacpi_parse_dma_option(option
, &res
->data
.dma
);
616 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
617 switch (res
->data
.start_dpf
.compatibility_priority
) {
618 case ACPI_GOOD_CONFIGURATION
:
619 priority
= PNP_RES_PRIORITY_PREFERRED
;
622 case ACPI_ACCEPTABLE_CONFIGURATION
:
623 priority
= PNP_RES_PRIORITY_ACCEPTABLE
;
626 case ACPI_SUB_OPTIMAL_CONFIGURATION
:
627 priority
= PNP_RES_PRIORITY_FUNCTIONAL
;
630 priority
= PNP_RES_PRIORITY_INVALID
;
633 /* TBD: Consider performance/robustness bits */
634 option
= pnp_register_dependent_option(dev
, priority
);
637 parse_data
->option
= option
;
640 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
641 /*only one EndDependentFn is allowed */
642 if (!parse_data
->option_independent
) {
643 pnp_warn("PnPACPI: more than one EndDependentFn");
646 parse_data
->option
= parse_data
->option_independent
;
647 parse_data
->option_independent
= NULL
;
650 case ACPI_RESOURCE_TYPE_IO
:
651 pnpacpi_parse_port_option(option
, &res
->data
.io
);
654 case ACPI_RESOURCE_TYPE_FIXED_IO
:
655 pnpacpi_parse_fixed_port_option(option
, &res
->data
.fixed_io
);
658 case ACPI_RESOURCE_TYPE_VENDOR
:
659 case ACPI_RESOURCE_TYPE_END_TAG
:
662 case ACPI_RESOURCE_TYPE_MEMORY24
:
663 pnpacpi_parse_mem24_option(option
, &res
->data
.memory24
);
666 case ACPI_RESOURCE_TYPE_MEMORY32
:
667 pnpacpi_parse_mem32_option(option
, &res
->data
.memory32
);
670 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
671 pnpacpi_parse_fixed_mem32_option(option
,
672 &res
->data
.fixed_memory32
);
675 case ACPI_RESOURCE_TYPE_ADDRESS16
:
676 case ACPI_RESOURCE_TYPE_ADDRESS32
:
677 case ACPI_RESOURCE_TYPE_ADDRESS64
:
678 pnpacpi_parse_address_option(option
, res
);
681 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
684 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
685 pnpacpi_parse_ext_irq_option(option
, &res
->data
.extended_irq
);
688 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
692 pnp_warn("PnPACPI: unknown resource type %d", res
->type
);
699 acpi_status
pnpacpi_parse_resource_option_data(acpi_handle handle
,
700 struct pnp_dev
* dev
)
703 struct acpipnp_parse_option_s parse_data
;
705 parse_data
.option
= pnp_register_independent_option(dev
);
706 if (!parse_data
.option
)
708 parse_data
.option_independent
= parse_data
.option
;
709 parse_data
.dev
= dev
;
710 status
= acpi_walk_resources(handle
, METHOD_NAME__PRS
,
711 pnpacpi_option_resource
, &parse_data
);
716 static int pnpacpi_supported_resource(struct acpi_resource
*res
)
719 case ACPI_RESOURCE_TYPE_IRQ
:
720 case ACPI_RESOURCE_TYPE_DMA
:
721 case ACPI_RESOURCE_TYPE_IO
:
722 case ACPI_RESOURCE_TYPE_FIXED_IO
:
723 case ACPI_RESOURCE_TYPE_MEMORY24
:
724 case ACPI_RESOURCE_TYPE_MEMORY32
:
725 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
726 case ACPI_RESOURCE_TYPE_ADDRESS16
:
727 case ACPI_RESOURCE_TYPE_ADDRESS32
:
728 case ACPI_RESOURCE_TYPE_ADDRESS64
:
729 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
738 static acpi_status
pnpacpi_count_resources(struct acpi_resource
*res
,
743 if (pnpacpi_supported_resource(res
))
748 static acpi_status
pnpacpi_type_resources(struct acpi_resource
*res
, void *data
)
750 struct acpi_resource
**resource
= data
;
752 if (pnpacpi_supported_resource(res
)) {
753 (*resource
)->type
= res
->type
;
754 (*resource
)->length
= sizeof(struct acpi_resource
);
761 int pnpacpi_build_resource_template(acpi_handle handle
,
762 struct acpi_buffer
*buffer
)
764 struct acpi_resource
*resource
;
768 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
769 pnpacpi_count_resources
, &res_cnt
);
770 if (ACPI_FAILURE(status
)) {
771 pnp_err("Evaluate _CRS failed");
776 buffer
->length
= sizeof(struct acpi_resource
) * (res_cnt
+ 1) + 1;
777 buffer
->pointer
= kzalloc(buffer
->length
- 1, GFP_KERNEL
);
778 if (!buffer
->pointer
)
780 pnp_dbg("Res cnt %d", res_cnt
);
781 resource
= (struct acpi_resource
*)buffer
->pointer
;
782 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
783 pnpacpi_type_resources
, &resource
);
784 if (ACPI_FAILURE(status
)) {
785 kfree(buffer
->pointer
);
786 pnp_err("Evaluate _CRS failed");
789 /* resource will pointer the end resource now */
790 resource
->type
= ACPI_RESOURCE_TYPE_END_TAG
;
795 static void pnpacpi_encode_irq(struct acpi_resource
*resource
,
798 int triggering
, polarity
;
800 decode_irq_flags(p
->flags
& IORESOURCE_BITS
, &triggering
, &polarity
);
801 resource
->data
.irq
.triggering
= triggering
;
802 resource
->data
.irq
.polarity
= polarity
;
803 if (triggering
== ACPI_EDGE_SENSITIVE
)
804 resource
->data
.irq
.sharable
= ACPI_EXCLUSIVE
;
806 resource
->data
.irq
.sharable
= ACPI_SHARED
;
807 resource
->data
.irq
.interrupt_count
= 1;
808 resource
->data
.irq
.interrupts
[0] = p
->start
;
811 static void pnpacpi_encode_ext_irq(struct acpi_resource
*resource
,
814 int triggering
, polarity
;
816 decode_irq_flags(p
->flags
& IORESOURCE_BITS
, &triggering
, &polarity
);
817 resource
->data
.extended_irq
.producer_consumer
= ACPI_CONSUMER
;
818 resource
->data
.extended_irq
.triggering
= triggering
;
819 resource
->data
.extended_irq
.polarity
= polarity
;
820 if (triggering
== ACPI_EDGE_SENSITIVE
)
821 resource
->data
.irq
.sharable
= ACPI_EXCLUSIVE
;
823 resource
->data
.irq
.sharable
= ACPI_SHARED
;
824 resource
->data
.extended_irq
.interrupt_count
= 1;
825 resource
->data
.extended_irq
.interrupts
[0] = p
->start
;
828 static void pnpacpi_encode_dma(struct acpi_resource
*resource
,
831 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
832 switch (p
->flags
& IORESOURCE_DMA_SPEED_MASK
) {
833 case IORESOURCE_DMA_TYPEA
:
834 resource
->data
.dma
.type
= ACPI_TYPE_A
;
836 case IORESOURCE_DMA_TYPEB
:
837 resource
->data
.dma
.type
= ACPI_TYPE_B
;
839 case IORESOURCE_DMA_TYPEF
:
840 resource
->data
.dma
.type
= ACPI_TYPE_F
;
843 resource
->data
.dma
.type
= ACPI_COMPATIBILITY
;
846 switch (p
->flags
& IORESOURCE_DMA_TYPE_MASK
) {
847 case IORESOURCE_DMA_8BIT
:
848 resource
->data
.dma
.transfer
= ACPI_TRANSFER_8
;
850 case IORESOURCE_DMA_8AND16BIT
:
851 resource
->data
.dma
.transfer
= ACPI_TRANSFER_8_16
;
854 resource
->data
.dma
.transfer
= ACPI_TRANSFER_16
;
857 resource
->data
.dma
.bus_master
= !!(p
->flags
& IORESOURCE_DMA_MASTER
);
858 resource
->data
.dma
.channel_count
= 1;
859 resource
->data
.dma
.channels
[0] = p
->start
;
862 static void pnpacpi_encode_io(struct acpi_resource
*resource
,
865 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
866 resource
->data
.io
.io_decode
= (p
->flags
& PNP_PORT_FLAG_16BITADDR
) ?
867 ACPI_DECODE_16
: ACPI_DECODE_10
;
868 resource
->data
.io
.minimum
= p
->start
;
869 resource
->data
.io
.maximum
= p
->end
;
870 resource
->data
.io
.alignment
= 0; /* Correct? */
871 resource
->data
.io
.address_length
= p
->end
- p
->start
+ 1;
874 static void pnpacpi_encode_fixed_io(struct acpi_resource
*resource
,
877 resource
->data
.fixed_io
.address
= p
->start
;
878 resource
->data
.fixed_io
.address_length
= p
->end
- p
->start
+ 1;
881 static void pnpacpi_encode_mem24(struct acpi_resource
*resource
,
884 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
885 resource
->data
.memory24
.write_protect
=
886 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
887 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
888 resource
->data
.memory24
.minimum
= p
->start
;
889 resource
->data
.memory24
.maximum
= p
->end
;
890 resource
->data
.memory24
.alignment
= 0;
891 resource
->data
.memory24
.address_length
= p
->end
- p
->start
+ 1;
894 static void pnpacpi_encode_mem32(struct acpi_resource
*resource
,
897 resource
->data
.memory32
.write_protect
=
898 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
899 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
900 resource
->data
.memory32
.minimum
= p
->start
;
901 resource
->data
.memory32
.maximum
= p
->end
;
902 resource
->data
.memory32
.alignment
= 0;
903 resource
->data
.memory32
.address_length
= p
->end
- p
->start
+ 1;
906 static void pnpacpi_encode_fixed_mem32(struct acpi_resource
*resource
,
909 resource
->data
.fixed_memory32
.write_protect
=
910 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
911 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
912 resource
->data
.fixed_memory32
.address
= p
->start
;
913 resource
->data
.fixed_memory32
.address_length
= p
->end
- p
->start
+ 1;
916 int pnpacpi_encode_resources(struct pnp_resource_table
*res_table
,
917 struct acpi_buffer
*buffer
)
920 /* pnpacpi_build_resource_template allocates extra mem */
921 int res_cnt
= (buffer
->length
- 1) / sizeof(struct acpi_resource
) - 1;
922 struct acpi_resource
*resource
= buffer
->pointer
;
923 int port
= 0, irq
= 0, dma
= 0, mem
= 0;
925 pnp_dbg("res cnt %d", res_cnt
);
926 while (i
< res_cnt
) {
927 switch (resource
->type
) {
928 case ACPI_RESOURCE_TYPE_IRQ
:
929 pnp_dbg("Encode irq");
930 pnpacpi_encode_irq(resource
,
931 &res_table
->irq_resource
[irq
]);
935 case ACPI_RESOURCE_TYPE_DMA
:
936 pnp_dbg("Encode dma");
937 pnpacpi_encode_dma(resource
,
938 &res_table
->dma_resource
[dma
]);
941 case ACPI_RESOURCE_TYPE_IO
:
942 pnp_dbg("Encode io");
943 pnpacpi_encode_io(resource
,
944 &res_table
->port_resource
[port
]);
947 case ACPI_RESOURCE_TYPE_FIXED_IO
:
948 pnp_dbg("Encode fixed io");
949 pnpacpi_encode_fixed_io(resource
,
951 port_resource
[port
]);
954 case ACPI_RESOURCE_TYPE_MEMORY24
:
955 pnp_dbg("Encode mem24");
956 pnpacpi_encode_mem24(resource
,
957 &res_table
->mem_resource
[mem
]);
960 case ACPI_RESOURCE_TYPE_MEMORY32
:
961 pnp_dbg("Encode mem32");
962 pnpacpi_encode_mem32(resource
,
963 &res_table
->mem_resource
[mem
]);
966 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
967 pnp_dbg("Encode fixed mem32");
968 pnpacpi_encode_fixed_mem32(resource
,
973 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
974 pnp_dbg("Encode ext irq");
975 pnpacpi_encode_ext_irq(resource
,
976 &res_table
->irq_resource
[irq
]);
979 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
980 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
981 case ACPI_RESOURCE_TYPE_VENDOR
:
982 case ACPI_RESOURCE_TYPE_END_TAG
:
983 case ACPI_RESOURCE_TYPE_ADDRESS16
:
984 case ACPI_RESOURCE_TYPE_ADDRESS32
:
985 case ACPI_RESOURCE_TYPE_ADDRESS64
:
986 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
987 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
988 default: /* other type */
989 pnp_warn("unknown resource type %d", resource
->type
);