diff options
author | Chris Metcalf <cmetcalf@tilera.com> | 2010-06-25 17:03:27 -0400 |
---|---|---|
committer | Chris Metcalf <cmetcalf@tilera.com> | 2010-07-06 13:41:46 -0400 |
commit | c78095bd8c77fca2619769ff8efb639fd100e373 (patch) | |
tree | 9841462486a97a3733f0e5b789e8f6dce47ca62f /arch/tile/include | |
parent | 2db098278118ed58f4b407ceda691e349df043ce (diff) |
arch/tile: Split the icache flush code off to a generic <arch> header.
This code is used in other places in our system than in Linux, so
to share it we now implement it as an inline function in our low-level
<arch> headers, and instantiate it in one file in Linux's arch/tile/lib.
The file is now cacheflush.c and is C code rather than the strangely-named
and assembler-implemented __invalidate_icache.S.
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'arch/tile/include')
-rw-r--r-- | arch/tile/include/arch/icache.h | 94 | ||||
-rw-r--r-- | arch/tile/include/asm/cacheflush.h | 9 |
2 files changed, 96 insertions, 7 deletions
diff --git a/arch/tile/include/arch/icache.h b/arch/tile/include/arch/icache.h new file mode 100644 index 000000000000..5c87c9016338 --- /dev/null +++ b/arch/tile/include/arch/icache.h | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * Copyright 2010 Tilera Corporation. All Rights Reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation, version 2. | ||
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, GOOD TITLE or | ||
11 | * NON INFRINGEMENT. See the GNU General Public License for | ||
12 | * more details. | ||
13 | * | ||
14 | */ | ||
15 | |||
16 | /** | ||
17 | * @file | ||
18 | * | ||
19 | * Support for invalidating bytes in the instruction | ||
20 | */ | ||
21 | |||
22 | #ifndef __ARCH_ICACHE_H__ | ||
23 | #define __ARCH_ICACHE_H__ | ||
24 | |||
25 | #include <arch/chip.h> | ||
26 | |||
27 | |||
28 | /** | ||
29 | * Invalidate the instruction cache for the given range of memory. | ||
30 | * | ||
31 | * @param addr The start of memory to be invalidated. | ||
32 | * @param size The number of bytes to be invalidated. | ||
33 | * @param page_size The system's page size, typically the PAGE_SIZE constant | ||
34 | * in sys/page.h. This value must be a power of two no larger | ||
35 | * than the page containing the code to be invalidated. If the value | ||
36 | * is smaller than the actual page size, this function will still | ||
37 | * work, but may run slower than necessary. | ||
38 | */ | ||
39 | static __inline void | ||
40 | invalidate_icache(const void* addr, unsigned long size, | ||
41 | unsigned long page_size) | ||
42 | { | ||
43 | const unsigned long cache_way_size = | ||
44 | CHIP_L1I_CACHE_SIZE() / CHIP_L1I_ASSOC(); | ||
45 | unsigned long max_useful_size; | ||
46 | const char* start, *end; | ||
47 | long num_passes; | ||
48 | |||
49 | if (__builtin_expect(size == 0, 0)) | ||
50 | return; | ||
51 | |||
52 | #ifdef __tilegx__ | ||
53 | /* Limit the number of bytes visited to avoid redundant iterations. */ | ||
54 | max_useful_size = (page_size < cache_way_size) ? page_size : cache_way_size; | ||
55 | |||
56 | /* No PA aliasing is possible, so one pass always suffices. */ | ||
57 | num_passes = 1; | ||
58 | #else | ||
59 | /* Limit the number of bytes visited to avoid redundant iterations. */ | ||
60 | max_useful_size = cache_way_size; | ||
61 | |||
62 | /* | ||
63 | * Compute how many passes we need (we'll treat 0 as if it were 1). | ||
64 | * This works because we know the page size is a power of two. | ||
65 | */ | ||
66 | num_passes = cache_way_size >> __builtin_ctzl(page_size); | ||
67 | #endif | ||
68 | |||
69 | if (__builtin_expect(size > max_useful_size, 0)) | ||
70 | size = max_useful_size; | ||
71 | |||
72 | /* Locate the first and last bytes to be invalidated. */ | ||
73 | start = (const char *)((unsigned long)addr & -CHIP_L1I_LINE_SIZE()); | ||
74 | end = (const char*)addr + size - 1; | ||
75 | |||
76 | __insn_mf(); | ||
77 | |||
78 | do | ||
79 | { | ||
80 | const char* p; | ||
81 | |||
82 | for (p = start; p <= end; p += CHIP_L1I_LINE_SIZE()) | ||
83 | __insn_icoh(p); | ||
84 | |||
85 | start += page_size; | ||
86 | end += page_size; | ||
87 | } | ||
88 | while (--num_passes > 0); | ||
89 | |||
90 | __insn_drain(); | ||
91 | } | ||
92 | |||
93 | |||
94 | #endif /* __ARCH_ICACHE_H__ */ | ||
diff --git a/arch/tile/include/asm/cacheflush.h b/arch/tile/include/asm/cacheflush.h index 7e2096a4ef7d..c5741da4eeac 100644 --- a/arch/tile/include/asm/cacheflush.h +++ b/arch/tile/include/asm/cacheflush.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/mm.h> | 21 | #include <linux/mm.h> |
22 | #include <linux/cache.h> | 22 | #include <linux/cache.h> |
23 | #include <asm/system.h> | 23 | #include <asm/system.h> |
24 | #include <arch/icache.h> | ||
24 | 25 | ||
25 | /* Caches are physically-indexed and so don't need special treatment */ | 26 | /* Caches are physically-indexed and so don't need special treatment */ |
26 | #define flush_cache_all() do { } while (0) | 27 | #define flush_cache_all() do { } while (0) |
@@ -37,14 +38,8 @@ | |||
37 | #define flush_icache_page(vma, pg) do { } while (0) | 38 | #define flush_icache_page(vma, pg) do { } while (0) |
38 | #define flush_icache_user_range(vma, pg, adr, len) do { } while (0) | 39 | #define flush_icache_user_range(vma, pg, adr, len) do { } while (0) |
39 | 40 | ||
40 | /* See "arch/tile/lib/__invalidate_icache.S". */ | ||
41 | extern void __invalidate_icache(unsigned long start, unsigned long size); | ||
42 | |||
43 | /* Flush the icache just on this cpu */ | 41 | /* Flush the icache just on this cpu */ |
44 | static inline void __flush_icache_range(unsigned long start, unsigned long end) | 42 | extern void __flush_icache_range(unsigned long start, unsigned long end); |
45 | { | ||
46 | __invalidate_icache(start, end - start); | ||
47 | } | ||
48 | 43 | ||
49 | /* Flush the entire icache on this cpu. */ | 44 | /* Flush the entire icache on this cpu. */ |
50 | #define __flush_icache() __flush_icache_range(0, CHIP_L1I_CACHE_SIZE()) | 45 | #define __flush_icache() __flush_icache_range(0, CHIP_L1I_CACHE_SIZE()) |