summaryrefslogtreecommitdiffstats
path: root/sys/dev/ofw/openfirm.c
diff options
context:
space:
mode:
authortmm <tmm@FreeBSD.org>2001-11-18 20:38:44 +0000
committertmm <tmm@FreeBSD.org>2001-11-18 20:38:44 +0000
commitf90b466a8546d0524d6a6e155053dd4a402050e0 (patch)
treef5fd72ad640b097477c78af41a09eb2e4caedfac /sys/dev/ofw/openfirm.c
parentc0b2cd0d3f0925c5e36e196283d850dbb4c006f1 (diff)
downloadFreeBSD-src-f90b466a8546d0524d6a6e155053dd4a402050e0.zip
FreeBSD-src-f90b466a8546d0524d6a6e155053dd4a402050e0.tar.gz
1. Add ofw_pci.h with definitions for the OpenFirmware PCI bindings
2. Add OF_getprop_alloc(), a helper function that will malloc() a sufficient amount of memory and then retrieve a property value into it. Approved by: benno Obtained from: NetBSD (1)
Diffstat (limited to 'sys/dev/ofw/openfirm.c')
-rw-r--r--sys/dev/ofw/openfirm.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c
index 61b6391..7704109 100644
--- a/sys/dev/ofw/openfirm.c
+++ b/sys/dev/ofw/openfirm.c
@@ -58,12 +58,16 @@
*/
#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
#include <sys/systm.h>
#include <machine/stdarg.h>
#include <dev/ofw/openfirm.h>
+MALLOC_DEFINE(M_OFWPROP, "openfirm", "OpenFirmware properties");
+
static ihandle_t stdin;
static ihandle_t stdout;
@@ -286,6 +290,30 @@ OF_getprop(phandle_t package, char *propname, void *buf, int buflen)
return args.size;
}
+/*
+ * Store the value of a property of a package into newly allocated memory (using
+ * the M_OFWPROP malloc pool and M_WAITOK). elsz is the size of a single element,
+ * the number of elements is return in number.
+ */
+int
+OF_getprop_alloc(phandle_t package, char *propname, int elsz, void **buf)
+{
+ int len;
+
+ *buf = NULL;
+ if ((len = OF_getproplen(package, propname)) == -1 ||
+ len % elsz != 0)
+ return (-1);
+
+ *buf = malloc(len, M_OFWPROP, M_WAITOK);
+ if (OF_getprop(package, propname, *buf, len) == -1) {
+ free(*buf, M_OFWPROP);
+ *buf = NULL;
+ return (-1);
+ }
+ return (len / elsz);
+}
+
/* Get the next property of a package. */
int
OF_nextprop(phandle_t package, char *previous, char *buf)
OpenPOWER on IntegriCloud