xref: /minix3/tests/modules/k_uvm/k_uvm.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*	$NetBSD: k_uvm.c,v 1.1 2012/02/17 22:36:50 jmmv Exp $	*/
2*11be35a1SLionel Sambuc /*
3*11be35a1SLionel Sambuc  * Copyright (c) 2012 The NetBSD Foundation, Inc.
4*11be35a1SLionel Sambuc  * All rights reserved.
5*11be35a1SLionel Sambuc  *
6*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
7*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
8*11be35a1SLionel Sambuc  * are met:
9*11be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
10*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
11*11be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
12*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
13*11be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
14*11be35a1SLionel Sambuc  *
15*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16*11be35a1SLionel Sambuc  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17*11be35a1SLionel Sambuc  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18*11be35a1SLionel Sambuc  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*11be35a1SLionel Sambuc  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20*11be35a1SLionel Sambuc  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*11be35a1SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22*11be35a1SLionel Sambuc  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*11be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24*11be35a1SLionel Sambuc  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25*11be35a1SLionel Sambuc  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26*11be35a1SLionel Sambuc  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*11be35a1SLionel Sambuc  */
28*11be35a1SLionel Sambuc 
29*11be35a1SLionel Sambuc #include <sys/cdefs.h>
30*11be35a1SLionel Sambuc __KERNEL_RCSID(0, "$NetBSD: k_uvm.c,v 1.1 2012/02/17 22:36:50 jmmv Exp $");
31*11be35a1SLionel Sambuc 
32*11be35a1SLionel Sambuc #include <sys/param.h>
33*11be35a1SLionel Sambuc #include <sys/kernel.h>
34*11be35a1SLionel Sambuc #include <sys/module.h>
35*11be35a1SLionel Sambuc #include <sys/sysctl.h>
36*11be35a1SLionel Sambuc 
37*11be35a1SLionel Sambuc MODULE(MODULE_CLASS_MISC, k_uvm, NULL);
38*11be35a1SLionel Sambuc 
39*11be35a1SLionel Sambuc /* --------------------------------------------------------------------- */
40*11be35a1SLionel Sambuc /* Sysctl interface to query information about the module.               */
41*11be35a1SLionel Sambuc /* --------------------------------------------------------------------- */
42*11be35a1SLionel Sambuc 
43*11be35a1SLionel Sambuc static struct sysctllog *clogp;
44*11be35a1SLionel Sambuc static int page_size;
45*11be35a1SLionel Sambuc 
46*11be35a1SLionel Sambuc #define K_UVM 0x12345678
47*11be35a1SLionel Sambuc #define K_UVM_VALUE 0
48*11be35a1SLionel Sambuc 
49*11be35a1SLionel Sambuc SYSCTL_SETUP(sysctl_k_uvm_setup, "sysctl k_uvm subtree setup")
50*11be35a1SLionel Sambuc {
51*11be35a1SLionel Sambuc 
52*11be35a1SLionel Sambuc 	sysctl_createv(clog, 0, NULL, NULL,
53*11be35a1SLionel Sambuc 	               CTLFLAG_PERMANENT,
54*11be35a1SLionel Sambuc 	               CTLTYPE_NODE, "k_uvm", NULL,
55*11be35a1SLionel Sambuc 	               NULL, 0, NULL, 0,
56*11be35a1SLionel Sambuc 	               CTL_VENDOR, K_UVM, CTL_EOL);
57*11be35a1SLionel Sambuc 
58*11be35a1SLionel Sambuc 	sysctl_createv(clog, 0, NULL, NULL,
59*11be35a1SLionel Sambuc 	               CTLFLAG_PERMANENT,
60*11be35a1SLionel Sambuc 	               CTLTYPE_INT, "page_size",
61*11be35a1SLionel Sambuc 		       SYSCTL_DESCR("Value of PAGE_SIZE"),
62*11be35a1SLionel Sambuc 		       NULL, 0, &page_size, 0,
63*11be35a1SLionel Sambuc 	               CTL_VENDOR, K_UVM, K_UVM_VALUE, CTL_EOL);
64*11be35a1SLionel Sambuc }
65*11be35a1SLionel Sambuc 
66*11be35a1SLionel Sambuc /* --------------------------------------------------------------------- */
67*11be35a1SLionel Sambuc /* Module management.                                                    */
68*11be35a1SLionel Sambuc /* --------------------------------------------------------------------- */
69*11be35a1SLionel Sambuc 
70*11be35a1SLionel Sambuc static
71*11be35a1SLionel Sambuc int
k_uvm_init(prop_dictionary_t props)72*11be35a1SLionel Sambuc k_uvm_init(prop_dictionary_t props)
73*11be35a1SLionel Sambuc {
74*11be35a1SLionel Sambuc 
75*11be35a1SLionel Sambuc 	page_size = PAGE_SIZE;
76*11be35a1SLionel Sambuc 
77*11be35a1SLionel Sambuc 	sysctl_k_uvm_setup(&clogp);
78*11be35a1SLionel Sambuc 
79*11be35a1SLionel Sambuc 	return 0;
80*11be35a1SLionel Sambuc }
81*11be35a1SLionel Sambuc 
82*11be35a1SLionel Sambuc static
83*11be35a1SLionel Sambuc int
k_uvm_fini(void * arg)84*11be35a1SLionel Sambuc k_uvm_fini(void *arg)
85*11be35a1SLionel Sambuc {
86*11be35a1SLionel Sambuc 
87*11be35a1SLionel Sambuc 	sysctl_teardown(&clogp);
88*11be35a1SLionel Sambuc 
89*11be35a1SLionel Sambuc 	return 0;
90*11be35a1SLionel Sambuc }
91*11be35a1SLionel Sambuc 
92*11be35a1SLionel Sambuc static
93*11be35a1SLionel Sambuc int
k_uvm_modcmd(modcmd_t cmd,void * arg)94*11be35a1SLionel Sambuc k_uvm_modcmd(modcmd_t cmd, void *arg)
95*11be35a1SLionel Sambuc {
96*11be35a1SLionel Sambuc 	int ret;
97*11be35a1SLionel Sambuc 
98*11be35a1SLionel Sambuc 	switch (cmd) {
99*11be35a1SLionel Sambuc 	case MODULE_CMD_INIT:
100*11be35a1SLionel Sambuc 		ret = k_uvm_init(arg);
101*11be35a1SLionel Sambuc 		break;
102*11be35a1SLionel Sambuc 
103*11be35a1SLionel Sambuc 	case MODULE_CMD_FINI:
104*11be35a1SLionel Sambuc 		ret = k_uvm_fini(arg);
105*11be35a1SLionel Sambuc 		break;
106*11be35a1SLionel Sambuc 
107*11be35a1SLionel Sambuc 	case MODULE_CMD_STAT:
108*11be35a1SLionel Sambuc 	default:
109*11be35a1SLionel Sambuc 		ret = ENOTTY;
110*11be35a1SLionel Sambuc 	}
111*11be35a1SLionel Sambuc 
112*11be35a1SLionel Sambuc 	return ret;
113*11be35a1SLionel Sambuc }
114