xref: /titanic_51/usr/src/uts/common/sys/ucode.h (revision adc586debf12d2592024c0b8b9e44ffa104f858c)
12449e17fSsherrym /*
22449e17fSsherrym  * CDDL HEADER START
32449e17fSsherrym  *
42449e17fSsherrym  * The contents of this file are subject to the terms of the
52449e17fSsherrym  * Common Development and Distribution License (the "License").
62449e17fSsherrym  * You may not use this file except in compliance with the License.
72449e17fSsherrym  *
82449e17fSsherrym  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92449e17fSsherrym  * or http://www.opensolaris.org/os/licensing.
102449e17fSsherrym  * See the License for the specific language governing permissions
112449e17fSsherrym  * and limitations under the License.
122449e17fSsherrym  *
132449e17fSsherrym  * When distributing Covered Code, include this CDDL HEADER in each
142449e17fSsherrym  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152449e17fSsherrym  * If applicable, add the following below this CDDL HEADER, with the
162449e17fSsherrym  * fields enclosed by brackets "[]" replaced with your own identifying
172449e17fSsherrym  * information: Portions Copyright [yyyy] [name of copyright owner]
182449e17fSsherrym  *
192449e17fSsherrym  * CDDL HEADER END
202449e17fSsherrym  */
212449e17fSsherrym /*
22*adc586deSMark Johnson  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
232449e17fSsherrym  * Use is subject to license terms.
242449e17fSsherrym  */
252449e17fSsherrym 
262449e17fSsherrym #ifndef	_SYS_UCODE_H
272449e17fSsherrym #define	_SYS_UCODE_H
282449e17fSsherrym 
29*adc586deSMark Johnson #ifdef _KERNEL
30*adc586deSMark Johnson #include <sys/cpuvar.h>
31*adc586deSMark Johnson #endif
322449e17fSsherrym #include <sys/types.h>
332449e17fSsherrym #include <sys/priv.h>
342449e17fSsherrym #include <sys/processor.h>
352449e17fSsherrym #ifndef _KERNEL
362449e17fSsherrym #include <limits.h>
372449e17fSsherrym #endif
382449e17fSsherrym #include <ucode/ucode_errno.h>
392449e17fSsherrym 
402449e17fSsherrym #ifdef __cplusplus
412449e17fSsherrym extern "C" {
422449e17fSsherrym #endif
432449e17fSsherrym 
442449e17fSsherrym /*
452449e17fSsherrym  *	/dev/ucode
462449e17fSsherrym  */
472449e17fSsherrym #define	UCODE_DRIVER_NAME	"ucode"
482449e17fSsherrym #define	UCODE_NODE_NAME		"ucode"
492449e17fSsherrym #define	UCODE_MINOR		((minor_t)0x3fffful)
502449e17fSsherrym 
512449e17fSsherrym /*
522449e17fSsherrym  * Where to install the microcode
532449e17fSsherrym  */
542449e17fSsherrym #define	UCODE_INSTALL_PATH		"platform/i86pc/ucode"
552449e17fSsherrym #define	UCODE_INSTALL_COMMON_PATH	".f"
562449e17fSsherrym 
572449e17fSsherrym /*
582449e17fSsherrym  * ioctl numbers
592449e17fSsherrym  */
602449e17fSsherrym #define	UCODE_IOC		(('u'<<24)|('c'<<16)|('o'<<8))
612449e17fSsherrym 
622449e17fSsherrym #define	UCODE_GET_VERSION	(UCODE_IOC|0)
632449e17fSsherrym #define	UCODE_UPDATE		(UCODE_IOC|1)
642449e17fSsherrym 
652449e17fSsherrym struct ucode_get_rev_struct {
662449e17fSsherrym 	uint32_t *ugv_rev;		/* microcode revision array */
672449e17fSsherrym 	int ugv_size;			/* size of the array */
682449e17fSsherrym 	ucode_errno_t ugv_errno;	/* EUC error code */
692449e17fSsherrym };
702449e17fSsherrym 
712449e17fSsherrym struct ucode_write_struct {
722449e17fSsherrym 	uint32_t uw_size;	/* size of the uw_code buffer */
732449e17fSsherrym 	uint8_t *uw_ucode;	/* pointer to the undigested microcode */
742449e17fSsherrym 	ucode_errno_t uw_errno;	/* EUC error code */
752449e17fSsherrym };
762449e17fSsherrym 
772449e17fSsherrym #if defined(_SYSCALL32_IMPL)
782449e17fSsherrym 
792449e17fSsherrym #include <sys/types32.h>
802449e17fSsherrym 
812449e17fSsherrym struct ucode_get_rev_struct32 {
822449e17fSsherrym 	caddr32_t ugv_rev;		/* microcode revision array */
832449e17fSsherrym 	int ugv_size;			/* size of the array */
842449e17fSsherrym 	ucode_errno_t ugv_errno;	/* EUC error code */
852449e17fSsherrym };
862449e17fSsherrym 
872449e17fSsherrym struct ucode_write_struct32 {
882449e17fSsherrym 	uint32_t uw_size;	/* size of the uw_code buffer */
892449e17fSsherrym 	caddr32_t uw_ucode;	/* pointer to the undigested microcode */
902449e17fSsherrym 	ucode_errno_t uw_errno;	/* EUC error code */
912449e17fSsherrym };
922449e17fSsherrym 
932449e17fSsherrym #endif	/* _SYSCALL32_IMPL */
942449e17fSsherrym 
952449e17fSsherrym /*
96*adc586deSMark Johnson  * AMD Microcode file information
972449e17fSsherrym  */
98*adc586deSMark Johnson typedef struct ucode_header_amd {
99*adc586deSMark Johnson 	uint32_t uh_date;
100*adc586deSMark Johnson 	uint32_t uh_patch_id;
101*adc586deSMark Johnson 	uint32_t uh_internal; /* patch data id & length, init flag */
102*adc586deSMark Johnson 	uint32_t uh_cksum;
103*adc586deSMark Johnson 	uint32_t uh_nb_id;
104*adc586deSMark Johnson 	uint32_t uh_sb_id;
105*adc586deSMark Johnson 	uint16_t uh_cpu_rev;
106*adc586deSMark Johnson 	uint8_t  uh_nb_rev;
107*adc586deSMark Johnson 	uint8_t  uh_sb_rev;
108*adc586deSMark Johnson 	uint32_t uh_bios_rev;
109*adc586deSMark Johnson 	uint32_t uh_match[8];
110*adc586deSMark Johnson } ucode_header_amd_t;
111*adc586deSMark Johnson 
112*adc586deSMark Johnson typedef struct ucode_file_amd {
113*adc586deSMark Johnson 	ucode_header_amd_t uf_header;
114*adc586deSMark Johnson 	uint8_t uf_data[896];
115*adc586deSMark Johnson 	uint8_t uf_resv[896];
116*adc586deSMark Johnson 	uint8_t uf_code_present;
117*adc586deSMark Johnson 	uint8_t uf_code[191];
118*adc586deSMark Johnson } ucode_file_amd_t;
119*adc586deSMark Johnson 
120*adc586deSMark Johnson typedef struct ucode_eqtbl_amd {
121*adc586deSMark Johnson 	uint32_t ue_inst_cpu;
122*adc586deSMark Johnson 	uint32_t ue_fixed_mask;
123*adc586deSMark Johnson 	uint32_t ue_fixed_comp;
124*adc586deSMark Johnson 	uint32_t ue_equiv_cpu;
125*adc586deSMark Johnson } ucode_eqtbl_amd_t;
126*adc586deSMark Johnson 
127*adc586deSMark Johnson /*
128*adc586deSMark Johnson  * Intel Microcode file information
129*adc586deSMark Johnson  */
130*adc586deSMark Johnson typedef struct ucode_header_intel {
1312449e17fSsherrym 	uint32_t	uh_header_ver;
1322449e17fSsherrym 	uint32_t	uh_rev;
1332449e17fSsherrym 	uint32_t	uh_date;
1342449e17fSsherrym 	uint32_t	uh_signature;
1352449e17fSsherrym 	uint32_t	uh_checksum;
1362449e17fSsherrym 	uint32_t	uh_loader_ver;
1372449e17fSsherrym 	uint32_t	uh_proc_flags;
1382449e17fSsherrym 	uint32_t	uh_body_size;
1392449e17fSsherrym 	uint32_t	uh_total_size;
1402449e17fSsherrym 	uint32_t	uh_reserved[3];
141*adc586deSMark Johnson } ucode_header_intel_t;
1422449e17fSsherrym 
143*adc586deSMark Johnson typedef struct ucode_ext_sig_intel {
1442449e17fSsherrym 	uint32_t	ues_signature;
1452449e17fSsherrym 	uint32_t	ues_proc_flags;
1462449e17fSsherrym 	uint32_t	ues_checksum;
147*adc586deSMark Johnson } ucode_ext_sig_intel_t;
1482449e17fSsherrym 
149*adc586deSMark Johnson typedef struct ucode_ext_table_intel {
1502449e17fSsherrym 	uint32_t	uet_count;
1512449e17fSsherrym 	uint32_t	uet_checksum;
1522449e17fSsherrym 	uint32_t	uet_reserved[3];
153*adc586deSMark Johnson 	ucode_ext_sig_intel_t uet_ext_sig[1];
154*adc586deSMark Johnson } ucode_ext_table_intel_t;
1552449e17fSsherrym 
156*adc586deSMark Johnson typedef struct ucode_file_intel {
157*adc586deSMark Johnson 	ucode_header_intel_t	*uf_header;
1582449e17fSsherrym 	uint8_t			*uf_body;
159*adc586deSMark Johnson 	ucode_ext_table_intel_t	*uf_ext_table;
160*adc586deSMark Johnson } ucode_file_intel_t;
161*adc586deSMark Johnson 
162*adc586deSMark Johnson /*
163*adc586deSMark Johnson  * common container
164*adc586deSMark Johnson  */
165*adc586deSMark Johnson typedef union ucode_file {
166*adc586deSMark Johnson 	ucode_file_amd_t *amd;
167*adc586deSMark Johnson 	ucode_file_intel_t intel;
1682449e17fSsherrym } ucode_file_t;
1692449e17fSsherrym 
1702449e17fSsherrym 
1712449e17fSsherrym #define	UCODE_SHORT_NAME_LEN	12	/* "32-bit-sig"-"8-bit-platid"\0 */
1722449e17fSsherrym /*
1732449e17fSsherrym  * Length of UCODE_INSTALL_COMMON_PATH/short-name
1742449e17fSsherrym  *	strlen(UCODE_INSTALL_COMMON_PATH) + 1 + UCODE_SHORT_NAME_LEN
1752449e17fSsherrym  * Use sizeof which will give us the additional byte for the '/' in between
1762449e17fSsherrym  * the common path and the file name.
1772449e17fSsherrym  */
1782449e17fSsherrym #define	UCODE_COMMON_NAME_LEN	\
1792449e17fSsherrym 	(sizeof (UCODE_INSTALL_COMMON_PATH) + (UCODE_SHORT_NAME_LEN))
1802449e17fSsherrym #define	UCODE_MAX_PATH_LEN	(PATH_MAX - UCODE_COMMON_NAME_LEN)
1812449e17fSsherrym 
1822449e17fSsherrym 
183*adc586deSMark Johnson #define	UCODE_HEADER_SIZE_INTEL		(sizeof (struct ucode_header_intel))
184*adc586deSMark Johnson #define	UCODE_EXT_TABLE_SIZE_INTEL	(20)	/* 20-bytes */
185*adc586deSMark Johnson #define	UCODE_EXT_SIG_SIZE_INTEL	(sizeof (struct ucode_ext_sig_intel))
1862449e17fSsherrym 
1872449e17fSsherrym #define	UCODE_KB(a)	((a) << 10)	/* KB */
1882449e17fSsherrym #define	UCODE_MB(a)	((a) << 20)	/* MB */
1892449e17fSsherrym #define	UCODE_DEFAULT_TOTAL_SIZE	UCODE_KB(2)
190*adc586deSMark Johnson #define	UCODE_DEFAULT_BODY_SIZE		(UCODE_KB(2) - UCODE_HEADER_SIZE_INTEL)
1912449e17fSsherrym 
1922449e17fSsherrym /*
1932449e17fSsherrym  * For a single microcode file, the minimum size is 1K, maximum size is 16K.
1942449e17fSsherrym  * Such limitations, while somewhat artificial, are not only to provide better
1952449e17fSsherrym  * sanity checks, but also avoid wasting precious memory at startup time as the
1962449e17fSsherrym  * microcode buffer for the first processor has to be statically allocated.
1972449e17fSsherrym  *
1982449e17fSsherrym  * For the concatenation of all the microcode binary files, the maximum size
1992449e17fSsherrym  * is 16M.
2002449e17fSsherrym  */
2012449e17fSsherrym #define	UCODE_MIN_SIZE			UCODE_KB(1)
2022449e17fSsherrym #define	UCODE_MAX_SIZE			UCODE_KB(16)
2032449e17fSsherrym #define	UCODE_MAX_COMBINED_SIZE		UCODE_MB(16)
2042449e17fSsherrym 
2052449e17fSsherrym #define	UCODE_SIZE_CONVERT(size, default_size) \
2062449e17fSsherrym 	((size) == 0 ? (default_size) : (size))
2072449e17fSsherrym 
208*adc586deSMark Johnson #define	UCODE_BODY_SIZE_INTEL(size) \
2092449e17fSsherrym 	UCODE_SIZE_CONVERT((size), UCODE_DEFAULT_BODY_SIZE)
2102449e17fSsherrym 
211*adc586deSMark Johnson #define	UCODE_TOTAL_SIZE_INTEL(size)			\
2122449e17fSsherrym 	UCODE_SIZE_CONVERT((size), UCODE_DEFAULT_TOTAL_SIZE)
2132449e17fSsherrym 
214*adc586deSMark Johnson #define	UCODE_MATCH_INTEL(sig1, sig2, pf1, pf2) \
2152449e17fSsherrym 	(((sig1) == (sig2)) && \
2162449e17fSsherrym 	(((pf1) & (pf2)) || (((pf1) == 0) && ((pf2) == 0))))
2172449e17fSsherrym 
218*adc586deSMark Johnson extern ucode_errno_t ucode_header_validate_intel(ucode_header_intel_t *);
219*adc586deSMark Johnson extern uint32_t ucode_checksum_intel(uint32_t, uint32_t, uint8_t *);
220*adc586deSMark Johnson 
221*adc586deSMark Johnson extern ucode_errno_t ucode_validate_amd(uint8_t *, int);
222*adc586deSMark Johnson extern ucode_errno_t ucode_validate_intel(uint8_t *, int);
223*adc586deSMark Johnson 
224*adc586deSMark Johnson #ifdef _KERNEL
2252449e17fSsherrym extern ucode_errno_t ucode_get_rev(uint32_t *);
2262449e17fSsherrym extern ucode_errno_t ucode_update(uint8_t *, int);
2272449e17fSsherrym 
228*adc586deSMark Johnson /*
229*adc586deSMark Johnson  * Microcode specific information per core
230*adc586deSMark Johnson  */
231*adc586deSMark Johnson typedef struct cpu_ucode_info {
232*adc586deSMark Johnson 	uint32_t	cui_platid;	/* platform id */
233*adc586deSMark Johnson 	uint32_t	cui_rev;	/* microcode revision */
234*adc586deSMark Johnson } cpu_ucode_info_t;
235*adc586deSMark Johnson 
236*adc586deSMark Johnson /*
237*adc586deSMark Johnson  * Data structure used for xcall
238*adc586deSMark Johnson  */
239*adc586deSMark Johnson typedef struct ucode_update {
240*adc586deSMark Johnson 	uint32_t		sig;	/* signature */
241*adc586deSMark Johnson 	cpu_ucode_info_t	info;	/* ucode info */
242*adc586deSMark Johnson 	uint32_t		expected_rev;
243*adc586deSMark Johnson 	uint32_t		new_rev;
244*adc586deSMark Johnson 	uint8_t			*ucodep; /* pointer to ucode */
245*adc586deSMark Johnson 	uint32_t		usize;
246*adc586deSMark Johnson } ucode_update_t;
247*adc586deSMark Johnson 
248*adc586deSMark Johnson /*
249*adc586deSMark Johnson  * Microcode kernel operations
250*adc586deSMark Johnson  */
251*adc586deSMark Johnson struct ucode_ops {
252*adc586deSMark Johnson 	uint32_t	write_msr;
253*adc586deSMark Johnson 	int		(*capable)(cpu_t *);
254*adc586deSMark Johnson 	void		(*file_reset)(ucode_file_t *, processorid_t);
255*adc586deSMark Johnson 	void		(*read_rev)(cpu_ucode_info_t *);
256*adc586deSMark Johnson 	uint32_t	(*load)(ucode_file_t *, cpu_ucode_info_t *, cpu_t *);
257*adc586deSMark Johnson 	ucode_errno_t	(*validate)(uint8_t *, int);
258*adc586deSMark Johnson 	ucode_errno_t	(*extract)(ucode_update_t *, uint8_t *, int);
259*adc586deSMark Johnson 	ucode_errno_t	(*locate)(cpu_t *, cpu_ucode_info_t *, ucode_file_t *);
260*adc586deSMark Johnson };
261*adc586deSMark Johnson #else
262*adc586deSMark Johnson 
2632449e17fSsherrym #define	UCODE_MAX_VENDORS_NAME_LEN		20
2642449e17fSsherrym 
2652449e17fSsherrym #define	UCODE_VENDORS				\
2662449e17fSsherrym static struct {					\
2672449e17fSsherrym 	char *filestr;				\
268*adc586deSMark Johnson 	char *extstr;				\
2692449e17fSsherrym 	char *vendorstr;			\
2702449e17fSsherrym 	int  supported;				\
2712449e17fSsherrym } ucode_vendors[] = {				\
272*adc586deSMark Johnson 	{ "intel", "txt", "GenuineIntel", 1 },	\
273*adc586deSMark Johnson 	{ "amd", "bin", "AuthenticAMD", 1 },	\
274*adc586deSMark Johnson 	{ NULL, NULL, NULL, 0 }			\
2752449e17fSsherrym }
2762449e17fSsherrym 
277*adc586deSMark Johnson /*
278*adc586deSMark Johnson  * Microcode user operations
279*adc586deSMark Johnson  */
280*adc586deSMark Johnson struct ucode_ops {
281*adc586deSMark Johnson 	int		(*convert)(const char *, uint8_t *, size_t);
282*adc586deSMark Johnson 	ucode_errno_t	(*gen_files)(uint8_t *, int, char *);
283*adc586deSMark Johnson 	ucode_errno_t	(*validate)(uint8_t *, int);
284*adc586deSMark Johnson };
285*adc586deSMark Johnson #endif
286*adc586deSMark Johnson 
287*adc586deSMark Johnson extern const struct ucode_ops *ucode;
288*adc586deSMark Johnson 
2892449e17fSsherrym #ifdef __cplusplus
2902449e17fSsherrym }
2912449e17fSsherrym #endif
2922449e17fSsherrym 
2932449e17fSsherrym #endif	/* _SYS_UCODE_H */
294