36#include <sys/kernel.h>
37#include <sys/malloc.h>
40#include <contrib/libfdt/libfdt.h>
42#include <machine/stdarg.h>
44#include <dev/fdt/fdt_common.h>
52#define debugf(fmt, args...) do { printf("%s(): ", __func__); \
53 printf(fmt,##args); } while (0)
55#define debugf(fmt, args...)
59#if defined(SOC_MV_ARMADAXP) || defined(SOC_MV_ARMADA38X) || \
60 defined(SOC_MV_DISCOVERY) || defined(SOC_MV_DOVE) || \
61 defined(SOC_MV_FREY) || defined(SOC_MV_KIRKWOOD) || \
62 defined(SOC_MV_LOKIPLUS) || defined(SOC_MV_ORION)
108#define FDT_FBSDVER_LEN 16
109#define FDT_MODEL_LEN 80
110#define FDT_COMPAT_LEN 255
111#define FDT_SERIAL_LEN 32
123 return (sysctl_handle_opaque(oidp,
fdtp, fdt_totalsize(
fdtp), req));
134 SYSCTL_ADD_PROC(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), OID_AUTO,
"dtb",
135 CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
138 SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt),
139 OID_AUTO,
"model", CTLFLAG_RD,
fdt_model,
142 SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt),
146 SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt),
150 SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt),
151 OID_AUTO,
"serial-number", CTLFLAG_RD,
fdt_serial,
165 if ((err = fdt_check_header(data)) != 0)
181 for (i = 0; i < len - 1; i++)
200 for (i = 0; i < len - 1; i++) {
234 int dtoff = fdt_off_dt_struct(
fdtp);
238 return (pint - dtoff);
249 offset = fdt_path_offset(
fdtp,
"/");
257 offset = fdt_next_subnode(
fdtp, offset);
270 offset = fdt_first_subnode(
fdtp, offset);
278 int offset, paroffset;
284 paroffset = fdt_parent_offset(
fdtp, offset);
309 prop = fdt_getprop(
fdtp, offset, propname, &len);
311 if (prop == NULL && strcmp(propname,
"name") == 0) {
313 fdt_get_name(
fdtp, offset, &len);
317 if (prop == NULL && offset == fdt_path_offset(
fdtp,
"/chosen")) {
318 if (strcmp(propname,
"fdtbootcpu") == 0)
319 return (
sizeof(cell_t));
320 if (strcmp(propname,
"fdtmemreserv") == 0)
321 return (
sizeof(uint64_t)*2*fdt_num_mem_rsv(
fdtp));
344 prop = fdt_getprop(
fdtp, offset, propname, &len);
346 if (prop == NULL && strcmp(propname,
"name") == 0) {
348 name = fdt_get_name(
fdtp, offset, &len);
349 strncpy(buf, name, buflen);
353 if (prop == NULL && offset == fdt_path_offset(
fdtp,
"/chosen")) {
354 if (strcmp(propname,
"fdtbootcpu") == 0) {
355 cpuid = cpu_to_fdt32(fdt_boot_cpuid_phys(
fdtp));
359 if (strcmp(propname,
"fdtmemreserv") == 0) {
360 prop = (
char *)
fdtp + fdt_off_mem_rsvmap(
fdtp);
361 len =
sizeof(uint64_t)*2*fdt_num_mem_rsv(
fdtp);
368 bcopy(prop, buf, min(len, buflen));
391 if (previous == NULL)
393 offset = fdt_first_property_offset(
fdtp, offset);
395 fdt_for_each_property_offset(offset,
fdtp, offset) {
396 prop = fdt_getprop_by_offset(
fdtp, offset, &name, NULL);
400 if (strcmp(name, previous) != 0)
402 offset = fdt_next_property_offset(
fdtp, offset);
410 prop = fdt_getprop_by_offset(
fdtp, offset, &name, &offset);
414 strncpy(buf, name,
size);
422 const void *buf,
size_t len)
430 if (fdt_setprop_inplace(
fdtp, offset, propname, buf, len) != 0)
432 return (fdt_setprop(
fdtp, offset, propname, buf, len));
451 offset = fdt_path_offset(
fdtp, device);
478#if defined(FDT_MARVELL)
500 for (i = 0; fdt_fixup_table[i].model != NULL; i++) {
501 if (strncmp(model, fdt_fixup_table[i].model,
510 fdt_fixup_table[i].model))
513 if (fdt_fixup_table[i].handler != NULL)
514 (*fdt_fixup_table[i].handler)(root);
524#if defined(FDT_MARVELL)
535 if (strncmp(
"perform-fixup", cmd, 13) != 0)
538 rv = ofw_fdt_fixup(
ofw);
int ofw_bus_node_is_compatible(phandle_t node, const char *compatstr)
static phandle_t fdt_offset_phandle(int offset)
static char fdt_serial[FDT_SERIAL_LEN]
static phandle_t ofw_fdt_parent(ofw_t, phandle_t)
static int ofw_fdt_nextprop(ofw_t, phandle_t, const char *, char *, size_t)
static int ofw_fdt_setprop(ofw_t, phandle_t, const char *, const void *, size_t)
static ssize_t ofw_fdt_getprop(ofw_t, phandle_t, const char *, void *, size_t)
static int ofw_fdt_init(ofw_t, void *)
static ssize_t ofw_fdt_instance_to_path(ofw_t, ihandle_t, char *, size_t)
static ofw_method_t ofw_fdt_methods[]
static phandle_t ofw_fdt_peer(ofw_t, phandle_t)
static char fdt_model[FDT_MODEL_LEN]
static char fdt_fbsd_version[FDT_FBSDVER_LEN]
static int sysctl_handle_dtb(SYSCTL_HANDLER_ARGS)
static phandle_t ofw_fdt_child(ofw_t, phandle_t)
static ssize_t ofw_fdt_package_to_path(ofw_t, phandle_t, char *, size_t)
SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, NULL)
static int fdt_phandle_offset(phandle_t p)
static phandle_t ofw_fdt_instance_to_package(ofw_t, ihandle_t)
static ssize_t ofw_fdt_canon(ofw_t, const char *, char *, size_t)
static void sysctl_register_fdt_oid(void *arg)
static int ofw_fdt_interpret(ofw_t, const char *, int, cell_t *)
static char fdt_compatible[FDT_COMPAT_LEN]
static phandle_t ofw_fdt_finddevice(ofw_t, const char *)
static ssize_t ofw_fdt_getproplen(ofw_t, phandle_t, const char *)
struct kobj_class ofw_def_t
phandle_t OF_node_from_xref(phandle_t xref)
ssize_t OF_package_to_path(phandle_t package, char *buf, size_t len)
phandle_t OF_instance_to_package(ihandle_t instance)