Esempio n. 1
0
/* 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);
}
Esempio n. 2
0
/* Get the length of a property of a package. */
static ssize_t
ofw_fdt_getproplen(ofw_t ofw, phandle_t package, const char *propname)
{
	const struct fdt_property *prop;
	int offset, len;

	offset = fdt_phandle_offset(package);
	if (offset < 0)
		return (-1);

	len = -1;
	prop = fdt_get_property(fdtp, offset, propname, &len);

	if (prop == NULL && strcmp(propname, "name") == 0) {
		/* Emulate the 'name' property */
		fdt_get_name(fdtp, offset, &len);
		return (len + 1);
	}

	if (prop == NULL && offset == fdt_path_offset(fdtp, "/chosen")) {
		if (strcmp(propname, "fdtbootcpu") == 0)
			return (sizeof(cell_t));
		if (strcmp(propname, "fdtmemreserv") == 0)
			return (sizeof(uint64_t)*2*fdt_num_mem_rsv(fdtp));
	}

	if (prop == NULL)
		return (-1);

	return (len);
}
Esempio n. 3
0
/*
 * Get the next property of a package. Return the actual len of retrieved
 * prop name.
 */
static int
ofw_fdt_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf,
    size_t size)
{
	const struct fdt_property *prop;
	int offset, rv;

	offset = fdt_phandle_offset(package);
	if (offset < 0)
		return (-1);

	if (previous == NULL)
		/* Find the first prop in the node */
		return (fdt_nextprop(offset, buf, size));

	/*
	 * Advance to the previous prop
	 */
	prop = fdt_get_property(fdtp, offset, previous, NULL);
	if (prop == NULL)
		return (-1);

	offset = fdt_pointer_offset(prop);
	rv = fdt_nextprop(offset, buf, size);
	return (rv);
}
Esempio n. 4
0
/* Get the value of a property of a package. */
static ssize_t
ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf,
    size_t buflen)
{
	const void *prop;
	const char *name;
	int len, offset;

	offset = fdt_phandle_offset(package);
	if (offset < 0)
		return (-1);

	if (strcmp(propname, "name") == 0) {
		/* Emulate the 'name' property */
		name = fdt_get_name(fdtp, offset, &len);
		strncpy(buf, name, buflen);
		if (len + 1 > buflen)
			len = buflen;
		return (len + 1);
	}

	prop = fdt_getprop(fdtp, offset, propname, &len);
	if (prop == NULL)
		return (-1);

	if (len > buflen)
		len = buflen;
	bcopy(prop, buf, len);
	return (len);
}
Esempio n. 5
0
/* Set the value of a property of a package. */
static int
ofw_fdt_setprop(ofw_t ofw, phandle_t package, const char *propname,
    const void *buf, size_t len)
{
	int offset;

	offset = fdt_phandle_offset(package);
	if (offset < 0)
		return (-1);

	return (fdt_setprop_inplace(fdtp, offset, propname, buf, len));
}
Esempio n. 6
0
/* 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));
}
Esempio n. 7
0
/* Get the value of a property of a package. */
static ssize_t
ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf,
    size_t buflen)
{
	const void *prop;
	const char *name;
	int len, offset;
	uint32_t cpuid;

	offset = fdt_phandle_offset(package);
	if (offset < 0)
		return (-1);

	prop = fdt_getprop(fdtp, offset, propname, &len);

	if (prop == NULL && strcmp(propname, "name") == 0) {
		/* Emulate the 'name' property */
		name = fdt_get_name(fdtp, offset, &len);
		strncpy(buf, name, buflen);
		if (len + 1 > buflen)
			len = buflen;
		return (len + 1);
	}

	if (prop == NULL && offset == fdt_path_offset(fdtp, "/chosen")) {
		if (strcmp(propname, "fdtbootcpu") == 0) {
			cpuid = cpu_to_fdt32(fdt_boot_cpuid_phys(fdtp));
			len = sizeof(cpuid);
			prop = &cpuid;
		}
		if (strcmp(propname, "fdtmemreserv") == 0) {
			prop = (char *)fdtp + fdt_off_mem_rsvmap(fdtp);
			len = sizeof(uint64_t)*2*fdt_num_mem_rsv(fdtp);
		}
	}

	if (prop == NULL)
		return (-1);

	if (len > buflen)
		len = buflen;
	bcopy(prop, buf, len);
	return (len);
}
Esempio n. 8
0
/*
 * Get the next property of a package. Return values:
 *  -1: package or previous property does not exist
 *   0: no more properties
 *   1: success
 */
static int
ofw_fdt_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf,
    size_t size)
{
	const struct fdt_property *prop;
	const char *name;
	int offset;

	offset = fdt_phandle_offset(package);
	if (offset < 0)
		return (-1);

	/* Find the first prop in the node */
	offset = fdt_first_property_offset(fdtp, offset);
	if (offset < 0)
		return (0); /* No properties */

	if (previous != NULL) {
		while (offset >= 0) {
			prop = fdt_get_property_by_offset(fdtp, offset, NULL);
			if (prop == NULL)
				return (-1); /* Internal error */

			offset = fdt_next_property_offset(fdtp, offset);
			if (offset < 0)
				return (0); /* No more properties */

			/* Check if the last one was the one we wanted */
			name = fdt_string(fdtp, fdt32_to_cpu(prop->nameoff));
			if (strcmp(name, previous) == 0)
				break;
		}
	}

	prop = fdt_get_property_by_offset(fdtp, offset, &offset);
	if (prop == NULL)
		return (-1); /* Internal error */

	strncpy(buf, fdt_string(fdtp, fdt32_to_cpu(prop->nameoff)), size);

	return (1);
}
Esempio n. 9
0
/* 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);
}
Esempio n. 10
0
/* Get the length of a property of a package. */
static ssize_t
ofw_fdt_getproplen(ofw_t ofw, phandle_t package, const char *propname)
{
	const struct fdt_property *prop;
	int offset, len;

	offset = fdt_phandle_offset(package);
	if (offset < 0)
		return (-1);

	if (strcmp(propname, "name") == 0) {
		/* Emulate the 'name' property */
		fdt_get_name(fdtp, offset, &len);
		return (len + 1);
	}

	len = -1;
	prop = fdt_get_property(fdtp, offset, propname, &len);

	return (len);
}