]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - kernel/memremap.c
2 * Copyright(c) 2015 Intel Corporation. All rights reserved.
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.
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.
13 #include <linux/device.h>
14 #include <linux/types.h>
19 /* temporary while we convert existing ioremap_cache users to memremap */
20 __weak
void __iomem
*ioremap_cache(resource_size_t offset
, unsigned long size
)
22 return ioremap(offset
, size
);
27 * memremap() - remap an iomem_resource as cacheable memory
28 * @offset: iomem resource start address
29 * @size: size of remap
30 * @flags: either MEMREMAP_WB or MEMREMAP_WT
32 * memremap() is "ioremap" for cases where it is known that the resource
33 * being mapped does not have i/o side effects and the __iomem
34 * annotation is not applicable.
36 * MEMREMAP_WB - matches the default mapping for "System RAM" on
37 * the architecture. This is usually a read-allocate write-back cache.
38 * Morever, if MEMREMAP_WB is specified and the requested remap region is RAM
39 * memremap() will bypass establishing a new mapping and instead return
40 * a pointer into the direct map.
42 * MEMREMAP_WT - establish a mapping whereby writes either bypass the
43 * cache or are written through to memory and never exist in a
44 * cache-dirty state with respect to program visibility. Attempts to
45 * map "System RAM" with this mapping type will fail.
47 void *memremap(resource_size_t offset
, size_t size
, unsigned long flags
)
49 int is_ram
= region_intersects(offset
, size
, "System RAM");
52 if (is_ram
== REGION_MIXED
) {
53 WARN_ONCE(1, "memremap attempted on mixed range %pa size: %#lx\n",
54 &offset
, (unsigned long) size
);
58 /* Try all mapping types requested until one returns non-NULL */
59 if (flags
& MEMREMAP_WB
) {
60 flags
&= ~MEMREMAP_WB
;
62 * MEMREMAP_WB is special in that it can be satisifed
63 * from the direct map. Some archs depend on the
64 * capability of memremap() to autodetect cases where
65 * the requested range is potentially in "System RAM"
67 if (is_ram
== REGION_INTERSECTS
)
70 addr
= ioremap_cache(offset
, size
);
74 * If we don't have a mapping yet and more request flags are
75 * pending then we will be attempting to establish a new virtual
76 * address mapping. Enforce that this mapping is not aliasing
79 if (!addr
&& is_ram
== REGION_INTERSECTS
&& flags
) {
80 WARN_ONCE(1, "memremap attempted on ram %pa size: %#lx\n",
81 &offset
, (unsigned long) size
);
85 if (!addr
&& (flags
& MEMREMAP_WT
)) {
86 flags
&= ~MEMREMAP_WT
;
87 addr
= ioremap_wt(offset
, size
);
92 EXPORT_SYMBOL(memremap
);
94 void memunmap(void *addr
)
96 if (is_vmalloc_addr(addr
))
97 iounmap((void __iomem
*) addr
);
99 EXPORT_SYMBOL(memunmap
);
101 static void devm_memremap_release(struct device
*dev
, void *res
)
106 static int devm_memremap_match(struct device
*dev
, void *res
, void *match_data
)
108 return *(void **)res
== match_data
;
111 void *devm_memremap(struct device
*dev
, resource_size_t offset
,
112 size_t size
, unsigned long flags
)
116 ptr
= devres_alloc(devm_memremap_release
, sizeof(*ptr
), GFP_KERNEL
);
120 addr
= memremap(offset
, size
, flags
);
123 devres_add(dev
, ptr
);
129 EXPORT_SYMBOL(devm_memremap
);
131 void devm_memunmap(struct device
*dev
, void *addr
)
133 WARN_ON(devres_destroy(dev
, devm_memremap_release
, devm_memremap_match
,
137 EXPORT_SYMBOL(devm_memunmap
);