blob: c6a1ede7d6e6a00efa89ac373240cd7031c506ad [file] [log] [blame]
Dean Nelsonbc63d382008-07-29 22:34:04 -07001/*
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
Dean Nelson261f3b42008-07-29 22:34:16 -070015#include <linux/module.h>
Dean Nelsonbc63d382008-07-29 22:34:04 -070016#include <linux/device.h>
Dean Nelson908787d2008-07-29 22:34:05 -070017#include <asm/sn/bte.h>
Dean Nelsonbc63d382008-07-29 22:34:04 -070018#include <asm/sn/sn_sal.h>
19#include "xp.h"
20
21/*
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
24 * defined here.
25 */
26EXPORT_SYMBOL_GPL(xp_nofault_PIOR);
27
28u64 xp_nofault_PIOR_target;
29EXPORT_SYMBOL_GPL(xp_nofault_PIOR_target);
30
31/*
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
Dean Nelsonc39838c2008-07-29 22:34:11 -070036 * (amo operations do not timeout on at least some CPUs on Shubs <= v1.2,
Dean Nelsonbc63d382008-07-29 22:34:04 -070037 * which unfortunately we have to work around).
38 */
39static enum xp_retval
40xp_register_nofault_code_sn2(void)
41{
42 int ret;
43 u64 func_addr;
44 u64 err_func_addr;
45
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,
49 1, 1);
50 if (ret != 0) {
51 dev_err(xp, "can't register nofault code, error=%d\n", ret);
52 return xpSalError;
53 }
54 /*
55 * Setup the nofault PIO read target. (There is no special reason why
56 * SH_IPI_ACCESS was selected.)
57 */
58 if (is_shub1())
59 xp_nofault_PIOR_target = SH1_IPI_ACCESS;
60 else if (is_shub2())
61 xp_nofault_PIOR_target = SH2_IPI_ACCESS0;
62
63 return xpSuccess;
64}
65
66void
67xp_unregister_nofault_code_sn2(void)
68{
69 u64 func_addr = *(u64 *)xp_nofault_PIOR;
70 u64 err_func_addr = *(u64 *)xp_error_PIOR;
71
72 /* unregister the PIO read nofault code region */
73 (void)sn_register_nofault_code(func_addr, err_func_addr,
74 err_func_addr, 1, 0);
75}
76
Dean Nelson908787d2008-07-29 22:34:05 -070077/*
78 * Wrapper for bte_copy().
79 *
80 * vdst - virtual address of the destination of the transfer.
81 * psrc - physical address of the source of the transfer.
82 * len - number of bytes to transfer from source to destination.
83 *
84 * Note: xp_remote_memcpy_sn2() should never be called while holding a spinlock.
85 */
86static enum xp_retval
87xp_remote_memcpy_sn2(void *vdst, const void *psrc, size_t len)
88{
89 bte_result_t ret;
90 u64 pdst = ia64_tpa(vdst);
Dean Nelsonea57f802008-07-29 22:34:14 -070091 /* ??? What are the rules governing the src and dst addresses passed in?
92 * ??? Currently we're assuming that dst is a virtual address and src
93 * ??? is a physical address, is this appropriate? Can we allow them to
94 * ??? be whatever and we make the change here without damaging the
95 * ??? addresses?
Dean Nelson908787d2008-07-29 22:34:05 -070096 */
97
98 /*
99 * Ensure that the physically mapped memory is contiguous.
100 *
101 * We do this by ensuring that the memory is from region 7 only.
102 * If the need should arise to use memory from one of the other
103 * regions, then modify the BUG_ON() statement to ensure that the
104 * memory from that region is always physically contiguous.
105 */
106 BUG_ON(REGION_NUMBER(vdst) != RGN_KERNEL);
107
108 ret = bte_copy((u64)psrc, pdst, len, (BTE_NOTIFY | BTE_WACQUIRE), NULL);
109 if (ret == BTE_SUCCESS)
110 return xpSuccess;
111
112 if (is_shub2())
113 dev_err(xp, "bte_copy() on shub2 failed, error=0x%x\n", ret);
114 else
115 dev_err(xp, "bte_copy() failed, error=%d\n", ret);
116
117 return xpBteCopyError;
118}
119
Dean Nelson261f3b42008-07-29 22:34:16 -0700120static int
121xp_cpu_to_nasid_sn2(int cpuid)
122{
123 return cpuid_to_nasid(cpuid);
124}
125
Dean Nelsonbc63d382008-07-29 22:34:04 -0700126enum xp_retval
127xp_init_sn2(void)
128{
129 BUG_ON(!is_shub());
130
131 xp_max_npartitions = XP_MAX_NPARTITIONS_SN2;
Dean Nelson261f3b42008-07-29 22:34:16 -0700132 xp_partition_id = sn_partition_id;
133 xp_region_size = sn_region_size;
Dean Nelsonbc63d382008-07-29 22:34:04 -0700134
Dean Nelson908787d2008-07-29 22:34:05 -0700135 xp_remote_memcpy = xp_remote_memcpy_sn2;
Dean Nelson261f3b42008-07-29 22:34:16 -0700136 xp_cpu_to_nasid = xp_cpu_to_nasid_sn2;
Dean Nelson908787d2008-07-29 22:34:05 -0700137
Dean Nelsonbc63d382008-07-29 22:34:04 -0700138 return xp_register_nofault_code_sn2();
139}
140
141void
142xp_exit_sn2(void)
143{
144 BUG_ON(!is_shub());
145
146 xp_unregister_nofault_code_sn2();
147}
148