xref: /netbsd-src/tests/modules/k_helper2/k_helper2.c (revision 0f10aa9dce10d06b907b06520ae9c3443b22e983)
1*0f10aa9dSchristos /*	$NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */
260bf661bSpgoyette /*
360bf661bSpgoyette  * Copyright (c) 2010 The NetBSD Foundation, Inc.
460bf661bSpgoyette  * All rights reserved.
560bf661bSpgoyette  *
660bf661bSpgoyette  * Redistribution and use in source and binary forms, with or without
760bf661bSpgoyette  * modification, are permitted provided that the following conditions
860bf661bSpgoyette  * are met:
960bf661bSpgoyette  * 1. Redistributions of source code must retain the above copyright
1060bf661bSpgoyette  *    notice, this list of conditions and the following disclaimer.
1160bf661bSpgoyette  * 2. Redistributions in binary form must reproduce the above copyright
1260bf661bSpgoyette  *    notice, this list of conditions and the following disclaimer in the
1360bf661bSpgoyette  *    documentation and/or other materials provided with the distribution.
1460bf661bSpgoyette  *
1560bf661bSpgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1660bf661bSpgoyette  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1760bf661bSpgoyette  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1860bf661bSpgoyette  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1960bf661bSpgoyette  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2060bf661bSpgoyette  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2160bf661bSpgoyette  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2260bf661bSpgoyette  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2360bf661bSpgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2460bf661bSpgoyette  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2560bf661bSpgoyette  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2660bf661bSpgoyette  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2760bf661bSpgoyette  */
2860bf661bSpgoyette 
2960bf661bSpgoyette #include <sys/cdefs.h>
30*0f10aa9dSchristos __KERNEL_RCSID(0, "$NetBSD: k_helper2.c,v 1.2 2010/11/03 16:10:23 christos Exp $");
3160bf661bSpgoyette 
3260bf661bSpgoyette #include <sys/param.h>
3360bf661bSpgoyette #include <sys/kernel.h>
3460bf661bSpgoyette #include <sys/module.h>
3560bf661bSpgoyette #include <sys/sysctl.h>
3660bf661bSpgoyette 
3760bf661bSpgoyette #include <prop/proplib.h>
3860bf661bSpgoyette 
3960bf661bSpgoyette MODULE(MODULE_CLASS_MISC, k_helper2, NULL);
4060bf661bSpgoyette 
4160bf661bSpgoyette /* --------------------------------------------------------------------- */
4260bf661bSpgoyette /* Sysctl interface to query information about the module.               */
4360bf661bSpgoyette /* --------------------------------------------------------------------- */
4460bf661bSpgoyette 
4560bf661bSpgoyette /* TODO: Change the integer variables below that represent booleans to
4660bf661bSpgoyette  * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */
4760bf661bSpgoyette 
48*0f10aa9dSchristos static struct sysctllog *clogp;
4960bf661bSpgoyette static int present = 1;
5060bf661bSpgoyette 
5160bf661bSpgoyette #define K_HELPER2 0x23456781
5260bf661bSpgoyette #define K_HELPER_PRESENT 0
5360bf661bSpgoyette 
5460bf661bSpgoyette SYSCTL_SETUP(sysctl_k_helper2_setup, "sysctl k_helper subtree setup")
5560bf661bSpgoyette {
5660bf661bSpgoyette 
5760bf661bSpgoyette 	sysctl_createv(clog, 0, NULL, NULL,
5860bf661bSpgoyette 	               CTLFLAG_PERMANENT,
5960bf661bSpgoyette 	               CTLTYPE_NODE, "k_helper2", NULL,
6060bf661bSpgoyette 	               NULL, 0, NULL, 0,
6160bf661bSpgoyette 	               CTL_VENDOR, K_HELPER2, CTL_EOL);
6260bf661bSpgoyette 
6360bf661bSpgoyette 	sysctl_createv(clog, 0, NULL, NULL,
6460bf661bSpgoyette 	               CTLFLAG_PERMANENT,
6560bf661bSpgoyette 	               CTLTYPE_INT, "present",
6660bf661bSpgoyette 		       SYSCTL_DESCR("Whether the module was loaded or not"),
6760bf661bSpgoyette 		       NULL, 0, &present, 0,
6860bf661bSpgoyette 	               CTL_VENDOR, K_HELPER2, K_HELPER_PRESENT, CTL_EOL);
6960bf661bSpgoyette }
7060bf661bSpgoyette 
7160bf661bSpgoyette /* --------------------------------------------------------------------- */
7260bf661bSpgoyette /* Module management.                                                    */
7360bf661bSpgoyette /* --------------------------------------------------------------------- */
7460bf661bSpgoyette 
7560bf661bSpgoyette static
7660bf661bSpgoyette int
k_helper2_init(prop_dictionary_t props)7760bf661bSpgoyette k_helper2_init(prop_dictionary_t props)
7860bf661bSpgoyette {
79*0f10aa9dSchristos 	sysctl_k_helper2_setup(&clogp);
8060bf661bSpgoyette 
8160bf661bSpgoyette 	return 0;
8260bf661bSpgoyette }
8360bf661bSpgoyette 
8460bf661bSpgoyette static
8560bf661bSpgoyette int
k_helper2_fini(void * arg)8660bf661bSpgoyette k_helper2_fini(void *arg)
8760bf661bSpgoyette {
8860bf661bSpgoyette 
89*0f10aa9dSchristos 	sysctl_teardown(&clogp);
9060bf661bSpgoyette 
9160bf661bSpgoyette 	return 0;
9260bf661bSpgoyette }
9360bf661bSpgoyette 
9460bf661bSpgoyette static
9560bf661bSpgoyette int
k_helper2_modcmd(modcmd_t cmd,void * arg)9660bf661bSpgoyette k_helper2_modcmd(modcmd_t cmd, void *arg)
9760bf661bSpgoyette {
9860bf661bSpgoyette 	int ret;
9960bf661bSpgoyette 
10060bf661bSpgoyette 	switch (cmd) {
10160bf661bSpgoyette 	case MODULE_CMD_INIT:
10260bf661bSpgoyette 		ret = k_helper2_init(arg);
10360bf661bSpgoyette 		break;
10460bf661bSpgoyette 
10560bf661bSpgoyette 	case MODULE_CMD_FINI:
10660bf661bSpgoyette 		ret = k_helper2_fini(arg);
10760bf661bSpgoyette 		break;
10860bf661bSpgoyette 
10960bf661bSpgoyette 	case MODULE_CMD_STAT:
11060bf661bSpgoyette 	default:
11160bf661bSpgoyette 		ret = ENOTTY;
11260bf661bSpgoyette 	}
11360bf661bSpgoyette 
11460bf661bSpgoyette 	return ret;
11560bf661bSpgoyette }
116