summaryrefslogtreecommitdiff
path: root/sys/arch/arm/mainbus
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2016-05-02 08:15:56 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2016-05-02 08:15:56 +0000
commite745dff34c8b0de52da4f946c480d9cae831323c (patch)
tree72221689fe098a9caa64a9147f2ae28c7042d034 /sys/arch/arm/mainbus
parent3c702be99add97af0c6607ca0e072c99ebf6ef01 (diff)
Rework mainbus and implement simplebus to be able to span a tree-like
topology based on device tree information. Introduce a common attach args structure to be used for all fdt-capable bus devices. ok jsg@ kettenis@
Diffstat (limited to 'sys/arch/arm/mainbus')
-rw-r--r--sys/arch/arm/mainbus/cpu_mainbus.c4
-rw-r--r--sys/arch/arm/mainbus/mainbus.c194
-rw-r--r--sys/arch/arm/mainbus/mainbus.h66
3 files changed, 146 insertions, 118 deletions
diff --git a/sys/arch/arm/mainbus/cpu_mainbus.c b/sys/arch/arm/mainbus/cpu_mainbus.c
index 63de2094b39..e6726605d70 100644
--- a/sys/arch/arm/mainbus/cpu_mainbus.c
+++ b/sys/arch/arm/mainbus/cpu_mainbus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu_mainbus.c,v 1.1 2004/02/01 05:09:49 drahn Exp $ */
+/* $OpenBSD: cpu_mainbus.c,v 1.2 2016/05/02 08:15:55 patrick Exp $ */
/* $NetBSD: cpu_mainbus.c,v 1.3 2002/01/05 22:41:48 chris Exp $ */
/*
@@ -72,7 +72,7 @@ static void cpu_mainbus_attach (struct device *, struct device *, void *);
static int
cpu_mainbus_match(struct device *parent, void *vcf, void *aux)
{
- struct mainbus_attach_args *ma = aux;
+ union mainbus_attach_args *ma = aux;
struct cfdata *cf = (struct cfdata *)vcf;
return (strcmp(cf->cf_driver->cd_name, ma->ma_name) == 0);
diff --git a/sys/arch/arm/mainbus/mainbus.c b/sys/arch/arm/mainbus/mainbus.c
index 6ad3e8ff755..c42e0dcbdf6 100644
--- a/sys/arch/arm/mainbus/mainbus.c
+++ b/sys/arch/arm/mainbus/mainbus.c
@@ -1,45 +1,18 @@
-/* $OpenBSD: mainbus.c,v 1.7 2013/05/30 16:15:01 deraadt Exp $ */
-/* $NetBSD: mainbus.c,v 1.3 2001/06/13 17:52:43 nathanw Exp $ */
-
+/* $OpenBSD: mainbus.c,v 1.8 2016/05/02 08:15:55 patrick Exp $ */
/*
- * Copyright (c) 1994,1995 Mark Brinicombe.
- * Copyright (c) 1994 Brini.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Brini.
- * 4. The name of the company nor the name of the author may be used to
- * endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * RiscBSD kernel project
+ * Copyright (c) 2016 Patrick Wildt <patrick@blueri.se>
*
- * mainbus.c
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
*
- * mainbus configuration
- *
- * Created : 15/12/94
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/param.h>
@@ -47,78 +20,155 @@
#include <sys/kernel.h>
#include <sys/device.h>
+#include <dev/ofw/openfirm.h>
+
#include <arm/mainbus/mainbus.h>
-/* Prototypes for functions provided */
+int mainbus_match(struct device *, void *, void *);
+void mainbus_attach(struct device *, struct device *, void *);
-int mainbusmatch(struct device *, void *, void *);
-void mainbusattach(struct device *, struct device *, void *);
-int mainbusprint(void *aux, const char *mainbus);
-int mainbussearch(struct device *, void *, void *);
+void mainbus_attach_node(struct device *, int);
-/* attach and device structures for the device */
+int mainbus_legacy_search(struct device *, void *, void *);
+void mainbus_legacy_found(struct device *, char *);
+
+struct mainbus_softc {
+ struct device sc_dev;
+ bus_space_tag_t sc_iot;
+ bus_dma_tag_t sc_dmat;
+};
struct cfattach mainbus_ca = {
- sizeof(struct device), mainbusmatch, mainbusattach
+ sizeof(struct mainbus_softc), mainbus_match, mainbus_attach, NULL,
+ config_activate_children
};
struct cfdriver mainbus_cd = {
NULL, "mainbus", DV_DULL
};
+struct arm32_bus_dma_tag mainbus_dma_tag = {
+ 0,
+ 0,
+ NULL,
+ _bus_dmamap_create,
+ _bus_dmamap_destroy,
+ _bus_dmamap_load,
+ _bus_dmamap_load_mbuf,
+ _bus_dmamap_load_uio,
+ _bus_dmamap_load_raw,
+ _bus_dmamap_unload,
+ _bus_dmamap_sync,
+ _bus_dmamem_alloc,
+ _bus_dmamem_free,
+ _bus_dmamem_map,
+ _bus_dmamem_unmap,
+ _bus_dmamem_mmap,
+};
+
/*
- * int mainbusmatch(struct device *parent, struct cfdata *cf, void *aux)
+ * Mainbus takes care of FDT and non-FDT machines, so we
+ * always attach.
*/
-
int
-mainbusmatch(struct device *parent, void *cf, 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_softc *sc = (struct mainbus_softc *)self;
+ char buffer[128];
+ int node;
+
+ if ((node = OF_peer(0)) == 0) {
+ printf(": no device tree\n");
+ config_search(mainbus_legacy_search, self, aux);
+ return;
+ }
+
+#ifdef CPU_ARMv7
+ extern struct bus_space armv7_bs_tag;
+ sc->sc_iot = &armv7_bs_tag;
+#endif
+ sc->sc_dmat = &mainbus_dma_tag;
+
+ if (OF_getprop(node, "model", buffer, sizeof(buffer)))
+ printf(": %s\n", buffer);
+ else
+ printf(": unknown model\n");
+
+ /* Attach CPU first. */
+ mainbus_legacy_found(self, "cpu");
+
+ /* TODO: Scan for interrupt controllers and attach them first? */
+
+ /* Scan the whole tree. */
+ for (node = OF_child(node);
+ node != 0;
+ node = OF_peer(node))
+ {
+ mainbus_attach_node(self, node);
+ }
+}
+
/*
- * void mainbusattach(struct device *parent, struct device *self, void *aux)
- *
- * probe and attach all children
+ * Look for a driver that wants to be attached to this node.
*/
-
void
-mainbusattach(struct device *parent, struct device *self, void *aux)
+mainbus_attach_node(struct device *self, int node)
{
- printf("\n");
+ struct mainbus_softc *sc = (struct mainbus_softc *)self;
+ struct fdt_attach_args fa;
+ char buffer[128];
+
+ if (!OF_getprop(node, "compatible", buffer, sizeof(buffer)))
+ return;
+
+ if (OF_getprop(node, "status", buffer, sizeof(buffer)))
+ if (!strcmp(buffer, "disabled"))
+ return;
- config_search(mainbussearch, self, aux);
+ memset(&fa, 0, sizeof(fa));
+ fa.fa_name = "";
+ fa.fa_node = node;
+ fa.fa_iot = sc->sc_iot;
+ fa.fa_dmat = sc->sc_dmat;
+
+ /* TODO: attach the device's clocks first? */
+
+ config_found(self, &fa, NULL);
}
+/*
+ * Legacy support for SoCs that do not use FDT.
+ */
int
-mainbussearch(struct device *parent, void *vcf, void *aux)
+mainbus_legacy_search(struct device *parent, void *match, void *aux)
{
- struct mainbus_attach_args ma;
- struct cfdata *cf = vcf;
+ union mainbus_attach_args ma;
+ struct cfdata *cf = match;
+ memset(&ma, 0, sizeof(ma));
ma.ma_name = cf->cf_driver->cd_name;
/* allow for devices to be disabled in UKC */
if ((*cf->cf_attach->ca_match)(parent, cf, &ma) == 0)
return 0;
- config_attach(parent, cf, &ma, mainbusprint);
+ config_attach(parent, cf, &ma, NULL);
return 1;
}
-/*
- * int mainbusprint(void *aux, const char *mainbus)
- *
- * print routine used during config of children
- */
-
-int
-mainbusprint(void *aux, const char *mainbus)
+void
+mainbus_legacy_found(struct device *self, char *name)
{
- struct mainbus_attach_args *ma = aux;
+ union mainbus_attach_args ma;
- if (mainbus != NULL)
- printf("%s at %s", ma->ma_name, mainbus);
+ memset(&ma, 0, sizeof(ma));
+ ma.ma_name = name;
- return (UNCONF);
+ config_found(self, &ma, NULL);
}
diff --git a/sys/arch/arm/mainbus/mainbus.h b/sys/arch/arm/mainbus/mainbus.h
index 3e1799628de..42a4076de34 100644
--- a/sys/arch/arm/mainbus/mainbus.h
+++ b/sys/arch/arm/mainbus/mainbus.h
@@ -1,51 +1,29 @@
-/* $OpenBSD: mainbus.h,v 1.2 2011/09/22 17:45:59 miod Exp $ */
-/* $NetBSD: mainbus.h,v 1.1 2001/02/24 19:38:02 reinoud Exp $ */
-
+/* $OpenBSD: mainbus.h,v 1.3 2016/05/02 08:15:55 patrick Exp $ */
/*
- * Copyright (c) 1994,1995 Mark Brinicombe.
- * Copyright (c) 1994 Brini.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Brini.
- * 4. The name of the company nor the name of the author may be used to
- * endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * RiscBSD kernel project
- *
- * mainbus.h
+ * Copyright (c) 2016 Patrick Wildt <patrick@blueri.se>
*
- * mainbus configuration
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
*
- * Created : 15/12/94
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/*
- * mainbus driver attach arguments
- */
+#ifndef __MAINBUS_H__
+#define __MAINBUS_H__
-struct mainbus_attach_args {
- const char *ma_name;
+#include <arm/fdt.h>
+
+/* Passed as third arg to attach functions. */
+union mainbus_attach_args {
+ const char *ma_name;
+ struct fdt_attach_args ma_faa;
};
+
+#endif /* __MAINBUS_H__ */