~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/pci_iomap.c

Version: ~ [ linux-5.9-rc6 ] ~ [ linux-5.8.10 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.66 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.146 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.198 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.236 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.236 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Implement the default iomap interfaces
  4  *
  5  * (C) Copyright 2004 Linus Torvalds
  6  */
  7 #include <linux/pci.h>
  8 #include <linux/io.h>
  9 
 10 #include <linux/export.h>
 11 
 12 #ifdef CONFIG_PCI
 13 /**
 14  * pci_iomap_range - create a virtual mapping cookie for a PCI BAR
 15  * @dev: PCI device that owns the BAR
 16  * @bar: BAR number
 17  * @offset: map memory at the given offset in BAR
 18  * @maxlen: max length of the memory to map
 19  *
 20  * Using this function you will get a __iomem address to your device BAR.
 21  * You can access it using ioread*() and iowrite*(). These functions hide
 22  * the details if this is a MMIO or PIO address space and will just do what
 23  * you expect from them in the correct way.
 24  *
 25  * @maxlen specifies the maximum length to map. If you want to get access to
 26  * the complete BAR from offset to the end, pass %0 here.
 27  * */
 28 void __iomem *pci_iomap_range(struct pci_dev *dev,
 29                               int bar,
 30                               unsigned long offset,
 31                               unsigned long maxlen)
 32 {
 33         resource_size_t start = pci_resource_start(dev, bar);
 34         resource_size_t len = pci_resource_len(dev, bar);
 35         unsigned long flags = pci_resource_flags(dev, bar);
 36 
 37         if (len <= offset || !start)
 38                 return NULL;
 39         len -= offset;
 40         start += offset;
 41         if (maxlen && len > maxlen)
 42                 len = maxlen;
 43         if (flags & IORESOURCE_IO)
 44                 return __pci_ioport_map(dev, start, len);
 45         if (flags & IORESOURCE_MEM)
 46                 return ioremap(start, len);
 47         /* What? */
 48         return NULL;
 49 }
 50 EXPORT_SYMBOL(pci_iomap_range);
 51 
 52 /**
 53  * pci_iomap_wc_range - create a virtual WC mapping cookie for a PCI BAR
 54  * @dev: PCI device that owns the BAR
 55  * @bar: BAR number
 56  * @offset: map memory at the given offset in BAR
 57  * @maxlen: max length of the memory to map
 58  *
 59  * Using this function you will get a __iomem address to your device BAR.
 60  * You can access it using ioread*() and iowrite*(). These functions hide
 61  * the details if this is a MMIO or PIO address space and will just do what
 62  * you expect from them in the correct way. When possible write combining
 63  * is used.
 64  *
 65  * @maxlen specifies the maximum length to map. If you want to get access to
 66  * the complete BAR from offset to the end, pass %0 here.
 67  * */
 68 void __iomem *pci_iomap_wc_range(struct pci_dev *dev,
 69                                  int bar,
 70                                  unsigned long offset,
 71                                  unsigned long maxlen)
 72 {
 73         resource_size_t start = pci_resource_start(dev, bar);
 74         resource_size_t len = pci_resource_len(dev, bar);
 75         unsigned long flags = pci_resource_flags(dev, bar);
 76 
 77 
 78         if (flags & IORESOURCE_IO)
 79                 return NULL;
 80 
 81         if (len <= offset || !start)
 82                 return NULL;
 83 
 84         len -= offset;
 85         start += offset;
 86         if (maxlen && len > maxlen)
 87                 len = maxlen;
 88 
 89         if (flags & IORESOURCE_MEM)
 90                 return ioremap_wc(start, len);
 91 
 92         /* What? */
 93         return NULL;
 94 }
 95 EXPORT_SYMBOL_GPL(pci_iomap_wc_range);
 96 
 97 /**
 98  * pci_iomap - create a virtual mapping cookie for a PCI BAR
 99  * @dev: PCI device that owns the BAR
100  * @bar: BAR number
101  * @maxlen: length of the memory to map
102  *
103  * Using this function you will get a __iomem address to your device BAR.
104  * You can access it using ioread*() and iowrite*(). These functions hide
105  * the details if this is a MMIO or PIO address space and will just do what
106  * you expect from them in the correct way.
107  *
108  * @maxlen specifies the maximum length to map. If you want to get access to
109  * the complete BAR without checking for its length first, pass %0 here.
110  * */
111 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
112 {
113         return pci_iomap_range(dev, bar, 0, maxlen);
114 }
115 EXPORT_SYMBOL(pci_iomap);
116 
117 /**
118  * pci_iomap_wc - create a virtual WC mapping cookie for a PCI BAR
119  * @dev: PCI device that owns the BAR
120  * @bar: BAR number
121  * @maxlen: length of the memory to map
122  *
123  * Using this function you will get a __iomem address to your device BAR.
124  * You can access it using ioread*() and iowrite*(). These functions hide
125  * the details if this is a MMIO or PIO address space and will just do what
126  * you expect from them in the correct way. When possible write combining
127  * is used.
128  *
129  * @maxlen specifies the maximum length to map. If you want to get access to
130  * the complete BAR without checking for its length first, pass %0 here.
131  * */
132 void __iomem *pci_iomap_wc(struct pci_dev *dev, int bar, unsigned long maxlen)
133 {
134         return pci_iomap_wc_range(dev, bar, 0, maxlen);
135 }
136 EXPORT_SYMBOL_GPL(pci_iomap_wc);
137 #endif /* CONFIG_PCI */
138 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp