summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2009-09-02 20:29:40 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2009-09-02 20:29:40 +0000
commit9a9c6a0e31cb1dd4854cbdf003ccb1df66262c9d (patch)
tree464f6edaecf4b4611275208289ca610e0c4e9a6d
parent7180b922aa0c73edb7ed27f42c3510d0cc8db325 (diff)
Attach devices to mainbus(4) based on information from the flattened device
tree.
-rw-r--r--sys/arch/socppc/dev/obio.c15
-rw-r--r--sys/arch/socppc/include/autoconf.h4
-rw-r--r--sys/arch/socppc/socppc/cpu.c17
-rw-r--r--sys/arch/socppc/socppc/mainbus.c73
4 files changed, 78 insertions, 31 deletions
diff --git a/sys/arch/socppc/dev/obio.c b/sys/arch/socppc/dev/obio.c
index 1081e854ce0..78f0820e21c 100644
--- a/sys/arch/socppc/dev/obio.c
+++ b/sys/arch/socppc/dev/obio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: obio.c,v 1.3 2008/05/25 16:23:58 kettenis Exp $ */
+/* $OpenBSD: obio.c,v 1.4 2009/09/02 20:29:39 kettenis Exp $ */
/*
* Copyright (c) 2008 Mark Kettenis
@@ -22,6 +22,8 @@
#include <machine/autoconf.h>
+#include <dev/ofw/openfirm.h>
+
int obio_match(struct device *, void *, void *);
void obio_attach(struct device *, struct device *, void *);
@@ -39,7 +41,16 @@ int obio_print(void *, const char *);
int
obio_match(struct device *parent, void *cfdata, void *aux)
{
- return (1);
+ struct mainbus_attach_args *ma = aux;
+ char buf[32];
+
+ if (OF_getprop(ma->ma_node, "device_type", buf, sizeof(buf)) <= 0)
+ return (0);
+
+ if (strcmp(buf, "soc") == 0)
+ return (1);
+
+ return (0);
}
void
diff --git a/sys/arch/socppc/include/autoconf.h b/sys/arch/socppc/include/autoconf.h
index 05806bd55a1..ec4a12f85cb 100644
--- a/sys/arch/socppc/include/autoconf.h
+++ b/sys/arch/socppc/include/autoconf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: autoconf.h,v 1.3 2008/05/25 16:23:58 kettenis Exp $ */
+/* $OpenBSD: autoconf.h,v 1.4 2009/09/02 20:29:39 kettenis Exp $ */
/*
* Copyright (c) 2008 Mark Kettenis
@@ -25,6 +25,7 @@ struct mainbus_attach_args {
bus_space_tag_t ma_iot;
bus_dma_tag_t ma_dmat;
char *ma_name;
+ int ma_node;
};
struct obio_attach_args {
@@ -34,6 +35,7 @@ struct obio_attach_args {
int oa_ivec;
int oa_phy;
char *oa_name;
+ int oa_node;
};
#define cf_offset cf_loc[0]
diff --git a/sys/arch/socppc/socppc/cpu.c b/sys/arch/socppc/socppc/cpu.c
index 870f7d6367e..ac91f928052 100644
--- a/sys/arch/socppc/socppc/cpu.c
+++ b/sys/arch/socppc/socppc/cpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.3 2009/08/27 20:42:02 miod Exp $ */
+/* $OpenBSD: cpu.c,v 1.4 2009/09/02 20:29:39 kettenis Exp $ */
/*
* Copyright (c) 2008 Mark Kettenis
@@ -20,6 +20,10 @@
#include <sys/systm.h>
#include <sys/device.h>
+#include <machine/autoconf.h>
+
+#include <dev/ofw/openfirm.h>
+
#define HID0_DOZE (1 << (31-8))
#define HID0_NAP (1 << (31-9))
#define HID0_SLEEP (1 << (31-10))
@@ -51,7 +55,16 @@ struct cfdriver cpu_cd = {
int
cpu_match(struct device *parent, void *cfdata, void *aux)
{
- return (1);
+ struct mainbus_attach_args *ma = aux;
+ char buf[32];
+
+ if (OF_getprop(ma->ma_node, "device_type", buf, sizeof(buf)) <= 0)
+ return (0);
+
+ if (strcmp(buf, "cpu") == 0)
+ return (1);
+
+ return (0);
}
void
diff --git a/sys/arch/socppc/socppc/mainbus.c b/sys/arch/socppc/socppc/mainbus.c
index 8e5aa8cbb83..0d0decfd081 100644
--- a/sys/arch/socppc/socppc/mainbus.c
+++ b/sys/arch/socppc/socppc/mainbus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mainbus.c,v 1.3 2008/05/17 15:49:05 kettenis Exp $ */
+/* $OpenBSD: mainbus.c,v 1.4 2009/09/02 20:29:39 kettenis Exp $ */
/*
* Copyright (c) 2008 Mark Kettenis
@@ -22,6 +22,8 @@
#include <machine/autoconf.h>
+#include <dev/ofw/openfirm.h>
+
int mainbus_match(struct device *, void *, void *);
void mainbus_attach(struct device *, struct device *, void *);
@@ -33,23 +35,6 @@ struct cfdriver mainbus_cd = {
NULL, "mainbus", DV_DULL
};
-int mainbus_search(struct device *, void *, void *);
-int mainbus_print(void *, const char *);
-
-int
-mainbus_match(struct device *parent, void *cfdata, void *aux)
-{
- return (1);
-}
-
-void
-mainbus_attach(struct device *parent, struct device *self, void *aux)
-{
- printf("\n");
-
- config_search(mainbus_search, self, self);
-}
-
struct ppc_bus_space mainbus_bus_space = { 0xff400000, 0x00100000, 0 };
struct powerpc_bus_dma_tag mainbus_bus_dma_tag = {
@@ -69,18 +54,54 @@ struct powerpc_bus_dma_tag mainbus_bus_dma_tag = {
_dmamem_mmap
};
+int mainbus_print(void *, const char *);
+
int
-mainbus_search(struct device *parent, void *cfdata, void *aux)
+mainbus_match(struct device *parent, void *cfdata, void *aux)
+{
+ return (1);
+}
+
+void
+mainbus_attach(struct device *parent, struct device *self, void *aux)
{
struct mainbus_attach_args ma;
- struct cfdata *cf = cfdata;
+ char name[32];
+ int node;
- ma.ma_iot = &mainbus_bus_space;
- ma.ma_dmat = &mainbus_bus_dma_tag;
- ma.ma_name = cf->cf_driver->cd_name;
- config_found(parent, &ma, mainbus_print);
+ printf("\n");
- return (1);
+ node = OF_finddevice("/cpus");
+ if (node != -1) {
+ for (node = OF_child(node); node != 0; node = OF_peer(node)) {
+ if (OF_getprop(node, "name", name, sizeof(name)) <= 0)
+ continue;
+
+ bzero(&ma, sizeof(ma));
+ ma.ma_name = name;
+ ma.ma_node = node;
+ config_found(self, &ma, mainbus_print);
+ ncpusfound++;
+ }
+ }
+
+ for (node = OF_child(OF_peer(0)); node != 0; node = OF_peer(node)) {
+ if (OF_getprop(node, "name", name, sizeof(name)) <= 0)
+ continue;
+
+ if (strcmp(name, "aliases") == 0 ||
+ strcmp(name, "chosen") == 0 ||
+ strcmp(name, "cpus") == 0 ||
+ strcmp(name, "memory") == 0)
+ continue;
+
+ bzero(&ma, sizeof(ma));
+ ma.ma_iot = &mainbus_bus_space;
+ ma.ma_dmat = &mainbus_bus_dma_tag;
+ ma.ma_name = name;
+ ma.ma_node = node;
+ config_found(self, &ma, mainbus_print);
+ }
}
int
@@ -89,7 +110,7 @@ mainbus_print(void *aux, const char *name)
struct mainbus_attach_args *ma = aux;
if (name)
- printf("%s at %s", ma->ma_name, name);
+ printf("\"%s\" at %s", ma->ma_name, name);
return (UNCONF);
}