sgi-xp: create a common xp_remote_memcpy() function
[linux-2.6/mini2440.git] / drivers / misc / sgi-xp / xp_sn2.c
blob3d553fa73f4d4ef54db6a724243fbb5dfd5b77b7
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.
6 * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
7 */
9 /*
10 * Cross Partition (XP) sn2-based functions.
12 * Architecture specific implementation of common functions.
15 #include <linux/device.h>
16 #include <asm/sn/bte.h>
17 #include <asm/sn/sn_sal.h>
18 #include "xp.h"
21 * The export of xp_nofault_PIOR needs to happen here since it is defined
22 * in drivers/misc/sgi-xp/xp_nofault.S. The target of the nofault read is
23 * defined here.
25 EXPORT_SYMBOL_GPL(xp_nofault_PIOR);
27 u64 xp_nofault_PIOR_target;
28 EXPORT_SYMBOL_GPL(xp_nofault_PIOR_target);
31 * Register a nofault code region which performs a cross-partition PIO read.
32 * If the PIO read times out, the MCA handler will consume the error and
33 * return to a kernel-provided instruction to indicate an error. This PIO read
34 * exists because it is guaranteed to timeout if the destination is down
35 * (AMO operations do not timeout on at least some CPUs on Shubs <= v1.2,
36 * which unfortunately we have to work around).
38 static enum xp_retval
39 xp_register_nofault_code_sn2(void)
41 int ret;
42 u64 func_addr;
43 u64 err_func_addr;
45 func_addr = *(u64 *)xp_nofault_PIOR;
46 err_func_addr = *(u64 *)xp_error_PIOR;
47 ret = sn_register_nofault_code(func_addr, err_func_addr, err_func_addr,
48 1, 1);
49 if (ret != 0) {
50 dev_err(xp, "can't register nofault code, error=%d\n", ret);
51 return xpSalError;
54 * Setup the nofault PIO read target. (There is no special reason why
55 * SH_IPI_ACCESS was selected.)
57 if (is_shub1())
58 xp_nofault_PIOR_target = SH1_IPI_ACCESS;
59 else if (is_shub2())
60 xp_nofault_PIOR_target = SH2_IPI_ACCESS0;
62 return xpSuccess;
65 void
66 xp_unregister_nofault_code_sn2(void)
68 u64 func_addr = *(u64 *)xp_nofault_PIOR;
69 u64 err_func_addr = *(u64 *)xp_error_PIOR;
71 /* unregister the PIO read nofault code region */
72 (void)sn_register_nofault_code(func_addr, err_func_addr,
73 err_func_addr, 1, 0);
77 * Wrapper for bte_copy().
79 * vdst - virtual address of the destination of the transfer.
80 * psrc - physical address of the source of the transfer.
81 * len - number of bytes to transfer from source to destination.
83 * Note: xp_remote_memcpy_sn2() should never be called while holding a spinlock.
85 static enum xp_retval
86 xp_remote_memcpy_sn2(void *vdst, const void *psrc, size_t len)
88 bte_result_t ret;
89 u64 pdst = ia64_tpa(vdst);
90 /* >>> What are the rules governing the src and dst addresses passed in?
91 * >>> Currently we're assuming that dst is a virtual address and src
92 * >>> is a physical address, is this appropriate? Can we allow them to
93 * >>> be whatever and we make the change here without damaging the
94 * >>> addresses?
98 * Ensure that the physically mapped memory is contiguous.
100 * We do this by ensuring that the memory is from region 7 only.
101 * If the need should arise to use memory from one of the other
102 * regions, then modify the BUG_ON() statement to ensure that the
103 * memory from that region is always physically contiguous.
105 BUG_ON(REGION_NUMBER(vdst) != RGN_KERNEL);
107 ret = bte_copy((u64)psrc, pdst, len, (BTE_NOTIFY | BTE_WACQUIRE), NULL);
108 if (ret == BTE_SUCCESS)
109 return xpSuccess;
111 if (is_shub2())
112 dev_err(xp, "bte_copy() on shub2 failed, error=0x%x\n", ret);
113 else
114 dev_err(xp, "bte_copy() failed, error=%d\n", ret);
116 return xpBteCopyError;
119 enum xp_retval
120 xp_init_sn2(void)
122 BUG_ON(!is_shub());
124 xp_max_npartitions = XP_MAX_NPARTITIONS_SN2;
126 xp_remote_memcpy = xp_remote_memcpy_sn2;
128 return xp_register_nofault_code_sn2();
131 void
132 xp_exit_sn2(void)
134 BUG_ON(!is_shub());
136 xp_unregister_nofault_code_sn2();