aboutsummaryrefslogtreecommitdiffstats
path: root/lib/devres.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2013-03-18 19:58:00 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-03-18 19:58:00 -0400
commitd608d71cd6d19792487d08333d63c7ff20294694 (patch)
treec9cad98ad9cbba487d32812d59c456ed774d6ffb /lib/devres.c
parented72d37a33fdf43dc47787fe220532cdec9da528 (diff)
parenta937536b868b8369b98967929045f1df54234323 (diff)
Merge tag 'v3.9-rc3' into v4l_for_linus
Linux 3.9-rc3 * tag 'v3.9-rc3': (11231 commits) Linux 3.9-rc3 perf,x86: fix link failure for non-Intel configs perf,x86: fix wrmsr_on_cpu() warning on suspend/resume Btrfs: fix warning of free_extent_map perf,x86: fix kernel crash with PEBS/BTS after suspend/resume ALSA: hda - Fix missing EAPD/GPIO setup for Cirrus codecs sound: sequencer: cap array index in seq_chn_common_event() mfd: twl4030-madc: Remove __exit_p annotation ALSA: hda/ca0132 - Remove extra setting of dsp_state. ALSA: hda/ca0132 - Check download state of DSP. ALSA: hda/ca0132 - Check if dspload_image succeeded. mm/fremap.c: fix possible oops on error path list: Fix double fetch of pointer in hlist_entry_safe() Btrfs: fix warning when creating snapshots Btrfs: return as soon as possible when edquot happens Btrfs: return EIO if we have extent tree corruption btrfs: use rcu_barrier() to wait for bdev puts at unmount Btrfs: remove btrfs_try_spin_lock Btrfs: get better concurrency for snapshot-aware defrag work hwmon: (pmbus/ltc2978) Fix temperature reporting ...
Diffstat (limited to 'lib/devres.c')
-rw-r--r--lib/devres.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/lib/devres.c b/lib/devres.c
index 80b9c76d436a..823533138fa0 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -1,3 +1,4 @@
1#include <linux/err.h>
1#include <linux/pci.h> 2#include <linux/pci.h>
2#include <linux/io.h> 3#include <linux/io.h>
3#include <linux/gfp.h> 4#include <linux/gfp.h>
@@ -86,22 +87,24 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
86EXPORT_SYMBOL(devm_iounmap); 87EXPORT_SYMBOL(devm_iounmap);
87 88
88/** 89/**
89 * devm_request_and_ioremap() - Check, request region, and ioremap resource 90 * devm_ioremap_resource() - check, request region, and ioremap resource
90 * @dev: Generic device to handle the resource for 91 * @dev: generic device to handle the resource for
91 * @res: resource to be handled 92 * @res: resource to be handled
92 * 93 *
93 * Takes all necessary steps to ioremap a mem resource. Uses managed device, so 94 * Checks that a resource is a valid memory region, requests the memory region
94 * everything is undone on driver detach. Checks arguments, so you can feed 95 * and ioremaps it either as cacheable or as non-cacheable memory depending on
95 * it the result from e.g. platform_get_resource() directly. Returns the 96 * the resource's flags. All operations are managed and will be undone on
96 * remapped pointer or NULL on error. Usage example: 97 * driver detach.
98 *
99 * Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
100 * on failure. Usage example:
97 * 101 *
98 * res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 102 * res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
99 * base = devm_request_and_ioremap(&pdev->dev, res); 103 * base = devm_ioremap_resource(&pdev->dev, res);
100 * if (!base) 104 * if (IS_ERR(base))
101 * return -EADDRNOTAVAIL; 105 * return PTR_ERR(base);
102 */ 106 */
103void __iomem *devm_request_and_ioremap(struct device *dev, 107void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
104 struct resource *res)
105{ 108{
106 resource_size_t size; 109 resource_size_t size;
107 const char *name; 110 const char *name;
@@ -111,7 +114,7 @@ void __iomem *devm_request_and_ioremap(struct device *dev,
111 114
112 if (!res || resource_type(res) != IORESOURCE_MEM) { 115 if (!res || resource_type(res) != IORESOURCE_MEM) {
113 dev_err(dev, "invalid resource\n"); 116 dev_err(dev, "invalid resource\n");
114 return NULL; 117 return ERR_PTR(-EINVAL);
115 } 118 }
116 119
117 size = resource_size(res); 120 size = resource_size(res);
@@ -119,7 +122,7 @@ void __iomem *devm_request_and_ioremap(struct device *dev,
119 122
120 if (!devm_request_mem_region(dev, res->start, size, name)) { 123 if (!devm_request_mem_region(dev, res->start, size, name)) {
121 dev_err(dev, "can't request region for resource %pR\n", res); 124 dev_err(dev, "can't request region for resource %pR\n", res);
122 return NULL; 125 return ERR_PTR(-EBUSY);
123 } 126 }
124 127
125 if (res->flags & IORESOURCE_CACHEABLE) 128 if (res->flags & IORESOURCE_CACHEABLE)
@@ -130,10 +133,39 @@ void __iomem *devm_request_and_ioremap(struct device *dev,
130 if (!dest_ptr) { 133 if (!dest_ptr) {
131 dev_err(dev, "ioremap failed for resource %pR\n", res); 134 dev_err(dev, "ioremap failed for resource %pR\n", res);
132 devm_release_mem_region(dev, res->start, size); 135 devm_release_mem_region(dev, res->start, size);
136 dest_ptr = ERR_PTR(-ENOMEM);
133 } 137 }
134 138
135 return dest_ptr; 139 return dest_ptr;
136} 140}
141EXPORT_SYMBOL(devm_ioremap_resource);
142
143/**
144 * devm_request_and_ioremap() - Check, request region, and ioremap resource
145 * @dev: Generic device to handle the resource for
146 * @res: resource to be handled
147 *
148 * Takes all necessary steps to ioremap a mem resource. Uses managed device, so
149 * everything is undone on driver detach. Checks arguments, so you can feed
150 * it the result from e.g. platform_get_resource() directly. Returns the
151 * remapped pointer or NULL on error. Usage example:
152 *
153 * res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
154 * base = devm_request_and_ioremap(&pdev->dev, res);
155 * if (!base)
156 * return -EADDRNOTAVAIL;
157 */
158void __iomem *devm_request_and_ioremap(struct device *device,
159 struct resource *res)
160{
161 void __iomem *dest_ptr;
162
163 dest_ptr = devm_ioremap_resource(device, res);
164 if (IS_ERR(dest_ptr))
165 return NULL;
166
167 return dest_ptr;
168}
137EXPORT_SYMBOL(devm_request_and_ioremap); 169EXPORT_SYMBOL(devm_request_and_ioremap);
138 170
139#ifdef CONFIG_HAS_IOPORT 171#ifdef CONFIG_HAS_IOPORT
@@ -195,6 +227,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
195 devm_ioport_map_match, (void *)addr)); 227 devm_ioport_map_match, (void *)addr));
196} 228}
197EXPORT_SYMBOL(devm_ioport_unmap); 229EXPORT_SYMBOL(devm_ioport_unmap);
230#endif /* CONFIG_HAS_IOPORT */
198 231
199#ifdef CONFIG_PCI 232#ifdef CONFIG_PCI
200/* 233/*
@@ -400,4 +433,3 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask)
400} 433}
401EXPORT_SYMBOL(pcim_iounmap_regions); 434EXPORT_SYMBOL(pcim_iounmap_regions);
402#endif /* CONFIG_PCI */ 435#endif /* CONFIG_PCI */
403#endif /* CONFIG_HAS_IOPORT */