staging: comedi: addi_apci_3120: use dma_alloc_coherent()
Use `dma_alloc_coherent()` to allocate the DMA buffers instead of using `__get_free_pages()` to allocate and `virt_to_bus()` to get the hardware address. The coherent buffers are fairly small - at most 4 pages (although there are two of them). Use of `virt_to_bus()` is discouraged. Note: `struct addi_private` is used by some other ADDI-DATA drivers as well, but this is the only one using the affected members. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
9c97e588d8
commit
fbfd9c8a17
|
@ -677,7 +677,7 @@ config COMEDI_ADDI_APCI_2200
|
||||||
|
|
||||||
config COMEDI_ADDI_APCI_3120
|
config COMEDI_ADDI_APCI_3120
|
||||||
tristate "ADDI-DATA APCI_3120/3001 support"
|
tristate "ADDI-DATA APCI_3120/3001 support"
|
||||||
depends on VIRT_TO_BUS
|
depends on HAS_DMA
|
||||||
select COMEDI_FC
|
select COMEDI_FC
|
||||||
---help---
|
---help---
|
||||||
Enable support for ADDI-DATA APCI_3120/3001 cards
|
Enable support for ADDI-DATA APCI_3120/3001 cards
|
||||||
|
|
|
@ -107,10 +107,9 @@ struct addi_private {
|
||||||
unsigned char b_DmaDoubleBuffer; /* we can use double buffering */
|
unsigned char b_DmaDoubleBuffer; /* we can use double buffering */
|
||||||
unsigned int ui_DmaActualBuffer; /* which buffer is used now */
|
unsigned int ui_DmaActualBuffer; /* which buffer is used now */
|
||||||
unsigned short *ul_DmaBufferVirtual[2]; /* pointers to DMA buffer */
|
unsigned short *ul_DmaBufferVirtual[2]; /* pointers to DMA buffer */
|
||||||
unsigned int ul_DmaBufferHw[2]; /* hw address of DMA buff */
|
dma_addr_t ul_DmaBufferHw[2]; /* hw address of DMA buff */
|
||||||
unsigned int ui_DmaBufferSize[2]; /* size of dma buffer in bytes */
|
unsigned int ui_DmaBufferSize[2]; /* size of dma buffer in bytes */
|
||||||
unsigned int ui_DmaBufferUsesize[2]; /* which size we may now used for transfer */
|
unsigned int ui_DmaBufferUsesize[2]; /* which size we may now used for transfer */
|
||||||
unsigned int ui_DmaBufferPageOrder[2]; /* log2 of pages in buffer */
|
|
||||||
unsigned char b_DigitalOutputRegister; /* Digital Output Register */
|
unsigned char b_DigitalOutputRegister; /* Digital Output Register */
|
||||||
unsigned char b_OutputMemoryStatus;
|
unsigned char b_OutputMemoryStatus;
|
||||||
unsigned char b_TimerSelectMode; /* Contain data written at iobase + 0C */
|
unsigned char b_TimerSelectMode; /* Contain data written at iobase + 0C */
|
||||||
|
|
|
@ -95,17 +95,16 @@ static int apci3120_auto_attach(struct comedi_device *dev,
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
for (order = 2; order >= 0; order--) {
|
for (order = 2; order >= 0; order--) {
|
||||||
devpriv->ul_DmaBufferVirtual[i] =
|
devpriv->ul_DmaBufferVirtual[i] =
|
||||||
(void *)__get_free_pages(GFP_KERNEL, order);
|
dma_alloc_coherent(dev->hw_dev, PAGE_SIZE << order,
|
||||||
|
&devpriv->ul_DmaBufferHw[i],
|
||||||
|
GFP_KERNEL);
|
||||||
|
|
||||||
if (devpriv->ul_DmaBufferVirtual[i])
|
if (devpriv->ul_DmaBufferVirtual[i])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!devpriv->ul_DmaBufferVirtual[i])
|
if (!devpriv->ul_DmaBufferVirtual[i])
|
||||||
break;
|
break;
|
||||||
devpriv->ui_DmaBufferPageOrder[i] = order;
|
|
||||||
devpriv->ui_DmaBufferSize[i] = PAGE_SIZE << order;
|
devpriv->ui_DmaBufferSize[i] = PAGE_SIZE << order;
|
||||||
devpriv->ul_DmaBufferHw[i] =
|
|
||||||
virt_to_bus(devpriv->ul_DmaBufferVirtual[i]);
|
|
||||||
}
|
}
|
||||||
if (!devpriv->ul_DmaBufferVirtual[0])
|
if (!devpriv->ul_DmaBufferVirtual[0])
|
||||||
devpriv->us_UseDma = 0;
|
devpriv->us_UseDma = 0;
|
||||||
|
@ -198,15 +197,16 @@ static void apci3120_detach(struct comedi_device *dev)
|
||||||
apci3120_reset(dev);
|
apci3120_reset(dev);
|
||||||
comedi_pci_detach(dev);
|
comedi_pci_detach(dev);
|
||||||
if (devpriv) {
|
if (devpriv) {
|
||||||
if (devpriv->ul_DmaBufferVirtual[0]) {
|
unsigned int i;
|
||||||
free_pages((unsigned long)devpriv->
|
|
||||||
ul_DmaBufferVirtual[0],
|
for (i = 0; i < 2; i++) {
|
||||||
devpriv->ui_DmaBufferPageOrder[0]);
|
if (devpriv->ul_DmaBufferVirtual[i]) {
|
||||||
}
|
dma_free_coherent(dev->hw_dev,
|
||||||
if (devpriv->ul_DmaBufferVirtual[1]) {
|
devpriv->ui_DmaBufferSize[i],
|
||||||
free_pages((unsigned long)devpriv->
|
devpriv->
|
||||||
ul_DmaBufferVirtual[1],
|
ul_DmaBufferVirtual[i],
|
||||||
devpriv->ui_DmaBufferPageOrder[1]);
|
devpriv->ul_DmaBufferHw[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue