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 (c) 2000 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 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/promif.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/promimpl.h> 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * This file contains the implementations of all Starcat-specific promif 34*7c478bd9Sstevel@tonic-gate * routines. Refer to FWARC case 2000/420 for the definitions of the 35*7c478bd9Sstevel@tonic-gate * platform-specific interfaces provided by Starcat OBP. 36*7c478bd9Sstevel@tonic-gate */ 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate static char *switch_tunnel_cmd = "SUNW,Starcat,switch-tunnel"; 39*7c478bd9Sstevel@tonic-gate static char *iosram_read_cmd = "SUNW,Starcat,iosram-read"; 40*7c478bd9Sstevel@tonic-gate static char *iosram_write_cmd = "SUNW,Starcat,iosram-write"; 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* 43*7c478bd9Sstevel@tonic-gate * Given the portid of the IOB to which the tunnel should be moved and the type 44*7c478bd9Sstevel@tonic-gate * of move that should be performed, ask OBP to switch the IOSRAM tunnel from 45*7c478bd9Sstevel@tonic-gate * its current host IOB to a new location. If the move type is 0, OBP will 46*7c478bd9Sstevel@tonic-gate * coordinate the change with SMS and will copy data from the current location 47*7c478bd9Sstevel@tonic-gate * to the new location. If the move type is 1, OBP will simply mark the new 48*7c478bd9Sstevel@tonic-gate * location valid and start using it, without doing any data copying and without 49*7c478bd9Sstevel@tonic-gate * communicating with SMS. Return 0 on success, non-zero on failure. 50*7c478bd9Sstevel@tonic-gate */ 51*7c478bd9Sstevel@tonic-gate int 52*7c478bd9Sstevel@tonic-gate prom_starcat_switch_tunnel(uint_t portid, uint_t msgtype) 53*7c478bd9Sstevel@tonic-gate { 54*7c478bd9Sstevel@tonic-gate static uint8_t warned = 0; 55*7c478bd9Sstevel@tonic-gate cell_t ci[6]; 56*7c478bd9Sstevel@tonic-gate int rv; 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate * Make sure we have the necessary support in OBP. 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate if (prom_test(switch_tunnel_cmd) == 0) { 62*7c478bd9Sstevel@tonic-gate ci[0] = p1275_ptr2cell(switch_tunnel_cmd); /* name */ 63*7c478bd9Sstevel@tonic-gate } else { 64*7c478bd9Sstevel@tonic-gate if (!warned) { 65*7c478bd9Sstevel@tonic-gate warned = 1; 66*7c478bd9Sstevel@tonic-gate prom_printf( 67*7c478bd9Sstevel@tonic-gate "Warning: No prom support for switch-tunnel!\n"); 68*7c478bd9Sstevel@tonic-gate } 69*7c478bd9Sstevel@tonic-gate return (-1); 70*7c478bd9Sstevel@tonic-gate } 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate /* 73*7c478bd9Sstevel@tonic-gate * Set up the arguments and call into OBP. 74*7c478bd9Sstevel@tonic-gate */ 75*7c478bd9Sstevel@tonic-gate ci[1] = (cell_t)2; /* #argument cells */ 76*7c478bd9Sstevel@tonic-gate ci[2] = (cell_t)1; /* #result cells */ 77*7c478bd9Sstevel@tonic-gate ci[3] = p1275_uint2cell(portid); 78*7c478bd9Sstevel@tonic-gate ci[4] = p1275_uint2cell(msgtype); 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate promif_preprom(); 81*7c478bd9Sstevel@tonic-gate rv = p1275_cif_handler(&ci); 82*7c478bd9Sstevel@tonic-gate promif_postprom(); 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate /* 85*7c478bd9Sstevel@tonic-gate * p1275_cif_handler will return 0 on success, non-zero on failure. If 86*7c478bd9Sstevel@tonic-gate * it fails, the return cell from OBP is meaningless, because the OBP 87*7c478bd9Sstevel@tonic-gate * client interface probably wasn't even invoked. OBP will return 0 on 88*7c478bd9Sstevel@tonic-gate * failure and non-zero on success for this interface. 89*7c478bd9Sstevel@tonic-gate */ 90*7c478bd9Sstevel@tonic-gate if (rv != 0) { 91*7c478bd9Sstevel@tonic-gate return (rv); 92*7c478bd9Sstevel@tonic-gate } else if (p1275_cell2int(ci[5]) == 0) { 93*7c478bd9Sstevel@tonic-gate return (-1); 94*7c478bd9Sstevel@tonic-gate } else { 95*7c478bd9Sstevel@tonic-gate return (0); 96*7c478bd9Sstevel@tonic-gate } 97*7c478bd9Sstevel@tonic-gate } 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate /* 100*7c478bd9Sstevel@tonic-gate * Request that OBP read 'len' bytes, starting at 'offset' in the IOSRAM chunk 101*7c478bd9Sstevel@tonic-gate * associated with 'key', into the memory indicated by 'buf'. Although there is 102*7c478bd9Sstevel@tonic-gate * a driver that provides this functionality, there are certain cases where the 103*7c478bd9Sstevel@tonic-gate * OS requires access to IOSRAM before the driver is loaded. Return 0 on 104*7c478bd9Sstevel@tonic-gate * success, non-zero on failure. 105*7c478bd9Sstevel@tonic-gate */ 106*7c478bd9Sstevel@tonic-gate int 107*7c478bd9Sstevel@tonic-gate prom_starcat_iosram_read(uint32_t key, uint32_t offset, uint32_t len, 108*7c478bd9Sstevel@tonic-gate caddr_t buf) 109*7c478bd9Sstevel@tonic-gate { 110*7c478bd9Sstevel@tonic-gate static uint8_t warned = 0; 111*7c478bd9Sstevel@tonic-gate cell_t ci[8]; 112*7c478bd9Sstevel@tonic-gate int rv; 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /* 115*7c478bd9Sstevel@tonic-gate * Make sure we have the necessary support in OBP. 116*7c478bd9Sstevel@tonic-gate */ 117*7c478bd9Sstevel@tonic-gate if (prom_test(iosram_read_cmd) == 0) { 118*7c478bd9Sstevel@tonic-gate ci[0] = p1275_ptr2cell(iosram_read_cmd); /* name */ 119*7c478bd9Sstevel@tonic-gate } else { 120*7c478bd9Sstevel@tonic-gate if (!warned) { 121*7c478bd9Sstevel@tonic-gate warned = 1; 122*7c478bd9Sstevel@tonic-gate prom_printf( 123*7c478bd9Sstevel@tonic-gate "Warning: No prom support for iosram-read!\n"); 124*7c478bd9Sstevel@tonic-gate } 125*7c478bd9Sstevel@tonic-gate return (-1); 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate /* 129*7c478bd9Sstevel@tonic-gate * Set up the arguments and call into OBP. Note that the argument order 130*7c478bd9Sstevel@tonic-gate * needs to be reversed to accomodate OBP. The order must remain as it 131*7c478bd9Sstevel@tonic-gate * is in the function prototype to maintain intercompatibility with the 132*7c478bd9Sstevel@tonic-gate * IOSRAM driver's equivalent routine. 133*7c478bd9Sstevel@tonic-gate */ 134*7c478bd9Sstevel@tonic-gate ci[1] = (cell_t)4; /* #argument cells */ 135*7c478bd9Sstevel@tonic-gate ci[2] = (cell_t)1; /* #result cells */ 136*7c478bd9Sstevel@tonic-gate ci[3] = p1275_ptr2cell(buf); 137*7c478bd9Sstevel@tonic-gate ci[4] = p1275_uint2cell(len); 138*7c478bd9Sstevel@tonic-gate ci[5] = p1275_uint2cell(offset); 139*7c478bd9Sstevel@tonic-gate ci[6] = p1275_uint2cell(key); 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate promif_preprom(); 142*7c478bd9Sstevel@tonic-gate rv = p1275_cif_handler(&ci); 143*7c478bd9Sstevel@tonic-gate promif_postprom(); 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /* 146*7c478bd9Sstevel@tonic-gate * p1275_cif_handler will return 0 on success, non-zero on failure. If 147*7c478bd9Sstevel@tonic-gate * it fails, the return cell from OBP is meaningless, because the OBP 148*7c478bd9Sstevel@tonic-gate * client interface probably wasn't even invoked. OBP will return 0 on 149*7c478bd9Sstevel@tonic-gate * success and non-zero on failure for this interface. 150*7c478bd9Sstevel@tonic-gate */ 151*7c478bd9Sstevel@tonic-gate if (rv != 0) { 152*7c478bd9Sstevel@tonic-gate return (rv); 153*7c478bd9Sstevel@tonic-gate } else if (p1275_cell2int(ci[7]) == 0) { 154*7c478bd9Sstevel@tonic-gate return (0); 155*7c478bd9Sstevel@tonic-gate } else { 156*7c478bd9Sstevel@tonic-gate return (-1); 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate /* 161*7c478bd9Sstevel@tonic-gate * Request that OBP write 'len' bytes from the memory indicated by 'buf' into 162*7c478bd9Sstevel@tonic-gate * the IOSRAM chunk associated with 'key', starting at 'offset'. Although there 163*7c478bd9Sstevel@tonic-gate * is a driver that provides this functionality, there are certain cases where 164*7c478bd9Sstevel@tonic-gate * the OS requires access to IOSRAM before the driver is loaded. Return 0 on 165*7c478bd9Sstevel@tonic-gate * success, non-zero on failure. 166*7c478bd9Sstevel@tonic-gate */ 167*7c478bd9Sstevel@tonic-gate int 168*7c478bd9Sstevel@tonic-gate prom_starcat_iosram_write(uint32_t key, uint32_t offset, uint32_t len, 169*7c478bd9Sstevel@tonic-gate caddr_t buf) 170*7c478bd9Sstevel@tonic-gate { 171*7c478bd9Sstevel@tonic-gate static uint8_t warned = 0; 172*7c478bd9Sstevel@tonic-gate cell_t ci[8]; 173*7c478bd9Sstevel@tonic-gate int rv; 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate /* 176*7c478bd9Sstevel@tonic-gate * Make sure we have the necessary support in OBP. 177*7c478bd9Sstevel@tonic-gate */ 178*7c478bd9Sstevel@tonic-gate if (prom_test(iosram_write_cmd) == 0) { 179*7c478bd9Sstevel@tonic-gate ci[0] = p1275_ptr2cell(iosram_write_cmd); /* name */ 180*7c478bd9Sstevel@tonic-gate } else { 181*7c478bd9Sstevel@tonic-gate if (!warned) { 182*7c478bd9Sstevel@tonic-gate warned = 1; 183*7c478bd9Sstevel@tonic-gate prom_printf( 184*7c478bd9Sstevel@tonic-gate "Warning: No prom support for iosram-write!\n"); 185*7c478bd9Sstevel@tonic-gate } 186*7c478bd9Sstevel@tonic-gate return (-1); 187*7c478bd9Sstevel@tonic-gate } 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate /* 190*7c478bd9Sstevel@tonic-gate * Set up the arguments and call into OBP. Note that the argument order 191*7c478bd9Sstevel@tonic-gate * needs to be reversed to accomodate OBP. The order must remain as it 192*7c478bd9Sstevel@tonic-gate * is in the function prototype to maintain intercompatibility with the 193*7c478bd9Sstevel@tonic-gate * IOSRAM driver's equivalent routine. 194*7c478bd9Sstevel@tonic-gate */ 195*7c478bd9Sstevel@tonic-gate ci[1] = (cell_t)4; /* #argument cells */ 196*7c478bd9Sstevel@tonic-gate ci[2] = (cell_t)1; /* #result cells */ 197*7c478bd9Sstevel@tonic-gate ci[3] = p1275_ptr2cell(buf); 198*7c478bd9Sstevel@tonic-gate ci[4] = p1275_uint2cell(len); 199*7c478bd9Sstevel@tonic-gate ci[5] = p1275_uint2cell(offset); 200*7c478bd9Sstevel@tonic-gate ci[6] = p1275_uint2cell(key); 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate promif_preprom(); 203*7c478bd9Sstevel@tonic-gate rv = p1275_cif_handler(&ci); 204*7c478bd9Sstevel@tonic-gate promif_postprom(); 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate /* 207*7c478bd9Sstevel@tonic-gate * p1275_cif_handler will return 0 on success, non-zero on failure. If 208*7c478bd9Sstevel@tonic-gate * it fails, the return cell from OBP is meaningless, because the OBP 209*7c478bd9Sstevel@tonic-gate * client interface probably wasn't even invoked. OBP will return 0 on 210*7c478bd9Sstevel@tonic-gate * success and non-zero on failure for this interface. 211*7c478bd9Sstevel@tonic-gate */ 212*7c478bd9Sstevel@tonic-gate if (rv != 0) { 213*7c478bd9Sstevel@tonic-gate return (rv); 214*7c478bd9Sstevel@tonic-gate } else if (p1275_cell2int(ci[7]) == 0) { 215*7c478bd9Sstevel@tonic-gate return (0); 216*7c478bd9Sstevel@tonic-gate } else { 217*7c478bd9Sstevel@tonic-gate return (-1); 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate } 220