Module Name: src Committed By: christos Date: Sun May 23 18:56:59 UTC 2010
Modified Files: src/sys/dev/ieee1394: firewire.c firewirereg.h fwdev.c fwdma.c fwmem.c fwohci.c fwohcivar.h if_fwip.c sbp.c Log Message: Revert all previous kmem_ commits. This needs to be done in a different way because we cannot call kmem_ from an interrupt context. I opened PR/43341 for it. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/dev/ieee1394/firewire.c cvs rdiff -u -r1.12 -r1.13 src/sys/dev/ieee1394/firewirereg.h cvs rdiff -u -r1.21 -r1.22 src/sys/dev/ieee1394/fwdev.c cvs rdiff -u -r1.15 -r1.16 src/sys/dev/ieee1394/fwdma.c cvs rdiff -u -r1.13 -r1.14 src/sys/dev/ieee1394/fwmem.c cvs rdiff -u -r1.127 -r1.128 src/sys/dev/ieee1394/fwohci.c cvs rdiff -u -r1.31 -r1.32 src/sys/dev/ieee1394/fwohcivar.h \ src/sys/dev/ieee1394/sbp.c cvs rdiff -u -r1.23 -r1.24 src/sys/dev/ieee1394/if_fwip.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ieee1394/firewire.c diff -u src/sys/dev/ieee1394/firewire.c:1.34 src/sys/dev/ieee1394/firewire.c:1.35 --- src/sys/dev/ieee1394/firewire.c:1.34 Sat May 22 22:24:40 2010 +++ src/sys/dev/ieee1394/firewire.c Sun May 23 14:56:58 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: firewire.c,v 1.34 2010/05/23 02:24:40 christos Exp $ */ +/* $NetBSD: firewire.c,v 1.35 2010/05/23 18:56:58 christos Exp $ */ /*- * Copyright (c) 2003 Hidetoshi Shimokawa * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: firewire.c,v 1.34 2010/05/23 02:24:40 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: firewire.c,v 1.35 2010/05/23 18:56:58 christos Exp $"); #include <sys/param.h> #include <sys/bus.h> @@ -48,8 +48,7 @@ #include <sys/errno.h> #include <sys/kernel.h> #include <sys/kthread.h> -#include <sys/kmem.h> -#include <sys/mutex.h> +#include <sys/malloc.h> #include <sys/queue.h> #include <sys/sysctl.h> #include <sys/systm.h> @@ -218,24 +217,28 @@ if (fc->nisodma > FWMAXNDMA) fc->nisodma = FWMAXNDMA; - fc->crom_src_buf = kmem_zalloc(sizeof(struct crom_src_buf), KM_NOSLEEP); + fc->crom_src_buf = + (struct crom_src_buf *)malloc(sizeof(struct crom_src_buf), + M_FW, M_NOWAIT | M_ZERO); if (fc->crom_src_buf == NULL) { - aprint_error_dev(fc->bdev, - "kmem alloc failure crom src buff\n"); + aprint_error_dev(fc->bdev, "Malloc Failure crom src buff\n"); return; } fc->topology_map = - kmem_zalloc(sizeof(struct fw_topology_map), KM_NOSLEEP); + (struct fw_topology_map *)malloc(sizeof(struct fw_topology_map), + M_FW, M_NOWAIT | M_ZERO); if (fc->topology_map == NULL) { aprint_error_dev(fc->dev, "Malloc Failure topology map\n"); - kmem_free(fc->crom_src_buf, sizeof(struct crom_src_buf)); + free(fc->crom_src_buf, M_FW); return; } - fc->speed_map = kmem_zalloc(sizeof(struct fw_speed_map), KM_NOSLEEP); + fc->speed_map = + (struct fw_speed_map *)malloc(sizeof(struct fw_speed_map), + M_FW, M_NOWAIT | M_ZERO); if (fc->speed_map == NULL) { aprint_error_dev(fc->dev, "Malloc Failure speed map\n"); - kmem_free(fc->crom_src_buf, sizeof(struct crom_src_buf)); - kmem_free(fc->topology_map, sizeof(struct fw_topology_map)); + free(fc->crom_src_buf, M_FW); + free(fc->topology_map, M_FW); return; } @@ -259,7 +262,7 @@ aprint_error_dev(self, "kthread_create failed\n"); config_pending_incr(); - devlist = kmem_alloc(sizeof(struct firewire_dev_list), KM_NOSLEEP); + devlist = malloc(sizeof(struct firewire_dev_list), M_DEVBUF, M_NOWAIT); if (devlist == NULL) { aprint_error_dev(self, "device list allocation failed\n"); return; @@ -270,7 +273,7 @@ faa.fwdev = NULL; devlist->dev = config_found(sc->dev, &faa, firewire_print); if (devlist->dev == NULL) - kmem_free(devlist, sizeof(struct firewire_dev_list)); + free(devlist, M_DEVBUF); else SLIST_INSERT_HEAD(&sc->devlist, devlist, link); @@ -312,7 +315,7 @@ if ((err = config_detach(devlist->dev, flags)) != 0) return err; SLIST_REMOVE(&sc->devlist, devlist, firewire_dev_list, link); - kmem_free(devlist, sizeof(struct firewire_dev_list)); + free(devlist, M_DEVBUF); } callout_stop(&fc->timeout_callout); @@ -323,11 +326,11 @@ for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL; fwdev = fwdev_next) { fwdev_next = STAILQ_NEXT(fwdev, link); - kmem_free(fwdev, sizeof(struct fw_device)); + free(fwdev, M_FW); } - kmem_free(fc->topology_map, sizeof(struct fw_topology_map)); - kmem_free(fc->speed_map, sizeof(struct fw_speed_map)); - kmem_free(fc->crom_src_buf, sizeof(struct crom_src_buf)); + free(fc->topology_map, M_FW); + free(fc->speed_map, M_FW); + free(fc->crom_src_buf, M_FW); cv_destroy(&fc->fc_cv); mutex_destroy(&fc->wait_lock); @@ -548,6 +551,7 @@ struct firewire_dev_list *devlist; struct firewire_dev_comm *fdc; struct crom_src *src; + uint32_t *newrom; if (fc->status == FWBUSMGRELECT) callout_stop(&fc->bmr_callout); @@ -582,13 +586,15 @@ * Configuration ROM. */ #define FW_MAX_GENERATION 0xF + newrom = malloc(CROMSIZE, M_FW, M_NOWAIT | M_ZERO); src = &fc->crom_src_buf->src; - crom_load(src, fc->new_rom, CROMSIZE); - if (memcmp(fc->new_rom, fc->config_rom, CROMSIZE) != 0) { + crom_load(src, newrom, CROMSIZE); + if (memcmp(newrom, fc->config_rom, CROMSIZE) != 0) { if (src->businfo.generation++ > FW_MAX_GENERATION) src->businfo.generation = FW_GENERATION_CHANGEABLE; - memcpy(fc->config_rom, fc->new_rom, CROMSIZE); + memcpy((void *)fc->config_rom, newrom, CROMSIZE); } + free(newrom, M_FW); } /* Call once after reboot */ @@ -804,7 +810,7 @@ { struct fw_xfer *xfer; - xfer = kmem_zalloc(sizeof(struct fw_xfer), KM_NOSLEEP); + xfer = malloc(sizeof(struct fw_xfer), type, M_NOWAIT | M_ZERO); if (xfer == NULL) return xfer; @@ -825,17 +831,17 @@ xfer->send.pay_len = send_len; xfer->recv.pay_len = recv_len; if (send_len > 0) { - xfer->send.payload = kmem_zalloc(send_len, KM_NOSLEEP); + xfer->send.payload = malloc(send_len, type, M_NOWAIT | M_ZERO); if (xfer->send.payload == NULL) { fw_xfer_free(xfer); return NULL; } } if (recv_len > 0) { - xfer->recv.payload = kmem_alloc(recv_len, KM_NOSLEEP); + xfer->recv.payload = malloc(recv_len, type, M_NOWAIT); if (xfer->recv.payload == NULL) { if (xfer->send.payload != NULL) - kmem_free(xfer->send.payload, send_len); + free(xfer->send.payload, type); fw_xfer_free(xfer); return NULL; } @@ -906,7 +912,7 @@ } fw_xfer_unload(xfer); cv_destroy(&xfer->cv); - kmem_free(xfer, sizeof(struct fw_xfer)); + free(xfer, xfer->malloc); } void @@ -918,12 +924,14 @@ return; } fw_xfer_unload(xfer); - if (xfer->send.pay_len > 0) - kmem_free(xfer->send.payload, xfer->send.pay_len); - if (xfer->recv.pay_len > 0) - kmem_free(xfer->recv.payload, xfer->recv.pay_len); + if (xfer->send.payload != NULL) { + free(xfer->send.payload, xfer->malloc); + } + if (xfer->recv.payload != NULL) { + free(xfer->recv.payload, xfer->malloc); + } cv_destroy(&xfer->cv); - kmem_free(xfer, sizeof(struct fw_xfer)); + free(xfer, xfer->malloc); } void @@ -1761,7 +1769,8 @@ mutex_exit(&fc->fc_mtx); if (fwdev == NULL) { /* new device */ - fwdev = kmem_zalloc(sizeof(struct fw_device), KM_NOSLEEP); + fwdev = + malloc(sizeof(struct fw_device), M_FW, M_NOWAIT | M_ZERO); if (fwdev == NULL) { if (firewire_debug) printf("node%d: no memory\n", node); @@ -1878,7 +1887,7 @@ char nodes[63]; todo = 0; - dfwdev = kmem_alloc(sizeof(struct fw_device), KM_NOSLEEP); + dfwdev = malloc(sizeof(*dfwdev), M_TEMP, M_NOWAIT); if (dfwdev == NULL) return; /* setup dummy fwdev */ @@ -1919,7 +1928,7 @@ } todo = todo2; } - kmem_free(dfwdev, sizeof(struct fw_device)); + free(dfwdev, M_TEMP); } static void @@ -1973,8 +1982,8 @@ mutex_exit(&fc->fc_mtx); switch (fwdev->status) { case FWDEVNEW: - devlist = kmem_alloc(sizeof(struct firewire_dev_list), - KM_NOSLEEP); + devlist = malloc(sizeof(struct firewire_dev_list), + M_DEVBUF, M_NOWAIT); if (devlist == NULL) { aprint_error_dev(fc->bdev, "memory allocation failed\n"); @@ -1988,8 +1997,7 @@ fwdev->sbp = config_found_sm_loc(sc->dev, "ieee1394if", locs, &fwa, firewire_print, config_stdsubmatch); if (fwdev->sbp == NULL) { - kmem_free(devlist, - sizeof(struct firewire_dev_list)); + free(devlist, M_DEVBUF); break; } @@ -2050,13 +2058,13 @@ SLIST_REMOVE(&sc->devlist, devlist, firewire_dev_list, link); - kmem_free(devlist, sizeof(struct firewire_dev_list)); + free(devlist, M_DEVBUF); if (config_detach(fwdev->sbp, DETACH_FORCE) != 0) return; STAILQ_REMOVE(&fc->devices, fwdev, fw_device, link); - kmem_free(fwdev, sizeof(struct fw_device)); + free(fwdev, M_FW); } } Index: src/sys/dev/ieee1394/firewirereg.h diff -u src/sys/dev/ieee1394/firewirereg.h:1.12 src/sys/dev/ieee1394/firewirereg.h:1.13 --- src/sys/dev/ieee1394/firewirereg.h:1.12 Sat May 22 22:24:40 2010 +++ src/sys/dev/ieee1394/firewirereg.h Sun May 23 14:56:58 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: firewirereg.h,v 1.12 2010/05/23 02:24:40 christos Exp $ */ +/* $NetBSD: firewirereg.h,v 1.13 2010/05/23 18:56:58 christos Exp $ */ /*- * Copyright (c) 2003 Hidetoshi Shimokawa * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa @@ -141,7 +141,6 @@ uint32_t csr_arc[CSRSIZE/4]; #define CROMSIZE 0x400 uint32_t *config_rom; - uint32_t *new_rom; struct crom_src_buf *crom_src_buf; struct crom_src *crom_src; struct crom_chunk *crom_root; Index: src/sys/dev/ieee1394/fwdev.c diff -u src/sys/dev/ieee1394/fwdev.c:1.21 src/sys/dev/ieee1394/fwdev.c:1.22 --- src/sys/dev/ieee1394/fwdev.c:1.21 Fri May 14 08:10:07 2010 +++ src/sys/dev/ieee1394/fwdev.c Sun May 23 14:56:58 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fwdev.c,v 1.21 2010/05/14 12:10:07 kiyohara Exp $ */ +/* $NetBSD: fwdev.c,v 1.22 2010/05/23 18:56:58 christos Exp $ */ /*- * Copyright (c) 2003 Hidetoshi Shimokawa * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fwdev.c,v 1.21 2010/05/14 12:10:07 kiyohara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fwdev.c,v 1.22 2010/05/23 18:56:58 christos Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -46,7 +46,7 @@ #include <sys/bus.h> #include <sys/conf.h> #include <sys/kernel.h> -#include <sys/kmem.h> +#include <sys/malloc.h> #include <sys/mbuf.h> #include <sys/poll.h> #include <sys/proc.h> @@ -91,7 +91,7 @@ static int fwdev_allocbuf(struct firewire_comm *, struct fw_xferq *, struct fw_bufspec *); -static int fwdev_freebuf(struct fw_xferq *, struct fw_bufspec *); +static int fwdev_freebuf(struct fw_xferq *); static int fw_read_async(struct fw_drv1 *, struct uio *, int); static int fw_write_async(struct fw_drv1 *, struct uio *, int); static void fw_hand(struct fw_xfer *); @@ -120,7 +120,7 @@ sc->si_drv1 = (void *)-1; mutex_exit(&sc->fc->fc_mtx); - sc->si_drv1 = kmem_zalloc(sizeof(struct fw_drv1), KM_SLEEP); + sc->si_drv1 = malloc(sizeof(struct fw_drv1), M_FW, M_WAITOK | M_ZERO); if (sc->si_drv1 == NULL) return ENOMEM; @@ -170,7 +170,7 @@ fc->irx_disable(fc, ir->dmach); } /* free extbuf */ - fwdev_freebuf(ir, &d->bufreq.rx); + fwdev_freebuf(ir); /* drain receiving buffer */ for (xfer = STAILQ_FIRST(&ir->q); xfer != NULL; xfer = STAILQ_FIRST(&ir->q)) { @@ -195,12 +195,12 @@ fc->itx_disable(fc, it->dmach); } /* free extbuf */ - fwdev_freebuf(it, &d->bufreq.tx); + fwdev_freebuf(it); it->flag &= ~(FWXFERQ_OPEN | FWXFERQ_MODEMASK | FWXFERQ_CHTAGMASK); d->it = NULL; } - kmem_free(sc->si_drv1, sizeof(struct fw_drv1)); + free(sc->si_drv1, M_FW); sc->si_drv1 = NULL; return err; @@ -577,8 +577,8 @@ err = EINVAL; break; } - fwb = (struct fw_bind *)kmem_alloc(sizeof(struct fw_bind), - KM_SLEEP); + fwb = (struct fw_bind *)malloc(sizeof(struct fw_bind), + M_FW, M_WAITOK); if (fwb == NULL) { err = ENOMEM; break; @@ -635,7 +635,7 @@ break; } /* myself */ - ptr = kmem_alloc(CROMSIZE, KM_SLEEP); + ptr = malloc(CROMSIZE, M_FW, M_WAITOK); len = CROMSIZE; for (i = 0; i < CROMSIZE/4; i++) ((uint32_t *)ptr)[i] = ntohl(fc->config_rom[i]); @@ -654,7 +654,7 @@ err = copyout(ptr, crom_buf->ptr, len); if (fwdev == NULL) /* myself */ - kmem_free(ptr, CROMSIZE); + free(ptr, M_FW); break; default: @@ -735,7 +735,8 @@ return EBUSY; q->bulkxfer = - kmem_alloc(sizeof(struct fw_bulkxfer) * b->nchunk, KM_SLEEP); + (struct fw_bulkxfer *)malloc(sizeof(struct fw_bulkxfer) * b->nchunk, + M_FW, M_WAITOK); if (q->bulkxfer == NULL) return ENOMEM; @@ -744,7 +745,7 @@ b->nchunk * b->npacket, BUS_DMA_WAITOK); if (q->buf == NULL) { - kmem_free(q->bulkxfer, sizeof(struct fw_bulkxfer) * b->nchunk); + free(q->bulkxfer, M_FW); q->bulkxfer = NULL; return ENOMEM; } @@ -772,14 +773,14 @@ } static int -fwdev_freebuf(struct fw_xferq *q, struct fw_bufspec *b) +fwdev_freebuf(struct fw_xferq *q) { if (q->flag & FWXFERQ_EXTBUF) { if (q->buf != NULL) fwdma_free_multiseg(q->buf); q->buf = NULL; - kmem_free(q->bulkxfer, sizeof(struct fw_bulkxfer) * b->nchunk); + free(q->bulkxfer, M_FW); q->bulkxfer = NULL; q->flag &= ~FWXFERQ_EXTBUF; q->psize = 0; Index: src/sys/dev/ieee1394/fwdma.c diff -u src/sys/dev/ieee1394/fwdma.c:1.15 src/sys/dev/ieee1394/fwdma.c:1.16 --- src/sys/dev/ieee1394/fwdma.c:1.15 Mon May 10 08:17:32 2010 +++ src/sys/dev/ieee1394/fwdma.c Sun May 23 14:56:58 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fwdma.c,v 1.15 2010/05/10 12:17:32 kiyohara Exp $ */ +/* $NetBSD: fwdma.c,v 1.16 2010/05/23 18:56:58 christos Exp $ */ /*- * Copyright (c) 2003 * Hidetoshi Shimokawa. All rights reserved. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fwdma.c,v 1.15 2010/05/10 12:17:32 kiyohara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fwdma.c,v 1.16 2010/05/23 18:56:58 christos Exp $"); #if defined(__FreeBSD__) __FBSDID("$FreeBSD: src/sys/dev/firewire/fwdma.c,v 1.9 2007/06/06 14:31:36 simokawa Exp $"); #endif @@ -46,7 +46,7 @@ #include <sys/systm.h> #include <sys/types.h> #include <sys/kernel.h> -#include <sys/kmem.h> +#include <sys/malloc.h> #include <sys/select.h> #include <machine/vmparam.h> @@ -155,9 +155,9 @@ } size = sizeof(struct fwdma_alloc_multi) + sizeof(struct fwdma_seg) * nseg; - am = kmem_zalloc(size, KM_SLEEP); + am = (struct fwdma_alloc_multi *)malloc(size, M_FW, M_WAITOK | M_ZERO); if (am == NULL) { - aprint_error_dev(fc->dev, "kmem alloc failed\n"); + aprint_error_dev(fc->dev, "malloc failed\n"); return NULL; } am->ssize = ssize; @@ -184,11 +184,8 @@ fwdma_free_multiseg(struct fwdma_alloc_multi *am) { struct fwdma_seg *seg; - int nseg; - nseg = am->nseg; for (seg = am->seg; am->nseg--; seg++) fwdma_free(am->dma_tag, seg->dma_map, seg->v_addr); - kmem_free(am, - sizeof(struct fwdma_alloc_multi) + sizeof(struct fwdma_seg) * nseg); + free(am, M_FW); } Index: src/sys/dev/ieee1394/fwmem.c diff -u src/sys/dev/ieee1394/fwmem.c:1.13 src/sys/dev/ieee1394/fwmem.c:1.14 --- src/sys/dev/ieee1394/fwmem.c:1.13 Mon May 10 08:17:32 2010 +++ src/sys/dev/ieee1394/fwmem.c Sun May 23 14:56:58 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fwmem.c,v 1.13 2010/05/10 12:17:32 kiyohara Exp $ */ +/* $NetBSD: fwmem.c,v 1.14 2010/05/23 18:56:58 christos Exp $ */ /*- * Copyright (c) 2002-2003 * Hidetoshi Shimokawa. All rights reserved. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fwmem.c,v 1.13 2010/05/10 12:17:32 kiyohara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fwmem.c,v 1.14 2010/05/23 18:56:58 christos Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -44,7 +44,7 @@ #include <sys/bus.h> #include <sys/conf.h> #include <sys/fcntl.h> -#include <sys/kmem.h> +#include <sys/malloc.h> #include <sys/sysctl.h> #include <dev/ieee1394/firewire.h> @@ -185,7 +185,9 @@ fms = (struct fwmem_softc *)sc->si_drv1; fms->refcount++; } else { - sc->si_drv1 = kmem_alloc(sizeof(struct fwmem_softc), KM_SLEEP); + sc->si_drv1 = (void *)-1; + sc->si_drv1 = malloc(sizeof(struct fwmem_softc), + M_FWMEM, M_WAITOK); if (sc->si_drv1 == NULL) return ENOMEM; fms = (struct fwmem_softc *)sc->si_drv1; @@ -223,7 +225,7 @@ STAILQ_REMOVE_HEAD(&fms->xferlist, link); fw_xfer_free(xfer); } - kmem_free(sc->si_drv1, sizeof(struct fwmem_softc)); + free(sc->si_drv1, M_FW); sc->si_drv1 = NULL; } Index: src/sys/dev/ieee1394/fwohci.c diff -u src/sys/dev/ieee1394/fwohci.c:1.127 src/sys/dev/ieee1394/fwohci.c:1.128 --- src/sys/dev/ieee1394/fwohci.c:1.127 Sat May 22 22:25:50 2010 +++ src/sys/dev/ieee1394/fwohci.c Sun May 23 14:56:58 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fwohci.c,v 1.127 2010/05/23 02:25:50 christos Exp $ */ +/* $NetBSD: fwohci.c,v 1.128 2010/05/23 18:56:58 christos Exp $ */ /*- * Copyright (c) 2003 Hidetoshi Shimokawa @@ -37,7 +37,7 @@ * */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fwohci.c,v 1.127 2010/05/23 02:25:50 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fwohci.c,v 1.128 2010/05/23 18:56:58 christos Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -46,7 +46,7 @@ #include <sys/errno.h> #include <sys/conf.h> #include <sys/kernel.h> -#include <sys/kmem.h> +#include <sys/malloc.h> #include <sys/mbuf.h> #include <sys/proc.h> #include <sys/reboot.h> @@ -414,7 +414,6 @@ aprint_error_dev(sc->fc.dev, "config_rom alloc failed."); return ENOMEM; } - sc->fc.new_rom = kmem_zalloc(CROMSIZE, KM_SLEEP); #if 0 memset(sc->fc.config_rom, 0, CROMSIZE); @@ -428,7 +427,7 @@ sc->fc.config_rom[0] |= fw_crc16(&sc->fc.config_rom[1], 5*4); #endif -/* SID receive buffer must align 2^11 */ +/* SID recieve buffer must align 2^11 */ #define OHCI_SIDSIZE (1 << 11) sc->sid_buf = fwdma_alloc_setup(sc->fc.dev, sc->fc.dmat, OHCI_SIDSIZE, &sc->sid_dma, OHCI_SIDSIZE, BUS_DMA_NOWAIT); @@ -436,7 +435,6 @@ aprint_error_dev(sc->fc.dev, "sid_buf alloc failed."); return ENOMEM; } - sc->sid_tmp_buf = kmem_alloc(OHCI_SIDSIZE, KM_SLEEP); fwdma_alloc_setup(sc->fc.dev, sc->fc.dmat, sizeof(uint32_t), &sc->dummy_dma, sizeof(uint32_t), BUS_DMA_NOWAIT); @@ -508,13 +506,9 @@ if (sc->sid_buf != NULL) fwdma_free(sc->sid_dma.dma_tag, sc->sid_dma.dma_map, sc->sid_dma.v_addr); - if (sc->sid_tmp_buf != NULL) - kmem_free(sc->sid_tmp_buf, OHCI_SIDSIZE); if (sc->fc.config_rom != NULL) fwdma_free(sc->crom_dma.dma_tag, sc->crom_dma.dma_map, sc->crom_dma.v_addr); - if (sc->fc.new_rom != NULL) - kmem_free(sc->fc.new_rom, CROMSIZE); fwohci_db_free(sc, &sc->arrq); fwohci_db_free(sc, &sc->arrs); @@ -1709,10 +1703,10 @@ db_tr->buf = NULL; } } + dbch->ndb = 0; db_tr = STAILQ_FIRST(&dbch->db_trq); fwdma_free_multiseg(dbch->am); - kmem_free(db_tr, sizeof(struct fwohcidb_tr) * dbch->ndb); - dbch->ndb = 0; + free(db_tr, M_FW); STAILQ_INIT(&dbch->db_trq); dbch->flags &= ~FWOHCI_DBCH_INIT; seldestroy(&dbch->xferq.rsel); @@ -1732,9 +1726,9 @@ /* allocate DB entries and attach one to each DMA channels */ /* DB entry must start at 16 bytes bounary. */ STAILQ_INIT(&dbch->db_trq); - db_tr = kmem_zalloc(db_tr_sz, KM_SLEEP); + db_tr = (struct fwohcidb_tr *)malloc(db_tr_sz, M_FW, M_WAITOK | M_ZERO); if (db_tr == NULL) { - aprint_error_dev(fc->dev, "kmem alloc failed\n"); + aprint_error_dev(fc->dev, "malloc(1) failed\n"); return; } @@ -1749,7 +1743,7 @@ #endif if (dbch->am == NULL) { aprint_error_dev(fc->dev, "fwdma_malloc_multiseg failed\n"); - kmem_free(db_tr, sizeof(struct fwohcidb_tr) * dbch->ndb); + free(db_tr, M_FW); return; } /* Attach DB to DMA ch. */ @@ -2146,7 +2140,11 @@ return; } plen -= 4; /* chop control info */ - buf = sc->sid_tmp_buf; + buf = (uint32_t *)malloc(OHCI_SIDSIZE, M_FW, M_NOWAIT); + if (buf == NULL) { + aprint_error_dev(fc->dev, "malloc failed\n"); + return; + } for (i = 0; i < plen / 4; i++) buf[i] = FWOHCI_DMA_READ(sc->sid_buf[i + 1]); #if 1 /* XXX needed?? */ @@ -2158,6 +2156,7 @@ fw_drain_txq(fc); #endif fw_sidrcv(fc, buf, plen); + free(buf, M_FW); } static void Index: src/sys/dev/ieee1394/fwohcivar.h diff -u src/sys/dev/ieee1394/fwohcivar.h:1.31 src/sys/dev/ieee1394/fwohcivar.h:1.32 --- src/sys/dev/ieee1394/fwohcivar.h:1.31 Sat May 22 22:25:50 2010 +++ src/sys/dev/ieee1394/fwohcivar.h Sun May 23 14:56:59 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fwohcivar.h,v 1.31 2010/05/23 02:25:50 christos Exp $ */ +/* $NetBSD: fwohcivar.h,v 1.32 2010/05/23 18:56:59 christos Exp $ */ /*- * Copyright (c) 2003 Hidetoshi SHimokawa @@ -66,7 +66,6 @@ } arrq, arrs, atrq, atrs, it[OHCI_DMA_ITCH], ir[OHCI_DMA_IRCH]; u_int maxrec; uint32_t *sid_buf; - uint32_t *sid_tmp_buf; struct fwdma_alloc sid_dma; struct fwdma_alloc crom_dma; struct fwdma_alloc dummy_dma; Index: src/sys/dev/ieee1394/sbp.c diff -u src/sys/dev/ieee1394/sbp.c:1.31 src/sys/dev/ieee1394/sbp.c:1.32 --- src/sys/dev/ieee1394/sbp.c:1.31 Mon May 10 08:17:33 2010 +++ src/sys/dev/ieee1394/sbp.c Sun May 23 14:56:59 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: sbp.c,v 1.31 2010/05/10 12:17:33 kiyohara Exp $ */ +/* $NetBSD: sbp.c,v 1.32 2010/05/23 18:56:59 christos Exp $ */ /*- * Copyright (c) 2003 Hidetoshi Shimokawa * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sbp.c,v 1.31 2010/05/10 12:17:33 kiyohara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sbp.c,v 1.32 2010/05/23 18:56:59 christos Exp $"); #include <sys/param.h> @@ -47,8 +47,8 @@ #include <sys/callout.h> #include <sys/condvar.h> #include <sys/kernel.h> -#include <sys/kmem.h> #include <sys/kthread.h> +#include <sys/malloc.h> #include <sys/mutex.h> #include <sys/proc.h> #include <sys/sysctl.h> @@ -708,14 +708,12 @@ /* Reallocate */ if (maxlun != target->num_lun) { - const int sbp_dev_p_sz = sizeof(struct sbp_dev *); + newluns = (struct sbp_dev **) realloc(target->luns, + sizeof(struct sbp_dev *) * maxlun, + M_SBP, M_NOWAIT | M_ZERO); - newluns = kmem_alloc(sbp_dev_p_sz * maxlun, KM_NOSLEEP); - if (newluns != NULL) - memcpy(*newluns, target->luns, - sizeof(struct sbp_dev *) * target->num_lun); - else { - aprint_error_dev(sc->sc_fd.dev, "kmem alloc failed\n"); + if (newluns == NULL) { + aprint_error_dev(sc->sc_fd.dev, "realloc failed\n"); newluns = target->luns; maxlun = target->num_lun; } @@ -724,9 +722,12 @@ * We must zero the extended region for the case * realloc() doesn't allocate new buffer. */ - if (maxlun > target->num_lun) + if (maxlun > target->num_lun) { + const int sbp_dev_p_sz = sizeof(struct sbp_dev *); + memset(&newluns[target->num_lun], 0, sbp_dev_p_sz * (maxlun - target->num_lun)); + } target->luns = newluns; target->num_lun = maxlun; @@ -748,10 +749,11 @@ sdev = target->luns[lun]; if (sdev == NULL) { - sdev = kmem_zalloc(sizeof(struct sbp_dev), KM_NOSLEEP); + sdev = malloc(sizeof(struct sbp_dev), + M_SBP, M_NOWAIT | M_ZERO); if (sdev == NULL) { aprint_error_dev(sc->sc_fd.dev, - "kmem alloc failed\n"); + "malloc failed\n"); goto next; } target->luns[lun] = sdev; @@ -785,7 +787,7 @@ fwdma_alloc_setup(sc->sc_fd.dev, sc->sc_dmat, SBP_DMA_SIZE, &sdev->dma, sizeof(uint32_t), BUS_DMA_NOWAIT); if (sdev->dma.v_addr == NULL) { - kmem_free(sdev, sizeof(struct sbp_dev)); + free(sdev, M_SBP); target->luns[lun] = NULL; goto next; } @@ -2046,7 +2048,7 @@ for (i = 0; i < SBP_QUEUE_LEN; i++) bus_dmamap_destroy(sc->sc_dmat, sdev->ocb[i].dmamap); fwdma_free(sdev->dma.dma_tag, sdev->dma.dma_map, sdev->dma.v_addr); - kmem_free(sdev, sizeof(struct sbp_dev)); + free(sdev, M_SBP); sdev = NULL; } @@ -2068,7 +2070,7 @@ fw_xfer_free_buf(xfer); } STAILQ_INIT(&target->xferlist); - kmem_free(target->luns, sizeof(struct sbp_dev *) * target->num_lun); + free(target->luns, M_SBP); target->num_lun = 0; target->luns = NULL; target->fwdev = NULL; @@ -2215,8 +2217,7 @@ /* XXX give up */ sbp_scsipi_detach_target(target); if (target->luns != NULL) - kmem_free(target->luns, - sizeof(struct sbp_dev *) * target->num_lun); + free(target->luns, M_SBP); target->num_lun = 0; target->luns = NULL; target->fwdev = NULL; Index: src/sys/dev/ieee1394/if_fwip.c diff -u src/sys/dev/ieee1394/if_fwip.c:1.23 src/sys/dev/ieee1394/if_fwip.c:1.24 --- src/sys/dev/ieee1394/if_fwip.c:1.23 Mon May 10 08:17:32 2010 +++ src/sys/dev/ieee1394/if_fwip.c Sun May 23 14:56:59 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: if_fwip.c,v 1.23 2010/05/10 12:17:32 kiyohara Exp $ */ +/* $NetBSD: if_fwip.c,v 1.24 2010/05/23 18:56:59 christos Exp $ */ /*- * Copyright (c) 2004 * Doug Rabson @@ -38,13 +38,13 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_fwip.c,v 1.23 2010/05/10 12:17:32 kiyohara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_fwip.c,v 1.24 2010/05/23 18:56:59 christos Exp $"); #include <sys/param.h> #include <sys/bus.h> #include <sys/device.h> #include <sys/errno.h> -#include <sys/kmem.h> +#include <sys/malloc.h> #include <sys/mbuf.h> #include <sys/mutex.h> #include <sys/sysctl.h> @@ -344,8 +344,6 @@ fc = sc->sc_fd.fc; if (sc->sc_dma_ch < 0) { - const size_t size = sizeof(struct fw_bulkxfer) * rx_queue_len; - sc->sc_dma_ch = fw_open_isodma(fc, /* tx */0); if (sc->sc_dma_ch < 0) return ENXIO; @@ -362,9 +360,11 @@ xferq->psize = MCLBYTES; xferq->queued = 0; xferq->buf = NULL; - xferq->bulkxfer = kmem_alloc(size, KM_SLEEP); + xferq->bulkxfer = (struct fw_bulkxfer *) malloc( + sizeof(struct fw_bulkxfer) * xferq->bnchunk, + M_FWIP, M_WAITOK); if (xferq->bulkxfer == NULL) { - aprint_error_ifnet(ifp, "if_fwip: kmem alloc failed\n"); + aprint_error_ifnet(ifp, "if_fwip: malloc failed\n"); return ENOMEM; } STAILQ_INIT(&xferq->stvalid); @@ -455,8 +455,7 @@ for (i = 0; i < xferq->bnchunk; i++) m_freem(xferq->bulkxfer[i].mbuf); - kmem_free(xferq->bulkxfer, - sizeof(struct fw_bulkxfer) * xferq->bnchunk); + free(xferq->bulkxfer, M_FWIP); fw_bindremove(fc, &sc->sc_fwb); for (xfer = STAILQ_FIRST(&sc->sc_fwb.xferlist); xfer != NULL;