xref: /openbmc/linux/arch/ia64/include/asm/uv/uv_hub.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
17f30491cSTony Luck /*
27f30491cSTony Luck  * This file is subject to the terms and conditions of the GNU General Public
37f30491cSTony Luck  * License.  See the file "COPYING" in the main directory of this archive
47f30491cSTony Luck  * for more details.
57f30491cSTony Luck  *
67f30491cSTony Luck  * SGI UV architectural definitions
77f30491cSTony Luck  *
87f30491cSTony Luck  * Copyright (C) 2008 Silicon Graphics, Inc. All rights reserved.
97f30491cSTony Luck  */
107f30491cSTony Luck 
117f30491cSTony Luck #ifndef __ASM_IA64_UV_HUB_H__
127f30491cSTony Luck #define __ASM_IA64_UV_HUB_H__
137f30491cSTony Luck 
147f30491cSTony Luck #include <linux/numa.h>
157f30491cSTony Luck #include <linux/percpu.h>
167f30491cSTony Luck #include <asm/types.h>
177f30491cSTony Luck #include <asm/percpu.h>
187f30491cSTony Luck 
197f30491cSTony Luck 
207f30491cSTony Luck /*
217f30491cSTony Luck  * Addressing Terminology
227f30491cSTony Luck  *
237f30491cSTony Luck  *	M       - The low M bits of a physical address represent the offset
247f30491cSTony Luck  *		  into the blade local memory. RAM memory on a blade is physically
257f30491cSTony Luck  *		  contiguous (although various IO spaces may punch holes in
267f30491cSTony Luck  *		  it)..
277f30491cSTony Luck  *
287f30491cSTony Luck  * 	N	- Number of bits in the node portion of a socket physical
297f30491cSTony Luck  * 		  address.
307f30491cSTony Luck  *
317f30491cSTony Luck  * 	NASID   - network ID of a router, Mbrick or Cbrick. Nasid values of
327f30491cSTony Luck  * 	 	  routers always have low bit of 1, C/MBricks have low bit
337f30491cSTony Luck  * 		  equal to 0. Most addressing macros that target UV hub chips
347f30491cSTony Luck  * 		  right shift the NASID by 1 to exclude the always-zero bit.
357f30491cSTony Luck  * 		  NASIDs contain up to 15 bits.
367f30491cSTony Luck  *
377f30491cSTony Luck  *	GNODE   - NASID right shifted by 1 bit. Most mmrs contain gnodes instead
387f30491cSTony Luck  *		  of nasids.
397f30491cSTony Luck  *
407f30491cSTony Luck  * 	PNODE   - the low N bits of the GNODE. The PNODE is the most useful variant
417f30491cSTony Luck  * 		  of the nasid for socket usage.
427f30491cSTony Luck  *
437f30491cSTony Luck  *
447f30491cSTony Luck  *  NumaLink Global Physical Address Format:
457f30491cSTony Luck  *  +--------------------------------+---------------------+
467f30491cSTony Luck  *  |00..000|      GNODE             |      NodeOffset     |
477f30491cSTony Luck  *  +--------------------------------+---------------------+
487f30491cSTony Luck  *          |<-------53 - M bits --->|<--------M bits ----->
497f30491cSTony Luck  *
507f30491cSTony Luck  *	M - number of node offset bits (35 .. 40)
517f30491cSTony Luck  *
527f30491cSTony Luck  *
537f30491cSTony Luck  *  Memory/UV-HUB Processor Socket Address Format:
547f30491cSTony Luck  *  +----------------+---------------+---------------------+
557f30491cSTony Luck  *  |00..000000000000|   PNODE       |      NodeOffset     |
567f30491cSTony Luck  *  +----------------+---------------+---------------------+
577f30491cSTony Luck  *                   <--- N bits --->|<--------M bits ----->
587f30491cSTony Luck  *
597f30491cSTony Luck  *	M - number of node offset bits (35 .. 40)
607f30491cSTony Luck  *	N - number of PNODE bits (0 .. 10)
617f30491cSTony Luck  *
627f30491cSTony Luck  *		Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64).
637f30491cSTony Luck  *		The actual values are configuration dependent and are set at
647f30491cSTony Luck  *		boot time. M & N values are set by the hardware/BIOS at boot.
657f30491cSTony Luck  */
667f30491cSTony Luck 
677f30491cSTony Luck 
687f30491cSTony Luck /*
697f30491cSTony Luck  * Maximum number of bricks in all partitions and in all coherency domains.
707f30491cSTony Luck  * This is the total number of bricks accessible in the numalink fabric. It
717f30491cSTony Luck  * includes all C & M bricks. Routers are NOT included.
727f30491cSTony Luck  *
737f30491cSTony Luck  * This value is also the value of the maximum number of non-router NASIDs
747f30491cSTony Luck  * in the numalink fabric.
757f30491cSTony Luck  *
767f30491cSTony Luck  * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused.
777f30491cSTony Luck  */
787f30491cSTony Luck #define UV_MAX_NUMALINK_BLADES	16384
797f30491cSTony Luck 
807f30491cSTony Luck /*
817f30491cSTony Luck  * Maximum number of C/Mbricks within a software SSI (hardware may support
827f30491cSTony Luck  * more).
837f30491cSTony Luck  */
847f30491cSTony Luck #define UV_MAX_SSI_BLADES	1
857f30491cSTony Luck 
867f30491cSTony Luck /*
877f30491cSTony Luck  * The largest possible NASID of a C or M brick (+ 2)
887f30491cSTony Luck  */
897f30491cSTony Luck #define UV_MAX_NASID_VALUE	(UV_MAX_NUMALINK_NODES * 2)
907f30491cSTony Luck 
917f30491cSTony Luck /*
927f30491cSTony Luck  * The following defines attributes of the HUB chip. These attributes are
937f30491cSTony Luck  * frequently referenced and are kept in the per-cpu data areas of each cpu.
947f30491cSTony Luck  * They are kept together in a struct to minimize cache misses.
957f30491cSTony Luck  */
967f30491cSTony Luck struct uv_hub_info_s {
977f30491cSTony Luck 	unsigned long	global_mmr_base;
987f30491cSTony Luck 	unsigned long	gpa_mask;
997f30491cSTony Luck 	unsigned long	gnode_upper;
1007f30491cSTony Luck 	unsigned long	lowmem_remap_top;
1017f30491cSTony Luck 	unsigned long	lowmem_remap_base;
1027f30491cSTony Luck 	unsigned short	pnode;
1037f30491cSTony Luck 	unsigned short	pnode_mask;
1047f30491cSTony Luck 	unsigned short	coherency_domain_number;
1057f30491cSTony Luck 	unsigned short	numa_blade_id;
1067f30491cSTony Luck 	unsigned char	blade_processor_id;
1077f30491cSTony Luck 	unsigned char	m_val;
1087f30491cSTony Luck 	unsigned char	n_val;
1097f30491cSTony Luck };
1107f30491cSTony Luck DECLARE_PER_CPU(struct uv_hub_info_s, __uv_hub_info);
1116065a244SChristoph Lameter #define uv_hub_info 		this_cpu_ptr(&__uv_hub_info)
1127f30491cSTony Luck #define uv_cpu_hub_info(cpu)	(&per_cpu(__uv_hub_info, cpu))
1137f30491cSTony Luck 
1147f30491cSTony Luck /*
1157f30491cSTony Luck  * Local & Global MMR space macros.
1167f30491cSTony Luck  * 	Note: macros are intended to be used ONLY by inline functions
1177f30491cSTony Luck  * 	in this file - not by other kernel code.
1187f30491cSTony Luck  * 		n -  NASID (full 15-bit global nasid)
1197f30491cSTony Luck  * 		g -  GNODE (full 15-bit global nasid, right shifted 1)
1207f30491cSTony Luck  * 		p -  PNODE (local part of nsids, right shifted 1)
1217f30491cSTony Luck  */
1227f30491cSTony Luck #define UV_NASID_TO_PNODE(n)		(((n) >> 1) & uv_hub_info->pnode_mask)
1237f30491cSTony Luck #define UV_PNODE_TO_NASID(p)		(((p) << 1) | uv_hub_info->gnode_upper)
1247f30491cSTony Luck 
1257f30491cSTony Luck #define UV_LOCAL_MMR_BASE		0xf4000000UL
1267f30491cSTony Luck #define UV_GLOBAL_MMR32_BASE		0xf8000000UL
1277f30491cSTony Luck #define UV_GLOBAL_MMR64_BASE		(uv_hub_info->global_mmr_base)
1287f30491cSTony Luck 
1297f30491cSTony Luck #define UV_GLOBAL_MMR32_PNODE_SHIFT	15
1307f30491cSTony Luck #define UV_GLOBAL_MMR64_PNODE_SHIFT	26
1317f30491cSTony Luck 
1327f30491cSTony Luck #define UV_GLOBAL_MMR32_PNODE_BITS(p)	((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT))
1337f30491cSTony Luck 
1347f30491cSTony Luck #define UV_GLOBAL_MMR64_PNODE_BITS(p)					\
1357f30491cSTony Luck 	((unsigned long)(p) << UV_GLOBAL_MMR64_PNODE_SHIFT)
1367f30491cSTony Luck 
1377f30491cSTony Luck /*
1387f30491cSTony Luck  * Macros for converting between kernel virtual addresses, socket local physical
1397f30491cSTony Luck  * addresses, and UV global physical addresses.
1407f30491cSTony Luck  * 	Note: use the standard __pa() & __va() macros for converting
1417f30491cSTony Luck  * 	      between socket virtual and socket physical addresses.
1427f30491cSTony Luck  */
1437f30491cSTony Luck 
1447f30491cSTony Luck /* socket phys RAM --> UV global physical address */
uv_soc_phys_ram_to_gpa(unsigned long paddr)1457f30491cSTony Luck static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr)
1467f30491cSTony Luck {
1477f30491cSTony Luck 	if (paddr < uv_hub_info->lowmem_remap_top)
1487f30491cSTony Luck 		paddr += uv_hub_info->lowmem_remap_base;
1497f30491cSTony Luck 	return paddr | uv_hub_info->gnode_upper;
1507f30491cSTony Luck }
1517f30491cSTony Luck 
1527f30491cSTony Luck 
1537f30491cSTony Luck /* socket virtual --> UV global physical address */
uv_gpa(void * v)1547f30491cSTony Luck static inline unsigned long uv_gpa(void *v)
1557f30491cSTony Luck {
1567f30491cSTony Luck 	return __pa(v) | uv_hub_info->gnode_upper;
1577f30491cSTony Luck }
1587f30491cSTony Luck 
1597f30491cSTony Luck /* socket virtual --> UV global physical address */
uv_vgpa(void * v)1607f30491cSTony Luck static inline void *uv_vgpa(void *v)
1617f30491cSTony Luck {
1627f30491cSTony Luck 	return (void *)uv_gpa(v);
1637f30491cSTony Luck }
1647f30491cSTony Luck 
1657f30491cSTony Luck /* UV global physical address --> socket virtual */
uv_va(unsigned long gpa)1667f30491cSTony Luck static inline void *uv_va(unsigned long gpa)
1677f30491cSTony Luck {
1687f30491cSTony Luck 	return __va(gpa & uv_hub_info->gpa_mask);
1697f30491cSTony Luck }
1707f30491cSTony Luck 
1717f30491cSTony Luck /* pnode, offset --> socket virtual */
uv_pnode_offset_to_vaddr(int pnode,unsigned long offset)1727f30491cSTony Luck static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
1737f30491cSTony Luck {
1747f30491cSTony Luck 	return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset);
1757f30491cSTony Luck }
1767f30491cSTony Luck 
1777f30491cSTony Luck 
1787f30491cSTony Luck /*
1797f30491cSTony Luck  * Access global MMRs using the low memory MMR32 space. This region supports
1807f30491cSTony Luck  * faster MMR access but not all MMRs are accessible in this space.
1817f30491cSTony Luck  */
uv_global_mmr32_address(int pnode,unsigned long offset)1827f30491cSTony Luck static inline unsigned long *uv_global_mmr32_address(int pnode,
1837f30491cSTony Luck 				unsigned long offset)
1847f30491cSTony Luck {
1857f30491cSTony Luck 	return __va(UV_GLOBAL_MMR32_BASE |
1867f30491cSTony Luck 		       UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset);
1877f30491cSTony Luck }
1887f30491cSTony Luck 
uv_write_global_mmr32(int pnode,unsigned long offset,unsigned long val)1897f30491cSTony Luck static inline void uv_write_global_mmr32(int pnode, unsigned long offset,
1907f30491cSTony Luck 				 unsigned long val)
1917f30491cSTony Luck {
1927f30491cSTony Luck 	*uv_global_mmr32_address(pnode, offset) = val;
1937f30491cSTony Luck }
1947f30491cSTony Luck 
uv_read_global_mmr32(int pnode,unsigned long offset)1957f30491cSTony Luck static inline unsigned long uv_read_global_mmr32(int pnode,
1967f30491cSTony Luck 						 unsigned long offset)
1977f30491cSTony Luck {
1987f30491cSTony Luck 	return *uv_global_mmr32_address(pnode, offset);
1997f30491cSTony Luck }
2007f30491cSTony Luck 
2017f30491cSTony Luck /*
2027f30491cSTony Luck  * Access Global MMR space using the MMR space located at the top of physical
2037f30491cSTony Luck  * memory.
2047f30491cSTony Luck  */
uv_global_mmr64_address(int pnode,unsigned long offset)2057f30491cSTony Luck static inline unsigned long *uv_global_mmr64_address(int pnode,
2067f30491cSTony Luck 				unsigned long offset)
2077f30491cSTony Luck {
2087f30491cSTony Luck 	return __va(UV_GLOBAL_MMR64_BASE |
2097f30491cSTony Luck 		    UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
2107f30491cSTony Luck }
2117f30491cSTony Luck 
uv_write_global_mmr64(int pnode,unsigned long offset,unsigned long val)2127f30491cSTony Luck static inline void uv_write_global_mmr64(int pnode, unsigned long offset,
2137f30491cSTony Luck 				unsigned long val)
2147f30491cSTony Luck {
2157f30491cSTony Luck 	*uv_global_mmr64_address(pnode, offset) = val;
2167f30491cSTony Luck }
2177f30491cSTony Luck 
uv_read_global_mmr64(int pnode,unsigned long offset)2187f30491cSTony Luck static inline unsigned long uv_read_global_mmr64(int pnode,
2197f30491cSTony Luck 						 unsigned long offset)
2207f30491cSTony Luck {
2217f30491cSTony Luck 	return *uv_global_mmr64_address(pnode, offset);
2227f30491cSTony Luck }
2237f30491cSTony Luck 
2247f30491cSTony Luck /*
2257f30491cSTony Luck  * Access hub local MMRs. Faster than using global space but only local MMRs
2267f30491cSTony Luck  * are accessible.
2277f30491cSTony Luck  */
uv_local_mmr_address(unsigned long offset)2287f30491cSTony Luck static inline unsigned long *uv_local_mmr_address(unsigned long offset)
2297f30491cSTony Luck {
2307f30491cSTony Luck 	return __va(UV_LOCAL_MMR_BASE | offset);
2317f30491cSTony Luck }
2327f30491cSTony Luck 
uv_read_local_mmr(unsigned long offset)2337f30491cSTony Luck static inline unsigned long uv_read_local_mmr(unsigned long offset)
2347f30491cSTony Luck {
2357f30491cSTony Luck 	return *uv_local_mmr_address(offset);
2367f30491cSTony Luck }
2377f30491cSTony Luck 
uv_write_local_mmr(unsigned long offset,unsigned long val)2387f30491cSTony Luck static inline void uv_write_local_mmr(unsigned long offset, unsigned long val)
2397f30491cSTony Luck {
2407f30491cSTony Luck 	*uv_local_mmr_address(offset) = val;
2417f30491cSTony Luck }
2427f30491cSTony Luck 
2437f30491cSTony Luck /*
2447f30491cSTony Luck  * Structures and definitions for converting between cpu, node, pnode, and blade
2457f30491cSTony Luck  * numbers.
2467f30491cSTony Luck  */
2477f30491cSTony Luck 
2487f30491cSTony Luck /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */
uv_blade_processor_id(void)2497f30491cSTony Luck static inline int uv_blade_processor_id(void)
2507f30491cSTony Luck {
2517f30491cSTony Luck 	return smp_processor_id();
2527f30491cSTony Luck }
2537f30491cSTony Luck 
2547f30491cSTony Luck /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */
uv_numa_blade_id(void)2557f30491cSTony Luck static inline int uv_numa_blade_id(void)
2567f30491cSTony Luck {
2577f30491cSTony Luck 	return 0;
2587f30491cSTony Luck }
2597f30491cSTony Luck 
260*f589c67fSRandy Dunlap /* Convert a cpu number to the UV blade number */
uv_cpu_to_blade_id(int cpu)2617f30491cSTony Luck static inline int uv_cpu_to_blade_id(int cpu)
2627f30491cSTony Luck {
2637f30491cSTony Luck 	return 0;
2647f30491cSTony Luck }
2657f30491cSTony Luck 
2667f30491cSTony Luck /* Convert linux node number to the UV blade number */
uv_node_to_blade_id(int nid)2677f30491cSTony Luck static inline int uv_node_to_blade_id(int nid)
2687f30491cSTony Luck {
2697f30491cSTony Luck 	return 0;
2707f30491cSTony Luck }
2717f30491cSTony Luck 
2727f30491cSTony Luck /* Convert a blade id to the PNODE of the blade */
uv_blade_to_pnode(int bid)2737f30491cSTony Luck static inline int uv_blade_to_pnode(int bid)
2747f30491cSTony Luck {
2757f30491cSTony Luck 	return 0;
2767f30491cSTony Luck }
2777f30491cSTony Luck 
2787f30491cSTony Luck /* Determine the number of possible cpus on a blade */
uv_blade_nr_possible_cpus(int bid)2797f30491cSTony Luck static inline int uv_blade_nr_possible_cpus(int bid)
2807f30491cSTony Luck {
2817f30491cSTony Luck 	return num_possible_cpus();
2827f30491cSTony Luck }
2837f30491cSTony Luck 
2847f30491cSTony Luck /* Determine the number of online cpus on a blade */
uv_blade_nr_online_cpus(int bid)2857f30491cSTony Luck static inline int uv_blade_nr_online_cpus(int bid)
2867f30491cSTony Luck {
2877f30491cSTony Luck 	return num_online_cpus();
2887f30491cSTony Luck }
2897f30491cSTony Luck 
2907f30491cSTony Luck /* Convert a cpu id to the PNODE of the blade containing the cpu */
uv_cpu_to_pnode(int cpu)2917f30491cSTony Luck static inline int uv_cpu_to_pnode(int cpu)
2927f30491cSTony Luck {
2937f30491cSTony Luck 	return 0;
2947f30491cSTony Luck }
2957f30491cSTony Luck 
2967f30491cSTony Luck /* Convert a linux node number to the PNODE of the blade */
uv_node_to_pnode(int nid)2977f30491cSTony Luck static inline int uv_node_to_pnode(int nid)
2987f30491cSTony Luck {
2997f30491cSTony Luck 	return 0;
3007f30491cSTony Luck }
3017f30491cSTony Luck 
3027f30491cSTony Luck /* Maximum possible number of blades */
uv_num_possible_blades(void)3037f30491cSTony Luck static inline int uv_num_possible_blades(void)
3047f30491cSTony Luck {
3057f30491cSTony Luck 	return 1;
3067f30491cSTony Luck }
3077f30491cSTony Luck 
uv_hub_send_ipi(int pnode,int apicid,int vector)30866666e50SJack Steiner static inline void uv_hub_send_ipi(int pnode, int apicid, int vector)
30966666e50SJack Steiner {
31066666e50SJack Steiner 	/* not currently needed on ia64 */
31166666e50SJack Steiner }
31266666e50SJack Steiner 
31366666e50SJack Steiner 
3147f30491cSTony Luck #endif /* __ASM_IA64_UV_HUB__ */
3157f30491cSTony Luck 
316