drctl.c revision 20046e4c1cecc35fec6e8881900a6a4fc194ac2a
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* DR control module for LDoms
*/
#include <sys/sysmacros.h>
#include <sys/ddi_impldefs.h>
#include <sys/drctl_impl.h>
static void *pack_message(int, int, int, void *, size_t *);
/*
* Configuration data structures
*/
static struct cb_ops drctl_cb_ops = {
drctl_open, /* open */
drctl_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
drctl_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* prop_op */
NULL, /* streamtab */
CB_REV, /* cb_ops revision */
nodev, /* async read */
nodev /* async write */
};
DEVO_REV, /* devo_rev */
0, /* refcnt */
drctl_getinfo, /* info */
nulldev, /* identify */
nulldev, /* probe */
drctl_attach, /* attach */
drctl_detach, /* detach */
nodev, /* reset */
&drctl_cb_ops, /* driver operations */
NULL, /* bus operations */
NULL, /* power */
};
&mod_driverops, /* type of module - driver */
"DR Control pseudo driver v%I%",
};
static struct modlinkage modlinkage = {
&modldrv,
};
/*
* Locking strategy
*
* One of the reasons for this module's existence is to serialize
* DR requests which might be coming from different sources. Only
* one operation is allowed to be in progress at any given time.
*
* A single lock word (the 'drc_busy' element below) is NULL
* when there is no operation in progress. When a client of this
* module initiates an operation it grabs the mutex 'drc_lock' in
* order to examine the lock word ('drc_busy'). If no other
* operation is in progress, the lock word will be NULL. If so,
* a cookie which uniquely identifies the requestor is stored in
* the lock word, and the mutex is released. Attempts by other
* clients to initiate an operation will fail.
*
* When the lock-holding client's operation is completed, the
* client will call a "finalize" function in this module, providing
* the cookie passed with the original request. Since the cookie
* matches, the operation will succeed and the lock word will be
* cleared. At this point, an new operation may be initiated.
*/
/*
* Driver private data
*/
static struct drctl_unit {
/* identifier for caller */
int drc_cmd; /* the cmd underway (or -1) */
int drc_flags; /* saved flag from above cmd */
int drc_inst; /* our single instance */
} drctl_state;
int
_init(void)
{
int rv;
return (rv);
}
int
_fini(void)
{
int rv;
return (rv);
return (0);
}
int
{
}
/*
* Do the attach work
*/
static int
{
char *str = "drctl_do_attach";
int retval = DDI_SUCCESS;
return (DDI_FAILURE);
}
if (retval != DDI_SUCCESS) {
return (retval);
}
return (retval);
}
static int
{
switch (cmd) {
case DDI_ATTACH:
default:
return (DDI_FAILURE);
}
}
/* ARGSUSED */
static int
{
switch (cmd) {
case DDI_DETACH:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
static int
{
return (0);
}
static int
{
return (EINVAL);
return (0);
}
static int
{
return (0);
}
/*
* This driver guarantees that if drctl_config_init returns 0,
* a valid response buffer will be passed back to the caller. This
* routine can be used to generate that response in cases where the
* upcall has not resulted in a response message from userland.
*/
static drctl_rsrc_t *
{
int idx;
}
return (rbuf);
}
static int
{
int rv = 0;
char *bufp;
static const char me[] = "drctl_config_common";
switch (cmd) {
case DRCTL_CPU_CONFIG_REQUEST:
case DRCTL_CPU_CONFIG_NOTIFY:
rv = 0;
break;
case DRCTL_MEM_CONFIG_REQUEST:
case DRCTL_MEM_CONFIG_NOTIFY:
case DRCTL_IO_CONFIG_REQUEST:
case DRCTL_IO_CONFIG_NOTIFY:
case DRCTL_IO_UNCONFIG_NOTIFY:
break;
}
if (rv != 0) {
return (rv);
}
/*
* If the operation is a FORCE, we don't send a message to
* the daemon. But, the upstream clients still expect a
* response, so generate a response with all ops 'allowed'.
*/
if (flags == DRCTL_FLAG_FORCE) {
}
return (0);
}
DR_DBG_CTL("%s: from pack_message, bufp = %p size %ld\n",
return (EIO);
/*
* For failure, as part of our contract with the caller,
* generate a response message, but mark all proposed
* changes as 'denied'.
*/
}
return (rv);
}
/*
* Since the response comes from userland, make sure it is
* at least the minimum size and, if it contains error
* strings, that the string area is null-terminated.
*/
static int
{
int idx;
int need_terminator = 0;
static const char me[] = "verify_response";
DR_DBG_CTL("%s: BAD size - count %d size %ld\n",
return (EIO);
}
}
DR_DBG_CTL("%s: unterm. strings: resp %p size %ld char %d\n",
/* Don't fail the transaction, but don't advertise strings */
}
return (0);
}
/*
* Prepare for a reconfig operation.
*/
int
{
static char me[] = "drctl_config_init";
int idx;
int rv;
if (ck == 0)
return (EINVAL);
return (EBUSY);
}
DR_DBG_CTL("%s: cmd %d flags %d res %p count %d\n",
/* Mark the link busy. Below we will fill in the actual cookie. */
/*
* If there wasn't a valid response msg passed back,
* create a response with each resource op denied.
*/
}
}
} else {
}
return (rv);
}
/*
* Complete a reconfig operation.
*/
int
{
int rv;
int notify_cmd;
int flags;
return (EBUSY);
}
/*
* Flip the saved _REQUEST command to its corresponding
* _NOTIFY command.
*/
case DRCTL_CPU_CONFIG_REQUEST:
break;
break;
case DRCTL_MEM_CONFIG_REQUEST:
case DRCTL_MEM_CONFIG_NOTIFY:
case DRCTL_IO_CONFIG_REQUEST:
case DRCTL_IO_CONFIG_NOTIFY:
case DRCTL_IO_UNCONFIG_NOTIFY:
default:
/* none of the above should have been accepted in _init */
ASSERT(0);
goto done;
}
done:
return (rv);
}
static int
{
int rv;
switch (cmd) {
break;
default:
}
return (rv);
}
/*
* Accept a preformatted request from caller and send a message to
* the daemon. A pointer to the daemon's response buffer is passed
* back in obufp, its size in osize.
*/
static int
{
int rv;
return (rv);
}
static void *
{
switch (cmd) {
case DRCTL_CPU_CONFIG_REQUEST:
case DRCTL_CPU_CONFIG_NOTIFY:
break;
default:
"drctl: pack_message received invalid cmd %d", cmd);
}
return (msgp);
}