4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * Derived from pseudocode supplied by Intel.
29 #pragma ident "%Z%%M% %I% %E% SMI"
32 * Workaround for Intel Orion chipset bug
34 * It is intended that this code implements exactly the workaround
35 * described in the errata. There is one exception, described below.
38 #include <sys/types.h>
40 #include <sys/mutex.h>
41 #include <sys/pci_cfgspace_impl.h>
43 #define PCI_82454_RW_CONTROL 0x54
51 boolean_t A2B0Found
= B_FALSE
;
52 boolean_t c82454PostingEnabled
= B_FALSE
;
56 boolean_t A2B0WorkAroundReqd
;
63 for (DeviceNo
= 0; DeviceNo
< PCI_MAX_DEVS
; DeviceNo
++) {
64 VendorID
= pci_mech1_getw(BusNo
, DeviceNo
, FunctionNo
,
66 DeviceID
= pci_mech1_getw(BusNo
, DeviceNo
, FunctionNo
,
68 RevisionID
= pci_mech1_getb(BusNo
, DeviceNo
, FunctionNo
,
70 if (VendorID
== 0x8086 && DeviceID
== 0x84c4) {
71 /* Found 82454 PCI Bridge */
73 if (RevisionID
<= 4) {
76 if (DeviceNo
== (0xc8 >> 3)) {
78 * c82454 Found - determine the status of
81 PciReg
= pci_mech1_getb(BusNo
, DeviceNo
,
82 FunctionNo
, PCI_82454_RW_CONTROL
);
84 c82454PostingEnabled
= B_TRUE
;
87 /* nc82454 Found - store device no. */
93 * Determine if nc82454 posting is to be enabled
94 * and need of workaround.
96 * [[ This is a deviation from the pseudocode in the errata.
97 * The errata has mismatched braces, leading to uncertainty
98 * as to whether this code is inside the test for 8086/84c4.
99 * The errata has this code clearly inside the DeviceNo loop.
100 * This code is obviously pointless until you've at least found
101 * the second 82454, and there's no need to execute it more
102 * than once, so I'm moving it outside that loop to execute
103 * once on completion of the scan. ]]
105 if (Num82454
>= 2 && A2B0Found
&&
106 c82454PostingEnabled
) {
107 A2B0WorkAroundReqd
= B_TRUE
;
108 /* Enable inbound posting on nc82454 */
109 PciReg
= pci_mech1_getb(0, ncDevNo
, 0,
110 PCI_82454_RW_CONTROL
);
112 pci_mech1_putb(0, ncDevNo
, 0,
113 PCI_82454_RW_CONTROL
, PciReg
);
115 A2B0WorkAroundReqd
= B_FALSE
;
118 return (A2B0WorkAroundReqd
);
122 * When I first read this code in the errata document, I asked "why doesn't
123 * the initial read of CFC (possibly) lead to the 'two responses' problem?"
125 * After thinking about it for a while, the answer is that we're trying to
126 * talk to the nc82454 itself. The c82454 doesn't have the problem, so it
127 * will recognize that this request is *not* for it, and won't respond.
128 * The nc82454 will either respond or not, depending on whether it "saw"
129 * the CF8 write, and if it responds it might or might not return the
130 * right data. That's all pretty much OK, if we're willing to assume
131 * that the only way that 84C48086 will come back is from the vendor ID/
132 * device ID registers on the nc82454. This is probabilistic, of course,
133 * because the nc82454 *could* be pointing at a register on some device
134 * that just *happened* to have that value, but that seems unlikely.
137 FuncDisableInboundPostingnc82454()
142 mutex_enter(&pcicfg_chipset_mutex
);
144 test
= pci_mech1_getl(0, ncDevNo
, 0, PCI_CONF_VENID
);
145 } while (test
!= 0x84c48086UL
);
148 * At this point we are guaranteed to be pointing to the nc82454 PCI
149 * bridge Vendor ID register.
153 * Impact of the erratum is that the configuration read will
154 * return the value which was last read.
155 * Hence read register 0x54 until the previous read value
156 * (VendorId/DeviceId) is not read anymore.
158 test
= pci_mech1_getl(0, ncDevNo
, 0, PCI_82454_RW_CONTROL
);
159 } while (test
== 0x84c48086UL
);
161 * At this point we are guaranteed to be pointing to the PCI
162 * Read/Write Control Register in the nc82454 PCI Bridge.
164 PciReg
= pci_mech1_getb(0, ncDevNo
, 0, PCI_82454_RW_CONTROL
);
166 pci_mech1_putb(0, ncDevNo
, 0, PCI_82454_RW_CONTROL
, PciReg
);
170 FuncEnableInboundPostingnc82454()
174 PciReg
= pci_mech1_getb(0, ncDevNo
, 0, PCI_82454_RW_CONTROL
);
176 pci_mech1_putb(0, ncDevNo
, 0, PCI_82454_RW_CONTROL
, PciReg
);
177 mutex_exit(&pcicfg_chipset_mutex
);
181 pci_orion_getb(int bus
, int device
, int function
, int reg
)
185 FuncDisableInboundPostingnc82454();
187 val
= pci_mech1_getb(bus
, device
, function
, reg
);
189 FuncEnableInboundPostingnc82454();
194 pci_orion_getw(int bus
, int device
, int function
, int reg
)
198 FuncDisableInboundPostingnc82454();
200 val
= pci_mech1_getw(bus
, device
, function
, reg
);
202 FuncEnableInboundPostingnc82454();
207 pci_orion_getl(int bus
, int device
, int function
, int reg
)
211 FuncDisableInboundPostingnc82454();
213 val
= pci_mech1_getl(bus
, device
, function
, reg
);
215 FuncEnableInboundPostingnc82454();
220 pci_orion_putb(int bus
, int device
, int function
, int reg
, uint8_t val
)
222 FuncDisableInboundPostingnc82454();
224 pci_mech1_putb(bus
, device
, function
, reg
, val
);
226 FuncEnableInboundPostingnc82454();
230 pci_orion_putw(int bus
, int device
, int function
, int reg
, uint16_t val
)
232 FuncDisableInboundPostingnc82454();
234 pci_mech1_putw(bus
, device
, function
, reg
, val
);
236 FuncEnableInboundPostingnc82454();
240 pci_orion_putl(int bus
, int device
, int function
, int reg
, uint32_t val
)
242 FuncDisableInboundPostingnc82454();
244 pci_mech1_putl(bus
, device
, function
, reg
, val
);
246 FuncEnableInboundPostingnc82454();