summaryrefslogtreecommitdiff
path: root/sys/dev/fdt
diff options
context:
space:
mode:
authorskrll <skrll@NetBSD.org>2023-04-07 08:55:29 +0000
committerskrll <skrll@NetBSD.org>2023-04-07 08:55:29 +0000
commit2e4048e4471cb61dc77d61e87ddf3b8d77033211 (patch)
tree9f93439ee7bc5219bf390cae6fc0bd649eca82a7 /sys/dev/fdt
parentd7c33465044ebcab16a4df619acfa7e109b8996a (diff)
Rename ARM_PLATFORM to FDT_PLATFORM and make it available outside arm.
Diffstat (limited to 'sys/dev/fdt')
-rw-r--r--sys/dev/fdt/fdt_platform.c83
-rw-r--r--sys/dev/fdt/fdtvar.h40
-rw-r--r--sys/dev/fdt/files.fdt3
3 files changed, 124 insertions, 2 deletions
diff --git a/sys/dev/fdt/fdt_platform.c b/sys/dev/fdt/fdt_platform.c
new file mode 100644
index 00000000000..3ef07cc7c73
--- /dev/null
+++ b/sys/dev/fdt/fdt_platform.c
@@ -0,0 +1,83 @@
+/* $NetBSD: fdt_platform.c,v 1.1 2023/04/07 08:55:31 skrll Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared D. McNeill <jmcneill@invisible.ca>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: fdt_platform.c,v 1.1 2023/04/07 08:55:31 skrll Exp $");
+
+#include <sys/param.h>
+
+#include <dev/ofw/openfirm.h>
+
+#include <dev/fdt/fdtvar.h>
+
+const struct fdt_platform *
+fdt_platform_find(void)
+{
+ static const struct fdt_platform_info *booted_platform = NULL;
+ __link_set_decl(fdt_platforms, struct fdt_platform_info);
+ struct fdt_platform_info * const *info;
+
+ if (booted_platform == NULL) {
+ const struct fdt_platform_info *best_info = NULL;
+ const int phandle = OF_peer(0);
+ int match, best_match = 0;
+
+ __link_set_foreach(info, fdt_platforms) {
+ const struct device_compatible_entry compat_data[] = {
+ { .compat = (*info)->fpi_compat },
+ DEVICE_COMPAT_EOL
+ };
+
+ match = of_compatible_match(phandle, compat_data);
+ if (match > best_match) {
+ best_match = match;
+ best_info = *info;
+ }
+ }
+
+ booted_platform = best_info;
+ }
+
+ /*
+ * No SoC specific platform was found. Try to find a generic
+ * platform definition and use that if available.
+ */
+ if (booted_platform == NULL) {
+ __link_set_foreach(info, fdt_platforms) {
+ if (strcmp((*info)->fpi_compat, FDT_PLATFORM_DEFAULT) == 0) {
+ booted_platform = *info;
+ break;
+ }
+ }
+ }
+
+ return booted_platform == NULL ? NULL : booted_platform->fpi_ops;
+}
+
+// XXXNH remove this and rely on a default
+FDT_PLATFORM(dummy, NULL, NULL);
diff --git a/sys/dev/fdt/fdtvar.h b/sys/dev/fdt/fdtvar.h
index d9a1395d31c..13f2486b43e 100644
--- a/sys/dev/fdt/fdtvar.h
+++ b/sys/dev/fdt/fdtvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.77 2022/03/04 08:19:06 skrll Exp $ */
+/* $NetBSD: fdtvar.h,v 1.78 2023/04/07 08:55:31 skrll Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@@ -306,6 +306,44 @@ _FDT_OPP_REGISTER(_name)
TAILQ_HEAD(fdt_conslist, fdt_console_info);
+/*
+ * Platform-specific data
+ */
+
+struct fdt_platform {
+ const struct pmap_devmap *
+ (*fp_devmap)(void);
+ void (*fp_bootstrap)(void);
+ int (*fp_mpstart)(void);
+ void (*fp_startup)(void);
+ void (*fp_init_attach_args)(struct fdt_attach_args *);
+ void (*fp_device_register)(device_t, void *);
+ void (*fp_reset)(void);
+ void (*fp_delay)(u_int);
+ u_int (*fp_uart_freq)(void);
+};
+
+struct fdt_platform_info {
+ const char * fpi_compat;
+ const struct fdt_platform * fpi_ops;
+};
+
+#define FDT_PLATFORM_DEFAULT ""
+
+#define _FDT_PLATFORM_REGISTER(name) \
+ __link_set_add_rodata(fdt_platforms, __CONCAT(name,_platinfo));
+
+#define FDT_PLATFORM(_name, _compat, _ops) \
+static const struct fdt_platform_info __CONCAT(_name,_platinfo) = { \
+ .fpi_compat = (_compat), \
+ .fpi_ops = (_ops) \
+}; \
+_FDT_PLATFORM_REGISTER(_name)
+
+const struct fdt_platform *
+ fdt_platform_find(void);
+
+
struct fdt_dma_range {
paddr_t dr_sysbase;
bus_addr_t dr_busbase;
diff --git a/sys/dev/fdt/files.fdt b/sys/dev/fdt/files.fdt
index 1833b67fef7..038e6880f2b 100644
--- a/sys/dev/fdt/files.fdt
+++ b/sys/dev/fdt/files.fdt
@@ -1,4 +1,4 @@
-# $NetBSD: files.fdt,v 1.66 2022/11/05 17:31:37 jmcneill Exp $
+# $NetBSD: files.fdt,v 1.67 2023/04/07 08:55:31 skrll Exp $
include "external/bsd/libfdt/conf/files.libfdt"
@@ -68,6 +68,7 @@ file dev/fdt/i2cmux_fdt.c iicmux_fdt
file dev/fdt/fdt_memory.c fdtbase
file dev/fdt/fdt_openfirm.c fdtbase
+file dev/fdt/fdt_platform.c fdtbase
file dev/fdt/fdt_subr.c fdtbase
file dev/fdt/fdt_clock.c fdt