iomap.c (e82a82c19f4272ea5437cc76e5711b98e2ee6223) iomap.c (f0c98ebc57c2d5e535bc4f9167f35650d2ba3c90)
1/*
2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
1/*
2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13#include <linux/memremap.h>
13#include <linux/rculist.h>
14#include <linux/export.h>
15#include <linux/ioport.h>
16#include <linux/module.h>
17#include <linux/types.h>
14#include <linux/rculist.h>
15#include <linux/export.h>
16#include <linux/ioport.h>
17#include <linux/module.h>
18#include <linux/types.h>
19#include <linux/pfn_t.h>
18#include <linux/io.h>
19#include <linux/mm.h>
20#include "nfit_test.h"
21
22static LIST_HEAD(iomap_head);
23
24static struct iomap_ops {
25 nfit_test_lookup_fn nfit_test_lookup;

--- 21 unchanged lines hidden (view full) ---

47 struct iomap_ops *ops;
48
49 ops = list_first_or_null_rcu(&iomap_head, typeof(*ops), list);
50 if (ops)
51 return ops->nfit_test_lookup(resource);
52 return NULL;
53}
54
20#include <linux/io.h>
21#include <linux/mm.h>
22#include "nfit_test.h"
23
24static LIST_HEAD(iomap_head);
25
26static struct iomap_ops {
27 nfit_test_lookup_fn nfit_test_lookup;

--- 21 unchanged lines hidden (view full) ---

49 struct iomap_ops *ops;
50
51 ops = list_first_or_null_rcu(&iomap_head, typeof(*ops), list);
52 if (ops)
53 return ops->nfit_test_lookup(resource);
54 return NULL;
55}
56
55static struct nfit_test_resource *get_nfit_res(resource_size_t resource)
57struct nfit_test_resource *get_nfit_res(resource_size_t resource)
56{
57 struct nfit_test_resource *res;
58
59 rcu_read_lock();
60 res = __get_nfit_res(resource);
61 rcu_read_unlock();
62
63 return res;
64}
58{
59 struct nfit_test_resource *res;
60
61 rcu_read_lock();
62 res = __get_nfit_res(resource);
63 rcu_read_unlock();
64
65 return res;
66}
67EXPORT_SYMBOL(get_nfit_res);
65
66void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size,
67 void __iomem *(*fallback_fn)(resource_size_t, unsigned long))
68{
69 struct nfit_test_resource *nfit_res = get_nfit_res(offset);
70
71 if (nfit_res)
72 return (void __iomem *) nfit_res->buf + offset

--- 19 unchanged lines hidden (view full) ---

92 struct nfit_test_resource *nfit_res = get_nfit_res(offset);
93
94 if (nfit_res)
95 return nfit_res->buf + offset - nfit_res->res->start;
96 return devm_memremap(dev, offset, size, flags);
97}
98EXPORT_SYMBOL(__wrap_devm_memremap);
99
68
69void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size,
70 void __iomem *(*fallback_fn)(resource_size_t, unsigned long))
71{
72 struct nfit_test_resource *nfit_res = get_nfit_res(offset);
73
74 if (nfit_res)
75 return (void __iomem *) nfit_res->buf + offset

--- 19 unchanged lines hidden (view full) ---

95 struct nfit_test_resource *nfit_res = get_nfit_res(offset);
96
97 if (nfit_res)
98 return nfit_res->buf + offset - nfit_res->res->start;
99 return devm_memremap(dev, offset, size, flags);
100}
101EXPORT_SYMBOL(__wrap_devm_memremap);
102
100#ifdef __HAVE_ARCH_PTE_DEVMAP
101#include <linux/memremap.h>
102#include <linux/pfn_t.h>
103
104void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res,
105 struct percpu_ref *ref, struct vmem_altmap *altmap)
106{
107 resource_size_t offset = res->start;
108 struct nfit_test_resource *nfit_res = get_nfit_res(offset);
109
110 if (nfit_res)
111 return nfit_res->buf + offset - nfit_res->res->start;

--- 5 unchanged lines hidden (view full) ---

117{
118 struct nfit_test_resource *nfit_res = get_nfit_res(addr);
119
120 if (nfit_res)
121 flags &= ~PFN_MAP;
122 return phys_to_pfn_t(addr, flags);
123}
124EXPORT_SYMBOL(__wrap_phys_to_pfn_t);
103void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res,
104 struct percpu_ref *ref, struct vmem_altmap *altmap)
105{
106 resource_size_t offset = res->start;
107 struct nfit_test_resource *nfit_res = get_nfit_res(offset);
108
109 if (nfit_res)
110 return nfit_res->buf + offset - nfit_res->res->start;

--- 5 unchanged lines hidden (view full) ---

116{
117 struct nfit_test_resource *nfit_res = get_nfit_res(addr);
118
119 if (nfit_res)
120 flags &= ~PFN_MAP;
121 return phys_to_pfn_t(addr, flags);
122}
123EXPORT_SYMBOL(__wrap_phys_to_pfn_t);
125#else
126/* to be removed post 4.5-rc1 */
127void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res)
128{
129 resource_size_t offset = res->start;
130 struct nfit_test_resource *nfit_res = get_nfit_res(offset);
131
124
132 if (nfit_res)
133 return nfit_res->buf + offset - nfit_res->res->start;
134 return devm_memremap_pages(dev, res);
135}
136EXPORT_SYMBOL(__wrap_devm_memremap_pages);
137#endif
138
139void *__wrap_memremap(resource_size_t offset, size_t size,
140 unsigned long flags)
141{
142 struct nfit_test_resource *nfit_res = get_nfit_res(offset);
143
144 if (nfit_res)
145 return nfit_res->buf + offset - nfit_res->res->start;
146 return memremap(offset, size, flags);

--- 77 unchanged lines hidden (view full) ---

224struct resource *__wrap___request_region(struct resource *parent,
225 resource_size_t start, resource_size_t n, const char *name,
226 int flags)
227{
228 return nfit_test_request_region(NULL, parent, start, n, name, flags);
229}
230EXPORT_SYMBOL(__wrap___request_region);
231
125void *__wrap_memremap(resource_size_t offset, size_t size,
126 unsigned long flags)
127{
128 struct nfit_test_resource *nfit_res = get_nfit_res(offset);
129
130 if (nfit_res)
131 return nfit_res->buf + offset - nfit_res->res->start;
132 return memremap(offset, size, flags);

--- 77 unchanged lines hidden (view full) ---

210struct resource *__wrap___request_region(struct resource *parent,
211 resource_size_t start, resource_size_t n, const char *name,
212 int flags)
213{
214 return nfit_test_request_region(NULL, parent, start, n, name, flags);
215}
216EXPORT_SYMBOL(__wrap___request_region);
217
218int __wrap_insert_resource(struct resource *parent, struct resource *res)
219{
220 if (get_nfit_res(res->start))
221 return 0;
222 return insert_resource(parent, res);
223}
224EXPORT_SYMBOL(__wrap_insert_resource);
225
226int __wrap_remove_resource(struct resource *res)
227{
228 if (get_nfit_res(res->start))
229 return 0;
230 return remove_resource(res);
231}
232EXPORT_SYMBOL(__wrap_remove_resource);
233
232struct resource *__wrap___devm_request_region(struct device *dev,
233 struct resource *parent, resource_size_t start,
234 resource_size_t n, const char *name)
235{
236 if (!dev)
237 return NULL;
238 return nfit_test_request_region(dev, parent, start, n, name, 0);
239}

--- 38 unchanged lines hidden ---
234struct resource *__wrap___devm_request_region(struct device *dev,
235 struct resource *parent, resource_size_t start,
236 resource_size_t n, const char *name)
237{
238 if (!dev)
239 return NULL;
240 return nfit_test_request_region(dev, parent, start, n, name, 0);
241}

--- 38 unchanged lines hidden ---