| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: usb_mem.c,v 1.78 2021/01/02 12:39:03 jmcneill Exp $ */ | | 1 | /* $NetBSD: usb_mem.c,v 1.79 2021/01/05 16:15:09 skrll Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Lennart Augustsson (lennart@augustsson.net) at | | 8 | * by Lennart Augustsson (lennart@augustsson.net) at |
9 | * Carlstedt Research & Technology. | | 9 | * Carlstedt Research & Technology. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -28,27 +28,27 @@ | | | @@ -28,27 +28,27 @@ |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | * POSSIBILITY OF SUCH DAMAGE. | | 30 | * POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | /* | | 33 | /* |
34 | * USB DMA memory allocation. | | 34 | * USB DMA memory allocation. |
35 | * We need to allocate a lot of small (many 8 byte, some larger) | | 35 | * We need to allocate a lot of small (many 8 byte, some larger) |
36 | * memory blocks that can be used for DMA. Using the bus_dma | | 36 | * memory blocks that can be used for DMA. Using the bus_dma |
37 | * routines directly would incur large overheads in space and time. | | 37 | * routines directly would incur large overheads in space and time. |
38 | */ | | 38 | */ |
39 | | | 39 | |
40 | #include <sys/cdefs.h> | | 40 | #include <sys/cdefs.h> |
41 | __KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.78 2021/01/02 12:39:03 jmcneill Exp $"); | | 41 | __KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.79 2021/01/05 16:15:09 skrll Exp $"); |
42 | | | 42 | |
43 | #ifdef _KERNEL_OPT | | 43 | #ifdef _KERNEL_OPT |
44 | #include "opt_usb.h" | | 44 | #include "opt_usb.h" |
45 | #endif | | 45 | #endif |
46 | | | 46 | |
47 | #include <sys/param.h> | | 47 | #include <sys/param.h> |
48 | #include <sys/bus.h> | | 48 | #include <sys/bus.h> |
49 | #include <sys/cpu.h> | | 49 | #include <sys/cpu.h> |
50 | #include <sys/device.h> /* for usbdivar.h */ | | 50 | #include <sys/device.h> /* for usbdivar.h */ |
51 | #include <sys/kernel.h> | | 51 | #include <sys/kernel.h> |
52 | #include <sys/kmem.h> | | 52 | #include <sys/kmem.h> |
53 | #include <sys/once.h> | | 53 | #include <sys/once.h> |
54 | #include <sys/queue.h> | | 54 | #include <sys/queue.h> |
| @@ -201,32 +201,28 @@ usb_block_allocmem(bus_dma_tag_t tag, si | | | @@ -201,32 +201,28 @@ usb_block_allocmem(bus_dma_tag_t tag, si |
201 | bus_dmamem_free(tag, b->segs, b->nsegs); | | 201 | bus_dmamem_free(tag, b->segs, b->nsegs); |
202 | free0: | | 202 | free0: |
203 | kmem_free(b->segs, b->nsegs_alloc * sizeof(*b->segs)); | | 203 | kmem_free(b->segs, b->nsegs_alloc * sizeof(*b->segs)); |
204 | kmem_free(b, sizeof(*b)); | | 204 | kmem_free(b, sizeof(*b)); |
205 | mutex_enter(&usb_blk_lock); | | 205 | mutex_enter(&usb_blk_lock); |
206 | | | 206 | |
207 | return USBD_NOMEM; | | 207 | return USBD_NOMEM; |
208 | } | | 208 | } |
209 | | | 209 | |
210 | #if 0 | | 210 | #if 0 |
211 | void | | 211 | void |
212 | usb_block_real_freemem(usb_dma_block_t *b) | | 212 | usb_block_real_freemem(usb_dma_block_t *b) |
213 | { | | 213 | { |
214 | #ifdef DIAGNOSTIC | | 214 | ASSERT_SLEEPABLE(); |
215 | if (cpu_softintr_p() || cpu_intr_p()) { | | 215 | |
216 | printf("usb_block_real_freemem: in interrupt context\n"); | | | |
217 | return; | | | |
218 | } | | | |
219 | #endif | | | |
220 | bus_dmamap_unload(b->tag, b->map); | | 216 | bus_dmamap_unload(b->tag, b->map); |
221 | bus_dmamap_destroy(b->tag, b->map); | | 217 | bus_dmamap_destroy(b->tag, b->map); |
222 | bus_dmamem_unmap(b->tag, b->kaddr, b->size); | | 218 | bus_dmamem_unmap(b->tag, b->kaddr, b->size); |
223 | bus_dmamem_free(b->tag, b->segs, b->nsegs); | | 219 | bus_dmamem_free(b->tag, b->segs, b->nsegs); |
224 | kmem_free(b->segs, b->nsegs_alloc * sizeof(*b->segs)); | | 220 | kmem_free(b->segs, b->nsegs_alloc * sizeof(*b->segs)); |
225 | kmem_free(b, sizeof(*b)); | | 221 | kmem_free(b, sizeof(*b)); |
226 | } | | 222 | } |
227 | #endif | | 223 | #endif |
228 | | | 224 | |
229 | #ifdef DEBUG | | 225 | #ifdef DEBUG |
230 | static bool | | 226 | static bool |
231 | usb_valid_block_p(usb_dma_block_t *b, struct usb_dma_block_qh *qh) | | 227 | usb_valid_block_p(usb_dma_block_t *b, struct usb_dma_block_qh *qh) |
232 | { | | 228 | { |