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