Re: [RFC/PATCH 1/4] pci: Add pci_enable_device_{io,mem} intefaces

Johannes Weiner
2007-12-17T23:51:22Z

Hi Benjamin,

Benjamin Herrenschmidt <benh@kernel.crashing.org> writes:

> --- linux-work.orig/drivers/pci/pci.c 2007-12-18 09:37:56.000000000 +1100
> +++ linux-work/drivers/pci/pci.c 2007-12-18 09:38:25.000000000 +1100
> [...]
> +int pci_enable_device_io(struct pci_dev *dev)
> +{
> + int err;
> + int i, bars = 0;
> +
> + if (atomic_add_return(1, &dev->enable_cnt) > 1)
> + return 0; /* already enabled */
> +
> + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
> + if (dev->resource[i].flags & IORESOURCE_IO)
> + bars |= (1 << i);
> +
> + err = do_pci_enable_device(dev, bars);
> + if (err < 0)
> + atomic_dec(&dev->enable_cnt);
> + return err;
> +}
> [...]
> +int pci_enable_device_mem(struct pci_dev *dev)
> +{
> + int err;
> + int i, bars = 0;
> +
> + if (atomic_add_return(1, &dev->enable_cnt) > 1)
> + return 0; /* already enabled */
> +
> + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
> + if (dev->resource[i].flags & IORESOURCE_MEM)
> + bars |= (1 << i);
> +
> + err = do_pci_enable_device(dev, bars);
> + if (err < 0)
> + atomic_dec(&dev->enable_cnt);
> + return err;
> +}

These two functions should be refactored, the only difference is the
flag checking.

Hannes