1*c88420b3Sdmick /*
2*c88420b3Sdmick * CDDL HEADER START
3*c88420b3Sdmick *
4*c88420b3Sdmick * The contents of this file are subject to the terms of the
5*c88420b3Sdmick * Common Development and Distribution License, Version 1.0 only
6*c88420b3Sdmick * (the "License"). You may not use this file except in compliance
7*c88420b3Sdmick * with the License.
8*c88420b3Sdmick *
9*c88420b3Sdmick * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*c88420b3Sdmick * or http://www.opensolaris.org/os/licensing.
11*c88420b3Sdmick * See the License for the specific language governing permissions
12*c88420b3Sdmick * and limitations under the License.
13*c88420b3Sdmick *
14*c88420b3Sdmick * When distributing Covered Code, include this CDDL HEADER in each
15*c88420b3Sdmick * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*c88420b3Sdmick * If applicable, add the following below this CDDL HEADER, with the
17*c88420b3Sdmick * fields enclosed by brackets "[]" replaced with your own identifying
18*c88420b3Sdmick * information: Portions Copyright [yyyy] [name of copyright owner]
19*c88420b3Sdmick *
20*c88420b3Sdmick * CDDL HEADER END
21*c88420b3Sdmick */
22*c88420b3Sdmick /*
23*c88420b3Sdmick * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24*c88420b3Sdmick * Use is subject to license terms.
25*c88420b3Sdmick *
26*c88420b3Sdmick * Derived from pseudocode supplied by Intel.
27*c88420b3Sdmick */
28*c88420b3Sdmick
29*c88420b3Sdmick #pragma ident "%Z%%M% %I% %E% SMI"
30*c88420b3Sdmick
31*c88420b3Sdmick /*
32*c88420b3Sdmick * Workaround for Intel Orion chipset bug
33*c88420b3Sdmick *
34*c88420b3Sdmick * It is intended that this code implements exactly the workaround
35*c88420b3Sdmick * described in the errata. There is one exception, described below.
36*c88420b3Sdmick */
37*c88420b3Sdmick
38*c88420b3Sdmick #include <sys/types.h>
39*c88420b3Sdmick #include <sys/pci.h>
40*c88420b3Sdmick #include <sys/mutex.h>
41*c88420b3Sdmick #include <sys/pci_cfgspace_impl.h>
42*c88420b3Sdmick
43*c88420b3Sdmick #define PCI_82454_RW_CONTROL 0x54
44*c88420b3Sdmick
45*c88420b3Sdmick static int ncDevNo;
46*c88420b3Sdmick
47*c88420b3Sdmick boolean_t
pci_is_broken_orion()48*c88420b3Sdmick pci_is_broken_orion()
49*c88420b3Sdmick {
50*c88420b3Sdmick int Num82454 = 0;
51*c88420b3Sdmick boolean_t A2B0Found = B_FALSE;
52*c88420b3Sdmick boolean_t c82454PostingEnabled = B_FALSE;
53*c88420b3Sdmick uint8_t PciReg;
54*c88420b3Sdmick uint16_t VendorID;
55*c88420b3Sdmick uint16_t DeviceID;
56*c88420b3Sdmick boolean_t A2B0WorkAroundReqd;
57*c88420b3Sdmick
58*c88420b3Sdmick int BusNo = 0;
59*c88420b3Sdmick int FunctionNo = 0;
60*c88420b3Sdmick int DeviceNo;
61*c88420b3Sdmick uint8_t RevisionID;
62*c88420b3Sdmick
63*c88420b3Sdmick for (DeviceNo = 0; DeviceNo < PCI_MAX_DEVS; DeviceNo++) {
64*c88420b3Sdmick VendorID = pci_mech1_getw(BusNo, DeviceNo, FunctionNo,
65*c88420b3Sdmick PCI_CONF_VENID);
66*c88420b3Sdmick DeviceID = pci_mech1_getw(BusNo, DeviceNo, FunctionNo,
67*c88420b3Sdmick PCI_CONF_DEVID);
68*c88420b3Sdmick RevisionID = pci_mech1_getb(BusNo, DeviceNo, FunctionNo,
69*c88420b3Sdmick PCI_CONF_REVID);
70*c88420b3Sdmick if (VendorID == 0x8086 && DeviceID == 0x84c4) {
71*c88420b3Sdmick /* Found 82454 PCI Bridge */
72*c88420b3Sdmick Num82454++;
73*c88420b3Sdmick if (RevisionID <= 4) {
74*c88420b3Sdmick A2B0Found = B_TRUE;
75*c88420b3Sdmick }
76*c88420b3Sdmick if (DeviceNo == (0xc8 >> 3)) {
77*c88420b3Sdmick /*
78*c88420b3Sdmick * c82454 Found - determine the status of
79*c88420b3Sdmick * inbound posting.
80*c88420b3Sdmick */
81*c88420b3Sdmick PciReg = pci_mech1_getb(BusNo, DeviceNo,
82*c88420b3Sdmick FunctionNo, PCI_82454_RW_CONTROL);
83*c88420b3Sdmick if (PciReg & 0x01) {
84*c88420b3Sdmick c82454PostingEnabled = B_TRUE;
85*c88420b3Sdmick }
86*c88420b3Sdmick } else {
87*c88420b3Sdmick /* nc82454 Found - store device no. */
88*c88420b3Sdmick ncDevNo = DeviceNo;
89*c88420b3Sdmick }
90*c88420b3Sdmick }
91*c88420b3Sdmick } /* DeviceNo */
92*c88420b3Sdmick /*
93*c88420b3Sdmick * Determine if nc82454 posting is to be enabled
94*c88420b3Sdmick * and need of workaround.
95*c88420b3Sdmick *
96*c88420b3Sdmick * [[ This is a deviation from the pseudocode in the errata.
97*c88420b3Sdmick * The errata has mismatched braces, leading to uncertainty
98*c88420b3Sdmick * as to whether this code is inside the test for 8086/84c4.
99*c88420b3Sdmick * The errata has this code clearly inside the DeviceNo loop.
100*c88420b3Sdmick * This code is obviously pointless until you've at least found
101*c88420b3Sdmick * the second 82454, and there's no need to execute it more
102*c88420b3Sdmick * than once, so I'm moving it outside that loop to execute
103*c88420b3Sdmick * once on completion of the scan. ]]
104*c88420b3Sdmick */
105*c88420b3Sdmick if (Num82454 >= 2 && A2B0Found &&
106*c88420b3Sdmick c82454PostingEnabled) {
107*c88420b3Sdmick A2B0WorkAroundReqd = B_TRUE;
108*c88420b3Sdmick /* Enable inbound posting on nc82454 */
109*c88420b3Sdmick PciReg = pci_mech1_getb(0, ncDevNo, 0,
110*c88420b3Sdmick PCI_82454_RW_CONTROL);
111*c88420b3Sdmick PciReg |= 0x01;
112*c88420b3Sdmick pci_mech1_putb(0, ncDevNo, 0,
113*c88420b3Sdmick PCI_82454_RW_CONTROL, PciReg);
114*c88420b3Sdmick } else {
115*c88420b3Sdmick A2B0WorkAroundReqd = B_FALSE;
116*c88420b3Sdmick }
117*c88420b3Sdmick
118*c88420b3Sdmick return (A2B0WorkAroundReqd);
119*c88420b3Sdmick }
120*c88420b3Sdmick
121*c88420b3Sdmick /*
122*c88420b3Sdmick * When I first read this code in the errata document, I asked "why doesn't
123*c88420b3Sdmick * the initial read of CFC (possibly) lead to the 'two responses' problem?"
124*c88420b3Sdmick *
125*c88420b3Sdmick * After thinking about it for a while, the answer is that we're trying to
126*c88420b3Sdmick * talk to the nc82454 itself. The c82454 doesn't have the problem, so it
127*c88420b3Sdmick * will recognize that this request is *not* for it, and won't respond.
128*c88420b3Sdmick * The nc82454 will either respond or not, depending on whether it "saw"
129*c88420b3Sdmick * the CF8 write, and if it responds it might or might not return the
130*c88420b3Sdmick * right data. That's all pretty much OK, if we're willing to assume
131*c88420b3Sdmick * that the only way that 84C48086 will come back is from the vendor ID/
132*c88420b3Sdmick * device ID registers on the nc82454. This is probabilistic, of course,
133*c88420b3Sdmick * because the nc82454 *could* be pointing at a register on some device
134*c88420b3Sdmick * that just *happened* to have that value, but that seems unlikely.
135*c88420b3Sdmick */
136*c88420b3Sdmick static void
FuncDisableInboundPostingnc82454()137*c88420b3Sdmick FuncDisableInboundPostingnc82454()
138*c88420b3Sdmick {
139*c88420b3Sdmick uint32_t test;
140*c88420b3Sdmick uint8_t PciReg;
141*c88420b3Sdmick
142*c88420b3Sdmick mutex_enter(&pcicfg_chipset_mutex);
143*c88420b3Sdmick do {
144*c88420b3Sdmick test = pci_mech1_getl(0, ncDevNo, 0, PCI_CONF_VENID);
145*c88420b3Sdmick } while (test != 0x84c48086UL);
146*c88420b3Sdmick
147*c88420b3Sdmick /*
148*c88420b3Sdmick * At this point we are guaranteed to be pointing to the nc82454 PCI
149*c88420b3Sdmick * bridge Vendor ID register.
150*c88420b3Sdmick */
151*c88420b3Sdmick do {
152*c88420b3Sdmick /*
153*c88420b3Sdmick * Impact of the erratum is that the configuration read will
154*c88420b3Sdmick * return the value which was last read.
155*c88420b3Sdmick * Hence read register 0x54 until the previous read value
156*c88420b3Sdmick * (VendorId/DeviceId) is not read anymore.
157*c88420b3Sdmick */
158*c88420b3Sdmick test = pci_mech1_getl(0, ncDevNo, 0, PCI_82454_RW_CONTROL);
159*c88420b3Sdmick } while (test == 0x84c48086UL);
160*c88420b3Sdmick /*
161*c88420b3Sdmick * At this point we are guaranteed to be pointing to the PCI
162*c88420b3Sdmick * Read/Write Control Register in the nc82454 PCI Bridge.
163*c88420b3Sdmick */
164*c88420b3Sdmick PciReg = pci_mech1_getb(0, ncDevNo, 0, PCI_82454_RW_CONTROL);
165*c88420b3Sdmick PciReg &= ~0x01;
166*c88420b3Sdmick pci_mech1_putb(0, ncDevNo, 0, PCI_82454_RW_CONTROL, PciReg);
167*c88420b3Sdmick }
168*c88420b3Sdmick
169*c88420b3Sdmick static void
FuncEnableInboundPostingnc82454()170*c88420b3Sdmick FuncEnableInboundPostingnc82454()
171*c88420b3Sdmick {
172*c88420b3Sdmick uint8_t PciReg;
173*c88420b3Sdmick
174*c88420b3Sdmick PciReg = pci_mech1_getb(0, ncDevNo, 0, PCI_82454_RW_CONTROL);
175*c88420b3Sdmick PciReg |= 0x01;
176*c88420b3Sdmick pci_mech1_putb(0, ncDevNo, 0, PCI_82454_RW_CONTROL, PciReg);
177*c88420b3Sdmick mutex_exit(&pcicfg_chipset_mutex);
178*c88420b3Sdmick }
179*c88420b3Sdmick
180*c88420b3Sdmick uint8_t
pci_orion_getb(int bus,int device,int function,int reg)181*c88420b3Sdmick pci_orion_getb(int bus, int device, int function, int reg)
182*c88420b3Sdmick {
183*c88420b3Sdmick uint8_t val;
184*c88420b3Sdmick
185*c88420b3Sdmick FuncDisableInboundPostingnc82454();
186*c88420b3Sdmick
187*c88420b3Sdmick val = pci_mech1_getb(bus, device, function, reg);
188*c88420b3Sdmick
189*c88420b3Sdmick FuncEnableInboundPostingnc82454();
190*c88420b3Sdmick return (val);
191*c88420b3Sdmick }
192*c88420b3Sdmick
193*c88420b3Sdmick uint16_t
pci_orion_getw(int bus,int device,int function,int reg)194*c88420b3Sdmick pci_orion_getw(int bus, int device, int function, int reg)
195*c88420b3Sdmick {
196*c88420b3Sdmick uint16_t val;
197*c88420b3Sdmick
198*c88420b3Sdmick FuncDisableInboundPostingnc82454();
199*c88420b3Sdmick
200*c88420b3Sdmick val = pci_mech1_getw(bus, device, function, reg);
201*c88420b3Sdmick
202*c88420b3Sdmick FuncEnableInboundPostingnc82454();
203*c88420b3Sdmick return (val);
204*c88420b3Sdmick }
205*c88420b3Sdmick
206*c88420b3Sdmick uint32_t
pci_orion_getl(int bus,int device,int function,int reg)207*c88420b3Sdmick pci_orion_getl(int bus, int device, int function, int reg)
208*c88420b3Sdmick {
209*c88420b3Sdmick uint32_t val;
210*c88420b3Sdmick
211*c88420b3Sdmick FuncDisableInboundPostingnc82454();
212*c88420b3Sdmick
213*c88420b3Sdmick val = pci_mech1_getl(bus, device, function, reg);
214*c88420b3Sdmick
215*c88420b3Sdmick FuncEnableInboundPostingnc82454();
216*c88420b3Sdmick return (val);
217*c88420b3Sdmick }
218*c88420b3Sdmick
219*c88420b3Sdmick void
pci_orion_putb(int bus,int device,int function,int reg,uint8_t val)220*c88420b3Sdmick pci_orion_putb(int bus, int device, int function, int reg, uint8_t val)
221*c88420b3Sdmick {
222*c88420b3Sdmick FuncDisableInboundPostingnc82454();
223*c88420b3Sdmick
224*c88420b3Sdmick pci_mech1_putb(bus, device, function, reg, val);
225*c88420b3Sdmick
226*c88420b3Sdmick FuncEnableInboundPostingnc82454();
227*c88420b3Sdmick }
228*c88420b3Sdmick
229*c88420b3Sdmick void
pci_orion_putw(int bus,int device,int function,int reg,uint16_t val)230*c88420b3Sdmick pci_orion_putw(int bus, int device, int function, int reg, uint16_t val)
231*c88420b3Sdmick {
232*c88420b3Sdmick FuncDisableInboundPostingnc82454();
233*c88420b3Sdmick
234*c88420b3Sdmick pci_mech1_putw(bus, device, function, reg, val);
235*c88420b3Sdmick
236*c88420b3Sdmick FuncEnableInboundPostingnc82454();
237*c88420b3Sdmick }
238*c88420b3Sdmick
239*c88420b3Sdmick void
pci_orion_putl(int bus,int device,int function,int reg,uint32_t val)240*c88420b3Sdmick pci_orion_putl(int bus, int device, int function, int reg, uint32_t val)
241*c88420b3Sdmick {
242*c88420b3Sdmick FuncDisableInboundPostingnc82454();
243*c88420b3Sdmick
244*c88420b3Sdmick pci_mech1_putl(bus, device, function, reg, val);
245*c88420b3Sdmick
246*c88420b3Sdmick FuncEnableInboundPostingnc82454();
247*c88420b3Sdmick }
248