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> 19906f3b20SMike Travis #include <linux/topology.h> 20bb898558SAl Viro #include <asm/types.h> 21bb898558SAl Viro #include <asm/percpu.h> 2266666e50SJack Steiner #include <asm/uv/uv_mmrs.h> 23c85375cdSMike Travis #include <asm/uv/bios.h> 2402dd0a06SRobin Holt #include <asm/irq_vectors.h> 2502dd0a06SRobin Holt #include <asm/io_apic.h> 26bb898558SAl Viro 27bb898558SAl Viro 28bb898558SAl Viro /* 29bb898558SAl Viro * Addressing Terminology 30bb898558SAl Viro * 31bb898558SAl Viro * M - The low M bits of a physical address represent the offset 32bb898558SAl Viro * into the blade local memory. RAM memory on a blade is physically 33bb898558SAl Viro * contiguous (although various IO spaces may punch holes in 34bb898558SAl Viro * it).. 35bb898558SAl Viro * 36bb898558SAl Viro * N - Number of bits in the node portion of a socket physical 37bb898558SAl Viro * address. 38bb898558SAl Viro * 39bb898558SAl Viro * NASID - network ID of a router, Mbrick or Cbrick. Nasid values of 40bb898558SAl Viro * routers always have low bit of 1, C/MBricks have low bit 41bb898558SAl Viro * equal to 0. Most addressing macros that target UV hub chips 42bb898558SAl Viro * right shift the NASID by 1 to exclude the always-zero bit. 43bb898558SAl Viro * NASIDs contain up to 15 bits. 44bb898558SAl Viro * 45bb898558SAl Viro * GNODE - NASID right shifted by 1 bit. Most mmrs contain gnodes instead 46bb898558SAl Viro * of nasids. 47bb898558SAl Viro * 48bb898558SAl Viro * PNODE - the low N bits of the GNODE. The PNODE is the most useful variant 49bb898558SAl Viro * of the nasid for socket usage. 50bb898558SAl Viro * 516a469e46SJack Steiner * GPA - (global physical address) a socket physical address converted 526a469e46SJack Steiner * so that it can be used by the GRU as a global address. Socket 536a469e46SJack Steiner * physical addresses 1) need additional NASID (node) bits added 546a469e46SJack Steiner * to the high end of the address, and 2) unaliased if the 556a469e46SJack Steiner * partition does not have a physical address 0. In addition, on 566a469e46SJack Steiner * UV2 rev 1, GPAs need the gnode left shifted to bits 39 or 40. 576a469e46SJack Steiner * 58bb898558SAl Viro * 59bb898558SAl Viro * NumaLink Global Physical Address Format: 60bb898558SAl Viro * +--------------------------------+---------------------+ 61bb898558SAl Viro * |00..000| GNODE | NodeOffset | 62bb898558SAl Viro * +--------------------------------+---------------------+ 63bb898558SAl Viro * |<-------53 - M bits --->|<--------M bits -----> 64bb898558SAl Viro * 65bb898558SAl Viro * M - number of node offset bits (35 .. 40) 66bb898558SAl Viro * 67bb898558SAl Viro * 68bb898558SAl Viro * Memory/UV-HUB Processor Socket Address Format: 69bb898558SAl Viro * +----------------+---------------+---------------------+ 70bb898558SAl Viro * |00..000000000000| PNODE | NodeOffset | 71bb898558SAl Viro * +----------------+---------------+---------------------+ 72bb898558SAl Viro * <--- N bits --->|<--------M bits -----> 73bb898558SAl Viro * 74bb898558SAl Viro * M - number of node offset bits (35 .. 40) 75bb898558SAl Viro * N - number of PNODE bits (0 .. 10) 76bb898558SAl Viro * 77bb898558SAl Viro * Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64). 78bb898558SAl Viro * The actual values are configuration dependent and are set at 79bb898558SAl Viro * boot time. M & N values are set by the hardware/BIOS at boot. 80bb898558SAl Viro * 81bb898558SAl Viro * 82bb898558SAl Viro * APICID format 83bb898558SAl Viro * NOTE!!!!!! This is the current format of the APICID. However, code 84bb898558SAl Viro * should assume that this will change in the future. Use functions 85bb898558SAl Viro * in this file for all APICID bit manipulations and conversion. 86bb898558SAl Viro * 87bb898558SAl Viro * 1111110000000000 88bb898558SAl Viro * 5432109876543210 892a919596SJack Steiner * pppppppppplc0cch Nehalem-EX (12 bits in hdw reg) 902a919596SJack Steiner * ppppppppplcc0cch Westmere-EX (12 bits in hdw reg) 912a919596SJack Steiner * pppppppppppcccch SandyBridge (15 bits in hdw reg) 92bb898558SAl Viro * sssssssssss 93bb898558SAl Viro * 94bb898558SAl Viro * p = pnode bits 95bb898558SAl Viro * l = socket number on board 96bb898558SAl Viro * c = core 97bb898558SAl Viro * h = hyperthread 98bb898558SAl Viro * s = bits that are in the SOCKET_ID CSR 99bb898558SAl Viro * 1002a919596SJack Steiner * Note: Processor may support fewer bits in the APICID register. The ACPI 101bb898558SAl Viro * tables hold all 16 bits. Software needs to be aware of this. 102bb898558SAl Viro * 103bb898558SAl Viro * Unless otherwise specified, all references to APICID refer to 104bb898558SAl Viro * the FULL value contained in ACPI tables, not the subset in the 105bb898558SAl Viro * processor APICID register. 106bb898558SAl Viro */ 107bb898558SAl Viro 108bb898558SAl Viro /* 109bb898558SAl Viro * Maximum number of bricks in all partitions and in all coherency domains. 110bb898558SAl Viro * This is the total number of bricks accessible in the numalink fabric. It 111bb898558SAl Viro * includes all C & M bricks. Routers are NOT included. 112bb898558SAl Viro * 113bb898558SAl Viro * This value is also the value of the maximum number of non-router NASIDs 114bb898558SAl Viro * in the numalink fabric. 115bb898558SAl Viro * 116bb898558SAl Viro * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused. 117bb898558SAl Viro */ 118bb898558SAl Viro #define UV_MAX_NUMALINK_BLADES 16384 119bb898558SAl Viro 120bb898558SAl Viro /* 121bb898558SAl Viro * Maximum number of C/Mbricks within a software SSI (hardware may support 122bb898558SAl Viro * more). 123bb898558SAl Viro */ 124bb898558SAl Viro #define UV_MAX_SSI_BLADES 256 125bb898558SAl Viro 126bb898558SAl Viro /* 127bb898558SAl Viro * The largest possible NASID of a C or M brick (+ 2) 128bb898558SAl Viro */ 1291d21e6e3SRobin Holt #define UV_MAX_NASID_VALUE (UV_MAX_NUMALINK_BLADES * 2) 130bb898558SAl Viro 131d38bb135SMike Travis /* System Controller Interface Reg info */ 1327f1baa06SMike Travis struct uv_scir_s { 1337f1baa06SMike Travis struct timer_list timer; 1347f1baa06SMike Travis unsigned long offset; 1357f1baa06SMike Travis unsigned long last; 1367f1baa06SMike Travis unsigned long idle_on; 1377f1baa06SMike Travis unsigned long idle_off; 1387f1baa06SMike Travis unsigned char state; 1397f1baa06SMike Travis unsigned char enabled; 1407f1baa06SMike Travis }; 1417f1baa06SMike Travis 142c85375cdSMike Travis /* GAM (globally addressed memory) range table */ 143c85375cdSMike Travis struct uv_gam_range_s { 144c85375cdSMike Travis u32 limit; /* PA bits 56:26 (GAM_RANGE_SHFT) */ 145c85375cdSMike Travis u16 nasid; /* node's global physical address */ 146c85375cdSMike Travis s8 base; /* entry index of node's base addr */ 147c85375cdSMike Travis u8 reserved; 148c85375cdSMike Travis }; 149c85375cdSMike Travis 150bb898558SAl Viro /* 151bb898558SAl Viro * The following defines attributes of the HUB chip. These attributes are 1520045ddd2SMike Travis * frequently referenced and are kept in a common per hub struct. 1530045ddd2SMike Travis * After setup, the struct is read only, so it should be readily 1540045ddd2SMike Travis * available in the L3 cache on the cpu socket for the node. 155bb898558SAl Viro */ 156bb898558SAl Viro struct uv_hub_info_s { 157bb898558SAl Viro unsigned long global_mmr_base; 1581de329c1SMike Travis unsigned long global_mmr_shift; 159bb898558SAl Viro unsigned long gpa_mask; 1606e27b91cSMike Travis unsigned short *socket_to_node; 1616e27b91cSMike Travis unsigned short *socket_to_pnode; 1626e27b91cSMike Travis unsigned short *pnode_to_socket; 163c85375cdSMike Travis struct uv_gam_range_s *gr_table; 1641de329c1SMike Travis unsigned short min_socket; 1651de329c1SMike Travis unsigned short min_pnode; 166c85375cdSMike Travis unsigned char m_val; 167c85375cdSMike Travis unsigned char n_val; 168c85375cdSMike Travis unsigned char gr_table_len; 1692a919596SJack Steiner unsigned char hub_revision; 1702a919596SJack Steiner unsigned char apic_pnode_shift; 1711de329c1SMike Travis unsigned char gpa_shift; 1726a469e46SJack Steiner unsigned char m_shift; 1736a469e46SJack Steiner unsigned char n_lshift; 1741de329c1SMike Travis unsigned int gnode_extra; 175bb898558SAl Viro unsigned long gnode_upper; 176bb898558SAl Viro unsigned long lowmem_remap_top; 177bb898558SAl Viro unsigned long lowmem_remap_base; 1781de329c1SMike Travis unsigned long global_gru_base; 1791de329c1SMike Travis unsigned long global_gru_shift; 180bb898558SAl Viro unsigned short pnode; 181bb898558SAl Viro unsigned short pnode_mask; 182bb898558SAl Viro unsigned short coherency_domain_number; 183bb898558SAl Viro unsigned short numa_blade_id; 184906f3b20SMike Travis unsigned short nr_possible_cpus; 185906f3b20SMike Travis unsigned short nr_online_cpus; 186906f3b20SMike Travis short memory_nid; 187bb898558SAl Viro }; 1887f1baa06SMike Travis 1890045ddd2SMike Travis /* CPU specific info with a pointer to the hub common info struct */ 1900045ddd2SMike Travis struct uv_cpu_info_s { 1910045ddd2SMike Travis void *p_uv_hub_info; 1920045ddd2SMike Travis unsigned char blade_cpu_id; 1930045ddd2SMike Travis struct uv_scir_s scir; 1940045ddd2SMike Travis }; 1950045ddd2SMike Travis DECLARE_PER_CPU(struct uv_cpu_info_s, __uv_cpu_info); 1960045ddd2SMike Travis 1970045ddd2SMike Travis #define uv_cpu_info this_cpu_ptr(&__uv_cpu_info) 1980045ddd2SMike Travis #define uv_cpu_info_per(cpu) (&per_cpu(__uv_cpu_info, cpu)) 1990045ddd2SMike Travis 200d38bb135SMike Travis #define uv_scir_info (&uv_cpu_info->scir) 201d38bb135SMike Travis #define uv_cpu_scir_info(cpu) (&uv_cpu_info_per(cpu)->scir) 202d38bb135SMike Travis 2033edcf2ffSMike Travis /* Node specific hub common info struct */ 2043edcf2ffSMike Travis extern void **__uv_hub_info_list; 2053edcf2ffSMike Travis static inline struct uv_hub_info_s *uv_hub_info_list(int node) 2063edcf2ffSMike Travis { 2073edcf2ffSMike Travis return (struct uv_hub_info_s *)__uv_hub_info_list[node]; 2083edcf2ffSMike Travis } 2093edcf2ffSMike Travis 2103edcf2ffSMike Travis static inline struct uv_hub_info_s *_uv_hub_info(void) 2113edcf2ffSMike Travis { 2123edcf2ffSMike Travis return (struct uv_hub_info_s *)uv_cpu_info->p_uv_hub_info; 2133edcf2ffSMike Travis } 2143edcf2ffSMike Travis #define uv_hub_info _uv_hub_info() 2153edcf2ffSMike Travis 2163edcf2ffSMike Travis static inline struct uv_hub_info_s *uv_cpu_hub_info(int cpu) 2173edcf2ffSMike Travis { 2183edcf2ffSMike Travis return (struct uv_hub_info_s *)uv_cpu_info_per(cpu)->p_uv_hub_info; 2193edcf2ffSMike Travis } 2203edcf2ffSMike Travis 2213edcf2ffSMike Travis #define UV_HUB_INFO_VERSION 0x7150 2223edcf2ffSMike Travis extern int uv_hub_info_version(void); 2233edcf2ffSMike Travis static inline int uv_hub_info_check(int version) 2243edcf2ffSMike Travis { 2253edcf2ffSMike Travis if (uv_hub_info_version() == version) 2263edcf2ffSMike Travis return 0; 2273edcf2ffSMike Travis 2283edcf2ffSMike Travis pr_crit("UV: uv_hub_info version(%x) mismatch, expecting(%x)\n", 2293edcf2ffSMike Travis uv_hub_info_version(), version); 2303edcf2ffSMike Travis 2313edcf2ffSMike Travis BUG(); /* Catastrophic - cannot continue on unknown UV system */ 2323edcf2ffSMike Travis } 2333edcf2ffSMike Travis #define _uv_hub_info_check() uv_hub_info_check(UV_HUB_INFO_VERSION) 2343edcf2ffSMike Travis 2352a919596SJack Steiner /* 2360045ddd2SMike Travis * HUB revision ranges for each UV HUB architecture. 2372a919596SJack Steiner * This is a software convention - NOT the hardware revision numbers in 2382a919596SJack Steiner * the hub chip. 2392a919596SJack Steiner */ 2402a919596SJack Steiner #define UV1_HUB_REVISION_BASE 1 2412a919596SJack Steiner #define UV2_HUB_REVISION_BASE 3 2426edbd471SMike Travis #define UV3_HUB_REVISION_BASE 5 243eb1e3461SMike Travis #define UV4_HUB_REVISION_BASE 7 2448078d195SMike Travis #define UV4A_HUB_REVISION_BASE 8 /* UV4 (fixed) rev 2 */ 2452a919596SJack Steiner 246e0ee1c97SMike Travis #ifdef UV1_HUB_IS_SUPPORTED 2472a919596SJack Steiner static inline int is_uv1_hub(void) 2482a919596SJack Steiner { 2492a919596SJack Steiner return uv_hub_info->hub_revision < UV2_HUB_REVISION_BASE; 2502a919596SJack Steiner } 251e0ee1c97SMike Travis #else 252e0ee1c97SMike Travis static inline int is_uv1_hub(void) 253e0ee1c97SMike Travis { 254e0ee1c97SMike Travis return 0; 255e0ee1c97SMike Travis } 256e0ee1c97SMike Travis #endif 2572a919596SJack Steiner 258e0ee1c97SMike Travis #ifdef UV2_HUB_IS_SUPPORTED 2592a919596SJack Steiner static inline int is_uv2_hub(void) 2602a919596SJack Steiner { 2616edbd471SMike Travis return ((uv_hub_info->hub_revision >= UV2_HUB_REVISION_BASE) && 2626edbd471SMike Travis (uv_hub_info->hub_revision < UV3_HUB_REVISION_BASE)); 2636edbd471SMike Travis } 264e0ee1c97SMike Travis #else 265e0ee1c97SMike Travis static inline int is_uv2_hub(void) 266e0ee1c97SMike Travis { 267e0ee1c97SMike Travis return 0; 268e0ee1c97SMike Travis } 269e0ee1c97SMike Travis #endif 2706edbd471SMike Travis 271e0ee1c97SMike Travis #ifdef UV3_HUB_IS_SUPPORTED 2726edbd471SMike Travis static inline int is_uv3_hub(void) 2736edbd471SMike Travis { 274eb1e3461SMike Travis return ((uv_hub_info->hub_revision >= UV3_HUB_REVISION_BASE) && 275eb1e3461SMike Travis (uv_hub_info->hub_revision < UV4_HUB_REVISION_BASE)); 2766edbd471SMike Travis } 277e0ee1c97SMike Travis #else 278e0ee1c97SMike Travis static inline int is_uv3_hub(void) 279e0ee1c97SMike Travis { 280e0ee1c97SMike Travis return 0; 281e0ee1c97SMike Travis } 282e0ee1c97SMike Travis #endif 2836edbd471SMike Travis 2848078d195SMike Travis /* First test "is UV4A", then "is UV4" */ 2858078d195SMike Travis #ifdef UV4A_HUB_IS_SUPPORTED 2868078d195SMike Travis static inline int is_uv4a_hub(void) 2878078d195SMike Travis { 2888078d195SMike Travis return (uv_hub_info->hub_revision >= UV4A_HUB_REVISION_BASE); 2898078d195SMike Travis } 2908078d195SMike Travis #else 2918078d195SMike Travis static inline int is_uv4a_hub(void) 2928078d195SMike Travis { 2938078d195SMike Travis return 0; 2948078d195SMike Travis } 2958078d195SMike Travis #endif 2968078d195SMike Travis 297eb1e3461SMike Travis #ifdef UV4_HUB_IS_SUPPORTED 298eb1e3461SMike Travis static inline int is_uv4_hub(void) 299eb1e3461SMike Travis { 300eb1e3461SMike Travis return uv_hub_info->hub_revision >= UV4_HUB_REVISION_BASE; 301eb1e3461SMike Travis } 302eb1e3461SMike Travis #else 303eb1e3461SMike Travis static inline int is_uv4_hub(void) 304eb1e3461SMike Travis { 305eb1e3461SMike Travis return 0; 306eb1e3461SMike Travis } 307eb1e3461SMike Travis #endif 308eb1e3461SMike Travis 3096edbd471SMike Travis static inline int is_uvx_hub(void) 3106edbd471SMike Travis { 311e0ee1c97SMike Travis if (uv_hub_info->hub_revision >= UV2_HUB_REVISION_BASE) 312e0ee1c97SMike Travis return uv_hub_info->hub_revision; 313e0ee1c97SMike Travis 314e0ee1c97SMike Travis return 0; 315e0ee1c97SMike Travis } 316e0ee1c97SMike Travis 317e0ee1c97SMike Travis static inline int is_uv_hub(void) 318e0ee1c97SMike Travis { 319e0ee1c97SMike Travis #ifdef UV1_HUB_IS_SUPPORTED 320e0ee1c97SMike Travis return uv_hub_info->hub_revision; 321e0ee1c97SMike Travis #endif 322e0ee1c97SMike Travis return is_uvx_hub(); 3232a919596SJack Steiner } 3242a919596SJack Steiner 325c8f730b1SRuss Anderson union uvh_apicid { 326c8f730b1SRuss Anderson unsigned long v; 327c8f730b1SRuss Anderson struct uvh_apicid_s { 328c8f730b1SRuss Anderson unsigned long local_apic_mask : 24; 329c8f730b1SRuss Anderson unsigned long local_apic_shift : 5; 330c8f730b1SRuss Anderson unsigned long unused1 : 3; 331c8f730b1SRuss Anderson unsigned long pnode_mask : 24; 332c8f730b1SRuss Anderson unsigned long pnode_shift : 5; 333c8f730b1SRuss Anderson unsigned long unused2 : 3; 334c8f730b1SRuss Anderson } s; 335c8f730b1SRuss Anderson }; 336c8f730b1SRuss Anderson 337bb898558SAl Viro /* 338bb898558SAl Viro * Local & Global MMR space macros. 339bb898558SAl Viro * Note: macros are intended to be used ONLY by inline functions 340bb898558SAl Viro * in this file - not by other kernel code. 341bb898558SAl Viro * n - NASID (full 15-bit global nasid) 342bb898558SAl Viro * g - GNODE (full 15-bit global nasid, right shifted 1) 343bb898558SAl Viro * p - PNODE (local part of nsids, right shifted 1) 344bb898558SAl Viro */ 345bb898558SAl Viro #define UV_NASID_TO_PNODE(n) (((n) >> 1) & uv_hub_info->pnode_mask) 346c4ed3f04SJack Steiner #define UV_PNODE_TO_GNODE(p) ((p) |uv_hub_info->gnode_extra) 347c4ed3f04SJack Steiner #define UV_PNODE_TO_NASID(p) (UV_PNODE_TO_GNODE(p) << 1) 348bb898558SAl Viro 3492a919596SJack Steiner #define UV1_LOCAL_MMR_BASE 0xf4000000UL 3502a919596SJack Steiner #define UV1_GLOBAL_MMR32_BASE 0xf8000000UL 3512a919596SJack Steiner #define UV1_LOCAL_MMR_SIZE (64UL * 1024 * 1024) 3522a919596SJack Steiner #define UV1_GLOBAL_MMR32_SIZE (64UL * 1024 * 1024) 3532a919596SJack Steiner 3542a919596SJack Steiner #define UV2_LOCAL_MMR_BASE 0xfa000000UL 3552a919596SJack Steiner #define UV2_GLOBAL_MMR32_BASE 0xfc000000UL 3562a919596SJack Steiner #define UV2_LOCAL_MMR_SIZE (32UL * 1024 * 1024) 3572a919596SJack Steiner #define UV2_GLOBAL_MMR32_SIZE (32UL * 1024 * 1024) 3582a919596SJack Steiner 3596edbd471SMike Travis #define UV3_LOCAL_MMR_BASE 0xfa000000UL 3606edbd471SMike Travis #define UV3_GLOBAL_MMR32_BASE 0xfc000000UL 3616edbd471SMike Travis #define UV3_LOCAL_MMR_SIZE (32UL * 1024 * 1024) 3626edbd471SMike Travis #define UV3_GLOBAL_MMR32_SIZE (32UL * 1024 * 1024) 3636edbd471SMike Travis 364eb1e3461SMike Travis #define UV4_LOCAL_MMR_BASE 0xfa000000UL 365eb1e3461SMike Travis #define UV4_GLOBAL_MMR32_BASE 0xfc000000UL 366eb1e3461SMike Travis #define UV4_LOCAL_MMR_SIZE (32UL * 1024 * 1024) 367eb1e3461SMike Travis #define UV4_GLOBAL_MMR32_SIZE (16UL * 1024 * 1024) 368eb1e3461SMike Travis 369eb1e3461SMike Travis #define UV_LOCAL_MMR_BASE ( \ 370eb1e3461SMike Travis is_uv1_hub() ? UV1_LOCAL_MMR_BASE : \ 371eb1e3461SMike Travis is_uv2_hub() ? UV2_LOCAL_MMR_BASE : \ 372eb1e3461SMike Travis is_uv3_hub() ? UV3_LOCAL_MMR_BASE : \ 373eb1e3461SMike Travis /*is_uv4_hub*/ UV4_LOCAL_MMR_BASE) 374eb1e3461SMike Travis 375eb1e3461SMike Travis #define UV_GLOBAL_MMR32_BASE ( \ 376eb1e3461SMike Travis is_uv1_hub() ? UV1_GLOBAL_MMR32_BASE : \ 377eb1e3461SMike Travis is_uv2_hub() ? UV2_GLOBAL_MMR32_BASE : \ 378eb1e3461SMike Travis is_uv3_hub() ? UV3_GLOBAL_MMR32_BASE : \ 379eb1e3461SMike Travis /*is_uv4_hub*/ UV4_GLOBAL_MMR32_BASE) 380eb1e3461SMike Travis 381eb1e3461SMike Travis #define UV_LOCAL_MMR_SIZE ( \ 382eb1e3461SMike Travis is_uv1_hub() ? UV1_LOCAL_MMR_SIZE : \ 383eb1e3461SMike Travis is_uv2_hub() ? UV2_LOCAL_MMR_SIZE : \ 384eb1e3461SMike Travis is_uv3_hub() ? UV3_LOCAL_MMR_SIZE : \ 385eb1e3461SMike Travis /*is_uv4_hub*/ UV4_LOCAL_MMR_SIZE) 386eb1e3461SMike Travis 387eb1e3461SMike Travis #define UV_GLOBAL_MMR32_SIZE ( \ 388eb1e3461SMike Travis is_uv1_hub() ? UV1_GLOBAL_MMR32_SIZE : \ 389eb1e3461SMike Travis is_uv2_hub() ? UV2_GLOBAL_MMR32_SIZE : \ 390eb1e3461SMike Travis is_uv3_hub() ? UV3_GLOBAL_MMR32_SIZE : \ 391eb1e3461SMike Travis /*is_uv4_hub*/ UV4_GLOBAL_MMR32_SIZE) 392eb1e3461SMike Travis 393bb898558SAl Viro #define UV_GLOBAL_MMR64_BASE (uv_hub_info->global_mmr_base) 394bb898558SAl Viro 39556abcf24SJack Steiner #define UV_GLOBAL_GRU_MMR_BASE 0x4000000 39656abcf24SJack Steiner 397bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_SHIFT 15 3981de329c1SMike Travis #define _UV_GLOBAL_MMR64_PNODE_SHIFT 26 3991de329c1SMike Travis #define UV_GLOBAL_MMR64_PNODE_SHIFT (uv_hub_info->global_mmr_shift) 400bb898558SAl Viro 401bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_BITS(p) ((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT)) 402bb898558SAl Viro 403bb898558SAl Viro #define UV_GLOBAL_MMR64_PNODE_BITS(p) \ 40467e83f30SJack Steiner (((unsigned long)(p)) << UV_GLOBAL_MMR64_PNODE_SHIFT) 405bb898558SAl Viro 406c8f730b1SRuss Anderson #define UVH_APICID 0x002D0E00L 407bb898558SAl Viro #define UV_APIC_PNODE_SHIFT 6 408bb898558SAl Viro 4098191c9f6SDimitri Sivanich #define UV_APICID_HIBIT_MASK 0xffff0000 4108191c9f6SDimitri Sivanich 4117f1baa06SMike Travis /* Local Bus from cpu's perspective */ 4127f1baa06SMike Travis #define LOCAL_BUS_BASE 0x1c00000 4137f1baa06SMike Travis #define LOCAL_BUS_SIZE (4 * 1024 * 1024) 4147f1baa06SMike Travis 4157f1baa06SMike Travis /* 4167f1baa06SMike Travis * System Controller Interface Reg 4177f1baa06SMike Travis * 4187f1baa06SMike Travis * Note there are NO leds on a UV system. This register is only 4197f1baa06SMike Travis * used by the system controller to monitor system-wide operation. 4207f1baa06SMike Travis * There are 64 regs per node. With Nahelem cpus (2 cores per node, 4217f1baa06SMike Travis * 8 cpus per core, 2 threads per cpu) there are 32 cpu threads on 4227f1baa06SMike Travis * a node. 4237f1baa06SMike Travis * 4247f1baa06SMike Travis * The window is located at top of ACPI MMR space 4257f1baa06SMike Travis */ 4267f1baa06SMike Travis #define SCIR_WINDOW_COUNT 64 4277f1baa06SMike Travis #define SCIR_LOCAL_MMR_BASE (LOCAL_BUS_BASE + \ 4287f1baa06SMike Travis LOCAL_BUS_SIZE - \ 4297f1baa06SMike Travis SCIR_WINDOW_COUNT) 4307f1baa06SMike Travis 4317f1baa06SMike Travis #define SCIR_CPU_HEARTBEAT 0x01 /* timer interrupt */ 4327f1baa06SMike Travis #define SCIR_CPU_ACTIVITY 0x02 /* not idle */ 4337f1baa06SMike Travis #define SCIR_CPU_HB_INTERVAL (HZ) /* once per second */ 4347f1baa06SMike Travis 4358661984fSDimitri Sivanich /* Loop through all installed blades */ 4368661984fSDimitri Sivanich #define for_each_possible_blade(bid) \ 4378661984fSDimitri Sivanich for ((bid) = 0; (bid) < uv_num_possible_blades(); (bid)++) 4388661984fSDimitri Sivanich 439bb898558SAl Viro /* 440bb898558SAl Viro * Macros for converting between kernel virtual addresses, socket local physical 441bb898558SAl Viro * addresses, and UV global physical addresses. 442bb898558SAl Viro * Note: use the standard __pa() & __va() macros for converting 443bb898558SAl Viro * between socket virtual and socket physical addresses. 444bb898558SAl Viro */ 445bb898558SAl Viro 446c85375cdSMike Travis /* global bits offset - number of local address bits in gpa for this UV arch */ 447c85375cdSMike Travis static inline unsigned int uv_gpa_shift(void) 448c85375cdSMike Travis { 449c85375cdSMike Travis return uv_hub_info->gpa_shift; 450c85375cdSMike Travis } 451c85375cdSMike Travis #define _uv_gpa_shift 452c85375cdSMike Travis 453c85375cdSMike Travis /* Find node that has the address range that contains global address */ 454c85375cdSMike Travis static inline struct uv_gam_range_s *uv_gam_range(unsigned long pa) 455c85375cdSMike Travis { 456c85375cdSMike Travis struct uv_gam_range_s *gr = uv_hub_info->gr_table; 457c85375cdSMike Travis unsigned long pal = (pa & uv_hub_info->gpa_mask) >> UV_GAM_RANGE_SHFT; 458c85375cdSMike Travis int i, num = uv_hub_info->gr_table_len; 459c85375cdSMike Travis 460c85375cdSMike Travis if (gr) { 461c85375cdSMike Travis for (i = 0; i < num; i++, gr++) { 462c85375cdSMike Travis if (pal < gr->limit) 463c85375cdSMike Travis return gr; 464c85375cdSMike Travis } 465c85375cdSMike Travis } 466c85375cdSMike Travis pr_crit("UV: GAM Range for 0x%lx not found at %p!\n", pa, gr); 467c85375cdSMike Travis BUG(); 468c85375cdSMike Travis } 469c85375cdSMike Travis 470c85375cdSMike Travis /* Return base address of node that contains global address */ 471c85375cdSMike Travis static inline unsigned long uv_gam_range_base(unsigned long pa) 472c85375cdSMike Travis { 473c85375cdSMike Travis struct uv_gam_range_s *gr = uv_gam_range(pa); 474c85375cdSMike Travis int base = gr->base; 475c85375cdSMike Travis 476c85375cdSMike Travis if (base < 0) 477c85375cdSMike Travis return 0UL; 478c85375cdSMike Travis 479c85375cdSMike Travis return uv_hub_info->gr_table[base].limit; 480c85375cdSMike Travis } 481c85375cdSMike Travis 482c85375cdSMike Travis /* socket phys RAM --> UV global NASID (UV4+) */ 483c85375cdSMike Travis static inline unsigned long uv_soc_phys_ram_to_nasid(unsigned long paddr) 484c85375cdSMike Travis { 485c85375cdSMike Travis return uv_gam_range(paddr)->nasid; 486c85375cdSMike Travis } 487c85375cdSMike Travis #define _uv_soc_phys_ram_to_nasid 488c85375cdSMike Travis 489c85375cdSMike Travis /* socket virtual --> UV global NASID (UV4+) */ 490c85375cdSMike Travis static inline unsigned long uv_gpa_nasid(void *v) 491c85375cdSMike Travis { 492c85375cdSMike Travis return uv_soc_phys_ram_to_nasid(__pa(v)); 493c85375cdSMike Travis } 494c85375cdSMike Travis 495bb898558SAl Viro /* socket phys RAM --> UV global physical address */ 496bb898558SAl Viro static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr) 497bb898558SAl Viro { 498c85375cdSMike Travis unsigned int m_val = uv_hub_info->m_val; 499c85375cdSMike Travis 500bb898558SAl Viro if (paddr < uv_hub_info->lowmem_remap_top) 501189f67c4SJack Steiner paddr |= uv_hub_info->lowmem_remap_base; 502ad483005SMike Travis 503ad483005SMike Travis if (m_val) { 5046a469e46SJack Steiner paddr |= uv_hub_info->gnode_upper; 505c85375cdSMike Travis paddr = ((paddr << uv_hub_info->m_shift) 506c85375cdSMike Travis >> uv_hub_info->m_shift) | 507c85375cdSMike Travis ((paddr >> uv_hub_info->m_val) 508c85375cdSMike Travis << uv_hub_info->n_lshift); 509ad483005SMike Travis } else { 510c85375cdSMike Travis paddr |= uv_soc_phys_ram_to_nasid(paddr) 511c85375cdSMike Travis << uv_hub_info->gpa_shift; 512ad483005SMike Travis } 5136a469e46SJack Steiner return paddr; 514bb898558SAl Viro } 515bb898558SAl Viro 516bb898558SAl Viro /* socket virtual --> UV global physical address */ 517bb898558SAl Viro static inline unsigned long uv_gpa(void *v) 518bb898558SAl Viro { 519189f67c4SJack Steiner return uv_soc_phys_ram_to_gpa(__pa(v)); 520bb898558SAl Viro } 521bb898558SAl Viro 522fae419f2SRobin Holt /* Top two bits indicate the requested address is in MMR space. */ 523fae419f2SRobin Holt static inline int 524fae419f2SRobin Holt uv_gpa_in_mmr_space(unsigned long gpa) 525fae419f2SRobin Holt { 526fae419f2SRobin Holt return (gpa >> 62) == 0x3UL; 527fae419f2SRobin Holt } 528fae419f2SRobin Holt 529729d69e6SRobin Holt /* UV global physical address --> socket phys RAM */ 530729d69e6SRobin Holt static inline unsigned long uv_gpa_to_soc_phys_ram(unsigned long gpa) 531729d69e6SRobin Holt { 5325a51467bSRuss Anderson unsigned long paddr; 533729d69e6SRobin Holt unsigned long remap_base = uv_hub_info->lowmem_remap_base; 534729d69e6SRobin Holt unsigned long remap_top = uv_hub_info->lowmem_remap_top; 535c85375cdSMike Travis unsigned int m_val = uv_hub_info->m_val; 536729d69e6SRobin Holt 537c85375cdSMike Travis if (m_val) 5386a469e46SJack Steiner gpa = ((gpa << uv_hub_info->m_shift) >> uv_hub_info->m_shift) | 5396a469e46SJack Steiner ((gpa >> uv_hub_info->n_lshift) << uv_hub_info->m_val); 540c85375cdSMike Travis 5415a51467bSRuss Anderson paddr = gpa & uv_hub_info->gpa_mask; 542729d69e6SRobin Holt if (paddr >= remap_base && paddr < remap_base + remap_top) 543729d69e6SRobin Holt paddr -= remap_base; 544729d69e6SRobin Holt return paddr; 545729d69e6SRobin Holt } 546729d69e6SRobin Holt 547906f3b20SMike Travis /* gpa -> gnode */ 5481d21e6e3SRobin Holt static inline unsigned long uv_gpa_to_gnode(unsigned long gpa) 5491d21e6e3SRobin Holt { 550c85375cdSMike Travis unsigned int n_lshift = uv_hub_info->n_lshift; 551c85375cdSMike Travis 552c85375cdSMike Travis if (n_lshift) 553c85375cdSMike Travis return gpa >> n_lshift; 554c85375cdSMike Travis 555c85375cdSMike Travis return uv_gam_range(gpa)->nasid >> 1; 5561d21e6e3SRobin Holt } 5571d21e6e3SRobin Holt 5581d21e6e3SRobin Holt /* gpa -> pnode */ 5591d21e6e3SRobin Holt static inline int uv_gpa_to_pnode(unsigned long gpa) 5601d21e6e3SRobin Holt { 561906f3b20SMike Travis return uv_gpa_to_gnode(gpa) & uv_hub_info->pnode_mask; 5621d21e6e3SRobin Holt } 5631d21e6e3SRobin Holt 5646a469e46SJack Steiner /* gpa -> node offset */ 5656a469e46SJack Steiner static inline unsigned long uv_gpa_to_offset(unsigned long gpa) 5666a469e46SJack Steiner { 567c85375cdSMike Travis unsigned int m_shift = uv_hub_info->m_shift; 568c85375cdSMike Travis 569c85375cdSMike Travis if (m_shift) 570c85375cdSMike Travis return (gpa << m_shift) >> m_shift; 571c85375cdSMike Travis 572c85375cdSMike Travis return (gpa & uv_hub_info->gpa_mask) - uv_gam_range_base(gpa); 573c85375cdSMike Travis } 574c85375cdSMike Travis 575c85375cdSMike Travis /* Convert socket to node */ 576c85375cdSMike Travis static inline int _uv_socket_to_node(int socket, unsigned short *s2nid) 577c85375cdSMike Travis { 578c85375cdSMike Travis return s2nid ? s2nid[socket - uv_hub_info->min_socket] : socket; 579c85375cdSMike Travis } 580c85375cdSMike Travis 581c85375cdSMike Travis static inline int uv_socket_to_node(int socket) 582c85375cdSMike Travis { 583c85375cdSMike Travis return _uv_socket_to_node(socket, uv_hub_info->socket_to_node); 5846a469e46SJack Steiner } 5856a469e46SJack Steiner 586bb898558SAl Viro /* pnode, offset --> socket virtual */ 587bb898558SAl Viro static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset) 588bb898558SAl Viro { 589c85375cdSMike Travis unsigned int m_val = uv_hub_info->m_val; 590c85375cdSMike Travis unsigned long base; 591c85375cdSMike Travis unsigned short sockid, node, *p2s; 592bb898558SAl Viro 593c85375cdSMike Travis if (m_val) 594c85375cdSMike Travis return __va(((unsigned long)pnode << m_val) | offset); 5956e27b91cSMike Travis 596c85375cdSMike Travis p2s = uv_hub_info->pnode_to_socket; 597c85375cdSMike Travis sockid = p2s ? p2s[pnode - uv_hub_info->min_pnode] : pnode; 598c85375cdSMike Travis node = uv_socket_to_node(sockid); 599c85375cdSMike Travis 600c85375cdSMike Travis /* limit address of previous socket is our base, except node 0 is 0 */ 601c85375cdSMike Travis if (!node) 602c85375cdSMike Travis return __va((unsigned long)offset); 603c85375cdSMike Travis 604c85375cdSMike Travis base = (unsigned long)(uv_hub_info->gr_table[node - 1].limit); 605c85375cdSMike Travis return __va(base << UV_GAM_RANGE_SHFT | offset); 6066e27b91cSMike Travis } 6076e27b91cSMike Travis 6086e27b91cSMike Travis /* Extract/Convert a PNODE from an APICID (full apicid, not processor subset) */ 609bb898558SAl Viro static inline int uv_apicid_to_pnode(int apicid) 610bb898558SAl Viro { 6116e27b91cSMike Travis int pnode = apicid >> uv_hub_info->apic_pnode_shift; 6126e27b91cSMike Travis unsigned short *s2pn = uv_hub_info->socket_to_pnode; 6136e27b91cSMike Travis 6146e27b91cSMike Travis return s2pn ? s2pn[pnode - uv_hub_info->min_socket] : pnode; 615bb898558SAl Viro } 616bb898558SAl Viro 617906f3b20SMike Travis /* Convert an apicid to the socket number on the blade */ 6182a919596SJack Steiner static inline int uv_apicid_to_socket(int apicid) 6192a919596SJack Steiner { 6202a919596SJack Steiner if (is_uv1_hub()) 6212a919596SJack Steiner return (apicid >> (uv_hub_info->apic_pnode_shift - 1)) & 1; 6222a919596SJack Steiner else 6232a919596SJack Steiner return 0; 6242a919596SJack Steiner } 6252a919596SJack Steiner 6262a919596SJack Steiner /* 627bb898558SAl Viro * Access global MMRs using the low memory MMR32 space. This region supports 628bb898558SAl Viro * faster MMR access but not all MMRs are accessible in this space. 629bb898558SAl Viro */ 63039d30770SMike Travis static inline unsigned long *uv_global_mmr32_address(int pnode, unsigned long offset) 631bb898558SAl Viro { 632bb898558SAl Viro return __va(UV_GLOBAL_MMR32_BASE | 633bb898558SAl Viro UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset); 634bb898558SAl Viro } 635bb898558SAl Viro 63639d30770SMike Travis static inline void uv_write_global_mmr32(int pnode, unsigned long offset, unsigned long val) 637bb898558SAl Viro { 6388dc579e8SJack Steiner writeq(val, uv_global_mmr32_address(pnode, offset)); 639bb898558SAl Viro } 640bb898558SAl Viro 64139d30770SMike Travis static inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset) 642bb898558SAl Viro { 6438dc579e8SJack Steiner return readq(uv_global_mmr32_address(pnode, offset)); 644bb898558SAl Viro } 645bb898558SAl Viro 646bb898558SAl Viro /* 647bb898558SAl Viro * Access Global MMR space using the MMR space located at the top of physical 648bb898558SAl Viro * memory. 649bb898558SAl Viro */ 650a289cc7cSRandy Dunlap static inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset) 651bb898558SAl Viro { 652bb898558SAl Viro return __va(UV_GLOBAL_MMR64_BASE | 653bb898558SAl Viro UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset); 654bb898558SAl Viro } 655bb898558SAl Viro 65639d30770SMike Travis static inline void uv_write_global_mmr64(int pnode, unsigned long offset, unsigned long val) 657bb898558SAl Viro { 6588dc579e8SJack Steiner writeq(val, uv_global_mmr64_address(pnode, offset)); 659bb898558SAl Viro } 660bb898558SAl Viro 66139d30770SMike Travis static inline unsigned long uv_read_global_mmr64(int pnode, unsigned long offset) 662bb898558SAl Viro { 6638dc579e8SJack Steiner return readq(uv_global_mmr64_address(pnode, offset)); 664bb898558SAl Viro } 665bb898558SAl Viro 66639d30770SMike Travis static inline void uv_write_global_mmr8(int pnode, unsigned long offset, unsigned char val) 66739d30770SMike Travis { 66839d30770SMike Travis writeb(val, uv_global_mmr64_address(pnode, offset)); 66939d30770SMike Travis } 67039d30770SMike Travis 67139d30770SMike Travis static inline unsigned char uv_read_global_mmr8(int pnode, unsigned long offset) 67239d30770SMike Travis { 67339d30770SMike Travis return readb(uv_global_mmr64_address(pnode, offset)); 67439d30770SMike Travis } 67539d30770SMike Travis 67656abcf24SJack Steiner /* 677bb898558SAl Viro * Access hub local MMRs. Faster than using global space but only local MMRs 678bb898558SAl Viro * are accessible. 679bb898558SAl Viro */ 680bb898558SAl Viro static inline unsigned long *uv_local_mmr_address(unsigned long offset) 681bb898558SAl Viro { 682bb898558SAl Viro return __va(UV_LOCAL_MMR_BASE | offset); 683bb898558SAl Viro } 684bb898558SAl Viro 685bb898558SAl Viro static inline unsigned long uv_read_local_mmr(unsigned long offset) 686bb898558SAl Viro { 6878dc579e8SJack Steiner return readq(uv_local_mmr_address(offset)); 688bb898558SAl Viro } 689bb898558SAl Viro 690bb898558SAl Viro static inline void uv_write_local_mmr(unsigned long offset, unsigned long val) 691bb898558SAl Viro { 6928dc579e8SJack Steiner writeq(val, uv_local_mmr_address(offset)); 693bb898558SAl Viro } 694bb898558SAl Viro 6957f1baa06SMike Travis static inline unsigned char uv_read_local_mmr8(unsigned long offset) 6967f1baa06SMike Travis { 6978dc579e8SJack Steiner return readb(uv_local_mmr_address(offset)); 6987f1baa06SMike Travis } 6997f1baa06SMike Travis 7007f1baa06SMike Travis static inline void uv_write_local_mmr8(unsigned long offset, unsigned char val) 7017f1baa06SMike Travis { 7028dc579e8SJack Steiner writeb(val, uv_local_mmr_address(offset)); 7037f1baa06SMike Travis } 7047f1baa06SMike Travis 705bb898558SAl Viro /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */ 706bb898558SAl Viro static inline int uv_blade_processor_id(void) 707bb898558SAl Viro { 7085627a825SMike Travis return uv_cpu_info->blade_cpu_id; 709bb898558SAl Viro } 710bb898558SAl Viro 7115627a825SMike Travis /* Blade-local cpu number of cpu N. Numbered 0 .. <# cpus on the blade> */ 7125627a825SMike Travis static inline int uv_cpu_blade_processor_id(int cpu) 7135627a825SMike Travis { 7145627a825SMike Travis return uv_cpu_info_per(cpu)->blade_cpu_id; 7155627a825SMike Travis } 7165627a825SMike Travis #define _uv_cpu_blade_processor_id 1 /* indicate function available */ 7175627a825SMike Travis 718906f3b20SMike Travis /* Blade number to Node number (UV1..UV4 is 1:1) */ 719906f3b20SMike Travis static inline int uv_blade_to_node(int blade) 720906f3b20SMike Travis { 721906f3b20SMike Travis return blade; 722906f3b20SMike Travis } 723906f3b20SMike Travis 724bb898558SAl Viro /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */ 725bb898558SAl Viro static inline int uv_numa_blade_id(void) 726bb898558SAl Viro { 727bb898558SAl Viro return uv_hub_info->numa_blade_id; 728bb898558SAl Viro } 729bb898558SAl Viro 730906f3b20SMike Travis /* 731906f3b20SMike Travis * Convert linux node number to the UV blade number. 732906f3b20SMike Travis * .. Currently for UV1 thru UV4 the node and the blade are identical. 733906f3b20SMike Travis * .. If this changes then you MUST check references to this function! 734906f3b20SMike Travis */ 735906f3b20SMike Travis static inline int uv_node_to_blade_id(int nid) 736906f3b20SMike Travis { 737906f3b20SMike Travis return nid; 738906f3b20SMike Travis } 739906f3b20SMike Travis 740bb898558SAl Viro /* Convert a cpu number to the the UV blade number */ 741bb898558SAl Viro static inline int uv_cpu_to_blade_id(int cpu) 742bb898558SAl Viro { 743906f3b20SMike Travis return uv_node_to_blade_id(cpu_to_node(cpu)); 744bb898558SAl Viro } 745bb898558SAl Viro 746bb898558SAl Viro /* Convert a blade id to the PNODE of the blade */ 747bb898558SAl Viro static inline int uv_blade_to_pnode(int bid) 748bb898558SAl Viro { 749906f3b20SMike Travis return uv_hub_info_list(uv_blade_to_node(bid))->pnode; 750bb898558SAl Viro } 751bb898558SAl Viro 7526c7184b7SJack Steiner /* Nid of memory node on blade. -1 if no blade-local memory */ 7536c7184b7SJack Steiner static inline int uv_blade_to_memory_nid(int bid) 7546c7184b7SJack Steiner { 755906f3b20SMike Travis return uv_hub_info_list(uv_blade_to_node(bid))->memory_nid; 7566c7184b7SJack Steiner } 7576c7184b7SJack Steiner 758bb898558SAl Viro /* Determine the number of possible cpus on a blade */ 759bb898558SAl Viro static inline int uv_blade_nr_possible_cpus(int bid) 760bb898558SAl Viro { 761906f3b20SMike Travis return uv_hub_info_list(uv_blade_to_node(bid))->nr_possible_cpus; 762bb898558SAl Viro } 763bb898558SAl Viro 764bb898558SAl Viro /* Determine the number of online cpus on a blade */ 765bb898558SAl Viro static inline int uv_blade_nr_online_cpus(int bid) 766bb898558SAl Viro { 767906f3b20SMike Travis return uv_hub_info_list(uv_blade_to_node(bid))->nr_online_cpus; 768bb898558SAl Viro } 769bb898558SAl Viro 770bb898558SAl Viro /* Convert a cpu id to the PNODE of the blade containing the cpu */ 771bb898558SAl Viro static inline int uv_cpu_to_pnode(int cpu) 772bb898558SAl Viro { 773906f3b20SMike Travis return uv_cpu_hub_info(cpu)->pnode; 774bb898558SAl Viro } 775bb898558SAl Viro 776bb898558SAl Viro /* Convert a linux node number to the PNODE of the blade */ 777bb898558SAl Viro static inline int uv_node_to_pnode(int nid) 778bb898558SAl Viro { 779906f3b20SMike Travis return uv_hub_info_list(nid)->pnode; 780bb898558SAl Viro } 781bb898558SAl Viro 782bb898558SAl Viro /* Maximum possible number of blades */ 783906f3b20SMike Travis extern short uv_possible_blades; 784bb898558SAl Viro static inline int uv_num_possible_blades(void) 785bb898558SAl Viro { 786bb898558SAl Viro return uv_possible_blades; 787bb898558SAl Viro } 788bb898558SAl Viro 7890d12ef0cSMike Travis /* Per Hub NMI support */ 7900d12ef0cSMike Travis extern void uv_nmi_setup(void); 791abdf1df6Stravis@sgi.com extern void uv_nmi_setup_hubless(void); 7920d12ef0cSMike Travis 79397d21003Smike.travis@hpe.com /* BIOS/Kernel flags exchange MMR */ 79497d21003Smike.travis@hpe.com #define UVH_BIOS_KERNEL_MMR UVH_SCRATCH5 79597d21003Smike.travis@hpe.com #define UVH_BIOS_KERNEL_MMR_ALIAS UVH_SCRATCH5_ALIAS 79697d21003Smike.travis@hpe.com #define UVH_BIOS_KERNEL_MMR_ALIAS_2 UVH_SCRATCH5_ALIAS_2 79797d21003Smike.travis@hpe.com 79897d21003Smike.travis@hpe.com /* TSC sync valid, set by BIOS */ 79997d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_MMR UVH_BIOS_KERNEL_MMR 80097d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_SHIFT 10 80197d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_SHIFT_UV2K 16 /* UV2/3k have different bits */ 80297d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_MASK 3 /* 0011 */ 80397d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_VALID 3 /* 0011 */ 80497d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_INVALID 2 /* 0010 */ 80597d21003Smike.travis@hpe.com 8060d12ef0cSMike Travis /* BMC sets a bit this MMR non-zero before sending an NMI */ 80797d21003Smike.travis@hpe.com #define UVH_NMI_MMR UVH_BIOS_KERNEL_MMR 80897d21003Smike.travis@hpe.com #define UVH_NMI_MMR_CLEAR UVH_BIOS_KERNEL_MMR_ALIAS 8090d12ef0cSMike Travis #define UVH_NMI_MMR_SHIFT 63 8100d12ef0cSMike Travis #define UVH_NMI_MMR_TYPE "SCRATCH5" 8110d12ef0cSMike Travis 8120d12ef0cSMike Travis /* Newer SMM NMI handler, not present in all systems */ 8130d12ef0cSMike Travis #define UVH_NMI_MMRX UVH_EVENT_OCCURRED0 8140d12ef0cSMike Travis #define UVH_NMI_MMRX_CLEAR UVH_EVENT_OCCURRED0_ALIAS 815c443c03dSMike Travis #define UVH_NMI_MMRX_SHIFT UVH_EVENT_OCCURRED0_EXTIO_INT0_SHFT 8160d12ef0cSMike Travis #define UVH_NMI_MMRX_TYPE "EXTIO_INT0" 8170d12ef0cSMike Travis 8180d12ef0cSMike Travis /* Non-zero indicates newer SMM NMI handler present */ 8190d12ef0cSMike Travis #define UVH_NMI_MMRX_SUPPORTED UVH_EXTIO_INT0_BROADCAST 8200d12ef0cSMike Travis 8210d12ef0cSMike Travis /* Indicates to BIOS that we want to use the newer SMM NMI handler */ 82297d21003Smike.travis@hpe.com #define UVH_NMI_MMRX_REQ UVH_BIOS_KERNEL_MMR_ALIAS_2 8230d12ef0cSMike Travis #define UVH_NMI_MMRX_REQ_SHIFT 62 8240d12ef0cSMike Travis 8250d12ef0cSMike Travis struct uv_hub_nmi_s { 8260d12ef0cSMike Travis raw_spinlock_t nmi_lock; 8270d12ef0cSMike Travis atomic_t in_nmi; /* flag this node in UV NMI IRQ */ 8280d12ef0cSMike Travis atomic_t cpu_owner; /* last locker of this struct */ 8290d12ef0cSMike Travis atomic_t read_mmr_count; /* count of MMR reads */ 8300d12ef0cSMike Travis atomic_t nmi_count; /* count of true UV NMIs */ 8310d12ef0cSMike Travis unsigned long nmi_value; /* last value read from NMI MMR */ 832abdf1df6Stravis@sgi.com bool hub_present; /* false means UV hubless system */ 833abdf1df6Stravis@sgi.com bool pch_owner; /* indicates this hub owns PCH */ 8340d12ef0cSMike Travis }; 8350d12ef0cSMike Travis 8360d12ef0cSMike Travis struct uv_cpu_nmi_s { 8370d12ef0cSMike Travis struct uv_hub_nmi_s *hub; 838e1632170SChristoph Lameter int state; 839e1632170SChristoph Lameter int pinging; 8400d12ef0cSMike Travis int queries; 8410d12ef0cSMike Travis int pings; 8420d12ef0cSMike Travis }; 8430d12ef0cSMike Travis 844e1632170SChristoph Lameter DECLARE_PER_CPU(struct uv_cpu_nmi_s, uv_cpu_nmi); 845e1632170SChristoph Lameter 8467c52198bSGeorge Beshers #define uv_hub_nmi this_cpu_read(uv_cpu_nmi.hub) 847e1632170SChristoph Lameter #define uv_cpu_nmi_per(cpu) (per_cpu(uv_cpu_nmi, cpu)) 8480d12ef0cSMike Travis #define uv_hub_nmi_per(cpu) (uv_cpu_nmi_per(cpu).hub) 8490d12ef0cSMike Travis 8500d12ef0cSMike Travis /* uv_cpu_nmi_states */ 8510d12ef0cSMike Travis #define UV_NMI_STATE_OUT 0 8520d12ef0cSMike Travis #define UV_NMI_STATE_IN 1 8530d12ef0cSMike Travis #define UV_NMI_STATE_DUMP 2 8540d12ef0cSMike Travis #define UV_NMI_STATE_DUMP_DONE 3 8550d12ef0cSMike Travis 8567f1baa06SMike Travis /* Update SCIR state */ 8577f1baa06SMike Travis static inline void uv_set_scir_bits(unsigned char value) 8587f1baa06SMike Travis { 859d38bb135SMike Travis if (uv_scir_info->state != value) { 860d38bb135SMike Travis uv_scir_info->state = value; 861d38bb135SMike Travis uv_write_local_mmr8(uv_scir_info->offset, value); 8627f1baa06SMike Travis } 8637f1baa06SMike Travis } 86466666e50SJack Steiner 86539d30770SMike Travis static inline unsigned long uv_scir_offset(int apicid) 86639d30770SMike Travis { 86739d30770SMike Travis return SCIR_LOCAL_MMR_BASE | (apicid & 0x3f); 86839d30770SMike Travis } 86939d30770SMike Travis 8707f1baa06SMike Travis static inline void uv_set_cpu_scir_bits(int cpu, unsigned char value) 8717f1baa06SMike Travis { 872d38bb135SMike Travis if (uv_cpu_scir_info(cpu)->state != value) { 87339d30770SMike Travis uv_write_global_mmr8(uv_cpu_to_pnode(cpu), 874d38bb135SMike Travis uv_cpu_scir_info(cpu)->offset, value); 875d38bb135SMike Travis uv_cpu_scir_info(cpu)->state = value; 8767f1baa06SMike Travis } 8777f1baa06SMike Travis } 878bb898558SAl Viro 8798191c9f6SDimitri Sivanich extern unsigned int uv_apicid_hibits; 88056abcf24SJack Steiner static unsigned long uv_hub_ipi_value(int apicid, int vector, int mode) 88156abcf24SJack Steiner { 8828191c9f6SDimitri Sivanich apicid |= uv_apicid_hibits; 88356abcf24SJack Steiner return (1UL << UVH_IPI_INT_SEND_SHFT) | 88456abcf24SJack Steiner ((apicid) << UVH_IPI_INT_APIC_ID_SHFT) | 88556abcf24SJack Steiner (mode << UVH_IPI_INT_DELIVERY_MODE_SHFT) | 88656abcf24SJack Steiner (vector << UVH_IPI_INT_VECTOR_SHFT); 88756abcf24SJack Steiner } 88856abcf24SJack Steiner 88966666e50SJack Steiner static inline void uv_hub_send_ipi(int pnode, int apicid, int vector) 89066666e50SJack Steiner { 89166666e50SJack Steiner unsigned long val; 89202dd0a06SRobin Holt unsigned long dmode = dest_Fixed; 89302dd0a06SRobin Holt 89402dd0a06SRobin Holt if (vector == NMI_VECTOR) 89502dd0a06SRobin Holt dmode = dest_NMI; 89666666e50SJack Steiner 89756abcf24SJack Steiner val = uv_hub_ipi_value(apicid, vector, dmode); 89866666e50SJack Steiner uv_write_global_mmr64(pnode, UVH_IPI_INT, val); 89966666e50SJack Steiner } 90066666e50SJack Steiner 9017a1110e8SJack Steiner /* 9027a1110e8SJack Steiner * Get the minimum revision number of the hub chips within the partition. 903eb1e3461SMike Travis * (See UVx_HUB_REVISION_BASE above for specific values.) 9047a1110e8SJack Steiner */ 9057a1110e8SJack Steiner static inline int uv_get_min_hub_revision_id(void) 9067a1110e8SJack Steiner { 9072a919596SJack Steiner return uv_hub_info->hub_revision; 9087a1110e8SJack Steiner } 9097a1110e8SJack Steiner 910bc5d9940SJack Steiner #endif /* CONFIG_X86_64 */ 9117f1baa06SMike Travis #endif /* _ASM_X86_UV_UV_HUB_H */ 912