xref: /netbsd-src/sys/arch/x86/include/cpu_ucode.h (revision fabddac10bbf2f20b7e9eb43f74295293c740912)
1*fabddac1Smsaitoh /* $NetBSD: cpu_ucode.h,v 1.5 2022/09/15 14:34:22 msaitoh Exp $ */
2a3f6c067Scegger /*
3a3f6c067Scegger  * Copyright (c) 2012 The NetBSD Foundation, Inc.
4a3f6c067Scegger  * All rights reserved.
5a3f6c067Scegger  *
6a3f6c067Scegger  * This code is derived from software contributed to The NetBSD Foundation
7a3f6c067Scegger  * by Christoph Egger.
8a3f6c067Scegger  *
9a3f6c067Scegger  * Redistribution and use in source and binary forms, with or without
10a3f6c067Scegger  * modification, are permitted provided that the following conditions
11a3f6c067Scegger  * are met:
12a3f6c067Scegger  * 1. Redistributions of source code must retain the above copyright
13a3f6c067Scegger  *    notice, this list of conditions and the following disclaimer.
14a3f6c067Scegger  * 2. Redistributions in binary form must reproduce the above copyright
15a3f6c067Scegger  *    notice, this list of conditions and the following disclaimer in the
16a3f6c067Scegger  *    documentation and/or other materials provided with the distribution.
17a3f6c067Scegger  *
18a3f6c067Scegger  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19a3f6c067Scegger  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20a3f6c067Scegger  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21a3f6c067Scegger  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22a3f6c067Scegger  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23a3f6c067Scegger  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24a3f6c067Scegger  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25a3f6c067Scegger  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26a3f6c067Scegger  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27a3f6c067Scegger  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28a3f6c067Scegger  * POSSIBILITY OF SUCH DAMAGE.
29a3f6c067Scegger  */
30a3f6c067Scegger 
31a3f6c067Scegger #ifndef _X86_CPU_UCODE_H_
32a3f6c067Scegger #define _X86_CPU_UCODE_H_
33a3f6c067Scegger 
34312c3390Sdrochner #define CPU_UCODE_LOADER_AMD 0
35312c3390Sdrochner struct cpu_ucode_version_amd {
36312c3390Sdrochner 	uint64_t version;
37312c3390Sdrochner };
38312c3390Sdrochner 
39312c3390Sdrochner #define CPU_UCODE_LOADER_INTEL1 1
40312c3390Sdrochner struct cpu_ucode_version_intel1 {
41312c3390Sdrochner 	uint32_t ucodeversion;
42312c3390Sdrochner 	int platformid;
43312c3390Sdrochner };
44312c3390Sdrochner 
45312c3390Sdrochner #ifdef _KERNEL
46a3f6c067Scegger #include <sys/cpu.h>
47a3f6c067Scegger #include <sys/cpuio.h>
48a3f6c067Scegger #include <dev/firmload.h>
49a3f6c067Scegger 
5069841942Schristos int cpu_ucode_amd_get_version(struct cpu_ucode_version *, void *, size_t);
51a3f6c067Scegger int cpu_ucode_amd_firmware_open(firmware_handle_t *, const char *);
52312c3390Sdrochner int cpu_ucode_amd_apply(struct cpu_ucode_softc *, int);
53312c3390Sdrochner 
5469841942Schristos int cpu_ucode_intel_get_version(struct cpu_ucode_version *, void *, size_t);
55312c3390Sdrochner int cpu_ucode_intel_firmware_open(firmware_handle_t *, const char *);
56312c3390Sdrochner int cpu_ucode_intel_apply(struct cpu_ucode_softc *, int);
57312c3390Sdrochner #endif /* _KERNEL */
58312c3390Sdrochner 
59312c3390Sdrochner struct intel1_ucode_header {
60312c3390Sdrochner 	uint32_t	uh_header_ver;
61312c3390Sdrochner 	uint32_t	uh_rev;
62312c3390Sdrochner 	uint32_t	uh_date;
63312c3390Sdrochner 	uint32_t	uh_signature;
64312c3390Sdrochner 	uint32_t	uh_checksum;
65312c3390Sdrochner 	uint32_t	uh_loader_rev;
66312c3390Sdrochner 	uint32_t	uh_proc_flags;
67312c3390Sdrochner 	uint32_t	uh_data_size;
68312c3390Sdrochner 	uint32_t	uh_total_size;
69312c3390Sdrochner 	uint32_t	uh_reserved[3];
70312c3390Sdrochner };
71312c3390Sdrochner 
72312c3390Sdrochner struct intel1_ucode_ext_table {
73312c3390Sdrochner 	uint32_t	uet_count;
74312c3390Sdrochner 	uint32_t	uet_checksum;
75312c3390Sdrochner 	uint32_t	uet_reserved[3];
76*fabddac1Smsaitoh };
77*fabddac1Smsaitoh 
78*fabddac1Smsaitoh struct intel1_ucode_proc_signature {
79*fabddac1Smsaitoh 	uint32_t	ups_signature;
80*fabddac1Smsaitoh 	uint32_t	ups_proc_flags;
81*fabddac1Smsaitoh 	uint32_t	ups_checksum;
82312c3390Sdrochner };
83a3f6c067Scegger 
84a3f6c067Scegger #endif
85