Dean Nelson | bc63d38 | 2008-07-29 22:34:04 -0700 | [diff] [blame] | 1 | /* |
| 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 Travis | 7a6d94f | 2020-10-05 15:39:29 -0500 | [diff] [blame] | 6 | * (C) Copyright 2020 Hewlett Packard Enterprise Development LP |
Dean Nelson | bc63d38 | 2008-07-29 22:34:04 -0700 | [diff] [blame] | 7 | * 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 Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 17 | #include <linux/device.h> |
| 18 | #include <asm/uv/uv_hub.h> |
Dean Nelson | 6c1c325 | 2008-11-05 17:27:22 -0600 | [diff] [blame] | 19 | #if defined CONFIG_X86_64 |
| 20 | #include <asm/uv/bios.h> |
Christoph Hellwig | df41017 | 2019-08-13 09:25:12 +0200 | [diff] [blame] | 21 | #elif defined CONFIG_IA64_SGI_UV |
Dean Nelson | 6c1c325 | 2008-11-05 17:27:22 -0600 | [diff] [blame] | 22 | #include <asm/sn/sn_sal.h> |
| 23 | #endif |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 24 | #include "../sgi-gru/grukservices.h" |
Dean Nelson | bc63d38 | 2008-07-29 22:34:04 -0700 | [diff] [blame] | 25 | #include "xp.h" |
| 26 | |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 27 | /* |
| 28 | * Convert a virtual memory address to a physical memory address. |
| 29 | */ |
| 30 | static unsigned long |
| 31 | xp_pa_uv(void *addr) |
Dean Nelson | 908787d | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 32 | { |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 33 | return uv_gpa(addr); |
| 34 | } |
| 35 | |
Robin Holt | 6821289 | 2009-12-15 16:47:53 -0800 | [diff] [blame] | 36 | /* |
| 37 | * Convert a global physical to socket physical address. |
| 38 | */ |
| 39 | static unsigned long |
| 40 | xp_socket_pa_uv(unsigned long gpa) |
| 41 | { |
| 42 | return uv_gpa_to_soc_phys_ram(gpa); |
| 43 | } |
| 44 | |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 45 | static enum xp_retval |
Robin Holt | c2c9f11 | 2009-12-15 16:47:56 -0800 | [diff] [blame] | 46 | xp_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 | |
| 65 | static enum xp_retval |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 66 | xp_remote_memcpy_uv(unsigned long dst_gpa, const unsigned long src_gpa, |
| 67 | size_t len) |
| 68 | { |
| 69 | int ret; |
| 70 | |
Robin Holt | c2c9f11 | 2009-12-15 16:47:56 -0800 | [diff] [blame] | 71 | if (uv_gpa_in_mmr_space(src_gpa)) |
| 72 | return xp_remote_mmr_read(dst_gpa, src_gpa, len); |
| 73 | |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 74 | 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 Nelson | 908787d | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 83 | static int |
| 84 | xp_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 Nelson | 6c1c325 | 2008-11-05 17:27:22 -0600 | [diff] [blame] | 90 | static enum xp_retval |
| 91 | xp_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 Hellwig | df41017 | 2019-08-13 09:25:12 +0200 | [diff] [blame] | 103 | #elif defined CONFIG_IA64_SGI_UV |
Dean Nelson | 6c1c325 | 2008-11-05 17:27:22 -0600 | [diff] [blame] | 104 | 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 | |
| 119 | static enum xp_retval |
| 120 | xp_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 Hellwig | df41017 | 2019-08-13 09:25:12 +0200 | [diff] [blame] | 133 | #elif defined CONFIG_IA64_SGI_UV |
Dean Nelson | 6c1c325 | 2008-11-05 17:27:22 -0600 | [diff] [blame] | 134 | 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 Nelson | bc63d38 | 2008-07-29 22:34:04 -0700 | [diff] [blame] | 149 | enum xp_retval |
| 150 | xp_init_uv(void) |
| 151 | { |
Mike Travis | 788b66e | 2020-10-06 16:34:27 -0500 | [diff] [blame] | 152 | WARN_ON(!is_uv_system()); |
| 153 | if (!is_uv_system()) |
| 154 | return xpUnsupported; |
Dean Nelson | bc63d38 | 2008-07-29 22:34:04 -0700 | [diff] [blame] | 155 | |
| 156 | xp_max_npartitions = XP_MAX_NPARTITIONS_UV; |
Christoph Hellwig | 9726bfc | 2019-08-13 09:24:56 +0200 | [diff] [blame] | 157 | #ifdef CONFIG_X86 |
Dean Nelson | 31de5ec | 2008-11-05 17:28:35 -0600 | [diff] [blame] | 158 | xp_partition_id = sn_partition_id; |
| 159 | xp_region_size = sn_region_size; |
Christoph Hellwig | 9726bfc | 2019-08-13 09:24:56 +0200 | [diff] [blame] | 160 | #endif |
Dean Nelson | a812dcc | 2008-07-29 22:34:16 -0700 | [diff] [blame] | 161 | xp_pa = xp_pa_uv; |
Robin Holt | 6821289 | 2009-12-15 16:47:53 -0800 | [diff] [blame] | 162 | xp_socket_pa = xp_socket_pa_uv; |
Dean Nelson | 908787d | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 163 | xp_remote_memcpy = xp_remote_memcpy_uv; |
Dean Nelson | 5b8669d | 2008-07-29 22:34:18 -0700 | [diff] [blame] | 164 | xp_cpu_to_nasid = xp_cpu_to_nasid_uv; |
Dean Nelson | 6c1c325 | 2008-11-05 17:27:22 -0600 | [diff] [blame] | 165 | xp_expand_memprotect = xp_expand_memprotect_uv; |
| 166 | xp_restrict_memprotect = xp_restrict_memprotect_uv; |
Dean Nelson | 908787d | 2008-07-29 22:34:05 -0700 | [diff] [blame] | 167 | |
| 168 | return xpSuccess; |
Dean Nelson | bc63d38 | 2008-07-29 22:34:04 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void |
| 172 | xp_exit_uv(void) |
| 173 | { |
Mike Travis | 788b66e | 2020-10-06 16:34:27 -0500 | [diff] [blame] | 174 | WARN_ON(!is_uv_system()); |
Dean Nelson | bc63d38 | 2008-07-29 22:34:04 -0700 | [diff] [blame] | 175 | } |