xp_uv.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_memcpy_uv(unsigned long dst_gpa, const unsigned long src_gpa,
  41. size_t len)
  42. {
  43. int ret;
  44. ret = gru_copy_gpa(dst_gpa, src_gpa, len);
  45. if (ret == 0)
  46. return xpSuccess;
  47. dev_err(xp, "gru_copy_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx "
  48. "len=%ld\n", dst_gpa, src_gpa, len);
  49. return xpGruCopyError;
  50. }
  51. static int
  52. xp_cpu_to_nasid_uv(int cpuid)
  53. {
  54. /* ??? Is this same as sn2 nasid in mach/part bitmaps set up by SAL? */
  55. return UV_PNODE_TO_NASID(uv_cpu_to_pnode(cpuid));
  56. }
  57. static enum xp_retval
  58. xp_expand_memprotect_uv(unsigned long phys_addr, unsigned long size)
  59. {
  60. int ret;
  61. #if defined CONFIG_X86_64
  62. ret = uv_bios_change_memprotect(phys_addr, size, UV_MEMPROT_ALLOW_RW);
  63. if (ret != BIOS_STATUS_SUCCESS) {
  64. dev_err(xp, "uv_bios_change_memprotect(,, "
  65. "UV_MEMPROT_ALLOW_RW) failed, ret=%d\n", ret);
  66. return xpBiosError;
  67. }
  68. #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
  69. u64 nasid_array;
  70. ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_1,
  71. &nasid_array);
  72. if (ret != 0) {
  73. dev_err(xp, "sn_change_memprotect(,, "
  74. "SN_MEMPROT_ACCESS_CLASS_1,) failed ret=%d\n", ret);
  75. return xpSalError;
  76. }
  77. #else
  78. #error not a supported configuration
  79. #endif
  80. return xpSuccess;
  81. }
  82. static enum xp_retval
  83. xp_restrict_memprotect_uv(unsigned long phys_addr, unsigned long size)
  84. {
  85. int ret;
  86. #if defined CONFIG_X86_64
  87. ret = uv_bios_change_memprotect(phys_addr, size,
  88. UV_MEMPROT_RESTRICT_ACCESS);
  89. if (ret != BIOS_STATUS_SUCCESS) {
  90. dev_err(xp, "uv_bios_change_memprotect(,, "
  91. "UV_MEMPROT_RESTRICT_ACCESS) failed, ret=%d\n", ret);
  92. return xpBiosError;
  93. }
  94. #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
  95. u64 nasid_array;
  96. ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_0,
  97. &nasid_array);
  98. if (ret != 0) {
  99. dev_err(xp, "sn_change_memprotect(,, "
  100. "SN_MEMPROT_ACCESS_CLASS_0,) failed ret=%d\n", ret);
  101. return xpSalError;
  102. }
  103. #else
  104. #error not a supported configuration
  105. #endif
  106. return xpSuccess;
  107. }
  108. enum xp_retval
  109. xp_init_uv(void)
  110. {
  111. BUG_ON(!is_uv());
  112. xp_max_npartitions = XP_MAX_NPARTITIONS_UV;
  113. xp_partition_id = sn_partition_id;
  114. xp_region_size = sn_region_size;
  115. xp_pa = xp_pa_uv;
  116. xp_socket_pa = xp_socket_pa_uv;
  117. xp_remote_memcpy = xp_remote_memcpy_uv;
  118. xp_cpu_to_nasid = xp_cpu_to_nasid_uv;
  119. xp_expand_memprotect = xp_expand_memprotect_uv;
  120. xp_restrict_memprotect = xp_restrict_memprotect_uv;
  121. return xpSuccess;
  122. }
  123. void
  124. xp_exit_uv(void)
  125. {
  126. BUG_ON(!is_uv());
  127. }