xref: /titanic_51/usr/src/uts/sun4u/snowbird/os/snowbird.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/esunddi.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include <sys/platform_module.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/errno.h>
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate #define	SHARED_SMBUS_PATH	"/pci@1f,0/pci@1,1/pmu@3/i2c@0,0/i2c-nvram@0,8e"
40*7c478bd9Sstevel@tonic-gate static dev_info_t *shared_smbus_dip;
41*7c478bd9Sstevel@tonic-gate static kmutex_t snowbird_smbus_mutex;
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate void
44*7c478bd9Sstevel@tonic-gate startup_platform(void)
45*7c478bd9Sstevel@tonic-gate {
46*7c478bd9Sstevel@tonic-gate 	mutex_init(&snowbird_smbus_mutex, NULL, NULL, NULL);
47*7c478bd9Sstevel@tonic-gate }
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate int
50*7c478bd9Sstevel@tonic-gate set_platform_tsb_spares()
51*7c478bd9Sstevel@tonic-gate {
52*7c478bd9Sstevel@tonic-gate 	return (0);
53*7c478bd9Sstevel@tonic-gate }
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate void
56*7c478bd9Sstevel@tonic-gate set_platform_defaults(void)
57*7c478bd9Sstevel@tonic-gate {
58*7c478bd9Sstevel@tonic-gate 	extern char *tod_module_name;
59*7c478bd9Sstevel@tonic-gate 	tod_module_name = "todds1307";
60*7c478bd9Sstevel@tonic-gate }
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /*
63*7c478bd9Sstevel@tonic-gate  * Definitions for accessing the pci config space of the isa node
64*7c478bd9Sstevel@tonic-gate  * of Southbridge.
65*7c478bd9Sstevel@tonic-gate  */
66*7c478bd9Sstevel@tonic-gate #define	PLATFORM_ISA_PATHNAME	"/pci@1f,0/isa@7"
67*7c478bd9Sstevel@tonic-gate #define	PLATFORM_ISA_PATHNAME_WITH_SIMBA	"/pci@1f,0/pci@1,1/isa@7"
68*7c478bd9Sstevel@tonic-gate ddi_acc_handle_t 	platform_isa_handle;	/* handle for isa pci space */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate void
71*7c478bd9Sstevel@tonic-gate load_platform_drivers(void)
72*7c478bd9Sstevel@tonic-gate {
73*7c478bd9Sstevel@tonic-gate 	dev_info_t 		*dip;		/* dip of the isa driver */
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 	if (ddi_install_driver("power") != DDI_SUCCESS)
76*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "Failed to install \"power\" driver.");
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 	/*
79*7c478bd9Sstevel@tonic-gate 	 * It is OK to return error because 'us' driver is not available
80*7c478bd9Sstevel@tonic-gate 	 * in all clusters (e.g. missing in Core cluster).
81*7c478bd9Sstevel@tonic-gate 	 */
82*7c478bd9Sstevel@tonic-gate 	(void) ddi_install_driver("us");
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 	/*
85*7c478bd9Sstevel@tonic-gate 	 * Install Isa driver. This is required for the southbridge IDE
86*7c478bd9Sstevel@tonic-gate 	 * workaround - to reset the IDE channel during IDE bus reset.
87*7c478bd9Sstevel@tonic-gate 	 * Panic the system in case ISA driver could not be loaded or
88*7c478bd9Sstevel@tonic-gate 	 * any problem in accessing its pci config space. Since the register
89*7c478bd9Sstevel@tonic-gate 	 * to reset the channel for IDE is in ISA config space!.
90*7c478bd9Sstevel@tonic-gate 	 */
91*7c478bd9Sstevel@tonic-gate 	dip = e_ddi_hold_devi_by_path(PLATFORM_ISA_PATHNAME_WITH_SIMBA, 0);
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	if (dip == NULL)
94*7c478bd9Sstevel@tonic-gate 	    dip = e_ddi_hold_devi_by_path(PLATFORM_ISA_PATHNAME, 0);
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate 	if (dip == NULL) {
97*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "Could not install the isa driver\n");
98*7c478bd9Sstevel@tonic-gate 		return;
99*7c478bd9Sstevel@tonic-gate 	}
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate 	if (pci_config_setup(dip, &platform_isa_handle) != DDI_SUCCESS) {
102*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "Could not get the config space of isa\n");
103*7c478bd9Sstevel@tonic-gate 		return;
104*7c478bd9Sstevel@tonic-gate 	}
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 	/*
107*7c478bd9Sstevel@tonic-gate 	 * Figure out which smbus_dip is shared with OBP for the nvram
108*7c478bd9Sstevel@tonic-gate 	 * device, so the lock can be acquired.
109*7c478bd9Sstevel@tonic-gate 	 *
110*7c478bd9Sstevel@tonic-gate 	 * This should really be done elsewhere, like startup_platform, but
111*7c478bd9Sstevel@tonic-gate 	 * that runs before the devinfo tree is setup with configure().
112*7c478bd9Sstevel@tonic-gate 	 * So it is here until there is a better place.
113*7c478bd9Sstevel@tonic-gate 	 */
114*7c478bd9Sstevel@tonic-gate 	dip = e_ddi_hold_devi_by_path(SHARED_SMBUS_PATH, 0);
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	if (dip != NULL) {
117*7c478bd9Sstevel@tonic-gate 		ASSERT(dip != NULL);
118*7c478bd9Sstevel@tonic-gate 		shared_smbus_dip = ddi_get_parent(dip);
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate 		ndi_hold_devi(shared_smbus_dip);
121*7c478bd9Sstevel@tonic-gate 		ndi_rele_devi(dip);
122*7c478bd9Sstevel@tonic-gate 	} else {
123*7c478bd9Sstevel@tonic-gate 		shared_smbus_dip = NULL;
124*7c478bd9Sstevel@tonic-gate 	}
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 	/*
127*7c478bd9Sstevel@tonic-gate 	 * Install the TOD driver
128*7c478bd9Sstevel@tonic-gate 	 */
129*7c478bd9Sstevel@tonic-gate 	if (ddi_install_driver("todds1307") != DDI_SUCCESS)
130*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "Failed to install \"todds1307\" driver.");
131*7c478bd9Sstevel@tonic-gate }
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate /*
134*7c478bd9Sstevel@tonic-gate  * This routine provides a workaround for a bug in the SB chip which
135*7c478bd9Sstevel@tonic-gate  * can cause data corruption. Will be invoked from the IDE HBA driver for
136*7c478bd9Sstevel@tonic-gate  * Acer SouthBridge at the time of IDE bus reset.
137*7c478bd9Sstevel@tonic-gate  */
138*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
139*7c478bd9Sstevel@tonic-gate int
140*7c478bd9Sstevel@tonic-gate plat_ide_chipreset(dev_info_t *dip, int chno)
141*7c478bd9Sstevel@tonic-gate {
142*7c478bd9Sstevel@tonic-gate 	uint8_t	val;
143*7c478bd9Sstevel@tonic-gate 	int	ret = DDI_SUCCESS;
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 	val = pci_config_get8(platform_isa_handle, 0x58);
146*7c478bd9Sstevel@tonic-gate 	/*
147*7c478bd9Sstevel@tonic-gate 	 * The dip passed as the argument is not used for snowbird.
148*7c478bd9Sstevel@tonic-gate 	 * This will be needed for platforms which have multiple on-board SB,
149*7c478bd9Sstevel@tonic-gate 	 * The dip passed will be used to match the corresponding ISA node.
150*7c478bd9Sstevel@tonic-gate 	 */
151*7c478bd9Sstevel@tonic-gate 	switch (chno) {
152*7c478bd9Sstevel@tonic-gate 		case 0:
153*7c478bd9Sstevel@tonic-gate 			/*
154*7c478bd9Sstevel@tonic-gate 			 * First disable the primary channel then re-enable it.
155*7c478bd9Sstevel@tonic-gate 			 * As per ALI no wait should be required in between have
156*7c478bd9Sstevel@tonic-gate 			 * given 1ms delay in between to be on safer side.
157*7c478bd9Sstevel@tonic-gate 			 * bit 2 of register 0x58 when 0 disable the channel 0.
158*7c478bd9Sstevel@tonic-gate 			 * bit 2 of register 0x58 when 1 enables the channel 0.
159*7c478bd9Sstevel@tonic-gate 			 */
160*7c478bd9Sstevel@tonic-gate 			pci_config_put8(platform_isa_handle, 0x58, val & 0xFB);
161*7c478bd9Sstevel@tonic-gate 			drv_usecwait(1000);
162*7c478bd9Sstevel@tonic-gate 			pci_config_put8(platform_isa_handle, 0x58, val);
163*7c478bd9Sstevel@tonic-gate 			break;
164*7c478bd9Sstevel@tonic-gate 		case 1:
165*7c478bd9Sstevel@tonic-gate 			/*
166*7c478bd9Sstevel@tonic-gate 			 * bit 3 of register 0x58 when 0 disable the channel 1.
167*7c478bd9Sstevel@tonic-gate 			 * bit 3 of register 0x58 when 1 enables the channel 1.
168*7c478bd9Sstevel@tonic-gate 			 */
169*7c478bd9Sstevel@tonic-gate 			pci_config_put8(platform_isa_handle, 0x58, val & 0xF7);
170*7c478bd9Sstevel@tonic-gate 			drv_usecwait(1000);
171*7c478bd9Sstevel@tonic-gate 			pci_config_put8(platform_isa_handle, 0x58, val);
172*7c478bd9Sstevel@tonic-gate 			break;
173*7c478bd9Sstevel@tonic-gate 		default:
174*7c478bd9Sstevel@tonic-gate 			/*
175*7c478bd9Sstevel@tonic-gate 			 * Unknown channel number passed. Return failure.
176*7c478bd9Sstevel@tonic-gate 			 */
177*7c478bd9Sstevel@tonic-gate 			ret = DDI_FAILURE;
178*7c478bd9Sstevel@tonic-gate 	}
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 	return (ret);
181*7c478bd9Sstevel@tonic-gate }
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
186*7c478bd9Sstevel@tonic-gate int
187*7c478bd9Sstevel@tonic-gate plat_cpu_poweron(struct cpu *cp)
188*7c478bd9Sstevel@tonic-gate {
189*7c478bd9Sstevel@tonic-gate 	return (ENOTSUP);	/* not supported on this platform */
190*7c478bd9Sstevel@tonic-gate }
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
193*7c478bd9Sstevel@tonic-gate int
194*7c478bd9Sstevel@tonic-gate plat_cpu_poweroff(struct cpu *cp)
195*7c478bd9Sstevel@tonic-gate {
196*7c478bd9Sstevel@tonic-gate 	return (ENOTSUP);	/* not supported on this platform */
197*7c478bd9Sstevel@tonic-gate }
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
200*7c478bd9Sstevel@tonic-gate void
201*7c478bd9Sstevel@tonic-gate plat_freelist_process(int mnode)
202*7c478bd9Sstevel@tonic-gate {
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate char *platform_module_list[] = {
206*7c478bd9Sstevel@tonic-gate 	(char *)0
207*7c478bd9Sstevel@tonic-gate };
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
210*7c478bd9Sstevel@tonic-gate void
211*7c478bd9Sstevel@tonic-gate plat_tod_fault(enum tod_fault_type tod_bad)
212*7c478bd9Sstevel@tonic-gate {
213*7c478bd9Sstevel@tonic-gate }
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate /*
216*7c478bd9Sstevel@tonic-gate  * Unfortunately, snowbird's smbus controller is used by both OBP
217*7c478bd9Sstevel@tonic-gate  * and the OS's i2c drivers.  The 'eeprom' command executes
218*7c478bd9Sstevel@tonic-gate  * OBP code to handle property requests.  If eeprom didn't do this, or if the
219*7c478bd9Sstevel@tonic-gate  * controllers were partitioned so that all devices on a given controller were
220*7c478bd9Sstevel@tonic-gate  * driven by either OBP or the OS, this wouldn't be necessary.
221*7c478bd9Sstevel@tonic-gate  *
222*7c478bd9Sstevel@tonic-gate  * Note that getprop doesn't have the same issue as it reads from cached
223*7c478bd9Sstevel@tonic-gate  * memory in OBP.
224*7c478bd9Sstevel@tonic-gate  */
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate /*
227*7c478bd9Sstevel@tonic-gate  * Common locking enter code
228*7c478bd9Sstevel@tonic-gate  */
229*7c478bd9Sstevel@tonic-gate void
230*7c478bd9Sstevel@tonic-gate plat_setprop_enter(void)
231*7c478bd9Sstevel@tonic-gate {
232*7c478bd9Sstevel@tonic-gate 	mutex_enter(&snowbird_smbus_mutex);
233*7c478bd9Sstevel@tonic-gate }
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate /*
236*7c478bd9Sstevel@tonic-gate  * Common locking exit code
237*7c478bd9Sstevel@tonic-gate  */
238*7c478bd9Sstevel@tonic-gate void
239*7c478bd9Sstevel@tonic-gate plat_setprop_exit(void)
240*7c478bd9Sstevel@tonic-gate {
241*7c478bd9Sstevel@tonic-gate 	mutex_exit(&snowbird_smbus_mutex);
242*7c478bd9Sstevel@tonic-gate }
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate /*
245*7c478bd9Sstevel@tonic-gate  * Called by smbus driver
246*7c478bd9Sstevel@tonic-gate  */
247*7c478bd9Sstevel@tonic-gate void
248*7c478bd9Sstevel@tonic-gate plat_shared_i2c_enter(dev_info_t *dip)
249*7c478bd9Sstevel@tonic-gate {
250*7c478bd9Sstevel@tonic-gate 	if (dip == shared_smbus_dip) {
251*7c478bd9Sstevel@tonic-gate 		plat_setprop_enter();
252*7c478bd9Sstevel@tonic-gate 	}
253*7c478bd9Sstevel@tonic-gate }
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate /*
256*7c478bd9Sstevel@tonic-gate  * Called by smbus driver
257*7c478bd9Sstevel@tonic-gate  */
258*7c478bd9Sstevel@tonic-gate void
259*7c478bd9Sstevel@tonic-gate plat_shared_i2c_exit(dev_info_t *dip)
260*7c478bd9Sstevel@tonic-gate {
261*7c478bd9Sstevel@tonic-gate 	if (dip == shared_smbus_dip) {
262*7c478bd9Sstevel@tonic-gate 		plat_setprop_exit();
263*7c478bd9Sstevel@tonic-gate 	}
264*7c478bd9Sstevel@tonic-gate }
265