xp_uv.c 3.2 KB

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