xref: /netbsd-src/sys/compat/common/kern_cpu_60.c (revision d91f98a8715141154279122ae81737cb65179572)
1*d91f98a8Spgoyette /*	$NetBSD: kern_cpu_60.c,v 1.4 2019/01/27 02:08:39 pgoyette Exp $	*/
2ab151d3eSchristos 
3ab151d3eSchristos /*-
4ab151d3eSchristos  * Copyright (c) 2018 The NetBSD Foundation, Inc.
5ab151d3eSchristos  * All rights reserved.
6ab151d3eSchristos  *
7ab151d3eSchristos  * This code is derived from software contributed to The NetBSD Foundation
8ab151d3eSchristos  * by Christos Zoulas.
9ab151d3eSchristos  *
10ab151d3eSchristos  * Redistribution and use in source and binary forms, with or without
11ab151d3eSchristos  * modification, are permitted provided that the following conditions
12ab151d3eSchristos  * are met:
13ab151d3eSchristos  * 1. Redistributions of source code must retain the above copyright
14ab151d3eSchristos  *    notice, this list of conditions and the following disclaimer.
15ab151d3eSchristos  * 2. Redistributions in binary form must reproduce the above copyright
16ab151d3eSchristos  *    notice, this list of conditions and the following disclaimer in the
17ab151d3eSchristos  *    documentation and/or other materials provided with the distribution.
18ab151d3eSchristos  *
19ab151d3eSchristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20ab151d3eSchristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21ab151d3eSchristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22ab151d3eSchristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23ab151d3eSchristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24ab151d3eSchristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25ab151d3eSchristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26ab151d3eSchristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ab151d3eSchristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28ab151d3eSchristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29ab151d3eSchristos  * POSSIBILITY OF SUCH DAMAGE.
30ab151d3eSchristos  */
31ab151d3eSchristos 
32ab151d3eSchristos #include <sys/cdefs.h>
33*d91f98a8Spgoyette __KERNEL_RCSID(0, "$NetBSD: kern_cpu_60.c,v 1.4 2019/01/27 02:08:39 pgoyette Exp $");
34*d91f98a8Spgoyette 
35*d91f98a8Spgoyette #ifdef _KERNEL_OPT
36*d91f98a8Spgoyette #include "opt_cpu_ucode.h"
37*d91f98a8Spgoyette #include "opt_compat_netbsd.h"
38*d91f98a8Spgoyette #endif
39cf143c37Schristos 
40cf143c37Schristos #ifdef _KERNEL_OPT
41cf143c37Schristos #include "opt_cpu_ucode.h"
42cf143c37Schristos #include "opt_compat_netbsd.h"
43cf143c37Schristos #endif
44ab151d3eSchristos 
45ab151d3eSchristos #include <sys/param.h>
46ab151d3eSchristos #include <sys/types.h>
47ab151d3eSchristos #include <sys/systm.h>
48ab151d3eSchristos #include <sys/errno.h>
49ab151d3eSchristos #include <sys/kauth.h>
50*d91f98a8Spgoyette #include <sys/lwp.h>
51ab151d3eSchristos #include <sys/cpu.h>
52ab151d3eSchristos 
534ca63f4cSchristos #include <compat/sys/cpuio.h>
544ca63f4cSchristos 
55ab151d3eSchristos static int
compat6_cpuctl_ioctl(struct lwp * l,u_long cmd,void * data)56cf143c37Schristos compat6_cpuctl_ioctl(struct lwp *l, u_long cmd, void *data)
57ab151d3eSchristos {
58*d91f98a8Spgoyette 
59ab151d3eSchristos 	switch (cmd) {
60ab151d3eSchristos #if defined(CPU_UCODE) && defined(COMPAT_60)
61ab151d3eSchristos 	case OIOC_CPU_UCODE_GET_VERSION:
62ab151d3eSchristos 		return compat6_cpu_ucode_get_version(data);
63ab151d3eSchristos 
64ab151d3eSchristos 	case OIOC_CPU_UCODE_APPLY:
65*d91f98a8Spgoyette 	    {
66*d91f98a8Spgoyette 		int error;
67*d91f98a8Spgoyette 
68ab151d3eSchristos 		error = kauth_authorize_machdep(l->l_cred,
69ab151d3eSchristos 		    KAUTH_MACHDEP_CPU_UCODE_APPLY, NULL, NULL, NULL, NULL);
70ab151d3eSchristos 		if (error)
71ab151d3eSchristos 			return error;
72ab151d3eSchristos 		return compat6_cpu_ucode_apply(data);
73*d91f98a8Spgoyette 	    }
74ab151d3eSchristos #endif
75ab151d3eSchristos  	default:
76ab151d3eSchristos 		return ENOTTY;
77ab151d3eSchristos  	}
78ab151d3eSchristos }
79ab151d3eSchristos 
80ab151d3eSchristos void
kern_cpu_60_init(void)81ab151d3eSchristos kern_cpu_60_init(void)
82ab151d3eSchristos {
83*d91f98a8Spgoyette 
84ab151d3eSchristos 	compat_cpuctl_ioctl = compat6_cpuctl_ioctl;
85ab151d3eSchristos }
86ab151d3eSchristos 
87ab151d3eSchristos void
kern_cpu_60_fini(void)88ab151d3eSchristos kern_cpu_60_fini(void)
89ab151d3eSchristos {
90*d91f98a8Spgoyette 
91ab151d3eSchristos 	compat_cpuctl_ioctl = (void *)enosys;
92ab151d3eSchristos }
93