2 * Copyright (C) 2017 SiFive
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.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/cacheinfo.h>
15 #include <linux/cpu.h>
17 #include <linux/of_device.h>
19 static void ci_leaf_init(struct cacheinfo
*this_leaf
,
20 struct device_node
*node
,
21 enum cache_type type
, unsigned int level
)
23 this_leaf
->of_node
= node
;
24 this_leaf
->level
= level
;
25 this_leaf
->type
= type
;
26 /* not a sector cache */
27 this_leaf
->physical_line_partition
= 1;
28 /* TODO: Add to DTS */
29 this_leaf
->attributes
=
32 | CACHE_WRITE_ALLOCATE
;
35 static int __init_cache_level(unsigned int cpu
)
37 struct cpu_cacheinfo
*this_cpu_ci
= get_cpu_cacheinfo(cpu
);
38 struct device_node
*np
= of_cpu_device_node_get(cpu
);
39 int levels
= 0, leaves
= 0, level
;
41 if (of_property_read_bool(np
, "cache-size"))
43 if (of_property_read_bool(np
, "i-cache-size"))
45 if (of_property_read_bool(np
, "d-cache-size"))
50 while ((np
= of_find_next_cache_node(np
))) {
51 if (!of_device_is_compatible(np
, "cache"))
53 if (of_property_read_u32(np
, "cache-level", &level
))
57 if (of_property_read_bool(np
, "cache-size"))
59 if (of_property_read_bool(np
, "i-cache-size"))
61 if (of_property_read_bool(np
, "d-cache-size"))
66 this_cpu_ci
->num_levels
= levels
;
67 this_cpu_ci
->num_leaves
= leaves
;
71 static int __populate_cache_leaves(unsigned int cpu
)
73 struct cpu_cacheinfo
*this_cpu_ci
= get_cpu_cacheinfo(cpu
);
74 struct cacheinfo
*this_leaf
= this_cpu_ci
->info_list
;
75 struct device_node
*np
= of_cpu_device_node_get(cpu
);
76 int levels
= 1, level
= 1;
78 if (of_property_read_bool(np
, "cache-size"))
79 ci_leaf_init(this_leaf
++, np
, CACHE_TYPE_UNIFIED
, level
);
80 if (of_property_read_bool(np
, "i-cache-size"))
81 ci_leaf_init(this_leaf
++, np
, CACHE_TYPE_INST
, level
);
82 if (of_property_read_bool(np
, "d-cache-size"))
83 ci_leaf_init(this_leaf
++, np
, CACHE_TYPE_DATA
, level
);
85 while ((np
= of_find_next_cache_node(np
))) {
86 if (!of_device_is_compatible(np
, "cache"))
88 if (of_property_read_u32(np
, "cache-level", &level
))
92 if (of_property_read_bool(np
, "cache-size"))
93 ci_leaf_init(this_leaf
++, np
, CACHE_TYPE_UNIFIED
, level
);
94 if (of_property_read_bool(np
, "i-cache-size"))
95 ci_leaf_init(this_leaf
++, np
, CACHE_TYPE_INST
, level
);
96 if (of_property_read_bool(np
, "d-cache-size"))
97 ci_leaf_init(this_leaf
++, np
, CACHE_TYPE_DATA
, level
);
104 DEFINE_SMP_CALL_CACHE_FUNCTION(init_cache_level
)
105 DEFINE_SMP_CALL_CACHE_FUNCTION(populate_cache_leaves
)