Commit c400c1e1 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: amplc_dio200_pci: use pci_ioremap_bar()

Use `pci_ioremap_bar()` to ioremap the PCI memory resources.  That
function just takes the PCI device and a bar index.  It also has some
additional sanity checks to make sure the bar is actually a memory
resource.

Eliminate some local variables from `dio200_pcie_board_setup()` and
`dio200_pci_auto_attach()` that were used to hold the results of
`pci_resource_len()` and `pci_resource_start()` that were only used
once.  Also eliminate the check that the bar is a memory resource in
`dio200_pcie_board_setup()` as `pci_ioremap_bar()` will do that for us.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Reviewed-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fed9fd2c
...@@ -339,7 +339,6 @@ static int dio200_pcie_board_setup(struct comedi_device *dev) ...@@ -339,7 +339,6 @@ static int dio200_pcie_board_setup(struct comedi_device *dev)
{ {
struct pci_dev *pcidev = comedi_to_pci_dev(dev); struct pci_dev *pcidev = comedi_to_pci_dev(dev);
void __iomem *brbase; void __iomem *brbase;
resource_size_t brlen;
/* /*
* The board uses Altera Cyclone IV with PCI-Express hard IP. * The board uses Altera Cyclone IV with PCI-Express hard IP.
...@@ -351,13 +350,11 @@ static int dio200_pcie_board_setup(struct comedi_device *dev) ...@@ -351,13 +350,11 @@ static int dio200_pcie_board_setup(struct comedi_device *dev)
* Enable" register at offset 0x50 to allow generation of PCIe * Enable" register at offset 0x50 to allow generation of PCIe
* interrupts when RXmlrq_i is asserted in the SOPC Builder system. * interrupts when RXmlrq_i is asserted in the SOPC Builder system.
*/ */
brlen = pci_resource_len(pcidev, 0); if (pci_resource_len(pcidev, 0) < 0x4000) {
if (brlen < 0x4000 ||
!(pci_resource_flags(pcidev, 0) & IORESOURCE_MEM)) {
dev_err(dev->class_dev, "error! bad PCI region!\n"); dev_err(dev->class_dev, "error! bad PCI region!\n");
return -EINVAL; return -EINVAL;
} }
brbase = ioremap_nocache(pci_resource_start(pcidev, 0), brlen); brbase = pci_ioremap_bar(pcidev, 0);
if (!brbase) { if (!brbase) {
dev_err(dev->class_dev, "error! failed to map registers!\n"); dev_err(dev->class_dev, "error! failed to map registers!\n");
return -ENOMEM; return -ENOMEM;
...@@ -375,7 +372,6 @@ static int dio200_pci_auto_attach(struct comedi_device *dev, ...@@ -375,7 +372,6 @@ static int dio200_pci_auto_attach(struct comedi_device *dev,
struct pci_dev *pci_dev = comedi_to_pci_dev(dev); struct pci_dev *pci_dev = comedi_to_pci_dev(dev);
const struct dio200_board *thisboard = NULL; const struct dio200_board *thisboard = NULL;
struct dio200_private *devpriv; struct dio200_private *devpriv;
resource_size_t base, len;
unsigned int bar; unsigned int bar;
int ret; int ret;
...@@ -399,14 +395,12 @@ static int dio200_pci_auto_attach(struct comedi_device *dev, ...@@ -399,14 +395,12 @@ static int dio200_pci_auto_attach(struct comedi_device *dev,
return ret; return ret;
bar = thisboard->mainbar; bar = thisboard->mainbar;
base = pci_resource_start(pci_dev, bar); if (pci_resource_len(pci_dev, bar) < thisboard->mainsize) {
len = pci_resource_len(pci_dev, bar);
if (len < thisboard->mainsize) {
dev_err(dev->class_dev, "error! PCI region size too small!\n"); dev_err(dev->class_dev, "error! PCI region size too small!\n");
return -EINVAL; return -EINVAL;
} }
if (pci_resource_flags(pci_dev, bar) & IORESOURCE_MEM) { if (pci_resource_flags(pci_dev, bar) & IORESOURCE_MEM) {
devpriv->io.u.membase = ioremap_nocache(base, len); devpriv->io.u.membase = pci_ioremap_bar(pci_dev, bar);
if (!devpriv->io.u.membase) { if (!devpriv->io.u.membase) {
dev_err(dev->class_dev, dev_err(dev->class_dev,
"error! cannot remap registers\n"); "error! cannot remap registers\n");
...@@ -414,7 +408,7 @@ static int dio200_pci_auto_attach(struct comedi_device *dev, ...@@ -414,7 +408,7 @@ static int dio200_pci_auto_attach(struct comedi_device *dev,
} }
devpriv->io.regtype = mmio_regtype; devpriv->io.regtype = mmio_regtype;
} else { } else {
devpriv->io.u.iobase = (unsigned long)base; devpriv->io.u.iobase = pci_resource_start(pci_dev, bar);
devpriv->io.regtype = io_regtype; devpriv->io.regtype = io_regtype;
} }
switch (context_model) { switch (context_model) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment