Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/ofw/ofw_fdt.c
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | |||||
static ofw_def_t ofw_fdt = { | static ofw_def_t ofw_fdt = { | ||||
OFW_FDT, | OFW_FDT, | ||||
ofw_fdt_methods, | ofw_fdt_methods, | ||||
0 | 0 | ||||
}; | }; | ||||
OFW_DEF(ofw_fdt); | OFW_DEF(ofw_fdt); | ||||
#define FDT_FBSDVER_LEN 16 | |||||
#define FDT_MODEL_LEN 80 | |||||
#define FDT_COMPAT_LEN 255 | |||||
static void *fdtp = NULL; | static void *fdtp = NULL; | ||||
static char fdt_model[FDT_MODEL_LEN]; | |||||
static char fdt_compatible[FDT_COMPAT_LEN]; | |||||
static char fdt_fbsd_version[FDT_FBSDVER_LEN]; | |||||
static int | static int | ||||
sysctl_handle_dtb(SYSCTL_HANDLER_ARGS) | sysctl_handle_dtb(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
return (sysctl_handle_opaque(oidp, fdtp, fdt_totalsize(fdtp), req)); | return (sysctl_handle_opaque(oidp, fdtp, fdt_totalsize(fdtp), req)); | ||||
} | } | ||||
static void | static void | ||||
sysctl_register_fdt_oid(void *arg) | sysctl_register_fdt_oid(void *arg) | ||||
{ | { | ||||
/* If there is no FDT registered, skip adding the sysctl */ | /* If there is no FDT registered, skip adding the sysctl */ | ||||
if (fdtp == NULL) | if (fdtp == NULL) | ||||
return; | return; | ||||
SYSCTL_ADD_PROC(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), OID_AUTO, "dtb", | SYSCTL_ADD_PROC(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), OID_AUTO, "dtb", | ||||
CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, | CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, | ||||
sysctl_handle_dtb, "", "Device Tree Blob"); | sysctl_handle_dtb, "", "Device Tree Blob"); | ||||
if (fdt_model[0] != '\0') | |||||
SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), | |||||
OID_AUTO, "model", CTLFLAG_RD, fdt_model, | |||||
FDT_MODEL_LEN, "System board model"); | |||||
if (fdt_compatible[0] != '\0') | |||||
SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), | |||||
OID_AUTO, "compatible", CTLFLAG_RD, fdt_compatible, | |||||
FDT_COMPAT_LEN, "Compatible platforms"); | |||||
if (fdt_fbsd_version[0] != '\0') | |||||
SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), | |||||
OID_AUTO, "freebsd-version", CTLFLAG_RD, fdt_fbsd_version, | |||||
FDT_FBSDVER_LEN, "FreeBSD DTS branding version"); | |||||
} | } | ||||
SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, NULL); | SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, NULL); | ||||
static int | static int | ||||
ofw_fdt_init(ofw_t ofw, void *data) | ofw_fdt_init(ofw_t ofw, void *data) | ||||
{ | { | ||||
phandle_t root; | |||||
ssize_t len; | |||||
int err; | int err; | ||||
int i; | |||||
/* Check FDT blob integrity */ | /* Check FDT blob integrity */ | ||||
if ((err = fdt_check_header(data)) != 0) | if ((err = fdt_check_header(data)) != 0) | ||||
return (err); | return (err); | ||||
fdtp = data; | fdtp = data; | ||||
root = ofw_fdt_finddevice(NULL, "/"); | |||||
len = ofw_fdt_getproplen(NULL, root, "model"); | |||||
bzero(fdt_model, FDT_MODEL_LEN); | |||||
ofw_fdt_getprop(NULL, root, "model", fdt_model, FDT_MODEL_LEN); | |||||
len = ofw_fdt_getproplen(NULL, root, "compatible"); | |||||
bzero(fdt_compatible, FDT_COMPAT_LEN); | |||||
ofw_fdt_getprop(NULL, root, "compatible", fdt_compatible, FDT_COMPAT_LEN); | |||||
/* Replace the middle '\0' with ' ' */ | |||||
for (i = 0; i < len - 1; i++) | |||||
if (fdt_compatible[i] == '\0') | |||||
fdt_compatible[i] = ' '; | |||||
if ((len = ofw_fdt_getproplen(NULL, root, "freebsd,dts-version")) > 0) { | |||||
bzero(fdt_fbsd_version, FDT_FBSDVER_LEN); | |||||
ofw_fdt_getprop(NULL, root, "freebsd,dts-version", | |||||
fdt_fbsd_version, FDT_FBSDVER_LEN); | |||||
} | |||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Device tree functions. | * Device tree functions. | ||||
* | * | ||||
* We use the offset from fdtp to the node as the 'phandle' in OF interface. | * We use the offset from fdtp to the node as the 'phandle' in OF interface. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | ofw_fdt_package_to_path(ofw_t ofw, phandle_t package, char *buf, size_t len) | ||||
return (-1); | return (-1); | ||||
} | } | ||||
#if defined(FDT_MARVELL) | #if defined(FDT_MARVELL) | ||||
static int | static int | ||||
ofw_fdt_fixup(ofw_t ofw) | ofw_fdt_fixup(ofw_t ofw) | ||||
{ | { | ||||
#define FDT_MODEL_LEN 80 | |||||
char model[FDT_MODEL_LEN]; | char model[FDT_MODEL_LEN]; | ||||
phandle_t root; | phandle_t root; | ||||
ssize_t len; | ssize_t len; | ||||
int i; | int i; | ||||
if ((root = ofw_fdt_finddevice(ofw, "/")) == -1) | if ((root = ofw_fdt_finddevice(ofw, "/")) == -1) | ||||
return (ENODEV); | return (ENODEV); | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |