blob: d238576b26fa9b6c8f5d96b8f41760db444d43f1 [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) uv-based functions.
11 *
12 * Architecture specific implementation of common functions.
13 *
14 */
15
Dean Nelsona812dcc2008-07-29 22:34:16 -070016#include <linux/device.h>
17#include <asm/uv/uv_hub.h>
Dean Nelson6c1c3252008-11-05 17:27:22 -060018#if defined CONFIG_X86_64
19#include <asm/uv/bios.h>
20#elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
21#include <asm/sn/sn_sal.h>
22#endif
Dean Nelsona812dcc2008-07-29 22:34:16 -070023#include "../sgi-gru/grukservices.h"
Dean Nelsonbc63d382008-07-29 22:34:04 -070024#include "xp.h"
25
Dean Nelsona812dcc2008-07-29 22:34:16 -070026/*
27 * Convert a virtual memory address to a physical memory address.
28 */
29static unsigned long
30xp_pa_uv(void *addr)
Dean Nelson908787d2008-07-29 22:34:05 -070031{
Dean Nelsona812dcc2008-07-29 22:34:16 -070032 return uv_gpa(addr);
33}
34
35static enum xp_retval
36xp_remote_memcpy_uv(unsigned long dst_gpa, const unsigned long src_gpa,
37 size_t len)
38{
39 int ret;
40
41 ret = gru_copy_gpa(dst_gpa, src_gpa, len);
42 if (ret == 0)
43 return xpSuccess;
44
45 dev_err(xp, "gru_copy_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx "
46 "len=%ld\n", dst_gpa, src_gpa, len);
47 return xpGruCopyError;
Dean Nelson908787d2008-07-29 22:34:05 -070048}
49
Dean Nelson5b8669d2008-07-29 22:34:18 -070050static int
51xp_cpu_to_nasid_uv(int cpuid)
52{
53 /* ??? Is this same as sn2 nasid in mach/part bitmaps set up by SAL? */
54 return UV_PNODE_TO_NASID(uv_cpu_to_pnode(cpuid));
55}
56
Dean Nelson6c1c3252008-11-05 17:27:22 -060057static enum xp_retval
58xp_expand_memprotect_uv(unsigned long phys_addr, unsigned long size)
59{
60 int ret;
61
62#if defined CONFIG_X86_64
63 ret = uv_bios_change_memprotect(phys_addr, size, UV_MEMPROT_ALLOW_RW);
64 if (ret != BIOS_STATUS_SUCCESS) {
65 dev_err(xp, "uv_bios_change_memprotect(,, "
66 "UV_MEMPROT_ALLOW_RW) failed, ret=%d\n", ret);
67 return xpBiosError;
68 }
69
70#elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
71 u64 nasid_array;
72
73 ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_1,
74 &nasid_array);
75 if (ret != 0) {
76 dev_err(xp, "sn_change_memprotect(,, "
77 "SN_MEMPROT_ACCESS_CLASS_1,) failed ret=%d\n", ret);
78 return xpSalError;
79 }
80#else
81 #error not a supported configuration
82#endif
83 return xpSuccess;
84}
85
86static enum xp_retval
87xp_restrict_memprotect_uv(unsigned long phys_addr, unsigned long size)
88{
89 int ret;
90
91#if defined CONFIG_X86_64
92 ret = uv_bios_change_memprotect(phys_addr, size,
93 UV_MEMPROT_RESTRICT_ACCESS);
94 if (ret != BIOS_STATUS_SUCCESS) {
95 dev_err(xp, "uv_bios_change_memprotect(,, "
96 "UV_MEMPROT_RESTRICT_ACCESS) failed, ret=%d\n", ret);
97 return xpBiosError;
98 }
99
100#elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
101 u64 nasid_array;
102
103 ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_0,
104 &nasid_array);
105 if (ret != 0) {
106 dev_err(xp, "sn_change_memprotect(,, "
107 "SN_MEMPROT_ACCESS_CLASS_0,) failed ret=%d\n", ret);
108 return xpSalError;
109 }
110#else
111 #error not a supported configuration
112#endif
113 return xpSuccess;
114}
115
Dean Nelsonbc63d382008-07-29 22:34:04 -0700116enum xp_retval
117xp_init_uv(void)
118{
119 BUG_ON(!is_uv());
120
121 xp_max_npartitions = XP_MAX_NPARTITIONS_UV;
Dean Nelson31de5ec2008-11-05 17:28:35 -0600122 xp_partition_id = sn_partition_id;
123 xp_region_size = sn_region_size;
Dean Nelson908787d2008-07-29 22:34:05 -0700124
Dean Nelsona812dcc2008-07-29 22:34:16 -0700125 xp_pa = xp_pa_uv;
Dean Nelson908787d2008-07-29 22:34:05 -0700126 xp_remote_memcpy = xp_remote_memcpy_uv;
Dean Nelson5b8669d2008-07-29 22:34:18 -0700127 xp_cpu_to_nasid = xp_cpu_to_nasid_uv;
Dean Nelson6c1c3252008-11-05 17:27:22 -0600128 xp_expand_memprotect = xp_expand_memprotect_uv;
129 xp_restrict_memprotect = xp_restrict_memprotect_uv;
Dean Nelson908787d2008-07-29 22:34:05 -0700130
131 return xpSuccess;
Dean Nelsonbc63d382008-07-29 22:34:04 -0700132}
133
134void
135xp_exit_uv(void)
136{
137 BUG_ON(!is_uv());
138}