Skip to content

Commit c907e0e

Browse files
Brian Starkeytorvalds
authored andcommitted
memremap: add MEMREMAP_WC flag
Add a flag to memremap() for writecombine mappings. Mappings satisfied by this flag will not be cached, however writes may be delayed or combined into more efficient bursts. This is most suitable for buffers written sequentially by the CPU for use by other DMA devices. Signed-off-by: Brian Starkey <brian.starkey@arm.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent cf61e2a commit c907e0e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

include/linux/io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ enum {
135135
/* See memremap() kernel-doc for usage description... */
136136
MEMREMAP_WB = 1 << 0,
137137
MEMREMAP_WT = 1 << 1,
138+
MEMREMAP_WC = 1 << 2,
138139
};
139140

140141
void *memremap(resource_size_t offset, size_t size, unsigned long flags);

kernel/memremap.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ static void *try_ram_remap(resource_size_t offset, size_t size)
4141
* memremap() - remap an iomem_resource as cacheable memory
4242
* @offset: iomem resource start address
4343
* @size: size of remap
44-
* @flags: either MEMREMAP_WB or MEMREMAP_WT
44+
* @flags: any of MEMREMAP_WB, MEMREMAP_WT and MEMREMAP_WC
4545
*
4646
* memremap() is "ioremap" for cases where it is known that the resource
4747
* being mapped does not have i/o side effects and the __iomem
48-
* annotation is not applicable.
48+
* annotation is not applicable. In the case of multiple flags, the different
49+
* mapping types will be attempted in the order listed below until one of
50+
* them succeeds.
4951
*
5052
* MEMREMAP_WB - matches the default mapping for System RAM on
5153
* the architecture. This is usually a read-allocate write-back cache.
@@ -57,6 +59,10 @@ static void *try_ram_remap(resource_size_t offset, size_t size)
5759
* cache or are written through to memory and never exist in a
5860
* cache-dirty state with respect to program visibility. Attempts to
5961
* map System RAM with this mapping type will fail.
62+
*
63+
* MEMREMAP_WC - establish a writecombine mapping, whereby writes may
64+
* be coalesced together (e.g. in the CPU's write buffers), but is otherwise
65+
* uncached. Attempts to map System RAM with this mapping type will fail.
6066
*/
6167
void *memremap(resource_size_t offset, size_t size, unsigned long flags)
6268
{
@@ -102,6 +108,9 @@ void *memremap(resource_size_t offset, size_t size, unsigned long flags)
102108
if (!addr && (flags & MEMREMAP_WT))
103109
addr = ioremap_wt(offset, size);
104110

111+
if (!addr && (flags & MEMREMAP_WC))
112+
addr = ioremap_wc(offset, size);
113+
105114
return addr;
106115
}
107116
EXPORT_SYMBOL(memremap);

0 commit comments

Comments
 (0)