2000-10-23 12:55:51 +00:00
|
|
|
/* $NecBSD: nsp_pisa.c,v 1.4 1999/04/15 01:35:54 kmatsuda Exp $ */
|
|
|
|
/* $NetBSD$ */
|
|
|
|
|
2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2000-10-23 12:55:51 +00:00
|
|
|
* [Ported for FreeBSD]
|
|
|
|
* Copyright (c) 2000
|
|
|
|
* Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
|
|
|
|
* All rights reserved.
|
|
|
|
* [NetBSD for NEC PC-98 series]
|
|
|
|
* Copyright (c) 1998
|
|
|
|
* NetBSD/pc98 porting staff. 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.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
#include <sys/param.h>
|
2004-05-27 03:49:45 +00:00
|
|
|
#include <sys/bus.h>
|
2000-10-23 12:55:51 +00:00
|
|
|
#include <sys/errno.h>
|
2004-05-27 03:49:45 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
2012-09-06 18:53:33 +00:00
|
|
|
#include <sys/module.h>
|
2004-05-27 03:49:45 +00:00
|
|
|
#include <sys/systm.h>
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2004-05-27 03:49:45 +00:00
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2012-09-06 18:53:33 +00:00
|
|
|
#include <sys/bus.h>
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2002-11-28 01:09:29 +00:00
|
|
|
#include <dev/pccard/pccardvar.h>
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
#include <cam/scsi/scsi_low.h>
|
|
|
|
|
|
|
|
#include <dev/nsp/nspreg.h>
|
|
|
|
#include <dev/nsp/nspvar.h>
|
|
|
|
|
|
|
|
#define NSP_HOSTID 7
|
|
|
|
|
2004-05-27 03:49:45 +00:00
|
|
|
#include "pccarddevs.h"
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2000-10-29 06:54:32 +00:00
|
|
|
#define PIO_MODE 0x100 /* pd_flags */
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2012-09-06 18:53:33 +00:00
|
|
|
static int nspprobe(device_t devi);
|
|
|
|
static int nspattach(device_t devi);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2012-09-06 18:53:33 +00:00
|
|
|
static void nsp_card_unload (device_t);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2002-11-28 01:09:29 +00:00
|
|
|
const struct pccard_product nsp_products[] = {
|
2005-06-24 14:36:54 +00:00
|
|
|
PCMCIA_CARD(IODATA3, CBSC16),
|
|
|
|
PCMCIA_CARD(PANASONIC, KME),
|
|
|
|
PCMCIA_CARD(WORKBIT2, NINJA_SCSI3),
|
|
|
|
PCMCIA_CARD(WORKBIT, ULTRA_NINJA_16),
|
2002-11-28 01:09:29 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
/*
|
2005-09-20 19:54:11 +00:00
|
|
|
* Additional code for FreeBSD new-bus PC Card frontend
|
2000-10-23 12:55:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
nsp_pccard_intr(void * arg)
|
|
|
|
{
|
2014-11-20 20:50:05 +00:00
|
|
|
struct nsp_softc *sc;
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
SCSI_LOW_LOCK(&sc->sc_sclow);
|
|
|
|
nspintr(sc);
|
|
|
|
SCSI_LOW_UNLOCK(&sc->sc_sclow);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-09-20 19:54:11 +00:00
|
|
|
nsp_release_resource(device_t dev)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
struct nsp_softc *sc = device_get_softc(dev);
|
|
|
|
|
2005-02-04 02:32:43 +00:00
|
|
|
if (sc->nsp_intrhand)
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_teardown_intr(dev, sc->irq_res, sc->nsp_intrhand);
|
2005-02-04 02:32:43 +00:00
|
|
|
if (sc->port_res)
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT,
|
|
|
|
sc->port_rid, sc->port_res);
|
2005-02-04 02:32:43 +00:00
|
|
|
if (sc->irq_res)
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IRQ,
|
|
|
|
sc->irq_rid, sc->irq_res);
|
2005-02-04 02:32:43 +00:00
|
|
|
if (sc->mem_res)
|
2000-10-23 12:55:51 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
|
|
|
sc->mem_rid, sc->mem_res);
|
2014-11-20 20:50:05 +00:00
|
|
|
mtx_destroy(&sc->sc_sclow.sl_lock);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-09-20 19:54:11 +00:00
|
|
|
nsp_alloc_resource(device_t dev)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
struct nsp_softc *sc = device_get_softc(dev);
|
2001-02-25 14:01:05 +00:00
|
|
|
u_long ioaddr, iosize, maddr, msize;
|
2000-10-23 12:55:51 +00:00
|
|
|
int error;
|
|
|
|
|
2001-02-25 14:01:05 +00:00
|
|
|
error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &ioaddr, &iosize);
|
|
|
|
if (error || iosize < NSP_IOSIZE)
|
|
|
|
return(ENOMEM);
|
|
|
|
|
2014-11-20 20:50:05 +00:00
|
|
|
mtx_init(&sc->sc_sclow.sl_lock, "nsp", NULL, MTX_DEF);
|
2000-10-23 12:55:51 +00:00
|
|
|
sc->port_rid = 0;
|
|
|
|
sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
|
2001-09-02 06:42:40 +00:00
|
|
|
0, ~0, NSP_IOSIZE, RF_ACTIVE);
|
2000-10-23 12:55:51 +00:00
|
|
|
if (sc->port_res == NULL) {
|
|
|
|
nsp_release_resource(dev);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->irq_rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
|
|
|
|
RF_ACTIVE);
|
2000-10-23 12:55:51 +00:00
|
|
|
if (sc->irq_res == NULL) {
|
|
|
|
nsp_release_resource(dev);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
|
2005-02-04 02:32:43 +00:00
|
|
|
if (error)
|
2000-10-23 12:55:51 +00:00
|
|
|
return(0); /* XXX */
|
|
|
|
|
2001-02-25 14:01:05 +00:00
|
|
|
/* No need to allocate memory if not configured and it's in PIO mode */
|
2000-10-23 12:55:51 +00:00
|
|
|
if (maddr == 0 || msize == 0) {
|
2012-09-06 18:53:33 +00:00
|
|
|
if ((device_get_flags(dev) & PIO_MODE) == 0) {
|
2001-02-25 14:01:05 +00:00
|
|
|
printf("Memory window was not configured. Configure or use in PIO mode.");
|
|
|
|
nsp_release_resource(dev);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
/* no need to allocate memory if PIO mode */
|
2000-10-23 12:55:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->mem_rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid,
|
|
|
|
RF_ACTIVE);
|
2000-10-23 12:55:51 +00:00
|
|
|
if (sc->mem_res == NULL) {
|
|
|
|
nsp_release_resource(dev);
|
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-09-20 19:54:11 +00:00
|
|
|
static int
|
|
|
|
nsp_pccard_probe(device_t dev)
|
2002-11-28 01:09:29 +00:00
|
|
|
{
|
|
|
|
const struct pccard_product *pp;
|
|
|
|
|
|
|
|
if ((pp = pccard_product_lookup(dev, nsp_products,
|
|
|
|
sizeof(nsp_products[0]), NULL)) != NULL) {
|
2005-02-04 02:32:43 +00:00
|
|
|
if (pp->pp_name)
|
|
|
|
device_set_desc(dev, pp->pp_name);
|
2014-11-20 20:50:05 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2002-11-28 01:09:29 +00:00
|
|
|
}
|
|
|
|
return(EIO);
|
|
|
|
}
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
static int
|
2005-09-20 19:54:11 +00:00
|
|
|
nsp_pccard_attach(device_t dev)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2005-09-20 19:54:11 +00:00
|
|
|
struct nsp_softc *sc = device_get_softc(dev);
|
2000-10-23 12:55:51 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = nsp_alloc_resource(dev);
|
2005-02-04 02:32:43 +00:00
|
|
|
if (error)
|
2000-10-23 12:55:51 +00:00
|
|
|
return(error);
|
|
|
|
if (nspprobe(dev) == 0) {
|
|
|
|
nsp_release_resource(dev);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
2014-11-20 20:50:05 +00:00
|
|
|
error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY |
|
|
|
|
INTR_MPSAFE, NULL, nsp_pccard_intr, sc, &sc->nsp_intrhand);
|
2000-10-23 12:55:51 +00:00
|
|
|
if (error) {
|
|
|
|
nsp_release_resource(dev);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
if (nspattach(dev) == 0) {
|
|
|
|
nsp_release_resource(dev);
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2009-06-11 17:14:28 +00:00
|
|
|
static int
|
2005-09-20 19:54:11 +00:00
|
|
|
nsp_pccard_detach(device_t dev)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
nsp_card_unload(dev);
|
|
|
|
nsp_release_resource(dev);
|
2009-06-11 17:14:28 +00:00
|
|
|
|
|
|
|
return (0);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t nsp_pccard_methods[] = {
|
|
|
|
/* Device interface */
|
2005-09-20 19:54:11 +00:00
|
|
|
DEVMETHOD(device_probe, nsp_pccard_probe),
|
|
|
|
DEVMETHOD(device_attach, nsp_pccard_attach),
|
2000-10-23 12:55:51 +00:00
|
|
|
DEVMETHOD(device_detach, nsp_pccard_detach),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t nsp_pccard_driver = {
|
|
|
|
"nsp",
|
|
|
|
nsp_pccard_methods,
|
|
|
|
sizeof(struct nsp_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t nsp_devclass;
|
|
|
|
|
2001-12-15 12:32:23 +00:00
|
|
|
MODULE_DEPEND(nsp, scsi_low, 1, 1, 1);
|
2000-10-23 12:55:51 +00:00
|
|
|
DRIVER_MODULE(nsp, pccard, nsp_pccard_driver, nsp_devclass, 0, 0);
|
|
|
|
|
2005-02-04 02:32:43 +00:00
|
|
|
static void
|
2012-09-06 18:53:33 +00:00
|
|
|
nsp_card_unload(device_t devi)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
2012-09-06 18:53:33 +00:00
|
|
|
struct nsp_softc *sc = device_get_softc(devi);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2014-11-20 20:50:05 +00:00
|
|
|
scsi_low_deactivate(&sc->sc_sclow);
|
|
|
|
scsi_low_detach(&sc->sc_sclow);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-09-06 18:53:33 +00:00
|
|
|
nspprobe(device_t devi)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
struct nsp_softc *sc = device_get_softc(devi);
|
|
|
|
|
2014-11-20 20:50:05 +00:00
|
|
|
rv = nspprobesubr(sc->port_res,
|
2012-09-06 18:53:33 +00:00
|
|
|
device_get_flags(devi));
|
2000-10-23 12:55:51 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-09-06 18:53:33 +00:00
|
|
|
nspattach(device_t devi)
|
2000-10-23 12:55:51 +00:00
|
|
|
{
|
|
|
|
struct nsp_softc *sc;
|
|
|
|
struct scsi_low_softc *slp;
|
2012-09-06 18:53:33 +00:00
|
|
|
u_int32_t flags = device_get_flags(devi);
|
|
|
|
u_int iobase = bus_get_resource_start(devi, SYS_RES_IOPORT, 0);
|
2000-10-23 12:55:51 +00:00
|
|
|
|
2005-02-04 02:32:43 +00:00
|
|
|
if (iobase == 0) {
|
2014-11-20 20:50:05 +00:00
|
|
|
device_printf(devi, "no ioaddr is given\n");
|
|
|
|
return (ENXIO);
|
2000-10-23 12:55:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-06 18:53:33 +00:00
|
|
|
sc = device_get_softc(devi);
|
2000-10-23 12:55:51 +00:00
|
|
|
slp = &sc->sc_sclow;
|
|
|
|
slp->sl_dev = devi;
|
|
|
|
|
2005-02-04 02:32:43 +00:00
|
|
|
if (sc->mem_res == NULL) {
|
2014-11-20 20:50:05 +00:00
|
|
|
device_printf(devi,
|
|
|
|
"WARNING: CANNOT GET Memory RESOURCE going PIO mode\n");
|
2005-02-04 02:32:43 +00:00
|
|
|
flags |= PIO_MODE;
|
2002-11-28 01:09:29 +00:00
|
|
|
}
|
|
|
|
|
2000-10-23 12:55:51 +00:00
|
|
|
/* slp->sl_irq = devi->pd_irq; */
|
|
|
|
sc->sc_iclkdiv = CLKDIVR_20M;
|
|
|
|
sc->sc_clkdiv = CLKDIVR_40M;
|
|
|
|
|
|
|
|
slp->sl_hostid = NSP_HOSTID;
|
|
|
|
slp->sl_cfgflags = flags;
|
|
|
|
|
|
|
|
nspattachsubr(sc);
|
|
|
|
|
|
|
|
return(NSP_IOSIZE);
|
|
|
|
}
|