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