xref: /openbmc/linux/arch/x86/include/asm/uv/uv_hub.h (revision c8f730b1)
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  *
8c8f730b1SRuss Anderson  * Copyright (C) 2007-2010 Silicon Graphics, Inc. All rights reserved.
9bb898558SAl Viro  */
10bb898558SAl Viro 
1105e4d316SH. Peter Anvin #ifndef _ASM_X86_UV_UV_HUB_H
1205e4d316SH. Peter Anvin #define _ASM_X86_UV_UV_HUB_H
13bb898558SAl Viro 
14bc5d9940SJack Steiner #ifdef CONFIG_X86_64
15bb898558SAl Viro #include <linux/numa.h>
16bb898558SAl Viro #include <linux/percpu.h>
17c08b6accSMike Travis #include <linux/timer.h>
188dc579e8SJack Steiner #include <linux/io.h>
19bb898558SAl Viro #include <asm/types.h>
20bb898558SAl Viro #include <asm/percpu.h>
2166666e50SJack Steiner #include <asm/uv/uv_mmrs.h>
2202dd0a06SRobin Holt #include <asm/irq_vectors.h>
2302dd0a06SRobin Holt #include <asm/io_apic.h>
24bb898558SAl Viro 
25bb898558SAl Viro 
26bb898558SAl Viro /*
27bb898558SAl Viro  * Addressing Terminology
28bb898558SAl Viro  *
29bb898558SAl Viro  *	M       - The low M bits of a physical address represent the offset
30bb898558SAl Viro  *		  into the blade local memory. RAM memory on a blade is physically
31bb898558SAl Viro  *		  contiguous (although various IO spaces may punch holes in
32bb898558SAl Viro  *		  it)..
33bb898558SAl Viro  *
34bb898558SAl Viro  *	N	- Number of bits in the node portion of a socket physical
35bb898558SAl Viro  *		  address.
36bb898558SAl Viro  *
37bb898558SAl Viro  *	NASID   - network ID of a router, Mbrick or Cbrick. Nasid values of
38bb898558SAl Viro  *		  routers always have low bit of 1, C/MBricks have low bit
39bb898558SAl Viro  *		  equal to 0. Most addressing macros that target UV hub chips
40bb898558SAl Viro  *		  right shift the NASID by 1 to exclude the always-zero bit.
41bb898558SAl Viro  *		  NASIDs contain up to 15 bits.
42bb898558SAl Viro  *
43bb898558SAl Viro  *	GNODE   - NASID right shifted by 1 bit. Most mmrs contain gnodes instead
44bb898558SAl Viro  *		  of nasids.
45bb898558SAl Viro  *
46bb898558SAl Viro  *	PNODE   - the low N bits of the GNODE. The PNODE is the most useful variant
47bb898558SAl Viro  *		  of the nasid for socket usage.
48bb898558SAl Viro  *
49bb898558SAl Viro  *
50bb898558SAl Viro  *  NumaLink Global Physical Address Format:
51bb898558SAl Viro  *  +--------------------------------+---------------------+
52bb898558SAl Viro  *  |00..000|      GNODE             |      NodeOffset     |
53bb898558SAl Viro  *  +--------------------------------+---------------------+
54bb898558SAl Viro  *          |<-------53 - M bits --->|<--------M bits ----->
55bb898558SAl Viro  *
56bb898558SAl Viro  *	M - number of node offset bits (35 .. 40)
57bb898558SAl Viro  *
58bb898558SAl Viro  *
59bb898558SAl Viro  *  Memory/UV-HUB Processor Socket Address Format:
60bb898558SAl Viro  *  +----------------+---------------+---------------------+
61bb898558SAl Viro  *  |00..000000000000|   PNODE       |      NodeOffset     |
62bb898558SAl Viro  *  +----------------+---------------+---------------------+
63bb898558SAl Viro  *                   <--- N bits --->|<--------M bits ----->
64bb898558SAl Viro  *
65bb898558SAl Viro  *	M - number of node offset bits (35 .. 40)
66bb898558SAl Viro  *	N - number of PNODE bits (0 .. 10)
67bb898558SAl Viro  *
68bb898558SAl Viro  *		Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64).
69bb898558SAl Viro  *		The actual values are configuration dependent and are set at
70bb898558SAl Viro  *		boot time. M & N values are set by the hardware/BIOS at boot.
71bb898558SAl Viro  *
72bb898558SAl Viro  *
73bb898558SAl Viro  * APICID format
74bb898558SAl Viro  *	NOTE!!!!!! This is the current format of the APICID. However, code
75bb898558SAl Viro  *	should assume that this will change in the future. Use functions
76bb898558SAl Viro  *	in this file for all APICID bit manipulations and conversion.
77bb898558SAl Viro  *
78bb898558SAl Viro  *		1111110000000000
79bb898558SAl Viro  *		5432109876543210
80c8f730b1SRuss Anderson  *		pppppppppplc0cch	Nehalem-EX
81c8f730b1SRuss Anderson  *		ppppppppplcc0cch	Westmere-EX
82bb898558SAl Viro  *		sssssssssss
83bb898558SAl Viro  *
84bb898558SAl Viro  *			p  = pnode bits
85bb898558SAl Viro  *			l =  socket number on board
86bb898558SAl Viro  *			c  = core
87bb898558SAl Viro  *			h  = hyperthread
88bb898558SAl Viro  *			s  = bits that are in the SOCKET_ID CSR
89bb898558SAl Viro  *
90bb898558SAl Viro  *	Note: Processor only supports 12 bits in the APICID register. The ACPI
91bb898558SAl Viro  *	      tables hold all 16 bits. Software needs to be aware of this.
92bb898558SAl Viro  *
93bb898558SAl Viro  *	      Unless otherwise specified, all references to APICID refer to
94bb898558SAl Viro  *	      the FULL value contained in ACPI tables, not the subset in the
95bb898558SAl Viro  *	      processor APICID register.
96bb898558SAl Viro  */
97bb898558SAl Viro 
98bb898558SAl Viro 
99bb898558SAl Viro /*
100bb898558SAl Viro  * Maximum number of bricks in all partitions and in all coherency domains.
101bb898558SAl Viro  * This is the total number of bricks accessible in the numalink fabric. It
102bb898558SAl Viro  * includes all C & M bricks. Routers are NOT included.
103bb898558SAl Viro  *
104bb898558SAl Viro  * This value is also the value of the maximum number of non-router NASIDs
105bb898558SAl Viro  * in the numalink fabric.
106bb898558SAl Viro  *
107bb898558SAl Viro  * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused.
108bb898558SAl Viro  */
109bb898558SAl Viro #define UV_MAX_NUMALINK_BLADES	16384
110bb898558SAl Viro 
111bb898558SAl Viro /*
112bb898558SAl Viro  * Maximum number of C/Mbricks within a software SSI (hardware may support
113bb898558SAl Viro  * more).
114bb898558SAl Viro  */
115bb898558SAl Viro #define UV_MAX_SSI_BLADES	256
116bb898558SAl Viro 
117bb898558SAl Viro /*
118bb898558SAl Viro  * The largest possible NASID of a C or M brick (+ 2)
119bb898558SAl Viro  */
1201d21e6e3SRobin Holt #define UV_MAX_NASID_VALUE	(UV_MAX_NUMALINK_BLADES * 2)
121bb898558SAl Viro 
1227f1baa06SMike Travis struct uv_scir_s {
1237f1baa06SMike Travis 	struct timer_list timer;
1247f1baa06SMike Travis 	unsigned long	offset;
1257f1baa06SMike Travis 	unsigned long	last;
1267f1baa06SMike Travis 	unsigned long	idle_on;
1277f1baa06SMike Travis 	unsigned long	idle_off;
1287f1baa06SMike Travis 	unsigned char	state;
1297f1baa06SMike Travis 	unsigned char	enabled;
1307f1baa06SMike Travis };
1317f1baa06SMike Travis 
132bb898558SAl Viro /*
133bb898558SAl Viro  * The following defines attributes of the HUB chip. These attributes are
134bb898558SAl Viro  * frequently referenced and are kept in the per-cpu data areas of each cpu.
135bb898558SAl Viro  * They are kept together in a struct to minimize cache misses.
136bb898558SAl Viro  */
137bb898558SAl Viro struct uv_hub_info_s {
138bb898558SAl Viro 	unsigned long		global_mmr_base;
139bb898558SAl Viro 	unsigned long		gpa_mask;
140c4ed3f04SJack Steiner 	unsigned int		gnode_extra;
141bb898558SAl Viro 	unsigned long		gnode_upper;
142bb898558SAl Viro 	unsigned long		lowmem_remap_top;
143bb898558SAl Viro 	unsigned long		lowmem_remap_base;
144bb898558SAl Viro 	unsigned short		pnode;
145bb898558SAl Viro 	unsigned short		pnode_mask;
146bb898558SAl Viro 	unsigned short		coherency_domain_number;
147bb898558SAl Viro 	unsigned short		numa_blade_id;
148bb898558SAl Viro 	unsigned char		blade_processor_id;
149bb898558SAl Viro 	unsigned char		m_val;
150bb898558SAl Viro 	unsigned char		n_val;
1517f1baa06SMike Travis 	struct uv_scir_s	scir;
152c8f730b1SRuss Anderson 	unsigned char		apic_pnode_shift;
153bb898558SAl Viro };
1547f1baa06SMike Travis 
155bb898558SAl Viro DECLARE_PER_CPU(struct uv_hub_info_s, __uv_hub_info);
156bb898558SAl Viro #define uv_hub_info		(&__get_cpu_var(__uv_hub_info))
157bb898558SAl Viro #define uv_cpu_hub_info(cpu)	(&per_cpu(__uv_hub_info, cpu))
158bb898558SAl Viro 
159c8f730b1SRuss Anderson union uvh_apicid {
160c8f730b1SRuss Anderson     unsigned long       v;
161c8f730b1SRuss Anderson     struct uvh_apicid_s {
162c8f730b1SRuss Anderson         unsigned long   local_apic_mask  : 24;
163c8f730b1SRuss Anderson         unsigned long   local_apic_shift :  5;
164c8f730b1SRuss Anderson         unsigned long   unused1          :  3;
165c8f730b1SRuss Anderson         unsigned long   pnode_mask       : 24;
166c8f730b1SRuss Anderson         unsigned long   pnode_shift      :  5;
167c8f730b1SRuss Anderson         unsigned long   unused2          :  3;
168c8f730b1SRuss Anderson     } s;
169c8f730b1SRuss Anderson };
170c8f730b1SRuss Anderson 
171bb898558SAl Viro /*
172bb898558SAl Viro  * Local & Global MMR space macros.
173bb898558SAl Viro  *	Note: macros are intended to be used ONLY by inline functions
174bb898558SAl Viro  *	in this file - not by other kernel code.
175bb898558SAl Viro  *		n -  NASID (full 15-bit global nasid)
176bb898558SAl Viro  *		g -  GNODE (full 15-bit global nasid, right shifted 1)
177bb898558SAl Viro  *		p -  PNODE (local part of nsids, right shifted 1)
178bb898558SAl Viro  */
179bb898558SAl Viro #define UV_NASID_TO_PNODE(n)		(((n) >> 1) & uv_hub_info->pnode_mask)
180c4ed3f04SJack Steiner #define UV_PNODE_TO_GNODE(p)		((p) |uv_hub_info->gnode_extra)
181c4ed3f04SJack Steiner #define UV_PNODE_TO_NASID(p)		(UV_PNODE_TO_GNODE(p) << 1)
182bb898558SAl Viro 
183bb898558SAl Viro #define UV_LOCAL_MMR_BASE		0xf4000000UL
184bb898558SAl Viro #define UV_GLOBAL_MMR32_BASE		0xf8000000UL
185bb898558SAl Viro #define UV_GLOBAL_MMR64_BASE		(uv_hub_info->global_mmr_base)
186bb898558SAl Viro #define UV_LOCAL_MMR_SIZE		(64UL * 1024 * 1024)
187bb898558SAl Viro #define UV_GLOBAL_MMR32_SIZE		(64UL * 1024 * 1024)
188bb898558SAl Viro 
18956abcf24SJack Steiner #define UV_GLOBAL_GRU_MMR_BASE		0x4000000
19056abcf24SJack Steiner 
191bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_SHIFT	15
192bb898558SAl Viro #define UV_GLOBAL_MMR64_PNODE_SHIFT	26
193bb898558SAl Viro 
194bb898558SAl Viro #define UV_GLOBAL_MMR32_PNODE_BITS(p)	((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT))
195bb898558SAl Viro 
196bb898558SAl Viro #define UV_GLOBAL_MMR64_PNODE_BITS(p)					\
19767e83f30SJack Steiner 	(((unsigned long)(p)) << UV_GLOBAL_MMR64_PNODE_SHIFT)
198bb898558SAl Viro 
199c8f730b1SRuss Anderson #define UVH_APICID		0x002D0E00L
200bb898558SAl Viro #define UV_APIC_PNODE_SHIFT	6
201bb898558SAl Viro 
2027f1baa06SMike Travis /* Local Bus from cpu's perspective */
2037f1baa06SMike Travis #define LOCAL_BUS_BASE		0x1c00000
2047f1baa06SMike Travis #define LOCAL_BUS_SIZE		(4 * 1024 * 1024)
2057f1baa06SMike Travis 
2067f1baa06SMike Travis /*
2077f1baa06SMike Travis  * System Controller Interface Reg
2087f1baa06SMike Travis  *
2097f1baa06SMike Travis  * Note there are NO leds on a UV system.  This register is only
2107f1baa06SMike Travis  * used by the system controller to monitor system-wide operation.
2117f1baa06SMike Travis  * There are 64 regs per node.  With Nahelem cpus (2 cores per node,
2127f1baa06SMike Travis  * 8 cpus per core, 2 threads per cpu) there are 32 cpu threads on
2137f1baa06SMike Travis  * a node.
2147f1baa06SMike Travis  *
2157f1baa06SMike Travis  * The window is located at top of ACPI MMR space
2167f1baa06SMike Travis  */
2177f1baa06SMike Travis #define SCIR_WINDOW_COUNT	64
2187f1baa06SMike Travis #define SCIR_LOCAL_MMR_BASE	(LOCAL_BUS_BASE + \
2197f1baa06SMike Travis 				 LOCAL_BUS_SIZE - \
2207f1baa06SMike Travis 				 SCIR_WINDOW_COUNT)
2217f1baa06SMike Travis 
2227f1baa06SMike Travis #define SCIR_CPU_HEARTBEAT	0x01	/* timer interrupt */
2237f1baa06SMike Travis #define SCIR_CPU_ACTIVITY	0x02	/* not idle */
2247f1baa06SMike Travis #define SCIR_CPU_HB_INTERVAL	(HZ)	/* once per second */
2257f1baa06SMike Travis 
2268661984fSDimitri Sivanich /* Loop through all installed blades */
2278661984fSDimitri Sivanich #define for_each_possible_blade(bid)		\
2288661984fSDimitri Sivanich 	for ((bid) = 0; (bid) < uv_num_possible_blades(); (bid)++)
2298661984fSDimitri Sivanich 
230bb898558SAl Viro /*
231bb898558SAl Viro  * Macros for converting between kernel virtual addresses, socket local physical
232bb898558SAl Viro  * addresses, and UV global physical addresses.
233bb898558SAl Viro  *	Note: use the standard __pa() & __va() macros for converting
234bb898558SAl Viro  *	      between socket virtual and socket physical addresses.
235bb898558SAl Viro  */
236bb898558SAl Viro 
237bb898558SAl Viro /* socket phys RAM --> UV global physical address */
238bb898558SAl Viro static inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr)
239bb898558SAl Viro {
240bb898558SAl Viro 	if (paddr < uv_hub_info->lowmem_remap_top)
241189f67c4SJack Steiner 		paddr |= uv_hub_info->lowmem_remap_base;
242bb898558SAl Viro 	return paddr | uv_hub_info->gnode_upper;
243bb898558SAl Viro }
244bb898558SAl Viro 
245bb898558SAl Viro 
246bb898558SAl Viro /* socket virtual --> UV global physical address */
247bb898558SAl Viro static inline unsigned long uv_gpa(void *v)
248bb898558SAl Viro {
249189f67c4SJack Steiner 	return uv_soc_phys_ram_to_gpa(__pa(v));
250bb898558SAl Viro }
251bb898558SAl Viro 
252fae419f2SRobin Holt /* Top two bits indicate the requested address is in MMR space.  */
253fae419f2SRobin Holt static inline int
254fae419f2SRobin Holt uv_gpa_in_mmr_space(unsigned long gpa)
255fae419f2SRobin Holt {
256fae419f2SRobin Holt 	return (gpa >> 62) == 0x3UL;
257fae419f2SRobin Holt }
258fae419f2SRobin Holt 
259729d69e6SRobin Holt /* UV global physical address --> socket phys RAM */
260729d69e6SRobin Holt static inline unsigned long uv_gpa_to_soc_phys_ram(unsigned long gpa)
261729d69e6SRobin Holt {
262729d69e6SRobin Holt 	unsigned long paddr = gpa & uv_hub_info->gpa_mask;
263729d69e6SRobin Holt 	unsigned long remap_base = uv_hub_info->lowmem_remap_base;
264729d69e6SRobin Holt 	unsigned long remap_top =  uv_hub_info->lowmem_remap_top;
265729d69e6SRobin Holt 
266729d69e6SRobin Holt 	if (paddr >= remap_base && paddr < remap_base + remap_top)
267729d69e6SRobin Holt 		paddr -= remap_base;
268729d69e6SRobin Holt 	return paddr;
269729d69e6SRobin Holt }
270729d69e6SRobin Holt 
271729d69e6SRobin Holt 
2721d21e6e3SRobin Holt /* gnode -> pnode */
2731d21e6e3SRobin Holt static inline unsigned long uv_gpa_to_gnode(unsigned long gpa)
2741d21e6e3SRobin Holt {
2751d21e6e3SRobin Holt 	return gpa >> uv_hub_info->m_val;
2761d21e6e3SRobin Holt }
2771d21e6e3SRobin Holt 
2781d21e6e3SRobin Holt /* gpa -> pnode */
2791d21e6e3SRobin Holt static inline int uv_gpa_to_pnode(unsigned long gpa)
2801d21e6e3SRobin Holt {
2811d21e6e3SRobin Holt 	unsigned long n_mask = (1UL << uv_hub_info->n_val) - 1;
2821d21e6e3SRobin Holt 
2831d21e6e3SRobin Holt 	return uv_gpa_to_gnode(gpa) & n_mask;
2841d21e6e3SRobin Holt }
2851d21e6e3SRobin Holt 
286bb898558SAl Viro /* pnode, offset --> socket virtual */
287bb898558SAl Viro static inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
288bb898558SAl Viro {
289bb898558SAl Viro 	return __va(((unsigned long)pnode << uv_hub_info->m_val) | offset);
290bb898558SAl Viro }
291bb898558SAl Viro 
292bb898558SAl Viro 
293bb898558SAl Viro /*
294bb898558SAl Viro  * Extract a PNODE from an APICID (full apicid, not processor subset)
295bb898558SAl Viro  */
296bb898558SAl Viro static inline int uv_apicid_to_pnode(int apicid)
297bb898558SAl Viro {
298c8f730b1SRuss Anderson 	return (apicid >> uv_hub_info->apic_pnode_shift);
299bb898558SAl Viro }
300bb898558SAl Viro 
301bb898558SAl Viro /*
302bb898558SAl Viro  * Access global MMRs using the low memory MMR32 space. This region supports
303bb898558SAl Viro  * faster MMR access but not all MMRs are accessible in this space.
304bb898558SAl Viro  */
30539d30770SMike Travis static inline unsigned long *uv_global_mmr32_address(int pnode, unsigned long offset)
306bb898558SAl Viro {
307bb898558SAl Viro 	return __va(UV_GLOBAL_MMR32_BASE |
308bb898558SAl Viro 		       UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset);
309bb898558SAl Viro }
310bb898558SAl Viro 
31139d30770SMike Travis static inline void uv_write_global_mmr32(int pnode, unsigned long offset, unsigned long val)
312bb898558SAl Viro {
3138dc579e8SJack Steiner 	writeq(val, uv_global_mmr32_address(pnode, offset));
314bb898558SAl Viro }
315bb898558SAl Viro 
31639d30770SMike Travis static inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset)
317bb898558SAl Viro {
3188dc579e8SJack Steiner 	return readq(uv_global_mmr32_address(pnode, offset));
319bb898558SAl Viro }
320bb898558SAl Viro 
321bb898558SAl Viro /*
322bb898558SAl Viro  * Access Global MMR space using the MMR space located at the top of physical
323bb898558SAl Viro  * memory.
324bb898558SAl Viro  */
325a289cc7cSRandy Dunlap static inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset)
326bb898558SAl Viro {
327bb898558SAl Viro 	return __va(UV_GLOBAL_MMR64_BASE |
328bb898558SAl Viro 		    UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
329bb898558SAl Viro }
330bb898558SAl Viro 
33139d30770SMike Travis static inline void uv_write_global_mmr64(int pnode, unsigned long offset, unsigned long val)
332bb898558SAl Viro {
3338dc579e8SJack Steiner 	writeq(val, uv_global_mmr64_address(pnode, offset));
334bb898558SAl Viro }
335bb898558SAl Viro 
33639d30770SMike Travis static inline unsigned long uv_read_global_mmr64(int pnode, unsigned long offset)
337bb898558SAl Viro {
3388dc579e8SJack Steiner 	return readq(uv_global_mmr64_address(pnode, offset));
339bb898558SAl Viro }
340bb898558SAl Viro 
341bb898558SAl Viro /*
34256abcf24SJack Steiner  * Global MMR space addresses when referenced by the GRU. (GRU does
34356abcf24SJack Steiner  * NOT use socket addressing).
34456abcf24SJack Steiner  */
34556abcf24SJack Steiner static inline unsigned long uv_global_gru_mmr_address(int pnode, unsigned long offset)
34656abcf24SJack Steiner {
347e1e0138dSJack Steiner 	return UV_GLOBAL_GRU_MMR_BASE | offset |
348e1e0138dSJack Steiner 		((unsigned long)pnode << uv_hub_info->m_val);
34956abcf24SJack Steiner }
35056abcf24SJack Steiner 
35139d30770SMike Travis static inline void uv_write_global_mmr8(int pnode, unsigned long offset, unsigned char val)
35239d30770SMike Travis {
35339d30770SMike Travis 	writeb(val, uv_global_mmr64_address(pnode, offset));
35439d30770SMike Travis }
35539d30770SMike Travis 
35639d30770SMike Travis static inline unsigned char uv_read_global_mmr8(int pnode, unsigned long offset)
35739d30770SMike Travis {
35839d30770SMike Travis 	return readb(uv_global_mmr64_address(pnode, offset));
35939d30770SMike Travis }
36039d30770SMike Travis 
36156abcf24SJack Steiner /*
362bb898558SAl Viro  * Access hub local MMRs. Faster than using global space but only local MMRs
363bb898558SAl Viro  * are accessible.
364bb898558SAl Viro  */
365bb898558SAl Viro static inline unsigned long *uv_local_mmr_address(unsigned long offset)
366bb898558SAl Viro {
367bb898558SAl Viro 	return __va(UV_LOCAL_MMR_BASE | offset);
368bb898558SAl Viro }
369bb898558SAl Viro 
370bb898558SAl Viro static inline unsigned long uv_read_local_mmr(unsigned long offset)
371bb898558SAl Viro {
3728dc579e8SJack Steiner 	return readq(uv_local_mmr_address(offset));
373bb898558SAl Viro }
374bb898558SAl Viro 
375bb898558SAl Viro static inline void uv_write_local_mmr(unsigned long offset, unsigned long val)
376bb898558SAl Viro {
3778dc579e8SJack Steiner 	writeq(val, uv_local_mmr_address(offset));
378bb898558SAl Viro }
379bb898558SAl Viro 
3807f1baa06SMike Travis static inline unsigned char uv_read_local_mmr8(unsigned long offset)
3817f1baa06SMike Travis {
3828dc579e8SJack Steiner 	return readb(uv_local_mmr_address(offset));
3837f1baa06SMike Travis }
3847f1baa06SMike Travis 
3857f1baa06SMike Travis static inline void uv_write_local_mmr8(unsigned long offset, unsigned char val)
3867f1baa06SMike Travis {
3878dc579e8SJack Steiner 	writeb(val, uv_local_mmr_address(offset));
3887f1baa06SMike Travis }
3897f1baa06SMike Travis 
390bb898558SAl Viro /*
391bb898558SAl Viro  * Structures and definitions for converting between cpu, node, pnode, and blade
392bb898558SAl Viro  * numbers.
393bb898558SAl Viro  */
394bb898558SAl Viro struct uv_blade_info {
395bb898558SAl Viro 	unsigned short	nr_possible_cpus;
396bb898558SAl Viro 	unsigned short	nr_online_cpus;
397bb898558SAl Viro 	unsigned short	pnode;
3986c7184b7SJack Steiner 	short		memory_nid;
399bb898558SAl Viro };
400bb898558SAl Viro extern struct uv_blade_info *uv_blade_info;
401bb898558SAl Viro extern short *uv_node_to_blade;
402bb898558SAl Viro extern short *uv_cpu_to_blade;
403bb898558SAl Viro extern short uv_possible_blades;
404bb898558SAl Viro 
405bb898558SAl Viro /* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */
406bb898558SAl Viro static inline int uv_blade_processor_id(void)
407bb898558SAl Viro {
408bb898558SAl Viro 	return uv_hub_info->blade_processor_id;
409bb898558SAl Viro }
410bb898558SAl Viro 
411bb898558SAl Viro /* Blade number of current cpu. Numnbered 0 .. <#blades -1> */
412bb898558SAl Viro static inline int uv_numa_blade_id(void)
413bb898558SAl Viro {
414bb898558SAl Viro 	return uv_hub_info->numa_blade_id;
415bb898558SAl Viro }
416bb898558SAl Viro 
417bb898558SAl Viro /* Convert a cpu number to the the UV blade number */
418bb898558SAl Viro static inline int uv_cpu_to_blade_id(int cpu)
419bb898558SAl Viro {
420bb898558SAl Viro 	return uv_cpu_to_blade[cpu];
421bb898558SAl Viro }
422bb898558SAl Viro 
423bb898558SAl Viro /* Convert linux node number to the UV blade number */
424bb898558SAl Viro static inline int uv_node_to_blade_id(int nid)
425bb898558SAl Viro {
426bb898558SAl Viro 	return uv_node_to_blade[nid];
427bb898558SAl Viro }
428bb898558SAl Viro 
429bb898558SAl Viro /* Convert a blade id to the PNODE of the blade */
430bb898558SAl Viro static inline int uv_blade_to_pnode(int bid)
431bb898558SAl Viro {
432bb898558SAl Viro 	return uv_blade_info[bid].pnode;
433bb898558SAl Viro }
434bb898558SAl Viro 
4356c7184b7SJack Steiner /* Nid of memory node on blade. -1 if no blade-local memory */
4366c7184b7SJack Steiner static inline int uv_blade_to_memory_nid(int bid)
4376c7184b7SJack Steiner {
4386c7184b7SJack Steiner 	return uv_blade_info[bid].memory_nid;
4396c7184b7SJack Steiner }
4406c7184b7SJack Steiner 
441bb898558SAl Viro /* Determine the number of possible cpus on a blade */
442bb898558SAl Viro static inline int uv_blade_nr_possible_cpus(int bid)
443bb898558SAl Viro {
444bb898558SAl Viro 	return uv_blade_info[bid].nr_possible_cpus;
445bb898558SAl Viro }
446bb898558SAl Viro 
447bb898558SAl Viro /* Determine the number of online cpus on a blade */
448bb898558SAl Viro static inline int uv_blade_nr_online_cpus(int bid)
449bb898558SAl Viro {
450bb898558SAl Viro 	return uv_blade_info[bid].nr_online_cpus;
451bb898558SAl Viro }
452bb898558SAl Viro 
453bb898558SAl Viro /* Convert a cpu id to the PNODE of the blade containing the cpu */
454bb898558SAl Viro static inline int uv_cpu_to_pnode(int cpu)
455bb898558SAl Viro {
456bb898558SAl Viro 	return uv_blade_info[uv_cpu_to_blade_id(cpu)].pnode;
457bb898558SAl Viro }
458bb898558SAl Viro 
459bb898558SAl Viro /* Convert a linux node number to the PNODE of the blade */
460bb898558SAl Viro static inline int uv_node_to_pnode(int nid)
461bb898558SAl Viro {
462bb898558SAl Viro 	return uv_blade_info[uv_node_to_blade_id(nid)].pnode;
463bb898558SAl Viro }
464bb898558SAl Viro 
465bb898558SAl Viro /* Maximum possible number of blades */
466bb898558SAl Viro static inline int uv_num_possible_blades(void)
467bb898558SAl Viro {
468bb898558SAl Viro 	return uv_possible_blades;
469bb898558SAl Viro }
470bb898558SAl Viro 
4717f1baa06SMike Travis /* Update SCIR state */
4727f1baa06SMike Travis static inline void uv_set_scir_bits(unsigned char value)
4737f1baa06SMike Travis {
4747f1baa06SMike Travis 	if (uv_hub_info->scir.state != value) {
4757f1baa06SMike Travis 		uv_hub_info->scir.state = value;
4767f1baa06SMike Travis 		uv_write_local_mmr8(uv_hub_info->scir.offset, value);
4777f1baa06SMike Travis 	}
4787f1baa06SMike Travis }
47966666e50SJack Steiner 
48039d30770SMike Travis static inline unsigned long uv_scir_offset(int apicid)
48139d30770SMike Travis {
48239d30770SMike Travis 	return SCIR_LOCAL_MMR_BASE | (apicid & 0x3f);
48339d30770SMike Travis }
48439d30770SMike Travis 
4857f1baa06SMike Travis static inline void uv_set_cpu_scir_bits(int cpu, unsigned char value)
4867f1baa06SMike Travis {
4877f1baa06SMike Travis 	if (uv_cpu_hub_info(cpu)->scir.state != value) {
48839d30770SMike Travis 		uv_write_global_mmr8(uv_cpu_to_pnode(cpu),
48939d30770SMike Travis 				uv_cpu_hub_info(cpu)->scir.offset, value);
4907f1baa06SMike Travis 		uv_cpu_hub_info(cpu)->scir.state = value;
4917f1baa06SMike Travis 	}
4927f1baa06SMike Travis }
493bb898558SAl Viro 
49456abcf24SJack Steiner static unsigned long uv_hub_ipi_value(int apicid, int vector, int mode)
49556abcf24SJack Steiner {
49656abcf24SJack Steiner 	return (1UL << UVH_IPI_INT_SEND_SHFT) |
49756abcf24SJack Steiner 			((apicid) << UVH_IPI_INT_APIC_ID_SHFT) |
49856abcf24SJack Steiner 			(mode << UVH_IPI_INT_DELIVERY_MODE_SHFT) |
49956abcf24SJack Steiner 			(vector << UVH_IPI_INT_VECTOR_SHFT);
50056abcf24SJack Steiner }
50156abcf24SJack Steiner 
50266666e50SJack Steiner static inline void uv_hub_send_ipi(int pnode, int apicid, int vector)
50366666e50SJack Steiner {
50466666e50SJack Steiner 	unsigned long val;
50502dd0a06SRobin Holt 	unsigned long dmode = dest_Fixed;
50602dd0a06SRobin Holt 
50702dd0a06SRobin Holt 	if (vector == NMI_VECTOR)
50802dd0a06SRobin Holt 		dmode = dest_NMI;
50966666e50SJack Steiner 
51056abcf24SJack Steiner 	val = uv_hub_ipi_value(apicid, vector, dmode);
51166666e50SJack Steiner 	uv_write_global_mmr64(pnode, UVH_IPI_INT, val);
51266666e50SJack Steiner }
51366666e50SJack Steiner 
5147a1110e8SJack Steiner /*
5157a1110e8SJack Steiner  * Get the minimum revision number of the hub chips within the partition.
5167a1110e8SJack Steiner  *     1 - initial rev 1.0 silicon
5177a1110e8SJack Steiner  *     2 - rev 2.0 production silicon
5187a1110e8SJack Steiner  */
5197a1110e8SJack Steiner static inline int uv_get_min_hub_revision_id(void)
5207a1110e8SJack Steiner {
5217a1110e8SJack Steiner 	extern int uv_min_hub_revision_id;
5227a1110e8SJack Steiner 
5237a1110e8SJack Steiner 	return uv_min_hub_revision_id;
5247a1110e8SJack Steiner }
5257a1110e8SJack Steiner 
526bc5d9940SJack Steiner #endif /* CONFIG_X86_64 */
5277f1baa06SMike Travis #endif /* _ASM_X86_UV_UV_HUB_H */
528