18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
38c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
48c2ecf20Sopenharmony_ci * for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * SGI UV architectural definitions
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * (C) Copyright 2020 Hewlett Packard Enterprise Development LP
98c2ecf20Sopenharmony_ci * Copyright (C) 2007-2014 Silicon Graphics, Inc. All rights reserved.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef _ASM_X86_UV_UV_HUB_H
138c2ecf20Sopenharmony_ci#define _ASM_X86_UV_UV_HUB_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_64
168c2ecf20Sopenharmony_ci#include <linux/numa.h>
178c2ecf20Sopenharmony_ci#include <linux/percpu.h>
188c2ecf20Sopenharmony_ci#include <linux/timer.h>
198c2ecf20Sopenharmony_ci#include <linux/io.h>
208c2ecf20Sopenharmony_ci#include <linux/topology.h>
218c2ecf20Sopenharmony_ci#include <asm/types.h>
228c2ecf20Sopenharmony_ci#include <asm/percpu.h>
238c2ecf20Sopenharmony_ci#include <asm/uv/uv.h>
248c2ecf20Sopenharmony_ci#include <asm/uv/uv_mmrs.h>
258c2ecf20Sopenharmony_ci#include <asm/uv/bios.h>
268c2ecf20Sopenharmony_ci#include <asm/irq_vectors.h>
278c2ecf20Sopenharmony_ci#include <asm/io_apic.h>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/*
318c2ecf20Sopenharmony_ci * Addressing Terminology
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci *	M       - The low M bits of a physical address represent the offset
348c2ecf20Sopenharmony_ci *		  into the blade local memory. RAM memory on a blade is physically
358c2ecf20Sopenharmony_ci *		  contiguous (although various IO spaces may punch holes in
368c2ecf20Sopenharmony_ci *		  it)..
378c2ecf20Sopenharmony_ci *
388c2ecf20Sopenharmony_ci *	N	- Number of bits in the node portion of a socket physical
398c2ecf20Sopenharmony_ci *		  address.
408c2ecf20Sopenharmony_ci *
418c2ecf20Sopenharmony_ci *	NASID   - network ID of a router, Mbrick or Cbrick. Nasid values of
428c2ecf20Sopenharmony_ci *		  routers always have low bit of 1, C/MBricks have low bit
438c2ecf20Sopenharmony_ci *		  equal to 0. Most addressing macros that target UV hub chips
448c2ecf20Sopenharmony_ci *		  right shift the NASID by 1 to exclude the always-zero bit.
458c2ecf20Sopenharmony_ci *		  NASIDs contain up to 15 bits.
468c2ecf20Sopenharmony_ci *
478c2ecf20Sopenharmony_ci *	GNODE   - NASID right shifted by 1 bit. Most mmrs contain gnodes instead
488c2ecf20Sopenharmony_ci *		  of nasids.
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci *	PNODE   - the low N bits of the GNODE. The PNODE is the most useful variant
518c2ecf20Sopenharmony_ci *		  of the nasid for socket usage.
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci *	GPA	- (global physical address) a socket physical address converted
548c2ecf20Sopenharmony_ci *		  so that it can be used by the GRU as a global address. Socket
558c2ecf20Sopenharmony_ci *		  physical addresses 1) need additional NASID (node) bits added
568c2ecf20Sopenharmony_ci *		  to the high end of the address, and 2) unaliased if the
578c2ecf20Sopenharmony_ci *		  partition does not have a physical address 0. In addition, on
588c2ecf20Sopenharmony_ci *		  UV2 rev 1, GPAs need the gnode left shifted to bits 39 or 40.
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci *
618c2ecf20Sopenharmony_ci *  NumaLink Global Physical Address Format:
628c2ecf20Sopenharmony_ci *  +--------------------------------+---------------------+
638c2ecf20Sopenharmony_ci *  |00..000|      GNODE             |      NodeOffset     |
648c2ecf20Sopenharmony_ci *  +--------------------------------+---------------------+
658c2ecf20Sopenharmony_ci *          |<-------53 - M bits --->|<--------M bits ----->
668c2ecf20Sopenharmony_ci *
678c2ecf20Sopenharmony_ci *	M - number of node offset bits (35 .. 40)
688c2ecf20Sopenharmony_ci *
698c2ecf20Sopenharmony_ci *
708c2ecf20Sopenharmony_ci *  Memory/UV-HUB Processor Socket Address Format:
718c2ecf20Sopenharmony_ci *  +----------------+---------------+---------------------+
728c2ecf20Sopenharmony_ci *  |00..000000000000|   PNODE       |      NodeOffset     |
738c2ecf20Sopenharmony_ci *  +----------------+---------------+---------------------+
748c2ecf20Sopenharmony_ci *                   <--- N bits --->|<--------M bits ----->
758c2ecf20Sopenharmony_ci *
768c2ecf20Sopenharmony_ci *	M - number of node offset bits (35 .. 40)
778c2ecf20Sopenharmony_ci *	N - number of PNODE bits (0 .. 10)
788c2ecf20Sopenharmony_ci *
798c2ecf20Sopenharmony_ci *		Note: M + N cannot currently exceed 44 (x86_64) or 46 (IA64).
808c2ecf20Sopenharmony_ci *		The actual values are configuration dependent and are set at
818c2ecf20Sopenharmony_ci *		boot time. M & N values are set by the hardware/BIOS at boot.
828c2ecf20Sopenharmony_ci *
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci * APICID format
858c2ecf20Sopenharmony_ci *	NOTE!!!!!! This is the current format of the APICID. However, code
868c2ecf20Sopenharmony_ci *	should assume that this will change in the future. Use functions
878c2ecf20Sopenharmony_ci *	in this file for all APICID bit manipulations and conversion.
888c2ecf20Sopenharmony_ci *
898c2ecf20Sopenharmony_ci *		1111110000000000
908c2ecf20Sopenharmony_ci *		5432109876543210
918c2ecf20Sopenharmony_ci *		pppppppppplc0cch	Nehalem-EX (12 bits in hdw reg)
928c2ecf20Sopenharmony_ci *		ppppppppplcc0cch	Westmere-EX (12 bits in hdw reg)
938c2ecf20Sopenharmony_ci *		pppppppppppcccch	SandyBridge (15 bits in hdw reg)
948c2ecf20Sopenharmony_ci *		sssssssssss
958c2ecf20Sopenharmony_ci *
968c2ecf20Sopenharmony_ci *			p  = pnode bits
978c2ecf20Sopenharmony_ci *			l =  socket number on board
988c2ecf20Sopenharmony_ci *			c  = core
998c2ecf20Sopenharmony_ci *			h  = hyperthread
1008c2ecf20Sopenharmony_ci *			s  = bits that are in the SOCKET_ID CSR
1018c2ecf20Sopenharmony_ci *
1028c2ecf20Sopenharmony_ci *	Note: Processor may support fewer bits in the APICID register. The ACPI
1038c2ecf20Sopenharmony_ci *	      tables hold all 16 bits. Software needs to be aware of this.
1048c2ecf20Sopenharmony_ci *
1058c2ecf20Sopenharmony_ci *	      Unless otherwise specified, all references to APICID refer to
1068c2ecf20Sopenharmony_ci *	      the FULL value contained in ACPI tables, not the subset in the
1078c2ecf20Sopenharmony_ci *	      processor APICID register.
1088c2ecf20Sopenharmony_ci */
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/*
1118c2ecf20Sopenharmony_ci * Maximum number of bricks in all partitions and in all coherency domains.
1128c2ecf20Sopenharmony_ci * This is the total number of bricks accessible in the numalink fabric. It
1138c2ecf20Sopenharmony_ci * includes all C & M bricks. Routers are NOT included.
1148c2ecf20Sopenharmony_ci *
1158c2ecf20Sopenharmony_ci * This value is also the value of the maximum number of non-router NASIDs
1168c2ecf20Sopenharmony_ci * in the numalink fabric.
1178c2ecf20Sopenharmony_ci *
1188c2ecf20Sopenharmony_ci * NOTE: a brick may contain 1 or 2 OS nodes. Don't get these confused.
1198c2ecf20Sopenharmony_ci */
1208c2ecf20Sopenharmony_ci#define UV_MAX_NUMALINK_BLADES	16384
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci/*
1238c2ecf20Sopenharmony_ci * Maximum number of C/Mbricks within a software SSI (hardware may support
1248c2ecf20Sopenharmony_ci * more).
1258c2ecf20Sopenharmony_ci */
1268c2ecf20Sopenharmony_ci#define UV_MAX_SSI_BLADES	256
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/*
1298c2ecf20Sopenharmony_ci * The largest possible NASID of a C or M brick (+ 2)
1308c2ecf20Sopenharmony_ci */
1318c2ecf20Sopenharmony_ci#define UV_MAX_NASID_VALUE	(UV_MAX_NUMALINK_BLADES * 2)
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/* GAM (globally addressed memory) range table */
1348c2ecf20Sopenharmony_cistruct uv_gam_range_s {
1358c2ecf20Sopenharmony_ci	u32	limit;		/* PA bits 56:26 (GAM_RANGE_SHFT) */
1368c2ecf20Sopenharmony_ci	u16	nasid;		/* node's global physical address */
1378c2ecf20Sopenharmony_ci	s8	base;		/* entry index of node's base addr */
1388c2ecf20Sopenharmony_ci	u8	reserved;
1398c2ecf20Sopenharmony_ci};
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/*
1428c2ecf20Sopenharmony_ci * The following defines attributes of the HUB chip. These attributes are
1438c2ecf20Sopenharmony_ci * frequently referenced and are kept in a common per hub struct.
1448c2ecf20Sopenharmony_ci * After setup, the struct is read only, so it should be readily
1458c2ecf20Sopenharmony_ci * available in the L3 cache on the cpu socket for the node.
1468c2ecf20Sopenharmony_ci */
1478c2ecf20Sopenharmony_cistruct uv_hub_info_s {
1488c2ecf20Sopenharmony_ci	unsigned int		hub_type;
1498c2ecf20Sopenharmony_ci	unsigned char		hub_revision;
1508c2ecf20Sopenharmony_ci	unsigned long		global_mmr_base;
1518c2ecf20Sopenharmony_ci	unsigned long		global_mmr_shift;
1528c2ecf20Sopenharmony_ci	unsigned long		gpa_mask;
1538c2ecf20Sopenharmony_ci	unsigned short		*socket_to_node;
1548c2ecf20Sopenharmony_ci	unsigned short		*socket_to_pnode;
1558c2ecf20Sopenharmony_ci	unsigned short		*pnode_to_socket;
1568c2ecf20Sopenharmony_ci	struct uv_gam_range_s	*gr_table;
1578c2ecf20Sopenharmony_ci	unsigned short		min_socket;
1588c2ecf20Sopenharmony_ci	unsigned short		min_pnode;
1598c2ecf20Sopenharmony_ci	unsigned char		m_val;
1608c2ecf20Sopenharmony_ci	unsigned char		n_val;
1618c2ecf20Sopenharmony_ci	unsigned char		gr_table_len;
1628c2ecf20Sopenharmony_ci	unsigned char		apic_pnode_shift;
1638c2ecf20Sopenharmony_ci	unsigned char		gpa_shift;
1648c2ecf20Sopenharmony_ci	unsigned char		nasid_shift;
1658c2ecf20Sopenharmony_ci	unsigned char		m_shift;
1668c2ecf20Sopenharmony_ci	unsigned char		n_lshift;
1678c2ecf20Sopenharmony_ci	unsigned int		gnode_extra;
1688c2ecf20Sopenharmony_ci	unsigned long		gnode_upper;
1698c2ecf20Sopenharmony_ci	unsigned long		lowmem_remap_top;
1708c2ecf20Sopenharmony_ci	unsigned long		lowmem_remap_base;
1718c2ecf20Sopenharmony_ci	unsigned long		global_gru_base;
1728c2ecf20Sopenharmony_ci	unsigned long		global_gru_shift;
1738c2ecf20Sopenharmony_ci	unsigned short		pnode;
1748c2ecf20Sopenharmony_ci	unsigned short		pnode_mask;
1758c2ecf20Sopenharmony_ci	unsigned short		coherency_domain_number;
1768c2ecf20Sopenharmony_ci	unsigned short		numa_blade_id;
1778c2ecf20Sopenharmony_ci	unsigned short		nr_possible_cpus;
1788c2ecf20Sopenharmony_ci	unsigned short		nr_online_cpus;
1798c2ecf20Sopenharmony_ci	short			memory_nid;
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* CPU specific info with a pointer to the hub common info struct */
1838c2ecf20Sopenharmony_cistruct uv_cpu_info_s {
1848c2ecf20Sopenharmony_ci	void			*p_uv_hub_info;
1858c2ecf20Sopenharmony_ci	unsigned char		blade_cpu_id;
1868c2ecf20Sopenharmony_ci	void			*reserved;
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ciDECLARE_PER_CPU(struct uv_cpu_info_s, __uv_cpu_info);
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci#define uv_cpu_info		this_cpu_ptr(&__uv_cpu_info)
1918c2ecf20Sopenharmony_ci#define uv_cpu_info_per(cpu)	(&per_cpu(__uv_cpu_info, cpu))
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci/* Node specific hub common info struct */
1948c2ecf20Sopenharmony_ciextern void **__uv_hub_info_list;
1958c2ecf20Sopenharmony_cistatic inline struct uv_hub_info_s *uv_hub_info_list(int node)
1968c2ecf20Sopenharmony_ci{
1978c2ecf20Sopenharmony_ci	return (struct uv_hub_info_s *)__uv_hub_info_list[node];
1988c2ecf20Sopenharmony_ci}
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cistatic inline struct uv_hub_info_s *_uv_hub_info(void)
2018c2ecf20Sopenharmony_ci{
2028c2ecf20Sopenharmony_ci	return (struct uv_hub_info_s *)uv_cpu_info->p_uv_hub_info;
2038c2ecf20Sopenharmony_ci}
2048c2ecf20Sopenharmony_ci#define	uv_hub_info	_uv_hub_info()
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistatic inline struct uv_hub_info_s *uv_cpu_hub_info(int cpu)
2078c2ecf20Sopenharmony_ci{
2088c2ecf20Sopenharmony_ci	return (struct uv_hub_info_s *)uv_cpu_info_per(cpu)->p_uv_hub_info;
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistatic inline int uv_hub_type(void)
2128c2ecf20Sopenharmony_ci{
2138c2ecf20Sopenharmony_ci	return uv_hub_info->hub_type;
2148c2ecf20Sopenharmony_ci}
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_cistatic inline __init void uv_hub_type_set(int uvmask)
2178c2ecf20Sopenharmony_ci{
2188c2ecf20Sopenharmony_ci	uv_hub_info->hub_type = uvmask;
2198c2ecf20Sopenharmony_ci}
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci/*
2238c2ecf20Sopenharmony_ci * HUB revision ranges for each UV HUB architecture.
2248c2ecf20Sopenharmony_ci * This is a software convention - NOT the hardware revision numbers in
2258c2ecf20Sopenharmony_ci * the hub chip.
2268c2ecf20Sopenharmony_ci */
2278c2ecf20Sopenharmony_ci#define UV2_HUB_REVISION_BASE		3
2288c2ecf20Sopenharmony_ci#define UV3_HUB_REVISION_BASE		5
2298c2ecf20Sopenharmony_ci#define UV4_HUB_REVISION_BASE		7
2308c2ecf20Sopenharmony_ci#define UV4A_HUB_REVISION_BASE		8	/* UV4 (fixed) rev 2 */
2318c2ecf20Sopenharmony_ci#define UV5_HUB_REVISION_BASE		9
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_cistatic inline int is_uv(int uvmask) { return uv_hub_type() & uvmask; }
2348c2ecf20Sopenharmony_cistatic inline int is_uv1_hub(void) { return 0; }
2358c2ecf20Sopenharmony_cistatic inline int is_uv2_hub(void) { return is_uv(UV2); }
2368c2ecf20Sopenharmony_cistatic inline int is_uv3_hub(void) { return is_uv(UV3); }
2378c2ecf20Sopenharmony_cistatic inline int is_uv4a_hub(void) { return is_uv(UV4A); }
2388c2ecf20Sopenharmony_cistatic inline int is_uv4_hub(void) { return is_uv(UV4); }
2398c2ecf20Sopenharmony_cistatic inline int is_uv5_hub(void) { return is_uv(UV5); }
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci/*
2428c2ecf20Sopenharmony_ci * UV4A is a revision of UV4.  So on UV4A, both is_uv4_hub() and
2438c2ecf20Sopenharmony_ci * is_uv4a_hub() return true, While on UV4, only is_uv4_hub()
2448c2ecf20Sopenharmony_ci * returns true.  So to get true results, first test if is UV4A,
2458c2ecf20Sopenharmony_ci * then test if is UV4.
2468c2ecf20Sopenharmony_ci */
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci/* UVX class: UV2,3,4 */
2498c2ecf20Sopenharmony_cistatic inline int is_uvx_hub(void) { return is_uv(UVX); }
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci/* UVY class: UV5,..? */
2528c2ecf20Sopenharmony_cistatic inline int is_uvy_hub(void) { return is_uv(UVY); }
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci/* Any UV Hubbed System */
2558c2ecf20Sopenharmony_cistatic inline int is_uv_hub(void) { return is_uv(UV_ANY); }
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ciunion uvh_apicid {
2588c2ecf20Sopenharmony_ci    unsigned long       v;
2598c2ecf20Sopenharmony_ci    struct uvh_apicid_s {
2608c2ecf20Sopenharmony_ci        unsigned long   local_apic_mask  : 24;
2618c2ecf20Sopenharmony_ci        unsigned long   local_apic_shift :  5;
2628c2ecf20Sopenharmony_ci        unsigned long   unused1          :  3;
2638c2ecf20Sopenharmony_ci        unsigned long   pnode_mask       : 24;
2648c2ecf20Sopenharmony_ci        unsigned long   pnode_shift      :  5;
2658c2ecf20Sopenharmony_ci        unsigned long   unused2          :  3;
2668c2ecf20Sopenharmony_ci    } s;
2678c2ecf20Sopenharmony_ci};
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/*
2708c2ecf20Sopenharmony_ci * Local & Global MMR space macros.
2718c2ecf20Sopenharmony_ci *	Note: macros are intended to be used ONLY by inline functions
2728c2ecf20Sopenharmony_ci *	in this file - not by other kernel code.
2738c2ecf20Sopenharmony_ci *		n -  NASID (full 15-bit global nasid)
2748c2ecf20Sopenharmony_ci *		g -  GNODE (full 15-bit global nasid, right shifted 1)
2758c2ecf20Sopenharmony_ci *		p -  PNODE (local part of nsids, right shifted 1)
2768c2ecf20Sopenharmony_ci */
2778c2ecf20Sopenharmony_ci#define UV_NASID_TO_PNODE(n)		\
2788c2ecf20Sopenharmony_ci		(((n) >> uv_hub_info->nasid_shift) & uv_hub_info->pnode_mask)
2798c2ecf20Sopenharmony_ci#define UV_PNODE_TO_GNODE(p)		((p) |uv_hub_info->gnode_extra)
2808c2ecf20Sopenharmony_ci#define UV_PNODE_TO_NASID(p)		\
2818c2ecf20Sopenharmony_ci		(UV_PNODE_TO_GNODE(p) << uv_hub_info->nasid_shift)
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci#define UV2_LOCAL_MMR_BASE		0xfa000000UL
2848c2ecf20Sopenharmony_ci#define UV2_GLOBAL_MMR32_BASE		0xfc000000UL
2858c2ecf20Sopenharmony_ci#define UV2_LOCAL_MMR_SIZE		(32UL * 1024 * 1024)
2868c2ecf20Sopenharmony_ci#define UV2_GLOBAL_MMR32_SIZE		(32UL * 1024 * 1024)
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci#define UV3_LOCAL_MMR_BASE		0xfa000000UL
2898c2ecf20Sopenharmony_ci#define UV3_GLOBAL_MMR32_BASE		0xfc000000UL
2908c2ecf20Sopenharmony_ci#define UV3_LOCAL_MMR_SIZE		(32UL * 1024 * 1024)
2918c2ecf20Sopenharmony_ci#define UV3_GLOBAL_MMR32_SIZE		(32UL * 1024 * 1024)
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci#define UV4_LOCAL_MMR_BASE		0xfa000000UL
2948c2ecf20Sopenharmony_ci#define UV4_GLOBAL_MMR32_BASE		0
2958c2ecf20Sopenharmony_ci#define UV4_LOCAL_MMR_SIZE		(32UL * 1024 * 1024)
2968c2ecf20Sopenharmony_ci#define UV4_GLOBAL_MMR32_SIZE		0
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci#define UV5_LOCAL_MMR_BASE		0xfa000000UL
2998c2ecf20Sopenharmony_ci#define UV5_GLOBAL_MMR32_BASE		0
3008c2ecf20Sopenharmony_ci#define UV5_LOCAL_MMR_SIZE		(32UL * 1024 * 1024)
3018c2ecf20Sopenharmony_ci#define UV5_GLOBAL_MMR32_SIZE		0
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci#define UV_LOCAL_MMR_BASE		(				\
3048c2ecf20Sopenharmony_ci					is_uv(UV2) ? UV2_LOCAL_MMR_BASE : \
3058c2ecf20Sopenharmony_ci					is_uv(UV3) ? UV3_LOCAL_MMR_BASE : \
3068c2ecf20Sopenharmony_ci					is_uv(UV4) ? UV4_LOCAL_MMR_BASE : \
3078c2ecf20Sopenharmony_ci					is_uv(UV5) ? UV5_LOCAL_MMR_BASE : \
3088c2ecf20Sopenharmony_ci					0)
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci#define UV_GLOBAL_MMR32_BASE		(				\
3118c2ecf20Sopenharmony_ci					is_uv(UV2) ? UV2_GLOBAL_MMR32_BASE : \
3128c2ecf20Sopenharmony_ci					is_uv(UV3) ? UV3_GLOBAL_MMR32_BASE : \
3138c2ecf20Sopenharmony_ci					is_uv(UV4) ? UV4_GLOBAL_MMR32_BASE : \
3148c2ecf20Sopenharmony_ci					is_uv(UV5) ? UV5_GLOBAL_MMR32_BASE : \
3158c2ecf20Sopenharmony_ci					0)
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci#define UV_LOCAL_MMR_SIZE		(				\
3188c2ecf20Sopenharmony_ci					is_uv(UV2) ? UV2_LOCAL_MMR_SIZE : \
3198c2ecf20Sopenharmony_ci					is_uv(UV3) ? UV3_LOCAL_MMR_SIZE : \
3208c2ecf20Sopenharmony_ci					is_uv(UV4) ? UV4_LOCAL_MMR_SIZE : \
3218c2ecf20Sopenharmony_ci					is_uv(UV5) ? UV5_LOCAL_MMR_SIZE : \
3228c2ecf20Sopenharmony_ci					0)
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci#define UV_GLOBAL_MMR32_SIZE		(				\
3258c2ecf20Sopenharmony_ci					is_uv(UV2) ? UV2_GLOBAL_MMR32_SIZE : \
3268c2ecf20Sopenharmony_ci					is_uv(UV3) ? UV3_GLOBAL_MMR32_SIZE : \
3278c2ecf20Sopenharmony_ci					is_uv(UV4) ? UV4_GLOBAL_MMR32_SIZE : \
3288c2ecf20Sopenharmony_ci					is_uv(UV5) ? UV5_GLOBAL_MMR32_SIZE : \
3298c2ecf20Sopenharmony_ci					0)
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci#define UV_GLOBAL_MMR64_BASE		(uv_hub_info->global_mmr_base)
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci#define UV_GLOBAL_GRU_MMR_BASE		0x4000000
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci#define UV_GLOBAL_MMR32_PNODE_SHIFT	15
3368c2ecf20Sopenharmony_ci#define _UV_GLOBAL_MMR64_PNODE_SHIFT	26
3378c2ecf20Sopenharmony_ci#define UV_GLOBAL_MMR64_PNODE_SHIFT	(uv_hub_info->global_mmr_shift)
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci#define UV_GLOBAL_MMR32_PNODE_BITS(p)	((p) << (UV_GLOBAL_MMR32_PNODE_SHIFT))
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci#define UV_GLOBAL_MMR64_PNODE_BITS(p)					\
3428c2ecf20Sopenharmony_ci	(((unsigned long)(p)) << UV_GLOBAL_MMR64_PNODE_SHIFT)
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci#define UVH_APICID		0x002D0E00L
3458c2ecf20Sopenharmony_ci#define UV_APIC_PNODE_SHIFT	6
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci/* Local Bus from cpu's perspective */
3488c2ecf20Sopenharmony_ci#define LOCAL_BUS_BASE		0x1c00000
3498c2ecf20Sopenharmony_ci#define LOCAL_BUS_SIZE		(4 * 1024 * 1024)
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci/*
3528c2ecf20Sopenharmony_ci * System Controller Interface Reg
3538c2ecf20Sopenharmony_ci *
3548c2ecf20Sopenharmony_ci * Note there are NO leds on a UV system.  This register is only
3558c2ecf20Sopenharmony_ci * used by the system controller to monitor system-wide operation.
3568c2ecf20Sopenharmony_ci * There are 64 regs per node.  With Nahelem cpus (2 cores per node,
3578c2ecf20Sopenharmony_ci * 8 cpus per core, 2 threads per cpu) there are 32 cpu threads on
3588c2ecf20Sopenharmony_ci * a node.
3598c2ecf20Sopenharmony_ci *
3608c2ecf20Sopenharmony_ci * The window is located at top of ACPI MMR space
3618c2ecf20Sopenharmony_ci */
3628c2ecf20Sopenharmony_ci#define SCIR_WINDOW_COUNT	64
3638c2ecf20Sopenharmony_ci#define SCIR_LOCAL_MMR_BASE	(LOCAL_BUS_BASE + \
3648c2ecf20Sopenharmony_ci				 LOCAL_BUS_SIZE - \
3658c2ecf20Sopenharmony_ci				 SCIR_WINDOW_COUNT)
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci#define SCIR_CPU_HEARTBEAT	0x01	/* timer interrupt */
3688c2ecf20Sopenharmony_ci#define SCIR_CPU_ACTIVITY	0x02	/* not idle */
3698c2ecf20Sopenharmony_ci#define SCIR_CPU_HB_INTERVAL	(HZ)	/* once per second */
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci/* Loop through all installed blades */
3728c2ecf20Sopenharmony_ci#define for_each_possible_blade(bid)		\
3738c2ecf20Sopenharmony_ci	for ((bid) = 0; (bid) < uv_num_possible_blades(); (bid)++)
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci/*
3768c2ecf20Sopenharmony_ci * Macros for converting between kernel virtual addresses, socket local physical
3778c2ecf20Sopenharmony_ci * addresses, and UV global physical addresses.
3788c2ecf20Sopenharmony_ci *	Note: use the standard __pa() & __va() macros for converting
3798c2ecf20Sopenharmony_ci *	      between socket virtual and socket physical addresses.
3808c2ecf20Sopenharmony_ci */
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci/* global bits offset - number of local address bits in gpa for this UV arch */
3838c2ecf20Sopenharmony_cistatic inline unsigned int uv_gpa_shift(void)
3848c2ecf20Sopenharmony_ci{
3858c2ecf20Sopenharmony_ci	return uv_hub_info->gpa_shift;
3868c2ecf20Sopenharmony_ci}
3878c2ecf20Sopenharmony_ci#define	_uv_gpa_shift
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci/* Find node that has the address range that contains global address  */
3908c2ecf20Sopenharmony_cistatic inline struct uv_gam_range_s *uv_gam_range(unsigned long pa)
3918c2ecf20Sopenharmony_ci{
3928c2ecf20Sopenharmony_ci	struct uv_gam_range_s *gr = uv_hub_info->gr_table;
3938c2ecf20Sopenharmony_ci	unsigned long pal = (pa & uv_hub_info->gpa_mask) >> UV_GAM_RANGE_SHFT;
3948c2ecf20Sopenharmony_ci	int i, num = uv_hub_info->gr_table_len;
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	if (gr) {
3978c2ecf20Sopenharmony_ci		for (i = 0; i < num; i++, gr++) {
3988c2ecf20Sopenharmony_ci			if (pal < gr->limit)
3998c2ecf20Sopenharmony_ci				return gr;
4008c2ecf20Sopenharmony_ci		}
4018c2ecf20Sopenharmony_ci	}
4028c2ecf20Sopenharmony_ci	pr_crit("UV: GAM Range for 0x%lx not found at %p!\n", pa, gr);
4038c2ecf20Sopenharmony_ci	BUG();
4048c2ecf20Sopenharmony_ci}
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci/* Return base address of node that contains global address  */
4078c2ecf20Sopenharmony_cistatic inline unsigned long uv_gam_range_base(unsigned long pa)
4088c2ecf20Sopenharmony_ci{
4098c2ecf20Sopenharmony_ci	struct uv_gam_range_s *gr = uv_gam_range(pa);
4108c2ecf20Sopenharmony_ci	int base = gr->base;
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	if (base < 0)
4138c2ecf20Sopenharmony_ci		return 0UL;
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	return uv_hub_info->gr_table[base].limit;
4168c2ecf20Sopenharmony_ci}
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci/* socket phys RAM --> UV global NASID (UV4+) */
4198c2ecf20Sopenharmony_cistatic inline unsigned long uv_soc_phys_ram_to_nasid(unsigned long paddr)
4208c2ecf20Sopenharmony_ci{
4218c2ecf20Sopenharmony_ci	return uv_gam_range(paddr)->nasid;
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci#define	_uv_soc_phys_ram_to_nasid
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci/* socket virtual --> UV global NASID (UV4+) */
4268c2ecf20Sopenharmony_cistatic inline unsigned long uv_gpa_nasid(void *v)
4278c2ecf20Sopenharmony_ci{
4288c2ecf20Sopenharmony_ci	return uv_soc_phys_ram_to_nasid(__pa(v));
4298c2ecf20Sopenharmony_ci}
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/* socket phys RAM --> UV global physical address */
4328c2ecf20Sopenharmony_cistatic inline unsigned long uv_soc_phys_ram_to_gpa(unsigned long paddr)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci	unsigned int m_val = uv_hub_info->m_val;
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	if (paddr < uv_hub_info->lowmem_remap_top)
4378c2ecf20Sopenharmony_ci		paddr |= uv_hub_info->lowmem_remap_base;
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	if (m_val) {
4408c2ecf20Sopenharmony_ci		paddr |= uv_hub_info->gnode_upper;
4418c2ecf20Sopenharmony_ci		paddr = ((paddr << uv_hub_info->m_shift)
4428c2ecf20Sopenharmony_ci						>> uv_hub_info->m_shift) |
4438c2ecf20Sopenharmony_ci			((paddr >> uv_hub_info->m_val)
4448c2ecf20Sopenharmony_ci						<< uv_hub_info->n_lshift);
4458c2ecf20Sopenharmony_ci	} else {
4468c2ecf20Sopenharmony_ci		paddr |= uv_soc_phys_ram_to_nasid(paddr)
4478c2ecf20Sopenharmony_ci						<< uv_hub_info->gpa_shift;
4488c2ecf20Sopenharmony_ci	}
4498c2ecf20Sopenharmony_ci	return paddr;
4508c2ecf20Sopenharmony_ci}
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci/* socket virtual --> UV global physical address */
4538c2ecf20Sopenharmony_cistatic inline unsigned long uv_gpa(void *v)
4548c2ecf20Sopenharmony_ci{
4558c2ecf20Sopenharmony_ci	return uv_soc_phys_ram_to_gpa(__pa(v));
4568c2ecf20Sopenharmony_ci}
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci/* Top two bits indicate the requested address is in MMR space.  */
4598c2ecf20Sopenharmony_cistatic inline int
4608c2ecf20Sopenharmony_ciuv_gpa_in_mmr_space(unsigned long gpa)
4618c2ecf20Sopenharmony_ci{
4628c2ecf20Sopenharmony_ci	return (gpa >> 62) == 0x3UL;
4638c2ecf20Sopenharmony_ci}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci/* UV global physical address --> socket phys RAM */
4668c2ecf20Sopenharmony_cistatic inline unsigned long uv_gpa_to_soc_phys_ram(unsigned long gpa)
4678c2ecf20Sopenharmony_ci{
4688c2ecf20Sopenharmony_ci	unsigned long paddr;
4698c2ecf20Sopenharmony_ci	unsigned long remap_base = uv_hub_info->lowmem_remap_base;
4708c2ecf20Sopenharmony_ci	unsigned long remap_top =  uv_hub_info->lowmem_remap_top;
4718c2ecf20Sopenharmony_ci	unsigned int m_val = uv_hub_info->m_val;
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	if (m_val)
4748c2ecf20Sopenharmony_ci		gpa = ((gpa << uv_hub_info->m_shift) >> uv_hub_info->m_shift) |
4758c2ecf20Sopenharmony_ci			((gpa >> uv_hub_info->n_lshift) << uv_hub_info->m_val);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	paddr = gpa & uv_hub_info->gpa_mask;
4788c2ecf20Sopenharmony_ci	if (paddr >= remap_base && paddr < remap_base + remap_top)
4798c2ecf20Sopenharmony_ci		paddr -= remap_base;
4808c2ecf20Sopenharmony_ci	return paddr;
4818c2ecf20Sopenharmony_ci}
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci/* gpa -> gnode */
4848c2ecf20Sopenharmony_cistatic inline unsigned long uv_gpa_to_gnode(unsigned long gpa)
4858c2ecf20Sopenharmony_ci{
4868c2ecf20Sopenharmony_ci	unsigned int n_lshift = uv_hub_info->n_lshift;
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci	if (n_lshift)
4898c2ecf20Sopenharmony_ci		return gpa >> n_lshift;
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	return uv_gam_range(gpa)->nasid >> 1;
4928c2ecf20Sopenharmony_ci}
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci/* gpa -> pnode */
4958c2ecf20Sopenharmony_cistatic inline int uv_gpa_to_pnode(unsigned long gpa)
4968c2ecf20Sopenharmony_ci{
4978c2ecf20Sopenharmony_ci	return uv_gpa_to_gnode(gpa) & uv_hub_info->pnode_mask;
4988c2ecf20Sopenharmony_ci}
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci/* gpa -> node offset */
5018c2ecf20Sopenharmony_cistatic inline unsigned long uv_gpa_to_offset(unsigned long gpa)
5028c2ecf20Sopenharmony_ci{
5038c2ecf20Sopenharmony_ci	unsigned int m_shift = uv_hub_info->m_shift;
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci	if (m_shift)
5068c2ecf20Sopenharmony_ci		return (gpa << m_shift) >> m_shift;
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci	return (gpa & uv_hub_info->gpa_mask) - uv_gam_range_base(gpa);
5098c2ecf20Sopenharmony_ci}
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci/* Convert socket to node */
5128c2ecf20Sopenharmony_cistatic inline int _uv_socket_to_node(int socket, unsigned short *s2nid)
5138c2ecf20Sopenharmony_ci{
5148c2ecf20Sopenharmony_ci	return s2nid ? s2nid[socket - uv_hub_info->min_socket] : socket;
5158c2ecf20Sopenharmony_ci}
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_cistatic inline int uv_socket_to_node(int socket)
5188c2ecf20Sopenharmony_ci{
5198c2ecf20Sopenharmony_ci	return _uv_socket_to_node(socket, uv_hub_info->socket_to_node);
5208c2ecf20Sopenharmony_ci}
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci/* pnode, offset --> socket virtual */
5238c2ecf20Sopenharmony_cistatic inline void *uv_pnode_offset_to_vaddr(int pnode, unsigned long offset)
5248c2ecf20Sopenharmony_ci{
5258c2ecf20Sopenharmony_ci	unsigned int m_val = uv_hub_info->m_val;
5268c2ecf20Sopenharmony_ci	unsigned long base;
5278c2ecf20Sopenharmony_ci	unsigned short sockid, node, *p2s;
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci	if (m_val)
5308c2ecf20Sopenharmony_ci		return __va(((unsigned long)pnode << m_val) | offset);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci	p2s = uv_hub_info->pnode_to_socket;
5338c2ecf20Sopenharmony_ci	sockid = p2s ? p2s[pnode - uv_hub_info->min_pnode] : pnode;
5348c2ecf20Sopenharmony_ci	node = uv_socket_to_node(sockid);
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci	/* limit address of previous socket is our base, except node 0 is 0 */
5378c2ecf20Sopenharmony_ci	if (!node)
5388c2ecf20Sopenharmony_ci		return __va((unsigned long)offset);
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci	base = (unsigned long)(uv_hub_info->gr_table[node - 1].limit);
5418c2ecf20Sopenharmony_ci	return __va(base << UV_GAM_RANGE_SHFT | offset);
5428c2ecf20Sopenharmony_ci}
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci/* Extract/Convert a PNODE from an APICID (full apicid, not processor subset) */
5458c2ecf20Sopenharmony_cistatic inline int uv_apicid_to_pnode(int apicid)
5468c2ecf20Sopenharmony_ci{
5478c2ecf20Sopenharmony_ci	int pnode = apicid >> uv_hub_info->apic_pnode_shift;
5488c2ecf20Sopenharmony_ci	unsigned short *s2pn = uv_hub_info->socket_to_pnode;
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci	return s2pn ? s2pn[pnode - uv_hub_info->min_socket] : pnode;
5518c2ecf20Sopenharmony_ci}
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_ci/*
5548c2ecf20Sopenharmony_ci * Access global MMRs using the low memory MMR32 space. This region supports
5558c2ecf20Sopenharmony_ci * faster MMR access but not all MMRs are accessible in this space.
5568c2ecf20Sopenharmony_ci */
5578c2ecf20Sopenharmony_cistatic inline unsigned long *uv_global_mmr32_address(int pnode, unsigned long offset)
5588c2ecf20Sopenharmony_ci{
5598c2ecf20Sopenharmony_ci	return __va(UV_GLOBAL_MMR32_BASE |
5608c2ecf20Sopenharmony_ci		       UV_GLOBAL_MMR32_PNODE_BITS(pnode) | offset);
5618c2ecf20Sopenharmony_ci}
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_cistatic inline void uv_write_global_mmr32(int pnode, unsigned long offset, unsigned long val)
5648c2ecf20Sopenharmony_ci{
5658c2ecf20Sopenharmony_ci	writeq(val, uv_global_mmr32_address(pnode, offset));
5668c2ecf20Sopenharmony_ci}
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_cistatic inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset)
5698c2ecf20Sopenharmony_ci{
5708c2ecf20Sopenharmony_ci	return readq(uv_global_mmr32_address(pnode, offset));
5718c2ecf20Sopenharmony_ci}
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci/*
5748c2ecf20Sopenharmony_ci * Access Global MMR space using the MMR space located at the top of physical
5758c2ecf20Sopenharmony_ci * memory.
5768c2ecf20Sopenharmony_ci */
5778c2ecf20Sopenharmony_cistatic inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset)
5788c2ecf20Sopenharmony_ci{
5798c2ecf20Sopenharmony_ci	return __va(UV_GLOBAL_MMR64_BASE |
5808c2ecf20Sopenharmony_ci		    UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
5818c2ecf20Sopenharmony_ci}
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_cistatic inline void uv_write_global_mmr64(int pnode, unsigned long offset, unsigned long val)
5848c2ecf20Sopenharmony_ci{
5858c2ecf20Sopenharmony_ci	writeq(val, uv_global_mmr64_address(pnode, offset));
5868c2ecf20Sopenharmony_ci}
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_cistatic inline unsigned long uv_read_global_mmr64(int pnode, unsigned long offset)
5898c2ecf20Sopenharmony_ci{
5908c2ecf20Sopenharmony_ci	return readq(uv_global_mmr64_address(pnode, offset));
5918c2ecf20Sopenharmony_ci}
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_cistatic inline void uv_write_global_mmr8(int pnode, unsigned long offset, unsigned char val)
5948c2ecf20Sopenharmony_ci{
5958c2ecf20Sopenharmony_ci	writeb(val, uv_global_mmr64_address(pnode, offset));
5968c2ecf20Sopenharmony_ci}
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_cistatic inline unsigned char uv_read_global_mmr8(int pnode, unsigned long offset)
5998c2ecf20Sopenharmony_ci{
6008c2ecf20Sopenharmony_ci	return readb(uv_global_mmr64_address(pnode, offset));
6018c2ecf20Sopenharmony_ci}
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci/*
6048c2ecf20Sopenharmony_ci * Access hub local MMRs. Faster than using global space but only local MMRs
6058c2ecf20Sopenharmony_ci * are accessible.
6068c2ecf20Sopenharmony_ci */
6078c2ecf20Sopenharmony_cistatic inline unsigned long *uv_local_mmr_address(unsigned long offset)
6088c2ecf20Sopenharmony_ci{
6098c2ecf20Sopenharmony_ci	return __va(UV_LOCAL_MMR_BASE | offset);
6108c2ecf20Sopenharmony_ci}
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_cistatic inline unsigned long uv_read_local_mmr(unsigned long offset)
6138c2ecf20Sopenharmony_ci{
6148c2ecf20Sopenharmony_ci	return readq(uv_local_mmr_address(offset));
6158c2ecf20Sopenharmony_ci}
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_cistatic inline void uv_write_local_mmr(unsigned long offset, unsigned long val)
6188c2ecf20Sopenharmony_ci{
6198c2ecf20Sopenharmony_ci	writeq(val, uv_local_mmr_address(offset));
6208c2ecf20Sopenharmony_ci}
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_cistatic inline unsigned char uv_read_local_mmr8(unsigned long offset)
6238c2ecf20Sopenharmony_ci{
6248c2ecf20Sopenharmony_ci	return readb(uv_local_mmr_address(offset));
6258c2ecf20Sopenharmony_ci}
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_cistatic inline void uv_write_local_mmr8(unsigned long offset, unsigned char val)
6288c2ecf20Sopenharmony_ci{
6298c2ecf20Sopenharmony_ci	writeb(val, uv_local_mmr_address(offset));
6308c2ecf20Sopenharmony_ci}
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ci/* Blade-local cpu number of current cpu. Numbered 0 .. <# cpus on the blade> */
6338c2ecf20Sopenharmony_cistatic inline int uv_blade_processor_id(void)
6348c2ecf20Sopenharmony_ci{
6358c2ecf20Sopenharmony_ci	return uv_cpu_info->blade_cpu_id;
6368c2ecf20Sopenharmony_ci}
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci/* Blade-local cpu number of cpu N. Numbered 0 .. <# cpus on the blade> */
6398c2ecf20Sopenharmony_cistatic inline int uv_cpu_blade_processor_id(int cpu)
6408c2ecf20Sopenharmony_ci{
6418c2ecf20Sopenharmony_ci	return uv_cpu_info_per(cpu)->blade_cpu_id;
6428c2ecf20Sopenharmony_ci}
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_ci/* Blade number to Node number (UV2..UV4 is 1:1) */
6458c2ecf20Sopenharmony_cistatic inline int uv_blade_to_node(int blade)
6468c2ecf20Sopenharmony_ci{
6478c2ecf20Sopenharmony_ci	return blade;
6488c2ecf20Sopenharmony_ci}
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci/* Blade number of current cpu. Numnbered 0 .. <#blades -1> */
6518c2ecf20Sopenharmony_cistatic inline int uv_numa_blade_id(void)
6528c2ecf20Sopenharmony_ci{
6538c2ecf20Sopenharmony_ci	return uv_hub_info->numa_blade_id;
6548c2ecf20Sopenharmony_ci}
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci/*
6578c2ecf20Sopenharmony_ci * Convert linux node number to the UV blade number.
6588c2ecf20Sopenharmony_ci * .. Currently for UV2 thru UV4 the node and the blade are identical.
6598c2ecf20Sopenharmony_ci * .. If this changes then you MUST check references to this function!
6608c2ecf20Sopenharmony_ci */
6618c2ecf20Sopenharmony_cistatic inline int uv_node_to_blade_id(int nid)
6628c2ecf20Sopenharmony_ci{
6638c2ecf20Sopenharmony_ci	return nid;
6648c2ecf20Sopenharmony_ci}
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci/* Convert a CPU number to the UV blade number */
6678c2ecf20Sopenharmony_cistatic inline int uv_cpu_to_blade_id(int cpu)
6688c2ecf20Sopenharmony_ci{
6698c2ecf20Sopenharmony_ci	return uv_node_to_blade_id(cpu_to_node(cpu));
6708c2ecf20Sopenharmony_ci}
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_ci/* Convert a blade id to the PNODE of the blade */
6738c2ecf20Sopenharmony_cistatic inline int uv_blade_to_pnode(int bid)
6748c2ecf20Sopenharmony_ci{
6758c2ecf20Sopenharmony_ci	return uv_hub_info_list(uv_blade_to_node(bid))->pnode;
6768c2ecf20Sopenharmony_ci}
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci/* Nid of memory node on blade. -1 if no blade-local memory */
6798c2ecf20Sopenharmony_cistatic inline int uv_blade_to_memory_nid(int bid)
6808c2ecf20Sopenharmony_ci{
6818c2ecf20Sopenharmony_ci	return uv_hub_info_list(uv_blade_to_node(bid))->memory_nid;
6828c2ecf20Sopenharmony_ci}
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci/* Determine the number of possible cpus on a blade */
6858c2ecf20Sopenharmony_cistatic inline int uv_blade_nr_possible_cpus(int bid)
6868c2ecf20Sopenharmony_ci{
6878c2ecf20Sopenharmony_ci	return uv_hub_info_list(uv_blade_to_node(bid))->nr_possible_cpus;
6888c2ecf20Sopenharmony_ci}
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci/* Determine the number of online cpus on a blade */
6918c2ecf20Sopenharmony_cistatic inline int uv_blade_nr_online_cpus(int bid)
6928c2ecf20Sopenharmony_ci{
6938c2ecf20Sopenharmony_ci	return uv_hub_info_list(uv_blade_to_node(bid))->nr_online_cpus;
6948c2ecf20Sopenharmony_ci}
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci/* Convert a cpu id to the PNODE of the blade containing the cpu */
6978c2ecf20Sopenharmony_cistatic inline int uv_cpu_to_pnode(int cpu)
6988c2ecf20Sopenharmony_ci{
6998c2ecf20Sopenharmony_ci	return uv_cpu_hub_info(cpu)->pnode;
7008c2ecf20Sopenharmony_ci}
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci/* Convert a linux node number to the PNODE of the blade */
7038c2ecf20Sopenharmony_cistatic inline int uv_node_to_pnode(int nid)
7048c2ecf20Sopenharmony_ci{
7058c2ecf20Sopenharmony_ci	return uv_hub_info_list(nid)->pnode;
7068c2ecf20Sopenharmony_ci}
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci/* Maximum possible number of blades */
7098c2ecf20Sopenharmony_ciextern short uv_possible_blades;
7108c2ecf20Sopenharmony_cistatic inline int uv_num_possible_blades(void)
7118c2ecf20Sopenharmony_ci{
7128c2ecf20Sopenharmony_ci	return uv_possible_blades;
7138c2ecf20Sopenharmony_ci}
7148c2ecf20Sopenharmony_ci
7158c2ecf20Sopenharmony_ci/* Per Hub NMI support */
7168c2ecf20Sopenharmony_ciextern void uv_nmi_setup(void);
7178c2ecf20Sopenharmony_ciextern void uv_nmi_setup_hubless(void);
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_ci/* BIOS/Kernel flags exchange MMR */
7208c2ecf20Sopenharmony_ci#define UVH_BIOS_KERNEL_MMR		UVH_SCRATCH5
7218c2ecf20Sopenharmony_ci#define UVH_BIOS_KERNEL_MMR_ALIAS	UVH_SCRATCH5_ALIAS
7228c2ecf20Sopenharmony_ci#define UVH_BIOS_KERNEL_MMR_ALIAS_2	UVH_SCRATCH5_ALIAS_2
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci/* TSC sync valid, set by BIOS */
7258c2ecf20Sopenharmony_ci#define UVH_TSC_SYNC_MMR	UVH_BIOS_KERNEL_MMR
7268c2ecf20Sopenharmony_ci#define UVH_TSC_SYNC_SHIFT	10
7278c2ecf20Sopenharmony_ci#define UVH_TSC_SYNC_SHIFT_UV2K	16	/* UV2/3k have different bits */
7288c2ecf20Sopenharmony_ci#define UVH_TSC_SYNC_MASK	3	/* 0011 */
7298c2ecf20Sopenharmony_ci#define UVH_TSC_SYNC_VALID	3	/* 0011 */
7308c2ecf20Sopenharmony_ci#define UVH_TSC_SYNC_UNKNOWN	0	/* 0000 */
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci/* BMC sets a bit this MMR non-zero before sending an NMI */
7338c2ecf20Sopenharmony_ci#define UVH_NMI_MMR		UVH_BIOS_KERNEL_MMR
7348c2ecf20Sopenharmony_ci#define UVH_NMI_MMR_CLEAR	UVH_BIOS_KERNEL_MMR_ALIAS
7358c2ecf20Sopenharmony_ci#define UVH_NMI_MMR_SHIFT	63
7368c2ecf20Sopenharmony_ci#define UVH_NMI_MMR_TYPE	"SCRATCH5"
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_cistruct uv_hub_nmi_s {
7398c2ecf20Sopenharmony_ci	raw_spinlock_t	nmi_lock;
7408c2ecf20Sopenharmony_ci	atomic_t	in_nmi;		/* flag this node in UV NMI IRQ */
7418c2ecf20Sopenharmony_ci	atomic_t	cpu_owner;	/* last locker of this struct */
7428c2ecf20Sopenharmony_ci	atomic_t	read_mmr_count;	/* count of MMR reads */
7438c2ecf20Sopenharmony_ci	atomic_t	nmi_count;	/* count of true UV NMIs */
7448c2ecf20Sopenharmony_ci	unsigned long	nmi_value;	/* last value read from NMI MMR */
7458c2ecf20Sopenharmony_ci	bool		hub_present;	/* false means UV hubless system */
7468c2ecf20Sopenharmony_ci	bool		pch_owner;	/* indicates this hub owns PCH */
7478c2ecf20Sopenharmony_ci};
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_cistruct uv_cpu_nmi_s {
7508c2ecf20Sopenharmony_ci	struct uv_hub_nmi_s	*hub;
7518c2ecf20Sopenharmony_ci	int			state;
7528c2ecf20Sopenharmony_ci	int			pinging;
7538c2ecf20Sopenharmony_ci	int			queries;
7548c2ecf20Sopenharmony_ci	int			pings;
7558c2ecf20Sopenharmony_ci};
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ciDECLARE_PER_CPU(struct uv_cpu_nmi_s, uv_cpu_nmi);
7588c2ecf20Sopenharmony_ci
7598c2ecf20Sopenharmony_ci#define uv_hub_nmi			this_cpu_read(uv_cpu_nmi.hub)
7608c2ecf20Sopenharmony_ci#define uv_cpu_nmi_per(cpu)		(per_cpu(uv_cpu_nmi, cpu))
7618c2ecf20Sopenharmony_ci#define uv_hub_nmi_per(cpu)		(uv_cpu_nmi_per(cpu).hub)
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_ci/* uv_cpu_nmi_states */
7648c2ecf20Sopenharmony_ci#define	UV_NMI_STATE_OUT		0
7658c2ecf20Sopenharmony_ci#define	UV_NMI_STATE_IN			1
7668c2ecf20Sopenharmony_ci#define	UV_NMI_STATE_DUMP		2
7678c2ecf20Sopenharmony_ci#define	UV_NMI_STATE_DUMP_DONE		3
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_ci/*
7708c2ecf20Sopenharmony_ci * Get the minimum revision number of the hub chips within the partition.
7718c2ecf20Sopenharmony_ci * (See UVx_HUB_REVISION_BASE above for specific values.)
7728c2ecf20Sopenharmony_ci */
7738c2ecf20Sopenharmony_cistatic inline int uv_get_min_hub_revision_id(void)
7748c2ecf20Sopenharmony_ci{
7758c2ecf20Sopenharmony_ci	return uv_hub_info->hub_revision;
7768c2ecf20Sopenharmony_ci}
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci#endif /* CONFIG_X86_64 */
7798c2ecf20Sopenharmony_ci#endif /* _ASM_X86_UV_UV_HUB_H */
780