xenbus_comms.c revision ea8190a2a3b5243d911d4bd8185a4161b02d09c0
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
*
*
* Low level code to talks to Xen Store: ringbuffer and event channel.
*
* Copyright (C) 2005 Rusty Russell, IBM Corporation
*
* This file may be distributed separately from the Linux kernel, or
* incorporated into other software packages, subject to the following license:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this source file (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify,
* and to permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/bootconf.h>
#include <vm/seg_kmem.h>
#ifdef XPV_HVM_DRIVER
#include <sys/xpv_support.h>
#include <sys/hypervisor.h>
#else
#include <vm/kboot_mmu.h>
#include <sys/bootinfo.h>
#include <sys/hypervisor.h>
#include <sys/evtchn_impl.h>
#endif
#ifndef XPV_HVM_DRIVER
static int xenbus_irq;
#endif
static kcondvar_t xb_wait_cv;
static kmutex_t xb_wait_lock;
/*ARGSUSED*/
static uint_t
xenbus_intr(void *unused)
{
return (DDI_INTR_CLAIMED);
}
static int
{
}
static void *
{
}
static const void *
{
}
int
{
volatile struct xenstore_domain_interface *intf =
extern int do_polled_io;
while (len != 0) {
void *dst;
unsigned int avail;
if (interrupts_unleashed && !do_polled_io) {
if (cv_wait_sig(&xb_wait_cv,
&xb_wait_lock) == 0) {
return (EINTR);
}
} else { /* polled mode needed for early probes */
(void) HYPERVISOR_yield();
}
}
/* Read indexes, then verify. */
membar_enter();
return (EIO);
if (avail == 0)
continue;
/* Other side must not see new header until data is there. */
/* This implies mb() before other side sees interrupt. */
}
return (0);
}
int
{
volatile struct xenstore_domain_interface *intf =
extern int do_polled_io;
while (len != 0) {
unsigned int avail;
const char *src;
if (interrupts_unleashed && !do_polled_io) {
if (cv_wait_sig(&xb_wait_cv,
&xb_wait_lock) == 0) {
return (EINTR);
}
} else { /* polled mode needed for early probes */
(void) HYPERVISOR_yield();
}
}
/* Read indexes, then verify. */
membar_enter();
return (EIO);
if (avail == 0)
continue;
/* We must read header before we read data. */
/* Other side must not see free space until we've copied out */
membar_enter();
/* Implies mb(): they will see new header. */
}
return (0);
}
void
xb_suspend(void)
{
#ifdef XPV_HVM_DRIVER
#else
#endif
}
void
xb_setup_intr(void)
{
#ifdef XPV_HVM_DRIVER
xenbus_intr, NULL);
#else
if (xenbus_irq < 0) {
return;
}
#endif
}
/*
* Set up our xenstore page and event channel. Domain 0 needs to allocate a
* page and event channel; other domains use what we are told.
*/
void
xb_init(void)
{
int err;
if (DOMAIN_IS_INITDOMAIN(xen_info)) {
return;
&xb_cookie);
xb_addr));
(int *)&xen_info->store_evtchn);
} else {
/*
* This is harmless on first boot, but needed for resume and
* migrate. We use kbm_map_ma() as a shortcut instead of
* directly using HYPERVISOR_update_va_mapping().
*/
}
}
void *
xb_xenstore_cookie(void)
{
return (xb_cookie);
}