/* Return the next sibling of this node or 0. */ static phandle_t ofw_fdt_peer(ofw_t ofw, phandle_t node) { int depth, offset; if (node == 0) { /* Find root node */ offset = fdt_path_offset(fdtp, "/"); return (fdt_offset_phandle(offset)); } offset = fdt_phandle_offset(node); if (offset < 0) return (0); for (depth = 1, offset = fdt_next_node(fdtp, offset, &depth); offset >= 0; offset = fdt_next_node(fdtp, offset, &depth)) { if (depth < 0) return (0); if (depth == 1) return (fdt_offset_phandle(offset)); } return (0); }
/* Return a package handle for the specified device. */ static phandle_t ofw_fdt_finddevice(ofw_t ofw, const char *device) { int offset; offset = fdt_path_offset(fdtp, device); return (fdt_offset_phandle(offset)); }
/* Return the parent of this node or 0. */ static phandle_t ofw_fdt_parent(ofw_t ofw, phandle_t node) { int offset, paroffset; offset = fdt_phandle_offset(node); if (offset < 0) return (0); paroffset = fdt_parent_offset(fdtp, offset); return (fdt_offset_phandle(paroffset)); }
/* Return the package handle that corresponds to an instance handle. */ static phandle_t ofw_fdt_instance_to_package(ofw_t ofw, ihandle_t instance) { int offset; /* * Note: FDT does not have the notion of instances, but we somewhat * abuse the semantics and let treat as 'instance' the internal * 'phandle' prop, so that ofw I/F consumers have a uniform way of * translation between internal representation (which appear in some * contexts as property values) and effective phandles. */ offset = fdt_node_offset_by_phandle(fdtp, instance); if (offset < 0) return (-1); return (fdt_offset_phandle(offset)); }
/* Return the first child of this node or 0. */ static phandle_t ofw_fdt_child(ofw_t ofw, phandle_t node) { int depth, offset; offset = fdt_phandle_offset(node); if (offset < 0) return (0); for (depth = 0, offset = fdt_next_node(fdtp, offset, &depth); (offset >= 0) && (depth > 0); offset = fdt_next_node(fdtp, offset, &depth)) { if (depth < 0) return (0); if (depth == 1) return (fdt_offset_phandle(offset)); } return (0); }