FreeBSD/Linux Kernel Cross Reference
sys/pccard/skel.c
1 /*
2 * Loadable kernel module skeleton driver
3 * 11 July 1995 Andrew McRae
4 *
5 *-------------------------------------------------------------------------
6 *
7 * Copyright (c) 1995 Andrew McRae. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/proc.h>
34 #include <sys/conf.h>
35 #include <sys/mount.h>
36 #include <sys/sysent.h>
37 #include <sys/exec.h>
38 #include <sys/lkm.h>
39
40 #include <sys/select.h>
41 #include <pccard/cardinfo.h>
42 #include <pccard/driver.h>
43 #include <pccard/slot.h>
44
45
46 /*
47 * This defines the lkm_misc module use by modload
48 * to define the module name.
49 */
50 MOD_MISC( "skel")
51
52
53 static int skelinit(struct pccard_devinfo *); /* init device */
54 static void skelunload(struct pccard_devinfo *); /* Disable driver */
55 static int skelintr(struct pccard_devinfo *); /* Interrupt handler */
56
57 static struct pccard_device skel_info = {
58 "skel",
59 skelinit,
60 skelunload,
61 skelintr,
62 0, /* Attributes - presently unused */
63 &net_imask /* Interrupt mask for device */
64 };
65
66 DATA_SET(pccarddrv_set, skel_info);
67
68 static int opened; /* Rather minimal device state... */
69
70 /*
71 * Module handler that processes loads and unloads.
72 * Once the module is loaded, the add driver routine is called
73 * to register the driver.
74 * If an unload is requested the remove driver routine is
75 * called to deregister the driver before unloading.
76 */
77 static int
78 skel_handle( lkmtp, cmd)
79 struct lkm_table *lkmtp;
80 int cmd;
81 {
82 int i;
83 struct lkm_misc *args = lkmtp->private.lkm_misc;
84 int err = 0; /* default = success*/
85
86 switch( cmd) {
87 case LKM_E_LOAD:
88
89 /*
90 * Don't load twice! (lkmexists() is exported by kern_lkm.c)
91 */
92 if( lkmexists( lkmtp))
93 return( EEXIST);
94 /*
95 * Now register the driver
96 */
97 pccard_add_driver(&skel_info);
98 break; /* Success*/
99 /*
100 * Attempt to deregister the driver.
101 */
102 case LKM_E_UNLOAD:
103 pccard_remove_driver(&skel_info);
104 break; /* Success*/
105
106 default: /* we only understand load/unload*/
107 err = EINVAL;
108 break;
109 }
110
111 return( err);
112 }
113
114
115 /*
116 * External entry point; should generally match name of .o file. The
117 * arguments are always the same for all loaded modules. The "load",
118 * "unload", and "stat" functions in "DISPATCH" will be called under
119 * their respective circumstances unless their value is "nosys". If
120 * called, they are called with the same arguments (cmd is included to
121 * allow the use of a single function, ver is included for version
122 * matching between modules and the kernel loader for the modules).
123 *
124 * Since we expect to link in the kernel and add external symbols to
125 * the kernel symbol name space in a future version, generally all
126 * functions used in the implementation of a particular module should
127 * be static unless they are expected to be seen in other modules or
128 * to resolve unresolved symbols alread existing in the kernel (the
129 * second case is not likely to ever occur).
130 *
131 * The entry point should return 0 unless it is refusing load (in which
132 * case it should return an errno from errno.h).
133 */
134 int
135 lkm_skel(lkmtp, cmd, ver)
136 struct lkm_table *lkmtp;
137 int cmd;
138 int ver;
139 {
140 DISPATCH(lkmtp,cmd,ver,skel_handle,skel_handle,nosys)
141 }
142 /*
143 * Skeleton driver entry points for PCCARD configuration.
144 */
145 /*
146 * Initialize the device.
147 */
148 static int
149 skelinit(struct pccard_devinfo *devi)
150 {
151 if ((1 << devi->unit) & opened)
152 return(EBUSY);
153 opened |= 1 << devi->unit;
154 printf("skel%d: init\n", devi->unit);
155 printf("iomem = 0x%x, iobase = 0x%x\n", devi->memory, devi->ioaddr);
156 return(0);
157 }
158 /*
159 * The device entry is being removed. Shut it down,
160 * and turn off interrupts etc. Not called unless
161 * the device was successfully installed.
162 */
163 static void
164 skelunload(struct pccard_devinfo *devi)
165 {
166 printf("skel%d: unload\n", devi->unit);
167 opened &= ~(1 << devi->unit);
168 }
169 /*
170 * Interrupt handler.
171 * Returns true if the interrupt is for us.
172 */
173 static int
174 skelintr(struct pccard_devinfo *devi)
175 {
176 return(0);
177 }
Cache object: 1301d83afb22d41fc9090cef21689671
|