Preliminary support for detaching an "adv" instance. This

could use some more work.

Derived from kern/12341, takashi.yamamoto@bigfoot.com.
This commit is contained in:
thorpej 2001-03-08 06:49:49 +00:00
parent 3a0778cdc4
commit 54bb0eddd9
3 changed files with 46 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: adv.c,v 1.21 2001/03/07 23:07:12 thorpej Exp $ */
/* $NetBSD: adv.c,v 1.22 2001/03/08 06:49:49 thorpej Exp $ */
/*
* Generic driver for the Advanced Systems Inc. Narrow SCSI controllers
@ -73,6 +73,7 @@
static int adv_alloc_control_data __P((ASC_SOFTC *));
static void adv_free_control_data __P((ASC_SOFTC *));
static int adv_create_ccbs __P((ASC_SOFTC *, ADV_CCB *, int));
static void adv_free_ccb __P((ASC_SOFTC *, ADV_CCB *));
static void adv_reset_ccb __P((ADV_CCB *));
@ -117,22 +118,22 @@ static int
adv_alloc_control_data(sc)
ASC_SOFTC *sc;
{
bus_dma_segment_t seg;
int error, rseg;
int error;
/*
* Allocate the control blocks.
*/
if ((error = bus_dmamem_alloc(sc->sc_dmat, sizeof(struct adv_control),
PAGE_SIZE, 0, &seg, 1, &rseg,
BUS_DMA_NOWAIT)) != 0) {
PAGE_SIZE, 0, &sc->sc_control_seg, 1,
&sc->sc_control_nsegs, BUS_DMA_NOWAIT)) != 0) {
printf("%s: unable to allocate control structures,"
" error = %d\n", sc->sc_dev.dv_xname, error);
return (error);
}
if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,
sizeof(struct adv_control), (caddr_t *) & sc->sc_control,
BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
if ((error = bus_dmamem_map(sc->sc_dmat, &sc->sc_control_seg,
sc->sc_control_nsegs, sizeof(struct adv_control),
(caddr_t *) & sc->sc_control,
BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
printf("%s: unable to map control structures, error = %d\n",
sc->sc_dev.dv_xname, error);
return (error);
@ -164,6 +165,20 @@ adv_alloc_control_data(sc)
return (0);
}
static void
adv_free_control_data(sc)
ASC_SOFTC *sc;
{
bus_dmamap_unload(sc->sc_dmat, sc->sc_dmamap_control);
bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamap_control);
sc->sc_dmamap_control = NULL;
bus_dmamem_unmap(sc->sc_dmat, (caddr_t) sc->sc_control,
sizeof(struct adv_control));
bus_dmamem_free(sc->sc_dmat, &sc->sc_control_seg,
sc->sc_control_nsegs);
}
/*
* Create a set of ccbs and add them to the free list. Called once
@ -528,9 +543,23 @@ adv_attach(sc)
printf("%s: WARNING: only %d of %d control blocks created\n",
sc->sc_dev.dv_xname, i, ADV_MAX_CCB);
}
config_found(&sc->sc_dev, &sc->sc_link, scsiprint);
sc->sc_child = config_found(&sc->sc_dev, &sc->sc_link, scsiprint);
}
int
adv_detach(sc, flags)
ASC_SOFTC *sc;
int flags;
{
int rv = 0;
if (sc->sc_child != NULL)
rv = config_detach(sc->sc_child, flags);
adv_free_control_data(sc);
return (rv);
}
static void
advminphys(bp)

View File

@ -1,4 +1,4 @@
/* $NetBSD: adv.h,v 1.7 2000/03/23 07:01:28 thorpej Exp $ */
/* $NetBSD: adv.h,v 1.8 2001/03/08 06:49:49 thorpej Exp $ */
/*
* Generic driver definitions and exported functions for the Advanced
@ -94,6 +94,7 @@ struct adv_control
int adv_init __P((ASC_SOFTC *sc));
void adv_attach __P((ASC_SOFTC *sc));
int adv_detach __P((ASC_SOFTC *sc, int));
int adv_intr __P((void *arg));
ADV_CCB *adv_ccb_phys_kv __P((ASC_SOFTC *, u_long));

View File

@ -1,4 +1,4 @@
/* $NetBSD: advlib.h,v 1.11 1999/08/07 07:20:16 thorpej Exp $ */
/* $NetBSD: advlib.h,v 1.12 2001/03/08 06:49:49 thorpej Exp $ */
/*
* Definitions for low level routines and data structures
@ -839,6 +839,8 @@ typedef struct asc_softc
{
struct device sc_dev;
struct device *sc_child;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
bus_dma_tag_t sc_dmat;
@ -847,6 +849,9 @@ typedef struct asc_softc
struct adv_control *sc_control; /* control structures */
bus_dma_segment_t sc_control_seg;
int sc_control_nsegs;
struct adv_ccb *sc_ccbhash[CCB_HASH_SIZE];
TAILQ_HEAD(, adv_ccb) sc_free_ccb, sc_waiting_ccb;
struct scsipi_link sc_link; /* prototype for devs */