cache-ncore.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2019 Intel Corporation <www.intel.com>
  4. *
  5. */
  6. #include <dm.h>
  7. #include <hang.h>
  8. #include <wait_bit.h>
  9. #include <asm/io.h>
  10. /* Directory */
  11. #define DIRUSFER 0x80010
  12. #define DIRUCASER0 0x80040
  13. #define DIRUSFMCR 0x80080
  14. #define DIRUSFMAR 0x80084
  15. #define DIRUSFMCR_SFID_SHIFT 16
  16. /* Coherent cache agent interface */
  17. #define CAIUIDR 0x00ffc
  18. #define CAIUIDR_CA_GET(v) (((v) & 0x00008000) >> 15)
  19. #define CAIUIDR_TYPE_GET(v) (((v) & 0x000f0000) >> 16)
  20. #define CAIUIDR_TYPE_ACE_CAI_DVM_SUPPORT 0
  21. #define CAIUIDR_TYPE_ACELITE_CAI_DVM_SUPPORT 1
  22. /* Coherent subsystem */
  23. #define CSADSER0 0xff040
  24. #define CSUIDR 0xffff8
  25. #define CSIDR 0xffffc
  26. #define CSUIDR_NUMCAIUS_GET(v) (((v) & 0x0000007f) >> 0)
  27. #define CSUIDR_NUMDIRUS_GET(v) (((v) & 0x003f0000) >> 16)
  28. #define CSUIDR_NUMCMIUS_GET(v) (((v) & 0x3f000000) >> 24)
  29. #define CSIDR_NUMSFS_GET(v) (((v) & 0x007c0000) >> 18)
  30. #define DIR_REG_SZ 0x1000
  31. #define CAIU_REG_SZ 0x1000
  32. #define CCU_DIR_REG_ADDR(base, reg, dir) \
  33. ((base) + (reg) + ((dir) * DIR_REG_SZ))
  34. /* OCRAM firewall register */
  35. #define OCRAM_FW_01 0x100204
  36. #define OCRAM_SECURE_REGIONS 4
  37. #define OCRAM_PRIVILEGED_MASK BIT(29)
  38. #define OCRAM_SECURE_MASK BIT(30)
  39. static void ncore_ccu_init_dirs(void __iomem *base)
  40. {
  41. ulong i, f;
  42. int ret;
  43. u32 num_of_dirs;
  44. u32 num_of_snoop_filters;
  45. u32 reg;
  46. num_of_dirs = CSUIDR_NUMDIRUS_GET(readl(base + CSUIDR));
  47. num_of_snoop_filters =
  48. CSIDR_NUMSFS_GET(readl(base + CSIDR)) + 1;
  49. /* Initialize each snoop filter in each directory */
  50. for (f = 0; f < num_of_snoop_filters; f++) {
  51. reg = f << DIRUSFMCR_SFID_SHIFT;
  52. for (i = 0; i < num_of_dirs; i++) {
  53. /* Initialize all entries */
  54. writel(reg, CCU_DIR_REG_ADDR(base, DIRUSFMCR, i));
  55. /* Poll snoop filter maintenance operation active
  56. * bit become 0.
  57. */
  58. ret = wait_for_bit_le32((const void *)
  59. CCU_DIR_REG_ADDR(base,
  60. DIRUSFMAR, i),
  61. BIT(0), false, 1000, false);
  62. if (ret) {
  63. puts("CCU: Directory initialization failed!\n");
  64. hang();
  65. }
  66. /* Enable snoop filter, a bit per snoop filter */
  67. setbits_le32((ulong)CCU_DIR_REG_ADDR(base, DIRUSFER, i),
  68. BIT(f));
  69. }
  70. }
  71. }
  72. static void ncore_ccu_init_coh_agent(void __iomem *base)
  73. {
  74. u32 num_of_coh_agent_intf;
  75. u32 num_of_dirs;
  76. u32 reg;
  77. u32 type;
  78. u32 i, dir;
  79. num_of_coh_agent_intf =
  80. CSUIDR_NUMCAIUS_GET(readl(base + CSUIDR));
  81. num_of_dirs = CSUIDR_NUMDIRUS_GET(readl(base + CSUIDR));
  82. for (i = 0; i < num_of_coh_agent_intf; i++) {
  83. reg = readl(base + CAIUIDR + (i * CAIU_REG_SZ));
  84. if (CAIUIDR_CA_GET(reg)) {
  85. /* Caching agent bit is enabled, enable caching agent
  86. * snoop in each directory
  87. */
  88. for (dir = 0; dir < num_of_dirs; dir++) {
  89. setbits_le32((ulong)
  90. CCU_DIR_REG_ADDR(base, DIRUCASER0,
  91. dir),
  92. BIT(i));
  93. }
  94. }
  95. type = CAIUIDR_TYPE_GET(reg);
  96. if (type == CAIUIDR_TYPE_ACE_CAI_DVM_SUPPORT ||
  97. type == CAIUIDR_TYPE_ACELITE_CAI_DVM_SUPPORT) {
  98. /* DVM support is enabled, enable ACE DVM snoop*/
  99. setbits_le32((ulong)(base + CSADSER0),
  100. BIT(i));
  101. }
  102. }
  103. }
  104. static void ocram_bypass_firewall(void __iomem *base)
  105. {
  106. int i;
  107. for (i = 0; i < OCRAM_SECURE_REGIONS; i++) {
  108. clrbits_le32(base + OCRAM_FW_01 + (i * sizeof(u32)),
  109. OCRAM_PRIVILEGED_MASK | OCRAM_SECURE_MASK);
  110. }
  111. }
  112. static int ncore_ccu_probe(struct udevice *dev)
  113. {
  114. void __iomem *base;
  115. fdt_addr_t addr;
  116. addr = dev_read_addr(dev);
  117. if (addr == FDT_ADDR_T_NONE)
  118. return -EINVAL;
  119. base = (void __iomem *)addr;
  120. ncore_ccu_init_dirs(base);
  121. ncore_ccu_init_coh_agent(base);
  122. ocram_bypass_firewall(base);
  123. return 0;
  124. }
  125. static const struct udevice_id ncore_ccu_ids[] = {
  126. { .compatible = "arteris,ncore-ccu" },
  127. {}
  128. };
  129. U_BOOT_DRIVER(ncore_ccu) = {
  130. .name = "ncore_ccu",
  131. .id = UCLASS_CACHE,
  132. .of_match = ncore_ccu_ids,
  133. .probe = ncore_ccu_probe,
  134. .flags = DM_FLAG_PRE_RELOC,
  135. };