aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorGarrett Wollman <wollman@FreeBSD.org>1994-10-16 03:52:14 +0000
committerGarrett Wollman <wollman@FreeBSD.org>1994-10-16 03:52:14 +0000
commit8478cabaea352368e75a5d8f4d653f41b4284579 (patch)
treeb0f27032127538e06570a686834fd889526bb208 /sys
parente78014a8dc709eb2e2bf9cac26b121578108195c (diff)
downloadsrc-8478cabaea352368e75a5d8f4d653f41b4284579.tar.gz
src-8478cabaea352368e75a5d8f4d653f41b4284579.zip
kern_clock.c: define dk_names[][].
kern_sysctl.c: call dev_sysctl for hw.devconf mib subtree kern_devconf.c: sysctl-accessible device-configuration and -management interface
Notes
Notes: svn path=/head/; revision=3640
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_clock.c5
-rw-r--r--sys/kern/kern_devconf.c177
-rw-r--r--sys/kern/kern_sysctl.c9
-rw-r--r--sys/kern/kern_tc.c5
-rw-r--r--sys/kern/kern_timeout.c5
5 files changed, 192 insertions, 9 deletions
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c
index db447bf3ea94..35e119be4085 100644
--- a/sys/kern/kern_clock.c
+++ b/sys/kern/kern_clock.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
- * $Id: kern_clock.c,v 1.8 1994/09/29 00:52:06 wollman Exp $
+ * $Id: kern_clock.c,v 1.9 1994/10/02 17:35:10 phk Exp $
*/
/* Portions of this software are covered by the following: */
@@ -88,7 +88,8 @@ long dk_wpms[DK_NDRIVE];
long dk_xfer[DK_NDRIVE];
int dk_busy;
-int dk_ndrive = DK_NDRIVE;
+int dk_ndrive = 0;
+char dk_names[DK_NDRIVE][DK_NAMELEN];
long tk_cancc;
long tk_nin;
diff --git a/sys/kern/kern_devconf.c b/sys/kern/kern_devconf.c
new file mode 100644
index 000000000000..43247f7c8b38
--- /dev/null
+++ b/sys/kern/kern_devconf.c
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 1994, Garrett A. Wollman. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: sysctl.h,v 1.17 1994/10/10 00:58:34 phk Exp $
+ */
+
+/*
+ * kern_devconf.c - manage device configuration table
+ *
+ * Garrett A. Wollman, October 1994.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <vm/vm.h> /* needed for sysctl.h */
+#include <sys/sysctl.h>
+#include <sys/devconf.h>
+
+static struct kern_devconf *dc_list = 0;
+static unsigned dc_lastnum = 0;
+
+int
+dev_attach(struct kern_devconf *kdc)
+{
+ int s = splclock();
+ kdc->kdc_next = dc_list;
+ if(kdc->kdc_next)
+ kdc->kdc_next->kdc_rlink = &kdc->kdc_next;
+ kdc->kdc_rlink = &dc_list;
+ kdc->kdc_number = ++dc_lastnum;
+ dc_list = kdc;
+ splx(s);
+ return 0;
+}
+
+int
+dev_detach(struct kern_devconf *kdc)
+{
+ struct kern_devconf *iter;
+ int s;
+
+ s = splclock();
+ *kdc->kdc_rlink = kdc->kdc_next;
+ if(kdc->kdc_next)
+ kdc->kdc_next->kdc_rlink = kdc->kdc_rlink;
+ splx(s);
+
+ return 0;
+}
+
+/*
+ * NB: the device must do a dev_detach inside its goaway routine, if it
+ * succeeds.
+ */
+int
+dev_goawayall(int force)
+{
+ int rv = 0;
+ struct kern_devconf *kdc = dc_list;
+
+ while(kdc) {
+ if(kdc->kdc_goaway(kdc, force)) {
+ rv++;
+ kdc = kdc->kdc_next;
+ } else {
+ kdc = dc_list;
+ }
+ }
+ return rv;
+}
+
+static void
+make_devconf(struct kern_devconf *kdc, struct devconf *dc)
+{
+ strncpy(dc->dc_name, kdc->kdc_name, sizeof dc->dc_name);
+ dc->dc_name[sizeof dc->dc_name - 1] = '\0';
+ dc->dc_unit = kdc->kdc_unit;
+ dc->dc_md = kdc->kdc_md;
+ dc->dc_number = kdc->kdc_number;
+ if(kdc->kdc_datalen)
+ dc->dc_datalen = kdc->kdc_datalen(kdc);
+ else
+ dc->dc_datalen = 0;
+}
+
+int
+dev_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
+ void *newp, size_t newlen, struct proc *p)
+{
+ struct kern_devconf *kdc;
+ struct devconf dc;
+ int rv;
+ size_t len;
+
+ /* all sysctl names at this level are terminal */
+ if (namelen != 1)
+ return ENOTDIR;
+
+ switch(name[0]) {
+ case DEVCONF_NUMBER:
+ return (sysctl_rdint(oldp, oldlenp, newp, dc_lastnum));
+
+ default:
+ for(kdc = dc_list; kdc; kdc = kdc->kdc_next) {
+ if(kdc->kdc_number == name[0])
+ break;
+ }
+
+ if(!kdc)
+ return ENXIO;
+
+ if(!oldp) {
+ *oldlenp = sizeof(struct devconf) - 1;
+
+ if(kdc->kdc_datalen) {
+ *oldlenp += kdc->kdc_datalen(kdc);
+ }
+ return 0;
+ }
+
+ len = *oldlenp;
+ make_devconf(kdc, &dc);
+ *oldlenp = (sizeof dc) - 1 + dc.dc_datalen;
+
+ if(len < *oldlenp) {
+ return ENOMEM;
+ }
+
+ rv = copyout(&dc, oldp, (sizeof dc) - 1);
+ if(rv)
+ return rv;
+
+ if(kdc->kdc_externalize)
+ rv = kdc->kdc_externalize(p, kdc,
+ &((struct devconf *)oldp)->dc_data,
+ len - ((sizeof dc) - 1));
+ if(rv)
+ return rv;
+
+ if(!newp)
+ return 0;
+
+ rv = suser(p->p_ucred, &p->p_acflag);
+ if(rv)
+ return rv;
+ if(!kdc->kdc_internalize)
+ return EOPNOTSUPP;
+
+ rv = kdc->kdc_internalize(p, kdc,
+ &((struct devconf *)newp)->dc_data,
+ newlen - ((sizeof dc) - 1));
+ return rv;
+ }
+}
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 5564d92d9056..f22606fb784a 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
- * $Id: kern_sysctl.c,v 1.16 1994/10/02 17:35:19 phk Exp $
+ * $Id: kern_sysctl.c,v 1.17 1994/10/06 21:06:30 davidg Exp $
*/
/*
@@ -319,8 +319,8 @@ hw_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
extern char machine[], cpu_model[];
extern int hw_float;
- /* all sysctl names at this level are terminal */
- if (namelen != 1)
+ /* almost all sysctl names at this level are terminal */
+ if (namelen != 1 && name[0] != HW_DEVCONF)
return (ENOTDIR); /* overloaded */
switch (name[0]) {
@@ -341,6 +341,9 @@ hw_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
return (sysctl_rdint(oldp, oldlenp, newp, PAGE_SIZE));
case HW_FLOATINGPT:
return (sysctl_rdint(oldp, oldlenp, newp, hw_float));
+ case HW_DEVCONF:
+ return (dev_sysctl(name + 1, namelen - 1, oldp, oldlenp,
+ newp, newlen, p));
default:
return (EOPNOTSUPP);
}
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index db447bf3ea94..35e119be4085 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
- * $Id: kern_clock.c,v 1.8 1994/09/29 00:52:06 wollman Exp $
+ * $Id: kern_clock.c,v 1.9 1994/10/02 17:35:10 phk Exp $
*/
/* Portions of this software are covered by the following: */
@@ -88,7 +88,8 @@ long dk_wpms[DK_NDRIVE];
long dk_xfer[DK_NDRIVE];
int dk_busy;
-int dk_ndrive = DK_NDRIVE;
+int dk_ndrive = 0;
+char dk_names[DK_NDRIVE][DK_NAMELEN];
long tk_cancc;
long tk_nin;
diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c
index db447bf3ea94..35e119be4085 100644
--- a/sys/kern/kern_timeout.c
+++ b/sys/kern/kern_timeout.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
- * $Id: kern_clock.c,v 1.8 1994/09/29 00:52:06 wollman Exp $
+ * $Id: kern_clock.c,v 1.9 1994/10/02 17:35:10 phk Exp $
*/
/* Portions of this software are covered by the following: */
@@ -88,7 +88,8 @@ long dk_wpms[DK_NDRIVE];
long dk_xfer[DK_NDRIVE];
int dk_busy;
-int dk_ndrive = DK_NDRIVE;
+int dk_ndrive = 0;
+char dk_names[DK_NDRIVE][DK_NAMELEN];
long tk_cancc;
long tk_nin;