[Midnightbsd-cvs] src: dev/ofw: update open firmware code
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Wed Dec 3 15:11:50 EST 2008
Log Message:
-----------
update open firmware code
Modified Files:
--------------
src/sys/dev/ofw:
ofw_bus_if.m (r1.1.1.1 -> r1.2)
ofw_console.c (r1.1.1.1 -> r1.2)
ofw_disk.c (r1.1.1.1 -> r1.2)
openfirm.c (r1.1.1.1 -> r1.2)
openfirm.h (r1.1.1.1 -> r1.2)
openfirmio.c (r1.1.1.1 -> r1.2)
openpromio.c (r1.1.1.1 -> r1.2)
Added Files:
-----------
src/sys/dev/ofw:
ofw_bus_subr.c (r1.1)
ofw_bus_subr.h (r1.1)
-------------- next part --------------
Index: ofw_console.c
===================================================================
RCS file: /home/cvs/src/sys/dev/ofw/ofw_console.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/ofw/ofw_console.c -L sys/dev/ofw/ofw_console.c -u -r1.1.1.1 -r1.2
--- sys/dev/ofw/ofw_console.c
+++ sys/dev/ofw/ofw_console.c
@@ -24,7 +24,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/ofw/ofw_console.c,v 1.31 2005/01/06 01:43:00 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/ofw/ofw_console.c,v 1.36 2006/11/06 17:43:10 rwatson Exp $");
#include "opt_comconsole.h"
#include "opt_ofw.h"
@@ -32,6 +32,7 @@
#include <sys/param.h>
#include <sys/kdb.h>
#include <sys/kernel.h>
+#include <sys/priv.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <sys/conf.h>
@@ -73,14 +74,13 @@
static void ofw_tty_stop(struct tty *, int);
static void ofw_timeout(void *);
-static cn_probe_t ofw_cons_probe;
-static cn_init_t ofw_cons_init;
-static cn_getc_t ofw_cons_getc;
-static cn_checkc_t ofw_cons_checkc;
-static cn_putc_t ofw_cons_putc;
+static cn_probe_t ofw_cnprobe;
+static cn_init_t ofw_cninit;
+static cn_term_t ofw_cnterm;
+static cn_getc_t ofw_cngetc;
+static cn_putc_t ofw_cnputc;
-CONS_DRIVER(ofw, ofw_cons_probe, ofw_cons_init, NULL, ofw_cons_getc,
- ofw_cons_checkc, ofw_cons_putc, NULL);
+CONSOLE_DRIVER(ofw);
static void
cn_drvinit(void *unused)
@@ -139,10 +139,10 @@
if ((tp->t_state & TS_ISOPEN) == 0) {
tp->t_state |= TS_CARR_ON;
ttyconsolemode(tp, 0);
- ttsetwater(tp);
setuptimeout = 1;
- } else if ((tp->t_state & TS_XCLUDE) && suser(td)) {
+ } else if ((tp->t_state & TS_XCLUDE) &&
+ priv_check(td, PRIV_TTY_EXCLUSIVE)) {
return (EBUSY);
}
@@ -228,7 +228,7 @@
tp = (struct tty *)v;
- while ((c = ofw_cons_checkc(NULL)) != -1) {
+ while ((c = ofw_cngetc(NULL)) != -1) {
if (tp->t_state & TS_ISOPEN) {
ttyld_rint(tp, c);
}
@@ -238,7 +238,7 @@
}
static void
-ofw_cons_probe(struct consdev *cp)
+ofw_cnprobe(struct consdev *cp)
{
int chosen;
@@ -261,7 +261,7 @@
}
static void
-ofw_cons_init(struct consdev *cp)
+ofw_cninit(struct consdev *cp)
{
/* XXX: This is the alias, but that should be good enough */
@@ -269,30 +269,13 @@
cp->cn_tp = ofw_tp;
}
-static int
-ofw_cons_getc(struct consdev *cp)
+static void
+ofw_cnterm(struct consdev *cp)
{
- unsigned char ch;
- int l;
-
- ch = '\0';
-
- while ((l = OF_read(stdin, &ch, 1)) != 1) {
- if (l != -2 && l != 0) {
- return (-1);
- }
- }
-
-#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
- if (kdb_alt_break(ch, &alt_break_state))
- kdb_enter("Break sequence on console");
-#endif
-
- return (ch);
}
static int
-ofw_cons_checkc(struct consdev *cp)
+ofw_cngetc(struct consdev *cp)
{
unsigned char ch;
@@ -308,7 +291,7 @@
}
static void
-ofw_cons_putc(struct consdev *cp, int c)
+ofw_cnputc(struct consdev *cp, int c)
{
char cbuf;
Index: openpromio.c
===================================================================
RCS file: /home/cvs/src/sys/dev/ofw/openpromio.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/ofw/openpromio.c -L sys/dev/ofw/openpromio.c -u -r1.1.1.1 -r1.2
--- sys/dev/ofw/openpromio.c
+++ sys/dev/ofw/openpromio.c
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/ofw/openpromio.c,v 1.7 2005/05/19 15:23:17 marius Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/ofw/openpromio.c,v 1.7.14.1 2007/12/23 11:26:48 marius Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -101,12 +101,17 @@
char *buf;
int error;
+ if ((flags & FREAD) == 0)
+ return (EPERM);
+
prop = buf = NULL;
error = 0;
- oprom = *(void **)data;
switch (cmd) {
case OPROMCHILD:
case OPROMNEXT:
+ if (data == NULL || *(void **)data == NULL)
+ return (EINVAL);
+ oprom = *(void **)data;
error = copyin(&oprom->oprom_size, &len, sizeof(len));
if (error != 0)
break;
@@ -135,6 +140,9 @@
break;
case OPROMGETPROP:
case OPROMNXTPROP:
+ if (data == NULL || *(void **)data == NULL)
+ return (EINVAL);
+ oprom = *(void **)data;
error = copyin(&oprom->oprom_size, &len, sizeof(len));
if (error != 0)
break;
Index: openfirm.c
===================================================================
RCS file: /home/cvs/src/sys/dev/ofw/openfirm.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/ofw/openfirm.c -L sys/dev/ofw/openfirm.c -u -r1.1.1.1 -r1.2
--- sys/dev/ofw/openfirm.c
+++ sys/dev/ofw/openfirm.c
@@ -30,9 +30,6 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/ofw/openfirm.c,v 1.14 2005/01/06 01:43:00 imp Exp $");
/*-
* Copyright (C) 2000 Benno Rice.
* All rights reserved.
@@ -56,9 +53,11 @@
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/dev/ofw/openfirm.c,v 1.21 2007/07/06 00:47:44 peter Exp $");
+
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
@@ -70,32 +69,27 @@
MALLOC_DEFINE(M_OFWPROP, "openfirm", "Open Firmware properties");
-static ihandle_t stdin;
static ihandle_t stdout;
-char *OF_buf;
-
-void ofbcopy(const void *, void *, size_t);
-
-/* Initialiaser */
+/* Initialiser */
void
OF_init(int (*openfirm)(void *))
{
- phandle_t chosen;
+ phandle_t chosen;
set_openfirm_callback(openfirm);
if ((chosen = OF_finddevice("/chosen")) == -1)
OF_exit();
- OF_getprop(chosen, "stdin", &stdin, sizeof(stdin));
- OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
+ if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
+ OF_exit();
}
void
OF_printf(const char *fmt, ...)
{
va_list va;
- char buf[1024];
+ char buf[1024];
va_start(va, fmt);
vsprintf(buf, fmt, va);
@@ -112,11 +106,11 @@
OF_test(char *name)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t service;
- cell_t missing;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t service;
+ cell_t missing;
} args = {
(cell_t)"test",
1,
@@ -125,8 +119,8 @@
args.service = (cell_t)name;
if (openfirmware(&args) == -1)
- return -1;
- return args.missing;
+ return (-1);
+ return (args.missing);
}
int
@@ -140,14 +134,14 @@
cell_t slot[16];
} args = {
(cell_t)"interpret",
- 1
+ 1,
};
cell_t status;
int i = 0;
+ va_start(ap, nreturns);
args.nreturns = ++nreturns;
args.slot[i++] = (cell_t)cmd;
- va_start(ap, nreturns);
while (i < 1)
args.slot[i++] = va_arg(ap, cell_t);
if (openfirmware(&args) == -1) {
@@ -166,18 +160,18 @@
OF_milliseconds()
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t ms;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t ms;
} args = {
(cell_t)"milliseconds",
0,
1,
};
-
+
openfirmware(&args);
- return args.ms;
+ return (args.ms);
}
/*
@@ -189,21 +183,21 @@
OF_peer(phandle_t node)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t node;
- cell_t next;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t node;
+ cell_t next;
} args = {
(cell_t)"peer",
1,
1,
};
- args.node = (cell_t)node;
+ args.node = node;
if (openfirmware(&args) == -1)
- return -1;
- return args.next;
+ return (-1);
+ return (args.next);
}
/* Return the first child of this node or 0. */
@@ -211,21 +205,21 @@
OF_child(phandle_t node)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t node;
- cell_t child;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t node;
+ cell_t child;
} args = {
(cell_t)"child",
1,
1,
};
- args.node = (cell_t)node;
+ args.node = node;
if (openfirmware(&args) == -1)
- return -1;
- return args.child;
+ return (-1);
+ return (args.child);
}
/* Return the parent of this node or 0. */
@@ -233,21 +227,21 @@
OF_parent(phandle_t node)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t node;
- cell_t parent;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t node;
+ cell_t parent;
} args = {
(cell_t)"parent",
1,
1,
};
- args.node = (cell_t)node;
+ args.node = node;
if (openfirmware(&args) == -1)
- return -1;
- return args.parent;
+ return (-1);
+ return (args.parent);
}
/* Return the package handle that corresponds to an instance handle. */
@@ -255,21 +249,21 @@
OF_instance_to_package(ihandle_t instance)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t instance;
- cell_t package;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t instance;
+ cell_t package;
} args = {
(cell_t)"instance-to-package",
1,
1,
};
-
- args.instance = (cell_t)instance;
+
+ args.instance = instance;
if (openfirmware(&args) == -1)
- return -1;
- return args.package;
+ return (-1);
+ return (args.package);
}
/* Get the length of a property of a package. */
@@ -277,23 +271,23 @@
OF_getproplen(phandle_t package, char *propname)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t package;
- cell_t propname;
- cell_t proplen;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t package;
+ cell_t propname;
+ cell_t proplen;
} args = {
(cell_t)"getproplen",
2,
1,
};
- args.package = (cell_t)package;
+ args.package = package;
args.propname = (cell_t)propname;
if (openfirmware(&args) == -1)
- return -1;
- return args.proplen;
+ return (-1);
+ return (args.proplen);
}
/* Get the value of a property of a package. */
@@ -301,27 +295,27 @@
OF_getprop(phandle_t package, char *propname, void *buf, int buflen)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t package;
- cell_t propname;
- cell_t buf;
- cell_t buflen;
- cell_t size;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t package;
+ cell_t propname;
+ cell_t buf;
+ cell_t buflen;
+ cell_t size;
} args = {
(cell_t)"getprop",
4,
1,
};
-
- args.package = (cell_t)package;
+
+ args.package = package;
args.propname = (cell_t)propname;
args.buf = (cell_t)buf;
- args.buflen = (cell_t)buflen;
+ args.buflen = buflen;
if (openfirmware(&args) == -1)
- return -1;
- return args.size;
+ return (-1);
+ return (args.size);
}
/*
@@ -353,25 +347,25 @@
OF_nextprop(phandle_t package, char *previous, char *buf)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t package;
- cell_t previous;
- cell_t buf;
- cell_t flag;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t package;
+ cell_t previous;
+ cell_t buf;
+ cell_t flag;
} args = {
(cell_t)"nextprop",
3,
1,
};
- args.package = (cell_t)package;
+ args.package = package;
args.previous = (cell_t)previous;
args.buf = (cell_t)buf;
if (openfirmware(&args) == -1)
- return -1;
- return args.flag;
+ return (-1);
+ return (args.flag);
}
/* Set the value of a property of a package. */
@@ -380,27 +374,27 @@
OF_setprop(phandle_t package, char *propname, void *buf, int len)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t package;
- cell_t propname;
- cell_t buf;
- cell_t len;
- cell_t size;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t package;
+ cell_t propname;
+ cell_t buf;
+ cell_t len;
+ cell_t size;
} args = {
(cell_t)"setprop",
4,
1,
};
-
- args.package = (cell_t)package;
+
+ args.package = package;
args.propname = (cell_t)propname;
args.buf = (cell_t)buf;
- args.len = (cell_t)len;
+ args.len = len;
if (openfirmware(&args) == -1)
- return -1;
- return args.size;
+ return (-1);
+ return (args.size);
}
/* Convert a device specifier to a fully qualified pathname. */
@@ -408,25 +402,25 @@
OF_canon(const char *device, char *buf, int len)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t device;
- cell_t buf;
- cell_t len;
- cell_t size;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t device;
+ cell_t buf;
+ cell_t len;
+ cell_t size;
} args = {
(cell_t)"canon",
3,
1,
};
-
+
args.device = (cell_t)device;
args.buf = (cell_t)buf;
- args.len = (cell_t)len;
+ args.len = len;
if (openfirmware(&args) == -1)
- return -1;
- return args.size;
+ return (-1);
+ return (args.size);
}
/* Return a package handle for the specified device. */
@@ -434,21 +428,21 @@
OF_finddevice(const char *device)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t device;
- cell_t package;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t device;
+ cell_t package;
} args = {
(cell_t)"finddevice",
1,
1,
- };
-
+ };
+
args.device = (cell_t)device;
if (openfirmware(&args) == -1)
- return -1;
- return args.package;
+ return (-1);
+ return (args.package);
}
/* Return the fully qualified pathname corresponding to an instance. */
@@ -456,25 +450,25 @@
OF_instance_to_path(ihandle_t instance, char *buf, int len)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t instance;
- cell_t buf;
- cell_t len;
- cell_t size;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t instance;
+ cell_t buf;
+ cell_t len;
+ cell_t size;
} args = {
(cell_t)"instance-to-path",
3,
1,
};
- args.instance = (cell_t)instance;
+ args.instance = instance;
args.buf = (cell_t)buf;
- args.len = (cell_t)len;
+ args.len = len;
if (openfirmware(&args) == -1)
- return -1;
- return(args.size);
+ return (-1);
+ return (args.size);
}
/* Return the fully qualified pathname corresponding to a package. */
@@ -482,25 +476,25 @@
OF_package_to_path(phandle_t package, char *buf, int len)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t package;
- cell_t buf;
- cell_t len;
- cell_t size;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t package;
+ cell_t buf;
+ cell_t len;
+ cell_t size;
} args = {
(cell_t)"package-to-path",
3,
1,
};
- args.package = (cell_t)package;
+ args.package = package;
args.buf = (cell_t)buf;
- args.len = (cell_t)len;
+ args.len = len;
if (openfirmware(&args) == -1)
- return -1;
- return(args.size);
+ return (-1);
+ return (args.size);
}
/* Call the method in the scope of a given instance. */
@@ -509,42 +503,41 @@
{
va_list ap;
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t method;
- cell_t instance;
- cell_t args_n_results[12];
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t method;
+ cell_t instance;
+ cell_t args_n_results[12];
} args = {
(cell_t)"call-method",
2,
1,
};
- cell_t *ip;
+ cell_t *cp;
int n;
if (nargs > 6)
- return -1;
- args.nargs = (cell_t)nargs + 2;
- args.nreturns = (cell_t)nreturns + 1;
+ return (-1);
+ args.nargs = nargs + 2;
+ args.nreturns = nreturns + 1;
args.method = (cell_t)method;
- args.instance = (cell_t)instance;
+ args.instance = instance;
va_start(ap, nreturns);
- for (ip = args.args_n_results + (n = (cell_t)nargs); --n >= 0;)
- *--ip = va_arg(ap, cell_t);
-
+ for (cp = args.args_n_results + (n = nargs); --n >= 0;)
+ *--cp = va_arg(ap, cell_t);
if (openfirmware(&args) == -1)
- return -1;
+ return (-1);
if (args.args_n_results[nargs])
- return args.args_n_results[nargs];
- for (ip = args.args_n_results + nargs + (n = args.nreturns); --n > 0;)
- *va_arg(ap, cell_t *) = *--ip;
+ return (args.args_n_results[nargs]);
+ for (cp = args.args_n_results + nargs + (n = args.nreturns); --n > 0;)
+ *va_arg(ap, cell_t *) = *--cp;
va_end(ap);
- return 0;
+ return (0);
}
/*
- * Device I/O functions.
+ * Device I/O functions
*/
/* Open an instance for a device. */
@@ -552,22 +545,22 @@
OF_open(char *device)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t device;
- cell_t instance;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t device;
+ cell_t instance;
} args = {
(cell_t)"open",
1,
1,
};
-
+
args.device = (cell_t)device;
if (openfirmware(&args) == -1 || args.instance == 0) {
- return -1;
+ return (-1);
}
- return args.instance;
+ return (args.instance);
}
/* Close an instance. */
@@ -575,17 +568,16 @@
OF_close(ihandle_t instance)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t instance;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t instance;
} args = {
(cell_t)"close",
1,
- 0,
};
-
- args.instance = (cell_t)instance;
+
+ args.instance = instance;
openfirmware(&args);
}
@@ -594,26 +586,26 @@
OF_read(ihandle_t instance, void *addr, int len)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t instance;
- cell_t addr;
- cell_t len;
- cell_t actual;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t instance;
+ cell_t addr;
+ cell_t len;
+ cell_t actual;
} args = {
(cell_t)"read",
3,
1,
};
- args.instance = (cell_t)instance;
+ args.instance = instance;
args.addr = (cell_t)addr;
- args.len = (cell_t)len;
+ args.len = len;
if (openfirmware(&args) == -1)
- return -1;
+ return (-1);
- return args.actual;
+ return (args.actual);
}
/* Write to an instance. */
@@ -621,25 +613,25 @@
OF_write(ihandle_t instance, void *addr, int len)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t instance;
- cell_t addr;
- cell_t len;
- cell_t actual;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t instance;
+ cell_t addr;
+ cell_t len;
+ cell_t actual;
} args = {
(cell_t)"write",
3,
1,
};
- args.instance = (cell_t)instance;
+ args.instance = instance;
args.addr = (cell_t)addr;
- args.len = (cell_t)len;
+ args.len = len;
if (openfirmware(&args) == -1)
- return -1;
- return args.actual;
+ return (-1);
+ return (args.actual);
}
/* Seek to a position. */
@@ -647,29 +639,29 @@
OF_seek(ihandle_t instance, u_int64_t pos)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t instance;
- cell_t poshi;
- cell_t poslo;
- cell_t status;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t instance;
+ cell_t poshi;
+ cell_t poslo;
+ cell_t status;
} args = {
(cell_t)"seek",
3,
1,
};
-
- args.instance = (cell_t)instance;
- args.poshi = (cell_t)(pos >> 32);
- args.poslo = (cell_t)pos;
+
+ args.instance = instance;
+ args.poshi = pos >> 32;
+ args.poslo = pos;
if (openfirmware(&args) == -1)
- return -1;
- return args.status;
+ return (-1);
+ return (args.status);
}
/*
- * Memory functions.
+ * Memory functions
*/
/* Claim an area of memory. */
@@ -677,13 +669,13 @@
OF_claim(void *virt, u_int size, u_int align)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t virt;
- cell_t size;
- cell_t align;
- cell_t baseaddr;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t virt;
+ cell_t size;
+ cell_t align;
+ cell_t baseaddr;
} args = {
(cell_t)"claim",
3,
@@ -691,11 +683,11 @@
};
args.virt = (cell_t)virt;
- args.size = (cell_t)size;
- args.align = (cell_t)align;
+ args.size = size;
+ args.align = align;
if (openfirmware(&args) == -1)
- return (void *)-1;
- return (void *)args.baseaddr;
+ return ((void *)-1);
+ return ((void *)args.baseaddr);
}
/* Release an area of memory. */
@@ -703,24 +695,23 @@
OF_release(void *virt, u_int size)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t virt;
- cell_t size;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t virt;
+ cell_t size;
} args = {
(cell_t)"release",
2,
- 0,
};
-
+
args.virt = (cell_t)virt;
- args.size = (cell_t)size;
+ args.size = size;
openfirmware(&args);
}
/*
- * Control transfer functions.
+ * Control transfer functions
*/
/* Reset the system and call "boot <bootspec>". */
@@ -728,19 +719,19 @@
OF_boot(char *bootspec)
{
static struct {
- cell_t name;
- cell_t nargs;
- cell_t nreturns;
- cell_t bootspec;
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t bootspec;
} args = {
(cell_t)"boot",
1,
- 0,
};
args.bootspec = (cell_t)bootspec;
openfirmware(&args);
- for (;;); /* just in case */
+ for (;;) /* just in case */
+ ;
}
/* Suspend and drop back to the Open Firmware interface. */
@@ -753,12 +744,10 @@
cell_t nreturns;
} args = {
(cell_t)"enter",
- 0,
- 0
};
openfirmware(&args);
- return; /* We may come back. */
+ /* We may come back. */
}
/* Shut down and drop back to the Open Firmware interface. */
@@ -771,39 +760,37 @@
cell_t nreturns;
} args = {
(cell_t)"exit",
- 0,
- 0
};
openfirmware(&args);
- for (;;); /* just in case */
+ for (;;) /* just in case */
+ ;
}
/* Free <size> bytes starting at <virt>, then call <entry> with <arg>. */
-#ifdef __notyet__
+#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;
- call_t entry;
- cell_t arg;
- cell_t len;
+ 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,
- 0,
};
args.virt = (cell_t)virt;
- args.size = (cell_t)size;
+ args.size = size;
args.entry = (cell_t)entry;
args.arg = (cell_t)arg;
- args.len = (cell_t)len;
+ args.len = len;
openfirmware(&args);
}
#else
@@ -815,21 +802,9 @@
* This is a REALLY dirty hack till the firmware gets this going
*/
#if 0
- OF_release(virt, size);
+ if (size > 0)
+ OF_release(virt, size);
#endif
entry(0, 0, openfirmware, arg, len);
}
#endif
-
-void
-ofbcopy(const void *src, void *dst, size_t len)
-{
- const char *sp = src;
- char *dp = dst;
-
- if (src == dst)
- return;
-
- while (len-- > 0)
- *dp++ = *sp++;
-}
Index: ofw_bus_if.m
===================================================================
RCS file: /home/cvs/src/sys/dev/ofw/ofw_bus_if.m,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/ofw/ofw_bus_if.m -L sys/dev/ofw/ofw_bus_if.m -u -r1.1.1.1 -r1.2
--- sys/dev/ofw/ofw_bus_if.m
+++ sys/dev/ofw/ofw_bus_if.m
@@ -1,6 +1,6 @@
#-
# Copyright (c) 2001, 2003 by Thomas Moestl <tmm at FreeBSD.org>
-# Copyright (c) 2004 by Marius Strobl <marius at FreeBSD.org>
+# Copyright (c) 2004, 2005 by Marius Strobl <marius at FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -23,22 +23,47 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
-# $FreeBSD: src/sys/dev/ofw/ofw_bus_if.m,v 1.2 2005/01/06 01:43:00 imp Exp $
+# $FreeBSD: src/sys/dev/ofw/ofw_bus_if.m,v 1.3 2005/11/22 16:37:45 marius Exp $
+
+# Interface for retrieving the package handle and a subset, namely
+# 'compatible', 'device_type', 'model' and 'name', of the standard
+# properties of a device on an Open Firmware assisted bus for use
+# in device drivers. The rest of the standard properties, 'address',
+# 'interrupts', 'reg' and 'status', are not covered by this interface
+# as they are expected to be only of interest in the respective bus
+# driver.
#include <sys/bus.h>
-#include <machine/bus.h>
#include <dev/ofw/openfirm.h>
INTERFACE ofw_bus;
+HEADER {
+ struct ofw_bus_devinfo {
+ phandle_t obd_node;
+ char *obd_compat;
+ char *obd_model;
+ char *obd_name;
+ char *obd_type;
+ };
+};
+
CODE {
+ static ofw_bus_get_devinfo_t ofw_bus_default_get_devinfo;
static ofw_bus_get_compat_t ofw_bus_default_get_compat;
static ofw_bus_get_model_t ofw_bus_default_get_model;
static ofw_bus_get_name_t ofw_bus_default_get_name;
static ofw_bus_get_node_t ofw_bus_default_get_node;
static ofw_bus_get_type_t ofw_bus_default_get_type;
+ static const struct ofw_bus_devinfo *
+ ofw_bus_default_get_devinfo(device_t bus, device_t dev)
+ {
+
+ return (NULL);
+ }
+
static const char *
ofw_bus_default_get_compat(device_t bus, device_t dev)
{
@@ -75,6 +100,15 @@
}
};
+# Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus
+# drivers which use the generic methods in ofw_bus_subr.c to implement the
+# reset of this interface. The default method will return NULL, which means
+# there is no such struct associated with the device.
+METHOD const struct ofw_bus_devinfo * get_devinfo {
+ device_t bus;
+ device_t dev;
+} DEFAULT ofw_bus_default_get_devinfo;
+
# Get the alternate firmware name for the device dev on the bus. The default
# method will return NULL, which means the device doesn't have such a property.
METHOD const char * get_compat {
Index: ofw_disk.c
===================================================================
RCS file: /home/cvs/src/sys/dev/ofw/ofw_disk.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/ofw/ofw_disk.c -L sys/dev/ofw/ofw_disk.c -u -r1.1.1.1 -r1.2
--- sys/dev/ofw/ofw_disk.c
+++ sys/dev/ofw/ofw_disk.c
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/ofw/ofw_disk.c,v 1.17 2005/01/06 01:43:00 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/ofw/ofw_disk.c,v 1.18 2005/10/31 03:09:38 grehan Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -82,6 +82,7 @@
u_int r;
r = OF_seek(sc->ofwd_instance, bp->bio_offset);
+
switch (bp->bio_cmd) {
case BIO_READ:
r = OF_read(sc->ofwd_instance, (void *)bp->bio_data,
@@ -164,7 +165,7 @@
bioq_init(&sc->ofwd_bio_queue);
mtx_init(&sc->ofwd_queue_mtx, "ofwd bio queue", NULL, MTX_DEF);
sc->ofwd_instance = ifd;
- sc->ofwd_mediasize = (off_t)2*33554432 * OFWD_BLOCKSIZE;
+ sc->ofwd_mediasize = (off_t)2*33554432;
sc->ofwd_sectorsize = OFWD_BLOCKSIZE;
sc->ofwd_fwsectors = 0;
sc->ofwd_fwheads = 0;
Index: openfirm.h
===================================================================
RCS file: /home/cvs/src/sys/dev/ofw/openfirm.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/ofw/openfirm.h -L sys/dev/ofw/openfirm.h -u -r1.1.1.1 -r1.2
--- sys/dev/ofw/openfirm.h
+++ sys/dev/ofw/openfirm.h
@@ -54,7 +54,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: src/sys/dev/ofw/openfirm.h,v 1.11 2005/01/06 01:43:00 imp Exp $
+ * $FreeBSD: src/sys/dev/ofw/openfirm.h,v 1.13 2007/06/16 22:30:38 marius Exp $
*/
#ifndef _OPENFIRM_H_
@@ -90,7 +90,6 @@
/* Generic functions */
int OF_test(char *);
-void OF_helloworld(void);
void OF_printf(const char *, ...);
/* Device tree functions */
@@ -130,10 +129,6 @@
/* User interface functions */
int OF_interpret(char *, int, ...);
-#if 0
-void *OF_set_callback(void *);
-void OF_set_symbol_lookup(void *, void *);
-#endif
/* Time function */
int OF_milliseconds(void);
--- /dev/null
+++ sys/dev/ofw/ofw_bus_subr.c
@@ -0,0 +1,128 @@
+/*-
+ * Copyright (c) 2005 Marius Strobl <marius at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/dev/ofw/ofw_bus_subr.c,v 1.1 2005/11/22 16:37:45 marius Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/errno.h>
+
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/openfirm.h>
+
+#include "ofw_bus_if.h"
+
+int
+ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *obd, phandle_t node)
+{
+
+ if (obd == NULL)
+ return (ENOMEM);
+ /* The 'name' property is considered mandatory. */
+ if ((OF_getprop_alloc(node, "name", 1, (void **)&obd->obd_name)) == -1)
+ return (EINVAL);
+ OF_getprop_alloc(node, "compatible", 1, (void **)&obd->obd_compat);
+ OF_getprop_alloc(node, "device_type", 1, (void **)&obd->obd_type);
+ OF_getprop_alloc(node, "model", 1, (void **)&obd->obd_model);
+ obd->obd_node = node;
+ return (0);
+}
+
+void
+ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *obd)
+{
+
+ if (obd == NULL)
+ return;
+ if (obd->obd_compat != NULL)
+ free(obd->obd_compat, M_OFWPROP);
+ if (obd->obd_model != NULL)
+ free(obd->obd_model, M_OFWPROP);
+ if (obd->obd_name != NULL)
+ free(obd->obd_name, M_OFWPROP);
+ if (obd->obd_type != NULL)
+ free(obd->obd_type, M_OFWPROP);
+}
+
+
+const char *
+ofw_bus_gen_get_compat(device_t bus, device_t dev)
+{
+ const struct ofw_bus_devinfo *obd;
+
+ obd = OFW_BUS_GET_DEVINFO(bus, dev);
+ if (obd == NULL)
+ return (NULL);
+ return (obd->obd_compat);
+}
+
+const char *
+ofw_bus_gen_get_model(device_t bus, device_t dev)
+{
+ const struct ofw_bus_devinfo *obd;
+
+ obd = OFW_BUS_GET_DEVINFO(bus, dev);
+ if (obd == NULL)
+ return (NULL);
+ return (obd->obd_model);
+}
+
+const char *
+ofw_bus_gen_get_name(device_t bus, device_t dev)
+{
+ const struct ofw_bus_devinfo *obd;
+
+ obd = OFW_BUS_GET_DEVINFO(bus, dev);
+ if (obd == NULL)
+ return (NULL);
+ return (obd->obd_name);
+}
+
+phandle_t
+ofw_bus_gen_get_node(device_t bus, device_t dev)
+{
+ const struct ofw_bus_devinfo *obd;
+
+ obd = OFW_BUS_GET_DEVINFO(bus, dev);
+ if (obd == NULL)
+ return (0);
+ return (obd->obd_node);
+}
+
+const char *
+ofw_bus_gen_get_type(device_t bus, device_t dev)
+{
+ const struct ofw_bus_devinfo *obd;
+
+ obd = OFW_BUS_GET_DEVINFO(bus, dev);
+ if (obd == NULL)
+ return (NULL);
+ return (obd->obd_type);
+}
--- /dev/null
+++ sys/dev/ofw/ofw_bus_subr.h
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2005 Marius Strobl <marius at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer,
+ * without modification, immediately at the beginning of the file.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/dev/ofw/ofw_bus_subr.h,v 1.1 2005/11/22 16:37:45 marius Exp $
+ */
+
+#ifndef _DEV_OFW_OFW_BUS_SUBR_H_
+#define _DEV_OFW_OFW_BUS_SUBR_H_
+
+#include <sys/bus.h>
+
+#include <dev/ofw/openfirm.h>
+
+#include "ofw_bus_if.h"
+
+int ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *, phandle_t);
+void ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *);
+
+ofw_bus_get_compat_t ofw_bus_gen_get_compat;
+ofw_bus_get_model_t ofw_bus_gen_get_model;
+ofw_bus_get_name_t ofw_bus_gen_get_name;
+ofw_bus_get_node_t ofw_bus_gen_get_node;
+ofw_bus_get_type_t ofw_bus_gen_get_type;
+
+#endif /* !_DEV_OFW_OFW_BUS_SUBR_H_ */
Index: openfirmio.c
===================================================================
RCS file: /home/cvs/src/sys/dev/ofw/openfirmio.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/ofw/openfirmio.c -L sys/dev/ofw/openfirmio.c -u -r1.1.1.1 -r1.2
--- sys/dev/ofw/openfirmio.c
+++ sys/dev/ofw/openfirmio.c
@@ -1,7 +1,7 @@
/* $NetBSD: openfirmio.c,v 1.4 2002/09/06 13:23:19 gehenna Exp $ */
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/ofw/openfirmio.c,v 1.13 2005/01/06 01:43:00 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/ofw/openfirmio.c,v 1.14 2006/09/01 20:12:12 marius Exp $");
/*-
* Copyright (c) 1992, 1993
@@ -184,9 +184,9 @@
case OFIOCSET:
/*
* Note: Text string values for at least the /options node
- * have to be null-terminated and the length paramter must
+ * have to be null-terminated and the length parameter must
* include this terminating null. However, like OF_getprop(),
- * OF_setprop() will return the the actual length of the text
+ * OF_setprop() will return the actual length of the text
* string, i.e. omitting the terminating null.
*/
if ((flags & FWRITE) == 0)
More information about the Midnightbsd-cvs
mailing list