2 * pnpacpi -- PnP ACPI driver
4 * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
5 * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/acpi.h>
23 #include <linux/pci.h>
27 #define valid_IRQ(i) (1)
29 #define valid_IRQ(i) (((i) != 0) && ((i) != 2))
35 static int irq_flags(int triggering
, int polarity
)
38 if (triggering
== ACPI_LEVEL_SENSITIVE
) {
39 if(polarity
== ACPI_ACTIVE_LOW
)
40 flag
= IORESOURCE_IRQ_LOWLEVEL
;
42 flag
= IORESOURCE_IRQ_HIGHLEVEL
;
45 if(polarity
== ACPI_ACTIVE_LOW
)
46 flag
= IORESOURCE_IRQ_LOWEDGE
;
48 flag
= IORESOURCE_IRQ_HIGHEDGE
;
53 static void decode_irq_flags(int flag
, int *triggering
, int *polarity
)
56 case IORESOURCE_IRQ_LOWLEVEL
:
57 *triggering
= ACPI_LEVEL_SENSITIVE
;
58 *polarity
= ACPI_ACTIVE_LOW
;
60 case IORESOURCE_IRQ_HIGHLEVEL
:
61 *triggering
= ACPI_LEVEL_SENSITIVE
;
62 *polarity
= ACPI_ACTIVE_HIGH
;
64 case IORESOURCE_IRQ_LOWEDGE
:
65 *triggering
= ACPI_EDGE_SENSITIVE
;
66 *polarity
= ACPI_ACTIVE_LOW
;
68 case IORESOURCE_IRQ_HIGHEDGE
:
69 *triggering
= ACPI_EDGE_SENSITIVE
;
70 *polarity
= ACPI_ACTIVE_HIGH
;
76 pnpacpi_parse_allocated_irqresource(struct pnp_resource_table
* res
, u32 gsi
,
77 int triggering
, int polarity
)
85 while (!(res
->irq_resource
[i
].flags
& IORESOURCE_UNSET
) &&
91 res
->irq_resource
[i
].flags
= IORESOURCE_IRQ
; // Also clears _UNSET flag
92 irq
= acpi_register_gsi(gsi
, triggering
, polarity
);
94 res
->irq_resource
[i
].flags
|= IORESOURCE_DISABLED
;
98 res
->irq_resource
[i
].start
= irq
;
99 res
->irq_resource
[i
].end
= irq
;
100 pcibios_penalize_isa_irq(irq
, 1);
104 pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table
* res
, u32 dma
)
107 while (i
< PNP_MAX_DMA
&&
108 !(res
->dma_resource
[i
].flags
& IORESOURCE_UNSET
))
110 if (i
< PNP_MAX_DMA
) {
111 res
->dma_resource
[i
].flags
= IORESOURCE_DMA
; // Also clears _UNSET flag
113 res
->dma_resource
[i
].flags
|= IORESOURCE_DISABLED
;
116 res
->dma_resource
[i
].start
= dma
;
117 res
->dma_resource
[i
].end
= dma
;
122 pnpacpi_parse_allocated_ioresource(struct pnp_resource_table
* res
,
126 while (!(res
->port_resource
[i
].flags
& IORESOURCE_UNSET
) &&
129 if (i
< PNP_MAX_PORT
) {
130 res
->port_resource
[i
].flags
= IORESOURCE_IO
; // Also clears _UNSET flag
131 if (len
<= 0 || (io
+ len
-1) >= 0x10003) {
132 res
->port_resource
[i
].flags
|= IORESOURCE_DISABLED
;
135 res
->port_resource
[i
].start
= io
;
136 res
->port_resource
[i
].end
= io
+ len
- 1;
141 pnpacpi_parse_allocated_memresource(struct pnp_resource_table
* res
,
145 while (!(res
->mem_resource
[i
].flags
& IORESOURCE_UNSET
) &&
148 if (i
< PNP_MAX_MEM
) {
149 res
->mem_resource
[i
].flags
= IORESOURCE_MEM
; // Also clears _UNSET flag
151 res
->mem_resource
[i
].flags
|= IORESOURCE_DISABLED
;
154 res
->mem_resource
[i
].start
= mem
;
155 res
->mem_resource
[i
].end
= mem
+ len
- 1;
160 static acpi_status
pnpacpi_allocated_resource(struct acpi_resource
*res
,
163 struct pnp_resource_table
* res_table
= (struct pnp_resource_table
*)data
;
167 case ACPI_RESOURCE_TYPE_IRQ
:
169 * Per spec, only one interrupt per descriptor is allowed in
170 * _CRS, but some firmware violates this, so parse them all.
172 for (i
= 0; i
< res
->data
.irq
.interrupt_count
; i
++) {
173 pnpacpi_parse_allocated_irqresource(res_table
,
174 res
->data
.irq
.interrupts
[i
],
175 res
->data
.irq
.triggering
,
176 res
->data
.irq
.polarity
);
180 case ACPI_RESOURCE_TYPE_DMA
:
181 if (res
->data
.dma
.channel_count
> 0)
182 pnpacpi_parse_allocated_dmaresource(res_table
,
183 res
->data
.dma
.channels
[0]);
186 case ACPI_RESOURCE_TYPE_IO
:
187 pnpacpi_parse_allocated_ioresource(res_table
,
188 res
->data
.io
.minimum
,
189 res
->data
.io
.address_length
);
192 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
193 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
196 case ACPI_RESOURCE_TYPE_FIXED_IO
:
197 pnpacpi_parse_allocated_ioresource(res_table
,
198 res
->data
.fixed_io
.address
,
199 res
->data
.fixed_io
.address_length
);
202 case ACPI_RESOURCE_TYPE_VENDOR
:
205 case ACPI_RESOURCE_TYPE_END_TAG
:
208 case ACPI_RESOURCE_TYPE_MEMORY24
:
209 pnpacpi_parse_allocated_memresource(res_table
,
210 res
->data
.memory24
.minimum
,
211 res
->data
.memory24
.address_length
);
213 case ACPI_RESOURCE_TYPE_MEMORY32
:
214 pnpacpi_parse_allocated_memresource(res_table
,
215 res
->data
.memory32
.minimum
,
216 res
->data
.memory32
.address_length
);
218 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
219 pnpacpi_parse_allocated_memresource(res_table
,
220 res
->data
.fixed_memory32
.address
,
221 res
->data
.fixed_memory32
.address_length
);
223 case ACPI_RESOURCE_TYPE_ADDRESS16
:
224 pnpacpi_parse_allocated_memresource(res_table
,
225 res
->data
.address16
.minimum
,
226 res
->data
.address16
.address_length
);
228 case ACPI_RESOURCE_TYPE_ADDRESS32
:
229 pnpacpi_parse_allocated_memresource(res_table
,
230 res
->data
.address32
.minimum
,
231 res
->data
.address32
.address_length
);
233 case ACPI_RESOURCE_TYPE_ADDRESS64
:
234 pnpacpi_parse_allocated_memresource(res_table
,
235 res
->data
.address64
.minimum
,
236 res
->data
.address64
.address_length
);
239 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
242 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
243 for (i
= 0; i
< res
->data
.extended_irq
.interrupt_count
; i
++) {
244 pnpacpi_parse_allocated_irqresource(res_table
,
245 res
->data
.extended_irq
.interrupts
[i
],
246 res
->data
.extended_irq
.triggering
,
247 res
->data
.extended_irq
.polarity
);
251 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
255 pnp_warn("PnPACPI: unknown resource type %d", res
->type
);
262 acpi_status
pnpacpi_parse_allocated_resource(acpi_handle handle
, struct pnp_resource_table
* res
)
264 /* Blank the resource table values */
265 pnp_init_resource_table(res
);
267 return acpi_walk_resources(handle
, METHOD_NAME__CRS
, pnpacpi_allocated_resource
, res
);
270 static void pnpacpi_parse_dma_option(struct pnp_option
*option
, struct acpi_resource_dma
*p
)
273 struct pnp_dma
* dma
;
275 if (p
->channel_count
== 0)
277 dma
= kcalloc(1, sizeof(struct pnp_dma
), GFP_KERNEL
);
281 for(i
= 0; i
< p
->channel_count
; i
++)
282 dma
->map
|= 1 << p
->channels
[i
];
285 dma
->flags
|= IORESOURCE_DMA_MASTER
;
287 case ACPI_COMPATIBILITY
:
288 dma
->flags
|= IORESOURCE_DMA_COMPATIBLE
;
291 dma
->flags
|= IORESOURCE_DMA_TYPEA
;
294 dma
->flags
|= IORESOURCE_DMA_TYPEB
;
297 dma
->flags
|= IORESOURCE_DMA_TYPEF
;
300 /* Set a default value ? */
301 dma
->flags
|= IORESOURCE_DMA_COMPATIBLE
;
302 pnp_err("Invalid DMA type");
304 switch (p
->transfer
) {
305 case ACPI_TRANSFER_8
:
306 dma
->flags
|= IORESOURCE_DMA_8BIT
;
308 case ACPI_TRANSFER_8_16
:
309 dma
->flags
|= IORESOURCE_DMA_8AND16BIT
;
311 case ACPI_TRANSFER_16
:
312 dma
->flags
|= IORESOURCE_DMA_16BIT
;
315 /* Set a default value ? */
316 dma
->flags
|= IORESOURCE_DMA_8AND16BIT
;
317 pnp_err("Invalid DMA transfer type");
320 pnp_register_dma_resource(option
,dma
);
325 static void pnpacpi_parse_irq_option(struct pnp_option
*option
,
326 struct acpi_resource_irq
*p
)
329 struct pnp_irq
* irq
;
331 if (p
->interrupt_count
== 0)
333 irq
= kcalloc(1, sizeof(struct pnp_irq
), GFP_KERNEL
);
337 for(i
= 0; i
< p
->interrupt_count
; i
++)
338 if (p
->interrupts
[i
])
339 __set_bit(p
->interrupts
[i
], irq
->map
);
340 irq
->flags
= irq_flags(p
->triggering
, p
->polarity
);
342 pnp_register_irq_resource(option
, irq
);
346 static void pnpacpi_parse_ext_irq_option(struct pnp_option
*option
,
347 struct acpi_resource_extended_irq
*p
)
350 struct pnp_irq
* irq
;
352 if (p
->interrupt_count
== 0)
354 irq
= kcalloc(1, sizeof(struct pnp_irq
), GFP_KERNEL
);
358 for(i
= 0; i
< p
->interrupt_count
; i
++)
359 if (p
->interrupts
[i
])
360 __set_bit(p
->interrupts
[i
], irq
->map
);
361 irq
->flags
= irq_flags(p
->triggering
, p
->polarity
);
363 pnp_register_irq_resource(option
, irq
);
368 pnpacpi_parse_port_option(struct pnp_option
*option
,
369 struct acpi_resource_io
*io
)
371 struct pnp_port
* port
;
373 if (io
->address_length
== 0)
375 port
= kcalloc(1, sizeof(struct pnp_port
), GFP_KERNEL
);
378 port
->min
= io
->minimum
;
379 port
->max
= io
->maximum
;
380 port
->align
= io
->alignment
;
381 port
->size
= io
->address_length
;
382 port
->flags
= ACPI_DECODE_16
== io
->io_decode
?
383 PNP_PORT_FLAG_16BITADDR
: 0;
384 pnp_register_port_resource(option
,port
);
389 pnpacpi_parse_fixed_port_option(struct pnp_option
*option
,
390 struct acpi_resource_fixed_io
*io
)
392 struct pnp_port
* port
;
394 if (io
->address_length
== 0)
396 port
= kcalloc(1, sizeof(struct pnp_port
), GFP_KERNEL
);
399 port
->min
= port
->max
= io
->address
;
400 port
->size
= io
->address_length
;
402 port
->flags
= PNP_PORT_FLAG_FIXED
;
403 pnp_register_port_resource(option
,port
);
408 pnpacpi_parse_mem24_option(struct pnp_option
*option
,
409 struct acpi_resource_memory24
*p
)
411 struct pnp_mem
* mem
;
413 if (p
->address_length
== 0)
415 mem
= kcalloc(1, sizeof(struct pnp_mem
), GFP_KERNEL
);
418 mem
->min
= p
->minimum
;
419 mem
->max
= p
->maximum
;
420 mem
->align
= p
->alignment
;
421 mem
->size
= p
->address_length
;
423 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->write_protect
) ?
424 IORESOURCE_MEM_WRITEABLE
: 0;
426 pnp_register_mem_resource(option
,mem
);
431 pnpacpi_parse_mem32_option(struct pnp_option
*option
,
432 struct acpi_resource_memory32
*p
)
434 struct pnp_mem
* mem
;
436 if (p
->address_length
== 0)
438 mem
= kcalloc(1, sizeof(struct pnp_mem
), GFP_KERNEL
);
441 mem
->min
= p
->minimum
;
442 mem
->max
= p
->maximum
;
443 mem
->align
= p
->alignment
;
444 mem
->size
= p
->address_length
;
446 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->write_protect
) ?
447 IORESOURCE_MEM_WRITEABLE
: 0;
449 pnp_register_mem_resource(option
,mem
);
454 pnpacpi_parse_fixed_mem32_option(struct pnp_option
*option
,
455 struct acpi_resource_fixed_memory32
*p
)
457 struct pnp_mem
* mem
;
459 if (p
->address_length
== 0)
461 mem
= kcalloc(1, sizeof(struct pnp_mem
), GFP_KERNEL
);
464 mem
->min
= mem
->max
= p
->address
;
465 mem
->size
= p
->address_length
;
468 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->write_protect
) ?
469 IORESOURCE_MEM_WRITEABLE
: 0;
471 pnp_register_mem_resource(option
,mem
);
476 pnpacpi_parse_address_option(struct pnp_option
*option
, struct acpi_resource
*r
)
478 struct acpi_resource_address64 addr
, *p
= &addr
;
480 struct pnp_mem
* mem
;
481 struct pnp_port
* port
;
483 status
= acpi_resource_to_address64(r
, p
);
484 if (!ACPI_SUCCESS(status
)) {
485 pnp_warn("PnPACPI: failed to convert resource type %d", r
->type
);
489 if (p
->address_length
== 0)
492 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
493 mem
= kcalloc(1, sizeof(struct pnp_mem
), GFP_KERNEL
);
496 mem
->min
= mem
->max
= p
->minimum
;
497 mem
->size
= p
->address_length
;
499 mem
->flags
= (p
->info
.mem
.write_protect
==
500 ACPI_READ_WRITE_MEMORY
) ? IORESOURCE_MEM_WRITEABLE
: 0;
501 pnp_register_mem_resource(option
,mem
);
502 } else if (p
->resource_type
== ACPI_IO_RANGE
) {
503 port
= kcalloc(1, sizeof(struct pnp_port
), GFP_KERNEL
);
506 port
->min
= port
->max
= p
->minimum
;
507 port
->size
= p
->address_length
;
509 port
->flags
= PNP_PORT_FLAG_FIXED
;
510 pnp_register_port_resource(option
,port
);
514 struct acpipnp_parse_option_s
{
515 struct pnp_option
*option
;
516 struct pnp_option
*option_independent
;
520 static acpi_status
pnpacpi_option_resource(struct acpi_resource
*res
,
524 struct acpipnp_parse_option_s
*parse_data
= (struct acpipnp_parse_option_s
*)data
;
525 struct pnp_dev
*dev
= parse_data
->dev
;
526 struct pnp_option
*option
= parse_data
->option
;
529 case ACPI_RESOURCE_TYPE_IRQ
:
530 pnpacpi_parse_irq_option(option
, &res
->data
.irq
);
533 case ACPI_RESOURCE_TYPE_DMA
:
534 pnpacpi_parse_dma_option(option
, &res
->data
.dma
);
537 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
538 switch (res
->data
.start_dpf
.compatibility_priority
) {
539 case ACPI_GOOD_CONFIGURATION
:
540 priority
= PNP_RES_PRIORITY_PREFERRED
;
543 case ACPI_ACCEPTABLE_CONFIGURATION
:
544 priority
= PNP_RES_PRIORITY_ACCEPTABLE
;
547 case ACPI_SUB_OPTIMAL_CONFIGURATION
:
548 priority
= PNP_RES_PRIORITY_FUNCTIONAL
;
551 priority
= PNP_RES_PRIORITY_INVALID
;
554 /* TBD: Considering performace/robustness bits */
555 option
= pnp_register_dependent_option(dev
, priority
);
558 parse_data
->option
= option
;
561 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
562 /*only one EndDependentFn is allowed*/
563 if (!parse_data
->option_independent
) {
564 pnp_warn("PnPACPI: more than one EndDependentFn");
567 parse_data
->option
= parse_data
->option_independent
;
568 parse_data
->option_independent
= NULL
;
571 case ACPI_RESOURCE_TYPE_IO
:
572 pnpacpi_parse_port_option(option
, &res
->data
.io
);
575 case ACPI_RESOURCE_TYPE_FIXED_IO
:
576 pnpacpi_parse_fixed_port_option(option
,
577 &res
->data
.fixed_io
);
580 case ACPI_RESOURCE_TYPE_VENDOR
:
581 case ACPI_RESOURCE_TYPE_END_TAG
:
584 case ACPI_RESOURCE_TYPE_MEMORY24
:
585 pnpacpi_parse_mem24_option(option
, &res
->data
.memory24
);
588 case ACPI_RESOURCE_TYPE_MEMORY32
:
589 pnpacpi_parse_mem32_option(option
, &res
->data
.memory32
);
592 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
593 pnpacpi_parse_fixed_mem32_option(option
,
594 &res
->data
.fixed_memory32
);
597 case ACPI_RESOURCE_TYPE_ADDRESS16
:
598 case ACPI_RESOURCE_TYPE_ADDRESS32
:
599 case ACPI_RESOURCE_TYPE_ADDRESS64
:
600 pnpacpi_parse_address_option(option
, res
);
603 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
606 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
607 pnpacpi_parse_ext_irq_option(option
,
608 &res
->data
.extended_irq
);
611 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
615 pnp_warn("PnPACPI: unknown resource type %d", res
->type
);
622 acpi_status
pnpacpi_parse_resource_option_data(acpi_handle handle
,
626 struct acpipnp_parse_option_s parse_data
;
628 parse_data
.option
= pnp_register_independent_option(dev
);
629 if (!parse_data
.option
)
631 parse_data
.option_independent
= parse_data
.option
;
632 parse_data
.dev
= dev
;
633 status
= acpi_walk_resources(handle
, METHOD_NAME__PRS
,
634 pnpacpi_option_resource
, &parse_data
);
642 static acpi_status
pnpacpi_count_resources(struct acpi_resource
*res
,
645 int *res_cnt
= (int *)data
;
647 case ACPI_RESOURCE_TYPE_IRQ
:
648 case ACPI_RESOURCE_TYPE_DMA
:
649 case ACPI_RESOURCE_TYPE_IO
:
650 case ACPI_RESOURCE_TYPE_FIXED_IO
:
651 case ACPI_RESOURCE_TYPE_MEMORY24
:
652 case ACPI_RESOURCE_TYPE_MEMORY32
:
653 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
654 case ACPI_RESOURCE_TYPE_ADDRESS16
:
655 case ACPI_RESOURCE_TYPE_ADDRESS32
:
656 case ACPI_RESOURCE_TYPE_ADDRESS64
:
657 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
659 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
660 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
661 case ACPI_RESOURCE_TYPE_VENDOR
:
662 case ACPI_RESOURCE_TYPE_END_TAG
:
663 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
670 static acpi_status
pnpacpi_type_resources(struct acpi_resource
*res
,
673 struct acpi_resource
**resource
= (struct acpi_resource
**)data
;
675 case ACPI_RESOURCE_TYPE_IRQ
:
676 case ACPI_RESOURCE_TYPE_DMA
:
677 case ACPI_RESOURCE_TYPE_IO
:
678 case ACPI_RESOURCE_TYPE_FIXED_IO
:
679 case ACPI_RESOURCE_TYPE_MEMORY24
:
680 case ACPI_RESOURCE_TYPE_MEMORY32
:
681 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
682 case ACPI_RESOURCE_TYPE_ADDRESS16
:
683 case ACPI_RESOURCE_TYPE_ADDRESS32
:
684 case ACPI_RESOURCE_TYPE_ADDRESS64
:
685 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
686 (*resource
)->type
= res
->type
;
688 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
689 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
690 case ACPI_RESOURCE_TYPE_VENDOR
:
691 case ACPI_RESOURCE_TYPE_END_TAG
:
692 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
700 int pnpacpi_build_resource_template(acpi_handle handle
,
701 struct acpi_buffer
*buffer
)
703 struct acpi_resource
*resource
;
707 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
708 pnpacpi_count_resources
, &res_cnt
);
709 if (ACPI_FAILURE(status
)) {
710 pnp_err("Evaluate _CRS failed");
715 buffer
->length
= sizeof(struct acpi_resource
) * (res_cnt
+ 1) + 1;
716 buffer
->pointer
= kcalloc(1, buffer
->length
- 1, GFP_KERNEL
);
717 if (!buffer
->pointer
)
719 pnp_dbg("Res cnt %d", res_cnt
);
720 resource
= (struct acpi_resource
*)buffer
->pointer
;
721 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
722 pnpacpi_type_resources
, &resource
);
723 if (ACPI_FAILURE(status
)) {
724 kfree(buffer
->pointer
);
725 pnp_err("Evaluate _CRS failed");
728 /* resource will pointer the end resource now */
729 resource
->type
= ACPI_RESOURCE_TYPE_END_TAG
;
734 static void pnpacpi_encode_irq(struct acpi_resource
*resource
,
737 int triggering
, polarity
;
739 decode_irq_flags(p
->flags
& IORESOURCE_BITS
, &triggering
,
741 resource
->type
= ACPI_RESOURCE_TYPE_IRQ
;
742 resource
->length
= sizeof(struct acpi_resource
);
743 resource
->data
.irq
.triggering
= triggering
;
744 resource
->data
.irq
.polarity
= polarity
;
745 if (triggering
== ACPI_EDGE_SENSITIVE
)
746 resource
->data
.irq
.sharable
= ACPI_EXCLUSIVE
;
748 resource
->data
.irq
.sharable
= ACPI_SHARED
;
749 resource
->data
.irq
.interrupt_count
= 1;
750 resource
->data
.irq
.interrupts
[0] = p
->start
;
753 static void pnpacpi_encode_ext_irq(struct acpi_resource
*resource
,
756 int triggering
, polarity
;
758 decode_irq_flags(p
->flags
& IORESOURCE_BITS
, &triggering
,
760 resource
->type
= ACPI_RESOURCE_TYPE_EXTENDED_IRQ
;
761 resource
->length
= sizeof(struct acpi_resource
);
762 resource
->data
.extended_irq
.producer_consumer
= ACPI_CONSUMER
;
763 resource
->data
.extended_irq
.triggering
= triggering
;
764 resource
->data
.extended_irq
.polarity
= polarity
;
765 if (triggering
== ACPI_EDGE_SENSITIVE
)
766 resource
->data
.irq
.sharable
= ACPI_EXCLUSIVE
;
768 resource
->data
.irq
.sharable
= ACPI_SHARED
;
769 resource
->data
.extended_irq
.interrupt_count
= 1;
770 resource
->data
.extended_irq
.interrupts
[0] = p
->start
;
773 static void pnpacpi_encode_dma(struct acpi_resource
*resource
,
776 resource
->type
= ACPI_RESOURCE_TYPE_DMA
;
777 resource
->length
= sizeof(struct acpi_resource
);
778 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
779 if (p
->flags
& IORESOURCE_DMA_COMPATIBLE
)
780 resource
->data
.dma
.type
= ACPI_COMPATIBILITY
;
781 else if (p
->flags
& IORESOURCE_DMA_TYPEA
)
782 resource
->data
.dma
.type
= ACPI_TYPE_A
;
783 else if (p
->flags
& IORESOURCE_DMA_TYPEB
)
784 resource
->data
.dma
.type
= ACPI_TYPE_B
;
785 else if (p
->flags
& IORESOURCE_DMA_TYPEF
)
786 resource
->data
.dma
.type
= ACPI_TYPE_F
;
787 if (p
->flags
& IORESOURCE_DMA_8BIT
)
788 resource
->data
.dma
.transfer
= ACPI_TRANSFER_8
;
789 else if (p
->flags
& IORESOURCE_DMA_8AND16BIT
)
790 resource
->data
.dma
.transfer
= ACPI_TRANSFER_8_16
;
791 else if (p
->flags
& IORESOURCE_DMA_16BIT
)
792 resource
->data
.dma
.transfer
= ACPI_TRANSFER_16
;
793 resource
->data
.dma
.bus_master
= p
->flags
& IORESOURCE_DMA_MASTER
;
794 resource
->data
.dma
.channel_count
= 1;
795 resource
->data
.dma
.channels
[0] = p
->start
;
798 static void pnpacpi_encode_io(struct acpi_resource
*resource
,
801 resource
->type
= ACPI_RESOURCE_TYPE_IO
;
802 resource
->length
= sizeof(struct acpi_resource
);
803 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
804 resource
->data
.io
.io_decode
= (p
->flags
& PNP_PORT_FLAG_16BITADDR
)?
805 ACPI_DECODE_16
: ACPI_DECODE_10
;
806 resource
->data
.io
.minimum
= p
->start
;
807 resource
->data
.io
.maximum
= p
->end
;
808 resource
->data
.io
.alignment
= 0; /* Correct? */
809 resource
->data
.io
.address_length
= p
->end
- p
->start
+ 1;
812 static void pnpacpi_encode_fixed_io(struct acpi_resource
*resource
,
815 resource
->type
= ACPI_RESOURCE_TYPE_FIXED_IO
;
816 resource
->length
= sizeof(struct acpi_resource
);
817 resource
->data
.fixed_io
.address
= p
->start
;
818 resource
->data
.fixed_io
.address_length
= p
->end
- p
->start
+ 1;
821 static void pnpacpi_encode_mem24(struct acpi_resource
*resource
,
824 resource
->type
= ACPI_RESOURCE_TYPE_MEMORY24
;
825 resource
->length
= sizeof(struct acpi_resource
);
826 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
827 resource
->data
.memory24
.write_protect
=
828 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
829 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
830 resource
->data
.memory24
.minimum
= p
->start
;
831 resource
->data
.memory24
.maximum
= p
->end
;
832 resource
->data
.memory24
.alignment
= 0;
833 resource
->data
.memory24
.address_length
= p
->end
- p
->start
+ 1;
836 static void pnpacpi_encode_mem32(struct acpi_resource
*resource
,
839 resource
->type
= ACPI_RESOURCE_TYPE_MEMORY32
;
840 resource
->length
= sizeof(struct acpi_resource
);
841 resource
->data
.memory32
.write_protect
=
842 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
843 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
844 resource
->data
.memory32
.minimum
= p
->start
;
845 resource
->data
.memory32
.maximum
= p
->end
;
846 resource
->data
.memory32
.alignment
= 0;
847 resource
->data
.memory32
.address_length
= p
->end
- p
->start
+ 1;
850 static void pnpacpi_encode_fixed_mem32(struct acpi_resource
*resource
,
853 resource
->type
= ACPI_RESOURCE_TYPE_FIXED_MEMORY32
;
854 resource
->length
= sizeof(struct acpi_resource
);
855 resource
->data
.fixed_memory32
.write_protect
=
856 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
857 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
858 resource
->data
.fixed_memory32
.address
= p
->start
;
859 resource
->data
.fixed_memory32
.address_length
= p
->end
- p
->start
+ 1;
862 int pnpacpi_encode_resources(struct pnp_resource_table
*res_table
,
863 struct acpi_buffer
*buffer
)
866 /* pnpacpi_build_resource_template allocates extra mem */
867 int res_cnt
= (buffer
->length
- 1)/sizeof(struct acpi_resource
) - 1;
868 struct acpi_resource
*resource
= (struct acpi_resource
*)buffer
->pointer
;
869 int port
= 0, irq
= 0, dma
= 0, mem
= 0;
871 pnp_dbg("res cnt %d", res_cnt
);
872 while (i
< res_cnt
) {
873 switch(resource
->type
) {
874 case ACPI_RESOURCE_TYPE_IRQ
:
875 pnp_dbg("Encode irq");
876 pnpacpi_encode_irq(resource
,
877 &res_table
->irq_resource
[irq
]);
881 case ACPI_RESOURCE_TYPE_DMA
:
882 pnp_dbg("Encode dma");
883 pnpacpi_encode_dma(resource
,
884 &res_table
->dma_resource
[dma
]);
887 case ACPI_RESOURCE_TYPE_IO
:
888 pnp_dbg("Encode io");
889 pnpacpi_encode_io(resource
,
890 &res_table
->port_resource
[port
]);
893 case ACPI_RESOURCE_TYPE_FIXED_IO
:
894 pnp_dbg("Encode fixed io");
895 pnpacpi_encode_fixed_io(resource
,
896 &res_table
->port_resource
[port
]);
899 case ACPI_RESOURCE_TYPE_MEMORY24
:
900 pnp_dbg("Encode mem24");
901 pnpacpi_encode_mem24(resource
,
902 &res_table
->mem_resource
[mem
]);
905 case ACPI_RESOURCE_TYPE_MEMORY32
:
906 pnp_dbg("Encode mem32");
907 pnpacpi_encode_mem32(resource
,
908 &res_table
->mem_resource
[mem
]);
911 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
912 pnp_dbg("Encode fixed mem32");
913 pnpacpi_encode_fixed_mem32(resource
,
914 &res_table
->mem_resource
[mem
]);
917 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
918 pnp_dbg("Encode ext irq");
919 pnpacpi_encode_ext_irq(resource
,
920 &res_table
->irq_resource
[irq
]);
923 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
924 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
925 case ACPI_RESOURCE_TYPE_VENDOR
:
926 case ACPI_RESOURCE_TYPE_END_TAG
:
927 case ACPI_RESOURCE_TYPE_ADDRESS16
:
928 case ACPI_RESOURCE_TYPE_ADDRESS32
:
929 case ACPI_RESOURCE_TYPE_ADDRESS64
:
930 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
931 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
932 default: /* other type */
933 pnp_warn("unknown resource type %d", resource
->type
);