Deleted Added
full compact
59c59
< __FBSDID("$FreeBSD: head/sys/dev/ofw/openfirm.c 171265 2007-07-06 00:47:44Z peter $");
---
> __FBSDID("$FreeBSD: head/sys/dev/ofw/ofw_standard.c 186347 2008-12-20 00:33:10Z nwhitehorn $");
68a69,70
> #include <dev/ofw/ofwvar.h>
> #include "ofw_if.h"
70c72,108
< MALLOC_DEFINE(M_OFWPROP, "openfirm", "Open Firmware properties");
---
> static void ofw_std_init(ofw_t ofw, void *openfirm);
> static int ofw_std_test(ofw_t ofw, const char *name);
> static int ofw_std_interpret(ofw_t ofw, const char *cmd, int nreturns,
> unsigned long *returns);
> static phandle_t ofw_std_peer(ofw_t ofw, phandle_t node);
> static phandle_t ofw_std_child(ofw_t ofw, phandle_t node);
> static phandle_t ofw_std_parent(ofw_t ofw, phandle_t node);
> static phandle_t ofw_std_instance_to_package(ofw_t ofw, ihandle_t instance);
> static ssize_t ofw_std_getproplen(ofw_t ofw, phandle_t package,
> const char *propname);
> static ssize_t ofw_std_getprop(ofw_t ofw, phandle_t package,
> const char *propname, void *buf, size_t buflen);
> static int ofw_std_nextprop(ofw_t ofw, phandle_t package, const char *previous,
> char *buf, size_t);
> static int ofw_std_setprop(ofw_t ofw, phandle_t package, char *propname,
> void *buf, size_t len);
> static ssize_t ofw_std_canon(ofw_t ofw, const char *device, char *buf,
> size_t len);
> static phandle_t ofw_std_finddevice(ofw_t ofw, const char *device);
> static ssize_t ofw_std_instance_to_path(ofw_t ofw, ihandle_t instance,
> char *buf, size_t len);
> static ssize_t ofw_std_package_to_path(ofw_t ofw, phandle_t package, char *buf,
> size_t len);
> static int ofw_std_call_method(ofw_t ofw, ihandle_t instance,
> const char *method, int nargs, int nreturns,
> unsigned long *args_and_returns);
> static ihandle_t ofw_std_open(ofw_t ofw, const char *device);
> static void ofw_std_close(ofw_t ofw, ihandle_t instance);
> static ssize_t ofw_std_read(ofw_t ofw, ihandle_t instance, void *addr,
> size_t len);
> static ssize_t ofw_std_write(ofw_t ofw, ihandle_t instance, const void *addr,
> size_t len);
> static int ofw_std_seek(ofw_t ofw, ihandle_t instance, u_int64_t pos);
> static caddr_t ofw_std_claim(ofw_t ofw, void *virt, size_t size, u_int align);
> static void ofw_std_release(ofw_t ofw, void *virt, size_t size);
> static void ofw_std_enter(ofw_t ofw);
> static void ofw_std_exit(ofw_t ofw);
72c110,123
< static ihandle_t stdout;
---
> static ofw_method_t ofw_std_methods[] = {
> OFWMETHOD(ofw_init, ofw_std_init),
> OFWMETHOD(ofw_peer, ofw_std_peer),
> OFWMETHOD(ofw_child, ofw_std_child),
> OFWMETHOD(ofw_parent, ofw_std_parent),
> OFWMETHOD(ofw_instance_to_package, ofw_std_instance_to_package),
> OFWMETHOD(ofw_getproplen, ofw_std_getproplen),
> OFWMETHOD(ofw_getprop, ofw_std_getprop),
> OFWMETHOD(ofw_nextprop, ofw_std_nextprop),
> OFWMETHOD(ofw_setprop, ofw_std_setprop),
> OFWMETHOD(ofw_canon, ofw_std_canon),
> OFWMETHOD(ofw_finddevice, ofw_std_finddevice),
> OFWMETHOD(ofw_instance_to_path, ofw_std_instance_to_path),
> OFWMETHOD(ofw_package_to_path, ofw_std_package_to_path),
74c125,136
< /* Initialiser */
---
> OFWMETHOD(ofw_test, ofw_std_test),
> OFWMETHOD(ofw_call_method, ofw_std_call_method),
> OFWMETHOD(ofw_interpret, ofw_std_interpret),
> OFWMETHOD(ofw_open, ofw_std_open),
> OFWMETHOD(ofw_close, ofw_std_close),
> OFWMETHOD(ofw_read, ofw_std_read),
> OFWMETHOD(ofw_write, ofw_std_write),
> OFWMETHOD(ofw_seek, ofw_std_seek),
> OFWMETHOD(ofw_claim, ofw_std_claim),
> OFWMETHOD(ofw_release, ofw_std_release),
> OFWMETHOD(ofw_enter, ofw_std_enter),
> OFWMETHOD(ofw_exit, ofw_std_exit),
76,79c138,139
< void
< OF_init(int (*openfirm)(void *))
< {
< phandle_t chosen;
---
> { 0, 0 }
> };
81,86c141,146
< set_openfirm_callback(openfirm);
< if ((chosen = OF_finddevice("/chosen")) == -1)
< OF_exit();
< if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
< OF_exit();
< }
---
> static ofw_def_t ofw_std = {
> OFW_STD_DIRECT,
> ofw_std_methods,
> 0
> };
> OFW_DEF(ofw_std);
88,92c148
< void
< OF_printf(const char *fmt, ...)
< {
< va_list va;
< char buf[1024];
---
> static int (*openfirmware)(void *);
94,97c150,155
< va_start(va, fmt);
< vsprintf(buf, fmt, va);
< OF_write(stdout, buf, strlen(buf));
< va_end(va);
---
> /* Initialiser */
>
> static void
> ofw_std_init(ofw_t ofw, void *openfirm)
> {
> openfirmware = (int (*)(void *))openfirm;
105,106c163,164
< int
< OF_test(char *name)
---
> static int
> ofw_std_test(ofw_t ofw, const char *name)
126,127c184,186
< int
< OF_interpret(char *cmd, int nreturns, ...)
---
> static int
> ofw_std_interpret(ofw_t ofw, const char *cmd, int nreturns,
> unsigned long *returns)
129d187
< va_list ap;
140c198
< int i = 0;
---
> int i = 0, j = 0;
142d199
< va_start(ap, nreturns);
145,146d201
< while (i < 1)
< args.slot[i++] = va_arg(ap, cell_t);
148d202
< va_end(ap);
153,154c207
< *va_arg(ap, cell_t *) = args.slot[i++];
< va_end(ap);
---
> returns[j] = args.slot[i++];
158,176d210
< /* Return firmware millisecond count. */
< int
< OF_milliseconds()
< {
< static struct {
< cell_t name;
< cell_t nargs;
< cell_t nreturns;
< cell_t ms;
< } args = {
< (cell_t)"milliseconds",
< 0,
< 1,
< };
<
< openfirmware(&args);
< return (args.ms);
< }
<
182,183c216,217
< phandle_t
< OF_peer(phandle_t node)
---
> static phandle_t
> ofw_std_peer(ofw_t ofw, phandle_t node)
204,205c238,239
< phandle_t
< OF_child(phandle_t node)
---
> static phandle_t
> ofw_std_child(ofw_t ofw, phandle_t node)
226,227c260,261
< phandle_t
< OF_parent(phandle_t node)
---
> static phandle_t
> ofw_std_parent(ofw_t ofw, phandle_t node)
248,249c282,283
< phandle_t
< OF_instance_to_package(ihandle_t instance)
---
> static phandle_t
> ofw_std_instance_to_package(ofw_t ofw, ihandle_t instance)
270,271c304,305
< int
< OF_getproplen(phandle_t package, char *propname)
---
> static ssize_t
> ofw_std_getproplen(ofw_t ofw, phandle_t package, const char *propname)
294,295c328,330
< int
< OF_getprop(phandle_t package, char *propname, void *buf, int buflen)
---
> static ssize_t
> ofw_std_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf,
> size_t buflen)
321,344d355
< /*
< * Store the value of a property of a package into newly allocated memory
< * (using the M_OFWPROP malloc pool and M_WAITOK). elsz is the size of a
< * single element, the number of elements is return in number.
< */
< int
< OF_getprop_alloc(phandle_t package, char *propname, int elsz, void **buf)
< {
< int len;
<
< *buf = NULL;
< if ((len = OF_getproplen(package, propname)) == -1 ||
< len % elsz != 0)
< return (-1);
<
< *buf = malloc(len, M_OFWPROP, M_WAITOK);
< if (OF_getprop(package, propname, *buf, len) == -1) {
< free(*buf, M_OFWPROP);
< *buf = NULL;
< return (-1);
< }
< return (len / elsz);
< }
<
346,347c357,359
< int
< OF_nextprop(phandle_t package, char *previous, char *buf)
---
> static int
> ofw_std_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf,
> size_t size)
373,374c385,387
< int
< OF_setprop(phandle_t package, char *propname, void *buf, int len)
---
> static int
> ofw_std_setprop(ofw_t ofw, phandle_t package, char *propname, void *buf,
> size_t len)
401,402c414,415
< int
< OF_canon(const char *device, char *buf, int len)
---
> static ssize_t
> ofw_std_canon(ofw_t ofw, const char *device, char *buf, size_t len)
427,428c440,441
< phandle_t
< OF_finddevice(const char *device)
---
> static phandle_t
> ofw_std_finddevice(ofw_t ofw, const char *device)
449,450c462,463
< int
< OF_instance_to_path(ihandle_t instance, char *buf, int len)
---
> static ssize_t
> ofw_std_instance_to_path(ofw_t ofw, ihandle_t instance, char *buf, size_t len)
475,476c488,489
< int
< OF_package_to_path(phandle_t package, char *buf, int len)
---
> static ssize_t
> ofw_std_package_to_path(ofw_t ofw, phandle_t package, char *buf, size_t len)
501,502c514,516
< int
< OF_call_method(char *method, ihandle_t instance, int nargs, int nreturns, ...)
---
> static int
> ofw_std_call_method(ofw_t ofw, ihandle_t instance, const char *method,
> int nargs, int nreturns, unsigned long *args_and_returns)
504d517
< va_list ap;
517a531
> unsigned long *ap;
526c540,541
< va_start(ap, nreturns);
---
>
> ap = args_and_returns;
528c543
< *--cp = va_arg(ap, cell_t);
---
> *--cp = *(ap++);
534,535c549
< *va_arg(ap, cell_t *) = *--cp;
< va_end(ap);
---
> *(ap++) = *--cp;
544,545c558,559
< ihandle_t
< OF_open(char *device)
---
> static ihandle_t
> ofw_std_open(ofw_t ofw, const char *device)
567,568c581,582
< void
< OF_close(ihandle_t instance)
---
> static void
> ofw_std_close(ofw_t ofw, ihandle_t instance)
585,586c599,600
< int
< OF_read(ihandle_t instance, void *addr, int len)
---
> static ssize_t
> ofw_std_read(ofw_t ofw, ihandle_t instance, void *addr, size_t len)
612,613c626,627
< int
< OF_write(ihandle_t instance, void *addr, int len)
---
> static ssize_t
> ofw_std_write(ofw_t ofw, ihandle_t instance, const void *addr, size_t len)
638,639c652,653
< int
< OF_seek(ihandle_t instance, u_int64_t pos)
---
> static int
> ofw_std_seek(ofw_t ofw, ihandle_t instance, u_int64_t pos)
668,669c682,683
< void *
< OF_claim(void *virt, u_int size, u_int align)
---
> static caddr_t
> ofw_std_claim(ofw_t ofw, void *virt, size_t size, u_int align)
694,695c708,709
< void
< OF_release(void *virt, u_int size)
---
> static void
> ofw_std_release(ofw_t ofw, void *virt, size_t size)
717,736d730
< /* Reset the system and call "boot <bootspec>". */
< void
< OF_boot(char *bootspec)
< {
< static struct {
< cell_t name;
< cell_t nargs;
< cell_t nreturns;
< cell_t bootspec;
< } args = {
< (cell_t)"boot",
< 1,
< };
<
< args.bootspec = (cell_t)bootspec;
< openfirmware(&args);
< for (;;) /* just in case */
< ;
< }
<
738,739c732,733
< void
< OF_enter()
---
> static void
> ofw_std_enter(ofw_t ofw)
754,755c748,749
< void
< OF_exit()
---
> static void
> ofw_std_exit(ofw_t ofw)
770,810d763
< /* Free <size> bytes starting at <virt>, then call <entry> with <arg>. */
< #if 0
< void
< OF_chain(void *virt, u_int size, void (*entry)(), void *arg, u_int len)
< {
< static struct {
< cell_t name;
< cell_t nargs;
< cell_t nreturns;
< cell_t virt;
< cell_t size;
< cell_t entry;
< cell_t arg;
< cell_t len;
< } args = {
< (cell_t)"chain",
< 5,
< };
<
< args.virt = (cell_t)virt;
< args.size = size;
< args.entry = (cell_t)entry;
< args.arg = (cell_t)arg;
< args.len = len;
< openfirmware(&args);
< }
< #else
< void
< OF_chain(void *virt, u_int size,
< void (*entry)(void *, u_int, void *, void *, u_int), void *arg, u_int len)
< {
< /*
< * This is a REALLY dirty hack till the firmware gets this going
< */
< #if 0
< if (size > 0)
< OF_release(virt, size);
< #endif
< entry(0, 0, openfirmware, arg, len);
< }
< #endif