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 struct { u64 start
, length
; } range
;
156 if (vendor_resource_matches(dev
, vendor
, &hp_ccsr_uuid
,
158 memcpy(&range
, vendor
->byte_data
, sizeof(range
));
159 pnp_add_mem_resource(dev
, range
.start
, range
.start
+
160 range
.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
,
212 flags
= IORESOURCE_DISABLED
;
214 pnp_add_irq_resource(dev
, i
, flags
);
216 } else if (r
->flags
& IORESOURCE_DISABLED
) {
217 pnp_add_irq_resource(dev
, 0, IORESOURCE_DISABLED
);
222 case ACPI_RESOURCE_TYPE_MEMORY24
:
223 case ACPI_RESOURCE_TYPE_MEMORY32
:
224 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
225 if (acpi_dev_resource_memory(res
, r
))
226 pnp_add_resource(dev
, r
);
228 case ACPI_RESOURCE_TYPE_IO
:
229 case ACPI_RESOURCE_TYPE_FIXED_IO
:
230 if (acpi_dev_resource_io(res
, r
))
231 pnp_add_resource(dev
, r
);
233 case ACPI_RESOURCE_TYPE_DMA
:
234 dma
= &res
->data
.dma
;
235 if (dma
->channel_count
> 0 && dma
->channels
[0] != (u8
) -1)
236 flags
= dma_flags(dev
, dma
->type
, dma
->bus_master
,
239 flags
= IORESOURCE_DISABLED
;
240 pnp_add_dma_resource(dev
, dma
->channels
[0], flags
);
243 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
244 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
247 case ACPI_RESOURCE_TYPE_VENDOR
:
248 vendor_typed
= &res
->data
.vendor_typed
;
249 pnpacpi_parse_allocated_vendor(dev
, vendor_typed
);
252 case ACPI_RESOURCE_TYPE_END_TAG
:
255 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
258 case ACPI_RESOURCE_TYPE_SERIAL_BUS
:
259 /* serial bus connections (I2C/SPI/UART) are not pnp */
263 dev_warn(&dev
->dev
, "unknown resource type %d in _CRS\n",
271 int pnpacpi_parse_allocated_resource(struct pnp_dev
*dev
)
273 struct acpi_device
*acpi_dev
= dev
->data
;
274 acpi_handle handle
= acpi_dev
->handle
;
277 pnp_dbg(&dev
->dev
, "parse allocated resources\n");
279 pnp_init_resources(dev
);
281 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
282 pnpacpi_allocated_resource
, dev
);
284 if (ACPI_FAILURE(status
)) {
285 if (status
!= AE_NOT_FOUND
)
286 dev_err(&dev
->dev
, "can't evaluate _CRS: %d", status
);
292 static __init
void pnpacpi_parse_dma_option(struct pnp_dev
*dev
,
293 unsigned int option_flags
,
294 struct acpi_resource_dma
*p
)
297 unsigned char map
= 0, flags
;
299 for (i
= 0; i
< p
->channel_count
; i
++)
300 map
|= 1 << p
->channels
[i
];
302 flags
= dma_flags(dev
, p
->type
, p
->bus_master
, p
->transfer
);
303 pnp_register_dma_resource(dev
, option_flags
, map
, flags
);
306 static __init
void pnpacpi_parse_irq_option(struct pnp_dev
*dev
,
307 unsigned int option_flags
,
308 struct acpi_resource_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 __set_bit(p
->interrupts
[i
], map
.bits
);
319 flags
= acpi_dev_irq_flags(p
->triggering
, p
->polarity
, p
->shareable
, p
->wake_capable
);
320 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
323 static __init
void pnpacpi_parse_ext_irq_option(struct pnp_dev
*dev
,
324 unsigned int option_flags
,
325 struct acpi_resource_extended_irq
*p
)
331 bitmap_zero(map
.bits
, PNP_IRQ_NR
);
332 for (i
= 0; i
< p
->interrupt_count
; i
++) {
333 if (p
->interrupts
[i
]) {
334 if (p
->interrupts
[i
] < PNP_IRQ_NR
)
335 __set_bit(p
->interrupts
[i
], map
.bits
);
338 "ignoring IRQ %d option (too large for %d entry bitmap)\n",
339 p
->interrupts
[i
], PNP_IRQ_NR
);
343 flags
= acpi_dev_irq_flags(p
->triggering
, p
->polarity
, p
->shareable
, p
->wake_capable
);
344 pnp_register_irq_resource(dev
, option_flags
, &map
, flags
);
347 static __init
void pnpacpi_parse_port_option(struct pnp_dev
*dev
,
348 unsigned int option_flags
,
349 struct acpi_resource_io
*io
)
351 unsigned char flags
= 0;
353 if (io
->io_decode
== ACPI_DECODE_16
)
354 flags
= IORESOURCE_IO_16BIT_ADDR
;
355 pnp_register_port_resource(dev
, option_flags
, io
->minimum
, io
->maximum
,
356 io
->alignment
, io
->address_length
, flags
);
359 static __init
void pnpacpi_parse_fixed_port_option(struct pnp_dev
*dev
,
360 unsigned int option_flags
,
361 struct acpi_resource_fixed_io
*io
)
363 pnp_register_port_resource(dev
, option_flags
, io
->address
, io
->address
,
364 0, io
->address_length
, IORESOURCE_IO_FIXED
);
367 static __init
void pnpacpi_parse_mem24_option(struct pnp_dev
*dev
,
368 unsigned int option_flags
,
369 struct acpi_resource_memory24
*p
)
371 unsigned char flags
= 0;
373 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
374 flags
= IORESOURCE_MEM_WRITEABLE
;
375 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
376 p
->alignment
, p
->address_length
, flags
);
379 static __init
void pnpacpi_parse_mem32_option(struct pnp_dev
*dev
,
380 unsigned int option_flags
,
381 struct acpi_resource_memory32
*p
)
383 unsigned char flags
= 0;
385 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
386 flags
= IORESOURCE_MEM_WRITEABLE
;
387 pnp_register_mem_resource(dev
, option_flags
, p
->minimum
, p
->maximum
,
388 p
->alignment
, p
->address_length
, flags
);
391 static __init
void pnpacpi_parse_fixed_mem32_option(struct pnp_dev
*dev
,
392 unsigned int option_flags
,
393 struct acpi_resource_fixed_memory32
*p
)
395 unsigned char flags
= 0;
397 if (p
->write_protect
== ACPI_READ_WRITE_MEMORY
)
398 flags
= IORESOURCE_MEM_WRITEABLE
;
399 pnp_register_mem_resource(dev
, option_flags
, p
->address
, p
->address
,
400 0, p
->address_length
, flags
);
403 static __init
void pnpacpi_parse_address_option(struct pnp_dev
*dev
,
404 unsigned int option_flags
,
405 struct acpi_resource
*r
)
407 struct acpi_resource_address64 addr
, *p
= &addr
;
409 unsigned char flags
= 0;
411 status
= acpi_resource_to_address64(r
, p
);
412 if (ACPI_FAILURE(status
)) {
413 dev_warn(&dev
->dev
, "can't convert resource type %d\n",
418 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
419 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
420 flags
= IORESOURCE_MEM_WRITEABLE
;
421 pnp_register_mem_resource(dev
, option_flags
, p
->address
.minimum
,
422 p
->address
.minimum
, 0, p
->address
.address_length
,
424 } else if (p
->resource_type
== ACPI_IO_RANGE
)
425 pnp_register_port_resource(dev
, option_flags
, p
->address
.minimum
,
426 p
->address
.minimum
, 0, p
->address
.address_length
,
427 IORESOURCE_IO_FIXED
);
430 static __init
void pnpacpi_parse_ext_address_option(struct pnp_dev
*dev
,
431 unsigned int option_flags
,
432 struct acpi_resource
*r
)
434 struct acpi_resource_extended_address64
*p
= &r
->data
.ext_address64
;
435 unsigned char flags
= 0;
437 if (p
->resource_type
== ACPI_MEMORY_RANGE
) {
438 if (p
->info
.mem
.write_protect
== ACPI_READ_WRITE_MEMORY
)
439 flags
= IORESOURCE_MEM_WRITEABLE
;
440 pnp_register_mem_resource(dev
, option_flags
, p
->address
.minimum
,
441 p
->address
.minimum
, 0, p
->address
.address_length
,
443 } else if (p
->resource_type
== ACPI_IO_RANGE
)
444 pnp_register_port_resource(dev
, option_flags
, p
->address
.minimum
,
445 p
->address
.minimum
, 0, p
->address
.address_length
,
446 IORESOURCE_IO_FIXED
);
449 struct acpipnp_parse_option_s
{
451 unsigned int option_flags
;
454 static __init acpi_status
pnpacpi_option_resource(struct acpi_resource
*res
,
458 struct acpipnp_parse_option_s
*parse_data
= data
;
459 struct pnp_dev
*dev
= parse_data
->dev
;
460 unsigned int option_flags
= parse_data
->option_flags
;
463 case ACPI_RESOURCE_TYPE_IRQ
:
464 pnpacpi_parse_irq_option(dev
, option_flags
, &res
->data
.irq
);
467 case ACPI_RESOURCE_TYPE_DMA
:
468 pnpacpi_parse_dma_option(dev
, option_flags
, &res
->data
.dma
);
471 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
472 switch (res
->data
.start_dpf
.compatibility_priority
) {
473 case ACPI_GOOD_CONFIGURATION
:
474 priority
= PNP_RES_PRIORITY_PREFERRED
;
477 case ACPI_ACCEPTABLE_CONFIGURATION
:
478 priority
= PNP_RES_PRIORITY_ACCEPTABLE
;
481 case ACPI_SUB_OPTIMAL_CONFIGURATION
:
482 priority
= PNP_RES_PRIORITY_FUNCTIONAL
;
485 priority
= PNP_RES_PRIORITY_INVALID
;
488 parse_data
->option_flags
= pnp_new_dependent_set(dev
, priority
);
491 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
492 parse_data
->option_flags
= 0;
495 case ACPI_RESOURCE_TYPE_IO
:
496 pnpacpi_parse_port_option(dev
, option_flags
, &res
->data
.io
);
499 case ACPI_RESOURCE_TYPE_FIXED_IO
:
500 pnpacpi_parse_fixed_port_option(dev
, option_flags
,
501 &res
->data
.fixed_io
);
504 case ACPI_RESOURCE_TYPE_VENDOR
:
505 case ACPI_RESOURCE_TYPE_END_TAG
:
508 case ACPI_RESOURCE_TYPE_MEMORY24
:
509 pnpacpi_parse_mem24_option(dev
, option_flags
,
510 &res
->data
.memory24
);
513 case ACPI_RESOURCE_TYPE_MEMORY32
:
514 pnpacpi_parse_mem32_option(dev
, option_flags
,
515 &res
->data
.memory32
);
518 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
519 pnpacpi_parse_fixed_mem32_option(dev
, option_flags
,
520 &res
->data
.fixed_memory32
);
523 case ACPI_RESOURCE_TYPE_ADDRESS16
:
524 case ACPI_RESOURCE_TYPE_ADDRESS32
:
525 case ACPI_RESOURCE_TYPE_ADDRESS64
:
526 pnpacpi_parse_address_option(dev
, option_flags
, res
);
529 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
530 pnpacpi_parse_ext_address_option(dev
, option_flags
, res
);
533 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
534 pnpacpi_parse_ext_irq_option(dev
, option_flags
,
535 &res
->data
.extended_irq
);
538 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
542 dev_warn(&dev
->dev
, "unknown resource type %d in _PRS\n",
550 int __init
pnpacpi_parse_resource_option_data(struct pnp_dev
*dev
)
552 struct acpi_device
*acpi_dev
= dev
->data
;
553 acpi_handle handle
= acpi_dev
->handle
;
555 struct acpipnp_parse_option_s parse_data
;
557 pnp_dbg(&dev
->dev
, "parse resource options\n");
559 parse_data
.dev
= dev
;
560 parse_data
.option_flags
= 0;
562 status
= acpi_walk_resources(handle
, METHOD_NAME__PRS
,
563 pnpacpi_option_resource
, &parse_data
);
565 if (ACPI_FAILURE(status
)) {
566 if (status
!= AE_NOT_FOUND
)
567 dev_err(&dev
->dev
, "can't evaluate _PRS: %d", status
);
573 static int pnpacpi_supported_resource(struct acpi_resource
*res
)
576 case ACPI_RESOURCE_TYPE_IRQ
:
577 case ACPI_RESOURCE_TYPE_DMA
:
578 case ACPI_RESOURCE_TYPE_IO
:
579 case ACPI_RESOURCE_TYPE_FIXED_IO
:
580 case ACPI_RESOURCE_TYPE_MEMORY24
:
581 case ACPI_RESOURCE_TYPE_MEMORY32
:
582 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
583 case ACPI_RESOURCE_TYPE_ADDRESS16
:
584 case ACPI_RESOURCE_TYPE_ADDRESS32
:
585 case ACPI_RESOURCE_TYPE_ADDRESS64
:
586 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
587 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
596 static acpi_status
pnpacpi_count_resources(struct acpi_resource
*res
,
601 if (pnpacpi_supported_resource(res
))
606 static acpi_status
pnpacpi_type_resources(struct acpi_resource
*res
, void *data
)
608 struct acpi_resource
**resource
= data
;
610 if (pnpacpi_supported_resource(res
)) {
611 (*resource
)->type
= res
->type
;
612 (*resource
)->length
= sizeof(struct acpi_resource
);
613 if (res
->type
== ACPI_RESOURCE_TYPE_IRQ
)
614 (*resource
)->data
.irq
.descriptor_length
=
615 res
->data
.irq
.descriptor_length
;
622 int pnpacpi_build_resource_template(struct pnp_dev
*dev
,
623 struct acpi_buffer
*buffer
)
625 struct acpi_device
*acpi_dev
= dev
->data
;
626 acpi_handle handle
= acpi_dev
->handle
;
627 struct acpi_resource
*resource
;
631 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
632 pnpacpi_count_resources
, &res_cnt
);
633 if (ACPI_FAILURE(status
)) {
634 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
639 buffer
->length
= sizeof(struct acpi_resource
) * (res_cnt
+ 1) + 1;
640 buffer
->pointer
= kzalloc(buffer
->length
- 1, GFP_KERNEL
);
641 if (!buffer
->pointer
)
644 resource
= (struct acpi_resource
*)buffer
->pointer
;
645 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
646 pnpacpi_type_resources
, &resource
);
647 if (ACPI_FAILURE(status
)) {
648 kfree(buffer
->pointer
);
649 dev_err(&dev
->dev
, "can't evaluate _CRS: %d\n", status
);
652 /* resource will pointer the end resource now */
653 resource
->type
= ACPI_RESOURCE_TYPE_END_TAG
;
654 resource
->length
= sizeof(struct acpi_resource
);
659 static void pnpacpi_encode_irq(struct pnp_dev
*dev
,
660 struct acpi_resource
*resource
,
663 struct acpi_resource_irq
*irq
= &resource
->data
.irq
;
664 u8 triggering
, polarity
, shareable
;
666 if (!pnp_resource_enabled(p
)) {
667 irq
->interrupt_count
= 0;
668 pnp_dbg(&dev
->dev
, " encode irq (%s)\n",
669 p
? "disabled" : "missing");
673 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
674 irq
->triggering
= triggering
;
675 irq
->polarity
= polarity
;
676 irq
->shareable
= shareable
;
677 irq
->interrupt_count
= 1;
678 irq
->interrupts
[0] = p
->start
;
680 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s (%d-byte descriptor)\n",
682 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
683 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
684 irq
->shareable
== ACPI_SHARED
? "shared" : "exclusive",
685 irq
->descriptor_length
);
688 static void pnpacpi_encode_ext_irq(struct pnp_dev
*dev
,
689 struct acpi_resource
*resource
,
692 struct acpi_resource_extended_irq
*extended_irq
= &resource
->data
.extended_irq
;
693 u8 triggering
, polarity
, shareable
;
695 if (!pnp_resource_enabled(p
)) {
696 extended_irq
->interrupt_count
= 0;
697 pnp_dbg(&dev
->dev
, " encode extended irq (%s)\n",
698 p
? "disabled" : "missing");
702 decode_irq_flags(dev
, p
->flags
, &triggering
, &polarity
, &shareable
);
703 extended_irq
->producer_consumer
= ACPI_CONSUMER
;
704 extended_irq
->triggering
= triggering
;
705 extended_irq
->polarity
= polarity
;
706 extended_irq
->shareable
= shareable
;
707 extended_irq
->interrupt_count
= 1;
708 extended_irq
->interrupts
[0] = p
->start
;
710 pnp_dbg(&dev
->dev
, " encode irq %d %s %s %s\n", (int) p
->start
,
711 triggering
== ACPI_LEVEL_SENSITIVE
? "level" : "edge",
712 polarity
== ACPI_ACTIVE_LOW
? "low" : "high",
713 extended_irq
->shareable
== ACPI_SHARED
? "shared" : "exclusive");
716 static void pnpacpi_encode_dma(struct pnp_dev
*dev
,
717 struct acpi_resource
*resource
,
720 struct acpi_resource_dma
*dma
= &resource
->data
.dma
;
722 if (!pnp_resource_enabled(p
)) {
723 dma
->channel_count
= 0;
724 pnp_dbg(&dev
->dev
, " encode dma (%s)\n",
725 p
? "disabled" : "missing");
729 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
730 switch (p
->flags
& IORESOURCE_DMA_SPEED_MASK
) {
731 case IORESOURCE_DMA_TYPEA
:
732 dma
->type
= ACPI_TYPE_A
;
734 case IORESOURCE_DMA_TYPEB
:
735 dma
->type
= ACPI_TYPE_B
;
737 case IORESOURCE_DMA_TYPEF
:
738 dma
->type
= ACPI_TYPE_F
;
741 dma
->type
= ACPI_COMPATIBILITY
;
744 switch (p
->flags
& IORESOURCE_DMA_TYPE_MASK
) {
745 case IORESOURCE_DMA_8BIT
:
746 dma
->transfer
= ACPI_TRANSFER_8
;
748 case IORESOURCE_DMA_8AND16BIT
:
749 dma
->transfer
= ACPI_TRANSFER_8_16
;
752 dma
->transfer
= ACPI_TRANSFER_16
;
755 dma
->bus_master
= !!(p
->flags
& IORESOURCE_DMA_MASTER
);
756 dma
->channel_count
= 1;
757 dma
->channels
[0] = p
->start
;
759 pnp_dbg(&dev
->dev
, " encode dma %d "
760 "type %#x transfer %#x master %d\n",
761 (int) p
->start
, dma
->type
, dma
->transfer
, dma
->bus_master
);
764 static void pnpacpi_encode_io(struct pnp_dev
*dev
,
765 struct acpi_resource
*resource
,
768 struct acpi_resource_io
*io
= &resource
->data
.io
;
770 if (pnp_resource_enabled(p
)) {
771 /* Note: pnp_assign_port copies pnp_port->flags into p->flags */
772 io
->io_decode
= (p
->flags
& IORESOURCE_IO_16BIT_ADDR
) ?
773 ACPI_DECODE_16
: ACPI_DECODE_10
;
774 io
->minimum
= p
->start
;
775 io
->maximum
= p
->end
;
776 io
->alignment
= 0; /* Correct? */
777 io
->address_length
= resource_size(p
);
780 io
->address_length
= 0;
783 pnp_dbg(&dev
->dev
, " encode io %#x-%#x decode %#x\n", io
->minimum
,
784 io
->minimum
+ io
->address_length
- 1, io
->io_decode
);
787 static void pnpacpi_encode_fixed_io(struct pnp_dev
*dev
,
788 struct acpi_resource
*resource
,
791 struct acpi_resource_fixed_io
*fixed_io
= &resource
->data
.fixed_io
;
793 if (pnp_resource_enabled(p
)) {
794 fixed_io
->address
= p
->start
;
795 fixed_io
->address_length
= resource_size(p
);
797 fixed_io
->address
= 0;
798 fixed_io
->address_length
= 0;
801 pnp_dbg(&dev
->dev
, " encode fixed_io %#x-%#x\n", fixed_io
->address
,
802 fixed_io
->address
+ fixed_io
->address_length
- 1);
805 static void pnpacpi_encode_mem24(struct pnp_dev
*dev
,
806 struct acpi_resource
*resource
,
809 struct acpi_resource_memory24
*memory24
= &resource
->data
.memory24
;
811 if (pnp_resource_enabled(p
)) {
812 /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */
813 memory24
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
814 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
815 memory24
->minimum
= p
->start
;
816 memory24
->maximum
= p
->end
;
817 memory24
->alignment
= 0;
818 memory24
->address_length
= resource_size(p
);
820 memory24
->minimum
= 0;
821 memory24
->address_length
= 0;
824 pnp_dbg(&dev
->dev
, " encode mem24 %#x-%#x write_protect %#x\n",
826 memory24
->minimum
+ memory24
->address_length
- 1,
827 memory24
->write_protect
);
830 static void pnpacpi_encode_mem32(struct pnp_dev
*dev
,
831 struct acpi_resource
*resource
,
834 struct acpi_resource_memory32
*memory32
= &resource
->data
.memory32
;
836 if (pnp_resource_enabled(p
)) {
837 memory32
->write_protect
= p
->flags
& IORESOURCE_MEM_WRITEABLE
?
838 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
839 memory32
->minimum
= p
->start
;
840 memory32
->maximum
= p
->end
;
841 memory32
->alignment
= 0;
842 memory32
->address_length
= resource_size(p
);
844 memory32
->minimum
= 0;
845 memory32
->alignment
= 0;
848 pnp_dbg(&dev
->dev
, " encode mem32 %#x-%#x write_protect %#x\n",
850 memory32
->minimum
+ memory32
->address_length
- 1,
851 memory32
->write_protect
);
854 static void pnpacpi_encode_fixed_mem32(struct pnp_dev
*dev
,
855 struct acpi_resource
*resource
,
858 struct acpi_resource_fixed_memory32
*fixed_memory32
= &resource
->data
.fixed_memory32
;
860 if (pnp_resource_enabled(p
)) {
861 fixed_memory32
->write_protect
=
862 p
->flags
& IORESOURCE_MEM_WRITEABLE
?
863 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
864 fixed_memory32
->address
= p
->start
;
865 fixed_memory32
->address_length
= resource_size(p
);
867 fixed_memory32
->address
= 0;
868 fixed_memory32
->address_length
= 0;
871 pnp_dbg(&dev
->dev
, " encode fixed_mem32 %#x-%#x write_protect %#x\n",
872 fixed_memory32
->address
,
873 fixed_memory32
->address
+ fixed_memory32
->address_length
- 1,
874 fixed_memory32
->write_protect
);
877 int pnpacpi_encode_resources(struct pnp_dev
*dev
, struct acpi_buffer
*buffer
)
880 /* pnpacpi_build_resource_template allocates extra mem */
881 int res_cnt
= (buffer
->length
- 1) / sizeof(struct acpi_resource
) - 1;
882 struct acpi_resource
*resource
= buffer
->pointer
;
883 unsigned int port
= 0, irq
= 0, dma
= 0, mem
= 0;
885 pnp_dbg(&dev
->dev
, "encode %d resources\n", res_cnt
);
886 while (i
< res_cnt
) {
887 switch (resource
->type
) {
888 case ACPI_RESOURCE_TYPE_IRQ
:
889 pnpacpi_encode_irq(dev
, resource
,
890 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
894 case ACPI_RESOURCE_TYPE_DMA
:
895 pnpacpi_encode_dma(dev
, resource
,
896 pnp_get_resource(dev
, IORESOURCE_DMA
, dma
));
899 case ACPI_RESOURCE_TYPE_IO
:
900 pnpacpi_encode_io(dev
, resource
,
901 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
904 case ACPI_RESOURCE_TYPE_FIXED_IO
:
905 pnpacpi_encode_fixed_io(dev
, resource
,
906 pnp_get_resource(dev
, IORESOURCE_IO
, port
));
909 case ACPI_RESOURCE_TYPE_MEMORY24
:
910 pnpacpi_encode_mem24(dev
, resource
,
911 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
914 case ACPI_RESOURCE_TYPE_MEMORY32
:
915 pnpacpi_encode_mem32(dev
, resource
,
916 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
919 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32
:
920 pnpacpi_encode_fixed_mem32(dev
, resource
,
921 pnp_get_resource(dev
, IORESOURCE_MEM
, mem
));
924 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ
:
925 pnpacpi_encode_ext_irq(dev
, resource
,
926 pnp_get_resource(dev
, IORESOURCE_IRQ
, irq
));
929 case ACPI_RESOURCE_TYPE_START_DEPENDENT
:
930 case ACPI_RESOURCE_TYPE_END_DEPENDENT
:
931 case ACPI_RESOURCE_TYPE_VENDOR
:
932 case ACPI_RESOURCE_TYPE_END_TAG
:
933 case ACPI_RESOURCE_TYPE_ADDRESS16
:
934 case ACPI_RESOURCE_TYPE_ADDRESS32
:
935 case ACPI_RESOURCE_TYPE_ADDRESS64
:
936 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
:
937 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER
:
938 default: /* other type */
940 "can't encode unknown resource type %d\n",