1272343Sngie/*	$NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */
2272343Sngie/*
3272343Sngie * Copyright (c) 2010 The NetBSD Foundation, Inc.
4272343Sngie * All rights reserved.
5272343Sngie *
6272343Sngie * Redistribution and use in source and binary forms, with or without
7272343Sngie * modification, are permitted provided that the following conditions
8272343Sngie * are met:
9272343Sngie * 1. Redistributions of source code must retain the above copyright
10272343Sngie *    notice, this list of conditions and the following disclaimer.
11272343Sngie * 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie *    notice, this list of conditions and the following disclaimer in the
13272343Sngie *    documentation and/or other materials provided with the distribution.
14272343Sngie *
15272343Sngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16272343Sngie * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17272343Sngie * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18272343Sngie * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19272343Sngie * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20272343Sngie * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21272343Sngie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22272343Sngie * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23272343Sngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24272343Sngie * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25272343Sngie * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26272343Sngie * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27272343Sngie */
28272343Sngie
29272343Sngie#include <sys/cdefs.h>
30272343Sngie__KERNEL_RCSID(0, "$NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $");
31272343Sngie
32272343Sngie#include <sys/param.h>
33272343Sngie#include <sys/kernel.h>
34272343Sngie#include <sys/module.h>
35272343Sngie#include <sys/sysctl.h>
36272343Sngie
37272343Sngie#include <prop/proplib.h>
38272343Sngie
39272343SngieMODULE(MODULE_CLASS_MISC, k_helper2, NULL);
40272343Sngie
41272343Sngie/* --------------------------------------------------------------------- */
42272343Sngie/* Sysctl interface to query information about the module.               */
43272343Sngie/* --------------------------------------------------------------------- */
44272343Sngie
45272343Sngie/* TODO: Change the integer variables below that represent booleans to
46272343Sngie * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */
47272343Sngie
48272343Sngiestatic struct sysctllog *clogp;
49272343Sngiestatic int present = 1;
50272343Sngie
51272343Sngie#define K_HELPER2 0x23456781
52272343Sngie#define K_HELPER_PRESENT 0
53272343Sngie
54272343SngieSYSCTL_SETUP(sysctl_k_helper2_setup, "sysctl k_helper subtree setup")
55272343Sngie{
56272343Sngie
57272343Sngie	sysctl_createv(clog, 0, NULL, NULL,
58272343Sngie	               CTLFLAG_PERMANENT,
59272343Sngie	               CTLTYPE_NODE, "k_helper2", NULL,
60272343Sngie	               NULL, 0, NULL, 0,
61272343Sngie	               CTL_VENDOR, K_HELPER2, CTL_EOL);
62272343Sngie
63272343Sngie	sysctl_createv(clog, 0, NULL, NULL,
64272343Sngie	               CTLFLAG_PERMANENT,
65272343Sngie	               CTLTYPE_INT, "present",
66272343Sngie		       SYSCTL_DESCR("Whether the module was loaded or not"),
67272343Sngie		       NULL, 0, &present, 0,
68272343Sngie	               CTL_VENDOR, K_HELPER2, K_HELPER_PRESENT, CTL_EOL);
69272343Sngie}
70272343Sngie
71272343Sngie/* --------------------------------------------------------------------- */
72272343Sngie/* Module management.                                                    */
73272343Sngie/* --------------------------------------------------------------------- */
74272343Sngie
75272343Sngiestatic
76272343Sngieint
77272343Sngiek_helper2_init(prop_dictionary_t props)
78272343Sngie{
79272343Sngie	sysctl_k_helper2_setup(&clogp);
80272343Sngie
81272343Sngie	return 0;
82272343Sngie}
83272343Sngie
84272343Sngiestatic
85272343Sngieint
86272343Sngiek_helper2_fini(void *arg)
87272343Sngie{
88272343Sngie
89272343Sngie	sysctl_teardown(&clogp);
90272343Sngie
91272343Sngie	return 0;
92272343Sngie}
93272343Sngie
94272343Sngiestatic
95272343Sngieint
96272343Sngiek_helper2_modcmd(modcmd_t cmd, void *arg)
97272343Sngie{
98272343Sngie	int ret;
99272343Sngie
100272343Sngie	switch (cmd) {
101272343Sngie	case MODULE_CMD_INIT:
102272343Sngie		ret = k_helper2_init(arg);
103272343Sngie		break;
104272343Sngie
105272343Sngie	case MODULE_CMD_FINI:
106272343Sngie		ret = k_helper2_fini(arg);
107272343Sngie		break;
108272343Sngie
109272343Sngie	case MODULE_CMD_STAT:
110272343Sngie	default:
111272343Sngie		ret = ENOTTY;
112272343Sngie	}
113272343Sngie
114272343Sngie	return ret;
115272343Sngie}
116