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/sunddi.h>
32*0Sstevel@tonic-gate #include <sys/sunndi.h>
33*0Sstevel@tonic-gate #include <sys/modctl.h>
34*0Sstevel@tonic-gate #include <sys/sysmacros.h>
35*0Sstevel@tonic-gate #include <sys/platform_module.h>
36*0Sstevel@tonic-gate #include <sys/errno.h>
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate * This platmod is used by both SUNW,Sun-Fire-280R (a.k.a littleneck) and
40*0Sstevel@tonic-gate * SUNW,Netra-T4 (a.k.a. lw2plus) platforms.
41*0Sstevel@tonic-gate */
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate #define LITTLENECK_NVRAM_PATH "/pci@8,700000/ebus@5/i2c@1,2e/nvram@0,a0"
44*0Sstevel@tonic-gate #define LW2PLUS_NVRAM_PATH "/pci@8,700000/ebus@5/i2c@1,30/nvram@0,e0"
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate static dev_info_t *shared_pcf8584_dip = NULL;
47*0Sstevel@tonic-gate static kmutex_t lneck_pcf8584_mutex;
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate int (*p2get_mem_unum)(int, uint64_t, char *, int, int *);
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate void
startup_platform(void)52*0Sstevel@tonic-gate startup_platform(void)
53*0Sstevel@tonic-gate {
54*0Sstevel@tonic-gate mutex_init(&lneck_pcf8584_mutex, NULL, NULL, NULL);
55*0Sstevel@tonic-gate }
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate int
set_platform_tsb_spares()58*0Sstevel@tonic-gate set_platform_tsb_spares()
59*0Sstevel@tonic-gate {
60*0Sstevel@tonic-gate return (0);
61*0Sstevel@tonic-gate }
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate void
set_platform_defaults(void)64*0Sstevel@tonic-gate set_platform_defaults(void)
65*0Sstevel@tonic-gate {
66*0Sstevel@tonic-gate }
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate void
load_platform_drivers(void)69*0Sstevel@tonic-gate load_platform_drivers(void)
70*0Sstevel@tonic-gate {
71*0Sstevel@tonic-gate char **drv;
72*0Sstevel@tonic-gate dev_info_t *nvram_dip;
73*0Sstevel@tonic-gate static char *boot_time_drivers[] = {
74*0Sstevel@tonic-gate "todds1287",
75*0Sstevel@tonic-gate "pcf8574",
76*0Sstevel@tonic-gate "mc-us3",
77*0Sstevel@tonic-gate NULL
78*0Sstevel@tonic-gate };
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate for (drv = boot_time_drivers; *drv; drv++) {
81*0Sstevel@tonic-gate if (i_ddi_attach_hw_nodes(*drv) != DDI_SUCCESS)
82*0Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to install \"%s\" driver.",
83*0Sstevel@tonic-gate *drv);
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate /* hold modules for keyswitch polling and plat_get_mem_unum() */
87*0Sstevel@tonic-gate (void) ddi_hold_driver(ddi_name_to_major("pcf8574"));
88*0Sstevel@tonic-gate (void) ddi_hold_driver(ddi_name_to_major("mc-us3"));
89*0Sstevel@tonic-gate
90*0Sstevel@tonic-gate /*
91*0Sstevel@tonic-gate * For littleneck we figure out which pcf8584 dip is shared with
92*0Sstevel@tonic-gate * OBP for the nvram device, so the lock can be acquired.
93*0Sstevel@tonic-gate * If this fails see if we're running on a Netra 20.
94*0Sstevel@tonic-gate * The Netra 20 nvram node is the SCC and is also shared by
95*0Sstevel@tonic-gate * Solaris and OBP.
96*0Sstevel@tonic-gate */
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate nvram_dip = e_ddi_hold_devi_by_path(LITTLENECK_NVRAM_PATH, 0);
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate if (nvram_dip == NULL)
101*0Sstevel@tonic-gate nvram_dip = e_ddi_hold_devi_by_path(LW2PLUS_NVRAM_PATH, 0);
102*0Sstevel@tonic-gate if (nvram_dip == NULL)
103*0Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to hold pcf8584");
104*0Sstevel@tonic-gate else {
105*0Sstevel@tonic-gate shared_pcf8584_dip = ddi_get_parent(nvram_dip);
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate ndi_hold_devi(shared_pcf8584_dip);
108*0Sstevel@tonic-gate ndi_rele_devi(nvram_dip);
109*0Sstevel@tonic-gate }
110*0Sstevel@tonic-gate }
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate /*ARGSUSED*/
113*0Sstevel@tonic-gate int
plat_cpu_poweron(struct cpu * cp)114*0Sstevel@tonic-gate plat_cpu_poweron(struct cpu *cp)
115*0Sstevel@tonic-gate {
116*0Sstevel@tonic-gate return (ENOTSUP); /* not supported on this platform */
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gate /*ARGSUSED*/
120*0Sstevel@tonic-gate int
plat_cpu_poweroff(struct cpu * cp)121*0Sstevel@tonic-gate plat_cpu_poweroff(struct cpu *cp)
122*0Sstevel@tonic-gate {
123*0Sstevel@tonic-gate return (ENOTSUP); /* not supported on this platform */
124*0Sstevel@tonic-gate }
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate /*ARGSUSED*/
127*0Sstevel@tonic-gate void
plat_freelist_process(int mnode)128*0Sstevel@tonic-gate plat_freelist_process(int mnode)
129*0Sstevel@tonic-gate {
130*0Sstevel@tonic-gate }
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate /*
133*0Sstevel@tonic-gate * No platform drivers on this platform
134*0Sstevel@tonic-gate */
135*0Sstevel@tonic-gate char *platform_module_list[] = {
136*0Sstevel@tonic-gate (char *)0
137*0Sstevel@tonic-gate };
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate /*ARGSUSED*/
140*0Sstevel@tonic-gate void
plat_tod_fault(enum tod_fault_type tod_bad)141*0Sstevel@tonic-gate plat_tod_fault(enum tod_fault_type tod_bad)
142*0Sstevel@tonic-gate {
143*0Sstevel@tonic-gate }
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate /*ARGSUSED*/
146*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)147*0Sstevel@tonic-gate plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
148*0Sstevel@tonic-gate int flt_in_memory, ushort_t flt_status, char *buf, int buflen, int *lenp)
149*0Sstevel@tonic-gate {
150*0Sstevel@tonic-gate if (flt_in_memory && (p2get_mem_unum != NULL))
151*0Sstevel@tonic-gate return (p2get_mem_unum(synd_code, P2ALIGN(flt_addr, 8),
152*0Sstevel@tonic-gate buf, buflen, lenp));
153*0Sstevel@tonic-gate else
154*0Sstevel@tonic-gate return (ENOTSUP);
155*0Sstevel@tonic-gate }
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gate int
plat_get_cpu_unum(int cpuid,char * buf,int buflen,int * lenp)158*0Sstevel@tonic-gate plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
159*0Sstevel@tonic-gate {
160*0Sstevel@tonic-gate if (snprintf(buf, buflen, "Slot %d", cpuid) >= buflen) {
161*0Sstevel@tonic-gate return (ENOSPC);
162*0Sstevel@tonic-gate } else {
163*0Sstevel@tonic-gate *lenp = strlen(buf);
164*0Sstevel@tonic-gate return (0);
165*0Sstevel@tonic-gate }
166*0Sstevel@tonic-gate }
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate /*
169*0Sstevel@tonic-gate * Littleneck's BBC pcf8584 controller is used by both OBP and the OS's i2c
170*0Sstevel@tonic-gate * drivers. The 'eeprom' command executes OBP code to handle property requests.
171*0Sstevel@tonic-gate * If eeprom didn't do this, or if the controllers were partitioned so that all
172*0Sstevel@tonic-gate * devices on a given controller were driven by either OBP or the OS, this
173*0Sstevel@tonic-gate * wouldn't be necessary.
174*0Sstevel@tonic-gate *
175*0Sstevel@tonic-gate * Note that getprop doesn't have the same issue as it reads from cached
176*0Sstevel@tonic-gate * memory in OBP.
177*0Sstevel@tonic-gate */
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate /*
180*0Sstevel@tonic-gate * Common locking enter code
181*0Sstevel@tonic-gate */
182*0Sstevel@tonic-gate void
plat_setprop_enter(void)183*0Sstevel@tonic-gate plat_setprop_enter(void)
184*0Sstevel@tonic-gate {
185*0Sstevel@tonic-gate mutex_enter(&lneck_pcf8584_mutex);
186*0Sstevel@tonic-gate }
187*0Sstevel@tonic-gate
188*0Sstevel@tonic-gate /*
189*0Sstevel@tonic-gate * Common locking exit code
190*0Sstevel@tonic-gate */
191*0Sstevel@tonic-gate void
plat_setprop_exit(void)192*0Sstevel@tonic-gate plat_setprop_exit(void)
193*0Sstevel@tonic-gate {
194*0Sstevel@tonic-gate mutex_exit(&lneck_pcf8584_mutex);
195*0Sstevel@tonic-gate }
196*0Sstevel@tonic-gate
197*0Sstevel@tonic-gate /*
198*0Sstevel@tonic-gate * Called by pcf8584 driver
199*0Sstevel@tonic-gate */
200*0Sstevel@tonic-gate void
plat_shared_i2c_enter(dev_info_t * i2cnexus_dip)201*0Sstevel@tonic-gate plat_shared_i2c_enter(dev_info_t *i2cnexus_dip)
202*0Sstevel@tonic-gate {
203*0Sstevel@tonic-gate if (i2cnexus_dip == shared_pcf8584_dip) {
204*0Sstevel@tonic-gate plat_setprop_enter();
205*0Sstevel@tonic-gate }
206*0Sstevel@tonic-gate }
207*0Sstevel@tonic-gate
208*0Sstevel@tonic-gate /*
209*0Sstevel@tonic-gate * Called by pcf8584 driver
210*0Sstevel@tonic-gate */
211*0Sstevel@tonic-gate void
plat_shared_i2c_exit(dev_info_t * i2cnexus_dip)212*0Sstevel@tonic-gate plat_shared_i2c_exit(dev_info_t *i2cnexus_dip)
213*0Sstevel@tonic-gate {
214*0Sstevel@tonic-gate if (i2cnexus_dip == shared_pcf8584_dip) {
215*0Sstevel@tonic-gate plat_setprop_exit();
216*0Sstevel@tonic-gate }
217*0Sstevel@tonic-gate }
218