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