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
6 * (C) Copyright 2020 Hewlett Packard Enterprise Development LP
7 * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
11 * Cross Partition (XP) uv-based functions.
13 * Architecture specific implementation of common functions.
17 #include <linux/device.h>
18 #include <asm/uv/uv_hub.h>
19 #if defined CONFIG_X86_64
20 #include <asm/uv/bios.h>
21 #elif defined CONFIG_IA64_SGI_UV
22 #include <asm/sn/sn_sal.h>
24 #include "../sgi-gru/grukservices.h"
28 * Convert a virtual memory address to a physical memory address.
37 * Convert a global physical to socket physical address.
40 xp_socket_pa_uv(unsigned long gpa
)
42 return uv_gpa_to_soc_phys_ram(gpa
);
46 xp_remote_mmr_read(unsigned long dst_gpa
, const unsigned long src_gpa
,
50 unsigned long *dst_va
= __va(uv_gpa_to_soc_phys_ram(dst_gpa
));
52 BUG_ON(!uv_gpa_in_mmr_space(src_gpa
));
55 ret
= gru_read_gpa(dst_va
, src_gpa
);
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
;
66 xp_remote_memcpy_uv(unsigned long dst_gpa
, const unsigned long src_gpa
,
71 if (uv_gpa_in_mmr_space(src_gpa
))
72 return xp_remote_mmr_read(dst_gpa
, src_gpa
, len
);
74 ret
= gru_copy_gpa(dst_gpa
, src_gpa
, len
);
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
;
84 xp_cpu_to_nasid_uv(int cpuid
)
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
));
91 xp_expand_memprotect_uv(unsigned long phys_addr
, unsigned long size
)
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
);
103 #elif defined CONFIG_IA64_SGI_UV
106 ret
= sn_change_memprotect(phys_addr
, size
, SN_MEMPROT_ACCESS_CLASS_1
,
109 dev_err(xp
, "sn_change_memprotect(,, "
110 "SN_MEMPROT_ACCESS_CLASS_1,) failed ret=%d\n", ret
);
114 #error not a supported configuration
119 static enum xp_retval
120 xp_restrict_memprotect_uv(unsigned long phys_addr
, unsigned long size
)
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
);
133 #elif defined CONFIG_IA64_SGI_UV
136 ret
= sn_change_memprotect(phys_addr
, size
, SN_MEMPROT_ACCESS_CLASS_0
,
139 dev_err(xp
, "sn_change_memprotect(,, "
140 "SN_MEMPROT_ACCESS_CLASS_0,) failed ret=%d\n", ret
);
144 #error not a supported configuration
152 WARN_ON(!is_uv_system());
154 return xpUnsupported
;
156 xp_max_npartitions
= XP_MAX_NPARTITIONS_UV
;
158 xp_partition_id
= sn_partition_id
;
159 xp_region_size
= sn_region_size
;
162 xp_socket_pa
= xp_socket_pa_uv
;
163 xp_remote_memcpy
= xp_remote_memcpy_uv
;
164 xp_cpu_to_nasid
= xp_cpu_to_nasid_uv
;
165 xp_expand_memprotect
= xp_expand_memprotect_uv
;
166 xp_restrict_memprotect
= xp_restrict_memprotect_uv
;
174 WARN_ON(!is_uv_system());