blob: 19fc7076af274f745a2c9f1f6e687071b91a5cd1 [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 *
Mike Travis7a6d94f2020-10-05 15:39:29 -05006 * (C) Copyright 2020 Hewlett Packard Enterprise Development LP
Dean Nelsonbc63d382008-07-29 22:34:04 -07007 * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
8 */
9
10/*
11 * Cross Partition (XP) uv-based functions.
12 *
13 * Architecture specific implementation of common functions.
14 *
15 */
16
Dean Nelsona812dcc2008-07-29 22:34:16 -070017#include <linux/device.h>
18#include <asm/uv/uv_hub.h>
Dean Nelson6c1c3252008-11-05 17:27:22 -060019#if defined CONFIG_X86_64
20#include <asm/uv/bios.h>
Christoph Hellwigdf410172019-08-13 09:25:12 +020021#elif defined CONFIG_IA64_SGI_UV
Dean Nelson6c1c3252008-11-05 17:27:22 -060022#include <asm/sn/sn_sal.h>
23#endif
Dean Nelsona812dcc2008-07-29 22:34:16 -070024#include "../sgi-gru/grukservices.h"
Dean Nelsonbc63d382008-07-29 22:34:04 -070025#include "xp.h"
26
Dean Nelsona812dcc2008-07-29 22:34:16 -070027/*
28 * Convert a virtual memory address to a physical memory address.
29 */
30static unsigned long
31xp_pa_uv(void *addr)
Dean Nelson908787d2008-07-29 22:34:05 -070032{
Dean Nelsona812dcc2008-07-29 22:34:16 -070033 return uv_gpa(addr);
34}
35
Robin Holt68212892009-12-15 16:47:53 -080036/*
37 * Convert a global physical to socket physical address.
38 */
39static unsigned long
40xp_socket_pa_uv(unsigned long gpa)
41{
42 return uv_gpa_to_soc_phys_ram(gpa);
43}
44
Dean Nelsona812dcc2008-07-29 22:34:16 -070045static enum xp_retval
Robin Holtc2c9f112009-12-15 16:47:56 -080046xp_remote_mmr_read(unsigned long dst_gpa, const unsigned long src_gpa,
47 size_t len)
48{
49 int ret;
50 unsigned long *dst_va = __va(uv_gpa_to_soc_phys_ram(dst_gpa));
51
52 BUG_ON(!uv_gpa_in_mmr_space(src_gpa));
53 BUG_ON(len != 8);
54
55 ret = gru_read_gpa(dst_va, src_gpa);
56 if (ret == 0)
57 return xpSuccess;
58
59 dev_err(xp, "gru_read_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx "
60 "len=%ld\n", dst_gpa, src_gpa, len);
61 return xpGruCopyError;
62}
63
64
65static enum xp_retval
Dean Nelsona812dcc2008-07-29 22:34:16 -070066xp_remote_memcpy_uv(unsigned long dst_gpa, const unsigned long src_gpa,
67 size_t len)
68{
69 int ret;
70
Robin Holtc2c9f112009-12-15 16:47:56 -080071 if (uv_gpa_in_mmr_space(src_gpa))
72 return xp_remote_mmr_read(dst_gpa, src_gpa, len);
73
Dean Nelsona812dcc2008-07-29 22:34:16 -070074 ret = gru_copy_gpa(dst_gpa, src_gpa, len);
75 if (ret == 0)
76 return xpSuccess;
77
78 dev_err(xp, "gru_copy_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx "
79 "len=%ld\n", dst_gpa, src_gpa, len);
80 return xpGruCopyError;
Dean Nelson908787d2008-07-29 22:34:05 -070081}
82
Dean Nelson5b8669d2008-07-29 22:34:18 -070083static int
84xp_cpu_to_nasid_uv(int cpuid)
85{
86 /* ??? Is this same as sn2 nasid in mach/part bitmaps set up by SAL? */
87 return UV_PNODE_TO_NASID(uv_cpu_to_pnode(cpuid));
88}
89
Dean Nelson6c1c3252008-11-05 17:27:22 -060090static enum xp_retval
91xp_expand_memprotect_uv(unsigned long phys_addr, unsigned long size)
92{
93 int ret;
94
95#if defined CONFIG_X86_64
96 ret = uv_bios_change_memprotect(phys_addr, size, UV_MEMPROT_ALLOW_RW);
97 if (ret != BIOS_STATUS_SUCCESS) {
98 dev_err(xp, "uv_bios_change_memprotect(,, "
99 "UV_MEMPROT_ALLOW_RW) failed, ret=%d\n", ret);
100 return xpBiosError;
101 }
102
Christoph Hellwigdf410172019-08-13 09:25:12 +0200103#elif defined CONFIG_IA64_SGI_UV
Dean Nelson6c1c3252008-11-05 17:27:22 -0600104 u64 nasid_array;
105
106 ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_1,
107 &nasid_array);
108 if (ret != 0) {
109 dev_err(xp, "sn_change_memprotect(,, "
110 "SN_MEMPROT_ACCESS_CLASS_1,) failed ret=%d\n", ret);
111 return xpSalError;
112 }
113#else
114 #error not a supported configuration
115#endif
116 return xpSuccess;
117}
118
119static enum xp_retval
120xp_restrict_memprotect_uv(unsigned long phys_addr, unsigned long size)
121{
122 int ret;
123
124#if defined CONFIG_X86_64
125 ret = uv_bios_change_memprotect(phys_addr, size,
126 UV_MEMPROT_RESTRICT_ACCESS);
127 if (ret != BIOS_STATUS_SUCCESS) {
128 dev_err(xp, "uv_bios_change_memprotect(,, "
129 "UV_MEMPROT_RESTRICT_ACCESS) failed, ret=%d\n", ret);
130 return xpBiosError;
131 }
132
Christoph Hellwigdf410172019-08-13 09:25:12 +0200133#elif defined CONFIG_IA64_SGI_UV
Dean Nelson6c1c3252008-11-05 17:27:22 -0600134 u64 nasid_array;
135
136 ret = sn_change_memprotect(phys_addr, size, SN_MEMPROT_ACCESS_CLASS_0,
137 &nasid_array);
138 if (ret != 0) {
139 dev_err(xp, "sn_change_memprotect(,, "
140 "SN_MEMPROT_ACCESS_CLASS_0,) failed ret=%d\n", ret);
141 return xpSalError;
142 }
143#else
144 #error not a supported configuration
145#endif
146 return xpSuccess;
147}
148
Dean Nelsonbc63d382008-07-29 22:34:04 -0700149enum xp_retval
150xp_init_uv(void)
151{
Mike Travis788b66e2020-10-06 16:34:27 -0500152 WARN_ON(!is_uv_system());
153 if (!is_uv_system())
154 return xpUnsupported;
Dean Nelsonbc63d382008-07-29 22:34:04 -0700155
156 xp_max_npartitions = XP_MAX_NPARTITIONS_UV;
Christoph Hellwig9726bfc2019-08-13 09:24:56 +0200157#ifdef CONFIG_X86
Dean Nelson31de5ec2008-11-05 17:28:35 -0600158 xp_partition_id = sn_partition_id;
159 xp_region_size = sn_region_size;
Christoph Hellwig9726bfc2019-08-13 09:24:56 +0200160#endif
Dean Nelsona812dcc2008-07-29 22:34:16 -0700161 xp_pa = xp_pa_uv;
Robin Holt68212892009-12-15 16:47:53 -0800162 xp_socket_pa = xp_socket_pa_uv;
Dean Nelson908787d2008-07-29 22:34:05 -0700163 xp_remote_memcpy = xp_remote_memcpy_uv;
Dean Nelson5b8669d2008-07-29 22:34:18 -0700164 xp_cpu_to_nasid = xp_cpu_to_nasid_uv;
Dean Nelson6c1c3252008-11-05 17:27:22 -0600165 xp_expand_memprotect = xp_expand_memprotect_uv;
166 xp_restrict_memprotect = xp_restrict_memprotect_uv;
Dean Nelson908787d2008-07-29 22:34:05 -0700167
168 return xpSuccess;
Dean Nelsonbc63d382008-07-29 22:34:04 -0700169}
170
171void
172xp_exit_uv(void)
173{
Mike Travis788b66e2020-10-06 16:34:27 -0500174 WARN_ON(!is_uv_system());
Dean Nelsonbc63d382008-07-29 22:34:04 -0700175}