1/* $NetBSD: openfirmio.c,v 1.4 2002/09/06 13:23:19 gehenna Exp $ */
2
3/*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
--- 29 unchanged lines hidden (view full) ---
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)openfirm.c 8.1 (Berkeley) 6/11/93
45 *
46 * $FreeBSD: head/sys/dev/ofw/openfirmio.c 116210 2003-06-11 18:33:03Z tmm $
47 */
48
49#include <sys/param.h>
50#include <sys/systm.h>
51#include <sys/conf.h>
52#include <sys/errno.h>
53#include <sys/fcntl.h>
54#include <sys/ioccom.h>
55#include <sys/kernel.h>
56#include <sys/malloc.h>
57#include <sys/module.h>
58
59#include <dev/ofw/openfirmio.h>
60
61static dev_t openfirm_dev;
62
63static d_ioctl_t openfirm_ioctl;
64
65#define OPENFIRM_MINOR 0
66
67static struct cdevsw openfirm_cdevsw = {
68 .d_open = nullopen,
69 .d_close = nullclose,
70 .d_ioctl = openfirm_ioctl,
71 .d_name = "openfirm",
72};
73
74static phandle_t lastnode; /* speed hack */
75
76static int openfirm_checkid(phandle_t, phandle_t);
77static int openfirm_getstr(int, const char *, char **);
78
79/* Maximum accepted name length. */
--- 37 unchanged lines hidden (view full) ---
117 struct thread *td)
118{
119 struct ofiocdesc *of;
120 phandle_t node;
121 int len, ok, error;
122 char *name, *value;
123 char newname[32];
124
125 if ((flags & FREAD) == 0)
126 return (EBADF);
127
128 of = (struct ofiocdesc *)data;
129 switch (cmd) {
130 case OFIOCGETOPTNODE:
131 *(phandle_t *) data = OF_finddevice("/options");
132 return (0);
133 case OFIOCGET:
134#if 0
135 case OFIOCSET:
136#endif
137 case OFIOCNEXTPROP:
138 case OFIOCFINDDEVICE:
139 case OFIOCGETPROPLEN:
140 node = of->of_nodeid;
141 break;
142 case OFIOCGETNEXT:
143 case OFIOCGETCHILD:
144 node = *(phandle_t *)data;
145 break;
146 default:
147 return (ENOIOCTL);
148 }
149
150 if (node != 0 && node != lastnode) {
151 /* Not an easy one, must search for it */
152 ok = openfirm_checkid(OF_peer(0), node);
153 if (!ok)
154 return (EINVAL);
155 lastnode = node;
156 }
157
158 name = value = NULL;
159 error = 0;
160 switch (cmd) {
161
162 case OFIOCGET:
163 case OFIOCGETPROPLEN:
164 if (node == 0)
165 return (EINVAL);
166 error = openfirm_getstr(of->of_namelen, of->of_name, &name);
167 if (error)
168 break;
169 len = OF_getproplen(node, name);
170 if (cmd == OFIOCGETPROPLEN) {
171 of->of_buflen = len;
172 break;
173 }
174 if (len > of->of_buflen) {
175 error = ENOMEM;
176 break;
177 }
178 of->of_buflen = len;
179 /* -1 means no entry; 0 means no value */
180 if (len <= 0)
181 break;
--- 20 unchanged lines hidden (view full) ---
202 break;
203 len = OF_setprop(node, name, value, of->of_buflen);
204 if (len != of->of_buflen)
205 error = EINVAL;
206 break;
207#endif
208
209 case OFIOCNEXTPROP:
210 if (node == 0 || of->of_buflen < 0)
211 return (EINVAL);
212 if (of->of_namelen != 0) {
213 error = openfirm_getstr(of->of_namelen, of->of_name,
214 &name);
215 if (error)
216 break;
217 }
--- 10 unchanged lines hidden (view full) ---
228 if (len > of->of_buflen)
229 len = of->of_buflen;
230 else
231 of->of_buflen = len;
232 error = copyout(newname, of->of_buf, len);
233 break;
234
235 case OFIOCGETNEXT:
236 node = OF_peer(node);
237 *(phandle_t *)data = lastnode = node;
238 break;
239
240 case OFIOCGETCHILD:
241 if (node == 0)
242 return (EINVAL);
243 node = OF_child(node);
244 *(phandle_t *)data = lastnode = node;
245 break;
246
247 case OFIOCFINDDEVICE:
248 error = openfirm_getstr(of->of_namelen, of->of_name, &name);
249 if (error)
250 break;
251 node = OF_finddevice(name);
252 if (node == 0 || node == -1) {
253 error = ENOENT;
254 break;
255 }
--- 41 unchanged lines hidden ---
2
3/*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
--- 29 unchanged lines hidden (view full) ---
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)openfirm.c 8.1 (Berkeley) 6/11/93
45 *
46 * $FreeBSD: head/sys/dev/ofw/openfirmio.c 116210 2003-06-11 18:33:03Z tmm $
47 */
48
49#include <sys/param.h>
50#include <sys/systm.h>
51#include <sys/conf.h>
52#include <sys/errno.h>
53#include <sys/fcntl.h>
54#include <sys/ioccom.h>
55#include <sys/kernel.h>
56#include <sys/malloc.h>
57#include <sys/module.h>
58
59#include <dev/ofw/openfirmio.h>
60
61static dev_t openfirm_dev;
62
63static d_ioctl_t openfirm_ioctl;
64
65#define OPENFIRM_MINOR 0
66
67static struct cdevsw openfirm_cdevsw = {
68 .d_open = nullopen,
69 .d_close = nullclose,
70 .d_ioctl = openfirm_ioctl,
71 .d_name = "openfirm",
72};
73
74static phandle_t lastnode; /* speed hack */
75
76static int openfirm_checkid(phandle_t, phandle_t);
77static int openfirm_getstr(int, const char *, char **);
78
79/* Maximum accepted name length. */
--- 37 unchanged lines hidden (view full) ---
117 struct thread *td)
118{
119 struct ofiocdesc *of;
120 phandle_t node;
121 int len, ok, error;
122 char *name, *value;
123 char newname[32];
124
125 if ((flags & FREAD) == 0)
126 return (EBADF);
127
128 of = (struct ofiocdesc *)data;
129 switch (cmd) {
130 case OFIOCGETOPTNODE:
131 *(phandle_t *) data = OF_finddevice("/options");
132 return (0);
133 case OFIOCGET:
134#if 0
135 case OFIOCSET:
136#endif
137 case OFIOCNEXTPROP:
138 case OFIOCFINDDEVICE:
139 case OFIOCGETPROPLEN:
140 node = of->of_nodeid;
141 break;
142 case OFIOCGETNEXT:
143 case OFIOCGETCHILD:
144 node = *(phandle_t *)data;
145 break;
146 default:
147 return (ENOIOCTL);
148 }
149
150 if (node != 0 && node != lastnode) {
151 /* Not an easy one, must search for it */
152 ok = openfirm_checkid(OF_peer(0), node);
153 if (!ok)
154 return (EINVAL);
155 lastnode = node;
156 }
157
158 name = value = NULL;
159 error = 0;
160 switch (cmd) {
161
162 case OFIOCGET:
163 case OFIOCGETPROPLEN:
164 if (node == 0)
165 return (EINVAL);
166 error = openfirm_getstr(of->of_namelen, of->of_name, &name);
167 if (error)
168 break;
169 len = OF_getproplen(node, name);
170 if (cmd == OFIOCGETPROPLEN) {
171 of->of_buflen = len;
172 break;
173 }
174 if (len > of->of_buflen) {
175 error = ENOMEM;
176 break;
177 }
178 of->of_buflen = len;
179 /* -1 means no entry; 0 means no value */
180 if (len <= 0)
181 break;
--- 20 unchanged lines hidden (view full) ---
202 break;
203 len = OF_setprop(node, name, value, of->of_buflen);
204 if (len != of->of_buflen)
205 error = EINVAL;
206 break;
207#endif
208
209 case OFIOCNEXTPROP:
210 if (node == 0 || of->of_buflen < 0)
211 return (EINVAL);
212 if (of->of_namelen != 0) {
213 error = openfirm_getstr(of->of_namelen, of->of_name,
214 &name);
215 if (error)
216 break;
217 }
--- 10 unchanged lines hidden (view full) ---
228 if (len > of->of_buflen)
229 len = of->of_buflen;
230 else
231 of->of_buflen = len;
232 error = copyout(newname, of->of_buf, len);
233 break;
234
235 case OFIOCGETNEXT:
236 node = OF_peer(node);
237 *(phandle_t *)data = lastnode = node;
238 break;
239
240 case OFIOCGETCHILD:
241 if (node == 0)
242 return (EINVAL);
243 node = OF_child(node);
244 *(phandle_t *)data = lastnode = node;
245 break;
246
247 case OFIOCFINDDEVICE:
248 error = openfirm_getstr(of->of_namelen, of->of_name, &name);
249 if (error)
250 break;
251 node = OF_finddevice(name);
252 if (node == 0 || node == -1) {
253 error = ENOENT;
254 break;
255 }
--- 41 unchanged lines hidden ---