xref: /onnv-gate/usr/src/uts/sun4v/ontario/os/ontario.c (revision 789:b348f31ed315)
1187Sdf157793 /*
2187Sdf157793  * CDDL HEADER START
3187Sdf157793  *
4187Sdf157793  * The contents of this file are subject to the terms of the
5187Sdf157793  * Common Development and Distribution License, Version 1.0 only
6187Sdf157793  * (the "License").  You may not use this file except in compliance
7187Sdf157793  * with the License.
8187Sdf157793  *
9187Sdf157793  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10187Sdf157793  * or http://www.opensolaris.org/os/licensing.
11187Sdf157793  * See the License for the specific language governing permissions
12187Sdf157793  * and limitations under the License.
13187Sdf157793  *
14187Sdf157793  * When distributing Covered Code, include this CDDL HEADER in each
15187Sdf157793  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16187Sdf157793  * If applicable, add the following below this CDDL HEADER, with the
17187Sdf157793  * fields enclosed by brackets "[]" replaced with your own identifying
18187Sdf157793  * information: Portions Copyright [yyyy] [name of copyright owner]
19187Sdf157793  *
20187Sdf157793  * CDDL HEADER END
21187Sdf157793  */
22187Sdf157793 
23187Sdf157793 /*
24187Sdf157793  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25187Sdf157793  * Use is subject to license terms.
26187Sdf157793  */
27187Sdf157793 
28187Sdf157793 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29187Sdf157793 
30187Sdf157793 #include <sys/param.h>
31187Sdf157793 #include <sys/systm.h>
32187Sdf157793 #include <sys/sysmacros.h>
33187Sdf157793 #include <sys/sunddi.h>
34187Sdf157793 #include <sys/esunddi.h>
35187Sdf157793 #include <sys/sunndi.h>
36187Sdf157793 
37187Sdf157793 #include <sys/platform_module.h>
38187Sdf157793 #include <sys/errno.h>
39187Sdf157793 #include <sys/utsname.h>
40187Sdf157793 #include <sys/modctl.h>
41187Sdf157793 #include <sys/systeminfo.h>
42187Sdf157793 #include <sys/promif.h>
43187Sdf157793 #include <sys/bootconf.h>
44187Sdf157793 
45187Sdf157793 /*
46187Sdf157793  * Definitions for accessing the pci config space of the isa node
47187Sdf157793  * of Southbridge.
48187Sdf157793  */
49654Sdf157793 #define	ONTARIO_ISA_PATHNAME	"/pci@7c0/pci@0/pci@1/pci@0/isa@2"
50654Sdf157793 #define	ONTARIO_IDE_PATHNAME	"/pci@7c0/pci@0/pci@1/pci@0/ide@8"
51187Sdf157793 
52187Sdf157793 /*
53187Sdf157793  * Handle for isa pci space
54187Sdf157793  */
55187Sdf157793 static ddi_acc_handle_t isa_handle;
56187Sdf157793 
57187Sdf157793 /*
58187Sdf157793  * Platform power management drivers list - empty by default
59187Sdf157793  */
60187Sdf157793 char *platform_module_list[] = {
61187Sdf157793 	(char *)0
62187Sdf157793 };
63187Sdf157793 
64187Sdf157793 
65187Sdf157793 /*ARGSUSED*/
66187Sdf157793 void
plat_tod_fault(enum tod_fault_type tod_bad)67187Sdf157793 plat_tod_fault(enum tod_fault_type tod_bad)
68187Sdf157793 {
69187Sdf157793 }
70187Sdf157793 
71187Sdf157793 void
load_platform_drivers(void)72187Sdf157793 load_platform_drivers(void)
73187Sdf157793 {
74187Sdf157793 	dev_info_t 		*dip;		/* dip of the isa driver */
75*789Sahrens 	pnode_t 		nodeid;
76187Sdf157793 
77187Sdf157793 	/*
78187Sdf157793 	 * Install ISA driver. This is required for the southbridge IDE
79187Sdf157793 	 * workaround - to reset the IDE channel during IDE bus reset.
80187Sdf157793 	 * Panic the system in case ISA driver could not be loaded or
81187Sdf157793 	 * any problem in accessing its pci config space. Since the register
82187Sdf157793 	 * to reset the channel for IDE is in ISA config space!.
83187Sdf157793 	 */
84187Sdf157793 
85187Sdf157793 	nodeid = prom_finddevice(ONTARIO_IDE_PATHNAME);
86187Sdf157793 	if (nodeid == OBP_BADNODE) {
87187Sdf157793 		return;
88187Sdf157793 	}
89187Sdf157793 	dip = e_ddi_hold_devi_by_path(ONTARIO_ISA_PATHNAME, 0);
90187Sdf157793 	if (dip == NULL) {
91187Sdf157793 		cmn_err(CE_PANIC, "Could not install the isa driver\n");
92187Sdf157793 		return;
93187Sdf157793 	}
94187Sdf157793 
95187Sdf157793 	if (pci_config_setup(dip, &isa_handle) != DDI_SUCCESS) {
96187Sdf157793 		cmn_err(CE_PANIC, "Could not get the config space of isa\n");
97187Sdf157793 		return;
98187Sdf157793 	}
99187Sdf157793 }
100187Sdf157793 
101187Sdf157793 /*
102187Sdf157793  * This routine provides a workaround for a bug in the SB chip which
103187Sdf157793  * can cause data corruption. Will be invoked from the IDE HBA driver for
104187Sdf157793  * Acer SouthBridge at the time of IDE bus reset.
105187Sdf157793  */
106187Sdf157793 /*ARGSUSED*/
107187Sdf157793 int
plat_ide_chipreset(dev_info_t * dip,int chno)108187Sdf157793 plat_ide_chipreset(dev_info_t *dip, int chno)
109187Sdf157793 {
110187Sdf157793 	uint8_t	val;
111187Sdf157793 	int	ret = DDI_SUCCESS;
112187Sdf157793 
113187Sdf157793 	if (isa_handle == NULL) {
114187Sdf157793 		return (DDI_FAILURE);
115187Sdf157793 	}
116187Sdf157793 
117187Sdf157793 	val = pci_config_get8(isa_handle, 0x58);
118187Sdf157793 	/*
119187Sdf157793 	 * The dip passed as the argument is not used here.
120187Sdf157793 	 * This will be needed for platforms which have multiple on-board SB,
121187Sdf157793 	 * The dip passed will be used to match the corresponding ISA node.
122187Sdf157793 	 */
123187Sdf157793 	switch (chno) {
124187Sdf157793 	case 0:
125187Sdf157793 		/*
126187Sdf157793 		 * First disable the primary channel then re-enable it.
127187Sdf157793 		 * As per ALI no wait should be required in between have
128187Sdf157793 		 * given 1ms delay in between to be on safer side.
129187Sdf157793 		 * bit 2 of register 0x58 when 0 disable the channel 0.
130187Sdf157793 		 * bit 2 of register 0x58 when 1 enables the channel 0.
131187Sdf157793 		 */
132187Sdf157793 		pci_config_put8(isa_handle, 0x58, val & 0xFB);
133187Sdf157793 		drv_usecwait(1000);
134187Sdf157793 		pci_config_put8(isa_handle, 0x58, val);
135187Sdf157793 		break;
136187Sdf157793 	case 1:
137187Sdf157793 		/*
138187Sdf157793 		 * bit 3 of register 0x58 when 0 disable the channel 1.
139187Sdf157793 		 * bit 3 of register 0x58 when 1 enables the channel 1.
140187Sdf157793 		 */
141187Sdf157793 		pci_config_put8(isa_handle, 0x58, val & 0xF7);
142187Sdf157793 		drv_usecwait(1000);
143187Sdf157793 		pci_config_put8(isa_handle, 0x58, val);
144187Sdf157793 		break;
145187Sdf157793 	default:
146187Sdf157793 		/*
147187Sdf157793 		 * Unknown channel number passed. Return failure.
148187Sdf157793 		 */
149187Sdf157793 		ret = DDI_FAILURE;
150187Sdf157793 	}
151187Sdf157793 
152187Sdf157793 	return (ret);
153187Sdf157793 }
154