1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Stuff for mucking about with properties
*
* XXX: There is no distinction between intefer and non-integer properties
* XXX: and no functions included for decoding properties. As is, this
* XXX: file is suitable for a big-endian machine, since properties are
* XXX: encoded using an XDR-like property encoding mechanism, which is
* XXX: big-endian native ordering. To fix this, you need to add type-
* XXX: sensitive decoding mechanisms and have the consumer of the data
* XXX: decode the data, since only the consumer can claim to know the
* XXX: the type of the data. (It can't be done automatically.)
*/
#include <sys/promif.h>
#include <sys/promimpl.h>
#include <sys/platform_module.h>
static void prom_setprop_null(void);
/*
* prom_setprop_{enter,exit} are set to plat_setprop_{enter,exit} on
* platforms which require access to the seeproms to be serialized.
* Otherwise these default to null functions. These functions must be
* called before promif_preprom, since it can sleep and change CPU's,
* thereby failing the assert in promif_postprom().
*/
void (*prom_setprop_enter)(void) = prom_setprop_null;
void (*prom_setprop_exit)(void) = prom_setprop_null;
int
prom_asr_export_len()
{
cell_t ci[4];
ci[0] = p1275_ptr2cell("SUNW,asr-export-len"); /* Service name */
ci[1] = (cell_t)0; /* #argument cells */
ci[2] = (cell_t)1; /* #return cells */
ci[3] = (cell_t)-1; /* Res1: Prime result */
promif_preprom();
(void) p1275_cif_handler(&ci);
promif_postprom();
return (p1275_cell2int(ci[3])); /* Res1: buf length */
}
int
prom_asr_list_keys_len()
{
cell_t ci[4];
ci[0] = p1275_ptr2cell("SUNW,asr-list-keys-len");
ci[1] = (cell_t)0; /* #argument cells */
ci[2] = (cell_t)1; /* #return cells */
ci[3] = (cell_t)-1; /* Res1: Prime result */
promif_preprom();
(void) p1275_cif_handler(&ci);
promif_postprom();
return (p1275_cell2int(ci[3])); /* Res1: buf length */
}
int
prom_asr_export(caddr_t value)
{
int rv;
cell_t ci[5];
ci[0] = p1275_ptr2cell("SUNW,asr-export"); /* Service name */
ci[1] = (cell_t)1; /* #argument cells */
ci[2] = (cell_t)1; /* #return cells */
ci[3] = p1275_ptr2cell(value); /* Arg1: buffer address */
ci[4] = -1; /* Res1: buf len */
promif_preprom();
rv = p1275_cif_handler(&ci);
promif_postprom();
if (rv != 0)
return (-1);
return (p1275_cell2int(ci[4])); /* Res1: buf length */
}
int
prom_asr_list_keys(caddr_t value)
{
int rv;
cell_t ci[5];
ci[0] = p1275_ptr2cell("SUNW,asr-list-keys"); /* Service name */
ci[1] = (cell_t)1; /* #argument cells */
ci[2] = (cell_t)1; /* #return cells */
ci[3] = p1275_ptr2cell(value); /* Arg1: buffer address */
ci[4] = -1; /* Res1: buf len */
promif_preprom();
rv = p1275_cif_handler(&ci);
promif_postprom();
if (rv != 0)
return (-1);
return (p1275_cell2int(ci[4])); /* Res1: buf length */
}
int
prom_asr_disable(char *keystr, int keystr_len,
char *reason, int reason_len)
{
int rv;
cell_t ci[5];
ci[0] = p1275_ptr2cell("SUNW,asr-disable"); /* Service name */
ci[1] = (cell_t)4; /* #argument cells */
ci[2] = (cell_t)0; /* #return cells */
ci[3] = p1275_ptr2cell(keystr); /* Arg1: key address */
ci[3] = p1275_int2cell(keystr_len); /* Arg2: key len */
ci[3] = p1275_ptr2cell(reason); /* Arg1: reason address */
ci[3] = p1275_int2cell(reason_len); /* Arg2: reason len */
promif_preprom();
rv = p1275_cif_handler(&ci);
promif_postprom();
return (rv);
}
int
prom_asr_enable(char *keystr, int keystr_len)
{
int rv;
cell_t ci[5];
ci[0] = p1275_ptr2cell("SUNW,asr-enable"); /* Service name */
ci[1] = (cell_t)2; /* #argument cells */
ci[2] = (cell_t)0; /* #return cells */
ci[3] = p1275_ptr2cell(keystr); /* Arg1: key address */
ci[3] = p1275_int2cell(keystr_len); /* Arg2: key len */
promif_preprom();
rv = p1275_cif_handler(&ci);
promif_postprom();
return (rv);
}
static void
prom_setprop_null(void)
{
}
int
prom_getproplen(pnode_t nodeid, caddr_t name)
{
cell_t ci[6];
ci[0] = p1275_ptr2cell("getproplen"); /* Service name */
ci[1] = (cell_t)2; /* #argument cells */
ci[2] = (cell_t)1; /* #return cells */
ci[3] = p1275_phandle2cell((phandle_t)nodeid); /* Arg1: package */
ci[4] = p1275_ptr2cell(name); /* Arg2: Property name */
ci[5] = (cell_t)-1; /* Res1: Prime result */
promif_preprom();
(void) p1275_cif_handler(&ci);
promif_postprom();
return (p1275_cell2int(ci[5])); /* Res1: Property length */
}
int
prom_getprop(pnode_t nodeid, caddr_t name, caddr_t value)
{
int len, rv;
cell_t ci[8];
/*
* This function assumes the buffer is large enough to
* hold the result, so in 1275 mode, we pass in the length
* of the property as the length of the buffer, since we
* have no way of knowing the size of the buffer. Pre-1275
* OpenBoot(tm) PROMs did not have a bounded getprop.
*
* Note that we ignore the "length" result of the service.
*/
if ((len = prom_getproplen(nodeid, name)) <= 0)
return (len);
ci[0] = p1275_ptr2cell("getprop"); /* Service name */
ci[1] = (cell_t)4; /* #argument cells */
ci[2] = (cell_t)0; /* #result cells */
ci[3] = p1275_phandle2cell((phandle_t)nodeid); /* Arg1: package */
ci[4] = p1275_ptr2cell(name); /* Arg2: property name */
ci[5] = p1275_ptr2cell(value); /* Arg3: buffer address */
ci[6] = len; /* Arg4: buf len (assumed) */
promif_preprom();
rv = p1275_cif_handler(&ci);
promif_postprom();
if (rv != 0)
return (-1);
return (len); /* Return known length */
}
int
prom_bounded_getprop(pnode_t nodeid, caddr_t name, caddr_t value, int len)
{
cell_t ci[8];
ci[0] = p1275_ptr2cell("getprop"); /* Service name */
ci[1] = (cell_t)4; /* #argument cells */
ci[2] = (cell_t)1; /* #result cells */
ci[3] = p1275_phandle2cell((phandle_t)nodeid); /* Arg1: package */
ci[4] = p1275_ptr2cell(name); /* Arg2: property name */
ci[5] = p1275_ptr2cell(value); /* Arg3: buffer address */
ci[6] = p1275_int2cell(len); /* Arg4: buffer length */
ci[7] = (cell_t)-1; /* Res1: Prime result */
promif_preprom();
(void) p1275_cif_handler(&ci);
promif_postprom();
return (p1275_cell2int(ci[7])); /* Res1: Returned length */
}
caddr_t
prom_nextprop(pnode_t nodeid, caddr_t previous, caddr_t next)
{
cell_t ci[7];
(void) prom_strcpy(next, ""); /* Prime result, in case call fails */
ci[0] = p1275_ptr2cell("nextprop"); /* Service name */
ci[1] = (cell_t)3; /* #argument cells */
ci[2] = (cell_t)0; /* #result cells */
ci[3] = p1275_phandle2cell((phandle_t)nodeid); /* Arg1: phandle */
ci[4] = p1275_ptr2cell(previous); /* Arg2: addr of prev name */
ci[5] = p1275_ptr2cell(next); /* Arg3: addr of 32 byte buf */
promif_preprom();
(void) p1275_cif_handler(&ci);
promif_postprom();
return (next);
}
int
prom_setprop(pnode_t nodeid, caddr_t name, caddr_t value, int len)
{
cell_t ci[8];
#ifdef PROM_32BIT_ADDRS
caddr_t ovalue = NULL;
if ((uintptr_t)value > (uint32_t)-1) {
ovalue = value;
value = promplat_alloc(len);
if (value == NULL) {
return (-1);
}
promplat_bcopy(ovalue, value, len);
}
#endif
prom_setprop_enter();
promif_preprom();
ci[0] = p1275_ptr2cell("setprop"); /* Service name */
ci[1] = (cell_t)4; /* #argument cells */
ci[2] = (cell_t)1; /* #result cells */
ci[3] = p1275_phandle2cell((phandle_t)nodeid); /* Arg1: phandle */
ci[4] = p1275_ptr2cell(name); /* Arg2: property name */
ci[5] = p1275_ptr2cell(value); /* Arg3: New value ptr */
ci[6] = p1275_int2cell(len); /* Arg4: New value len */
ci[7] = (cell_t)-1; /* Res1: Prime result */
(void) p1275_cif_handler(&ci);
promif_postprom();
prom_setprop_exit();
#ifdef PROM_32BIT_ADDRS
if (ovalue != NULL)
promplat_free(value, len);
#endif
return (p1275_cell2int(ci[7])); /* Res1: Actual new size */
}
/*
* prom_decode_composite_string:
*
* Returns successive strings in a composite string property.
* A composite string property is a buffer containing one or more
* NULL terminated strings contained within the length of the buffer.
*
* Always call with the base address and length of the property buffer.
* On the first call, call with prev == 0, call successively
* with prev == to the last value returned from this function
* until the routine returns zero which means no more string values.
*/
char *
prom_decode_composite_string(void *buf, size_t buflen, char *prev)
{
if ((buf == 0) || (buflen == 0) || ((int)buflen == -1))
return ((char *)0);
if (prev == 0)
return ((char *)buf);
prev += prom_strlen(prev) + 1;
if (prev >= ((char *)buf + buflen))
return ((char *)0);
return (prev);
}
|