xref: /illumos-gate/usr/src/uts/sun4u/littleneck/os/littleneck.c (revision ed093b41a93e8563e6e1e5dae0768dda2a7bcc27)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <sys/param.h>
28 #include <sys/systm.h>
29 #include <sys/sunddi.h>
30 #include <sys/sunndi.h>
31 #include <sys/modctl.h>
32 #include <sys/sysmacros.h>
33 #include <sys/platform_module.h>
34 #include <sys/errno.h>
35 
36 /*
37  * This platmod is used by both SUNW,Sun-Fire-280R (a.k.a littleneck) and
38  * SUNW,Netra-T4 (a.k.a. lw2plus) platforms.
39  */
40 
41 #define	LITTLENECK_NVRAM_PATH	"/pci@8,700000/ebus@5/i2c@1,2e/nvram@0,a0"
42 #define	LW2PLUS_NVRAM_PATH	"/pci@8,700000/ebus@5/i2c@1,30/nvram@0,e0"
43 
44 static dev_info_t *shared_pcf8584_dip = NULL;
45 static kmutex_t lneck_pcf8584_mutex;
46 
47 int (*p2get_mem_unum)(int, uint64_t, char *, int, int *);
48 
49 void
50 startup_platform(void)
51 {
52 	mutex_init(&lneck_pcf8584_mutex, NULL, MUTEX_ADAPTIVE, NULL);
53 }
54 
55 int
56 set_platform_tsb_spares()
57 {
58 	return (0);
59 }
60 
61 void
62 set_platform_defaults(void)
63 {
64 }
65 
66 void
67 load_platform_drivers(void)
68 {
69 	char		**drv;
70 	dev_info_t	*nvram_dip;
71 	static char	*boot_time_drivers[] = {
72 		"todds1287",
73 		"pcf8574",
74 		"mc-us3",
75 		NULL
76 	};
77 
78 	for (drv = boot_time_drivers; *drv; drv++) {
79 		if (i_ddi_attach_hw_nodes(*drv) != DDI_SUCCESS)
80 			cmn_err(CE_WARN, "Failed to install \"%s\" driver.",
81 			    *drv);
82 	}
83 
84 	/* hold modules for keyswitch polling and plat_get_mem_unum() */
85 	(void) ddi_hold_driver(ddi_name_to_major("pcf8574"));
86 	(void) ddi_hold_driver(ddi_name_to_major("mc-us3"));
87 
88 	/*
89 	 * For littleneck we figure out which pcf8584 dip is shared with
90 	 * OBP for the nvram device, so the lock can be acquired.
91 	 * If this fails see if we're running on a Netra 20.
92 	 * The Netra 20 nvram node is the SCC and is also shared by
93 	 * Solaris and OBP.
94 	 */
95 
96 	nvram_dip = e_ddi_hold_devi_by_path(LITTLENECK_NVRAM_PATH, 0);
97 
98 	if (nvram_dip == NULL)
99 		nvram_dip = e_ddi_hold_devi_by_path(LW2PLUS_NVRAM_PATH, 0);
100 	if (nvram_dip == NULL)
101 		cmn_err(CE_WARN, "Failed to hold pcf8584");
102 	else {
103 		shared_pcf8584_dip = ddi_get_parent(nvram_dip);
104 
105 		ndi_hold_devi(shared_pcf8584_dip);
106 		ndi_rele_devi(nvram_dip);
107 	}
108 }
109 
110 /*ARGSUSED*/
111 int
112 plat_cpu_poweron(struct cpu *cp)
113 {
114 	return (ENOTSUP);	/* not supported on this platform */
115 }
116 
117 /*ARGSUSED*/
118 int
119 plat_cpu_poweroff(struct cpu *cp)
120 {
121 	return (ENOTSUP);	/* not supported on this platform */
122 }
123 
124 /*ARGSUSED*/
125 void
126 plat_freelist_process(int mnode)
127 {
128 }
129 
130 /*
131  * No platform drivers on this platform
132  */
133 char *platform_module_list[] = {
134 	(char *)0
135 };
136 
137 /*ARGSUSED*/
138 void
139 plat_tod_fault(enum tod_fault_type tod_bad)
140 {
141 }
142 
143 /*ARGSUSED*/
144 int
145 plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
146     int flt_in_memory, ushort_t flt_status, char *buf, int buflen, int *lenp)
147 {
148 	if (flt_in_memory && (p2get_mem_unum != NULL))
149 		return (p2get_mem_unum(synd_code, P2ALIGN(flt_addr, 8),
150 		    buf, buflen, lenp));
151 	else
152 		return (ENOTSUP);
153 }
154 
155 int
156 plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
157 {
158 	if (snprintf(buf, buflen, "Slot %d", cpuid) >= buflen) {
159 		return (ENOSPC);
160 	} else {
161 		*lenp = strlen(buf);
162 		return (0);
163 	}
164 }
165 
166 /*
167  * Littleneck's BBC pcf8584 controller is used by both OBP and the OS's i2c
168  * drivers.  The 'eeprom' command executes OBP code to handle property requests.
169  * If eeprom didn't do this, or if the controllers were partitioned so that all
170  * devices on a given controller were driven by either OBP or the OS, this
171  * wouldn't be necessary.
172  *
173  * Note that getprop doesn't have the same issue as it reads from cached
174  * memory in OBP.
175  */
176 
177 /*
178  * Common locking enter code
179  */
180 void
181 plat_setprop_enter(void)
182 {
183 	mutex_enter(&lneck_pcf8584_mutex);
184 }
185 
186 /*
187  * Common locking exit code
188  */
189 void
190 plat_setprop_exit(void)
191 {
192 	mutex_exit(&lneck_pcf8584_mutex);
193 }
194 
195 /*
196  * Called by pcf8584 driver
197  */
198 void
199 plat_shared_i2c_enter(dev_info_t *i2cnexus_dip)
200 {
201 	if (i2cnexus_dip == shared_pcf8584_dip) {
202 		plat_setprop_enter();
203 	}
204 }
205 
206 /*
207  * Called by pcf8584 driver
208  */
209 void
210 plat_shared_i2c_exit(dev_info_t *i2cnexus_dip)
211 {
212 	if (i2cnexus_dip == shared_pcf8584_dip) {
213 		plat_setprop_exit();
214 	}
215 }
216