cache.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 SiFive, Inc
  4. *
  5. * Authors:
  6. * Pragnesh Patel <pragnesh.patel@sifive.com>
  7. */
  8. #include <common.h>
  9. #include <asm/global_data.h>
  10. #include <asm/io.h>
  11. #include <linux/bitops.h>
  12. /* Register offsets */
  13. #define L2_CACHE_CONFIG 0x000
  14. #define L2_CACHE_ENABLE 0x008
  15. #define MASK_NUM_WAYS GENMASK(15, 8)
  16. #define NUM_WAYS_SHIFT 8
  17. DECLARE_GLOBAL_DATA_PTR;
  18. int cache_enable_ways(void)
  19. {
  20. const void *blob = gd->fdt_blob;
  21. int node;
  22. fdt_addr_t base;
  23. u32 config;
  24. u32 ways;
  25. volatile u32 *enable;
  26. node = fdt_node_offset_by_compatible(blob, -1,
  27. "sifive,fu540-c000-ccache");
  28. if (node < 0)
  29. return node;
  30. base = fdtdec_get_addr_size_auto_parent(blob, 0, node, "reg", 0,
  31. NULL, false);
  32. if (base == FDT_ADDR_T_NONE)
  33. return FDT_ADDR_T_NONE;
  34. config = readl((volatile u32 *)base + L2_CACHE_CONFIG);
  35. ways = (config & MASK_NUM_WAYS) >> NUM_WAYS_SHIFT;
  36. enable = (volatile u32 *)(base + L2_CACHE_ENABLE);
  37. /* memory barrier */
  38. mb();
  39. (*enable) = ways - 1;
  40. /* memory barrier */
  41. mb();
  42. return 0;
  43. }