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