vbi.c revision 11e871b2c3c4e5a506263fa376920a758dc62916
/*
* 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.
*/
/*
* Private interfaces for VirtualBox access to Solaris kernel internal
* facilities.
*
*/
#include <sys/schedctl.h>
#include <sys/sysmacros.h>
#include <sys/x86_archext.h>
#include <vm/seg_kmem.h>
#include <sys/machparam.h>
#include "vbi.h"
/*
* We have to use dl_lookup to find contig_free().
*/
extern void contig_free(void *, size_t);
#pragma weak contig_free
/*
* Workarounds for running on old versions of solaris with different cross call
* interfaces. If we find xc_init_cpu() in the kenel, then just use the defined
* interfaces for xc_call() from the include file where the xc_call()
* interfaces just takes a pointer to a ulong_t array. The array must be long
* enough to hold "ncpus" bits at runtime.
* The reason for the hacks is that using the type "cpuset_t" is pretty much
* impossible from code built outside the Solaris source repository that wants
* to run on multiple releases of Solaris.
*
* For old style xc_call()s, 32 bit solaris and older 64 bit versions use
* "ulong_t" as cpuset_t.
*
* Later versions of 64 bit Solaris used: struct {ulong_t words[x];}
* where "x" depends on NCPU.
*
* We detect the difference in 64 bit support by checking the kernel value of
* max_cpuid, which always holds the compiled value of NCPU - 1.
*
* If Solaris increases NCPU to more than 256, this module will continue
* to work on all versions of Solaris as long as the number of installed
* CPUs in the machine is <= VBI_NCPU. If VBI_NCPU is increased, this code
* has to be re-written some to provide compatibility with older Solaris which
* expects cpuset_t to be based on NCPU==256 -- or we discontinue support
*/
static int use_old = 0;
static int use_old_with_ulong = 0;
#define VBI_NCPU 256
typedef struct vbi_cpuset {
} vbi_cpuset_t;
/*
* module linkage stuff
*/
static struct modlmisc vbi_modlmisc = {
&mod_miscops, "VirtualBox Interfaces V6"
};
static struct modlinkage vbi_modlinkage = {
};
extern uintptr_t kernelbase;
static int vbi_verbose = 0;
/* Introduced in v6 */
static int vbi_is_nevada = 0;
#ifdef _LP64
/* 64-bit Solaris 10 offsets */
/* CPU */
static int off_s10_cpu_runrun = 232;
static int off_s10_cpu_kprunrun = 233;
/* kthread_t */
static int off_s10_t_preempt = 42;
/* 64-bit Solaris 11 (Nevada/OpenSolaris) offsets */
/* CPU */
static int off_s11_cpu_runrun = 216;
static int off_s11_cpu_kprunrun = 217;
/* kthread_t */
static int off_s11_t_preempt = 42;
#else
/* 32-bit Solaris 10 offsets */
/* CPU */
static int off_s10_cpu_runrun = 124;
static int off_s10_cpu_kprunrun = 125;
/* kthread_t */
static int off_s10_t_preempt = 26;
/* 32-bit Solaris 11 (Nevada/OpenSolaris) offsets */
/* CPU */
static int off_s11_cpu_runrun = 112;
static int off_s11_cpu_kprunrun = 113;
/* kthread_t */
static int off_s11_t_preempt = 26;
#endif
/* Which offsets will be used */
static int off_cpu_runrun = -1;
static int off_cpu_kprunrun = -1;
static int off_t_preempt = -1;
#define VBI_PREEMPT_DISABLE() \
{ \
VBI_T_PREEMPT++; \
}
#define VBI_PREEMPT_ENABLE() \
{ \
if (--VBI_T_PREEMPT == 0 && \
}
/* End of v6 intro */
#if 0
int
_init(void)
{
if (!err)
return (err);
}
#endif
int
vbi_init(void)
{
int err;
/*
* Check to see if this version of virtualbox interface module will work
* with the kernel.
*/
/*
* Our bit vector storage needs to be large enough for the
* actual number of CPUs running in the sytem.
*/
return (EINVAL);
} else {
use_old = 1;
use_old_with_ulong = 1;
return (EINVAL); /* cpuset_t size mismatch */
}
/*
* In older versions of Solaris contig_free() is a static routine.
*/
if (p_contig_free == NULL) {
p_contig_free = (void (*)(void *, size_t))
if (p_contig_free == NULL) {
return (EINVAL);
}
}
/*
* Check if this is S10 or Nevada
*/
{
/* Nevada detected... */
vbi_is_nevada = 1;
}
else
{
/* Solaris 10 detected... */
vbi_is_nevada = 0;
}
/*
* Sanity checking...
*/
/* CPU */
char crr = VBI_CPU_RUNRUN;
char krr = VBI_CPU_KPRUNRUN;
{
return EINVAL;
}
/* Thread */
char t_preempt = VBI_T_PREEMPT;
{
return EINVAL;
}
return (0);
}
#if 0
int
_fini(void)
{
if (err != 0)
return (err);
return (0);
}
int
{
}
#endif
static ddi_dma_attr_t base_attr = {
DMA_ATTR_V0, /* Version Number */
(uint64_t)0, /* lower limit */
(uint64_t)0, /* high limit */
1, /* list length (1 for contiguous) */
1, /* device granularity */
0 /* bus-specific flags */
};
static void *
{
void *ptr;
if ((size & PAGEOFFSET) != 0)
return (NULL);
if (npages == 0)
return (NULL);
if (!contig)
VBI_VERBOSE("vbi_internal_alloc() failure");
return (NULL);
}
if (pfn == PFN_INVALID)
panic("vbi_contig_alloc(): hat_getpfnum() failed\n");
return (ptr);
}
void *
{
}
void
{
}
void *
{
VBI_VERBOSE("vbi_kernel_map() bad pa or size");
return (NULL);
}
return (va);
}
void
{
} else {
}
}
void *
vbi_curthread(void)
{
return (curthread);
}
int
vbi_yield(void)
{
int rv = 0;
char tpr = VBI_T_PREEMPT;
char kpr = VBI_CPU_KPRUNRUN;
rv = 1;
return (rv);
}
vbi_timer_granularity(void)
{
return (nsec_per_tick);
}
typedef struct vbi_timer {
void (*vbi_func)();
void *vbi_arg1;
void *vbi_arg2;
} vbi_timer_t;
static void
vbi_timer_callback(void *arg)
{
vbi_timer_t *t = arg;
if (t->vbi_interval == 0)
}
void *
{
t->vbi_handler.cyh_arg = (void *)t;
t->vbi_cyclic = CYCLIC_NONE;
t->vbi_interval = interval;
return (t);
}
void
vbi_timer_destroy(void *timer)
{
vbi_timer_t *t = timer;
if (t != NULL) {
kmem_free(t, sizeof (*t));
}
}
void
{
vbi_timer_t *t = timer;
if (interval == 0)
else
}
void
vbi_timer_stop(void *timer)
{
vbi_timer_t *t = timer;
if (t->vbi_cyclic == CYCLIC_NONE)
return;
if (t->vbi_cyclic != CYCLIC_NONE) {
cyclic_remove(t->vbi_cyclic);
t->vbi_cyclic = CYCLIC_NONE;
}
}
vbi_tod(void)
{
}
void *
vbi_proc(void)
{
proc_t *p;
drv_getparm(UPROCP, &p);
return (p);
}
void
{
thread_lock(t);
(void) thread_change_pri(t, priority, 0);
thread_unlock(t);
}
void *
{
kthread_t *t;
return (t);
}
void
vbi_thread_exit(void)
{
thread_exit();
}
void *
{
}
void
{
}
int
vbi_cpu_id(void)
{
}
int
vbi_max_cpu_id(void)
{
return (max_cpuid);
}
int
vbi_cpu_maxcount(void)
{
return (max_cpuid + 1);
}
int
vbi_cpu_count(void)
{
return (ncpus);
}
int
vbi_cpu_online(int c)
{
int x;
x = cpu_is_online(cpu[c]);
return (x);
}
void
vbi_preempt_disable(void)
{
}
void
vbi_preempt_enable(void)
{
}
void
{
int i;
for (i = 0; i < VBI_SET_WORDS; ++i)
if (use_old) {
if (use_old_with_ulong) {
} else {
}
} else {
}
}
void
{
int i;
for (i = 0; i < VBI_SET_WORDS; ++i)
if (use_old) {
if (use_old_with_ulong) {
} else {
}
} else {
}
}
void
{
int i;
for (i = 0; i < VBI_SET_WORDS; ++i)
if (use_old) {
if (use_old_with_ulong) {
} else {
}
} else {
}
}
int
{
/*
* kernel mappings on x86 are always locked, so only handle user.
*/
if (err != 0) {
VBI_VERBOSE("vbi_lock_va() failed to lock");
return (-1);
}
}
return (0);
}
/*ARGSUSED*/
void
{
}
vbi_va_to_pa(void *addr)
{
if (IS_KERNEL(v))
else
if (pfn == PFN_INVALID)
return (-(uint64_t)1);
}
struct segvbi_crargs {
};
struct segvbi_data {
};
static struct seg_ops segvbi_ops;
static int
{
struct segvbi_crargs *a = args;
struct segvbi_data *data;
int error = 0;
ulong_t p;
/*
* now load locked mappings to the pages
*/
}
return (error);
}
/*
* Duplicate a seg and return new segment in newseg.
*/
static int
{
struct segvbi_data *ndata;
return (0);
}
static int
{
panic("segvbi_unmap");
return (ENOTSUP);
return (0);
}
static void
{
}
/*
* We never demand-fault for seg_vbi.
*/
static int
{
return (FC_MAKE_ERR(EFAULT));
}
static int
{
return (0);
}
static int
{
return (EACCES);
}
static int
{
return (EINVAL);
}
static int
{
return (-1);
}
static int
{
return (0);
}
static size_t
{
size_t v;
*vec++ = 1;
return (v);
}
static int
{
return (0);
}
static int
{
}
static u_offset_t
{
}
static int
{
return (MAP_SHARED);
}
static int
{
return (0);
}
static int
{
return (0);
}
static void
{}
static int
{
return (ENOTSUP);
}
static int
{
return (ENOTSUP);
}
static int
{
return (ENODEV);
}
static lgrp_mem_policy_info_t *
{
return (NULL);
}
static int
{
return (0);
}
static struct seg_ops segvbi_ops = {
(int (*)())segvbi_kluster,
};
/*
* Interfaces to inject physical pages into user address space
* and later remove them.
*/
int
{
struct segvbi_crargs args;
int error = 0;
else
if (error)
VBI_VERBOSE("vbi_user_map() failed");
return (error);
}
/*
* This is revision 2 of the interface.
*/
struct vbi_cpu_watch {
void (*vbi_cpu_func)();
void *vbi_cpu_arg;
};
static int
{
vbi_cpu_watch_t *w = arg;
int online;
online = 1;
online = 0;
else
return (0);
return (0);
}
{
int c;
vbi_cpu_watch_t *w;
w = kmem_alloc(sizeof (*w), KM_SLEEP);
w->vbi_cpu_func = func;
w->vbi_cpu_arg = arg;
if (current_too) {
for (c = 0; c < ncpus; ++c) {
if (cpu_is_online(cpu[c]))
}
}
return (w);
}
void
{
kmem_free(w, sizeof (*w));
}
/*
* Simple timers are pretty much a pass through to the cyclic subsystem.
*/
struct vbi_stimer {
void *s_arg;
};
static void
vbi_stimer_func(void *arg)
{
vbi_stimer_t *t = arg;
}
extern vbi_stimer_t *
void *arg,
int on_cpu)
{
t->s_tick = 0;
t = NULL;
goto done;
}
if (interval == 0)
else
if (on_cpu != VBI_ANY_CPU)
done:
return (t);
}
extern void
{
cyclic_remove(t->s_cyclic);
kmem_free(t, sizeof (*t));
}
/*
* Global timers are more complicated. They include a counter on the callback,
* that indicates the first call on a given cpu.
*/
struct vbi_gtimer {
void *g_arg;
};
static void
vbi_gtimer_func(void *arg)
{
vbi_gtimer_t *t = arg;
}
/*
* Whenever a cpu is onlined, need to reset the g_counters[] for it to zero.
*/
static void
{
vbi_gtimer_t *t = arg;
h->cyh_func = vbi_gtimer_func;
h->cyh_arg = t;
h->cyh_level = CY_LOCK_LEVEL;
else
}
void *arg,
{
vbi_gtimer_t *t;
/*
* one shot global timer is not supported yet.
*/
if (interval == 0)
return (NULL);
t = kmem_zalloc(sizeof (*t), KM_SLEEP);
t->g_interval = interval;
t->g_cyclic = CYCLIC_NONE;
return (t);
}
extern void
{
cyclic_remove(t->g_cyclic);
kmem_free(t, sizeof (*t));
}
int
vbi_is_preempt_enabled(void)
{
char tpr = VBI_T_PREEMPT;
return (tpr == 0);
}
void
vbi_poke_cpu(int c)
{
if (c < ncpus)
poke_cpu(c);
}
/*
* This is revision 5 of the interface. As more functions are added,
* they should go after this point in the file and the revision level
* increased. Also change vbi_modlmisc at the top of the file.
*/
void *
{
}
void
{
}
/*
* This is revision 6 of the interface.
*/
int
vbi_is_preempt_pending(void)
{
char crr = VBI_CPU_RUNRUN;
char krr = VBI_CPU_KPRUNRUN;
}