diff options
| author | Rafal Jaworowski <raj@FreeBSD.org> | 2010-05-28 10:43:56 +0000 |
|---|---|---|
| committer | Rafal Jaworowski <raj@FreeBSD.org> | 2010-05-28 10:43:56 +0000 |
| commit | 8297758a2206bc0fdc5383ddc4a496aca1686af0 (patch) | |
| tree | 8ab64de3265e079ec3e830ced915bbb9259ecf0e /sys/dev | |
| parent | 77e46080d80c913b50bd4fcea136a457c9c8af62 (diff) | |
Notes
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/ofw/ofw_bus_subr.c | 49 | ||||
| -rw-r--r-- | sys/dev/ofw/ofw_bus_subr.h | 4 | ||||
| -rw-r--r-- | sys/dev/ofw/ofw_if.m | 2 | ||||
| -rw-r--r-- | sys/dev/ofw/ofw_standard.c | 5 | ||||
| -rw-r--r-- | sys/dev/ofw/openfirm.c | 22 | ||||
| -rw-r--r-- | sys/dev/ofw/openfirm.h | 2 |
6 files changed, 73 insertions, 11 deletions
diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c index 05ce13c8e1bc..ae9379fd9af4 100644 --- a/sys/dev/ofw/ofw_bus_subr.c +++ b/sys/dev/ofw/ofw_bus_subr.c @@ -30,6 +30,7 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include "opt_platform.h" #include <sys/param.h> #include <sys/systm.h> #include <sys/bus.h> @@ -146,6 +147,53 @@ ofw_bus_gen_get_type(device_t bus, device_t dev) return (obd->obd_type); } +int +ofw_bus_is_compatible(device_t dev, const char *onecompat) +{ + phandle_t node; + const char *compat; + int len, onelen, l; + + if ((compat = ofw_bus_get_compat(dev)) == NULL) + return (0); + + if ((node = ofw_bus_get_node(dev)) == 0) + return (0); + + /* Get total 'compatible' prop len */ + if ((len = OF_getproplen(node, "compatible")) <= 0) + return (0); + + onelen = strlen(onecompat); + + while (len > 0) { + if (strncasecmp(compat, onecompat, onelen) == 0) + /* Found it. */ + return (1); + + /* Slide to the next sub-string. */ + l = strlen(compat) + 1; + compat += l; + len -= l; + } + return (0); +} + +int +ofw_bus_is_compatible_strict(device_t dev, const char *compatible) +{ + const char *compat; + + if ((compat = ofw_bus_get_compat(dev)) == NULL) + return (0); + + if (strncasecmp(compat, compatible, strlen(compatible)) == 0) + return (1); + + return (0); +} + +#ifndef FDT void ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz) { @@ -262,3 +310,4 @@ ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz, } return (0); } +#endif /* !FDT */ diff --git a/sys/dev/ofw/ofw_bus_subr.h b/sys/dev/ofw/ofw_bus_subr.h index 14bcbc9547e6..1e8376602da2 100644 --- a/sys/dev/ofw/ofw_bus_subr.h +++ b/sys/dev/ofw/ofw_bus_subr.h @@ -67,4 +67,8 @@ int ofw_bus_lookup_imap(phandle_t, struct ofw_bus_iinfo *, void *, int, int ofw_bus_search_intrmap(void *, int, void *, int, void *, int, void *, void *, void *, int); +/* Helper routine for checking compat prop */ +int ofw_bus_is_compatible(device_t, const char *); +int ofw_bus_is_compatible_strict(device_t, const char *); + #endif /* !_DEV_OFW_OFW_BUS_SUBR_H_ */ diff --git a/sys/dev/ofw/ofw_if.m b/sys/dev/ofw/ofw_if.m index 902f071aa40e..d896e00697aa 100644 --- a/sys/dev/ofw/ofw_if.m +++ b/sys/dev/ofw/ofw_if.m @@ -43,7 +43,7 @@ INTERFACE ofw; * @param _cookie A handle to the client interface, generally the OF * callback routine. */ -METHOD void init { +METHOD int init { ofw_t _ofw; void *_cookie; }; diff --git a/sys/dev/ofw/ofw_standard.c b/sys/dev/ofw/ofw_standard.c index e521fa059d34..5845bf380e1b 100644 --- a/sys/dev/ofw/ofw_standard.c +++ b/sys/dev/ofw/ofw_standard.c @@ -70,7 +70,7 @@ __FBSDID("$FreeBSD$"); #include "ofw_if.h" -static void ofw_std_init(ofw_t ofw, void *openfirm); +static int 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); @@ -150,11 +150,12 @@ static int (*openfirmware)(void *); /* Initializer */ -static void +static int ofw_std_init(ofw_t ofw, void *openfirm) { openfirmware = (int (*)(void *))openfirm; + return (0); } /* diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c index 17cda68678aa..414b402fab55 100644 --- a/sys/dev/ofw/openfirm.c +++ b/sys/dev/ofw/openfirm.c @@ -58,6 +58,8 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include "opt_platform.h" + #include <sys/param.h> #include <sys/kernel.h> #include <sys/malloc.h> @@ -110,10 +112,11 @@ OF_install(char *name, int prio) } /* Initializer */ -void +int OF_init(void *cookie) { phandle_t chosen; + int rv; ofw_obj = &ofw_kernel_obj; /* @@ -123,14 +126,16 @@ OF_init(void *cookie) kobj_class_compile_static(ofw_def_impl, &ofw_kernel_kops); kobj_init((kobj_t)ofw_obj, ofw_def_impl); - OFW_INIT(ofw_obj, cookie); + rv = OFW_INIT(ofw_obj, cookie); + + if ((chosen = OF_finddevice("/chosen")) > 0) + if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) + stdout = -1; - if ((chosen = OF_finddevice("/chosen")) == -1) - OF_exit(); - if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) - stdout = -1; + return (rv); } +#ifndef FDT void OF_printf(const char *fmt, ...) { @@ -154,6 +159,7 @@ OF_test(const char *name) return (OFW_TEST(ofw_obj, name)); } +#endif int OF_interpret(const char *cmd, int nreturns, ...) @@ -228,7 +234,7 @@ OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen) } /* - * Resursively search the node and its parent for the given property, working + * Recursively search the node and its parent for the given property, working * downward from the node to the device tree root. Returns the value of the * first match. */ @@ -315,6 +321,7 @@ OF_package_to_path(phandle_t package, char *buf, size_t len) return (OFW_PACKAGE_TO_PATH(ofw_obj, package, buf, len)); } +#ifndef FDT /* Call the method in the scope of a given instance. */ int OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns, @@ -428,3 +435,4 @@ OF_exit() for (;;) /* just in case */ ; } +#endif diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h index 10e8aad80acd..fc692defd447 100644 --- a/sys/dev/ofw/openfirm.h +++ b/sys/dev/ofw/openfirm.h @@ -83,7 +83,7 @@ MALLOC_DECLARE(M_OFWPROP); */ boolean_t OF_install(char *name, int prio); -void OF_init(void *cookie); +int OF_init(void *cookie); /* * Known Open Firmware interface names |
