xref: /onnv-gate/usr/src/uts/i86pc/os/pci_neptune.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 
27*748Sdmick #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*748Sdmick 
29*748Sdmick /*
30*748Sdmick  * Support for Intel "Neptune" PCI chip set
31*748Sdmick  */
32*748Sdmick 
33*748Sdmick #include <sys/types.h>
34*748Sdmick #include <sys/pci.h>
35*748Sdmick #include <sys/pci_impl.h>
36*748Sdmick #include <sys/sunddi.h>
37*748Sdmick #include <sys/pci_cfgspace_impl.h>
38*748Sdmick 
39*748Sdmick /*
40*748Sdmick  * This variable is a place holder for the initial value in PCI_PMC register
41*748Sdmick  * of neptune chipset.
42*748Sdmick  */
43*748Sdmick static unsigned char neptune_BIOS_cfg_method = 0;
44*748Sdmick 
45*748Sdmick /*
46*748Sdmick  * Special hack for Intel's Neptune chipset, 82433NX and 82434NX.
47*748Sdmick  *
48*748Sdmick  * The motherboards I've seen still use a version of the BIOS
49*748Sdmick  * that operates using Configuration Mechanism #2 like the older
50*748Sdmick  * Mercury BIOS and chipset (the 82433LX and 82434LX).
51*748Sdmick  *
52*748Sdmick  */
53*748Sdmick boolean_t
pci_check_neptune(void)54*748Sdmick pci_check_neptune(void)
55*748Sdmick {
56*748Sdmick 	uint8_t		oldstatus;
57*748Sdmick 	uint32_t	tmp;
58*748Sdmick 
59*748Sdmick 	/* enable the config address space, bus=0 function=0 */
60*748Sdmick 	oldstatus = inb(PCI_CSE_PORT);
61*748Sdmick 	outb(PCI_CSE_PORT, PCI_MECH2_CONFIG_ENABLE);
62*748Sdmick 	outb(PCI_FORW_PORT, 0);
63*748Sdmick 
64*748Sdmick 	/*
65*748Sdmick 	 * First check the vendor and device ids of the Host to
66*748Sdmick 	 * PCI bridge. But it isn't sufficient just to do this check
67*748Sdmick 	 * because the same device ID can refer to either
68*748Sdmick 	 * the Neptune or Mercury chipset.
69*748Sdmick 	 */
70*748Sdmick 
71*748Sdmick 	/* check the vendor id, the device id, and the revision id */
72*748Sdmick 	/* the Neptune revision ID == 0x11, allow 0x1? */
73*748Sdmick 	if ((inl(PCI_CADDR2(0, PCI_CONF_VENID)) != 0x04a38086) ||
74*748Sdmick 		(inb(PCI_CADDR2(0, PCI_CONF_REVID)) & 0xf0) != 0x10) {
75*748Sdmick 		/* disable mechanism #2 config address space */
76*748Sdmick 		outb(PCI_CSE_PORT, oldstatus);
77*748Sdmick 		return (B_FALSE);
78*748Sdmick 	}
79*748Sdmick 
80*748Sdmick 	/* disable mechanism #2 config address space */
81*748Sdmick 	outb(PCI_CSE_PORT, oldstatus);
82*748Sdmick 
83*748Sdmick 	/*
84*748Sdmick 	 * Now I know that the bridge *might* be a Neptune (it could be
85*748Sdmick 	 * a Mercury chip.) Try enabling mechanism #1 to differentiate
86*748Sdmick 	 * between the two chipsets.
87*748Sdmick 	 */
88*748Sdmick 
89*748Sdmick 	/*
90*748Sdmick 	 * save the old value in case it's not Neptune (the Mercury
91*748Sdmick 	 * chip has the deturbo and reset bits in the 0xcf9 register
92*748Sdmick 	 * and the forward register at 0xcfa)
93*748Sdmick 	 */
94*748Sdmick 	tmp = inl(PCI_CONFADD);
95*748Sdmick 
96*748Sdmick 	/*
97*748Sdmick 	 * The Intel Neptune chipset defines this extra register
98*748Sdmick 	 * to enable Config Mechanism #1.
99*748Sdmick 	 */
100*748Sdmick 	neptune_BIOS_cfg_method = inb(PCI_PMC);
101*748Sdmick 	outb(PCI_PMC, neptune_BIOS_cfg_method | 1);
102*748Sdmick 
103*748Sdmick 	/* make certain mechanism #1 works correctly */
104*748Sdmick 	/* check the vendor and device id's of the Host to PCI bridge */
105*748Sdmick 	outl(PCI_CONFADD, PCI_CADDR1(0, 0, 0, PCI_CONF_VENID));
106*748Sdmick 	if (inl(PCI_CONFDATA) != ((0x04a3 << 16) | 0x8086)) {
107*748Sdmick 		outb(PCI_PMC, neptune_BIOS_cfg_method);
108*748Sdmick 		outl(PCI_CONFADD, tmp);
109*748Sdmick 		return (B_FALSE);
110*748Sdmick 	}
111*748Sdmick 	outb(PCI_PMC, neptune_BIOS_cfg_method);
112*748Sdmick 	return (B_TRUE);
113*748Sdmick }
114*748Sdmick 
115*748Sdmick static void
pci_neptune_enable()116*748Sdmick pci_neptune_enable()
117*748Sdmick {
118*748Sdmick 	/*
119*748Sdmick 	 * Switch the chipset to use Mechanism 1.
120*748Sdmick 	 */
121*748Sdmick 	mutex_enter(&pcicfg_chipset_mutex);
122*748Sdmick 	outb(PCI_PMC, neptune_BIOS_cfg_method | 1);
123*748Sdmick }
124*748Sdmick 
125*748Sdmick static void
pci_neptune_disable()126*748Sdmick pci_neptune_disable()
127*748Sdmick {
128*748Sdmick 	/*
129*748Sdmick 	 * The Neptune chipset has a bug that if you write the PMC,
130*748Sdmick 	 * it erroneously looks at some of the bits in the latches for
131*748Sdmick 	 * adjacent registers... like, say, the "reset" bit.  We zero
132*748Sdmick 	 * out the config address register to work around this bug.
133*748Sdmick 	 */
134*748Sdmick 	outl(PCI_CONFADD, PCI_CADDR1(0, 0, 0, 0));
135*748Sdmick 	outb(PCI_PMC, neptune_BIOS_cfg_method);
136*748Sdmick 	mutex_exit(&pcicfg_chipset_mutex);
137*748Sdmick }
138*748Sdmick 
139*748Sdmick uint8_t
pci_neptune_getb(int bus,int device,int function,int reg)140*748Sdmick pci_neptune_getb(int bus, int device, int function, int reg)
141*748Sdmick {
142*748Sdmick 	uint8_t	val;
143*748Sdmick 
144*748Sdmick 	pci_neptune_enable();
145*748Sdmick 
146*748Sdmick 	val = pci_mech1_getb(bus, device, function, reg);
147*748Sdmick 
148*748Sdmick 	pci_neptune_disable();
149*748Sdmick 	return (val);
150*748Sdmick }
151*748Sdmick 
152*748Sdmick uint16_t
pci_neptune_getw(int bus,int device,int function,int reg)153*748Sdmick pci_neptune_getw(int bus, int device, int function, int reg)
154*748Sdmick {
155*748Sdmick 	uint16_t val;
156*748Sdmick 
157*748Sdmick 	pci_neptune_enable();
158*748Sdmick 
159*748Sdmick 	val = pci_mech1_getw(bus, device, function, reg);
160*748Sdmick 
161*748Sdmick 	pci_neptune_disable();
162*748Sdmick 	return (val);
163*748Sdmick }
164*748Sdmick 
165*748Sdmick uint32_t
pci_neptune_getl(int bus,int device,int function,int reg)166*748Sdmick pci_neptune_getl(int bus, int device, int function, int reg)
167*748Sdmick {
168*748Sdmick 	uint32_t val;
169*748Sdmick 
170*748Sdmick 	pci_neptune_enable();
171*748Sdmick 
172*748Sdmick 	val = pci_mech1_getl(bus, device, function, reg);
173*748Sdmick 
174*748Sdmick 	pci_neptune_disable();
175*748Sdmick 	return (val);
176*748Sdmick }
177*748Sdmick 
178*748Sdmick void
pci_neptune_putb(int bus,int device,int function,int reg,uint8_t val)179*748Sdmick pci_neptune_putb(int bus, int device, int function, int reg, uint8_t val)
180*748Sdmick {
181*748Sdmick 	pci_neptune_enable();
182*748Sdmick 
183*748Sdmick 	pci_mech1_putb(bus, device, function, reg, val);
184*748Sdmick 
185*748Sdmick 	pci_neptune_disable();
186*748Sdmick }
187*748Sdmick 
188*748Sdmick void
pci_neptune_putw(int bus,int device,int function,int reg,uint16_t val)189*748Sdmick pci_neptune_putw(int bus, int device, int function, int reg, uint16_t val)
190*748Sdmick {
191*748Sdmick 	pci_neptune_enable();
192*748Sdmick 
193*748Sdmick 	pci_mech1_putw(bus, device, function, reg, val);
194*748Sdmick 
195*748Sdmick 	pci_neptune_disable();
196*748Sdmick }
197*748Sdmick 
198*748Sdmick void
pci_neptune_putl(int bus,int device,int function,int reg,uint32_t val)199*748Sdmick pci_neptune_putl(int bus, int device, int function, int reg, uint32_t val)
200*748Sdmick {
201*748Sdmick 	pci_neptune_enable();
202*748Sdmick 
203*748Sdmick 	pci_mech1_putl(bus, device, function, reg, val);
204*748Sdmick 
205*748Sdmick 	pci_neptune_disable();
206*748Sdmick }
207