Modernise and tidy up.
This commit is contained in:
parent
fe4f77506e
commit
df0d590aef
@ -69,7 +69,6 @@ echo ${TOP}/sys/${1}io.h
|
||||
echo ${TOP}/modules/${1}
|
||||
echo ${TOP}/modules/${1}/Makefile
|
||||
|
||||
|
||||
mkdir ${TOP}/modules/${1}
|
||||
|
||||
#######################################################################
|
||||
@ -93,7 +92,7 @@ DONE
|
||||
cat >${TOP}/i386/conf/${UPPER} <<DONE
|
||||
# Configuration file for kernel type: ${UPPER}
|
||||
ident ${UPPER}
|
||||
# \$${RCS_KEYWORD}: $
|
||||
# \$${RCS_KEYWORD}$
|
||||
DONE
|
||||
|
||||
grep -v GENERIC < /sys/i386/conf/GENERIC >>${TOP}/i386/conf/${UPPER}
|
||||
@ -108,9 +107,6 @@ then
|
||||
mkdir -p ${TOP}/dev/${1}
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
cat >${TOP}/dev/${1}/${1}.c <<DONE
|
||||
/*
|
||||
* Copyright (c) [year] [your name]
|
||||
@ -136,10 +132,6 @@ cat >${TOP}/dev/${1}/${1}.c <<DONE
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* ${1} driver
|
||||
* \$${RCS_KEYWORD}: $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -147,6 +139,9 @@ cat >${TOP}/dev/${1}/${1}.c <<DONE
|
||||
* hopefully it will make it's way into the handbook.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("\$${RCS_KEYWORD}$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/conf.h> /* cdevsw stuff */
|
||||
@ -156,19 +151,21 @@ cat >${TOP}/dev/${1}/${1}.c <<DONE
|
||||
#include <sys/module.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/${1}io.h> /* ${1} IOCTL definitions */
|
||||
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
#include <machine/bus_pio.h>
|
||||
#include <machine/bus_memio.h>
|
||||
#include <sys/rman.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <pci/pcireg.h>
|
||||
#include <pci/pcivar.h>
|
||||
|
||||
#include <isa/isavar.h>
|
||||
|
||||
#include "isa_if.h"
|
||||
#include <sys/${1}io.h> /* ${1} IOCTL definitions */
|
||||
|
||||
/* XXX These should be defined in terms of bus-space ops */
|
||||
#define ${UPPER}_INB(port) inb(port_start)
|
||||
@ -276,7 +273,6 @@ static driver_t ${1}_isa_driver = {
|
||||
sizeof (struct ${1}_softc)
|
||||
};
|
||||
|
||||
|
||||
DRIVER_MODULE(${1}, isa, ${1}_isa_driver, ${1}_devclass, 0, 0);
|
||||
|
||||
/*
|
||||
@ -340,7 +336,6 @@ ${1}_isa_identify (driver_t *driver, device_t parent)
|
||||
device_t child;
|
||||
int i;
|
||||
|
||||
|
||||
/*
|
||||
* If we've already got ${UPPER} attached somehow, don't try again.
|
||||
* Maybe it was in the hints file. or it was loaded before.
|
||||
@ -355,9 +350,8 @@ ${1}_isa_identify (driver_t *driver, device_t parent)
|
||||
|
||||
ioport = res[i].ioport;
|
||||
irq = res[i].irq;
|
||||
if ((ioport == 0) && (irq == 0)) {
|
||||
if ((ioport == 0) && (irq == 0))
|
||||
return; /* we've added all our local hints */
|
||||
}
|
||||
|
||||
child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "${1}", -1);
|
||||
bus_set_resource(child, SYS_RES_IOPORT, 0, ioport, NUMPORTS);
|
||||
@ -365,7 +359,6 @@ ${1}_isa_identify (driver_t *driver, device_t parent)
|
||||
bus_set_resource(child, SYS_RES_DRQ, 0, res[i].drq, 1);
|
||||
bus_set_resource(child, SYS_RES_MEMORY, 0, res[i].mem, MEMSIZE);
|
||||
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* If we wanted to pretend PNP found it
|
||||
@ -404,7 +397,6 @@ ${1}_isa_probe (device_t device)
|
||||
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
||||
u_long port_start, port_count;
|
||||
|
||||
|
||||
bzero(scp, sizeof(*scp));
|
||||
scp->device = device;
|
||||
|
||||
@ -539,11 +531,9 @@ ${1}_isa_attach (device_t device)
|
||||
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
||||
|
||||
error = ${1}_attach(device, scp);
|
||||
if (error) {
|
||||
if (error)
|
||||
${1}_isa_detach(device);
|
||||
}
|
||||
return (error);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -567,9 +557,9 @@ ${1}_isa_detach (device_t device)
|
||||
***************************************
|
||||
*/
|
||||
|
||||
static int ${1}_pci_probe __P((device_t));
|
||||
static int ${1}_pci_attach __P((device_t));
|
||||
static int ${1}_pci_detach __P((device_t));
|
||||
static int ${1}_pci_probe(device_t);
|
||||
static int ${1}_pci_attach(device_t);
|
||||
static int ${1}_pci_detach(device_t);
|
||||
|
||||
static device_method_t ${1}_pci_methods[] = {
|
||||
/* Device interface */
|
||||
@ -585,7 +575,6 @@ static driver_t ${1}_pci_driver = {
|
||||
sizeof(struct ${1}_softc),
|
||||
};
|
||||
|
||||
|
||||
DRIVER_MODULE(${1}, pci, ${1}_pci_driver, ${1}_devclass, 0, 0);
|
||||
/*
|
||||
* Cardbus is a pci bus plus extra, so use the pci driver unless special
|
||||
@ -624,10 +613,9 @@ ${1}_pci_probe (device_t device)
|
||||
if (ep->desc) {
|
||||
device_set_desc(device, ep->desc);
|
||||
return 0; /* If there might be a better driver, return -2 */
|
||||
} else {
|
||||
} else
|
||||
return ENXIO;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
${1}_pci_attach(device_t device)
|
||||
@ -636,9 +624,8 @@ ${1}_pci_attach(device_t device)
|
||||
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
||||
|
||||
error = ${1}_attach(device, scp);
|
||||
if (error) {
|
||||
if (error)
|
||||
${1}_pci_detach(device);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -652,7 +639,6 @@ ${1}_pci_detach (device_t device)
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************
|
||||
* Common Attachment sub-functions
|
||||
@ -668,9 +654,8 @@ ${1}_attach(device_t device, struct ${1}_softc * scp)
|
||||
UID_ROOT, GID_OPERATOR, 0600, "${1}%d", unit);
|
||||
scp->dev->si_drv1 = scp;
|
||||
|
||||
if (${1}_allocate_resources(device)) {
|
||||
if (${1}_allocate_resources(device))
|
||||
goto errexit;
|
||||
}
|
||||
|
||||
scp->bt = rman_get_bustag(scp->res_ioport);
|
||||
scp->bh = rman_get_bushandle(scp->res_ioport);
|
||||
@ -693,10 +678,9 @@ ${1}_attach(device_t device, struct ${1}_softc * scp)
|
||||
if (BUS_SETUP_INTR(parent, device, scp->res_irq, INTR_TYPE_TTY,
|
||||
${1}intr, scp, &scp->intr_cookie) == 0) {
|
||||
/* do something if successful */
|
||||
} else {
|
||||
} else
|
||||
goto errexit;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If we want to access the memory we will need
|
||||
@ -741,9 +725,8 @@ ${1}_detach(device_t device, struct ${1}_softc *scp)
|
||||
*/
|
||||
if (scp->intr_cookie != NULL) {
|
||||
if (BUS_TEARDOWN_INTR(parent, device,
|
||||
scp->res_irq, scp->intr_cookie) != 0) {
|
||||
scp->res_irq, scp->intr_cookie) != 0)
|
||||
printf("intr teardown failed.. continuing\n");
|
||||
}
|
||||
scp->intr_cookie = NULL;
|
||||
}
|
||||
|
||||
@ -764,27 +747,23 @@ ${1}_allocate_resources(device_t device)
|
||||
|
||||
scp->res_ioport = bus_alloc_resource(device, SYS_RES_IOPORT,
|
||||
&scp->rid_ioport, 0ul, ~0ul, size, RF_ACTIVE);
|
||||
if (scp->res_ioport == NULL) {
|
||||
if (scp->res_ioport == NULL)
|
||||
goto errexit;
|
||||
}
|
||||
|
||||
scp->res_irq = bus_alloc_resource(device, SYS_RES_IRQ,
|
||||
&scp->rid_irq, 0ul, ~0ul, 1, RF_SHAREABLE|RF_ACTIVE);
|
||||
if (scp->res_irq == NULL) {
|
||||
if (scp->res_irq == NULL)
|
||||
goto errexit;
|
||||
}
|
||||
|
||||
scp->res_drq = bus_alloc_resource(device, SYS_RES_DRQ,
|
||||
&scp->rid_drq, 0ul, ~0ul, 1, RF_ACTIVE);
|
||||
if (scp->res_drq == NULL) {
|
||||
if (scp->res_drq == NULL)
|
||||
goto errexit;
|
||||
}
|
||||
|
||||
scp->res_memory = bus_alloc_resource(device, SYS_RES_MEMORY,
|
||||
&scp->rid_memory, 0ul, ~0ul, MSIZE, RF_ACTIVE);
|
||||
if (scp->res_memory == NULL) {
|
||||
if (scp->res_memory == NULL)
|
||||
goto errexit;
|
||||
}
|
||||
return (0);
|
||||
|
||||
errexit:
|
||||
@ -827,9 +806,8 @@ ${1}_deallocate_resources(device_t device)
|
||||
scp->rid_drq, scp->res_drq);
|
||||
scp->res_drq = 0;
|
||||
}
|
||||
if (scp->dev) {
|
||||
if (scp->dev)
|
||||
destroy_dev(scp->dev);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -896,7 +874,6 @@ ${1}read(dev_t dev, struct uio *uio, int ioflag)
|
||||
struct ${1}_softc *scp = DEV2SOFTC(dev);
|
||||
int toread;
|
||||
|
||||
|
||||
/*
|
||||
* Do processing
|
||||
* read from buffer
|
||||
@ -929,9 +906,8 @@ ${1}mmap(dev_t dev, vm_offset_t offset, int nprot)
|
||||
* page number that it would map to.
|
||||
*/
|
||||
#if 0 /* if we had a frame buffer or whatever.. do this */
|
||||
if (offset > FRAMEBUFFERSIZE - PAGE_SIZE) {
|
||||
if (offset > FRAMEBUFFERSIZE - PAGE_SIZE)
|
||||
return (-1);
|
||||
}
|
||||
return i386_btop((FRAMEBASE + offset));
|
||||
#else
|
||||
return (-1);
|
||||
@ -1008,7 +984,3 @@ exit
|
||||
#edit to your taste..
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
#
|
||||
# Trust me, RUN THIS SCRIPT :)
|
||||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
#-------cut here------------------
|
||||
cd /sys/i386/conf
|
||||
|
||||
@ -21,7 +23,7 @@ DONE
|
||||
cat >${UPPER} <<DONE
|
||||
# Configuration file for kernel type: ${UPPER}
|
||||
ident ${UPPER}
|
||||
# \$FreeBSD$"
|
||||
# \$FreeBSD\$
|
||||
DONE
|
||||
|
||||
grep -v GENERIC < GENERIC >>${UPPER}
|
||||
@ -37,24 +39,23 @@ cat >../../dev/${1}.c <<DONE
|
||||
* Copyright ME
|
||||
*
|
||||
* ${1} driver
|
||||
* \$FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("\$FreeBSD\$");
|
||||
|
||||
#include "${1}.h" /* generated file.. defines N${UPPER} */
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h> /* SYSINIT stuff */
|
||||
#include <sys/conf.h> /* cdevsw stuff */
|
||||
#include <sys/devfsext.h> /* DEVFS definitions */
|
||||
#include <sys/malloc.h> /* malloc region definitions */
|
||||
#include <sys/proc.h>
|
||||
#include <machine/clock.h> /* DELAY() */
|
||||
#include <sys/${1}io.h> /* ${1} IOCTL definitions */
|
||||
#ifdef DEVFS
|
||||
#include <sys/devfsext.h> /* DEVFS defintitions */
|
||||
#endif /* DEVFS */
|
||||
|
||||
#include <machine/clock.h> /* DELAY() */
|
||||
|
||||
#include "${1}.h" /* generated file.. defines N${UPPER} */
|
||||
|
||||
/* Function prototypes (these should all be static) */
|
||||
static d_open_t ${1}open;
|
||||
@ -80,7 +81,8 @@ static struct cdevsw ${1}_cdevsw = {
|
||||
NULL,
|
||||
"${1}",
|
||||
NULL,
|
||||
-1 };
|
||||
-1
|
||||
};
|
||||
|
||||
/*
|
||||
* device specific Misc defines
|
||||
@ -94,9 +96,7 @@ static struct cdevsw ${1}_cdevsw = {
|
||||
struct ${1}_softc {
|
||||
struct isa_device *dev;
|
||||
char buffer[BUFFERSIZE];
|
||||
#ifdef DEVFS
|
||||
static void *devfs_token;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct ${1}_softc *sc_p;
|
||||
@ -121,13 +121,15 @@ do { /* the do-while is a safe way to do this grouping */ \
|
||||
return (RETVAL); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
#define CHECKUNIT_DIAG(RETVAL) CHECKUNIT(RETVAL)
|
||||
#else /* DIAGNOSTIC */
|
||||
#define CHECKUNIT_DIAG(RETVAL)
|
||||
#endif /* DIAGNOSTIC */
|
||||
|
||||
int ${1}ioctl (dev_t dev, int cmd, caddr_t data, int flag, struct thread *td)
|
||||
static int
|
||||
${1}ioctl (dev_t dev, int cmd, caddr_t data, int flag, struct thread *td)
|
||||
{
|
||||
int unit = UNIT(dev);
|
||||
sc_p scp = sca[unit];
|
||||
@ -144,6 +146,7 @@ int ${1}ioctl (dev_t dev, int cmd, caddr_t data, int flag, struct thread *td)
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* You also need read, write, open, close routines.
|
||||
* This should get you started
|
||||
@ -269,17 +272,13 @@ ${1}_drvinit(void *unused)
|
||||
return;
|
||||
}
|
||||
sca[unit] = scp;
|
||||
#if DEVFS
|
||||
scp->devfs_token = devfs_add_devswf(&${1}_cdevsw, unit, DV_CHR,
|
||||
UID_ROOT, GID_KMEM, 0640, "${1}%d", unit);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
SYSINIT(${1}dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+CDEV_MAJOR,
|
||||
${1}_drvinit, NULL)
|
||||
|
||||
|
||||
DONE
|
||||
|
||||
cat >../../sys/${1}io.h <<DONE
|
||||
@ -317,5 +316,3 @@ exit
|
||||
#edit to your taste..
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user