/*
* 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.
* Copyright (c) 2011 Bayard G. Bell. All rights reserved.
*/
/*
* fcode helper driver -- provide priv. access and kernel communication
* to the userland fcode interpreter.
*/
#include <sys/ddi_impldefs.h>
#include <sys/ndi_impldefs.h>
/*
* Soft state associated with each instance of driver open.
*/
static struct fc_state {
} *fc_states;
#define FC_STATE_ACTIVE(s) ((s) != 0)
fc_open, /* open */
fc_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
fc_read, /* read */
nodev, /* write */
fc_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* prop_op */
NULL, /* streamtab */
};
DEVO_REV, /* devo_rev, */
0, /* refcnt */
fc_info, /* info */
nulldev, /* identify */
nulldev, /* probe */
fc_attach, /* attach */
fc_detach, /* detach */
nodev, /* reset */
&fc_cb_ops, /* driver operations */
NULL, /* bus operations */
NULL, /* power */
ddi_quiesce_not_needed, /* quiesce */
};
/*
* Module linkage information for the kernel.
*/
"FCode driver",
};
&modldrv,
};
int
_init(void)
{
int error;
if (error != 0) {
return (error);
}
return (0);
}
int
{
}
int
_fini(void)
{
int error;
if (error != 0) {
return (error);
}
return (0);
}
/*ARGSUSED*/
static int
{
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
error = DDI_SUCCESS;
break;
case DDI_INFO_DEVT2INSTANCE:
/* All dev_t's map to the same, single instance */
*result = (void *)0;
error = DDI_SUCCESS;
break;
default:
break;
}
return (error);
}
static int
{
switch (cmd) {
case DDI_ATTACH:
fc_open_count = 0;
fc_max_opens * sizeof (struct fc_state));
error = DDI_FAILURE;
} else {
error = DDI_SUCCESS;
}
break;
default:
error = DDI_FAILURE;
break;
}
return (error);
}
static int
{
switch (cmd) {
case DDI_DETACH:
error = DDI_SUCCESS;
break;
default:
error = DDI_FAILURE;
break;
}
return (error);
}
/*
* Allow multiple opens by tweaking the dev_t such that it looks like each
* open is getting a different minor device. Each minor gets a separate
* entry in the fc_states[] table.
*/
/*ARGSUSED*/
static int
{
int m;
return (EINVAL);
while (fc_open_count >= fc_max_opens) {
/*
* maximum open instance reached, wait for a close
*/
"fcode: Maximum fcode open reached, waiting for exit\n");
return (EINTR);
/*NOTREACHED*/
}
}
continue;
break; /* It's ours. */
}
ASSERT(m < fc_max_opens);
fc_open_count, m + 1);
return (0);
}
/*ARGSUSED*/
static int
{
/*
* The close indicates we're done with this request.
* If we haven't validated this request, then something
* bad may have happened (ie: perhaps the user program was
* killed), so we should invalidate it, then close the session.
*/
}
"fc_close: Send invalidate cmd\n");
}
/*
* else - fp->error already set by userland interpreter
*/
}
}
/*
* Mark the request as done ...
*/
/*
* rectify count and signal any waiters
*/
fc_open_count, m + 1);
if (fc_open_count >= fc_max_opens) {
}
return (0);
}
/*ARGSUSED*/
static int
{
/*
* Wait for a internal request for the interpreter
* and sleep till one arrives. When one arrives,
* return from the read. (No data is actually returned).
*/
return (EINVAL);
}
/*
* Wait for a request, allowing the wait to be interrupted.
*/
return (EINTR);
/*
* Update our state and store the request pointer.
*/
return (0);
}
/*ARGSUSED*/
static int
{
if (m >= fc_max_opens) {
return (EINVAL);
}
switch (cmd) {
case FC_GET_PARAMETERS:
/*
* This should be the first command and is used to
* return data about the request, including the
* the fcode address and size and the unit address
* of the new child. The fcode offset,size can later
* be used as an offset in an mmap request to allow
* the fcode to be mapped in.
*/
case FC_GET_MY_ARGS:
/*
* Get the inital setting of my-args. This should be done
* after FC_GET_PARAMETERS.
*/
case FC_RUN_PRIV:
/*
* Run a priveledged op on behalf of the interpreter,
* or download device tree data from the interpreter.
*/
case FC_VALIDATE:
/*
* The interpreter is done, mark state as done, validating
* the data downloaded into the kernel.
*/
case FC_GET_FCODE_DATA:
/*
* Copy out device fcode to user buffer.
*/
case FC_SET_FCODE_ERROR:
/*
* Copy in interpreter error status
*/
}
/*
* Invalid ioctl command
*/
return (ENOTTY);
}
/*
* fc_get_parameters: Get information about the current request.
* The input 'arg' is a pointer to 'struct fc_parameters' which
* we write back to the caller with the information from the req
* structure.
*/
/*ARGSUSED*/
static int
{
/*
* It's an error if we're not in state FC_STATE_READ_DONE
*/
return (EINVAL);
}
/*
* Create and copyout the attachment point ihandle,
* the fcode kaddr,len and the unit address.
* Note how we treat ihandles and phandles (they are the same thing
* only accross this interface ... a dev_info_t *.)
*/
/*
* XXX - APA This needs to be made more bus independant.
*/
} else {
"There are no bus specific arguments\n");
}
return (EFAULT);
}
/*
* Update our state
*/
return (0);
}
/*
* fc_get_my_args: Get the initial setting for my-args.
* The input 'arg' is a pointer where the my-arg string is written
* to. The string is NULL terminated.
*/
/*ARGSUSED*/
static int
{
/*
* It's an error if we're not in state FC_STATE_READ_DONE
*/
return (EINVAL);
}
"There are no bus specific my-args\n");
return (EINVAL);
}
"my-args is larger than %d\n", FC_GET_MY_ARGS_BUFLEN);
return (EINVAL);
}
return (EFAULT);
}
return (0);
}
/*ARGSUSED*/
static int
{
char *name;
/*
* It's an error if we're not in state FC_STATE_IN_PROGRESS
*/
return (EINVAL);
}
/*
* Get the first three cells to figure out how large the buffer
* needs to be; allocate it and copy it in. The array is variable
* sized based on the fixed portion plus the given number of arg.
* cells and given number of result cells.
*/
"fault copying in first 2 cells from %p\n", arg);
return (EFAULT);
}
/*
* XXX We should probably limit #args and #results to something
* reasonable without blindly copying it in.
*/
/*
* Don't bother copying in the result cells
*/
"fault copying in argument array from %p\n", arg);
return (EFAULT);
}
/*
* reset the error fields.
*/
/*
* Copy in the service name into our copy of the array.
* Later, be careful not to copy out the svc name pointer.
*/
"fault copying in service name from %p\n",
return (EFAULT);
}
"service name <%s> nargs %d nresults %d\n",
/*
* Call the driver's ops function to provide the service
*/
/*
* If error is non-zero, we need to log the error and
* the service name, and write back the error to the
* callers argument array.
*/
"service name <%s> was unserviced\n", name);
sizeof (fc_cell_t));
if (error) {
"fault copying out error result\n");
return (EFAULT);
}
return (0);
}
if (cp->priv_error) {
"service name <%s> caused a priv violation\n", name);
sizeof (fc_cell_t));
sizeof (fc_cell_t));
if (error) {
"fault copying out priv error result\n");
return (EFAULT);
}
return (0);
}
/*
* We believe we have a successful result at this point, thus we
* have to copy out the actual number of result cells to be
* returned, the two error fields and each of the results.
*/
"results (from ops function) overflow\n");
if (error) {
"fault copying out (good) results\n");
return (EFAULT);
}
return (0);
}
/*ARGSUSED*/
static int
{
/*
* It's an error if we're not in state FC_STATE_IN_PROGRESS
*/
return (EINVAL);
}
/*
* Send a "validate" command down the line.
* The command has no arguments and no results.
*/
/*
* Update our state.
*/
return (0);
}
/*
* fc_get_fcode: Copy out device fcode to user buffer.
* The input 'arg' is a pointer to 'fc_fcode_info_t' which
* should have fcode_size field set. The fcode_ptr field is a
* pointer to a user buffer of fcode_size.
*/
/*ARGSUSED*/
static int
{
/*
* It's an error if we're not in state FC_STATE_IN_PROGRESS
*/
return (EINVAL);
}
/*
* Get the fc_fcode_info structure from userland.
*/
"fault copying in fcode_info from %p\n", arg);
return (EFAULT);
}
/*
* Validate that buffer size is what we expect.
*/
"requested size (0x%x) doesn't match real size (0x%x)\n",
return (EINVAL);
}
/*
* Copyout the fcode.
*/
return (EFAULT);
}
return (0);
}
/*
* fc_set_fcode_error: Copy in fcode error.
* The input 'arg' is a pointer to int which
* should have the appropriate error code set.
*/
/*ARGSUSED*/
static int
{
int status;
/*
* It's an error if we're not in state FC_STATE_IN_PROGRESS.
*/
"fc_ioctl:fc_set_fcode_error: wrong state (%d)\n",
return (EINVAL);
}
/*
* Get the error code from userland.
* We expect these to be negative values to denote
* interpreter errors.
*/
"fault copying in status from %p\n", arg);
return (EFAULT);
}
if (!FC_ERROR_VALID(status)) {
"invalid error code specified %i\n", status);
return (EINVAL);
}
return (0);
}