1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * pnpacpi -- PnP ACPI driver
5 * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
6 * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
7 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
8 * Bjorn Helgaas <bjorn.helgaas@hp.com>
10 #include <linux/kernel.h>
11 #include <linux/acpi.h>
12 #include <linux/pci.h>
13 #include <linux/pnp.h>
14 #include <linux/slab.h>
18 static void decode_irq_flags(struct pnp_dev
*dev
, int flags
, u8
*triggering
,
19 u8
*polarity
, u8
*shareable
)
21 switch (flags
& (IORESOURCE_IRQ_LOWLEVEL
| IORESOURCE_IRQ_HIGHLEVEL
|
22 IORESOURCE_IRQ_LOWEDGE
| IORESOURCE_IRQ_HIGHEDGE
)) {
23 case IORESOURCE_IRQ_LOWLEVEL
:
24 *triggering
= ACPI_LEVEL_SENSITIVE
;
25 *polarity
= ACPI_ACTIVE_LOW
;
27 case IORESOURCE_IRQ_HIGHLEVEL
:
28 *triggering
= ACPI_LEVEL_SENSITIVE
;
29 *polarity
= ACPI_ACTIVE_HIGH
;
31 case IORESOURCE_IRQ_LOWEDGE
:
32 *triggering
= ACPI_EDGE_SENSITIVE
;
33 *polarity
= ACPI_ACTIVE_LOW
;
35 case IORESOURCE_IRQ_HIGHEDGE
:
36 *triggering
= ACPI_EDGE_SENSITIVE
;
37 *polarity
= ACPI_ACTIVE_HIGH
;
40 dev_err(&dev
->dev
, "can't encode invalid IRQ mode %#x\n",
42 *triggering
= ACPI_EDGE_SENSITIVE
;
43 *polarity
= ACPI_ACTIVE_HIGH
;
47 if (flags
& IORESOURCE_IRQ_SHAREABLE
)
48 *shareable
= ACPI_SHARED
;
50 *shareable
= ACPI_EXCLUSIVE
;
53 static int dma_flags(struct pnp_dev
*dev
, int type
, int bus_master
,
59 flags
|= IORESOURCE_DMA_MASTER
;
61 case ACPI_COMPATIBILITY
:
62 flags
|= IORESOURCE_DMA_COMPATIBLE
;
65 flags
|= IORESOURCE_DMA_TYPEA
;
68 flags
|= IORESOURCE_DMA_TYPEB
;
71 flags
|= IORESOURCE_DMA_TYPEF
;
74 /* Set a default value ? */
75 flags
|= IORESOURCE_DMA_COMPATIBLE
;
76 dev_err(&dev
->dev
, "invalid DMA type %d\n", type
);
80 flags
|= IORESOURCE_DMA_8BIT
;
82 case ACPI_TRANSFER_8_16
:
83 flags
|= IORESOURCE_DMA_8AND16BIT
;
85 case ACPI_TRANSFER_16
:
86 flags
|= IORESOURCE_DMA_16BIT
;
89 /* Set a default value ? */
90 flags
|= IORESOURCE_DMA_8AND16BIT
;
91 dev_err(&dev
->dev
, "invalid DMA transfer type %d\n", transfer
);
101 static void pnpacpi_add_irqresource(struct pnp_dev
*dev
, struct resource
*r
)
103 if (!(r
->flags
& IORESOURCE_DISABLED
))
104 pcibios_penalize_isa_irq(r
->start
, 1);
106 pnp_add_resource(dev
, r
);
110 * Device CSRs that do not appear in PCI config space should be described
111 * via ACPI. This would normally be done with Address Space Descriptors
112 * marked as "consumer-only," but old versions of Windows and Linux ignore
113 * the producer/consumer flag, so HP invented a vendor-defined resource to
114 * describe the location and size of CSR space.
116 static struct acpi_vendor_uuid hp_ccsr_uuid
= {
118 .data
= { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
119 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
122 static int vendor_resource_matches(struct pnp_dev
*dev
,
123 struct acpi_resource_vendor_typed
*vendor
,
124 struct acpi_vendor_uuid
*match
,
127 int uuid_len
= sizeof(vendor
->uuid
);
128 u8 uuid_subtype
= vendor
->uuid_subtype
;
129 u8
*uuid
= vendor
->uuid
;
132 /* byte_length includes uuid_subtype and uuid */
133 actual_len
= vendor
->byte_length
- uuid_len
- 1;
135 if (uuid_subtype
== match
->subtype
&&
136 uuid_len
== sizeof(match
->data
) &&
137 memcmp(uuid
, match
->data
, uuid_len
) == 0) {
138 if (expected_len
&& expected_len
!= actual_len
) {
140 "wrong vendor descriptor size; expected %d, found %d bytes\n",
141 expected_len
, actual_len
);
151 static void pnpacpi_parse_allocated_vendor(struct pnp_dev
*dev
,
152 struct acpi_resource_vendor_typed
*vendor
)
154 if (vendor_resource_matches(dev
, vendor
, &hp_ccsr_uuid
, 16)) {
157 memcpy(&start
, vendor
->byte_data
, sizeof(start
));
158 memcpy(&length
, vendor
->byte_data
+ 8, sizeof(length
));
160 pnp_add_mem_resource(dev
, start
, start
+ length
- 1, 0);
164 static acpi_status
pnpacpi_allocated_resource(struct acpi_resource
*res
,
167 struct pnp_dev
*dev
= data
;
168 struct acpi_resource_dma
*dma
;
169 struct acpi_resource_vendor_typed
*vendor_typed
;
170 struct acpi_resource_gpio
*gpio
;
171 struct resource_win win
= {{0}, 0};
172 struct resource
*r
= &win
.res
;
175 if (acpi_dev_resource_address_space(res
, &win
)
176 || acpi_dev_resource_ext_address_space(res
, &win
)) {
177 pnp_add_resource(dev
, &win
.res
);
182 if (acpi_dev_resource_interrupt(res
, 0, r
)) {
183 pnpacpi_add_irqresource(dev
, r
);
184 for (i
= 1; acpi_dev_resource_interrupt(res
, i
, r
); i
++)
185 pnpacpi_add_irqresource(dev
, r
);
189 * The IRQ encoder puts a single interrupt in each
190 * descriptor, so if a _CRS descriptor has more than
191 * one interrupt, we won't be able to re-encode it.
193 if (pnp_can_write(dev
)) {
195 "multiple interrupts in _CRS descriptor; configuration can't be changed\n");
196 dev
->capabilities
&= ~PNP_WRITE
;
200 } else if (acpi_gpio_get_irq_resource(res
, &gpio
)) {
202 * If the resource is GpioInt() type then extract the IRQ
203 * from GPIO resource and fill it into IRQ resource type.
205 i
= acpi_dev_gpio_irq_get(dev
->data
, 0);
207 flags
= acpi_dev_irq_flags(gpio
->triggering
,
211 flags
= IORESOURCE_DISABLED
;
213 pnp_add_irq_resource(dev
, i
, flags
);
215 } else if (r
->flags
& IORESOURCE_DISABLED
) {
216 pnp_add_irq_resource(dev
, 0, IORESOURCE_DISABLED
);
221 case ACPI_RESOURCE_TYPE_MEMORY24
:
222 case ACPI_RESOURCE_TYPE_MEMORY32
:
223 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
224 if (acpi_dev_resource_memory(res
, r
))
225 pnp_add_resource(dev
, r
);
227 case ACPI_RESOURCE_TYPE_IO
:
228 case ACPI_RESOURCE_TYPE_FIXED_IO
:
229 if (acpi_dev_resource_io(res
, r
))
230 pnp_add_resource(dev
, r
);
232 case ACPI_RESOURCE_TYPE_DMA
:
233 dma
= &res
->data
.dma
;
234 if (dma
->channel_count
> 0 && dma
->channels
[0] != (u8
) -1)
235 flags
= dma_flags(dev
, dma
->type
, dma
->bus_master
,
238 flags
= IORESOURCE_DISABLED
;
239 pnp_add_dma_resource(dev
, dma
->channels
[0], flags
);
242 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
243 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
246 case ACPI_RESOURCE_TYPE_VENDOR
:
247 vendor_typed
= &res
->data
.vendor_typed
;
248 pnpacpi_parse_allocated_vendor(dev
, vendor_typed
);
251 case ACPI_RESOURCE_TYPE_END_TAG
:
254 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
257 case ACPI_RESOURCE_TYPE_SERIAL_BUS
:
258 /* serial bus connections (I2C/SPI/UART) are not pnp */
262 dev_warn(&dev
->dev
, "unknown resource type %d in _CRS\n",
270 int pnpacpi_parse_allocated_resource(struct pnp_dev
*dev
)
272 struct acpi_device
*acpi_dev
= dev
->data
;
273 acpi_handle handle
= acpi_dev
->handle
;
276 pnp_dbg(&dev
->dev
, "parse allocated resources\n");
278 pnp_init_resources(dev
);
280 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
281 pnpacpi_allocated_resource
, dev
);
283 if (ACPI_FAILURE(status
)) {
284 if (status
!= AE_NOT_FOUND
)
285 dev_err(&dev
->dev
, "can't evaluate _CRS: %d", status
);
291 static __init
void pnpacpi_parse_dma_option(struct pnp_dev
*dev
,
292 unsigned int option_flags
,
293 struct acpi_resource_dma
*p
)
296 unsigned char map
= 0, flags
;
298 for (i
= 0; i
< p
->channel_count
; i
++)
299 map
|= 1 << p
->channels
[i
];
301 flags
= dma_flags(dev
, p
->type
, p
->bus_master
, p
->transfer
);
302 pnp_register_dma_resource(dev
, option_flags
, map
, flags
);
305 static __init
void pnpacpi_parse_irq_option(struct pnp_dev
*dev
,
306 unsigned int option_flags
,
307 struct acpi_resource_irq
*p
)
313 bitmap_zero(map
.bits
, PNP_IRQ_NR
);
314 for (i
= 0; i
< p
->interrupt_count
; i
++)
315 if (p
->interrupts
[i
])
316 __set_bit(p
->interrupts
[i
], map
.bits
);
318 flags
= acpi_dev_irq_flags(p
->triggering
, p
->polarity
, p
->shareable
);
319 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
322 static __init
void pnpacpi_parse_ext_irq_option(struct pnp_dev
*dev
,
323 unsigned int option_flags
,
324 struct acpi_resource_extended_irq
*p
)
330 bitmap_zero(map
.bits
, PNP_IRQ_NR
);
331 for (i
= 0; i
< p
->interrupt_count
; i
++) {
332 if (p
->interrupts
[i
]) {
333 if (p
->interrupts
[i
] < PNP_IRQ_NR
)
334 __set_bit(p
->interrupts
[i
], map
.bits
);
337 "ignoring IRQ %d option (too large for %d entry bitmap)\n",
338 p
->interrupts
[i
], PNP_IRQ_NR
);
342 flags
= acpi_dev_irq_flags(p
->triggering
, p
->polarity
, p
->shareable
);
343 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
346 static __init
void pnpacpi_parse_port_option(struct pnp_dev
*dev
,
347 unsigned int option_flags
,
348 struct acpi_resource_io
*io
)
350 unsigned char flags
= 0;
352 if (io
->io_decode
== ACPI_DECODE_16
)
353 flags
= IORESOURCE_IO_16BIT_ADDR
;
354 pnp_register_port_resource(dev
, option_flags
, io
->minimum
, io
->maximum
,
355 io
->alignment
, io
->address_length
, flags
);
358 static __init
void pnpacpi_parse_fixed_port_option(struct pnp_dev
*dev
,
359 unsigned int option_flags
,
360 struct acpi_resource_fixed_io
*io
)
362 pnp_register_port_resource(dev
, option_flags
, io
->address
, io
->address
,
363 0, io
->address_length
, IORESOURCE_IO_FIXED
);
366 static __init
void pnpacpi_parse_mem24_option(struct pnp_dev
*dev
,
367 unsigned int option_flags
,
368 struct acpi_resource_memory24
*p
)
370 unsigned char flags
= 0;
372 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
373 flags
= IORESOURCE_MEM_WRITEABLE
;
374 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
375 p
->alignment
, p
->address_length
, flags
);
378 static __init
void pnpacpi_parse_mem32_option(struct pnp_dev
*dev
,
379 unsigned int option_flags
,
380 struct acpi_resource_memory32
*p
)
382 unsigned char flags
= 0;
384 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
385 flags
= IORESOURCE_MEM_WRITEABLE
;
386 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
387 p
->alignment
, p
->address_length
, flags
);
390 static __init
void pnpacpi_parse_fixed_mem32_option(struct pnp_dev
*dev
,
391 unsigned int option_flags
,
392 struct acpi_resource_fixed_memory32
*p
)
394 unsigned char flags
= 0;
396 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
397 flags
= IORESOURCE_MEM_WRITEABLE
;
398 pnp_register_mem_resource(dev
, option_flags
, p
->address
, p
->address
,
399 0, p
->address_length
, flags
);
402 static __init
void pnpacpi_parse_address_option(struct pnp_dev
*dev
,
403 unsigned int option_flags
,
404 struct acpi_resource
*r
)
406 struct acpi_resource_address64 addr
, *p
= &addr
;
408 unsigned char flags
= 0;
410 status
= acpi_resource_to_address64(r
, p
);
411 if (ACPI_FAILURE(status
)) {
412 dev_warn(&dev
->dev
, "can't convert resource type %d\n",
417 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
418 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
419 flags
= IORESOURCE_MEM_WRITEABLE
;
420 pnp_register_mem_resource(dev
, option_flags
, p
->address
.minimum
,
421 p
->address
.minimum
, 0, p
->address
.address_length
,
423 } else if (p
->resource_type
== ACPI_IO_RANGE
)
424 pnp_register_port_resource(dev
, option_flags
, p
->address
.minimum
,
425 p
->address
.minimum
, 0, p
->address
.address_length
,
426 IORESOURCE_IO_FIXED
);
429 static __init
void pnpacpi_parse_ext_address_option(struct pnp_dev
*dev
,
430 unsigned int option_flags
,
431 struct acpi_resource
*r
)
433 struct acpi_resource_extended_address64
*p
= &r
->data
.ext_address64
;
434 unsigned char flags
= 0;
436 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
437 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
438 flags
= IORESOURCE_MEM_WRITEABLE
;
439 pnp_register_mem_resource(dev
, option_flags
, p
->address
.minimum
,
440 p
->address
.minimum
, 0, p
->address
.address_length
,
442 } else if (p
->resource_type
== ACPI_IO_RANGE
)
443 pnp_register_port_resource(dev
, option_flags
, p
->address
.minimum
,
444 p
->address
.minimum
, 0, p
->address
.address_length
,
445 IORESOURCE_IO_FIXED
);
448 struct acpipnp_parse_option_s
{
450 unsigned int option_flags
;
453 static __init acpi_status
pnpacpi_option_resource(struct acpi_resource
*res
,
457 struct acpipnp_parse_option_s
*parse_data
= data
;
458 struct pnp_dev
*dev
= parse_data
->dev
;
459 unsigned int option_flags
= parse_data
->option_flags
;
462 case ACPI_RESOURCE_TYPE_IRQ
:
463 pnpacpi_parse_irq_option(dev
, option_flags
, &res
->data
.irq
);
466 case ACPI_RESOURCE_TYPE_DMA
:
467 pnpacpi_parse_dma_option(dev
, option_flags
, &res
->data
.dma
);
470 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
471 switch (res
->data
.start_dpf
.compatibility_priority
) {
472 case ACPI_GOOD_CONFIGURATION
:
473 priority
= PNP_RES_PRIORITY_PREFERRED
;
476 case ACPI_ACCEPTABLE_CONFIGURATION
:
477 priority
= PNP_RES_PRIORITY_ACCEPTABLE
;
480 case ACPI_SUB_OPTIMAL_CONFIGURATION
:
481 priority
= PNP_RES_PRIORITY_FUNCTIONAL
;
484 priority
= PNP_RES_PRIORITY_INVALID
;
487 parse_data
->option_flags
= pnp_new_dependent_set(dev
, priority
);
490 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
491 parse_data
->option_flags
= 0;
494 case ACPI_RESOURCE_TYPE_IO
:
495 pnpacpi_parse_port_option(dev
, option_flags
, &res
->data
.io
);
498 case ACPI_RESOURCE_TYPE_FIXED_IO
:
499 pnpacpi_parse_fixed_port_option(dev
, option_flags
,
500 &res
->data
.fixed_io
);
503 case ACPI_RESOURCE_TYPE_VENDOR
:
504 case ACPI_RESOURCE_TYPE_END_TAG
:
507 case ACPI_RESOURCE_TYPE_MEMORY24
:
508 pnpacpi_parse_mem24_option(dev
, option_flags
,
509 &res
->data
.memory24
);
512 case ACPI_RESOURCE_TYPE_MEMORY32
:
513 pnpacpi_parse_mem32_option(dev
, option_flags
,
514 &res
->data
.memory32
);
517 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
518 pnpacpi_parse_fixed_mem32_option(dev
, option_flags
,
519 &res
->data
.fixed_memory32
);
522 case ACPI_RESOURCE_TYPE_ADDRESS16
:
523 case ACPI_RESOURCE_TYPE_ADDRESS32
:
524 case ACPI_RESOURCE_TYPE_ADDRESS64
:
525 pnpacpi_parse_address_option(dev
, option_flags
, res
);
528 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
529 pnpacpi_parse_ext_address_option(dev
, option_flags
, res
);
532 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
533 pnpacpi_parse_ext_irq_option(dev
, option_flags
,
534 &res
->data
.extended_irq
);
537 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
541 dev_warn(&dev
->dev
, "unknown resource type %d in _PRS\n",
549 int __init
pnpacpi_parse_resource_option_data(struct pnp_dev
*dev
)
551 struct acpi_device
*acpi_dev
= dev
->data
;
552 acpi_handle handle
= acpi_dev
->handle
;
554 struct acpipnp_parse_option_s parse_data
;
556 pnp_dbg(&dev
->dev
, "parse resource options\n");
558 parse_data
.dev
= dev
;
559 parse_data
.option_flags
= 0;
561 status
= acpi_walk_resources(handle
, METHOD_NAME__PRS
,
562 pnpacpi_option_resource
, &parse_data
);
564 if (ACPI_FAILURE(status
)) {
565 if (status
!= AE_NOT_FOUND
)
566 dev_err(&dev
->dev
, "can't evaluate _PRS: %d", status
);
572 static int pnpacpi_supported_resource(struct acpi_resource
*res
)
575 case ACPI_RESOURCE_TYPE_IRQ
:
576 case ACPI_RESOURCE_TYPE_DMA
:
577 case ACPI_RESOURCE_TYPE_IO
:
578 case ACPI_RESOURCE_TYPE_FIXED_IO
:
579 case ACPI_RESOURCE_TYPE_MEMORY24
:
580 case ACPI_RESOURCE_TYPE_MEMORY32
:
581 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
582 case ACPI_RESOURCE_TYPE_ADDRESS16
:
583 case ACPI_RESOURCE_TYPE_ADDRESS32
:
584 case ACPI_RESOURCE_TYPE_ADDRESS64
:
585 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
586 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
595 static acpi_status
pnpacpi_count_resources(struct acpi_resource
*res
,
600 if (pnpacpi_supported_resource(res
))
605 static acpi_status
pnpacpi_type_resources(struct acpi_resource
*res
, void *data
)
607 struct acpi_resource
**resource
= data
;
609 if (pnpacpi_supported_resource(res
)) {
610 (*resource
)->type
= res
->type
;
611 (*resource
)->length
= sizeof(struct acpi_resource
);
612 if (res
->type
== ACPI_RESOURCE_TYPE_IRQ
)
613 (*resource
)->data
.irq
.descriptor_length
=
614 res
->data
.irq
.descriptor_length
;
621 int pnpacpi_build_resource_template(struct pnp_dev
*dev
,
622 struct acpi_buffer
*buffer
)
624 struct acpi_device
*acpi_dev
= dev
->data
;
625 acpi_handle handle
= acpi_dev
->handle
;
626 struct acpi_resource
*resource
;
630 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
631 pnpacpi_count_resources
, &res_cnt
);
632 if (ACPI_FAILURE(status
)) {
633 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
638 buffer
->length
= sizeof(struct acpi_resource
) * (res_cnt
+ 1) + 1;
639 buffer
->pointer
= kzalloc(buffer
->length
- 1, GFP_KERNEL
);
640 if (!buffer
->pointer
)
643 resource
= (struct acpi_resource
*)buffer
->pointer
;
644 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
645 pnpacpi_type_resources
, &resource
);
646 if (ACPI_FAILURE(status
)) {
647 kfree(buffer
->pointer
);
648 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
651 /* resource will pointer the end resource now */
652 resource
->type
= ACPI_RESOURCE_TYPE_END_TAG
;
653 resource
->length
= sizeof(struct acpi_resource
);
658 static void pnpacpi_encode_irq(struct pnp_dev
*dev
,
659 struct acpi_resource
*resource
,
662 struct acpi_resource_irq
*irq
= &resource
->data
.irq
;
663 u8 triggering
, polarity
, shareable
;
665 if (!pnp_resource_enabled(p
)) {
666 irq
->interrupt_count
= 0;
667 pnp_dbg(&dev
->dev
, " encode irq (%s)\n",
668 p
? "disabled" : "missing");
672 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
673 irq
->triggering
= triggering
;
674 irq
->polarity
= polarity
;
675 irq
->shareable
= shareable
;
676 irq
->interrupt_count
= 1;
677 irq
->interrupts
[0] = p
->start
;
679 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s (%d-byte descriptor)\n",
681 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
682 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
683 irq
->shareable
== ACPI_SHARED
? "shared" : "exclusive",
684 irq
->descriptor_length
);
687 static void pnpacpi_encode_ext_irq(struct pnp_dev
*dev
,
688 struct acpi_resource
*resource
,
691 struct acpi_resource_extended_irq
*extended_irq
= &resource
->data
.extended_irq
;
692 u8 triggering
, polarity
, shareable
;
694 if (!pnp_resource_enabled(p
)) {
695 extended_irq
->interrupt_count
= 0;
696 pnp_dbg(&dev
->dev
, " encode extended irq (%s)\n",
697 p
? "disabled" : "missing");
701 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
702 extended_irq
->producer_consumer
= ACPI_CONSUMER
;
703 extended_irq
->triggering
= triggering
;
704 extended_irq
->polarity
= polarity
;
705 extended_irq
->shareable
= shareable
;
706 extended_irq
->interrupt_count
= 1;
707 extended_irq
->interrupts
[0] = p
->start
;
709 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s\n", (int) p
->start
,
710 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
711 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
712 extended_irq
->shareable
== ACPI_SHARED
? "shared" : "exclusive");
715 static void pnpacpi_encode_dma(struct pnp_dev
*dev
,
716 struct acpi_resource
*resource
,
719 struct acpi_resource_dma
*dma
= &resource
->data
.dma
;
721 if (!pnp_resource_enabled(p
)) {
722 dma
->channel_count
= 0;
723 pnp_dbg(&dev
->dev
, " encode dma (%s)\n",
724 p
? "disabled" : "missing");
728 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
729 switch (p
->flags
& IORESOURCE_DMA_SPEED_MASK
) {
730 case IORESOURCE_DMA_TYPEA
:
731 dma
->type
= ACPI_TYPE_A
;
733 case IORESOURCE_DMA_TYPEB
:
734 dma
->type
= ACPI_TYPE_B
;
736 case IORESOURCE_DMA_TYPEF
:
737 dma
->type
= ACPI_TYPE_F
;
740 dma
->type
= ACPI_COMPATIBILITY
;
743 switch (p
->flags
& IORESOURCE_DMA_TYPE_MASK
) {
744 case IORESOURCE_DMA_8BIT
:
745 dma
->transfer
= ACPI_TRANSFER_8
;
747 case IORESOURCE_DMA_8AND16BIT
:
748 dma
->transfer
= ACPI_TRANSFER_8_16
;
751 dma
->transfer
= ACPI_TRANSFER_16
;
754 dma
->bus_master
= !!(p
->flags
& IORESOURCE_DMA_MASTER
);
755 dma
->channel_count
= 1;
756 dma
->channels
[0] = p
->start
;
758 pnp_dbg(&dev
->dev
, " encode dma %d "
759 "type %#x transfer %#x master %d\n",
760 (int) p
->start
, dma
->type
, dma
->transfer
, dma
->bus_master
);
763 static void pnpacpi_encode_io(struct pnp_dev
*dev
,
764 struct acpi_resource
*resource
,
767 struct acpi_resource_io
*io
= &resource
->data
.io
;
769 if (pnp_resource_enabled(p
)) {
770 /* Note: pnp_assign_port copies pnp_port->flags into p->flags */
771 io
->io_decode
= (p
->flags
& IORESOURCE_IO_16BIT_ADDR
) ?
772 ACPI_DECODE_16
: ACPI_DECODE_10
;
773 io
->minimum
= p
->start
;
774 io
->maximum
= p
->end
;
775 io
->alignment
= 0; /* Correct? */
776 io
->address_length
= resource_size(p
);
779 io
->address_length
= 0;
782 pnp_dbg(&dev
->dev
, " encode io %#x-%#x decode %#x\n", io
->minimum
,
783 io
->minimum
+ io
->address_length
- 1, io
->io_decode
);
786 static void pnpacpi_encode_fixed_io(struct pnp_dev
*dev
,
787 struct acpi_resource
*resource
,
790 struct acpi_resource_fixed_io
*fixed_io
= &resource
->data
.fixed_io
;
792 if (pnp_resource_enabled(p
)) {
793 fixed_io
->address
= p
->start
;
794 fixed_io
->address_length
= resource_size(p
);
796 fixed_io
->address
= 0;
797 fixed_io
->address_length
= 0;
800 pnp_dbg(&dev
->dev
, " encode fixed_io %#x-%#x\n", fixed_io
->address
,
801 fixed_io
->address
+ fixed_io
->address_length
- 1);
804 static void pnpacpi_encode_mem24(struct pnp_dev
*dev
,
805 struct acpi_resource
*resource
,
808 struct acpi_resource_memory24
*memory24
= &resource
->data
.memory24
;
810 if (pnp_resource_enabled(p
)) {
811 /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */
812 memory24
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
813 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
814 memory24
->minimum
= p
->start
;
815 memory24
->maximum
= p
->end
;
816 memory24
->alignment
= 0;
817 memory24
->address_length
= resource_size(p
);
819 memory24
->minimum
= 0;
820 memory24
->address_length
= 0;
823 pnp_dbg(&dev
->dev
, " encode mem24 %#x-%#x write_protect %#x\n",
825 memory24
->minimum
+ memory24
->address_length
- 1,
826 memory24
->write_protect
);
829 static void pnpacpi_encode_mem32(struct pnp_dev
*dev
,
830 struct acpi_resource
*resource
,
833 struct acpi_resource_memory32
*memory32
= &resource
->data
.memory32
;
835 if (pnp_resource_enabled(p
)) {
836 memory32
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
837 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
838 memory32
->minimum
= p
->start
;
839 memory32
->maximum
= p
->end
;
840 memory32
->alignment
= 0;
841 memory32
->address_length
= resource_size(p
);
843 memory32
->minimum
= 0;
844 memory32
->alignment
= 0;
847 pnp_dbg(&dev
->dev
, " encode mem32 %#x-%#x write_protect %#x\n",
849 memory32
->minimum
+ memory32
->address_length
- 1,
850 memory32
->write_protect
);
853 static void pnpacpi_encode_fixed_mem32(struct pnp_dev
*dev
,
854 struct acpi_resource
*resource
,
857 struct acpi_resource_fixed_memory32
*fixed_memory32
= &resource
->data
.fixed_memory32
;
859 if (pnp_resource_enabled(p
)) {
860 fixed_memory32
->write_protect
=
861 p
->flags
& IORESOURCE_MEM_WRITEABLE
?
862 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
863 fixed_memory32
->address
= p
->start
;
864 fixed_memory32
->address_length
= resource_size(p
);
866 fixed_memory32
->address
= 0;
867 fixed_memory32
->address_length
= 0;
870 pnp_dbg(&dev
->dev
, " encode fixed_mem32 %#x-%#x write_protect %#x\n",
871 fixed_memory32
->address
,
872 fixed_memory32
->address
+ fixed_memory32
->address_length
- 1,
873 fixed_memory32
->write_protect
);
876 int pnpacpi_encode_resources(struct pnp_dev
*dev
, struct acpi_buffer
*buffer
)
879 /* pnpacpi_build_resource_template allocates extra mem */
880 int res_cnt
= (buffer
->length
- 1) / sizeof(struct acpi_resource
) - 1;
881 struct acpi_resource
*resource
= buffer
->pointer
;
882 unsigned int port
= 0, irq
= 0, dma
= 0, mem
= 0;
884 pnp_dbg(&dev
->dev
, "encode %d resources\n", res_cnt
);
885 while (i
< res_cnt
) {
886 switch (resource
->type
) {
887 case ACPI_RESOURCE_TYPE_IRQ
:
888 pnpacpi_encode_irq(dev
, resource
,
889 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
893 case ACPI_RESOURCE_TYPE_DMA
:
894 pnpacpi_encode_dma(dev
, resource
,
895 pnp_get_resource(dev
, IORESOURCE_DMA
, dma
));
898 case ACPI_RESOURCE_TYPE_IO
:
899 pnpacpi_encode_io(dev
, resource
,
900 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
903 case ACPI_RESOURCE_TYPE_FIXED_IO
:
904 pnpacpi_encode_fixed_io(dev
, resource
,
905 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
908 case ACPI_RESOURCE_TYPE_MEMORY24
:
909 pnpacpi_encode_mem24(dev
, resource
,
910 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
913 case ACPI_RESOURCE_TYPE_MEMORY32
:
914 pnpacpi_encode_mem32(dev
, resource
,
915 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
918 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
919 pnpacpi_encode_fixed_mem32(dev
, resource
,
920 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
923 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
924 pnpacpi_encode_ext_irq(dev
, resource
,
925 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
928 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
929 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
930 case ACPI_RESOURCE_TYPE_VENDOR
:
931 case ACPI_RESOURCE_TYPE_END_TAG
:
932 case ACPI_RESOURCE_TYPE_ADDRESS16
:
933 case ACPI_RESOURCE_TYPE_ADDRESS32
:
934 case ACPI_RESOURCE_TYPE_ADDRESS64
:
935 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
936 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
937 default: /* other type */
939 "can't encode unknown resource type %d\n",