2 # This writes a skeleton driver and puts it into the kernel tree for you.
3 # It also adds FOO and files.FOO configuration files so you can compile
4 # a kernel with your FOO driver linked in.
6 # cd /usr/src; make buildkernel KERNCONF=FOO
8 # More interestingly, it creates a modules/foo directory
9 # which it populates, to allow you to compile a FOO module
10 # which can be linked with your presently running kernel (if you feel brave).
12 # cd /sys/modules/foo; make depend; make; make install; kldload foo
14 # arg1 to this script is expected to be lowercase "foo"
15 # arg2 path to the kernel sources, "/sys" if omitted
17 # Trust me, RUN THIS SCRIPT :)
20 # o generate foo_isa.c, foo_pci.c, foo_pccard.c, foo_cardbus.c, and foovar.h
21 # o Put pccard stuff in here.
26 if [ "X${1}" = "X" ]; then
27 echo "Hey, how about some help here... give me a device name!"
30 if [ "X${2}" = "X" ]; then
32 echo "Using ${TOP} as the path to the kernel sources!"
36 UPPER=`echo ${1} |tr "[:lower:]" "[:upper:]"`
40 if [ -d ${TOP}/modules/${1} ]; then
41 echo "There appears to already be a module called ${1}"
42 echo -n "Should it be overwritten? [Y]"
44 if [ "-z" "$VAL" ]; then
49 echo "Cleaning up from prior runs"
50 rm -rf ${TOP}/dev/${1}
51 rm -rf ${TOP}/modules/${1}
52 rm ${TOP}/conf/files.${UPPER}
53 rm ${TOP}/i386/conf/${UPPER}
54 rm ${TOP}/sys/${1}io.h
62 echo "The following files will be created:"
63 echo ${TOP}/modules/${1}
64 echo ${TOP}/conf/files.${UPPER}
65 echo ${TOP}/i386/conf/${UPPER}
67 echo ${TOP}/dev/${1}/${1}.c
68 echo ${TOP}/sys/${1}io.h
69 echo ${TOP}/modules/${1}
70 echo ${TOP}/modules/${1}/Makefile
72 mkdir ${TOP}/modules/${1}
74 #######################################################################
75 #######################################################################
77 # Create configuration information needed to create a kernel
78 # containing this driver.
80 # Not really needed if we are going to do this as a module.
81 #######################################################################
82 # First add the file to a local file list.
83 #######################################################################
85 cat >${TOP}/conf/files.${UPPER} <<DONE
86 dev/${1}/${1}.c optional ${1}
89 #######################################################################
90 # Then create a configuration file for a kernel that contains this driver.
91 #######################################################################
92 cat >${TOP}/i386/conf/${UPPER} <<DONE
93 # Configuration file for kernel type: ${UPPER}
96 files "${TOP}/conf/files.${UPPER}"
104 cat >>${TOP}/i386/conf/${UPPER} <<DONE
105 # trust me, you'll need this
111 if [ ! -d ${TOP}/dev/${1} ]; then
112 mkdir -p ${TOP}/dev/${1}
115 cat >${TOP}/dev/${1}/${1}.c <<DONE
117 * Copyright (c) [year] [your name]
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions and the following disclaimer.
124 * 2. Redistributions in binary form must reproduce the above copyright
125 * notice, this list of conditions and the following disclaimer in the
126 * documentation and/or other materials provided with the distribution.
128 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
129 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
130 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
131 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
132 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
133 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
134 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
135 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
136 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
137 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
142 * http://www.daemonnews.org/200008/isa.html is required reading.
143 * hopefully it will make it's way into the handbook.
146 #include <sys/cdefs.h>
147 __FBSDID("\$${RCS_KEYWORD}$");
149 #include <sys/param.h>
150 #include <sys/systm.h>
151 #include <sys/conf.h> /* cdevsw stuff */
152 #include <sys/kernel.h> /* SYSINIT stuff */
153 #include <sys/uio.h> /* SYSINIT stuff */
154 #include <sys/malloc.h> /* malloc region definitions */
155 #include <sys/module.h>
157 #include <sys/proc.h>
158 #include <sys/time.h>
159 #include <sys/${1}io.h> /* ${1} IOCTL definitions */
161 #include <machine/bus.h>
162 #include <machine/resource.h>
163 #include <sys/rman.h>
165 #include <dev/pci/pcireg.h>
166 #include <dev/pci/pcivar.h>
168 #include <isa/isavar.h>
172 /* XXX These should be defined in terms of bus-space ops. */
173 #define ${UPPER}_INB(port) inb(port_start)
174 #define ${UPPER}_OUTB(port, val) ( port_start, (val))
175 #define SOME_PORT 123
176 #define EXPECTED_VALUE 0x42
179 * The softc is automatically allocated by the parent bus using the
180 * size specified in the driver_t declaration below.
182 #define DEV2SOFTC(dev) ((struct ${1}_softc *) (dev)->si_drv1)
183 #define DEVICE2SOFTC(dev) ((struct ${1}_softc *) device_get_softc(dev))
186 * Device specific misc defines.
188 #define BUFFERSIZE 1024
190 #define MEMSIZE (4 * 1024) /* Imaginable h/w buffer size. */
193 * One of these per allocated device.
197 bus_space_handle_t bh;
202 struct resource* res_ioport; /* Resource for port range. */
203 struct resource* res_memory; /* Resource for mem range. */
204 struct resource* res_irq; /* Resource for irq range. */
205 struct resource* res_drq; /* Resource for dma channel. */
209 void *vaddr; /* Virtual address of mem resource. */
210 char buffer[BUFFERSIZE]; /* If we need to buffer something. */
213 /* Function prototypes (these should all be static). */
214 static int ${1}_deallocate_resources(device_t device);
215 static int ${1}_allocate_resources(device_t device);
216 static int ${1}_attach(device_t device, struct ${1}_softc *scp);
217 static int ${1}_detach(device_t device, struct ${1}_softc *scp);
219 static d_open_t ${1}open;
220 static d_close_t ${1}close;
221 static d_read_t ${1}read;
222 static d_write_t ${1}write;
223 static d_ioctl_t ${1}ioctl;
224 static d_mmap_t ${1}mmap;
225 static d_poll_t ${1}poll;
226 static void ${1}intr(void *arg);
228 static struct cdevsw ${1}_cdevsw = {
229 .d_version = D_VERSION,
231 .d_close = ${1}close,
233 .d_write = ${1}write,
234 .d_ioctl = ${1}ioctl,
240 static devclass_t ${1}_devclass;
243 ******************************************
244 * ISA Attachment structures and functions.
245 ******************************************
247 static void ${1}_isa_identify (driver_t *, device_t);
248 static int ${1}_isa_probe (device_t);
249 static int ${1}_isa_attach (device_t);
250 static int ${1}_isa_detach (device_t);
252 static struct isa_pnp_id ${1}_ids[] = {
253 {0x12345678, "ABCco Widget"},
254 {0xfedcba98, "shining moon Widget ripoff"},
258 static device_method_t ${1}_methods[] = {
259 DEVMETHOD(device_identify, ${1}_isa_identify),
260 DEVMETHOD(device_probe, ${1}_isa_probe),
261 DEVMETHOD(device_attach, ${1}_isa_attach),
262 DEVMETHOD(device_detach, ${1}_isa_detach),
266 static driver_t ${1}_isa_driver = {
269 sizeof (struct ${1}_softc)
272 DRIVER_MODULE(${1}, isa, ${1}_isa_driver, ${1}_devclass, 0, 0);
275 * Here list some port addresses we might expect our widget to appear at:
276 * This list should only be used for cards that have some non-destructive
277 * (to other cards) way of probing these address. Otherwise the driver
278 * should not go looking for instances of itself, but instead rely on
279 * the hints file. Strange failures for people with other cards might
282 static struct localhints {
288 { 0x210, 11, 2, 0xcd000},
289 { 0x310, 12, 3, 0xdd000},
290 { 0x320, 9, 6, 0xd4000},
294 #define MAXHINTS 10 /* Just an arbitrary safety limit. */
296 * Called once when the driver is somehow connected with the bus,
297 * (Either linked in and the bus is started, or loaded as a module).
299 * The aim of this routine in an ISA driver is to add child entries to
300 * the parent bus so that it looks as if the devices were detected by
301 * some pnp-like method, or at least mentioned in the hints.
303 * For NON-PNP "dumb" devices:
304 * Add entries into the bus's list of likely devices, so that
305 * our 'probe routine' will be called for them.
306 * This is similar to what the 'hints' code achieves, except this is
307 * loadable with the driver.
308 * In the 'dumb' case we end up with more children than needed but
309 * some (or all) of them will fail probe() and only waste a little memory.
311 * For NON-PNP "Smart" devices:
312 * If the device has a NON-PNP way of being detected and setting/sensing
313 * the card, then do that here and add a child for each set of
317 * If the device is always PNP capable then this function can be removed.
318 * The ISA PNP system will have automatically added it to the system and
319 * so your identify routine needn't do anything.
321 * If the device is mentioned in the 'hints' file then this
322 * function can be removed. All devices mentioned in the hints
323 * file get added as children for probing, whether or not the
324 * driver is linked in. So even as a module it MAY still be there.
325 * See isa/isahint.c for hints being added in.
328 ${1}_isa_identify (driver_t *driver, device_t parent)
336 * If we've already got ${UPPER} attached somehow, don't try again.
337 * Maybe it was in the hints file. or it was loaded before.
339 if (device_find_child(parent, "${1}", 0)) {
340 printf("${UPPER}: already attached\n");
343 /* XXX Look at dev/acpica/acpi_isa.c for use of ISA_ADD_CONFIG() macro. */
344 /* XXX What is ISA_SET_CONFIG_CALLBACK(parent, child, pnpbios_set_config, 0)? */
345 for (i = 0; i < MAXHINTS; i++) {
347 ioport = res[i].ioport;
349 if ((ioport == 0) && (irq == 0))
350 return; /* We've added all our local hints. */
352 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "${1}", -1);
353 bus_set_resource(child, SYS_RES_IOPORT, 0, ioport, NUMPORTS);
354 bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1);
355 bus_set_resource(child, SYS_RES_DRQ, 0, res[i].drq, 1);
356 bus_set_resource(child, SYS_RES_MEMORY, 0, res[i].mem, MEMSIZE);
360 * If we wanted to pretend PNP found it
361 * we could do this, and put matching entries
362 * in the PNP table, but I think it's probably too hacky.
363 * As you see, some people have done it though.
364 * Basically EISA (remember that?) would do this I think.
366 isa_set_vendorid(child, PNP_EISAID("ESS1888"));
367 isa_set_logicalid(child, PNP_EISAID("ESS1888"));
372 * Do some smart probing (e.g. like the lnc driver)
373 * and add a child for each one found.
380 * The ISA code calls this for each device it knows about,
381 * whether via the PNP code or via the hints etc.
382 * If the device nas no PNP capabilities, remove all the
383 * PNP entries, but keep the call to ISA_PNP_PROBE()
384 * As it will guard against accidentally recognising
385 * foreign hardware. This is because we will be called to check against
389 ${1}_isa_probe (device_t device)
392 device_t parent = device_get_parent(device);
393 struct ${1}_softc *scp = DEVICE2SOFTC(device);
394 u_long port_start, port_count;
396 bzero(scp, sizeof(*scp));
397 scp->device = device;
400 * Check this device for a PNP match in our table.
401 * There are several possible outcomes.
402 * error == 0 We match a PNP.
403 * error == ENXIO, It is a PNP device but not in our table.
404 * error == ENOENT, It is not a PNP device.. try heuristic probes.
405 * -- logic from if_ed_isa.c, added info from isa/isa_if.m:
407 * If we had a list of devices that we could handle really well,
408 * and a list which we could handle only basic functions, then
409 * we would call this twice, once for each list,
410 * and return a value of '-2' or something if we could
411 * only handle basic functions. This would allow a specific
412 * Widgetplus driver to make a better offer if it knows how to
413 * do all the extended functions. (See non-pnp part for more info).
415 error = ISA_PNP_PROBE(parent, device, ${1}_ids);
419 * We found a PNP device.
420 * Do nothing, as it's all done in attach().
425 * Well it didn't show up in the PNP tables
426 * so look directly at known ports (if we have any)
427 * in case we are looking for an old pre-PNP card.
429 * Hopefully the 'identify' routine will have picked these
430 * up for us first if they use some proprietary detection
433 * The ports, irqs etc should come from a 'hints' section
434 * which is read in by code in isa/isahint.c
435 * and kern/subr_bus.c to create resource entries,
436 * or have been added by the 'identify routine above.
437 * Note that HINTS based resource requests have NO
438 * SIZE for the memory or ports requests (just a base)
439 * so we may need to 'correct' this before we
443 * Find out the values of any resources we
444 * need for our dumb probe. Also check we have enough ports
445 * in the request. (could be hints based).
446 * Should probably do the same for memory regions too.
448 error = bus_get_resource(device, SYS_RES_IOPORT, 0,
449 &port_start, &port_count);
450 if (port_count != NUMPORTS) {
451 bus_set_resource(device, SYS_RES_IOPORT, 0,
452 port_start, NUMPORTS);
456 * Make a temporary resource reservation.
457 * If we can't get the resources we need then
458 * we need to abort. Possibly this indicates
459 * the resources were used by another device
460 * in which case the probe would have failed anyhow.
462 if ((error = (${1}_allocate_resources(device)))) {
467 /* Dummy heuristic type probe. */
468 if (inb(port_start) != EXPECTED_VALUE) {
470 * It isn't what we hoped, so quit looking for it.
474 u_long membase = bus_get_resource_start(device,
475 SYS_RES_MEMORY, 0 /*rid*/);
478 * If we discover in some way that the device has
479 * XXX bytes of memory window, we can override
480 * or set the memory size in the child resource list.
482 memsize = inb(port_start + 1) * 1024; /* for example */
483 error = bus_set_resource(device, SYS_RES_MEMORY,
484 /*rid*/0, membase, memsize);
486 * We found one, return non-positive numbers..
487 * Return -N if we can't handle it, but not well.
488 * Return -2 if we would LIKE the device.
489 * Return -1 if we want it a lot.
490 * Return 0 if we MUST get the device.
491 * This allows drivers to 'bid' for a device.
493 device_set_desc(device, "ACME Widget model 1234");
494 error = -1; /* We want it but someone else
495 may be even better. */
498 * Unreserve the resources for now because
499 * another driver may bid for device too.
500 * If we lose the bid, but still hold the resources, we will
501 * effectively have disabled the other driver from getting them
502 * which will result in neither driver getting the device.
503 * We will ask for them again in attach if we win.
505 ${1}_deallocate_resources(device);
508 /* It was PNP but not ours, leave immediately. */
517 * Called if the probe succeeded and our bid won the device.
518 * We can be destructive here as we know we have the device.
519 * This is the first place we can be sure we have a softc structure.
520 * You would do ISA specific attach things here, but generically there aren't
521 * any (yay new-bus!).
524 ${1}_isa_attach (device_t device)
527 struct ${1}_softc *scp = DEVICE2SOFTC(device);
529 error = ${1}_attach(device, scp);
531 ${1}_isa_detach(device);
536 * Detach the driver (e.g. module unload),
537 * call the bus independent version
538 * and undo anything we did in the ISA attach routine.
541 ${1}_isa_detach (device_t device)
544 struct ${1}_softc *scp = DEVICE2SOFTC(device);
546 error = ${1}_detach(device, scp);
551 ***************************************
552 * PCI Attachment structures and code
553 ***************************************
556 static int ${1}_pci_probe(device_t);
557 static int ${1}_pci_attach(device_t);
558 static int ${1}_pci_detach(device_t);
560 static device_method_t ${1}_pci_methods[] = {
561 /* Device interface */
562 DEVMETHOD(device_probe, ${1}_pci_probe),
563 DEVMETHOD(device_attach, ${1}_pci_attach),
564 DEVMETHOD(device_detach, ${1}_pci_detach),
568 static driver_t ${1}_pci_driver = {
571 sizeof(struct ${1}_softc),
574 DRIVER_MODULE(${1}, pci, ${1}_pci_driver, ${1}_devclass, 0, 0);
576 * Cardbus is a pci bus plus extra, so use the pci driver unless special
577 * things need to be done only in the cardbus case.
579 DRIVER_MODULE(${1}, cardbus, ${1}_pci_driver, ${1}_devclass, 0, 0);
586 { 0x1234abcd, "ACME PCI Widgetplus" },
587 { 0x1243fedc, "Happy moon brand RIPOFFplus" },
592 * See if this card is specifically mentioned in our list of known devices.
593 * Theoretically we might also put in a weak bid for some devices that
594 * report themselves to be some generic type of device if we can handle
595 * that generic type. (other PCI_XXX calls give that info).
596 * This would allow a specific driver to over-ride us.
598 * See the comments in the ISA section regarding returning non-positive
599 * values from probe routines.
602 ${1}_pci_probe (device_t device)
604 u_int32_t type = pci_get_devid(device);
605 struct _pcsid *ep =pci_ids;
607 while (ep->type && ep->type != type)
610 device_set_desc(device, ep->desc);
611 return 0; /* If there might be a better driver, return -2 */
617 ${1}_pci_attach(device_t device)
620 struct ${1}_softc *scp = DEVICE2SOFTC(device);
622 error = ${1}_attach(device, scp);
624 ${1}_pci_detach(device);
629 ${1}_pci_detach (device_t device)
632 struct ${1}_softc *scp = DEVICE2SOFTC(device);
634 error = ${1}_detach(device, scp);
639 ****************************************
640 * Common Attachment sub-functions
641 ****************************************
644 ${1}_attach(device_t device, struct ${1}_softc * scp)
646 device_t parent = device_get_parent(device);
647 int unit = device_get_unit(device);
649 scp->dev = make_dev(&${1}_cdevsw, 0,
650 UID_ROOT, GID_OPERATOR, 0600, "${1}%d", unit);
651 scp->dev->si_drv1 = scp;
653 if (${1}_allocate_resources(device))
656 scp->bt = rman_get_bustag(scp->res_ioport);
657 scp->bh = rman_get_bushandle(scp->res_ioport);
659 /* Register the interrupt handler. */
661 * The type should be one of:
667 * This will probably change with SMPng. INTR_TYPE_FAST may be
668 * OR'd into this type to mark the interrupt fast. However, fast
669 * interrupts cannot be shared at all so special precautions are
670 * necessary when coding fast interrupt routines.
673 /* Default to the tty mask for registration. */ /* XXX */
674 if (BUS_SETUP_INTR(parent, device, scp->res_irq, INTR_TYPE_TTY,
675 ${1}intr, scp, &scp->intr_cookie) == 0) {
676 /* Do something if successful. */
682 * If we want to access the memory we will need
683 * to know where it was mapped.
685 * Use of this function is discouraged, however. You should
686 * be accessing the device with the bus_space API if at all
689 scp->vaddr = rman_get_virtual(scp->res_memory);
694 * Undo anything we may have done.
696 ${1}_detach(device, scp);
701 ${1}_detach(device_t device, struct ${1}_softc *scp)
703 device_t parent = device_get_parent(device);
706 * At this point stick a strong piece of wood into the device
707 * to make sure it is stopped safely. The alternative is to
708 * simply REFUSE to detach if it's busy. What you do depends on
709 * your specific situation.
711 * Sometimes the parent bus will detach you anyway, even if you
712 * are busy. You must cope with that possibility. Your hardware
713 * might even already be gone in the case of cardbus or pccard
716 /* ZAP some register */
719 * Take our interrupt handler out of the list of handlers
720 * that can handle this irq.
722 if (scp->intr_cookie != NULL) {
723 if (BUS_TEARDOWN_INTR(parent, device,
724 scp->res_irq, scp->intr_cookie) != 0)
725 printf("intr teardown failed.. continuing\n");
726 scp->intr_cookie = NULL;
730 * Deallocate any system resources we may have
731 * allocated on behalf of this driver.
734 return ${1}_deallocate_resources(device);
738 ${1}_allocate_resources(device_t device)
741 struct ${1}_softc *scp = DEVICE2SOFTC(device);
742 int size = 16; /* SIZE of port range used. */
744 scp->res_ioport = bus_alloc_resource(device, SYS_RES_IOPORT,
745 &scp->rid_ioport, 0ul, ~0ul, size, RF_ACTIVE);
746 if (scp->res_ioport == NULL)
749 scp->res_irq = bus_alloc_resource(device, SYS_RES_IRQ,
750 &scp->rid_irq, 0ul, ~0ul, 1, RF_SHAREABLE|RF_ACTIVE);
751 if (scp->res_irq == NULL)
754 scp->res_drq = bus_alloc_resource(device, SYS_RES_DRQ,
755 &scp->rid_drq, 0ul, ~0ul, 1, RF_ACTIVE);
756 if (scp->res_drq == NULL)
759 scp->res_memory = bus_alloc_resource(device, SYS_RES_MEMORY,
760 &scp->rid_memory, 0ul, ~0ul, MSIZE, RF_ACTIVE);
761 if (scp->res_memory == NULL)
767 /* Cleanup anything we may have assigned. */
768 ${1}_deallocate_resources(device);
769 return (ENXIO); /* For want of a better idea. */
773 ${1}_deallocate_resources(device_t device)
775 struct ${1}_softc *scp = DEVICE2SOFTC(device);
777 if (scp->res_irq != 0) {
778 bus_deactivate_resource(device, SYS_RES_IRQ,
779 scp->rid_irq, scp->res_irq);
780 bus_release_resource(device, SYS_RES_IRQ,
781 scp->rid_irq, scp->res_irq);
784 if (scp->res_ioport != 0) {
785 bus_deactivate_resource(device, SYS_RES_IOPORT,
786 scp->rid_ioport, scp->res_ioport);
787 bus_release_resource(device, SYS_RES_IOPORT,
788 scp->rid_ioport, scp->res_ioport);
791 if (scp->res_memory != 0) {
792 bus_deactivate_resource(device, SYS_RES_MEMORY,
793 scp->rid_memory, scp->res_memory);
794 bus_release_resource(device, SYS_RES_MEMORY,
795 scp->rid_memory, scp->res_memory);
798 if (scp->res_drq != 0) {
799 bus_deactivate_resource(device, SYS_RES_DRQ,
800 scp->rid_drq, scp->res_drq);
801 bus_release_resource(device, SYS_RES_DRQ,
802 scp->rid_drq, scp->res_drq);
806 destroy_dev(scp->dev);
813 struct ${1}_softc *scp = (struct ${1}_softc *) arg;
816 * Well we got an interrupt, now what?
818 * Make sure that the interrupt routine will always terminate,
819 * even in the face of "bogus" data from the card.
821 (void)scp; /* Delete this line after using scp. */
826 ${1}ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
828 struct ${1}_softc *scp = DEV2SOFTC(dev);
830 (void)scp; /* Delete this line after using scp. */
833 /* Whatever resets it. */
835 ${UPPER}_OUTB(SOME_PORT, 0xff);
844 * You also need read, write, open, close routines.
845 * This should get you started.
848 ${1}open(struct cdev *dev, int oflags, int devtype, struct thread *td)
850 struct ${1}_softc *scp = DEV2SOFTC(dev);
855 (void)scp; /* Delete this line after using scp. */
860 ${1}close(struct cdev *dev, int fflag, int devtype, struct thread *td)
862 struct ${1}_softc *scp = DEV2SOFTC(dev);
867 (void)scp; /* Delete this line after using scp. */
872 ${1}read(struct cdev *dev, struct uio *uio, int ioflag)
874 struct ${1}_softc *scp = DEV2SOFTC(dev);
881 (void)scp; /* Delete this line after using scp. */
882 toread = (min(uio->uio_resid, sizeof(scp->buffer)));
883 return(uiomove(scp->buffer, toread, uio));
887 ${1}write(struct cdev *dev, struct uio *uio, int ioflag)
889 struct ${1}_softc *scp = DEV2SOFTC(dev);
896 (void)scp; /* Delete this line after using scp. */
897 towrite = (min(uio->uio_resid, sizeof(scp->buffer)));
898 return(uiomove(scp->buffer, towrite, uio));
902 ${1}mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
904 struct ${1}_softc *scp = DEV2SOFTC(dev);
907 * Given a byte offset into your device, return the PHYSICAL
908 * page number that it would map to.
910 (void)scp; /* Delete this line after using scp. */
911 #if 0 /* If we had a frame buffer or whatever... do this. */
912 if (offset > FRAMEBUFFERSIZE - PAGE_SIZE)
914 return i386_btop((FRAMEBASE + offset));
921 ${1}poll(struct cdev *dev, int which, struct thread *td)
923 struct ${1}_softc *scp = DEV2SOFTC(dev);
928 (void)scp; /* Delete this line after using scp. */
929 return (0); /* This is the wrong value I'm sure. */
934 cat >${TOP}/sys/${1}io.h <<DONE
936 * Definitions needed to access the ${1} device (ioctls etc)
937 * see mtio.h, ioctl.h as examples.
943 #include <sys/types.h>
945 #include <sys/ioccom.h>
948 * Define an ioctl here.
950 #define DHIOCRESET _IO('D', 0) /* Reset the ${1} device. */
954 if [ ! -d ${TOP}/modules/${1} ]; then
955 mkdir -p ${TOP}/modules/${1}
958 cat >${TOP}/modules/${1}/Makefile <<DONE
959 # ${UPPER} Loadable Kernel Module
961 # \$${RCS_KEYWORD}: $
963 .PATH: \${.CURDIR}/../../dev/${1}
966 SRCS += opt_inet.h device_if.h bus_if.h pci_if.h isa_if.h
968 # You may need to do this is your device is an if_xxx driver.
970 echo "#define INET 1" > opt_inet.h
972 .include <bsd.kmod.mk>
975 echo -n "Do you want to build the '${1}' module? [Y]"
977 if [ "-z" "$VAL" ]; then
982 (cd ${TOP}/modules/${1}; make depend; make )
990 echo -n "Do you want to build the '${UPPER}' kernel? [Y]"
992 if [ "-z" "$VAL" ]; then
998 cd ${TOP}/i386/conf; \
1000 cd ${TOP}/i386/compile/${UPPER}; \
1010 #--------------end of script---------------
1012 # Edit to your taste...