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 3568212893SRobin Holt /* 3668212893SRobin Holt * Convert a global physical to socket physical address. 3768212893SRobin Holt */ 3868212893SRobin Holt static unsigned long 3968212893SRobin Holt xp_socket_pa_uv(unsigned long gpa) 4068212893SRobin Holt { 4168212893SRobin Holt return uv_gpa_to_soc_phys_ram(gpa); 4268212893SRobin Holt } 4368212893SRobin Holt 44a812dcc3SDean Nelson static enum xp_retval 45*c2c9f115SRobin Holt xp_remote_mmr_read(unsigned long dst_gpa, const unsigned long src_gpa, 46*c2c9f115SRobin Holt size_t len) 47*c2c9f115SRobin Holt { 48*c2c9f115SRobin Holt int ret; 49*c2c9f115SRobin Holt unsigned long *dst_va = __va(uv_gpa_to_soc_phys_ram(dst_gpa)); 50*c2c9f115SRobin Holt 51*c2c9f115SRobin Holt BUG_ON(!uv_gpa_in_mmr_space(src_gpa)); 52*c2c9f115SRobin Holt BUG_ON(len != 8); 53*c2c9f115SRobin Holt 54*c2c9f115SRobin Holt ret = gru_read_gpa(dst_va, src_gpa); 55*c2c9f115SRobin Holt if (ret == 0) 56*c2c9f115SRobin Holt return xpSuccess; 57*c2c9f115SRobin Holt 58*c2c9f115SRobin Holt dev_err(xp, "gru_read_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx " 59*c2c9f115SRobin Holt "len=%ld\n", dst_gpa, src_gpa, len); 60*c2c9f115SRobin Holt return xpGruCopyError; 61*c2c9f115SRobin Holt } 62*c2c9f115SRobin Holt 63*c2c9f115SRobin Holt 64*c2c9f115SRobin Holt static enum xp_retval 65a812dcc3SDean Nelson xp_remote_memcpy_uv(unsigned long dst_gpa, const unsigned long src_gpa, 66a812dcc3SDean Nelson size_t len) 67a812dcc3SDean Nelson { 68a812dcc3SDean Nelson int ret; 69a812dcc3SDean Nelson 70*c2c9f115SRobin Holt if (uv_gpa_in_mmr_space(src_gpa)) 71*c2c9f115SRobin Holt return xp_remote_mmr_read(dst_gpa, src_gpa, len); 72*c2c9f115SRobin Holt 73a812dcc3SDean Nelson ret = gru_copy_gpa(dst_gpa, src_gpa, len); 74a812dcc3SDean Nelson if (ret == 0) 75a812dcc3SDean Nelson return xpSuccess; 76a812dcc3SDean Nelson 77a812dcc3SDean Nelson dev_err(xp, "gru_copy_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx " 78a812dcc3SDean Nelson "len=%ld\n", dst_gpa, src_gpa, len); 79a812dcc3SDean Nelson return xpGruCopyError; 80908787dbSDean Nelson } 81908787dbSDean Nelson 825b8669dfSDean Nelson static int 835b8669dfSDean Nelson xp_cpu_to_nasid_uv(int cpuid) 845b8669dfSDean Nelson { 855b8669dfSDean Nelson /* ??? Is this same as sn2 nasid in mach/part bitmaps set up by SAL? */ 865b8669dfSDean Nelson return UV_PNODE_TO_NASID(uv_cpu_to_pnode(cpuid)); 875b8669dfSDean Nelson } 885b8669dfSDean Nelson 896c1c325dSDean Nelson static enum xp_retval 906c1c325dSDean Nelson xp_expand_memprotect_uv(unsigned long phys_addr, unsigned long size) 916c1c325dSDean Nelson { 926c1c325dSDean Nelson int ret; 936c1c325dSDean Nelson 946c1c325dSDean Nelson #if defined CONFIG_X86_64 956c1c325dSDean Nelson ret = uv_bios_change_memprotect(phys_addr, size, UV_MEMPROT_ALLOW_RW); 966c1c325dSDean Nelson if (ret != BIOS_STATUS_SUCCESS) { 976c1c325dSDean Nelson dev_err(xp, "uv_bios_change_memprotect(,, " 986c1c325dSDean Nelson "UV_MEMPROT_ALLOW_RW) failed, ret=%d\n", ret); 996c1c325dSDean Nelson return xpBiosError; 1006c1c325dSDean Nelson } 1016c1c325dSDean Nelson 1026c1c325dSDean Nelson #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV 1036c1c325dSDean Nelson u64 nasid_array; 1046c1c325dSDean Nelson 1056c1c325dSDean Nelson ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_1, 1066c1c325dSDean Nelson &nasid_array); 1076c1c325dSDean Nelson if (ret != 0) { 1086c1c325dSDean Nelson dev_err(xp, "sn_change_memprotect(,, " 1096c1c325dSDean Nelson "SN_MEMPROT_ACCESS_CLASS_1,) failed ret=%d\n", ret); 1106c1c325dSDean Nelson return xpSalError; 1116c1c325dSDean Nelson } 1126c1c325dSDean Nelson #else 1136c1c325dSDean Nelson #error not a supported configuration 1146c1c325dSDean Nelson #endif 1156c1c325dSDean Nelson return xpSuccess; 1166c1c325dSDean Nelson } 1176c1c325dSDean Nelson 1186c1c325dSDean Nelson static enum xp_retval 1196c1c325dSDean Nelson xp_restrict_memprotect_uv(unsigned long phys_addr, unsigned long size) 1206c1c325dSDean Nelson { 1216c1c325dSDean Nelson int ret; 1226c1c325dSDean Nelson 1236c1c325dSDean Nelson #if defined CONFIG_X86_64 1246c1c325dSDean Nelson ret = uv_bios_change_memprotect(phys_addr, size, 1256c1c325dSDean Nelson UV_MEMPROT_RESTRICT_ACCESS); 1266c1c325dSDean Nelson if (ret != BIOS_STATUS_SUCCESS) { 1276c1c325dSDean Nelson dev_err(xp, "uv_bios_change_memprotect(,, " 1286c1c325dSDean Nelson "UV_MEMPROT_RESTRICT_ACCESS) failed, ret=%d\n", ret); 1296c1c325dSDean Nelson return xpBiosError; 1306c1c325dSDean Nelson } 1316c1c325dSDean Nelson 1326c1c325dSDean Nelson #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV 1336c1c325dSDean Nelson u64 nasid_array; 1346c1c325dSDean Nelson 1356c1c325dSDean Nelson ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_0, 1366c1c325dSDean Nelson &nasid_array); 1376c1c325dSDean Nelson if (ret != 0) { 1386c1c325dSDean Nelson dev_err(xp, "sn_change_memprotect(,, " 1396c1c325dSDean Nelson "SN_MEMPROT_ACCESS_CLASS_0,) failed ret=%d\n", ret); 1406c1c325dSDean Nelson return xpSalError; 1416c1c325dSDean Nelson } 1426c1c325dSDean Nelson #else 1436c1c325dSDean Nelson #error not a supported configuration 1446c1c325dSDean Nelson #endif 1456c1c325dSDean Nelson return xpSuccess; 1466c1c325dSDean Nelson } 1476c1c325dSDean Nelson 148bc63d387SDean Nelson enum xp_retval 149bc63d387SDean Nelson xp_init_uv(void) 150bc63d387SDean Nelson { 151bc63d387SDean Nelson BUG_ON(!is_uv()); 152bc63d387SDean Nelson 153bc63d387SDean Nelson xp_max_npartitions = XP_MAX_NPARTITIONS_UV; 15431de5eceSDean Nelson xp_partition_id = sn_partition_id; 15531de5eceSDean Nelson xp_region_size = sn_region_size; 156908787dbSDean Nelson 157a812dcc3SDean Nelson xp_pa = xp_pa_uv; 15868212893SRobin Holt xp_socket_pa = xp_socket_pa_uv; 159908787dbSDean Nelson xp_remote_memcpy = xp_remote_memcpy_uv; 1605b8669dfSDean Nelson xp_cpu_to_nasid = xp_cpu_to_nasid_uv; 1616c1c325dSDean Nelson xp_expand_memprotect = xp_expand_memprotect_uv; 1626c1c325dSDean Nelson xp_restrict_memprotect = xp_restrict_memprotect_uv; 163908787dbSDean Nelson 164908787dbSDean Nelson return xpSuccess; 165bc63d387SDean Nelson } 166bc63d387SDean Nelson 167bc63d387SDean Nelson void 168bc63d387SDean Nelson xp_exit_uv(void) 169bc63d387SDean Nelson { 170bc63d387SDean Nelson BUG_ON(!is_uv()); 171bc63d387SDean Nelson } 172