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 <kristen.c.accardi@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>
38 #include <acpi/acpi.h>
39 #include <acpi/acpi_bus.h>
40 #include <acpi/actypes.h>
44 #define PCI_MAX_BUS 0x100
45 #define ACPI_STA_DEVICE_PRESENT 0x01
47 #define METHOD_NAME__SUN "_SUN"
48 #define METHOD_NAME__HPP "_HPP"
49 #define METHOD_NAME_OSHP "OSHP"
51 /* Status code for running acpi method to gain native control */
53 #define OSC_NOT_EXIST 1
54 #define OSC_RUN_FAILED 2
55 #define OSHP_NOT_EXIST 3
56 #define OSHP_RUN_FAILED 4
57 #define NC_RUN_SUCCESS 5
59 #define PHP_RES_BUS 0xA0
60 #define PHP_RES_IO 0xA1
61 #define PHP_RES_MEM 0xA2
62 #define PHP_RES_PMEM 0xA3
64 #define BRIDGE_TYPE_P2P 0x00
65 #define BRIDGE_TYPE_HOST 0x01
67 /* this should go to drivers/acpi/include/ */
75 struct acpi_php_slot {
76 struct acpi_php_slot *next;
77 struct acpi_bridge *bridge;
84 void *slot_ops; /* _STA, _EJx, etc */
89 struct acpi_bridge *parent;
90 struct acpi_bridge *next;
91 struct acpi_bridge *child;
94 int pbus; /* pdev->bus->number */
95 int pdevice; /* PCI_SLOT(pdev->devfn) */
96 int pfunction; /* PCI_DEVFN(pdev->devfn) */
97 int bus; /* pdev->subordinate->number */
98 struct acpi__hpp *_hpp;
99 struct acpi_php_slot *slots;
104 static struct acpi_bridge *acpi_bridges_head;
106 static u8 * acpi_path_name( acpi_handle handle)
109 static u8 path_name[ACPI_PATHNAME_MAX];
110 struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
112 memset(path_name, 0, sizeof (path_name));
113 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
115 if (ACPI_FAILURE(status))
121 static void acpi_get__hpp ( struct acpi_bridge *ab);
122 static int acpi_run_oshp ( struct acpi_bridge *ab);
123 static int osc_run_status = NC_NOT_RUN;
124 static int oshp_run_status = NC_NOT_RUN;
126 static int acpi_add_slot_to_php_slots(
127 struct acpi_bridge *ab,
134 struct acpi_php_slot *aps;
135 static long samesun = -1;
137 aps = (struct acpi_php_slot *) kmalloc (sizeof(struct acpi_php_slot), GFP_KERNEL);
139 err ("acpi_pciehprm: alloc for aps fail\n");
142 memset(aps, 0, sizeof(struct acpi_php_slot));
144 aps->handle = handle;
146 aps->dev = (adr >> 16) & 0xffff;
147 aps->fun = adr & 0xffff;
150 aps->next = ab->slots; /* cling to the bridge */
158 if (osc_run_status == OSC_NOT_EXIST)
159 oshp_run_status = acpi_run_oshp(ab);
161 if (sun != samesun) {
162 info("acpi_pciehprm: Slot sun(%x) at s:b:d:f=0x%02x:%02x:%02x:%02x\n",
163 aps->sun, ab->seg, aps->bus, aps->dev, aps->fun);
169 static void acpi_get__hpp ( struct acpi_bridge *ab)
173 struct acpi_buffer ret_buf = { 0, NULL};
174 union acpi_object *ext_obj, *package;
175 u8 *path_name = acpi_path_name(ab->handle);
179 status = acpi_evaluate_object(ab->handle, METHOD_NAME__HPP, NULL, &ret_buf);
181 case AE_BUFFER_OVERFLOW:
182 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
183 if (!ret_buf.pointer) {
184 err ("acpi_pciehprm:%s alloc for _HPP fail\n", path_name);
187 status = acpi_evaluate_object(ab->handle, METHOD_NAME__HPP, NULL, &ret_buf);
188 if (ACPI_SUCCESS(status))
191 if (ACPI_FAILURE(status)) {
192 err("acpi_pciehprm:%s _HPP fail=0x%x\n", path_name, status);
197 ext_obj = (union acpi_object *) ret_buf.pointer;
198 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
199 err ("acpi_pciehprm:%s _HPP obj not a package\n", path_name);
200 goto free_and_return;
203 len = ext_obj->package.count;
204 package = (union acpi_object *) ret_buf.pointer;
205 for ( i = 0; (i < len) || (i < 4); i++) {
206 ext_obj = (union acpi_object *) &package->package.elements[i];
207 switch (ext_obj->type) {
208 case ACPI_TYPE_INTEGER:
209 nui[i] = (u8)ext_obj->integer.value;
212 err ("acpi_pciehprm:%s _HPP obj type incorrect\n", path_name);
213 goto free_and_return;
217 ab->_hpp = kmalloc (sizeof (struct acpi__hpp), GFP_KERNEL);
219 err ("acpi_pciehprm:%s alloc for _HPP failed\n", path_name);
220 goto free_and_return;
222 memset(ab->_hpp, 0, sizeof(struct acpi__hpp));
224 ab->_hpp->cache_line_size = nui[0];
225 ab->_hpp->latency_timer = nui[1];
226 ab->_hpp->enable_serr = nui[2];
227 ab->_hpp->enable_perr = nui[3];
229 dbg(" _HPP: cache_line_size=0x%x\n", ab->_hpp->cache_line_size);
230 dbg(" _HPP: latency timer =0x%x\n", ab->_hpp->latency_timer);
231 dbg(" _HPP: enable SERR =0x%x\n", ab->_hpp->enable_serr);
232 dbg(" _HPP: enable PERR =0x%x\n", ab->_hpp->enable_perr);
235 kfree(ret_buf.pointer);
238 static int acpi_run_oshp ( struct acpi_bridge *ab)
241 u8 *path_name = acpi_path_name(ab->handle);
244 status = acpi_evaluate_object(ab->handle, METHOD_NAME_OSHP, NULL, NULL);
245 if (ACPI_FAILURE(status)) {
246 err("acpi_pciehprm:%s OSHP fails=0x%x\n", path_name, status);
247 oshp_run_status = (status == AE_NOT_FOUND) ? OSHP_NOT_EXIST : OSHP_RUN_FAILED;
249 oshp_run_status = NC_RUN_SUCCESS;
250 dbg("acpi_pciehprm:%s OSHP passes =0x%x\n", path_name, status);
251 dbg("acpi_pciehprm:%s oshp_run_status =0x%x\n", path_name, oshp_run_status);
253 return oshp_run_status;
256 /* find acpi_bridge downword from ab. */
257 static struct acpi_bridge *
258 find_acpi_bridge_by_bus(
259 struct acpi_bridge *ab,
261 int bus /* pdev->subordinate->number */
264 struct acpi_bridge *lab = NULL;
269 if ((ab->bus == bus) && (ab->seg == seg))
273 lab = find_acpi_bridge_by_bus(ab->child, seg, bus);
277 lab = find_acpi_bridge_by_bus(ab->next, seg, bus);
283 * Build a device tree of ACPI PCI Bridges
285 static void pciehprm_acpi_register_a_bridge (
286 struct acpi_bridge **head,
287 struct acpi_bridge *pab, /* parent bridge to which child bridge is added */
288 struct acpi_bridge *cab /* child bridge to add */
291 struct acpi_bridge *lpab;
292 struct acpi_bridge *lcab;
294 lpab = find_acpi_bridge_by_bus(*head, pab->seg, pab->bus);
296 if (!(pab->type & BRIDGE_TYPE_HOST))
297 warn("PCI parent bridge s:b(%x:%x) not in list.\n", pab->seg, pab->bus);
303 if ((cab->type & BRIDGE_TYPE_HOST) && (pab == cab))
306 lcab = find_acpi_bridge_by_bus(*head, cab->seg, cab->bus);
308 if ((pab->bus != lcab->parent->bus) || (lcab->bus != cab->bus))
309 err("PCI child bridge s:b(%x:%x) in list with diff parent.\n", cab->seg, cab->bus);
315 lcab->next = lpab->child;
319 static acpi_status pciehprm_acpi_build_php_slots_callback(
330 acpi_handle phandle = NULL;
331 struct acpi_bridge *pab = (struct acpi_bridge *)context;
332 struct acpi_bridge *lab;
334 u8 *path_name = acpi_path_name(handle);
337 status = acpi_evaluate_integer(handle, METHOD_NAME__SUN, NULL, &sun);
342 if (ACPI_FAILURE(status)) {
343 err("acpi_pciehprm:%s _SUN fail=0x%x\n", path_name, status);
348 /* get _ADR. _ADR must exist if _SUN exists */
349 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
350 if (ACPI_FAILURE(status)) {
351 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name, status);
355 dbg("acpi_pciehprm:%s sun=0x%08x adr=0x%08x\n", path_name, (u32)sun, (u32)adr);
357 status = acpi_get_parent(handle, &phandle);
358 if (ACPI_FAILURE(status)) {
359 err("acpi_pciehprm:%s get_parent fail=0x%x\n", path_name, status);
366 if (pab->bus == bus_num) {
369 dbg("WARN: pab is not parent\n");
370 lab = find_acpi_bridge_by_bus(pab, seg_num, bus_num);
372 dbg("acpi_pciehprm: alloc new P2P bridge(%x) for sun(%08x)\n", (u32)bus_num, (u32)sun);
373 lab = (struct acpi_bridge *)kmalloc(sizeof(struct acpi_bridge), GFP_KERNEL);
375 err("acpi_pciehprm: alloc for ab fail\n");
378 memset(lab, 0, sizeof(struct acpi_bridge));
380 lab->handle = phandle;
381 lab->pbus = pab->bus;
382 lab->pdevice = (int)(padr >> 16) & 0xffff;
383 lab->pfunction = (int)(padr & 0xffff);
384 lab->bus = (int)bus_num;
386 lab->type = BRIDGE_TYPE_P2P;
388 pciehprm_acpi_register_a_bridge (&acpi_bridges_head, pab, lab);
390 dbg("acpi_pciehprm: found P2P bridge(%x) for sun(%08x)\n", (u32)bus_num, (u32)sun);
393 acpi_add_slot_to_php_slots(lab, (int)bus_num, handle, (u32)adr, (u32)sun);
398 static int pciehprm_acpi_build_php_slots(
399 struct acpi_bridge *ab,
404 u8 *path_name = acpi_path_name(ab->handle);
406 /* Walk down this pci bridge to get _SUNs if any behind P2P */
407 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
410 pciehprm_acpi_build_php_slots_callback,
413 if (ACPI_FAILURE(status)) {
414 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);
421 static void build_a_bridge(
422 struct acpi_bridge *pab,
423 struct acpi_bridge *ab
426 u8 *path_name = acpi_path_name(ab->handle);
428 pciehprm_acpi_register_a_bridge (&acpi_bridges_head, pab, ab);
431 case BRIDGE_TYPE_HOST:
432 dbg("acpi_pciehprm: Registered PCI HOST Bridge(%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
433 ab->bus, ab->seg, ab->pbus, ab->pdevice, ab->pfunction, path_name);
435 case BRIDGE_TYPE_P2P:
436 dbg("acpi_pciehprm: Registered PCI P2P Bridge(%02x-%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
437 ab->pbus, ab->bus, ab->seg, ab->pbus, ab->pdevice, ab->pfunction, path_name);
441 /* build any immediate PHP slots under this pci bridge */
442 pciehprm_acpi_build_php_slots(ab, 1);
445 static struct acpi_bridge * add_p2p_bridge(
447 struct acpi_bridge *pab, /* parent */
451 struct acpi_bridge *ab;
452 struct pci_dev *pdev;
453 ulong devnum, funcnum;
454 u8 *path_name = acpi_path_name(handle);
456 ab = (struct acpi_bridge *) kmalloc (sizeof(struct acpi_bridge), GFP_KERNEL);
458 err("acpi_pciehprm: alloc for ab fail\n");
461 memset(ab, 0, sizeof(struct acpi_bridge));
463 devnum = (adr >> 16) & 0xffff;
464 funcnum = adr & 0xffff;
466 pdev = pci_find_slot(pab->bus, PCI_DEVFN(devnum, funcnum));
467 if (!pdev || !pdev->subordinate) {
468 err("acpi_pciehprm:%s is not a P2P Bridge\n", path_name);
475 ab->pbus = pab->bus; /* or pdev->bus->number */
476 ab->pdevice = devnum; /* or PCI_SLOT(pdev->devfn) */
477 ab->pfunction = funcnum; /* or PCI_FUNC(pdev->devfn) */
478 ab->bus = pdev->subordinate->number;
480 ab->type = BRIDGE_TYPE_P2P;
482 dbg("acpi_pciehprm: P2P(%x-%x) on pci=b:d:f(%x:%x:%x) acpi=b:d:f(%x:%x:%x) [%s]\n",
483 pab->bus, ab->bus, pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
484 pab->bus, (u32)devnum, (u32)funcnum, path_name);
486 build_a_bridge(pab, ab);
491 static acpi_status scan_p2p_bridge(
498 struct acpi_bridge *pab = (struct acpi_bridge *)context;
499 struct acpi_bridge *ab;
502 u8 *path_name = acpi_path_name(handle);
503 ulong devnum, funcnum;
504 struct pci_dev *pdev;
506 /* get device, function */
507 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
508 if (ACPI_FAILURE(status)) {
509 if (status != AE_NOT_FOUND)
510 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name, status);
514 devnum = (adr >> 16) & 0xffff;
515 funcnum = adr & 0xffff;
517 pdev = pci_find_slot(pab->bus, PCI_DEVFN(devnum, funcnum));
520 if (!pdev->subordinate)
523 ab = add_p2p_bridge(handle, pab, adr);
525 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
531 if (ACPI_FAILURE(status))
532 dbg("acpi_pciehprm:%s find_p2p fail=0x%x\n", path_name, status);
538 static struct acpi_bridge * add_host_bridge(
546 struct acpi_bridge *ab;
547 u8 *path_name = acpi_path_name(handle);
549 /* get device, function: host br adr is always 0000 though. */
550 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
551 if (ACPI_FAILURE(status)) {
552 err("acpi_pciehprm:%s _ADR fail=0x%x\n", path_name, status);
555 dbg("acpi_pciehprm: ROOT PCI seg(0x%x)bus(0x%x)dev(0x%x)func(0x%x) [%s]\n", (u32)segnum,
556 (u32)busnum, (u32)(adr >> 16) & 0xffff, (u32)adr & 0xffff, path_name);
558 ab = (struct acpi_bridge *) kmalloc (sizeof(struct acpi_bridge), GFP_KERNEL);
560 err("acpi_pciehprm: alloc for ab fail\n");
563 memset(ab, 0, sizeof(struct acpi_bridge));
566 ab->seg = (int)segnum;
567 ab->bus = ab->pbus = (int)busnum;
568 ab->pdevice = (int)(adr >> 16) & 0xffff;
569 ab->pfunction = (int)(adr & 0xffff);
571 ab->type = BRIDGE_TYPE_HOST;
573 status = pci_osc_control_set (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
574 if (ACPI_FAILURE(status)) {
575 err("%s: status %x\n", __FUNCTION__, status);
576 osc_run_status = (status == AE_NOT_FOUND) ? OSC_NOT_EXIST : OSC_RUN_FAILED;
578 osc_run_status = NC_RUN_SUCCESS;
580 dbg("%s: osc_run_status %x\n", __FUNCTION__, osc_run_status);
582 build_a_bridge(ab, ab);
587 static acpi_status acpi_scan_from_root_pci_callback (
597 struct acpi_bridge *ab;
598 u8 *path_name = acpi_path_name(handle);
600 /* get bus number of this pci root bridge */
601 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &segnum);
602 if (ACPI_FAILURE(status)) {
603 if (status != AE_NOT_FOUND) {
604 err("acpi_pciehprm:%s evaluate _SEG fail=0x%x\n", path_name, status);
610 /* get bus number of this pci root bridge */
611 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL, &busnum);
612 if (ACPI_FAILURE(status)) {
613 err("acpi_pciehprm:%s evaluate _BBN fail=0x%x\n", path_name, status);
617 ab = add_host_bridge(handle, segnum, busnum);
619 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
625 if (ACPI_FAILURE(status))
626 dbg("acpi_pciehprm:%s find_p2p fail=0x%x\n", path_name, status);
632 static int pciehprm_acpi_scan_pci (void)
637 * TBD: traverse LDM device tree with the help of
638 * unified ACPI augmented for php device population.
640 status = acpi_get_devices ( PCI_ROOT_HID_STRING,
641 acpi_scan_from_root_pci_callback,
644 if (ACPI_FAILURE(status)) {
645 err("acpi_pciehprm:get_device PCI ROOT HID fail=0x%x\n", status);
652 int pciehprm_init(enum php_ctlr_type ctlr_type)
656 if (ctlr_type != PCI)
659 dbg("pciehprm ACPI init <enter>\n");
660 acpi_bridges_head = NULL;
662 /* construct PCI bus:device tree of acpi_handles */
663 rc = pciehprm_acpi_scan_pci();
667 if ((oshp_run_status != NC_RUN_SUCCESS) && (osc_run_status != NC_RUN_SUCCESS)) {
668 err("Fails to gain control of native hot-plug\n");
672 dbg("pciehprm ACPI init %s\n", (rc)?"fail":"success");
676 static void free_a_slot(struct acpi_php_slot *aps)
678 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);
683 static void free_a_bridge( struct acpi_bridge *ab)
685 struct acpi_php_slot *aps, *next;
688 case BRIDGE_TYPE_HOST:
689 dbg("Free ACPI PCI HOST Bridge(%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
690 ab->bus, acpi_path_name(ab->handle), ab->seg, ab->pbus, ab->pdevice, ab->pfunction);
692 case BRIDGE_TYPE_P2P:
693 dbg("Free ACPI PCI P2P Bridge(%x-%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
694 ab->pbus, ab->bus, acpi_path_name(ab->handle), ab->seg, ab->pbus, ab->pdevice, ab->pfunction);
698 /* free slots first */
699 for (aps = ab->slots; aps; aps = next) {
707 static void pciehprm_free_bridges ( struct acpi_bridge *ab)
713 pciehprm_free_bridges (ab->child);
716 pciehprm_free_bridges (ab->next);
721 void pciehprm_cleanup(void)
723 pciehprm_free_bridges (acpi_bridges_head);
726 static int get_number_of_slots (
727 struct acpi_bridge *ab,
731 struct acpi_php_slot *aps;
735 for ( aps = ab->slots; aps; aps = aps->next)
736 if (aps->dev != prev_slot) {
737 prev_slot = aps->dev;
742 slot_num += get_number_of_slots (ab->child, 0);
748 slot_num += get_number_of_slots (ab->next, 0);
753 static struct acpi_php_slot * get_acpi_slot (
754 struct acpi_bridge *ab,
758 struct acpi_php_slot *aps = NULL;
760 for ( aps = ab->slots; aps; aps = aps->next)
764 if (!aps && ab->child) {
765 aps = (struct acpi_php_slot *)get_acpi_slot (ab->child, sun);
770 if (!aps && ab->next) {
771 aps = (struct acpi_php_slot *)get_acpi_slot (ab->next, sun);
781 void * pciehprm_get_slot(struct slot *slot)
783 struct acpi_bridge *ab = acpi_bridges_head;
784 struct acpi_php_slot *aps = get_acpi_slot (ab, slot->number);
788 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);
794 int pciehprm_set_hpp(
795 struct controller *ctrl,
796 struct pci_func *func,
800 struct acpi_bridge *ab;
801 struct pci_bus lpci_bus, *pci_bus;
804 u8 cls= 0x08; /* default cache line size */
805 u8 lt = 0x40; /* default latency timer */
809 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
811 pci_bus->number = func->bus;
812 devfn = PCI_DEVFN(func->device, func->function);
814 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->bus);
818 lt = (u8)ab->_hpp->latency_timer;
819 cls = (u8)ab->_hpp->cache_line_size;
820 ep = (u8)ab->_hpp->enable_perr;
821 es = (u8)ab->_hpp->enable_serr;
823 dbg("_hpp: no _hpp for B/D/F=%#x/%#x/%#x. use default value\n", func->bus, func->device, func->function);
825 dbg("_hpp: no acpi bridge for B/D/F = %#x/%#x/%#x. use default value\n", func->bus, func->device, func->function);
828 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
829 /* set subordinate Latency Timer */
830 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_SEC_LATENCY_TIMER, lt);
833 /* set base Latency Timer */
834 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_LATENCY_TIMER, lt);
835 dbg(" set latency timer =0x%02x: %x\n", lt, rc);
837 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_CACHE_LINE_SIZE, cls);
838 dbg(" set cache_line_size=0x%02x: %x\n", cls, rc);
843 void pciehprm_enable_card(
844 struct controller *ctrl,
845 struct pci_func *func,
848 u16 command, cmd, bcommand, bcmd;
849 struct pci_bus lpci_bus, *pci_bus;
850 struct acpi_bridge *ab;
854 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
856 pci_bus->number = func->bus;
857 devfn = PCI_DEVFN(func->device, func->function);
859 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_COMMAND, &cmd);
861 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
862 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, &bcmd);
865 command = cmd | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
866 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
867 bcommand = bcmd | PCI_BRIDGE_CTL_NO_ISA;
869 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->bus);
872 if (ab->_hpp->enable_perr) {
873 command |= PCI_COMMAND_PARITY;
874 bcommand |= PCI_BRIDGE_CTL_PARITY;
876 command &= ~PCI_COMMAND_PARITY;
877 bcommand &= ~PCI_BRIDGE_CTL_PARITY;
879 if (ab->_hpp->enable_serr) {
880 command |= PCI_COMMAND_SERR;
881 bcommand |= PCI_BRIDGE_CTL_SERR;
883 command &= ~PCI_COMMAND_SERR;
884 bcommand &= ~PCI_BRIDGE_CTL_SERR;
887 dbg("no _hpp for B/D/F = %#x/%#x/%#x.\n", func->bus, func->device, func->function);
889 dbg("no acpi bridge for B/D/F = %#x/%#x/%#x.\n", func->bus, func->device, func->function);
891 if (command != cmd) {
892 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_COMMAND, command);
894 if ((card_type == PCI_HEADER_TYPE_BRIDGE) && (bcommand != bcmd)) {
895 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, bcommand);