1bc63d387SDean Nelson /* 2bc63d387SDean Nelson * This file is subject to the terms and conditions of the GNU General Public 3bc63d387SDean Nelson * License. See the file "COPYING" in the main directory of this archive 4bc63d387SDean Nelson * for more details. 5bc63d387SDean Nelson * 6bc63d387SDean Nelson * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved. 7bc63d387SDean Nelson */ 8bc63d387SDean Nelson 9bc63d387SDean Nelson /* 10bc63d387SDean Nelson * Cross Partition (XP) uv-based functions. 11bc63d387SDean Nelson * 12bc63d387SDean Nelson * Architecture specific implementation of common functions. 13bc63d387SDean Nelson * 14bc63d387SDean Nelson */ 15bc63d387SDean Nelson 16a812dcc3SDean Nelson #include <linux/device.h> 17a812dcc3SDean Nelson #include <asm/uv/uv_hub.h> 186c1c325dSDean Nelson #if defined CONFIG_X86_64 196c1c325dSDean Nelson #include <asm/uv/bios.h> 206c1c325dSDean Nelson #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV 216c1c325dSDean Nelson #include <asm/sn/sn_sal.h> 226c1c325dSDean Nelson #endif 23a812dcc3SDean Nelson #include "../sgi-gru/grukservices.h" 24bc63d387SDean Nelson #include "xp.h" 25bc63d387SDean Nelson 26a812dcc3SDean Nelson /* 27a812dcc3SDean Nelson * Convert a virtual memory address to a physical memory address. 28a812dcc3SDean Nelson */ 29a812dcc3SDean Nelson static unsigned long 30a812dcc3SDean Nelson xp_pa_uv(void *addr) 31908787dbSDean Nelson { 32a812dcc3SDean Nelson return uv_gpa(addr); 33a812dcc3SDean Nelson } 34a812dcc3SDean Nelson 35a812dcc3SDean Nelson static enum xp_retval 36a812dcc3SDean Nelson xp_remote_memcpy_uv(unsigned long dst_gpa, const unsigned long src_gpa, 37a812dcc3SDean Nelson size_t len) 38a812dcc3SDean Nelson { 39a812dcc3SDean Nelson int ret; 40a812dcc3SDean Nelson 41a812dcc3SDean Nelson ret = gru_copy_gpa(dst_gpa, src_gpa, len); 42a812dcc3SDean Nelson if (ret == 0) 43a812dcc3SDean Nelson return xpSuccess; 44a812dcc3SDean Nelson 45a812dcc3SDean Nelson dev_err(xp, "gru_copy_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx " 46a812dcc3SDean Nelson "len=%ld\n", dst_gpa, src_gpa, len); 47a812dcc3SDean Nelson return xpGruCopyError; 48908787dbSDean Nelson } 49908787dbSDean Nelson 505b8669dfSDean Nelson static int 515b8669dfSDean Nelson xp_cpu_to_nasid_uv(int cpuid) 525b8669dfSDean Nelson { 535b8669dfSDean Nelson /* ??? Is this same as sn2 nasid in mach/part bitmaps set up by SAL? */ 545b8669dfSDean Nelson return UV_PNODE_TO_NASID(uv_cpu_to_pnode(cpuid)); 555b8669dfSDean Nelson } 565b8669dfSDean Nelson 576c1c325dSDean Nelson static enum xp_retval 586c1c325dSDean Nelson xp_expand_memprotect_uv(unsigned long phys_addr, unsigned long size) 596c1c325dSDean Nelson { 606c1c325dSDean Nelson int ret; 616c1c325dSDean Nelson 626c1c325dSDean Nelson #if defined CONFIG_X86_64 636c1c325dSDean Nelson ret = uv_bios_change_memprotect(phys_addr, size, UV_MEMPROT_ALLOW_RW); 646c1c325dSDean Nelson if (ret != BIOS_STATUS_SUCCESS) { 656c1c325dSDean Nelson dev_err(xp, "uv_bios_change_memprotect(,, " 666c1c325dSDean Nelson "UV_MEMPROT_ALLOW_RW) failed, ret=%d\n", ret); 676c1c325dSDean Nelson return xpBiosError; 686c1c325dSDean Nelson } 696c1c325dSDean Nelson 706c1c325dSDean Nelson #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV 716c1c325dSDean Nelson u64 nasid_array; 726c1c325dSDean Nelson 736c1c325dSDean Nelson ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_1, 746c1c325dSDean Nelson &nasid_array); 756c1c325dSDean Nelson if (ret != 0) { 766c1c325dSDean Nelson dev_err(xp, "sn_change_memprotect(,, " 776c1c325dSDean Nelson "SN_MEMPROT_ACCESS_CLASS_1,) failed ret=%d\n", ret); 786c1c325dSDean Nelson return xpSalError; 796c1c325dSDean Nelson } 806c1c325dSDean Nelson #else 816c1c325dSDean Nelson #error not a supported configuration 826c1c325dSDean Nelson #endif 836c1c325dSDean Nelson return xpSuccess; 846c1c325dSDean Nelson } 856c1c325dSDean Nelson 866c1c325dSDean Nelson static enum xp_retval 876c1c325dSDean Nelson xp_restrict_memprotect_uv(unsigned long phys_addr, unsigned long size) 886c1c325dSDean Nelson { 896c1c325dSDean Nelson int ret; 906c1c325dSDean Nelson 916c1c325dSDean Nelson #if defined CONFIG_X86_64 926c1c325dSDean Nelson ret = uv_bios_change_memprotect(phys_addr, size, 936c1c325dSDean Nelson UV_MEMPROT_RESTRICT_ACCESS); 946c1c325dSDean Nelson if (ret != BIOS_STATUS_SUCCESS) { 956c1c325dSDean Nelson dev_err(xp, "uv_bios_change_memprotect(,, " 966c1c325dSDean Nelson "UV_MEMPROT_RESTRICT_ACCESS) failed, ret=%d\n", ret); 976c1c325dSDean Nelson return xpBiosError; 986c1c325dSDean Nelson } 996c1c325dSDean Nelson 1006c1c325dSDean Nelson #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV 1016c1c325dSDean Nelson u64 nasid_array; 1026c1c325dSDean Nelson 1036c1c325dSDean Nelson ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_0, 1046c1c325dSDean Nelson &nasid_array); 1056c1c325dSDean Nelson if (ret != 0) { 1066c1c325dSDean Nelson dev_err(xp, "sn_change_memprotect(,, " 1076c1c325dSDean Nelson "SN_MEMPROT_ACCESS_CLASS_0,) failed ret=%d\n", ret); 1086c1c325dSDean Nelson return xpSalError; 1096c1c325dSDean Nelson } 1106c1c325dSDean Nelson #else 1116c1c325dSDean Nelson #error not a supported configuration 1126c1c325dSDean Nelson #endif 1136c1c325dSDean Nelson return xpSuccess; 1146c1c325dSDean Nelson } 1156c1c325dSDean Nelson 116bc63d387SDean Nelson enum xp_retval 117bc63d387SDean Nelson xp_init_uv(void) 118bc63d387SDean Nelson { 119bc63d387SDean Nelson BUG_ON(!is_uv()); 120bc63d387SDean Nelson 121bc63d387SDean Nelson xp_max_npartitions = XP_MAX_NPARTITIONS_UV; 122*31de5eceSDean Nelson xp_partition_id = sn_partition_id; 123*31de5eceSDean Nelson xp_region_size = sn_region_size; 124908787dbSDean Nelson 125a812dcc3SDean Nelson xp_pa = xp_pa_uv; 126908787dbSDean Nelson xp_remote_memcpy = xp_remote_memcpy_uv; 1275b8669dfSDean Nelson xp_cpu_to_nasid = xp_cpu_to_nasid_uv; 1286c1c325dSDean Nelson xp_expand_memprotect = xp_expand_memprotect_uv; 1296c1c325dSDean Nelson xp_restrict_memprotect = xp_restrict_memprotect_uv; 130908787dbSDean Nelson 131908787dbSDean Nelson return xpSuccess; 132bc63d387SDean Nelson } 133bc63d387SDean Nelson 134bc63d387SDean Nelson void 135bc63d387SDean Nelson xp_exit_uv(void) 136bc63d387SDean Nelson { 137bc63d387SDean Nelson BUG_ON(!is_uv()); 138bc63d387SDean Nelson } 139