gnttab.c revision 5b1df0b52166fd52a6824b3c1e3c6d4ae6cfb42d
/*
* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* gnttab.c
*
* Granting foreign access to our memory reservation.
*
* Copyright (c) 2005-2006, Christopher Clark
* Copyright (c) 2004-2005, K A Fraser
*
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation; or, when 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.
*/
#include <sys/archsystm.h>
#ifdef XPV_HVM_DRIVER
#include <sys/xpv_support.h>
#endif
#include <sys/hypervisor.h>
#include <sys/sysmacros.h>
#include <sys/machsystm.h>
#include <sys/bootconf.h>
#include <sys/bootsvcs.h>
#ifndef XPV_HVM_DRIVER
#include <sys/bootinfo.h>
#include <sys/multiboot.h>
#include <vm/kboot_mmu.h>
#endif
#include <sys/bootprops.h>
#include <vm/seg_kmem.h>
/* Globals */
static grant_ref_t **gnttab_list;
static uint_t nr_grant_frames;
static int gnttab_free_count;
static grant_ref_t gnttab_free_head;
static kmutex_t gnttab_list_lock;
static grant_entry_t *shared;
static struct gnttab_free_callback *gnttab_free_callback_list;
/* Macros */
#define CMPXCHG(t, c, n) atomic_cas_16((t), (c), (n))
/* External tools reserve first few grant table entries. */
#define NR_RESERVED_ENTRIES 8
#define GNTTAB_LIST_END 0xffffffff
/* Implementation */
static uint_t
max_nr_grant_frames(void)
{
struct gnttab_query_size query;
int rc;
return (4); /* Legacy max supported number of frames */
return (query.max_nr_frames);
}
static void
do_free_callbacks(void)
{
} else {
}
}
}
static void
check_free_callbacks(void)
{
}
static int
{
for (i = nr_grant_frames; i < new_nr_grant_frames; i++)
for (i = GREFS_PER_GRANT_FRAME * nr_grant_frames;
GNTTAB_ENTRY(i) = i + 1;
GNTTAB_ENTRY(i) = gnttab_free_head;
return (0);
}
static int
{
return (-1);
return (grow_gnttab_list(extra));
}
static int
get_free_entries(int count)
{
if (gnttab_free_count < count &&
return (rc);
}
while (count-- > 1)
return (ref);
}
static void
{
}
/*
* Public grant-issuing interface functions
*/
int
{
int ref;
return (-1);
return (ref);
}
void
{
}
int
{
}
/* ARGSUSED */
int
{
do {
return (0);
}
return (1);
}
void
{
/*
* XXPV - we don't support freeing a page here
*/
if (page != 0) {
"gnttab_end_foreign_access_ref: using unsupported free_page interface");
/* free_page(page); */
}
} else {
/*
* XXX This needs to be fixed so that the ref and page are
* placed on a list to be freed up later.
*/
}
}
int
{
int ref;
return (-1);
return (ref);
}
void
{
}
{
/*
* If a transfer is not even yet started, try to reclaim the grant
* reference and return failure (== 0).
*/
return (0);
(void) HYPERVISOR_yield();
}
/* If a transfer is in progress then wait until it is completed. */
while (!(flags & GTF_transfer_completed)) {
(void) HYPERVISOR_yield();
}
/* Read the frame number /after/ reading completion status. */
return (frame);
}
{
return (frame);
}
void
{
}
void
{
int count = 1;
if (head == GNTTAB_LIST_END)
return;
count++;
}
}
int
{
int h = get_free_entries(count);
if (h == -1)
return (-1);
*head = h;
return (0);
}
int
{
return (*private_head == GNTTAB_LIST_END);
}
int
{
grant_ref_t g = *private_head;
if (g == GNTTAB_LIST_END)
return (-1);
*private_head = GNTTAB_ENTRY(g);
return (g);
}
void
{
*private_head = release;
}
void
{
goto out;
out:
}
void
{
struct gnttab_free_callback **pcb;
break;
}
}
}
static gnttab_frame_t *
{
KM_SLEEP);
/*LINTED: constant in conditional context*/
/*
* Take pset->nr_frames pages of grant table space from
* the hypervisor and map it
*/
}
return (frames);
}
#ifdef XPV_HVM_DRIVER
static void
gnttab_map(void)
{
struct xen_add_to_physmap xatp;
int i;
for (i = 0; i < max_nr_grant_frames(); i++) {
/*
* This call replaces the existing machine page backing
* the given gpfn with the page from the allocated grant
* table at index idx. The existing machine page is
* returned to the free list.
*/
panic("Couldn't map grant table");
va += MMU_PAGESIZE;
}
}
#endif /* XPV_HVM_DRIVER */
void
gnttab_init(void)
{
int i;
/*
* gnttab_init() should only be invoked once.
*/
ASSERT(nr_grant_frames == 0);
nr_grant_frames = 1;
#ifdef XPV_HVM_DRIVER
gnttab_map();
#else /* XPV_HVM_DRIVER */
MMU_PAGESIZE, 0, 0, 0, 0, VM_SLEEP);
xen_assign_pfn(frames[i]),
}
#endif
KM_SLEEP);
for (i = 0; i < nr_grant_frames; i++) {
}
GNTTAB_ENTRY(i) = i + 1;
}
void
gnttab_resume(void)
{
int i;
if (available_frames < nr_grant_frames) {
"frames: required(%u), available(%u)", nr_grant_frames,
}
#ifdef XPV_HVM_DRIVER
gnttab_map();
#endif /* XPV_HVM_DRIVER */
for (i = 0; i < available_frames; i++) {
(void) HYPERVISOR_update_va_mapping(GT_PGADDR(i),
UVMF_INVLPG | UVMF_ALL);
}
}
void
gnttab_suspend(void)
{
int i;
/*
* clear grant table mappings before suspending
*/
for (i = 0; i < max_nr_grant_frames(); i++) {
(void) HYPERVISOR_update_va_mapping(GT_PGADDR(i),
0, UVMF_INVLPG);
}
}
/*
* Local variables:
* c-file-style: "solaris"
* indent-tabs-mode: t
* c-indent-level: 8
* c-basic-offset: 8
* tab-width: 8
* End:
*/