common.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright (c) 2016, Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef SOC_NPS_COMMON_H
  33. #define SOC_NPS_COMMON_H
  34. #ifdef CONFIG_SMP
  35. #define NPS_IPI_IRQ 5
  36. #endif
  37. #define NPS_HOST_REG_BASE 0xF6000000
  38. #define NPS_MSU_BLKID 0x018
  39. #define CTOP_INST_RSPI_GIC_0_R12 0x3C56117E
  40. #define CTOP_INST_MOV2B_FLIP_R3_B1_B2_INST 0x5B60
  41. #define CTOP_INST_MOV2B_FLIP_R3_B1_B2_LIMM 0x00010422
  42. #ifndef AUX_IENABLE
  43. #define AUX_IENABLE 0x40c
  44. #endif
  45. #define CTOP_AUX_IACK (0xFFFFF800 + 0x088)
  46. #ifndef __ASSEMBLY__
  47. /* In order to increase compilation test coverage */
  48. #ifdef CONFIG_ARC
  49. static inline void nps_ack_gic(void)
  50. {
  51. __asm__ __volatile__ (
  52. " .word %0\n"
  53. :
  54. : "i"(CTOP_INST_RSPI_GIC_0_R12)
  55. : "memory");
  56. }
  57. #else
  58. static inline void nps_ack_gic(void) { }
  59. #define write_aux_reg(r, v)
  60. #define read_aux_reg(r) 0
  61. #endif
  62. /* CPU global ID */
  63. struct global_id {
  64. union {
  65. struct {
  66. #ifdef CONFIG_EZNPS_MTM_EXT
  67. u32 __reserved:20, cluster:4, core:4, thread:4;
  68. #else
  69. u32 __reserved:24, cluster:4, core:4;
  70. #endif
  71. };
  72. u32 value;
  73. };
  74. };
  75. /*
  76. * Convert logical to physical CPU IDs
  77. *
  78. * The conversion swap bits 1 and 2 of cluster id (out of 4 bits)
  79. * Now quad of logical clusters id's are adjacent physically,
  80. * and not like the id's physically came with each cluster.
  81. * Below table is 4x4 mesh of core clusters as it layout on chip.
  82. * Cluster ids are in format: logical (physical)
  83. *
  84. * ----------------- ------------------
  85. * 3 | 5 (3) 7 (7) | | 13 (11) 15 (15)|
  86. *
  87. * 2 | 4 (2) 6 (6) | | 12 (10) 14 (14)|
  88. * ----------------- ------------------
  89. * 1 | 1 (1) 3 (5) | | 9 (9) 11 (13)|
  90. *
  91. * 0 | 0 (0) 2 (4) | | 8 (8) 10 (12)|
  92. * ----------------- ------------------
  93. * 0 1 2 3
  94. */
  95. static inline int nps_cluster_logic_to_phys(int cluster)
  96. {
  97. #ifdef __arc__
  98. __asm__ __volatile__(
  99. " mov r3,%0\n"
  100. " .short %1\n"
  101. " .word %2\n"
  102. " mov %0,r3\n"
  103. : "+r"(cluster)
  104. : "i"(CTOP_INST_MOV2B_FLIP_R3_B1_B2_INST),
  105. "i"(CTOP_INST_MOV2B_FLIP_R3_B1_B2_LIMM)
  106. : "r3");
  107. #endif
  108. return cluster;
  109. }
  110. #define NPS_CPU_TO_CLUSTER_NUM(cpu) \
  111. ({ struct global_id gid; gid.value = cpu; \
  112. nps_cluster_logic_to_phys(gid.cluster); })
  113. struct nps_host_reg_address {
  114. union {
  115. struct {
  116. u32 base:8, cl_x:4, cl_y:4,
  117. blkid:6, reg:8, __reserved:2;
  118. };
  119. u32 value;
  120. };
  121. };
  122. struct nps_host_reg_address_non_cl {
  123. union {
  124. struct {
  125. u32 base:7, blkid:11, reg:12, __reserved:2;
  126. };
  127. u32 value;
  128. };
  129. };
  130. static inline void *nps_host_reg_non_cl(u32 blkid, u32 reg)
  131. {
  132. struct nps_host_reg_address_non_cl reg_address;
  133. reg_address.value = NPS_HOST_REG_BASE;
  134. reg_address.blkid = blkid;
  135. reg_address.reg = reg;
  136. return (void *)reg_address.value;
  137. }
  138. static inline void *nps_host_reg(u32 cpu, u32 blkid, u32 reg)
  139. {
  140. struct nps_host_reg_address reg_address;
  141. u32 cl = NPS_CPU_TO_CLUSTER_NUM(cpu);
  142. reg_address.value = NPS_HOST_REG_BASE;
  143. reg_address.cl_x = (cl >> 2) & 0x3;
  144. reg_address.cl_y = cl & 0x3;
  145. reg_address.blkid = blkid;
  146. reg_address.reg = reg;
  147. return (void *)reg_address.value;
  148. }
  149. #endif /* __ASSEMBLY__ */
  150. #endif /* SOC_NPS_COMMON_H */