common.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 __ASSEMBLY__
  43. /* In order to increase compilation test coverage */
  44. #ifdef CONFIG_ARC
  45. static inline void nps_ack_gic(void)
  46. {
  47. __asm__ __volatile__ (
  48. " .word %0\n"
  49. :
  50. : "i"(CTOP_INST_RSPI_GIC_0_R12)
  51. : "memory");
  52. }
  53. #else
  54. static inline void nps_ack_gic(void) { }
  55. #define write_aux_reg(r, v)
  56. #define read_aux_reg(r) 0
  57. #endif
  58. /* CPU global ID */
  59. struct global_id {
  60. union {
  61. struct {
  62. #ifdef CONFIG_EZNPS_MTM_EXT
  63. u32 __reserved:20, cluster:4, core:4, thread:4;
  64. #else
  65. u32 __reserved:24, cluster:4, core:4;
  66. #endif
  67. };
  68. u32 value;
  69. };
  70. };
  71. /*
  72. * Convert logical to physical CPU IDs
  73. *
  74. * The conversion swap bits 1 and 2 of cluster id (out of 4 bits)
  75. * Now quad of logical clusters id's are adjacent physically,
  76. * and not like the id's physically came with each cluster.
  77. * Below table is 4x4 mesh of core clusters as it layout on chip.
  78. * Cluster ids are in format: logical (physical)
  79. *
  80. * ----------------- ------------------
  81. * 3 | 5 (3) 7 (7) | | 13 (11) 15 (15)|
  82. *
  83. * 2 | 4 (2) 6 (6) | | 12 (10) 14 (14)|
  84. * ----------------- ------------------
  85. * 1 | 1 (1) 3 (5) | | 9 (9) 11 (13)|
  86. *
  87. * 0 | 0 (0) 2 (4) | | 8 (8) 10 (12)|
  88. * ----------------- ------------------
  89. * 0 1 2 3
  90. */
  91. static inline int nps_cluster_logic_to_phys(int cluster)
  92. {
  93. #ifdef __arc__
  94. __asm__ __volatile__(
  95. " mov r3,%0\n"
  96. " .short %1\n"
  97. " .word %2\n"
  98. " mov %0,r3\n"
  99. : "+r"(cluster)
  100. : "i"(CTOP_INST_MOV2B_FLIP_R3_B1_B2_INST),
  101. "i"(CTOP_INST_MOV2B_FLIP_R3_B1_B2_LIMM)
  102. : "r3");
  103. #endif
  104. return cluster;
  105. }
  106. #define NPS_CPU_TO_CLUSTER_NUM(cpu) \
  107. ({ struct global_id gid; gid.value = cpu; \
  108. nps_cluster_logic_to_phys(gid.cluster); })
  109. struct nps_host_reg_address {
  110. union {
  111. struct {
  112. u32 base:8, cl_x:4, cl_y:4,
  113. blkid:6, reg:8, __reserved:2;
  114. };
  115. u32 value;
  116. };
  117. };
  118. struct nps_host_reg_address_non_cl {
  119. union {
  120. struct {
  121. u32 base:7, blkid:11, reg:12, __reserved:2;
  122. };
  123. u32 value;
  124. };
  125. };
  126. static inline void *nps_host_reg_non_cl(u32 blkid, u32 reg)
  127. {
  128. struct nps_host_reg_address_non_cl reg_address;
  129. reg_address.value = NPS_HOST_REG_BASE;
  130. reg_address.blkid = blkid;
  131. reg_address.reg = reg;
  132. return (void *)reg_address.value;
  133. }
  134. static inline void *nps_host_reg(u32 cpu, u32 blkid, u32 reg)
  135. {
  136. struct nps_host_reg_address reg_address;
  137. u32 cl = NPS_CPU_TO_CLUSTER_NUM(cpu);
  138. reg_address.value = NPS_HOST_REG_BASE;
  139. reg_address.cl_x = (cl >> 2) & 0x3;
  140. reg_address.cl_y = cl & 0x3;
  141. reg_address.blkid = blkid;
  142. reg_address.reg = reg;
  143. return (void *)reg_address.value;
  144. }
  145. #endif /* __ASSEMBLY__ */
  146. #endif /* SOC_NPS_COMMON_H */