152 lines · c
1/*2 * This file is subject to the terms and conditions of the GNU General Public3 * License. See the file "COPYING" in the main directory of this archive4 * for more details.5 *6 * (C) Copyright 2020 Hewlett Packard Enterprise Development LP7 * 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 17#include <linux/device.h>18#include <asm/uv/uv_hub.h>19#if defined CONFIG_X86_6420#include <asm/uv/bios.h>21#endif22#include "../sgi-gru/grukservices.h"23#include "xp.h"24 25/*26 * Convert a virtual memory address to a physical memory address.27 */28static unsigned long29xp_pa_uv(void *addr)30{31 return uv_gpa(addr);32}33 34/*35 * Convert a global physical to socket physical address.36 */37static unsigned long38xp_socket_pa_uv(unsigned long gpa)39{40 return uv_gpa_to_soc_phys_ram(gpa);41}42 43static enum xp_retval44xp_remote_mmr_read(unsigned long dst_gpa, const unsigned long src_gpa,45 size_t len)46{47 int ret;48 unsigned long *dst_va = __va(uv_gpa_to_soc_phys_ram(dst_gpa));49 50 BUG_ON(!uv_gpa_in_mmr_space(src_gpa));51 BUG_ON(len != 8);52 53 ret = gru_read_gpa(dst_va, src_gpa);54 if (ret == 0)55 return xpSuccess;56 57 dev_err(xp, "gru_read_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx "58 "len=%ld\n", dst_gpa, src_gpa, len);59 return xpGruCopyError;60}61 62 63static enum xp_retval64xp_remote_memcpy_uv(unsigned long dst_gpa, const unsigned long src_gpa,65 size_t len)66{67 int ret;68 69 if (uv_gpa_in_mmr_space(src_gpa))70 return xp_remote_mmr_read(dst_gpa, src_gpa, len);71 72 ret = gru_copy_gpa(dst_gpa, src_gpa, len);73 if (ret == 0)74 return xpSuccess;75 76 dev_err(xp, "gru_copy_gpa() failed, dst_gpa=0x%016lx src_gpa=0x%016lx "77 "len=%ld\n", dst_gpa, src_gpa, len);78 return xpGruCopyError;79}80 81static int82xp_cpu_to_nasid_uv(int cpuid)83{84 /* ??? Is this same as sn2 nasid in mach/part bitmaps set up by SAL? */85 return UV_PNODE_TO_NASID(uv_cpu_to_pnode(cpuid));86}87 88static enum xp_retval89xp_expand_memprotect_uv(unsigned long phys_addr, unsigned long size)90{91 int ret;92 93#if defined CONFIG_X86_6494 ret = uv_bios_change_memprotect(phys_addr, size, UV_MEMPROT_ALLOW_RW);95 if (ret != BIOS_STATUS_SUCCESS) {96 dev_err(xp, "uv_bios_change_memprotect(,, "97 "UV_MEMPROT_ALLOW_RW) failed, ret=%d\n", ret);98 return xpBiosError;99 }100#else101 #error not a supported configuration102#endif103 return xpSuccess;104}105 106static enum xp_retval107xp_restrict_memprotect_uv(unsigned long phys_addr, unsigned long size)108{109 int ret;110 111#if defined CONFIG_X86_64112 ret = uv_bios_change_memprotect(phys_addr, size,113 UV_MEMPROT_RESTRICT_ACCESS);114 if (ret != BIOS_STATUS_SUCCESS) {115 dev_err(xp, "uv_bios_change_memprotect(,, "116 "UV_MEMPROT_RESTRICT_ACCESS) failed, ret=%d\n", ret);117 return xpBiosError;118 }119#else120 #error not a supported configuration121#endif122 return xpSuccess;123}124 125enum xp_retval126xp_init_uv(void)127{128 WARN_ON(!is_uv_system());129 if (!is_uv_system())130 return xpUnsupported;131 132 xp_max_npartitions = XP_MAX_NPARTITIONS_UV;133#ifdef CONFIG_X86134 xp_partition_id = sn_partition_id;135 xp_region_size = sn_region_size;136#endif137 xp_pa = xp_pa_uv;138 xp_socket_pa = xp_socket_pa_uv;139 xp_remote_memcpy = xp_remote_memcpy_uv;140 xp_cpu_to_nasid = xp_cpu_to_nasid_uv;141 xp_expand_memprotect = xp_expand_memprotect_uv;142 xp_restrict_memprotect = xp_restrict_memprotect_uv;143 144 return xpSuccess;145}146 147void148xp_exit_uv(void)149{150 WARN_ON(!is_uv_system());151}152