xp_uv.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * (C) Copyright 2020 Hewlett Packard Enterprise Development LP
  7. * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
  8. */
  9. /*
  10. * Cross Partition (XP) uv-based functions.
  11. *
  12. * Architecture specific implementation of common functions.
  13. *
  14. */
  15. #include <linux/device.h>
  16. #include <asm/uv/uv_hub.h>
  17. #if defined CONFIG_X86_64
  18. #include <asm/uv/bios.h>
  19. #elif defined CONFIG_IA64_SGI_UV
  20. #include <asm/sn/sn_sal.h>
  21. #endif
  22. #include "../sgi-gru/grukservices.h"
  23. #include "xp.h"
  24. /*
  25. * Convert a virtual memory address to a physical memory address.
  26. */
  27. static unsigned long
  28. xp_pa_uv(void *addr)
  29. {
  30. return uv_gpa(addr);
  31. }
  32. /*
  33. * Convert a global physical to socket physical address.
  34. */
  35. static unsigned long
  36. xp_socket_pa_uv(unsigned long gpa)
  37. {
  38. return uv_gpa_to_soc_phys_ram(gpa);
  39. }
  40. static enum xp_retval
  41. xp_remote_mmr_read(unsigned long dst_gpa, const unsigned long src_gpa,
  42. size_t len)
  43. {
  44. int ret;
  45. unsigned long *dst_va = __va(uv_gpa_to_soc_phys_ram(dst_gpa));
  46. BUG_ON(!uv_gpa_in_mmr_space(src_gpa));
  47. BUG_ON(len != 8);
  48. ret = gru_read_gpa(dst_va, src_gpa);
  49. if (ret == 0)
  50. return xpSuccess;
  51. dev_err(xp, "gru_read_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx "
  52. "len=%ld\n", dst_gpa, src_gpa, len);
  53. return xpGruCopyError;
  54. }
  55. static enum xp_retval
  56. xp_remote_memcpy_uv(unsigned long dst_gpa, const unsigned long src_gpa,
  57. size_t len)
  58. {
  59. int ret;
  60. if (uv_gpa_in_mmr_space(src_gpa))
  61. return xp_remote_mmr_read(dst_gpa, src_gpa, len);
  62. ret = gru_copy_gpa(dst_gpa, src_gpa, len);
  63. if (ret == 0)
  64. return xpSuccess;
  65. dev_err(xp, "gru_copy_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx "
  66. "len=%ld\n", dst_gpa, src_gpa, len);
  67. return xpGruCopyError;
  68. }
  69. static int
  70. xp_cpu_to_nasid_uv(int cpuid)
  71. {
  72. /* ??? Is this same as sn2 nasid in mach/part bitmaps set up by SAL? */
  73. return UV_PNODE_TO_NASID(uv_cpu_to_pnode(cpuid));
  74. }
  75. static enum xp_retval
  76. xp_expand_memprotect_uv(unsigned long phys_addr, unsigned long size)
  77. {
  78. int ret;
  79. #if defined CONFIG_X86_64
  80. ret = uv_bios_change_memprotect(phys_addr, size, UV_MEMPROT_ALLOW_RW);
  81. if (ret != BIOS_STATUS_SUCCESS) {
  82. dev_err(xp, "uv_bios_change_memprotect(,, "
  83. "UV_MEMPROT_ALLOW_RW) failed, ret=%d\n", ret);
  84. return xpBiosError;
  85. }
  86. #elif defined CONFIG_IA64_SGI_UV
  87. u64 nasid_array;
  88. ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_1,
  89. &nasid_array);
  90. if (ret != 0) {
  91. dev_err(xp, "sn_change_memprotect(,, "
  92. "SN_MEMPROT_ACCESS_CLASS_1,) failed ret=%d\n", ret);
  93. return xpSalError;
  94. }
  95. #else
  96. #error not a supported configuration
  97. #endif
  98. return xpSuccess;
  99. }
  100. static enum xp_retval
  101. xp_restrict_memprotect_uv(unsigned long phys_addr, unsigned long size)
  102. {
  103. int ret;
  104. #if defined CONFIG_X86_64
  105. ret = uv_bios_change_memprotect(phys_addr, size,
  106. UV_MEMPROT_RESTRICT_ACCESS);
  107. if (ret != BIOS_STATUS_SUCCESS) {
  108. dev_err(xp, "uv_bios_change_memprotect(,, "
  109. "UV_MEMPROT_RESTRICT_ACCESS) failed, ret=%d\n", ret);
  110. return xpBiosError;
  111. }
  112. #elif defined CONFIG_IA64_SGI_UV
  113. u64 nasid_array;
  114. ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_0,
  115. &nasid_array);
  116. if (ret != 0) {
  117. dev_err(xp, "sn_change_memprotect(,, "
  118. "SN_MEMPROT_ACCESS_CLASS_0,) failed ret=%d\n", ret);
  119. return xpSalError;
  120. }
  121. #else
  122. #error not a supported configuration
  123. #endif
  124. return xpSuccess;
  125. }
  126. enum xp_retval
  127. xp_init_uv(void)
  128. {
  129. WARN_ON(!is_uv_system());
  130. if (!is_uv_system())
  131. return xpUnsupported;
  132. xp_max_npartitions = XP_MAX_NPARTITIONS_UV;
  133. #ifdef CONFIG_X86
  134. xp_partition_id = sn_partition_id;
  135. xp_region_size = sn_region_size;
  136. #endif
  137. xp_pa = xp_pa_uv;
  138. xp_socket_pa = xp_socket_pa_uv;
  139. xp_remote_memcpy = xp_remote_memcpy_uv;
  140. xp_cpu_to_nasid = xp_cpu_to_nasid_uv;
  141. xp_expand_memprotect = xp_expand_memprotect_uv;
  142. xp_restrict_memprotect = xp_restrict_memprotect_uv;
  143. return xpSuccess;
  144. }
  145. void
  146. xp_exit_uv(void)
  147. {
  148. WARN_ON(!is_uv_system());
  149. }