[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XenPPC] [PATCH] detect platform (and non-hypervisor mode)



Signed-off-by: Maria Butrico <butrico@xxxxxxxxxxxxxx>

summary:    detect platform (and non-hypervisor mode).

        Detects the platform from the value of the compatible
        property (from ofd tree).

diff -r a0fa2ce45bae xen/arch/ppc/Makefile
--- a/xen/arch/ppc/Makefile     Mon May 22 11:01:31 2006 -0400
+++ b/xen/arch/ppc/Makefile     Mon May 22 15:53:36 2006 -0400
@@ -8,6 +8,7 @@ obj-y += audit.o
 obj-y += audit.o
 obj-y += bitops.o
 obj-y += boot_of.o
+obj-y += compatible.o
 obj-y += dart.o
 obj-y += dart_u3.o
 obj-y += dart_u4.o
diff -r a0fa2ce45bae xen/arch/ppc/setup.c
--- a/xen/arch/ppc/setup.c      Mon May 22 11:01:31 2006 -0400
+++ b/xen/arch/ppc/setup.c      Mon May 22 15:53:36 2006 -0400
@@ -272,6 +272,9 @@ static void __init __start_xen(multiboot
         debugger_trap_immediate();
 #endif
 
+    extern void init_platform (void);
+    init_platform();
+
     start_of_day();
 
     /* Create initial domain 0. */
diff -r a0fa2ce45bae xen/arch/ppc/compatible.c
--- /dev/null   Thu Jan  1 00:00:00 1970 +0000
+++ b/xen/arch/ppc/compatible.c Mon May 22 15:53:36 2006 -0400
@@ -0,0 +1,104 @@
+#include <xen/config.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/compile.h>
+#include <public/of-devtree.h>
+#include "oftree.h"
+
+#define DEBUG
+#ifdef DEBUG
+#define DBG(fmt...) printk(fmt)
+#else
+#define DBG(fmt...)
+#endif
+
+static void pmac_init(void);
+static void maple_init(void);
+
+enum platform_type { pmac = 1, maple = 2 };
+struct platform {
+    enum platform_type type;
+    char *compat_s;
+    void (*init_func)(void);
+};
+static struct platform platforms[] = {
+    { .type = pmac,  .compat_s = "Power Macintosh", .init_func = pmac_init },
+    { .type = maple, .compat_s = "Momentum,Maple",  .init_func = maple_init  },
+};
+                                                                               
 
+struct global_platform {
+    enum platform_type platform_type;
+    int hv_supported;
+};
+static struct global_platform my_platform;
+
+
+static void pmac_init(void)
+{
+    my_platform.hv_supported = 0;
+}
+
+static void maple_init(void)
+{
+    my_platform.hv_supported = 1;
+}
+
+void init_platform(void)
+{
+    void *oft_p;
+    char compatible_string[256];
+    int compatible_length;
+    char *cmpstr;
+    int used_length;
+
+    memset(&my_platform, 0, sizeof(my_platform));
+
+    oft_p = (void *)oftree;
+    compatible_length = ofd_getprop(oft_p, OFD_ROOT, "compatible",
+                                    compatible_string, 
sizeof(compatible_string));
+    if (compatible_length < 0) {
+        return;
+    }
+
+    // loop over each null terminated piece of the compatible property
+    for (cmpstr = compatible_string, used_length = 0;
+         used_length < compatible_length;
+         cmpstr = &compatible_string[used_length]) {
+        int i;
+        for (i = 0; i < ARRAY_SIZE(platforms); i++) {
+            if (strstr(cmpstr, platforms[i].compat_s)) {
+                DBG("Found platform %s.\n", platforms[i].compat_s);
+                my_platform.platform_type = platforms[i].type;
+                (void) platforms[i].init_func();
+                DBG("%s: platform type=%d  hv=%d\n",
+                    __func__,
+                    my_platform.platform_type,
+                    my_platform.hv_supported);
+
+                return;
+            }
+        }
+        used_length += strlen(cmpstr) + 1;
+    }
+
+    DBG("Warning: %s is not aware of this machine type.  "
+              "Compatible is:\n", __func__);
+    for (used_length = 0; used_length < compatible_length; used_length++) {
+        if (compatible_string[used_length] == '\0' ) {
+            DBG(" NULL ");
+        } else {
+            DBG("%c", compatible_string[used_length]);
+        }
+    }
+    DBG("\n");
+}
+
+int hv_supported(void)
+{
+    return my_platform.hv_supported;
+}
+
+int is_platform_pmac(void)
+{
+    return (my_platform.platform_type == pmac);
+}

_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.