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
, int *triggering
,
32 int *polarity
, int *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
;
186 if (acpi_dev_resource_memory(res
, &r
)
187 || acpi_dev_resource_io(res
, &r
)
188 || acpi_dev_resource_address_space(res
, &r
)
189 || acpi_dev_resource_ext_address_space(res
, &r
)) {
190 pnp_add_resource(dev
, &r
);
195 if (acpi_dev_resource_interrupt(res
, 0, &r
)) {
196 pnpacpi_add_irqresource(dev
, &r
);
197 for (i
= 1; acpi_dev_resource_interrupt(res
, i
, &r
); i
++)
198 pnpacpi_add_irqresource(dev
, &r
);
202 * The IRQ encoder puts a single interrupt in each
203 * descriptor, so if a _CRS descriptor has more than
204 * one interrupt, we won't be able to re-encode it.
206 if (pnp_can_write(dev
)) {
207 dev_warn(&dev
->dev
, "multiple interrupts in "
208 "_CRS descriptor; configuration can't "
210 dev
->capabilities
&= ~PNP_WRITE
;
214 } else if (r
.flags
& IORESOURCE_DISABLED
) {
215 pnp_add_irq_resource(dev
, 0, IORESOURCE_DISABLED
);
220 case ACPI_RESOURCE_TYPE_DMA
:
221 dma
= &res
->data
.dma
;
222 if (dma
->channel_count
> 0 && dma
->channels
[0] != (u8
) -1)
223 flags
= dma_flags(dev
, dma
->type
, dma
->bus_master
,
226 flags
= IORESOURCE_DISABLED
;
227 pnp_add_dma_resource(dev
, dma
->channels
[0], flags
);
230 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
231 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
234 case ACPI_RESOURCE_TYPE_VENDOR
:
235 vendor_typed
= &res
->data
.vendor_typed
;
236 pnpacpi_parse_allocated_vendor(dev
, vendor_typed
);
239 case ACPI_RESOURCE_TYPE_END_TAG
:
242 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
246 dev_warn(&dev
->dev
, "unknown resource type %d in _CRS\n",
254 int pnpacpi_parse_allocated_resource(struct pnp_dev
*dev
)
256 struct acpi_device
*acpi_dev
= dev
->data
;
257 acpi_handle handle
= acpi_dev
->handle
;
260 pnp_dbg(&dev
->dev
, "parse allocated resources\n");
262 pnp_init_resources(dev
);
264 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
265 pnpacpi_allocated_resource
, dev
);
267 if (ACPI_FAILURE(status
)) {
268 if (status
!= AE_NOT_FOUND
)
269 dev_err(&dev
->dev
, "can't evaluate _CRS: %d", status
);
275 static __init
void pnpacpi_parse_dma_option(struct pnp_dev
*dev
,
276 unsigned int option_flags
,
277 struct acpi_resource_dma
*p
)
280 unsigned char map
= 0, flags
;
282 for (i
= 0; i
< p
->channel_count
; i
++)
283 map
|= 1 << p
->channels
[i
];
285 flags
= dma_flags(dev
, p
->type
, p
->bus_master
, p
->transfer
);
286 pnp_register_dma_resource(dev
, option_flags
, map
, flags
);
289 static __init
void pnpacpi_parse_irq_option(struct pnp_dev
*dev
,
290 unsigned int option_flags
,
291 struct acpi_resource_irq
*p
)
297 bitmap_zero(map
.bits
, PNP_IRQ_NR
);
298 for (i
= 0; i
< p
->interrupt_count
; i
++)
299 if (p
->interrupts
[i
])
300 __set_bit(p
->interrupts
[i
], map
.bits
);
302 flags
= acpi_dev_irq_flags(p
->triggering
, p
->polarity
, p
->sharable
);
303 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
306 static __init
void pnpacpi_parse_ext_irq_option(struct pnp_dev
*dev
,
307 unsigned int option_flags
,
308 struct acpi_resource_extended_irq
*p
)
314 bitmap_zero(map
.bits
, PNP_IRQ_NR
);
315 for (i
= 0; i
< p
->interrupt_count
; i
++) {
316 if (p
->interrupts
[i
]) {
317 if (p
->interrupts
[i
] < PNP_IRQ_NR
)
318 __set_bit(p
->interrupts
[i
], map
.bits
);
320 dev_err(&dev
->dev
, "ignoring IRQ %d option "
321 "(too large for %d entry bitmap)\n",
322 p
->interrupts
[i
], PNP_IRQ_NR
);
326 flags
= acpi_dev_irq_flags(p
->triggering
, p
->polarity
, p
->sharable
);
327 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
330 static __init
void pnpacpi_parse_port_option(struct pnp_dev
*dev
,
331 unsigned int option_flags
,
332 struct acpi_resource_io
*io
)
334 unsigned char flags
= 0;
336 if (io
->io_decode
== ACPI_DECODE_16
)
337 flags
= IORESOURCE_IO_16BIT_ADDR
;
338 pnp_register_port_resource(dev
, option_flags
, io
->minimum
, io
->maximum
,
339 io
->alignment
, io
->address_length
, flags
);
342 static __init
void pnpacpi_parse_fixed_port_option(struct pnp_dev
*dev
,
343 unsigned int option_flags
,
344 struct acpi_resource_fixed_io
*io
)
346 pnp_register_port_resource(dev
, option_flags
, io
->address
, io
->address
,
347 0, io
->address_length
, IORESOURCE_IO_FIXED
);
350 static __init
void pnpacpi_parse_mem24_option(struct pnp_dev
*dev
,
351 unsigned int option_flags
,
352 struct acpi_resource_memory24
*p
)
354 unsigned char flags
= 0;
356 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
357 flags
= IORESOURCE_MEM_WRITEABLE
;
358 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
359 p
->alignment
, p
->address_length
, flags
);
362 static __init
void pnpacpi_parse_mem32_option(struct pnp_dev
*dev
,
363 unsigned int option_flags
,
364 struct acpi_resource_memory32
*p
)
366 unsigned char flags
= 0;
368 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
369 flags
= IORESOURCE_MEM_WRITEABLE
;
370 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
371 p
->alignment
, p
->address_length
, flags
);
374 static __init
void pnpacpi_parse_fixed_mem32_option(struct pnp_dev
*dev
,
375 unsigned int option_flags
,
376 struct acpi_resource_fixed_memory32
*p
)
378 unsigned char flags
= 0;
380 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
381 flags
= IORESOURCE_MEM_WRITEABLE
;
382 pnp_register_mem_resource(dev
, option_flags
, p
->address
, p
->address
,
383 0, p
->address_length
, flags
);
386 static __init
void pnpacpi_parse_address_option(struct pnp_dev
*dev
,
387 unsigned int option_flags
,
388 struct acpi_resource
*r
)
390 struct acpi_resource_address64 addr
, *p
= &addr
;
392 unsigned char flags
= 0;
394 status
= acpi_resource_to_address64(r
, p
);
395 if (ACPI_FAILURE(status
)) {
396 dev_warn(&dev
->dev
, "can't convert resource type %d\n",
401 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
402 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
403 flags
= IORESOURCE_MEM_WRITEABLE
;
404 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
,
405 p
->minimum
, 0, p
->address_length
,
407 } else if (p
->resource_type
== ACPI_IO_RANGE
)
408 pnp_register_port_resource(dev
, option_flags
, p
->minimum
,
409 p
->minimum
, 0, p
->address_length
,
410 IORESOURCE_IO_FIXED
);
413 static __init
void pnpacpi_parse_ext_address_option(struct pnp_dev
*dev
,
414 unsigned int option_flags
,
415 struct acpi_resource
*r
)
417 struct acpi_resource_extended_address64
*p
= &r
->data
.ext_address64
;
418 unsigned char flags
= 0;
420 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
421 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
422 flags
= IORESOURCE_MEM_WRITEABLE
;
423 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
,
424 p
->minimum
, 0, p
->address_length
,
426 } else if (p
->resource_type
== ACPI_IO_RANGE
)
427 pnp_register_port_resource(dev
, option_flags
, p
->minimum
,
428 p
->minimum
, 0, p
->address_length
,
429 IORESOURCE_IO_FIXED
);
432 struct acpipnp_parse_option_s
{
434 unsigned int option_flags
;
437 static __init acpi_status
pnpacpi_option_resource(struct acpi_resource
*res
,
441 struct acpipnp_parse_option_s
*parse_data
= data
;
442 struct pnp_dev
*dev
= parse_data
->dev
;
443 unsigned int option_flags
= parse_data
->option_flags
;
446 case ACPI_RESOURCE_TYPE_IRQ
:
447 pnpacpi_parse_irq_option(dev
, option_flags
, &res
->data
.irq
);
450 case ACPI_RESOURCE_TYPE_DMA
:
451 pnpacpi_parse_dma_option(dev
, option_flags
, &res
->data
.dma
);
454 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
455 switch (res
->data
.start_dpf
.compatibility_priority
) {
456 case ACPI_GOOD_CONFIGURATION
:
457 priority
= PNP_RES_PRIORITY_PREFERRED
;
460 case ACPI_ACCEPTABLE_CONFIGURATION
:
461 priority
= PNP_RES_PRIORITY_ACCEPTABLE
;
464 case ACPI_SUB_OPTIMAL_CONFIGURATION
:
465 priority
= PNP_RES_PRIORITY_FUNCTIONAL
;
468 priority
= PNP_RES_PRIORITY_INVALID
;
471 parse_data
->option_flags
= pnp_new_dependent_set(dev
, priority
);
474 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
475 parse_data
->option_flags
= 0;
478 case ACPI_RESOURCE_TYPE_IO
:
479 pnpacpi_parse_port_option(dev
, option_flags
, &res
->data
.io
);
482 case ACPI_RESOURCE_TYPE_FIXED_IO
:
483 pnpacpi_parse_fixed_port_option(dev
, option_flags
,
484 &res
->data
.fixed_io
);
487 case ACPI_RESOURCE_TYPE_VENDOR
:
488 case ACPI_RESOURCE_TYPE_END_TAG
:
491 case ACPI_RESOURCE_TYPE_MEMORY24
:
492 pnpacpi_parse_mem24_option(dev
, option_flags
,
493 &res
->data
.memory24
);
496 case ACPI_RESOURCE_TYPE_MEMORY32
:
497 pnpacpi_parse_mem32_option(dev
, option_flags
,
498 &res
->data
.memory32
);
501 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
502 pnpacpi_parse_fixed_mem32_option(dev
, option_flags
,
503 &res
->data
.fixed_memory32
);
506 case ACPI_RESOURCE_TYPE_ADDRESS16
:
507 case ACPI_RESOURCE_TYPE_ADDRESS32
:
508 case ACPI_RESOURCE_TYPE_ADDRESS64
:
509 pnpacpi_parse_address_option(dev
, option_flags
, res
);
512 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
513 pnpacpi_parse_ext_address_option(dev
, option_flags
, res
);
516 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
517 pnpacpi_parse_ext_irq_option(dev
, option_flags
,
518 &res
->data
.extended_irq
);
521 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
525 dev_warn(&dev
->dev
, "unknown resource type %d in _PRS\n",
533 int __init
pnpacpi_parse_resource_option_data(struct pnp_dev
*dev
)
535 struct acpi_device
*acpi_dev
= dev
->data
;
536 acpi_handle handle
= acpi_dev
->handle
;
538 struct acpipnp_parse_option_s parse_data
;
540 pnp_dbg(&dev
->dev
, "parse resource options\n");
542 parse_data
.dev
= dev
;
543 parse_data
.option_flags
= 0;
545 status
= acpi_walk_resources(handle
, METHOD_NAME__PRS
,
546 pnpacpi_option_resource
, &parse_data
);
548 if (ACPI_FAILURE(status
)) {
549 if (status
!= AE_NOT_FOUND
)
550 dev_err(&dev
->dev
, "can't evaluate _PRS: %d", status
);
556 static int pnpacpi_supported_resource(struct acpi_resource
*res
)
559 case ACPI_RESOURCE_TYPE_IRQ
:
560 case ACPI_RESOURCE_TYPE_DMA
:
561 case ACPI_RESOURCE_TYPE_IO
:
562 case ACPI_RESOURCE_TYPE_FIXED_IO
:
563 case ACPI_RESOURCE_TYPE_MEMORY24
:
564 case ACPI_RESOURCE_TYPE_MEMORY32
:
565 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
566 case ACPI_RESOURCE_TYPE_ADDRESS16
:
567 case ACPI_RESOURCE_TYPE_ADDRESS32
:
568 case ACPI_RESOURCE_TYPE_ADDRESS64
:
569 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
570 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
579 static acpi_status
pnpacpi_count_resources(struct acpi_resource
*res
,
584 if (pnpacpi_supported_resource(res
))
589 static acpi_status
pnpacpi_type_resources(struct acpi_resource
*res
, void *data
)
591 struct acpi_resource
**resource
= data
;
593 if (pnpacpi_supported_resource(res
)) {
594 (*resource
)->type
= res
->type
;
595 (*resource
)->length
= sizeof(struct acpi_resource
);
596 if (res
->type
== ACPI_RESOURCE_TYPE_IRQ
)
597 (*resource
)->data
.irq
.descriptor_length
=
598 res
->data
.irq
.descriptor_length
;
605 int pnpacpi_build_resource_template(struct pnp_dev
*dev
,
606 struct acpi_buffer
*buffer
)
608 struct acpi_device
*acpi_dev
= dev
->data
;
609 acpi_handle handle
= acpi_dev
->handle
;
610 struct acpi_resource
*resource
;
614 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
615 pnpacpi_count_resources
, &res_cnt
);
616 if (ACPI_FAILURE(status
)) {
617 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
622 buffer
->length
= sizeof(struct acpi_resource
) * (res_cnt
+ 1) + 1;
623 buffer
->pointer
= kzalloc(buffer
->length
- 1, GFP_KERNEL
);
624 if (!buffer
->pointer
)
627 resource
= (struct acpi_resource
*)buffer
->pointer
;
628 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
629 pnpacpi_type_resources
, &resource
);
630 if (ACPI_FAILURE(status
)) {
631 kfree(buffer
->pointer
);
632 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
635 /* resource will pointer the end resource now */
636 resource
->type
= ACPI_RESOURCE_TYPE_END_TAG
;
641 static void pnpacpi_encode_irq(struct pnp_dev
*dev
,
642 struct acpi_resource
*resource
,
645 struct acpi_resource_irq
*irq
= &resource
->data
.irq
;
646 int triggering
, polarity
, shareable
;
648 if (!pnp_resource_enabled(p
)) {
649 irq
->interrupt_count
= 0;
650 pnp_dbg(&dev
->dev
, " encode irq (%s)\n",
651 p
? "disabled" : "missing");
655 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
656 irq
->triggering
= triggering
;
657 irq
->polarity
= polarity
;
658 irq
->sharable
= shareable
;
659 irq
->interrupt_count
= 1;
660 irq
->interrupts
[0] = p
->start
;
662 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s (%d-byte descriptor)\n",
664 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
665 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
666 irq
->sharable
== ACPI_SHARED
? "shared" : "exclusive",
667 irq
->descriptor_length
);
670 static void pnpacpi_encode_ext_irq(struct pnp_dev
*dev
,
671 struct acpi_resource
*resource
,
674 struct acpi_resource_extended_irq
*extended_irq
= &resource
->data
.extended_irq
;
675 int triggering
, polarity
, shareable
;
677 if (!pnp_resource_enabled(p
)) {
678 extended_irq
->interrupt_count
= 0;
679 pnp_dbg(&dev
->dev
, " encode extended irq (%s)\n",
680 p
? "disabled" : "missing");
684 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
685 extended_irq
->producer_consumer
= ACPI_CONSUMER
;
686 extended_irq
->triggering
= triggering
;
687 extended_irq
->polarity
= polarity
;
688 extended_irq
->sharable
= shareable
;
689 extended_irq
->interrupt_count
= 1;
690 extended_irq
->interrupts
[0] = p
->start
;
692 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s\n", (int) p
->start
,
693 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
694 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
695 extended_irq
->sharable
== ACPI_SHARED
? "shared" : "exclusive");
698 static void pnpacpi_encode_dma(struct pnp_dev
*dev
,
699 struct acpi_resource
*resource
,
702 struct acpi_resource_dma
*dma
= &resource
->data
.dma
;
704 if (!pnp_resource_enabled(p
)) {
705 dma
->channel_count
= 0;
706 pnp_dbg(&dev
->dev
, " encode dma (%s)\n",
707 p
? "disabled" : "missing");
711 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
712 switch (p
->flags
& IORESOURCE_DMA_SPEED_MASK
) {
713 case IORESOURCE_DMA_TYPEA
:
714 dma
->type
= ACPI_TYPE_A
;
716 case IORESOURCE_DMA_TYPEB
:
717 dma
->type
= ACPI_TYPE_B
;
719 case IORESOURCE_DMA_TYPEF
:
720 dma
->type
= ACPI_TYPE_F
;
723 dma
->type
= ACPI_COMPATIBILITY
;
726 switch (p
->flags
& IORESOURCE_DMA_TYPE_MASK
) {
727 case IORESOURCE_DMA_8BIT
:
728 dma
->transfer
= ACPI_TRANSFER_8
;
730 case IORESOURCE_DMA_8AND16BIT
:
731 dma
->transfer
= ACPI_TRANSFER_8_16
;
734 dma
->transfer
= ACPI_TRANSFER_16
;
737 dma
->bus_master
= !!(p
->flags
& IORESOURCE_DMA_MASTER
);
738 dma
->channel_count
= 1;
739 dma
->channels
[0] = p
->start
;
741 pnp_dbg(&dev
->dev
, " encode dma %d "
742 "type %#x transfer %#x master %d\n",
743 (int) p
->start
, dma
->type
, dma
->transfer
, dma
->bus_master
);
746 static void pnpacpi_encode_io(struct pnp_dev
*dev
,
747 struct acpi_resource
*resource
,
750 struct acpi_resource_io
*io
= &resource
->data
.io
;
752 if (pnp_resource_enabled(p
)) {
753 /* Note: pnp_assign_port copies pnp_port->flags into p->flags */
754 io
->io_decode
= (p
->flags
& IORESOURCE_IO_16BIT_ADDR
) ?
755 ACPI_DECODE_16
: ACPI_DECODE_10
;
756 io
->minimum
= p
->start
;
757 io
->maximum
= p
->end
;
758 io
->alignment
= 0; /* Correct? */
759 io
->address_length
= resource_size(p
);
762 io
->address_length
= 0;
765 pnp_dbg(&dev
->dev
, " encode io %#x-%#x decode %#x\n", io
->minimum
,
766 io
->minimum
+ io
->address_length
- 1, io
->io_decode
);
769 static void pnpacpi_encode_fixed_io(struct pnp_dev
*dev
,
770 struct acpi_resource
*resource
,
773 struct acpi_resource_fixed_io
*fixed_io
= &resource
->data
.fixed_io
;
775 if (pnp_resource_enabled(p
)) {
776 fixed_io
->address
= p
->start
;
777 fixed_io
->address_length
= resource_size(p
);
779 fixed_io
->address
= 0;
780 fixed_io
->address_length
= 0;
783 pnp_dbg(&dev
->dev
, " encode fixed_io %#x-%#x\n", fixed_io
->address
,
784 fixed_io
->address
+ fixed_io
->address_length
- 1);
787 static void pnpacpi_encode_mem24(struct pnp_dev
*dev
,
788 struct acpi_resource
*resource
,
791 struct acpi_resource_memory24
*memory24
= &resource
->data
.memory24
;
793 if (pnp_resource_enabled(p
)) {
794 /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */
795 memory24
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
796 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
797 memory24
->minimum
= p
->start
;
798 memory24
->maximum
= p
->end
;
799 memory24
->alignment
= 0;
800 memory24
->address_length
= resource_size(p
);
802 memory24
->minimum
= 0;
803 memory24
->address_length
= 0;
806 pnp_dbg(&dev
->dev
, " encode mem24 %#x-%#x write_protect %#x\n",
808 memory24
->minimum
+ memory24
->address_length
- 1,
809 memory24
->write_protect
);
812 static void pnpacpi_encode_mem32(struct pnp_dev
*dev
,
813 struct acpi_resource
*resource
,
816 struct acpi_resource_memory32
*memory32
= &resource
->data
.memory32
;
818 if (pnp_resource_enabled(p
)) {
819 memory32
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
820 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
821 memory32
->minimum
= p
->start
;
822 memory32
->maximum
= p
->end
;
823 memory32
->alignment
= 0;
824 memory32
->address_length
= resource_size(p
);
826 memory32
->minimum
= 0;
827 memory32
->alignment
= 0;
830 pnp_dbg(&dev
->dev
, " encode mem32 %#x-%#x write_protect %#x\n",
832 memory32
->minimum
+ memory32
->address_length
- 1,
833 memory32
->write_protect
);
836 static void pnpacpi_encode_fixed_mem32(struct pnp_dev
*dev
,
837 struct acpi_resource
*resource
,
840 struct acpi_resource_fixed_memory32
*fixed_memory32
= &resource
->data
.fixed_memory32
;
842 if (pnp_resource_enabled(p
)) {
843 fixed_memory32
->write_protect
=
844 p
->flags
& IORESOURCE_MEM_WRITEABLE
?
845 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
846 fixed_memory32
->address
= p
->start
;
847 fixed_memory32
->address_length
= resource_size(p
);
849 fixed_memory32
->address
= 0;
850 fixed_memory32
->address_length
= 0;
853 pnp_dbg(&dev
->dev
, " encode fixed_mem32 %#x-%#x write_protect %#x\n",
854 fixed_memory32
->address
,
855 fixed_memory32
->address
+ fixed_memory32
->address_length
- 1,
856 fixed_memory32
->write_protect
);
859 int pnpacpi_encode_resources(struct pnp_dev
*dev
, struct acpi_buffer
*buffer
)
862 /* pnpacpi_build_resource_template allocates extra mem */
863 int res_cnt
= (buffer
->length
- 1) / sizeof(struct acpi_resource
) - 1;
864 struct acpi_resource
*resource
= buffer
->pointer
;
865 int port
= 0, irq
= 0, dma
= 0, mem
= 0;
867 pnp_dbg(&dev
->dev
, "encode %d resources\n", res_cnt
);
868 while (i
< res_cnt
) {
869 switch (resource
->type
) {
870 case ACPI_RESOURCE_TYPE_IRQ
:
871 pnpacpi_encode_irq(dev
, resource
,
872 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
876 case ACPI_RESOURCE_TYPE_DMA
:
877 pnpacpi_encode_dma(dev
, resource
,
878 pnp_get_resource(dev
, IORESOURCE_DMA
, dma
));
881 case ACPI_RESOURCE_TYPE_IO
:
882 pnpacpi_encode_io(dev
, resource
,
883 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
886 case ACPI_RESOURCE_TYPE_FIXED_IO
:
887 pnpacpi_encode_fixed_io(dev
, resource
,
888 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
891 case ACPI_RESOURCE_TYPE_MEMORY24
:
892 pnpacpi_encode_mem24(dev
, resource
,
893 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
896 case ACPI_RESOURCE_TYPE_MEMORY32
:
897 pnpacpi_encode_mem32(dev
, resource
,
898 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
901 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
902 pnpacpi_encode_fixed_mem32(dev
, resource
,
903 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
906 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
907 pnpacpi_encode_ext_irq(dev
, resource
,
908 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
911 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
912 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
913 case ACPI_RESOURCE_TYPE_VENDOR
:
914 case ACPI_RESOURCE_TYPE_END_TAG
:
915 case ACPI_RESOURCE_TYPE_ADDRESS16
:
916 case ACPI_RESOURCE_TYPE_ADDRESS32
:
917 case ACPI_RESOURCE_TYPE_ADDRESS64
:
918 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
919 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
920 default: /* other type */
921 dev_warn(&dev
->dev
, "can't encode unknown resource "
922 "type %d\n", resource
->type
);