Home | History | Annotate | Line # | Download | only in usb
usb_mem.h revision 1.5
      1 /*	$NetBSD: usb_mem.h,v 1.5 1999/08/17 16:06:21 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (augustss (at) carlstedt.se) at
      9  * Carlstedt Research & Technology.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *        This product includes software developed by the NetBSD
     22  *        Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #if defined(__NetBSD__) || defined(__OpenBSD__)
     41 typedef struct usb_block_dma {
     42 	bus_dma_tag_t tag;
     43 	bus_dmamap_t map;
     44         caddr_t kaddr;
     45         bus_dma_segment_t segs[1];
     46         int nsegs;
     47         size_t size;
     48         size_t align;
     49 	int fullblock;
     50 	LIST_ENTRY(usb_block_dma) next;
     51 } usb_dma_block_t;
     52 
     53 typedef struct {
     54 	usb_dma_block_t *block;
     55 	u_int offs;
     56 } usb_dma_t;
     57 
     58 #define DMAADDR(dma) ((dma)->block->segs[0].ds_addr + (dma)->offs)
     59 #define KERNADDR(dma) ((void *)((dma)->block->kaddr + (dma)->offs))
     60 
     61 usbd_status	usb_allocmem __P((bus_dma_tag_t, size_t, size_t, usb_dma_t *));
     62 void		usb_freemem  __P((bus_dma_tag_t, usb_dma_t *));
     63 
     64 #elif defined(__FreeBSD__)
     65 
     66 /*
     67  * FreeBSD does not have special functions for dma memory, so let's keep it
     68  * simple for now.
     69  */
     70 
     71 #include <sys/param.h>
     72 #include <sys/systm.h>
     73 #include <sys/queue.h>
     74 #include <sys/proc.h>
     75 #include <sys/buf.h>
     76 #include <sys/malloc.h>
     77 #include <sys/kernel.h>
     78 #include <vm/vm.h>
     79 #include <vm/pmap.h>
     80 
     81 #include <machine/pmap.h>       /* for vtophys */
     82 
     83 typedef void * usb_dma_t;
     84 
     85 #define		usb_allocmem(t,s,a,p)	(*(p) = malloc(s, M_USB, M_NOWAIT), (*(p) == NULL? USBD_NOMEM: USBD_NORMAL_COMPLETION))
     86 #define		usb_freemem(t,p)	(free(*(p), M_USB))
     87 
     88 #define DMAADDR(dma)	(vtophys(*(dma)))
     89 #define KERNADDR(dma)	((void *) *(dma))
     90 #endif
     91 
     92