cacheinfo.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #include <linux/bitops.h>
  4. #include <linux/cacheinfo.h>
  5. #include <linux/cpu.h>
  6. static void ci_leaf_init(struct cacheinfo *this_leaf,
  7. enum cache_type type, unsigned int level)
  8. {
  9. char cache_type = (type & CACHE_TYPE_INST ? ICACHE : DCACHE);
  10. this_leaf->level = level;
  11. this_leaf->type = type;
  12. this_leaf->coherency_line_size = CACHE_LINE_SIZE(cache_type);
  13. this_leaf->number_of_sets = CACHE_SET(cache_type);;
  14. this_leaf->ways_of_associativity = CACHE_WAY(cache_type);
  15. this_leaf->size = this_leaf->number_of_sets *
  16. this_leaf->coherency_line_size * this_leaf->ways_of_associativity;
  17. #if defined(CONFIG_CPU_DCACHE_WRITETHROUGH)
  18. this_leaf->attributes = CACHE_WRITE_THROUGH;
  19. #else
  20. this_leaf->attributes = CACHE_WRITE_BACK;
  21. #endif
  22. }
  23. int init_cache_level(unsigned int cpu)
  24. {
  25. struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
  26. /* Only 1 level and I/D cache seperate. */
  27. this_cpu_ci->num_levels = 1;
  28. this_cpu_ci->num_leaves = 2;
  29. return 0;
  30. }
  31. int populate_cache_leaves(unsigned int cpu)
  32. {
  33. unsigned int level, idx;
  34. struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
  35. struct cacheinfo *this_leaf = this_cpu_ci->info_list;
  36. for (idx = 0, level = 1; level <= this_cpu_ci->num_levels &&
  37. idx < this_cpu_ci->num_leaves; idx++, level++) {
  38. ci_leaf_init(this_leaf++, CACHE_TYPE_DATA, level);
  39. ci_leaf_init(this_leaf++, CACHE_TYPE_INST, level);
  40. }
  41. return 0;
  42. }