Module Name:    src
Committed By:   christos
Date:           Sat Mar 17 15:56:32 UTC 2018

Modified Files:
        src/sys/arch/x86/include: cpu_ucode.h
        src/sys/arch/x86/x86: cpu_ucode.c cpu_ucode_amd.c cpu_ucode_intel.c

Log Message:
tuck in all the compat microcode code in one place.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/include/cpu_ucode.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/cpu_ucode.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x86/x86/cpu_ucode_amd.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/x86/x86/cpu_ucode_intel.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/include/cpu_ucode.h
diff -u src/sys/arch/x86/include/cpu_ucode.h:1.3 src/sys/arch/x86/include/cpu_ucode.h:1.4
--- src/sys/arch/x86/include/cpu_ucode.h:1.3	Wed Oct 17 16:19:55 2012
+++ src/sys/arch/x86/include/cpu_ucode.h	Sat Mar 17 11:56:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode.h,v 1.3 2012/10/17 20:19:55 drochner Exp $ */
+/* $NetBSD: cpu_ucode.h,v 1.4 2018/03/17 15:56:32 christos Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -47,14 +47,11 @@ struct cpu_ucode_version_intel1 {
 #include <sys/cpuio.h>
 #include <dev/firmload.h>
 
-int cpu_ucode_amd_get_version(struct cpu_ucode_version *);
-#ifdef COMPAT_60
-int compat6_cpu_ucode_amd_get_version(struct compat6_cpu_ucode *);
-#endif
+int cpu_ucode_amd_get_version(struct cpu_ucode_version *, void *, size_t);
 int cpu_ucode_amd_firmware_open(firmware_handle_t *, const char *);
 int cpu_ucode_amd_apply(struct cpu_ucode_softc *, int);
 
-int cpu_ucode_intel_get_version(struct cpu_ucode_version *);
+int cpu_ucode_intel_get_version(struct cpu_ucode_version *, void *, size_t);
 int cpu_ucode_intel_firmware_open(firmware_handle_t *, const char *);
 int cpu_ucode_intel_apply(struct cpu_ucode_softc *, int);
 #endif /* _KERNEL */

Index: src/sys/arch/x86/x86/cpu_ucode.c
diff -u src/sys/arch/x86/x86/cpu_ucode.c:1.5 src/sys/arch/x86/x86/cpu_ucode.c:1.6
--- src/sys/arch/x86/x86/cpu_ucode.c:1.5	Wed Jan  7 02:05:48 2015
+++ src/sys/arch/x86/x86/cpu_ucode.c	Sat Mar 17 11:56:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode.c,v 1.5 2015/01/07 07:05:48 ozaki-r Exp $ */
+/* $NetBSD: cpu_ucode.c,v 1.6 2018/03/17 15:56:32 christos Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.5 2015/01/07 07:05:48 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.6 2018/03/17 15:56:32 christos Exp $");
 
 #include "opt_cpu_ucode.h"
 #include "opt_compat_netbsd.h"
@@ -50,34 +50,30 @@ static struct cpu_ucode_softc ucode_soft
 int
 cpu_ucode_get_version(struct cpu_ucode_version *data)
 {
+	union {
+		struct cpu_ucode_version_amd a;
+		struct cpu_ucode_version_intel1 i;
+	} v;
+	size_t l;
+	int error;
+
+	if (!data->data)
+		return 0;
 
 	switch (cpu_vendor) {
 	case CPUVENDOR_AMD:
-		return cpu_ucode_amd_get_version(data);
+		error = cpu_ucode_amd_get_version(data, &v, l = sizeof(v.a));
 	case CPUVENDOR_INTEL:
-		return cpu_ucode_intel_get_version(data);
+		error = cpu_ucode_intel_get_version(data, &v, l = sizeof(v.i));
 	default:
 		return EOPNOTSUPP;
 	}
 
-	return 0;
-}
-
-#ifdef COMPAT_60
-int
-compat6_cpu_ucode_get_version(struct compat6_cpu_ucode *data)
-{
-
-	switch (cpu_vendor) {
-	case CPUVENDOR_AMD:
-		return compat6_cpu_ucode_amd_get_version(data);
-	default:
-		return EOPNOTSUPP;
-	}
+	if (error)
+		return error;
 
-	return 0;
+	return copyout(&v, data->data, l);
 }
-#endif /* COMPAT60 */
 
 int
 cpu_ucode_md_open(firmware_handle_t *fwh, int loader_version, const char *fwname)
@@ -124,6 +120,21 @@ cpu_ucode_apply(const struct cpu_ucode *
 
 #ifdef COMPAT_60
 int
+compat6_cpu_ucode_get_version(struct compat6_cpu_ucode *data)
+{
+	struct cpu_ucode_version ndata;
+
+	switch (cpu_vendor) {
+	case CPUVENDOR_AMD:
+		ndata.loader_version = CPU_UCODE_LOADER_AMD;
+		return cpu_ucode_amd_get_version(&ndata, &data->version,
+		    sizeof(data->version));
+	default:
+		return EOPNOTSUPP;
+	}
+}
+
+int
 compat6_cpu_ucode_apply(const struct compat6_cpu_ucode *data)
 {
 	struct cpu_ucode_softc *sc = &ucode_softc;

Index: src/sys/arch/x86/x86/cpu_ucode_amd.c
diff -u src/sys/arch/x86/x86/cpu_ucode_amd.c:1.7 src/sys/arch/x86/x86/cpu_ucode_amd.c:1.8
--- src/sys/arch/x86/x86/cpu_ucode_amd.c:1.7	Fri Nov 15 03:47:55 2013
+++ src/sys/arch/x86/x86/cpu_ucode_amd.c	Sat Mar 17 11:56:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_amd.c,v 1.7 2013/11/15 08:47:55 msaitoh Exp $ */
+/* $NetBSD: cpu_ucode_amd.c,v 1.8 2018/03/17 15:56:32 christos Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,11 +29,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_amd.c,v 1.7 2013/11/15 08:47:55 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_amd.c,v 1.8 2018/03/17 15:56:32 christos Exp $");
 
 #include "opt_xen.h"
 #include "opt_cpu_ucode.h"
-#include "opt_compat_netbsd.h"
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -101,33 +100,21 @@ amd_cpufamily(void)
 }
 
 int
-cpu_ucode_amd_get_version(struct cpu_ucode_version *ucode)
+cpu_ucode_amd_get_version(struct cpu_ucode_version *ucode, void *ptr,
+    size_t len)
 {
-	struct cpu_ucode_version_amd data;
+	struct cpu_ucode_version_amd *data = ptr;
 
-	if (ucode->loader_version != CPU_UCODE_LOADER_AMD || amd_cpufamily() < 0x10)
+	if (ucode->loader_version != CPU_UCODE_LOADER_AMD
+	    || amd_cpufamily() < 0x10)
 		return EOPNOTSUPP;
-	if (!ucode->data)
-		return 0;
-
-	data.version = rdmsr(MSR_UCODE_AMD_PATCHLEVEL);
-	return copyout(&data, ucode->data, sizeof(data));
-}
 
-#ifdef COMPAT_60
-int
-compat6_cpu_ucode_amd_get_version(struct compat6_cpu_ucode *ucode)
-{
-	uint64_t uclevel;
-
-	if (amd_cpufamily() < 0x10)
-		return EOPNOTSUPP;
+	if (len < sizeof(*data))
+		return ENOSPC;
 
-	uclevel = rdmsr(MSR_UCODE_AMD_PATCHLEVEL);
-	ucode->version = uclevel;
+	data->version = rdmsr(MSR_UCODE_AMD_PATCHLEVEL);
 	return 0;
 }
-#endif /* COMPAT60 */
 
 int
 cpu_ucode_amd_firmware_open(firmware_handle_t *fwh, const char *fwname)

Index: src/sys/arch/x86/x86/cpu_ucode_intel.c
diff -u src/sys/arch/x86/x86/cpu_ucode_intel.c:1.12 src/sys/arch/x86/x86/cpu_ucode_intel.c:1.13
--- src/sys/arch/x86/x86/cpu_ucode_intel.c:1.12	Wed May 31 22:45:08 2017
+++ src/sys/arch/x86/x86/cpu_ucode_intel.c	Sat Mar 17 11:56:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_intel.c,v 1.12 2017/06/01 02:45:08 chs Exp $ */
+/* $NetBSD: cpu_ucode_intel.c,v 1.13 2018/03/17 15:56:32 christos Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,11 +29,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.12 2017/06/01 02:45:08 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.13 2018/03/17 15:56:32 christos Exp $");
 
 #include "opt_xen.h"
 #include "opt_cpu_ucode.h"
-#include "opt_compat_netbsd.h"
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -65,20 +64,21 @@ intel_getcurrentucode(uint32_t *ucodever
 }
 
 int
-cpu_ucode_intel_get_version(struct cpu_ucode_version *ucode)
+cpu_ucode_intel_get_version(struct cpu_ucode_version *ucode,
+    void *ptr, size_t len)
 {
 	struct cpu_info *ci = curcpu();
-	struct cpu_ucode_version_intel1 data;
+	struct cpu_ucode_version_intel1 *data = ptr;
 
 	if (ucode->loader_version != CPU_UCODE_LOADER_INTEL1 ||
 	    CPUID_TO_FAMILY(ci->ci_signature) < 6)
 		return EOPNOTSUPP;
-	if (!ucode->data)
-		return 0;
 
-	intel_getcurrentucode(&data.ucodeversion, &data.platformid);
+	if (len < sizeof(*data))
+		return ENOSPC;
 
-	return copyout(&data, ucode->data, sizeof(data));
+	intel_getcurrentucode(&data->ucodeversion, &data->platformid);
+	return 0;
 }
 
 int

Reply via email to