xref: /illumos-gate/usr/src/uts/i86pc/os/pci_neptune.c (revision 2d6eb4a5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*c88420b3Sdmick  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * Support for Intel "Neptune" PCI chip set
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/pci.h>
337c478bd9Sstevel@tonic-gate #include <sys/pci_impl.h>
347c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
35*c88420b3Sdmick #include <sys/pci_cfgspace_impl.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * This variable is a place holder for the initial value in PCI_PMC register
397c478bd9Sstevel@tonic-gate  * of neptune chipset.
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate static unsigned char neptune_BIOS_cfg_method = 0;
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * Special hack for Intel's Neptune chipset, 82433NX and 82434NX.
457c478bd9Sstevel@tonic-gate  *
467c478bd9Sstevel@tonic-gate  * The motherboards I've seen still use a version of the BIOS
477c478bd9Sstevel@tonic-gate  * that operates using Configuration Mechanism #2 like the older
487c478bd9Sstevel@tonic-gate  * Mercury BIOS and chipset (the 82433LX and 82434LX).
497c478bd9Sstevel@tonic-gate  *
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate boolean_t
pci_check_neptune(void)527c478bd9Sstevel@tonic-gate pci_check_neptune(void)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate 	uint8_t		oldstatus;
557c478bd9Sstevel@tonic-gate 	uint32_t	tmp;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	/* enable the config address space, bus=0 function=0 */
587c478bd9Sstevel@tonic-gate 	oldstatus = inb(PCI_CSE_PORT);
597c478bd9Sstevel@tonic-gate 	outb(PCI_CSE_PORT, PCI_MECH2_CONFIG_ENABLE);
607c478bd9Sstevel@tonic-gate 	outb(PCI_FORW_PORT, 0);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	/*
637c478bd9Sstevel@tonic-gate 	 * First check the vendor and device ids of the Host to
647c478bd9Sstevel@tonic-gate 	 * PCI bridge. But it isn't sufficient just to do this check
657c478bd9Sstevel@tonic-gate 	 * because the same device ID can refer to either
667c478bd9Sstevel@tonic-gate 	 * the Neptune or Mercury chipset.
677c478bd9Sstevel@tonic-gate 	 */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	/* check the vendor id, the device id, and the revision id */
707c478bd9Sstevel@tonic-gate 	/* the Neptune revision ID == 0x11, allow 0x1? */
717c478bd9Sstevel@tonic-gate 	if ((inl(PCI_CADDR2(0, PCI_CONF_VENID)) != 0x04a38086) ||
727c478bd9Sstevel@tonic-gate 		(inb(PCI_CADDR2(0, PCI_CONF_REVID)) & 0xf0) != 0x10) {
737c478bd9Sstevel@tonic-gate 		/* disable mechanism #2 config address space */
747c478bd9Sstevel@tonic-gate 		outb(PCI_CSE_PORT, oldstatus);
757c478bd9Sstevel@tonic-gate 		return (B_FALSE);
767c478bd9Sstevel@tonic-gate 	}
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	/* disable mechanism #2 config address space */
797c478bd9Sstevel@tonic-gate 	outb(PCI_CSE_PORT, oldstatus);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	/*
827c478bd9Sstevel@tonic-gate 	 * Now I know that the bridge *might* be a Neptune (it could be
837c478bd9Sstevel@tonic-gate 	 * a Mercury chip.) Try enabling mechanism #1 to differentiate
847c478bd9Sstevel@tonic-gate 	 * between the two chipsets.
857c478bd9Sstevel@tonic-gate 	 */
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	/*
887c478bd9Sstevel@tonic-gate 	 * save the old value in case it's not Neptune (the Mercury
897c478bd9Sstevel@tonic-gate 	 * chip has the deturbo and reset bits in the 0xcf9 register
907c478bd9Sstevel@tonic-gate 	 * and the forward register at 0xcfa)
917c478bd9Sstevel@tonic-gate 	 */
927c478bd9Sstevel@tonic-gate 	tmp = inl(PCI_CONFADD);
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	/*
957c478bd9Sstevel@tonic-gate 	 * The Intel Neptune chipset defines this extra register
967c478bd9Sstevel@tonic-gate 	 * to enable Config Mechanism #1.
977c478bd9Sstevel@tonic-gate 	 */
987c478bd9Sstevel@tonic-gate 	neptune_BIOS_cfg_method = inb(PCI_PMC);
997c478bd9Sstevel@tonic-gate 	outb(PCI_PMC, neptune_BIOS_cfg_method | 1);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	/* make certain mechanism #1 works correctly */
1027c478bd9Sstevel@tonic-gate 	/* check the vendor and device id's of the Host to PCI bridge */
1037c478bd9Sstevel@tonic-gate 	outl(PCI_CONFADD, PCI_CADDR1(0, 0, 0, PCI_CONF_VENID));
1047c478bd9Sstevel@tonic-gate 	if (inl(PCI_CONFDATA) != ((0x04a3 << 16) | 0x8086)) {
1057c478bd9Sstevel@tonic-gate 		outb(PCI_PMC, neptune_BIOS_cfg_method);
1067c478bd9Sstevel@tonic-gate 		outl(PCI_CONFADD, tmp);
1077c478bd9Sstevel@tonic-gate 		return (B_FALSE);
1087c478bd9Sstevel@tonic-gate 	}
1097c478bd9Sstevel@tonic-gate 	outb(PCI_PMC, neptune_BIOS_cfg_method);
1107c478bd9Sstevel@tonic-gate 	return (B_TRUE);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate static void
pci_neptune_enable()1147c478bd9Sstevel@tonic-gate pci_neptune_enable()
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	/*
1177c478bd9Sstevel@tonic-gate 	 * Switch the chipset to use Mechanism 1.
1187c478bd9Sstevel@tonic-gate 	 */
1197c478bd9Sstevel@tonic-gate 	mutex_enter(&pcicfg_chipset_mutex);
1207c478bd9Sstevel@tonic-gate 	outb(PCI_PMC, neptune_BIOS_cfg_method | 1);
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate static void
pci_neptune_disable()1247c478bd9Sstevel@tonic-gate pci_neptune_disable()
1257c478bd9Sstevel@tonic-gate {
1267c478bd9Sstevel@tonic-gate 	/*
1277c478bd9Sstevel@tonic-gate 	 * The Neptune chipset has a bug that if you write the PMC,
1287c478bd9Sstevel@tonic-gate 	 * it erroneously looks at some of the bits in the latches for
1297c478bd9Sstevel@tonic-gate 	 * adjacent registers... like, say, the "reset" bit.  We zero
1307c478bd9Sstevel@tonic-gate 	 * out the config address register to work around this bug.
1317c478bd9Sstevel@tonic-gate 	 */
1327c478bd9Sstevel@tonic-gate 	outl(PCI_CONFADD, PCI_CADDR1(0, 0, 0, 0));
1337c478bd9Sstevel@tonic-gate 	outb(PCI_PMC, neptune_BIOS_cfg_method);
1347c478bd9Sstevel@tonic-gate 	mutex_exit(&pcicfg_chipset_mutex);
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate uint8_t
pci_neptune_getb(int bus,int device,int function,int reg)1387c478bd9Sstevel@tonic-gate pci_neptune_getb(int bus, int device, int function, int reg)
1397c478bd9Sstevel@tonic-gate {
1407c478bd9Sstevel@tonic-gate 	uint8_t	val;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	pci_neptune_enable();
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	val = pci_mech1_getb(bus, device, function, reg);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	pci_neptune_disable();
1477c478bd9Sstevel@tonic-gate 	return (val);
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate uint16_t
pci_neptune_getw(int bus,int device,int function,int reg)1517c478bd9Sstevel@tonic-gate pci_neptune_getw(int bus, int device, int function, int reg)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate 	uint16_t val;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	pci_neptune_enable();
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	val = pci_mech1_getw(bus, device, function, reg);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	pci_neptune_disable();
1607c478bd9Sstevel@tonic-gate 	return (val);
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate uint32_t
pci_neptune_getl(int bus,int device,int function,int reg)1647c478bd9Sstevel@tonic-gate pci_neptune_getl(int bus, int device, int function, int reg)
1657c478bd9Sstevel@tonic-gate {
1667c478bd9Sstevel@tonic-gate 	uint32_t val;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	pci_neptune_enable();
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	val = pci_mech1_getl(bus, device, function, reg);
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	pci_neptune_disable();
1737c478bd9Sstevel@tonic-gate 	return (val);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate void
pci_neptune_putb(int bus,int device,int function,int reg,uint8_t val)1777c478bd9Sstevel@tonic-gate pci_neptune_putb(int bus, int device, int function, int reg, uint8_t val)
1787c478bd9Sstevel@tonic-gate {
1797c478bd9Sstevel@tonic-gate 	pci_neptune_enable();
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	pci_mech1_putb(bus, device, function, reg, val);
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	pci_neptune_disable();
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate void
pci_neptune_putw(int bus,int device,int function,int reg,uint16_t val)1877c478bd9Sstevel@tonic-gate pci_neptune_putw(int bus, int device, int function, int reg, uint16_t val)
1887c478bd9Sstevel@tonic-gate {
1897c478bd9Sstevel@tonic-gate 	pci_neptune_enable();
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	pci_mech1_putw(bus, device, function, reg, val);
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	pci_neptune_disable();
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate void
pci_neptune_putl(int bus,int device,int function,int reg,uint32_t val)1977c478bd9Sstevel@tonic-gate pci_neptune_putl(int bus, int device, int function, int reg, uint32_t val)
1987c478bd9Sstevel@tonic-gate {
1997c478bd9Sstevel@tonic-gate 	pci_neptune_enable();
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	pci_mech1_putl(bus, device, function, reg, val);
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	pci_neptune_disable();
2047c478bd9Sstevel@tonic-gate }
205