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 <linux/pci-acpi.h>
36 #include <asm/uaccess.h>
37 #include <asm/system.h>
39 #include <asm/iosapic.h>
41 #include <acpi/acpi.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/actypes.h>
47 #define PCI_MAX_BUS 0x100
48 #define ACPI_STA_DEVICE_PRESENT 0x01
50 #define METHOD_NAME__SUN "_SUN"
51 #define METHOD_NAME__HPP "_HPP"
52 #define METHOD_NAME_OSHP "OSHP"
54 #define PHP_RES_BUS 0xA0
55 #define PHP_RES_IO 0xA1
56 #define PHP_RES_MEM 0xA2
57 #define PHP_RES_PMEM 0xA3
59 #define BRIDGE_TYPE_P2P 0x00
60 #define BRIDGE_TYPE_HOST 0x01
62 /* this should go to drivers/acpi/include/ */
70 struct acpi_php_slot {
71 struct acpi_php_slot *next;
72 struct acpi_bridge *bridge;
79 struct pci_resource *mem_head;
80 struct pci_resource *p_mem_head;
81 struct pci_resource *io_head;
82 struct pci_resource *bus_head;
83 void *slot_ops; /* _STA, _EJx, etc */
88 struct acpi_bridge *parent;
89 struct acpi_bridge *next;
90 struct acpi_bridge *child;
93 int pbus; /* pdev->bus->number */
94 int pdevice; /* PCI_SLOT(pdev->devfn) */
95 int pfunction; /* PCI_DEVFN(pdev->devfn) */
96 int bus; /* pdev->subordinate->number */
97 struct acpi__hpp *_hpp;
98 struct acpi_php_slot *slots;
99 struct pci_resource *tmem_head; /* total from crs */
100 struct pci_resource *tp_mem_head; /* total from crs */
101 struct pci_resource *tio_head; /* total from crs */
102 struct pci_resource *tbus_head; /* total from crs */
103 struct pci_resource *mem_head; /* available */
104 struct pci_resource *p_mem_head; /* available */
105 struct pci_resource *io_head; /* available */
106 struct pci_resource *bus_head; /* available */
111 static struct acpi_bridge *acpi_bridges_head;
113 static u8 * acpi_path_name( acpi_handle handle)
116 static u8 path_name[ACPI_PATHNAME_MAX];
117 struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
119 memset(path_name, 0, sizeof (path_name));
120 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
122 if (ACPI_FAILURE(status))
128 static void acpi_get__hpp ( struct acpi_bridge *ab);
129 static void acpi_run_oshp ( struct acpi_bridge *ab);
130 static int osc_exist = 0;
131 static int oshp_exist = 0;
132 static int run__osc_success = 0;
133 static int run_oshp_success = 0;
135 static int acpi_add_slot_to_php_slots(
136 struct acpi_bridge *ab,
143 struct acpi_php_slot *aps;
144 static long samesun = -1;
146 aps = (struct acpi_php_slot *) kmalloc (sizeof(struct acpi_php_slot), GFP_KERNEL);
148 err ("acpi_pciehprm: alloc for aps fail\n");
151 memset(aps, 0, sizeof(struct acpi_php_slot));
153 aps->handle = handle;
155 aps->dev = (adr >> 16) & 0xffff;
156 aps->fun = adr & 0xffff;
159 aps->next = ab->slots; /* cling to the bridge */
170 if (sun != samesun) {
171 info("acpi_pciehprm: Slot sun(%x) at s:b:d:f=0x%02x:%02x:%02x:%02x\n",
172 aps->sun, ab->seg, aps->bus, aps->dev, aps->fun);
178 static void acpi_get__hpp ( struct acpi_bridge *ab)
182 struct acpi_buffer ret_buf = { 0, NULL};
183 union acpi_object *ext_obj, *package;
184 u8 *path_name = acpi_path_name(ab->handle);
188 status = acpi_evaluate_object(ab->handle, METHOD_NAME__HPP, NULL, &ret_buf);
190 case AE_BUFFER_OVERFLOW:
191 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
192 if (!ret_buf.pointer) {
193 err ("acpi_pciehprm:%s alloc for _HPP fail\n", path_name);
196 status = acpi_evaluate_object(ab->handle, METHOD_NAME__HPP, NULL, &ret_buf);
197 if (ACPI_SUCCESS(status))
200 if (ACPI_FAILURE(status)) {
201 err("acpi_pciehprm:%s _HPP fail=0x%x\n", path_name, status);
206 ext_obj = (union acpi_object *) ret_buf.pointer;
207 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
208 err ("acpi_pciehprm:%s _HPP obj not a package\n", path_name);
209 goto free_and_return;
212 len = ext_obj->package.count;
213 package = (union acpi_object *) ret_buf.pointer;
214 for ( i = 0; (i < len) || (i < 4); i++) {
215 ext_obj = (union acpi_object *) &package->package.elements[i];
216 switch (ext_obj->type) {
217 case ACPI_TYPE_INTEGER:
218 nui[i] = (u8)ext_obj->integer.value;
221 err ("acpi_pciehprm:%s _HPP obj type incorrect\n", path_name);
222 goto free_and_return;
226 ab->_hpp = kmalloc (sizeof (struct acpi__hpp), GFP_KERNEL);
228 err ("acpi_pciehprm:%s alloc for _HPP failed\n", path_name);
229 goto free_and_return;
231 memset(ab->_hpp, 0, sizeof(struct acpi__hpp));
233 ab->_hpp->cache_line_size = nui[0];
234 ab->_hpp->latency_timer = nui[1];
235 ab->_hpp->enable_serr = nui[2];
236 ab->_hpp->enable_perr = nui[3];
238 dbg(" _HPP: cache_line_size=0x%x\n", ab->_hpp->cache_line_size);
239 dbg(" _HPP: latency timer =0x%x\n", ab->_hpp->latency_timer);
240 dbg(" _HPP: enable SERR =0x%x\n", ab->_hpp->enable_serr);
241 dbg(" _HPP: enable PERR =0x%x\n", ab->_hpp->enable_perr);
244 kfree(ret_buf.pointer);
247 static void acpi_run_oshp ( struct acpi_bridge *ab)
250 u8 *path_name = acpi_path_name(ab->handle);
251 struct acpi_buffer ret_buf = { 0, NULL};
254 status = acpi_evaluate_object(ab->handle, METHOD_NAME_OSHP, NULL, &ret_buf);
255 if (ACPI_FAILURE(status)) {
256 err("acpi_pciehprm:%s OSHP fails=0x%x\n", path_name, status);
257 oshp_exist = (status == 0x5) ? 0 : 1;
260 run_oshp_success = 1;
261 dbg("acpi_pciehprm:%s OSHP passes =0x%x\n", path_name, status);
266 static acpi_status acpi_evaluate_crs(
268 struct acpi_resource **retbuf
272 struct acpi_buffer crsbuf;
273 u8 *path_name = acpi_path_name(handle);
276 crsbuf.pointer = NULL;
278 status = acpi_get_current_resources (handle, &crsbuf);
281 case AE_BUFFER_OVERFLOW:
284 dbg("acpi_pciehprm:%s _CRS not found\n", path_name);
287 err ("acpi_pciehprm:%s _CRS fail=0x%x\n", path_name, status);
291 crsbuf.pointer = kmalloc (crsbuf.length, GFP_KERNEL);
292 if (!crsbuf.pointer) {
293 err ("acpi_pciehprm: alloc %ld bytes for %s _CRS fail\n", (ulong)crsbuf.length, path_name);
297 status = acpi_get_current_resources (handle, &crsbuf);
298 if (ACPI_FAILURE(status)) {
299 err("acpi_pciehprm: %s _CRS fail=0x%x.\n", path_name, status);
300 kfree(crsbuf.pointer);
304 *retbuf = crsbuf.pointer;
309 static void free_pci_resource ( struct pci_resource *aprh)
311 struct pci_resource *res, *next;
313 for (res = aprh; res; res = next) {
319 static void print_pci_resource ( struct pci_resource *aprh)
321 struct pci_resource *res;
323 for (res = aprh; res; res = res->next)
324 dbg(" base= 0x%x length= 0x%x\n", res->base, res->length);
327 static void print_slot_resources( struct acpi_php_slot *aps)
330 dbg(" BUS Resources:\n");
331 print_pci_resource (aps->bus_head);
335 dbg(" IO Resources:\n");
336 print_pci_resource (aps->io_head);
340 dbg(" MEM Resources:\n");
341 print_pci_resource (aps->mem_head);
344 if (aps->p_mem_head) {
345 dbg(" PMEM Resources:\n");
346 print_pci_resource (aps->p_mem_head);
350 static void print_pci_resources( struct acpi_bridge *ab)
353 dbg(" Total BUS Resources:\n");
354 print_pci_resource (ab->tbus_head);
357 dbg(" BUS Resources:\n");
358 print_pci_resource (ab->bus_head);
362 dbg(" Total IO Resources:\n");
363 print_pci_resource (ab->tio_head);
366 dbg(" IO Resources:\n");
367 print_pci_resource (ab->io_head);
371 dbg(" Total MEM Resources:\n");
372 print_pci_resource (ab->tmem_head);
375 dbg(" MEM Resources:\n");
376 print_pci_resource (ab->mem_head);
379 if (ab->tp_mem_head) {
380 dbg(" Total PMEM Resources:\n");
381 print_pci_resource (ab->tp_mem_head);
383 if (ab->p_mem_head) {
384 dbg(" PMEM Resources:\n");
385 print_pci_resource (ab->p_mem_head);
388 dbg(" _HPP: cache_line_size=0x%x\n", ab->_hpp->cache_line_size);
389 dbg(" _HPP: latency timer =0x%x\n", ab->_hpp->latency_timer);
390 dbg(" _HPP: enable SERR =0x%x\n", ab->_hpp->enable_serr);
391 dbg(" _HPP: enable PERR =0x%x\n", ab->_hpp->enable_perr);
395 static int pciehprm_delete_resource(
396 struct pci_resource **aprh,
400 struct pci_resource *res;
401 struct pci_resource *prevnode;
402 struct pci_resource *split_node;
405 pciehp_resource_sort_and_combine(aprh);
407 for (res = *aprh; res; res = res->next) {
408 if (res->base > base)
411 if ((res->base + res->length) < (base + size))
414 if (res->base < base) {
417 if ((res->length - (tbase - res->base)) < size)
420 split_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
424 split_node->base = res->base;
425 split_node->length = tbase - res->base;
427 res->length -= split_node->length;
429 split_node->next = res->next;
430 res->next = split_node;
433 if (res->length >= size) {
434 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
438 split_node->base = res->base + size;
439 split_node->length = res->length - size;
442 split_node->next = res->next;
443 res->next = split_node;
450 while (prevnode->next != res)
451 prevnode = prevnode->next;
453 prevnode->next = res->next;
463 static int pciehprm_delete_resources(
464 struct pci_resource **aprh,
465 struct pci_resource *this
468 struct pci_resource *res;
470 for (res = this; res; res = res->next)
471 pciehprm_delete_resource(aprh, res->base, res->length);
476 static int pciehprm_add_resource(
477 struct pci_resource **aprh,
481 struct pci_resource *res;
483 for (res = *aprh; res; res = res->next) {
484 if ((res->base + res->length) == base) {
489 if (res->next == *aprh)
494 res = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
496 err ("acpi_pciehprm: alloc for res fail\n");
499 memset(res, 0, sizeof (struct pci_resource));
510 static int pciehprm_add_resources(
511 struct pci_resource **aprh,
512 struct pci_resource *this
515 struct pci_resource *res;
518 for (res = this; res && !rc; res = res->next)
519 rc = pciehprm_add_resource(aprh, res->base, res->length);
524 static void acpi_parse_io (
525 struct acpi_bridge *ab,
526 union acpi_resource_data *data
529 struct acpi_resource_io *dataio;
530 dataio = (struct acpi_resource_io *) data;
532 dbg("Io Resource\n");
533 dbg(" %d bit decode\n", ACPI_DECODE_16 == dataio->io_decode ? 16:10);
534 dbg(" Range minimum base: %08X\n", dataio->min_base_address);
535 dbg(" Range maximum base: %08X\n", dataio->max_base_address);
536 dbg(" Alignment: %08X\n", dataio->alignment);
537 dbg(" Range Length: %08X\n", dataio->range_length);
540 static void acpi_parse_fixed_io (
541 struct acpi_bridge *ab,
542 union acpi_resource_data *data
545 struct acpi_resource_fixed_io *datafio;
546 datafio = (struct acpi_resource_fixed_io *) data;
548 dbg("Fixed Io Resource\n");
549 dbg(" Range base address: %08X", datafio->base_address);
550 dbg(" Range length: %08X", datafio->range_length);
553 static void acpi_parse_address16_32 (
554 struct acpi_bridge *ab,
555 union acpi_resource_data *data,
556 acpi_resource_type id
560 * acpi_resource_address16 == acpi_resource_address32
561 * acpi_resource_address16 *data16 = (acpi_resource_address16 *) data;
563 struct acpi_resource_address32 *data32 = (struct acpi_resource_address32 *) data;
564 struct pci_resource **aprh, **tprh;
566 if (id == ACPI_RSTYPE_ADDRESS16)
567 dbg("acpi_pciehprm:16-Bit Address Space Resource\n");
569 dbg("acpi_pciehprm:32-Bit Address Space Resource\n");
571 switch (data32->resource_type) {
572 case ACPI_MEMORY_RANGE:
573 dbg(" Resource Type: Memory Range\n");
574 aprh = &ab->mem_head;
575 tprh = &ab->tmem_head;
577 switch (data32->attribute.memory.cache_attribute) {
578 case ACPI_NON_CACHEABLE_MEMORY:
579 dbg(" Type Specific: Noncacheable memory\n");
581 case ACPI_CACHABLE_MEMORY:
582 dbg(" Type Specific: Cacheable memory\n");
584 case ACPI_WRITE_COMBINING_MEMORY:
585 dbg(" Type Specific: Write-combining memory\n");
587 case ACPI_PREFETCHABLE_MEMORY:
588 aprh = &ab->p_mem_head;
589 dbg(" Type Specific: Prefetchable memory\n");
592 dbg(" Type Specific: Invalid cache attribute\n");
596 dbg(" Type Specific: Read%s\n", ACPI_READ_WRITE_MEMORY == data32->attribute.memory.read_write_attribute ? "/Write":" Only");
600 dbg(" Resource Type: I/O Range\n");
602 tprh = &ab->tio_head;
604 switch (data32->attribute.io.range_attribute) {
605 case ACPI_NON_ISA_ONLY_RANGES:
606 dbg(" Type Specific: Non-ISA Io Addresses\n");
608 case ACPI_ISA_ONLY_RANGES:
609 dbg(" Type Specific: ISA Io Addresses\n");
611 case ACPI_ENTIRE_RANGE:
612 dbg(" Type Specific: ISA and non-ISA Io Addresses\n");
615 dbg(" Type Specific: Invalid range attribute\n");
620 case ACPI_BUS_NUMBER_RANGE:
621 dbg(" Resource Type: Bus Number Range(fixed)\n");
622 /* fixup to be compatible with the rest of php driver */
623 data32->min_address_range++;
624 data32->address_length--;
625 aprh = &ab->bus_head;
626 tprh = &ab->tbus_head;
629 dbg(" Resource Type: Invalid resource type. Exiting.\n");
633 dbg(" Resource %s\n", ACPI_CONSUMER == data32->producer_consumer ? "Consumer":"Producer");
634 dbg(" %s decode\n", ACPI_SUB_DECODE == data32->decode ? "Subtractive":"Positive");
635 dbg(" Min address is %s fixed\n", ACPI_ADDRESS_FIXED == data32->min_address_fixed ? "":"not");
636 dbg(" Max address is %s fixed\n", ACPI_ADDRESS_FIXED == data32->max_address_fixed ? "":"not");
637 dbg(" Granularity: %08X\n", data32->granularity);
638 dbg(" Address range min: %08X\n", data32->min_address_range);
639 dbg(" Address range max: %08X\n", data32->max_address_range);
640 dbg(" Address translation offset: %08X\n", data32->address_translation_offset);
641 dbg(" Address Length: %08X\n", data32->address_length);
643 if (0xFF != data32->resource_source.index) {
644 dbg(" Resource Source Index: %X\n", data32->resource_source.index);
645 /* dbg(" Resource Source: %s\n", data32->resource_source.string_ptr); */
648 pciehprm_add_resource(aprh, data32->min_address_range, data32->address_length);
651 static acpi_status acpi_parse_crs(
652 struct acpi_bridge *ab,
653 struct acpi_resource *crsbuf
656 acpi_status status = AE_OK;
657 struct acpi_resource *resource = crsbuf;
662 dbg("acpi_pciehprm: PCI bus 0x%x Resource structure %x.\n", ab->bus, count++);
663 switch (resource->id) {
664 case ACPI_RSTYPE_IRQ:
665 dbg("Irq -------- Resource\n");
667 case ACPI_RSTYPE_DMA:
668 dbg("DMA -------- Resource\n");
670 case ACPI_RSTYPE_START_DPF:
671 dbg("Start DPF -------- Resource\n");
673 case ACPI_RSTYPE_END_DPF:
674 dbg("End DPF -------- Resource\n");
677 acpi_parse_io (ab, &resource->data);
679 case ACPI_RSTYPE_FIXED_IO:
680 acpi_parse_fixed_io (ab, &resource->data);
682 case ACPI_RSTYPE_VENDOR:
683 dbg("Vendor -------- Resource\n");
685 case ACPI_RSTYPE_END_TAG:
686 dbg("End_tag -------- Resource\n");
689 case ACPI_RSTYPE_MEM24:
690 dbg("Mem24 -------- Resource\n");
692 case ACPI_RSTYPE_MEM32:
693 dbg("Mem32 -------- Resource\n");
695 case ACPI_RSTYPE_FIXED_MEM32:
696 dbg("Fixed Mem32 -------- Resource\n");
698 case ACPI_RSTYPE_ADDRESS16:
699 acpi_parse_address16_32(ab, &resource->data, ACPI_RSTYPE_ADDRESS16);
701 case ACPI_RSTYPE_ADDRESS32:
702 acpi_parse_address16_32(ab, &resource->data, ACPI_RSTYPE_ADDRESS32);
704 case ACPI_RSTYPE_ADDRESS64:
705 info("Address64 -------- Resource unparsed\n");
707 case ACPI_RSTYPE_EXT_IRQ:
708 dbg("Ext Irq -------- Resource\n");
711 dbg("Invalid -------- resource type 0x%x\n", resource->id);
715 resource = (struct acpi_resource *) ((char *)resource + resource->length);
721 static acpi_status acpi_get_crs( struct acpi_bridge *ab)
724 struct acpi_resource *crsbuf;
726 status = acpi_evaluate_crs(ab->handle, &crsbuf);
727 if (ACPI_SUCCESS(status)) {
728 status = acpi_parse_crs(ab, crsbuf);
731 pciehp_resource_sort_and_combine(&ab->bus_head);
732 pciehp_resource_sort_and_combine(&ab->io_head);
733 pciehp_resource_sort_and_combine(&ab->mem_head);
734 pciehp_resource_sort_and_combine(&ab->p_mem_head);
736 pciehprm_add_resources (&ab->tbus_head, ab->bus_head);
737 pciehprm_add_resources (&ab->tio_head, ab->io_head);
738 pciehprm_add_resources (&ab->tmem_head, ab->mem_head);
739 pciehprm_add_resources (&ab->tp_mem_head, ab->p_mem_head);
745 /* find acpi_bridge downword from ab. */
746 static struct acpi_bridge *
747 find_acpi_bridge_by_bus(
748 struct acpi_bridge *ab,
750 int bus /* pdev->subordinate->number */
753 struct acpi_bridge *lab = NULL;
758 if ((ab->bus == bus) && (ab->seg == seg))
762 lab = find_acpi_bridge_by_bus(ab->child, seg, bus);
766 lab = find_acpi_bridge_by_bus(ab->next, seg, bus);
772 * Build a device tree of ACPI PCI Bridges
774 static void pciehprm_acpi_register_a_bridge (
775 struct acpi_bridge **head,
776 struct acpi_bridge *pab, /* parent bridge to which child bridge is added */
777 struct acpi_bridge *cab /* child bridge to add */
780 struct acpi_bridge *lpab;
781 struct acpi_bridge *lcab;
783 lpab = find_acpi_bridge_by_bus(*head, pab->seg, pab->bus);
785 if (!(pab->type & BRIDGE_TYPE_HOST))
786 warn("PCI parent bridge s:b(%x:%x) not in list.\n", pab->seg, pab->bus);
792 if ((cab->type & BRIDGE_TYPE_HOST) && (pab == cab))
795 lcab = find_acpi_bridge_by_bus(*head, cab->seg, cab->bus);
797 if ((pab->bus != lcab->parent->bus) || (lcab->bus != cab->bus))
798 err("PCI child bridge s:b(%x:%x) in list with diff parent.\n", cab->seg, cab->bus);
804 lcab->next = lpab->child;
808 static acpi_status pciehprm_acpi_build_php_slots_callback(
819 acpi_handle phandle = NULL;
820 struct acpi_bridge *pab = (struct acpi_bridge *)context;
821 struct acpi_bridge *lab;
823 u8 *path_name = acpi_path_name(handle);
826 status = acpi_evaluate_integer(handle, METHOD_NAME__SUN, NULL, &sun);
831 if (ACPI_FAILURE(status)) {
832 err("acpi_pciehprm:%s _SUN fail=0x%x\n", path_name, status);
837 /* get _ADR. _ADR must exist if _SUN exists */
838 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
839 if (ACPI_FAILURE(status)) {
840 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name, status);
844 dbg("acpi_pciehprm:%s sun=0x%08x adr=0x%08x\n", path_name, (u32)sun, (u32)adr);
846 status = acpi_get_parent(handle, &phandle);
847 if (ACPI_FAILURE(status)) {
848 err("acpi_pciehprm:%s get_parent fail=0x%x\n", path_name, status);
855 if (pab->bus == bus_num) {
858 dbg("WARN: pab is not parent\n");
859 lab = find_acpi_bridge_by_bus(pab, seg_num, bus_num);
861 dbg("acpi_pciehprm: alloc new P2P bridge(%x) for sun(%08x)\n", (u32)bus_num, (u32)sun);
862 lab = (struct acpi_bridge *)kmalloc(sizeof(struct acpi_bridge), GFP_KERNEL);
864 err("acpi_pciehprm: alloc for ab fail\n");
867 memset(lab, 0, sizeof(struct acpi_bridge));
869 lab->handle = phandle;
870 lab->pbus = pab->bus;
871 lab->pdevice = (int)(padr >> 16) & 0xffff;
872 lab->pfunction = (int)(padr & 0xffff);
873 lab->bus = (int)bus_num;
875 lab->type = BRIDGE_TYPE_P2P;
877 pciehprm_acpi_register_a_bridge (&acpi_bridges_head, pab, lab);
879 dbg("acpi_pciehprm: found P2P bridge(%x) for sun(%08x)\n", (u32)bus_num, (u32)sun);
882 acpi_add_slot_to_php_slots(lab, (int)bus_num, handle, (u32)adr, (u32)sun);
887 static int pciehprm_acpi_build_php_slots(
888 struct acpi_bridge *ab,
893 u8 *path_name = acpi_path_name(ab->handle);
895 /* Walk down this pci bridge to get _SUNs if any behind P2P */
896 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
899 pciehprm_acpi_build_php_slots_callback,
902 if (ACPI_FAILURE(status)) {
903 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);
910 static void build_a_bridge(
911 struct acpi_bridge *pab,
912 struct acpi_bridge *ab
915 u8 *path_name = acpi_path_name(ab->handle);
917 pciehprm_acpi_register_a_bridge (&acpi_bridges_head, pab, ab);
920 case BRIDGE_TYPE_HOST:
921 dbg("acpi_pciehprm: Registered PCI HOST Bridge(%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
922 ab->bus, ab->seg, ab->pbus, ab->pdevice, ab->pfunction, path_name);
924 case BRIDGE_TYPE_P2P:
925 dbg("acpi_pciehprm: Registered PCI P2P Bridge(%02x-%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
926 ab->pbus, ab->bus, ab->seg, ab->pbus, ab->pdevice, ab->pfunction, path_name);
930 /* build any immediate PHP slots under this pci bridge */
931 pciehprm_acpi_build_php_slots(ab, 1);
934 static struct acpi_bridge * add_p2p_bridge(
936 struct acpi_bridge *pab, /* parent */
940 struct acpi_bridge *ab;
941 struct pci_dev *pdev;
942 ulong devnum, funcnum;
943 u8 *path_name = acpi_path_name(handle);
945 ab = (struct acpi_bridge *) kmalloc (sizeof(struct acpi_bridge), GFP_KERNEL);
947 err("acpi_pciehprm: alloc for ab fail\n");
950 memset(ab, 0, sizeof(struct acpi_bridge));
952 devnum = (adr >> 16) & 0xffff;
953 funcnum = adr & 0xffff;
955 pdev = pci_find_slot(pab->bus, PCI_DEVFN(devnum, funcnum));
956 if (!pdev || !pdev->subordinate) {
957 err("acpi_pciehprm:%s is not a P2P Bridge\n", path_name);
964 ab->pbus = pab->bus; /* or pdev->bus->number */
965 ab->pdevice = devnum; /* or PCI_SLOT(pdev->devfn) */
966 ab->pfunction = funcnum; /* or PCI_FUNC(pdev->devfn) */
967 ab->bus = pdev->subordinate->number;
969 ab->type = BRIDGE_TYPE_P2P;
971 dbg("acpi_pciehprm: P2P(%x-%x) on pci=b:d:f(%x:%x:%x) acpi=b:d:f(%x:%x:%x) [%s]\n",
972 pab->bus, ab->bus, pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
973 pab->bus, (u32)devnum, (u32)funcnum, path_name);
975 build_a_bridge(pab, ab);
980 static acpi_status scan_p2p_bridge(
987 struct acpi_bridge *pab = (struct acpi_bridge *)context;
988 struct acpi_bridge *ab;
991 u8 *path_name = acpi_path_name(handle);
992 ulong devnum, funcnum;
993 struct pci_dev *pdev;
995 /* get device, function */
996 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
997 if (ACPI_FAILURE(status)) {
998 if (status != AE_NOT_FOUND)
999 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name, status);
1003 devnum = (adr >> 16) & 0xffff;
1004 funcnum = adr & 0xffff;
1006 pdev = pci_find_slot(pab->bus, PCI_DEVFN(devnum, funcnum));
1009 if (!pdev->subordinate)
1012 ab = add_p2p_bridge(handle, pab, adr);
1014 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
1020 if (ACPI_FAILURE(status))
1021 dbg("acpi_pciehprm:%s find_p2p fail=0x%x\n", path_name, status);
1027 static struct acpi_bridge * add_host_bridge(
1035 struct acpi_bridge *ab;
1036 u8 *path_name = acpi_path_name(handle);
1038 /* get device, function: host br adr is always 0000 though. */
1039 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
1040 if (ACPI_FAILURE(status)) {
1041 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name, status);
1044 dbg("acpi_pciehprm: ROOT PCI seg(0x%x)bus(0x%x)dev(0x%x)func(0x%x) [%s]\n", (u32)segnum,
1045 (u32)busnum, (u32)(adr >> 16) & 0xffff, (u32)adr & 0xffff, path_name);
1047 ab = (struct acpi_bridge *) kmalloc (sizeof(struct acpi_bridge), GFP_KERNEL);
1049 err("acpi_pciehprm: alloc for ab fail\n");
1052 memset(ab, 0, sizeof(struct acpi_bridge));
1054 ab->handle = handle;
1055 ab->seg = (int)segnum;
1056 ab->bus = ab->pbus = (int)busnum;
1057 ab->pdevice = (int)(adr >> 16) & 0xffff;
1058 ab->pfunction = (int)(adr & 0xffff);
1060 ab->type = BRIDGE_TYPE_HOST;
1062 /* get root pci bridge's current resources */
1063 status = acpi_get_crs(ab);
1064 if (ACPI_FAILURE(status)) {
1065 err("acpi_pciehprm:%s evaluate _CRS fail=0x%x\n", path_name, status);
1069 status = pci_osc_control_set (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
1070 if (ACPI_FAILURE(status)) {
1071 dbg("%s: status %x\n", __FUNCTION__, status);
1073 run__osc_success = 1;
1076 dbg("%s: status %x run__osc_success %x osc_exist %x \n",
1077 __FUNCTION__, status, run__osc_success, osc_exist);
1079 build_a_bridge(ab, ab);
1084 static acpi_status acpi_scan_from_root_pci_callback (
1094 struct acpi_bridge *ab;
1095 u8 *path_name = acpi_path_name(handle);
1097 /* get bus number of this pci root bridge */
1098 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &segnum);
1099 if (ACPI_FAILURE(status)) {
1100 if (status != AE_NOT_FOUND) {
1101 err("acpi_pciehprm:%s evaluate _SEG fail=0x%x\n", path_name, status);
1107 /* get bus number of this pci root bridge */
1108 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL, &busnum);
1109 if (ACPI_FAILURE(status)) {
1110 err("acpi_pciehprm:%s evaluate _BBN fail=0x%x\n", path_name, status);
1114 ab = add_host_bridge(handle, segnum, busnum);
1116 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
1122 if (ACPI_FAILURE(status))
1123 dbg("acpi_pciehprm:%s find_p2p fail=0x%x\n", path_name, status);
1129 static int pciehprm_acpi_scan_pci (void)
1134 * TBD: traverse LDM device tree with the help of
1135 * unified ACPI augmented for php device population.
1137 status = acpi_get_devices ( PCI_ROOT_HID_STRING,
1138 acpi_scan_from_root_pci_callback,
1141 if (ACPI_FAILURE(status)) {
1142 err("acpi_pciehprm:get_device PCI ROOT HID fail=0x%x\n", status);
1149 int pciehprm_init(enum php_ctlr_type ctlr_type)
1153 if (ctlr_type != PCI)
1156 dbg("pciehprm ACPI init <enter>\n");
1157 acpi_bridges_head = NULL;
1159 /* construct PCI bus:device tree of acpi_handles */
1160 rc = pciehprm_acpi_scan_pci();
1166 err("Both _OSC and OSHP methods do not exist\n");
1168 } else if (!run_oshp_success) {
1169 err("Fails to run OSHP to gain control of native hot-plug\n");
1172 } else if (!run__osc_success) {
1173 err("Fails to run _OSC to gain control of native hot-plug\n");
1176 dbg("%s: run__osc_success %x osc_exist %x\n", __FUNCTION__,
1177 run__osc_success, osc_exist);
1178 dbg("%s: run_oshp_success %x oshp_exist %x", __FUNCTION__,
1179 run_oshp_success, oshp_exist);
1181 dbg("pciehprm ACPI init %s\n", (rc)?"fail":"success");
1185 static void free_a_slot(struct acpi_php_slot *aps)
1187 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);
1189 free_pci_resource (aps->io_head);
1190 free_pci_resource (aps->bus_head);
1191 free_pci_resource (aps->mem_head);
1192 free_pci_resource (aps->p_mem_head);
1197 static void free_a_bridge( struct acpi_bridge *ab)
1199 struct acpi_php_slot *aps, *next;
1202 case BRIDGE_TYPE_HOST:
1203 dbg("Free ACPI PCI HOST Bridge(%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
1204 ab->bus, acpi_path_name(ab->handle), ab->seg, ab->pbus, ab->pdevice, ab->pfunction);
1206 case BRIDGE_TYPE_P2P:
1207 dbg("Free ACPI PCI P2P Bridge(%x-%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
1208 ab->pbus, ab->bus, acpi_path_name(ab->handle), ab->seg, ab->pbus, ab->pdevice, ab->pfunction);
1212 /* free slots first */
1213 for (aps = ab->slots; aps; aps = next) {
1218 free_pci_resource (ab->io_head);
1219 free_pci_resource (ab->tio_head);
1220 free_pci_resource (ab->bus_head);
1221 free_pci_resource (ab->tbus_head);
1222 free_pci_resource (ab->mem_head);
1223 free_pci_resource (ab->tmem_head);
1224 free_pci_resource (ab->p_mem_head);
1225 free_pci_resource (ab->tp_mem_head);
1230 static void pciehprm_free_bridges ( struct acpi_bridge *ab)
1236 pciehprm_free_bridges (ab->child);
1239 pciehprm_free_bridges (ab->next);
1244 void pciehprm_cleanup(void)
1246 pciehprm_free_bridges (acpi_bridges_head);
1249 static int get_number_of_slots (
1250 struct acpi_bridge *ab,
1254 struct acpi_php_slot *aps;
1258 for ( aps = ab->slots; aps; aps = aps->next)
1259 if (aps->dev != prev_slot) {
1260 prev_slot = aps->dev;
1265 slot_num += get_number_of_slots (ab->child, 0);
1271 slot_num += get_number_of_slots (ab->next, 0);
1276 static int print_acpi_resources (struct acpi_bridge *ab)
1278 struct acpi_php_slot *aps;
1282 case BRIDGE_TYPE_HOST:
1283 dbg("PCI HOST Bridge (%x) [%s]\n", ab->bus, acpi_path_name(ab->handle));
1285 case BRIDGE_TYPE_P2P:
1286 dbg("PCI P2P Bridge (%x-%x) [%s]\n", ab->pbus, ab->bus, acpi_path_name(ab->handle));
1290 print_pci_resources (ab);
1292 for ( i = -1, aps = ab->slots; aps; aps = aps->next) {
1295 dbg(" Slot sun(%x) s:b:d:f(%02x:%02x:%02x:%02x)\n", aps->sun, aps->seg, aps->bus, aps->dev, aps->fun);
1296 print_slot_resources(aps);
1301 print_acpi_resources (ab->child);
1304 print_acpi_resources (ab->next);
1309 int pciehprm_print_pirt(void)
1311 dbg("PCIEHPRM ACPI Slots\n");
1312 if (acpi_bridges_head)
1313 print_acpi_resources (acpi_bridges_head);
1318 static struct acpi_php_slot * get_acpi_slot (
1319 struct acpi_bridge *ab,
1323 struct acpi_php_slot *aps = NULL;
1325 for ( aps = ab->slots; aps; aps = aps->next)
1326 if (aps->sun == sun)
1329 if (!aps && ab->child) {
1330 aps = (struct acpi_php_slot *)get_acpi_slot (ab->child, sun);
1335 if (!aps && ab->next) {
1336 aps = (struct acpi_php_slot *)get_acpi_slot (ab->next, sun);
1346 void * pciehprm_get_slot(struct slot *slot)
1348 struct acpi_bridge *ab = acpi_bridges_head;
1349 struct acpi_php_slot *aps = get_acpi_slot (ab, slot->number);
1353 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);
1359 static void pciehprm_dump_func_res( struct pci_func *fun)
1361 struct pci_func *func = fun;
1363 if (func->bus_head) {
1364 dbg(": BUS Resources:\n");
1365 print_pci_resource (func->bus_head);
1367 if (func->io_head) {
1368 dbg(": IO Resources:\n");
1369 print_pci_resource (func->io_head);
1371 if (func->mem_head) {
1372 dbg(": MEM Resources:\n");
1373 print_pci_resource (func->mem_head);
1375 if (func->p_mem_head) {
1376 dbg(": PMEM Resources:\n");
1377 print_pci_resource (func->p_mem_head);
1381 static void pciehprm_dump_ctrl_res( struct controller *ctlr)
1383 struct controller *ctrl = ctlr;
1385 if (ctrl->bus_head) {
1386 dbg(": BUS Resources:\n");
1387 print_pci_resource (ctrl->bus_head);
1389 if (ctrl->io_head) {
1390 dbg(": IO Resources:\n");
1391 print_pci_resource (ctrl->io_head);
1393 if (ctrl->mem_head) {
1394 dbg(": MEM Resources:\n");
1395 print_pci_resource (ctrl->mem_head);
1397 if (ctrl->p_mem_head) {
1398 dbg(": PMEM Resources:\n");
1399 print_pci_resource (ctrl->p_mem_head);
1403 static int pciehprm_get_used_resources (
1404 struct controller *ctrl,
1405 struct pci_func *func
1408 return pciehp_save_used_resources (ctrl, func, !DISABLE_CARD);
1411 static int configure_existing_function(
1412 struct controller *ctrl,
1413 struct pci_func *func
1418 /* see how much resources the func has used. */
1419 rc = pciehprm_get_used_resources (ctrl, func);
1422 /* subtract the resources used by the func from ctrl resources */
1423 rc = pciehprm_delete_resources (&ctrl->bus_head, func->bus_head);
1424 rc |= pciehprm_delete_resources (&ctrl->io_head, func->io_head);
1425 rc |= pciehprm_delete_resources (&ctrl->mem_head, func->mem_head);
1426 rc |= pciehprm_delete_resources (&ctrl->p_mem_head, func->p_mem_head);
1428 warn("aCEF: cannot del used resources\n");
1430 err("aCEF: cannot get used resources\n");
1435 static int bind_pci_resources_to_slots ( struct controller *ctrl)
1437 struct pci_func *func, new_func;
1438 int busn = ctrl->slot_bus;
1442 for (devn = 0; devn < 32; devn++) {
1443 for (funn = 0; funn < 8; funn++) {
1445 if (devn == ctrl->device && funn == ctrl->function)
1448 /* find out if this entry is for an occupied slot */
1450 pci_bus_read_config_dword(ctrl->pci_dev->subordinate, PCI_DEVFN(devn, funn), PCI_VENDOR_ID, &vid);
1452 if (vid != 0xFFFFFFFF) {
1453 dbg("%s: vid = %x\n", __FUNCTION__, vid);
1454 func = pciehp_slot_find(busn, devn, funn);
1456 memset(&new_func, 0, sizeof(struct pci_func));
1457 new_func.bus = busn;
1458 new_func.device = devn;
1459 new_func.function = funn;
1460 new_func.is_a_board = 1;
1461 configure_existing_function(ctrl, &new_func);
1462 pciehprm_dump_func_res(&new_func);
1464 configure_existing_function(ctrl, func);
1465 pciehprm_dump_func_res(func);
1467 dbg("aCCF:existing PCI 0x%x Func ResourceDump\n", ctrl->bus);
1475 static int bind_pci_resources(
1476 struct controller *ctrl,
1477 struct acpi_bridge *ab
1483 dbg("bapr: BUS Resources add on PCI 0x%x\n", ab->bus);
1484 status = pciehprm_add_resources (&ctrl->bus_head, ab->bus_head);
1485 if (pciehprm_delete_resources (&ab->bus_head, ctrl->bus_head))
1486 warn("bapr: cannot sub BUS Resource on PCI 0x%x\n", ab->bus);
1488 err("bapr: BUS Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1492 info("bapr: No BUS Resource on PCI 0x%x.\n", ab->bus);
1495 dbg("bapr: IO Resources add on PCI 0x%x\n", ab->bus);
1496 status = pciehprm_add_resources (&ctrl->io_head, ab->io_head);
1497 if (pciehprm_delete_resources (&ab->io_head, ctrl->io_head))
1498 warn("bapr: cannot sub IO Resource on PCI 0x%x\n", ab->bus);
1500 err("bapr: IO Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1504 info("bapr: No IO Resource on PCI 0x%x.\n", ab->bus);
1507 dbg("bapr: MEM Resources add on PCI 0x%x\n", ab->bus);
1508 status = pciehprm_add_resources (&ctrl->mem_head, ab->mem_head);
1509 if (pciehprm_delete_resources (&ab->mem_head, ctrl->mem_head))
1510 warn("bapr: cannot sub MEM Resource on PCI 0x%x\n", ab->bus);
1512 err("bapr: MEM Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1516 info("bapr: No MEM Resource on PCI 0x%x.\n", ab->bus);
1518 if (ab->p_mem_head) {
1519 dbg("bapr: PMEM Resources add on PCI 0x%x\n", ab->bus);
1520 status = pciehprm_add_resources (&ctrl->p_mem_head, ab->p_mem_head);
1521 if (pciehprm_delete_resources (&ab->p_mem_head, ctrl->p_mem_head))
1522 warn("bapr: cannot sub PMEM Resource on PCI 0x%x\n", ab->bus);
1524 err("bapr: PMEM Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1528 info("bapr: No PMEM Resource on PCI 0x%x.\n", ab->bus);
1533 static int no_pci_resources( struct acpi_bridge *ab)
1535 return !(ab->p_mem_head || ab->mem_head || ab->io_head || ab->bus_head);
1538 static int find_pci_bridge_resources (
1539 struct controller *ctrl,
1540 struct acpi_bridge *ab
1544 struct pci_func func;
1546 memset(&func, 0, sizeof(struct pci_func));
1548 func.bus = ab->pbus;
1549 func.device = ab->pdevice;
1550 func.function = ab->pfunction;
1551 func.is_a_board = 1;
1553 /* Get used resources for this PCI bridge */
1554 rc = pciehp_save_used_resources (ctrl, &func, !DISABLE_CARD);
1556 ab->io_head = func.io_head;
1557 ab->mem_head = func.mem_head;
1558 ab->p_mem_head = func.p_mem_head;
1559 ab->bus_head = func.bus_head;
1561 pciehprm_delete_resource(&ab->bus_head, ctrl->pci_dev->subordinate->number, 1);
1566 static int get_pci_resources_from_bridge(
1567 struct controller *ctrl,
1568 struct acpi_bridge *ab
1573 dbg("grfb: Get Resources for PCI 0x%x from actual PCI bridge 0x%x.\n", ctrl->bus, ab->bus);
1575 rc = find_pci_bridge_resources (ctrl, ab);
1577 pciehp_resource_sort_and_combine(&ab->bus_head);
1578 pciehp_resource_sort_and_combine(&ab->io_head);
1579 pciehp_resource_sort_and_combine(&ab->mem_head);
1580 pciehp_resource_sort_and_combine(&ab->p_mem_head);
1582 pciehprm_add_resources (&ab->tbus_head, ab->bus_head);
1583 pciehprm_add_resources (&ab->tio_head, ab->io_head);
1584 pciehprm_add_resources (&ab->tmem_head, ab->mem_head);
1585 pciehprm_add_resources (&ab->tp_mem_head, ab->p_mem_head);
1590 static int get_pci_resources(
1591 struct controller *ctrl,
1592 struct acpi_bridge *ab
1597 if (no_pci_resources(ab)) {
1598 dbg("spbr:PCI 0x%x has no resources. Get parent resources.\n", ab->bus);
1599 rc = get_pci_resources_from_bridge(ctrl, ab);
1606 * Get resources for this ctrl.
1607 * 1. get total resources from ACPI _CRS or bridge (this ctrl)
1608 * 2. find used resources of existing adapters
1609 * 3. subtract used resources from total resources
1611 int pciehprm_find_available_resources( struct controller *ctrl)
1614 struct acpi_bridge *ab;
1616 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->pci_dev->subordinate->number);
1618 err("pfar:cannot locate acpi bridge of PCI 0x%x.\n", ctrl->pci_dev->subordinate->number);
1621 if (no_pci_resources(ab)) {
1622 rc = get_pci_resources(ctrl, ab);
1624 err("pfar:cannot get pci resources of PCI 0x%x.\n", ctrl->pci_dev->subordinate->number);
1629 rc = bind_pci_resources(ctrl, ab);
1630 dbg("pfar:pre-Bind PCI 0x%x Ctrl Resource Dump\n", ctrl->pci_dev->subordinate->number);
1631 pciehprm_dump_ctrl_res(ctrl);
1633 bind_pci_resources_to_slots (ctrl);
1635 dbg("pfar:post-Bind PCI 0x%x Ctrl Resource Dump\n", ctrl->pci_dev->subordinate->number);
1636 pciehprm_dump_ctrl_res(ctrl);
1641 int pciehprm_set_hpp(
1642 struct controller *ctrl,
1643 struct pci_func *func,
1647 struct acpi_bridge *ab;
1648 struct pci_bus lpci_bus, *pci_bus;
1651 u8 cls= 0x08; /* default cache line size */
1652 u8 lt = 0x40; /* default latency timer */
1656 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
1657 pci_bus = &lpci_bus;
1658 pci_bus->number = func->bus;
1659 devfn = PCI_DEVFN(func->device, func->function);
1661 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->bus);
1665 lt = (u8)ab->_hpp->latency_timer;
1666 cls = (u8)ab->_hpp->cache_line_size;
1667 ep = (u8)ab->_hpp->enable_perr;
1668 es = (u8)ab->_hpp->enable_serr;
1670 dbg("_hpp: no _hpp for B/D/F=%#x/%#x/%#x. use default value\n", func->bus, func->device, func->function);
1672 dbg("_hpp: no acpi bridge for B/D/F = %#x/%#x/%#x. use default value\n", func->bus, func->device, func->function);
1675 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
1676 /* set subordinate Latency Timer */
1677 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_SEC_LATENCY_TIMER, lt);
1680 /* set base Latency Timer */
1681 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_LATENCY_TIMER, lt);
1682 dbg(" set latency timer =0x%02x: %x\n", lt, rc);
1684 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_CACHE_LINE_SIZE, cls);
1685 dbg(" set cache_line_size=0x%02x: %x\n", cls, rc);
1690 void pciehprm_enable_card(
1691 struct controller *ctrl,
1692 struct pci_func *func,
1695 u16 command, cmd, bcommand, bcmd;
1696 struct pci_bus lpci_bus, *pci_bus;
1697 struct acpi_bridge *ab;
1701 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
1702 pci_bus = &lpci_bus;
1703 pci_bus->number = func->bus;
1704 devfn = PCI_DEVFN(func->device, func->function);
1706 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_COMMAND, &command);
1708 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
1709 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, &bcommand);
1712 cmd = command = command | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
1713 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
1714 bcmd = bcommand = bcommand | PCI_BRIDGE_CTL_NO_ISA;
1716 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->bus);
1719 if (ab->_hpp->enable_perr) {
1720 command |= PCI_COMMAND_PARITY;
1721 bcommand |= PCI_BRIDGE_CTL_PARITY;
1723 command &= ~PCI_COMMAND_PARITY;
1724 bcommand &= ~PCI_BRIDGE_CTL_PARITY;
1726 if (ab->_hpp->enable_serr) {
1727 command |= PCI_COMMAND_SERR;
1728 bcommand |= PCI_BRIDGE_CTL_SERR;
1730 command &= ~PCI_COMMAND_SERR;
1731 bcommand &= ~PCI_BRIDGE_CTL_SERR;
1734 dbg("no _hpp for B/D/F = %#x/%#x/%#x.\n", func->bus, func->device, func->function);
1736 dbg("no acpi bridge for B/D/F = %#x/%#x/%#x.\n", func->bus, func->device, func->function);
1738 if (command != cmd) {
1739 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_COMMAND, command);
1741 if ((card_type == PCI_HEADER_TYPE_BRIDGE) && (bcommand != bcmd)) {
1742 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, bcommand);