diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2016-06-12 12:55:43 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2016-06-12 12:55:43 +0000 |
commit | 494023bbc011eaf34cb9b91f8c8ff2420c7eb7ee (patch) | |
tree | f04deec1f655b7bc286a917320b3e7fd84ab68be | |
parent | 35f094a40d2d7a67758b27cb7e47044c49bd9605 (diff) |
Add OF_getpropint() and OF_getpropintarray().
ok visa@, jsg@
-rw-r--r-- | sys/dev/ofw/fdt.c | 31 | ||||
-rw-r--r-- | sys/dev/ofw/openfirm.h | 4 |
2 files changed, 33 insertions, 2 deletions
diff --git a/sys/dev/ofw/fdt.c b/sys/dev/ofw/fdt.c index 73c997f36a8..2aa28d41278 100644 --- a/sys/dev/ofw/fdt.c +++ b/sys/dev/ofw/fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdt.c,v 1.11 2016/06/08 15:27:05 jsg Exp $ */ +/* $OpenBSD: fdt.c,v 1.12 2016/06/12 12:55:42 kettenis Exp $ */ /* * Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net> @@ -793,6 +793,35 @@ OF_getprop(int handle, char *prop, void *buf, int buflen) return len; } +uint32_t +OF_getpropint(int handle, char *prop, uint32_t defval) +{ + uint32_t val; + int len; + + len = OF_getprop(handle, prop, &val, sizeof(val)); + if (len != sizeof(val)) + return defval; + + return betoh32(val); +} + +int +OF_getpropintarray(int handle, char *prop, uint32_t *buf, int buflen) +{ + int len; + int i; + + len = OF_getprop(handle, prop, buf, buflen); + if (len <0 || (len % sizeof(uint32_t))) + return -1; + + for (i = 0; i < len / sizeof(uint32_t); i++) + buf[i] = betoh32(buf[i]); + + return len; +} + int OF_nextprop(int handle, char *prop, void *nextprop) { diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h index 4b9c3cf0976..4d505deec4c 100644 --- a/sys/dev/ofw/openfirm.h +++ b/sys/dev/ofw/openfirm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: openfirm.h,v 1.11 2016/05/16 21:12:17 kettenis Exp $ */ +/* $OpenBSD: openfirm.h,v 1.12 2016/06/12 12:55:42 kettenis Exp $ */ /* $NetBSD: openfirm.h,v 1.1 1996/09/30 16:35:10 ws Exp $ */ /* @@ -48,6 +48,8 @@ int OF_parent(int phandle); int OF_instance_to_package(int ihandle); int OF_getproplen(int handle, char *prop); int OF_getprop(int handle, char *prop, void *buf, int buflen); +uint32_t OF_getpropint(int handle, char *, uint32_t); +int OF_getpropintarray(int, char *, uint32_t *, int); int OF_setprop(int, char *, const void *, int); int OF_nextprop(int, char *, void *); int OF_finddevice(char *name); |