xp_uv.c 3.9 KB

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