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>
27 #include <linux/slab.h>
31 static void decode_irq_flags(struct pnp_dev
*dev
, int flags
, u8
*triggering
,
32 u8
*polarity
, u8
*shareable
)
34 switch (flags
& (IORESOURCE_IRQ_LOWLEVEL
| IORESOURCE_IRQ_HIGHLEVEL
|
35 IORESOURCE_IRQ_LOWEDGE
| IORESOURCE_IRQ_HIGHEDGE
)) {
36 case IORESOURCE_IRQ_LOWLEVEL
:
37 *triggering
= ACPI_LEVEL_SENSITIVE
;
38 *polarity
= ACPI_ACTIVE_LOW
;
40 case IORESOURCE_IRQ_HIGHLEVEL
:
41 *triggering
= ACPI_LEVEL_SENSITIVE
;
42 *polarity
= ACPI_ACTIVE_HIGH
;
44 case IORESOURCE_IRQ_LOWEDGE
:
45 *triggering
= ACPI_EDGE_SENSITIVE
;
46 *polarity
= ACPI_ACTIVE_LOW
;
48 case IORESOURCE_IRQ_HIGHEDGE
:
49 *triggering
= ACPI_EDGE_SENSITIVE
;
50 *polarity
= ACPI_ACTIVE_HIGH
;
53 dev_err(&dev
->dev
, "can't encode invalid IRQ mode %#x\n",
55 *triggering
= ACPI_EDGE_SENSITIVE
;
56 *polarity
= ACPI_ACTIVE_HIGH
;
60 if (flags
& IORESOURCE_IRQ_SHAREABLE
)
61 *shareable
= ACPI_SHARED
;
63 *shareable
= ACPI_EXCLUSIVE
;
66 static int dma_flags(struct pnp_dev
*dev
, int type
, int bus_master
,
72 flags
|= IORESOURCE_DMA_MASTER
;
74 case ACPI_COMPATIBILITY
:
75 flags
|= IORESOURCE_DMA_COMPATIBLE
;
78 flags
|= IORESOURCE_DMA_TYPEA
;
81 flags
|= IORESOURCE_DMA_TYPEB
;
84 flags
|= IORESOURCE_DMA_TYPEF
;
87 /* Set a default value ? */
88 flags
|= IORESOURCE_DMA_COMPATIBLE
;
89 dev_err(&dev
->dev
, "invalid DMA type %d\n", type
);
93 flags
|= IORESOURCE_DMA_8BIT
;
95 case ACPI_TRANSFER_8_16
:
96 flags
|= IORESOURCE_DMA_8AND16BIT
;
98 case ACPI_TRANSFER_16
:
99 flags
|= IORESOURCE_DMA_16BIT
;
102 /* Set a default value ? */
103 flags
|= IORESOURCE_DMA_8AND16BIT
;
104 dev_err(&dev
->dev
, "invalid DMA transfer type %d\n", transfer
);
111 * Allocated Resources
114 static void pnpacpi_add_irqresource(struct pnp_dev
*dev
, struct resource
*r
)
116 if (!(r
->flags
& IORESOURCE_DISABLED
))
117 pcibios_penalize_isa_irq(r
->start
, 1);
119 pnp_add_resource(dev
, r
);
123 * Device CSRs that do not appear in PCI config space should be described
124 * via ACPI. This would normally be done with Address Space Descriptors
125 * marked as "consumer-only," but old versions of Windows and Linux ignore
126 * the producer/consumer flag, so HP invented a vendor-defined resource to
127 * describe the location and size of CSR space.
129 static struct acpi_vendor_uuid hp_ccsr_uuid
= {
131 .data
= { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
132 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
135 static int vendor_resource_matches(struct pnp_dev
*dev
,
136 struct acpi_resource_vendor_typed
*vendor
,
137 struct acpi_vendor_uuid
*match
,
140 int uuid_len
= sizeof(vendor
->uuid
);
141 u8 uuid_subtype
= vendor
->uuid_subtype
;
142 u8
*uuid
= vendor
->uuid
;
145 /* byte_length includes uuid_subtype and uuid */
146 actual_len
= vendor
->byte_length
- uuid_len
- 1;
148 if (uuid_subtype
== match
->subtype
&&
149 uuid_len
== sizeof(match
->data
) &&
150 memcmp(uuid
, match
->data
, uuid_len
) == 0) {
151 if (expected_len
&& expected_len
!= actual_len
) {
152 dev_err(&dev
->dev
, "wrong vendor descriptor size; "
153 "expected %d, found %d bytes\n",
154 expected_len
, actual_len
);
164 static void pnpacpi_parse_allocated_vendor(struct pnp_dev
*dev
,
165 struct acpi_resource_vendor_typed
*vendor
)
167 if (vendor_resource_matches(dev
, vendor
, &hp_ccsr_uuid
, 16)) {
170 memcpy(&start
, vendor
->byte_data
, sizeof(start
));
171 memcpy(&length
, vendor
->byte_data
+ 8, sizeof(length
));
173 pnp_add_mem_resource(dev
, start
, start
+ length
- 1, 0);
177 static acpi_status
pnpacpi_allocated_resource(struct acpi_resource
*res
,
180 struct pnp_dev
*dev
= data
;
181 struct acpi_resource_dma
*dma
;
182 struct acpi_resource_vendor_typed
*vendor_typed
;
183 struct resource_win win
= {{0}, 0};
184 struct resource
*r
= &win
.res
;
187 if (acpi_dev_resource_address_space(res
, &win
)
188 || acpi_dev_resource_ext_address_space(res
, &win
)) {
189 pnp_add_resource(dev
, &win
.res
);
194 if (acpi_dev_resource_interrupt(res
, 0, r
)) {
195 pnpacpi_add_irqresource(dev
, r
);
196 for (i
= 1; acpi_dev_resource_interrupt(res
, i
, r
); i
++)
197 pnpacpi_add_irqresource(dev
, r
);
201 * The IRQ encoder puts a single interrupt in each
202 * descriptor, so if a _CRS descriptor has more than
203 * one interrupt, we won't be able to re-encode it.
205 if (pnp_can_write(dev
)) {
206 dev_warn(&dev
->dev
, "multiple interrupts in "
207 "_CRS descriptor; configuration can't "
209 dev
->capabilities
&= ~PNP_WRITE
;
213 } else if (r
->flags
& IORESOURCE_DISABLED
) {
214 pnp_add_irq_resource(dev
, 0, IORESOURCE_DISABLED
);
219 case ACPI_RESOURCE_TYPE_MEMORY24
:
220 case ACPI_RESOURCE_TYPE_MEMORY32
:
221 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
222 if (acpi_dev_resource_memory(res
, r
))
223 pnp_add_resource(dev
, r
);
225 case ACPI_RESOURCE_TYPE_IO
:
226 case ACPI_RESOURCE_TYPE_FIXED_IO
:
227 if (acpi_dev_resource_io(res
, r
))
228 pnp_add_resource(dev
, r
);
230 case ACPI_RESOURCE_TYPE_DMA
:
231 dma
= &res
->data
.dma
;
232 if (dma
->channel_count
> 0 && dma
->channels
[0] != (u8
) -1)
233 flags
= dma_flags(dev
, dma
->type
, dma
->bus_master
,
236 flags
= IORESOURCE_DISABLED
;
237 pnp_add_dma_resource(dev
, dma
->channels
[0], flags
);
240 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
241 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
244 case ACPI_RESOURCE_TYPE_VENDOR
:
245 vendor_typed
= &res
->data
.vendor_typed
;
246 pnpacpi_parse_allocated_vendor(dev
, vendor_typed
);
249 case ACPI_RESOURCE_TYPE_END_TAG
:
252 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
256 dev_warn(&dev
->dev
, "unknown resource type %d in _CRS\n",
264 int pnpacpi_parse_allocated_resource(struct pnp_dev
*dev
)
266 struct acpi_device
*acpi_dev
= dev
->data
;
267 acpi_handle handle
= acpi_dev
->handle
;
270 pnp_dbg(&dev
->dev
, "parse allocated resources\n");
272 pnp_init_resources(dev
);
274 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
275 pnpacpi_allocated_resource
, dev
);
277 if (ACPI_FAILURE(status
)) {
278 if (status
!= AE_NOT_FOUND
)
279 dev_err(&dev
->dev
, "can't evaluate _CRS: %d", status
);
285 static __init
void pnpacpi_parse_dma_option(struct pnp_dev
*dev
,
286 unsigned int option_flags
,
287 struct acpi_resource_dma
*p
)
290 unsigned char map
= 0, flags
;
292 for (i
= 0; i
< p
->channel_count
; i
++)
293 map
|= 1 << p
->channels
[i
];
295 flags
= dma_flags(dev
, p
->type
, p
->bus_master
, p
->transfer
);
296 pnp_register_dma_resource(dev
, option_flags
, map
, flags
);
299 static __init
void pnpacpi_parse_irq_option(struct pnp_dev
*dev
,
300 unsigned int option_flags
,
301 struct acpi_resource_irq
*p
)
307 bitmap_zero(map
.bits
, PNP_IRQ_NR
);
308 for (i
= 0; i
< p
->interrupt_count
; i
++)
309 if (p
->interrupts
[i
])
310 __set_bit(p
->interrupts
[i
], map
.bits
);
312 flags
= acpi_dev_irq_flags(p
->triggering
, p
->polarity
, p
->sharable
);
313 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
316 static __init
void pnpacpi_parse_ext_irq_option(struct pnp_dev
*dev
,
317 unsigned int option_flags
,
318 struct acpi_resource_extended_irq
*p
)
324 bitmap_zero(map
.bits
, PNP_IRQ_NR
);
325 for (i
= 0; i
< p
->interrupt_count
; i
++) {
326 if (p
->interrupts
[i
]) {
327 if (p
->interrupts
[i
] < PNP_IRQ_NR
)
328 __set_bit(p
->interrupts
[i
], map
.bits
);
330 dev_err(&dev
->dev
, "ignoring IRQ %d option "
331 "(too large for %d entry bitmap)\n",
332 p
->interrupts
[i
], PNP_IRQ_NR
);
336 flags
= acpi_dev_irq_flags(p
->triggering
, p
->polarity
, p
->sharable
);
337 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
340 static __init
void pnpacpi_parse_port_option(struct pnp_dev
*dev
,
341 unsigned int option_flags
,
342 struct acpi_resource_io
*io
)
344 unsigned char flags
= 0;
346 if (io
->io_decode
== ACPI_DECODE_16
)
347 flags
= IORESOURCE_IO_16BIT_ADDR
;
348 pnp_register_port_resource(dev
, option_flags
, io
->minimum
, io
->maximum
,
349 io
->alignment
, io
->address_length
, flags
);
352 static __init
void pnpacpi_parse_fixed_port_option(struct pnp_dev
*dev
,
353 unsigned int option_flags
,
354 struct acpi_resource_fixed_io
*io
)
356 pnp_register_port_resource(dev
, option_flags
, io
->address
, io
->address
,
357 0, io
->address_length
, IORESOURCE_IO_FIXED
);
360 static __init
void pnpacpi_parse_mem24_option(struct pnp_dev
*dev
,
361 unsigned int option_flags
,
362 struct acpi_resource_memory24
*p
)
364 unsigned char flags
= 0;
366 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
367 flags
= IORESOURCE_MEM_WRITEABLE
;
368 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
369 p
->alignment
, p
->address_length
, flags
);
372 static __init
void pnpacpi_parse_mem32_option(struct pnp_dev
*dev
,
373 unsigned int option_flags
,
374 struct acpi_resource_memory32
*p
)
376 unsigned char flags
= 0;
378 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
379 flags
= IORESOURCE_MEM_WRITEABLE
;
380 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
381 p
->alignment
, p
->address_length
, flags
);
384 static __init
void pnpacpi_parse_fixed_mem32_option(struct pnp_dev
*dev
,
385 unsigned int option_flags
,
386 struct acpi_resource_fixed_memory32
*p
)
388 unsigned char flags
= 0;
390 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
391 flags
= IORESOURCE_MEM_WRITEABLE
;
392 pnp_register_mem_resource(dev
, option_flags
, p
->address
, p
->address
,
393 0, p
->address_length
, flags
);
396 static __init
void pnpacpi_parse_address_option(struct pnp_dev
*dev
,
397 unsigned int option_flags
,
398 struct acpi_resource
*r
)
400 struct acpi_resource_address64 addr
, *p
= &addr
;
402 unsigned char flags
= 0;
404 status
= acpi_resource_to_address64(r
, p
);
405 if (ACPI_FAILURE(status
)) {
406 dev_warn(&dev
->dev
, "can't convert resource type %d\n",
411 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
412 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
413 flags
= IORESOURCE_MEM_WRITEABLE
;
414 pnp_register_mem_resource(dev
, option_flags
, p
->address
.minimum
,
415 p
->address
.minimum
, 0, p
->address
.address_length
,
417 } else if (p
->resource_type
== ACPI_IO_RANGE
)
418 pnp_register_port_resource(dev
, option_flags
, p
->address
.minimum
,
419 p
->address
.minimum
, 0, p
->address
.address_length
,
420 IORESOURCE_IO_FIXED
);
423 static __init
void pnpacpi_parse_ext_address_option(struct pnp_dev
*dev
,
424 unsigned int option_flags
,
425 struct acpi_resource
*r
)
427 struct acpi_resource_extended_address64
*p
= &r
->data
.ext_address64
;
428 unsigned char flags
= 0;
430 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
431 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
432 flags
= IORESOURCE_MEM_WRITEABLE
;
433 pnp_register_mem_resource(dev
, option_flags
, p
->address
.minimum
,
434 p
->address
.minimum
, 0, p
->address
.address_length
,
436 } else if (p
->resource_type
== ACPI_IO_RANGE
)
437 pnp_register_port_resource(dev
, option_flags
, p
->address
.minimum
,
438 p
->address
.minimum
, 0, p
->address
.address_length
,
439 IORESOURCE_IO_FIXED
);
442 struct acpipnp_parse_option_s
{
444 unsigned int option_flags
;
447 static __init acpi_status
pnpacpi_option_resource(struct acpi_resource
*res
,
451 struct acpipnp_parse_option_s
*parse_data
= data
;
452 struct pnp_dev
*dev
= parse_data
->dev
;
453 unsigned int option_flags
= parse_data
->option_flags
;
456 case ACPI_RESOURCE_TYPE_IRQ
:
457 pnpacpi_parse_irq_option(dev
, option_flags
, &res
->data
.irq
);
460 case ACPI_RESOURCE_TYPE_DMA
:
461 pnpacpi_parse_dma_option(dev
, option_flags
, &res
->data
.dma
);
464 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
465 switch (res
->data
.start_dpf
.compatibility_priority
) {
466 case ACPI_GOOD_CONFIGURATION
:
467 priority
= PNP_RES_PRIORITY_PREFERRED
;
470 case ACPI_ACCEPTABLE_CONFIGURATION
:
471 priority
= PNP_RES_PRIORITY_ACCEPTABLE
;
474 case ACPI_SUB_OPTIMAL_CONFIGURATION
:
475 priority
= PNP_RES_PRIORITY_FUNCTIONAL
;
478 priority
= PNP_RES_PRIORITY_INVALID
;
481 parse_data
->option_flags
= pnp_new_dependent_set(dev
, priority
);
484 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
485 parse_data
->option_flags
= 0;
488 case ACPI_RESOURCE_TYPE_IO
:
489 pnpacpi_parse_port_option(dev
, option_flags
, &res
->data
.io
);
492 case ACPI_RESOURCE_TYPE_FIXED_IO
:
493 pnpacpi_parse_fixed_port_option(dev
, option_flags
,
494 &res
->data
.fixed_io
);
497 case ACPI_RESOURCE_TYPE_VENDOR
:
498 case ACPI_RESOURCE_TYPE_END_TAG
:
501 case ACPI_RESOURCE_TYPE_MEMORY24
:
502 pnpacpi_parse_mem24_option(dev
, option_flags
,
503 &res
->data
.memory24
);
506 case ACPI_RESOURCE_TYPE_MEMORY32
:
507 pnpacpi_parse_mem32_option(dev
, option_flags
,
508 &res
->data
.memory32
);
511 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
512 pnpacpi_parse_fixed_mem32_option(dev
, option_flags
,
513 &res
->data
.fixed_memory32
);
516 case ACPI_RESOURCE_TYPE_ADDRESS16
:
517 case ACPI_RESOURCE_TYPE_ADDRESS32
:
518 case ACPI_RESOURCE_TYPE_ADDRESS64
:
519 pnpacpi_parse_address_option(dev
, option_flags
, res
);
522 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
523 pnpacpi_parse_ext_address_option(dev
, option_flags
, res
);
526 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
527 pnpacpi_parse_ext_irq_option(dev
, option_flags
,
528 &res
->data
.extended_irq
);
531 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
535 dev_warn(&dev
->dev
, "unknown resource type %d in _PRS\n",
543 int __init
pnpacpi_parse_resource_option_data(struct pnp_dev
*dev
)
545 struct acpi_device
*acpi_dev
= dev
->data
;
546 acpi_handle handle
= acpi_dev
->handle
;
548 struct acpipnp_parse_option_s parse_data
;
550 pnp_dbg(&dev
->dev
, "parse resource options\n");
552 parse_data
.dev
= dev
;
553 parse_data
.option_flags
= 0;
555 status
= acpi_walk_resources(handle
, METHOD_NAME__PRS
,
556 pnpacpi_option_resource
, &parse_data
);
558 if (ACPI_FAILURE(status
)) {
559 if (status
!= AE_NOT_FOUND
)
560 dev_err(&dev
->dev
, "can't evaluate _PRS: %d", status
);
566 static int pnpacpi_supported_resource(struct acpi_resource
*res
)
569 case ACPI_RESOURCE_TYPE_IRQ
:
570 case ACPI_RESOURCE_TYPE_DMA
:
571 case ACPI_RESOURCE_TYPE_IO
:
572 case ACPI_RESOURCE_TYPE_FIXED_IO
:
573 case ACPI_RESOURCE_TYPE_MEMORY24
:
574 case ACPI_RESOURCE_TYPE_MEMORY32
:
575 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
576 case ACPI_RESOURCE_TYPE_ADDRESS16
:
577 case ACPI_RESOURCE_TYPE_ADDRESS32
:
578 case ACPI_RESOURCE_TYPE_ADDRESS64
:
579 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
580 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
589 static acpi_status
pnpacpi_count_resources(struct acpi_resource
*res
,
594 if (pnpacpi_supported_resource(res
))
599 static acpi_status
pnpacpi_type_resources(struct acpi_resource
*res
, void *data
)
601 struct acpi_resource
**resource
= data
;
603 if (pnpacpi_supported_resource(res
)) {
604 (*resource
)->type
= res
->type
;
605 (*resource
)->length
= sizeof(struct acpi_resource
);
606 if (res
->type
== ACPI_RESOURCE_TYPE_IRQ
)
607 (*resource
)->data
.irq
.descriptor_length
=
608 res
->data
.irq
.descriptor_length
;
615 int pnpacpi_build_resource_template(struct pnp_dev
*dev
,
616 struct acpi_buffer
*buffer
)
618 struct acpi_device
*acpi_dev
= dev
->data
;
619 acpi_handle handle
= acpi_dev
->handle
;
620 struct acpi_resource
*resource
;
624 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
625 pnpacpi_count_resources
, &res_cnt
);
626 if (ACPI_FAILURE(status
)) {
627 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
632 buffer
->length
= sizeof(struct acpi_resource
) * (res_cnt
+ 1) + 1;
633 buffer
->pointer
= kzalloc(buffer
->length
- 1, GFP_KERNEL
);
634 if (!buffer
->pointer
)
637 resource
= (struct acpi_resource
*)buffer
->pointer
;
638 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
639 pnpacpi_type_resources
, &resource
);
640 if (ACPI_FAILURE(status
)) {
641 kfree(buffer
->pointer
);
642 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
645 /* resource will pointer the end resource now */
646 resource
->type
= ACPI_RESOURCE_TYPE_END_TAG
;
647 resource
->length
= sizeof(struct acpi_resource
);
652 static void pnpacpi_encode_irq(struct pnp_dev
*dev
,
653 struct acpi_resource
*resource
,
656 struct acpi_resource_irq
*irq
= &resource
->data
.irq
;
657 u8 triggering
, polarity
, shareable
;
659 if (!pnp_resource_enabled(p
)) {
660 irq
->interrupt_count
= 0;
661 pnp_dbg(&dev
->dev
, " encode irq (%s)\n",
662 p
? "disabled" : "missing");
666 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
667 irq
->triggering
= triggering
;
668 irq
->polarity
= polarity
;
669 irq
->sharable
= shareable
;
670 irq
->interrupt_count
= 1;
671 irq
->interrupts
[0] = p
->start
;
673 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s (%d-byte descriptor)\n",
675 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
676 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
677 irq
->sharable
== ACPI_SHARED
? "shared" : "exclusive",
678 irq
->descriptor_length
);
681 static void pnpacpi_encode_ext_irq(struct pnp_dev
*dev
,
682 struct acpi_resource
*resource
,
685 struct acpi_resource_extended_irq
*extended_irq
= &resource
->data
.extended_irq
;
686 u8 triggering
, polarity
, shareable
;
688 if (!pnp_resource_enabled(p
)) {
689 extended_irq
->interrupt_count
= 0;
690 pnp_dbg(&dev
->dev
, " encode extended irq (%s)\n",
691 p
? "disabled" : "missing");
695 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
696 extended_irq
->producer_consumer
= ACPI_CONSUMER
;
697 extended_irq
->triggering
= triggering
;
698 extended_irq
->polarity
= polarity
;
699 extended_irq
->sharable
= shareable
;
700 extended_irq
->interrupt_count
= 1;
701 extended_irq
->interrupts
[0] = p
->start
;
703 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s\n", (int) p
->start
,
704 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
705 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
706 extended_irq
->sharable
== ACPI_SHARED
? "shared" : "exclusive");
709 static void pnpacpi_encode_dma(struct pnp_dev
*dev
,
710 struct acpi_resource
*resource
,
713 struct acpi_resource_dma
*dma
= &resource
->data
.dma
;
715 if (!pnp_resource_enabled(p
)) {
716 dma
->channel_count
= 0;
717 pnp_dbg(&dev
->dev
, " encode dma (%s)\n",
718 p
? "disabled" : "missing");
722 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
723 switch (p
->flags
& IORESOURCE_DMA_SPEED_MASK
) {
724 case IORESOURCE_DMA_TYPEA
:
725 dma
->type
= ACPI_TYPE_A
;
727 case IORESOURCE_DMA_TYPEB
:
728 dma
->type
= ACPI_TYPE_B
;
730 case IORESOURCE_DMA_TYPEF
:
731 dma
->type
= ACPI_TYPE_F
;
734 dma
->type
= ACPI_COMPATIBILITY
;
737 switch (p
->flags
& IORESOURCE_DMA_TYPE_MASK
) {
738 case IORESOURCE_DMA_8BIT
:
739 dma
->transfer
= ACPI_TRANSFER_8
;
741 case IORESOURCE_DMA_8AND16BIT
:
742 dma
->transfer
= ACPI_TRANSFER_8_16
;
745 dma
->transfer
= ACPI_TRANSFER_16
;
748 dma
->bus_master
= !!(p
->flags
& IORESOURCE_DMA_MASTER
);
749 dma
->channel_count
= 1;
750 dma
->channels
[0] = p
->start
;
752 pnp_dbg(&dev
->dev
, " encode dma %d "
753 "type %#x transfer %#x master %d\n",
754 (int) p
->start
, dma
->type
, dma
->transfer
, dma
->bus_master
);
757 static void pnpacpi_encode_io(struct pnp_dev
*dev
,
758 struct acpi_resource
*resource
,
761 struct acpi_resource_io
*io
= &resource
->data
.io
;
763 if (pnp_resource_enabled(p
)) {
764 /* Note: pnp_assign_port copies pnp_port->flags into p->flags */
765 io
->io_decode
= (p
->flags
& IORESOURCE_IO_16BIT_ADDR
) ?
766 ACPI_DECODE_16
: ACPI_DECODE_10
;
767 io
->minimum
= p
->start
;
768 io
->maximum
= p
->end
;
769 io
->alignment
= 0; /* Correct? */
770 io
->address_length
= resource_size(p
);
773 io
->address_length
= 0;
776 pnp_dbg(&dev
->dev
, " encode io %#x-%#x decode %#x\n", io
->minimum
,
777 io
->minimum
+ io
->address_length
- 1, io
->io_decode
);
780 static void pnpacpi_encode_fixed_io(struct pnp_dev
*dev
,
781 struct acpi_resource
*resource
,
784 struct acpi_resource_fixed_io
*fixed_io
= &resource
->data
.fixed_io
;
786 if (pnp_resource_enabled(p
)) {
787 fixed_io
->address
= p
->start
;
788 fixed_io
->address_length
= resource_size(p
);
790 fixed_io
->address
= 0;
791 fixed_io
->address_length
= 0;
794 pnp_dbg(&dev
->dev
, " encode fixed_io %#x-%#x\n", fixed_io
->address
,
795 fixed_io
->address
+ fixed_io
->address_length
- 1);
798 static void pnpacpi_encode_mem24(struct pnp_dev
*dev
,
799 struct acpi_resource
*resource
,
802 struct acpi_resource_memory24
*memory24
= &resource
->data
.memory24
;
804 if (pnp_resource_enabled(p
)) {
805 /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */
806 memory24
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
807 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
808 memory24
->minimum
= p
->start
;
809 memory24
->maximum
= p
->end
;
810 memory24
->alignment
= 0;
811 memory24
->address_length
= resource_size(p
);
813 memory24
->minimum
= 0;
814 memory24
->address_length
= 0;
817 pnp_dbg(&dev
->dev
, " encode mem24 %#x-%#x write_protect %#x\n",
819 memory24
->minimum
+ memory24
->address_length
- 1,
820 memory24
->write_protect
);
823 static void pnpacpi_encode_mem32(struct pnp_dev
*dev
,
824 struct acpi_resource
*resource
,
827 struct acpi_resource_memory32
*memory32
= &resource
->data
.memory32
;
829 if (pnp_resource_enabled(p
)) {
830 memory32
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
831 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
832 memory32
->minimum
= p
->start
;
833 memory32
->maximum
= p
->end
;
834 memory32
->alignment
= 0;
835 memory32
->address_length
= resource_size(p
);
837 memory32
->minimum
= 0;
838 memory32
->alignment
= 0;
841 pnp_dbg(&dev
->dev
, " encode mem32 %#x-%#x write_protect %#x\n",
843 memory32
->minimum
+ memory32
->address_length
- 1,
844 memory32
->write_protect
);
847 static void pnpacpi_encode_fixed_mem32(struct pnp_dev
*dev
,
848 struct acpi_resource
*resource
,
851 struct acpi_resource_fixed_memory32
*fixed_memory32
= &resource
->data
.fixed_memory32
;
853 if (pnp_resource_enabled(p
)) {
854 fixed_memory32
->write_protect
=
855 p
->flags
& IORESOURCE_MEM_WRITEABLE
?
856 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
857 fixed_memory32
->address
= p
->start
;
858 fixed_memory32
->address_length
= resource_size(p
);
860 fixed_memory32
->address
= 0;
861 fixed_memory32
->address_length
= 0;
864 pnp_dbg(&dev
->dev
, " encode fixed_mem32 %#x-%#x write_protect %#x\n",
865 fixed_memory32
->address
,
866 fixed_memory32
->address
+ fixed_memory32
->address_length
- 1,
867 fixed_memory32
->write_protect
);
870 int pnpacpi_encode_resources(struct pnp_dev
*dev
, struct acpi_buffer
*buffer
)
873 /* pnpacpi_build_resource_template allocates extra mem */
874 int res_cnt
= (buffer
->length
- 1) / sizeof(struct acpi_resource
) - 1;
875 struct acpi_resource
*resource
= buffer
->pointer
;
876 unsigned int port
= 0, irq
= 0, dma
= 0, mem
= 0;
878 pnp_dbg(&dev
->dev
, "encode %d resources\n", res_cnt
);
879 while (i
< res_cnt
) {
880 switch (resource
->type
) {
881 case ACPI_RESOURCE_TYPE_IRQ
:
882 pnpacpi_encode_irq(dev
, resource
,
883 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
887 case ACPI_RESOURCE_TYPE_DMA
:
888 pnpacpi_encode_dma(dev
, resource
,
889 pnp_get_resource(dev
, IORESOURCE_DMA
, dma
));
892 case ACPI_RESOURCE_TYPE_IO
:
893 pnpacpi_encode_io(dev
, resource
,
894 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
897 case ACPI_RESOURCE_TYPE_FIXED_IO
:
898 pnpacpi_encode_fixed_io(dev
, resource
,
899 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
902 case ACPI_RESOURCE_TYPE_MEMORY24
:
903 pnpacpi_encode_mem24(dev
, resource
,
904 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
907 case ACPI_RESOURCE_TYPE_MEMORY32
:
908 pnpacpi_encode_mem32(dev
, resource
,
909 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
912 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
913 pnpacpi_encode_fixed_mem32(dev
, resource
,
914 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
917 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
918 pnpacpi_encode_ext_irq(dev
, resource
,
919 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
922 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
923 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
924 case ACPI_RESOURCE_TYPE_VENDOR
:
925 case ACPI_RESOURCE_TYPE_END_TAG
:
926 case ACPI_RESOURCE_TYPE_ADDRESS16
:
927 case ACPI_RESOURCE_TYPE_ADDRESS32
:
928 case ACPI_RESOURCE_TYPE_ADDRESS64
:
929 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
930 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
931 default: /* other type */
932 dev_warn(&dev
->dev
, "can't encode unknown resource "
933 "type %d\n", resource
->type
);