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 129587 2004-05-22 16:43:42Z marius $");
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/*
78 * Verify target ID is valid (exists in the OPENPROM tree), as
79 * listed from node ID sid forward.
80 */
81static int
82openfirm_checkid(phandle_t sid, phandle_t tid)
83{
84
--- 6 unchanged lines hidden (view full) ---
91
92static int
93openfirm_getstr(int len, const char *user, char **cpp)
94{
95 int error;
96 char *cp;
97
98 /* Reject obvious bogus requests */
99 if ((u_int)len > OFIOCMAXNAME)
100 return (ENAMETOOLONG);
101
102 *cpp = cp = malloc(len + 1, M_TEMP, M_WAITOK);
103 if (cp == NULL)
104 return (ENOMEM);
105 error = copyin(user, cp, len);
106 cp[len] = '\0';
107 return (error);
--- 13 unchanged lines hidden (view full) ---
121 return (EBADF);
122
123 of = (struct ofiocdesc *)data;
124 switch (cmd) {
125 case OFIOCGETOPTNODE:
126 *(phandle_t *) data = OF_finddevice("/options");
127 return (0);
128 case OFIOCGET:
129 case OFIOCSET:
130 case OFIOCNEXTPROP:
131 case OFIOCFINDDEVICE:
132 case OFIOCGETPROPLEN:
133 node = of->of_nodeid;
134 break;
135 case OFIOCGETNEXT:
136 case OFIOCGETCHILD:
137 node = *(phandle_t *)data;
--- 38 unchanged lines hidden (view full) ---
176 if (value == NULL) {
177 error = ENOMEM;
178 break;
179 }
180 len = OF_getprop(node, name, (void *)value, len);
181 error = copyout(value, of->of_buf, len);
182 break;
183
184 case OFIOCSET:
185 /*
186 * Note: Text string values for at least the /options node
187 * have to be null-terminated and the length paramter must
188 * include this terminating null. However, like OF_getprop(),
189 * OF_setprop() will return the the actual length of the text
190 * string, i.e. omitting the terminating null.
191 */
192 if ((flags & FWRITE) == 0)
193 return (EBADF);
194 if (node == 0)
195 return (EINVAL);
196 if ((u_int)of->of_buflen > OFIOCMAXVALUE)
197 return (ENAMETOOLONG);
198 error = openfirm_getstr(of->of_namelen, of->of_name, &name);
199 if (error)
200 break;
201 value = malloc(of->of_buflen, M_TEMP, M_WAITOK);
202 if (value == NULL) {
203 error = ENOMEM;
204 break;
205 }
206 error = copyin(of->of_buf, value, of->of_buflen);
207 if (error)
208 break;
209 len = OF_setprop(node, name, value, of->of_buflen);
210 if (len < 0)
211 error = EINVAL;
212 of->of_buflen = len;
213 break;
214
215 case OFIOCNEXTPROP:
216 if (node == 0 || of->of_buflen < 0)
217 return (EINVAL);
218 if (of->of_namelen != 0) {
219 error = openfirm_getstr(of->of_namelen, of->of_name,
220 &name);
221 if (error)
--- 81 unchanged lines hidden ---
2
3#include <sys/cdefs.h>
4__FBSDID("$FreeBSD: head/sys/dev/ofw/openfirmio.c 129587 2004-05-22 16:43:42Z marius $");
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/*
78 * Verify target ID is valid (exists in the OPENPROM tree), as
79 * listed from node ID sid forward.
80 */
81static int
82openfirm_checkid(phandle_t sid, phandle_t tid)
83{
84
--- 6 unchanged lines hidden (view full) ---
91
92static int
93openfirm_getstr(int len, const char *user, char **cpp)
94{
95 int error;
96 char *cp;
97
98 /* Reject obvious bogus requests */
99 if ((u_int)len > OFIOCMAXNAME)
100 return (ENAMETOOLONG);
101
102 *cpp = cp = malloc(len + 1, M_TEMP, M_WAITOK);
103 if (cp == NULL)
104 return (ENOMEM);
105 error = copyin(user, cp, len);
106 cp[len] = '\0';
107 return (error);
--- 13 unchanged lines hidden (view full) ---
121 return (EBADF);
122
123 of = (struct ofiocdesc *)data;
124 switch (cmd) {
125 case OFIOCGETOPTNODE:
126 *(phandle_t *) data = OF_finddevice("/options");
127 return (0);
128 case OFIOCGET:
129 case OFIOCSET:
130 case OFIOCNEXTPROP:
131 case OFIOCFINDDEVICE:
132 case OFIOCGETPROPLEN:
133 node = of->of_nodeid;
134 break;
135 case OFIOCGETNEXT:
136 case OFIOCGETCHILD:
137 node = *(phandle_t *)data;
--- 38 unchanged lines hidden (view full) ---
176 if (value == NULL) {
177 error = ENOMEM;
178 break;
179 }
180 len = OF_getprop(node, name, (void *)value, len);
181 error = copyout(value, of->of_buf, len);
182 break;
183
184 case OFIOCSET:
185 /*
186 * Note: Text string values for at least the /options node
187 * have to be null-terminated and the length paramter must
188 * include this terminating null. However, like OF_getprop(),
189 * OF_setprop() will return the the actual length of the text
190 * string, i.e. omitting the terminating null.
191 */
192 if ((flags & FWRITE) == 0)
193 return (EBADF);
194 if (node == 0)
195 return (EINVAL);
196 if ((u_int)of->of_buflen > OFIOCMAXVALUE)
197 return (ENAMETOOLONG);
198 error = openfirm_getstr(of->of_namelen, of->of_name, &name);
199 if (error)
200 break;
201 value = malloc(of->of_buflen, M_TEMP, M_WAITOK);
202 if (value == NULL) {
203 error = ENOMEM;
204 break;
205 }
206 error = copyin(of->of_buf, value, of->of_buflen);
207 if (error)
208 break;
209 len = OF_setprop(node, name, value, of->of_buflen);
210 if (len < 0)
211 error = EINVAL;
212 of->of_buflen = len;
213 break;
214
215 case OFIOCNEXTPROP:
216 if (node == 0 || of->of_buflen < 0)
217 return (EINVAL);
218 if (of->of_namelen != 0) {
219 error = openfirm_getstr(of->of_namelen, of->of_name,
220 &name);
221 if (error)
--- 81 unchanged lines hidden ---