63#include "opt_platform.h"
66#include <sys/kernel.h>
68#include <sys/malloc.h>
72#include <sys/endian.h>
74#include <machine/stdarg.h>
100static struct mtx xreflist_lock;
101static boolean_t xref_init_done;
103#define FIND_BY_XREF 0
104#define FIND_BY_NODE 1
130 xrefinfo_create(
child);
134 "linux,phandle", &
xref,
sizeof(
xref)) == -1)
136 xi = malloc(
sizeof(*xi), M_OFWPROP, M_WAITOK | M_ZERO);
139 SLIST_INSERT_HEAD(&xreflist, xi, next_entry);
152 mtx_init(&xreflist_lock,
"OF xreflist lock", NULL, MTX_DEF);
154 xref_init_done =
true;
164 mtx_lock(&xreflist_lock);
165 SLIST_FOREACH(xi, &xreflist, next_entry) {
173 mtx_unlock(&xreflist_lock);
182 xi = malloc(
sizeof(*xi), M_OFWPROP, M_WAITOK);
186 mtx_lock(&xreflist_lock);
187 SLIST_INSERT_HEAD(&xreflist, xi, next_entry);
188 mtx_unlock(&xreflist_lock);
202 static int curr_prio = 0;
213 SET_FOREACH(ofwpp, ofw_set) {
217 !strcmp(ofwp->name, name) &&
246 rv = OFW_INIT(
ofw_obj, cookie);
276 (void)kvprintf(fmt,
OF_putchar, NULL, 10, va);
292 return (OFW_TEST(
ofw_obj, name));
306 status = OFW_INTERPRET(
ofw_obj, cmd, nreturns, slots);
310 va_start(ap, nreturns);
312 *va_arg(ap, cell_t *) = slots[i++];
363 return (OFW_INSTANCE_TO_PACKAGE(
ofw_obj, instance));
374 return (OFW_GETPROPLEN(
ofw_obj, package, propname));
393 return (OFW_GETPROP(
ofw_obj, package, propname, buf, buflen));
402 KASSERT(len % 4 == 0, (
"Need a multiple of 4 bytes"));
408 for (i = 0; i < len/4; i++)
409 buf[i] = be32toh(buf[i]);
455 *buf = malloc(len, M_OFWPROP, M_WAITOK);
456 if (
OF_getprop(package, propname, *buf, len) == -1) {
457 free(*buf, M_OFWPROP);
481 *buf = malloc(len, M_OFWPROP, M_WAITOK);
482 if (
OF_getprop(package, propname, *buf, len) == -1) {
483 free(*buf, M_OFWPROP);
501 return (ret *
sizeof(
pcell_t));
517 for (i = 0; i < retval * elsz / 4; i++)
518 cell[i] = be32toh(cell[i]);
527 free(buf, M_OFWPROP);
538 return (OFW_NEXTPROP(
ofw_obj, package, previous, buf,
size));
549 return (OFW_SETPROP(
ofw_obj, package, propname, buf,len));
560 return (OFW_CANON(
ofw_obj, device, buf, len));
571 return (OFW_FINDDEVICE(
ofw_obj, device));
582 return (OFW_INSTANCE_TO_PATH(
ofw_obj, instance, buf, len));
593 return (OFW_PACKAGE_TO_PATH(
ofw_obj, package, buf, len));
616 "linux,phandle", &rxref,
sizeof(rxref)) == -1)
632 if (xref_init_done) {
649 if (xref_init_done) {
667 if (xref_init_done) {
672 panic(
"Attempt to find device before xreflist_init");
680 if (xref_init_done) {
685 panic(
"Attempt to find xref before xreflist_init");
699 if (xref_init_done) {
706 panic(
"Attempt to register device before xreflist_init");
715 cell_t args_n_results[12];
720 va_start(ap, nreturns);
721 for (n = 0; n < nargs; n++)
722 args_n_results[n] = va_arg(ap, cell_t);
724 status = OFW_CALL_METHOD(
ofw_obj, instance, method, nargs, nreturns,
729 for (; n < nargs + nreturns; n++)
730 *va_arg(ap, cell_t *) = args_n_results[n];
747 return (OFW_OPEN(
ofw_obj, device));
769 return (OFW_READ(
ofw_obj, instance, addr, len));
780 return (OFW_WRITE(
ofw_obj, instance, addr, len));
791 return (OFW_SEEK(
ofw_obj, instance, pos));
841 panic(
"OF_exit: Open Firmware not available");
METHOD phandle_t parent
Return parent of node.
METHOD phandle_t child
Return first child of node.
struct kobj_class ofw_def_t
ssize_t OF_getencprop_alloc(phandle_t package, const char *name, void **buf)
static struct ofw_kobj ofw_kernel_obj
static phandle_t OF_child_xref_phandle(phandle_t parent, phandle_t xref)
ssize_t OF_getencprop_alloc_multi(phandle_t package, const char *name, int elsz, void **buf)
ssize_t OF_read(ihandle_t instance, void *addr, size_t len)
phandle_t OF_node_from_xref(phandle_t xref)
ihandle_t OF_open(const char *device)
SET_DECLARE(ofw_set, ofw_def_t)
int OF_test(const char *name)
ssize_t OF_searchencprop(phandle_t node, const char *propname, pcell_t *buf, size_t len)
phandle_t OF_peer(phandle_t node)
ssize_t OF_searchprop(phandle_t node, const char *propname, void *buf, size_t len)
phandle_t OF_xref_from_node(phandle_t node)
static void xrefinfo_init(void *unsed)
static void OF_putchar(int c, void *arg)
static ofw_def_t * ofw_def_impl
boolean_t OF_install(char *name, int prio)
phandle_t OF_finddevice(const char *device)
ssize_t OF_getproplen(phandle_t package, const char *propname)
void OF_close(ihandle_t instance)
static struct kobj_ops ofw_kernel_kops
int OF_nextprop(phandle_t package, const char *previous, char *buf, size_t size)
int OF_interpret(const char *cmd, int nreturns,...)
ssize_t OF_canon(const char *device, char *buf, size_t len)
void * OF_claim(void *virt, size_t size, u_int align)
ssize_t OF_instance_to_path(ihandle_t instance, char *buf, size_t len)
ssize_t OF_package_to_path(phandle_t package, char *buf, size_t len)
int OF_seek(ihandle_t instance, uint64_t pos)
device_t OF_device_from_xref(phandle_t xref)
int OF_setprop(phandle_t package, const char *propname, const void *buf, size_t len)
void OF_printf(const char *fmt,...)
void OF_release(void *virt, size_t size)
phandle_t OF_parent(phandle_t node)
ssize_t OF_getencprop(phandle_t node, const char *propname, pcell_t *buf, size_t len)
int OF_init(void *cookie)
int OF_hasprop(phandle_t package, const char *propname)
static struct xrefinfo * xrefinfo_find(uintptr_t key, int find_by)
ssize_t OF_write(ihandle_t instance, const void *addr, size_t len)
static struct xrefinfo * xrefinfo_add(phandle_t node, phandle_t xref, device_t dev)
static SLIST_HEAD(xrefinfo)
phandle_t OF_instance_to_package(ihandle_t instance)
ssize_t OF_getprop_alloc_multi(phandle_t package, const char *propname, int elsz, void **buf)
ssize_t OF_getprop_alloc(phandle_t package, const char *propname, void **buf)
phandle_t OF_child(phandle_t node)
SYSINIT(xrefinfo, SI_SUB_KMEM, SI_ORDER_ANY, xrefinfo_init, NULL)
phandle_t OF_xref_from_device(device_t dev)
void OF_prop_free(void *buf)
int OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns,...)
ssize_t OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen)
MALLOC_DEFINE(M_OFWPROP, "openfirm", "Open Firmware properties")
int OF_device_register_xref(phandle_t xref, device_t dev)