~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to arch/sparc/prom/tree_32.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
static char promlib_buf[128];
21
21
 
22
22
/* Internal version of prom_getchild that does not alter return values. */
23
 
int __prom_getchild(int node)
 
23
static phandle __prom_getchild(phandle node)
24
24
{
25
25
        unsigned long flags;
26
 
        int cnode;
 
26
        phandle cnode;
27
27
 
28
28
        spin_lock_irqsave(&prom_lock, flags);
29
29
        cnode = prom_nodeops->no_child(node);
36
36
/* Return the child of node 'node' or zero if no this node has no
37
37
 * direct descendent.
38
38
 */
39
 
int prom_getchild(int node)
 
39
phandle prom_getchild(phandle node)
40
40
{
41
 
        int cnode;
 
41
        phandle cnode;
42
42
 
43
 
        if (node == -1)
 
43
        if ((s32)node == -1)
44
44
                return 0;
45
45
 
46
46
        cnode = __prom_getchild(node);
47
 
        if (cnode == 0 || cnode == -1)
 
47
        if (cnode == 0 || (s32)cnode == -1)
48
48
                return 0;
49
49
 
50
50
        return cnode;
52
52
EXPORT_SYMBOL(prom_getchild);
53
53
 
54
54
/* Internal version of prom_getsibling that does not alter return values. */
55
 
int __prom_getsibling(int node)
 
55
static phandle __prom_getsibling(phandle node)
56
56
{
57
57
        unsigned long flags;
58
 
        int cnode;
 
58
        phandle cnode;
59
59
 
60
60
        spin_lock_irqsave(&prom_lock, flags);
61
61
        cnode = prom_nodeops->no_nextnode(node);
68
68
/* Return the next sibling of node 'node' or zero if no more siblings
69
69
 * at this level of depth in the tree.
70
70
 */
71
 
int prom_getsibling(int node)
 
71
phandle prom_getsibling(phandle node)
72
72
{
73
 
        int sibnode;
 
73
        phandle sibnode;
74
74
 
75
 
        if (node == -1)
 
75
        if ((s32)node == -1)
76
76
                return 0;
77
77
 
78
78
        sibnode = __prom_getsibling(node);
79
 
        if (sibnode == 0 || sibnode == -1)
 
79
        if (sibnode == 0 || (s32)sibnode == -1)
80
80
                return 0;
81
81
 
82
82
        return sibnode;
86
86
/* Return the length in bytes of property 'prop' at node 'node'.
87
87
 * Return -1 on error.
88
88
 */
89
 
int prom_getproplen(int node, const char *prop)
 
89
int prom_getproplen(phandle node, const char *prop)
90
90
{
91
91
        int ret;
92
92
        unsigned long flags;
106
106
 * 'buffer' which has a size of 'bufsize'.  If the acquisition
107
107
 * was successful the length will be returned, else -1 is returned.
108
108
 */
109
 
int prom_getproperty(int node, const char *prop, char *buffer, int bufsize)
 
109
int prom_getproperty(phandle node, const char *prop, char *buffer, int bufsize)
110
110
{
111
111
        int plen, ret;
112
112
        unsigned long flags;
126
126
/* Acquire an integer property and return its value.  Returns -1
127
127
 * on failure.
128
128
 */
129
 
int prom_getint(int node, char *prop)
 
129
int prom_getint(phandle node, char *prop)
130
130
{
131
131
        static int intprop;
132
132
 
140
140
/* Acquire an integer property, upon error return the passed default
141
141
 * integer.
142
142
 */
143
 
int prom_getintdefault(int node, char *property, int deflt)
 
143
int prom_getintdefault(phandle node, char *property, int deflt)
144
144
{
145
145
        int retval;
146
146
 
152
152
EXPORT_SYMBOL(prom_getintdefault);
153
153
 
154
154
/* Acquire a boolean property, 1=TRUE 0=FALSE. */
155
 
int prom_getbool(int node, char *prop)
 
155
int prom_getbool(phandle node, char *prop)
156
156
{
157
157
        int retval;
158
158
 
166
166
 * string on error.  The char pointer is the user supplied string
167
167
 * buffer.
168
168
 */
169
 
void prom_getstring(int node, char *prop, char *user_buf, int ubuf_size)
 
169
void prom_getstring(phandle node, char *prop, char *user_buf, int ubuf_size)
170
170
{
171
171
        int len;
172
172
 
173
173
        len = prom_getproperty(node, prop, user_buf, ubuf_size);
174
174
        if(len != -1) return;
175
175
        user_buf[0] = 0;
176
 
        return;
177
176
}
178
177
EXPORT_SYMBOL(prom_getstring);
179
178
 
180
179
 
181
 
/* Does the device at node 'node' have name 'name'?
182
 
 * YES = 1   NO = 0
183
 
 */
184
 
int prom_nodematch(int node, char *name)
185
 
{
186
 
        int error;
187
 
 
188
 
        static char namebuf[128];
189
 
        error = prom_getproperty(node, "name", namebuf, sizeof(namebuf));
190
 
        if (error == -1) return 0;
191
 
        if(strcmp(namebuf, name) == 0) return 1;
192
 
        return 0;
193
 
}
194
 
 
195
180
/* Search siblings at 'node_start' for a node with name
196
181
 * 'nodename'.  Return node if successful, zero if not.
197
182
 */
198
 
int prom_searchsiblings(int node_start, char *nodename)
 
183
phandle prom_searchsiblings(phandle node_start, char *nodename)
199
184
{
200
185
 
201
 
        int thisnode, error;
 
186
        phandle thisnode;
 
187
        int error;
202
188
 
203
189
        for(thisnode = node_start; thisnode;
204
190
            thisnode=prom_getsibling(thisnode)) {
214
200
EXPORT_SYMBOL(prom_searchsiblings);
215
201
 
216
202
/* Interal version of nextprop that does not alter return values. */
217
 
char * __prom_nextprop(int node, char * oprop)
 
203
static char *__prom_nextprop(phandle node, char * oprop)
218
204
{
219
205
        unsigned long flags;
220
206
        char *prop;
227
213
        return prop;
228
214
}
229
215
 
230
 
/* Return the first property name for node 'node'. */
231
 
/* buffer is unused argument, but as v9 uses it, we need to have the same interface */
232
 
char * prom_firstprop(int node, char *bufer)
233
 
{
234
 
        if (node == 0 || node == -1)
235
 
                return "";
236
 
 
237
 
        return __prom_nextprop(node, "");
238
 
}
239
 
EXPORT_SYMBOL(prom_firstprop);
240
 
 
241
216
/* Return the property type string after property type 'oprop'
242
217
 * at node 'node' .  Returns empty string if no more
243
218
 * property types for this node.
244
219
 */
245
 
char * prom_nextprop(int node, char *oprop, char *buffer)
 
220
char *prom_nextprop(phandle node, char *oprop, char *buffer)
246
221
{
247
 
        if (node == 0 || node == -1)
 
222
        if (node == 0 || (s32)node == -1)
248
223
                return "";
249
224
 
250
225
        return __prom_nextprop(node, oprop);
251
226
}
252
227
EXPORT_SYMBOL(prom_nextprop);
253
228
 
254
 
int prom_finddevice(char *name)
 
229
phandle prom_finddevice(char *name)
255
230
{
256
231
        char nbuf[128];
257
232
        char *s = name, *d;
258
 
        int node = prom_root_node, node2;
 
233
        phandle node = prom_root_node, node2;
259
234
        unsigned int which_io, phys_addr;
260
235
        struct linux_prom_registers reg[PROMREG_MAX];
261
236
 
278
253
                                if (d != s + 3 && (!*d || *d == '/')
279
254
                                    && d <= s + 3 + 8) {
280
255
                                        node2 = node;
281
 
                                        while (node2 && node2 != -1) {
 
256
                                        while (node2 && (s32)node2 != -1) {
282
257
                                                if (prom_getproperty (node2, "reg", (char *)reg, sizeof (reg)) > 0) {
283
258
                                                        if (which_io == reg[0].which_io && phys_addr == reg[0].phys_addr) {
284
259
                                                                node = node2;
286
261
                                                        }
287
262
                                                }
288
263
                                                node2 = prom_getsibling(node2);
289
 
                                                if (!node2 || node2 == -1)
 
264
                                                if (!node2 || (s32)node2 == -1)
290
265
                                                        break;
291
266
                                                node2 = prom_searchsiblings(prom_getsibling(node2), nbuf);
292
267
                                        }
299
274
}
300
275
EXPORT_SYMBOL(prom_finddevice);
301
276
 
302
 
int prom_node_has_property(int node, char *prop)
303
 
{
304
 
        char *current_property = "";
305
 
 
306
 
        do {
307
 
                current_property = prom_nextprop(node, current_property, NULL);
308
 
                if(!strcmp(current_property, prop))
309
 
                   return 1;
310
 
        } while (*current_property);
311
 
        return 0;
312
 
}
313
 
EXPORT_SYMBOL(prom_node_has_property);
314
 
 
315
277
/* Set property 'pname' at node 'node' to value 'value' which has a length
316
278
 * of 'size' bytes.  Return the number of bytes the prom accepted.
317
279
 */
318
 
int prom_setprop(int node, const char *pname, char *value, int size)
 
280
int prom_setprop(phandle node, const char *pname, char *value, int size)
319
281
{
320
282
        unsigned long flags;
321
283
        int ret;
322
284
 
323
 
        if(size == 0) return 0;
324
 
        if((pname == 0) || (value == 0)) return 0;
 
285
        if (size == 0)
 
286
                return 0;
 
287
        if ((pname == NULL) || (value == NULL))
 
288
                return 0;
325
289
        spin_lock_irqsave(&prom_lock, flags);
326
290
        ret = prom_nodeops->no_setprop(node, pname, value, size);
327
291
        restore_current();
330
294
}
331
295
EXPORT_SYMBOL(prom_setprop);
332
296
 
333
 
int prom_inst2pkg(int inst)
 
297
phandle prom_inst2pkg(int inst)
334
298
{
335
 
        int node;
 
299
        phandle node;
336
300
        unsigned long flags;
337
301
        
338
302
        spin_lock_irqsave(&prom_lock, flags);
339
303
        node = (*romvec->pv_v2devops.v2_inst2pkg)(inst);
340
304
        restore_current();
341
305
        spin_unlock_irqrestore(&prom_lock, flags);
342
 
        if (node == -1) return 0;
343
 
        return node;
344
 
}
345
 
 
346
 
/* Return 'node' assigned to a particular prom 'path'
347
 
 * FIXME: Should work for v0 as well
348
 
 */
349
 
int prom_pathtoinode(char *path)
350
 
{
351
 
        int node, inst;
352
 
        
353
 
        inst = prom_devopen (path);
354
 
        if (inst == -1) return 0;
355
 
        node = prom_inst2pkg (inst);
356
 
        prom_devclose (inst);
357
 
        if (node == -1) return 0;
 
306
        if ((s32)node == -1)
 
307
                return 0;
358
308
        return node;
359
309
}