lkml.org 
[lkml]   [2007]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    SubjectRe: [PATCH] Clarify pci_iomap() usage for MMIO-only devices
    Linus Torvalds wrote:
    > Why do people insist on
    > using the old interfaces (and matching them with the new setup)?


    readl/writel is [slightly] faster, and possibility of using even-write
    __raw_writel() exists, in the old interface...

    ...but pci_iomap() is a bus-friendly wrapper that handles a few checks
    and function calls for you, even if you know your device is always MMIO.

    A new pci_mmio_map() helper, to be used with 100% MMIO hardware, might
    help eliminate confusion.

    Jeff


    diff --git a/include/asm-generic/iomap.h b/include/asm-generic/iomap.h
    index cde592f..69e5390 100644
    --- a/include/asm-generic/iomap.h
    +++ b/include/asm-generic/iomap.h
    @@ -63,6 +63,7 @@ extern void ioport_unmap(void __iomem *);
    /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
    struct pci_dev;
    extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
    +extern void __iomem *pci_mmio_map(struct pci_dev *dev, int bar, unsigned long max);
    extern void pci_iounmap(struct pci_dev *dev, void __iomem *);

    #endif
    diff --git a/lib/iomap.c b/lib/iomap.c
    index 864f2ec..c87d7f3 100644
    --- a/lib/iomap.c
    +++ b/lib/iomap.c
    @@ -275,9 +275,32 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
    return NULL;
    }

    +/* for people who wish to use readl/writel exclusively */
    +void __iomem *pci_mmio_map(struct pci_dev *dev, int bar, unsigned long maxlen)
    +{
    + unsigned long start = pci_resource_start(dev, bar);
    + unsigned long len = pci_resource_len(dev, bar);
    + unsigned long flags = pci_resource_flags(dev, bar);
    +
    + if (!len || !start)
    + return NULL;
    + if (maxlen && len > maxlen)
    + len = maxlen;
    + if (flags & IORESOURCE_IO)
    + return NULL;
    + if (flags & IORESOURCE_MEM) {
    + if (flags & IORESOURCE_CACHEABLE)
    + return ioremap(start, len);
    + return ioremap_nocache(start, len);
    + }
    + /* What? */
    + return NULL;
    +}
    +
    void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
    {
    IO_COND(addr, /* nothing */, iounmap(addr));
    }
    EXPORT_SYMBOL(pci_iomap);
    +EXPORT_SYMBOL(pci_mmio_map);
    EXPORT_SYMBOL(pci_iounmap);
    \
     
     \ /
      Last update: 2007-09-18 22:25    [W:0.024 / U:30.460 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site