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