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
6 * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
10 * Cross Partition (XP) sn2-based functions.
12 * Architecture specific implementation of common functions.
15 #include <linux/module.h>
16 #include <linux/device.h>
17 #include <asm/sn/bte.h>
18 #include <asm/sn/sn_sal.h>
22 * The export of xp_nofault_PIOR needs to happen here since it is defined
23 * in drivers/misc/sgi-xp/xp_nofault.S. The target of the nofault read is
26 EXPORT_SYMBOL_GPL(xp_nofault_PIOR);
28 u64 xp_nofault_PIOR_target;
29 EXPORT_SYMBOL_GPL(xp_nofault_PIOR_target);
32 * Register a nofault code region which performs a cross-partition PIO read.
33 * If the PIO read times out, the MCA handler will consume the error and
34 * return to a kernel-provided instruction to indicate an error. This PIO read
35 * exists because it is guaranteed to timeout if the destination is down
36 * (amo operations do not timeout on at least some CPUs on Shubs <= v1.2,
37 * which unfortunately we have to work around).
40 xp_register_nofault_code_sn2(void)
46 func_addr = *(u64 *)xp_nofault_PIOR;
47 err_func_addr = *(u64 *)xp_error_PIOR;
48 ret = sn_register_nofault_code(func_addr, err_func_addr, err_func_addr,
51 dev_err(xp, "can't register nofault code, error=%d\n", ret);
55 * Setup the nofault PIO read target. (There is no special reason why
56 * SH_IPI_ACCESS was selected.)
59 xp_nofault_PIOR_target = SH1_IPI_ACCESS;
61 xp_nofault_PIOR_target = SH2_IPI_ACCESS0;
67 xp_unregister_nofault_code_sn2(void)
69 u64 func_addr = *(u64 *)xp_nofault_PIOR;
70 u64 err_func_addr = *(u64 *)xp_error_PIOR;
72 /* unregister the PIO read nofault code region */
73 (void)sn_register_nofault_code(func_addr, err_func_addr,
78 * Convert a virtual memory address to a physical memory address.
87 * Wrapper for bte_copy().
89 * dst_pa - physical address of the destination of the transfer.
90 * src_pa - physical address of the source of the transfer.
91 * len - number of bytes to transfer from source to destination.
93 * Note: xp_remote_memcpy_sn2() should never be called while holding a spinlock.
96 xp_remote_memcpy_sn2(unsigned long dst_pa, const unsigned long src_pa,
101 ret = bte_copy(src_pa, dst_pa, len, (BTE_NOTIFY | BTE_WACQUIRE), NULL);
102 if (ret == BTE_SUCCESS)
106 dev_err(xp, "bte_copy() on shub2 failed, error=0x%x dst_pa="
107 "0x%016lx src_pa=0x%016lx len=%ld\\n", ret, dst_pa,
110 dev_err(xp, "bte_copy() failed, error=%d dst_pa=0x%016lx "
111 "src_pa=0x%016lx len=%ld\\n", ret, dst_pa, src_pa, len);
114 return xpBteCopyError;
118 xp_cpu_to_nasid_sn2(int cpuid)
120 return cpuid_to_nasid(cpuid);
123 static enum xp_retval
124 xp_expand_memprotect_sn2(unsigned long phys_addr, unsigned long size)
129 ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_1,
132 dev_err(xp, "sn_change_memprotect(,, "
133 "SN_MEMPROT_ACCESS_CLASS_1,) failed ret=%d\n", ret);
139 static enum xp_retval
140 xp_restrict_memprotect_sn2(unsigned long phys_addr, unsigned long size)
145 ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_0,
148 dev_err(xp, "sn_change_memprotect(,, "
149 "SN_MEMPROT_ACCESS_CLASS_0,) failed ret=%d\n", ret);
160 xp_max_npartitions = XP_MAX_NPARTITIONS_SN2;
161 xp_partition_id = sn_partition_id;
162 xp_region_size = sn_region_size;
165 xp_remote_memcpy = xp_remote_memcpy_sn2;
166 xp_cpu_to_nasid = xp_cpu_to_nasid_sn2;
167 xp_expand_memprotect = xp_expand_memprotect_sn2;
168 xp_restrict_memprotect = xp_restrict_memprotect_sn2;
170 return xp_register_nofault_code_sn2();
178 xp_unregister_nofault_code_sn2();