Module Name: src
Committed By: jmcneill
Date: Fri Apr 21 23:35:01 UTC 2017
Modified Files:
src/sys/dev/fdt: fdt_subr.c fdtvar.h
Log Message:
Add some helpers to find the stdout device.
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/fdt/fdt_subr.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/fdtvar.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/fdt/fdt_subr.c
diff -u src/sys/dev/fdt/fdt_subr.c:1.7 src/sys/dev/fdt/fdt_subr.c:1.8
--- src/sys/dev/fdt/fdt_subr.c:1.7 Fri Apr 21 21:08:57 2017
+++ src/sys/dev/fdt/fdt_subr.c Fri Apr 21 23:35:01 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_subr.c,v 1.7 2017/04/21 21:08:57 jmcneill Exp $ */
+/* $NetBSD: fdt_subr.c,v 1.8 2017/04/21 23:35:01 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.7 2017/04/21 21:08:57 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.8 2017/04/21 23:35:01 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -216,3 +216,55 @@ fdtbus_get_reg(int phandle, u_int index,
return 0;
}
+
+const char *
+fdtbus_get_stdout_path(void)
+{
+ const int off = fdt_path_offset(fdtbus_get_data(), "/chosen");
+ if (off < 0)
+ return NULL;
+
+ return fdt_getprop(fdtbus_get_data(), off, "stdout-path", NULL);
+}
+
+int
+fdtbus_get_stdout_phandle(void)
+{
+ const char *prop, *p;
+ int off, len;
+
+ prop = fdtbus_get_stdout_path();
+ if (prop == NULL)
+ return -1;
+
+ p = strchr(prop, ':');
+ len = p == NULL ? strlen(prop) : (p - prop);
+ if (*prop != '/') {
+ /* Alias */
+ prop = fdt_get_alias_namelen(fdtbus_get_data(), prop, len);
+ if (prop == NULL)
+ return -1;
+ len = strlen(prop);
+ }
+ off = fdt_path_offset_namelen(fdtbus_get_data(), prop, len);
+ if (off < 0)
+ return -1;
+
+ return fdtbus_offset2phandle(off);
+}
+
+int
+fdtbus_get_stdout_speed(void)
+{
+ const char *prop, *p;
+
+ prop = fdtbus_get_stdout_path();
+ if (prop == NULL)
+ return -1;
+
+ p = strchr(prop, ':');
+ if (p == NULL)
+ return -1;
+
+ return (int)strtoul(p + 1, NULL, 10);
+}
Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.9 src/sys/dev/fdt/fdtvar.h:1.10
--- src/sys/dev/fdt/fdtvar.h:1.9 Sun Apr 16 12:24:57 2017
+++ src/sys/dev/fdt/fdtvar.h Fri Apr 21 23:35:01 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.9 2017/04/16 12:24:57 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.10 2017/04/21 23:35:01 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -165,4 +165,8 @@ int fdtbus_phandle2offset(int);
int fdtbus_offset2phandle(int);
bool fdtbus_get_path(int, char *, size_t);
+const char * fdtbus_get_stdout_path(void);
+int fdtbus_get_stdout_phandle(void);
+int fdtbus_get_stdout_speed(void);
+
#endif /* _DEV_FDT_FDTVAR_H */