FreeBSD/sys/dev/ofw/ofw_fdt.c
/* Get the value of a property of a package. */
Get the value of a property of a package.
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) {
		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);
}
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 , " " ) == 0 ) { 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 , " " ) ) { if ( strcmp ( propname , " " ) == 0 ) { cpuid = cpu_to_fdt32 ( fdt_boot_cpuid_phys ( fdtp ) ) ; len = sizeof ( cpuid ) ; prop = & cpuid ; } if ( strcmp ( propname , " " ) == 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 ) ; }
Get the value of a property of a package.
Get the value of a property of a package .
/* Emulate the 'name' property */