xref: /openbmc/linux/arch/x86/include/asm/uv/uv_hub.h (revision de0038bf)
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>
224fb7d087SMike Travis #include <asm/uv/uv.h>
2366666e50SJack Steiner #include <asm/uv/uv_mmrs.h>
24c85375cdSMike Travis #include <asm/uv/bios.h>
2502dd0a06SRobin Holt #include <asm/irq_vectors.h>
2602dd0a06SRobin Holt #include <asm/io_apic.h>
27bb898558SAl Viro 
28bb898558SAl Viro 
29bb898558SAl Viro /*
30bb898558SAl Viro  * Addressing Terminology
31bb898558SAl Viro  *
32bb898558SAl Viro  *	M       - The low M bits of a physical address represent the offset
33bb898558SAl Viro  *		  into the blade local memory. RAM memory on a blade is physically
34bb898558SAl Viro  *		  contiguous (although various IO spaces may punch holes in
35bb898558SAl Viro  *		  it)..
36bb898558SAl Viro  *
37bb898558SAl Viro  *	N	- Number of bits in the node portion of a socket physical
38bb898558SAl Viro  *		  address.
39bb898558SAl Viro  *
40bb898558SAl Viro  *	NASID   - network ID of a router, Mbrick or Cbrick. Nasid values of
41bb898558SAl Viro  *		  routers always have low bit of 1, C/MBricks have low bit
42bb898558SAl Viro  *		  equal to 0. Most addressing macros that target UV hub chips
43bb898558SAl Viro  *		  right shift the NASID by 1 to exclude the always-zero bit.
44bb898558SAl Viro  *		  NASIDs contain up to 15 bits.
45bb898558SAl Viro  *
46bb898558SAl Viro  *	GNODE   - NASID right shifted by 1 bit. Most mmrs contain gnodes instead
47bb898558SAl Viro  *		  of nasids.
48bb898558SAl Viro  *
49bb898558SAl Viro  *	PNODE   - the low N bits of the GNODE. The PNODE is the most useful variant
50bb898558SAl Viro  *		  of the nasid for socket usage.
51bb898558SAl Viro  *
526a469e46SJack Steiner  *	GPA	- (global physical address) a socket physical address converted
536a469e46SJack Steiner  *		  so that it can be used by the GRU as a global address. Socket
546a469e46SJack Steiner  *		  physical addresses 1) need additional NASID (node) bits added
556a469e46SJack Steiner  *		  to the high end of the address, and 2) unaliased if the
566a469e46SJack Steiner  *		  partition does not have a physical address 0. In addition, on
576a469e46SJack Steiner  *		  UV2 rev 1, GPAs need the gnode left shifted to bits 39 or 40.
586a469e46SJack Steiner  *
59bb898558SAl Viro  *
60bb898558SAl Viro  *  NumaLink Global Physical Address Format:
61bb898558SAl Viro  *  +--------------------------------+---------------------+
62bb898558SAl Viro  *  |00..000|      GNODE             |      NodeOffset     |
63bb898558SAl Viro  *  +--------------------------------+---------------------+
64bb898558SAl Viro  *          |<-------53 - M bits --->|<--------M bits ----->
65bb898558SAl Viro  *
66bb898558SAl Viro  *	M - number of node offset bits (35 .. 40)
67bb898558SAl Viro  *
68bb898558SAl Viro  *
69bb898558SAl Viro  *  Memory/UV-HUB Processor Socket Address Format:
70bb898558SAl Viro  *  +----------------+---------------+---------------------+
71bb898558SAl Viro  *  |00..000000000000|   PNODE       |      NodeOffset     |
72bb898558SAl Viro  *  +----------------+---------------+---------------------+
73bb898558SAl Viro  *                   <--- N bits --->|<--------M bits ----->
74bb898558SAl Viro  *
75bb898558SAl Viro  *	M - number of node offset bits (35 .. 40)
76bb898558SAl Viro  *	N - number of PNODE bits (0 .. 10)
77bb898558SAl Viro  *
78bb898558SAl Viro  *		Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64).
79bb898558SAl Viro  *		The actual values are configuration dependent and are set at
80bb898558SAl Viro  *		boot time. M & N values are set by the hardware/BIOS at boot.
81bb898558SAl Viro  *
82bb898558SAl Viro  *
83bb898558SAl Viro  * APICID format
84bb898558SAl Viro  *	NOTE!!!!!! This is the current format of the APICID. However, code
85bb898558SAl Viro  *	should assume that this will change in the future. Use functions
86bb898558SAl Viro  *	in this file for all APICID bit manipulations and conversion.
87bb898558SAl Viro  *
88bb898558SAl Viro  *		1111110000000000
89bb898558SAl Viro  *		5432109876543210
902a919596SJack Steiner  *		pppppppppplc0cch	Nehalem-EX (12 bits in hdw reg)
912a919596SJack Steiner  *		ppppppppplcc0cch	Westmere-EX (12 bits in hdw reg)
922a919596SJack Steiner  *		pppppppppppcccch	SandyBridge (15 bits in hdw reg)
93bb898558SAl Viro  *		sssssssssss
94bb898558SAl Viro  *
95bb898558SAl Viro  *			p  = pnode bits
96bb898558SAl Viro  *			l =  socket number on board
97bb898558SAl Viro  *			c  = core
98bb898558SAl Viro  *			h  = hyperthread
99bb898558SAl Viro  *			s  = bits that are in the SOCKET_ID CSR
100bb898558SAl Viro  *
1012a919596SJack Steiner  *	Note: Processor may support fewer bits in the APICID register. The ACPI
102bb898558SAl Viro  *	      tables hold all 16 bits. Software needs to be aware of this.
103bb898558SAl Viro  *
104bb898558SAl Viro  *	      Unless otherwise specified, all references to APICID refer to
105bb898558SAl Viro  *	      the FULL value contained in ACPI tables, not the subset in the
106bb898558SAl Viro  *	      processor APICID register.
107bb898558SAl Viro  */
108bb898558SAl Viro 
109bb898558SAl Viro /*
110bb898558SAl Viro  * Maximum number of bricks in all partitions and in all coherency domains.
111bb898558SAl Viro  * This is the total number of bricks accessible in the numalink fabric. It
112bb898558SAl Viro  * includes all C & M bricks. Routers are NOT included.
113bb898558SAl Viro  *
114bb898558SAl Viro  * This value is also the value of the maximum number of non-router NASIDs
115bb898558SAl Viro  * in the numalink fabric.
116bb898558SAl Viro  *
117bb898558SAl Viro  * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused.
118bb898558SAl Viro  */
119bb898558SAl Viro #define UV_MAX_NUMALINK_BLADES	16384
120bb898558SAl Viro 
121bb898558SAl Viro /*
122bb898558SAl Viro  * Maximum number of C/Mbricks within a software SSI (hardware may support
123bb898558SAl Viro  * more).
124bb898558SAl Viro  */
125bb898558SAl Viro #define UV_MAX_SSI_BLADES	256
126bb898558SAl Viro 
127bb898558SAl Viro /*
128bb898558SAl Viro  * The largest possible NASID of a C or M brick (+ 2)
129bb898558SAl Viro  */
1301d21e6e3SRobin Holt #define UV_MAX_NASID_VALUE	(UV_MAX_NUMALINK_BLADES * 2)
131bb898558SAl Viro 
132d38bb135SMike Travis /* System Controller Interface Reg info */
1337f1baa06SMike Travis struct uv_scir_s {
1347f1baa06SMike Travis 	struct timer_list timer;
1357f1baa06SMike Travis 	unsigned long	offset;
1367f1baa06SMike Travis 	unsigned long	last;
1377f1baa06SMike Travis 	unsigned long	idle_on;
1387f1baa06SMike Travis 	unsigned long	idle_off;
1397f1baa06SMike Travis 	unsigned char	state;
1407f1baa06SMike Travis 	unsigned char	enabled;
1417f1baa06SMike Travis };
1427f1baa06SMike Travis 
143c85375cdSMike Travis /* GAM (globally addressed memory) range table */
144c85375cdSMike Travis struct uv_gam_range_s {
145c85375cdSMike Travis 	u32	limit;		/* PA bits 56:26 (GAM_RANGE_SHFT) */
146c85375cdSMike Travis 	u16	nasid;		/* node's global physical address */
147c85375cdSMike Travis 	s8	base;		/* entry index of node's base addr */
148c85375cdSMike Travis 	u8	reserved;
149c85375cdSMike Travis };
150c85375cdSMike Travis 
151bb898558SAl Viro /*
152bb898558SAl Viro  * The following defines attributes of the HUB chip. These attributes are
1530045ddd2SMike Travis  * frequently referenced and are kept in a common per hub struct.
1540045ddd2SMike Travis  * After setup, the struct is read only, so it should be readily
1550045ddd2SMike Travis  * available in the L3 cache on the cpu socket for the node.
156bb898558SAl Viro  */
157bb898558SAl Viro struct uv_hub_info_s {
158bb898558SAl Viro 	unsigned long		global_mmr_base;
1591de329c1SMike Travis 	unsigned long		global_mmr_shift;
160bb898558SAl Viro 	unsigned long		gpa_mask;
1616e27b91cSMike Travis 	unsigned short		*socket_to_node;
1626e27b91cSMike Travis 	unsigned short		*socket_to_pnode;
1636e27b91cSMike Travis 	unsigned short		*pnode_to_socket;
164c85375cdSMike Travis 	struct uv_gam_range_s	*gr_table;
1651de329c1SMike Travis 	unsigned short		min_socket;
1661de329c1SMike Travis 	unsigned short		min_pnode;
167c85375cdSMike Travis 	unsigned char		m_val;
168c85375cdSMike Travis 	unsigned char		n_val;
169c85375cdSMike Travis 	unsigned char		gr_table_len;
1702a919596SJack Steiner 	unsigned char		hub_revision;
1712a919596SJack Steiner 	unsigned char		apic_pnode_shift;
1721de329c1SMike Travis 	unsigned char		gpa_shift;
1736a469e46SJack Steiner 	unsigned char		m_shift;
1746a469e46SJack Steiner 	unsigned char		n_lshift;
1751de329c1SMike Travis 	unsigned int		gnode_extra;
176bb898558SAl Viro 	unsigned long		gnode_upper;
177bb898558SAl Viro 	unsigned long		lowmem_remap_top;
178bb898558SAl Viro 	unsigned long		lowmem_remap_base;
1791de329c1SMike Travis 	unsigned long		global_gru_base;
1801de329c1SMike Travis 	unsigned long		global_gru_shift;
181bb898558SAl Viro 	unsigned short		pnode;
182bb898558SAl Viro 	unsigned short		pnode_mask;
183bb898558SAl Viro 	unsigned short		coherency_domain_number;
184bb898558SAl Viro 	unsigned short		numa_blade_id;
185906f3b20SMike Travis 	unsigned short		nr_possible_cpus;
186906f3b20SMike Travis 	unsigned short		nr_online_cpus;
187906f3b20SMike Travis 	short			memory_nid;
188bb898558SAl Viro };
1897f1baa06SMike Travis 
1900045ddd2SMike Travis /* CPU specific info with a pointer to the hub common info struct */
1910045ddd2SMike Travis struct uv_cpu_info_s {
1920045ddd2SMike Travis 	void			*p_uv_hub_info;
1930045ddd2SMike Travis 	unsigned char		blade_cpu_id;
1940045ddd2SMike Travis 	struct uv_scir_s	scir;
1950045ddd2SMike Travis };
1960045ddd2SMike Travis DECLARE_PER_CPU(struct uv_cpu_info_s, __uv_cpu_info);
1970045ddd2SMike Travis 
1980045ddd2SMike Travis #define uv_cpu_info		this_cpu_ptr(&__uv_cpu_info)
1990045ddd2SMike Travis #define uv_cpu_info_per(cpu)	(&per_cpu(__uv_cpu_info, cpu))
2000045ddd2SMike Travis 
201d38bb135SMike Travis #define	uv_scir_info		(&uv_cpu_info->scir)
202d38bb135SMike Travis #define	uv_cpu_scir_info(cpu)	(&uv_cpu_info_per(cpu)->scir)
203d38bb135SMike Travis 
2043edcf2ffSMike Travis /* Node specific hub common info struct */
2053edcf2ffSMike Travis extern void **__uv_hub_info_list;
2063edcf2ffSMike Travis static inline struct uv_hub_info_s *uv_hub_info_list(int node)
2073edcf2ffSMike Travis {
2083edcf2ffSMike Travis 	return (struct uv_hub_info_s *)__uv_hub_info_list[node];
2093edcf2ffSMike Travis }
2103edcf2ffSMike Travis 
2113edcf2ffSMike Travis static inline struct uv_hub_info_s *_uv_hub_info(void)
2123edcf2ffSMike Travis {
2133edcf2ffSMike Travis 	return (struct uv_hub_info_s *)uv_cpu_info->p_uv_hub_info;
2143edcf2ffSMike Travis }
2153edcf2ffSMike Travis #define	uv_hub_info	_uv_hub_info()
2163edcf2ffSMike Travis 
2173edcf2ffSMike Travis static inline struct uv_hub_info_s *uv_cpu_hub_info(int cpu)
2183edcf2ffSMike Travis {
2193edcf2ffSMike Travis 	return (struct uv_hub_info_s *)uv_cpu_info_per(cpu)->p_uv_hub_info;
2203edcf2ffSMike Travis }
2213edcf2ffSMike Travis 
2222a919596SJack Steiner /*
2230045ddd2SMike Travis  * HUB revision ranges for each UV HUB architecture.
2242a919596SJack Steiner  * This is a software convention - NOT the hardware revision numbers in
2252a919596SJack Steiner  * the hub chip.
2262a919596SJack Steiner  */
2272a919596SJack Steiner #define UV1_HUB_REVISION_BASE		1
2282a919596SJack Steiner #define UV2_HUB_REVISION_BASE		3
2296edbd471SMike Travis #define UV3_HUB_REVISION_BASE		5
230eb1e3461SMike Travis #define UV4_HUB_REVISION_BASE		7
2318078d195SMike Travis #define UV4A_HUB_REVISION_BASE		8	/* UV4 (fixed) rev 2 */
2322a919596SJack Steiner 
2334fb7d087SMike Travis static inline int is_uv1_hub(void)
2344fb7d087SMike Travis {
2354fb7d087SMike Travis 	return is_uv_hubbed(uv(1));
2364fb7d087SMike Travis }
2372a919596SJack Steiner 
2384fb7d087SMike Travis static inline int is_uv2_hub(void)
2394fb7d087SMike Travis {
2404fb7d087SMike Travis 	return is_uv_hubbed(uv(2));
2414fb7d087SMike Travis }
2426edbd471SMike Travis 
2434fb7d087SMike Travis static inline int is_uv3_hub(void)
2444fb7d087SMike Travis {
2454fb7d087SMike Travis 	return is_uv_hubbed(uv(3));
2464fb7d087SMike Travis }
2476edbd471SMike Travis 
2488078d195SMike Travis /* First test "is UV4A", then "is UV4" */
2494fb7d087SMike Travis static inline int is_uv4a_hub(void)
2504fb7d087SMike Travis {
2514fb7d087SMike Travis 	if (is_uv_hubbed(uv(4)))
2524fb7d087SMike Travis 		return (uv_hub_info->hub_revision == UV4A_HUB_REVISION_BASE);
2538078d195SMike Travis 	return 0;
2548078d195SMike Travis }
2558078d195SMike Travis 
2564fb7d087SMike Travis static inline int is_uv4_hub(void)
2574fb7d087SMike Travis {
2584fb7d087SMike Travis 	return is_uv_hubbed(uv(4));
2594fb7d087SMike Travis }
260eb1e3461SMike Travis 
2616edbd471SMike Travis static inline int is_uvx_hub(void)
2626edbd471SMike Travis {
2634fb7d087SMike Travis 	return (is_uv_hubbed(-2) >= uv(2));
264e0ee1c97SMike Travis }
265e0ee1c97SMike Travis 
266e0ee1c97SMike Travis static inline int is_uv_hub(void)
267e0ee1c97SMike Travis {
2684fb7d087SMike Travis 	return is_uv1_hub() || is_uvx_hub();
2692a919596SJack Steiner }
2702a919596SJack Steiner 
271c8f730b1SRuss Anderson union uvh_apicid {
272c8f730b1SRuss Anderson     unsigned long       v;
273c8f730b1SRuss Anderson     struct uvh_apicid_s {
274c8f730b1SRuss Anderson         unsigned long   local_apic_mask  : 24;
275c8f730b1SRuss Anderson         unsigned long   local_apic_shift :  5;
276c8f730b1SRuss Anderson         unsigned long   unused1          :  3;
277c8f730b1SRuss Anderson         unsigned long   pnode_mask       : 24;
278c8f730b1SRuss Anderson         unsigned long   pnode_shift      :  5;
279c8f730b1SRuss Anderson         unsigned long   unused2          :  3;
280c8f730b1SRuss Anderson     } s;
281c8f730b1SRuss Anderson };
282c8f730b1SRuss Anderson 
283bb898558SAl Viro /*
284bb898558SAl Viro  * Local & Global MMR space macros.
285bb898558SAl Viro  *	Note: macros are intended to be used ONLY by inline functions
286bb898558SAl Viro  *	in this file - not by other kernel code.
287bb898558SAl Viro  *		n -  NASID (full 15-bit global nasid)
288bb898558SAl Viro  *		g -  GNODE (full 15-bit global nasid, right shifted 1)
289bb898558SAl Viro  *		p -  PNODE (local part of nsids, right shifted 1)
290bb898558SAl Viro  */
291bb898558SAl Viro #define UV_NASID_TO_PNODE(n)		(((n) >> 1) & uv_hub_info->pnode_mask)
292c4ed3f04SJack Steiner #define UV_PNODE_TO_GNODE(p)		((p) |uv_hub_info->gnode_extra)
293c4ed3f04SJack Steiner #define UV_PNODE_TO_NASID(p)		(UV_PNODE_TO_GNODE(p) << 1)
294bb898558SAl Viro 
2952a919596SJack Steiner #define UV1_LOCAL_MMR_BASE		0xf4000000UL
2962a919596SJack Steiner #define UV1_GLOBAL_MMR32_BASE		0xf8000000UL
2972a919596SJack Steiner #define UV1_LOCAL_MMR_SIZE		(64UL * 1024 * 1024)
2982a919596SJack Steiner #define UV1_GLOBAL_MMR32_SIZE		(64UL * 1024 * 1024)
2992a919596SJack Steiner 
3002a919596SJack Steiner #define UV2_LOCAL_MMR_BASE		0xfa000000UL
3012a919596SJack Steiner #define UV2_GLOBAL_MMR32_BASE		0xfc000000UL
3022a919596SJack Steiner #define UV2_LOCAL_MMR_SIZE		(32UL * 1024 * 1024)
3032a919596SJack Steiner #define UV2_GLOBAL_MMR32_SIZE		(32UL * 1024 * 1024)
3042a919596SJack Steiner 
3056edbd471SMike Travis #define UV3_LOCAL_MMR_BASE		0xfa000000UL
3066edbd471SMike Travis #define UV3_GLOBAL_MMR32_BASE		0xfc000000UL
3076edbd471SMike Travis #define UV3_LOCAL_MMR_SIZE		(32UL * 1024 * 1024)
3086edbd471SMike Travis #define UV3_GLOBAL_MMR32_SIZE		(32UL * 1024 * 1024)
3096edbd471SMike Travis 
310eb1e3461SMike Travis #define UV4_LOCAL_MMR_BASE		0xfa000000UL
311eb1e3461SMike Travis #define UV4_GLOBAL_MMR32_BASE		0xfc000000UL
312eb1e3461SMike Travis #define UV4_LOCAL_MMR_SIZE		(32UL * 1024 * 1024)
313eb1e3461SMike Travis #define UV4_GLOBAL_MMR32_SIZE		(16UL * 1024 * 1024)
314eb1e3461SMike Travis 
315eb1e3461SMike Travis #define UV_LOCAL_MMR_BASE		(				\
316eb1e3461SMike Travis 					is_uv1_hub() ? UV1_LOCAL_MMR_BASE : \
317eb1e3461SMike Travis 					is_uv2_hub() ? UV2_LOCAL_MMR_BASE : \
318eb1e3461SMike Travis 					is_uv3_hub() ? UV3_LOCAL_MMR_BASE : \
319eb1e3461SMike Travis 					/*is_uv4_hub*/ UV4_LOCAL_MMR_BASE)
320eb1e3461SMike Travis 
321eb1e3461SMike Travis #define UV_GLOBAL_MMR32_BASE		(				\
322eb1e3461SMike Travis 					is_uv1_hub() ? UV1_GLOBAL_MMR32_BASE : \
323eb1e3461SMike Travis 					is_uv2_hub() ? UV2_GLOBAL_MMR32_BASE : \
324eb1e3461SMike Travis 					is_uv3_hub() ? UV3_GLOBAL_MMR32_BASE : \
325eb1e3461SMike Travis 					/*is_uv4_hub*/ UV4_GLOBAL_MMR32_BASE)
326eb1e3461SMike Travis 
327eb1e3461SMike Travis #define UV_LOCAL_MMR_SIZE		(				\
328eb1e3461SMike Travis 					is_uv1_hub() ? UV1_LOCAL_MMR_SIZE : \
329eb1e3461SMike Travis 					is_uv2_hub() ? UV2_LOCAL_MMR_SIZE : \
330eb1e3461SMike Travis 					is_uv3_hub() ? UV3_LOCAL_MMR_SIZE : \
331eb1e3461SMike Travis 					/*is_uv4_hub*/ UV4_LOCAL_MMR_SIZE)
332eb1e3461SMike Travis 
333eb1e3461SMike Travis #define UV_GLOBAL_MMR32_SIZE		(				\
334eb1e3461SMike Travis 					is_uv1_hub() ? UV1_GLOBAL_MMR32_SIZE : \
335eb1e3461SMike Travis 					is_uv2_hub() ? UV2_GLOBAL_MMR32_SIZE : \
336eb1e3461SMike Travis 					is_uv3_hub() ? UV3_GLOBAL_MMR32_SIZE : \
337eb1e3461SMike Travis 					/*is_uv4_hub*/ UV4_GLOBAL_MMR32_SIZE)
338eb1e3461SMike Travis 
339bb898558SAl Viro #define UV_GLOBAL_MMR64_BASE		(uv_hub_info->global_mmr_base)
340bb898558SAl Viro 
34156abcf24SJack Steiner #define UV_GLOBAL_GRU_MMR_BASE		0x4000000
34256abcf24SJack Steiner 
343bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_SHIFT	15
3441de329c1SMike Travis #define _UV_GLOBAL_MMR64_PNODE_SHIFT	26
3451de329c1SMike Travis #define UV_GLOBAL_MMR64_PNODE_SHIFT	(uv_hub_info->global_mmr_shift)
346bb898558SAl Viro 
347bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_BITS(p)	((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT))
348bb898558SAl Viro 
349bb898558SAl Viro #define UV_GLOBAL_MMR64_PNODE_BITS(p)					\
35067e83f30SJack Steiner 	(((unsigned long)(p)) << UV_GLOBAL_MMR64_PNODE_SHIFT)
351bb898558SAl Viro 
352c8f730b1SRuss Anderson #define UVH_APICID		0x002D0E00L
353bb898558SAl Viro #define UV_APIC_PNODE_SHIFT	6
354bb898558SAl Viro 
3558191c9f6SDimitri Sivanich #define UV_APICID_HIBIT_MASK	0xffff0000
3568191c9f6SDimitri Sivanich 
3577f1baa06SMike Travis /* Local Bus from cpu's perspective */
3587f1baa06SMike Travis #define LOCAL_BUS_BASE		0x1c00000
3597f1baa06SMike Travis #define LOCAL_BUS_SIZE		(4 * 1024 * 1024)
3607f1baa06SMike Travis 
3617f1baa06SMike Travis /*
3627f1baa06SMike Travis  * System Controller Interface Reg
3637f1baa06SMike Travis  *
3647f1baa06SMike Travis  * Note there are NO leds on a UV system.  This register is only
3657f1baa06SMike Travis  * used by the system controller to monitor system-wide operation.
3667f1baa06SMike Travis  * There are 64 regs per node.  With Nahelem cpus (2 cores per node,
3677f1baa06SMike Travis  * 8 cpus per core, 2 threads per cpu) there are 32 cpu threads on
3687f1baa06SMike Travis  * a node.
3697f1baa06SMike Travis  *
3707f1baa06SMike Travis  * The window is located at top of ACPI MMR space
3717f1baa06SMike Travis  */
3727f1baa06SMike Travis #define SCIR_WINDOW_COUNT	64
3737f1baa06SMike Travis #define SCIR_LOCAL_MMR_BASE	(LOCAL_BUS_BASE + \
3747f1baa06SMike Travis 				 LOCAL_BUS_SIZE - \
3757f1baa06SMike Travis 				 SCIR_WINDOW_COUNT)
3767f1baa06SMike Travis 
3777f1baa06SMike Travis #define SCIR_CPU_HEARTBEAT	0x01	/* timer interrupt */
3787f1baa06SMike Travis #define SCIR_CPU_ACTIVITY	0x02	/* not idle */
3797f1baa06SMike Travis #define SCIR_CPU_HB_INTERVAL	(HZ)	/* once per second */
3807f1baa06SMike Travis 
3818661984fSDimitri Sivanich /* Loop through all installed blades */
3828661984fSDimitri Sivanich #define for_each_possible_blade(bid)		\
3838661984fSDimitri Sivanich 	for ((bid) = 0; (bid) < uv_num_possible_blades(); (bid)++)
3848661984fSDimitri Sivanich 
385bb898558SAl Viro /*
386bb898558SAl Viro  * Macros for converting between kernel virtual addresses, socket local physical
387bb898558SAl Viro  * addresses, and UV global physical addresses.
388bb898558SAl Viro  *	Note: use the standard __pa() & __va() macros for converting
389bb898558SAl Viro  *	      between socket virtual and socket physical addresses.
390bb898558SAl Viro  */
391bb898558SAl Viro 
392c85375cdSMike Travis /* global bits offset - number of local address bits in gpa for this UV arch */
393c85375cdSMike Travis static inline unsigned int uv_gpa_shift(void)
394c85375cdSMike Travis {
395c85375cdSMike Travis 	return uv_hub_info->gpa_shift;
396c85375cdSMike Travis }
397c85375cdSMike Travis #define	_uv_gpa_shift
398c85375cdSMike Travis 
399c85375cdSMike Travis /* Find node that has the address range that contains global address  */
400c85375cdSMike Travis static inline struct uv_gam_range_s *uv_gam_range(unsigned long pa)
401c85375cdSMike Travis {
402c85375cdSMike Travis 	struct uv_gam_range_s *gr = uv_hub_info->gr_table;
403c85375cdSMike Travis 	unsigned long pal = (pa & uv_hub_info->gpa_mask) >> UV_GAM_RANGE_SHFT;
404c85375cdSMike Travis 	int i, num = uv_hub_info->gr_table_len;
405c85375cdSMike Travis 
406c85375cdSMike Travis 	if (gr) {
407c85375cdSMike Travis 		for (i = 0; i < num; i++, gr++) {
408c85375cdSMike Travis 			if (pal < gr->limit)
409c85375cdSMike Travis 				return gr;
410c85375cdSMike Travis 		}
411c85375cdSMike Travis 	}
412c85375cdSMike Travis 	pr_crit("UV: GAM Range for 0x%lx not found at %p!\n", pa, gr);
413c85375cdSMike Travis 	BUG();
414c85375cdSMike Travis }
415c85375cdSMike Travis 
416c85375cdSMike Travis /* Return base address of node that contains global address  */
417c85375cdSMike Travis static inline unsigned long uv_gam_range_base(unsigned long pa)
418c85375cdSMike Travis {
419c85375cdSMike Travis 	struct uv_gam_range_s *gr = uv_gam_range(pa);
420c85375cdSMike Travis 	int base = gr->base;
421c85375cdSMike Travis 
422c85375cdSMike Travis 	if (base < 0)
423c85375cdSMike Travis 		return 0UL;
424c85375cdSMike Travis 
425c85375cdSMike Travis 	return uv_hub_info->gr_table[base].limit;
426c85375cdSMike Travis }
427c85375cdSMike Travis 
428c85375cdSMike Travis /* socket phys RAM --> UV global NASID (UV4+) */
429c85375cdSMike Travis static inline unsigned long uv_soc_phys_ram_to_nasid(unsigned long paddr)
430c85375cdSMike Travis {
431c85375cdSMike Travis 	return uv_gam_range(paddr)->nasid;
432c85375cdSMike Travis }
433c85375cdSMike Travis #define	_uv_soc_phys_ram_to_nasid
434c85375cdSMike Travis 
435c85375cdSMike Travis /* socket virtual --> UV global NASID (UV4+) */
436c85375cdSMike Travis static inline unsigned long uv_gpa_nasid(void *v)
437c85375cdSMike Travis {
438c85375cdSMike Travis 	return uv_soc_phys_ram_to_nasid(__pa(v));
439c85375cdSMike Travis }
440c85375cdSMike Travis 
441bb898558SAl Viro /* socket phys RAM --> UV global physical address */
442bb898558SAl Viro static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr)
443bb898558SAl Viro {
444c85375cdSMike Travis 	unsigned int m_val = uv_hub_info->m_val;
445c85375cdSMike Travis 
446bb898558SAl Viro 	if (paddr < uv_hub_info->lowmem_remap_top)
447189f67c4SJack Steiner 		paddr |= uv_hub_info->lowmem_remap_base;
448ad483005SMike Travis 
449ad483005SMike Travis 	if (m_val) {
4506a469e46SJack Steiner 		paddr |= uv_hub_info->gnode_upper;
451c85375cdSMike Travis 		paddr = ((paddr << uv_hub_info->m_shift)
452c85375cdSMike Travis 						>> uv_hub_info->m_shift) |
453c85375cdSMike Travis 			((paddr >> uv_hub_info->m_val)
454c85375cdSMike Travis 						<< uv_hub_info->n_lshift);
455ad483005SMike Travis 	} else {
456c85375cdSMike Travis 		paddr |= uv_soc_phys_ram_to_nasid(paddr)
457c85375cdSMike Travis 						<< uv_hub_info->gpa_shift;
458ad483005SMike Travis 	}
4596a469e46SJack Steiner 	return paddr;
460bb898558SAl Viro }
461bb898558SAl Viro 
462bb898558SAl Viro /* socket virtual --> UV global physical address */
463bb898558SAl Viro static inline unsigned long uv_gpa(void *v)
464bb898558SAl Viro {
465189f67c4SJack Steiner 	return uv_soc_phys_ram_to_gpa(__pa(v));
466bb898558SAl Viro }
467bb898558SAl Viro 
468fae419f2SRobin Holt /* Top two bits indicate the requested address is in MMR space.  */
469fae419f2SRobin Holt static inline int
470fae419f2SRobin Holt uv_gpa_in_mmr_space(unsigned long gpa)
471fae419f2SRobin Holt {
472fae419f2SRobin Holt 	return (gpa >> 62) == 0x3UL;
473fae419f2SRobin Holt }
474fae419f2SRobin Holt 
475729d69e6SRobin Holt /* UV global physical address --> socket phys RAM */
476729d69e6SRobin Holt static inline unsigned long uv_gpa_to_soc_phys_ram(unsigned long gpa)
477729d69e6SRobin Holt {
4785a51467bSRuss Anderson 	unsigned long paddr;
479729d69e6SRobin Holt 	unsigned long remap_base = uv_hub_info->lowmem_remap_base;
480729d69e6SRobin Holt 	unsigned long remap_top =  uv_hub_info->lowmem_remap_top;
481c85375cdSMike Travis 	unsigned int m_val = uv_hub_info->m_val;
482729d69e6SRobin Holt 
483c85375cdSMike Travis 	if (m_val)
4846a469e46SJack Steiner 		gpa = ((gpa << uv_hub_info->m_shift) >> uv_hub_info->m_shift) |
4856a469e46SJack Steiner 			((gpa >> uv_hub_info->n_lshift) << uv_hub_info->m_val);
486c85375cdSMike Travis 
4875a51467bSRuss Anderson 	paddr = gpa & uv_hub_info->gpa_mask;
488729d69e6SRobin Holt 	if (paddr >= remap_base && paddr < remap_base + remap_top)
489729d69e6SRobin Holt 		paddr -= remap_base;
490729d69e6SRobin Holt 	return paddr;
491729d69e6SRobin Holt }
492729d69e6SRobin Holt 
493906f3b20SMike Travis /* gpa -> gnode */
4941d21e6e3SRobin Holt static inline unsigned long uv_gpa_to_gnode(unsigned long gpa)
4951d21e6e3SRobin Holt {
496c85375cdSMike Travis 	unsigned int n_lshift = uv_hub_info->n_lshift;
497c85375cdSMike Travis 
498c85375cdSMike Travis 	if (n_lshift)
499c85375cdSMike Travis 		return gpa >> n_lshift;
500c85375cdSMike Travis 
501c85375cdSMike Travis 	return uv_gam_range(gpa)->nasid >> 1;
5021d21e6e3SRobin Holt }
5031d21e6e3SRobin Holt 
5041d21e6e3SRobin Holt /* gpa -> pnode */
5051d21e6e3SRobin Holt static inline int uv_gpa_to_pnode(unsigned long gpa)
5061d21e6e3SRobin Holt {
507906f3b20SMike Travis 	return uv_gpa_to_gnode(gpa) & uv_hub_info->pnode_mask;
5081d21e6e3SRobin Holt }
5091d21e6e3SRobin Holt 
5106a469e46SJack Steiner /* gpa -> node offset */
5116a469e46SJack Steiner static inline unsigned long uv_gpa_to_offset(unsigned long gpa)
5126a469e46SJack Steiner {
513c85375cdSMike Travis 	unsigned int m_shift = uv_hub_info->m_shift;
514c85375cdSMike Travis 
515c85375cdSMike Travis 	if (m_shift)
516c85375cdSMike Travis 		return (gpa << m_shift) >> m_shift;
517c85375cdSMike Travis 
518c85375cdSMike Travis 	return (gpa & uv_hub_info->gpa_mask) - uv_gam_range_base(gpa);
519c85375cdSMike Travis }
520c85375cdSMike Travis 
521c85375cdSMike Travis /* Convert socket to node */
522c85375cdSMike Travis static inline int _uv_socket_to_node(int socket, unsigned short *s2nid)
523c85375cdSMike Travis {
524c85375cdSMike Travis 	return s2nid ? s2nid[socket - uv_hub_info->min_socket] : socket;
525c85375cdSMike Travis }
526c85375cdSMike Travis 
527c85375cdSMike Travis static inline int uv_socket_to_node(int socket)
528c85375cdSMike Travis {
529c85375cdSMike Travis 	return _uv_socket_to_node(socket, uv_hub_info->socket_to_node);
5306a469e46SJack Steiner }
5316a469e46SJack Steiner 
532bb898558SAl Viro /* pnode, offset --> socket virtual */
533bb898558SAl Viro static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
534bb898558SAl Viro {
535c85375cdSMike Travis 	unsigned int m_val = uv_hub_info->m_val;
536c85375cdSMike Travis 	unsigned long base;
537c85375cdSMike Travis 	unsigned short sockid, node, *p2s;
538bb898558SAl Viro 
539c85375cdSMike Travis 	if (m_val)
540c85375cdSMike Travis 		return __va(((unsigned long)pnode << m_val) | offset);
5416e27b91cSMike Travis 
542c85375cdSMike Travis 	p2s = uv_hub_info->pnode_to_socket;
543c85375cdSMike Travis 	sockid = p2s ? p2s[pnode - uv_hub_info->min_pnode] : pnode;
544c85375cdSMike Travis 	node = uv_socket_to_node(sockid);
545c85375cdSMike Travis 
546c85375cdSMike Travis 	/* limit address of previous socket is our base, except node 0 is 0 */
547c85375cdSMike Travis 	if (!node)
548c85375cdSMike Travis 		return __va((unsigned long)offset);
549c85375cdSMike Travis 
550c85375cdSMike Travis 	base = (unsigned long)(uv_hub_info->gr_table[node - 1].limit);
551c85375cdSMike Travis 	return __va(base << UV_GAM_RANGE_SHFT | offset);
5526e27b91cSMike Travis }
5536e27b91cSMike Travis 
5546e27b91cSMike Travis /* Extract/Convert a PNODE from an APICID (full apicid, not processor subset) */
555bb898558SAl Viro static inline int uv_apicid_to_pnode(int apicid)
556bb898558SAl Viro {
5576e27b91cSMike Travis 	int pnode = apicid >> uv_hub_info->apic_pnode_shift;
5586e27b91cSMike Travis 	unsigned short *s2pn = uv_hub_info->socket_to_pnode;
5596e27b91cSMike Travis 
5606e27b91cSMike Travis 	return s2pn ? s2pn[pnode - uv_hub_info->min_socket] : pnode;
561bb898558SAl Viro }
562bb898558SAl Viro 
563906f3b20SMike Travis /* Convert an apicid to the socket number on the blade */
5642a919596SJack Steiner static inline int uv_apicid_to_socket(int apicid)
5652a919596SJack Steiner {
5662a919596SJack Steiner 	if (is_uv1_hub())
5672a919596SJack Steiner 		return (apicid >> (uv_hub_info->apic_pnode_shift - 1)) & 1;
5682a919596SJack Steiner 	else
5692a919596SJack Steiner 		return 0;
5702a919596SJack Steiner }
5712a919596SJack Steiner 
5722a919596SJack Steiner /*
573bb898558SAl Viro  * Access global MMRs using the low memory MMR32 space. This region supports
574bb898558SAl Viro  * faster MMR access but not all MMRs are accessible in this space.
575bb898558SAl Viro  */
57639d30770SMike Travis static inline unsigned long *uv_global_mmr32_address(int pnode, unsigned long offset)
577bb898558SAl Viro {
578bb898558SAl Viro 	return __va(UV_GLOBAL_MMR32_BASE |
579bb898558SAl Viro 		       UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset);
580bb898558SAl Viro }
581bb898558SAl Viro 
58239d30770SMike Travis static inline void uv_write_global_mmr32(int pnode, unsigned long offset, unsigned long val)
583bb898558SAl Viro {
5848dc579e8SJack Steiner 	writeq(val, uv_global_mmr32_address(pnode, offset));
585bb898558SAl Viro }
586bb898558SAl Viro 
58739d30770SMike Travis static inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset)
588bb898558SAl Viro {
5898dc579e8SJack Steiner 	return readq(uv_global_mmr32_address(pnode, offset));
590bb898558SAl Viro }
591bb898558SAl Viro 
592bb898558SAl Viro /*
593bb898558SAl Viro  * Access Global MMR space using the MMR space located at the top of physical
594bb898558SAl Viro  * memory.
595bb898558SAl Viro  */
596a289cc7cSRandy Dunlap static inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset)
597bb898558SAl Viro {
598bb898558SAl Viro 	return __va(UV_GLOBAL_MMR64_BASE |
599bb898558SAl Viro 		    UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
600bb898558SAl Viro }
601bb898558SAl Viro 
60239d30770SMike Travis static inline void uv_write_global_mmr64(int pnode, unsigned long offset, unsigned long val)
603bb898558SAl Viro {
6048dc579e8SJack Steiner 	writeq(val, uv_global_mmr64_address(pnode, offset));
605bb898558SAl Viro }
606bb898558SAl Viro 
60739d30770SMike Travis static inline unsigned long uv_read_global_mmr64(int pnode, unsigned long offset)
608bb898558SAl Viro {
6098dc579e8SJack Steiner 	return readq(uv_global_mmr64_address(pnode, offset));
610bb898558SAl Viro }
611bb898558SAl Viro 
61239d30770SMike Travis static inline void uv_write_global_mmr8(int pnode, unsigned long offset, unsigned char val)
61339d30770SMike Travis {
61439d30770SMike Travis 	writeb(val, uv_global_mmr64_address(pnode, offset));
61539d30770SMike Travis }
61639d30770SMike Travis 
61739d30770SMike Travis static inline unsigned char uv_read_global_mmr8(int pnode, unsigned long offset)
61839d30770SMike Travis {
61939d30770SMike Travis 	return readb(uv_global_mmr64_address(pnode, offset));
62039d30770SMike Travis }
62139d30770SMike Travis 
62256abcf24SJack Steiner /*
623bb898558SAl Viro  * Access hub local MMRs. Faster than using global space but only local MMRs
624bb898558SAl Viro  * are accessible.
625bb898558SAl Viro  */
626bb898558SAl Viro static inline unsigned long *uv_local_mmr_address(unsigned long offset)
627bb898558SAl Viro {
628bb898558SAl Viro 	return __va(UV_LOCAL_MMR_BASE | offset);
629bb898558SAl Viro }
630bb898558SAl Viro 
631bb898558SAl Viro static inline unsigned long uv_read_local_mmr(unsigned long offset)
632bb898558SAl Viro {
6338dc579e8SJack Steiner 	return readq(uv_local_mmr_address(offset));
634bb898558SAl Viro }
635bb898558SAl Viro 
636bb898558SAl Viro static inline void uv_write_local_mmr(unsigned long offset, unsigned long val)
637bb898558SAl Viro {
6388dc579e8SJack Steiner 	writeq(val, uv_local_mmr_address(offset));
639bb898558SAl Viro }
640bb898558SAl Viro 
6417f1baa06SMike Travis static inline unsigned char uv_read_local_mmr8(unsigned long offset)
6427f1baa06SMike Travis {
6438dc579e8SJack Steiner 	return readb(uv_local_mmr_address(offset));
6447f1baa06SMike Travis }
6457f1baa06SMike Travis 
6467f1baa06SMike Travis static inline void uv_write_local_mmr8(unsigned long offset, unsigned char val)
6477f1baa06SMike Travis {
6488dc579e8SJack Steiner 	writeb(val, uv_local_mmr_address(offset));
6497f1baa06SMike Travis }
6507f1baa06SMike Travis 
651bb898558SAl Viro /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */
652bb898558SAl Viro static inline int uv_blade_processor_id(void)
653bb898558SAl Viro {
6545627a825SMike Travis 	return uv_cpu_info->blade_cpu_id;
655bb898558SAl Viro }
656bb898558SAl Viro 
6575627a825SMike Travis /* Blade-local cpu number of cpu N. Numbered 0 .. <# cpus on the blade> */
6585627a825SMike Travis static inline int uv_cpu_blade_processor_id(int cpu)
6595627a825SMike Travis {
6605627a825SMike Travis 	return uv_cpu_info_per(cpu)->blade_cpu_id;
6615627a825SMike Travis }
6625627a825SMike Travis 
663906f3b20SMike Travis /* Blade number to Node number (UV1..UV4 is 1:1) */
664906f3b20SMike Travis static inline int uv_blade_to_node(int blade)
665906f3b20SMike Travis {
666906f3b20SMike Travis 	return blade;
667906f3b20SMike Travis }
668906f3b20SMike Travis 
669bb898558SAl Viro /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */
670bb898558SAl Viro static inline int uv_numa_blade_id(void)
671bb898558SAl Viro {
672bb898558SAl Viro 	return uv_hub_info->numa_blade_id;
673bb898558SAl Viro }
674bb898558SAl Viro 
675906f3b20SMike Travis /*
676906f3b20SMike Travis  * Convert linux node number to the UV blade number.
677906f3b20SMike Travis  * .. Currently for UV1 thru UV4 the node and the blade are identical.
678906f3b20SMike Travis  * .. If this changes then you MUST check references to this function!
679906f3b20SMike Travis  */
680906f3b20SMike Travis static inline int uv_node_to_blade_id(int nid)
681906f3b20SMike Travis {
682906f3b20SMike Travis 	return nid;
683906f3b20SMike Travis }
684906f3b20SMike Travis 
685de0038bfSRandy Dunlap /* Convert a CPU number to the UV blade number */
686bb898558SAl Viro static inline int uv_cpu_to_blade_id(int cpu)
687bb898558SAl Viro {
688906f3b20SMike Travis 	return uv_node_to_blade_id(cpu_to_node(cpu));
689bb898558SAl Viro }
690bb898558SAl Viro 
691bb898558SAl Viro /* Convert a blade id to the PNODE of the blade */
692bb898558SAl Viro static inline int uv_blade_to_pnode(int bid)
693bb898558SAl Viro {
694906f3b20SMike Travis 	return uv_hub_info_list(uv_blade_to_node(bid))->pnode;
695bb898558SAl Viro }
696bb898558SAl Viro 
6976c7184b7SJack Steiner /* Nid of memory node on blade. -1 if no blade-local memory */
6986c7184b7SJack Steiner static inline int uv_blade_to_memory_nid(int bid)
6996c7184b7SJack Steiner {
700906f3b20SMike Travis 	return uv_hub_info_list(uv_blade_to_node(bid))->memory_nid;
7016c7184b7SJack Steiner }
7026c7184b7SJack Steiner 
703bb898558SAl Viro /* Determine the number of possible cpus on a blade */
704bb898558SAl Viro static inline int uv_blade_nr_possible_cpus(int bid)
705bb898558SAl Viro {
706906f3b20SMike Travis 	return uv_hub_info_list(uv_blade_to_node(bid))->nr_possible_cpus;
707bb898558SAl Viro }
708bb898558SAl Viro 
709bb898558SAl Viro /* Determine the number of online cpus on a blade */
710bb898558SAl Viro static inline int uv_blade_nr_online_cpus(int bid)
711bb898558SAl Viro {
712906f3b20SMike Travis 	return uv_hub_info_list(uv_blade_to_node(bid))->nr_online_cpus;
713bb898558SAl Viro }
714bb898558SAl Viro 
715bb898558SAl Viro /* Convert a cpu id to the PNODE of the blade containing the cpu */
716bb898558SAl Viro static inline int uv_cpu_to_pnode(int cpu)
717bb898558SAl Viro {
718906f3b20SMike Travis 	return uv_cpu_hub_info(cpu)->pnode;
719bb898558SAl Viro }
720bb898558SAl Viro 
721bb898558SAl Viro /* Convert a linux node number to the PNODE of the blade */
722bb898558SAl Viro static inline int uv_node_to_pnode(int nid)
723bb898558SAl Viro {
724906f3b20SMike Travis 	return uv_hub_info_list(nid)->pnode;
725bb898558SAl Viro }
726bb898558SAl Viro 
727bb898558SAl Viro /* Maximum possible number of blades */
728906f3b20SMike Travis extern short uv_possible_blades;
729bb898558SAl Viro static inline int uv_num_possible_blades(void)
730bb898558SAl Viro {
731bb898558SAl Viro 	return uv_possible_blades;
732bb898558SAl Viro }
733bb898558SAl Viro 
7340d12ef0cSMike Travis /* Per Hub NMI support */
7350d12ef0cSMike Travis extern void uv_nmi_setup(void);
736abdf1df6Stravis@sgi.com extern void uv_nmi_setup_hubless(void);
7370d12ef0cSMike Travis 
73897d21003Smike.travis@hpe.com /* BIOS/Kernel flags exchange MMR */
73997d21003Smike.travis@hpe.com #define UVH_BIOS_KERNEL_MMR		UVH_SCRATCH5
74097d21003Smike.travis@hpe.com #define UVH_BIOS_KERNEL_MMR_ALIAS	UVH_SCRATCH5_ALIAS
74197d21003Smike.travis@hpe.com #define UVH_BIOS_KERNEL_MMR_ALIAS_2	UVH_SCRATCH5_ALIAS_2
74297d21003Smike.travis@hpe.com 
74397d21003Smike.travis@hpe.com /* TSC sync valid, set by BIOS */
74497d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_MMR	UVH_BIOS_KERNEL_MMR
74597d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_SHIFT	10
74697d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_SHIFT_UV2K	16	/* UV2/3k have different bits */
74797d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_MASK	3	/* 0011 */
74897d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_VALID	3	/* 0011 */
74997d21003Smike.travis@hpe.com #define UVH_TSC_SYNC_INVALID	2	/* 0010 */
75097d21003Smike.travis@hpe.com 
7510d12ef0cSMike Travis /* BMC sets a bit this MMR non-zero before sending an NMI */
75297d21003Smike.travis@hpe.com #define UVH_NMI_MMR		UVH_BIOS_KERNEL_MMR
75397d21003Smike.travis@hpe.com #define UVH_NMI_MMR_CLEAR	UVH_BIOS_KERNEL_MMR_ALIAS
7540d12ef0cSMike Travis #define UVH_NMI_MMR_SHIFT	63
7550d12ef0cSMike Travis #define UVH_NMI_MMR_TYPE	"SCRATCH5"
7560d12ef0cSMike Travis 
7570d12ef0cSMike Travis /* Newer SMM NMI handler, not present in all systems */
7580d12ef0cSMike Travis #define UVH_NMI_MMRX		UVH_EVENT_OCCURRED0
7590d12ef0cSMike Travis #define UVH_NMI_MMRX_CLEAR	UVH_EVENT_OCCURRED0_ALIAS
760c443c03dSMike Travis #define UVH_NMI_MMRX_SHIFT	UVH_EVENT_OCCURRED0_EXTIO_INT0_SHFT
7610d12ef0cSMike Travis #define UVH_NMI_MMRX_TYPE	"EXTIO_INT0"
7620d12ef0cSMike Travis 
7630d12ef0cSMike Travis /* Non-zero indicates newer SMM NMI handler present */
7640d12ef0cSMike Travis #define UVH_NMI_MMRX_SUPPORTED	UVH_EXTIO_INT0_BROADCAST
7650d12ef0cSMike Travis 
7660d12ef0cSMike Travis /* Indicates to BIOS that we want to use the newer SMM NMI handler */
76797d21003Smike.travis@hpe.com #define UVH_NMI_MMRX_REQ	UVH_BIOS_KERNEL_MMR_ALIAS_2
7680d12ef0cSMike Travis #define UVH_NMI_MMRX_REQ_SHIFT	62
7690d12ef0cSMike Travis 
7700d12ef0cSMike Travis struct uv_hub_nmi_s {
7710d12ef0cSMike Travis 	raw_spinlock_t	nmi_lock;
7720d12ef0cSMike Travis 	atomic_t	in_nmi;		/* flag this node in UV NMI IRQ */
7730d12ef0cSMike Travis 	atomic_t	cpu_owner;	/* last locker of this struct */
7740d12ef0cSMike Travis 	atomic_t	read_mmr_count;	/* count of MMR reads */
7750d12ef0cSMike Travis 	atomic_t	nmi_count;	/* count of true UV NMIs */
7760d12ef0cSMike Travis 	unsigned long	nmi_value;	/* last value read from NMI MMR */
777abdf1df6Stravis@sgi.com 	bool		hub_present;	/* false means UV hubless system */
778abdf1df6Stravis@sgi.com 	bool		pch_owner;	/* indicates this hub owns PCH */
7790d12ef0cSMike Travis };
7800d12ef0cSMike Travis 
7810d12ef0cSMike Travis struct uv_cpu_nmi_s {
7820d12ef0cSMike Travis 	struct uv_hub_nmi_s	*hub;
783e1632170SChristoph Lameter 	int			state;
784e1632170SChristoph Lameter 	int			pinging;
7850d12ef0cSMike Travis 	int			queries;
7860d12ef0cSMike Travis 	int			pings;
7870d12ef0cSMike Travis };
7880d12ef0cSMike Travis 
789e1632170SChristoph Lameter DECLARE_PER_CPU(struct uv_cpu_nmi_s, uv_cpu_nmi);
790e1632170SChristoph Lameter 
7917c52198bSGeorge Beshers #define uv_hub_nmi			this_cpu_read(uv_cpu_nmi.hub)
792e1632170SChristoph Lameter #define uv_cpu_nmi_per(cpu)		(per_cpu(uv_cpu_nmi, cpu))
7930d12ef0cSMike Travis #define uv_hub_nmi_per(cpu)		(uv_cpu_nmi_per(cpu).hub)
7940d12ef0cSMike Travis 
7950d12ef0cSMike Travis /* uv_cpu_nmi_states */
7960d12ef0cSMike Travis #define	UV_NMI_STATE_OUT		0
7970d12ef0cSMike Travis #define	UV_NMI_STATE_IN			1
7980d12ef0cSMike Travis #define	UV_NMI_STATE_DUMP		2
7990d12ef0cSMike Travis #define	UV_NMI_STATE_DUMP_DONE		3
8000d12ef0cSMike Travis 
8017f1baa06SMike Travis /* Update SCIR state */
8027f1baa06SMike Travis static inline void uv_set_scir_bits(unsigned char value)
8037f1baa06SMike Travis {
804d38bb135SMike Travis 	if (uv_scir_info->state != value) {
805d38bb135SMike Travis 		uv_scir_info->state = value;
806d38bb135SMike Travis 		uv_write_local_mmr8(uv_scir_info->offset, value);
8077f1baa06SMike Travis 	}
8087f1baa06SMike Travis }
80966666e50SJack Steiner 
81039d30770SMike Travis static inline unsigned long uv_scir_offset(int apicid)
81139d30770SMike Travis {
81239d30770SMike Travis 	return SCIR_LOCAL_MMR_BASE | (apicid & 0x3f);
81339d30770SMike Travis }
81439d30770SMike Travis 
8157f1baa06SMike Travis static inline void uv_set_cpu_scir_bits(int cpu, unsigned char value)
8167f1baa06SMike Travis {
817d38bb135SMike Travis 	if (uv_cpu_scir_info(cpu)->state != value) {
81839d30770SMike Travis 		uv_write_global_mmr8(uv_cpu_to_pnode(cpu),
819d38bb135SMike Travis 				uv_cpu_scir_info(cpu)->offset, value);
820d38bb135SMike Travis 		uv_cpu_scir_info(cpu)->state = value;
8217f1baa06SMike Travis 	}
8227f1baa06SMike Travis }
823bb898558SAl Viro 
8248191c9f6SDimitri Sivanich extern unsigned int uv_apicid_hibits;
82566666e50SJack Steiner 
8267a1110e8SJack Steiner /*
8277a1110e8SJack Steiner  * Get the minimum revision number of the hub chips within the partition.
828eb1e3461SMike Travis  * (See UVx_HUB_REVISION_BASE above for specific values.)
8297a1110e8SJack Steiner  */
8307a1110e8SJack Steiner static inline int uv_get_min_hub_revision_id(void)
8317a1110e8SJack Steiner {
8322a919596SJack Steiner 	return uv_hub_info->hub_revision;
8337a1110e8SJack Steiner }
8347a1110e8SJack Steiner 
835bc5d9940SJack Steiner #endif /* CONFIG_X86_64 */
8367f1baa06SMike Travis #endif /* _ASM_X86_UV_UV_HUB_H */
837