Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/fdt Add some helpers to find the stdout device.
details: https://anonhg.NetBSD.org/src/rev/031da7208b21
branches: trunk
changeset: 353152:031da7208b21
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Fri Apr 21 23:35:01 2017 +0000
description:
Add some helpers to find the stdout device.
diffstat:
sys/dev/fdt/fdt_subr.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-
sys/dev/fdt/fdtvar.h | 6 ++++-
2 files changed, 59 insertions(+), 3 deletions(-)
diffs (92 lines):
diff -r 59939afef8b4 -r 031da7208b21 sys/dev/fdt/fdt_subr.c
--- a/sys/dev/fdt/fdt_subr.c Fri Apr 21 23:07:45 2017 +0000
+++ b/sys/dev/fdt/fdt_subr.c Fri Apr 21 23:35:01 2017 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
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);
+}
diff -r 59939afef8b4 -r 031da7208b21 sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h Fri Apr 21 23:07:45 2017 +0000
+++ b/sys/dev/fdt/fdtvar.h Fri Apr 21 23:35:01 2017 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -165,4 +165,8 @@
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 */
Home |
Main Index |
Thread Index |
Old Index