p_online.c revision a31148363f598def767ac48c5d82e1572e44b935
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/processor.h>
/*
* CPU state diagram
*
* P_SPARE
* P_POWEROFF <---> P_OFFLINE <---> P_ONLINE <---> P_NOINTR
* P_FAULTED
*/
int
{
int status;
int error = 0;
int flags = 0;
/*
* Try to get a pointer to the requested CPU structure.
*/
goto out;
}
if (new_status & P_FORCED)
flags = CPU_FORCED;
new_status &= ~P_FORCED;
/*
* Perform credentials check.
*/
switch (new_status) {
case P_STATUS:
goto out;
case P_ONLINE:
case P_OFFLINE:
case P_NOINTR:
case P_FAULTED:
case P_SPARE:
if (secpolicy_ponline(CRED()) != 0)
break;
default:
}
if (error)
goto out;
/*
* return 0 if the CPU is already in the desired new state.
*/
if (status == new_status)
goto out;
switch (new_status) {
case P_ONLINE:
switch (status) {
case P_POWEROFF:
/*
* If CPU is powered off, power it on.
*/
break;
/* FALLTHROUGH */
case P_OFFLINE:
case P_FAULTED:
case P_SPARE:
/*
* If CPU is in one of the offline states,
* bring it online.
*/
break;
case P_NOINTR:
break;
}
break;
case P_OFFLINE:
switch (status) {
case P_NOINTR:
/*
* Before we take the CPU offline, we first enable I/O
* interrupts.
*/
/* FALLTHROUGH */
case P_ONLINE:
case P_FAULTED:
case P_SPARE:
/*
* CPU is online, or in a special offline state.
* Take it offline.
*/
break;
case P_POWEROFF:
/*
* If CPU is powered off, power it on.
*/
}
break;
case P_NOINTR:
switch (status) {
case P_POWEROFF:
/*
* if CPU is powered off, power it on.
*/
break;
/* FALLTHROUGH */
case P_OFFLINE:
case P_FAULTED:
case P_SPARE:
/*
* First, bring the CPU online.
*/
break;
/* FALLTHROUGH */
case P_ONLINE:
/*
* CPU is now online. Try to disable interrupts.
*/
}
break;
case P_FAULTED:
switch (status) {
case P_POWEROFF:
/*
* If CPU is powered off, power it on.
*/
break;
/*FALLTHROUGH*/
case P_OFFLINE:
case P_SPARE:
case P_ONLINE:
case P_NOINTR:
/*
* Mark this CPU as faulted.
*/
}
break;
case P_SPARE:
switch (status) {
case P_POWEROFF:
/*
* If CPU is powered off, power it on.
*/
break;
/*FALLTHROUGH*/
case P_OFFLINE:
case P_FAULTED:
case P_ONLINE:
case P_NOINTR:
/*
* Mark this CPU as a spare.
*/
}
break;
}
out:
return (error);
}
int
{
int rc;
return (rc);
}
/*
*
* only in this system call path and other paths conveying CPU state to
* userland. In general, other kernel consumers should be using the accessor
*/
int
{
int ret;
int old_status;
if (ret != 0)
return (old_status);
}