From d610baec202a5d7db5d7c4f6edf5468164162f69 Mon Sep 17 00:00:00 2001 From: christos Date: Mon, 19 Jan 2009 17:39:02 +0000 Subject: [PATCH] provide compat_50 --- sys/compat/sys/cpuio.h | 80 ++++++++++++++++++++++++++++++++++++++++++ sys/kern/kern_cpu.c | 42 +++++++++++++++++++--- sys/sys/cpuio.h | 8 +++-- 3 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 sys/compat/sys/cpuio.h diff --git a/sys/compat/sys/cpuio.h b/sys/compat/sys/cpuio.h new file mode 100644 index 000000000000..6dafb4d7f898 --- /dev/null +++ b/sys/compat/sys/cpuio.h @@ -0,0 +1,80 @@ +/* $NetBSD: cpuio.h,v 1.1 2009/01/19 17:39:02 christos Exp $ */ + +/*- + * Copyright (c) 2007 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * 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. + */ + +#if !defined(_COMPAT_SYS_CPUIO_H_) +#define _COMPAT_SYS_CPUIO_H_ + +#include +#include +#include + +#ifndef _KERNEL +#include +#endif + +typedef struct cpustate50 { + u_int cs_id; /* matching ci_cpuid */ + bool cs_online; /* running unbound LWPs */ + bool cs_intr; /* fielding interrupts */ + bool cs_unused[2]; /* reserved */ + int32_t cs_lastmod; /* time of last state change */ + char cs_name[16]; /* reserved */ + uint32_t cs_reserved[4]; /* reserved */ +} cpustate50_t; + +static __inline +void cpustate_to_cpustate50(const cpustate_t *cp, cpustate50_t *cp50) +{ + cp50->cs_id = (int32_t)cp->cs_id; + cp50->cs_online = (int32_t)cp->cs_online; + cp50->cs_intr = (int32_t)cp->cs_intr; + memcpy(cp50->cs_unused, cp->cs_unused, sizeof(cp50->cs_unused)); + cp50->cs_lastmod = (int32_t)cp->cs_lastmod; + memcpy(cp50->cs_name, cp->cs_name, sizeof(cp50->cs_name)); + memcpy(cp50->cs_reserved, cp->cs_reserved, sizeof(cp50->cs_reserved)); +} + +static __inline +void cpustate50_to_cpustate(const cpustate50_t *cp50, cpustate_t *cp) +{ + cp->cs_id = cp50->cs_id; + cp->cs_online = cp50->cs_online; + cp->cs_intr = cp50->cs_intr; + memcpy(cp->cs_unused, cp50->cs_unused, sizeof(cp->cs_unused)); + cp->cs_lastmod = cp50->cs_lastmod; + memcpy(cp->cs_name, cp50->cs_name, sizeof(cp->cs_name)); + memcpy(cp->cs_reserved, cp50->cs_reserved, sizeof(cp->cs_reserved)); +} + +#define IOC_CPU_OSETSTATE _IOW('c', 0, cpustate50_t) +#define IOC_CPU_OETSTATE _IOWR('c', 1, cpustate50_t) + +#endif /* !_COMPAT_SYS_CPUIO_H_ */ diff --git a/sys/kern/kern_cpu.c b/sys/kern/kern_cpu.c index 6893b6c92fbe..9854e9165d01 100644 --- a/sys/kern/kern_cpu.c +++ b/sys/kern/kern_cpu.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_cpu.c,v 1.39 2008/12/07 11:40:53 ad Exp $ */ +/* $NetBSD: kern_cpu.c,v 1.40 2009/01/19 17:39:02 christos Exp $ */ /*- * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. @@ -56,7 +56,9 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.39 2008/12/07 11:40:53 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.40 2009/01/19 17:39:02 christos Exp $"); + +#include "opt_compat_netbsd.h" #include #include @@ -79,6 +81,10 @@ __KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.39 2008/12/07 11:40:53 ad Exp $"); #include +#ifdef COMPAT_50 +#include +#endif + void cpuctlattach(int); static void cpu_xc_online(struct cpu_info *); @@ -157,8 +163,20 @@ cpuctl_ioctl(dev_t dev, u_long cmd, void *data, int flag, lwp_t *l) mutex_enter(&cpu_lock); switch (cmd) { +#ifdef IOC_CPU_OSETSTATE + cpustate_t csb; + + case IOC_CPU_OSETSTATE: { + cpustate50_t *ocs = data; + cpustate50_to_cpustate(ocs, &csb); + cs = &csb; + error = 1; + /*FALLTHROUGH*/ + } +#endif case IOC_CPU_SETSTATE: - cs = data; + if (error == 0) + cs = data; error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_CPU, KAUTH_REQ_SYSTEM_CPU_SETSTATE, cs, NULL, NULL); @@ -176,8 +194,18 @@ cpuctl_ioctl(dev_t dev, u_long cmd, void *data, int flag, lwp_t *l) error = cpu_setstate(ci, cs->cs_online); break; +#ifdef IOC_CPU_OGETSTATE + case IOC_CPU_OGETSTATE: { + cpustate50_t *ocs = data; + cpustate50_to_cpustate(ocs, &csb); + cs = &csb; + error = 1; + /*FALLTHROUGH*/ + } +#endif case IOC_CPU_GETSTATE: - cs = data; + if (error == 0) + cs = data; id = cs->cs_id; memset(cs, 0, sizeof(*cs)); cs->cs_id = id; @@ -192,6 +220,12 @@ cpuctl_ioctl(dev_t dev, u_long cmd, void *data, int flag, lwp_t *l) cs->cs_online = true; cs->cs_intr = true; cs->cs_lastmod = ci->ci_schedstate.spc_lastmod; +#ifdef IOC_CPU_OGETSTATE + if (cmd == IOC_CPU_OGETSTATE) { + cpustate50_t *ocs = data; + cpustate_to_cpustate50(cs, ocs); + } +#endif break; case IOC_CPU_MAPID: diff --git a/sys/sys/cpuio.h b/sys/sys/cpuio.h index 19f1163ab7e4..841b64d860bf 100644 --- a/sys/sys/cpuio.h +++ b/sys/sys/cpuio.h @@ -1,4 +1,4 @@ -/* $NetBSD: cpuio.h,v 1.2 2008/04/28 20:24:10 martin Exp $ */ +/* $NetBSD: cpuio.h,v 1.3 2009/01/19 17:39:02 christos Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -54,9 +54,11 @@ typedef struct cpustate { uint32_t cs_reserved[4]; /* reserved */ } cpustate_t; -#define IOC_CPU_SETSTATE _IOW('c', 0, cpustate_t) -#define IOC_CPU_GETSTATE _IOWR('c', 1, cpustate_t) +/* 0 IOC_CPU_OSETSTATE */ +/* 1 IOC_CPU_OGETSTATE */ #define IOC_CPU_GETCOUNT _IOR('c', 2, int) #define IOC_CPU_MAPID _IOWR('c', 3, int) +#define IOC_CPU_SETSTATE _IOW('c', 4, cpustate_t) +#define IOC_CPU_GETSTATE _IOWR('c', 5, cpustate_t) #endif /* !_SYS_CPUIO_H_ */