From a183d81dc9f985f94974a821886cd57bd784480f Mon Sep 17 00:00:00 2001 From: "Stephen J. Kiernan" Date: Sat, 6 Aug 2016 18:48:47 +0000 Subject: [PATCH] Add hw.fdt sysctl node. Make FDT blob available via opaque hw.fdt.dtb sysctl, if a DTB has been installed by the time sysctls are registered. Reviewed by: andrew Approved by: sjg (mentor) Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D7411 --- sys/dev/fdt/fdt_common.c | 3 +++ sys/dev/fdt/fdt_common.h | 3 +++ sys/dev/ofw/ofw_fdt.c | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/sys/dev/fdt/fdt_common.c b/sys/dev/fdt/fdt_common.c index 4e0d6e206c5b..2f4555f81a4d 100644 --- a/sys/dev/fdt/fdt_common.c +++ b/sys/dev/fdt/fdt_common.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include @@ -60,6 +61,8 @@ __FBSDID("$FreeBSD$"); #define FDT_REG_CELLS 4 +SYSCTL_NODE(_hw, OID_AUTO, fdt, CTLFLAG_RD, 0, "Flattened Device Tree"); + vm_paddr_t fdt_immr_pa; vm_offset_t fdt_immr_va; vm_offset_t fdt_immr_size; diff --git a/sys/dev/fdt/fdt_common.h b/sys/dev/fdt/fdt_common.h index 94f84ff3fe49..afddc310c127 100644 --- a/sys/dev/fdt/fdt_common.h +++ b/sys/dev/fdt/fdt_common.h @@ -32,6 +32,7 @@ #ifndef _FDT_COMMON_H_ #define _FDT_COMMON_H_ +#include #include #include #include @@ -80,6 +81,8 @@ extern struct fdt_pm_mask_entry fdt_pm_mask_table[]; extern u_char fdt_static_dtb; #endif +SYSCTL_DECL(_hw_fdt); + int fdt_addrsize_cells(phandle_t, int *, int *); u_long fdt_data_get(void *, int); int fdt_data_to_res(pcell_t *, int, int, u_long *, u_long *); diff --git a/sys/dev/ofw/ofw_fdt.c b/sys/dev/ofw/ofw_fdt.c index fc41d5bc6a3c..0f7cf07919b3 100644 --- a/sys/dev/ofw/ofw_fdt.c +++ b/sys/dev/ofw/ofw_fdt.c @@ -95,6 +95,27 @@ OFW_DEF(ofw_fdt); static void *fdtp = NULL; +static int +sysctl_handle_dtb(SYSCTL_HANDLER_ARGS) +{ + + return (sysctl_handle_opaque(oidp, fdtp, fdt_totalsize(fdtp), req)); +} + +static void +sysctl_register_fdt_oid(void *arg) +{ + + /* If there is no FDT registered, skip adding the sysctl */ + if (fdtp == NULL) + return; + + SYSCTL_ADD_PROC(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), OID_AUTO, "dtb", + CTLTYPE_OPAQUE | CTLFLAG_RD, NULL, 0, sysctl_handle_dtb, "", + "Device Tree Blob"); +} +SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, 0); + static int ofw_fdt_init(ofw_t ofw, void *data) {