Author: raj
Date: Fri May 28 10:43:56 2010
New Revision: 208614
URL: http://svn.freebsd.org/changeset/base/208614

Log:
  Prepare and extend OFW layer for FDT support.
  
  o Let OFW_INIT() and OF_init() return status value.
  
  o Provide helper routines for 'compatible' property handling.
  
  o Only compile OF and OFW code, which is relevant in FDT scenario.
  
  o Other minor cosmetics
  
  Reviewed by:  imp
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/dev/ofw/ofw_bus_subr.c
  head/sys/dev/ofw/ofw_bus_subr.h
  head/sys/dev/ofw/ofw_if.m
  head/sys/dev/ofw/ofw_standard.c
  head/sys/dev/ofw/openfirm.c
  head/sys/dev/ofw/openfirm.h
  head/sys/powerpc/ofw/ofw_real.c

Modified: head/sys/dev/ofw/ofw_bus_subr.c
==============================================================================
--- head/sys/dev/ofw/ofw_bus_subr.c     Fri May 28 10:35:44 2010        
(r208613)
+++ head/sys/dev/ofw/ofw_bus_subr.c     Fri May 28 10:43:56 2010        
(r208614)
@@ -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, devic
        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 i
        }
        return (0);
 }
+#endif /* !FDT */

Modified: head/sys/dev/ofw/ofw_bus_subr.h
==============================================================================
--- head/sys/dev/ofw/ofw_bus_subr.h     Fri May 28 10:35:44 2010        
(r208613)
+++ head/sys/dev/ofw/ofw_bus_subr.h     Fri May 28 10:43:56 2010        
(r208614)
@@ -67,4 +67,8 @@ int   ofw_bus_lookup_imap(phandle_t, struc
 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_ */

Modified: head/sys/dev/ofw/ofw_if.m
==============================================================================
--- head/sys/dev/ofw/ofw_if.m   Fri May 28 10:35:44 2010        (r208613)
+++ head/sys/dev/ofw/ofw_if.m   Fri May 28 10:43:56 2010        (r208614)
@@ -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;
 };

Modified: head/sys/dev/ofw/ofw_standard.c
==============================================================================
--- head/sys/dev/ofw/ofw_standard.c     Fri May 28 10:35:44 2010        
(r208613)
+++ head/sys/dev/ofw/ofw_standard.c     Fri May 28 10:43:56 2010        
(r208614)
@@ -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);
 }
 
 /*

Modified: head/sys/dev/ofw/openfirm.c
==============================================================================
--- head/sys/dev/ofw/openfirm.c Fri May 28 10:35:44 2010        (r208613)
+++ head/sys/dev/ofw/openfirm.c Fri May 28 10:43:56 2010        (r208614)
@@ -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
 }
 
 /*
- * 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, ch
        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

Modified: head/sys/dev/ofw/openfirm.h
==============================================================================
--- head/sys/dev/ofw/openfirm.h Fri May 28 10:35:44 2010        (r208613)
+++ head/sys/dev/ofw/openfirm.h Fri May 28 10:43:56 2010        (r208614)
@@ -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

Modified: head/sys/powerpc/ofw/ofw_real.c
==============================================================================
--- head/sys/powerpc/ofw/ofw_real.c     Fri May 28 10:35:44 2010        
(r208613)
+++ head/sys/powerpc/ofw/ofw_real.c     Fri May 28 10:43:56 2010        
(r208614)
@@ -76,7 +76,7 @@ __FBSDID("$FreeBSD$");
 #include <dev/ofw/ofwvar.h>
 #include "ofw_if.h"
 
-static void ofw_real_init(ofw_t, void *openfirm);
+static int ofw_real_init(ofw_t, void *openfirm);
 static int ofw_real_test(ofw_t, const char *name);
 static phandle_t ofw_real_peer(ofw_t, phandle_t node);
 static phandle_t ofw_real_child(ofw_t, phandle_t node);
@@ -256,13 +256,14 @@ ofw_real_unmap(cell_t physaddr, void *bu
 
 /* Initialiser */
 
-static void
+static int
 ofw_real_init(ofw_t ofw, void *openfirm)
 {
        openfirmware = (int (*)(void *))openfirm;
 
        mtx_init(&of_bounce_mtx, "OF Bounce Page", MTX_DEF, 0);
        of_bounce_virt = NULL;
+       return (0);
 }
 
 /*
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to