1/* $NetBSD: openfirmio.c,v 1.4 2002/09/06 13:23:19 gehenna Exp $ */
2
3#include <sys/cdefs.h>
4__FBSDID("$FreeBSD: head/sys/dev/ofw/openfirmio.c 128019 2004-04-07 20:46:16Z imp $");
5
6/*
7 * Copyright (c) 1992, 1993
8 * The Regents of the University of California. All rights reserved.
9 *
10 * This software was developed by the Computer Systems Engineering group
11 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
12 * contributed to Berkeley.
--- 56 unchanged lines hidden (view full) ---
69 .d_name = "openfirm",
70};
71
72static phandle_t lastnode; /* speed hack */
73
74static int openfirm_checkid(phandle_t, phandle_t);
75static int openfirm_getstr(int, const char *, char **);
76
77/* Maximum accepted name length. */
78#define OFW_NAME_MAX 8191
79
80/*
81 * Verify target ID is valid (exists in the OPENPROM tree), as
82 * listed from node ID sid forward.
83 */
84static int
85openfirm_checkid(phandle_t sid, phandle_t tid)
86{
87
--- 6 unchanged lines hidden (view full) ---
94
95static int
96openfirm_getstr(int len, const char *user, char **cpp)
97{
98 int error;
99 char *cp;
100
101 /* Reject obvious bogus requests */
102 if ((u_int)len > OFW_NAME_MAX)
103 return (ENAMETOOLONG);
104
105 *cpp = cp = malloc(len + 1, M_TEMP, M_WAITOK);
106 if (cp == NULL)
107 return (ENOMEM);
108 error = copyin(user, cp, len);
109 cp[len] = '\0';
110 return (error);
--- 13 unchanged lines hidden (view full) ---
124 return (EBADF);
125
126 of = (struct ofiocdesc *)data;
127 switch (cmd) {
128 case OFIOCGETOPTNODE:
129 *(phandle_t *) data = OF_finddevice("/options");
130 return (0);
131 case OFIOCGET:
132#if 0
133 case OFIOCSET:
134#endif
135 case OFIOCNEXTPROP:
136 case OFIOCFINDDEVICE:
137 case OFIOCGETPROPLEN:
138 node = of->of_nodeid;
139 break;
140 case OFIOCGETNEXT:
141 case OFIOCGETCHILD:
142 node = *(phandle_t *)data;
--- 38 unchanged lines hidden (view full) ---
181 if (value == NULL) {
182 error = ENOMEM;
183 break;
184 }
185 len = OF_getprop(node, name, (void *)value, len);
186 error = copyout(value, of->of_buf, len);
187 break;
188
189#if 0
190 case OFIOCSET:
191 if ((flags & FWRITE) == 0)
192 return (EBADF);
193 if (node == 0)
194 return (EINVAL);
195 error = openfirm_getstr(of->of_namelen, of->of_name, &name);
196 if (error)
197 break;
198 error = openfirm_getstr(of->of_buflen, of->of_buf, &value);
199 if (error)
200 break;
201 len = OF_setprop(node, name, value, of->of_buflen);
202 if (len != of->of_buflen)
203 error = EINVAL;
204 break;
205#endif
206
207 case OFIOCNEXTPROP:
208 if (node == 0 || of->of_buflen < 0)
209 return (EINVAL);
210 if (of->of_namelen != 0) {
211 error = openfirm_getstr(of->of_namelen, of->of_name,
212 &name);
213 if (error)
--- 81 unchanged lines hidden ---
2
3#include <sys/cdefs.h>
4__FBSDID("$FreeBSD: head/sys/dev/ofw/openfirmio.c 128019 2004-04-07 20:46:16Z imp $");
5
6/*
7 * Copyright (c) 1992, 1993
8 * The Regents of the University of California. All rights reserved.
9 *
10 * This software was developed by the Computer Systems Engineering group
11 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
12 * contributed to Berkeley.
--- 56 unchanged lines hidden (view full) ---
69 .d_name = "openfirm",
70};
71
72static phandle_t lastnode; /* speed hack */
73
74static int openfirm_checkid(phandle_t, phandle_t);
75static int openfirm_getstr(int, const char *, char **);
76
77/* Maximum accepted name length. */
78#define OFW_NAME_MAX 8191
79
80/*
81 * Verify target ID is valid (exists in the OPENPROM tree), as
82 * listed from node ID sid forward.
83 */
84static int
85openfirm_checkid(phandle_t sid, phandle_t tid)
86{
87
--- 6 unchanged lines hidden (view full) ---
94
95static int
96openfirm_getstr(int len, const char *user, char **cpp)
97{
98 int error;
99 char *cp;
100
101 /* Reject obvious bogus requests */
102 if ((u_int)len > OFW_NAME_MAX)
103 return (ENAMETOOLONG);
104
105 *cpp = cp = malloc(len + 1, M_TEMP, M_WAITOK);
106 if (cp == NULL)
107 return (ENOMEM);
108 error = copyin(user, cp, len);
109 cp[len] = '\0';
110 return (error);
--- 13 unchanged lines hidden (view full) ---
124 return (EBADF);
125
126 of = (struct ofiocdesc *)data;
127 switch (cmd) {
128 case OFIOCGETOPTNODE:
129 *(phandle_t *) data = OF_finddevice("/options");
130 return (0);
131 case OFIOCGET:
132#if 0
133 case OFIOCSET:
134#endif
135 case OFIOCNEXTPROP:
136 case OFIOCFINDDEVICE:
137 case OFIOCGETPROPLEN:
138 node = of->of_nodeid;
139 break;
140 case OFIOCGETNEXT:
141 case OFIOCGETCHILD:
142 node = *(phandle_t *)data;
--- 38 unchanged lines hidden (view full) ---
181 if (value == NULL) {
182 error = ENOMEM;
183 break;
184 }
185 len = OF_getprop(node, name, (void *)value, len);
186 error = copyout(value, of->of_buf, len);
187 break;
188
189#if 0
190 case OFIOCSET:
191 if ((flags & FWRITE) == 0)
192 return (EBADF);
193 if (node == 0)
194 return (EINVAL);
195 error = openfirm_getstr(of->of_namelen, of->of_name, &name);
196 if (error)
197 break;
198 error = openfirm_getstr(of->of_buflen, of->of_buf, &value);
199 if (error)
200 break;
201 len = OF_setprop(node, name, value, of->of_buflen);
202 if (len != of->of_buflen)
203 error = EINVAL;
204 break;
205#endif
206
207 case OFIOCNEXTPROP:
208 if (node == 0 || of->of_buflen < 0)
209 return (EINVAL);
210 if (of->of_namelen != 0) {
211 error = openfirm_getstr(of->of_namelen, of->of_name,
212 &name);
213 if (error)
--- 81 unchanged lines hidden ---