Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Support CPU microcode loading via cpuctl(8).
details: https://anonhg.NetBSD.org/src/rev/484458430c78
branches: trunk
changeset: 772708:484458430c78
user: cegger <cegger%NetBSD.org@localhost>
date: Fri Jan 13 16:05:14 2012 +0000
description:
Support CPU microcode loading via cpuctl(8).
Implemented and enabled via CPU_UCODE kernel config option
for x86 and Xen Dom0.
Tested on different AMD machines with different
CPU families.
ok wiz@ for the manpages
ok releng@
ok core@ via releng@
diffstat:
share/man/man4/options.4 | 7 +-
sys/arch/amd64/conf/GENERIC | 6 +-
sys/arch/amd64/conf/XEN3_DOM0 | 4 +-
sys/arch/i386/conf/GENERIC | 6 +-
sys/arch/i386/conf/XEN3_DOM0 | 4 +-
sys/arch/x86/conf/files.x86 | 6 +-
sys/arch/x86/include/cpu_ucode.h | 42 +++
sys/arch/x86/x86/cpu_ucode.c | 102 ++++++++
sys/arch/x86/x86/cpu_ucode_amd.c | 292 ++++++++++++++++++++++++
sys/arch/xen/conf/files.xen | 6 +-
sys/arch/xen/xen/xen_ucode.c | 101 ++++++++
sys/kern/kern_cpu.c | 71 +++++-
sys/secmodel/securelevel/secmodel_securelevel.c | 9 +-
sys/secmodel/suser/secmodel_suser.c | 5 +-
sys/sys/cpu.h | 19 +-
sys/sys/cpuio.h | 12 +-
sys/sys/kauth.h | 4 +-
usr.sbin/cpuctl/cpuctl.8 | 43 +++-
usr.sbin/cpuctl/cpuctl.c | 68 ++++-
19 files changed, 770 insertions(+), 37 deletions(-)
diffs (truncated from 1167 to 300 lines):
diff -r 2ab9f5dcdbaf -r 484458430c78 share/man/man4/options.4
--- a/share/man/man4/options.4 Fri Jan 13 13:41:25 2012 +0000
+++ b/share/man/man4/options.4 Fri Jan 13 16:05:14 2012 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: options.4,v 1.410 2012/01/09 15:16:31 drochner Exp $
+.\" $NetBSD: options.4,v 1.411 2012/01/13 16:05:16 cegger Exp $
.\"
.\" Copyright (c) 1996
.\" Perry E. Metzger. All rights reserved.
@@ -30,7 +30,7 @@
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\"
-.Dd January 9, 2012
+.Dd January 13, 2012
.Dt OPTIONS 4
.Os
.Sh NAME
@@ -1093,6 +1093,9 @@
.El
.Ss Miscellaneous Options
.Bl -ohang
+.It Cd options CPU_UCODE
+Support cpu microcode loading via
+.Xr cpuctl 8 .
.It Cd options MEMORY_DISK_DYNAMIC
This option makes the
.Xr md 4
diff -r 2ab9f5dcdbaf -r 484458430c78 sys/arch/amd64/conf/GENERIC
--- a/sys/arch/amd64/conf/GENERIC Fri Jan 13 13:41:25 2012 +0000
+++ b/sys/arch/amd64/conf/GENERIC Fri Jan 13 16:05:14 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.342 2011/12/31 00:10:06 christos Exp $
+# $NetBSD: GENERIC,v 1.343 2012/01/13 16:05:14 cegger Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.342 $"
+#ident "GENERIC-$Revision: 1.343 $"
maxusers 64 # estimated number of users
@@ -60,6 +60,8 @@
options KTRACE # system call tracing via ktrace(1)
+options CPU_UCODE # cpu ucode loading support
+
# Note: SysV IPC parameters could be changed dynamically, see sysctl(8).
options SYSVMSG # System V-like message queues
options SYSVSEM # System V-like semaphores
diff -r 2ab9f5dcdbaf -r 484458430c78 sys/arch/amd64/conf/XEN3_DOM0
--- a/sys/arch/amd64/conf/XEN3_DOM0 Fri Jan 13 13:41:25 2012 +0000
+++ b/sys/arch/amd64/conf/XEN3_DOM0 Fri Jan 13 16:05:14 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOM0,v 1.76 2011/12/18 05:49:23 dholland Exp $
+# $NetBSD: XEN3_DOM0,v 1.77 2012/01/13 16:05:14 cegger Exp $
include "arch/amd64/conf/std.xen"
@@ -35,6 +35,8 @@
options KTRACE # system call tracing via ktrace(1)
+options CPU_UCODE # cpu ucode loading support
+
options SYSVMSG # System V-like message queues
options SYSVSEM # System V-like semaphores
options SYSVSHM # System V-like memory sharing
diff -r 2ab9f5dcdbaf -r 484458430c78 sys/arch/i386/conf/GENERIC
--- a/sys/arch/i386/conf/GENERIC Fri Jan 13 13:41:25 2012 +0000
+++ b/sys/arch/i386/conf/GENERIC Fri Jan 13 16:05:14 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1061 2011/12/31 00:11:21 christos Exp $
+# $NetBSD: GENERIC,v 1.1062 2012/01/13 16:05:14 cegger Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.1061 $"
+#ident "GENERIC-$Revision: 1.1062 $"
maxusers 64 # estimated number of users
@@ -80,6 +80,8 @@
options KTRACE # system call tracing via ktrace(1)
+options CPU_UCODE # cpu ucode loading support
+
# Note: SysV IPC parameters can be changed dynamically; see sysctl(8).
options SYSVMSG # System V-like message queues
options SYSVSEM # System V-like semaphores
diff -r 2ab9f5dcdbaf -r 484458430c78 sys/arch/i386/conf/XEN3_DOM0
--- a/sys/arch/i386/conf/XEN3_DOM0 Fri Jan 13 13:41:25 2012 +0000
+++ b/sys/arch/i386/conf/XEN3_DOM0 Fri Jan 13 16:05:14 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOM0,v 1.58 2011/12/18 05:49:28 dholland Exp $
+# $NetBSD: XEN3_DOM0,v 1.59 2012/01/13 16:05:14 cegger Exp $
#
# XEN3_0: Xen 3.0 domain0 kernel
@@ -45,6 +45,8 @@
options KTRACE # system call tracing via ktrace(1)
+options CPU_UCODE # cpu ucode loading support
+
options SYSVMSG # System V-like message queues
options SYSVSEM # System V-like semaphores
#options SEMMNI=10 # number of semaphore identifiers
diff -r 2ab9f5dcdbaf -r 484458430c78 sys/arch/x86/conf/files.x86
--- a/sys/arch/x86/conf/files.x86 Fri Jan 13 13:41:25 2012 +0000
+++ b/sys/arch/x86/conf/files.x86 Fri Jan 13 16:05:14 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.x86,v 1.75 2011/10/19 05:22:25 dyoung Exp $
+# $NetBSD: files.x86,v 1.76 2012/01/13 16:05:14 cegger Exp $
# options for MP configuration through the MP spec
defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI
@@ -93,6 +93,10 @@
file arch/x86/x86/x86_userconf.c userconf
file arch/x86/x86/x86_machdep.c
+defflag CPU_UCODE
+file arch/x86/x86/cpu_ucode.c cpu_ucode needs-flag
+file arch/x86/x86/cpu_ucode_amd.c cpu_ucode needs-flag
+
define lapic
file arch/x86/x86/lapic.c lapic needs-flag
diff -r 2ab9f5dcdbaf -r 484458430c78 sys/arch/x86/include/cpu_ucode.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/include/cpu_ucode.h Fri Jan 13 16:05:14 2012 +0000
@@ -0,0 +1,42 @@
+/* $NetBSD: cpu_ucode.h,v 1.1 2012/01/13 16:05:14 cegger Exp $ */
+/*
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christoph Egger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _X86_CPU_UCODE_H_
+#define _X86_CPU_UCODE_H_
+
+#include <sys/cpu.h>
+#include <sys/cpuio.h>
+#include <dev/firmload.h>
+
+int cpu_ucode_amd_get_version(struct cpu_ucode *);
+int cpu_ucode_amd_firmware_open(firmware_handle_t *, const char *);
+int cpu_ucode_amd_apply(struct cpu_ucode_softc *);
+
+#endif
diff -r 2ab9f5dcdbaf -r 484458430c78 sys/arch/x86/x86/cpu_ucode.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/x86/cpu_ucode.c Fri Jan 13 16:05:14 2012 +0000
@@ -0,0 +1,102 @@
+/* $NetBSD: cpu_ucode.c,v 1.1 2012/01/13 16:05:15 cegger Exp $ */
+/*
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christoph Egger.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.1 2012/01/13 16:05:15 cegger Exp $");
+
+#include "opt_cpu_ucode.h"
+
+#include <sys/param.h>
+#include <sys/cpuio.h>
+#include <sys/cpu.h>
+
+#include <dev/firmload.h>
+
+#include <machine/cpuvar.h>
+#include <machine/cputypes.h>
+
+#include <x86/cpu_ucode.h>
+
+static struct cpu_ucode_softc ucode_softc;
+
+int
+cpu_ucode_get_version(void *data)
+{
+ struct cpu_ucode *ucode = data;
+
+ switch (cpu_vendor) {
+ case CPUVENDOR_AMD:
+ return cpu_ucode_amd_get_version(ucode);
+ default:
+ ucode->version = (uint64_t)-1;
+ return EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
+int
+cpu_ucode_md_open(firmware_handle_t *fwh, const char *fwname)
+{
+ switch (cpu_vendor) {
+ case CPUVENDOR_AMD:
+ return cpu_ucode_amd_firmware_open(fwh, fwname);
+ case CPUVENDOR_INTEL:
+ return EOPNOTSUPP; /* not yet supported */
+ default:
+ return EOPNOTSUPP;
+ }
+}
+
+int
+cpu_ucode_apply(void *data)
+{
+ struct cpu_ucode *ucode = data;
+ struct cpu_ucode_softc *sc = &ucode_softc;
+ int error;
+
+ error = cpu_ucode_load(sc, ucode->fwname);
+ if (error)
+ return error;
+
+ switch (cpu_vendor) {
+ case CPUVENDOR_AMD:
+ error = cpu_ucode_amd_apply(sc);
+ break;
+ default:
+ return EOPNOTSUPP;
+ }
+
+ if (sc->sc_blob != NULL)
+ firmware_free(sc->sc_blob, 0);
+ sc->sc_blob = NULL;
+ sc->sc_blobsize = 0;
+ return error;
+}
diff -r 2ab9f5dcdbaf -r 484458430c78 sys/arch/x86/x86/cpu_ucode_amd.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_amd.c Fri Jan 13 16:05:14 2012 +0000
@@ -0,0 +1,292 @@
+/* $NetBSD: cpu_ucode_amd.c,v 1.1 2012/01/13 16:05:15 cegger Exp $ */
+/*
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
Home |
Main Index |
Thread Index |
Old Index