1bb898558SAl Viro /* 2bb898558SAl Viro * This file is subject to the terms and conditions of the GNU General Public 3bb898558SAl Viro * License. See the file "COPYING" in the main directory of this archive 4bb898558SAl Viro * for more details. 5bb898558SAl Viro * 6bb898558SAl Viro * SGI UV architectural definitions 7bb898558SAl Viro * 85f40f7d9SDimitri Sivanich * Copyright (C) 2007-2014 Silicon Graphics, Inc. All rights reserved. 9bb898558SAl Viro */ 10bb898558SAl Viro 1105e4d316SH. Peter Anvin #ifndef _ASM_X86_UV_UV_HUB_H 1205e4d316SH. Peter Anvin #define _ASM_X86_UV_UV_HUB_H 13bb898558SAl Viro 14bc5d9940SJack Steiner #ifdef CONFIG_X86_64 15bb898558SAl Viro #include <linux/numa.h> 16bb898558SAl Viro #include <linux/percpu.h> 17c08b6accSMike Travis #include <linux/timer.h> 188dc579e8SJack Steiner #include <linux/io.h> 19bb898558SAl Viro #include <asm/types.h> 20bb898558SAl Viro #include <asm/percpu.h> 2166666e50SJack Steiner #include <asm/uv/uv_mmrs.h> 2202dd0a06SRobin Holt #include <asm/irq_vectors.h> 2302dd0a06SRobin Holt #include <asm/io_apic.h> 24bb898558SAl Viro 25bb898558SAl Viro 26bb898558SAl Viro /* 27bb898558SAl Viro * Addressing Terminology 28bb898558SAl Viro * 29bb898558SAl Viro * M - The low M bits of a physical address represent the offset 30bb898558SAl Viro * into the blade local memory. RAM memory on a blade is physically 31bb898558SAl Viro * contiguous (although various IO spaces may punch holes in 32bb898558SAl Viro * it).. 33bb898558SAl Viro * 34bb898558SAl Viro * N - Number of bits in the node portion of a socket physical 35bb898558SAl Viro * address. 36bb898558SAl Viro * 37bb898558SAl Viro * NASID - network ID of a router, Mbrick or Cbrick. Nasid values of 38bb898558SAl Viro * routers always have low bit of 1, C/MBricks have low bit 39bb898558SAl Viro * equal to 0. Most addressing macros that target UV hub chips 40bb898558SAl Viro * right shift the NASID by 1 to exclude the always-zero bit. 41bb898558SAl Viro * NASIDs contain up to 15 bits. 42bb898558SAl Viro * 43bb898558SAl Viro * GNODE - NASID right shifted by 1 bit. Most mmrs contain gnodes instead 44bb898558SAl Viro * of nasids. 45bb898558SAl Viro * 46bb898558SAl Viro * PNODE - the low N bits of the GNODE. The PNODE is the most useful variant 47bb898558SAl Viro * of the nasid for socket usage. 48bb898558SAl Viro * 496a469e46SJack Steiner * GPA - (global physical address) a socket physical address converted 506a469e46SJack Steiner * so that it can be used by the GRU as a global address. Socket 516a469e46SJack Steiner * physical addresses 1) need additional NASID (node) bits added 526a469e46SJack Steiner * to the high end of the address, and 2) unaliased if the 536a469e46SJack Steiner * partition does not have a physical address 0. In addition, on 546a469e46SJack Steiner * UV2 rev 1, GPAs need the gnode left shifted to bits 39 or 40. 556a469e46SJack Steiner * 56bb898558SAl Viro * 57bb898558SAl Viro * NumaLink Global Physical Address Format: 58bb898558SAl Viro * +--------------------------------+---------------------+ 59bb898558SAl Viro * |00..000| GNODE | NodeOffset | 60bb898558SAl Viro * +--------------------------------+---------------------+ 61bb898558SAl Viro * |<-------53 - M bits --->|<--------M bits -----> 62bb898558SAl Viro * 63bb898558SAl Viro * M - number of node offset bits (35 .. 40) 64bb898558SAl Viro * 65bb898558SAl Viro * 66bb898558SAl Viro * Memory/UV-HUB Processor Socket Address Format: 67bb898558SAl Viro * +----------------+---------------+---------------------+ 68bb898558SAl Viro * |00..000000000000| PNODE | NodeOffset | 69bb898558SAl Viro * +----------------+---------------+---------------------+ 70bb898558SAl Viro * <--- N bits --->|<--------M bits -----> 71bb898558SAl Viro * 72bb898558SAl Viro * M - number of node offset bits (35 .. 40) 73bb898558SAl Viro * N - number of PNODE bits (0 .. 10) 74bb898558SAl Viro * 75bb898558SAl Viro * Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64). 76bb898558SAl Viro * The actual values are configuration dependent and are set at 77bb898558SAl Viro * boot time. M & N values are set by the hardware/BIOS at boot. 78bb898558SAl Viro * 79bb898558SAl Viro * 80bb898558SAl Viro * APICID format 81bb898558SAl Viro * NOTE!!!!!! This is the current format of the APICID. However, code 82bb898558SAl Viro * should assume that this will change in the future. Use functions 83bb898558SAl Viro * in this file for all APICID bit manipulations and conversion. 84bb898558SAl Viro * 85bb898558SAl Viro * 1111110000000000 86bb898558SAl Viro * 5432109876543210 872a919596SJack Steiner * pppppppppplc0cch Nehalem-EX (12 bits in hdw reg) 882a919596SJack Steiner * ppppppppplcc0cch Westmere-EX (12 bits in hdw reg) 892a919596SJack Steiner * pppppppppppcccch SandyBridge (15 bits in hdw reg) 90bb898558SAl Viro * sssssssssss 91bb898558SAl Viro * 92bb898558SAl Viro * p = pnode bits 93bb898558SAl Viro * l = socket number on board 94bb898558SAl Viro * c = core 95bb898558SAl Viro * h = hyperthread 96bb898558SAl Viro * s = bits that are in the SOCKET_ID CSR 97bb898558SAl Viro * 982a919596SJack Steiner * Note: Processor may support fewer bits in the APICID register. The ACPI 99bb898558SAl Viro * tables hold all 16 bits. Software needs to be aware of this. 100bb898558SAl Viro * 101bb898558SAl Viro * Unless otherwise specified, all references to APICID refer to 102bb898558SAl Viro * the FULL value contained in ACPI tables, not the subset in the 103bb898558SAl Viro * processor APICID register. 104bb898558SAl Viro */ 105bb898558SAl Viro 106bb898558SAl Viro 107bb898558SAl Viro /* 108bb898558SAl Viro * Maximum number of bricks in all partitions and in all coherency domains. 109bb898558SAl Viro * This is the total number of bricks accessible in the numalink fabric. It 110bb898558SAl Viro * includes all C & M bricks. Routers are NOT included. 111bb898558SAl Viro * 112bb898558SAl Viro * This value is also the value of the maximum number of non-router NASIDs 113bb898558SAl Viro * in the numalink fabric. 114bb898558SAl Viro * 115bb898558SAl Viro * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused. 116bb898558SAl Viro */ 117bb898558SAl Viro #define UV_MAX_NUMALINK_BLADES 16384 118bb898558SAl Viro 119bb898558SAl Viro /* 120bb898558SAl Viro * Maximum number of C/Mbricks within a software SSI (hardware may support 121bb898558SAl Viro * more). 122bb898558SAl Viro */ 123bb898558SAl Viro #define UV_MAX_SSI_BLADES 256 124bb898558SAl Viro 125bb898558SAl Viro /* 126bb898558SAl Viro * The largest possible NASID of a C or M brick (+ 2) 127bb898558SAl Viro */ 1281d21e6e3SRobin Holt #define UV_MAX_NASID_VALUE (UV_MAX_NUMALINK_BLADES * 2) 129bb898558SAl Viro 1307f1baa06SMike Travis struct uv_scir_s { 1317f1baa06SMike Travis struct timer_list timer; 1327f1baa06SMike Travis unsigned long offset; 1337f1baa06SMike Travis unsigned long last; 1347f1baa06SMike Travis unsigned long idle_on; 1357f1baa06SMike Travis unsigned long idle_off; 1367f1baa06SMike Travis unsigned char state; 1377f1baa06SMike Travis unsigned char enabled; 1387f1baa06SMike Travis }; 1397f1baa06SMike Travis 140bb898558SAl Viro /* 141bb898558SAl Viro * The following defines attributes of the HUB chip. These attributes are 1420045ddd2SMike Travis * frequently referenced and are kept in a common per hub struct. 1430045ddd2SMike Travis * After setup, the struct is read only, so it should be readily 1440045ddd2SMike Travis * available in the L3 cache on the cpu socket for the node. 145bb898558SAl Viro */ 146bb898558SAl Viro struct uv_hub_info_s { 147bb898558SAl Viro unsigned long global_mmr_base; 148bb898558SAl Viro unsigned long gpa_mask; 149c4ed3f04SJack Steiner unsigned int gnode_extra; 1502a919596SJack Steiner unsigned char hub_revision; 1512a919596SJack Steiner unsigned char apic_pnode_shift; 1526a469e46SJack Steiner unsigned char m_shift; 1536a469e46SJack Steiner unsigned char n_lshift; 154bb898558SAl Viro unsigned long gnode_upper; 155bb898558SAl Viro unsigned long lowmem_remap_top; 156bb898558SAl Viro unsigned long lowmem_remap_base; 157bb898558SAl Viro unsigned short pnode; 158bb898558SAl Viro unsigned short pnode_mask; 159bb898558SAl Viro unsigned short coherency_domain_number; 160bb898558SAl Viro unsigned short numa_blade_id; 161bb898558SAl Viro unsigned char blade_processor_id; 162bb898558SAl Viro unsigned char m_val; 163bb898558SAl Viro unsigned char n_val; 1647f1baa06SMike Travis struct uv_scir_s scir; 165bb898558SAl Viro }; 1667f1baa06SMike Travis 167bb898558SAl Viro DECLARE_PER_CPU(struct uv_hub_info_s, __uv_hub_info); 16889cbc767SChristoph Lameter #define uv_hub_info this_cpu_ptr(&__uv_hub_info) 169bb898558SAl Viro #define uv_cpu_hub_info(cpu) (&per_cpu(__uv_hub_info, cpu)) 170bb898558SAl Viro 1710045ddd2SMike Travis /* CPU specific info with a pointer to the hub common info struct */ 1720045ddd2SMike Travis struct uv_cpu_info_s { 1730045ddd2SMike Travis void *p_uv_hub_info; 1740045ddd2SMike Travis unsigned char blade_cpu_id; 1750045ddd2SMike Travis struct uv_scir_s scir; 1760045ddd2SMike Travis }; 1770045ddd2SMike Travis DECLARE_PER_CPU(struct uv_cpu_info_s, __uv_cpu_info); 1780045ddd2SMike Travis 1790045ddd2SMike Travis #define uv_cpu_info this_cpu_ptr(&__uv_cpu_info) 1800045ddd2SMike Travis #define uv_cpu_info_per(cpu) (&per_cpu(__uv_cpu_info, cpu)) 1810045ddd2SMike Travis 1822a919596SJack Steiner /* 1830045ddd2SMike Travis * HUB revision ranges for each UV HUB architecture. 1842a919596SJack Steiner * This is a software convention - NOT the hardware revision numbers in 1852a919596SJack Steiner * the hub chip. 1862a919596SJack Steiner */ 1872a919596SJack Steiner #define UV1_HUB_REVISION_BASE 1 1882a919596SJack Steiner #define UV2_HUB_REVISION_BASE 3 1896edbd471SMike Travis #define UV3_HUB_REVISION_BASE 5 190eb1e3461SMike Travis #define UV4_HUB_REVISION_BASE 7 1912a919596SJack Steiner 192e0ee1c97SMike Travis #ifdef UV1_HUB_IS_SUPPORTED 1932a919596SJack Steiner static inline int is_uv1_hub(void) 1942a919596SJack Steiner { 1952a919596SJack Steiner return uv_hub_info->hub_revision < UV2_HUB_REVISION_BASE; 1962a919596SJack Steiner } 197e0ee1c97SMike Travis #else 198e0ee1c97SMike Travis static inline int is_uv1_hub(void) 199e0ee1c97SMike Travis { 200e0ee1c97SMike Travis return 0; 201e0ee1c97SMike Travis } 202e0ee1c97SMike Travis #endif 2032a919596SJack Steiner 204e0ee1c97SMike Travis #ifdef UV2_HUB_IS_SUPPORTED 2052a919596SJack Steiner static inline int is_uv2_hub(void) 2062a919596SJack Steiner { 2076edbd471SMike Travis return ((uv_hub_info->hub_revision >= UV2_HUB_REVISION_BASE) && 2086edbd471SMike Travis (uv_hub_info->hub_revision < UV3_HUB_REVISION_BASE)); 2096edbd471SMike Travis } 210e0ee1c97SMike Travis #else 211e0ee1c97SMike Travis static inline int is_uv2_hub(void) 212e0ee1c97SMike Travis { 213e0ee1c97SMike Travis return 0; 214e0ee1c97SMike Travis } 215e0ee1c97SMike Travis #endif 2166edbd471SMike Travis 217e0ee1c97SMike Travis #ifdef UV3_HUB_IS_SUPPORTED 2186edbd471SMike Travis static inline int is_uv3_hub(void) 2196edbd471SMike Travis { 220eb1e3461SMike Travis return ((uv_hub_info->hub_revision >= UV3_HUB_REVISION_BASE) && 221eb1e3461SMike Travis (uv_hub_info->hub_revision < UV4_HUB_REVISION_BASE)); 2226edbd471SMike Travis } 223e0ee1c97SMike Travis #else 224e0ee1c97SMike Travis static inline int is_uv3_hub(void) 225e0ee1c97SMike Travis { 226e0ee1c97SMike Travis return 0; 227e0ee1c97SMike Travis } 228e0ee1c97SMike Travis #endif 2296edbd471SMike Travis 230eb1e3461SMike Travis #ifdef UV4_HUB_IS_SUPPORTED 231eb1e3461SMike Travis static inline int is_uv4_hub(void) 232eb1e3461SMike Travis { 233eb1e3461SMike Travis return uv_hub_info->hub_revision >= UV4_HUB_REVISION_BASE; 234eb1e3461SMike Travis } 235eb1e3461SMike Travis #else 236eb1e3461SMike Travis static inline int is_uv4_hub(void) 237eb1e3461SMike Travis { 238eb1e3461SMike Travis return 0; 239eb1e3461SMike Travis } 240eb1e3461SMike Travis #endif 241eb1e3461SMike Travis 2426edbd471SMike Travis static inline int is_uvx_hub(void) 2436edbd471SMike Travis { 244e0ee1c97SMike Travis if (uv_hub_info->hub_revision >= UV2_HUB_REVISION_BASE) 245e0ee1c97SMike Travis return uv_hub_info->hub_revision; 246e0ee1c97SMike Travis 247e0ee1c97SMike Travis return 0; 248e0ee1c97SMike Travis } 249e0ee1c97SMike Travis 250e0ee1c97SMike Travis static inline int is_uv_hub(void) 251e0ee1c97SMike Travis { 252e0ee1c97SMike Travis #ifdef UV1_HUB_IS_SUPPORTED 253e0ee1c97SMike Travis return uv_hub_info->hub_revision; 254e0ee1c97SMike Travis #endif 255e0ee1c97SMike Travis return is_uvx_hub(); 2562a919596SJack Steiner } 2572a919596SJack Steiner 258c8f730b1SRuss Anderson union uvh_apicid { 259c8f730b1SRuss Anderson unsigned long v; 260c8f730b1SRuss Anderson struct uvh_apicid_s { 261c8f730b1SRuss Anderson unsigned long local_apic_mask : 24; 262c8f730b1SRuss Anderson unsigned long local_apic_shift : 5; 263c8f730b1SRuss Anderson unsigned long unused1 : 3; 264c8f730b1SRuss Anderson unsigned long pnode_mask : 24; 265c8f730b1SRuss Anderson unsigned long pnode_shift : 5; 266c8f730b1SRuss Anderson unsigned long unused2 : 3; 267c8f730b1SRuss Anderson } s; 268c8f730b1SRuss Anderson }; 269c8f730b1SRuss Anderson 270bb898558SAl Viro /* 271bb898558SAl Viro * Local & Global MMR space macros. 272bb898558SAl Viro * Note: macros are intended to be used ONLY by inline functions 273bb898558SAl Viro * in this file - not by other kernel code. 274bb898558SAl Viro * n - NASID (full 15-bit global nasid) 275bb898558SAl Viro * g - GNODE (full 15-bit global nasid, right shifted 1) 276bb898558SAl Viro * p - PNODE (local part of nsids, right shifted 1) 277bb898558SAl Viro */ 278bb898558SAl Viro #define UV_NASID_TO_PNODE(n) (((n) >> 1) & uv_hub_info->pnode_mask) 279c4ed3f04SJack Steiner #define UV_PNODE_TO_GNODE(p) ((p) |uv_hub_info->gnode_extra) 280c4ed3f04SJack Steiner #define UV_PNODE_TO_NASID(p) (UV_PNODE_TO_GNODE(p) << 1) 281bb898558SAl Viro 2822a919596SJack Steiner #define UV1_LOCAL_MMR_BASE 0xf4000000UL 2832a919596SJack Steiner #define UV1_GLOBAL_MMR32_BASE 0xf8000000UL 2842a919596SJack Steiner #define UV1_LOCAL_MMR_SIZE (64UL * 1024 * 1024) 2852a919596SJack Steiner #define UV1_GLOBAL_MMR32_SIZE (64UL * 1024 * 1024) 2862a919596SJack Steiner 2872a919596SJack Steiner #define UV2_LOCAL_MMR_BASE 0xfa000000UL 2882a919596SJack Steiner #define UV2_GLOBAL_MMR32_BASE 0xfc000000UL 2892a919596SJack Steiner #define UV2_LOCAL_MMR_SIZE (32UL * 1024 * 1024) 2902a919596SJack Steiner #define UV2_GLOBAL_MMR32_SIZE (32UL * 1024 * 1024) 2912a919596SJack Steiner 2926edbd471SMike Travis #define UV3_LOCAL_MMR_BASE 0xfa000000UL 2936edbd471SMike Travis #define UV3_GLOBAL_MMR32_BASE 0xfc000000UL 2946edbd471SMike Travis #define UV3_LOCAL_MMR_SIZE (32UL * 1024 * 1024) 2956edbd471SMike Travis #define UV3_GLOBAL_MMR32_SIZE (32UL * 1024 * 1024) 2966edbd471SMike Travis 297eb1e3461SMike Travis #define UV4_LOCAL_MMR_BASE 0xfa000000UL 298eb1e3461SMike Travis #define UV4_GLOBAL_MMR32_BASE 0xfc000000UL 299eb1e3461SMike Travis #define UV4_LOCAL_MMR_SIZE (32UL * 1024 * 1024) 300eb1e3461SMike Travis #define UV4_GLOBAL_MMR32_SIZE (16UL * 1024 * 1024) 301eb1e3461SMike Travis 302eb1e3461SMike Travis #define UV_LOCAL_MMR_BASE ( \ 303eb1e3461SMike Travis is_uv1_hub() ? UV1_LOCAL_MMR_BASE : \ 304eb1e3461SMike Travis is_uv2_hub() ? UV2_LOCAL_MMR_BASE : \ 305eb1e3461SMike Travis is_uv3_hub() ? UV3_LOCAL_MMR_BASE : \ 306eb1e3461SMike Travis /*is_uv4_hub*/ UV4_LOCAL_MMR_BASE) 307eb1e3461SMike Travis 308eb1e3461SMike Travis #define UV_GLOBAL_MMR32_BASE ( \ 309eb1e3461SMike Travis is_uv1_hub() ? UV1_GLOBAL_MMR32_BASE : \ 310eb1e3461SMike Travis is_uv2_hub() ? UV2_GLOBAL_MMR32_BASE : \ 311eb1e3461SMike Travis is_uv3_hub() ? UV3_GLOBAL_MMR32_BASE : \ 312eb1e3461SMike Travis /*is_uv4_hub*/ UV4_GLOBAL_MMR32_BASE) 313eb1e3461SMike Travis 314eb1e3461SMike Travis #define UV_LOCAL_MMR_SIZE ( \ 315eb1e3461SMike Travis is_uv1_hub() ? UV1_LOCAL_MMR_SIZE : \ 316eb1e3461SMike Travis is_uv2_hub() ? UV2_LOCAL_MMR_SIZE : \ 317eb1e3461SMike Travis is_uv3_hub() ? UV3_LOCAL_MMR_SIZE : \ 318eb1e3461SMike Travis /*is_uv4_hub*/ UV4_LOCAL_MMR_SIZE) 319eb1e3461SMike Travis 320eb1e3461SMike Travis #define UV_GLOBAL_MMR32_SIZE ( \ 321eb1e3461SMike Travis is_uv1_hub() ? UV1_GLOBAL_MMR32_SIZE : \ 322eb1e3461SMike Travis is_uv2_hub() ? UV2_GLOBAL_MMR32_SIZE : \ 323eb1e3461SMike Travis is_uv3_hub() ? UV3_GLOBAL_MMR32_SIZE : \ 324eb1e3461SMike Travis /*is_uv4_hub*/ UV4_GLOBAL_MMR32_SIZE) 325eb1e3461SMike Travis 326bb898558SAl Viro #define UV_GLOBAL_MMR64_BASE (uv_hub_info->global_mmr_base) 327bb898558SAl Viro 32856abcf24SJack Steiner #define UV_GLOBAL_GRU_MMR_BASE 0x4000000 32956abcf24SJack Steiner 330bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_SHIFT 15 331bb898558SAl Viro #define UV_GLOBAL_MMR64_PNODE_SHIFT 26 332bb898558SAl Viro 333bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_BITS(p) ((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT)) 334bb898558SAl Viro 335bb898558SAl Viro #define UV_GLOBAL_MMR64_PNODE_BITS(p) \ 33667e83f30SJack Steiner (((unsigned long)(p)) << UV_GLOBAL_MMR64_PNODE_SHIFT) 337bb898558SAl Viro 338c8f730b1SRuss Anderson #define UVH_APICID 0x002D0E00L 339bb898558SAl Viro #define UV_APIC_PNODE_SHIFT 6 340bb898558SAl Viro 3418191c9f6SDimitri Sivanich #define UV_APICID_HIBIT_MASK 0xffff0000 3428191c9f6SDimitri Sivanich 3437f1baa06SMike Travis /* Local Bus from cpu's perspective */ 3447f1baa06SMike Travis #define LOCAL_BUS_BASE 0x1c00000 3457f1baa06SMike Travis #define LOCAL_BUS_SIZE (4 * 1024 * 1024) 3467f1baa06SMike Travis 3477f1baa06SMike Travis /* 3487f1baa06SMike Travis * System Controller Interface Reg 3497f1baa06SMike Travis * 3507f1baa06SMike Travis * Note there are NO leds on a UV system. This register is only 3517f1baa06SMike Travis * used by the system controller to monitor system-wide operation. 3527f1baa06SMike Travis * There are 64 regs per node. With Nahelem cpus (2 cores per node, 3537f1baa06SMike Travis * 8 cpus per core, 2 threads per cpu) there are 32 cpu threads on 3547f1baa06SMike Travis * a node. 3557f1baa06SMike Travis * 3567f1baa06SMike Travis * The window is located at top of ACPI MMR space 3577f1baa06SMike Travis */ 3587f1baa06SMike Travis #define SCIR_WINDOW_COUNT 64 3597f1baa06SMike Travis #define SCIR_LOCAL_MMR_BASE (LOCAL_BUS_BASE + \ 3607f1baa06SMike Travis LOCAL_BUS_SIZE - \ 3617f1baa06SMike Travis SCIR_WINDOW_COUNT) 3627f1baa06SMike Travis 3637f1baa06SMike Travis #define SCIR_CPU_HEARTBEAT 0x01 /* timer interrupt */ 3647f1baa06SMike Travis #define SCIR_CPU_ACTIVITY 0x02 /* not idle */ 3657f1baa06SMike Travis #define SCIR_CPU_HB_INTERVAL (HZ) /* once per second */ 3667f1baa06SMike Travis 3678661984fSDimitri Sivanich /* Loop through all installed blades */ 3688661984fSDimitri Sivanich #define for_each_possible_blade(bid) \ 3698661984fSDimitri Sivanich for ((bid) = 0; (bid) < uv_num_possible_blades(); (bid)++) 3708661984fSDimitri Sivanich 371bb898558SAl Viro /* 372bb898558SAl Viro * Macros for converting between kernel virtual addresses, socket local physical 373bb898558SAl Viro * addresses, and UV global physical addresses. 374bb898558SAl Viro * Note: use the standard __pa() & __va() macros for converting 375bb898558SAl Viro * between socket virtual and socket physical addresses. 376bb898558SAl Viro */ 377bb898558SAl Viro 378bb898558SAl Viro /* socket phys RAM --> UV global physical address */ 379bb898558SAl Viro static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr) 380bb898558SAl Viro { 381bb898558SAl Viro if (paddr < uv_hub_info->lowmem_remap_top) 382189f67c4SJack Steiner paddr |= uv_hub_info->lowmem_remap_base; 3836a469e46SJack Steiner paddr |= uv_hub_info->gnode_upper; 3846a469e46SJack Steiner paddr = ((paddr << uv_hub_info->m_shift) >> uv_hub_info->m_shift) | 3856a469e46SJack Steiner ((paddr >> uv_hub_info->m_val) << uv_hub_info->n_lshift); 3866a469e46SJack Steiner return paddr; 387bb898558SAl Viro } 388bb898558SAl Viro 389bb898558SAl Viro 390bb898558SAl Viro /* socket virtual --> UV global physical address */ 391bb898558SAl Viro static inline unsigned long uv_gpa(void *v) 392bb898558SAl Viro { 393189f67c4SJack Steiner return uv_soc_phys_ram_to_gpa(__pa(v)); 394bb898558SAl Viro } 395bb898558SAl Viro 396fae419f2SRobin Holt /* Top two bits indicate the requested address is in MMR space. */ 397fae419f2SRobin Holt static inline int 398fae419f2SRobin Holt uv_gpa_in_mmr_space(unsigned long gpa) 399fae419f2SRobin Holt { 400fae419f2SRobin Holt return (gpa >> 62) == 0x3UL; 401fae419f2SRobin Holt } 402fae419f2SRobin Holt 403729d69e6SRobin Holt /* UV global physical address --> socket phys RAM */ 404729d69e6SRobin Holt static inline unsigned long uv_gpa_to_soc_phys_ram(unsigned long gpa) 405729d69e6SRobin Holt { 4065a51467bSRuss Anderson unsigned long paddr; 407729d69e6SRobin Holt unsigned long remap_base = uv_hub_info->lowmem_remap_base; 408729d69e6SRobin Holt unsigned long remap_top = uv_hub_info->lowmem_remap_top; 409729d69e6SRobin Holt 4106a469e46SJack Steiner gpa = ((gpa << uv_hub_info->m_shift) >> uv_hub_info->m_shift) | 4116a469e46SJack Steiner ((gpa >> uv_hub_info->n_lshift) << uv_hub_info->m_val); 4125a51467bSRuss Anderson paddr = gpa & uv_hub_info->gpa_mask; 413729d69e6SRobin Holt if (paddr >= remap_base && paddr < remap_base + remap_top) 414729d69e6SRobin Holt paddr -= remap_base; 415729d69e6SRobin Holt return paddr; 416729d69e6SRobin Holt } 417729d69e6SRobin Holt 418729d69e6SRobin Holt 4196a469e46SJack Steiner /* gpa -> pnode */ 4201d21e6e3SRobin Holt static inline unsigned long uv_gpa_to_gnode(unsigned long gpa) 4211d21e6e3SRobin Holt { 4226a469e46SJack Steiner return gpa >> uv_hub_info->n_lshift; 4231d21e6e3SRobin Holt } 4241d21e6e3SRobin Holt 4251d21e6e3SRobin Holt /* gpa -> pnode */ 4261d21e6e3SRobin Holt static inline int uv_gpa_to_pnode(unsigned long gpa) 4271d21e6e3SRobin Holt { 4281d21e6e3SRobin Holt unsigned long n_mask = (1UL << uv_hub_info->n_val) - 1; 4291d21e6e3SRobin Holt 4301d21e6e3SRobin Holt return uv_gpa_to_gnode(gpa) & n_mask; 4311d21e6e3SRobin Holt } 4321d21e6e3SRobin Holt 4336a469e46SJack Steiner /* gpa -> node offset*/ 4346a469e46SJack Steiner static inline unsigned long uv_gpa_to_offset(unsigned long gpa) 4356a469e46SJack Steiner { 4366a469e46SJack Steiner return (gpa << uv_hub_info->m_shift) >> uv_hub_info->m_shift; 4376a469e46SJack Steiner } 4386a469e46SJack Steiner 439bb898558SAl Viro /* pnode, offset --> socket virtual */ 440bb898558SAl Viro static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset) 441bb898558SAl Viro { 442bb898558SAl Viro return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset); 443bb898558SAl Viro } 444bb898558SAl Viro 445bb898558SAl Viro 446bb898558SAl Viro /* 447bb898558SAl Viro * Extract a PNODE from an APICID (full apicid, not processor subset) 448bb898558SAl Viro */ 449bb898558SAl Viro static inline int uv_apicid_to_pnode(int apicid) 450bb898558SAl Viro { 451c8f730b1SRuss Anderson return (apicid >> uv_hub_info->apic_pnode_shift); 452bb898558SAl Viro } 453bb898558SAl Viro 454bb898558SAl Viro /* 4552a919596SJack Steiner * Convert an apicid to the socket number on the blade 4562a919596SJack Steiner */ 4572a919596SJack Steiner static inline int uv_apicid_to_socket(int apicid) 4582a919596SJack Steiner { 4592a919596SJack Steiner if (is_uv1_hub()) 4602a919596SJack Steiner return (apicid >> (uv_hub_info->apic_pnode_shift - 1)) & 1; 4612a919596SJack Steiner else 4622a919596SJack Steiner return 0; 4632a919596SJack Steiner } 4642a919596SJack Steiner 4652a919596SJack Steiner /* 466bb898558SAl Viro * Access global MMRs using the low memory MMR32 space. This region supports 467bb898558SAl Viro * faster MMR access but not all MMRs are accessible in this space. 468bb898558SAl Viro */ 46939d30770SMike Travis static inline unsigned long *uv_global_mmr32_address(int pnode, unsigned long offset) 470bb898558SAl Viro { 471bb898558SAl Viro return __va(UV_GLOBAL_MMR32_BASE | 472bb898558SAl Viro UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset); 473bb898558SAl Viro } 474bb898558SAl Viro 47539d30770SMike Travis static inline void uv_write_global_mmr32(int pnode, unsigned long offset, unsigned long val) 476bb898558SAl Viro { 4778dc579e8SJack Steiner writeq(val, uv_global_mmr32_address(pnode, offset)); 478bb898558SAl Viro } 479bb898558SAl Viro 48039d30770SMike Travis static inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset) 481bb898558SAl Viro { 4828dc579e8SJack Steiner return readq(uv_global_mmr32_address(pnode, offset)); 483bb898558SAl Viro } 484bb898558SAl Viro 485bb898558SAl Viro /* 486bb898558SAl Viro * Access Global MMR space using the MMR space located at the top of physical 487bb898558SAl Viro * memory. 488bb898558SAl Viro */ 489a289cc7cSRandy Dunlap static inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset) 490bb898558SAl Viro { 491bb898558SAl Viro return __va(UV_GLOBAL_MMR64_BASE | 492bb898558SAl Viro UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset); 493bb898558SAl Viro } 494bb898558SAl Viro 49539d30770SMike Travis static inline void uv_write_global_mmr64(int pnode, unsigned long offset, unsigned long val) 496bb898558SAl Viro { 4978dc579e8SJack Steiner writeq(val, uv_global_mmr64_address(pnode, offset)); 498bb898558SAl Viro } 499bb898558SAl Viro 50039d30770SMike Travis static inline unsigned long uv_read_global_mmr64(int pnode, unsigned long offset) 501bb898558SAl Viro { 5028dc579e8SJack Steiner return readq(uv_global_mmr64_address(pnode, offset)); 503bb898558SAl Viro } 504bb898558SAl Viro 505bb898558SAl Viro /* 50656abcf24SJack Steiner * Global MMR space addresses when referenced by the GRU. (GRU does 50756abcf24SJack Steiner * NOT use socket addressing). 50856abcf24SJack Steiner */ 50956abcf24SJack Steiner static inline unsigned long uv_global_gru_mmr_address(int pnode, unsigned long offset) 51056abcf24SJack Steiner { 511e1e0138dSJack Steiner return UV_GLOBAL_GRU_MMR_BASE | offset | 512e1e0138dSJack Steiner ((unsigned long)pnode << uv_hub_info->m_val); 51356abcf24SJack Steiner } 51456abcf24SJack Steiner 51539d30770SMike Travis static inline void uv_write_global_mmr8(int pnode, unsigned long offset, unsigned char val) 51639d30770SMike Travis { 51739d30770SMike Travis writeb(val, uv_global_mmr64_address(pnode, offset)); 51839d30770SMike Travis } 51939d30770SMike Travis 52039d30770SMike Travis static inline unsigned char uv_read_global_mmr8(int pnode, unsigned long offset) 52139d30770SMike Travis { 52239d30770SMike Travis return readb(uv_global_mmr64_address(pnode, offset)); 52339d30770SMike Travis } 52439d30770SMike Travis 52556abcf24SJack Steiner /* 526bb898558SAl Viro * Access hub local MMRs. Faster than using global space but only local MMRs 527bb898558SAl Viro * are accessible. 528bb898558SAl Viro */ 529bb898558SAl Viro static inline unsigned long *uv_local_mmr_address(unsigned long offset) 530bb898558SAl Viro { 531bb898558SAl Viro return __va(UV_LOCAL_MMR_BASE | offset); 532bb898558SAl Viro } 533bb898558SAl Viro 534bb898558SAl Viro static inline unsigned long uv_read_local_mmr(unsigned long offset) 535bb898558SAl Viro { 5368dc579e8SJack Steiner return readq(uv_local_mmr_address(offset)); 537bb898558SAl Viro } 538bb898558SAl Viro 539bb898558SAl Viro static inline void uv_write_local_mmr(unsigned long offset, unsigned long val) 540bb898558SAl Viro { 5418dc579e8SJack Steiner writeq(val, uv_local_mmr_address(offset)); 542bb898558SAl Viro } 543bb898558SAl Viro 5447f1baa06SMike Travis static inline unsigned char uv_read_local_mmr8(unsigned long offset) 5457f1baa06SMike Travis { 5468dc579e8SJack Steiner return readb(uv_local_mmr_address(offset)); 5477f1baa06SMike Travis } 5487f1baa06SMike Travis 5497f1baa06SMike Travis static inline void uv_write_local_mmr8(unsigned long offset, unsigned char val) 5507f1baa06SMike Travis { 5518dc579e8SJack Steiner writeb(val, uv_local_mmr_address(offset)); 5527f1baa06SMike Travis } 5537f1baa06SMike Travis 554bb898558SAl Viro /* 555bb898558SAl Viro * Structures and definitions for converting between cpu, node, pnode, and blade 556bb898558SAl Viro * numbers. 557bb898558SAl Viro */ 558bb898558SAl Viro struct uv_blade_info { 559bb898558SAl Viro unsigned short nr_possible_cpus; 560bb898558SAl Viro unsigned short nr_online_cpus; 561bb898558SAl Viro unsigned short pnode; 5626c7184b7SJack Steiner short memory_nid; 563bb898558SAl Viro }; 564bb898558SAl Viro extern struct uv_blade_info *uv_blade_info; 565bb898558SAl Viro extern short *uv_node_to_blade; 566bb898558SAl Viro extern short *uv_cpu_to_blade; 567bb898558SAl Viro extern short uv_possible_blades; 568bb898558SAl Viro 569bb898558SAl Viro /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */ 570bb898558SAl Viro static inline int uv_blade_processor_id(void) 571bb898558SAl Viro { 572bb898558SAl Viro return uv_hub_info->blade_processor_id; 573bb898558SAl Viro } 574bb898558SAl Viro 575bb898558SAl Viro /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */ 576bb898558SAl Viro static inline int uv_numa_blade_id(void) 577bb898558SAl Viro { 578bb898558SAl Viro return uv_hub_info->numa_blade_id; 579bb898558SAl Viro } 580bb898558SAl Viro 581bb898558SAl Viro /* Convert a cpu number to the the UV blade number */ 582bb898558SAl Viro static inline int uv_cpu_to_blade_id(int cpu) 583bb898558SAl Viro { 584bb898558SAl Viro return uv_cpu_to_blade[cpu]; 585bb898558SAl Viro } 586bb898558SAl Viro 587bb898558SAl Viro /* Convert linux node number to the UV blade number */ 588bb898558SAl Viro static inline int uv_node_to_blade_id(int nid) 589bb898558SAl Viro { 590bb898558SAl Viro return uv_node_to_blade[nid]; 591bb898558SAl Viro } 592bb898558SAl Viro 593bb898558SAl Viro /* Convert a blade id to the PNODE of the blade */ 594bb898558SAl Viro static inline int uv_blade_to_pnode(int bid) 595bb898558SAl Viro { 596bb898558SAl Viro return uv_blade_info[bid].pnode; 597bb898558SAl Viro } 598bb898558SAl Viro 5996c7184b7SJack Steiner /* Nid of memory node on blade. -1 if no blade-local memory */ 6006c7184b7SJack Steiner static inline int uv_blade_to_memory_nid(int bid) 6016c7184b7SJack Steiner { 6026c7184b7SJack Steiner return uv_blade_info[bid].memory_nid; 6036c7184b7SJack Steiner } 6046c7184b7SJack Steiner 605bb898558SAl Viro /* Determine the number of possible cpus on a blade */ 606bb898558SAl Viro static inline int uv_blade_nr_possible_cpus(int bid) 607bb898558SAl Viro { 608bb898558SAl Viro return uv_blade_info[bid].nr_possible_cpus; 609bb898558SAl Viro } 610bb898558SAl Viro 611bb898558SAl Viro /* Determine the number of online cpus on a blade */ 612bb898558SAl Viro static inline int uv_blade_nr_online_cpus(int bid) 613bb898558SAl Viro { 614bb898558SAl Viro return uv_blade_info[bid].nr_online_cpus; 615bb898558SAl Viro } 616bb898558SAl Viro 617bb898558SAl Viro /* Convert a cpu id to the PNODE of the blade containing the cpu */ 618bb898558SAl Viro static inline int uv_cpu_to_pnode(int cpu) 619bb898558SAl Viro { 620bb898558SAl Viro return uv_blade_info[uv_cpu_to_blade_id(cpu)].pnode; 621bb898558SAl Viro } 622bb898558SAl Viro 623bb898558SAl Viro /* Convert a linux node number to the PNODE of the blade */ 624bb898558SAl Viro static inline int uv_node_to_pnode(int nid) 625bb898558SAl Viro { 626bb898558SAl Viro return uv_blade_info[uv_node_to_blade_id(nid)].pnode; 627bb898558SAl Viro } 628bb898558SAl Viro 629bb898558SAl Viro /* Maximum possible number of blades */ 630bb898558SAl Viro static inline int uv_num_possible_blades(void) 631bb898558SAl Viro { 632bb898558SAl Viro return uv_possible_blades; 633bb898558SAl Viro } 634bb898558SAl Viro 6350d12ef0cSMike Travis /* Per Hub NMI support */ 6360d12ef0cSMike Travis extern void uv_nmi_setup(void); 6370d12ef0cSMike Travis 6380d12ef0cSMike Travis /* BMC sets a bit this MMR non-zero before sending an NMI */ 6390d12ef0cSMike Travis #define UVH_NMI_MMR UVH_SCRATCH5 6400d12ef0cSMike Travis #define UVH_NMI_MMR_CLEAR UVH_SCRATCH5_ALIAS 6410d12ef0cSMike Travis #define UVH_NMI_MMR_SHIFT 63 6420d12ef0cSMike Travis #define UVH_NMI_MMR_TYPE "SCRATCH5" 6430d12ef0cSMike Travis 6440d12ef0cSMike Travis /* Newer SMM NMI handler, not present in all systems */ 6450d12ef0cSMike Travis #define UVH_NMI_MMRX UVH_EVENT_OCCURRED0 6460d12ef0cSMike Travis #define UVH_NMI_MMRX_CLEAR UVH_EVENT_OCCURRED0_ALIAS 647c443c03dSMike Travis #define UVH_NMI_MMRX_SHIFT UVH_EVENT_OCCURRED0_EXTIO_INT0_SHFT 6480d12ef0cSMike Travis #define UVH_NMI_MMRX_TYPE "EXTIO_INT0" 6490d12ef0cSMike Travis 6500d12ef0cSMike Travis /* Non-zero indicates newer SMM NMI handler present */ 6510d12ef0cSMike Travis #define UVH_NMI_MMRX_SUPPORTED UVH_EXTIO_INT0_BROADCAST 6520d12ef0cSMike Travis 6530d12ef0cSMike Travis /* Indicates to BIOS that we want to use the newer SMM NMI handler */ 6540d12ef0cSMike Travis #define UVH_NMI_MMRX_REQ UVH_SCRATCH5_ALIAS_2 6550d12ef0cSMike Travis #define UVH_NMI_MMRX_REQ_SHIFT 62 6560d12ef0cSMike Travis 6570d12ef0cSMike Travis struct uv_hub_nmi_s { 6580d12ef0cSMike Travis raw_spinlock_t nmi_lock; 6590d12ef0cSMike Travis atomic_t in_nmi; /* flag this node in UV NMI IRQ */ 6600d12ef0cSMike Travis atomic_t cpu_owner; /* last locker of this struct */ 6610d12ef0cSMike Travis atomic_t read_mmr_count; /* count of MMR reads */ 6620d12ef0cSMike Travis atomic_t nmi_count; /* count of true UV NMIs */ 6630d12ef0cSMike Travis unsigned long nmi_value; /* last value read from NMI MMR */ 6640d12ef0cSMike Travis }; 6650d12ef0cSMike Travis 6660d12ef0cSMike Travis struct uv_cpu_nmi_s { 6670d12ef0cSMike Travis struct uv_hub_nmi_s *hub; 668e1632170SChristoph Lameter int state; 669e1632170SChristoph Lameter int pinging; 6700d12ef0cSMike Travis int queries; 6710d12ef0cSMike Travis int pings; 6720d12ef0cSMike Travis }; 6730d12ef0cSMike Travis 674e1632170SChristoph Lameter DECLARE_PER_CPU(struct uv_cpu_nmi_s, uv_cpu_nmi); 675e1632170SChristoph Lameter 6767c52198bSGeorge Beshers #define uv_hub_nmi this_cpu_read(uv_cpu_nmi.hub) 677e1632170SChristoph Lameter #define uv_cpu_nmi_per(cpu) (per_cpu(uv_cpu_nmi, cpu)) 6780d12ef0cSMike Travis #define uv_hub_nmi_per(cpu) (uv_cpu_nmi_per(cpu).hub) 6790d12ef0cSMike Travis 6800d12ef0cSMike Travis /* uv_cpu_nmi_states */ 6810d12ef0cSMike Travis #define UV_NMI_STATE_OUT 0 6820d12ef0cSMike Travis #define UV_NMI_STATE_IN 1 6830d12ef0cSMike Travis #define UV_NMI_STATE_DUMP 2 6840d12ef0cSMike Travis #define UV_NMI_STATE_DUMP_DONE 3 6850d12ef0cSMike Travis 6867f1baa06SMike Travis /* Update SCIR state */ 6877f1baa06SMike Travis static inline void uv_set_scir_bits(unsigned char value) 6887f1baa06SMike Travis { 6897f1baa06SMike Travis if (uv_hub_info->scir.state != value) { 6907f1baa06SMike Travis uv_hub_info->scir.state = value; 6917f1baa06SMike Travis uv_write_local_mmr8(uv_hub_info->scir.offset, value); 6927f1baa06SMike Travis } 6937f1baa06SMike Travis } 69466666e50SJack Steiner 69539d30770SMike Travis static inline unsigned long uv_scir_offset(int apicid) 69639d30770SMike Travis { 69739d30770SMike Travis return SCIR_LOCAL_MMR_BASE | (apicid & 0x3f); 69839d30770SMike Travis } 69939d30770SMike Travis 7007f1baa06SMike Travis static inline void uv_set_cpu_scir_bits(int cpu, unsigned char value) 7017f1baa06SMike Travis { 7027f1baa06SMike Travis if (uv_cpu_hub_info(cpu)->scir.state != value) { 70339d30770SMike Travis uv_write_global_mmr8(uv_cpu_to_pnode(cpu), 70439d30770SMike Travis uv_cpu_hub_info(cpu)->scir.offset, value); 7057f1baa06SMike Travis uv_cpu_hub_info(cpu)->scir.state = value; 7067f1baa06SMike Travis } 7077f1baa06SMike Travis } 708bb898558SAl Viro 7098191c9f6SDimitri Sivanich extern unsigned int uv_apicid_hibits; 71056abcf24SJack Steiner static unsigned long uv_hub_ipi_value(int apicid, int vector, int mode) 71156abcf24SJack Steiner { 7128191c9f6SDimitri Sivanich apicid |= uv_apicid_hibits; 71356abcf24SJack Steiner return (1UL << UVH_IPI_INT_SEND_SHFT) | 71456abcf24SJack Steiner ((apicid) << UVH_IPI_INT_APIC_ID_SHFT) | 71556abcf24SJack Steiner (mode << UVH_IPI_INT_DELIVERY_MODE_SHFT) | 71656abcf24SJack Steiner (vector << UVH_IPI_INT_VECTOR_SHFT); 71756abcf24SJack Steiner } 71856abcf24SJack Steiner 71966666e50SJack Steiner static inline void uv_hub_send_ipi(int pnode, int apicid, int vector) 72066666e50SJack Steiner { 72166666e50SJack Steiner unsigned long val; 72202dd0a06SRobin Holt unsigned long dmode = dest_Fixed; 72302dd0a06SRobin Holt 72402dd0a06SRobin Holt if (vector == NMI_VECTOR) 72502dd0a06SRobin Holt dmode = dest_NMI; 72666666e50SJack Steiner 72756abcf24SJack Steiner val = uv_hub_ipi_value(apicid, vector, dmode); 72866666e50SJack Steiner uv_write_global_mmr64(pnode, UVH_IPI_INT, val); 72966666e50SJack Steiner } 73066666e50SJack Steiner 7317a1110e8SJack Steiner /* 7327a1110e8SJack Steiner * Get the minimum revision number of the hub chips within the partition. 733eb1e3461SMike Travis * (See UVx_HUB_REVISION_BASE above for specific values.) 7347a1110e8SJack Steiner */ 7357a1110e8SJack Steiner static inline int uv_get_min_hub_revision_id(void) 7367a1110e8SJack Steiner { 7372a919596SJack Steiner return uv_hub_info->hub_revision; 7387a1110e8SJack Steiner } 7397a1110e8SJack Steiner 740bc5d9940SJack Steiner #endif /* CONFIG_X86_64 */ 7417f1baa06SMike Travis #endif /* _ASM_X86_UV_UV_HUB_H */ 742