diff options
| -rw-r--r-- | arch/s390/kernel/cache.c | 388 |
1 files changed, 92 insertions, 296 deletions
diff --git a/arch/s390/kernel/cache.c b/arch/s390/kernel/cache.c index c0b03c28d157..fe21f074cf9f 100644 --- a/arch/s390/kernel/cache.c +++ b/arch/s390/kernel/cache.c | |||
| @@ -5,37 +5,11 @@ | |||
| 5 | * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com> | 5 | * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com> |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include <linux/notifier.h> | ||
| 9 | #include <linux/seq_file.h> | 8 | #include <linux/seq_file.h> |
| 10 | #include <linux/init.h> | ||
| 11 | #include <linux/list.h> | ||
| 12 | #include <linux/slab.h> | ||
| 13 | #include <linux/cpu.h> | 9 | #include <linux/cpu.h> |
| 10 | #include <linux/cacheinfo.h> | ||
| 14 | #include <asm/facility.h> | 11 | #include <asm/facility.h> |
| 15 | 12 | ||
| 16 | struct cache { | ||
| 17 | unsigned long size; | ||
| 18 | unsigned int line_size; | ||
| 19 | unsigned int associativity; | ||
| 20 | unsigned int nr_sets; | ||
| 21 | unsigned int level : 3; | ||
| 22 | unsigned int type : 2; | ||
| 23 | unsigned int private : 1; | ||
| 24 | struct list_head list; | ||
| 25 | }; | ||
| 26 | |||
| 27 | struct cache_dir { | ||
| 28 | struct kobject *kobj; | ||
| 29 | struct cache_index_dir *index; | ||
| 30 | }; | ||
| 31 | |||
| 32 | struct cache_index_dir { | ||
| 33 | struct kobject kobj; | ||
| 34 | int cpu; | ||
| 35 | struct cache *cache; | ||
| 36 | struct cache_index_dir *next; | ||
| 37 | }; | ||
| 38 | |||
| 39 | enum { | 13 | enum { |
| 40 | CACHE_SCOPE_NOTEXISTS, | 14 | CACHE_SCOPE_NOTEXISTS, |
| 41 | CACHE_SCOPE_PRIVATE, | 15 | CACHE_SCOPE_PRIVATE, |
| @@ -44,10 +18,10 @@ enum { | |||
| 44 | }; | 18 | }; |
| 45 | 19 | ||
| 46 | enum { | 20 | enum { |
| 47 | CACHE_TYPE_SEPARATE, | 21 | CTYPE_SEPARATE, |
| 48 | CACHE_TYPE_DATA, | 22 | CTYPE_DATA, |
| 49 | CACHE_TYPE_INSTRUCTION, | 23 | CTYPE_INSTRUCTION, |
| 50 | CACHE_TYPE_UNIFIED, | 24 | CTYPE_UNIFIED, |
| 51 | }; | 25 | }; |
| 52 | 26 | ||
| 53 | enum { | 27 | enum { |
| @@ -70,39 +44,59 @@ struct cache_info { | |||
| 70 | }; | 44 | }; |
| 71 | 45 | ||
| 72 | #define CACHE_MAX_LEVEL 8 | 46 | #define CACHE_MAX_LEVEL 8 |
| 73 | |||
| 74 | union cache_topology { | 47 | union cache_topology { |
| 75 | struct cache_info ci[CACHE_MAX_LEVEL]; | 48 | struct cache_info ci[CACHE_MAX_LEVEL]; |
| 76 | unsigned long long raw; | 49 | unsigned long long raw; |
| 77 | }; | 50 | }; |
| 78 | 51 | ||
| 79 | static const char * const cache_type_string[] = { | 52 | static const char * const cache_type_string[] = { |
| 80 | "Data", | 53 | "", |
| 81 | "Instruction", | 54 | "Instruction", |
| 55 | "Data", | ||
| 56 | "", | ||
| 82 | "Unified", | 57 | "Unified", |
| 83 | }; | 58 | }; |
| 84 | 59 | ||
| 85 | static struct cache_dir *cache_dir_cpu[NR_CPUS]; | 60 | static const enum cache_type cache_type_map[] = { |
| 86 | static LIST_HEAD(cache_list); | 61 | [CTYPE_SEPARATE] = CACHE_TYPE_SEPARATE, |
| 62 | [CTYPE_DATA] = CACHE_TYPE_DATA, | ||
| 63 | [CTYPE_INSTRUCTION] = CACHE_TYPE_INST, | ||
| 64 | [CTYPE_UNIFIED] = CACHE_TYPE_UNIFIED, | ||
| 65 | }; | ||
| 87 | 66 | ||
| 88 | void show_cacheinfo(struct seq_file *m) | 67 | void show_cacheinfo(struct seq_file *m) |
| 89 | { | 68 | { |
| 90 | struct cache *cache; | 69 | int cpu = smp_processor_id(), idx; |
| 91 | int index = 0; | 70 | struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); |
| 71 | struct cacheinfo *cache; | ||
| 92 | 72 | ||
| 93 | list_for_each_entry(cache, &cache_list, list) { | 73 | for (idx = 0; idx < this_cpu_ci->num_leaves; idx++) { |
| 94 | seq_printf(m, "cache%-11d: ", index); | 74 | cache = this_cpu_ci->info_list + idx; |
| 75 | seq_printf(m, "cache%-11d: ", idx); | ||
| 95 | seq_printf(m, "level=%d ", cache->level); | 76 | seq_printf(m, "level=%d ", cache->level); |
| 96 | seq_printf(m, "type=%s ", cache_type_string[cache->type]); | 77 | seq_printf(m, "type=%s ", cache_type_string[cache->type]); |
| 97 | seq_printf(m, "scope=%s ", cache->private ? "Private" : "Shared"); | 78 | seq_printf(m, "scope=%s ", |
| 98 | seq_printf(m, "size=%luK ", cache->size >> 10); | 79 | cache->disable_sysfs ? "Shared" : "Private"); |
| 99 | seq_printf(m, "line_size=%u ", cache->line_size); | 80 | seq_printf(m, "size=%dK ", cache->size >> 10); |
| 100 | seq_printf(m, "associativity=%d", cache->associativity); | 81 | seq_printf(m, "line_size=%u ", cache->coherency_line_size); |
| 82 | seq_printf(m, "associativity=%d", cache->ways_of_associativity); | ||
| 101 | seq_puts(m, "\n"); | 83 | seq_puts(m, "\n"); |
| 102 | index++; | ||
| 103 | } | 84 | } |
| 104 | } | 85 | } |
| 105 | 86 | ||
| 87 | static inline enum cache_type get_cache_type(struct cache_info *ci, int level) | ||
| 88 | { | ||
| 89 | if (level >= CACHE_MAX_LEVEL) | ||
| 90 | return CACHE_TYPE_NOCACHE; | ||
| 91 | |||
| 92 | ci += level; | ||
| 93 | |||
| 94 | if (ci->scope != CACHE_SCOPE_SHARED && ci->scope != CACHE_SCOPE_PRIVATE) | ||
| 95 | return CACHE_TYPE_NOCACHE; | ||
| 96 | |||
| 97 | return cache_type_map[ci->type]; | ||
| 98 | } | ||
| 99 | |||
| 106 | static inline unsigned long ecag(int ai, int li, int ti) | 100 | static inline unsigned long ecag(int ai, int li, int ti) |
| 107 | { | 101 | { |
| 108 | unsigned long cmd, val; | 102 | unsigned long cmd, val; |
| @@ -113,277 +107,79 @@ static inline unsigned long ecag(int ai, int li, int ti) | |||
| 113 | return val; | 107 | return val; |
| 114 | } | 108 | } |
| 115 | 109 | ||
| 116 | static int __init cache_add(int level, int private, int type) | 110 | static void ci_leaf_init(struct cacheinfo *this_leaf, int private, |
| 111 | enum cache_type type, unsigned int level) | ||
| 117 | { | 112 | { |
| 118 | struct cache *cache; | 113 | int ti, num_sets; |
| 119 | int ti; | 114 | int cpu = smp_processor_id(); |
| 120 | 115 | ||
| 121 | cache = kzalloc(sizeof(*cache), GFP_KERNEL); | 116 | if (type == CACHE_TYPE_INST) |
| 122 | if (!cache) | ||
| 123 | return -ENOMEM; | ||
| 124 | if (type == CACHE_TYPE_INSTRUCTION) | ||
| 125 | ti = CACHE_TI_INSTRUCTION; | 117 | ti = CACHE_TI_INSTRUCTION; |
| 126 | else | 118 | else |
| 127 | ti = CACHE_TI_UNIFIED; | 119 | ti = CACHE_TI_UNIFIED; |
| 128 | cache->size = ecag(EXTRACT_SIZE, level, ti); | ||
| 129 | cache->line_size = ecag(EXTRACT_LINE_SIZE, level, ti); | ||
| 130 | cache->associativity = ecag(EXTRACT_ASSOCIATIVITY, level, ti); | ||
| 131 | cache->nr_sets = cache->size / cache->associativity; | ||
| 132 | cache->nr_sets /= cache->line_size; | ||
| 133 | cache->private = private; | ||
| 134 | cache->level = level + 1; | ||
| 135 | cache->type = type - 1; | ||
| 136 | list_add_tail(&cache->list, &cache_list); | ||
| 137 | return 0; | ||
| 138 | } | ||
| 139 | |||
| 140 | static void __init cache_build_info(void) | ||
| 141 | { | ||
| 142 | struct cache *cache, *next; | ||
| 143 | union cache_topology ct; | ||
| 144 | int level, private, rc; | ||
| 145 | |||
| 146 | ct.raw = ecag(EXTRACT_TOPOLOGY, 0, 0); | ||
| 147 | for (level = 0; level < CACHE_MAX_LEVEL; level++) { | ||
| 148 | switch (ct.ci[level].scope) { | ||
| 149 | case CACHE_SCOPE_SHARED: | ||
| 150 | private = 0; | ||
| 151 | break; | ||
| 152 | case CACHE_SCOPE_PRIVATE: | ||
| 153 | private = 1; | ||
| 154 | break; | ||
| 155 | default: | ||
| 156 | return; | ||
| 157 | } | ||
| 158 | if (ct.ci[level].type == CACHE_TYPE_SEPARATE) { | ||
| 159 | rc = cache_add(level, private, CACHE_TYPE_DATA); | ||
| 160 | rc |= cache_add(level, private, CACHE_TYPE_INSTRUCTION); | ||
| 161 | } else { | ||
| 162 | rc = cache_add(level, private, ct.ci[level].type); | ||
| 163 | } | ||
| 164 | if (rc) | ||
| 165 | goto error; | ||
| 166 | } | ||
| 167 | return; | ||
| 168 | error: | ||
| 169 | list_for_each_entry_safe(cache, next, &cache_list, list) { | ||
