From b58a29586b128f093a3495b80c68b85fd368598c Mon Sep 17 00:00:00 2001 From: David Schleef Date: Fri, 22 Nov 2002 06:55:05 +0000 Subject: [PATCH] Change buf_alloc to buf_change, and fix allocation and mapping of buffers. Added buf_page_list with list of pointers to buffer pages. --- comedi/comedi_fops.c | 24 ++-- comedi/drivers.c | 88 +++++++++----- comedi/drivers/mite.c | 231 +++---------------------------------- comedi/drivers/mite.h | 4 +- comedi/drivers/ni_pcidio.c | 6 +- comedi/drivers/ni_pcimio.c | 43 ++----- include/linux/comedidev.h | 52 +-------- 7 files changed, 104 insertions(+), 344 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 6beb4771..996f69f1 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -231,10 +231,13 @@ static int do_bufconfig_ioctl(comedi_device *dev,void *arg) * (we round up) */ bc.size = (bc.size + 1)&PAGE_MASK; - ret = s->buf_alloc(dev,s,bc.size); + ret = comedi_buf_alloc(dev, s, bc.size); + if(ret < 0) return ret; - if(ret < 0) - return ret; + if(s->buf_change){ + ret = s->buf_change(dev,s,bc.size); + if(ret < 0) return ret; + } DPRINTK("comedi%i subd %d buffer resized to %i bytes\n", dev->minor, bc.subdevice, async->prealloc_bufsz); @@ -1212,10 +1215,10 @@ static int comedi_mmap_v22(struct file * file, struct vm_area_struct *vma) kdev_t minor=MINOR(RDEV_OF_FILE(file)); comedi_device *dev=comedi_get_device_by_minor(minor); comedi_async *async = NULL; - unsigned long pos; unsigned long start = vma->vm_start; unsigned long size; - unsigned long page; + int n_pages; + int i; if(!dev->attached) { @@ -1250,16 +1253,13 @@ static int comedi_mmap_v22(struct file * file, struct vm_area_struct *vma) if(size&(~PAGE_MASK)) return -EFAULT; - pos = (unsigned long)async->prealloc_buf; - while(size>0){ - page = kvirt_to_pa(pos); - if(remap_page_range(start, page, PAGE_SIZE, PAGE_SHARED)){ + n_pages = size >> PAGE_SHIFT; + for(i=0;ibuf_page_list[i]), + PAGE_SIZE, PAGE_SHARED)){ return -EAGAIN; } - - pos += PAGE_SIZE; start += PAGE_SIZE; - size -= PAGE_SIZE; } vma->vm_ops = &comedi_vm_ops; diff --git a/comedi/drivers.c b/comedi/drivers.c index c2c4e966..276f5c2f 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -37,8 +37,6 @@ #include -//#include "kvmem.h" - static int postconfig(comedi_device *dev); static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s, comedi_insn *insn,lsampl_t *data); @@ -46,7 +44,7 @@ static int insn_inval(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,l static void *comedi_recognize(comedi_driver *driv, const char *name); static void comedi_report_boards(comedi_driver *driv); static int poll_invalid(comedi_device *dev,comedi_subdevice *s); -static int buf_alloc(comedi_device *dev, comedi_subdevice *s, +int comedi_buf_alloc(comedi_device *dev, comedi_subdevice *s, unsigned long new_size); comedi_driver *comedi_drivers; @@ -73,7 +71,8 @@ int comedi_device_detach(comedi_device *dev) for(i=0;in_subdevices;i++){ s=dev->subdevices+i; if(s->async){ - if(s->buf_alloc) s->buf_alloc(dev,s,0); + comedi_buf_alloc(dev, s, 0); + if(s->buf_change) s->buf_change(dev,s,0); kfree(s->async); } } @@ -225,6 +224,7 @@ static int postconfig(comedi_device *dev) int i; comedi_subdevice *s; comedi_async *async = NULL; + int ret; for(i=0;in_subdevices;i++){ s=dev->subdevices+i; @@ -249,14 +249,17 @@ static int postconfig(comedi_device *dev) #define DEFAULT_BUF_SIZE (64*1024) async->max_bufsize = DEFAULT_BUF_MAXSIZE; - if(!s->buf_alloc) s->buf_alloc = buf_alloc; async->prealloc_buf = NULL; async->prealloc_bufsz = 0; - if(s->buf_alloc(dev,s,DEFAULT_BUF_SIZE) < 0){ + if(comedi_buf_alloc(dev,s,DEFAULT_BUF_SIZE) < 0){ printk("Buffer allocation failed\n"); return -ENOMEM; } + if(s->buf_change){ + ret = s->buf_change(dev,s,DEFAULT_BUF_SIZE); + if(ret < 0)return ret; + } } if(!s->range_table && !s->range_table_list) @@ -358,14 +361,39 @@ static int insn_rw_emulate_bits(comedi_device *dev,comedi_subdevice *s, return 1; } -/* - * Default allocator for Comedi buffers - * Override function should allocate a new buffer of size new_size, - * and update async->prealloc_buf and async->prealloc_bufsz. Set - * NULL and 0 if the allocation fails. If new_size is 0, deallocate - * the old buffer and don't allocate a new one. - */ -static int buf_alloc(comedi_device *dev, comedi_subdevice *s, + +static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) +{ + unsigned long ret = 0UL; + pmd_t *pmd; + pte_t *ptep, pte; + + if(!pgd_none(*pgd)){ + pmd = pmd_offset(pgd, adr); + if(!pmd_none(*pmd)){ + ptep = pte_offset(pmd, adr); + pte = *ptep; + if(pte_present(pte)){ + ret = (unsigned long) page_address(pte_page(pte)); + ret |= (adr & (PAGE_SIZE - 1)); + } + } + } + return ret; +} + +static inline unsigned long kvirt_to_kva(unsigned long adr) +{ + unsigned long va, kva; + + va = VMALLOC_VMADDR(adr); + kva = uvirt_to_kva(pgd_offset_k(va), va); + + return kva; +} + + +int comedi_buf_alloc(comedi_device *dev, comedi_subdevice *s, unsigned long new_size) { comedi_async *async = s->async; @@ -376,43 +404,41 @@ static int buf_alloc(comedi_device *dev, comedi_subdevice *s, } if(async->prealloc_bufsz){ - unsigned long adr, size; - unsigned long page; + int i; + int n_pages = async->prealloc_bufsz >> PAGE_SHIFT; - size = async->prealloc_bufsz; - adr = (unsigned long)async->prealloc_buf; - while(size>0){ - page = kvirt_to_pa(adr); - mem_map_unreserve(virt_to_page(__va(page))); - adr += PAGE_SIZE; - size -= PAGE_SIZE; + for(i=0;ibuf_page_list[i])))); } vfree(async->prealloc_buf); async->prealloc_buf = NULL; + kfree(async->buf_page_list); + async->buf_page_list = NULL; } if(new_size){ unsigned long adr; - unsigned long size; - unsigned long page; + int n_pages = new_size >> PAGE_SHIFT; + int i; + async->buf_page_list = kmalloc(sizeof(unsigned long)*n_pages, GFP_KERNEL); async->prealloc_buf = vmalloc_32(new_size); if(async->prealloc_buf == NULL){ async->prealloc_bufsz = 0; + kfree(async->buf_page_list); return -ENOMEM; } memset(async->prealloc_buf,0,new_size); adr = (unsigned long)async->prealloc_buf; - size = new_size; - while(size > 0){ - page = kvirt_to_pa(adr); - mem_map_reserve(virt_to_page(__va(page))); + for(i=0;ibuf_page_list[i] = kvirt_to_kva(adr); + mem_map_reserve(virt_to_page(__va(__pa(async->buf_page_list[i])))); adr += PAGE_SIZE; - size -= PAGE_SIZE; } } + async->prealloc_bufsz = new_size; return 0; @@ -422,7 +448,7 @@ static int buf_alloc(comedi_device *dev, comedi_subdevice *s, void comedi_buf_munge( comedi_device *dev, comedi_subdevice *s, unsigned int num_bytes ) { - unsigned int offset = s->async->buf_write_count; + unsigned int offset = s->async->buf_write_ptr; if( s->munge == NULL || ( s->async->cmd.flags & CMDF_RAWDATA ) ) return; diff --git a/comedi/drivers/mite.c b/comedi/drivers/mite.c index 54efecab..43000a32 100644 --- a/comedi/drivers/mite.c +++ b/comedi/drivers/mite.c @@ -53,7 +53,6 @@ #include #include -#include #include "mite.h" @@ -183,98 +182,6 @@ void mite_list_devices(void) } -#if 0 -int mite_kvmem_segment_load(struct mite_struct *mite,int i,char *kvmem,unsigned int len) -{ - int count,offset; - - offset=((int)kvmem)&(PAGE_SIZE-1); - - mite->ring[i].addr = cpu_to_le32(kvirt_to_bus((int)kvmem)); - - count=PAGE_SIZE-offset; - if(count>len)count=len; - mite->ring[i].count = cpu_to_le32(count); - - return count; -} - - -/* - * Create the short linkchaining MITE linked list using kernel memory - */ -unsigned long mite_ll_from_kvmem(struct mite_struct *mite,comedi_async *async,int reqlen) -{ - int i,size_so_far, continuous_aq, len; - unsigned long nup; - unsigned long prealloc_buf,prealloc_bufsz; - - MDPRINTK("mite_ll_from_kvmem\n"); - prealloc_buf=(unsigned long)async->prealloc_buf; - prealloc_bufsz=async->prealloc_bufsz; - - continuous_aq = (async->cmd.stop_src == TRIG_NONE? 1:0); - if(continuous_aq) { - len = prealloc_bufsz; - }else{ - len = (reqlen>prealloc_bufsz?prealloc_bufsz:reqlen); - } - - //find the kernel's memory pages. - nup = (unsigned long)async->data; - i=0; - size_so_far=0; - MDPRINTK("buf=0x%08lx bufsz=0x%08lx\n", - (unsigned long)prealloc_buf,prealloc_bufsz); - - while(((void*)nup < (async->data+len))&&(i<(MITE_RING_SIZE-1))) { - int count; - count = 1+TOP_OF_PAGE(nup)-nup; - if(count>len-size_so_far) count = len-size_so_far; - // it's already a kernel address :-) - mite->ring[i].addr = cpu_to_le32(kvirt_to_bus(nup)); - mite->ring[i].count = cpu_to_le32(count); - mite->ring[i].next = cpu_to_le32(virt_to_bus(mite->ring+i+1)); - size_so_far += count; - nup += count; - i++; - } - - /*End the mite->ring by setting the last element's count to 0. - To make a looping ring for continuous acquisition, - mite->ring[i-1].next = cpu_to_le32(virt_to_bus(mite->ring)); - */ - //mite->ring[i].count=0; - - if (continuous_aq&&(i>0)) { - mite->ring[i-1].next = cpu_to_le32(virt_to_bus(mite->ring+0)); - mite->DMA_CheckNearEnd = 0; - }else if (prealloc_bufsz < reqlen) { - mite->ring[i-1].next = cpu_to_le32(virt_to_bus(mite->ring+0)); - mite->DMA_CheckNearEnd = 1; - } - else { - mite->ring[i].count=0; - mite->DMA_CheckNearEnd = 0; - } - - - MDPRINTK("i was %d, size_so_far was %d\n",i,size_so_far); - if(size_so_farComedi Error: MITE_RING_SIZE is too small to hold the needed buffer\n"); - } -#ifdef DEBUG_MITE - for(i=0; iring[i].addr, - mite->ring[i].next, mite->ring[i].count); - } -#endif - MDPRINTK("exit mite_ll_from_kvmem\n"); - return virt_to_bus(&(mite->ring[0])); -} -#endif - - void mite_dma_arm( struct mite_struct *mite, unsigned int channel ) { int chor; @@ -288,60 +195,6 @@ void mite_dma_arm( struct mite_struct *mite, unsigned int channel ) } -#if 0 -void mite_setregs(struct mite_struct *mite,unsigned long ll_start,int chan,int dir) -{ - //*mite is the mite to work with - //ll_start is the beginning of the linkshort mite linked list - //chan is the DMA channel to use on the MITE (0,1,2,3) - //dir is the direction of the transfer COMEDI_INPUT or COMEDI_OUTPUT - int chor,chcr,mcr,dcr,lkcr; - - MDPRINTK("mite_setregs\n"); - - chor = CHOR_DMARESET | CHOR_FRESET; //reset DMA and FIFO - writel(chor,mite->mite_io_addr+MITE_CHOR+CHAN_OFFSET(chan)); - - //short link chaining mode - chcr = CHCR_SET_DMA_IE| CHCR_LINKSHORT | CHCR_SET_DONE_IE; - /*Link Complete Interrupt: interrupt every time a link in MITE_RING - is completed. This can generate a lot of extra interrupts, but right now we - update the values of buf_int_ptr and buf_int_count at each interrupt. A - better method is to poll the MITE before each user "read()" to calculate the - number of bytes available. mite_bytes_transferred() is provided to get the - number of bytes transferred to system memory so far. - */ - chcr |= CHCR_SET_LC_IE; - - if(dir == COMEDI_INPUT){ - chcr |= CHCR_DEV_TO_MEM; - } - writel(chcr,mite->mite_io_addr+MITE_CHCR+CHAN_OFFSET(chan)); - - //16 bits, to memory - mcr = CR_RL64 | CR_ASEQxP1 | CR_PSIZEHALF; - writel(mcr,mite->mite_io_addr+MITE_MCR+CHAN_OFFSET(chan)); - - //16 bits, from STC - dcr = CR_RL64 | CR_ASEQx(1) | CR_PSIZEHALF; - dcr |= CR_PORTIO | CR_AMDEVICE | CR_REQS(0x4+chan); - writel(dcr,mite->mite_io_addr+MITE_DCR+CHAN_OFFSET(chan)); - - //reset the DAR - writel(0,mite->mite_io_addr+MITE_DAR+CHAN_OFFSET(chan)); - - //the link is 32bits - lkcr = CR_RL64 | CR_ASEQUP | CR_PSIZEWORD; - writel(lkcr,mite->mite_io_addr+MITE_LKCR+CHAN_OFFSET(chan)); - - //starting address for link chaining - writel(ll_start,mite->mite_io_addr+MITE_LKAR+CHAN_OFFSET(chan)); - - MDPRINTK("exit mite_setregs\n"); -} -#endif - - /**************************************/ int mite_load_buffer(struct mite_struct *mite, unsigned int channel, comedi_async *async) @@ -363,7 +216,7 @@ int mite_load_buffer(struct mite_struct *mite, unsigned int channel, comedi_asyn n_links = async->prealloc_bufsz >> PAGE_SHIFT; - MDPRINTK("buf=%p buf(bus)=%p bufsz=0x%08x n_links=0x%04x\n", + MDPRINTK("buf=%p buf(bus)=%08lx bufsz=0x%08x n_links=0x%04x\n", async->prealloc_buf, virt_to_bus(async->prealloc_buf), async->prealloc_bufsz, n_links); mite_chan->ring = kmalloc(n_links * sizeof(struct mite_dma_chain), GFP_KERNEL); @@ -376,76 +229,22 @@ int mite_load_buffer(struct mite_struct *mite, unsigned int channel, comedi_asyn for(i=0;iring[i].count = cpu_to_le32(PAGE_SIZE); -#ifdef USE_KMALLOC - mite_chan->ring[i].addr = cpu_to_le32( - virt_to_bus(async->prealloc_buf + i*PAGE_SIZE)); -#else - mite_chan->ring[i].addr = cpu_to_le32( - kvirt_to_bus((unsigned long)async->prealloc_buf + i*PAGE_SIZE)); -#endif - mite_chan->ring[i].next = cpu_to_le32(virt_to_bus(mite_chan->ring+i+1)); + mite_chan->ring[i].addr = cpu_to_le32(virt_to_bus( + (void *)async->buf_page_list[i])); + mite_chan->ring[i].next = cpu_to_le32(virt_to_bus( + mite_chan->ring+i+1)); } - mite_chan->ring[n_links-1].next = cpu_to_le32(virt_to_bus(mite_chan->ring)); + mite_chan->ring[n_links-1].next = cpu_to_le32(virt_to_bus( + mite_chan->ring)); return 0; } -int mite_buf_alloc(struct mite_struct *mite, unsigned int channel, +int mite_buf_change(struct mite_struct *mite, unsigned int channel, comedi_async *async, unsigned long new_size) { - MDPRINTK("mite_buf_alloc ch%i\n", channel); - - if(async->prealloc_buf && async->prealloc_bufsz == new_size){ - return 0; - } - - if(async->prealloc_bufsz){ -#ifdef USE_KMALLOC - kfree(async->prealloc_buf); -#else - { - unsigned long addr = (unsigned long)async->prealloc_buf; - unsigned long size = async->prealloc_bufsz; - unsigned long page; - - while(size>0){ - page = kvirt_to_pa(addr); - mem_map_unreserve(virt_to_page(__va(page))); - addr += PAGE_SIZE; - size -= PAGE_SIZE; - } - } - vfree(async->prealloc_buf); -#endif - async->prealloc_buf = NULL; - async->prealloc_bufsz = 0; - } - - if(new_size){ -#ifdef USE_KMALLOC - async->prealloc_buf = kmalloc(new_size, GFP_KERNEL); -#else - async->prealloc_buf = vmalloc_32(new_size); - { - unsigned long addr = (unsigned long)async->prealloc_buf; - unsigned long size = async->prealloc_bufsz; - unsigned long page; - - while(size>0){ - page = kvirt_to_pa(addr); - mem_map_reserve(virt_to_page(__va(page))); - addr += PAGE_SIZE; - size -= PAGE_SIZE; - } - } -#endif - if(async->prealloc_buf == NULL){ - async->prealloc_bufsz = 0; - return -ENOMEM; - } - } - async->prealloc_bufsz = new_size; + MDPRINTK("mite_buf_change ch%i\n", channel); mite_load_buffer(mite, channel, async); @@ -578,6 +377,8 @@ void mite_dma_disarm(struct mite_struct *mite, unsigned int channel) #ifdef DEBUG_MITE +static void mite_decode(char **bit_str, unsigned int bits); + /* names of bits in mite registers */ static char *mite_CHOR_strings[] = { @@ -648,7 +449,7 @@ static char *mite_CHSR_strings[] = { "28", "lpauses", "30", "int", }; -void mite_dump_regs(struct mite_struct *mite, unsigned int channel) +void mite_dump_regs(struct mite_struct *mite, int channel) { unsigned long mite_io_addr = (unsigned long) mite->mite_io_addr; unsigned long addr=0; @@ -673,12 +474,12 @@ void mite_dump_regs(struct mite_struct *mite, unsigned int channel) printk("mite status[MAR] at 0x%08lx =0x%08x\n",addr, readl(addr)); addr = mite_io_addr+MITE_DCR+CHAN_OFFSET(channel); printk("mite status[DCR] at 0x%08lx =0x%08lx\n",addr, temp=readl(addr)); - mite_decode(mite_CR_strings,temp); + mite_decode(mite_DCR_strings,temp); addr = mite_io_addr+MITE_DAR+CHAN_OFFSET(channel); printk("mite status[DAR] at 0x%08lx =0x%08x\n",addr, readl(addr)); addr = mite_io_addr+MITE_LKCR+CHAN_OFFSET(channel); printk("mite status[LKCR]at 0x%08lx =0x%08lx\n",addr, temp=readl(addr)); - mite_decode(mite_CR_strings,temp); + mite_decode(mite_LKCR_strings,temp); addr = mite_io_addr+MITE_LKAR+CHAN_OFFSET(channel); printk("mite status[LKAR]at 0x%08lx =0x%08x\n",addr, readl(addr)); @@ -689,7 +490,7 @@ void mite_dump_regs(struct mite_struct *mite, unsigned int channel) printk("mite status[FCR] at 0x%08lx =0x%08x\n\n",addr, readl(addr)); } -void mite_decode(char **bit_str, unsigned int bits) +static void mite_decode(char **bit_str, unsigned int bits) { int i; @@ -730,7 +531,7 @@ EXPORT_SYMBOL(mite_setregs); EXPORT_SYMBOL(mite_devices); EXPORT_SYMBOL(mite_list_devices); EXPORT_SYMBOL(mite_prep_dma); -EXPORT_SYMBOL(mite_buf_alloc); +EXPORT_SYMBOL(mite_buf_change); EXPORT_SYMBOL(mite_bytes_transferred); EXPORT_SYMBOL(mite_bytes_read); EXPORT_SYMBOL(mite_bytes_in_transit); diff --git a/comedi/drivers/mite.h b/comedi/drivers/mite.h index 80d99dd1..c48a8d95 100644 --- a/comedi/drivers/mite.h +++ b/comedi/drivers/mite.h @@ -107,12 +107,12 @@ void mite_setregs(struct mite_struct *mite,unsigned long ll_start,int chan, int void mite_prep_dma(struct mite_struct *mite, unsigned int channel, unsigned int num_device_bits, unsigned int num_memory_bits ); -int mite_buf_alloc(struct mite_struct *mite, unsigned int channel, +int mite_buf_change(struct mite_struct *mite, unsigned int channel, comedi_async *async, unsigned long new_size); #ifdef DEBUG_MITE void mite_print_chsr(unsigned int chsr); -void mite_dump_regs(struct mite_struct *mite, channel); +void mite_dump_regs(struct mite_struct *mite, int channel); #endif #define CHAN_OFFSET(x) (0x100*(x)) diff --git a/comedi/drivers/ni_pcidio.c b/comedi/drivers/ni_pcidio.c index 288f22b0..32c86e65 100644 --- a/comedi/drivers/ni_pcidio.c +++ b/comedi/drivers/ni_pcidio.c @@ -903,12 +903,12 @@ static int ni_pcidio_cancel(comedi_device *dev, comedi_subdevice *s) } -static int ni_pcidio_alloc(comedi_device *dev, comedi_subdevice *s, +static int ni_pcidio_change(comedi_device *dev, comedi_subdevice *s, unsigned long new_size) { int ret; - ret = mite_buf_alloc(devpriv->mite, DI_DMA_CHAN, s->async, new_size); + ret = mite_buf_change(devpriv->mite, DI_DMA_CHAN, s->async, new_size); if(ret<0)return ret; memset(s->async->prealloc_buf, 0xaa, s->async->prealloc_bufsz); @@ -974,7 +974,7 @@ static int nidio_attach(comedi_device *dev,comedi_devconfig *it) s->do_cmdtest = ni_pcidio_cmdtest; s->cancel = ni_pcidio_cancel; s->len_chanlist=32; /* XXX */ - s->buf_alloc = ni_pcidio_alloc; + s->buf_change = ni_pcidio_change; writel(0,dev->iobase+Port_IO(0)); writel(0,dev->iobase+Port_Pin_Directions(0)); diff --git a/comedi/drivers/ni_pcimio.c b/comedi/drivers/ni_pcimio.c index 13b8efcd..62e3ffa1 100644 --- a/comedi/drivers/ni_pcimio.c +++ b/comedi/drivers/ni_pcimio.c @@ -704,9 +704,9 @@ typedef struct{ static int pcimio_find_device(comedi_device *dev,int bus,int slot); -static int pcimio_ai_alloc(comedi_device *dev, comedi_subdevice *s, +static int pcimio_ai_change(comedi_device *dev, comedi_subdevice *s, unsigned long new_size); -static int pcimio_ao_alloc(comedi_device *dev, comedi_subdevice *s, +static int pcimio_ao_change(comedi_device *dev, comedi_subdevice *s, unsigned long new_size); @@ -763,8 +763,8 @@ static int pcimio_attach(comedi_device *dev,comedi_devconfig *it) ret = ni_E_init(dev,it); if(ret<0)return ret; - dev->subdevices[0].buf_alloc = pcimio_ai_alloc; - dev->subdevices[1].buf_alloc = pcimio_ao_alloc; + dev->subdevices[0].buf_change = pcimio_ai_change; + dev->subdevices[1].buf_change = pcimio_ao_change; return ret; } @@ -797,50 +797,23 @@ static int pcimio_find_device(comedi_device *dev,int bus,int slot) return -EIO; } -static int pcimio_ai_alloc(comedi_device *dev, comedi_subdevice *s, +static int pcimio_ai_change(comedi_device *dev, comedi_subdevice *s, unsigned long new_size) { int ret; - ret = mite_buf_alloc(devpriv->mite, AI_DMA_CHAN, s->async, new_size); + ret = mite_buf_change(devpriv->mite, AI_DMA_CHAN, s->async, new_size); if(ret<0)return ret; return 0; -#if 0 - comedi_async *async = s->async; - - if(async->prealloc_buf && async->prealloc_bufsz == new_size){ - return 0; - } - - if(async->prealloc_bufsz){ - pci_free_consistent(devpriv->mite->pcidev, - async->prealloc_bufsz, async->prealloc_buf, - devpriv->ai_dma_handle); - async->prealloc_buf = NULL; - async->prealloc_bufsz = 0; - } - - if(new_size){ - async->prealloc_buf = pci_alloc_consistent(devpriv->mite->pcidev, - new_size, &devpriv->ai_dma_handle); - if(async->prealloc_buf == NULL){ - async->prealloc_bufsz = 0; - return -ENOMEM; - } - } - async->prealloc_bufsz = new_size; - - return 0; -#endif } -static int pcimio_ao_alloc(comedi_device *dev, comedi_subdevice *s, +static int pcimio_ao_change(comedi_device *dev, comedi_subdevice *s, unsigned long new_size) { int ret; - ret = mite_buf_alloc(devpriv->mite, AO_DMA_CHAN, s->async, new_size); + ret = mite_buf_change(devpriv->mite, AO_DMA_CHAN, s->async, new_size); if(ret<0)return ret; return 0; diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index 0d3ca599..f25a13cd 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -132,8 +132,8 @@ struct comedi_subdevice_struct{ //int (*do_lock)(comedi_device *,comedi_subdevice *); //int (*do_unlock)(comedi_device *,comedi_subdevice *); - /* buffer allocation overload function */ - int (*buf_alloc)(comedi_device *,comedi_subdevice *s,unsigned long new_size); + /* called when the buffer changes */ + int (*buf_change)(comedi_device *,comedi_subdevice *s,unsigned long new_size); void (*munge)( comedi_device *, comedi_subdevice *s, void *data, unsigned int num_bytes, unsigned int start_chan_index ); @@ -144,6 +144,7 @@ struct comedi_subdevice_struct{ struct comedi_async_struct{ void *prealloc_buf; /* pre-allocated buffer */ unsigned int prealloc_bufsz; /* buffer size, in bytes */ + unsigned long *buf_page_list; /* physical address of each page */ unsigned int max_bufsize; /* maximum buffer size, bytes */ unsigned int mmap_count; /* current number of mmaps of prealloc_buf */ @@ -236,13 +237,6 @@ const int comedi_debug = 0; void comedi_event(comedi_device *dev,comedi_subdevice *s,unsigned int mask); void comedi_error(comedi_device *dev,const char *s); -#if 0 -void comedi_done(comedi_device *dev,comedi_subdevice *s); -void comedi_error_done(comedi_device *dev,comedi_subdevice *s); -void comedi_eos(comedi_device *dev,comedi_subdevice *s); -void comedi_eobuf(comedi_device *dev,comedi_subdevice *s); -void comedi_bufcheck(comedi_device *dev,comedi_subdevice *s); -#endif comedi_device * comedi_get_device_by_minor(kdev_t minor); @@ -264,6 +258,9 @@ void cleanup_polling(void); void start_polling(comedi_device *); void stop_polling(comedi_device *); +int comedi_buf_alloc(comedi_device *dev, comedi_subdevice *s, unsigned long + new_size); + #ifdef CONFIG_PROC_FS void comedi_proc_init(void); void comedi_proc_cleanup(void); @@ -347,43 +344,6 @@ static inline unsigned int bytes_per_sample( const comedi_subdevice *subd ) return sizeof( sampl_t ); } -#if LINUX_VERSION_CODE >= 0x020200 -static inline unsigned long uvirt_to_kva(pgd_t *pgd, unsigned long adr) -{ - unsigned long ret = 0UL; - pmd_t *pmd; - pte_t *ptep, pte; - - if(!pgd_none(*pgd)){ - pmd = pmd_offset(pgd, adr); - if(!pmd_none(*pmd)){ - ptep = pte_offset(pmd, adr); - pte = *ptep; - if(pte_present(pte)){ - ret = (unsigned long) page_address(pte_page(pte)); - ret |= (adr & (PAGE_SIZE - 1)); - } - } - } - return ret; -} - -static inline unsigned long kvirt_to_pa(unsigned long adr) -{ - unsigned long va, kva, ret; - - va = VMALLOC_VMADDR(adr); - kva = uvirt_to_kva(pgd_offset_k(va), va); - ret = __pa(kva); - return ret; -} -#else -static inline unsigned long kvirt_to_pa(unsigned long adr) -{ - return 0; -} -#endif - int comedi_buf_put(comedi_async *async, sampl_t x); int comedi_buf_get(comedi_async *async, sampl_t *x); -- 2.26.2