summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorMatthew Dempsky <matthew@cvs.openbsd.org>2011-05-09 22:33:55 +0000
committerMatthew Dempsky <matthew@cvs.openbsd.org>2011-05-09 22:33:55 +0000
commit15cd6a42ff78f176a0db39dfa7401274f1792bfc (patch)
tree69a950d47edcd44df04df75de2fe47d28c886f8c /sys/dev
parenta9b23f00f1cdf8ec5565371412b53af1247703da (diff)
Refactor queue allocation and initialization into a wdc_alloc_queue()
function, and let attachment code calls this rather than malloc(9). This prevents re-initialization of the queue in shared queue chipsets. Also, add wdc_free_queue() as a complementary function. Earlier version (without wdc_free_queue()) tested by sthen@ and Amit Kulkarni on various pciide(4) chips. ok dlg@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ic/wdc.c41
-rw-r--r--sys/dev/ic/wdcvar.h4
-rw-r--r--sys/dev/isa/wdc_isa.c7
-rw-r--r--sys/dev/isa/wdc_isapnp.c7
-rw-r--r--sys/dev/pci/pciide.c34
-rw-r--r--sys/dev/pcmcia/wdc_pcmcia.c9
6 files changed, 55 insertions, 47 deletions
diff --git a/sys/dev/ic/wdc.c b/sys/dev/ic/wdc.c
index 734e447eb66..d7b1a22a6a9 100644
--- a/sys/dev/ic/wdc.c
+++ b/sys/dev/ic/wdc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wdc.c,v 1.115 2011/05/09 22:25:50 matthew Exp $ */
+/* $OpenBSD: wdc.c,v 1.116 2011/05/09 22:33:54 matthew Exp $ */
/* $NetBSD: wdc.c,v 1.68 1999/06/23 19:00:17 bouyer Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved.
@@ -697,12 +697,38 @@ wdcprobe(struct channel_softc *chp)
return (ret_value);
}
+struct channel_queue *
+wdc_alloc_queue(void)
+{
+ static int inited = 0;
+ struct channel_queue *queue;
+
+ /* Initialize global data. */
+ if (inited == 0) {
+ /* Initialize the wdc_xfer pool. */
+ pool_init(&wdc_xfer_pool, sizeof(struct wdc_xfer), 0,
+ 0, 0, "wdcspl", NULL);
+ inited = 1;
+ }
+
+ queue = malloc(sizeof(*queue), M_DEVBUF, M_NOWAIT);
+ if (queue != NULL) {
+ TAILQ_INIT(&queue->sc_xfer);
+ }
+ return (queue);
+}
+
+void
+wdc_free_queue(struct channel_queue *queue)
+{
+ free(queue, M_DEVBUF);
+}
+
void
wdcattach(struct channel_softc *chp)
{
int channel_flags, ctrl_flags, i;
struct ata_atapi_attach aa_link;
- static int inited = 0, s;
#ifdef WDCDEBUG
int savedmask = wdcdebug_mask;
#endif
@@ -747,17 +773,6 @@ wdcattach(struct channel_softc *chp)
}
#endif /* WDCDEBUG */
- /* initialise global data */
- s = splbio();
- if (inited == 0) {
- /* Initialize the wdc_xfer pool. */
- pool_init(&wdc_xfer_pool, sizeof(struct wdc_xfer), 0,
- 0, 0, "wdcspl", NULL);
- inited++;
- }
- TAILQ_INIT(&chp->ch_queue->sc_xfer);
- splx(s);
-
for (i = 0; i < 2; i++) {
struct ata_drive_datas *drvp = &chp->ch_drive[i];
diff --git a/sys/dev/ic/wdcvar.h b/sys/dev/ic/wdcvar.h
index ea7b16f292b..1ab0136f9b3 100644
--- a/sys/dev/ic/wdcvar.h
+++ b/sys/dev/ic/wdcvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: wdcvar.h,v 1.50 2011/05/08 17:33:57 matthew Exp $ */
+/* $OpenBSD: wdcvar.h,v 1.51 2011/05/09 22:33:54 matthew Exp $ */
/* $NetBSD: wdcvar.h,v 1.17 1999/04/11 20:50:29 bouyer Exp $ */
/*-
@@ -259,6 +259,8 @@ int wdcprobe(struct channel_softc *);
void wdcattach(struct channel_softc *);
int wdcdetach(struct channel_softc *, int);
int wdcintr(void *);
+struct channel_queue *wdc_alloc_queue(void);
+void wdc_free_queue(struct channel_queue *);
void wdc_exec_xfer(struct channel_softc *, struct wdc_xfer *);
struct wdc_xfer *wdc_get_xfer(int); /* int = WDC_NOSLEEP/CANSLEEP */
#define WDC_CANSLEEP 0x00
diff --git a/sys/dev/isa/wdc_isa.c b/sys/dev/isa/wdc_isa.c
index 9ddd63146c3..5c683da88c1 100644
--- a/sys/dev/isa/wdc_isa.c
+++ b/sys/dev/isa/wdc_isa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wdc_isa.c,v 1.13 2008/06/26 05:42:16 ray Exp $ */
+/* $OpenBSD: wdc_isa.c,v 1.14 2011/05/09 22:33:54 matthew Exp $ */
/* $NetBSD: wdc_isa.c,v 1.15 1999/05/19 14:41:25 bouyer Exp $ */
/*-
@@ -164,10 +164,9 @@ wdc_isa_attach(struct device *parent, struct device *self, void *aux)
sc->sc_wdcdev.nchannels = 1;
sc->wdc_channel.channel = 0;
sc->wdc_channel.wdc = &sc->sc_wdcdev;
- sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
- M_DEVBUF, M_NOWAIT);
+ sc->wdc_channel.ch_queue = wdc_alloc_queue();
if (sc->wdc_channel.ch_queue == NULL) {
- printf("%s: can't allocate memory for command queue",
+ printf("%s: cannot allocate channel queue",
sc->sc_wdcdev.sc_dev.dv_xname);
return;
}
diff --git a/sys/dev/isa/wdc_isapnp.c b/sys/dev/isa/wdc_isapnp.c
index 267ff3694ca..61d7c68d8a2 100644
--- a/sys/dev/isa/wdc_isapnp.c
+++ b/sys/dev/isa/wdc_isapnp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wdc_isapnp.c,v 1.8 2008/06/26 05:42:16 ray Exp $ */
+/* $OpenBSD: wdc_isapnp.c,v 1.9 2011/05/09 22:33:54 matthew Exp $ */
/* $NetBSD: wdc_isapnp.c,v 1.13 1999/03/22 10:00:12 mycroft Exp $ */
/*-
@@ -135,10 +135,9 @@ wdc_isapnp_attach(parent, self, aux)
sc->sc_wdcdev.nchannels = 1;
sc->wdc_channel.channel = 0;
sc->wdc_channel.wdc = &sc->sc_wdcdev;
- sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
- M_DEVBUF, M_NOWAIT);
+ sc->wdc_channel.ch_queue = wdc_alloc_queue();
if (sc->wdc_channel.ch_queue == NULL) {
- printf(": can't allocate memory for command queue\n");
+ printf(": cannot allocate channel queue\n");
return;
}
diff --git a/sys/dev/pci/pciide.c b/sys/dev/pci/pciide.c
index e43fd1f1a08..b2ef4c98ec7 100644
--- a/sys/dev/pci/pciide.c
+++ b/sys/dev/pci/pciide.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pciide.c,v 1.329 2011/05/09 22:25:50 matthew Exp $ */
+/* $OpenBSD: pciide.c,v 1.330 2011/05/09 22:33:54 matthew Exp $ */
/* $NetBSD: pciide.c,v 1.127 2001/08/03 01:31:08 tsutsui Exp $ */
/*
@@ -2155,11 +2155,10 @@ pciide_chansetup(struct pciide_softc *sc, int channel, pcireg_t interface)
cp->name = PCIIDE_CHANNEL_NAME(channel);
cp->wdc_channel.channel = channel;
cp->wdc_channel.wdc = &sc->sc_wdcdev;
- cp->wdc_channel.ch_queue =
- malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+ cp->wdc_channel.ch_queue = wdc_alloc_queue();
if (cp->wdc_channel.ch_queue == NULL) {
printf("%s: %s "
- "cannot allocate memory for command queue",
+ "cannot allocate channel queue",
sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
return (0);
}
@@ -2173,7 +2172,7 @@ pciide_chanfree(struct pciide_softc *sc, int channel)
{
struct pciide_channel *cp = &sc->pciide_channels[channel];
if (cp->wdc_channel.ch_queue)
- free(cp->wdc_channel.ch_queue, M_DEVBUF);
+ wdc_free_queue(cp->wdc_channel.ch_queue);
}
/* some common code used by several chip channel_map */
@@ -3636,12 +3635,11 @@ cmd_channel_map(struct pci_attach_args *pa, struct pciide_softc *sc,
cp->wdc_channel.ch_queue =
sc->pciide_channels[0].wdc_channel.ch_queue;
} else {
- cp->wdc_channel.ch_queue =
- malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+ cp->wdc_channel.ch_queue = wdc_alloc_queue();
}
if (cp->wdc_channel.ch_queue == NULL) {
printf(
- "%s: %s cannot allocate memory for command queue",
+ "%s: %s cannot allocate channel queue",
sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
return;
}
@@ -4001,11 +3999,10 @@ cmd680_channel_map(struct pci_attach_args *pa, struct pciide_softc *sc,
cp->wdc_channel.channel = channel;
cp->wdc_channel.wdc = &sc->sc_wdcdev;
- cp->wdc_channel.ch_queue =
- malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+ cp->wdc_channel.ch_queue = wdc_alloc_queue();
if (cp->wdc_channel.ch_queue == NULL) {
printf("%s %s: "
- "can't allocate memory for command queue",
+ "cannot allocate channel queue",
sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
return;
}
@@ -4604,11 +4601,10 @@ sii3114_chansetup(struct pciide_softc *sc, int channel)
cp->name = channel_names[channel];
cp->wdc_channel.channel = channel;
cp->wdc_channel.wdc = &sc->sc_wdcdev;
- cp->wdc_channel.ch_queue =
- malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+ cp->wdc_channel.ch_queue = wdc_alloc_queue();
if (cp->wdc_channel.ch_queue == NULL) {
printf("%s %s channel: "
- "can't allocate memory for command queue",
+ "cannot allocate channel queue",
sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
return (0);
}
@@ -4804,10 +4800,9 @@ cy693_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
cp->name = PCIIDE_CHANNEL_NAME(0);
cp->wdc_channel.channel = 0;
cp->wdc_channel.wdc = &sc->sc_wdcdev;
- cp->wdc_channel.ch_queue =
- malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+ cp->wdc_channel.ch_queue = wdc_alloc_queue();
if (cp->wdc_channel.ch_queue == NULL) {
- printf(": cannot allocate memory for command queue\n");
+ printf(": cannot allocate channel queue\n");
return;
}
printf(", %s %s to ", PCIIDE_CHANNEL_NAME(0),
@@ -6804,11 +6799,10 @@ pdcsata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
cp->name = NULL;
cp->wdc_channel.channel = channel;
cp->wdc_channel.wdc = &sc->sc_wdcdev;
- cp->wdc_channel.ch_queue =
- malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+ cp->wdc_channel.ch_queue = wdc_alloc_queue();
if (cp->wdc_channel.ch_queue == NULL) {
printf("%s: channel %d: "
- "can't allocate memory for command queue\n",
+ "cannot allocate channel queue\n",
sc->sc_wdcdev.sc_dev.dv_xname, channel);
continue;
}
diff --git a/sys/dev/pcmcia/wdc_pcmcia.c b/sys/dev/pcmcia/wdc_pcmcia.c
index 04e484a211d..39ada125c16 100644
--- a/sys/dev/pcmcia/wdc_pcmcia.c
+++ b/sys/dev/pcmcia/wdc_pcmcia.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wdc_pcmcia.c,v 1.25 2011/03/31 13:05:27 jasper Exp $ */
+/* $OpenBSD: wdc_pcmcia.c,v 1.26 2011/05/09 22:33:54 matthew Exp $ */
/* $NetBSD: wdc_pcmcia.c,v 1.19 1999/02/19 21:49:43 abs Exp $ */
/*-
@@ -343,10 +343,9 @@ wdc_pcmcia_attach(parent, self, aux)
sc->sc_wdcdev.nchannels = 1;
sc->wdc_channel.channel = 0;
sc->wdc_channel.wdc = &sc->sc_wdcdev;
- sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
- M_DEVBUF, M_NOWAIT);
+ sc->wdc_channel.ch_queue = wdc_alloc_queue();
if (sc->wdc_channel.ch_queue == NULL) {
- printf("can't allocate memory for command queue\n");
+ printf("cannot allocate channel queue\n");
goto ch_queue_alloc_failed;
}
if (quirks & WDC_PCMCIA_NO_EXTRA_RESETS)
@@ -406,7 +405,7 @@ wdc_pcmcia_detach(self, flags)
return (error);
if (sc->wdc_channel.ch_queue != NULL)
- free(sc->wdc_channel.ch_queue, M_DEVBUF);
+ wdc_free_queue(sc->wdc_channel.ch_queue);
/* Unmap our i/o window and i/o space. */
pcmcia_io_unmap(sc->sc_pf, sc->sc_iowindow);