Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86 tuck in all the compat microcode code in one pl...



details:   https://anonhg.NetBSD.org/src/rev/fa42db8f4405
branches:  trunk
changeset: 321474:fa42db8f4405
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Mar 17 15:56:32 2018 +0000

description:
tuck in all the compat microcode code in one place.

diffstat:

 sys/arch/x86/include/cpu_ucode.h   |   9 ++----
 sys/arch/x86/x86/cpu_ucode.c       |  51 +++++++++++++++++++++++--------------
 sys/arch/x86/x86/cpu_ucode_amd.c   |  35 ++++++++-----------------
 sys/arch/x86/x86/cpu_ucode_intel.c |  18 ++++++------
 4 files changed, 54 insertions(+), 59 deletions(-)

diffs (230 lines):

diff -r 3410111569e4 -r fa42db8f4405 sys/arch/x86/include/cpu_ucode.h
--- a/sys/arch/x86/include/cpu_ucode.h  Sat Mar 17 13:14:27 2018 +0000
+++ b/sys/arch/x86/include/cpu_ucode.h  Sat Mar 17 15:56:32 2018 +0000
@@ -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 @@
 #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 */
diff -r 3410111569e4 -r fa42db8f4405 sys/arch/x86/x86/cpu_ucode.c
--- a/sys/arch/x86/x86/cpu_ucode.c      Sat Mar 17 13:14:27 2018 +0000
+++ b/sys/arch/x86/x86/cpu_ucode.c      Sat Mar 17 15:56:32 2018 +0000
@@ -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 @@
 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)
-{
+       if (error)
+               return error;
 
-       switch (cpu_vendor) {
-       case CPUVENDOR_AMD:
-               return compat6_cpu_ucode_amd_get_version(data);
-       default:
-               return EOPNOTSUPP;
-       }
-
-       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 @@
 
 #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;
diff -r 3410111569e4 -r fa42db8f4405 sys/arch/x86/x86/cpu_ucode_amd.c
--- a/sys/arch/x86/x86/cpu_ucode_amd.c  Sat Mar 17 13:14:27 2018 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_amd.c  Sat Mar 17 15:56:32 2018 +0000
@@ -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 @@
 }
 
 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;
-
-       if (ucode->loader_version != CPU_UCODE_LOADER_AMD || amd_cpufamily() < 0x10)
-               return EOPNOTSUPP;
-       if (!ucode->data)
-               return 0;
+       struct cpu_ucode_version_amd *data = ptr;
 
-       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)
+       if (ucode->loader_version != CPU_UCODE_LOADER_AMD
+           || amd_cpufamily() < 0x10)
                return EOPNOTSUPP;
 
-       uclevel = rdmsr(MSR_UCODE_AMD_PATCHLEVEL);
-       ucode->version = uclevel;
+       if (len < sizeof(*data))
+               return ENOSPC;
+
+       data->version = rdmsr(MSR_UCODE_AMD_PATCHLEVEL);
        return 0;
 }
-#endif /* COMPAT60 */
 
 int
 cpu_ucode_amd_firmware_open(firmware_handle_t *fwh, const char *fwname)
diff -r 3410111569e4 -r fa42db8f4405 sys/arch/x86/x86/cpu_ucode_intel.c
--- a/sys/arch/x86/x86/cpu_ucode_intel.c        Sat Mar 17 13:14:27 2018 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_intel.c        Sat Mar 17 15:56:32 2018 +0000
@@ -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 @@
 }
 
 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



Home | Main Index | Thread Index | Old Index