Module Name: src
Committed By: pgoyette
Date: Sat Mar 17 21:37:53 UTC 2018
Modified Files:
src/sys/arch/x86/include [pgoyette-compat]: cpu_ucode.h
src/sys/arch/x86/x86 [pgoyette-compat]: cpu_ucode.c cpu_ucode_amd.c
cpu_ucode_intel.c
src/sys/arch/xen/conf [pgoyette-compat]: files.xen
src/sys/compat/common [pgoyette-compat]: Makefile.sysio compat_mod.c
src/sys/compat/sys [pgoyette-compat]: cpuio.h
src/sys/kern [pgoyette-compat]: kern_cpu.c
Added Files:
src/sys/compat/common [pgoyette-compat]: kern_cpu_60.c
Removed Files:
src/sys/arch/xen/xen [pgoyette-compat]: xen_ucode.c
Log Message:
Import christos's changes for the compat_60 cpu_ucode stuff
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.36.1 src/sys/arch/x86/include/cpu_ucode.h
cvs rdiff -u -r1.5.16.2 -r1.5.16.3 src/sys/arch/x86/x86/cpu_ucode.c
cvs rdiff -u -r1.7 -r1.7.28.1 src/sys/arch/x86/x86/cpu_ucode_amd.c
cvs rdiff -u -r1.12 -r1.12.8.1 src/sys/arch/x86/x86/cpu_ucode_intel.c
cvs rdiff -u -r1.165 -r1.165.2.1 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.5 -r0 src/sys/arch/xen/xen/xen_ucode.c
cvs rdiff -u -r1.7.18.3 -r1.7.18.4 src/sys/compat/common/Makefile.sysio
cvs rdiff -u -r1.24.14.13 -r1.24.14.14 src/sys/compat/common/compat_mod.c
cvs rdiff -u -r0 -r1.1.2.2 src/sys/compat/common/kern_cpu_60.c
cvs rdiff -u -r1.5 -r1.5.16.1 src/sys/compat/sys/cpuio.h
cvs rdiff -u -r1.71.16.6 -r1.71.16.7 src/sys/kern/kern_cpu.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.3.36.1
--- src/sys/arch/x86/include/cpu_ucode.h:1.3 Wed Oct 17 20:19:55 2012
+++ src/sys/arch/x86/include/cpu_ucode.h Sat Mar 17 21:37:52 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.3.36.1 2018/03/17 21:37:52 pgoyette 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.16.2 src/sys/arch/x86/x86/cpu_ucode.c:1.5.16.3
--- src/sys/arch/x86/x86/cpu_ucode.c:1.5.16.2 Sat Mar 17 06:49:56 2018
+++ src/sys/arch/x86/x86/cpu_ucode.c Sat Mar 17 21:37:52 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode.c,v 1.5.16.2 2018/03/17 06:49:56 pgoyette Exp $ */
+/* $NetBSD: cpu_ucode.c,v 1.5.16.3 2018/03/17 21:37:52 pgoyette Exp $ */
/*
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -29,9 +29,11 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.5.16.2 2018/03/17 06:49:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,v 1.5.16.3 2018/03/17 21:37:52 pgoyette Exp $");
#if defined(_KERNEL_OPT)
+#include "opt_xen.h"
+
#include "opt_cpu_ucode.h"
#include "opt_compat_netbsd.h"
#endif
@@ -47,39 +49,40 @@ __KERNEL_RCSID(0, "$NetBSD: cpu_ucode.c,
#include <x86/cpu_ucode.h>
+#ifdef XEN
+#include <xen/xen-public/xen.h>
+#include <xen/hypervisor.h>
+#endif
+
static struct cpu_ucode_softc ucode_softc;
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)
@@ -94,6 +97,7 @@ cpu_ucode_md_open(firmware_handle_t *fwh
}
}
+#ifndef XEN
int
cpu_ucode_apply(const struct cpu_ucode *data)
{
@@ -114,7 +118,7 @@ cpu_ucode_apply(const struct cpu_ucode *
error = cpu_ucode_intel_apply(sc, data->cpu_nr);
break;
default:
- return EOPNOTSUPP;
+ error = EOPNOTSUPP;
}
if (sc->sc_blob != NULL)
@@ -123,28 +127,66 @@ cpu_ucode_apply(const struct cpu_ucode *
sc->sc_blobsize = 0;
return error;
}
-
-#ifdef COMPAT_60
+#else
int
-compat6_cpu_ucode_apply(const struct compat6_cpu_ucode *data)
+cpu_ucode_apply(const struct cpu_ucode *data)
{
struct cpu_ucode_softc *sc = &ucode_softc;
+ struct xen_platform_op op;
int error;
- if (cpu_vendor != CPUVENDOR_AMD)
+ /* Xen updates all??? */
+ if (data->cpu_nr != CPU_UCODE_ALL_CPUS)
return EOPNOTSUPP;
- sc->loader_version = CPU_UCODE_LOADER_AMD;
+ sc->loader_version = data->loader_version;
error = cpu_ucode_load(sc, data->fwname);
if (error)
return error;
- error = cpu_ucode_amd_apply(sc, CPU_UCODE_ALL_CPUS);
+ op.cmd = XENPF_microcode_update;
+ set_xen_guest_handle(op.u.microcode.data, sc->sc_blob);
+ op.u.microcode.length = sc->sc_blobsize;
- if (sc->sc_blob != NULL)
+ error = -HYPERVISOR_platform_op(&op);
+
+ if (sc->sc_blob)
firmware_free(sc->sc_blob, sc->sc_blobsize);
sc->sc_blob = NULL;
sc->sc_blobsize = 0;
return error;
}
+#endif
+
+#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 *data6)
+{
+
+ if (cpu_vendor != CPUVENDOR_AMD)
+ return EOPNOTSUPP;
+
+ struct cpu_ucode data;
+
+ data.loader_version = CPU_UCODE_LOADER_AMD;
+ data.cpu_nr = CPU_UCODE_ALL_CPUS;
+ strcpy(data.fwname, data6->fwname);
+
+ return cpu_ucode_apply(&data);
+}
#endif /* COMPAT60 */
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.7.28.1
--- src/sys/arch/x86/x86/cpu_ucode_amd.c:1.7 Fri Nov 15 08:47:55 2013
+++ src/sys/arch/x86/x86/cpu_ucode_amd.c Sat Mar 17 21:37:52 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.7.28.1 2018/03/17 21:37:52 pgoyette 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.7.28.1 2018/03/17 21:37:52 pgoyette 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.12.8.1
--- src/sys/arch/x86/x86/cpu_ucode_intel.c:1.12 Thu Jun 1 02:45:08 2017
+++ src/sys/arch/x86/x86/cpu_ucode_intel.c Sat Mar 17 21:37:52 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.12.8.1 2018/03/17 21:37:52 pgoyette 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.12.8.1 2018/03/17 21:37:52 pgoyette 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
Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.165 src/sys/arch/xen/conf/files.xen:1.165.2.1
--- src/sys/arch/xen/conf/files.xen:1.165 Mon Jan 22 22:36:11 2018
+++ src/sys/arch/xen/conf/files.xen Sat Mar 17 21:37:52 2018
@@ -1,4 +1,4 @@
-# $NetBSD: files.xen,v 1.165 2018/01/22 22:36:11 jdolecek Exp $
+# $NetBSD: files.xen,v 1.165.2.1 2018/03/17 21:37:52 pgoyette Exp $
# NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp
# NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp
@@ -93,7 +93,7 @@ file arch/xen/x86/xen_pmap.c
file arch/xen/x86/xen_intr.c
file arch/xen/x86/xenfunc.c
-file arch/xen/xen/xen_ucode.c dom0ops & cpu_ucode needs-flag
+file arch/x86/x86/cpu_ucode.c dom0ops & cpu_ucode needs-flag
file arch/x86/x86/cpu_ucode_amd.c dom0ops & cpu_ucode needs-flag
file arch/x86/x86/cpu_ucode_intel.c dom0ops & cpu_ucode needs-flag
Index: src/sys/compat/common/Makefile.sysio
diff -u src/sys/compat/common/Makefile.sysio:1.7.18.3 src/sys/compat/common/Makefile.sysio:1.7.18.4
--- src/sys/compat/common/Makefile.sysio:1.7.18.3 Thu Mar 15 09:12:05 2018
+++ src/sys/compat/common/Makefile.sysio Sat Mar 17 21:37:52 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.sysio,v 1.7.18.3 2018/03/15 09:12:05 pgoyette Exp $
+# $NetBSD: Makefile.sysio,v 1.7.18.4 2018/03/17 21:37:52 pgoyette Exp $
# Sources for syscall and ioctl compatibility across the versions.
@@ -38,7 +38,7 @@ SRCS+= kern_50.c kern_time_50.c kern_sel
vfs_syscalls_50.c uipc_syscalls_50.c uvm_50.c
# Compatibility code for NetBSD 6.0
-SRCS+= kern_sa_60.c tty_60.c kern_time_60.c
+SRCS+= kern_sa_60.c tty_60.c kern_time_60.c kern_cpu_60.c
# Compatibility code for NetBSD 7.0
SRCS+= rtsock_70.c uipc_usrreq_70.c
Index: src/sys/compat/common/compat_mod.c
diff -u src/sys/compat/common/compat_mod.c:1.24.14.13 src/sys/compat/common/compat_mod.c:1.24.14.14
--- src/sys/compat/common/compat_mod.c:1.24.14.13 Fri Mar 16 08:10:26 2018
+++ src/sys/compat/common/compat_mod.c Sat Mar 17 21:37:52 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_mod.c,v 1.24.14.13 2018/03/16 08:10:26 pgoyette Exp $ */
+/* $NetBSD: compat_mod.c,v 1.24.14.14 2018/03/17 21:37:52 pgoyette Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: compat_mod.c,v 1.24.14.13 2018/03/16 08:10:26 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_mod.c,v 1.24.14.14 2018/03/17 21:37:52 pgoyette Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -64,6 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: compat_mod.c
#include <compat/common/compat_mod.h>
#include <compat/common/if_43.h>
#include <compat/sys/uvm.h>
+#include <compat/sys/cpuio.h>
#if defined(COMPAT_09) || defined(COMPAT_43) || defined(COMPAT_50)
static struct sysctllog *compat_clog = NULL;
@@ -292,6 +293,12 @@ compat_modcmd(modcmd_t cmd, void *arg)
#ifdef COMPAT_70
compat_70_init();
#endif
+#ifdef COMPAT_60
+ kern_cpu_60_init();
+#endif
+#ifdef COMPAT_60
+ kern_cpu_60_fini();
+#endif
return 0;
case MODULE_CMD_FINI:
Index: src/sys/compat/sys/cpuio.h
diff -u src/sys/compat/sys/cpuio.h:1.5 src/sys/compat/sys/cpuio.h:1.5.16.1
--- src/sys/compat/sys/cpuio.h:1.5 Sun Sep 6 06:00:59 2015
+++ src/sys/compat/sys/cpuio.h Sat Mar 17 21:37:52 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuio.h,v 1.5 2015/09/06 06:00:59 dholland Exp $ */
+/* $NetBSD: cpuio.h,v 1.5.16.1 2018/03/17 21:37:52 pgoyette Exp $ */
#include <sys/ioccom.h>
@@ -7,5 +7,10 @@ struct compat6_cpu_ucode {
char fwname[PATH_MAX];
};
+extern int (*compat_cpuctl_ioctl)(u_long, void *);
+
#define OIOC_CPU_UCODE_GET_VERSION _IOR('c', 4, struct compat6_cpu_ucode)
#define OIOC_CPU_UCODE_APPLY _IOW('c', 5, struct compat6_cpu_ucode)
+
+void kern_cpu_60_init(void);
+void kern_cpu_60_fini(void);
Index: src/sys/kern/kern_cpu.c
diff -u src/sys/kern/kern_cpu.c:1.71.16.6 src/sys/kern/kern_cpu.c:1.71.16.7
--- src/sys/kern/kern_cpu.c:1.71.16.6 Sat Mar 17 06:49:57 2018
+++ src/sys/kern/kern_cpu.c Sat Mar 17 21:37:53 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_cpu.c,v 1.71.16.6 2018/03/17 06:49:57 pgoyette Exp $ */
+/* $NetBSD: kern_cpu.c,v 1.71.16.7 2018/03/17 21:37:53 pgoyette Exp $ */
/*-
* Copyright (c) 2007, 2008, 2009, 2010, 2012 The NetBSD Foundation, Inc.
@@ -56,10 +56,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.71.16.6 2018/03/17 06:49:57 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.71.16.7 2018/03/17 21:37:53 pgoyette Exp $");
#include "opt_cpu_ucode.h"
-#include "opt_compat_netbsd.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -128,6 +127,7 @@ struct cpu_info **cpu_infos __read_most
kcpuset_t * kcpuset_attached __read_mostly = NULL;
kcpuset_t * kcpuset_running __read_mostly = NULL;
+int (*compat_cpuctl_ioctl)(u_long, void *) = (void *)enosys;
static char cpu_model[128];
@@ -285,12 +285,6 @@ cpuctl_ioctl(dev_t dev, u_long cmd, void
error = cpu_ucode_get_version((struct cpu_ucode_version *)data);
break;
-#ifdef COMPAT_60
- case OIOC_CPU_UCODE_GET_VERSION:
- error = compat6_cpu_ucode_get_version((struct compat6_cpu_ucode *)data);
- break;
-#endif
-
case IOC_CPU_UCODE_APPLY:
error = kauth_authorize_machdep(l->l_cred,
KAUTH_MACHDEP_CPU_UCODE_APPLY,
@@ -299,21 +293,10 @@ cpuctl_ioctl(dev_t dev, u_long cmd, void
break;
error = cpu_ucode_apply((const struct cpu_ucode *)data);
break;
-
-#ifdef COMPAT_60
- case OIOC_CPU_UCODE_APPLY:
- error = kauth_authorize_machdep(l->l_cred,
- KAUTH_MACHDEP_CPU_UCODE_APPLY,
- NULL, NULL, NULL, NULL);
- if (error != 0)
- break;
- error = compat6_cpu_ucode_apply((const struct compat6_cpu_ucode *)data);
- break;
-#endif
#endif
default:
- error = ENOTTY;
+ error = (*compat_cpuctl_ioctl)(cmd, data);
break;
}
mutex_exit(&cpu_lock);
Added files:
Index: src/sys/compat/common/kern_cpu_60.c
diff -u /dev/null src/sys/compat/common/kern_cpu_60.c:1.1.2.2
--- /dev/null Sat Mar 17 21:37:53 2018
+++ src/sys/compat/common/kern_cpu_60.c Sat Mar 17 21:37:52 2018
@@ -0,0 +1,75 @@
+/* $NetBSD: kern_cpu_60.c,v 1.1.2.2 2018/03/17 21:37:52 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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: kern_cpu_60.c,v 1.1.2.2 2018/03/17 21:37:52 pgoyette Exp $");
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+#include <sys/kauth.h>
+#include <sys/cpu.h>
+#include <sys/cpuio.h>
+
+#include <compat/sys/cpuio.h>
+
+static int
+compat6_cpuctl_ioctl(u_long cmd, void *data)
+{
+ switch (cmd) {
+#if defined(CPU_UCODE) && defined(COMPAT_60)
+ case OIOC_CPU_UCODE_GET_VERSION:
+ return compat6_cpu_ucode_get_version(data);
+
+ case OIOC_CPU_UCODE_APPLY:
+ error = kauth_authorize_machdep(l->l_cred,
+ KAUTH_MACHDEP_CPU_UCODE_APPLY, NULL, NULL, NULL, NULL);
+ if (error)
+ return error;
+ return compat6_cpu_ucode_apply(data);
+#endif
+ default:
+ return ENOTTY;
+ }
+}
+
+void
+kern_cpu_60_init(void)
+{
+ compat_cpuctl_ioctl = compat6_cpuctl_ioctl;
+}
+
+void
+kern_cpu_60_fini(void)
+{
+ compat_cpuctl_ioctl = (void *)enosys;
+}