183c2dc15ce824450e7044b9f90cd529c25747ae0David Howells/* ASB2305 PCI I/O mapping handler 283c2dc15ce824450e7044b9f90cd529c25747ae0David Howells * 383c2dc15ce824450e7044b9f90cd529c25747ae0David Howells * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 483c2dc15ce824450e7044b9f90cd529c25747ae0David Howells * Written by David Howells (dhowells@redhat.com) 583c2dc15ce824450e7044b9f90cd529c25747ae0David Howells * 683c2dc15ce824450e7044b9f90cd529c25747ae0David Howells * This program is free software; you can redistribute it and/or 783c2dc15ce824450e7044b9f90cd529c25747ae0David Howells * modify it under the terms of the GNU General Public Licence 883c2dc15ce824450e7044b9f90cd529c25747ae0David Howells * as published by the Free Software Foundation; either version 983c2dc15ce824450e7044b9f90cd529c25747ae0David Howells * 2 of the Licence, or (at your option) any later version. 1083c2dc15ce824450e7044b9f90cd529c25747ae0David Howells */ 1183c2dc15ce824450e7044b9f90cd529c25747ae0David Howells#include <linux/pci.h> 1283c2dc15ce824450e7044b9f90cd529c25747ae0David Howells#include <linux/module.h> 1383c2dc15ce824450e7044b9f90cd529c25747ae0David Howells 1483c2dc15ce824450e7044b9f90cd529c25747ae0David Howells/* 1583c2dc15ce824450e7044b9f90cd529c25747ae0David Howells * Create a virtual mapping cookie for a PCI BAR (memory or IO) 1683c2dc15ce824450e7044b9f90cd529c25747ae0David Howells */ 1783c2dc15ce824450e7044b9f90cd529c25747ae0David Howellsvoid __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen) 1883c2dc15ce824450e7044b9f90cd529c25747ae0David Howells{ 1983c2dc15ce824450e7044b9f90cd529c25747ae0David Howells resource_size_t start = pci_resource_start(dev, bar); 2083c2dc15ce824450e7044b9f90cd529c25747ae0David Howells resource_size_t len = pci_resource_len(dev, bar); 2183c2dc15ce824450e7044b9f90cd529c25747ae0David Howells unsigned long flags = pci_resource_flags(dev, bar); 2283c2dc15ce824450e7044b9f90cd529c25747ae0David Howells 2383c2dc15ce824450e7044b9f90cd529c25747ae0David Howells if (!len || !start) 2483c2dc15ce824450e7044b9f90cd529c25747ae0David Howells return NULL; 2583c2dc15ce824450e7044b9f90cd529c25747ae0David Howells 2683c2dc15ce824450e7044b9f90cd529c25747ae0David Howells if ((flags & IORESOURCE_IO) || (flags & IORESOURCE_MEM)) { 2783c2dc15ce824450e7044b9f90cd529c25747ae0David Howells if (flags & IORESOURCE_CACHEABLE && !(flags & IORESOURCE_IO)) 2883c2dc15ce824450e7044b9f90cd529c25747ae0David Howells return ioremap(start, len); 2983c2dc15ce824450e7044b9f90cd529c25747ae0David Howells else 3083c2dc15ce824450e7044b9f90cd529c25747ae0David Howells return ioremap_nocache(start, len); 3183c2dc15ce824450e7044b9f90cd529c25747ae0David Howells } 3283c2dc15ce824450e7044b9f90cd529c25747ae0David Howells 3383c2dc15ce824450e7044b9f90cd529c25747ae0David Howells return NULL; 3483c2dc15ce824450e7044b9f90cd529c25747ae0David Howells} 3583c2dc15ce824450e7044b9f90cd529c25747ae0David HowellsEXPORT_SYMBOL(pci_iomap); 36