summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_hints.c
diff options
context:
space:
mode:
authorray <ray@FreeBSD.org>2012-09-03 08:52:05 +0000
committerray <ray@FreeBSD.org>2012-09-03 08:52:05 +0000
commitd9abd894ecf50ac672b1ada3a2034b45801d1a5f (patch)
treed1e0adc87a8e5acd17ea32c2dd6a2fd343b1ff09 /sys/kern/subr_hints.c
parentded352a8c674a822d85b1f89c905340a079ae1c2 (diff)
downloadFreeBSD-src-d9abd894ecf50ac672b1ada3a2034b45801d1a5f.zip
FreeBSD-src-d9abd894ecf50ac672b1ada3a2034b45801d1a5f.tar.gz
Add kern.hintmode sysctl variable to show current state of hints:
0 - loader hints in environment only; 1 - static hints only 2 - fallback mode (Dynamic KENV with fallback to kernel environment) Add kern.hintmode write handler, accept only value 2. That will switch static KENV to dynamic. So it will be possible to change device hints. Approved by: adrian (mentor)
Diffstat (limited to 'sys/kern/subr_hints.c')
-rw-r--r--sys/kern/subr_hints.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/sys/kern/subr_hints.c b/sys/kern/subr_hints.c
index afa959d..e27acf5 100644
--- a/sys/kern/subr_hints.c
+++ b/sys/kern/subr_hints.c
@@ -29,8 +29,10 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/lock.h>
+#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/systm.h>
+#include <sys/sysctl.h>
#include <sys/bus.h>
/*
@@ -42,6 +44,81 @@ static int use_kenv;
static char *hintp;
/*
+ * Define kern.hintmode sysctl, which only accept value 2, that cause to
+ * switch from Static KENV mode to Dynamic KENV. So systems that have hints
+ * compiled into kernel will be able to see/modify KENV (and hints too).
+ */
+
+static int
+sysctl_hintmode(SYSCTL_HANDLER_ARGS)
+{
+ int error, i, from_kenv, value, eqidx;
+ const char *cp;
+ char *line, *eq;
+
+ from_kenv = 0;
+ cp = kern_envp;
+ value = hintmode;
+
+ /* Fetch candidate for new hintmode value */
+ error = sysctl_handle_int(oidp, &value, 0, req);
+ if (error || !req->newptr)
+ return (error);
+
+ if (value != 2)
+ /* Only accept swithing to hintmode 2 */
+ return (EINVAL);
+
+ /* Migrate from static to dynamic hints */
+ switch (hintmode) {
+ case 0:
+ if (dynamic_kenv)
+ /* Already here */
+ hintmode = value; /* XXX: Need we switch or not ? */
+ return (0);
+ from_kenv = 1;
+ cp = kern_envp;
+ break;
+ case 1:
+ cp = static_hints;
+ break;
+ case 2:
+ /* Nothing to do, hintmode already 2 */
+ return (0);
+ }
+
+ while (cp) {
+ i = strlen(cp);
+ if (i == 0)
+ break;
+ if (from_kenv) {
+ if (strncmp(cp, "hint.", 5) != 0)
+ /* kenv can have not only hints */
+ continue;
+ }
+ eq = strchr(cp, '=');
+ if (!eq)
+ /* Bad hint value */
+ continue;
+ eqidx = eq - cp;
+
+ line = malloc(i+1, M_TEMP, M_WAITOK);
+ strcpy(line, cp);
+ line[eqidx] = '\0';
+ setenv(line, line + eqidx + 1);
+ free(line, M_TEMP);
+ cp += i + 1;
+ }
+
+ hintmode = value;
+ use_kenv = 1;
+ return (0);
+}
+
+SYSCTL_PROC(_kern, OID_AUTO, hintmode, CTLTYPE_INT|CTLFLAG_RW,
+ &hintmode, 0, sysctl_hintmode, "I", "Get/set current hintmode");
+
+/*
* Evil wildcarding resource string lookup.
* This walks the supplied env string table and returns a match.
* The start point can be remembered for incremental searches.
OpenPOWER on IntegriCloud