xref: /freebsd/sys/x86/include/ucode.h (revision 34467bd762a77345915d07f4f0630c3fe0b53a23)
197edfc1bSMark Johnston /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
397edfc1bSMark Johnston  *
497edfc1bSMark Johnston  * Copyright (c) 2018 The FreeBSD Foundation
597edfc1bSMark Johnston  *
697edfc1bSMark Johnston  * This software was developed by Mark Johnston under sponsorship from
797edfc1bSMark Johnston  * the FreeBSD Foundation.
897edfc1bSMark Johnston  *
997edfc1bSMark Johnston  * Redistribution and use in source and binary forms, with or without
1097edfc1bSMark Johnston  * modification, are permitted provided that the following conditions
1197edfc1bSMark Johnston  * are met:
1297edfc1bSMark Johnston  * 1. Redistributions of source code must retain the above copyright
1397edfc1bSMark Johnston  *    notice, this list of conditions and the following disclaimer.
1497edfc1bSMark Johnston  * 2. Redistributions in binary form must reproduce the above copyright
1597edfc1bSMark Johnston  *    notice, this list of conditions and the following disclaimer in the
1697edfc1bSMark Johnston  *    documentation and/or other materials provided with the distribution.
1797edfc1bSMark Johnston  *
1897edfc1bSMark Johnston  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1997edfc1bSMark Johnston  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2097edfc1bSMark Johnston  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2197edfc1bSMark Johnston  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2297edfc1bSMark Johnston  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2397edfc1bSMark Johnston  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2497edfc1bSMark Johnston  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2597edfc1bSMark Johnston  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2697edfc1bSMark Johnston  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2797edfc1bSMark Johnston  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2897edfc1bSMark Johnston  * SUCH DAMAGE.
2997edfc1bSMark Johnston  */
3097edfc1bSMark Johnston 
3197edfc1bSMark Johnston #ifndef _MACHINE_UCODE_H_
3297edfc1bSMark Johnston #define	_MACHINE_UCODE_H_
3397edfc1bSMark Johnston 
34*34467bd7SChuck Silvers #ifdef _KERNEL
35*34467bd7SChuck Silvers #include <sys/types.h>
36*34467bd7SChuck Silvers #else
37*34467bd7SChuck Silvers #include <stdbool.h>
38*34467bd7SChuck Silvers #endif
39*34467bd7SChuck Silvers 
4097edfc1bSMark Johnston struct ucode_intel_header {
4197edfc1bSMark Johnston 	uint32_t	header_version;
4297edfc1bSMark Johnston 	int32_t		update_revision;
4397edfc1bSMark Johnston 	uint32_t	dat;
4497edfc1bSMark Johnston 	uint32_t	processor_signature;
4597edfc1bSMark Johnston 	uint32_t	checksum;
4697edfc1bSMark Johnston 	uint32_t	loader_revision;
4797edfc1bSMark Johnston 	uint32_t	processor_flags;
4897edfc1bSMark Johnston #define	UCODE_INTEL_DEFAULT_DATA_SIZE		2000
4997edfc1bSMark Johnston 	uint32_t	data_size;
5097edfc1bSMark Johnston 	uint32_t	total_size;
5197edfc1bSMark Johnston 	uint32_t	reserved[3];
5297edfc1bSMark Johnston };
5397edfc1bSMark Johnston 
5497edfc1bSMark Johnston struct ucode_intel_extsig_table {
5597edfc1bSMark Johnston 	uint32_t	signature_count;
5697edfc1bSMark Johnston 	uint32_t	signature_table_checksum;
5797edfc1bSMark Johnston 	uint32_t	reserved[3];
5897edfc1bSMark Johnston 	struct ucode_intel_extsig {
5997edfc1bSMark Johnston 		uint32_t	processor_signature;
6097edfc1bSMark Johnston 		uint32_t	processor_flags;
6197edfc1bSMark Johnston 		uint32_t	checksum;
6297edfc1bSMark Johnston 	} entries[0];
6397edfc1bSMark Johnston };
6497edfc1bSMark Johnston 
65*34467bd7SChuck Silvers const void *ucode_amd_find(const char *path, uint32_t signature,
66*34467bd7SChuck Silvers 	    uint32_t revision, const uint8_t *fw_data, size_t fw_size,
67*34467bd7SChuck Silvers 	    size_t *selected_sizep);
68fd24a63aSChuck Silvers int	ucode_intel_load(const void *data, bool unsafe,
69d5089b3aSMark Johnston 	    uint64_t *nrevp, uint64_t *orevp);
70*34467bd7SChuck Silvers int	ucode_amd_load(const void *data, bool unsafe,
71*34467bd7SChuck Silvers 	    uint64_t *nrevp, uint64_t *orevp);
7297edfc1bSMark Johnston size_t	ucode_load_bsp(uintptr_t free);
7397edfc1bSMark Johnston void	ucode_load_ap(int cpu);
7497edfc1bSMark Johnston void	ucode_reload(void);
7597edfc1bSMark Johnston void *	ucode_update(void *data);
7697edfc1bSMark Johnston 
7797edfc1bSMark Johnston #endif /* _MACHINE_UCODE_H_ */
78