provide compat_50

This commit is contained in:
christos 2009-01-19 17:39:02 +00:00
parent 1b3ee850af
commit d610baec20
3 changed files with 123 additions and 7 deletions

80
sys/compat/sys/cpuio.h Normal file
View File

@ -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 <sys/types.h>
#include <sys/time.h>
#include <sys/ioccom.h>
#ifndef _KERNEL
#include <stdbool.h>
#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_ */

View File

@ -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 <sys/cdefs.h>
__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 <sys/param.h>
#include <sys/systm.h>
@ -79,6 +81,10 @@ __KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.39 2008/12/07 11:40:53 ad Exp $");
#include <uvm/uvm_extern.h>
#ifdef COMPAT_50
#include <compat/sys/cpuio.h>
#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:

View File

@ -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_ */