source: trunk/packages/xen-3.1/xen-3.1/xen/arch/powerpc/of_handler/devtree.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 6.7 KB
Line 
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 *
16 * Copyright (C) IBM Corp. 2005
17 *
18 * Authors: Jimi Xenidis <jimix@watson.ibm.com>
19 */
20
21#include "ofh.h"
22#include <of-devtree.h>
23
24s32
25ofh_peer(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
26{
27    if (nargs == 1) {
28        if (nrets == 1) {
29            ofdn_t ph = argp[0];
30            s32 *sib_ph = &retp[0];
31            void *mem = ofd_mem(b);
32
33            *sib_ph = ofd_node_peer(mem, ph);
34            return OF_SUCCESS;
35        }
36    }
37    return OF_FAILURE;
38}
39
40s32
41ofh_child(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
42{
43    if (nargs == 1) {
44        if (nrets == 1) {
45            ofdn_t ph = argp[0];
46            s32 *ch_ph = &retp[0];
47            void *mem = ofd_mem(b);
48
49            *ch_ph = ofd_node_child(mem, ph);
50            return OF_SUCCESS;
51        }
52    }
53    return OF_FAILURE;
54}
55
56s32
57ofh_parent(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
58{
59    if (nargs == 1) {
60        if (nrets == 1) {
61            ofdn_t ph = argp[0];
62            s32 *parent_ph = &retp[0];
63            void *mem = ofd_mem(b);
64
65            *parent_ph = ofd_node_parent(mem, ph);
66            return OF_SUCCESS;
67        }
68    }
69    return OF_FAILURE;
70}
71
72s32
73ofh_instance_to_package(u32 nargs, u32 nrets, s32 argp[], s32 retp[],
74        ulong b __attribute__ ((unused)))
75{
76    if (nargs == 1) {
77        if (nrets == 1) {
78            struct ofh_ihandle *ih =
79                (struct ofh_ihandle *)(ulong)argp[0];
80            s32 *p = &retp[0];
81
82            *p = (s32)ih->ofi_node;
83            return OF_SUCCESS;
84        }
85    }
86    return OF_FAILURE;
87}
88
89s32
90ofh_getproplen(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
91{
92    if (nargs == 2) {
93        if (nrets == 1) {
94            ofdn_t ph = argp[0];
95            const char *name = (const char *)(ulong)argp[1];
96            s32 *size = &retp[0];
97            void *mem = ofd_mem(b);
98
99            *size = ofd_getproplen(mem, ph, name);
100            if (*size >= 0) {
101                return OF_SUCCESS;
102            }
103        }
104    }
105    return OF_FAILURE;
106}
107
108s32
109ofh_getprop(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
110{
111    if (nargs == 4) {
112        if (nrets == 1) {
113            ofdn_t ph = argp[0];
114            const char *name = (const char *)(ulong)argp[1];
115            void *buf = (void *)(ulong)argp[2];
116            ulong buflen = argp[3];
117            s32 *size = &retp[0];
118            void *mem = ofd_mem(b);
119
120            *size = ofd_getprop(mem, ph, name, buf, buflen);
121            if (*size > 0) {
122                return OF_SUCCESS;
123            }
124        }
125    }
126    return OF_FAILURE;
127}
128
129s32
130ofh_nextprop(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
131{
132    if (nargs == 3) {
133        if (nrets == 1) {
134            ofdn_t ph = argp[0];
135            const char *prev = (const char *)(ulong)argp[1];
136            char *name = (char *)(ulong)argp[2];
137            s32 *flag = &retp[0];
138            void *mem = ofd_mem(b);
139
140            *flag = ofd_nextprop(mem, ph, prev, name);
141            if (*flag > 0) {
142                *flag = 1;
143            }
144            return OF_SUCCESS;
145        }
146    }
147    return OF_FAILURE;
148}
149
150s32
151ofh_setprop(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
152{
153    if (nargs == 4) {
154        if (nrets == 1) {
155            ofdn_t ph = argp[0];
156            const char *name = (const char *)(ulong)argp[1];
157            const void *buf = (void *)(ulong)argp[2];
158            ulong buflen = argp[3];
159            s32 *size = &retp[0];
160            void *mem = ofd_mem(b);
161
162            *size = ofd_setprop(mem, ph, name, buf, buflen);
163            return OF_SUCCESS;
164        }
165    }
166    return OF_FAILURE;
167}
168
169s32
170ofh_canon(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
171{
172    if (nargs == 3) {
173        if (nrets == 1) {
174            const char *dev_spec = (const char *)(ulong)argp[0];
175            char *buf = (char *)(ulong)argp[1];
176            u32 sz = argp[2];
177            s32 *len = &retp[0];
178            void *mem = ofd_mem(b);
179            ofdn_t ph;
180
181            ph = ofd_node_find(mem, dev_spec);
182            if (ph > 0) {
183                *len = ofd_node_to_path(mem, ph, buf, sz);
184                return OF_SUCCESS;
185            }
186        }
187    }
188    return OF_FAILURE;
189}
190
191s32 ofh_active_package = -1;
192
193s32
194ofh_finddevice(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
195{
196    if (nargs == 1) {
197        if (nrets == 1) {
198            s32 *ap = DRELA(&ofh_active_package, b);
199            const char *devspec = (const char *)(ulong)argp[0];
200            s32 *ph = &retp[0];
201            void *mem = ofd_mem(b);
202
203            /* good enuff */
204            if (devspec[0] == '\0') {
205                if (*ap == -1) {
206                    *ph = -1;
207                    return OF_FAILURE;
208                }
209                *ph = *ap;
210            } else {
211                *ph = ofd_node_find(mem, devspec);
212                if (*ph <= 0) {
213                    *ph = -1;
214                    return OF_FAILURE;
215                }
216            }
217            *ap = *ph;
218            return OF_SUCCESS;
219        }
220    }
221    return OF_FAILURE;
222}
223
224s32
225ofh_instance_to_path(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
226{
227    if (nargs == 3) {
228        if (nrets == 1) {
229            struct ofh_ihandle *ih =
230                (struct ofh_ihandle *)((ulong)argp[0]);
231            char *buf = (char *)(ulong)argp[1];
232            u32 sz = argp[2];
233            s32 *len = &retp[0];
234            ofdn_t ph;
235            void *mem = ofd_mem(b);
236
237            ph = ih->ofi_node;
238            if (ph > 0) {
239                *len = ofd_node_to_path(mem, ph, buf, sz);
240                return OF_SUCCESS;
241            }
242        }
243    }
244    return OF_FAILURE;
245}
246
247s32
248ofh_package_to_path(u32 nargs, u32 nrets, s32 argp[], s32 retp[], ulong b)
249{
250    if (nargs == 3) {
251        if (nrets == 1) {
252            ofdn_t ph = argp[0];
253            char *buf = (char *)(ulong)argp[1];
254            u32 sz = argp[2];
255            s32 *len = &retp[0];
256            void *mem = ofd_mem(b);
257
258            if (ph > 0) {
259                *len = ofd_node_to_path(mem, ph, buf, sz);
260                return OF_SUCCESS;
261            }
262        }
263    }
264    return OF_FAILURE;
265}
266
267
268
Note: See TracBrowser for help on using the repository browser.