2002-08-02 10:37:22 +00:00
|
|
|
#!/bin/sh
|
2000-11-08 21:54:28 +00:00
|
|
|
# This writes a skeleton driver and puts it into the kernel tree for you.
|
|
|
|
# It also adds FOO and files.FOO configuration files so you can compile
|
|
|
|
# a kernel with your FOO driver linked in.
|
|
|
|
# To do so:
|
2001-04-14 18:51:39 +00:00
|
|
|
# cd /usr/src; make buildkernel KERNCONF=FOO
|
1997-02-02 07:19:30 +00:00
|
|
|
#
|
2000-11-08 21:54:28 +00:00
|
|
|
# More interestingly, it creates a modules/foo directory
|
|
|
|
# which it populates, to allow you to compile a FOO module
|
2001-04-14 18:51:39 +00:00
|
|
|
# which can be linked with your presently running kernel (if you feel brave).
|
2000-11-08 21:54:28 +00:00
|
|
|
# To do so:
|
|
|
|
# cd /sys/modules/foo; make depend; make; make install; kldload foo
|
|
|
|
#
|
2002-08-02 10:37:22 +00:00
|
|
|
# arg1 to this script is expected to be lowercase "foo"
|
2006-08-06 11:06:35 +00:00
|
|
|
# arg2 path to the kernel sources, "/sys" if omitted
|
1998-01-12 07:47:03 +00:00
|
|
|
#
|
1997-02-02 07:19:30 +00:00
|
|
|
# Trust me, RUN THIS SCRIPT :)
|
2000-11-08 21:54:28 +00:00
|
|
|
#
|
2000-12-18 21:08:53 +00:00
|
|
|
# TODO:
|
|
|
|
# o generate foo_isa.c, foo_pci.c, foo_pccard.c, foo_cardbus.c, and foovar.h
|
|
|
|
# o Put pccard stuff in here.
|
|
|
|
#
|
2000-10-24 16:45:58 +00:00
|
|
|
# $FreeBSD$"
|
1997-02-02 07:19:30 +00:00
|
|
|
#
|
2000-11-11 09:49:49 +00:00
|
|
|
#
|
2003-10-03 19:31:55 +00:00
|
|
|
if [ "X${1}" = "X" ]; then
|
|
|
|
echo "Hey, how about some help here... give me a device name!"
|
1997-02-02 07:19:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2006-08-06 11:06:35 +00:00
|
|
|
if [ "X${2}" = "X" ]; then
|
|
|
|
TOP=`cd /sys; pwd -P`
|
|
|
|
echo "Using ${TOP} as the path to the kernel sources!"
|
|
|
|
else
|
|
|
|
TOP=${2}
|
|
|
|
fi
|
2002-08-02 10:37:22 +00:00
|
|
|
UPPER=`echo ${1} |tr "[:lower:]" "[:upper:]"`
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2000-10-26 21:53:37 +00:00
|
|
|
RCS_KEYWORD=FreeBSD
|
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
if [ -d ${TOP}/modules/${1} ]; then
|
2000-11-08 21:54:28 +00:00
|
|
|
echo "There appears to already be a module called ${1}"
|
|
|
|
echo -n "Should it be overwritten? [Y]"
|
|
|
|
read VAL
|
2003-10-03 19:31:55 +00:00
|
|
|
if [ "-z" "$VAL" ]; then
|
|
|
|
VAL=YES
|
2000-11-08 21:54:28 +00:00
|
|
|
fi
|
2002-08-02 10:37:22 +00:00
|
|
|
case ${VAL} in
|
2000-11-08 21:54:28 +00:00
|
|
|
[yY]*)
|
2003-10-03 19:31:55 +00:00
|
|
|
echo "Cleaning up from prior runs"
|
|
|
|
rm -rf ${TOP}/dev/${1}
|
|
|
|
rm -rf ${TOP}/modules/${1}
|
2006-08-06 11:06:35 +00:00
|
|
|
rm ${TOP}/conf/files.${UPPER}
|
2003-10-03 19:31:55 +00:00
|
|
|
rm ${TOP}/i386/conf/${UPPER}
|
|
|
|
rm ${TOP}/sys/${1}io.h
|
|
|
|
;;
|
2000-11-08 21:54:28 +00:00
|
|
|
*)
|
2003-10-03 19:31:55 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
2000-11-08 21:54:28 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "The following files will be created:"
|
2000-10-24 16:45:58 +00:00
|
|
|
echo ${TOP}/modules/${1}
|
2006-08-06 11:06:35 +00:00
|
|
|
echo ${TOP}/conf/files.${UPPER}
|
2000-10-24 16:45:58 +00:00
|
|
|
echo ${TOP}/i386/conf/${UPPER}
|
|
|
|
echo ${TOP}/dev/${1}
|
|
|
|
echo ${TOP}/dev/${1}/${1}.c
|
|
|
|
echo ${TOP}/sys/${1}io.h
|
|
|
|
echo ${TOP}/modules/${1}
|
|
|
|
echo ${TOP}/modules/${1}/Makefile
|
|
|
|
|
|
|
|
mkdir ${TOP}/modules/${1}
|
1998-01-12 07:47:03 +00:00
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
#######################################################################
|
|
|
|
#######################################################################
|
|
|
|
#
|
|
|
|
# Create configuration information needed to create a kernel
|
|
|
|
# containing this driver.
|
|
|
|
#
|
|
|
|
# Not really needed if we are going to do this as a module.
|
|
|
|
#######################################################################
|
|
|
|
# First add the file to a local file list.
|
|
|
|
#######################################################################
|
|
|
|
|
2006-08-06 11:06:35 +00:00
|
|
|
cat >${TOP}/conf/files.${UPPER} <<DONE
|
2000-10-26 21:37:38 +00:00
|
|
|
dev/${1}/${1}.c optional ${1}
|
1997-02-02 07:19:30 +00:00
|
|
|
DONE
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
#######################################################################
|
|
|
|
# Then create a configuration file for a kernel that contains this driver.
|
|
|
|
#######################################################################
|
|
|
|
cat >${TOP}/i386/conf/${UPPER} <<DONE
|
1997-02-02 07:19:30 +00:00
|
|
|
# Configuration file for kernel type: ${UPPER}
|
2002-08-02 10:37:22 +00:00
|
|
|
# \$${RCS_KEYWORD}$
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2006-08-09 10:53:26 +00:00
|
|
|
files "${TOP}/conf/files.${UPPER}"
|
|
|
|
|
2006-08-06 11:06:35 +00:00
|
|
|
include GENERIC
|
|
|
|
|
|
|
|
ident ${UPPER}
|
|
|
|
|
|
|
|
DONE
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
cat >>${TOP}/i386/conf/${UPPER} <<DONE
|
2006-08-09 10:53:26 +00:00
|
|
|
# trust me, you'll need this
|
|
|
|
options KDB
|
|
|
|
options DDB
|
2000-10-26 21:37:38 +00:00
|
|
|
device ${1}
|
1997-02-02 07:19:30 +00:00
|
|
|
DONE
|
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
if [ ! -d ${TOP}/dev/${1} ]; then
|
2000-10-24 16:45:58 +00:00
|
|
|
mkdir -p ${TOP}/dev/${1}
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat >${TOP}/dev/${1}/${1}.c <<DONE
|
1997-02-02 07:19:30 +00:00
|
|
|
/*
|
2000-10-26 21:53:37 +00:00
|
|
|
* Copyright (c) [year] [your name]
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* 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.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
|
|
|
|
2000-11-09 18:55:44 +00:00
|
|
|
/*
|
|
|
|
* http://www.daemonnews.org/200008/isa.html is required reading.
|
|
|
|
* hopefully it will make it's way into the handbook.
|
|
|
|
*/
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("\$${RCS_KEYWORD}$");
|
|
|
|
|
1997-02-02 07:19:30 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h> /* cdevsw stuff */
|
2000-10-24 16:45:58 +00:00
|
|
|
#include <sys/kernel.h> /* SYSINIT stuff */
|
|
|
|
#include <sys/uio.h> /* SYSINIT stuff */
|
1997-02-02 07:19:30 +00:00
|
|
|
#include <sys/malloc.h> /* malloc region definitions */
|
2000-10-24 16:45:58 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
2001-11-13 17:58:14 +00:00
|
|
|
#include <sys/proc.h>
|
2002-08-02 10:37:22 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/${1}io.h> /* ${1} IOCTL definitions */
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
2003-10-03 19:15:07 +00:00
|
|
|
#include <sys/rman.h>
|
2000-10-24 16:45:58 +00:00
|
|
|
|
2003-10-03 19:15:07 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2000-11-11 09:49:49 +00:00
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
#include <isa/isavar.h>
|
2002-08-02 10:37:22 +00:00
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
#include "isa_if.h"
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
/* XXX These should be defined in terms of bus-space ops. */
|
2000-11-08 21:54:28 +00:00
|
|
|
#define ${UPPER}_INB(port) inb(port_start)
|
|
|
|
#define ${UPPER}_OUTB(port, val) ( port_start, (val))
|
2000-10-24 16:45:58 +00:00
|
|
|
#define SOME_PORT 123
|
|
|
|
#define EXPECTED_VALUE 0x42
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2001-04-14 18:51:39 +00:00
|
|
|
/*
|
|
|
|
* The softc is automatically allocated by the parent bus using the
|
2003-10-03 19:31:55 +00:00
|
|
|
* size specified in the driver_t declaration below.
|
2001-04-14 18:51:39 +00:00
|
|
|
*/
|
2000-12-18 21:08:53 +00:00
|
|
|
#define DEV2SOFTC(dev) ((struct ${1}_softc *) (dev)->si_drv1)
|
|
|
|
#define DEVICE2SOFTC(dev) ((struct ${1}_softc *) device_get_softc(dev))
|
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Device specific misc defines.
|
2000-11-11 09:49:49 +00:00
|
|
|
*/
|
|
|
|
#define BUFFERSIZE 1024
|
|
|
|
#define NUMPORTS 4
|
2003-10-03 19:31:55 +00:00
|
|
|
#define MEMSIZE (4 * 1024) /* Imaginable h/w buffer size. */
|
2000-11-11 09:49:49 +00:00
|
|
|
|
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* One of these per allocated device.
|
2000-11-11 09:49:49 +00:00
|
|
|
*/
|
|
|
|
struct ${1}_softc {
|
|
|
|
bus_space_tag_t bt;
|
|
|
|
bus_space_handle_t bh;
|
|
|
|
int rid_ioport;
|
|
|
|
int rid_memory;
|
|
|
|
int rid_irq;
|
|
|
|
int rid_drq;
|
2003-10-03 19:31:55 +00:00
|
|
|
struct resource* res_ioport; /* Resource for port range. */
|
|
|
|
struct resource* res_memory; /* Resource for mem range. */
|
|
|
|
struct resource* res_irq; /* Resource for irq range. */
|
|
|
|
struct resource* res_drq; /* Resource for dma channel. */
|
2000-11-11 09:49:49 +00:00
|
|
|
device_t device;
|
2006-08-06 11:04:22 +00:00
|
|
|
struct cdev *dev;
|
2000-11-11 09:49:49 +00:00
|
|
|
void *intr_cookie;
|
2003-10-03 19:31:55 +00:00
|
|
|
void *vaddr; /* Virtual address of mem resource. */
|
|
|
|
char buffer[BUFFERSIZE]; /* If we need to buffer something. */
|
2002-08-02 10:37:22 +00:00
|
|
|
};
|
2000-11-11 09:49:49 +00:00
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
/* Function prototypes (these should all be static). */
|
2000-10-26 21:37:38 +00:00
|
|
|
static int ${1}_deallocate_resources(device_t device);
|
|
|
|
static int ${1}_allocate_resources(device_t device);
|
2000-12-18 21:08:53 +00:00
|
|
|
static int ${1}_attach(device_t device, struct ${1}_softc *scp);
|
|
|
|
static int ${1}_detach(device_t device, struct ${1}_softc *scp);
|
2000-10-24 16:45:58 +00:00
|
|
|
|
|
|
|
static d_open_t ${1}open;
|
|
|
|
static d_close_t ${1}close;
|
|
|
|
static d_read_t ${1}read;
|
|
|
|
static d_write_t ${1}write;
|
|
|
|
static d_ioctl_t ${1}ioctl;
|
|
|
|
static d_mmap_t ${1}mmap;
|
|
|
|
static d_poll_t ${1}poll;
|
2000-10-25 15:08:11 +00:00
|
|
|
static void ${1}intr(void *arg);
|
2002-08-02 10:37:22 +00:00
|
|
|
|
1997-02-02 07:19:30 +00:00
|
|
|
static struct cdevsw ${1}_cdevsw = {
|
2006-08-06 11:04:22 +00:00
|
|
|
.d_version = D_VERSION,
|
2003-10-03 19:15:07 +00:00
|
|
|
.d_open = ${1}open,
|
|
|
|
.d_close = ${1}close,
|
|
|
|
.d_read = ${1}read,
|
|
|
|
.d_write = ${1}write,
|
|
|
|
.d_ioctl = ${1}ioctl,
|
|
|
|
.d_poll = ${1}poll,
|
|
|
|
.d_mmap = ${1}mmap,
|
|
|
|
.d_name = "${1}",
|
2000-10-24 16:45:58 +00:00
|
|
|
};
|
2000-11-12 10:46:38 +00:00
|
|
|
|
|
|
|
static devclass_t ${1}_devclass;
|
2002-08-02 10:37:22 +00:00
|
|
|
|
2000-12-18 21:08:53 +00:00
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
******************************************
|
|
|
|
* ISA Attachment structures and functions.
|
|
|
|
******************************************
|
2000-12-18 21:08:53 +00:00
|
|
|
*/
|
2000-11-11 09:49:49 +00:00
|
|
|
static void ${1}_isa_identify (driver_t *, device_t);
|
|
|
|
static int ${1}_isa_probe (device_t);
|
|
|
|
static int ${1}_isa_attach (device_t);
|
|
|
|
static int ${1}_isa_detach (device_t);
|
2000-10-24 16:45:58 +00:00
|
|
|
|
|
|
|
static struct isa_pnp_id ${1}_ids[] = {
|
2000-11-09 18:55:44 +00:00
|
|
|
{0x12345678, "ABCco Widget"},
|
|
|
|
{0xfedcba98, "shining moon Widget ripoff"},
|
|
|
|
{0, NULL}
|
2000-10-24 16:45:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static device_method_t ${1}_methods[] = {
|
2000-11-08 21:54:28 +00:00
|
|
|
DEVMETHOD(device_identify, ${1}_isa_identify),
|
2000-10-24 16:45:58 +00:00
|
|
|
DEVMETHOD(device_probe, ${1}_isa_probe),
|
|
|
|
DEVMETHOD(device_attach, ${1}_isa_attach),
|
|
|
|
DEVMETHOD(device_detach, ${1}_isa_detach),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ${1}_isa_driver = {
|
|
|
|
"${1}",
|
|
|
|
${1}_methods,
|
|
|
|
sizeof (struct ${1}_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
DRIVER_MODULE(${1}, isa, ${1}_isa_driver, ${1}_devclass, 0, 0);
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2000-11-08 21:54:28 +00:00
|
|
|
/*
|
|
|
|
* Here list some port addresses we might expect our widget to appear at:
|
2000-12-18 21:08:53 +00:00
|
|
|
* This list should only be used for cards that have some non-destructive
|
|
|
|
* (to other cards) way of probing these address. Otherwise the driver
|
|
|
|
* should not go looking for instances of itself, but instead rely on
|
|
|
|
* the hints file. Strange failures for people with other cards might
|
|
|
|
* result.
|
2000-11-08 21:54:28 +00:00
|
|
|
*/
|
|
|
|
static struct localhints {
|
|
|
|
int ioport;
|
|
|
|
int irq;
|
|
|
|
int drq;
|
|
|
|
int mem;
|
|
|
|
} res[] = {
|
|
|
|
{ 0x210, 11, 2, 0xcd000},
|
|
|
|
{ 0x310, 12, 3, 0xdd000},
|
|
|
|
{ 0x320, 9, 6, 0xd4000},
|
|
|
|
{0,0,0,0}
|
|
|
|
};
|
2000-10-24 16:45:58 +00:00
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
#define MAXHINTS 10 /* Just an arbitrary safety limit. */
|
2000-11-08 21:54:28 +00:00
|
|
|
/*
|
2000-11-09 18:55:44 +00:00
|
|
|
* Called once when the driver is somehow connected with the bus,
|
|
|
|
* (Either linked in and the bus is started, or loaded as a module).
|
|
|
|
*
|
|
|
|
* The aim of this routine in an ISA driver is to add child entries to
|
|
|
|
* the parent bus so that it looks as if the devices were detected by
|
2001-04-14 18:51:39 +00:00
|
|
|
* some pnp-like method, or at least mentioned in the hints.
|
2000-11-09 18:55:44 +00:00
|
|
|
*
|
|
|
|
* For NON-PNP "dumb" devices:
|
|
|
|
* Add entries into the bus's list of likely devices, so that
|
2000-11-08 21:54:28 +00:00
|
|
|
* our 'probe routine' will be called for them.
|
|
|
|
* This is similar to what the 'hints' code achieves, except this is
|
|
|
|
* loadable with the driver.
|
2000-11-09 18:55:44 +00:00
|
|
|
* In the 'dumb' case we end up with more children than needed but
|
|
|
|
* some (or all) of them will fail probe() and only waste a little memory.
|
|
|
|
*
|
|
|
|
* For NON-PNP "Smart" devices:
|
|
|
|
* If the device has a NON-PNP way of being detected and setting/sensing
|
|
|
|
* the card, then do that here and add a child for each set of
|
2002-08-02 10:37:22 +00:00
|
|
|
* hardware found.
|
2000-11-09 18:55:44 +00:00
|
|
|
*
|
|
|
|
* For PNP devices:
|
|
|
|
* If the device is always PNP capable then this function can be removed.
|
2000-12-18 21:08:53 +00:00
|
|
|
* The ISA PNP system will have automatically added it to the system and
|
|
|
|
* so your identify routine needn't do anything.
|
2000-11-09 18:55:44 +00:00
|
|
|
*
|
2001-04-14 18:51:39 +00:00
|
|
|
* If the device is mentioned in the 'hints' file then this
|
|
|
|
* function can be removed. All devices mentioned in the hints
|
2000-11-09 18:55:44 +00:00
|
|
|
* file get added as children for probing, whether or not the
|
|
|
|
* driver is linked in. So even as a module it MAY still be there.
|
|
|
|
* See isa/isahint.c for hints being added in.
|
2000-11-08 21:54:28 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
${1}_isa_identify (driver_t *driver, device_t parent)
|
|
|
|
{
|
|
|
|
u_int32_t irq=0;
|
|
|
|
u_int32_t ioport;
|
|
|
|
device_t child;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we've already got ${UPPER} attached somehow, don't try again.
|
2000-11-09 18:55:44 +00:00
|
|
|
* Maybe it was in the hints file. or it was loaded before.
|
2000-11-08 21:54:28 +00:00
|
|
|
*/
|
|
|
|
if (device_find_child(parent, "${1}", 0)) {
|
|
|
|
printf("${UPPER}: already attached\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-10-03 19:31:55 +00:00
|
|
|
/* XXX Look at dev/acpica/acpi_isa.c for use of ISA_ADD_CONFIG() macro. */
|
|
|
|
/* XXX What is ISA_SET_CONFIG_CALLBACK(parent, child, pnpbios_set_config, 0)? */
|
2000-11-08 21:54:28 +00:00
|
|
|
for (i = 0; i < MAXHINTS; i++) {
|
2000-11-15 12:05:21 +00:00
|
|
|
|
|
|
|
ioport = res[i].ioport;
|
|
|
|
irq = res[i].irq;
|
2002-08-02 10:37:22 +00:00
|
|
|
if ((ioport == 0) && (irq == 0))
|
2003-10-03 19:31:55 +00:00
|
|
|
return; /* We've added all our local hints. */
|
2000-11-08 21:54:28 +00:00
|
|
|
|
|
|
|
child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "${1}", -1);
|
|
|
|
bus_set_resource(child, SYS_RES_IOPORT, 0, ioport, NUMPORTS);
|
|
|
|
bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1);
|
|
|
|
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
|
|
|
|
* we could do this, and put matching entries
|
|
|
|
* in the PNP table, but I think it's probably too hacky.
|
|
|
|
* As you see, some people have done it though.
|
2003-10-03 19:31:55 +00:00
|
|
|
* Basically EISA (remember that?) would do this I think.
|
2000-11-08 21:54:28 +00:00
|
|
|
*/
|
|
|
|
isa_set_vendorid(child, PNP_EISAID("ESS1888"));
|
|
|
|
isa_set_logicalid(child, PNP_EISAID("ESS1888"));
|
|
|
|
#endif
|
|
|
|
}
|
2000-11-09 18:55:44 +00:00
|
|
|
#if 0
|
2000-12-18 21:08:53 +00:00
|
|
|
/*
|
|
|
|
* Do some smart probing (e.g. like the lnc driver)
|
|
|
|
* and add a child for each one found.
|
|
|
|
*/
|
2000-11-09 18:55:44 +00:00
|
|
|
#endif
|
2000-11-08 21:54:28 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2000-10-24 16:45:58 +00:00
|
|
|
/*
|
|
|
|
* The ISA code calls this for each device it knows about,
|
|
|
|
* whether via the PNP code or via the hints etc.
|
2002-08-02 10:37:22 +00:00
|
|
|
* If the device nas no PNP capabilities, remove all the
|
2000-11-09 18:55:44 +00:00
|
|
|
* PNP entries, but keep the call to ISA_PNP_PROBE()
|
|
|
|
* As it will guard against accidentally recognising
|
|
|
|
* foreign hardware. This is because we will be called to check against
|
|
|
|
* ALL PNP hardware.
|
2000-10-24 16:45:58 +00:00
|
|
|
*/
|
1997-02-02 07:19:30 +00:00
|
|
|
static int
|
2000-10-24 16:45:58 +00:00
|
|
|
${1}_isa_probe (device_t device)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-10-24 16:45:58 +00:00
|
|
|
int error;
|
2000-11-08 21:54:28 +00:00
|
|
|
device_t parent = device_get_parent(device);
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
2000-11-08 21:54:28 +00:00
|
|
|
u_long port_start, port_count;
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
bzero(scp, sizeof(*scp));
|
|
|
|
scp->device = device;
|
1997-02-02 07:19:30 +00:00
|
|
|
|
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Check this device for a PNP match in our table.
|
2000-10-24 16:45:58 +00:00
|
|
|
* There are several possible outcomes.
|
2003-10-03 19:31:55 +00:00
|
|
|
* error == 0 We match a PNP.
|
2001-04-14 18:51:39 +00:00
|
|
|
* error == ENXIO, It is a PNP device but not in our table.
|
|
|
|
* error == ENOENT, It is not a PNP device.. try heuristic probes.
|
2000-10-24 16:45:58 +00:00
|
|
|
* -- logic from if_ed_isa.c, added info from isa/isa_if.m:
|
2000-11-15 12:05:21 +00:00
|
|
|
*
|
|
|
|
* If we had a list of devices that we could handle really well,
|
|
|
|
* and a list which we could handle only basic functions, then
|
|
|
|
* we would call this twice, once for each list,
|
|
|
|
* and return a value of '-2' or something if we could
|
|
|
|
* only handle basic functions. This would allow a specific
|
|
|
|
* Widgetplus driver to make a better offer if it knows how to
|
2003-10-03 19:31:55 +00:00
|
|
|
* do all the extended functions. (See non-pnp part for more info).
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2000-11-08 21:54:28 +00:00
|
|
|
error = ISA_PNP_PROBE(parent, device, ${1}_ids);
|
2000-10-24 16:45:58 +00:00
|
|
|
switch (error) {
|
|
|
|
case 0:
|
|
|
|
/*
|
|
|
|
* We found a PNP device.
|
2003-10-03 19:31:55 +00:00
|
|
|
* Do nothing, as it's all done in attach().
|
2000-10-24 16:45:58 +00:00
|
|
|
*/
|
2000-10-26 21:37:38 +00:00
|
|
|
break;
|
2000-10-24 16:45:58 +00:00
|
|
|
case ENOENT:
|
|
|
|
/*
|
|
|
|
* Well it didn't show up in the PNP tables
|
|
|
|
* so look directly at known ports (if we have any)
|
|
|
|
* in case we are looking for an old pre-PNP card.
|
2002-08-02 10:37:22 +00:00
|
|
|
*
|
2000-11-08 21:54:28 +00:00
|
|
|
* Hopefully the 'identify' routine will have picked these
|
2000-11-15 12:05:21 +00:00
|
|
|
* up for us first if they use some proprietary detection
|
|
|
|
* method.
|
2000-10-24 16:45:58 +00:00
|
|
|
*
|
2000-11-15 12:05:21 +00:00
|
|
|
* The ports, irqs etc should come from a 'hints' section
|
2000-10-24 16:45:58 +00:00
|
|
|
* which is read in by code in isa/isahint.c
|
2000-11-09 18:55:44 +00:00
|
|
|
* and kern/subr_bus.c to create resource entries,
|
|
|
|
* or have been added by the 'identify routine above.
|
2001-04-14 18:51:39 +00:00
|
|
|
* Note that HINTS based resource requests have NO
|
2000-11-15 12:05:21 +00:00
|
|
|
* SIZE for the memory or ports requests (just a base)
|
|
|
|
* so we may need to 'correct' this before we
|
|
|
|
* do any probing.
|
|
|
|
*/
|
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Find out the values of any resources we
|
2002-08-02 10:37:22 +00:00
|
|
|
* need for our dumb probe. Also check we have enough ports
|
|
|
|
* in the request. (could be hints based).
|
2000-11-15 12:05:21 +00:00
|
|
|
* Should probably do the same for memory regions too.
|
|
|
|
*/
|
|
|
|
error = bus_get_resource(device, SYS_RES_IOPORT, 0,
|
2002-08-02 10:37:22 +00:00
|
|
|
&port_start, &port_count);
|
2000-11-15 12:05:21 +00:00
|
|
|
if (port_count != NUMPORTS) {
|
|
|
|
bus_set_resource(device, SYS_RES_IOPORT, 0,
|
2002-08-02 10:37:22 +00:00
|
|
|
port_start, NUMPORTS);
|
2000-11-15 12:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make a temporary resource reservation.
|
2000-11-09 18:55:44 +00:00
|
|
|
* If we can't get the resources we need then
|
|
|
|
* we need to abort. Possibly this indicates
|
2000-11-15 12:05:21 +00:00
|
|
|
* the resources were used by another device
|
|
|
|
* in which case the probe would have failed anyhow.
|
2000-10-24 16:45:58 +00:00
|
|
|
*/
|
2000-11-09 18:55:44 +00:00
|
|
|
if ((error = (${1}_allocate_resources(device)))) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto errexit;
|
2000-11-08 21:54:28 +00:00
|
|
|
}
|
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
/* Dummy heuristic type probe. */
|
2002-08-02 10:37:22 +00:00
|
|
|
if (inb(port_start) != EXPECTED_VALUE) {
|
|
|
|
/*
|
2000-11-08 21:54:28 +00:00
|
|
|
* It isn't what we hoped, so quit looking for it.
|
2000-10-26 21:37:38 +00:00
|
|
|
*/
|
|
|
|
error = ENXIO;
|
|
|
|
} else {
|
2000-11-09 18:55:44 +00:00
|
|
|
u_long membase = bus_get_resource_start(device,
|
|
|
|
SYS_RES_MEMORY, 0 /*rid*/);
|
|
|
|
u_long memsize;
|
|
|
|
/*
|
|
|
|
* If we discover in some way that the device has
|
|
|
|
* XXX bytes of memory window, we can override
|
|
|
|
* or set the memory size in the child resource list.
|
|
|
|
*/
|
|
|
|
memsize = inb(port_start + 1) * 1024; /* for example */
|
|
|
|
error = bus_set_resource(device, SYS_RES_MEMORY,
|
|
|
|
/*rid*/0, membase, memsize);
|
2000-10-26 21:37:38 +00:00
|
|
|
/*
|
2000-11-15 12:05:21 +00:00
|
|
|
* We found one, return non-positive numbers..
|
|
|
|
* Return -N if we cant handle it, but not well.
|
2003-10-03 19:31:55 +00:00
|
|
|
* Return -2 if we would LIKE the device.
|
|
|
|
* Return -1 if we want it a lot.
|
|
|
|
* Return 0 if we MUST get the device.
|
2000-11-09 18:55:44 +00:00
|
|
|
* This allows drivers to 'bid' for a device.
|
2000-10-24 16:45:58 +00:00
|
|
|
*/
|
2000-11-09 18:55:44 +00:00
|
|
|
device_set_desc(device, "ACME Widget model 1234");
|
2003-10-03 19:31:55 +00:00
|
|
|
error = -1; /* We want it but someone else
|
|
|
|
may be even better. */
|
2000-10-24 16:45:58 +00:00
|
|
|
}
|
2000-11-09 18:55:44 +00:00
|
|
|
/*
|
|
|
|
* Unreserve the resources for now because
|
|
|
|
* another driver may bid for device too.
|
2001-04-14 18:51:39 +00:00
|
|
|
* If we lose the bid, but still hold the resources, we will
|
|
|
|
* effectively have disabled the other driver from getting them
|
2000-11-09 18:55:44 +00:00
|
|
|
* which will result in neither driver getting the device.
|
|
|
|
* We will ask for them again in attach if we win.
|
|
|
|
*/
|
|
|
|
${1}_deallocate_resources(device);
|
2000-10-24 16:45:58 +00:00
|
|
|
break;
|
|
|
|
case ENXIO:
|
2003-10-03 19:31:55 +00:00
|
|
|
/* It was PNP but not ours, leave immediately. */
|
2000-10-24 16:45:58 +00:00
|
|
|
default:
|
|
|
|
error = ENXIO;
|
|
|
|
}
|
2000-11-09 18:55:44 +00:00
|
|
|
errexit:
|
2000-10-24 16:45:58 +00:00
|
|
|
return (error);
|
1997-02-02 07:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-11-09 18:55:44 +00:00
|
|
|
* Called if the probe succeeded and our bid won the device.
|
1997-02-02 07:19:30 +00:00
|
|
|
* We can be destructive here as we know we have the device.
|
2000-11-09 18:55:44 +00:00
|
|
|
* This is the first place we can be sure we have a softc structure.
|
2000-11-11 09:49:49 +00:00
|
|
|
* You would do ISA specific attach things here, but generically there aren't
|
2003-10-03 19:31:55 +00:00
|
|
|
* any (yay new-bus!).
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
|
|
|
static int
|
2000-10-24 16:45:58 +00:00
|
|
|
${1}_isa_attach (device_t device)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-11-11 09:49:49 +00:00
|
|
|
int error;
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
2000-11-11 09:49:49 +00:00
|
|
|
|
|
|
|
error = ${1}_attach(device, scp);
|
2002-08-02 10:37:22 +00:00
|
|
|
if (error)
|
2000-11-11 09:49:49 +00:00
|
|
|
${1}_isa_detach(device);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Detach the driver (e.g. module unload),
|
2000-11-11 09:49:49 +00:00
|
|
|
* call the bus independent version
|
|
|
|
* and undo anything we did in the ISA attach routine.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
${1}_isa_detach (device_t device)
|
|
|
|
{
|
|
|
|
int error;
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
2000-11-11 09:49:49 +00:00
|
|
|
|
|
|
|
error = ${1}_detach(device, scp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2000-12-18 21:08:53 +00:00
|
|
|
/*
|
|
|
|
***************************************
|
|
|
|
* PCI Attachment structures and code
|
|
|
|
***************************************
|
|
|
|
*/
|
2000-11-11 09:49:49 +00:00
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
static int ${1}_pci_probe(device_t);
|
|
|
|
static int ${1}_pci_attach(device_t);
|
|
|
|
static int ${1}_pci_detach(device_t);
|
2000-11-11 09:49:49 +00:00
|
|
|
|
|
|
|
static device_method_t ${1}_pci_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, ${1}_pci_probe),
|
|
|
|
DEVMETHOD(device_attach, ${1}_pci_attach),
|
|
|
|
DEVMETHOD(device_detach, ${1}_pci_detach),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ${1}_pci_driver = {
|
|
|
|
"${1}",
|
|
|
|
${1}_pci_methods,
|
|
|
|
sizeof(struct ${1}_softc),
|
|
|
|
};
|
|
|
|
|
2000-11-12 10:46:38 +00:00
|
|
|
DRIVER_MODULE(${1}, pci, ${1}_pci_driver, ${1}_devclass, 0, 0);
|
2000-12-18 21:08:53 +00:00
|
|
|
/*
|
|
|
|
* Cardbus is a pci bus plus extra, so use the pci driver unless special
|
|
|
|
* things need to be done only in the cardbus case.
|
|
|
|
*/
|
|
|
|
DRIVER_MODULE(${1}, cardbus, ${1}_pci_driver, ${1}_devclass, 0, 0);
|
2000-11-11 09:49:49 +00:00
|
|
|
|
|
|
|
static struct _pcsid
|
|
|
|
{
|
|
|
|
u_int32_t type;
|
|
|
|
const char *desc;
|
|
|
|
} pci_ids[] = {
|
|
|
|
{ 0x1234abcd, "ACME PCI Widgetplus" },
|
2000-12-18 21:08:53 +00:00
|
|
|
{ 0x1243fedc, "Happy moon brand RIPOFFplus" },
|
2000-11-11 09:49:49 +00:00
|
|
|
{ 0x00000000, NULL }
|
|
|
|
};
|
|
|
|
|
2000-11-15 12:05:21 +00:00
|
|
|
/*
|
2001-04-14 18:51:39 +00:00
|
|
|
* See if this card is specifically mentioned in our list of known devices.
|
2000-11-15 12:05:21 +00:00
|
|
|
* Theoretically we might also put in a weak bid for some devices that
|
2000-12-18 21:08:53 +00:00
|
|
|
* report themselves to be some generic type of device if we can handle
|
2000-11-15 12:05:21 +00:00
|
|
|
* that generic type. (other PCI_XXX calls give that info).
|
|
|
|
* This would allow a specific driver to over-ride us.
|
|
|
|
*
|
|
|
|
* See the comments in the ISA section regarding returning non-positive
|
|
|
|
* values from probe routines.
|
|
|
|
*/
|
2000-11-11 09:49:49 +00:00
|
|
|
static int
|
|
|
|
${1}_pci_probe (device_t device)
|
|
|
|
{
|
|
|
|
u_int32_t type = pci_get_devid(device);
|
|
|
|
struct _pcsid *ep =pci_ids;
|
|
|
|
|
|
|
|
while (ep->type && ep->type != type)
|
|
|
|
++ep;
|
|
|
|
if (ep->desc) {
|
|
|
|
device_set_desc(device, ep->desc);
|
2000-12-18 21:08:53 +00:00
|
|
|
return 0; /* If there might be a better driver, return -2 */
|
2002-08-02 10:37:22 +00:00
|
|
|
} else
|
2000-11-11 09:49:49 +00:00
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
${1}_pci_attach(device_t device)
|
|
|
|
{
|
|
|
|
int error;
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
2000-11-11 09:49:49 +00:00
|
|
|
|
|
|
|
error = ${1}_attach(device, scp);
|
2002-08-02 10:37:22 +00:00
|
|
|
if (error)
|
2000-11-11 09:49:49 +00:00
|
|
|
${1}_pci_detach(device);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
${1}_pci_detach (device_t device)
|
|
|
|
{
|
|
|
|
int error;
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
2000-11-11 09:49:49 +00:00
|
|
|
|
|
|
|
error = ${1}_detach(device, scp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2000-12-18 21:08:53 +00:00
|
|
|
/*
|
|
|
|
****************************************
|
2001-04-14 18:51:39 +00:00
|
|
|
* Common Attachment sub-functions
|
2000-12-18 21:08:53 +00:00
|
|
|
****************************************
|
|
|
|
*/
|
2000-11-11 09:49:49 +00:00
|
|
|
static int
|
2000-12-18 21:08:53 +00:00
|
|
|
${1}_attach(device_t device, struct ${1}_softc * scp)
|
2000-11-11 09:49:49 +00:00
|
|
|
{
|
2000-10-26 21:37:38 +00:00
|
|
|
device_t parent = device_get_parent(device);
|
2000-12-18 21:08:53 +00:00
|
|
|
int unit = device_get_unit(device);
|
1998-10-22 16:10:29 +00:00
|
|
|
|
2000-10-26 21:37:38 +00:00
|
|
|
scp->dev = make_dev(&${1}_cdevsw, 0,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0600, "${1}%d", unit);
|
2000-11-11 09:49:49 +00:00
|
|
|
scp->dev->si_drv1 = scp;
|
2000-10-26 21:37:38 +00:00
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
if (${1}_allocate_resources(device))
|
2000-10-26 21:37:38 +00:00
|
|
|
goto errexit;
|
|
|
|
|
2000-11-09 18:55:44 +00:00
|
|
|
scp->bt = rman_get_bustag(scp->res_ioport);
|
|
|
|
scp->bh = rman_get_bushandle(scp->res_ioport);
|
2000-10-26 21:37:38 +00:00
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
/* Register the interrupt handler. */
|
2000-11-09 18:55:44 +00:00
|
|
|
/*
|
|
|
|
* The type should be one of:
|
|
|
|
* INTR_TYPE_TTY
|
2000-12-18 21:08:53 +00:00
|
|
|
* INTR_TYPE_BIO
|
|
|
|
* INTR_TYPE_CAM
|
|
|
|
* INTR_TYPE_NET
|
|
|
|
* INTR_TYPE_MISC
|
|
|
|
* This will probably change with SMPng. INTR_TYPE_FAST may be
|
2001-04-14 18:51:39 +00:00
|
|
|
* OR'd into this type to mark the interrupt fast. However, fast
|
2000-12-18 21:08:53 +00:00
|
|
|
* interrupts cannot be shared at all so special precautions are
|
2001-04-14 18:51:39 +00:00
|
|
|
* necessary when coding fast interrupt routines.
|
2000-11-09 18:55:44 +00:00
|
|
|
*/
|
2000-10-25 15:08:11 +00:00
|
|
|
if (scp->res_irq) {
|
2003-10-03 19:31:55 +00:00
|
|
|
/* Default to the tty mask for registration. */ /* XXX */
|
2000-10-25 15:08:11 +00:00
|
|
|
if (BUS_SETUP_INTR(parent, device, scp->res_irq, INTR_TYPE_TTY,
|
2000-10-26 21:37:38 +00:00
|
|
|
${1}intr, scp, &scp->intr_cookie) == 0) {
|
2003-10-03 19:31:55 +00:00
|
|
|
/* Do something if successful. */
|
2002-08-02 10:37:22 +00:00
|
|
|
} else
|
2000-11-11 09:49:49 +00:00
|
|
|
goto errexit;
|
2000-10-25 15:08:11 +00:00
|
|
|
}
|
2000-11-09 18:55:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we want to access the memory we will need
|
|
|
|
* to know where it was mapped.
|
2000-12-18 21:08:53 +00:00
|
|
|
*
|
|
|
|
* Use of this function is discouraged, however. You should
|
|
|
|
* be accessing the device with the bus_space API if at all
|
|
|
|
* possible.
|
2000-11-09 18:55:44 +00:00
|
|
|
*/
|
|
|
|
scp->vaddr = rman_get_virtual(scp->res_memory);
|
2000-10-24 16:45:58 +00:00
|
|
|
return 0;
|
2000-10-26 21:37:38 +00:00
|
|
|
|
|
|
|
errexit:
|
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Undo anything we may have done.
|
2000-10-26 21:37:38 +00:00
|
|
|
*/
|
2000-11-11 09:49:49 +00:00
|
|
|
${1}_detach(device, scp);
|
2000-10-26 21:37:38 +00:00
|
|
|
return (ENXIO);
|
2000-10-24 16:45:58 +00:00
|
|
|
}
|
1998-10-22 16:10:29 +00:00
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
static int
|
2000-12-18 21:08:53 +00:00
|
|
|
${1}_detach(device_t device, struct ${1}_softc *scp)
|
2000-10-24 16:45:58 +00:00
|
|
|
{
|
2000-10-25 15:08:11 +00:00
|
|
|
device_t parent = device_get_parent(device);
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2000-10-26 21:37:38 +00:00
|
|
|
/*
|
|
|
|
* At this point stick a strong piece of wood into the device
|
2002-08-02 10:37:22 +00:00
|
|
|
* to make sure it is stopped safely. The alternative is to
|
|
|
|
* simply REFUSE to detach if it's busy. What you do depends on
|
2000-10-26 21:37:38 +00:00
|
|
|
* your specific situation.
|
2000-12-18 21:08:53 +00:00
|
|
|
*
|
|
|
|
* Sometimes the parent bus will detach you anyway, even if you
|
|
|
|
* are busy. You must cope with that possibility. Your hardware
|
|
|
|
* might even already be gone in the case of cardbus or pccard
|
|
|
|
* devices.
|
2000-10-26 21:37:38 +00:00
|
|
|
*/
|
|
|
|
/* ZAP some register */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take our interrupt handler out of the list of handlers
|
|
|
|
* that can handle this irq.
|
|
|
|
*/
|
|
|
|
if (scp->intr_cookie != NULL) {
|
2000-10-25 15:08:11 +00:00
|
|
|
if (BUS_TEARDOWN_INTR(parent, device,
|
2002-08-02 10:37:22 +00:00
|
|
|
scp->res_irq, scp->intr_cookie) != 0)
|
2000-10-25 15:08:11 +00:00
|
|
|
printf("intr teardown failed.. continuing\n");
|
2000-10-26 21:37:38 +00:00
|
|
|
scp->intr_cookie = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Deallocate any system resources we may have
|
2000-10-26 21:37:38 +00:00
|
|
|
* allocated on behalf of this driver.
|
|
|
|
*/
|
2000-11-09 18:55:44 +00:00
|
|
|
scp->vaddr = NULL;
|
2000-10-26 21:37:38 +00:00
|
|
|
return ${1}_deallocate_resources(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
${1}_allocate_resources(device_t device)
|
|
|
|
{
|
|
|
|
int error;
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
2003-10-03 19:31:55 +00:00
|
|
|
int size = 16; /* SIZE of port range used. */
|
2000-10-26 21:37:38 +00:00
|
|
|
|
|
|
|
scp->res_ioport = bus_alloc_resource(device, SYS_RES_IOPORT,
|
|
|
|
&scp->rid_ioport, 0ul, ~0ul, size, RF_ACTIVE);
|
2002-08-02 10:37:22 +00:00
|
|
|
if (scp->res_ioport == NULL)
|
2000-10-26 21:37:38 +00:00
|
|
|
goto errexit;
|
|
|
|
|
|
|
|
scp->res_irq = bus_alloc_resource(device, SYS_RES_IRQ,
|
2000-11-09 18:55:44 +00:00
|
|
|
&scp->rid_irq, 0ul, ~0ul, 1, RF_SHAREABLE|RF_ACTIVE);
|
2002-08-02 10:37:22 +00:00
|
|
|
if (scp->res_irq == NULL)
|
2000-10-26 21:37:38 +00:00
|
|
|
goto errexit;
|
|
|
|
|
|
|
|
scp->res_drq = bus_alloc_resource(device, SYS_RES_DRQ,
|
|
|
|
&scp->rid_drq, 0ul, ~0ul, 1, RF_ACTIVE);
|
2002-08-02 10:37:22 +00:00
|
|
|
if (scp->res_drq == NULL)
|
2000-10-26 21:37:38 +00:00
|
|
|
goto errexit;
|
|
|
|
|
2000-11-08 21:54:28 +00:00
|
|
|
scp->res_memory = bus_alloc_resource(device, SYS_RES_MEMORY,
|
2000-10-26 21:37:38 +00:00
|
|
|
&scp->rid_memory, 0ul, ~0ul, MSIZE, RF_ACTIVE);
|
2002-08-02 10:37:22 +00:00
|
|
|
if (scp->res_memory == NULL)
|
2000-10-26 21:37:38 +00:00
|
|
|
goto errexit;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
errexit:
|
|
|
|
error = ENXIO;
|
2003-10-03 19:31:55 +00:00
|
|
|
/* Cleanup anything we may have assigned. */
|
2000-10-26 21:37:38 +00:00
|
|
|
${1}_deallocate_resources(device);
|
2003-10-03 19:31:55 +00:00
|
|
|
return (ENXIO); /* For want of a better idea. */
|
2000-10-26 21:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
${1}_deallocate_resources(device_t device)
|
|
|
|
{
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEVICE2SOFTC(device);
|
2000-10-26 21:37:38 +00:00
|
|
|
|
|
|
|
if (scp->res_irq != 0) {
|
2000-10-25 15:08:11 +00:00
|
|
|
bus_deactivate_resource(device, SYS_RES_IRQ,
|
|
|
|
scp->rid_irq, scp->res_irq);
|
|
|
|
bus_release_resource(device, SYS_RES_IRQ,
|
|
|
|
scp->rid_irq, scp->res_irq);
|
|
|
|
scp->res_irq = 0;
|
|
|
|
}
|
|
|
|
if (scp->res_ioport != 0) {
|
|
|
|
bus_deactivate_resource(device, SYS_RES_IOPORT,
|
|
|
|
scp->rid_ioport, scp->res_ioport);
|
|
|
|
bus_release_resource(device, SYS_RES_IOPORT,
|
|
|
|
scp->rid_ioport, scp->res_ioport);
|
|
|
|
scp->res_ioport = 0;
|
|
|
|
}
|
2000-11-15 12:05:21 +00:00
|
|
|
if (scp->res_memory != 0) {
|
2000-10-25 15:08:11 +00:00
|
|
|
bus_deactivate_resource(device, SYS_RES_MEMORY,
|
|
|
|
scp->rid_memory, scp->res_memory);
|
|
|
|
bus_release_resource(device, SYS_RES_MEMORY,
|
|
|
|
scp->rid_memory, scp->res_memory);
|
2000-11-15 12:05:21 +00:00
|
|
|
scp->res_memory = 0;
|
2000-10-25 15:08:11 +00:00
|
|
|
}
|
|
|
|
if (scp->res_drq != 0) {
|
|
|
|
bus_deactivate_resource(device, SYS_RES_DRQ,
|
|
|
|
scp->rid_drq, scp->res_drq);
|
|
|
|
bus_release_resource(device, SYS_RES_DRQ,
|
|
|
|
scp->rid_drq, scp->res_drq);
|
|
|
|
scp->res_drq = 0;
|
|
|
|
}
|
2002-08-02 10:37:22 +00:00
|
|
|
if (scp->dev)
|
2000-10-25 15:08:11 +00:00
|
|
|
destroy_dev(scp->dev);
|
2000-10-24 16:45:58 +00:00
|
|
|
return (0);
|
1997-02-02 07:19:30 +00:00
|
|
|
}
|
|
|
|
|
1998-10-22 16:10:29 +00:00
|
|
|
static void
|
2000-10-24 16:45:58 +00:00
|
|
|
${1}intr(void *arg)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = (struct ${1}_softc *) arg;
|
2000-10-24 16:45:58 +00:00
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Well we got an interrupt, now what?
|
2000-12-18 21:08:53 +00:00
|
|
|
*
|
|
|
|
* Make sure that the interrupt routine will always terminate,
|
|
|
|
* even in the face of "bogus" data from the card.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2003-10-03 19:31:55 +00:00
|
|
|
(void)scp; /* Delete this line after using scp. */
|
1997-02-02 07:19:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
static int
|
2006-08-06 11:04:22 +00:00
|
|
|
${1}ioctl (struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEV2SOFTC(dev);
|
2000-10-24 16:45:58 +00:00
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
(void)scp; /* Delete this line after using scp. */
|
1997-02-02 07:19:30 +00:00
|
|
|
switch (cmd) {
|
2000-10-24 16:45:58 +00:00
|
|
|
case DHIOCRESET:
|
2003-10-03 19:31:55 +00:00
|
|
|
/* Whatever resets it. */
|
2000-11-08 21:54:28 +00:00
|
|
|
#if 0
|
2002-08-02 10:37:22 +00:00
|
|
|
${UPPER}_OUTB(SOME_PORT, 0xff);
|
2000-11-08 21:54:28 +00:00
|
|
|
#endif
|
1997-02-02 07:19:30 +00:00
|
|
|
break;
|
2000-10-24 16:45:58 +00:00
|
|
|
default:
|
1997-02-02 07:19:30 +00:00
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
return (0);
|
2000-10-24 16:45:58 +00:00
|
|
|
}
|
1997-02-02 07:19:30 +00:00
|
|
|
/*
|
|
|
|
* You also need read, write, open, close routines.
|
2003-10-03 19:31:55 +00:00
|
|
|
* This should get you started.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2000-10-24 16:45:58 +00:00
|
|
|
static int
|
2006-08-06 11:04:22 +00:00
|
|
|
${1}open(struct cdev *dev, int oflags, int devtype, struct thread *td)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEV2SOFTC(dev);
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Do processing.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2003-10-03 19:31:55 +00:00
|
|
|
(void)scp; /* Delete this line after using scp. */
|
1997-02-02 07:19:30 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
static int
|
2006-08-06 11:04:22 +00:00
|
|
|
${1}close(struct cdev *dev, int fflag, int devtype, struct thread *td)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEV2SOFTC(dev);
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Do processing.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2003-10-03 19:31:55 +00:00
|
|
|
(void)scp; /* Delete this line after using scp. */
|
1997-02-02 07:19:30 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
static int
|
2006-08-06 11:04:22 +00:00
|
|
|
${1}read(struct cdev *dev, struct uio *uio, int ioflag)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEV2SOFTC(dev);
|
2000-10-24 16:45:58 +00:00
|
|
|
int toread;
|
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Do processing.
|
|
|
|
* Read from buffer.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2003-10-03 19:31:55 +00:00
|
|
|
(void)scp; /* Delete this line after using scp. */
|
1997-02-02 07:19:30 +00:00
|
|
|
toread = (min(uio->uio_resid, sizeof(scp->buffer)));
|
|
|
|
return(uiomove(scp->buffer, toread, uio));
|
|
|
|
}
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
static int
|
2006-08-06 11:04:22 +00:00
|
|
|
${1}write(struct cdev *dev, struct uio *uio, int ioflag)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEV2SOFTC(dev);
|
1997-02-02 07:19:30 +00:00
|
|
|
int towrite;
|
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Do processing.
|
|
|
|
* Write to buffer.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2003-10-03 19:31:55 +00:00
|
|
|
(void)scp; /* Delete this line after using scp. */
|
1997-02-02 07:19:30 +00:00
|
|
|
towrite = (min(uio->uio_resid, sizeof(scp->buffer)));
|
|
|
|
return(uiomove(scp->buffer, towrite, uio));
|
|
|
|
}
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
static int
|
2006-08-06 11:04:22 +00:00
|
|
|
${1}mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEV2SOFTC(dev);
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
/*
|
2000-11-08 21:54:28 +00:00
|
|
|
* Given a byte offset into your device, return the PHYSICAL
|
|
|
|
* page number that it would map to.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2003-10-03 19:31:55 +00:00
|
|
|
(void)scp; /* Delete this line after using scp. */
|
|
|
|
#if 0 /* If we had a frame buffer or whatever... do this. */
|
2002-08-02 10:37:22 +00:00
|
|
|
if (offset > FRAMEBUFFERSIZE - PAGE_SIZE)
|
1997-02-02 07:19:30 +00:00
|
|
|
return (-1);
|
|
|
|
return i386_btop((FRAMEBASE + offset));
|
|
|
|
#else
|
|
|
|
return (-1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
static int
|
2006-08-06 11:04:22 +00:00
|
|
|
${1}poll(struct cdev *dev, int which, struct thread *td)
|
1997-02-02 07:19:30 +00:00
|
|
|
{
|
2000-12-18 21:08:53 +00:00
|
|
|
struct ${1}_softc *scp = DEV2SOFTC(dev);
|
1997-02-02 07:19:30 +00:00
|
|
|
|
2002-08-02 10:37:22 +00:00
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Do processing.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2003-10-03 19:31:55 +00:00
|
|
|
(void)scp; /* Delete this line after using scp. */
|
|
|
|
return (0); /* This is the wrong value I'm sure. */
|
1997-02-02 07:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DONE
|
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
cat >${TOP}/sys/${1}io.h <<DONE
|
1997-02-02 07:19:30 +00:00
|
|
|
/*
|
|
|
|
* Definitions needed to access the ${1} device (ioctls etc)
|
2003-10-03 19:31:55 +00:00
|
|
|
* see mtio.h, ioctl.h as examples.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
|
|
|
#ifndef SYS_DHIO_H
|
|
|
|
#define SYS_DHIO_H
|
|
|
|
|
|
|
|
#ifndef KERNEL
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
|
|
|
|
/*
|
2003-10-03 19:31:55 +00:00
|
|
|
* Define an ioctl here.
|
1997-02-02 07:19:30 +00:00
|
|
|
*/
|
2003-10-03 19:31:55 +00:00
|
|
|
#define DHIOCRESET _IO('D', 0) /* Reset the ${1} device. */
|
1997-02-02 07:19:30 +00:00
|
|
|
#endif
|
|
|
|
DONE
|
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
if [ ! -d ${TOP}/modules/${1} ]; then
|
2000-10-24 16:45:58 +00:00
|
|
|
mkdir -p ${TOP}/modules/${1}
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat >${TOP}/modules/${1}/Makefile <<DONE
|
1998-01-12 07:47:03 +00:00
|
|
|
# ${UPPER} Loadable Kernel Module
|
|
|
|
#
|
2000-10-26 21:53:37 +00:00
|
|
|
# \$${RCS_KEYWORD}: $
|
2002-08-02 10:37:22 +00:00
|
|
|
|
2000-10-24 16:45:58 +00:00
|
|
|
.PATH: \${.CURDIR}/../../dev/${1}
|
|
|
|
KMOD = ${1}
|
|
|
|
SRCS = ${1}.c
|
|
|
|
SRCS += opt_inet.h device_if.h bus_if.h pci_if.h isa_if.h
|
2002-08-02 10:37:22 +00:00
|
|
|
|
2003-10-03 19:31:55 +00:00
|
|
|
# You may need to do this is your device is an if_xxx driver.
|
2000-10-24 16:45:58 +00:00
|
|
|
opt_inet.h:
|
|
|
|
echo "#define INET 1" > opt_inet.h
|
2002-08-02 10:37:22 +00:00
|
|
|
|
1998-01-12 07:47:03 +00:00
|
|
|
.include <bsd.kmod.mk>
|
|
|
|
DONE
|
2000-10-24 16:45:58 +00:00
|
|
|
|
2006-08-06 11:06:35 +00:00
|
|
|
echo -n "Do you want to build the '${1}' module? [Y]"
|
|
|
|
read VAL
|
|
|
|
if [ "-z" "$VAL" ]; then
|
|
|
|
VAL=YES
|
|
|
|
fi
|
|
|
|
case ${VAL} in
|
|
|
|
[yY]*)
|
|
|
|
(cd ${TOP}/modules/${1}; make depend; make )
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# exit
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo ""
|
2006-08-09 10:53:26 +00:00
|
|
|
echo -n "Do you want to build the '${UPPER}' kernel? [Y]"
|
|
|
|
read VAL
|
|
|
|
if [ "-z" "$VAL" ]; then
|
|
|
|
VAL=YES
|
|
|
|
fi
|
|
|
|
case ${VAL} in
|
|
|
|
[yY]*)
|
|
|
|
(
|
|
|
|
cd ${TOP}/i386/conf; \
|
|
|
|
config ${UPPER}; \
|
|
|
|
cd ${TOP}/i386/compile/${UPPER}; \
|
|
|
|
make depend; \
|
|
|
|
make; \
|
|
|
|
)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# exit
|
|
|
|
;;
|
|
|
|
esac
|
1997-02-02 07:19:30 +00:00
|
|
|
|
|
|
|
#--------------end of script---------------
|
|
|
|
#
|
2003-10-03 19:31:55 +00:00
|
|
|
# Edit to your taste...
|
1997-02-02 07:19:30 +00:00
|
|
|
#
|
2002-08-02 10:37:22 +00:00
|
|
|
#
|