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