summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2020-10-30 13:07:48 +0000
committerkettenis <kettenis@openbsd.org>2020-10-30 13:07:48 +0000
commitfe6512f2e4b2fa62a9f3deb268765ae07e2c5e67 (patch)
treea98a964f355dfa4b859f32f11bb8453c3c2b9eb7
parentWhitespace fixes. (diff)
downloadwireguard-openbsd-fe6512f2e4b2fa62a9f3deb268765ae07e2c5e67.tar.xz
wireguard-openbsd-fe6512f2e4b2fa62a9f3deb268765ae07e2c5e67.zip
Add code to determine the console devie node.
-rw-r--r--sys/arch/powerpc64/include/fdt.h5
-rw-r--r--sys/arch/powerpc64/powerpc64/machdep.c80
2 files changed, 83 insertions, 2 deletions
diff --git a/sys/arch/powerpc64/include/fdt.h b/sys/arch/powerpc64/include/fdt.h
index 735d00b7835..6cabd58c85a 100644
--- a/sys/arch/powerpc64/include/fdt.h
+++ b/sys/arch/powerpc64/include/fdt.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdt.h,v 1.1 2020/06/07 16:11:34 kettenis Exp $ */
+/* $OpenBSD: fdt.h,v 1.2 2020/10/30 13:07:48 kettenis Exp $ */
/*
* Copyright (c) 2016 Patrick Wildt <patrick@blueri.se>
*
@@ -33,4 +33,7 @@ struct fdt_attach_args {
int fa_scells;
};
+extern int stdout_node;
+extern int stdout_speed;
+
#endif /* _MACHINE_FDT_H_ */
diff --git a/sys/arch/powerpc64/powerpc64/machdep.c b/sys/arch/powerpc64/powerpc64/machdep.c
index e812d95508a..0e2bfb38c6e 100644
--- a/sys/arch/powerpc64/powerpc64/machdep.c
+++ b/sys/arch/powerpc64/powerpc64/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.62 2020/10/19 18:54:58 kettenis Exp $ */
+/* $OpenBSD: machdep.c,v 1.63 2020/10/30 13:07:48 kettenis Exp $ */
/*
* Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
@@ -41,6 +41,7 @@
#include <uvm/uvm_extern.h>
#include <dev/ofw/fdt.h>
+#include <dev/ofw/openfirm.h>
#include <dev/cons.h>
#ifdef DDB
@@ -100,6 +101,81 @@ const char *parse_bootduid(const char *);
paddr_t fdt_pa;
size_t fdt_size;
+int stdout_node;
+int stdout_speed;
+
+static int
+atoi(const char *s)
+{
+ int n, neg;
+
+ n = 0;
+ neg = 0;
+
+ while (*s == '-') {
+ s++;
+ neg = !neg;
+ }
+
+ while (*s != '\0') {
+ if (*s < '0' || *s > '9')
+ break;
+
+ n = (10 * n) + (*s - '0');
+ s++;
+ }
+
+ return (neg ? -n : n);
+}
+
+void *
+fdt_find_cons(void)
+{
+ char *alias = "serial0";
+ char buf[128];
+ char *stdout = NULL;
+ char *p;
+ void *node;
+
+ /* First check if "stdout-path" is set. */
+ node = fdt_find_node("/chosen");
+ if (node) {
+ if (fdt_node_property(node, "stdout-path", &stdout) > 0) {
+ if (strchr(stdout, ':') != NULL) {
+ strlcpy(buf, stdout, sizeof(buf));
+ if ((p = strchr(buf, ':')) != NULL) {
+ *p++ = '\0';
+ stdout_speed = atoi(p);
+ }
+ stdout = buf;
+ }
+ if (stdout[0] != '/') {
+ /* It's an alias. */
+ alias = stdout;
+ stdout = NULL;
+ }
+ }
+ }
+
+ /* Perform alias lookup if necessary. */
+ if (stdout == NULL) {
+ node = fdt_find_node("/aliases");
+ if (node)
+ fdt_node_property(node, alias, &stdout);
+ }
+
+ /* Lookup the physical address of the interface. */
+ if (stdout) {
+ node = fdt_find_node(stdout);
+ if (node) {
+ stdout_node = OF_finddevice(stdout);
+ return (node);
+ }
+ }
+
+ return (NULL);
+}
+
void
init_powernv(void *fdt, void *tocbase)
{
@@ -152,6 +228,8 @@ init_powernv(void *fdt, void *tocbase)
fdt_pa = (paddr_t)fdt;
fdt_size = fdt_get_size(fdt);
+ fdt_find_cons();
+
/*
* Initialize all traps with the stub that calls the generic
* trap handler.