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 /* Status code for running acpi method to gain native control */
56 #define OSC_NOT_EXIST 1
57 #define OSC_RUN_FAILED 2
58 #define OSHP_NOT_EXIST 3
59 #define OSHP_RUN_FAILED 4
60 #define NC_RUN_SUCCESS 5
62 #define PHP_RES_BUS 0xA0
63 #define PHP_RES_IO 0xA1
64 #define PHP_RES_MEM 0xA2
65 #define PHP_RES_PMEM 0xA3
67 #define BRIDGE_TYPE_P2P 0x00
68 #define BRIDGE_TYPE_HOST 0x01
70 /* this should go to drivers/acpi/include/ */
78 struct acpi_php_slot {
79 struct acpi_php_slot *next;
80 struct acpi_bridge *bridge;
87 struct pci_resource *mem_head;
88 struct pci_resource *p_mem_head;
89 struct pci_resource *io_head;
90 struct pci_resource *bus_head;
91 void *slot_ops; /* _STA, _EJx, etc */
96 struct acpi_bridge *parent;
97 struct acpi_bridge *next;
98 struct acpi_bridge *child;
101 int pbus; /* pdev->bus->number */
102 int pdevice; /* PCI_SLOT(pdev->devfn) */
103 int pfunction; /* PCI_DEVFN(pdev->devfn) */
104 int bus; /* pdev->subordinate->number */
105 struct acpi__hpp *_hpp;
106 struct acpi_php_slot *slots;
107 struct pci_resource *tmem_head; /* total from crs */
108 struct pci_resource *tp_mem_head; /* total from crs */
109 struct pci_resource *tio_head; /* total from crs */
110 struct pci_resource *tbus_head; /* total from crs */
111 struct pci_resource *mem_head; /* available */
112 struct pci_resource *p_mem_head; /* available */
113 struct pci_resource *io_head; /* available */
114 struct pci_resource *bus_head; /* available */
119 static struct acpi_bridge *acpi_bridges_head;
121 static u8 * acpi_path_name( acpi_handle handle)
124 static u8 path_name[ACPI_PATHNAME_MAX];
125 struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
127 memset(path_name, 0, sizeof (path_name));
128 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
130 if (ACPI_FAILURE(status))
136 static void acpi_get__hpp ( struct acpi_bridge *ab);
137 static int acpi_run_oshp ( struct acpi_bridge *ab);
138 static int osc_run_status = NC_NOT_RUN;
139 static int oshp_run_status = NC_NOT_RUN;
141 static int acpi_add_slot_to_php_slots(
142 struct acpi_bridge *ab,
149 struct acpi_php_slot *aps;
150 static long samesun = -1;
152 aps = (struct acpi_php_slot *) kmalloc (sizeof(struct acpi_php_slot), GFP_KERNEL);
154 err ("acpi_pciehprm: alloc for aps fail\n");
157 memset(aps, 0, sizeof(struct acpi_php_slot));
159 aps->handle = handle;
161 aps->dev = (adr >> 16) & 0xffff;
162 aps->fun = adr & 0xffff;
165 aps->next = ab->slots; /* cling to the bridge */
173 if (osc_run_status == OSC_NOT_EXIST)
174 oshp_run_status = acpi_run_oshp(ab);
176 if (sun != samesun) {
177 info("acpi_pciehprm: Slot sun(%x) at s:b:d:f=0x%02x:%02x:%02x:%02x\n",
178 aps->sun, ab->seg, aps->bus, aps->dev, aps->fun);
184 static void acpi_get__hpp ( struct acpi_bridge *ab)
188 struct acpi_buffer ret_buf = { 0, NULL};
189 union acpi_object *ext_obj, *package;
190 u8 *path_name = acpi_path_name(ab->handle);
194 status = acpi_evaluate_object(ab->handle, METHOD_NAME__HPP, NULL, &ret_buf);
196 case AE_BUFFER_OVERFLOW:
197 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
198 if (!ret_buf.pointer) {
199 err ("acpi_pciehprm:%s alloc for _HPP fail\n", path_name);
202 status = acpi_evaluate_object(ab->handle, METHOD_NAME__HPP, NULL, &ret_buf);
203 if (ACPI_SUCCESS(status))
206 if (ACPI_FAILURE(status)) {
207 err("acpi_pciehprm:%s _HPP fail=0x%x\n", path_name, status);
212 ext_obj = (union acpi_object *) ret_buf.pointer;
213 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
214 err ("acpi_pciehprm:%s _HPP obj not a package\n", path_name);
215 goto free_and_return;
218 len = ext_obj->package.count;
219 package = (union acpi_object *) ret_buf.pointer;
220 for ( i = 0; (i < len) || (i < 4); i++) {
221 ext_obj = (union acpi_object *) &package->package.elements[i];
222 switch (ext_obj->type) {
223 case ACPI_TYPE_INTEGER:
224 nui[i] = (u8)ext_obj->integer.value;
227 err ("acpi_pciehprm:%s _HPP obj type incorrect\n", path_name);
228 goto free_and_return;
232 ab->_hpp = kmalloc (sizeof (struct acpi__hpp), GFP_KERNEL);
234 err ("acpi_pciehprm:%s alloc for _HPP failed\n", path_name);
235 goto free_and_return;
237 memset(ab->_hpp, 0, sizeof(struct acpi__hpp));
239 ab->_hpp->cache_line_size = nui[0];
240 ab->_hpp->latency_timer = nui[1];
241 ab->_hpp->enable_serr = nui[2];
242 ab->_hpp->enable_perr = nui[3];
244 dbg(" _HPP: cache_line_size=0x%x\n", ab->_hpp->cache_line_size);
245 dbg(" _HPP: latency timer =0x%x\n", ab->_hpp->latency_timer);
246 dbg(" _HPP: enable SERR =0x%x\n", ab->_hpp->enable_serr);
247 dbg(" _HPP: enable PERR =0x%x\n", ab->_hpp->enable_perr);
250 kfree(ret_buf.pointer);
253 static int acpi_run_oshp ( struct acpi_bridge *ab)
256 u8 *path_name = acpi_path_name(ab->handle);
257 struct acpi_buffer ret_buf = { 0, NULL};
260 status = acpi_evaluate_object(ab->handle, METHOD_NAME_OSHP, NULL, &ret_buf);
261 if (ACPI_FAILURE(status)) {
262 err("acpi_pciehprm:%s OSHP fails=0x%x\n", path_name, status);
263 oshp_run_status = (status == AE_NOT_FOUND) ? OSHP_NOT_EXIST : OSHP_RUN_FAILED;
265 oshp_run_status = NC_RUN_SUCCESS;
266 dbg("acpi_pciehprm:%s OSHP passes =0x%x\n", path_name, status);
267 dbg("acpi_pciehprm:%s oshp_run_status =0x%x\n", path_name, oshp_run_status);
269 return oshp_run_status;
272 static acpi_status acpi_evaluate_crs(
274 struct acpi_resource **retbuf
278 struct acpi_buffer crsbuf;
279 u8 *path_name = acpi_path_name(handle);
282 crsbuf.pointer = NULL;
284 status = acpi_get_current_resources (handle, &crsbuf);
287 case AE_BUFFER_OVERFLOW:
290 dbg("acpi_pciehprm:%s _CRS not found\n", path_name);
293 err ("acpi_pciehprm:%s _CRS fail=0x%x\n", path_name, status);
297 crsbuf.pointer = kmalloc (crsbuf.length, GFP_KERNEL);
298 if (!crsbuf.pointer) {
299 err ("acpi_pciehprm: alloc %ld bytes for %s _CRS fail\n", (ulong)crsbuf.length, path_name);
303 status = acpi_get_current_resources (handle, &crsbuf);
304 if (ACPI_FAILURE(status)) {
305 err("acpi_pciehprm: %s _CRS fail=0x%x.\n", path_name, status);
306 kfree(crsbuf.pointer);
310 *retbuf = crsbuf.pointer;
315 static void free_pci_resource ( struct pci_resource *aprh)
317 struct pci_resource *res, *next;
319 for (res = aprh; res; res = next) {
325 static void print_pci_resource ( struct pci_resource *aprh)
327 struct pci_resource *res;
329 for (res = aprh; res; res = res->next)
330 dbg(" base= 0x%x length= 0x%x\n", res->base, res->length);
333 static void print_slot_resources( struct acpi_php_slot *aps)
336 dbg(" BUS Resources:\n");
337 print_pci_resource (aps->bus_head);
341 dbg(" IO Resources:\n");
342 print_pci_resource (aps->io_head);
346 dbg(" MEM Resources:\n");
347 print_pci_resource (aps->mem_head);
350 if (aps->p_mem_head) {
351 dbg(" PMEM Resources:\n");
352 print_pci_resource (aps->p_mem_head);
356 static void print_pci_resources( struct acpi_bridge *ab)
359 dbg(" Total BUS Resources:\n");
360 print_pci_resource (ab->tbus_head);
363 dbg(" BUS Resources:\n");
364 print_pci_resource (ab->bus_head);
368 dbg(" Total IO Resources:\n");
369 print_pci_resource (ab->tio_head);
372 dbg(" IO Resources:\n");
373 print_pci_resource (ab->io_head);
377 dbg(" Total MEM Resources:\n");
378 print_pci_resource (ab->tmem_head);
381 dbg(" MEM Resources:\n");
382 print_pci_resource (ab->mem_head);
385 if (ab->tp_mem_head) {
386 dbg(" Total PMEM Resources:\n");
387 print_pci_resource (ab->tp_mem_head);
389 if (ab->p_mem_head) {
390 dbg(" PMEM Resources:\n");
391 print_pci_resource (ab->p_mem_head);
394 dbg(" _HPP: cache_line_size=0x%x\n", ab->_hpp->cache_line_size);
395 dbg(" _HPP: latency timer =0x%x\n", ab->_hpp->latency_timer);
396 dbg(" _HPP: enable SERR =0x%x\n", ab->_hpp->enable_serr);
397 dbg(" _HPP: enable PERR =0x%x\n", ab->_hpp->enable_perr);
401 static int pciehprm_delete_resource(
402 struct pci_resource **aprh,
406 struct pci_resource *res;
407 struct pci_resource *prevnode;
408 struct pci_resource *split_node;
411 pciehp_resource_sort_and_combine(aprh);
413 for (res = *aprh; res; res = res->next) {
414 if (res->base > base)
417 if ((res->base + res->length) < (base + size))
420 if (res->base < base) {
423 if ((res->length - (tbase - res->base)) < size)
426 split_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
430 split_node->base = res->base;
431 split_node->length = tbase - res->base;
433 res->length -= split_node->length;
435 split_node->next = res->next;
436 res->next = split_node;
439 if (res->length >= size) {
440 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
444 split_node->base = res->base + size;
445 split_node->length = res->length - size;
448 split_node->next = res->next;
449 res->next = split_node;
456 while (prevnode->next != res)
457 prevnode = prevnode->next;
459 prevnode->next = res->next;
469 static int pciehprm_delete_resources(
470 struct pci_resource **aprh,
471 struct pci_resource *this
474 struct pci_resource *res;
476 for (res = this; res; res = res->next)
477 pciehprm_delete_resource(aprh, res->base, res->length);
482 static int pciehprm_add_resource(
483 struct pci_resource **aprh,
487 struct pci_resource *res;
489 for (res = *aprh; res; res = res->next) {
490 if ((res->base + res->length) == base) {
495 if (res->next == *aprh)
500 res = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
502 err ("acpi_pciehprm: alloc for res fail\n");
505 memset(res, 0, sizeof (struct pci_resource));
516 static int pciehprm_add_resources(
517 struct pci_resource **aprh,
518 struct pci_resource *this
521 struct pci_resource *res;
524 for (res = this; res && !rc; res = res->next)
525 rc = pciehprm_add_resource(aprh, res->base, res->length);
530 static void acpi_parse_io (
531 struct acpi_bridge *ab,
532 union acpi_resource_data *data
535 struct acpi_resource_io *dataio;
536 dataio = (struct acpi_resource_io *) data;
538 dbg("Io Resource\n");
539 dbg(" %d bit decode\n", ACPI_DECODE_16 == dataio->io_decode ? 16:10);
540 dbg(" Range minimum base: %08X\n", dataio->min_base_address);
541 dbg(" Range maximum base: %08X\n", dataio->max_base_address);
542 dbg(" Alignment: %08X\n", dataio->alignment);
543 dbg(" Range Length: %08X\n", dataio->range_length);
546 static void acpi_parse_fixed_io (
547 struct acpi_bridge *ab,
548 union acpi_resource_data *data
551 struct acpi_resource_fixed_io *datafio;
552 datafio = (struct acpi_resource_fixed_io *) data;
554 dbg("Fixed Io Resource\n");
555 dbg(" Range base address: %08X", datafio->base_address);
556 dbg(" Range length: %08X", datafio->range_length);
559 static void acpi_parse_address16_32 (
560 struct acpi_bridge *ab,
561 union acpi_resource_data *data,
562 acpi_resource_type id
566 * acpi_resource_address16 == acpi_resource_address32
567 * acpi_resource_address16 *data16 = (acpi_resource_address16 *) data;
569 struct acpi_resource_address32 *data32 = (struct acpi_resource_address32 *) data;
570 struct pci_resource **aprh, **tprh;
572 if (id == ACPI_RSTYPE_ADDRESS16)
573 dbg("acpi_pciehprm:16-Bit Address Space Resource\n");
575 dbg("acpi_pciehprm:32-Bit Address Space Resource\n");
577 switch (data32->resource_type) {
578 case ACPI_MEMORY_RANGE:
579 dbg(" Resource Type: Memory Range\n");
580 aprh = &ab->mem_head;
581 tprh = &ab->tmem_head;
583 switch (data32->attribute.memory.cache_attribute) {
584 case ACPI_NON_CACHEABLE_MEMORY:
585 dbg(" Type Specific: Noncacheable memory\n");
587 case ACPI_CACHABLE_MEMORY:
588 dbg(" Type Specific: Cacheable memory\n");
590 case ACPI_WRITE_COMBINING_MEMORY:
591 dbg(" Type Specific: Write-combining memory\n");
593 case ACPI_PREFETCHABLE_MEMORY:
594 aprh = &ab->p_mem_head;
595 dbg(" Type Specific: Prefetchable memory\n");
598 dbg(" Type Specific: Invalid cache attribute\n");
602 dbg(" Type Specific: Read%s\n", ACPI_READ_WRITE_MEMORY == data32->attribute.memory.read_write_attribute ? "/Write":" Only");
606 dbg(" Resource Type: I/O Range\n");
608 tprh = &ab->tio_head;
610 switch (data32->attribute.io.range_attribute) {
611 case ACPI_NON_ISA_ONLY_RANGES:
612 dbg(" Type Specific: Non-ISA Io Addresses\n");
614 case ACPI_ISA_ONLY_RANGES:
615 dbg(" Type Specific: ISA Io Addresses\n");
617 case ACPI_ENTIRE_RANGE:
618 dbg(" Type Specific: ISA and non-ISA Io Addresses\n");
621 dbg(" Type Specific: Invalid range attribute\n");
626 case ACPI_BUS_NUMBER_RANGE:
627 dbg(" Resource Type: Bus Number Range(fixed)\n");
628 /* fixup to be compatible with the rest of php driver */
629 data32->min_address_range++;
630 data32->address_length--;
631 aprh = &ab->bus_head;
632 tprh = &ab->tbus_head;
635 dbg(" Resource Type: Invalid resource type. Exiting.\n");
639 dbg(" Resource %s\n", ACPI_CONSUMER == data32->producer_consumer ? "Consumer":"Producer");
640 dbg(" %s decode\n", ACPI_SUB_DECODE == data32->decode ? "Subtractive":"Positive");
641 dbg(" Min address is %s fixed\n", ACPI_ADDRESS_FIXED == data32->min_address_fixed ? "":"not");
642 dbg(" Max address is %s fixed\n", ACPI_ADDRESS_FIXED == data32->max_address_fixed ? "":"not");
643 dbg(" Granularity: %08X\n", data32->granularity);
644 dbg(" Address range min: %08X\n", data32->min_address_range);
645 dbg(" Address range max: %08X\n", data32->max_address_range);
646 dbg(" Address translation offset: %08X\n", data32->address_translation_offset);
647 dbg(" Address Length: %08X\n", data32->address_length);
649 if (0xFF != data32->resource_source.index) {
650 dbg(" Resource Source Index: %X\n", data32->resource_source.index);
651 /* dbg(" Resource Source: %s\n", data32->resource_source.string_ptr); */
654 pciehprm_add_resource(aprh, data32->min_address_range, data32->address_length);
657 static acpi_status acpi_parse_crs(
658 struct acpi_bridge *ab,
659 struct acpi_resource *crsbuf
662 acpi_status status = AE_OK;
663 struct acpi_resource *resource = crsbuf;
668 dbg("acpi_pciehprm: PCI bus 0x%x Resource structure %x.\n", ab->bus, count++);
669 switch (resource->id) {
670 case ACPI_RSTYPE_IRQ:
671 dbg("Irq -------- Resource\n");
673 case ACPI_RSTYPE_DMA:
674 dbg("DMA -------- Resource\n");
676 case ACPI_RSTYPE_START_DPF:
677 dbg("Start DPF -------- Resource\n");
679 case ACPI_RSTYPE_END_DPF:
680 dbg("End DPF -------- Resource\n");
683 acpi_parse_io (ab, &resource->data);
685 case ACPI_RSTYPE_FIXED_IO:
686 acpi_parse_fixed_io (ab, &resource->data);
688 case ACPI_RSTYPE_VENDOR:
689 dbg("Vendor -------- Resource\n");
691 case ACPI_RSTYPE_END_TAG:
692 dbg("End_tag -------- Resource\n");
695 case ACPI_RSTYPE_MEM24:
696 dbg("Mem24 -------- Resource\n");
698 case ACPI_RSTYPE_MEM32:
699 dbg("Mem32 -------- Resource\n");
701 case ACPI_RSTYPE_FIXED_MEM32:
702 dbg("Fixed Mem32 -------- Resource\n");
704 case ACPI_RSTYPE_ADDRESS16:
705 acpi_parse_address16_32(ab, &resource->data, ACPI_RSTYPE_ADDRESS16);
707 case ACPI_RSTYPE_ADDRESS32:
708 acpi_parse_address16_32(ab, &resource->data, ACPI_RSTYPE_ADDRESS32);
710 case ACPI_RSTYPE_ADDRESS64:
711 info("Address64 -------- Resource unparsed\n");
713 case ACPI_RSTYPE_EXT_IRQ:
714 dbg("Ext Irq -------- Resource\n");
717 dbg("Invalid -------- resource type 0x%x\n", resource->id);
721 resource = (struct acpi_resource *) ((char *)resource + resource->length);
727 static acpi_status acpi_get_crs( struct acpi_bridge *ab)
730 struct acpi_resource *crsbuf;
732 status = acpi_evaluate_crs(ab->handle, &crsbuf);
733 if (ACPI_SUCCESS(status)) {
734 status = acpi_parse_crs(ab, crsbuf);
737 pciehp_resource_sort_and_combine(&ab->bus_head);
738 pciehp_resource_sort_and_combine(&ab->io_head);
739 pciehp_resource_sort_and_combine(&ab->mem_head);
740 pciehp_resource_sort_and_combine(&ab->p_mem_head);
742 pciehprm_add_resources (&ab->tbus_head, ab->bus_head);
743 pciehprm_add_resources (&ab->tio_head, ab->io_head);
744 pciehprm_add_resources (&ab->tmem_head, ab->mem_head);
745 pciehprm_add_resources (&ab->tp_mem_head, ab->p_mem_head);
751 /* find acpi_bridge downword from ab. */
752 static struct acpi_bridge *
753 find_acpi_bridge_by_bus(
754 struct acpi_bridge *ab,
756 int bus /* pdev->subordinate->number */
759 struct acpi_bridge *lab = NULL;
764 if ((ab->bus == bus) && (ab->seg == seg))
768 lab = find_acpi_bridge_by_bus(ab->child, seg, bus);
772 lab = find_acpi_bridge_by_bus(ab->next, seg, bus);
778 * Build a device tree of ACPI PCI Bridges
780 static void pciehprm_acpi_register_a_bridge (
781 struct acpi_bridge **head,
782 struct acpi_bridge *pab, /* parent bridge to which child bridge is added */
783 struct acpi_bridge *cab /* child bridge to add */
786 struct acpi_bridge *lpab;
787 struct acpi_bridge *lcab;
789 lpab = find_acpi_bridge_by_bus(*head, pab->seg, pab->bus);
791 if (!(pab->type & BRIDGE_TYPE_HOST))
792 warn("PCI parent bridge s:b(%x:%x) not in list.\n", pab->seg, pab->bus);
798 if ((cab->type & BRIDGE_TYPE_HOST) && (pab == cab))
801 lcab = find_acpi_bridge_by_bus(*head, cab->seg, cab->bus);
803 if ((pab->bus != lcab->parent->bus) || (lcab->bus != cab->bus))
804 err("PCI child bridge s:b(%x:%x) in list with diff parent.\n", cab->seg, cab->bus);
810 lcab->next = lpab->child;
814 static acpi_status pciehprm_acpi_build_php_slots_callback(
825 acpi_handle phandle = NULL;
826 struct acpi_bridge *pab = (struct acpi_bridge *)context;
827 struct acpi_bridge *lab;
829 u8 *path_name = acpi_path_name(handle);
832 status = acpi_evaluate_integer(handle, METHOD_NAME__SUN, NULL, &sun);
837 if (ACPI_FAILURE(status)) {
838 err("acpi_pciehprm:%s _SUN fail=0x%x\n", path_name, status);
843 /* get _ADR. _ADR must exist if _SUN exists */
844 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
845 if (ACPI_FAILURE(status)) {
846 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name, status);
850 dbg("acpi_pciehprm:%s sun=0x%08x adr=0x%08x\n", path_name, (u32)sun, (u32)adr);
852 status = acpi_get_parent(handle, &phandle);
853 if (ACPI_FAILURE(status)) {
854 err("acpi_pciehprm:%s get_parent fail=0x%x\n", path_name, status);
861 if (pab->bus == bus_num) {
864 dbg("WARN: pab is not parent\n");
865 lab = find_acpi_bridge_by_bus(pab, seg_num, bus_num);
867 dbg("acpi_pciehprm: alloc new P2P bridge(%x) for sun(%08x)\n", (u32)bus_num, (u32)sun);
868 lab = (struct acpi_bridge *)kmalloc(sizeof(struct acpi_bridge), GFP_KERNEL);
870 err("acpi_pciehprm: alloc for ab fail\n");
873 memset(lab, 0, sizeof(struct acpi_bridge));
875 lab->handle = phandle;
876 lab->pbus = pab->bus;
877 lab->pdevice = (int)(padr >> 16) & 0xffff;
878 lab->pfunction = (int)(padr & 0xffff);
879 lab->bus = (int)bus_num;
881 lab->type = BRIDGE_TYPE_P2P;
883 pciehprm_acpi_register_a_bridge (&acpi_bridges_head, pab, lab);
885 dbg("acpi_pciehprm: found P2P bridge(%x) for sun(%08x)\n", (u32)bus_num, (u32)sun);
888 acpi_add_slot_to_php_slots(lab, (int)bus_num, handle, (u32)adr, (u32)sun);
893 static int pciehprm_acpi_build_php_slots(
894 struct acpi_bridge *ab,
899 u8 *path_name = acpi_path_name(ab->handle);
901 /* Walk down this pci bridge to get _SUNs if any behind P2P */
902 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
905 pciehprm_acpi_build_php_slots_callback,
908 if (ACPI_FAILURE(status)) {
909 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);
916 static void build_a_bridge(
917 struct acpi_bridge *pab,
918 struct acpi_bridge *ab
921 u8 *path_name = acpi_path_name(ab->handle);
923 pciehprm_acpi_register_a_bridge (&acpi_bridges_head, pab, ab);
926 case BRIDGE_TYPE_HOST:
927 dbg("acpi_pciehprm: Registered PCI HOST Bridge(%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
928 ab->bus, ab->seg, ab->pbus, ab->pdevice, ab->pfunction, path_name);
930 case BRIDGE_TYPE_P2P:
931 dbg("acpi_pciehprm: Registered PCI P2P Bridge(%02x-%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
932 ab->pbus, ab->bus, ab->seg, ab->pbus, ab->pdevice, ab->pfunction, path_name);
936 /* build any immediate PHP slots under this pci bridge */
937 pciehprm_acpi_build_php_slots(ab, 1);
940 static struct acpi_bridge * add_p2p_bridge(
942 struct acpi_bridge *pab, /* parent */
946 struct acpi_bridge *ab;
947 struct pci_dev *pdev;
948 ulong devnum, funcnum;
949 u8 *path_name = acpi_path_name(handle);
951 ab = (struct acpi_bridge *) kmalloc (sizeof(struct acpi_bridge), GFP_KERNEL);
953 err("acpi_pciehprm: alloc for ab fail\n");
956 memset(ab, 0, sizeof(struct acpi_bridge));
958 devnum = (adr >> 16) & 0xffff;
959 funcnum = adr & 0xffff;
961 pdev = pci_find_slot(pab->bus, PCI_DEVFN(devnum, funcnum));
962 if (!pdev || !pdev->subordinate) {
963 err("acpi_pciehprm:%s is not a P2P Bridge\n", path_name);
970 ab->pbus = pab->bus; /* or pdev->bus->number */
971 ab->pdevice = devnum; /* or PCI_SLOT(pdev->devfn) */
972 ab->pfunction = funcnum; /* or PCI_FUNC(pdev->devfn) */
973 ab->bus = pdev->subordinate->number;
975 ab->type = BRIDGE_TYPE_P2P;
977 dbg("acpi_pciehprm: P2P(%x-%x) on pci=b:d:f(%x:%x:%x) acpi=b:d:f(%x:%x:%x) [%s]\n",
978 pab->bus, ab->bus, pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
979 pab->bus, (u32)devnum, (u32)funcnum, path_name);
981 build_a_bridge(pab, ab);
986 static acpi_status scan_p2p_bridge(
993 struct acpi_bridge *pab = (struct acpi_bridge *)context;
994 struct acpi_bridge *ab;
997 u8 *path_name = acpi_path_name(handle);
998 ulong devnum, funcnum;
999 struct pci_dev *pdev;
1001 /* get device, function */
1002 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
1003 if (ACPI_FAILURE(status)) {
1004 if (status != AE_NOT_FOUND)
1005 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name, status);
1009 devnum = (adr >> 16) & 0xffff;
1010 funcnum = adr & 0xffff;
1012 pdev = pci_find_slot(pab->bus, PCI_DEVFN(devnum, funcnum));
1015 if (!pdev->subordinate)
1018 ab = add_p2p_bridge(handle, pab, adr);
1020 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
1026 if (ACPI_FAILURE(status))
1027 dbg("acpi_pciehprm:%s find_p2p fail=0x%x\n", path_name, status);
1033 static struct acpi_bridge * add_host_bridge(
1041 struct acpi_bridge *ab;
1042 u8 *path_name = acpi_path_name(handle);
1044 /* get device, function: host br adr is always 0000 though. */
1045 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
1046 if (ACPI_FAILURE(status)) {
1047 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name, status);
1050 dbg("acpi_pciehprm: ROOT PCI seg(0x%x)bus(0x%x)dev(0x%x)func(0x%x) [%s]\n", (u32)segnum,
1051 (u32)busnum, (u32)(adr >> 16) & 0xffff, (u32)adr & 0xffff, path_name);
1053 ab = (struct acpi_bridge *) kmalloc (sizeof(struct acpi_bridge), GFP_KERNEL);
1055 err("acpi_pciehprm: alloc for ab fail\n");
1058 memset(ab, 0, sizeof(struct acpi_bridge));
1060 ab->handle = handle;
1061 ab->seg = (int)segnum;
1062 ab->bus = ab->pbus = (int)busnum;
1063 ab->pdevice = (int)(adr >> 16) & 0xffff;
1064 ab->pfunction = (int)(adr & 0xffff);
1066 ab->type = BRIDGE_TYPE_HOST;
1068 /* get root pci bridge's current resources */
1069 status = acpi_get_crs(ab);
1070 if (ACPI_FAILURE(status)) {
1071 err("acpi_pciehprm:%s evaluate _CRS fail=0x%x\n", path_name, status);
1076 status = pci_osc_control_set (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
1077 if (ACPI_FAILURE(status)) {
1078 err("%s: status %x\n", __FUNCTION__, status);
1079 osc_run_status = (status == AE_NOT_FOUND) ? OSC_NOT_EXIST : OSC_RUN_FAILED;
1081 osc_run_status = NC_RUN_SUCCESS;
1083 dbg("%s: osc_run_status %x\n", __FUNCTION__, osc_run_status);
1085 build_a_bridge(ab, ab);
1090 static acpi_status acpi_scan_from_root_pci_callback (
1100 struct acpi_bridge *ab;
1101 u8 *path_name = acpi_path_name(handle);
1103 /* get bus number of this pci root bridge */
1104 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &segnum);
1105 if (ACPI_FAILURE(status)) {
1106 if (status != AE_NOT_FOUND) {
1107 err("acpi_pciehprm:%s evaluate _SEG fail=0x%x\n", path_name, status);
1113 /* get bus number of this pci root bridge */
1114 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL, &busnum);
1115 if (ACPI_FAILURE(status)) {
1116 err("acpi_pciehprm:%s evaluate _BBN fail=0x%x\n", path_name, status);
1120 ab = add_host_bridge(handle, segnum, busnum);
1122 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
1128 if (ACPI_FAILURE(status))
1129 dbg("acpi_pciehprm:%s find_p2p fail=0x%x\n", path_name, status);
1135 static int pciehprm_acpi_scan_pci (void)
1140 * TBD: traverse LDM device tree with the help of
1141 * unified ACPI augmented for php device population.
1143 status = acpi_get_devices ( PCI_ROOT_HID_STRING,
1144 acpi_scan_from_root_pci_callback,
1147 if (ACPI_FAILURE(status)) {
1148 err("acpi_pciehprm:get_device PCI ROOT HID fail=0x%x\n", status);
1155 int pciehprm_init(enum php_ctlr_type ctlr_type)
1159 if (ctlr_type != PCI)
1162 dbg("pciehprm ACPI init <enter>\n");
1163 acpi_bridges_head = NULL;
1165 /* construct PCI bus:device tree of acpi_handles */
1166 rc = pciehprm_acpi_scan_pci();
1170 if ((oshp_run_status != NC_RUN_SUCCESS) && (osc_run_status != NC_RUN_SUCCESS)) {
1171 err("Fails to gain control of native hot-plug\n");
1175 dbg("pciehprm ACPI init %s\n", (rc)?"fail":"success");
1179 static void free_a_slot(struct acpi_php_slot *aps)
1181 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);
1183 free_pci_resource (aps->io_head);
1184 free_pci_resource (aps->bus_head);
1185 free_pci_resource (aps->mem_head);
1186 free_pci_resource (aps->p_mem_head);
1191 static void free_a_bridge( struct acpi_bridge *ab)
1193 struct acpi_php_slot *aps, *next;
1196 case BRIDGE_TYPE_HOST:
1197 dbg("Free ACPI PCI HOST Bridge(%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
1198 ab->bus, acpi_path_name(ab->handle), ab->seg, ab->pbus, ab->pdevice, ab->pfunction);
1200 case BRIDGE_TYPE_P2P:
1201 dbg("Free ACPI PCI P2P Bridge(%x-%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
1202 ab->pbus, ab->bus, acpi_path_name(ab->handle), ab->seg, ab->pbus, ab->pdevice, ab->pfunction);
1206 /* free slots first */
1207 for (aps = ab->slots; aps; aps = next) {
1212 free_pci_resource (ab->io_head);
1213 free_pci_resource (ab->tio_head);
1214 free_pci_resource (ab->bus_head);
1215 free_pci_resource (ab->tbus_head);
1216 free_pci_resource (ab->mem_head);
1217 free_pci_resource (ab->tmem_head);
1218 free_pci_resource (ab->p_mem_head);
1219 free_pci_resource (ab->tp_mem_head);
1224 static void pciehprm_free_bridges ( struct acpi_bridge *ab)
1230 pciehprm_free_bridges (ab->child);
1233 pciehprm_free_bridges (ab->next);
1238 void pciehprm_cleanup(void)
1240 pciehprm_free_bridges (acpi_bridges_head);
1243 static int get_number_of_slots (
1244 struct acpi_bridge *ab,
1248 struct acpi_php_slot *aps;
1252 for ( aps = ab->slots; aps; aps = aps->next)
1253 if (aps->dev != prev_slot) {
1254 prev_slot = aps->dev;
1259 slot_num += get_number_of_slots (ab->child, 0);
1265 slot_num += get_number_of_slots (ab->next, 0);
1270 static int print_acpi_resources (struct acpi_bridge *ab)
1272 struct acpi_php_slot *aps;
1276 case BRIDGE_TYPE_HOST:
1277 dbg("PCI HOST Bridge (%x) [%s]\n", ab->bus, acpi_path_name(ab->handle));
1279 case BRIDGE_TYPE_P2P:
1280 dbg("PCI P2P Bridge (%x-%x) [%s]\n", ab->pbus, ab->bus, acpi_path_name(ab->handle));
1284 print_pci_resources (ab);
1286 for ( i = -1, aps = ab->slots; aps; aps = aps->next) {
1289 dbg(" Slot sun(%x) s:b:d:f(%02x:%02x:%02x:%02x)\n", aps->sun, aps->seg, aps->bus, aps->dev, aps->fun);
1290 print_slot_resources(aps);
1295 print_acpi_resources (ab->child);
1298 print_acpi_resources (ab->next);
1303 int pciehprm_print_pirt(void)
1305 dbg("PCIEHPRM ACPI Slots\n");
1306 if (acpi_bridges_head)
1307 print_acpi_resources (acpi_bridges_head);
1312 static struct acpi_php_slot * get_acpi_slot (
1313 struct acpi_bridge *ab,
1317 struct acpi_php_slot *aps = NULL;
1319 for ( aps = ab->slots; aps; aps = aps->next)
1320 if (aps->sun == sun)
1323 if (!aps && ab->child) {
1324 aps = (struct acpi_php_slot *)get_acpi_slot (ab->child, sun);
1329 if (!aps && ab->next) {
1330 aps = (struct acpi_php_slot *)get_acpi_slot (ab->next, sun);
1340 void * pciehprm_get_slot(struct slot *slot)
1342 struct acpi_bridge *ab = acpi_bridges_head;
1343 struct acpi_php_slot *aps = get_acpi_slot (ab, slot->number);
1347 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);
1353 static void pciehprm_dump_func_res( struct pci_func *fun)
1355 struct pci_func *func = fun;
1357 if (func->bus_head) {
1358 dbg(": BUS Resources:\n");
1359 print_pci_resource (func->bus_head);
1361 if (func->io_head) {
1362 dbg(": IO Resources:\n");
1363 print_pci_resource (func->io_head);
1365 if (func->mem_head) {
1366 dbg(": MEM Resources:\n");
1367 print_pci_resource (func->mem_head);
1369 if (func->p_mem_head) {
1370 dbg(": PMEM Resources:\n");
1371 print_pci_resource (func->p_mem_head);
1375 static void pciehprm_dump_ctrl_res( struct controller *ctlr)
1377 struct controller *ctrl = ctlr;
1379 if (ctrl->bus_head) {
1380 dbg(": BUS Resources:\n");
1381 print_pci_resource (ctrl->bus_head);
1383 if (ctrl->io_head) {
1384 dbg(": IO Resources:\n");
1385 print_pci_resource (ctrl->io_head);
1387 if (ctrl->mem_head) {
1388 dbg(": MEM Resources:\n");
1389 print_pci_resource (ctrl->mem_head);
1391 if (ctrl->p_mem_head) {
1392 dbg(": PMEM Resources:\n");
1393 print_pci_resource (ctrl->p_mem_head);
1397 static int pciehprm_get_used_resources (
1398 struct controller *ctrl,
1399 struct pci_func *func
1402 return pciehp_save_used_resources (ctrl, func, !DISABLE_CARD);
1405 static int configure_existing_function(
1406 struct controller *ctrl,
1407 struct pci_func *func
1412 /* see how much resources the func has used. */
1413 rc = pciehprm_get_used_resources (ctrl, func);
1416 /* subtract the resources used by the func from ctrl resources */
1417 rc = pciehprm_delete_resources (&ctrl->bus_head, func->bus_head);
1418 rc |= pciehprm_delete_resources (&ctrl->io_head, func->io_head);
1419 rc |= pciehprm_delete_resources (&ctrl->mem_head, func->mem_head);
1420 rc |= pciehprm_delete_resources (&ctrl->p_mem_head, func->p_mem_head);
1422 warn("aCEF: cannot del used resources\n");
1424 err("aCEF: cannot get used resources\n");
1429 static int bind_pci_resources_to_slots ( struct controller *ctrl)
1431 struct pci_func *func, new_func;
1432 int busn = ctrl->slot_bus;
1436 for (devn = 0; devn < 32; devn++) {
1437 for (funn = 0; funn < 8; funn++) {
1439 if (devn == ctrl->device && funn == ctrl->function)
1442 /* find out if this entry is for an occupied slot */
1444 pci_bus_read_config_dword(ctrl->pci_dev->subordinate, PCI_DEVFN(devn, funn), PCI_VENDOR_ID, &vid);
1446 if (vid != 0xFFFFFFFF) {
1447 dbg("%s: vid = %x\n", __FUNCTION__, vid);
1448 func = pciehp_slot_find(busn, devn, funn);
1450 memset(&new_func, 0, sizeof(struct pci_func));
1451 new_func.bus = busn;
1452 new_func.device = devn;
1453 new_func.function = funn;
1454 new_func.is_a_board = 1;
1455 configure_existing_function(ctrl, &new_func);
1456 pciehprm_dump_func_res(&new_func);
1458 configure_existing_function(ctrl, func);
1459 pciehprm_dump_func_res(func);
1461 dbg("aCCF:existing PCI 0x%x Func ResourceDump\n", ctrl->bus);
1469 static int bind_pci_resources(
1470 struct controller *ctrl,
1471 struct acpi_bridge *ab
1477 dbg("bapr: BUS Resources add on PCI 0x%x\n", ab->bus);
1478 status = pciehprm_add_resources (&ctrl->bus_head, ab->bus_head);
1479 if (pciehprm_delete_resources (&ab->bus_head, ctrl->bus_head))
1480 warn("bapr: cannot sub BUS Resource on PCI 0x%x\n", ab->bus);
1482 err("bapr: BUS Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1486 info("bapr: No BUS Resource on PCI 0x%x.\n", ab->bus);
1489 dbg("bapr: IO Resources add on PCI 0x%x\n", ab->bus);
1490 status = pciehprm_add_resources (&ctrl->io_head, ab->io_head);
1491 if (pciehprm_delete_resources (&ab->io_head, ctrl->io_head))
1492 warn("bapr: cannot sub IO Resource on PCI 0x%x\n", ab->bus);
1494 err("bapr: IO Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1498 info("bapr: No IO Resource on PCI 0x%x.\n", ab->bus);
1501 dbg("bapr: MEM Resources add on PCI 0x%x\n", ab->bus);
1502 status = pciehprm_add_resources (&ctrl->mem_head, ab->mem_head);
1503 if (pciehprm_delete_resources (&ab->mem_head, ctrl->mem_head))
1504 warn("bapr: cannot sub MEM Resource on PCI 0x%x\n", ab->bus);
1506 err("bapr: MEM Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1510 info("bapr: No MEM Resource on PCI 0x%x.\n", ab->bus);
1512 if (ab->p_mem_head) {
1513 dbg("bapr: PMEM Resources add on PCI 0x%x\n", ab->bus);
1514 status = pciehprm_add_resources (&ctrl->p_mem_head, ab->p_mem_head);
1515 if (pciehprm_delete_resources (&ab->p_mem_head, ctrl->p_mem_head))
1516 warn("bapr: cannot sub PMEM Resource on PCI 0x%x\n", ab->bus);
1518 err("bapr: PMEM Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1522 info("bapr: No PMEM Resource on PCI 0x%x.\n", ab->bus);
1527 static int no_pci_resources( struct acpi_bridge *ab)
1529 return !(ab->p_mem_head || ab->mem_head || ab->io_head || ab->bus_head);
1532 static int find_pci_bridge_resources (
1533 struct controller *ctrl,
1534 struct acpi_bridge *ab
1538 struct pci_func func;
1540 memset(&func, 0, sizeof(struct pci_func));
1542 func.bus = ab->pbus;
1543 func.device = ab->pdevice;
1544 func.function = ab->pfunction;
1545 func.is_a_board = 1;
1547 /* Get used resources for this PCI bridge */
1548 rc = pciehp_save_used_resources (ctrl, &func, !DISABLE_CARD);
1550 ab->io_head = func.io_head;
1551 ab->mem_head = func.mem_head;
1552 ab->p_mem_head = func.p_mem_head;
1553 ab->bus_head = func.bus_head;
1555 pciehprm_delete_resource(&ab->bus_head, ctrl->pci_dev->subordinate->number, 1);
1560 static int get_pci_resources_from_bridge(
1561 struct controller *ctrl,
1562 struct acpi_bridge *ab
1567 dbg("grfb: Get Resources for PCI 0x%x from actual PCI bridge 0x%x.\n", ctrl->bus, ab->bus);
1569 rc = find_pci_bridge_resources (ctrl, ab);
1571 pciehp_resource_sort_and_combine(&ab->bus_head);
1572 pciehp_resource_sort_and_combine(&ab->io_head);
1573 pciehp_resource_sort_and_combine(&ab->mem_head);
1574 pciehp_resource_sort_and_combine(&ab->p_mem_head);
1576 pciehprm_add_resources (&ab->tbus_head, ab->bus_head);
1577 pciehprm_add_resources (&ab->tio_head, ab->io_head);
1578 pciehprm_add_resources (&ab->tmem_head, ab->mem_head);
1579 pciehprm_add_resources (&ab->tp_mem_head, ab->p_mem_head);
1584 static int get_pci_resources(
1585 struct controller *ctrl,
1586 struct acpi_bridge *ab
1591 if (no_pci_resources(ab)) {
1592 dbg("spbr:PCI 0x%x has no resources. Get parent resources.\n", ab->bus);
1593 rc = get_pci_resources_from_bridge(ctrl, ab);
1600 * Get resources for this ctrl.
1601 * 1. get total resources from ACPI _CRS or bridge (this ctrl)
1602 * 2. find used resources of existing adapters
1603 * 3. subtract used resources from total resources
1605 int pciehprm_find_available_resources( struct controller *ctrl)
1608 struct acpi_bridge *ab;
1610 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->pci_dev->subordinate->number);
1612 err("pfar:cannot locate acpi bridge of PCI 0x%x.\n", ctrl->pci_dev->subordinate->number);
1615 if (no_pci_resources(ab)) {
1616 rc = get_pci_resources(ctrl, ab);
1618 err("pfar:cannot get pci resources of PCI 0x%x.\n", ctrl->pci_dev->subordinate->number);
1623 rc = bind_pci_resources(ctrl, ab);
1624 dbg("pfar:pre-Bind PCI 0x%x Ctrl Resource Dump\n", ctrl->pci_dev->subordinate->number);
1625 pciehprm_dump_ctrl_res(ctrl);
1627 bind_pci_resources_to_slots (ctrl);
1629 dbg("pfar:post-Bind PCI 0x%x Ctrl Resource Dump\n", ctrl->pci_dev->subordinate->number);
1630 pciehprm_dump_ctrl_res(ctrl);
1635 int pciehprm_set_hpp(
1636 struct controller *ctrl,
1637 struct pci_func *func,
1641 struct acpi_bridge *ab;
1642 struct pci_bus lpci_bus, *pci_bus;
1645 u8 cls= 0x08; /* default cache line size */
1646 u8 lt = 0x40; /* default latency timer */
1650 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
1651 pci_bus = &lpci_bus;
1652 pci_bus->number = func->bus;
1653 devfn = PCI_DEVFN(func->device, func->function);
1655 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->bus);
1659 lt = (u8)ab->_hpp->latency_timer;
1660 cls = (u8)ab->_hpp->cache_line_size;
1661 ep = (u8)ab->_hpp->enable_perr;
1662 es = (u8)ab->_hpp->enable_serr;
1664 dbg("_hpp: no _hpp for B/D/F=%#x/%#x/%#x. use default value\n", func->bus, func->device, func->function);
1666 dbg("_hpp: no acpi bridge for B/D/F = %#x/%#x/%#x. use default value\n", func->bus, func->device, func->function);
1669 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
1670 /* set subordinate Latency Timer */
1671 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_SEC_LATENCY_TIMER, lt);
1674 /* set base Latency Timer */
1675 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_LATENCY_TIMER, lt);
1676 dbg(" set latency timer =0x%02x: %x\n", lt, rc);
1678 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_CACHE_LINE_SIZE, cls);
1679 dbg(" set cache_line_size=0x%02x: %x\n", cls, rc);
1684 void pciehprm_enable_card(
1685 struct controller *ctrl,
1686 struct pci_func *func,
1689 u16 command, cmd, bcommand, bcmd;
1690 struct pci_bus lpci_bus, *pci_bus;
1691 struct acpi_bridge *ab;
1695 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
1696 pci_bus = &lpci_bus;
1697 pci_bus->number = func->bus;
1698 devfn = PCI_DEVFN(func->device, func->function);
1700 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_COMMAND, &command);
1702 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
1703 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, &bcommand);
1706 cmd = command = command | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
1707 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
1708 bcmd = bcommand = bcommand | PCI_BRIDGE_CTL_NO_ISA;
1710 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->bus);
1713 if (ab->_hpp->enable_perr) {
1714 command |= PCI_COMMAND_PARITY;
1715 bcommand |= PCI_BRIDGE_CTL_PARITY;
1717 command &= ~PCI_COMMAND_PARITY;
1718 bcommand &= ~PCI_BRIDGE_CTL_PARITY;
1720 if (ab->_hpp->enable_serr) {
1721 command |= PCI_COMMAND_SERR;
1722 bcommand |= PCI_BRIDGE_CTL_SERR;
1724 command &= ~PCI_COMMAND_SERR;
1725 bcommand &= ~PCI_BRIDGE_CTL_SERR;
1728 dbg("no _hpp for B/D/F = %#x/%#x/%#x.\n", func->bus, func->device, func->function);
1730 dbg("no acpi bridge for B/D/F = %#x/%#x/%#x.\n", func->bus, func->device, func->function);
1732 if (command != cmd) {
1733 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_COMMAND, command);
1735 if ((card_type == PCI_HEADER_TYPE_BRIDGE) && (bcommand != bcmd)) {
1736 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, bcommand);