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 * 8bb898558SAl Viro * Copyright (C) 2007-2008 Silicon Graphics, Inc. All rights reserved. 9bb898558SAl Viro */ 10bb898558SAl Viro 11bb898558SAl Viro #ifndef ASM_X86__UV__UV_HUB_H 12bb898558SAl Viro #define ASM_X86__UV__UV_HUB_H 13bb898558SAl Viro 14bb898558SAl Viro #include <linux/numa.h> 15bb898558SAl Viro #include <linux/percpu.h> 16bb898558SAl Viro #include <asm/types.h> 17bb898558SAl Viro #include <asm/percpu.h> 18bb898558SAl Viro 19bb898558SAl Viro 20bb898558SAl Viro /* 21bb898558SAl Viro * Addressing Terminology 22bb898558SAl Viro * 23bb898558SAl Viro * M - The low M bits of a physical address represent the offset 24bb898558SAl Viro * into the blade local memory. RAM memory on a blade is physically 25bb898558SAl Viro * contiguous (although various IO spaces may punch holes in 26bb898558SAl Viro * it).. 27bb898558SAl Viro * 28bb898558SAl Viro * N - Number of bits in the node portion of a socket physical 29bb898558SAl Viro * address. 30bb898558SAl Viro * 31bb898558SAl Viro * NASID - network ID of a router, Mbrick or Cbrick. Nasid values of 32bb898558SAl Viro * routers always have low bit of 1, C/MBricks have low bit 33bb898558SAl Viro * equal to 0. Most addressing macros that target UV hub chips 34bb898558SAl Viro * right shift the NASID by 1 to exclude the always-zero bit. 35bb898558SAl Viro * NASIDs contain up to 15 bits. 36bb898558SAl Viro * 37bb898558SAl Viro * GNODE - NASID right shifted by 1 bit. Most mmrs contain gnodes instead 38bb898558SAl Viro * of nasids. 39bb898558SAl Viro * 40bb898558SAl Viro * PNODE - the low N bits of the GNODE. The PNODE is the most useful variant 41bb898558SAl Viro * of the nasid for socket usage. 42bb898558SAl Viro * 43bb898558SAl Viro * 44bb898558SAl Viro * NumaLink Global Physical Address Format: 45bb898558SAl Viro * +--------------------------------+---------------------+ 46bb898558SAl Viro * |00..000| GNODE | NodeOffset | 47bb898558SAl Viro * +--------------------------------+---------------------+ 48bb898558SAl Viro * |<-------53 - M bits --->|<--------M bits -----> 49bb898558SAl Viro * 50bb898558SAl Viro * M - number of node offset bits (35 .. 40) 51bb898558SAl Viro * 52bb898558SAl Viro * 53bb898558SAl Viro * Memory/UV-HUB Processor Socket Address Format: 54bb898558SAl Viro * +----------------+---------------+---------------------+ 55bb898558SAl Viro * |00..000000000000| PNODE | NodeOffset | 56bb898558SAl Viro * +----------------+---------------+---------------------+ 57bb898558SAl Viro * <--- N bits --->|<--------M bits -----> 58bb898558SAl Viro * 59bb898558SAl Viro * M - number of node offset bits (35 .. 40) 60bb898558SAl Viro * N - number of PNODE bits (0 .. 10) 61bb898558SAl Viro * 62bb898558SAl Viro * Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64). 63bb898558SAl Viro * The actual values are configuration dependent and are set at 64bb898558SAl Viro * boot time. M & N values are set by the hardware/BIOS at boot. 65bb898558SAl Viro * 66bb898558SAl Viro * 67bb898558SAl Viro * APICID format 68bb898558SAl Viro * NOTE!!!!!! This is the current format of the APICID. However, code 69bb898558SAl Viro * should assume that this will change in the future. Use functions 70bb898558SAl Viro * in this file for all APICID bit manipulations and conversion. 71bb898558SAl Viro * 72bb898558SAl Viro * 1111110000000000 73bb898558SAl Viro * 5432109876543210 74bb898558SAl Viro * pppppppppplc0cch 75bb898558SAl Viro * sssssssssss 76bb898558SAl Viro * 77bb898558SAl Viro * p = pnode bits 78bb898558SAl Viro * l = socket number on board 79bb898558SAl Viro * c = core 80bb898558SAl Viro * h = hyperthread 81bb898558SAl Viro * s = bits that are in the SOCKET_ID CSR 82bb898558SAl Viro * 83bb898558SAl Viro * Note: Processor only supports 12 bits in the APICID register. The ACPI 84bb898558SAl Viro * tables hold all 16 bits. Software needs to be aware of this. 85bb898558SAl Viro * 86bb898558SAl Viro * Unless otherwise specified, all references to APICID refer to 87bb898558SAl Viro * the FULL value contained in ACPI tables, not the subset in the 88bb898558SAl Viro * processor APICID register. 89bb898558SAl Viro */ 90bb898558SAl Viro 91bb898558SAl Viro 92bb898558SAl Viro /* 93bb898558SAl Viro * Maximum number of bricks in all partitions and in all coherency domains. 94bb898558SAl Viro * This is the total number of bricks accessible in the numalink fabric. It 95bb898558SAl Viro * includes all C & M bricks. Routers are NOT included. 96bb898558SAl Viro * 97bb898558SAl Viro * This value is also the value of the maximum number of non-router NASIDs 98bb898558SAl Viro * in the numalink fabric. 99bb898558SAl Viro * 100bb898558SAl Viro * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused. 101bb898558SAl Viro */ 102bb898558SAl Viro #define UV_MAX_NUMALINK_BLADES 16384 103bb898558SAl Viro 104bb898558SAl Viro /* 105bb898558SAl Viro * Maximum number of C/Mbricks within a software SSI (hardware may support 106bb898558SAl Viro * more). 107bb898558SAl Viro */ 108bb898558SAl Viro #define UV_MAX_SSI_BLADES 256 109bb898558SAl Viro 110bb898558SAl Viro /* 111bb898558SAl Viro * The largest possible NASID of a C or M brick (+ 2) 112bb898558SAl Viro */ 113bb898558SAl Viro #define UV_MAX_NASID_VALUE (UV_MAX_NUMALINK_NODES * 2) 114bb898558SAl Viro 115bb898558SAl Viro /* 116bb898558SAl Viro * The following defines attributes of the HUB chip. These attributes are 117bb898558SAl Viro * frequently referenced and are kept in the per-cpu data areas of each cpu. 118bb898558SAl Viro * They are kept together in a struct to minimize cache misses. 119bb898558SAl Viro */ 120bb898558SAl Viro struct uv_hub_info_s { 121bb898558SAl Viro unsigned long global_mmr_base; 122bb898558SAl Viro unsigned long gpa_mask; 123bb898558SAl Viro unsigned long gnode_upper; 124bb898558SAl Viro unsigned long lowmem_remap_top; 125bb898558SAl Viro unsigned long lowmem_remap_base; 126bb898558SAl Viro unsigned short pnode; 127bb898558SAl Viro unsigned short pnode_mask; 128bb898558SAl Viro unsigned short coherency_domain_number; 129bb898558SAl Viro unsigned short numa_blade_id; 130bb898558SAl Viro unsigned char blade_processor_id; 131bb898558SAl Viro unsigned char m_val; 132bb898558SAl Viro unsigned char n_val; 133bb898558SAl Viro }; 134bb898558SAl Viro DECLARE_PER_CPU(struct uv_hub_info_s, __uv_hub_info); 135bb898558SAl Viro #define uv_hub_info (&__get_cpu_var(__uv_hub_info)) 136bb898558SAl Viro #define uv_cpu_hub_info(cpu) (&per_cpu(__uv_hub_info, cpu)) 137bb898558SAl Viro 138bb898558SAl Viro /* 139bb898558SAl Viro * Local & Global MMR space macros. 140bb898558SAl Viro * Note: macros are intended to be used ONLY by inline functions 141bb898558SAl Viro * in this file - not by other kernel code. 142bb898558SAl Viro * n - NASID (full 15-bit global nasid) 143bb898558SAl Viro * g - GNODE (full 15-bit global nasid, right shifted 1) 144bb898558SAl Viro * p - PNODE (local part of nsids, right shifted 1) 145bb898558SAl Viro */ 146bb898558SAl Viro #define UV_NASID_TO_PNODE(n) (((n) >> 1) & uv_hub_info->pnode_mask) 147bb898558SAl Viro #define UV_PNODE_TO_NASID(p) (((p) << 1) | uv_hub_info->gnode_upper) 148bb898558SAl Viro 149bb898558SAl Viro #define UV_LOCAL_MMR_BASE 0xf4000000UL 150bb898558SAl Viro #define UV_GLOBAL_MMR32_BASE 0xf8000000UL 151bb898558SAl Viro #define UV_GLOBAL_MMR64_BASE (uv_hub_info->global_mmr_base) 152bb898558SAl Viro #define UV_LOCAL_MMR_SIZE (64UL * 1024 * 1024) 153bb898558SAl Viro #define UV_GLOBAL_MMR32_SIZE (64UL * 1024 * 1024) 154bb898558SAl Viro 155bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_SHIFT 15 156bb898558SAl Viro #define UV_GLOBAL_MMR64_PNODE_SHIFT 26 157bb898558SAl Viro 158bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_BITS(p) ((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT)) 159bb898558SAl Viro 160bb898558SAl Viro #define UV_GLOBAL_MMR64_PNODE_BITS(p) \ 161bb898558SAl Viro ((unsigned long)(p) << UV_GLOBAL_MMR64_PNODE_SHIFT) 162bb898558SAl Viro 163bb898558SAl Viro #define UV_APIC_PNODE_SHIFT 6 164bb898558SAl Viro 165bb898558SAl Viro /* 166bb898558SAl Viro * Macros for converting between kernel virtual addresses, socket local physical 167bb898558SAl Viro * addresses, and UV global physical addresses. 168bb898558SAl Viro * Note: use the standard __pa() & __va() macros for converting 169bb898558SAl Viro * between socket virtual and socket physical addresses. 170bb898558SAl Viro */ 171bb898558SAl Viro 172bb898558SAl Viro /* socket phys RAM --> UV global physical address */ 173bb898558SAl Viro static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr) 174bb898558SAl Viro { 175bb898558SAl Viro if (paddr < uv_hub_info->lowmem_remap_top) 176bb898558SAl Viro paddr += uv_hub_info->lowmem_remap_base; 177bb898558SAl Viro return paddr | uv_hub_info->gnode_upper; 178bb898558SAl Viro } 179bb898558SAl Viro 180bb898558SAl Viro 181bb898558SAl Viro /* socket virtual --> UV global physical address */ 182bb898558SAl Viro static inline unsigned long uv_gpa(void *v) 183bb898558SAl Viro { 184bb898558SAl Viro return __pa(v) | uv_hub_info->gnode_upper; 185bb898558SAl Viro } 186bb898558SAl Viro 187bb898558SAl Viro /* socket virtual --> UV global physical address */ 188bb898558SAl Viro static inline void *uv_vgpa(void *v) 189bb898558SAl Viro { 190bb898558SAl Viro return (void *)uv_gpa(v); 191bb898558SAl Viro } 192bb898558SAl Viro 193bb898558SAl Viro /* UV global physical address --> socket virtual */ 194bb898558SAl Viro static inline void *uv_va(unsigned long gpa) 195bb898558SAl Viro { 196bb898558SAl Viro return __va(gpa & uv_hub_info->gpa_mask); 197bb898558SAl Viro } 198bb898558SAl Viro 199bb898558SAl Viro /* pnode, offset --> socket virtual */ 200bb898558SAl Viro static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset) 201bb898558SAl Viro { 202bb898558SAl Viro return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset); 203bb898558SAl Viro } 204bb898558SAl Viro 205bb898558SAl Viro 206bb898558SAl Viro /* 207bb898558SAl Viro * Extract a PNODE from an APICID (full apicid, not processor subset) 208bb898558SAl Viro */ 209bb898558SAl Viro static inline int uv_apicid_to_pnode(int apicid) 210bb898558SAl Viro { 211bb898558SAl Viro return (apicid >> UV_APIC_PNODE_SHIFT); 212bb898558SAl Viro } 213bb898558SAl Viro 214bb898558SAl Viro /* 215bb898558SAl Viro * Access global MMRs using the low memory MMR32 space. This region supports 216bb898558SAl Viro * faster MMR access but not all MMRs are accessible in this space. 217bb898558SAl Viro */ 218bb898558SAl Viro static inline unsigned long *uv_global_mmr32_address(int pnode, 219bb898558SAl Viro unsigned long offset) 220bb898558SAl Viro { 221bb898558SAl Viro return __va(UV_GLOBAL_MMR32_BASE | 222bb898558SAl Viro UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset); 223bb898558SAl Viro } 224bb898558SAl Viro 225bb898558SAl Viro static inline void uv_write_global_mmr32(int pnode, unsigned long offset, 226bb898558SAl Viro unsigned long val) 227bb898558SAl Viro { 228bb898558SAl Viro *uv_global_mmr32_address(pnode, offset) = val; 229bb898558SAl Viro } 230bb898558SAl Viro 231bb898558SAl Viro static inline unsigned long uv_read_global_mmr32(int pnode, 232bb898558SAl Viro unsigned long offset) 233bb898558SAl Viro { 234bb898558SAl Viro return *uv_global_mmr32_address(pnode, offset); 235bb898558SAl Viro } 236bb898558SAl Viro 237bb898558SAl Viro /* 238bb898558SAl Viro * Access Global MMR space using the MMR space located at the top of physical 239bb898558SAl Viro * memory. 240bb898558SAl Viro */ 241bb898558SAl Viro static inline unsigned long *uv_global_mmr64_address(int pnode, 242bb898558SAl Viro unsigned long offset) 243bb898558SAl Viro { 244bb898558SAl Viro return __va(UV_GLOBAL_MMR64_BASE | 245bb898558SAl Viro UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset); 246bb898558SAl Viro } 247bb898558SAl Viro 248bb898558SAl Viro static inline void uv_write_global_mmr64(int pnode, unsigned long offset, 249bb898558SAl Viro unsigned long val) 250bb898558SAl Viro { 251bb898558SAl Viro *uv_global_mmr64_address(pnode, offset) = val; 252bb898558SAl Viro } 253bb898558SAl Viro 254bb898558SAl Viro static inline unsigned long uv_read_global_mmr64(int pnode, 255bb898558SAl Viro unsigned long offset) 256bb898558SAl Viro { 257bb898558SAl Viro return *uv_global_mmr64_address(pnode, offset); 258bb898558SAl Viro } 259bb898558SAl Viro 260bb898558SAl Viro /* 261bb898558SAl Viro * Access hub local MMRs. Faster than using global space but only local MMRs 262bb898558SAl Viro * are accessible. 263bb898558SAl Viro */ 264bb898558SAl Viro static inline unsigned long *uv_local_mmr_address(unsigned long offset) 265bb898558SAl Viro { 266bb898558SAl Viro return __va(UV_LOCAL_MMR_BASE | offset); 267bb898558SAl Viro } 268bb898558SAl Viro 269bb898558SAl Viro static inline unsigned long uv_read_local_mmr(unsigned long offset) 270bb898558SAl Viro { 271bb898558SAl Viro return *uv_local_mmr_address(offset); 272bb898558SAl Viro } 273bb898558SAl Viro 274bb898558SAl Viro static inline void uv_write_local_mmr(unsigned long offset, unsigned long val) 275bb898558SAl Viro { 276bb898558SAl Viro *uv_local_mmr_address(offset) = val; 277bb898558SAl Viro } 278bb898558SAl Viro 279bb898558SAl Viro /* 280bb898558SAl Viro * Structures and definitions for converting between cpu, node, pnode, and blade 281bb898558SAl Viro * numbers. 282bb898558SAl Viro */ 283bb898558SAl Viro struct uv_blade_info { 284bb898558SAl Viro unsigned short nr_possible_cpus; 285bb898558SAl Viro unsigned short nr_online_cpus; 286bb898558SAl Viro unsigned short pnode; 287bb898558SAl Viro }; 288bb898558SAl Viro extern struct uv_blade_info *uv_blade_info; 289bb898558SAl Viro extern short *uv_node_to_blade; 290bb898558SAl Viro extern short *uv_cpu_to_blade; 291bb898558SAl Viro extern short uv_possible_blades; 292bb898558SAl Viro 293bb898558SAl Viro /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */ 294bb898558SAl Viro static inline int uv_blade_processor_id(void) 295bb898558SAl Viro { 296bb898558SAl Viro return uv_hub_info->blade_processor_id; 297bb898558SAl Viro } 298bb898558SAl Viro 299bb898558SAl Viro /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */ 300bb898558SAl Viro static inline int uv_numa_blade_id(void) 301bb898558SAl Viro { 302bb898558SAl Viro return uv_hub_info->numa_blade_id; 303bb898558SAl Viro } 304bb898558SAl Viro 305bb898558SAl Viro /* Convert a cpu number to the the UV blade number */ 306bb898558SAl Viro static inline int uv_cpu_to_blade_id(int cpu) 307bb898558SAl Viro { 308bb898558SAl Viro return uv_cpu_to_blade[cpu]; 309bb898558SAl Viro } 310bb898558SAl Viro 311bb898558SAl Viro /* Convert linux node number to the UV blade number */ 312bb898558SAl Viro static inline int uv_node_to_blade_id(int nid) 313bb898558SAl Viro { 314bb898558SAl Viro return uv_node_to_blade[nid]; 315bb898558SAl Viro } 316bb898558SAl Viro 317bb898558SAl Viro /* Convert a blade id to the PNODE of the blade */ 318bb898558SAl Viro static inline int uv_blade_to_pnode(int bid) 319bb898558SAl Viro { 320bb898558SAl Viro return uv_blade_info[bid].pnode; 321bb898558SAl Viro } 322bb898558SAl Viro 323bb898558SAl Viro /* Determine the number of possible cpus on a blade */ 324bb898558SAl Viro static inline int uv_blade_nr_possible_cpus(int bid) 325bb898558SAl Viro { 326bb898558SAl Viro return uv_blade_info[bid].nr_possible_cpus; 327bb898558SAl Viro } 328bb898558SAl Viro 329bb898558SAl Viro /* Determine the number of online cpus on a blade */ 330bb898558SAl Viro static inline int uv_blade_nr_online_cpus(int bid) 331bb898558SAl Viro { 332bb898558SAl Viro return uv_blade_info[bid].nr_online_cpus; 333bb898558SAl Viro } 334bb898558SAl Viro 335bb898558SAl Viro /* Convert a cpu id to the PNODE of the blade containing the cpu */ 336bb898558SAl Viro static inline int uv_cpu_to_pnode(int cpu) 337bb898558SAl Viro { 338bb898558SAl Viro return uv_blade_info[uv_cpu_to_blade_id(cpu)].pnode; 339bb898558SAl Viro } 340bb898558SAl Viro 341bb898558SAl Viro /* Convert a linux node number to the PNODE of the blade */ 342bb898558SAl Viro static inline int uv_node_to_pnode(int nid) 343bb898558SAl Viro { 344bb898558SAl Viro return uv_blade_info[uv_node_to_blade_id(nid)].pnode; 345bb898558SAl Viro } 346bb898558SAl Viro 347bb898558SAl Viro /* Maximum possible number of blades */ 348bb898558SAl Viro static inline int uv_num_possible_blades(void) 349bb898558SAl Viro { 350bb898558SAl Viro return uv_possible_blades; 351bb898558SAl Viro } 352bb898558SAl Viro 353bb898558SAl Viro #endif /* ASM_X86__UV__UV_HUB_H */ 354bb898558SAl Viro 355