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
, int shareable
)
85 while (!(res
->irq_resource
[i
].flags
& IORESOURCE_UNSET
) &&
91 res
->irq_resource
[i
].flags
= IORESOURCE_IRQ
; // Also clears _UNSET flag
92 res
->irq_resource
[i
].flags
|= irq_flags(triggering
, polarity
);
93 irq
= acpi_register_gsi(gsi
, triggering
, polarity
);
95 res
->irq_resource
[i
].flags
|= IORESOURCE_DISABLED
;
100 res
->irq_resource
[i
].flags
|= IORESOURCE_IRQ_SHAREABLE
;
102 res
->irq_resource
[i
].start
= irq
;
103 res
->irq_resource
[i
].end
= irq
;
104 pcibios_penalize_isa_irq(irq
, 1);
107 static int dma_flags(int type
, int bus_master
, int transfer
)
112 flags
|= IORESOURCE_DMA_MASTER
;
114 case ACPI_COMPATIBILITY
:
115 flags
|= IORESOURCE_DMA_COMPATIBLE
;
118 flags
|= IORESOURCE_DMA_TYPEA
;
121 flags
|= IORESOURCE_DMA_TYPEB
;
124 flags
|= IORESOURCE_DMA_TYPEF
;
127 /* Set a default value ? */
128 flags
|= IORESOURCE_DMA_COMPATIBLE
;
129 pnp_err("Invalid DMA type");
132 case ACPI_TRANSFER_8
:
133 flags
|= IORESOURCE_DMA_8BIT
;
135 case ACPI_TRANSFER_8_16
:
136 flags
|= IORESOURCE_DMA_8AND16BIT
;
138 case ACPI_TRANSFER_16
:
139 flags
|= IORESOURCE_DMA_16BIT
;
142 /* Set a default value ? */
143 flags
|= IORESOURCE_DMA_8AND16BIT
;
144 pnp_err("Invalid DMA transfer type");
151 pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table
*res
, u32 dma
,
152 int type
, int bus_master
, int transfer
)
155 while (i
< PNP_MAX_DMA
&&
156 !(res
->dma_resource
[i
].flags
& IORESOURCE_UNSET
))
158 if (i
< PNP_MAX_DMA
) {
159 res
->dma_resource
[i
].flags
= IORESOURCE_DMA
; // Also clears _UNSET flag
160 res
->dma_resource
[i
].flags
|= dma_flags(type
, bus_master
, transfer
);
162 res
->dma_resource
[i
].flags
|= IORESOURCE_DISABLED
;
165 res
->dma_resource
[i
].start
= dma
;
166 res
->dma_resource
[i
].end
= dma
;
171 pnpacpi_parse_allocated_ioresource(struct pnp_resource_table
*res
,
172 u64 io
, u64 len
, int io_decode
)
175 while (!(res
->port_resource
[i
].flags
& IORESOURCE_UNSET
) &&
178 if (i
< PNP_MAX_PORT
) {
179 res
->port_resource
[i
].flags
= IORESOURCE_IO
; // Also clears _UNSET flag
180 if (io_decode
== ACPI_DECODE_16
)
181 res
->port_resource
[i
].flags
|= PNP_PORT_FLAG_16BITADDR
;
182 if (len
<= 0 || (io
+ len
-1) >= 0x10003) {
183 res
->port_resource
[i
].flags
|= IORESOURCE_DISABLED
;
186 res
->port_resource
[i
].start
= io
;
187 res
->port_resource
[i
].end
= io
+ len
- 1;
192 pnpacpi_parse_allocated_memresource(struct pnp_resource_table
*res
,
193 u64 mem
, u64 len
, int write_protect
)
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;
214 pnpacpi_parse_allocated_address_space(struct pnp_resource_table
*res_table
,
215 struct acpi_resource
*res
)
217 struct acpi_resource_address64 addr
, *p
= &addr
;
220 status
= acpi_resource_to_address64(res
, p
);
221 if (!ACPI_SUCCESS(status
)) {
222 pnp_warn("PnPACPI: failed to convert resource type %d",
227 if (p
->producer_consumer
== ACPI_PRODUCER
)
230 if (p
->resource_type
== ACPI_MEMORY_RANGE
)
231 pnpacpi_parse_allocated_memresource(res_table
,
232 p
->minimum
, p
->address_length
, 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
: ACPI_DECODE_16
);
239 static acpi_status
pnpacpi_allocated_resource(struct acpi_resource
*res
,
242 struct pnp_resource_table
*res_table
= (struct pnp_resource_table
*)data
;
246 case ACPI_RESOURCE_TYPE_IRQ
:
248 * Per spec, only one interrupt per descriptor is allowed in
249 * _CRS, but some firmware violates this, so parse them all.
251 for (i
= 0; i
< res
->data
.irq
.interrupt_count
; i
++) {
252 pnpacpi_parse_allocated_irqresource(res_table
,
253 res
->data
.irq
.interrupts
[i
],
254 res
->data
.irq
.triggering
,
255 res
->data
.irq
.polarity
,
256 res
->data
.irq
.sharable
);
260 case ACPI_RESOURCE_TYPE_DMA
:
261 if (res
->data
.dma
.channel_count
> 0)
262 pnpacpi_parse_allocated_dmaresource(res_table
,
263 res
->data
.dma
.channels
[0],
265 res
->data
.dma
.bus_master
,
266 res
->data
.dma
.transfer
);
269 case ACPI_RESOURCE_TYPE_IO
:
270 pnpacpi_parse_allocated_ioresource(res_table
,
271 res
->data
.io
.minimum
,
272 res
->data
.io
.address_length
,
273 res
->data
.io
.io_decode
);
276 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
277 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
280 case ACPI_RESOURCE_TYPE_FIXED_IO
:
281 pnpacpi_parse_allocated_ioresource(res_table
,
282 res
->data
.fixed_io
.address
,
283 res
->data
.fixed_io
.address_length
,
287 case ACPI_RESOURCE_TYPE_VENDOR
:
290 case ACPI_RESOURCE_TYPE_END_TAG
:
293 case ACPI_RESOURCE_TYPE_MEMORY24
:
294 pnpacpi_parse_allocated_memresource(res_table
,
295 res
->data
.memory24
.minimum
,
296 res
->data
.memory24
.address_length
,
297 res
->data
.memory24
.write_protect
);
299 case ACPI_RESOURCE_TYPE_MEMORY32
:
300 pnpacpi_parse_allocated_memresource(res_table
,
301 res
->data
.memory32
.minimum
,
302 res
->data
.memory32
.address_length
,
303 res
->data
.memory32
.write_protect
);
305 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
306 pnpacpi_parse_allocated_memresource(res_table
,
307 res
->data
.fixed_memory32
.address
,
308 res
->data
.fixed_memory32
.address_length
,
309 res
->data
.fixed_memory32
.write_protect
);
311 case ACPI_RESOURCE_TYPE_ADDRESS16
:
312 case ACPI_RESOURCE_TYPE_ADDRESS32
:
313 case ACPI_RESOURCE_TYPE_ADDRESS64
:
314 pnpacpi_parse_allocated_address_space(res_table
, res
);
317 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
318 if (res
->data
.ext_address64
.producer_consumer
== ACPI_PRODUCER
)
322 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
323 if (res
->data
.extended_irq
.producer_consumer
== ACPI_PRODUCER
)
326 for (i
= 0; i
< res
->data
.extended_irq
.interrupt_count
; i
++) {
327 pnpacpi_parse_allocated_irqresource(res_table
,
328 res
->data
.extended_irq
.interrupts
[i
],
329 res
->data
.extended_irq
.triggering
,
330 res
->data
.extended_irq
.polarity
,
331 res
->data
.extended_irq
.sharable
);
335 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
339 pnp_warn("PnPACPI: unknown resource type %d", res
->type
);
346 acpi_status
pnpacpi_parse_allocated_resource(acpi_handle handle
, struct pnp_resource_table
*res
)
348 /* Blank the resource table values */
349 pnp_init_resource_table(res
);
351 return acpi_walk_resources(handle
, METHOD_NAME__CRS
, pnpacpi_allocated_resource
, res
);
354 static void pnpacpi_parse_dma_option(struct pnp_option
*option
, struct acpi_resource_dma
*p
)
357 struct pnp_dma
* dma
;
359 if (p
->channel_count
== 0)
361 dma
= kzalloc(sizeof(struct pnp_dma
), GFP_KERNEL
);
365 for(i
= 0; i
< p
->channel_count
; i
++)
366 dma
->map
|= 1 << p
->channels
[i
];
368 dma
->flags
= dma_flags(p
->type
, p
->bus_master
, p
->transfer
);
370 pnp_register_dma_resource(option
, dma
);
375 static void pnpacpi_parse_irq_option(struct pnp_option
*option
,
376 struct acpi_resource_irq
*p
)
381 if (p
->interrupt_count
== 0)
383 irq
= kzalloc(sizeof(struct pnp_irq
), GFP_KERNEL
);
387 for(i
= 0; i
< p
->interrupt_count
; i
++)
388 if (p
->interrupts
[i
])
389 __set_bit(p
->interrupts
[i
], irq
->map
);
390 irq
->flags
= irq_flags(p
->triggering
, p
->polarity
);
392 pnp_register_irq_resource(option
, irq
);
396 static void pnpacpi_parse_ext_irq_option(struct pnp_option
*option
,
397 struct acpi_resource_extended_irq
*p
)
402 if (p
->interrupt_count
== 0)
404 irq
= kzalloc(sizeof(struct pnp_irq
), GFP_KERNEL
);
408 for(i
= 0; i
< p
->interrupt_count
; i
++)
409 if (p
->interrupts
[i
])
410 __set_bit(p
->interrupts
[i
], irq
->map
);
411 irq
->flags
= irq_flags(p
->triggering
, p
->polarity
);
413 pnp_register_irq_resource(option
, irq
);
418 pnpacpi_parse_port_option(struct pnp_option
*option
,
419 struct acpi_resource_io
*io
)
421 struct pnp_port
*port
;
423 if (io
->address_length
== 0)
425 port
= kzalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
428 port
->min
= io
->minimum
;
429 port
->max
= io
->maximum
;
430 port
->align
= io
->alignment
;
431 port
->size
= io
->address_length
;
432 port
->flags
= ACPI_DECODE_16
== io
->io_decode
?
433 PNP_PORT_FLAG_16BITADDR
: 0;
434 pnp_register_port_resource(option
, port
);
439 pnpacpi_parse_fixed_port_option(struct pnp_option
*option
,
440 struct acpi_resource_fixed_io
*io
)
442 struct pnp_port
*port
;
444 if (io
->address_length
== 0)
446 port
= kzalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
449 port
->min
= port
->max
= io
->address
;
450 port
->size
= io
->address_length
;
452 port
->flags
= PNP_PORT_FLAG_FIXED
;
453 pnp_register_port_resource(option
, port
);
458 pnpacpi_parse_mem24_option(struct pnp_option
*option
,
459 struct acpi_resource_memory24
*p
)
463 if (p
->address_length
== 0)
465 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
468 mem
->min
= p
->minimum
;
469 mem
->max
= p
->maximum
;
470 mem
->align
= p
->alignment
;
471 mem
->size
= p
->address_length
;
473 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->write_protect
) ?
474 IORESOURCE_MEM_WRITEABLE
: 0;
476 pnp_register_mem_resource(option
, mem
);
481 pnpacpi_parse_mem32_option(struct pnp_option
*option
,
482 struct acpi_resource_memory32
*p
)
486 if (p
->address_length
== 0)
488 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
491 mem
->min
= p
->minimum
;
492 mem
->max
= p
->maximum
;
493 mem
->align
= p
->alignment
;
494 mem
->size
= p
->address_length
;
496 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->write_protect
) ?
497 IORESOURCE_MEM_WRITEABLE
: 0;
499 pnp_register_mem_resource(option
, mem
);
504 pnpacpi_parse_fixed_mem32_option(struct pnp_option
*option
,
505 struct acpi_resource_fixed_memory32
*p
)
509 if (p
->address_length
== 0)
511 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
514 mem
->min
= mem
->max
= p
->address
;
515 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
);
526 pnpacpi_parse_address_option(struct pnp_option
*option
, struct acpi_resource
*r
)
528 struct acpi_resource_address64 addr
, *p
= &addr
;
531 struct pnp_port
*port
;
533 status
= acpi_resource_to_address64(r
, p
);
534 if (!ACPI_SUCCESS(status
)) {
535 pnp_warn("PnPACPI: failed to convert resource type %d", r
->type
);
539 if (p
->address_length
== 0)
542 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
543 mem
= kzalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
546 mem
->min
= mem
->max
= p
->minimum
;
547 mem
->size
= p
->address_length
;
549 mem
->flags
= (p
->info
.mem
.write_protect
==
550 ACPI_READ_WRITE_MEMORY
) ? IORESOURCE_MEM_WRITEABLE
: 0;
551 pnp_register_mem_resource(option
, mem
);
552 } else if (p
->resource_type
== ACPI_IO_RANGE
) {
553 port
= kzalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
556 port
->min
= port
->max
= p
->minimum
;
557 port
->size
= p
->address_length
;
559 port
->flags
= PNP_PORT_FLAG_FIXED
;
560 pnp_register_port_resource(option
, port
);
564 struct acpipnp_parse_option_s
{
565 struct pnp_option
*option
;
566 struct pnp_option
*option_independent
;
570 static acpi_status
pnpacpi_option_resource(struct acpi_resource
*res
,
574 struct acpipnp_parse_option_s
*parse_data
= (struct acpipnp_parse_option_s
*)data
;
575 struct pnp_dev
*dev
= parse_data
->dev
;
576 struct pnp_option
*option
= parse_data
->option
;
579 case ACPI_RESOURCE_TYPE_IRQ
:
580 pnpacpi_parse_irq_option(option
, &res
->data
.irq
);
583 case ACPI_RESOURCE_TYPE_DMA
:
584 pnpacpi_parse_dma_option(option
, &res
->data
.dma
);
587 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
588 switch (res
->data
.start_dpf
.compatibility_priority
) {
589 case ACPI_GOOD_CONFIGURATION
:
590 priority
= PNP_RES_PRIORITY_PREFERRED
;
593 case ACPI_ACCEPTABLE_CONFIGURATION
:
594 priority
= PNP_RES_PRIORITY_ACCEPTABLE
;
597 case ACPI_SUB_OPTIMAL_CONFIGURATION
:
598 priority
= PNP_RES_PRIORITY_FUNCTIONAL
;
601 priority
= PNP_RES_PRIORITY_INVALID
;
604 /* TBD: Considering performace/robustness bits */
605 option
= pnp_register_dependent_option(dev
, priority
);
608 parse_data
->option
= option
;
611 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
612 /*only one EndDependentFn is allowed*/
613 if (!parse_data
->option_independent
) {
614 pnp_warn("PnPACPI: more than one EndDependentFn");
617 parse_data
->option
= parse_data
->option_independent
;
618 parse_data
->option_independent
= NULL
;
621 case ACPI_RESOURCE_TYPE_IO
:
622 pnpacpi_parse_port_option(option
, &res
->data
.io
);
625 case ACPI_RESOURCE_TYPE_FIXED_IO
:
626 pnpacpi_parse_fixed_port_option(option
,
627 &res
->data
.fixed_io
);
630 case ACPI_RESOURCE_TYPE_VENDOR
:
631 case ACPI_RESOURCE_TYPE_END_TAG
:
634 case ACPI_RESOURCE_TYPE_MEMORY24
:
635 pnpacpi_parse_mem24_option(option
, &res
->data
.memory24
);
638 case ACPI_RESOURCE_TYPE_MEMORY32
:
639 pnpacpi_parse_mem32_option(option
, &res
->data
.memory32
);
642 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
643 pnpacpi_parse_fixed_mem32_option(option
,
644 &res
->data
.fixed_memory32
);
647 case ACPI_RESOURCE_TYPE_ADDRESS16
:
648 case ACPI_RESOURCE_TYPE_ADDRESS32
:
649 case ACPI_RESOURCE_TYPE_ADDRESS64
:
650 pnpacpi_parse_address_option(option
, res
);
653 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
656 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
657 pnpacpi_parse_ext_irq_option(option
,
658 &res
->data
.extended_irq
);
661 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
665 pnp_warn("PnPACPI: unknown resource type %d", res
->type
);
672 acpi_status
pnpacpi_parse_resource_option_data(acpi_handle handle
,
676 struct acpipnp_parse_option_s parse_data
;
678 parse_data
.option
= pnp_register_independent_option(dev
);
679 if (!parse_data
.option
)
681 parse_data
.option_independent
= parse_data
.option
;
682 parse_data
.dev
= dev
;
683 status
= acpi_walk_resources(handle
, METHOD_NAME__PRS
,
684 pnpacpi_option_resource
, &parse_data
);
689 static int pnpacpi_supported_resource(struct acpi_resource
*res
)
692 case ACPI_RESOURCE_TYPE_IRQ
:
693 case ACPI_RESOURCE_TYPE_DMA
:
694 case ACPI_RESOURCE_TYPE_IO
:
695 case ACPI_RESOURCE_TYPE_FIXED_IO
:
696 case ACPI_RESOURCE_TYPE_MEMORY24
:
697 case ACPI_RESOURCE_TYPE_MEMORY32
:
698 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
699 case ACPI_RESOURCE_TYPE_ADDRESS16
:
700 case ACPI_RESOURCE_TYPE_ADDRESS32
:
701 case ACPI_RESOURCE_TYPE_ADDRESS64
:
702 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
711 static acpi_status
pnpacpi_count_resources(struct acpi_resource
*res
,
714 int *res_cnt
= (int *)data
;
716 if (pnpacpi_supported_resource(res
))
721 static acpi_status
pnpacpi_type_resources(struct acpi_resource
*res
, void *data
)
723 struct acpi_resource
**resource
= (struct acpi_resource
**)data
;
725 if (pnpacpi_supported_resource(res
)) {
726 (*resource
)->type
= res
->type
;
727 (*resource
)->length
= sizeof(struct acpi_resource
);
734 int pnpacpi_build_resource_template(acpi_handle handle
,
735 struct acpi_buffer
*buffer
)
737 struct acpi_resource
*resource
;
741 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
742 pnpacpi_count_resources
, &res_cnt
);
743 if (ACPI_FAILURE(status
)) {
744 pnp_err("Evaluate _CRS failed");
749 buffer
->length
= sizeof(struct acpi_resource
) * (res_cnt
+ 1) + 1;
750 buffer
->pointer
= kzalloc(buffer
->length
- 1, GFP_KERNEL
);
751 if (!buffer
->pointer
)
753 pnp_dbg("Res cnt %d", res_cnt
);
754 resource
= (struct acpi_resource
*)buffer
->pointer
;
755 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
756 pnpacpi_type_resources
, &resource
);
757 if (ACPI_FAILURE(status
)) {
758 kfree(buffer
->pointer
);
759 pnp_err("Evaluate _CRS failed");
762 /* resource will pointer the end resource now */
763 resource
->type
= ACPI_RESOURCE_TYPE_END_TAG
;
768 static void pnpacpi_encode_irq(struct acpi_resource
*resource
,
771 int triggering
, polarity
;
773 decode_irq_flags(p
->flags
& IORESOURCE_BITS
, &triggering
, &polarity
);
774 resource
->data
.irq
.triggering
= triggering
;
775 resource
->data
.irq
.polarity
= polarity
;
776 if (triggering
== ACPI_EDGE_SENSITIVE
)
777 resource
->data
.irq
.sharable
= ACPI_EXCLUSIVE
;
779 resource
->data
.irq
.sharable
= ACPI_SHARED
;
780 resource
->data
.irq
.interrupt_count
= 1;
781 resource
->data
.irq
.interrupts
[0] = p
->start
;
784 static void pnpacpi_encode_ext_irq(struct acpi_resource
*resource
,
787 int triggering
, polarity
;
789 decode_irq_flags(p
->flags
& IORESOURCE_BITS
, &triggering
, &polarity
);
790 resource
->data
.extended_irq
.producer_consumer
= ACPI_CONSUMER
;
791 resource
->data
.extended_irq
.triggering
= triggering
;
792 resource
->data
.extended_irq
.polarity
= polarity
;
793 if (triggering
== ACPI_EDGE_SENSITIVE
)
794 resource
->data
.irq
.sharable
= ACPI_EXCLUSIVE
;
796 resource
->data
.irq
.sharable
= ACPI_SHARED
;
797 resource
->data
.extended_irq
.interrupt_count
= 1;
798 resource
->data
.extended_irq
.interrupts
[0] = p
->start
;
801 static void pnpacpi_encode_dma(struct acpi_resource
*resource
,
804 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
805 switch (p
->flags
& IORESOURCE_DMA_SPEED_MASK
) {
806 case IORESOURCE_DMA_TYPEA
:
807 resource
->data
.dma
.type
= ACPI_TYPE_A
;
809 case IORESOURCE_DMA_TYPEB
:
810 resource
->data
.dma
.type
= ACPI_TYPE_B
;
812 case IORESOURCE_DMA_TYPEF
:
813 resource
->data
.dma
.type
= ACPI_TYPE_F
;
816 resource
->data
.dma
.type
= ACPI_COMPATIBILITY
;
819 switch (p
->flags
& IORESOURCE_DMA_TYPE_MASK
) {
820 case IORESOURCE_DMA_8BIT
:
821 resource
->data
.dma
.transfer
= ACPI_TRANSFER_8
;
823 case IORESOURCE_DMA_8AND16BIT
:
824 resource
->data
.dma
.transfer
= ACPI_TRANSFER_8_16
;
827 resource
->data
.dma
.transfer
= ACPI_TRANSFER_16
;
830 resource
->data
.dma
.bus_master
= !!(p
->flags
& IORESOURCE_DMA_MASTER
);
831 resource
->data
.dma
.channel_count
= 1;
832 resource
->data
.dma
.channels
[0] = p
->start
;
835 static void pnpacpi_encode_io(struct acpi_resource
*resource
,
838 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
839 resource
->data
.io
.io_decode
= (p
->flags
& PNP_PORT_FLAG_16BITADDR
)?
840 ACPI_DECODE_16
: ACPI_DECODE_10
;
841 resource
->data
.io
.minimum
= p
->start
;
842 resource
->data
.io
.maximum
= p
->end
;
843 resource
->data
.io
.alignment
= 0; /* Correct? */
844 resource
->data
.io
.address_length
= p
->end
- p
->start
+ 1;
847 static void pnpacpi_encode_fixed_io(struct acpi_resource
*resource
,
850 resource
->data
.fixed_io
.address
= p
->start
;
851 resource
->data
.fixed_io
.address_length
= p
->end
- p
->start
+ 1;
854 static void pnpacpi_encode_mem24(struct acpi_resource
*resource
,
857 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
858 resource
->data
.memory24
.write_protect
=
859 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
860 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
861 resource
->data
.memory24
.minimum
= p
->start
;
862 resource
->data
.memory24
.maximum
= p
->end
;
863 resource
->data
.memory24
.alignment
= 0;
864 resource
->data
.memory24
.address_length
= p
->end
- p
->start
+ 1;
867 static void pnpacpi_encode_mem32(struct acpi_resource
*resource
,
870 resource
->data
.memory32
.write_protect
=
871 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
872 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
873 resource
->data
.memory32
.minimum
= p
->start
;
874 resource
->data
.memory32
.maximum
= p
->end
;
875 resource
->data
.memory32
.alignment
= 0;
876 resource
->data
.memory32
.address_length
= p
->end
- p
->start
+ 1;
879 static void pnpacpi_encode_fixed_mem32(struct acpi_resource
*resource
,
882 resource
->data
.fixed_memory32
.write_protect
=
883 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
884 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
885 resource
->data
.fixed_memory32
.address
= p
->start
;
886 resource
->data
.fixed_memory32
.address_length
= p
->end
- p
->start
+ 1;
889 int pnpacpi_encode_resources(struct pnp_resource_table
*res_table
,
890 struct acpi_buffer
*buffer
)
893 /* pnpacpi_build_resource_template allocates extra mem */
894 int res_cnt
= (buffer
->length
- 1)/sizeof(struct acpi_resource
) - 1;
895 struct acpi_resource
*resource
= (struct acpi_resource
*)buffer
->pointer
;
896 int port
= 0, irq
= 0, dma
= 0, mem
= 0;
898 pnp_dbg("res cnt %d", res_cnt
);
899 while (i
< res_cnt
) {
900 switch(resource
->type
) {
901 case ACPI_RESOURCE_TYPE_IRQ
:
902 pnp_dbg("Encode irq");
903 pnpacpi_encode_irq(resource
,
904 &res_table
->irq_resource
[irq
]);
908 case ACPI_RESOURCE_TYPE_DMA
:
909 pnp_dbg("Encode dma");
910 pnpacpi_encode_dma(resource
,
911 &res_table
->dma_resource
[dma
]);
914 case ACPI_RESOURCE_TYPE_IO
:
915 pnp_dbg("Encode io");
916 pnpacpi_encode_io(resource
,
917 &res_table
->port_resource
[port
]);
920 case ACPI_RESOURCE_TYPE_FIXED_IO
:
921 pnp_dbg("Encode fixed io");
922 pnpacpi_encode_fixed_io(resource
,
923 &res_table
->port_resource
[port
]);
926 case ACPI_RESOURCE_TYPE_MEMORY24
:
927 pnp_dbg("Encode mem24");
928 pnpacpi_encode_mem24(resource
,
929 &res_table
->mem_resource
[mem
]);
932 case ACPI_RESOURCE_TYPE_MEMORY32
:
933 pnp_dbg("Encode mem32");
934 pnpacpi_encode_mem32(resource
,
935 &res_table
->mem_resource
[mem
]);
938 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
939 pnp_dbg("Encode fixed mem32");
940 pnpacpi_encode_fixed_mem32(resource
,
941 &res_table
->mem_resource
[mem
]);
944 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
945 pnp_dbg("Encode ext irq");
946 pnpacpi_encode_ext_irq(resource
,
947 &res_table
->irq_resource
[irq
]);
950 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
951 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
952 case ACPI_RESOURCE_TYPE_VENDOR
:
953 case ACPI_RESOURCE_TYPE_END_TAG
:
954 case ACPI_RESOURCE_TYPE_ADDRESS16
:
955 case ACPI_RESOURCE_TYPE_ADDRESS32
:
956 case ACPI_RESOURCE_TYPE_ADDRESS64
:
957 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
958 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
959 default: /* other type */
960 pnp_warn("unknown resource type %d", resource
->type
);