11 #include <linux/list.h>
12 #include <linux/slab.h>
23 unsigned int private : 1;
72 #define CACHE_MAX_LEVEL 8
76 unsigned long long raw;
79 static const char *
const cache_type_string[] = {
97 seq_printf(m,
"scope=%s ", cache->private ?
"Private" :
"Shared");
106 static inline unsigned long ecag(
int ai,
int li,
int ti)
110 cmd = ai << 4 | li << 1 | ti;
111 asm volatile(
".insn rsy,0xeb000000004c,%0,0,0(%1)"
112 :
"=d" (
val) :
"a" (cmd));
133 cache->private =
private;
134 cache->
level = level + 1;
135 cache->
type = type - 1;
140 static void __init cache_build_info(
void)
148 switch (
ct.ci[level].scope) {
163 rc = cache_add(level,
private,
ct.ci[level].type);
188 cache_dir = kzalloc(
sizeof(*cache_dir),
GFP_KERNEL);
192 cache_dir_cpu[
cpu] = cache_dir;
204 static void cache_index_release(
struct kobject *kobj)
208 index = kobj_to_cache_index_dir(kobj);
218 return kobj_attr->
show(kobj, kobj_attr, buf);
221 #define DEFINE_CACHE_ATTR(_name, _format, _value) \
222 static ssize_t cache_##_name##_show(struct kobject *kobj, \
223 struct kobj_attribute *attr, \
226 struct cache_index_dir *index; \
228 index = kobj_to_cache_index_dir(kobj); \
229 return sprintf(buf, _format, _value); \
231 static struct kobj_attribute cache_##_name##_attr = \
232 __ATTR(_name, 0444, cache_##_name##_show, NULL);
241 static ssize_t shared_cpu_map_func(
struct kobject *kobj,
int type,
char *buf)
246 index = kobj_to_cache_index_dir(kobj);
250 len +=
sprintf(&buf[len],
"\n");
257 return shared_cpu_map_func(kobj, 0, buf);
260 __ATTR(shared_cpu_map, 0444, shared_cpu_map_show,
NULL);
265 return shared_cpu_map_func(kobj, 1, buf);
268 __ATTR(shared_cpu_list, 0444, shared_cpu_list_show,
NULL);
270 static struct attribute *cache_index_default_attrs[] = {
271 &cache_type_attr.attr,
272 &cache_size_attr.attr,
273 &cache_number_of_sets_attr.attr,
274 &cache_ways_of_associativity_attr.attr,
275 &cache_level_attr.attr,
276 &cache_coherency_line_size_attr.attr,
277 &cache_shared_cpu_map_attr.
attr,
278 &cache_shared_cpu_list_attr.
attr,
282 static const struct sysfs_ops cache_index_ops = {
283 .show = cache_index_show,
286 static struct kobj_type cache_index_type = {
287 .sysfs_ops = &cache_index_ops,
288 .release = cache_index_release,
289 .default_attrs = cache_index_default_attrs,
292 static int __cpuinit cache_create_index_dir(
struct cache_dir *cache_dir,
293 struct cache *cache,
int index,
299 index_dir = kzalloc(
sizeof(*index_dir),
GFP_KERNEL);
305 cache_dir->
kobj,
"index%d", index);
309 cache_dir->
index = index_dir;
316 static int __cpuinit cache_add_cpu(
int cpu)
318 struct cache_dir *cache_dir;
322 if (list_empty(&cache_list))
324 cache_dir = cache_create_cache_dir(cpu);
330 rc = cache_create_index_dir(cache_dir, cache, index, cpu);
338 static void __cpuinit cache_remove_cpu(
int cpu)
341 struct cache_dir *cache_dir;
343 cache_dir = cache_dir_cpu[
cpu];
346 index = cache_dir->
index;
358 unsigned long action,
void *hcpu)
360 int cpu = (
long)hcpu;
365 rc = cache_add_cpu(cpu);
367 cache_remove_cpu(cpu);
370 cache_remove_cpu(cpu);
373 return rc ? NOTIFY_BAD : NOTIFY_OK;
380 if (!test_facility(34))