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>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/acpi.h>
23 #include <linux/pci.h>
27 #define valid_IRQ(i) (1)
29 #define valid_IRQ(i) (((i) != 0) && ((i) != 2))
35 static int irq_flags(int edge_level
, int active_high_low
)
38 if (edge_level
== ACPI_LEVEL_SENSITIVE
) {
39 if(active_high_low
== ACPI_ACTIVE_LOW
)
40 flag
= IORESOURCE_IRQ_LOWLEVEL
;
42 flag
= IORESOURCE_IRQ_HIGHLEVEL
;
45 if(active_high_low
== ACPI_ACTIVE_LOW
)
46 flag
= IORESOURCE_IRQ_LOWEDGE
;
48 flag
= IORESOURCE_IRQ_HIGHEDGE
;
53 static void decode_irq_flags(int flag
, int *edge_level
, int *active_high_low
)
56 case IORESOURCE_IRQ_LOWLEVEL
:
57 *edge_level
= ACPI_LEVEL_SENSITIVE
;
58 *active_high_low
= ACPI_ACTIVE_LOW
;
60 case IORESOURCE_IRQ_HIGHLEVEL
:
61 *edge_level
= ACPI_LEVEL_SENSITIVE
;
62 *active_high_low
= ACPI_ACTIVE_HIGH
;
64 case IORESOURCE_IRQ_LOWEDGE
:
65 *edge_level
= ACPI_EDGE_SENSITIVE
;
66 *active_high_low
= ACPI_ACTIVE_LOW
;
68 case IORESOURCE_IRQ_HIGHEDGE
:
69 *edge_level
= ACPI_EDGE_SENSITIVE
;
70 *active_high_low
= ACPI_ACTIVE_HIGH
;
76 pnpacpi_parse_allocated_irqresource(struct pnp_resource_table
* res
, int irq
)
79 while (!(res
->irq_resource
[i
].flags
& IORESOURCE_UNSET
) &&
82 if (i
< PNP_MAX_IRQ
) {
83 res
->irq_resource
[i
].flags
= IORESOURCE_IRQ
; //Also clears _UNSET flag
85 res
->irq_resource
[i
].flags
|= IORESOURCE_DISABLED
;
88 res
->irq_resource
[i
].start
=(unsigned long) irq
;
89 res
->irq_resource
[i
].end
= (unsigned long) irq
;
94 pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table
* res
, int dma
)
97 while (i
< PNP_MAX_DMA
&&
98 !(res
->dma_resource
[i
].flags
& IORESOURCE_UNSET
))
100 if (i
< PNP_MAX_DMA
) {
101 res
->dma_resource
[i
].flags
= IORESOURCE_DMA
; // Also clears _UNSET flag
103 res
->dma_resource
[i
].flags
|= IORESOURCE_DISABLED
;
106 res
->dma_resource
[i
].start
=(unsigned long) dma
;
107 res
->dma_resource
[i
].end
= (unsigned long) dma
;
112 pnpacpi_parse_allocated_ioresource(struct pnp_resource_table
* res
,
116 while (!(res
->port_resource
[i
].flags
& IORESOURCE_UNSET
) &&
119 if (i
< PNP_MAX_PORT
) {
120 res
->port_resource
[i
].flags
= IORESOURCE_IO
; // Also clears _UNSET flag
121 if (len
<= 0 || (io
+ len
-1) >= 0x10003) {
122 res
->port_resource
[i
].flags
|= IORESOURCE_DISABLED
;
125 res
->port_resource
[i
].start
= (unsigned long) io
;
126 res
->port_resource
[i
].end
= (unsigned long)(io
+ len
- 1);
131 pnpacpi_parse_allocated_memresource(struct pnp_resource_table
* res
,
135 while (!(res
->mem_resource
[i
].flags
& IORESOURCE_UNSET
) &&
138 if (i
< PNP_MAX_MEM
) {
139 res
->mem_resource
[i
].flags
= IORESOURCE_MEM
; // Also clears _UNSET flag
141 res
->mem_resource
[i
].flags
|= IORESOURCE_DISABLED
;
144 res
->mem_resource
[i
].start
= (unsigned long) mem
;
145 res
->mem_resource
[i
].end
= (unsigned long)(mem
+ len
- 1);
150 static acpi_status
pnpacpi_allocated_resource(struct acpi_resource
*res
,
153 struct pnp_resource_table
* res_table
= (struct pnp_resource_table
*)data
;
156 case ACPI_RSTYPE_IRQ
:
157 if ((res
->data
.irq
.number_of_interrupts
> 0) &&
158 valid_IRQ(res
->data
.irq
.interrupts
[0])) {
159 pnpacpi_parse_allocated_irqresource(res_table
,
160 acpi_register_gsi(res
->data
.irq
.interrupts
[0],
161 res
->data
.irq
.edge_level
,
162 res
->data
.irq
.active_high_low
));
163 pcibios_penalize_isa_irq(res
->data
.irq
.interrupts
[0]);
167 case ACPI_RSTYPE_EXT_IRQ
:
168 if ((res
->data
.extended_irq
.number_of_interrupts
> 0) &&
169 valid_IRQ(res
->data
.extended_irq
.interrupts
[0])) {
170 pnpacpi_parse_allocated_irqresource(res_table
,
171 acpi_register_gsi(res
->data
.extended_irq
.interrupts
[0],
172 res
->data
.extended_irq
.edge_level
,
173 res
->data
.extended_irq
.active_high_low
));
174 pcibios_penalize_isa_irq(res
->data
.extended_irq
.interrupts
[0]);
177 case ACPI_RSTYPE_DMA
:
178 if (res
->data
.dma
.number_of_channels
> 0)
179 pnpacpi_parse_allocated_dmaresource(res_table
,
180 res
->data
.dma
.channels
[0]);
183 pnpacpi_parse_allocated_ioresource(res_table
,
184 res
->data
.io
.min_base_address
,
185 res
->data
.io
.range_length
);
187 case ACPI_RSTYPE_FIXED_IO
:
188 pnpacpi_parse_allocated_ioresource(res_table
,
189 res
->data
.fixed_io
.base_address
,
190 res
->data
.fixed_io
.range_length
);
192 case ACPI_RSTYPE_MEM24
:
193 pnpacpi_parse_allocated_memresource(res_table
,
194 res
->data
.memory24
.min_base_address
,
195 res
->data
.memory24
.range_length
);
197 case ACPI_RSTYPE_MEM32
:
198 pnpacpi_parse_allocated_memresource(res_table
,
199 res
->data
.memory32
.min_base_address
,
200 res
->data
.memory32
.range_length
);
202 case ACPI_RSTYPE_FIXED_MEM32
:
203 pnpacpi_parse_allocated_memresource(res_table
,
204 res
->data
.fixed_memory32
.range_base_address
,
205 res
->data
.fixed_memory32
.range_length
);
207 case ACPI_RSTYPE_ADDRESS16
:
208 pnpacpi_parse_allocated_memresource(res_table
,
209 res
->data
.address16
.min_address_range
,
210 res
->data
.address16
.address_length
);
212 case ACPI_RSTYPE_ADDRESS32
:
213 pnpacpi_parse_allocated_memresource(res_table
,
214 res
->data
.address32
.min_address_range
,
215 res
->data
.address32
.address_length
);
217 case ACPI_RSTYPE_ADDRESS64
:
218 pnpacpi_parse_allocated_memresource(res_table
,
219 res
->data
.address64
.min_address_range
,
220 res
->data
.address64
.address_length
);
222 case ACPI_RSTYPE_VENDOR
:
225 pnp_warn("PnPACPI: unknown resource type %d", res
->id
);
232 acpi_status
pnpacpi_parse_allocated_resource(acpi_handle handle
, struct pnp_resource_table
* res
)
234 /* Blank the resource table values */
235 pnp_init_resource_table(res
);
237 return acpi_walk_resources(handle
, METHOD_NAME__CRS
, pnpacpi_allocated_resource
, res
);
240 static void pnpacpi_parse_dma_option(struct pnp_option
*option
, struct acpi_resource_dma
*p
)
243 struct pnp_dma
* dma
;
245 if (p
->number_of_channels
== 0)
247 dma
= pnpacpi_kmalloc(sizeof(struct pnp_dma
), GFP_KERNEL
);
251 for(i
= 0; i
< p
->number_of_channels
; i
++)
252 dma
->map
|= 1 << p
->channels
[i
];
255 dma
->flags
|= IORESOURCE_DMA_MASTER
;
257 case ACPI_COMPATIBILITY
:
258 dma
->flags
|= IORESOURCE_DMA_COMPATIBLE
;
261 dma
->flags
|= IORESOURCE_DMA_TYPEA
;
264 dma
->flags
|= IORESOURCE_DMA_TYPEB
;
267 dma
->flags
|= IORESOURCE_DMA_TYPEF
;
270 /* Set a default value ? */
271 dma
->flags
|= IORESOURCE_DMA_COMPATIBLE
;
272 pnp_err("Invalid DMA type");
274 switch (p
->transfer
) {
275 case ACPI_TRANSFER_8
:
276 dma
->flags
|= IORESOURCE_DMA_8BIT
;
278 case ACPI_TRANSFER_8_16
:
279 dma
->flags
|= IORESOURCE_DMA_8AND16BIT
;
281 case ACPI_TRANSFER_16
:
282 dma
->flags
|= IORESOURCE_DMA_16BIT
;
285 /* Set a default value ? */
286 dma
->flags
|= IORESOURCE_DMA_8AND16BIT
;
287 pnp_err("Invalid DMA transfer type");
290 pnp_register_dma_resource(option
,dma
);
295 static void pnpacpi_parse_irq_option(struct pnp_option
*option
,
296 struct acpi_resource_irq
*p
)
299 struct pnp_irq
* irq
;
301 if (p
->number_of_interrupts
== 0)
303 irq
= pnpacpi_kmalloc(sizeof(struct pnp_irq
), GFP_KERNEL
);
307 for(i
= 0; i
< p
->number_of_interrupts
; i
++)
308 if (p
->interrupts
[i
])
309 __set_bit(p
->interrupts
[i
], irq
->map
);
310 irq
->flags
= irq_flags(p
->edge_level
, p
->active_high_low
);
312 pnp_register_irq_resource(option
, irq
);
316 static void pnpacpi_parse_ext_irq_option(struct pnp_option
*option
,
317 struct acpi_resource_ext_irq
*p
)
320 struct pnp_irq
* irq
;
322 if (p
->number_of_interrupts
== 0)
324 irq
= pnpacpi_kmalloc(sizeof(struct pnp_irq
), GFP_KERNEL
);
328 for(i
= 0; i
< p
->number_of_interrupts
; i
++)
329 if (p
->interrupts
[i
])
330 __set_bit(p
->interrupts
[i
], irq
->map
);
331 irq
->flags
= irq_flags(p
->edge_level
, p
->active_high_low
);
333 pnp_register_irq_resource(option
, irq
);
338 pnpacpi_parse_port_option(struct pnp_option
*option
,
339 struct acpi_resource_io
*io
)
341 struct pnp_port
* port
;
343 if (io
->range_length
== 0)
345 port
= pnpacpi_kmalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
348 port
->min
= io
->min_base_address
;
349 port
->max
= io
->max_base_address
;
350 port
->align
= io
->alignment
;
351 port
->size
= io
->range_length
;
352 port
->flags
= ACPI_DECODE_16
== io
->io_decode
?
353 PNP_PORT_FLAG_16BITADDR
: 0;
354 pnp_register_port_resource(option
,port
);
359 pnpacpi_parse_fixed_port_option(struct pnp_option
*option
,
360 struct acpi_resource_fixed_io
*io
)
362 struct pnp_port
* port
;
364 if (io
->range_length
== 0)
366 port
= pnpacpi_kmalloc(sizeof(struct pnp_port
), GFP_KERNEL
);
369 port
->min
= port
->max
= io
->base_address
;
370 port
->size
= io
->range_length
;
372 port
->flags
= PNP_PORT_FLAG_FIXED
;
373 pnp_register_port_resource(option
,port
);
378 pnpacpi_parse_mem24_option(struct pnp_option
*option
,
379 struct acpi_resource_mem24
*p
)
381 struct pnp_mem
* mem
;
383 if (p
->range_length
== 0)
385 mem
= pnpacpi_kmalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
388 mem
->min
= p
->min_base_address
;
389 mem
->max
= p
->max_base_address
;
390 mem
->align
= p
->alignment
;
391 mem
->size
= p
->range_length
;
393 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->read_write_attribute
) ?
394 IORESOURCE_MEM_WRITEABLE
: 0;
396 pnp_register_mem_resource(option
,mem
);
401 pnpacpi_parse_mem32_option(struct pnp_option
*option
,
402 struct acpi_resource_mem32
*p
)
404 struct pnp_mem
* mem
;
406 if (p
->range_length
== 0)
408 mem
= pnpacpi_kmalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
411 mem
->min
= p
->min_base_address
;
412 mem
->max
= p
->max_base_address
;
413 mem
->align
= p
->alignment
;
414 mem
->size
= p
->range_length
;
416 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->read_write_attribute
) ?
417 IORESOURCE_MEM_WRITEABLE
: 0;
419 pnp_register_mem_resource(option
,mem
);
424 pnpacpi_parse_fixed_mem32_option(struct pnp_option
*option
,
425 struct acpi_resource_fixed_mem32
*p
)
427 struct pnp_mem
* mem
;
429 if (p
->range_length
== 0)
431 mem
= pnpacpi_kmalloc(sizeof(struct pnp_mem
), GFP_KERNEL
);
434 mem
->min
= mem
->max
= p
->range_base_address
;
435 mem
->size
= p
->range_length
;
438 mem
->flags
= (ACPI_READ_WRITE_MEMORY
== p
->read_write_attribute
) ?
439 IORESOURCE_MEM_WRITEABLE
: 0;
441 pnp_register_mem_resource(option
,mem
);
445 struct acpipnp_parse_option_s
{
446 struct pnp_option
*option
;
450 static acpi_status
pnpacpi_option_resource(struct acpi_resource
*res
,
454 struct acpipnp_parse_option_s
*parse_data
= (struct acpipnp_parse_option_s
*)data
;
455 struct pnp_dev
*dev
= parse_data
->dev
;
456 struct pnp_option
*option
= parse_data
->option
;
459 case ACPI_RSTYPE_IRQ
:
460 pnpacpi_parse_irq_option(option
, &res
->data
.irq
);
462 case ACPI_RSTYPE_EXT_IRQ
:
463 pnpacpi_parse_ext_irq_option(option
,
464 &res
->data
.extended_irq
);
466 case ACPI_RSTYPE_DMA
:
467 pnpacpi_parse_dma_option(option
, &res
->data
.dma
);
470 pnpacpi_parse_port_option(option
, &res
->data
.io
);
472 case ACPI_RSTYPE_FIXED_IO
:
473 pnpacpi_parse_fixed_port_option(option
,
474 &res
->data
.fixed_io
);
476 case ACPI_RSTYPE_MEM24
:
477 pnpacpi_parse_mem24_option(option
, &res
->data
.memory24
);
479 case ACPI_RSTYPE_MEM32
:
480 pnpacpi_parse_mem32_option(option
, &res
->data
.memory32
);
482 case ACPI_RSTYPE_FIXED_MEM32
:
483 pnpacpi_parse_fixed_mem32_option(option
,
484 &res
->data
.fixed_memory32
);
486 case ACPI_RSTYPE_START_DPF
:
487 switch (res
->data
.start_dpf
.compatibility_priority
) {
488 case ACPI_GOOD_CONFIGURATION
:
489 priority
= PNP_RES_PRIORITY_PREFERRED
;
492 case ACPI_ACCEPTABLE_CONFIGURATION
:
493 priority
= PNP_RES_PRIORITY_ACCEPTABLE
;
496 case ACPI_SUB_OPTIMAL_CONFIGURATION
:
497 priority
= PNP_RES_PRIORITY_FUNCTIONAL
;
500 priority
= PNP_RES_PRIORITY_INVALID
;
503 /* TBD: Considering performace/robustness bits */
504 option
= pnp_register_dependent_option(dev
, priority
);
507 parse_data
->option
= option
;
509 case ACPI_RSTYPE_END_DPF
:
510 return AE_CTRL_TERMINATE
;
512 pnp_warn("PnPACPI: unknown resource type %d", res
->id
);
519 acpi_status
pnpacpi_parse_resource_option_data(acpi_handle handle
,
523 struct acpipnp_parse_option_s parse_data
;
525 parse_data
.option
= pnp_register_independent_option(dev
);
526 if (!parse_data
.option
)
528 parse_data
.dev
= dev
;
529 status
= acpi_walk_resources(handle
, METHOD_NAME__PRS
,
530 pnpacpi_option_resource
, &parse_data
);
538 static acpi_status
pnpacpi_count_resources(struct acpi_resource
*res
,
541 int *res_cnt
= (int *)data
;
543 case ACPI_RSTYPE_IRQ
:
544 case ACPI_RSTYPE_EXT_IRQ
:
545 case ACPI_RSTYPE_DMA
:
547 case ACPI_RSTYPE_FIXED_IO
:
548 case ACPI_RSTYPE_MEM24
:
549 case ACPI_RSTYPE_MEM32
:
550 case ACPI_RSTYPE_FIXED_MEM32
:
552 case ACPI_RSTYPE_ADDRESS16
:
553 case ACPI_RSTYPE_ADDRESS32
:
554 case ACPI_RSTYPE_ADDRESS64
:
563 static acpi_status
pnpacpi_type_resources(struct acpi_resource
*res
,
566 struct acpi_resource
**resource
= (struct acpi_resource
**)data
;
568 case ACPI_RSTYPE_IRQ
:
569 case ACPI_RSTYPE_EXT_IRQ
:
570 case ACPI_RSTYPE_DMA
:
572 case ACPI_RSTYPE_FIXED_IO
:
573 case ACPI_RSTYPE_MEM24
:
574 case ACPI_RSTYPE_MEM32
:
575 case ACPI_RSTYPE_FIXED_MEM32
:
577 case ACPI_RSTYPE_ADDRESS16
:
578 case ACPI_RSTYPE_ADDRESS32
:
579 case ACPI_RSTYPE_ADDRESS64
:
581 (*resource
)->id
= res
->id
;
590 int pnpacpi_build_resource_template(acpi_handle handle
,
591 struct acpi_buffer
*buffer
)
593 struct acpi_resource
*resource
;
597 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
598 pnpacpi_count_resources
, &res_cnt
);
599 if (ACPI_FAILURE(status
)) {
600 pnp_err("Evaluate _CRS failed");
605 buffer
->length
= sizeof(struct acpi_resource
) * (res_cnt
+ 1) + 1;
606 buffer
->pointer
= pnpacpi_kmalloc(buffer
->length
- 1, GFP_KERNEL
);
607 if (!buffer
->pointer
)
609 pnp_dbg("Res cnt %d", res_cnt
);
610 resource
= (struct acpi_resource
*)buffer
->pointer
;
611 status
= acpi_walk_resources(handle
, METHOD_NAME__CRS
,
612 pnpacpi_type_resources
, &resource
);
613 if (ACPI_FAILURE(status
)) {
614 kfree(buffer
->pointer
);
615 pnp_err("Evaluate _CRS failed");
618 /* resource will pointer the end resource now */
619 resource
->id
= ACPI_RSTYPE_END_TAG
;
624 static void pnpacpi_encode_irq(struct acpi_resource
*resource
,
627 int edge_level
, active_high_low
;
629 decode_irq_flags(p
->flags
& IORESOURCE_BITS
, &edge_level
,
631 resource
->id
= ACPI_RSTYPE_IRQ
;
632 resource
->length
= sizeof(struct acpi_resource
);
633 resource
->data
.irq
.edge_level
= edge_level
;
634 resource
->data
.irq
.active_high_low
= active_high_low
;
635 if (edge_level
== ACPI_EDGE_SENSITIVE
)
636 resource
->data
.irq
.shared_exclusive
= ACPI_EXCLUSIVE
;
638 resource
->data
.irq
.shared_exclusive
= ACPI_SHARED
;
639 resource
->data
.irq
.number_of_interrupts
= 1;
640 resource
->data
.irq
.interrupts
[0] = p
->start
;
643 static void pnpacpi_encode_ext_irq(struct acpi_resource
*resource
,
646 int edge_level
, active_high_low
;
648 decode_irq_flags(p
->flags
& IORESOURCE_BITS
, &edge_level
,
650 resource
->id
= ACPI_RSTYPE_EXT_IRQ
;
651 resource
->length
= sizeof(struct acpi_resource
);
652 resource
->data
.extended_irq
.producer_consumer
= ACPI_CONSUMER
;
653 resource
->data
.extended_irq
.edge_level
= edge_level
;
654 resource
->data
.extended_irq
.active_high_low
= active_high_low
;
655 if (edge_level
== ACPI_EDGE_SENSITIVE
)
656 resource
->data
.irq
.shared_exclusive
= ACPI_EXCLUSIVE
;
658 resource
->data
.irq
.shared_exclusive
= ACPI_SHARED
;
659 resource
->data
.extended_irq
.number_of_interrupts
= 1;
660 resource
->data
.extended_irq
.interrupts
[0] = p
->start
;
663 static void pnpacpi_encode_dma(struct acpi_resource
*resource
,
666 resource
->id
= ACPI_RSTYPE_DMA
;
667 resource
->length
= sizeof(struct acpi_resource
);
668 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
669 if (p
->flags
& IORESOURCE_DMA_COMPATIBLE
)
670 resource
->data
.dma
.type
= ACPI_COMPATIBILITY
;
671 else if (p
->flags
& IORESOURCE_DMA_TYPEA
)
672 resource
->data
.dma
.type
= ACPI_TYPE_A
;
673 else if (p
->flags
& IORESOURCE_DMA_TYPEB
)
674 resource
->data
.dma
.type
= ACPI_TYPE_B
;
675 else if (p
->flags
& IORESOURCE_DMA_TYPEF
)
676 resource
->data
.dma
.type
= ACPI_TYPE_F
;
677 if (p
->flags
& IORESOURCE_DMA_8BIT
)
678 resource
->data
.dma
.transfer
= ACPI_TRANSFER_8
;
679 else if (p
->flags
& IORESOURCE_DMA_8AND16BIT
)
680 resource
->data
.dma
.transfer
= ACPI_TRANSFER_8_16
;
681 else if (p
->flags
& IORESOURCE_DMA_16BIT
)
682 resource
->data
.dma
.transfer
= ACPI_TRANSFER_16
;
683 resource
->data
.dma
.bus_master
= p
->flags
& IORESOURCE_DMA_MASTER
;
684 resource
->data
.dma
.number_of_channels
= 1;
685 resource
->data
.dma
.channels
[0] = p
->start
;
688 static void pnpacpi_encode_io(struct acpi_resource
*resource
,
691 resource
->id
= ACPI_RSTYPE_IO
;
692 resource
->length
= sizeof(struct acpi_resource
);
693 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
694 resource
->data
.io
.io_decode
= (p
->flags
& PNP_PORT_FLAG_16BITADDR
)?
695 ACPI_DECODE_16
: ACPI_DECODE_10
;
696 resource
->data
.io
.min_base_address
= p
->start
;
697 resource
->data
.io
.max_base_address
= p
->end
;
698 resource
->data
.io
.alignment
= 0; /* Correct? */
699 resource
->data
.io
.range_length
= p
->end
- p
->start
+ 1;
702 static void pnpacpi_encode_fixed_io(struct acpi_resource
*resource
,
705 resource
->id
= ACPI_RSTYPE_FIXED_IO
;
706 resource
->length
= sizeof(struct acpi_resource
);
707 resource
->data
.fixed_io
.base_address
= p
->start
;
708 resource
->data
.fixed_io
.range_length
= p
->end
- p
->start
+ 1;
711 static void pnpacpi_encode_mem24(struct acpi_resource
*resource
,
714 resource
->id
= ACPI_RSTYPE_MEM24
;
715 resource
->length
= sizeof(struct acpi_resource
);
716 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
717 resource
->data
.memory24
.read_write_attribute
=
718 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
719 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
720 resource
->data
.memory24
.min_base_address
= p
->start
;
721 resource
->data
.memory24
.max_base_address
= p
->end
;
722 resource
->data
.memory24
.alignment
= 0;
723 resource
->data
.memory24
.range_length
= p
->end
- p
->start
+ 1;
726 static void pnpacpi_encode_mem32(struct acpi_resource
*resource
,
729 resource
->id
= ACPI_RSTYPE_MEM32
;
730 resource
->length
= sizeof(struct acpi_resource
);
731 resource
->data
.memory32
.read_write_attribute
=
732 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
733 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
734 resource
->data
.memory32
.min_base_address
= p
->start
;
735 resource
->data
.memory32
.max_base_address
= p
->end
;
736 resource
->data
.memory32
.alignment
= 0;
737 resource
->data
.memory32
.range_length
= p
->end
- p
->start
+ 1;
740 static void pnpacpi_encode_fixed_mem32(struct acpi_resource
*resource
,
743 resource
->id
= ACPI_RSTYPE_FIXED_MEM32
;
744 resource
->length
= sizeof(struct acpi_resource
);
745 resource
->data
.fixed_memory32
.read_write_attribute
=
746 (p
->flags
& IORESOURCE_MEM_WRITEABLE
) ?
747 ACPI_READ_WRITE_MEMORY
: ACPI_READ_ONLY_MEMORY
;
748 resource
->data
.fixed_memory32
.range_base_address
= p
->start
;
749 resource
->data
.fixed_memory32
.range_length
= p
->end
- p
->start
+ 1;
752 int pnpacpi_encode_resources(struct pnp_resource_table
*res_table
,
753 struct acpi_buffer
*buffer
)
756 /* pnpacpi_build_resource_template allocates extra mem */
757 int res_cnt
= (buffer
->length
- 1)/sizeof(struct acpi_resource
) - 1;
758 struct acpi_resource
*resource
= (struct acpi_resource
*)buffer
->pointer
;
759 int port
= 0, irq
= 0, dma
= 0, mem
= 0;
761 pnp_dbg("res cnt %d", res_cnt
);
762 while (i
< res_cnt
) {
763 switch(resource
->id
) {
764 case ACPI_RSTYPE_IRQ
:
765 pnp_dbg("Encode irq");
766 pnpacpi_encode_irq(resource
,
767 &res_table
->irq_resource
[irq
]);
771 case ACPI_RSTYPE_EXT_IRQ
:
772 pnp_dbg("Encode ext irq");
773 pnpacpi_encode_ext_irq(resource
,
774 &res_table
->irq_resource
[irq
]);
777 case ACPI_RSTYPE_DMA
:
778 pnp_dbg("Encode dma");
779 pnpacpi_encode_dma(resource
,
780 &res_table
->dma_resource
[dma
]);
784 pnp_dbg("Encode io");
785 pnpacpi_encode_io(resource
,
786 &res_table
->port_resource
[port
]);
789 case ACPI_RSTYPE_FIXED_IO
:
790 pnp_dbg("Encode fixed io");
791 pnpacpi_encode_fixed_io(resource
,
792 &res_table
->port_resource
[port
]);
795 case ACPI_RSTYPE_MEM24
:
796 pnp_dbg("Encode mem24");
797 pnpacpi_encode_mem24(resource
,
798 &res_table
->mem_resource
[mem
]);
801 case ACPI_RSTYPE_MEM32
:
802 pnp_dbg("Encode mem32");
803 pnpacpi_encode_mem32(resource
,
804 &res_table
->mem_resource
[mem
]);
807 case ACPI_RSTYPE_FIXED_MEM32
:
808 pnp_dbg("Encode fixed mem32");
809 pnpacpi_encode_fixed_mem32(resource
,
810 &res_table
->mem_resource
[mem
]);
813 default: /* other type */
814 pnp_warn("unknown resource type %d", resource
->id
);