Add some helpers to find the stdout device.

This commit is contained in:
jmcneill 2017-04-21 23:35:01 +00:00
parent dec46a9666
commit d343fa5477
2 changed files with 59 additions and 3 deletions

View File

@ -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>
@ -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, bus_addr_t *paddr, bus_size_t *psize)
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);
}

View File

@ -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>
@ -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 */