1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _ASM_X86_UV_BIOS_H
3 #define _ASM_X86_UV_BIOS_H
4 
5 /*
6  * UV BIOS layer definitions.
7  *
8  * (C) Copyright 2020 Hewlett Packard Enterprise Development LP
9  * Copyright (C) 2007-2017 Silicon Graphics, Inc. All rights reserved.
10  * Copyright (c) Russ Anderson <rja@sgi.com>
11  */
12 
13 #include <linux/rtc.h>
14 
15 /*
16  * Values for the BIOS calls.  It is passed as the first * argument in the
17  * BIOS call.  Passing any other value in the first argument will result
18  * in a BIOS_STATUS_UNIMPLEMENTED return status.
19  */
20 enum uv_bios_cmd {
21 	UV_BIOS_COMMON,
22 	UV_BIOS_GET_SN_INFO,
23 	UV_BIOS_FREQ_BASE,
24 	UV_BIOS_WATCHLIST_ALLOC,
25 	UV_BIOS_WATCHLIST_FREE,
26 	UV_BIOS_MEMPROTECT,
27 	UV_BIOS_GET_PARTITION_ADDR,
28 	UV_BIOS_SET_LEGACY_VGA_TARGET
29 };
30 
31 #define UV_BIOS_EXTRA			    0x10000
32 #define UV_BIOS_GET_PCI_TOPOLOGY	    0x10001
33 #define UV_BIOS_GET_GEOINFO		    0x10003
34 
35 #define UV_BIOS_EXTRA_OP_MEM_COPYIN	    0x1000
36 #define UV_BIOS_EXTRA_OP_MEM_COPYOUT	    0x2000
37 #define UV_BIOS_EXTRA_OP_MASK		    0x0fff
38 #define UV_BIOS_EXTRA_GET_HEAPSIZE	    1
39 #define UV_BIOS_EXTRA_INSTALL_HEAP	    2
40 #define UV_BIOS_EXTRA_MASTER_NASID	    3
41 #define UV_BIOS_EXTRA_OBJECT_COUNT	    (10|UV_BIOS_EXTRA_OP_MEM_COPYOUT)
42 #define UV_BIOS_EXTRA_ENUM_OBJECTS	    (12|UV_BIOS_EXTRA_OP_MEM_COPYOUT)
43 #define UV_BIOS_EXTRA_ENUM_PORTS	    (13|UV_BIOS_EXTRA_OP_MEM_COPYOUT)
44 
45 /*
46  * Status values returned from a BIOS call.
47  */
48 enum {
49 	BIOS_STATUS_MORE_PASSES		=  1,
50 	BIOS_STATUS_SUCCESS		=  0,
51 	BIOS_STATUS_UNIMPLEMENTED	= -ENOSYS,
52 	BIOS_STATUS_EINVAL		= -EINVAL,
53 	BIOS_STATUS_UNAVAIL		= -EBUSY,
54 	BIOS_STATUS_ABORT		= -EINTR,
55 };
56 
57 /* Address map parameters */
58 struct uv_gam_parameters {
59 	u64	mmr_base;
60 	u64	gru_base;
61 	u8	mmr_shift;	/* Convert PNode to MMR space offset */
62 	u8	gru_shift;	/* Convert PNode to GRU space offset */
63 	u8	gpa_shift;	/* Size of offset field in GRU phys addr */
64 	u8	unused1;
65 };
66 
67 /* UV_TABLE_GAM_RANGE_ENTRY values */
68 #define UV_GAM_RANGE_TYPE_UNUSED	0 /* End of table */
69 #define UV_GAM_RANGE_TYPE_RAM		1 /* Normal RAM */
70 #define UV_GAM_RANGE_TYPE_NVRAM		2 /* Non-volatile memory */
71 #define UV_GAM_RANGE_TYPE_NV_WINDOW	3 /* NVMDIMM block window */
72 #define UV_GAM_RANGE_TYPE_NV_MAILBOX	4 /* NVMDIMM mailbox */
73 #define UV_GAM_RANGE_TYPE_HOLE		5 /* Unused address range */
74 #define UV_GAM_RANGE_TYPE_MAX		6
75 
76 /* The structure stores PA bits 56:26, for 64MB granularity */
77 #define UV_GAM_RANGE_SHFT		26		/* 64MB */
78 
79 struct uv_gam_range_entry {
80 	char	type;		/* Entry type: GAM_RANGE_TYPE_UNUSED, etc. */
81 	char	unused1;
82 	u16	nasid;		/* HNasid */
83 	u16	sockid;		/* Socket ID, high bits of APIC ID */
84 	u16	pnode;		/* Index to MMR and GRU spaces */
85 	u32	unused2;
86 	u32	limit;		/* PA bits 56:26 (UV_GAM_RANGE_SHFT) */
87 };
88 
89 #define	UV_AT_SIZE	8	/* 7 character arch type + NULL char */
90 struct uv_arch_type_entry {
91 	char	archtype[UV_AT_SIZE];
92 };
93 
94 #define	UV_SYSTAB_SIG			"UVST"
95 #define	UV_SYSTAB_VERSION_1		1	/* UV2/3 BIOS version */
96 #define	UV_SYSTAB_VERSION_UV4		0x400	/* UV4 BIOS base version */
97 #define	UV_SYSTAB_VERSION_UV4_1		0x401	/* + gpa_shift */
98 #define	UV_SYSTAB_VERSION_UV4_2		0x402	/* + TYPE_NVRAM/WINDOW/MBOX */
99 #define	UV_SYSTAB_VERSION_UV4_3		0x403	/* - GAM Range PXM Value */
100 #define	UV_SYSTAB_VERSION_UV4_LATEST	UV_SYSTAB_VERSION_UV4_3
101 
102 #define	UV_SYSTAB_VERSION_UV5		0x500	/* UV5 GAM base version */
103 #define	UV_SYSTAB_VERSION_UV5_LATEST	UV_SYSTAB_VERSION_UV5
104 
105 #define	UV_SYSTAB_TYPE_UNUSED		0	/* End of table (offset == 0) */
106 #define	UV_SYSTAB_TYPE_GAM_PARAMS	1	/* GAM PARAM conversions */
107 #define	UV_SYSTAB_TYPE_GAM_RNG_TBL	2	/* GAM entry table */
108 #define	UV_SYSTAB_TYPE_ARCH_TYPE	3	/* UV arch type */
109 #define	UV_SYSTAB_TYPE_MAX		4
110 
111 /*
112  * The UV system table describes specific firmware
113  * capabilities available to the Linux kernel at runtime.
114  */
115 struct uv_systab {
116 	char signature[4];	/* must be UV_SYSTAB_SIG */
117 	u32 revision;		/* distinguish different firmware revs */
118 	u64 function;		/* BIOS runtime callback function ptr */
119 	u32 size;		/* systab size (starting with _VERSION_UV4) */
120 	struct {
121 		u32 type:8;	/* type of entry */
122 		u32 offset:24;	/* byte offset from struct start to entry */
123 	} entry[1];		/* additional entries follow */
124 };
125 extern struct uv_systab *uv_systab;
126 
127 #define UV_BIOS_MAXSTRING	      128
128 struct uv_bios_hub_info {
129 	unsigned int id;
130 	union {
131 		struct {
132 			unsigned long long this_part:1;
133 			unsigned long long is_shared:1;
134 			unsigned long long is_disabled:1;
135 		} fields;
136 		struct {
137 			unsigned long long flags;
138 			unsigned long long reserved;
139 		} b;
140 	} f;
141 	char name[UV_BIOS_MAXSTRING];
142 	char location[UV_BIOS_MAXSTRING];
143 	unsigned int ports;
144 };
145 
146 struct uv_bios_port_info {
147 	unsigned int port;
148 	unsigned int conn_id;
149 	unsigned int conn_port;
150 };
151 
152 /* (... end of definitions from UV BIOS ...) */
153 
154 enum {
155 	BIOS_FREQ_BASE_PLATFORM = 0,
156 	BIOS_FREQ_BASE_INTERVAL_TIMER = 1,
157 	BIOS_FREQ_BASE_REALTIME_CLOCK = 2
158 };
159 
160 union partition_info_u {
161 	u64	val;
162 	struct {
163 		u64	hub_version	:  8,
164 			partition_id	: 16,
165 			coherence_id	: 16,
166 			region_size	: 24;
167 	};
168 };
169 
170 enum uv_memprotect {
171 	UV_MEMPROT_RESTRICT_ACCESS,
172 	UV_MEMPROT_ALLOW_AMO,
173 	UV_MEMPROT_ALLOW_RW
174 };
175 
176 extern s64 uv_bios_get_sn_info(int, int *, long *, long *, long *, long *);
177 extern s64 uv_bios_freq_base(u64, u64 *);
178 extern int uv_bios_mq_watchlist_alloc(unsigned long, unsigned int,
179 					unsigned long *);
180 extern int uv_bios_mq_watchlist_free(int, int);
181 extern s64 uv_bios_change_memprotect(u64, u64, enum uv_memprotect);
182 extern s64 uv_bios_reserved_page_pa(u64, u64 *, u64 *, u64 *);
183 extern int uv_bios_set_legacy_vga_target(bool decode, int domain, int bus);
184 
185 extern s64 uv_bios_get_master_nasid(u64 sz, u64 *nasid);
186 extern s64 uv_bios_get_heapsize(u64 nasid, u64 sz, u64 *heap_sz);
187 extern s64 uv_bios_install_heap(u64 nasid, u64 sz, u64 *heap);
188 extern s64 uv_bios_obj_count(u64 nasid, u64 sz, u64 *objcnt);
189 extern s64 uv_bios_enum_objs(u64 nasid, u64 sz, u64 *objbuf);
190 extern s64 uv_bios_enum_ports(u64 nasid, u64 obj_id, u64 sz, u64 *portbuf);
191 extern s64 uv_bios_get_geoinfo(u64 nasid, u64 sz, u64 *geo);
192 extern s64 uv_bios_get_pci_topology(u64 sz, u64 *buf);
193 
194 extern int uv_bios_init(void);
195 extern unsigned long get_uv_systab_phys(bool msg);
196 
197 extern unsigned long sn_rtc_cycles_per_second;
198 extern int uv_type;
199 extern long sn_partition_id;
200 extern long sn_coherency_id;
201 extern long sn_region_size;
202 extern long system_serial_number;
203 extern ssize_t uv_get_archtype(char *buf, int len);
204 extern int uv_get_hubless_system(void);
205 
206 extern struct kobject *sgi_uv_kobj;	/* /sys/firmware/sgi_uv */
207 
208 /*
209  * EFI runtime lock; cf. firmware/efi/runtime-wrappers.c for details
210  */
211 extern struct semaphore __efi_uv_runtime_lock;
212 
213 #endif /* _ASM_X86_UV_BIOS_H */
214