From 4efc4bbdc1602d887d784be629a7a4efbf6b6e19 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 10 May 2013 14:07:15 +0100 Subject: staging: comedi: work without HAS_DMA The core "comedi" module and the "mite" helper module for NI PCI devices both have calls to `dma_alloc_coherent()` and `dma_free_coherent()`. Those functions are only available if `CONFIG_HAS_DMA` is defined. Apart from the "mite" module, the functions are only called for comedi drivers that set `s->async_dma_dir` (where `s` is a pointer to a `struct comedi_subdevice`) to anything other than `DMA_NONE`. Change local helper functions `__comedi_buf_alloc()` and `__comedi_buf_free()` to only call `dma_alloc_coherent()` and `dma_free_coherent()` if `CONFIG_HAS_DMA` is defined. Change the "Kconfig" to make the following configuration options depend on `HAS_DMA`: `COMEDI_MITE` - builds the "mite" module. `COMEDI_NI_6527` - selects `COMEDI_MITE`. `COMEDI_NI_65XX` - selects `COMEDI_MITE`. `COMEDI_NI_670X` - selects `COMEDI_MITE`. `COMEDI_NI_LABPC_PCI` - selects `COMEDI_MITE`. `COMEDI_NI_PCIDIO` - selects `COMEDI_MITE`. `COMEDI_NI_TIOCMD` - selects `COMEDI_MITE`. `COMEDI_NI_660X` - selects `COMEDI_NI_TIOCMD`, sets `s->async_dma_dir`. `COMEDI_NI_PCIMIO` - selects `COMEDI_NI_TIOCMD`, sets `s->async_dma_dir`. Signed-off-by: Ian Abbott Reviewed-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/comedi_buf.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/staging/comedi/comedi_buf.c') diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index ca709901fb3e..b6cd67ad55d1 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -51,10 +51,12 @@ static void __comedi_buf_free(struct comedi_device *dev, clear_bit(PG_reserved, &(virt_to_page(buf->virt_addr)->flags)); if (s->async_dma_dir != DMA_NONE) { +#ifdef CONFIG_HAS_DMA dma_free_coherent(dev->hw_dev, PAGE_SIZE, buf->virt_addr, buf->dma_addr); +#endif } else { free_page((unsigned long)buf->virt_addr); } @@ -84,11 +86,15 @@ static void __comedi_buf_alloc(struct comedi_device *dev, for (i = 0; i < n_pages; i++) { buf = &async->buf_page_list[i]; if (s->async_dma_dir != DMA_NONE) +#ifdef CONFIG_HAS_DMA buf->virt_addr = dma_alloc_coherent(dev->hw_dev, PAGE_SIZE, &buf->dma_addr, GFP_KERNEL | __GFP_COMP); +#else + break; +#endif else buf->virt_addr = (void *)get_zeroed_page(GFP_KERNEL); if (!buf->virt_addr) -- cgit v1.2.3-55-g7522 From e9166139f6f829c2e7bf6695f13e08d09303d6ca Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Fri, 10 May 2013 14:07:16 +0100 Subject: staging: comedi: complain if dma buffer allocation not supported When allocating a buffer to support asynchronous comedi commands, if a DMA coherent buffer was requested but `CONFIG_HAS_DMA` is undefined, bail out of local helper function `__comedi_buf_alloc()` with an error message. Signed-off-by: Ian Abbott Reviewed-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/comedi_buf.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/staging/comedi/comedi_buf.c') diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index b6cd67ad55d1..d4be0e68509b 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -76,6 +76,12 @@ static void __comedi_buf_alloc(struct comedi_device *dev, struct comedi_buf_page *buf; unsigned i; + if (!IS_ENABLED(CONFIG_HAS_DMA) && s->async_dma_dir != DMA_NONE) { + dev_err(dev->class_dev, + "dma buffer allocation not supported\n"); + return; + } + async->buf_page_list = vzalloc(sizeof(*buf) * n_pages); if (async->buf_page_list) pages = vmalloc(sizeof(struct page *) * n_pages); -- cgit v1.2.3-55-g7522