diff options
author | jake <jake@FreeBSD.org> | 2001-07-31 03:36:26 +0000 |
---|---|---|
committer | jake <jake@FreeBSD.org> | 2001-07-31 03:36:26 +0000 |
commit | 104745ff114499d8f2003702d56c3b969f1b064b (patch) | |
tree | cb99726fad9e605a4f06b4c55dcde6f4c761c11b /sys/dev/ofw | |
parent | d47551647162edb928487e16e76531f482c470e8 (diff) | |
download | FreeBSD-src-104745ff114499d8f2003702d56c3b969f1b064b.zip FreeBSD-src-104745ff114499d8f2003702d56c3b969f1b064b.tar.gz |
Make the openfirmware functions work on 64 bit architectures by using
a standard cell_t type for the fields of all argument structs. Also
make ihandle_t and phandle_t unsigned to avoid sign extension problems.
Approved by: benno
Diffstat (limited to 'sys/dev/ofw')
-rw-r--r-- | sys/dev/ofw/openfirm.c | 472 | ||||
-rw-r--r-- | sys/dev/ofw/openfirm.h | 6 |
2 files changed, 241 insertions, 237 deletions
diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c index ce0d2fe..61b6391 100644 --- a/sys/dev/ofw/openfirm.c +++ b/sys/dev/ofw/openfirm.c @@ -57,6 +57,7 @@ * $FreeBSD$ */ +#include <sys/param.h> #include <sys/systm.h> #include <machine/stdarg.h> @@ -105,18 +106,18 @@ int OF_test(char *name) { static struct { - char *name; - int nargs; - int nreturns; - char *service; - int missing; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t service; + cell_t missing; } args = { - "test", + (cell_t)"test", 1, 1, }; - args.service = name; + args.service = (cell_t)name; if (openfirmware(&args) == -1) return -1; return args.missing; @@ -127,12 +128,12 @@ int OF_milliseconds() { static struct { - char *name; - int nargs; - int nreturns; - int ms; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t ms; } args = { - "milliseconds", + (cell_t)"milliseconds", 0, 1, }; @@ -150,18 +151,18 @@ phandle_t OF_peer(phandle_t node) { static struct { - char *name; - int nargs; - int nreturns; - phandle_t node; - phandle_t next; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t node; + cell_t next; } args = { - "peer", + (cell_t)"peer", 1, 1, }; - args.node = node; + args.node = (cell_t)node; if (openfirmware(&args) == -1) return -1; return args.next; @@ -172,18 +173,18 @@ phandle_t OF_child(phandle_t node) { static struct { - char *name; - int nargs; - int nreturns; - phandle_t node; - phandle_t child; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t node; + cell_t child; } args = { - "child", + (cell_t)"child", 1, 1, }; - args.node = node; + args.node = (cell_t)node; if (openfirmware(&args) == -1) return -1; return args.child; @@ -194,18 +195,18 @@ phandle_t OF_parent(phandle_t node) { static struct { - char *name; - int nargs; - int nreturns; - phandle_t node; - phandle_t parent; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t node; + cell_t parent; } args = { - "parent", + (cell_t)"parent", 1, 1, }; - args.node = node; + args.node = (cell_t)node; if (openfirmware(&args) == -1) return -1; return args.parent; @@ -216,18 +217,18 @@ phandle_t OF_instance_to_package(ihandle_t instance) { static struct { - char *name; - int nargs; - int nreturns; - ihandle_t instance; - phandle_t package; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t instance; + cell_t package; } args = { - "instance-to-package", + (cell_t)"instance-to-package", 1, 1, }; - args.instance = instance; + args.instance = (cell_t)instance; if (openfirmware(&args) == -1) return -1; return args.package; @@ -238,20 +239,20 @@ int OF_getproplen(phandle_t package, char *propname) { static struct { - char *name; - int nargs; - int nreturns; - phandle_t package; - char *propname; - int proplen; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t package; + cell_t propname; + cell_t proplen; } args = { - "getproplen", + (cell_t)"getproplen", 2, 1, }; - args.package = package; - args.propname = propname; + args.package = (cell_t)package; + args.propname = (cell_t)propname; if (openfirmware(&args) == -1) return -1; return args.proplen; @@ -262,24 +263,24 @@ int OF_getprop(phandle_t package, char *propname, void *buf, int buflen) { static struct { - char *name; - int nargs; - int nreturns; - phandle_t package; - char *propname; - void *buf; - int buflen; - int 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 = { - "getprop", + (cell_t)"getprop", 4, 1, }; - args.package = package; - args.propname = propname; - args.buf = buf; - args.buflen = buflen; + args.package = (cell_t)package; + args.propname = (cell_t)propname; + args.buf = (cell_t)buf; + args.buflen = (cell_t)buflen; if (openfirmware(&args) == -1) return -1; return args.size; @@ -290,22 +291,22 @@ int OF_nextprop(phandle_t package, char *previous, char *buf) { static struct { - char *name; - int nargs; - int nreturns; - phandle_t package; - char *previous; - char *buf; - int flag; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t package; + cell_t previous; + cell_t buf; + cell_t flag; } args = { - "nextprop", + (cell_t)"nextprop", 3, 1, }; - args.package = package; - args.previous = previous; - args.buf = buf; + args.package = (cell_t)package; + args.previous = (cell_t)previous; + args.buf = (cell_t)buf; if (openfirmware(&args) == -1) return -1; return args.flag; @@ -317,24 +318,24 @@ int OF_setprop(phandle_t package, char *propname, void *buf, int len) { static struct { - char *name; - int nargs; - int nreturns; - phandle_t package; - char *propname; - void *buf; - int len; - int 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 = { - "setprop", + (cell_t)"setprop", 4, 1, }; - args.package = package; - args.propname = propname; - args.buf = buf; - args.len = len; + args.package = (cell_t)package; + args.propname = (cell_t)propname; + args.buf = (cell_t)buf; + args.len = (cell_t)len; if (openfirmware(&args) == -1) return -1; return args.size; @@ -345,22 +346,22 @@ int OF_canon(const char *device, char *buf, int len) { static struct { - char *name; - int nargs; - int nreturns; - char *device; - char *buf; - int len; - int size; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t device; + cell_t buf; + cell_t len; + cell_t size; } args = { - "canon", + (cell_t)"canon", 3, 1, }; - args.device = (char *)(uintptr_t *)device; - args.buf = buf; - args.len = len; + args.device = (cell_t)device; + args.buf = (cell_t)buf; + args.len = (cell_t)len; if (openfirmware(&args) == -1) return -1; return args.size; @@ -371,18 +372,18 @@ phandle_t OF_finddevice(const char *device) { static struct { - char *name; - int nargs; - int nreturns; - char *device; - phandle_t package; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t device; + cell_t package; } args = { - "finddevice", + (cell_t)"finddevice", 1, 1, }; - args.device = (char *)(uintptr_t *)device; + args.device = (cell_t)device; if (openfirmware(&args) == -1) return -1; return args.package; @@ -393,22 +394,22 @@ int OF_instance_to_path(ihandle_t instance, char *buf, int len) { static struct { - char *name; - int nargs; - int nreturns; - ihandle_t instance; - char *buf; - int len; - int size; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t instance; + cell_t buf; + cell_t len; + cell_t size; } args = { - "instance-to-path", + (cell_t)"instance-to-path", 3, 1, }; - args.instance = instance; - args.buf = buf; - args.len = len; + args.instance = (cell_t)instance; + args.buf = (cell_t)buf; + args.len = (cell_t)len; if (openfirmware(&args) == -1) return -1; return(args.size); @@ -419,22 +420,22 @@ int OF_package_to_path(phandle_t package, char *buf, int len) { static struct { - char *name; - int nargs; - int nreturns; - phandle_t package; - char *buf; - int len; - int size; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t package; + cell_t buf; + cell_t len; + cell_t size; } args = { - "package-to-path", + (cell_t)"package-to-path", 3, 1, }; - args.package = package; - args.buf = buf; - args.len = len; + args.package = (cell_t)package; + args.buf = (cell_t)buf; + args.len = (cell_t)len; if (openfirmware(&args) == -1) return -1; return(args.size); @@ -446,35 +447,36 @@ OF_call_method(char *method, ihandle_t instance, int nargs, int nreturns, ...) { va_list ap; static struct { - char *name; - int nargs; - int nreturns; - char *method; - ihandle_t instance; - int 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 = { - "call-method", + (cell_t)"call-method", 2, 1, }; - int *ip, n; + cell_t *ip; + int n; if (nargs > 6) return -1; - args.nargs = nargs + 2; - args.nreturns = nreturns + 1; - args.method = method; - args.instance = instance; + args.nargs = (cell_t)nargs + 2; + args.nreturns = (cell_t)nreturns + 1; + args.method = (cell_t)method; + args.instance = (cell_t)instance; va_start(ap, nreturns); - for (ip = args.args_n_results + (n = nargs); --n >= 0;) - *--ip = va_arg(ap, int); + for (ip = args.args_n_results + (n = (cell_t)nargs); --n >= 0;) + *--ip = va_arg(ap, cell_t); if (openfirmware(&args) == -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, int *) = *--ip; + *va_arg(ap, cell_t *) = *--ip; va_end(ap); return 0; } @@ -488,18 +490,18 @@ ihandle_t OF_open(char *device) { static struct { - char *name; - int nargs; - int nreturns; - char *device; - ihandle_t instance; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t device; + cell_t instance; } args = { - "open", + (cell_t)"open", 1, 1, }; - args.device = device; + args.device = (cell_t)device; if (openfirmware(&args) == -1 || args.instance == 0) { return -1; } @@ -511,17 +513,17 @@ void OF_close(ihandle_t instance) { static struct { - char *name; - int nargs; - int nreturns; - ihandle_t instance; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t instance; } args = { - "close", + (cell_t)"close", 1, 0, }; - args.instance = instance; + args.instance = (cell_t)instance; openfirmware(&args); } @@ -530,22 +532,22 @@ int OF_read(ihandle_t instance, void *addr, int len) { static struct { - char *name; - int nargs; - int nreturns; - ihandle_t instance; - void *addr; - int len; - int actual; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t instance; + cell_t addr; + cell_t len; + cell_t actual; } args = { - "read", + (cell_t)"read", 3, 1, }; - args.instance = instance; - args.addr = addr; - args.len = len; + args.instance = (cell_t)instance; + args.addr = (cell_t)addr; + args.len = (cell_t)len; if (openfirmware(&args) == -1) return -1; @@ -557,22 +559,22 @@ int OF_write(ihandle_t instance, void *addr, int len) { static struct { - char *name; - int nargs; - int nreturns; - ihandle_t instance; - void *addr; - int len; - int actual; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t instance; + cell_t addr; + cell_t len; + cell_t actual; } args = { - "write", + (cell_t)"write", 3, 1, }; - args.instance = instance; - args.addr = addr; - args.len = len; + args.instance = (cell_t)instance; + args.addr = (cell_t)addr; + args.len = (cell_t)len; if (openfirmware(&args) == -1) return -1; return args.actual; @@ -583,22 +585,22 @@ int OF_seek(ihandle_t instance, u_int64_t pos) { static struct { - char *name; - int nargs; - int nreturns; - ihandle_t instance; - int poshi; - int poslo; - int status; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t instance; + cell_t poshi; + cell_t poslo; + cell_t status; } args = { - "seek", + (cell_t)"seek", 3, 1, }; - args.instance = instance; - args.poshi = (int)(pos >> 32); - args.poslo = (int)pos; + args.instance = (cell_t)instance; + args.poshi = (cell_t)(pos >> 32); + args.poslo = (cell_t)pos; if (openfirmware(&args) == -1) return -1; return args.status; @@ -613,25 +615,25 @@ void * OF_claim(void *virt, u_int size, u_int align) { static struct { - char *name; - int nargs; - int nreturns; - void *virt; - u_int size; - u_int align; - void *baseaddr; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t virt; + cell_t size; + cell_t align; + cell_t baseaddr; } args = { - "claim", + (cell_t)"claim", 3, 1, }; - args.virt = virt; - args.size = size; - args.align = align; + args.virt = (cell_t)virt; + args.size = (cell_t)size; + args.align = (cell_t)align; if (openfirmware(&args) == -1) return (void *)-1; - return args.baseaddr; + return (void *)args.baseaddr; } /* Release an area of memory. */ @@ -639,19 +641,19 @@ void OF_release(void *virt, u_int size) { static struct { - char *name; - int nargs; - int nreturns; - void *virt; - u_int size; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t virt; + cell_t size; } args = { - "release", + (cell_t)"release", 2, 0, }; - args.virt = virt; - args.size = size; + args.virt = (cell_t)virt; + args.size = (cell_t)size; openfirmware(&args); } @@ -664,17 +666,17 @@ void OF_boot(char *bootspec) { static struct { - char *name; - int nargs; - int nreturns; - char *bootspec; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t bootspec; } args = { - "boot", + (cell_t)"boot", 1, 0, }; - args.bootspec = bootspec; + args.bootspec = (cell_t)bootspec; openfirmware(&args); for (;;); /* just in case */ } @@ -684,11 +686,11 @@ void OF_enter() { static struct { - char *name; - int nargs; - int nreturns; + cell_t name; + cell_t nargs; + cell_t nreturns; } args = { - "enter", + (cell_t)"enter", 0, 0 }; @@ -702,11 +704,11 @@ void OF_exit() { static struct { - char *name; - int nargs; - int nreturns; + cell_t name; + cell_t nargs; + cell_t nreturns; } args = { - "exit", + (cell_t)"exit", 0, 0 }; @@ -721,25 +723,25 @@ void OF_chain(void *virt, u_int size, void (*entry)(), void *arg, u_int len) { static struct { - char *name; - int nargs; - int nreturns; - void *virt; - u_int size; - void (*entry)(); - void *arg; - u_int len; + cell_t name; + cell_t nargs; + cell_t nreturns; + cell_t virt; + cell_t size; + call_t entry; + cell_t arg; + cell_t len; } args = { - "chain", + (cell_t)"chain", 5, 0, }; - args.virt = virt; - args.size = size; - args.entry = entry; - args.arg = arg; - args.len = len; + args.virt = (cell_t)virt; + args.size = (cell_t)size; + args.entry = (cell_t)entry; + args.arg = (cell_t)arg; + args.len = (cell_t)len; openfirmware(&args); } #else diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h index 62ac3e6..d3760a9 100644 --- a/sys/dev/ofw/openfirm.h +++ b/sys/dev/ofw/openfirm.h @@ -67,8 +67,10 @@ #include <sys/cdefs.h> #include <sys/types.h> -typedef int ihandle_t; -typedef int phandle_t; +typedef unsigned long cell_t; + +typedef unsigned int ihandle_t; +typedef unsigned int phandle_t; /* * Stuff that is used by the OpenFirmware code. |