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) 1991-1995, 1996, 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 /*
30*0Sstevel@tonic-gate * This module provides kernel callbacks to IEEE 1275-1994 system.
31*0Sstevel@tonic-gate * such that address and name lookups can work and use kernel symbol names.
32*0Sstevel@tonic-gate * For example "ctrace" will provide symbolic names, if they are available.
33*0Sstevel@tonic-gate * Also, normal firmware name to address lookups should work, though be
34*0Sstevel@tonic-gate * careful with clashing kernel names, such as "startup" and "reset" which
35*0Sstevel@tonic-gate * may be the firmware names and *not* the kernel names.
36*0Sstevel@tonic-gate *
37*0Sstevel@tonic-gate * This file contains the glue that gets control from the firmware and
38*0Sstevel@tonic-gate * transfers data from/to the firmware.
39*0Sstevel@tonic-gate *
40*0Sstevel@tonic-gate * The platform code needs to provide the routines add_vx_handler
41*0Sstevel@tonic-gate * and remove_vx_handler, which add/remove an Open Firmware callback
42*0Sstevel@tonic-gate * handler for a given callback name.
43*0Sstevel@tonic-gate */
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate #include <sys/types.h>
46*0Sstevel@tonic-gate #include <sys/param.h>
47*0Sstevel@tonic-gate #include <sys/systm.h>
48*0Sstevel@tonic-gate #include <sys/debug.h>
49*0Sstevel@tonic-gate #include <sys/errno.h>
50*0Sstevel@tonic-gate #include <sys/modctl.h>
51*0Sstevel@tonic-gate #include <sys/kobj.h>
52*0Sstevel@tonic-gate #include <sys/promif.h>
53*0Sstevel@tonic-gate #include <sys/prom_isa.h>
54*0Sstevel@tonic-gate #include <sys/ddi.h>
55*0Sstevel@tonic-gate #include <sys/sunddi.h>
56*0Sstevel@tonic-gate #include <sys/reboot.h>
57*0Sstevel@tonic-gate #include <rpc/types.h>
58*0Sstevel@tonic-gate #include <rpc/xdr.h>
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate #define DPRINTF(str) if (obpsym_debug) prom_printf(str)
61*0Sstevel@tonic-gate #define DPRINTF1(str, a) if (obpsym_debug) prom_printf(str, a);
62*0Sstevel@tonic-gate #define DPRINTF2(str, a, b) if (obpsym_debug) prom_printf(str, a, b);
63*0Sstevel@tonic-gate #define DXPRINTF if (obpsym_debug > 1) prom_printf
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate #define MAX_NAME 128
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate static void
ieee_sym_to_value(cell_t * cif)69*0Sstevel@tonic-gate ieee_sym_to_value(cell_t *cif)
70*0Sstevel@tonic-gate {
71*0Sstevel@tonic-gate int error = -1;
72*0Sstevel@tonic-gate uintptr_t symvalue = 0;
73*0Sstevel@tonic-gate unsigned int nargs, nresults;
74*0Sstevel@tonic-gate char *symname;
75*0Sstevel@tonic-gate extern int name_to_value(char *name, uintptr_t *value);
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate nargs = p1275_cell2uint(cif[1]);
78*0Sstevel@tonic-gate nresults = p1275_cell2uint(cif[2]);
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate if (nresults == 0)
81*0Sstevel@tonic-gate return; /* No room for results. Just return. */
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate /*
84*0Sstevel@tonic-gate * If there are no arguments, fall through and return an error.
85*0Sstevel@tonic-gate * Otherwise, try to translate the symbol name arg to a value.
86*0Sstevel@tonic-gate */
87*0Sstevel@tonic-gate if (nargs != 0) {
88*0Sstevel@tonic-gate symname = p1275_cell2ptr(cif[3]); /* argument 0 */
89*0Sstevel@tonic-gate error = name_to_value(symname, &symvalue);
90*0Sstevel@tonic-gate }
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate /*
93*0Sstevel@tonic-gate * Stuff the results in the argument array and set the
94*0Sstevel@tonic-gate * nresults element to the number of results actually returned
95*0Sstevel@tonic-gate * in the argument array. (It's a maximum of 2).
96*0Sstevel@tonic-gate *
97*0Sstevel@tonic-gate * cif[0]: service name ( Pointer to service name )
98*0Sstevel@tonic-gate * cif[1]: nargs ( number of argument cells)
99*0Sstevel@tonic-gate * cif[2]: nresults ( number of result cells)
100*0Sstevel@tonic-gate * cif[3]: argument{0} ( First argument cell )
101*0Sstevel@tonic-gate * ...
102*0Sstevel@tonic-gate * cif[3 + nargs]: result{0} ( First result cell )
103*0Sstevel@tonic-gate * ...
104*0Sstevel@tonic-gate */
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate cif[3 + nargs] = p1275_int2cell(error);
107*0Sstevel@tonic-gate if (nresults > 1) {
108*0Sstevel@tonic-gate cif[3 + nargs + 1] = p1275_uintptr2cell(symvalue);
109*0Sstevel@tonic-gate cif[2] = p1275_int2cell(2); /* there are 2 results */
110*0Sstevel@tonic-gate } else {
111*0Sstevel@tonic-gate cif[2] = p1275_int2cell(1); /* there is 1 result */
112*0Sstevel@tonic-gate }
113*0Sstevel@tonic-gate }
114*0Sstevel@tonic-gate
115*0Sstevel@tonic-gate static char symbol[MAX_NAME];
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate static void
ieee_value_to_sym(cell_t * cif)118*0Sstevel@tonic-gate ieee_value_to_sym(cell_t *cif)
119*0Sstevel@tonic-gate {
120*0Sstevel@tonic-gate u_int nargs, nresults;
121*0Sstevel@tonic-gate u_long value;
122*0Sstevel@tonic-gate u_int offset;
123*0Sstevel@tonic-gate char *name = symbol;
124*0Sstevel@tonic-gate extern u_long value_to_name(uintptr_t value, char *symbol);
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate nargs = p1275_cell2uint(cif[1]);
127*0Sstevel@tonic-gate nresults = p1275_cell2uint(cif[2]);
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate if (nresults == 0)
130*0Sstevel@tonic-gate return; /* No room for results. Just return. */
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate /*
133*0Sstevel@tonic-gate * If there are no arguments, fall through and return "not found".
134*0Sstevel@tonic-gate * Otherwise, try to translate the value to a symbol-name/offset.
135*0Sstevel@tonic-gate */
136*0Sstevel@tonic-gate *name = (char)0;
137*0Sstevel@tonic-gate offset = (u_int)-1;
138*0Sstevel@tonic-gate if (nargs != 0) {
139*0Sstevel@tonic-gate value = p1275_cell2uintptr(cif[3]); /* argument 0 */
140*0Sstevel@tonic-gate offset = value_to_name(value, name);
141*0Sstevel@tonic-gate }
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate /*
144*0Sstevel@tonic-gate * Stuff the results in the argument array and set the
145*0Sstevel@tonic-gate * nresults element to the number of results actually returned
146*0Sstevel@tonic-gate * in the argument array. (It's a maximum of 2).
147*0Sstevel@tonic-gate *
148*0Sstevel@tonic-gate * cif[0]: service name ( Pointer to service name )
149*0Sstevel@tonic-gate * cif[1]: nargs ( number of argument cells)
150*0Sstevel@tonic-gate * cif[2]: nresults ( number of result cells)
151*0Sstevel@tonic-gate * cif[3]: argument{0} ( First argument cell )
152*0Sstevel@tonic-gate * ...
153*0Sstevel@tonic-gate * cif[3 + nargs]: result{0} ( First result cell )
154*0Sstevel@tonic-gate * ...
155*0Sstevel@tonic-gate */
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gate /*
158*0Sstevel@tonic-gate * Treat this as an integer, so we sign-extend -1, offsets
159*0Sstevel@tonic-gate * are always postive, -1 indicates not found.
160*0Sstevel@tonic-gate */
161*0Sstevel@tonic-gate cif[3 + nargs] = p1275_int2cell((int)offset);
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate if (nresults > 1) {
164*0Sstevel@tonic-gate cif[3 + nargs + 1] = p1275_ptr2cell(name);
165*0Sstevel@tonic-gate cif[2] = p1275_int2cell(2); /* there are 2 results */
166*0Sstevel@tonic-gate } else {
167*0Sstevel@tonic-gate cif[2] = p1275_int2cell(1); /* there is 1 result */
168*0Sstevel@tonic-gate }
169*0Sstevel@tonic-gate }
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate void
set_sym_callbacks()172*0Sstevel@tonic-gate set_sym_callbacks()
173*0Sstevel@tonic-gate {
174*0Sstevel@tonic-gate extern int callback_handler(cell_t *arg_array);
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate /*
177*0Sstevel@tonic-gate * This code assumes a wrapper for the callbacks,
178*0Sstevel@tonic-gate * though not all implementations will need them,
179*0Sstevel@tonic-gate * they should be easy enough to provide. It might
180*0Sstevel@tonic-gate * be better to provide these as 2 macros set by each
181*0Sstevel@tonic-gate * platform, this assumes there's a single handler.
182*0Sstevel@tonic-gate */
183*0Sstevel@tonic-gate (void) prom_set_symbol_lookup((void *)callback_handler,
184*0Sstevel@tonic-gate (void *)callback_handler);
185*0Sstevel@tonic-gate }
186*0Sstevel@tonic-gate
187*0Sstevel@tonic-gate int
install_callbacks(void)188*0Sstevel@tonic-gate install_callbacks(void)
189*0Sstevel@tonic-gate {
190*0Sstevel@tonic-gate void add_vx_handler(char *, int, void (*f)(cell_t *));
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gate add_vx_handler("sym-to-value", 0, ieee_sym_to_value);
193*0Sstevel@tonic-gate add_vx_handler("value-to-sym", 0, ieee_value_to_sym);
194*0Sstevel@tonic-gate set_sym_callbacks();
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gate return (0);
197*0Sstevel@tonic-gate }
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate void
remove_callbacks(void)200*0Sstevel@tonic-gate remove_callbacks(void)
201*0Sstevel@tonic-gate {
202*0Sstevel@tonic-gate void remove_vx_handler(char *);
203*0Sstevel@tonic-gate
204*0Sstevel@tonic-gate (void) prom_set_symbol_lookup((void *)0, (void *)0);
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate remove_vx_handler("sym-to-value");
207*0Sstevel@tonic-gate remove_vx_handler("value-to-sym");
208*0Sstevel@tonic-gate }
209