drctl.c revision af4c679f647cf088543c762e33d41a3ac52cfa14
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* DR control module for LDoms
*/
#include <sys/sysmacros.h>
#include <sys/ddi_impldefs.h>
#include <sys/drctl_impl.h>
/*
* 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 */
ddi_quiesce_not_needed, /* quiesce */
};
&mod_driverops, /* type of module - driver */
"DR Control pseudo driver",
};
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);
}
/*
* Create a reponse structure which includes an array of drctl_rsrc_t
* structures in which each status element is set to the 'status'
* arg. There is no error text, so set the 'offset' elements to 0.
*/
static drctl_resp_t *
{
int i;
DR_DBG_KMEM("%s: alloc addr %p size %ld\n",
for (i = 0; i < count; i++) {
}
return (resp);
}
/*
* Generate an error response message.
*/
static drctl_resp_t *
{
DR_DBG_KMEM("%s: alloc addr %p size %ld\n",
return (resp);
}
/*
* Since response comes from userland, verify that it is at least the
* minimum size based on the size of the original request. Verify
* that any offsets to error strings are within the string area of
* the response and, force the string area to be null-terminated.
*/
static int
verify_response(int cmd,
{
int is_cpu = 0;
int i;
switch (cmd) {
case DRCTL_CPU_CONFIG_REQUEST:
return (EIO);
is_cpu = 1;
break;
case DRCTL_IO_CONFIG_REQUEST:
if (count != 1)
return (EIO);
break;
case DRCTL_MEM_CONFIG_REQUEST:
break;
default:
return (EIO);
}
for (i = 0; i < count; i++)
/* string can't be inside the bounds of original request */
/* string must start inside the message */
return (EIO);
/* If there are any strings, terminate the string area. */
return (0);
}
static int
{
int rv = 0;
char *bufp;
switch (cmd) {
case DRCTL_CPU_CONFIG_REQUEST:
case DRCTL_CPU_CONFIG_NOTIFY:
case DRCTL_IO_UNCONFIG_NOTIFY:
case DRCTL_IO_CONFIG_REQUEST:
case DRCTL_IO_CONFIG_NOTIFY:
case DRCTL_MEM_CONFIG_REQUEST:
case DRCTL_MEM_CONFIG_NOTIFY:
rv = 0;
break;
default:
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 (EINVAL);
}
/*
* Prepare for a reconfig operation.
*/
int
{
static char inval_msg[] = "Invalid command format received.\n";
static char unsup_msg[] = "Unsuppported command received.\n";
static char unk_msg [] = "Failure reason unknown.\n";
static char rsp_msg [] = "Invalid response from "
"reconfiguration daemon.\n";
static char drd_msg [] = "Cannot communicate with reconfiguration "
"daemon (drd) in target domain.\n"
"drd(1M) SMF service may not be enabled.\n";
static char busy_msg [] = "Busy executing earlier command; "
"please try again later.\n";
char *ermsg;
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 (rv == 0) {
/*
* If the upcall to the daemon returned successfully, we
* still need to validate the format of the returned msg.
*/
DR_DBG_KMEM("%s: free addr %p size %ld\n",
} else { /* message format is valid */
}
} else {
switch (rv) {
case ENOTSUP:
break;
case EIO:
break;
default:
break;
}
}
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;
break;
case DRCTL_IO_CONFIG_REQUEST:
break;
case DRCTL_MEM_CONFIG_REQUEST:
break;
break;
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;
if (rv == 0) {
*osize =
bufp =
DR_DBG_KMEM("%s: alloc addr %p size %ld\n",
}
DR_DBG_KMEM("%s: free addr %p size %ld\n",
}
return (rv);
}
static void *
pack_message(int cmd,
{
switch (cmd) {
case DRCTL_CPU_CONFIG_REQUEST:
case DRCTL_CPU_CONFIG_NOTIFY:
break;
case DRCTL_MEM_CONFIG_REQUEST:
case DRCTL_MEM_CONFIG_NOTIFY:
break;
case DRCTL_IO_CONFIG_REQUEST:
case DRCTL_IO_CONFIG_NOTIFY:
case DRCTL_IO_UNCONFIG_NOTIFY:
*data_size = sizeof (drctl_rsrc_t) +
break;
default:
"drctl: pack_message received invalid cmd %d", cmd);
break;
}
if (data_size) {
DR_DBG_KMEM("%s: alloc addr %p size %ld\n",
}
return (msgp);
}
/*
* Block DR operations
*/
void
drctl_block(void)
{
/* Wait for any in progress DR operation to complete */
/* Mark the link busy */
}
/*
* Unblock DR operations
*/
void
drctl_unblock(void)
{
/* Mark the link free */
}