/*
* 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.
*/
#include <sys/xpv_user.h>
#include <sys/hypervisor.h>
#include <sys/xen_errno.h>
#include <sys/privcmd_impl.h>
/*ARGSUSED*/
static int
{
switch (cmd) {
case DDI_INFO_DEVT2DEVINFO:
case DDI_INFO_DEVT2INSTANCE:
break;
default:
return (DDI_FAILURE);
}
case PRIVCMD_MINOR:
break;
default:
return (DDI_FAILURE);
}
if (cmd == DDI_INFO_DEVT2INSTANCE)
*result = 0;
else
*result = privcmd_devi;
return (DDI_SUCCESS);
}
static int
{
if (cmd != DDI_ATTACH)
return (DDI_FAILURE);
return (DDI_FAILURE);
privcmd_devi = devi;
return (DDI_SUCCESS);
}
static int
{
if (cmd != DDI_DETACH)
return (DDI_FAILURE);
privcmd_devi = NULL;
return (DDI_SUCCESS);
}
/*ARGSUSED1*/
static int
{
}
/*
* Map a contiguous set of machine frames in a foreign domain.
* Used in the following way:
*
* privcmd_mmap_t p;
* privcmd_mmap_entry_t e;
*
* addr = mmap(NULL, size, prot, MAP_SHARED, fd, 0);
* p.num = number of privcmd_mmap_entry_t's
* p.dom = domid;
* p.entry = &e;
* e.va = addr;
* e.mfn = mfn;
* e.npages = btopr(size);
* ioctl(fd, IOCTL_PRIVCMD_MMAP, &p);
*/
/*ARGSUSED2*/
int
{
int i, error = 0;
return (EFAULT);
goto done;
}
break;
}
break;
}
/*
* Find the segment we want to mess with, then add
* the mfn range to the segment.
*/
else
if (error != 0)
break;
}
done:
return (error);
}
/*
* Set up the address range to map to an array of mfns in
* a foreign domain. Used in the following way:
*
* privcmd_mmap_batch_t p;
*
* addr = mmap(NULL, size, prot, MAP_SHARED, fd, 0);
* p.num = number of pages
* p.dom = domid
* p.addr = addr;
* p.arr = array of mfns, indexed 0 .. p.num - 1
* ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &p);
*/
/*ARGSUSED2*/
static int
{
int i, error = 0;
return (EFAULT);
goto done;
}
break;
}
if (mfn == MFN_INVALID) {
/*
* This mfn is invalid and should not be added to
* segmf, as we'd only cause an immediate EFAULT when
* we tried to fault it in.
*/
continue;
}
continue;
/*
* Tell the process that this MFN could not be mapped, so it
* won't later try to access it.
*/
break;
}
}
done:
return (error);
}
/*ARGSUSED*/
static int
{
if (secpolicy_xvm_control(cr))
return (EPERM);
/*
* Everything is a -native- data type.
*/
return (EOVERFLOW);
switch (cmd) {
case IOCTL_PRIVCMD_HYPERCALL:
case IOCTL_PRIVCMD_MMAP:
if (DOMAIN_IS_PRIVILEGED(xen_info))
break;
case IOCTL_PRIVCMD_MMAPBATCH:
if (DOMAIN_IS_PRIVILEGED(xen_info))
break;
default:
break;
}
return (EINVAL);
}
/*
* The real magic happens in the segmf segment driver.
*/
/*ARGSUSED8*/
static int
{
struct segmf_crargs a;
int error;
if (secpolicy_xvm_control(cr))
return (EPERM);
goto rangeunlock;
}
} else {
/*
* User specified address
*/
}
/*
* The mapping *must* be MAP_SHARED at offset 0.
*
* (Foreign pages are treated like device memory; the
* ioctl interface allows the backing objects to be
* arbitrarily redefined to point at any machine frame.)
*/
goto rangeunlock;
}
return (error);
}
nulldev, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
nodev, /* devmap */
nodev, /* mmap */
nochpoll, /* poll */
NULL,
};
0,
nulldev, /* identify */
nulldev, /* probe */
nodev, /* reset */
0, /* struct bus_ops */
NULL, /* power */
ddi_quiesce_not_needed, /* quiesce */
};
"privcmd driver",
};
};
int
_init(void)
{
return (mod_install(&modl));
}
int
_fini(void)
{
return (mod_remove(&modl));
}
int
{
}