2 * PCIEHPRM ACPI: PHP Resource Manager for ACPI platform
4 * Copyright (C) 2003-2004 Intel Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
16 * NON INFRINGEMENT. See the GNU General Public License for more
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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Send feedback to <dely.l.sy@intel.com>
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/pci.h>
32 #include <linux/init.h>
33 #include <linux/acpi.h>
34 #include <linux/efi.h>
35 #include <asm/uaccess.h>
36 #include <asm/system.h>
38 #include <asm/iosapic.h>
40 #include <acpi/acpi.h>
41 #include <acpi/acpi_bus.h>
42 #include <acpi/actypes.h>
46 #define PCI_MAX_BUS 0x100
47 #define ACPI_STA_DEVICE_PRESENT 0x01
49 #define METHOD_NAME__SUN "_SUN"
50 #define METHOD_NAME__HPP "_HPP"
51 #define METHOD_NAME_OSHP "OSHP"
53 #define PHP_RES_BUS 0xA0
54 #define PHP_RES_IO 0xA1
55 #define PHP_RES_MEM 0xA2
56 #define PHP_RES_PMEM 0xA3
58 #define BRIDGE_TYPE_P2P 0x00
59 #define BRIDGE_TYPE_HOST 0x01
61 /* this should go to drivers/acpi/include/ */
69 struct acpi_php_slot
{
70 struct acpi_php_slot
*next
;
71 struct acpi_bridge
*bridge
;
78 struct pci_resource
*mem_head
;
79 struct pci_resource
*p_mem_head
;
80 struct pci_resource
*io_head
;
81 struct pci_resource
*bus_head
;
82 void *slot_ops
; /* _STA, _EJx, etc */
87 struct acpi_bridge
*parent
;
88 struct acpi_bridge
*next
;
89 struct acpi_bridge
*child
;
92 int pbus
; /* pdev->bus->number */
93 int pdevice
; /* PCI_SLOT(pdev->devfn) */
94 int pfunction
; /* PCI_DEVFN(pdev->devfn) */
95 int bus
; /* pdev->subordinate->number */
96 struct acpi__hpp
*_hpp
;
97 struct acpi_php_slot
*slots
;
98 struct pci_resource
*tmem_head
; /* total from crs */
99 struct pci_resource
*tp_mem_head
; /* total from crs */
100 struct pci_resource
*tio_head
; /* total from crs */
101 struct pci_resource
*tbus_head
; /* total from crs */
102 struct pci_resource
*mem_head
; /* available */
103 struct pci_resource
*p_mem_head
; /* available */
104 struct pci_resource
*io_head
; /* available */
105 struct pci_resource
*bus_head
; /* available */
110 static struct acpi_bridge
*acpi_bridges_head
;
112 static u8
* acpi_path_name( acpi_handle handle
)
115 static u8 path_name
[ACPI_PATHNAME_MAX
];
116 struct acpi_buffer ret_buf
= { ACPI_PATHNAME_MAX
, path_name
};
118 memset(path_name
, 0, sizeof (path_name
));
119 status
= acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &ret_buf
);
121 if (ACPI_FAILURE(status
))
127 static void acpi_get__hpp ( struct acpi_bridge
*ab
);
128 static void acpi_run_oshp ( struct acpi_bridge
*ab
);
130 static int acpi_add_slot_to_php_slots(
131 struct acpi_bridge
*ab
,
138 struct acpi_php_slot
*aps
;
139 static long samesun
= -1;
141 aps
= (struct acpi_php_slot
*) kmalloc (sizeof(struct acpi_php_slot
), GFP_KERNEL
);
143 err ("acpi_pciehprm: alloc for aps fail\n");
146 memset(aps
, 0, sizeof(struct acpi_php_slot
));
148 aps
->handle
= handle
;
150 aps
->dev
= (adr
>> 16) & 0xffff;
151 aps
->fun
= adr
& 0xffff;
154 aps
->next
= ab
->slots
; /* cling to the bridge */
164 if (sun
!= samesun
) {
165 info("acpi_pciehprm: Slot sun(%x) at s:b:d:f=0x%02x:%02x:%02x:%02x\n",
166 aps
->sun
, ab
->seg
, aps
->bus
, aps
->dev
, aps
->fun
);
172 static void acpi_get__hpp ( struct acpi_bridge
*ab
)
176 struct acpi_buffer ret_buf
= { 0, NULL
};
177 union acpi_object
*ext_obj
, *package
;
178 u8
*path_name
= acpi_path_name(ab
->handle
);
182 status
= acpi_evaluate_object(ab
->handle
, METHOD_NAME__HPP
, NULL
, &ret_buf
);
184 case AE_BUFFER_OVERFLOW
:
185 ret_buf
.pointer
= kmalloc (ret_buf
.length
, GFP_KERNEL
);
186 if (!ret_buf
.pointer
) {
187 err ("acpi_pciehprm:%s alloc for _HPP fail\n", path_name
);
190 status
= acpi_evaluate_object(ab
->handle
, METHOD_NAME__HPP
, NULL
, &ret_buf
);
191 if (ACPI_SUCCESS(status
))
194 if (ACPI_FAILURE(status
)) {
195 err("acpi_pciehprm:%s _HPP fail=0x%x\n", path_name
, status
);
200 ext_obj
= (union acpi_object
*) ret_buf
.pointer
;
201 if (ext_obj
->type
!= ACPI_TYPE_PACKAGE
) {
202 err ("acpi_pciehprm:%s _HPP obj not a package\n", path_name
);
203 goto free_and_return
;
206 len
= ext_obj
->package
.count
;
207 package
= (union acpi_object
*) ret_buf
.pointer
;
208 for ( i
= 0; (i
< len
) || (i
< 4); i
++) {
209 ext_obj
= (union acpi_object
*) &package
->package
.elements
[i
];
210 switch (ext_obj
->type
) {
211 case ACPI_TYPE_INTEGER
:
212 nui
[i
] = (u8
)ext_obj
->integer
.value
;
215 err ("acpi_pciehprm:%s _HPP obj type incorrect\n", path_name
);
216 goto free_and_return
;
220 ab
->_hpp
= kmalloc (sizeof (struct acpi__hpp
), GFP_KERNEL
);
222 err ("acpi_pciehprm:%s alloc for _HPP failed\n", path_name
);
223 goto free_and_return
;
225 memset(ab
->_hpp
, 0, sizeof(struct acpi__hpp
));
227 ab
->_hpp
->cache_line_size
= nui
[0];
228 ab
->_hpp
->latency_timer
= nui
[1];
229 ab
->_hpp
->enable_serr
= nui
[2];
230 ab
->_hpp
->enable_perr
= nui
[3];
232 dbg(" _HPP: cache_line_size=0x%x\n", ab
->_hpp
->cache_line_size
);
233 dbg(" _HPP: latency timer =0x%x\n", ab
->_hpp
->latency_timer
);
234 dbg(" _HPP: enable SERR =0x%x\n", ab
->_hpp
->enable_serr
);
235 dbg(" _HPP: enable PERR =0x%x\n", ab
->_hpp
->enable_perr
);
238 kfree(ret_buf
.pointer
);
241 static void acpi_run_oshp ( struct acpi_bridge
*ab
)
244 u8
*path_name
= acpi_path_name(ab
->handle
);
245 struct acpi_buffer ret_buf
= { 0, NULL
};
248 status
= acpi_evaluate_object(ab
->handle
, METHOD_NAME_OSHP
, NULL
, &ret_buf
);
249 if (ACPI_FAILURE(status
)) {
250 err("acpi_pciehprm:%s OSHP fails=0x%x\n", path_name
, status
);
252 dbg("acpi_pciehprm:%s OSHP passes =0x%x\n", path_name
, status
);
256 static acpi_status
acpi_evaluate_crs(
258 struct acpi_resource
**retbuf
262 struct acpi_buffer crsbuf
;
263 u8
*path_name
= acpi_path_name(handle
);
266 crsbuf
.pointer
= NULL
;
268 status
= acpi_get_current_resources (handle
, &crsbuf
);
271 case AE_BUFFER_OVERFLOW
:
274 dbg("acpi_pciehprm:%s _CRS not found\n", path_name
);
277 err ("acpi_pciehprm:%s _CRS fail=0x%x\n", path_name
, status
);
281 crsbuf
.pointer
= kmalloc (crsbuf
.length
, GFP_KERNEL
);
282 if (!crsbuf
.pointer
) {
283 err ("acpi_pciehprm: alloc %ld bytes for %s _CRS fail\n", (ulong
)crsbuf
.length
, path_name
);
287 status
= acpi_get_current_resources (handle
, &crsbuf
);
288 if (ACPI_FAILURE(status
)) {
289 err("acpi_pciehprm: %s _CRS fail=0x%x.\n", path_name
, status
);
290 kfree(crsbuf
.pointer
);
294 *retbuf
= crsbuf
.pointer
;
299 static void free_pci_resource ( struct pci_resource
*aprh
)
301 struct pci_resource
*res
, *next
;
303 for (res
= aprh
; res
; res
= next
) {
309 static void print_pci_resource ( struct pci_resource
*aprh
)
311 struct pci_resource
*res
;
313 for (res
= aprh
; res
; res
= res
->next
)
314 dbg(" base= 0x%x length= 0x%x\n", res
->base
, res
->length
);
317 static void print_slot_resources( struct acpi_php_slot
*aps
)
320 dbg(" BUS Resources:\n");
321 print_pci_resource (aps
->bus_head
);
325 dbg(" IO Resources:\n");
326 print_pci_resource (aps
->io_head
);
330 dbg(" MEM Resources:\n");
331 print_pci_resource (aps
->mem_head
);
334 if (aps
->p_mem_head
) {
335 dbg(" PMEM Resources:\n");
336 print_pci_resource (aps
->p_mem_head
);
340 static void print_pci_resources( struct acpi_bridge
*ab
)
343 dbg(" Total BUS Resources:\n");
344 print_pci_resource (ab
->tbus_head
);
347 dbg(" BUS Resources:\n");
348 print_pci_resource (ab
->bus_head
);
352 dbg(" Total IO Resources:\n");
353 print_pci_resource (ab
->tio_head
);
356 dbg(" IO Resources:\n");
357 print_pci_resource (ab
->io_head
);
361 dbg(" Total MEM Resources:\n");
362 print_pci_resource (ab
->tmem_head
);
365 dbg(" MEM Resources:\n");
366 print_pci_resource (ab
->mem_head
);
369 if (ab
->tp_mem_head
) {
370 dbg(" Total PMEM Resources:\n");
371 print_pci_resource (ab
->tp_mem_head
);
373 if (ab
->p_mem_head
) {
374 dbg(" PMEM Resources:\n");
375 print_pci_resource (ab
->p_mem_head
);
378 dbg(" _HPP: cache_line_size=0x%x\n", ab
->_hpp
->cache_line_size
);
379 dbg(" _HPP: latency timer =0x%x\n", ab
->_hpp
->latency_timer
);
380 dbg(" _HPP: enable SERR =0x%x\n", ab
->_hpp
->enable_serr
);
381 dbg(" _HPP: enable PERR =0x%x\n", ab
->_hpp
->enable_perr
);
385 static int pciehprm_delete_resource(
386 struct pci_resource
**aprh
,
390 struct pci_resource
*res
;
391 struct pci_resource
*prevnode
;
392 struct pci_resource
*split_node
;
395 pciehp_resource_sort_and_combine(aprh
);
397 for (res
= *aprh
; res
; res
= res
->next
) {
398 if (res
->base
> base
)
401 if ((res
->base
+ res
->length
) < (base
+ size
))
404 if (res
->base
< base
) {
407 if ((res
->length
- (tbase
- res
->base
)) < size
)
410 split_node
= (struct pci_resource
*) kmalloc(sizeof(struct pci_resource
), GFP_KERNEL
);
414 split_node
->base
= res
->base
;
415 split_node
->length
= tbase
- res
->base
;
417 res
->length
-= split_node
->length
;
419 split_node
->next
= res
->next
;
420 res
->next
= split_node
;
423 if (res
->length
>= size
) {
424 split_node
= (struct pci_resource
*) kmalloc(sizeof(struct pci_resource
), GFP_KERNEL
);
428 split_node
->base
= res
->base
+ size
;
429 split_node
->length
= res
->length
- size
;
432 split_node
->next
= res
->next
;
433 res
->next
= split_node
;
440 while (prevnode
->next
!= res
)
441 prevnode
= prevnode
->next
;
443 prevnode
->next
= res
->next
;
453 static int pciehprm_delete_resources(
454 struct pci_resource
**aprh
,
455 struct pci_resource
*this
458 struct pci_resource
*res
;
460 for (res
= this; res
; res
= res
->next
)
461 pciehprm_delete_resource(aprh
, res
->base
, res
->length
);
466 static int pciehprm_add_resource(
467 struct pci_resource
**aprh
,
471 struct pci_resource
*res
;
473 for (res
= *aprh
; res
; res
= res
->next
) {
474 if ((res
->base
+ res
->length
) == base
) {
479 if (res
->next
== *aprh
)
484 res
= kmalloc(sizeof(struct pci_resource
), GFP_KERNEL
);
486 err ("acpi_pciehprm: alloc for res fail\n");
489 memset(res
, 0, sizeof (struct pci_resource
));
500 static int pciehprm_add_resources(
501 struct pci_resource
**aprh
,
502 struct pci_resource
*this
505 struct pci_resource
*res
;
508 for (res
= this; res
&& !rc
; res
= res
->next
)
509 rc
= pciehprm_add_resource(aprh
, res
->base
, res
->length
);
514 static void acpi_parse_io (
515 struct acpi_bridge
*ab
,
516 union acpi_resource_data
*data
519 struct acpi_resource_io
*dataio
;
520 dataio
= (struct acpi_resource_io
*) data
;
522 dbg("Io Resource\n");
523 dbg(" %d bit decode\n", ACPI_DECODE_16
== dataio
->io_decode
? 16:10);
524 dbg(" Range minimum base: %08X\n", dataio
->min_base_address
);
525 dbg(" Range maximum base: %08X\n", dataio
->max_base_address
);
526 dbg(" Alignment: %08X\n", dataio
->alignment
);
527 dbg(" Range Length: %08X\n", dataio
->range_length
);
530 static void acpi_parse_fixed_io (
531 struct acpi_bridge
*ab
,
532 union acpi_resource_data
*data
535 struct acpi_resource_fixed_io
*datafio
;
536 datafio
= (struct acpi_resource_fixed_io
*) data
;
538 dbg("Fixed Io Resource\n");
539 dbg(" Range base address: %08X", datafio
->base_address
);
540 dbg(" Range length: %08X", datafio
->range_length
);
543 static void acpi_parse_address16_32 (
544 struct acpi_bridge
*ab
,
545 union acpi_resource_data
*data
,
546 acpi_resource_type id
550 * acpi_resource_address16 == acpi_resource_address32
551 * acpi_resource_address16 *data16 = (acpi_resource_address16 *) data;
553 struct acpi_resource_address32
*data32
= (struct acpi_resource_address32
*) data
;
554 struct pci_resource
**aprh
, **tprh
;
556 if (id
== ACPI_RSTYPE_ADDRESS16
)
557 dbg("acpi_pciehprm:16-Bit Address Space Resource\n");
559 dbg("acpi_pciehprm:32-Bit Address Space Resource\n");
561 switch (data32
->resource_type
) {
562 case ACPI_MEMORY_RANGE
:
563 dbg(" Resource Type: Memory Range\n");
564 aprh
= &ab
->mem_head
;
565 tprh
= &ab
->tmem_head
;
567 switch (data32
->attribute
.memory
.cache_attribute
) {
568 case ACPI_NON_CACHEABLE_MEMORY
:
569 dbg(" Type Specific: Noncacheable memory\n");
571 case ACPI_CACHABLE_MEMORY
:
572 dbg(" Type Specific: Cacheable memory\n");
574 case ACPI_WRITE_COMBINING_MEMORY
:
575 dbg(" Type Specific: Write-combining memory\n");
577 case ACPI_PREFETCHABLE_MEMORY
:
578 aprh
= &ab
->p_mem_head
;
579 dbg(" Type Specific: Prefetchable memory\n");
582 dbg(" Type Specific: Invalid cache attribute\n");
586 dbg(" Type Specific: Read%s\n", ACPI_READ_WRITE_MEMORY
== data32
->attribute
.memory
.read_write_attribute
? "/Write":" Only");
590 dbg(" Resource Type: I/O Range\n");
592 tprh
= &ab
->tio_head
;
594 switch (data32
->attribute
.io
.range_attribute
) {
595 case ACPI_NON_ISA_ONLY_RANGES
:
596 dbg(" Type Specific: Non-ISA Io Addresses\n");
598 case ACPI_ISA_ONLY_RANGES
:
599 dbg(" Type Specific: ISA Io Addresses\n");
601 case ACPI_ENTIRE_RANGE
:
602 dbg(" Type Specific: ISA and non-ISA Io Addresses\n");
605 dbg(" Type Specific: Invalid range attribute\n");
610 case ACPI_BUS_NUMBER_RANGE
:
611 dbg(" Resource Type: Bus Number Range(fixed)\n");
612 /* fixup to be compatible with the rest of php driver */
613 data32
->min_address_range
++;
614 data32
->address_length
--;
615 aprh
= &ab
->bus_head
;
616 tprh
= &ab
->tbus_head
;
619 dbg(" Resource Type: Invalid resource type. Exiting.\n");
623 dbg(" Resource %s\n", ACPI_CONSUMER
== data32
->producer_consumer
? "Consumer":"Producer");
624 dbg(" %s decode\n", ACPI_SUB_DECODE
== data32
->decode
? "Subtractive":"Positive");
625 dbg(" Min address is %s fixed\n", ACPI_ADDRESS_FIXED
== data32
->min_address_fixed
? "":"not");
626 dbg(" Max address is %s fixed\n", ACPI_ADDRESS_FIXED
== data32
->max_address_fixed
? "":"not");
627 dbg(" Granularity: %08X\n", data32
->granularity
);
628 dbg(" Address range min: %08X\n", data32
->min_address_range
);
629 dbg(" Address range max: %08X\n", data32
->max_address_range
);
630 dbg(" Address translation offset: %08X\n", data32
->address_translation_offset
);
631 dbg(" Address Length: %08X\n", data32
->address_length
);
633 if (0xFF != data32
->resource_source
.index
) {
634 dbg(" Resource Source Index: %X\n", data32
->resource_source
.index
);
635 /* dbg(" Resource Source: %s\n", data32->resource_source.string_ptr); */
638 pciehprm_add_resource(aprh
, data32
->min_address_range
, data32
->address_length
);
641 static acpi_status
acpi_parse_crs(
642 struct acpi_bridge
*ab
,
643 struct acpi_resource
*crsbuf
646 acpi_status status
= AE_OK
;
647 struct acpi_resource
*resource
= crsbuf
;
652 dbg("acpi_pciehprm: PCI bus 0x%x Resource structure %x.\n", ab
->bus
, count
++);
653 switch (resource
->id
) {
654 case ACPI_RSTYPE_IRQ
:
655 dbg("Irq -------- Resource\n");
657 case ACPI_RSTYPE_DMA
:
658 dbg("DMA -------- Resource\n");
660 case ACPI_RSTYPE_START_DPF
:
661 dbg("Start DPF -------- Resource\n");
663 case ACPI_RSTYPE_END_DPF
:
664 dbg("End DPF -------- Resource\n");
667 acpi_parse_io (ab
, &resource
->data
);
669 case ACPI_RSTYPE_FIXED_IO
:
670 acpi_parse_fixed_io (ab
, &resource
->data
);
672 case ACPI_RSTYPE_VENDOR
:
673 dbg("Vendor -------- Resource\n");
675 case ACPI_RSTYPE_END_TAG
:
676 dbg("End_tag -------- Resource\n");
679 case ACPI_RSTYPE_MEM24
:
680 dbg("Mem24 -------- Resource\n");
682 case ACPI_RSTYPE_MEM32
:
683 dbg("Mem32 -------- Resource\n");
685 case ACPI_RSTYPE_FIXED_MEM32
:
686 dbg("Fixed Mem32 -------- Resource\n");
688 case ACPI_RSTYPE_ADDRESS16
:
689 acpi_parse_address16_32(ab
, &resource
->data
, ACPI_RSTYPE_ADDRESS16
);
691 case ACPI_RSTYPE_ADDRESS32
:
692 acpi_parse_address16_32(ab
, &resource
->data
, ACPI_RSTYPE_ADDRESS32
);
694 case ACPI_RSTYPE_ADDRESS64
:
695 info("Address64 -------- Resource unparsed\n");
697 case ACPI_RSTYPE_EXT_IRQ
:
698 dbg("Ext Irq -------- Resource\n");
701 dbg("Invalid -------- resource type 0x%x\n", resource
->id
);
705 resource
= (struct acpi_resource
*) ((char *)resource
+ resource
->length
);
711 static acpi_status
acpi_get_crs( struct acpi_bridge
*ab
)
714 struct acpi_resource
*crsbuf
;
716 status
= acpi_evaluate_crs(ab
->handle
, &crsbuf
);
717 if (ACPI_SUCCESS(status
)) {
718 status
= acpi_parse_crs(ab
, crsbuf
);
721 pciehp_resource_sort_and_combine(&ab
->bus_head
);
722 pciehp_resource_sort_and_combine(&ab
->io_head
);
723 pciehp_resource_sort_and_combine(&ab
->mem_head
);
724 pciehp_resource_sort_and_combine(&ab
->p_mem_head
);
726 pciehprm_add_resources (&ab
->tbus_head
, ab
->bus_head
);
727 pciehprm_add_resources (&ab
->tio_head
, ab
->io_head
);
728 pciehprm_add_resources (&ab
->tmem_head
, ab
->mem_head
);
729 pciehprm_add_resources (&ab
->tp_mem_head
, ab
->p_mem_head
);
735 /* find acpi_bridge downword from ab. */
736 static struct acpi_bridge
*
737 find_acpi_bridge_by_bus(
738 struct acpi_bridge
*ab
,
740 int bus
/* pdev->subordinate->number */
743 struct acpi_bridge
*lab
= NULL
;
748 if ((ab
->bus
== bus
) && (ab
->seg
== seg
))
752 lab
= find_acpi_bridge_by_bus(ab
->child
, seg
, bus
);
756 lab
= find_acpi_bridge_by_bus(ab
->next
, seg
, bus
);
762 * Build a device tree of ACPI PCI Bridges
764 static void pciehprm_acpi_register_a_bridge (
765 struct acpi_bridge
**head
,
766 struct acpi_bridge
*pab
, /* parent bridge to which child bridge is added */
767 struct acpi_bridge
*cab
/* child bridge to add */
770 struct acpi_bridge
*lpab
;
771 struct acpi_bridge
*lcab
;
773 lpab
= find_acpi_bridge_by_bus(*head
, pab
->seg
, pab
->bus
);
775 if (!(pab
->type
& BRIDGE_TYPE_HOST
))
776 warn("PCI parent bridge s:b(%x:%x) not in list.\n", pab
->seg
, pab
->bus
);
782 if ((cab
->type
& BRIDGE_TYPE_HOST
) && (pab
== cab
))
785 lcab
= find_acpi_bridge_by_bus(*head
, cab
->seg
, cab
->bus
);
787 if ((pab
->bus
!= lcab
->parent
->bus
) || (lcab
->bus
!= cab
->bus
))
788 err("PCI child bridge s:b(%x:%x) in list with diff parent.\n", cab
->seg
, cab
->bus
);
794 lcab
->next
= lpab
->child
;
798 static acpi_status
pciehprm_acpi_build_php_slots_callback(
809 acpi_handle phandle
= NULL
;
810 struct acpi_bridge
*pab
= (struct acpi_bridge
*)context
;
811 struct acpi_bridge
*lab
;
813 u8
*path_name
= acpi_path_name(handle
);
816 status
= acpi_evaluate_integer(handle
, METHOD_NAME__SUN
, NULL
, &sun
);
821 if (ACPI_FAILURE(status
)) {
822 err("acpi_pciehprm:%s _SUN fail=0x%x\n", path_name
, status
);
827 /* get _ADR. _ADR must exist if _SUN exists */
828 status
= acpi_evaluate_integer(handle
, METHOD_NAME__ADR
, NULL
, &adr
);
829 if (ACPI_FAILURE(status
)) {
830 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name
, status
);
834 dbg("acpi_pciehprm:%s sun=0x%08x adr=0x%08x\n", path_name
, (u32
)sun
, (u32
)adr
);
836 status
= acpi_get_parent(handle
, &phandle
);
837 if (ACPI_FAILURE(status
)) {
838 err("acpi_pciehprm:%s get_parent fail=0x%x\n", path_name
, status
);
845 if (pab
->bus
== bus_num
) {
848 dbg("WARN: pab is not parent\n");
849 lab
= find_acpi_bridge_by_bus(pab
, seg_num
, bus_num
);
851 dbg("acpi_pciehprm: alloc new P2P bridge(%x) for sun(%08x)\n", (u32
)bus_num
, (u32
)sun
);
852 lab
= (struct acpi_bridge
*)kmalloc(sizeof(struct acpi_bridge
), GFP_KERNEL
);
854 err("acpi_pciehprm: alloc for ab fail\n");
857 memset(lab
, 0, sizeof(struct acpi_bridge
));
859 lab
->handle
= phandle
;
860 lab
->pbus
= pab
->bus
;
861 lab
->pdevice
= (int)(padr
>> 16) & 0xffff;
862 lab
->pfunction
= (int)(padr
& 0xffff);
863 lab
->bus
= (int)bus_num
;
865 lab
->type
= BRIDGE_TYPE_P2P
;
867 pciehprm_acpi_register_a_bridge (&acpi_bridges_head
, pab
, lab
);
869 dbg("acpi_pciehprm: found P2P bridge(%x) for sun(%08x)\n", (u32
)bus_num
, (u32
)sun
);
872 acpi_add_slot_to_php_slots(lab
, (int)bus_num
, handle
, (u32
)adr
, (u32
)sun
);
877 static int pciehprm_acpi_build_php_slots(
878 struct acpi_bridge
*ab
,
883 u8
*path_name
= acpi_path_name(ab
->handle
);
885 /* Walk down this pci bridge to get _SUNs if any behind P2P */
886 status
= acpi_walk_namespace ( ACPI_TYPE_DEVICE
,
889 pciehprm_acpi_build_php_slots_callback
,
892 if (ACPI_FAILURE(status
)) {
893 dbg("acpi_pciehprm:%s walk for _SUN on pci bridge seg:bus(%x:%x) fail=0x%x\n", path_name
, ab
->seg
, ab
->bus
, status
);
900 static void build_a_bridge(
901 struct acpi_bridge
*pab
,
902 struct acpi_bridge
*ab
905 u8
*path_name
= acpi_path_name(ab
->handle
);
907 pciehprm_acpi_register_a_bridge (&acpi_bridges_head
, pab
, ab
);
910 case BRIDGE_TYPE_HOST
:
911 dbg("acpi_pciehprm: Registered PCI HOST Bridge(%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
912 ab
->bus
, ab
->seg
, ab
->pbus
, ab
->pdevice
, ab
->pfunction
, path_name
);
914 case BRIDGE_TYPE_P2P
:
915 dbg("acpi_pciehprm: Registered PCI P2P Bridge(%02x-%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
916 ab
->pbus
, ab
->bus
, ab
->seg
, ab
->pbus
, ab
->pdevice
, ab
->pfunction
, path_name
);
920 /* build any immediate PHP slots under this pci bridge */
921 pciehprm_acpi_build_php_slots(ab
, 1);
924 static struct acpi_bridge
* add_p2p_bridge(
926 struct acpi_bridge
*pab
, /* parent */
930 struct acpi_bridge
*ab
;
931 struct pci_dev
*pdev
;
932 ulong devnum
, funcnum
;
933 u8
*path_name
= acpi_path_name(handle
);
935 ab
= (struct acpi_bridge
*) kmalloc (sizeof(struct acpi_bridge
), GFP_KERNEL
);
937 err("acpi_pciehprm: alloc for ab fail\n");
940 memset(ab
, 0, sizeof(struct acpi_bridge
));
942 devnum
= (adr
>> 16) & 0xffff;
943 funcnum
= adr
& 0xffff;
945 pdev
= pci_find_slot(pab
->bus
, PCI_DEVFN(devnum
, funcnum
));
946 if (!pdev
|| !pdev
->subordinate
) {
947 err("acpi_pciehprm:%s is not a P2P Bridge\n", path_name
);
954 ab
->pbus
= pab
->bus
; /* or pdev->bus->number */
955 ab
->pdevice
= devnum
; /* or PCI_SLOT(pdev->devfn) */
956 ab
->pfunction
= funcnum
; /* or PCI_FUNC(pdev->devfn) */
957 ab
->bus
= pdev
->subordinate
->number
;
959 ab
->type
= BRIDGE_TYPE_P2P
;
961 dbg("acpi_pciehprm: P2P(%x-%x) on pci=b:d:f(%x:%x:%x) acpi=b:d:f(%x:%x:%x) [%s]\n",
962 pab
->bus
, ab
->bus
, pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
),
963 pab
->bus
, (u32
)devnum
, (u32
)funcnum
, path_name
);
965 build_a_bridge(pab
, ab
);
970 static acpi_status
scan_p2p_bridge(
977 struct acpi_bridge
*pab
= (struct acpi_bridge
*)context
;
978 struct acpi_bridge
*ab
;
981 u8
*path_name
= acpi_path_name(handle
);
982 ulong devnum
, funcnum
;
983 struct pci_dev
*pdev
;
985 /* get device, function */
986 status
= acpi_evaluate_integer(handle
, METHOD_NAME__ADR
, NULL
, &adr
);
987 if (ACPI_FAILURE(status
)) {
988 if (status
!= AE_NOT_FOUND
)
989 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name
, status
);
993 devnum
= (adr
>> 16) & 0xffff;
994 funcnum
= adr
& 0xffff;
996 pdev
= pci_find_slot(pab
->bus
, PCI_DEVFN(devnum
, funcnum
));
999 if (!pdev
->subordinate
)
1002 ab
= add_p2p_bridge(handle
, pab
, adr
);
1004 status
= acpi_walk_namespace ( ACPI_TYPE_DEVICE
,
1010 if (ACPI_FAILURE(status
))
1011 dbg("acpi_pciehprm:%s find_p2p fail=0x%x\n", path_name
, status
);
1017 static struct acpi_bridge
* add_host_bridge(
1025 struct acpi_bridge
*ab
;
1026 u8
*path_name
= acpi_path_name(handle
);
1028 /* get device, function: host br adr is always 0000 though. */
1029 status
= acpi_evaluate_integer(handle
, METHOD_NAME__ADR
, NULL
, &adr
);
1030 if (ACPI_FAILURE(status
)) {
1031 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name
, status
);
1034 dbg("acpi_pciehprm: ROOT PCI seg(0x%x)bus(0x%x)dev(0x%x)func(0x%x) [%s]\n", (u32
)segnum
,
1035 (u32
)busnum
, (u32
)(adr
>> 16) & 0xffff, (u32
)adr
& 0xffff, path_name
);
1037 ab
= (struct acpi_bridge
*) kmalloc (sizeof(struct acpi_bridge
), GFP_KERNEL
);
1039 err("acpi_pciehprm: alloc for ab fail\n");
1042 memset(ab
, 0, sizeof(struct acpi_bridge
));
1044 ab
->handle
= handle
;
1045 ab
->seg
= (int)segnum
;
1046 ab
->bus
= ab
->pbus
= (int)busnum
;
1047 ab
->pdevice
= (int)(adr
>> 16) & 0xffff;
1048 ab
->pfunction
= (int)(adr
& 0xffff);
1050 ab
->type
= BRIDGE_TYPE_HOST
;
1052 /* get root pci bridge's current resources */
1053 status
= acpi_get_crs(ab
);
1054 if (ACPI_FAILURE(status
)) {
1055 err("acpi_pciehprm:%s evaluate _CRS fail=0x%x\n", path_name
, status
);
1059 build_a_bridge(ab
, ab
);
1064 static acpi_status
acpi_scan_from_root_pci_callback (
1074 struct acpi_bridge
*ab
;
1075 u8
*path_name
= acpi_path_name(handle
);
1077 /* get bus number of this pci root bridge */
1078 status
= acpi_evaluate_integer(handle
, METHOD_NAME__SEG
, NULL
, &segnum
);
1079 if (ACPI_FAILURE(status
)) {
1080 if (status
!= AE_NOT_FOUND
) {
1081 err("acpi_pciehprm:%s evaluate _SEG fail=0x%x\n", path_name
, status
);
1087 /* get bus number of this pci root bridge */
1088 status
= acpi_evaluate_integer(handle
, METHOD_NAME__BBN
, NULL
, &busnum
);
1089 if (ACPI_FAILURE(status
)) {
1090 err("acpi_pciehprm:%s evaluate _BBN fail=0x%x\n", path_name
, status
);
1094 ab
= add_host_bridge(handle
, segnum
, busnum
);
1096 status
= acpi_walk_namespace ( ACPI_TYPE_DEVICE
,
1102 if (ACPI_FAILURE(status
))
1103 dbg("acpi_pciehprm:%s find_p2p fail=0x%x\n", path_name
, status
);
1109 static int pciehprm_acpi_scan_pci (void)
1114 * TBD: traverse LDM device tree with the help of
1115 * unified ACPI augmented for php device population.
1117 status
= acpi_get_devices ( PCI_ROOT_HID_STRING
,
1118 acpi_scan_from_root_pci_callback
,
1121 if (ACPI_FAILURE(status
)) {
1122 err("acpi_pciehprm:get_device PCI ROOT HID fail=0x%x\n", status
);
1129 int pciehprm_init(enum php_ctlr_type ctlr_type
)
1133 if (ctlr_type
!= PCI
)
1136 dbg("pciehprm ACPI init <enter>\n");
1137 acpi_bridges_head
= NULL
;
1139 /* construct PCI bus:device tree of acpi_handles */
1140 rc
= pciehprm_acpi_scan_pci();
1144 dbg("pciehprm ACPI init %s\n", (rc
)?"fail":"success");
1148 static void free_a_slot(struct acpi_php_slot
*aps
)
1150 dbg(" free a php func of slot(0x%02x) on PCI b:d:f=0x%02x:%02x:%02x\n", aps
->sun
, aps
->bus
, aps
->dev
, aps
->fun
);
1152 free_pci_resource (aps
->io_head
);
1153 free_pci_resource (aps
->bus_head
);
1154 free_pci_resource (aps
->mem_head
);
1155 free_pci_resource (aps
->p_mem_head
);
1160 static void free_a_bridge( struct acpi_bridge
*ab
)
1162 struct acpi_php_slot
*aps
, *next
;
1165 case BRIDGE_TYPE_HOST
:
1166 dbg("Free ACPI PCI HOST Bridge(%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
1167 ab
->bus
, acpi_path_name(ab
->handle
), ab
->seg
, ab
->pbus
, ab
->pdevice
, ab
->pfunction
);
1169 case BRIDGE_TYPE_P2P
:
1170 dbg("Free ACPI PCI P2P Bridge(%x-%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
1171 ab
->pbus
, ab
->bus
, acpi_path_name(ab
->handle
), ab
->seg
, ab
->pbus
, ab
->pdevice
, ab
->pfunction
);
1175 /* free slots first */
1176 for (aps
= ab
->slots
; aps
; aps
= next
) {
1181 free_pci_resource (ab
->io_head
);
1182 free_pci_resource (ab
->tio_head
);
1183 free_pci_resource (ab
->bus_head
);
1184 free_pci_resource (ab
->tbus_head
);
1185 free_pci_resource (ab
->mem_head
);
1186 free_pci_resource (ab
->tmem_head
);
1187 free_pci_resource (ab
->p_mem_head
);
1188 free_pci_resource (ab
->tp_mem_head
);
1193 static void pciehprm_free_bridges ( struct acpi_bridge
*ab
)
1199 pciehprm_free_bridges (ab
->child
);
1202 pciehprm_free_bridges (ab
->next
);
1207 void pciehprm_cleanup(void)
1209 pciehprm_free_bridges (acpi_bridges_head
);
1212 static int get_number_of_slots (
1213 struct acpi_bridge
*ab
,
1217 struct acpi_php_slot
*aps
;
1221 for ( aps
= ab
->slots
; aps
; aps
= aps
->next
)
1222 if (aps
->dev
!= prev_slot
) {
1223 prev_slot
= aps
->dev
;
1228 slot_num
+= get_number_of_slots (ab
->child
, 0);
1234 slot_num
+= get_number_of_slots (ab
->next
, 0);
1239 static int print_acpi_resources (struct acpi_bridge
*ab
)
1241 struct acpi_php_slot
*aps
;
1245 case BRIDGE_TYPE_HOST
:
1246 dbg("PCI HOST Bridge (%x) [%s]\n", ab
->bus
, acpi_path_name(ab
->handle
));
1248 case BRIDGE_TYPE_P2P
:
1249 dbg("PCI P2P Bridge (%x-%x) [%s]\n", ab
->pbus
, ab
->bus
, acpi_path_name(ab
->handle
));
1253 print_pci_resources (ab
);
1255 for ( i
= -1, aps
= ab
->slots
; aps
; aps
= aps
->next
) {
1258 dbg(" Slot sun(%x) s:b:d:f(%02x:%02x:%02x:%02x)\n", aps
->sun
, aps
->seg
, aps
->bus
, aps
->dev
, aps
->fun
);
1259 print_slot_resources(aps
);
1264 print_acpi_resources (ab
->child
);
1267 print_acpi_resources (ab
->next
);
1272 int pciehprm_print_pirt(void)
1274 dbg("PCIEHPRM ACPI Slots\n");
1275 if (acpi_bridges_head
)
1276 print_acpi_resources (acpi_bridges_head
);
1281 static struct acpi_php_slot
* get_acpi_slot (
1282 struct acpi_bridge
*ab
,
1286 struct acpi_php_slot
*aps
= NULL
;
1288 for ( aps
= ab
->slots
; aps
; aps
= aps
->next
)
1289 if (aps
->sun
== sun
)
1292 if (!aps
&& ab
->child
) {
1293 aps
= (struct acpi_php_slot
*)get_acpi_slot (ab
->child
, sun
);
1298 if (!aps
&& ab
->next
) {
1299 aps
= (struct acpi_php_slot
*)get_acpi_slot (ab
->next
, sun
);
1309 void * pciehprm_get_slot(struct slot
*slot
)
1311 struct acpi_bridge
*ab
= acpi_bridges_head
;
1312 struct acpi_php_slot
*aps
= get_acpi_slot (ab
, slot
->number
);
1316 dbg("Got acpi slot sun(%x): s:b:d:f(%x:%x:%x:%x)\n", aps
->sun
, aps
->seg
, aps
->bus
, aps
->dev
, aps
->fun
);
1322 static void pciehprm_dump_func_res( struct pci_func
*fun
)
1324 struct pci_func
*func
= fun
;
1326 if (func
->bus_head
) {
1327 dbg(": BUS Resources:\n");
1328 print_pci_resource (func
->bus_head
);
1330 if (func
->io_head
) {
1331 dbg(": IO Resources:\n");
1332 print_pci_resource (func
->io_head
);
1334 if (func
->mem_head
) {
1335 dbg(": MEM Resources:\n");
1336 print_pci_resource (func
->mem_head
);
1338 if (func
->p_mem_head
) {
1339 dbg(": PMEM Resources:\n");
1340 print_pci_resource (func
->p_mem_head
);
1344 static void pciehprm_dump_ctrl_res( struct controller
*ctlr
)
1346 struct controller
*ctrl
= ctlr
;
1348 if (ctrl
->bus_head
) {
1349 dbg(": BUS Resources:\n");
1350 print_pci_resource (ctrl
->bus_head
);
1352 if (ctrl
->io_head
) {
1353 dbg(": IO Resources:\n");
1354 print_pci_resource (ctrl
->io_head
);
1356 if (ctrl
->mem_head
) {
1357 dbg(": MEM Resources:\n");
1358 print_pci_resource (ctrl
->mem_head
);
1360 if (ctrl
->p_mem_head
) {
1361 dbg(": PMEM Resources:\n");
1362 print_pci_resource (ctrl
->p_mem_head
);
1366 static int pciehprm_get_used_resources (
1367 struct controller
*ctrl
,
1368 struct pci_func
*func
1371 return pciehp_save_used_resources (ctrl
, func
, !DISABLE_CARD
);
1374 static int configure_existing_function(
1375 struct controller
*ctrl
,
1376 struct pci_func
*func
1381 /* see how much resources the func has used. */
1382 rc
= pciehprm_get_used_resources (ctrl
, func
);
1385 /* subtract the resources used by the func from ctrl resources */
1386 rc
= pciehprm_delete_resources (&ctrl
->bus_head
, func
->bus_head
);
1387 rc
|= pciehprm_delete_resources (&ctrl
->io_head
, func
->io_head
);
1388 rc
|= pciehprm_delete_resources (&ctrl
->mem_head
, func
->mem_head
);
1389 rc
|= pciehprm_delete_resources (&ctrl
->p_mem_head
, func
->p_mem_head
);
1391 warn("aCEF: cannot del used resources\n");
1393 err("aCEF: cannot get used resources\n");
1398 static int bind_pci_resources_to_slots ( struct controller
*ctrl
)
1400 struct pci_func
*func
, new_func
;
1401 int busn
= ctrl
->slot_bus
;
1405 for (devn
= 0; devn
< 32; devn
++) {
1406 for (funn
= 0; funn
< 8; funn
++) {
1408 if (devn == ctrl->device && funn == ctrl->function)
1411 /* find out if this entry is for an occupied slot */
1413 pci_bus_read_config_dword(ctrl
->pci_dev
->subordinate
, PCI_DEVFN(devn
, funn
), PCI_VENDOR_ID
, &vid
);
1415 if (vid
!= 0xFFFFFFFF) {
1416 dbg("%s: vid = %x\n", __FUNCTION__
, vid
);
1417 func
= pciehp_slot_find(busn
, devn
, funn
);
1419 memset(&new_func
, 0, sizeof(struct pci_func
));
1420 new_func
.bus
= busn
;
1421 new_func
.device
= devn
;
1422 new_func
.function
= funn
;
1423 new_func
.is_a_board
= 1;
1424 configure_existing_function(ctrl
, &new_func
);
1425 pciehprm_dump_func_res(&new_func
);
1427 configure_existing_function(ctrl
, func
);
1428 pciehprm_dump_func_res(func
);
1430 dbg("aCCF:existing PCI 0x%x Func ResourceDump\n", ctrl
->bus
);
1438 static int bind_pci_resources(
1439 struct controller
*ctrl
,
1440 struct acpi_bridge
*ab
1446 dbg("bapr: BUS Resources add on PCI 0x%x\n", ab
->bus
);
1447 status
= pciehprm_add_resources (&ctrl
->bus_head
, ab
->bus_head
);
1448 if (pciehprm_delete_resources (&ab
->bus_head
, ctrl
->bus_head
))
1449 warn("bapr: cannot sub BUS Resource on PCI 0x%x\n", ab
->bus
);
1451 err("bapr: BUS Resource add on PCI 0x%x: fail=0x%x\n", ab
->bus
, status
);
1455 info("bapr: No BUS Resource on PCI 0x%x.\n", ab
->bus
);
1458 dbg("bapr: IO Resources add on PCI 0x%x\n", ab
->bus
);
1459 status
= pciehprm_add_resources (&ctrl
->io_head
, ab
->io_head
);
1460 if (pciehprm_delete_resources (&ab
->io_head
, ctrl
->io_head
))
1461 warn("bapr: cannot sub IO Resource on PCI 0x%x\n", ab
->bus
);
1463 err("bapr: IO Resource add on PCI 0x%x: fail=0x%x\n", ab
->bus
, status
);
1467 info("bapr: No IO Resource on PCI 0x%x.\n", ab
->bus
);
1470 dbg("bapr: MEM Resources add on PCI 0x%x\n", ab
->bus
);
1471 status
= pciehprm_add_resources (&ctrl
->mem_head
, ab
->mem_head
);
1472 if (pciehprm_delete_resources (&ab
->mem_head
, ctrl
->mem_head
))
1473 warn("bapr: cannot sub MEM Resource on PCI 0x%x\n", ab
->bus
);
1475 err("bapr: MEM Resource add on PCI 0x%x: fail=0x%x\n", ab
->bus
, status
);
1479 info("bapr: No MEM Resource on PCI 0x%x.\n", ab
->bus
);
1481 if (ab
->p_mem_head
) {
1482 dbg("bapr: PMEM Resources add on PCI 0x%x\n", ab
->bus
);
1483 status
= pciehprm_add_resources (&ctrl
->p_mem_head
, ab
->p_mem_head
);
1484 if (pciehprm_delete_resources (&ab
->p_mem_head
, ctrl
->p_mem_head
))
1485 warn("bapr: cannot sub PMEM Resource on PCI 0x%x\n", ab
->bus
);
1487 err("bapr: PMEM Resource add on PCI 0x%x: fail=0x%x\n", ab
->bus
, status
);
1491 info("bapr: No PMEM Resource on PCI 0x%x.\n", ab
->bus
);
1496 static int no_pci_resources( struct acpi_bridge
*ab
)
1498 return !(ab
->p_mem_head
|| ab
->mem_head
|| ab
->io_head
|| ab
->bus_head
);
1501 static int find_pci_bridge_resources (
1502 struct controller
*ctrl
,
1503 struct acpi_bridge
*ab
1507 struct pci_func func
;
1509 memset(&func
, 0, sizeof(struct pci_func
));
1511 func
.bus
= ab
->pbus
;
1512 func
.device
= ab
->pdevice
;
1513 func
.function
= ab
->pfunction
;
1514 func
.is_a_board
= 1;
1516 /* Get used resources for this PCI bridge */
1517 rc
= pciehp_save_used_resources (ctrl
, &func
, !DISABLE_CARD
);
1519 ab
->io_head
= func
.io_head
;
1520 ab
->mem_head
= func
.mem_head
;
1521 ab
->p_mem_head
= func
.p_mem_head
;
1522 ab
->bus_head
= func
.bus_head
;
1524 pciehprm_delete_resource(&ab
->bus_head
, ctrl
->pci_dev
->subordinate
->number
, 1);
1529 static int get_pci_resources_from_bridge(
1530 struct controller
*ctrl
,
1531 struct acpi_bridge
*ab
1536 dbg("grfb: Get Resources for PCI 0x%x from actual PCI bridge 0x%x.\n", ctrl
->bus
, ab
->bus
);
1538 rc
= find_pci_bridge_resources (ctrl
, ab
);
1540 pciehp_resource_sort_and_combine(&ab
->bus_head
);
1541 pciehp_resource_sort_and_combine(&ab
->io_head
);
1542 pciehp_resource_sort_and_combine(&ab
->mem_head
);
1543 pciehp_resource_sort_and_combine(&ab
->p_mem_head
);
1545 pciehprm_add_resources (&ab
->tbus_head
, ab
->bus_head
);
1546 pciehprm_add_resources (&ab
->tio_head
, ab
->io_head
);
1547 pciehprm_add_resources (&ab
->tmem_head
, ab
->mem_head
);
1548 pciehprm_add_resources (&ab
->tp_mem_head
, ab
->p_mem_head
);
1553 static int get_pci_resources(
1554 struct controller
*ctrl
,
1555 struct acpi_bridge
*ab
1560 if (no_pci_resources(ab
)) {
1561 dbg("spbr:PCI 0x%x has no resources. Get parent resources.\n", ab
->bus
);
1562 rc
= get_pci_resources_from_bridge(ctrl
, ab
);
1569 * Get resources for this ctrl.
1570 * 1. get total resources from ACPI _CRS or bridge (this ctrl)
1571 * 2. find used resources of existing adapters
1572 * 3. subtract used resources from total resources
1574 int pciehprm_find_available_resources( struct controller
*ctrl
)
1577 struct acpi_bridge
*ab
;
1579 ab
= find_acpi_bridge_by_bus(acpi_bridges_head
, ctrl
->seg
, ctrl
->pci_dev
->subordinate
->number
);
1581 err("pfar:cannot locate acpi bridge of PCI 0x%x.\n", ctrl
->pci_dev
->subordinate
->number
);
1584 if (no_pci_resources(ab
)) {
1585 rc
= get_pci_resources(ctrl
, ab
);
1587 err("pfar:cannot get pci resources of PCI 0x%x.\n", ctrl
->pci_dev
->subordinate
->number
);
1592 rc
= bind_pci_resources(ctrl
, ab
);
1593 dbg("pfar:pre-Bind PCI 0x%x Ctrl Resource Dump\n", ctrl
->pci_dev
->subordinate
->number
);
1594 pciehprm_dump_ctrl_res(ctrl
);
1596 bind_pci_resources_to_slots (ctrl
);
1598 dbg("pfar:post-Bind PCI 0x%x Ctrl Resource Dump\n", ctrl
->pci_dev
->subordinate
->number
);
1599 pciehprm_dump_ctrl_res(ctrl
);
1604 int pciehprm_set_hpp(
1605 struct controller
*ctrl
,
1606 struct pci_func
*func
,
1610 struct acpi_bridge
*ab
;
1611 struct pci_bus lpci_bus
, *pci_bus
;
1614 u8 cls
= 0x08; /* default cache line size */
1615 u8 lt
= 0x40; /* default latency timer */
1619 memcpy(&lpci_bus
, ctrl
->pci_bus
, sizeof(lpci_bus
));
1620 pci_bus
= &lpci_bus
;
1621 pci_bus
->number
= func
->bus
;
1622 devfn
= PCI_DEVFN(func
->device
, func
->function
);
1624 ab
= find_acpi_bridge_by_bus(acpi_bridges_head
, ctrl
->seg
, ctrl
->bus
);
1628 lt
= (u8
)ab
->_hpp
->latency_timer
;
1629 cls
= (u8
)ab
->_hpp
->cache_line_size
;
1630 ep
= (u8
)ab
->_hpp
->enable_perr
;
1631 es
= (u8
)ab
->_hpp
->enable_serr
;
1633 dbg("_hpp: no _hpp for B/D/F=%#x/%#x/%#x. use default value\n", func
->bus
, func
->device
, func
->function
);
1635 dbg("_hpp: no acpi bridge for B/D/F = %#x/%#x/%#x. use default value\n", func
->bus
, func
->device
, func
->function
);
1638 if (card_type
== PCI_HEADER_TYPE_BRIDGE
) {
1639 /* set subordinate Latency Timer */
1640 rc
|= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_SEC_LATENCY_TIMER
, lt
);
1643 /* set base Latency Timer */
1644 rc
|= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_LATENCY_TIMER
, lt
);
1645 dbg(" set latency timer =0x%02x: %x\n", lt
, rc
);
1647 rc
|= pci_bus_write_config_byte(pci_bus
, devfn
, PCI_CACHE_LINE_SIZE
, cls
);
1648 dbg(" set cache_line_size=0x%02x: %x\n", cls
, rc
);
1653 void pciehprm_enable_card(
1654 struct controller
*ctrl
,
1655 struct pci_func
*func
,
1658 u16 command
, cmd
, bcommand
, bcmd
;
1659 struct pci_bus lpci_bus
, *pci_bus
;
1660 struct acpi_bridge
*ab
;
1664 memcpy(&lpci_bus
, ctrl
->pci_bus
, sizeof(lpci_bus
));
1665 pci_bus
= &lpci_bus
;
1666 pci_bus
->number
= func
->bus
;
1667 devfn
= PCI_DEVFN(func
->device
, func
->function
);
1669 rc
= pci_bus_read_config_word(pci_bus
, devfn
, PCI_COMMAND
, &command
);
1671 if (card_type
== PCI_HEADER_TYPE_BRIDGE
) {
1672 rc
= pci_bus_read_config_word(pci_bus
, devfn
, PCI_BRIDGE_CONTROL
, &bcommand
);
1675 cmd
= command
= command
| PCI_COMMAND_MASTER
| PCI_COMMAND_INVALIDATE
1676 | PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
;
1677 bcmd
= bcommand
= bcommand
| PCI_BRIDGE_CTL_NO_ISA
;
1679 ab
= find_acpi_bridge_by_bus(acpi_bridges_head
, ctrl
->seg
, ctrl
->bus
);
1682 if (ab
->_hpp
->enable_perr
) {
1683 command
|= PCI_COMMAND_PARITY
;
1684 bcommand
|= PCI_BRIDGE_CTL_PARITY
;
1686 command
&= ~PCI_COMMAND_PARITY
;
1687 bcommand
&= ~PCI_BRIDGE_CTL_PARITY
;
1689 if (ab
->_hpp
->enable_serr
) {
1690 command
|= PCI_COMMAND_SERR
;
1691 bcommand
|= PCI_BRIDGE_CTL_SERR
;
1693 command
&= ~PCI_COMMAND_SERR
;
1694 bcommand
&= ~PCI_BRIDGE_CTL_SERR
;
1697 dbg("no _hpp for B/D/F = %#x/%#x/%#x.\n", func
->bus
, func
->device
, func
->function
);
1699 dbg("no acpi bridge for B/D/F = %#x/%#x/%#x.\n", func
->bus
, func
->device
, func
->function
);
1701 if (command
!= cmd
) {
1702 rc
= pci_bus_write_config_word(pci_bus
, devfn
, PCI_COMMAND
, command
);
1704 if ((card_type
== PCI_HEADER_TYPE_BRIDGE
) && (bcommand
!= bcmd
)) {
1705 rc
= pci_bus_write_config_word(pci_bus
, devfn
, PCI_BRIDGE_CONTROL
, bcommand
);