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>
6 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/kernel.h>
24 #include <linux/acpi.h>
25 #include <linux/pci.h>
26 #include <linux/pnp.h>
31 #define valid_IRQ(i) (1)
33 #define valid_IRQ(i) (((i) != 0) && ((i) != 2))
39 static int irq_flags(int triggering
, int polarity
, int shareable
)
43 if (triggering
== ACPI_LEVEL_SENSITIVE
) {
44 if (polarity
== ACPI_ACTIVE_LOW
)
45 flags
= IORESOURCE_IRQ_LOWLEVEL
;
47 flags
= IORESOURCE_IRQ_HIGHLEVEL
;
49 if (polarity
== ACPI_ACTIVE_LOW
)
50 flags
= IORESOURCE_IRQ_LOWEDGE
;
52 flags
= IORESOURCE_IRQ_HIGHEDGE
;
55 if (shareable
== ACPI_SHARED
)
56 flags
|= IORESOURCE_IRQ_SHAREABLE
;
61 static void decode_irq_flags(struct pnp_dev
*dev
, int flags
, int *triggering
,
62 int *polarity
, int *shareable
)
64 switch (flags
& (IORESOURCE_IRQ_LOWLEVEL
| IORESOURCE_IRQ_HIGHLEVEL
|
65 IORESOURCE_IRQ_LOWEDGE
| IORESOURCE_IRQ_HIGHEDGE
)) {
66 case IORESOURCE_IRQ_LOWLEVEL
:
67 *triggering
= ACPI_LEVEL_SENSITIVE
;
68 *polarity
= ACPI_ACTIVE_LOW
;
70 case IORESOURCE_IRQ_HIGHLEVEL
:
71 *triggering
= ACPI_LEVEL_SENSITIVE
;
72 *polarity
= ACPI_ACTIVE_HIGH
;
74 case IORESOURCE_IRQ_LOWEDGE
:
75 *triggering
= ACPI_EDGE_SENSITIVE
;
76 *polarity
= ACPI_ACTIVE_LOW
;
78 case IORESOURCE_IRQ_HIGHEDGE
:
79 *triggering
= ACPI_EDGE_SENSITIVE
;
80 *polarity
= ACPI_ACTIVE_HIGH
;
83 dev_err(&dev
->dev
, "can't encode invalid IRQ mode %#x\n",
85 *triggering
= ACPI_EDGE_SENSITIVE
;
86 *polarity
= ACPI_ACTIVE_HIGH
;
90 if (flags
& IORESOURCE_IRQ_SHAREABLE
)
91 *shareable
= ACPI_SHARED
;
93 *shareable
= ACPI_EXCLUSIVE
;
96 static void pnpacpi_parse_allocated_irqresource(struct pnp_dev
*dev
,
97 u32 gsi
, int triggering
,
98 int polarity
, int shareable
)
103 if (!valid_IRQ(gsi
)) {
104 pnp_add_irq_resource(dev
, gsi
, IORESOURCE_DISABLED
);
109 * in IO-APIC mode, use overrided attribute. Two reasons:
110 * 1. BIOS bug in DSDT
111 * 2. BIOS uses IO-APIC mode Interrupt Source Override
113 if (!acpi_get_override_irq(gsi
, &t
, &p
)) {
114 t
= t
? ACPI_LEVEL_SENSITIVE
: ACPI_EDGE_SENSITIVE
;
115 p
= p
? ACPI_ACTIVE_LOW
: ACPI_ACTIVE_HIGH
;
117 if (triggering
!= t
|| polarity
!= p
) {
118 dev_warn(&dev
->dev
, "IRQ %d override to %s, %s\n",
119 gsi
, t
? "edge":"level", p
? "low":"high");
125 flags
= irq_flags(triggering
, polarity
, shareable
);
126 irq
= acpi_register_gsi(&dev
->dev
, gsi
, triggering
, polarity
);
128 pcibios_penalize_isa_irq(irq
, 1);
130 flags
|= IORESOURCE_DISABLED
;
132 pnp_add_irq_resource(dev
, irq
, flags
);
135 static int dma_flags(struct pnp_dev
*dev
, int type
, int bus_master
,
141 flags
|= IORESOURCE_DMA_MASTER
;
143 case ACPI_COMPATIBILITY
:
144 flags
|= IORESOURCE_DMA_COMPATIBLE
;
147 flags
|= IORESOURCE_DMA_TYPEA
;
150 flags
|= IORESOURCE_DMA_TYPEB
;
153 flags
|= IORESOURCE_DMA_TYPEF
;
156 /* Set a default value ? */
157 flags
|= IORESOURCE_DMA_COMPATIBLE
;
158 dev_err(&dev
->dev
, "invalid DMA type %d\n", type
);
161 case ACPI_TRANSFER_8
:
162 flags
|= IORESOURCE_DMA_8BIT
;
164 case ACPI_TRANSFER_8_16
:
165 flags
|= IORESOURCE_DMA_8AND16BIT
;
167 case ACPI_TRANSFER_16
:
168 flags
|= IORESOURCE_DMA_16BIT
;
171 /* Set a default value ? */
172 flags
|= IORESOURCE_DMA_8AND16BIT
;
173 dev_err(&dev
->dev
, "invalid DMA transfer type %d\n", transfer
);
179 static void pnpacpi_parse_allocated_ioresource(struct pnp_dev
*dev
, u64 start
,
180 u64 len
, int io_decode
)
183 u64 end
= start
+ len
- 1;
185 if (io_decode
== ACPI_DECODE_16
)
186 flags
|= IORESOURCE_IO_16BIT_ADDR
;
187 if (len
== 0 || end
>= 0x10003)
188 flags
|= IORESOURCE_DISABLED
;
190 pnp_add_io_resource(dev
, start
, end
, flags
);
194 * Device CSRs that do not appear in PCI config space should be described
195 * via ACPI. This would normally be done with Address Space Descriptors
196 * marked as "consumer-only," but old versions of Windows and Linux ignore
197 * the producer/consumer flag, so HP invented a vendor-defined resource to
198 * describe the location and size of CSR space.
200 static struct acpi_vendor_uuid hp_ccsr_uuid
= {
202 .data
= { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
203 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
206 static int vendor_resource_matches(struct pnp_dev
*dev
,
207 struct acpi_resource_vendor_typed
*vendor
,
208 struct acpi_vendor_uuid
*match
,
211 int uuid_len
= sizeof(vendor
->uuid
);
212 u8 uuid_subtype
= vendor
->uuid_subtype
;
213 u8
*uuid
= vendor
->uuid
;
216 /* byte_length includes uuid_subtype and uuid */
217 actual_len
= vendor
->byte_length
- uuid_len
- 1;
219 if (uuid_subtype
== match
->subtype
&&
220 uuid_len
== sizeof(match
->data
) &&
221 memcmp(uuid
, match
->data
, uuid_len
) == 0) {
222 if (expected_len
&& expected_len
!= actual_len
) {
223 dev_err(&dev
->dev
, "wrong vendor descriptor size; "
224 "expected %d, found %d bytes\n",
225 expected_len
, actual_len
);
235 static void pnpacpi_parse_allocated_vendor(struct pnp_dev
*dev
,
236 struct acpi_resource_vendor_typed
*vendor
)
238 if (vendor_resource_matches(dev
, vendor
, &hp_ccsr_uuid
, 16)) {
241 memcpy(&start
, vendor
->byte_data
, sizeof(start
));
242 memcpy(&length
, vendor
->byte_data
+ 8, sizeof(length
));
244 pnp_add_mem_resource(dev
, start
, start
+ length
- 1, 0);
248 static void pnpacpi_parse_allocated_memresource(struct pnp_dev
*dev
,
253 u64 end
= start
+ len
- 1;
256 flags
|= IORESOURCE_DISABLED
;
257 if (write_protect
== ACPI_READ_WRITE_MEMORY
)
258 flags
|= IORESOURCE_MEM_WRITEABLE
;
260 pnp_add_mem_resource(dev
, start
, end
, flags
);
263 static void pnpacpi_parse_allocated_address_space(struct pnp_dev
*dev
,
264 struct acpi_resource
*res
)
266 struct acpi_resource_address64 addr
, *p
= &addr
;
269 status
= acpi_resource_to_address64(res
, p
);
270 if (!ACPI_SUCCESS(status
)) {
271 dev_warn(&dev
->dev
, "failed to convert resource type %d\n",
276 if (p
->producer_consumer
== ACPI_PRODUCER
)
279 if (p
->resource_type
== ACPI_MEMORY_RANGE
)
280 pnpacpi_parse_allocated_memresource(dev
,
281 p
->minimum
, p
->address_length
,
282 p
->info
.mem
.write_protect
);
283 else if (p
->resource_type
== ACPI_IO_RANGE
)
284 pnpacpi_parse_allocated_ioresource(dev
,
285 p
->minimum
, p
->address_length
,
286 p
->granularity
== 0xfff ? ACPI_DECODE_10
:
290 static void pnpacpi_parse_allocated_ext_address_space(struct pnp_dev
*dev
,
291 struct acpi_resource
*res
)
293 struct acpi_resource_extended_address64
*p
= &res
->data
.ext_address64
;
295 if (p
->producer_consumer
== ACPI_PRODUCER
)
298 if (p
->resource_type
== ACPI_MEMORY_RANGE
)
299 pnpacpi_parse_allocated_memresource(dev
,
300 p
->minimum
, p
->address_length
,
301 p
->info
.mem
.write_protect
);
302 else if (p
->resource_type
== ACPI_IO_RANGE
)
303 pnpacpi_parse_allocated_ioresource(dev
,
304 p
->minimum
, p
->address_length
,
305 p
->granularity
== 0xfff ? ACPI_DECODE_10
:
309 static acpi_status
pnpacpi_allocated_resource(struct acpi_resource
*res
,
312 struct pnp_dev
*dev
= data
;
313 struct acpi_resource_irq
*irq
;
314 struct acpi_resource_dma
*dma
;
315 struct acpi_resource_io
*io
;
316 struct acpi_resource_fixed_io
*fixed_io
;
317 struct acpi_resource_vendor_typed
*vendor_typed
;
318 struct acpi_resource_memory24
*memory24
;
319 struct acpi_resource_memory32
*memory32
;
320 struct acpi_resource_fixed_memory32
*fixed_memory32
;
321 struct acpi_resource_extended_irq
*extended_irq
;
325 case ACPI_RESOURCE_TYPE_IRQ
:
327 * Per spec, only one interrupt per descriptor is allowed in
328 * _CRS, but some firmware violates this, so parse them all.
330 irq
= &res
->data
.irq
;
331 if (irq
->interrupt_count
== 0)
332 pnp_add_irq_resource(dev
, 0, IORESOURCE_DISABLED
);
334 for (i
= 0; i
< irq
->interrupt_count
; i
++) {
335 pnpacpi_parse_allocated_irqresource(dev
,
343 * The IRQ encoder puts a single interrupt in each
344 * descriptor, so if a _CRS descriptor has more than
345 * one interrupt, we won't be able to re-encode it.
347 if (pnp_can_write(dev
) && irq
->interrupt_count
> 1) {
348 dev_warn(&dev
->dev
, "multiple interrupts in "
349 "_CRS descriptor; configuration can't "
351 dev
->capabilities
&= ~PNP_WRITE
;
356 case ACPI_RESOURCE_TYPE_DMA
:
357 dma
= &res
->data
.dma
;
358 if (dma
->channel_count
> 0 && dma
->channels
[0] != (u8
) -1)
359 flags
= dma_flags(dev
, dma
->type
, dma
->bus_master
,
362 flags
= IORESOURCE_DISABLED
;
363 pnp_add_dma_resource(dev
, dma
->channels
[0], flags
);
366 case ACPI_RESOURCE_TYPE_IO
:
368 pnpacpi_parse_allocated_ioresource(dev
,
374 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
375 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
378 case ACPI_RESOURCE_TYPE_FIXED_IO
:
379 fixed_io
= &res
->data
.fixed_io
;
380 pnpacpi_parse_allocated_ioresource(dev
,
382 fixed_io
->address_length
,
386 case ACPI_RESOURCE_TYPE_VENDOR
:
387 vendor_typed
= &res
->data
.vendor_typed
;
388 pnpacpi_parse_allocated_vendor(dev
, vendor_typed
);
391 case ACPI_RESOURCE_TYPE_END_TAG
:
394 case ACPI_RESOURCE_TYPE_MEMORY24
:
395 memory24
= &res
->data
.memory24
;
396 pnpacpi_parse_allocated_memresource(dev
,
398 memory24
->address_length
,
399 memory24
->write_protect
);
401 case ACPI_RESOURCE_TYPE_MEMORY32
:
402 memory32
= &res
->data
.memory32
;
403 pnpacpi_parse_allocated_memresource(dev
,
405 memory32
->address_length
,
406 memory32
->write_protect
);
408 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
409 fixed_memory32
= &res
->data
.fixed_memory32
;
410 pnpacpi_parse_allocated_memresource(dev
,
411 fixed_memory32
->address
,
412 fixed_memory32
->address_length
,
413 fixed_memory32
->write_protect
);
415 case ACPI_RESOURCE_TYPE_ADDRESS16
:
416 case ACPI_RESOURCE_TYPE_ADDRESS32
:
417 case ACPI_RESOURCE_TYPE_ADDRESS64
:
418 pnpacpi_parse_allocated_address_space(dev
, res
);
421 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
422 pnpacpi_parse_allocated_ext_address_space(dev
, res
);
425 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
426 extended_irq
= &res
->data
.extended_irq
;
428 if (extended_irq
->interrupt_count
== 0)
429 pnp_add_irq_resource(dev
, 0, IORESOURCE_DISABLED
);
431 for (i
= 0; i
< extended_irq
->interrupt_count
; i
++) {
432 pnpacpi_parse_allocated_irqresource(dev
,
433 extended_irq
->interrupts
[i
],
434 extended_irq
->triggering
,
435 extended_irq
->polarity
,
436 extended_irq
->sharable
);
440 * The IRQ encoder puts a single interrupt in each
441 * descriptor, so if a _CRS descriptor has more than
442 * one interrupt, we won't be able to re-encode it.
444 if (pnp_can_write(dev
) &&
445 extended_irq
->interrupt_count
> 1) {
446 dev_warn(&dev
->dev
, "multiple interrupts in "
447 "_CRS descriptor; configuration can't "
449 dev
->capabilities
&= ~PNP_WRITE
;
454 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
458 dev_warn(&dev
->dev
, "unknown resource type %d in _CRS\n",
466 int pnpacpi_parse_allocated_resource(struct pnp_dev
*dev
)
468 acpi_handle handle
= dev
->data
;
471 pnp_dbg(&dev
->dev
, "parse allocated resources\n");
473 pnp_init_resources(dev
);
475 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
476 pnpacpi_allocated_resource
, dev
);
478 if (ACPI_FAILURE(status
)) {
479 if (status
!= AE_NOT_FOUND
)
480 dev_err(&dev
->dev
, "can't evaluate _CRS: %d", status
);
486 static __init
void pnpacpi_parse_dma_option(struct pnp_dev
*dev
,
487 unsigned int option_flags
,
488 struct acpi_resource_dma
*p
)
491 unsigned char map
= 0, flags
;
493 if (p
->channel_count
== 0)
496 for (i
= 0; i
< p
->channel_count
; i
++)
497 map
|= 1 << p
->channels
[i
];
499 flags
= dma_flags(dev
, p
->type
, p
->bus_master
, p
->transfer
);
500 pnp_register_dma_resource(dev
, option_flags
, map
, flags
);
503 static __init
void pnpacpi_parse_irq_option(struct pnp_dev
*dev
,
504 unsigned int option_flags
,
505 struct acpi_resource_irq
*p
)
511 if (p
->interrupt_count
== 0)
514 bitmap_zero(map
.bits
, PNP_IRQ_NR
);
515 for (i
= 0; i
< p
->interrupt_count
; i
++)
516 if (p
->interrupts
[i
])
517 __set_bit(p
->interrupts
[i
], map
.bits
);
519 flags
= irq_flags(p
->triggering
, p
->polarity
, p
->sharable
);
520 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
523 static __init
void pnpacpi_parse_ext_irq_option(struct pnp_dev
*dev
,
524 unsigned int option_flags
,
525 struct acpi_resource_extended_irq
*p
)
531 if (p
->interrupt_count
== 0)
534 bitmap_zero(map
.bits
, PNP_IRQ_NR
);
535 for (i
= 0; i
< p
->interrupt_count
; i
++) {
536 if (p
->interrupts
[i
]) {
537 if (p
->interrupts
[i
] < PNP_IRQ_NR
)
538 __set_bit(p
->interrupts
[i
], map
.bits
);
540 dev_err(&dev
->dev
, "ignoring IRQ %d option "
541 "(too large for %d entry bitmap)\n",
542 p
->interrupts
[i
], PNP_IRQ_NR
);
546 flags
= irq_flags(p
->triggering
, p
->polarity
, p
->sharable
);
547 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
550 static __init
void pnpacpi_parse_port_option(struct pnp_dev
*dev
,
551 unsigned int option_flags
,
552 struct acpi_resource_io
*io
)
554 unsigned char flags
= 0;
556 if (io
->address_length
== 0)
559 if (io
->io_decode
== ACPI_DECODE_16
)
560 flags
= IORESOURCE_IO_16BIT_ADDR
;
561 pnp_register_port_resource(dev
, option_flags
, io
->minimum
, io
->maximum
,
562 io
->alignment
, io
->address_length
, flags
);
565 static __init
void pnpacpi_parse_fixed_port_option(struct pnp_dev
*dev
,
566 unsigned int option_flags
,
567 struct acpi_resource_fixed_io
*io
)
569 if (io
->address_length
== 0)
572 pnp_register_port_resource(dev
, option_flags
, io
->address
, io
->address
,
573 0, io
->address_length
, IORESOURCE_IO_FIXED
);
576 static __init
void pnpacpi_parse_mem24_option(struct pnp_dev
*dev
,
577 unsigned int option_flags
,
578 struct acpi_resource_memory24
*p
)
580 unsigned char flags
= 0;
582 if (p
->address_length
== 0)
585 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
586 flags
= IORESOURCE_MEM_WRITEABLE
;
587 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
588 p
->alignment
, p
->address_length
, flags
);
591 static __init
void pnpacpi_parse_mem32_option(struct pnp_dev
*dev
,
592 unsigned int option_flags
,
593 struct acpi_resource_memory32
*p
)
595 unsigned char flags
= 0;
597 if (p
->address_length
== 0)
600 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
601 flags
= IORESOURCE_MEM_WRITEABLE
;
602 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
603 p
->alignment
, p
->address_length
, flags
);
606 static __init
void pnpacpi_parse_fixed_mem32_option(struct pnp_dev
*dev
,
607 unsigned int option_flags
,
608 struct acpi_resource_fixed_memory32
*p
)
610 unsigned char flags
= 0;
612 if (p
->address_length
== 0)
615 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
616 flags
= IORESOURCE_MEM_WRITEABLE
;
617 pnp_register_mem_resource(dev
, option_flags
, p
->address
, p
->address
,
618 0, p
->address_length
, flags
);
621 static __init
void pnpacpi_parse_address_option(struct pnp_dev
*dev
,
622 unsigned int option_flags
,
623 struct acpi_resource
*r
)
625 struct acpi_resource_address64 addr
, *p
= &addr
;
627 unsigned char flags
= 0;
629 status
= acpi_resource_to_address64(r
, p
);
630 if (ACPI_FAILURE(status
)) {
631 dev_warn(&dev
->dev
, "can't convert resource type %d\n",
636 if (p
->address_length
== 0)
639 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
640 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
641 flags
= IORESOURCE_MEM_WRITEABLE
;
642 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
,
643 p
->minimum
, 0, p
->address_length
,
645 } else if (p
->resource_type
== ACPI_IO_RANGE
)
646 pnp_register_port_resource(dev
, option_flags
, p
->minimum
,
647 p
->minimum
, 0, p
->address_length
,
648 IORESOURCE_IO_FIXED
);
651 static __init
void pnpacpi_parse_ext_address_option(struct pnp_dev
*dev
,
652 unsigned int option_flags
,
653 struct acpi_resource
*r
)
655 struct acpi_resource_extended_address64
*p
= &r
->data
.ext_address64
;
656 unsigned char flags
= 0;
658 if (p
->address_length
== 0)
661 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
662 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
663 flags
= IORESOURCE_MEM_WRITEABLE
;
664 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
,
665 p
->minimum
, 0, p
->address_length
,
667 } else if (p
->resource_type
== ACPI_IO_RANGE
)
668 pnp_register_port_resource(dev
, option_flags
, p
->minimum
,
669 p
->minimum
, 0, p
->address_length
,
670 IORESOURCE_IO_FIXED
);
673 struct acpipnp_parse_option_s
{
675 unsigned int option_flags
;
678 static __init acpi_status
pnpacpi_option_resource(struct acpi_resource
*res
,
682 struct acpipnp_parse_option_s
*parse_data
= data
;
683 struct pnp_dev
*dev
= parse_data
->dev
;
684 unsigned int option_flags
= parse_data
->option_flags
;
687 case ACPI_RESOURCE_TYPE_IRQ
:
688 pnpacpi_parse_irq_option(dev
, option_flags
, &res
->data
.irq
);
691 case ACPI_RESOURCE_TYPE_DMA
:
692 pnpacpi_parse_dma_option(dev
, option_flags
, &res
->data
.dma
);
695 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
696 switch (res
->data
.start_dpf
.compatibility_priority
) {
697 case ACPI_GOOD_CONFIGURATION
:
698 priority
= PNP_RES_PRIORITY_PREFERRED
;
701 case ACPI_ACCEPTABLE_CONFIGURATION
:
702 priority
= PNP_RES_PRIORITY_ACCEPTABLE
;
705 case ACPI_SUB_OPTIMAL_CONFIGURATION
:
706 priority
= PNP_RES_PRIORITY_FUNCTIONAL
;
709 priority
= PNP_RES_PRIORITY_INVALID
;
712 parse_data
->option_flags
= pnp_new_dependent_set(dev
, priority
);
715 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
716 parse_data
->option_flags
= 0;
719 case ACPI_RESOURCE_TYPE_IO
:
720 pnpacpi_parse_port_option(dev
, option_flags
, &res
->data
.io
);
723 case ACPI_RESOURCE_TYPE_FIXED_IO
:
724 pnpacpi_parse_fixed_port_option(dev
, option_flags
,
725 &res
->data
.fixed_io
);
728 case ACPI_RESOURCE_TYPE_VENDOR
:
729 case ACPI_RESOURCE_TYPE_END_TAG
:
732 case ACPI_RESOURCE_TYPE_MEMORY24
:
733 pnpacpi_parse_mem24_option(dev
, option_flags
,
734 &res
->data
.memory24
);
737 case ACPI_RESOURCE_TYPE_MEMORY32
:
738 pnpacpi_parse_mem32_option(dev
, option_flags
,
739 &res
->data
.memory32
);
742 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
743 pnpacpi_parse_fixed_mem32_option(dev
, option_flags
,
744 &res
->data
.fixed_memory32
);
747 case ACPI_RESOURCE_TYPE_ADDRESS16
:
748 case ACPI_RESOURCE_TYPE_ADDRESS32
:
749 case ACPI_RESOURCE_TYPE_ADDRESS64
:
750 pnpacpi_parse_address_option(dev
, option_flags
, res
);
753 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
754 pnpacpi_parse_ext_address_option(dev
, option_flags
, res
);
757 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
758 pnpacpi_parse_ext_irq_option(dev
, option_flags
,
759 &res
->data
.extended_irq
);
762 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
766 dev_warn(&dev
->dev
, "unknown resource type %d in _PRS\n",
774 int __init
pnpacpi_parse_resource_option_data(struct pnp_dev
*dev
)
776 acpi_handle handle
= dev
->data
;
778 struct acpipnp_parse_option_s parse_data
;
780 pnp_dbg(&dev
->dev
, "parse resource options\n");
782 parse_data
.dev
= dev
;
783 parse_data
.option_flags
= 0;
785 status
= acpi_walk_resources(handle
, METHOD_NAME__PRS
,
786 pnpacpi_option_resource
, &parse_data
);
788 if (ACPI_FAILURE(status
)) {
789 if (status
!= AE_NOT_FOUND
)
790 dev_err(&dev
->dev
, "can't evaluate _PRS: %d", status
);
796 static int pnpacpi_supported_resource(struct acpi_resource
*res
)
799 case ACPI_RESOURCE_TYPE_IRQ
:
800 case ACPI_RESOURCE_TYPE_DMA
:
801 case ACPI_RESOURCE_TYPE_IO
:
802 case ACPI_RESOURCE_TYPE_FIXED_IO
:
803 case ACPI_RESOURCE_TYPE_MEMORY24
:
804 case ACPI_RESOURCE_TYPE_MEMORY32
:
805 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
806 case ACPI_RESOURCE_TYPE_ADDRESS16
:
807 case ACPI_RESOURCE_TYPE_ADDRESS32
:
808 case ACPI_RESOURCE_TYPE_ADDRESS64
:
809 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
810 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
819 static acpi_status
pnpacpi_count_resources(struct acpi_resource
*res
,
824 if (pnpacpi_supported_resource(res
))
829 static acpi_status
pnpacpi_type_resources(struct acpi_resource
*res
, void *data
)
831 struct acpi_resource
**resource
= data
;
833 if (pnpacpi_supported_resource(res
)) {
834 (*resource
)->type
= res
->type
;
835 (*resource
)->length
= sizeof(struct acpi_resource
);
836 if (res
->type
== ACPI_RESOURCE_TYPE_IRQ
)
837 (*resource
)->data
.irq
.descriptor_length
=
838 res
->data
.irq
.descriptor_length
;
845 int pnpacpi_build_resource_template(struct pnp_dev
*dev
,
846 struct acpi_buffer
*buffer
)
848 acpi_handle handle
= dev
->data
;
849 struct acpi_resource
*resource
;
853 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
854 pnpacpi_count_resources
, &res_cnt
);
855 if (ACPI_FAILURE(status
)) {
856 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
861 buffer
->length
= sizeof(struct acpi_resource
) * (res_cnt
+ 1) + 1;
862 buffer
->pointer
= kzalloc(buffer
->length
- 1, GFP_KERNEL
);
863 if (!buffer
->pointer
)
866 resource
= (struct acpi_resource
*)buffer
->pointer
;
867 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
868 pnpacpi_type_resources
, &resource
);
869 if (ACPI_FAILURE(status
)) {
870 kfree(buffer
->pointer
);
871 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
874 /* resource will pointer the end resource now */
875 resource
->type
= ACPI_RESOURCE_TYPE_END_TAG
;
880 static void pnpacpi_encode_irq(struct pnp_dev
*dev
,
881 struct acpi_resource
*resource
,
884 struct acpi_resource_irq
*irq
= &resource
->data
.irq
;
885 int triggering
, polarity
, shareable
;
887 if (!pnp_resource_enabled(p
)) {
888 irq
->interrupt_count
= 0;
889 pnp_dbg(&dev
->dev
, " encode irq (%s)\n",
890 p
? "disabled" : "missing");
894 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
895 irq
->triggering
= triggering
;
896 irq
->polarity
= polarity
;
897 irq
->sharable
= shareable
;
898 irq
->interrupt_count
= 1;
899 irq
->interrupts
[0] = p
->start
;
901 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s (%d-byte descriptor)\n",
903 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
904 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
905 irq
->sharable
== ACPI_SHARED
? "shared" : "exclusive",
906 irq
->descriptor_length
);
909 static void pnpacpi_encode_ext_irq(struct pnp_dev
*dev
,
910 struct acpi_resource
*resource
,
913 struct acpi_resource_extended_irq
*extended_irq
= &resource
->data
.extended_irq
;
914 int triggering
, polarity
, shareable
;
916 if (!pnp_resource_enabled(p
)) {
917 extended_irq
->interrupt_count
= 0;
918 pnp_dbg(&dev
->dev
, " encode extended irq (%s)\n",
919 p
? "disabled" : "missing");
923 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
924 extended_irq
->producer_consumer
= ACPI_CONSUMER
;
925 extended_irq
->triggering
= triggering
;
926 extended_irq
->polarity
= polarity
;
927 extended_irq
->sharable
= shareable
;
928 extended_irq
->interrupt_count
= 1;
929 extended_irq
->interrupts
[0] = p
->start
;
931 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s\n", (int) p
->start
,
932 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
933 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
934 extended_irq
->sharable
== ACPI_SHARED
? "shared" : "exclusive");
937 static void pnpacpi_encode_dma(struct pnp_dev
*dev
,
938 struct acpi_resource
*resource
,
941 struct acpi_resource_dma
*dma
= &resource
->data
.dma
;
943 if (!pnp_resource_enabled(p
)) {
944 dma
->channel_count
= 0;
945 pnp_dbg(&dev
->dev
, " encode dma (%s)\n",
946 p
? "disabled" : "missing");
950 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
951 switch (p
->flags
& IORESOURCE_DMA_SPEED_MASK
) {
952 case IORESOURCE_DMA_TYPEA
:
953 dma
->type
= ACPI_TYPE_A
;
955 case IORESOURCE_DMA_TYPEB
:
956 dma
->type
= ACPI_TYPE_B
;
958 case IORESOURCE_DMA_TYPEF
:
959 dma
->type
= ACPI_TYPE_F
;
962 dma
->type
= ACPI_COMPATIBILITY
;
965 switch (p
->flags
& IORESOURCE_DMA_TYPE_MASK
) {
966 case IORESOURCE_DMA_8BIT
:
967 dma
->transfer
= ACPI_TRANSFER_8
;
969 case IORESOURCE_DMA_8AND16BIT
:
970 dma
->transfer
= ACPI_TRANSFER_8_16
;
973 dma
->transfer
= ACPI_TRANSFER_16
;
976 dma
->bus_master
= !!(p
->flags
& IORESOURCE_DMA_MASTER
);
977 dma
->channel_count
= 1;
978 dma
->channels
[0] = p
->start
;
980 pnp_dbg(&dev
->dev
, " encode dma %d "
981 "type %#x transfer %#x master %d\n",
982 (int) p
->start
, dma
->type
, dma
->transfer
, dma
->bus_master
);
985 static void pnpacpi_encode_io(struct pnp_dev
*dev
,
986 struct acpi_resource
*resource
,
989 struct acpi_resource_io
*io
= &resource
->data
.io
;
991 if (pnp_resource_enabled(p
)) {
992 /* Note: pnp_assign_port copies pnp_port->flags into p->flags */
993 io
->io_decode
= (p
->flags
& IORESOURCE_IO_16BIT_ADDR
) ?
994 ACPI_DECODE_16
: ACPI_DECODE_10
;
995 io
->minimum
= p
->start
;
996 io
->maximum
= p
->end
;
997 io
->alignment
= 0; /* Correct? */
998 io
->address_length
= p
->end
- p
->start
+ 1;
1001 io
->address_length
= 0;
1004 pnp_dbg(&dev
->dev
, " encode io %#x-%#x decode %#x\n", io
->minimum
,
1005 io
->minimum
+ io
->address_length
- 1, io
->io_decode
);
1008 static void pnpacpi_encode_fixed_io(struct pnp_dev
*dev
,
1009 struct acpi_resource
*resource
,
1012 struct acpi_resource_fixed_io
*fixed_io
= &resource
->data
.fixed_io
;
1014 if (pnp_resource_enabled(p
)) {
1015 fixed_io
->address
= p
->start
;
1016 fixed_io
->address_length
= p
->end
- p
->start
+ 1;
1018 fixed_io
->address
= 0;
1019 fixed_io
->address_length
= 0;
1022 pnp_dbg(&dev
->dev
, " encode fixed_io %#x-%#x\n", fixed_io
->address
,
1023 fixed_io
->address
+ fixed_io
->address_length
- 1);
1026 static void pnpacpi_encode_mem24(struct pnp_dev
*dev
,
1027 struct acpi_resource
*resource
,
1030 struct acpi_resource_memory24
*memory24
= &resource
->data
.memory24
;
1032 if (pnp_resource_enabled(p
)) {
1033 /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */
1034 memory24
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
1035 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
1036 memory24
->minimum
= p
->start
;
1037 memory24
->maximum
= p
->end
;
1038 memory24
->alignment
= 0;
1039 memory24
->address_length
= p
->end
- p
->start
+ 1;
1041 memory24
->minimum
= 0;
1042 memory24
->address_length
= 0;
1045 pnp_dbg(&dev
->dev
, " encode mem24 %#x-%#x write_protect %#x\n",
1047 memory24
->minimum
+ memory24
->address_length
- 1,
1048 memory24
->write_protect
);
1051 static void pnpacpi_encode_mem32(struct pnp_dev
*dev
,
1052 struct acpi_resource
*resource
,
1055 struct acpi_resource_memory32
*memory32
= &resource
->data
.memory32
;
1057 if (pnp_resource_enabled(p
)) {
1058 memory32
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
1059 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
1060 memory32
->minimum
= p
->start
;
1061 memory32
->maximum
= p
->end
;
1062 memory32
->alignment
= 0;
1063 memory32
->address_length
= p
->end
- p
->start
+ 1;
1065 memory32
->minimum
= 0;
1066 memory32
->alignment
= 0;
1069 pnp_dbg(&dev
->dev
, " encode mem32 %#x-%#x write_protect %#x\n",
1071 memory32
->minimum
+ memory32
->address_length
- 1,
1072 memory32
->write_protect
);
1075 static void pnpacpi_encode_fixed_mem32(struct pnp_dev
*dev
,
1076 struct acpi_resource
*resource
,
1079 struct acpi_resource_fixed_memory32
*fixed_memory32
= &resource
->data
.fixed_memory32
;
1081 if (pnp_resource_enabled(p
)) {
1082 fixed_memory32
->write_protect
=
1083 p
->flags
& IORESOURCE_MEM_WRITEABLE
?
1084 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
1085 fixed_memory32
->address
= p
->start
;
1086 fixed_memory32
->address_length
= p
->end
- p
->start
+ 1;
1088 fixed_memory32
->address
= 0;
1089 fixed_memory32
->address_length
= 0;
1092 pnp_dbg(&dev
->dev
, " encode fixed_mem32 %#x-%#x write_protect %#x\n",
1093 fixed_memory32
->address
,
1094 fixed_memory32
->address
+ fixed_memory32
->address_length
- 1,
1095 fixed_memory32
->write_protect
);
1098 int pnpacpi_encode_resources(struct pnp_dev
*dev
, struct acpi_buffer
*buffer
)
1101 /* pnpacpi_build_resource_template allocates extra mem */
1102 int res_cnt
= (buffer
->length
- 1) / sizeof(struct acpi_resource
) - 1;
1103 struct acpi_resource
*resource
= buffer
->pointer
;
1104 int port
= 0, irq
= 0, dma
= 0, mem
= 0;
1106 pnp_dbg(&dev
->dev
, "encode %d resources\n", res_cnt
);
1107 while (i
< res_cnt
) {
1108 switch (resource
->type
) {
1109 case ACPI_RESOURCE_TYPE_IRQ
:
1110 pnpacpi_encode_irq(dev
, resource
,
1111 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
1115 case ACPI_RESOURCE_TYPE_DMA
:
1116 pnpacpi_encode_dma(dev
, resource
,
1117 pnp_get_resource(dev
, IORESOURCE_DMA
, dma
));
1120 case ACPI_RESOURCE_TYPE_IO
:
1121 pnpacpi_encode_io(dev
, resource
,
1122 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
1125 case ACPI_RESOURCE_TYPE_FIXED_IO
:
1126 pnpacpi_encode_fixed_io(dev
, resource
,
1127 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
1130 case ACPI_RESOURCE_TYPE_MEMORY24
:
1131 pnpacpi_encode_mem24(dev
, resource
,
1132 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
1135 case ACPI_RESOURCE_TYPE_MEMORY32
:
1136 pnpacpi_encode_mem32(dev
, resource
,
1137 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
1140 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
1141 pnpacpi_encode_fixed_mem32(dev
, resource
,
1142 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
1145 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
1146 pnpacpi_encode_ext_irq(dev
, resource
,
1147 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
1150 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
1151 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
1152 case ACPI_RESOURCE_TYPE_VENDOR
:
1153 case ACPI_RESOURCE_TYPE_END_TAG
:
1154 case ACPI_RESOURCE_TYPE_ADDRESS16
:
1155 case ACPI_RESOURCE_TYPE_ADDRESS32
:
1156 case ACPI_RESOURCE_TYPE_ADDRESS64
:
1157 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
1158 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
1159 default: /* other type */
1160 dev_warn(&dev
->dev
, "can't encode unknown resource "
1161 "type %d\n", resource
->type
);