xref: /onnv-gate/usr/src/uts/sun4u/excalibur/os/excalibur.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/param.h>
30*0Sstevel@tonic-gate #include <sys/systm.h>
31*0Sstevel@tonic-gate #include <sys/sysmacros.h>
32*0Sstevel@tonic-gate #include <sys/sunddi.h>
33*0Sstevel@tonic-gate #include <sys/esunddi.h>
34*0Sstevel@tonic-gate #include <sys/sunndi.h>
35*0Sstevel@tonic-gate #include <sys/conf.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #include <sys/platform_module.h>
38*0Sstevel@tonic-gate #include <sys/errno.h>
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #include <sys/sunldi.h>
41*0Sstevel@tonic-gate #include <sys/file.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #define	SHARED_PCF8584_PATH "/pci@8,700000/ebus@5/i2c@1,2e/nvram@0,a0"
44*0Sstevel@tonic-gate static dev_info_t *shared_pcf8584_dip;
45*0Sstevel@tonic-gate static kmutex_t excal_pcf8584_mutex;
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate int (*p2get_mem_unum)(int, uint64_t, char *, int, int *);
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /*
50*0Sstevel@tonic-gate  * Excalibur fan information
51*0Sstevel@tonic-gate  */
52*0Sstevel@tonic-gate typedef struct xcalfan_info {
53*0Sstevel@tonic-gate 	char		*pathname;
54*0Sstevel@tonic-gate 	int8_t		val8;
55*0Sstevel@tonic-gate 	ldi_handle_t	lh;
56*0Sstevel@tonic-gate } xcalfan_info_t;
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate static xcalfan_info_t xcalfans[] = {
59*0Sstevel@tonic-gate 	{"/pci@8,700000/ebus@5/i2c@1,30/fan-control@0,48:2", 63, NULL},
60*0Sstevel@tonic-gate 	{"/pci@8,700000/ebus@5/i2c@1,30/fan-control@0,48:0", 63, NULL},
61*0Sstevel@tonic-gate 	{"/pci@8,700000/ebus@5/i2c@1,30/fan-control@0,48:4", 31, NULL}
62*0Sstevel@tonic-gate };
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate #define	NFANS	(sizeof (xcalfans) / sizeof (xcalfans[0]))
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate void
startup_platform(void)67*0Sstevel@tonic-gate startup_platform(void)
68*0Sstevel@tonic-gate {
69*0Sstevel@tonic-gate 	mutex_init(&excal_pcf8584_mutex, NULL, NULL, NULL);
70*0Sstevel@tonic-gate }
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate int
set_platform_tsb_spares()73*0Sstevel@tonic-gate set_platform_tsb_spares()
74*0Sstevel@tonic-gate {
75*0Sstevel@tonic-gate 	return (0);
76*0Sstevel@tonic-gate }
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate void
set_platform_defaults(void)79*0Sstevel@tonic-gate set_platform_defaults(void)
80*0Sstevel@tonic-gate {
81*0Sstevel@tonic-gate }
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate void
load_platform_drivers(void)84*0Sstevel@tonic-gate load_platform_drivers(void)
85*0Sstevel@tonic-gate {
86*0Sstevel@tonic-gate 	ldi_ident_t	li;
87*0Sstevel@tonic-gate 	dev_info_t	*dip;
88*0Sstevel@tonic-gate 	char		**drv;
89*0Sstevel@tonic-gate 	int		i, err;
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate 	static char *boot_time_drivers[] = {
92*0Sstevel@tonic-gate 		"todds1287",
93*0Sstevel@tonic-gate 		"us",
94*0Sstevel@tonic-gate 		"mc-us3",
95*0Sstevel@tonic-gate 		"bbc_beep",
96*0Sstevel@tonic-gate 		"max1617",
97*0Sstevel@tonic-gate 		"tda8444",
98*0Sstevel@tonic-gate 		"seeprom",
99*0Sstevel@tonic-gate 		NULL
100*0Sstevel@tonic-gate 	};
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	for (drv = boot_time_drivers; *drv; drv++) {
103*0Sstevel@tonic-gate 		if ((i_ddi_attach_hw_nodes(*drv) != DDI_SUCCESS) &&
104*0Sstevel@tonic-gate 		    (strcmp(*drv, "us") != 0))
105*0Sstevel@tonic-gate 			/*
106*0Sstevel@tonic-gate 			 * It is OK if 'us' driver doesn't load. It's
107*0Sstevel@tonic-gate 			 * not available in Core cluster.
108*0Sstevel@tonic-gate 			 */
109*0Sstevel@tonic-gate 			cmn_err(CE_WARN, "Failed to install \"%s\" driver.",
110*0Sstevel@tonic-gate 			    *drv);
111*0Sstevel@tonic-gate 	}
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate 	/*
114*0Sstevel@tonic-gate 	 * mc-us3 must stay loaded for plat_get_mem_unum()
115*0Sstevel@tonic-gate 	 */
116*0Sstevel@tonic-gate 	(void) ddi_hold_driver(ddi_name_to_major("mc-us3"));
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate 	/*
119*0Sstevel@tonic-gate 	 * Figure out which pcf8584_dip is shared with OBP for the nvram
120*0Sstevel@tonic-gate 	 * device, so the lock can be acquired.
121*0Sstevel@tonic-gate 	 *
122*0Sstevel@tonic-gate 	 * This should really be done elsewhere, like startup_platform, but
123*0Sstevel@tonic-gate 	 * that runs before the devinfo tree is setup with configure().
124*0Sstevel@tonic-gate 	 * So it is here until there is a better place.
125*0Sstevel@tonic-gate 	 */
126*0Sstevel@tonic-gate 	dip = e_ddi_hold_devi_by_path(SHARED_PCF8584_PATH, 0);
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate 	ASSERT(dip != NULL);
129*0Sstevel@tonic-gate 	shared_pcf8584_dip = ddi_get_parent(dip);
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	ndi_hold_devi(shared_pcf8584_dip);
132*0Sstevel@tonic-gate 	ndi_rele_devi(dip);
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate 	li = ldi_ident_from_anon();
135*0Sstevel@tonic-gate 	for (i = 0; i < NFANS; ++i) {
136*0Sstevel@tonic-gate 		err = ldi_open_by_name(xcalfans[i].pathname,
137*0Sstevel@tonic-gate 		    FWRITE, kcred, &xcalfans[i].lh, li);
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate 		if (err != 0) {
140*0Sstevel@tonic-gate 			cmn_err(CE_WARN, "plat_fan_blast: "
141*0Sstevel@tonic-gate 			    "Failed to get fan device handle for %s",
142*0Sstevel@tonic-gate 			    xcalfans[i].pathname);
143*0Sstevel@tonic-gate 			continue;
144*0Sstevel@tonic-gate 		}
145*0Sstevel@tonic-gate 	}
146*0Sstevel@tonic-gate 	ldi_ident_release(li);
147*0Sstevel@tonic-gate }
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate /*ARGSUSED*/
150*0Sstevel@tonic-gate int
plat_cpu_poweron(struct cpu * cp)151*0Sstevel@tonic-gate plat_cpu_poweron(struct cpu *cp)
152*0Sstevel@tonic-gate {
153*0Sstevel@tonic-gate 	return (ENOTSUP);	/* not supported on this platform */
154*0Sstevel@tonic-gate }
155*0Sstevel@tonic-gate 
156*0Sstevel@tonic-gate /*ARGSUSED*/
157*0Sstevel@tonic-gate int
plat_cpu_poweroff(struct cpu * cp)158*0Sstevel@tonic-gate plat_cpu_poweroff(struct cpu *cp)
159*0Sstevel@tonic-gate {
160*0Sstevel@tonic-gate 	return (ENOTSUP);	/* not supported on this platform */
161*0Sstevel@tonic-gate }
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate /*ARGSUSED*/
164*0Sstevel@tonic-gate void
plat_freelist_process(int mnode)165*0Sstevel@tonic-gate plat_freelist_process(int mnode)
166*0Sstevel@tonic-gate {
167*0Sstevel@tonic-gate }
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate char *platform_module_list[] = {
170*0Sstevel@tonic-gate 	"schppm",	/* must attach before xcalppm */
171*0Sstevel@tonic-gate 	"xcalppm",
172*0Sstevel@tonic-gate 	(char *)0
173*0Sstevel@tonic-gate };
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate /*ARGSUSED*/
176*0Sstevel@tonic-gate void
plat_tod_fault(enum tod_fault_type tod_bad)177*0Sstevel@tonic-gate plat_tod_fault(enum tod_fault_type tod_bad)
178*0Sstevel@tonic-gate {
179*0Sstevel@tonic-gate }
180*0Sstevel@tonic-gate 
181*0Sstevel@tonic-gate /*ARGSUSED*/
182*0Sstevel@tonic-gate int
plat_get_mem_unum(int synd_code,uint64_t flt_addr,int flt_bus_id,int flt_in_memory,ushort_t flt_status,char * buf,int buflen,int * lenp)183*0Sstevel@tonic-gate plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
184*0Sstevel@tonic-gate     int flt_in_memory, ushort_t flt_status, char *buf, int buflen, int *lenp)
185*0Sstevel@tonic-gate {
186*0Sstevel@tonic-gate 	if (flt_in_memory && (p2get_mem_unum != NULL))
187*0Sstevel@tonic-gate 		return (p2get_mem_unum(synd_code, P2ALIGN(flt_addr, 8),
188*0Sstevel@tonic-gate 			buf, buflen, lenp));
189*0Sstevel@tonic-gate 	else
190*0Sstevel@tonic-gate 		return (ENOTSUP);
191*0Sstevel@tonic-gate }
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate int
plat_get_cpu_unum(int cpuid,char * buf,int buflen,int * lenp)194*0Sstevel@tonic-gate plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
195*0Sstevel@tonic-gate {
196*0Sstevel@tonic-gate 	if (snprintf(buf, buflen, "Slot %d", cpuid) >= buflen) {
197*0Sstevel@tonic-gate 		return (ENOSPC);
198*0Sstevel@tonic-gate 	} else {
199*0Sstevel@tonic-gate 		*lenp = strlen(buf);
200*0Sstevel@tonic-gate 		return (0);
201*0Sstevel@tonic-gate 	}
202*0Sstevel@tonic-gate }
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate /*
205*0Sstevel@tonic-gate  * Unfortunately, excal's BBC pcf8584 controller is used by both OBP
206*0Sstevel@tonic-gate  * and the OS's i2c drivers.  The 'eeprom' command executes
207*0Sstevel@tonic-gate  * OBP code to handle property requests.  If eeprom didn't do this, or if the
208*0Sstevel@tonic-gate  * controllers were partitioned so that all devices on a given controller were
209*0Sstevel@tonic-gate  * driven by either OBP or the OS, this wouldn't be necessary.
210*0Sstevel@tonic-gate  *
211*0Sstevel@tonic-gate  * Note that getprop doesn't have the same issue as it reads from cached
212*0Sstevel@tonic-gate  * memory in OBP.
213*0Sstevel@tonic-gate  */
214*0Sstevel@tonic-gate 
215*0Sstevel@tonic-gate /*
216*0Sstevel@tonic-gate  * Common locking enter code
217*0Sstevel@tonic-gate  */
218*0Sstevel@tonic-gate void
plat_setprop_enter(void)219*0Sstevel@tonic-gate plat_setprop_enter(void)
220*0Sstevel@tonic-gate {
221*0Sstevel@tonic-gate 	mutex_enter(&excal_pcf8584_mutex);
222*0Sstevel@tonic-gate }
223*0Sstevel@tonic-gate 
224*0Sstevel@tonic-gate /*
225*0Sstevel@tonic-gate  * Common locking exit code
226*0Sstevel@tonic-gate  */
227*0Sstevel@tonic-gate void
plat_setprop_exit(void)228*0Sstevel@tonic-gate plat_setprop_exit(void)
229*0Sstevel@tonic-gate {
230*0Sstevel@tonic-gate 	mutex_exit(&excal_pcf8584_mutex);
231*0Sstevel@tonic-gate }
232*0Sstevel@tonic-gate 
233*0Sstevel@tonic-gate /*
234*0Sstevel@tonic-gate  * Called by pcf8584 driver
235*0Sstevel@tonic-gate  */
236*0Sstevel@tonic-gate void
plat_shared_i2c_enter(dev_info_t * dip)237*0Sstevel@tonic-gate plat_shared_i2c_enter(dev_info_t *dip)
238*0Sstevel@tonic-gate {
239*0Sstevel@tonic-gate 	if (dip == shared_pcf8584_dip) {
240*0Sstevel@tonic-gate 		plat_setprop_enter();
241*0Sstevel@tonic-gate 	}
242*0Sstevel@tonic-gate }
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate /*
245*0Sstevel@tonic-gate  * Called by pcf8584 driver
246*0Sstevel@tonic-gate  */
247*0Sstevel@tonic-gate void
plat_shared_i2c_exit(dev_info_t * dip)248*0Sstevel@tonic-gate plat_shared_i2c_exit(dev_info_t *dip)
249*0Sstevel@tonic-gate {
250*0Sstevel@tonic-gate 	if (dip == shared_pcf8584_dip) {
251*0Sstevel@tonic-gate 		plat_setprop_exit();
252*0Sstevel@tonic-gate 	}
253*0Sstevel@tonic-gate }
254*0Sstevel@tonic-gate 
255*0Sstevel@tonic-gate /*
256*0Sstevel@tonic-gate  * Set platform fans to maximum speed
257*0Sstevel@tonic-gate  */
258*0Sstevel@tonic-gate void
plat_fan_blast(void)259*0Sstevel@tonic-gate plat_fan_blast(void)
260*0Sstevel@tonic-gate {
261*0Sstevel@tonic-gate 	struct uio	uio;
262*0Sstevel@tonic-gate 	struct iovec	iov;
263*0Sstevel@tonic-gate 	int8_t		fv;
264*0Sstevel@tonic-gate 	int		err;
265*0Sstevel@tonic-gate 	int		i;
266*0Sstevel@tonic-gate 
267*0Sstevel@tonic-gate 	for (i = 0; i < NFANS; ++i) {
268*0Sstevel@tonic-gate 		fv = xcalfans[i].val8;
269*0Sstevel@tonic-gate 		bzero(&uio, sizeof (uio));
270*0Sstevel@tonic-gate 		bzero(&iov, sizeof (iov));
271*0Sstevel@tonic-gate 		iov.iov_base = &fv;
272*0Sstevel@tonic-gate 		iov.iov_len = sizeof (fv);
273*0Sstevel@tonic-gate 		uio.uio_iov = &iov;
274*0Sstevel@tonic-gate 		uio.uio_iovcnt = 1;
275*0Sstevel@tonic-gate 		uio.uio_loffset = 0;
276*0Sstevel@tonic-gate 		uio.uio_segflg = UIO_SYSSPACE;
277*0Sstevel@tonic-gate 		uio.uio_resid = sizeof (fv);
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate 		err = ldi_write(xcalfans[i].lh, &uio, kcred);
280*0Sstevel@tonic-gate 		if (err != 0) {
281*0Sstevel@tonic-gate 			if (err == EAGAIN) {
282*0Sstevel@tonic-gate 				cmn_err(CE_WARN, "!plat_fan_blast: Cannot "
283*0Sstevel@tonic-gate 				    "write %d to %s now, try again later.",
284*0Sstevel@tonic-gate 				    xcalfans[i].val8, xcalfans[i].pathname);
285*0Sstevel@tonic-gate 			} else {
286*0Sstevel@tonic-gate 				cmn_err(CE_WARN, "plat_fan_blast: "
287*0Sstevel@tonic-gate 				    "Error %d while writing %d to %s.", err,
288*0Sstevel@tonic-gate 				    xcalfans[i].val8, xcalfans[i].pathname);
289*0Sstevel@tonic-gate 			}
290*0Sstevel@tonic-gate 		}
291*0Sstevel@tonic-gate 	}
292*0Sstevel@tonic-gate }
293