]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/misc/sgi-xp/xp_sn2.c
1fcfdebca2c5637395d7d43e376553b022183624
[linux-2.6-omap-h63xx.git] / drivers / misc / sgi-xp / xp_sn2.c
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 /*
10  * Cross Partition (XP) sn2-based functions.
11  *
12  *      Architecture specific implementation of common functions.
13  */
14
15 #include <linux/device.h>
16 #include <asm/sn/bte.h>
17 #include <asm/sn/sn_sal.h>
18 #include "xp.h"
19
20 /*
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.
24  */
25 EXPORT_SYMBOL_GPL(xp_nofault_PIOR);
26
27 u64 xp_nofault_PIOR_target;
28 EXPORT_SYMBOL_GPL(xp_nofault_PIOR_target);
29
30 /*
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).
37  */
38 static enum xp_retval
39 xp_register_nofault_code_sn2(void)
40 {
41         int ret;
42         u64 func_addr;
43         u64 err_func_addr;
44
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;
52         }
53         /*
54          * Setup the nofault PIO read target. (There is no special reason why
55          * SH_IPI_ACCESS was selected.)
56          */
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;
61
62         return xpSuccess;
63 }
64
65 void
66 xp_unregister_nofault_code_sn2(void)
67 {
68         u64 func_addr = *(u64 *)xp_nofault_PIOR;
69         u64 err_func_addr = *(u64 *)xp_error_PIOR;
70
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);
74 }
75
76 /*
77  * Wrapper for bte_copy().
78  *
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.
82  *
83  * Note: xp_remote_memcpy_sn2() should never be called while holding a spinlock.
84  */
85 static enum xp_retval
86 xp_remote_memcpy_sn2(void *vdst, const void *psrc, size_t len)
87 {
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?
95          */
96
97         /*
98          * Ensure that the physically mapped memory is contiguous.
99          *
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.
104          */
105         BUG_ON(REGION_NUMBER(vdst) != RGN_KERNEL);
106
107         ret = bte_copy((u64)psrc, pdst, len, (BTE_NOTIFY | BTE_WACQUIRE), NULL);
108         if (ret == BTE_SUCCESS)
109                 return xpSuccess;
110
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);
115
116         return xpBteCopyError;
117 }
118
119 enum xp_retval
120 xp_init_sn2(void)
121 {
122         BUG_ON(!is_shub());
123
124         xp_max_npartitions = XP_MAX_NPARTITIONS_SN2;
125
126         xp_remote_memcpy = xp_remote_memcpy_sn2;
127
128         return xp_register_nofault_code_sn2();
129 }
130
131 void
132 xp_exit_sn2(void)
133 {
134         BUG_ON(!is_shub());
135
136         xp_unregister_nofault_code_sn2();
137 }
138