xref: /titanic_41/usr/src/uts/common/sys/ucode.h (revision 7b9b3bf3fd4f7bfad91fce91e3e9fba62ac85c77)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_UCODE_H
27 #define	_SYS_UCODE_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <sys/priv.h>
33 #include <sys/processor.h>
34 #ifndef _KERNEL
35 #include <limits.h>
36 #endif
37 #include <ucode/ucode_errno.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  *	/dev/ucode
45  */
46 #define	UCODE_DRIVER_NAME	"ucode"
47 #define	UCODE_NODE_NAME		"ucode"
48 #define	UCODE_MINOR		((minor_t)0x3fffful)
49 
50 /*
51  * Where to install the microcode
52  */
53 #define	UCODE_INSTALL_PATH		"platform/i86pc/ucode"
54 #define	UCODE_INSTALL_COMMON_PATH	".f"
55 
56 /*
57  * ioctl numbers
58  */
59 #define	UCODE_IOC		(('u'<<24)|('c'<<16)|('o'<<8))
60 
61 #define	UCODE_GET_VERSION	(UCODE_IOC|0)
62 #define	UCODE_UPDATE		(UCODE_IOC|1)
63 
64 struct ucode_get_rev_struct {
65 	uint32_t *ugv_rev;		/* microcode revision array */
66 	int ugv_size;			/* size of the array */
67 	ucode_errno_t ugv_errno;	/* EUC error code */
68 };
69 
70 struct ucode_write_struct {
71 	uint32_t uw_size;	/* size of the uw_code buffer */
72 	uint8_t *uw_ucode;	/* pointer to the undigested microcode */
73 	ucode_errno_t uw_errno;	/* EUC error code */
74 };
75 
76 #if defined(_SYSCALL32_IMPL)
77 
78 #include <sys/types32.h>
79 
80 struct ucode_get_rev_struct32 {
81 	caddr32_t ugv_rev;		/* microcode revision array */
82 	int ugv_size;			/* size of the array */
83 	ucode_errno_t ugv_errno;	/* EUC error code */
84 };
85 
86 struct ucode_write_struct32 {
87 	uint32_t uw_size;	/* size of the uw_code buffer */
88 	caddr32_t uw_ucode;	/* pointer to the undigested microcode */
89 	ucode_errno_t uw_errno;	/* EUC error code */
90 };
91 
92 #endif	/* _SYSCALL32_IMPL */
93 
94 /*
95  * Microcode file information
96  */
97 typedef struct ucode_header {
98 	uint32_t	uh_header_ver;
99 	uint32_t	uh_rev;
100 	uint32_t	uh_date;
101 	uint32_t	uh_signature;
102 	uint32_t	uh_checksum;
103 	uint32_t	uh_loader_ver;
104 	uint32_t	uh_proc_flags;
105 	uint32_t	uh_body_size;
106 	uint32_t	uh_total_size;
107 	uint32_t	uh_reserved[3];
108 } ucode_header_t;
109 
110 typedef struct ucode_ext_sig {
111 	uint32_t	ues_signature;
112 	uint32_t	ues_proc_flags;
113 	uint32_t	ues_checksum;
114 } ucode_ext_sig_t;
115 
116 typedef struct ucode_ext_table {
117 	uint32_t	uet_count;
118 	uint32_t	uet_checksum;
119 	uint32_t	uet_reserved[3];
120 	ucode_ext_sig_t uet_ext_sig[1];
121 } ucode_ext_table_t;
122 
123 typedef struct ucode_file {
124 	ucode_header_t		uf_header;
125 	uint8_t			*uf_body;
126 	ucode_ext_table_t	*uf_ext_table;
127 } ucode_file_t;
128 
129 
130 #define	UCODE_SHORT_NAME_LEN	12	/* "32-bit-sig"-"8-bit-platid"\0 */
131 /*
132  * Length of UCODE_INSTALL_COMMON_PATH/short-name
133  *	strlen(UCODE_INSTALL_COMMON_PATH) + 1 + UCODE_SHORT_NAME_LEN
134  * Use sizeof which will give us the additional byte for the '/' in between
135  * the common path and the file name.
136  */
137 #define	UCODE_COMMON_NAME_LEN	\
138 	(sizeof (UCODE_INSTALL_COMMON_PATH) + (UCODE_SHORT_NAME_LEN))
139 #define	UCODE_MAX_PATH_LEN	(PATH_MAX - UCODE_COMMON_NAME_LEN)
140 
141 
142 #define	UCODE_HEADER_SIZE	(sizeof (struct ucode_header))
143 #define	UCODE_EXT_TABLE_SIZE	(20)	/* 20-bytes */
144 #define	UCODE_EXT_SIG_SIZE	(sizeof (struct ucode_ext_sig))
145 
146 #define	UCODE_KB(a)	((a) << 10)	/* KB */
147 #define	UCODE_MB(a)	((a) << 20)	/* MB */
148 #define	UCODE_DEFAULT_TOTAL_SIZE	UCODE_KB(2)
149 #define	UCODE_DEFAULT_BODY_SIZE		(UCODE_KB(2) - UCODE_HEADER_SIZE)
150 
151 /*
152  * For a single microcode file, the minimum size is 1K, maximum size is 16K.
153  * Such limitations, while somewhat artificial, are not only to provide better
154  * sanity checks, but also avoid wasting precious memory at startup time as the
155  * microcode buffer for the first processor has to be statically allocated.
156  *
157  * For the concatenation of all the microcode binary files, the maximum size
158  * is 16M.
159  */
160 #define	UCODE_MIN_SIZE			UCODE_KB(1)
161 #define	UCODE_MAX_SIZE			UCODE_KB(16)
162 #define	UCODE_MAX_COMBINED_SIZE		UCODE_MB(16)
163 
164 #define	UCODE_SIZE_CONVERT(size, default_size) \
165 	((size) == 0 ? (default_size) : (size))
166 
167 #define	UCODE_BODY_SIZE(size) \
168 	UCODE_SIZE_CONVERT((size), UCODE_DEFAULT_BODY_SIZE)
169 
170 #define	UCODE_TOTAL_SIZE(size) \
171 	UCODE_SIZE_CONVERT((size), UCODE_DEFAULT_TOTAL_SIZE)
172 
173 #define	UCODE_MATCH(sig1, sig2, pf1, pf2) \
174 	(((sig1) == (sig2)) && \
175 	(((pf1) & (pf2)) || (((pf1) == 0) && ((pf2) == 0))))
176 
177 extern ucode_errno_t ucode_header_validate(ucode_header_t *);
178 extern uint32_t ucode_checksum(uint32_t, uint32_t, uint8_t *);
179 extern ucode_errno_t ucode_validate(uint8_t *, int);
180 extern ucode_errno_t ucode_get_rev(uint32_t *);
181 extern ucode_errno_t ucode_update(uint8_t *, int);
182 
183 #define	UCODE_MAX_VENDORS_NAME_LEN		20
184 
185 #define	UCODE_VENDORS				\
186 static struct {					\
187 	char *filestr;				\
188 	char *vendorstr;			\
189 	int  supported;				\
190 } ucode_vendors[] = {				\
191 	{ "intel", "GenuineIntel", 1 },		\
192 	{ "amd", "AuthenticAMD", 0 },		\
193 	{ NULL, NULL, 0 }				\
194 }
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #endif	/* _SYS_UCODE_H */
201