/* atmdma.c */ /* DMA management routines for ATM device driver */ /* Copyright (c) 1996 Robert Geist and James Westall * Clemson University Dept. of Computer Science * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define ONE_PAGE (4096) #define FB_SIZE_WORDS (2*1024*1024) #define DMA_BUFSIZE (128*1024) #define MAX_DMA (DMA_BUFSIZE - ONE_PAGE) #define KMALLOC_HDR_SIZE (24) #include "atmdd.h" static int dma_mapped = 0; /* DMA area mapped? */ static int dma_alloc = 0; /* DMA area allocated? */ static unsigned int *vbase; static unsigned int *kmalloc_base0; static unsigned int *kmalloc_base1; /**/ /* Allocate a couple of DMA'able buffers */ int atm_getdma( struct pddtype *ape) { unsigned int *uspace_ptr; unsigned char *tbase; /* Don't allow a second call here */ if (dma_alloc) return(1); /* Allocate two large contiguous buffer pools, memmap them */ /* and then return the virtual and physical addresses to */ /* the user. Since kmalloc reserves a small header at */ /* the beginning of each allocated block and we memmap */ /* requires page aligned units, we are not able to use */ /* any of the first allocated page! */ kmalloc_base0 = (unsigned int *) kmalloc(sizeof(struct rbptype), GFP_DMA); if(!kmalloc_base0) { printk("Kmalloc for ATM DMA buffer 0 failed \n"); return(1); } kmalloc_base1 = (unsigned int *) kmalloc(sizeof(struct xbptype), GFP_DMA); if(!kmalloc_base1) { printk("Kmalloc for ATM DMA buffer 1 failed \n"); return(1); } memset(kmalloc_base0, 0, sizeof(struct rbptype)); memset(kmalloc_base1, 0, sizeof(struct xbptype)); ape->dmabuf[0].kbase = kmalloc_base0; ape->dmabuf[1].kbase = kmalloc_base1; ape->rbpool = (struct rbptype *)ape->dmabuf[0].kbase; ape->xbpool = (struct xbptype *)ape->dmabuf[1].kbase; ape->dmabuf[0].phys_base = virt_to_phys(ape->dmabuf[0].kbase); ape->dmabuf[1].phys_base = virt_to_phys(ape->dmabuf[1].kbase); printk("ape->dmabuf[0].kbase is %x\n", ape->dmabuf[0].kbase); printk("ape->dmabuf[0].phys_base is %x\n", ape->dmabuf[0].phys_base); dma_alloc = 1; return(0); } /**/ /* Free the kmalloc'd DMA buffers */ int atm_freedma( struct pddtype *ape) { if (dma_alloc) { kfree(kmalloc_base0); kfree(kmalloc_base1); } dma_alloc = 0; }